| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/webcrypto/algorithms/ec.h" | 5 #include "components/webcrypto/algorithms/ec.h" |
| 6 | 6 |
| 7 #include <openssl/ec.h> | 7 #include <openssl/ec.h> |
| 8 #include <openssl/ec_key.h> | 8 #include <openssl/ec_key.h> |
| 9 #include <openssl/evp.h> | 9 #include <openssl/evp.h> |
| 10 #include <openssl/pkcs12.h> | 10 #include <openssl/pkcs12.h> |
| 11 | 11 |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/stl_util.h" | |
| 14 #include "components/webcrypto/algorithms/asymmetric_key_util.h" | 13 #include "components/webcrypto/algorithms/asymmetric_key_util.h" |
| 15 #include "components/webcrypto/algorithms/util.h" | 14 #include "components/webcrypto/algorithms/util.h" |
| 16 #include "components/webcrypto/blink_key_handle.h" | 15 #include "components/webcrypto/blink_key_handle.h" |
| 17 #include "components/webcrypto/crypto_data.h" | 16 #include "components/webcrypto/crypto_data.h" |
| 18 #include "components/webcrypto/generate_key_result.h" | 17 #include "components/webcrypto/generate_key_result.h" |
| 19 #include "components/webcrypto/jwk.h" | 18 #include "components/webcrypto/jwk.h" |
| 20 #include "components/webcrypto/status.h" | 19 #include "components/webcrypto/status.h" |
| 21 #include "crypto/openssl_util.h" | 20 #include "crypto/openssl_util.h" |
| 22 #include "crypto/scoped_openssl_types.h" | 21 #include "crypto/scoped_openssl_types.h" |
| 23 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h" | 22 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h" |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 return Status::Success(); | 151 return Status::Success(); |
| 153 } | 152 } |
| 154 | 153 |
| 155 // Writes an unsigned BIGNUM into |jwk|, zero-padding it to a length of | 154 // Writes an unsigned BIGNUM into |jwk|, zero-padding it to a length of |
| 156 // |padded_length|. | 155 // |padded_length|. |
| 157 Status WritePaddedBIGNUM(const std::string& member_name, | 156 Status WritePaddedBIGNUM(const std::string& member_name, |
| 158 const BIGNUM* value, | 157 const BIGNUM* value, |
| 159 size_t padded_length, | 158 size_t padded_length, |
| 160 JwkWriter* jwk) { | 159 JwkWriter* jwk) { |
| 161 std::vector<uint8_t> padded_bytes(padded_length); | 160 std::vector<uint8_t> padded_bytes(padded_length); |
| 162 if (!BN_bn2bin_padded(vector_as_array(&padded_bytes), padded_bytes.size(), | 161 if (!BN_bn2bin_padded(padded_bytes.data(), padded_bytes.size(), value)) |
| 163 value)) { | |
| 164 return Status::OperationError(); | 162 return Status::OperationError(); |
| 165 } | |
| 166 jwk->SetBytes(member_name, CryptoData(padded_bytes)); | 163 jwk->SetBytes(member_name, CryptoData(padded_bytes)); |
| 167 return Status::Success(); | 164 return Status::Success(); |
| 168 } | 165 } |
| 169 | 166 |
| 170 // Reads a fixed length BIGNUM from a JWK. | 167 // Reads a fixed length BIGNUM from a JWK. |
| 171 Status ReadPaddedBIGNUM(const JwkReader& jwk, | 168 Status ReadPaddedBIGNUM(const JwkReader& jwk, |
| 172 const std::string& member_name, | 169 const std::string& member_name, |
| 173 size_t expected_length, | 170 size_t expected_length, |
| 174 crypto::ScopedBIGNUM* out) { | 171 crypto::ScopedBIGNUM* out) { |
| 175 std::string bytes; | 172 std::string bytes; |
| (...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 569 | 566 |
| 570 if (algorithm.ecParams()->namedCurve() != | 567 if (algorithm.ecParams()->namedCurve() != |
| 571 key->algorithm().ecParams()->namedCurve()) { | 568 key->algorithm().ecParams()->namedCurve()) { |
| 572 return Status::ErrorUnexpected(); | 569 return Status::ErrorUnexpected(); |
| 573 } | 570 } |
| 574 | 571 |
| 575 return Status::Success(); | 572 return Status::Success(); |
| 576 } | 573 } |
| 577 | 574 |
| 578 } // namespace webcrypto | 575 } // namespace webcrypto |
| OLD | NEW |