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 <vector> | 5 #include <vector> |
6 #include <openssl/evp.h> | 6 #include <openssl/evp.h> |
7 | 7 |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "content/child/webcrypto/crypto_data.h" | 9 #include "content/child/webcrypto/crypto_data.h" |
10 #include "content/child/webcrypto/openssl/aes_key_openssl.h" | 10 #include "content/child/webcrypto/openssl/aes_key_openssl.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 // TODO(eroman): Hook up 256-bit support when it is available. | 29 // TODO(eroman): Hook up 256-bit support when it is available. |
30 default: | 30 default: |
31 return NULL; | 31 return NULL; |
32 } | 32 } |
33 } | 33 } |
34 | 34 |
35 Status AesGcmEncryptDecrypt(EncryptOrDecrypt mode, | 35 Status AesGcmEncryptDecrypt(EncryptOrDecrypt mode, |
36 const blink::WebCryptoAlgorithm& algorithm, | 36 const blink::WebCryptoAlgorithm& algorithm, |
37 const blink::WebCryptoKey& key, | 37 const blink::WebCryptoKey& key, |
38 const CryptoData& data, | 38 const CryptoData& data, |
39 std::vector<uint8>* buffer) { | 39 std::vector<uint8_t>* buffer) { |
40 const std::vector<uint8>& raw_key = SymKeyOpenSsl::Cast(key)->raw_key_data(); | 40 const std::vector<uint8_t>& raw_key = |
| 41 SymKeyOpenSsl::Cast(key)->raw_key_data(); |
41 const blink::WebCryptoAesGcmParams* params = algorithm.aesGcmParams(); | 42 const blink::WebCryptoAesGcmParams* params = algorithm.aesGcmParams(); |
42 | 43 |
43 crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE); | 44 crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE); |
44 | 45 |
45 unsigned int tag_length_bits; | 46 unsigned int tag_length_bits; |
46 Status status = GetAesGcmTagLengthInBits(params, &tag_length_bits); | 47 Status status = GetAesGcmTagLengthInBits(params, &tag_length_bits); |
47 if (status.IsError()) | 48 if (status.IsError()) |
48 return status; | 49 return status; |
49 unsigned int tag_length_bytes = tag_length_bits / 8; | 50 unsigned int tag_length_bytes = tag_length_bits / 8; |
50 | 51 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 return Status::Success(); | 110 return Status::Success(); |
110 } | 111 } |
111 | 112 |
112 class AesGcmImplementation : public AesAlgorithm { | 113 class AesGcmImplementation : public AesAlgorithm { |
113 public: | 114 public: |
114 AesGcmImplementation() : AesAlgorithm("GCM") {} | 115 AesGcmImplementation() : AesAlgorithm("GCM") {} |
115 | 116 |
116 virtual Status Encrypt(const blink::WebCryptoAlgorithm& algorithm, | 117 virtual Status Encrypt(const blink::WebCryptoAlgorithm& algorithm, |
117 const blink::WebCryptoKey& key, | 118 const blink::WebCryptoKey& key, |
118 const CryptoData& data, | 119 const CryptoData& data, |
119 std::vector<uint8>* buffer) const OVERRIDE { | 120 std::vector<uint8_t>* buffer) const OVERRIDE { |
120 return AesGcmEncryptDecrypt(ENCRYPT, algorithm, key, data, buffer); | 121 return AesGcmEncryptDecrypt(ENCRYPT, algorithm, key, data, buffer); |
121 } | 122 } |
122 | 123 |
123 virtual Status Decrypt(const blink::WebCryptoAlgorithm& algorithm, | 124 virtual Status Decrypt(const blink::WebCryptoAlgorithm& algorithm, |
124 const blink::WebCryptoKey& key, | 125 const blink::WebCryptoKey& key, |
125 const CryptoData& data, | 126 const CryptoData& data, |
126 std::vector<uint8>* buffer) const OVERRIDE { | 127 std::vector<uint8_t>* buffer) const OVERRIDE { |
127 return AesGcmEncryptDecrypt(DECRYPT, algorithm, key, data, buffer); | 128 return AesGcmEncryptDecrypt(DECRYPT, algorithm, key, data, buffer); |
128 } | 129 } |
129 }; | 130 }; |
130 | 131 |
131 } // namespace | 132 } // namespace |
132 | 133 |
133 AlgorithmImplementation* CreatePlatformAesGcmImplementation() { | 134 AlgorithmImplementation* CreatePlatformAesGcmImplementation() { |
134 return new AesGcmImplementation; | 135 return new AesGcmImplementation; |
135 } | 136 } |
136 | 137 |
137 } // namespace webcrypto | 138 } // namespace webcrypto |
138 | 139 |
139 } // namespace content | 140 } // namespace content |
OLD | NEW |