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 CONTENT_CHILD_WEBCRYPTO_OPENSSL_UTIL_OPENSSL_H_ | 5 #ifndef CONTENT_CHILD_WEBCRYPTO_OPENSSL_UTIL_OPENSSL_H_ |
6 #define CONTENT_CHILD_WEBCRYPTO_OPENSSL_UTIL_OPENSSL_H_ | 6 #define CONTENT_CHILD_WEBCRYPTO_OPENSSL_UTIL_OPENSSL_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include <openssl/ossl_typ.h> | 10 #include <openssl/ossl_typ.h> |
11 | 11 |
| 12 #include "crypto/scoped_openssl_types.h" |
12 #include "third_party/WebKit/public/platform/WebCryptoAlgorithm.h" | 13 #include "third_party/WebKit/public/platform/WebCryptoAlgorithm.h" |
13 #include "third_party/WebKit/public/platform/WebCryptoKey.h" | 14 #include "third_party/WebKit/public/platform/WebCryptoKey.h" |
14 | 15 |
15 namespace content { | 16 namespace content { |
16 | 17 |
17 namespace webcrypto { | 18 namespace webcrypto { |
18 | 19 |
19 class CryptoData; | 20 class CryptoData; |
20 class Status; | 21 class Status; |
21 | 22 |
22 // The values of these constants correspond with the "enc" parameter of | 23 // The values of these constants correspond with the "enc" parameter of |
23 // EVP_CipherInit_ex(), do not change. | 24 // EVP_CipherInit_ex(), do not change. |
24 enum EncryptOrDecrypt { DECRYPT=0, ENCRYPT=1 }; | 25 enum EncryptOrDecrypt { DECRYPT=0, ENCRYPT=1 }; |
25 | 26 |
26 const EVP_MD* GetDigest(blink::WebCryptoAlgorithmId id); | 27 const EVP_MD* GetDigest(blink::WebCryptoAlgorithmId id); |
27 | 28 |
28 // Does either encryption or decryption for an AEAD algorithm. | 29 // Does either encryption or decryption for an AEAD algorithm. |
29 // * |mode| controls whether encryption or decryption is done | 30 // * |mode| controls whether encryption or decryption is done |
30 // * |aead_alg| the algorithm (for instance AES-GCM) | 31 // * |aead_alg| the algorithm (for instance AES-GCM) |
31 // * |buffer| where the ciphertext or plaintext is written to. | 32 // * |buffer| where the ciphertext or plaintext is written to. |
32 Status AeadEncryptDecrypt(EncryptOrDecrypt mode, | 33 Status AeadEncryptDecrypt(EncryptOrDecrypt mode, |
33 const std::vector<uint8_t>& raw_key, | 34 const std::vector<uint8_t>& raw_key, |
34 const CryptoData& data, | 35 const CryptoData& data, |
35 unsigned int tag_length_bytes, | 36 unsigned int tag_length_bytes, |
36 const CryptoData& iv, | 37 const CryptoData& iv, |
37 const CryptoData& additional_data, | 38 const CryptoData& additional_data, |
38 const EVP_AEAD* aead_alg, | 39 const EVP_AEAD* aead_alg, |
39 std::vector<uint8_t>* buffer); | 40 std::vector<uint8_t>* buffer); |
40 | 41 |
| 42 // Creates a WebCrypto public key given an EVP_PKEY. This step includes |
| 43 // exporting the key to SPKI format, for use by serialization later. |
| 44 Status CreateWebCryptoPublicKey( |
| 45 crypto::ScopedEVP_PKEY public_key, |
| 46 const blink::WebCryptoKeyAlgorithm& algorithm, |
| 47 bool extractable, |
| 48 blink::WebCryptoKeyUsageMask usages, |
| 49 blink::WebCryptoKey* key); |
| 50 |
| 51 // Creates a WebCrypto private key given an EVP_PKEY. This step includes |
| 52 // exporting the key to PKCS8 format, for use by serialization later. |
| 53 Status CreateWebCryptoPrivateKey( |
| 54 crypto::ScopedEVP_PKEY private_key, |
| 55 const blink::WebCryptoKeyAlgorithm& algorithm, |
| 56 bool extractable, |
| 57 blink::WebCryptoKeyUsageMask usages, |
| 58 blink::WebCryptoKey* key); |
| 59 |
| 60 // Imports SPKI bytes to an EVP_PKEY for a public key. The resulting asymmetric |
| 61 // key may be invalid, and should be verified using something like |
| 62 // RSA_check_key(). The only validation performed by this function is to ensure |
| 63 // the key type matched |expected_pkey_id|. |
| 64 Status ImportUnverifiedPkeyFromSpki(const CryptoData& key_data, |
| 65 int expected_pkey_id, |
| 66 crypto::ScopedEVP_PKEY* pkey); |
| 67 |
| 68 // Imports PKCS8 bytes to an EVP_PKEY for a private key. The resulting |
| 69 // asymmetric key may be invalid, and should be verified using something like |
| 70 // RSA_check_key(). The only validation performed by this function is to ensure |
| 71 // the key type matched |expected_pkey_id|. |
| 72 Status ImportUnverifiedPkeyFromPkcs8(const CryptoData& key_data, |
| 73 int expected_pkey_id, |
| 74 crypto::ScopedEVP_PKEY* pkey); |
| 75 |
41 } // namespace webcrypto | 76 } // namespace webcrypto |
42 | 77 |
43 } // namespace content | 78 } // namespace content |
44 | 79 |
45 #endif // CONTENT_CHILD_WEBCRYPTO_OPENSSL_UTIL_OPENSSL_H_ | 80 #endif // CONTENT_CHILD_WEBCRYPTO_OPENSSL_UTIL_OPENSSL_H_ |
OLD | NEW |