| 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 #ifndef COMPONENTS_WEBCRYPTO_ALGORITHMS_UTIL_OPENSSL_H_ | 5 #ifndef COMPONENTS_WEBCRYPTO_ALGORITHMS_UTIL_OPENSSL_H_ |
| 6 #define COMPONENTS_WEBCRYPTO_ALGORITHMS_UTIL_OPENSSL_H_ | 6 #define COMPONENTS_WEBCRYPTO_ALGORITHMS_UTIL_OPENSSL_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include <openssl/ossl_typ.h> | 11 #include <openssl/base.h> |
| 12 | 12 |
| 13 #include "crypto/scoped_openssl_types.h" | 13 #include "crypto/scoped_openssl_types.h" |
| 14 #include "third_party/WebKit/public/platform/WebCryptoAlgorithm.h" | 14 #include "third_party/WebKit/public/platform/WebCryptoAlgorithm.h" |
| 15 #include "third_party/WebKit/public/platform/WebCryptoKey.h" | 15 #include "third_party/WebKit/public/platform/WebCryptoKey.h" |
| 16 | 16 |
| 17 namespace webcrypto { | 17 namespace webcrypto { |
| 18 | 18 |
| 19 class CryptoData; | 19 class CryptoData; |
| 20 class GenerateKeyResult; | 20 class GenerateKeyResult; |
| 21 class Status; | 21 class Status; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 32 // * |buffer| where the ciphertext or plaintext is written to. | 32 // * |buffer| where the ciphertext or plaintext is written to. |
| 33 Status AeadEncryptDecrypt(EncryptOrDecrypt mode, | 33 Status AeadEncryptDecrypt(EncryptOrDecrypt mode, |
| 34 const std::vector<uint8_t>& raw_key, | 34 const std::vector<uint8_t>& raw_key, |
| 35 const CryptoData& data, | 35 const CryptoData& data, |
| 36 unsigned int tag_length_bytes, | 36 unsigned int tag_length_bytes, |
| 37 const CryptoData& iv, | 37 const CryptoData& iv, |
| 38 const CryptoData& additional_data, | 38 const CryptoData& additional_data, |
| 39 const EVP_AEAD* aead_alg, | 39 const EVP_AEAD* aead_alg, |
| 40 std::vector<uint8_t>* buffer); | 40 std::vector<uint8_t>* buffer); |
| 41 | 41 |
| 42 // Generates a random secret key of the given bit length. If the bit length is | |
| 43 // not a multiple of 8, then the resulting key will have ceil(keylen_bits / 8) | |
| 44 // bytes, and the "unused" bits will be set to zero. This function does not do | |
| 45 // any validation checks on the provided parameters. | |
| 46 Status GenerateWebCryptoSecretKey(const blink::WebCryptoKeyAlgorithm& algorithm, | |
| 47 bool extractable, | |
| 48 blink::WebCryptoKeyUsageMask usages, | |
| 49 unsigned int keylen_bits, | |
| 50 GenerateKeyResult* result); | |
| 51 | |
| 52 // Creates a WebCrypto secret key given a the raw data. The provided |key_data| | |
| 53 // will be copied into the new key. This function does not do any validation | |
| 54 // checks for the provided parameters. | |
| 55 Status CreateWebCryptoSecretKey(const CryptoData& key_data, | |
| 56 const blink::WebCryptoKeyAlgorithm& algorithm, | |
| 57 bool extractable, | |
| 58 blink::WebCryptoKeyUsageMask usages, | |
| 59 blink::WebCryptoKey* key); | |
| 60 | |
| 61 // Creates a WebCrypto public key given an EVP_PKEY. This step includes | 42 // Creates a WebCrypto public key given an EVP_PKEY. This step includes |
| 62 // exporting the key to SPKI format, for use by serialization later. | 43 // exporting the key to SPKI format, for use by serialization later. |
| 63 Status CreateWebCryptoPublicKey(crypto::ScopedEVP_PKEY public_key, | 44 Status CreateWebCryptoPublicKey(crypto::ScopedEVP_PKEY public_key, |
| 64 const blink::WebCryptoKeyAlgorithm& algorithm, | 45 const blink::WebCryptoKeyAlgorithm& algorithm, |
| 65 bool extractable, | 46 bool extractable, |
| 66 blink::WebCryptoKeyUsageMask usages, | 47 blink::WebCryptoKeyUsageMask usages, |
| 67 blink::WebCryptoKey* key); | 48 blink::WebCryptoKey* key); |
| 68 | 49 |
| 69 // Creates a WebCrypto private key given an EVP_PKEY. This step includes | 50 // Creates a WebCrypto private key given an EVP_PKEY. This step includes |
| 70 // exporting the key to PKCS8 format, for use by serialization later. | 51 // exporting the key to PKCS8 format, for use by serialization later. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 92 | 73 |
| 93 // Allocates a new BIGNUM given a std::string big-endian representation. | 74 // Allocates a new BIGNUM given a std::string big-endian representation. |
| 94 BIGNUM* CreateBIGNUM(const std::string& n); | 75 BIGNUM* CreateBIGNUM(const std::string& n); |
| 95 | 76 |
| 96 // Converts a BIGNUM to a big endian byte array. | 77 // Converts a BIGNUM to a big endian byte array. |
| 97 std::vector<uint8_t> BIGNUMToVector(const BIGNUM* n); | 78 std::vector<uint8_t> BIGNUMToVector(const BIGNUM* n); |
| 98 | 79 |
| 99 } // namespace webcrypto | 80 } // namespace webcrypto |
| 100 | 81 |
| 101 #endif // COMPONENTS_WEBCRYPTO_ALGORITHMS_UTIL_OPENSSL_H_ | 82 #endif // COMPONENTS_WEBCRYPTO_ALGORITHMS_UTIL_OPENSSL_H_ |
| OLD | NEW |