| 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/rsa.h" | 5 #include "components/webcrypto/algorithms/rsa.h" |
| 6 | 6 |
| 7 #include <openssl/evp.h> | 7 #include <openssl/evp.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/stl_util.h" | |
| 11 #include "components/webcrypto/algorithms/asymmetric_key_util.h" | 10 #include "components/webcrypto/algorithms/asymmetric_key_util.h" |
| 12 #include "components/webcrypto/algorithms/util.h" | 11 #include "components/webcrypto/algorithms/util.h" |
| 13 #include "components/webcrypto/blink_key_handle.h" | 12 #include "components/webcrypto/blink_key_handle.h" |
| 14 #include "components/webcrypto/crypto_data.h" | 13 #include "components/webcrypto/crypto_data.h" |
| 15 #include "components/webcrypto/generate_key_result.h" | 14 #include "components/webcrypto/generate_key_result.h" |
| 16 #include "components/webcrypto/jwk.h" | 15 #include "components/webcrypto/jwk.h" |
| 17 #include "components/webcrypto/status.h" | 16 #include "components/webcrypto/status.h" |
| 18 #include "crypto/openssl_util.h" | 17 #include "crypto/openssl_util.h" |
| 19 #include "crypto/scoped_openssl_types.h" | 18 #include "crypto/scoped_openssl_types.h" |
| 20 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h" | 19 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h" |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 return Status::OperationError(); | 224 return Status::OperationError(); |
| 226 | 225 |
| 227 return CreateWebCryptoRsaPublicKey(pkey.Pass(), algorithm.id(), | 226 return CreateWebCryptoRsaPublicKey(pkey.Pass(), algorithm.id(), |
| 228 algorithm.rsaHashedImportParams()->hash(), | 227 algorithm.rsaHashedImportParams()->hash(), |
| 229 extractable, usages, key); | 228 extractable, usages, key); |
| 230 } | 229 } |
| 231 | 230 |
| 232 // Converts a BIGNUM to a big endian byte array. | 231 // Converts a BIGNUM to a big endian byte array. |
| 233 std::vector<uint8_t> BIGNUMToVector(const BIGNUM* n) { | 232 std::vector<uint8_t> BIGNUMToVector(const BIGNUM* n) { |
| 234 std::vector<uint8_t> v(BN_num_bytes(n)); | 233 std::vector<uint8_t> v(BN_num_bytes(n)); |
| 235 BN_bn2bin(n, vector_as_array(&v)); | 234 BN_bn2bin(n, v.data()); |
| 236 return v; | 235 return v; |
| 237 } | 236 } |
| 238 | 237 |
| 239 // Synthesizes an import algorithm given a key algorithm, so that | 238 // Synthesizes an import algorithm given a key algorithm, so that |
| 240 // deserialization can re-use the ImportKey*() methods. | 239 // deserialization can re-use the ImportKey*() methods. |
| 241 blink::WebCryptoAlgorithm SynthesizeImportAlgorithmForClone( | 240 blink::WebCryptoAlgorithm SynthesizeImportAlgorithmForClone( |
| 242 const blink::WebCryptoKeyAlgorithm& algorithm) { | 241 const blink::WebCryptoKeyAlgorithm& algorithm) { |
| 243 return blink::WebCryptoAlgorithm::adoptParamsAndCreate( | 242 return blink::WebCryptoAlgorithm::adoptParamsAndCreate( |
| 244 algorithm.id(), new blink::WebCryptoRsaHashedImportParams( | 243 algorithm.id(), new blink::WebCryptoRsaHashedImportParams( |
| 245 algorithm.rsaHashedParams()->hash())); | 244 algorithm.rsaHashedParams()->hash())); |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 memcmp(algorithm.rsaHashedParams()->publicExponent().data(), | 540 memcmp(algorithm.rsaHashedParams()->publicExponent().data(), |
| 542 key->algorithm().rsaHashedParams()->publicExponent().data(), | 541 key->algorithm().rsaHashedParams()->publicExponent().data(), |
| 543 key->algorithm().rsaHashedParams()->publicExponent().size())) { | 542 key->algorithm().rsaHashedParams()->publicExponent().size())) { |
| 544 return Status::ErrorUnexpected(); | 543 return Status::ErrorUnexpected(); |
| 545 } | 544 } |
| 546 | 545 |
| 547 return Status::Success(); | 546 return Status::Success(); |
| 548 } | 547 } |
| 549 | 548 |
| 550 } // namespace webcrypto | 549 } // namespace webcrypto |
| OLD | NEW |