| 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 return Status::Success(); | 113 return Status::Success(); |
| 113 } | 114 } |
| 114 | 115 |
| 115 class AesGcmImplementation : public AesAlgorithm { | 116 class AesGcmImplementation : public AesAlgorithm { |
| 116 public: | 117 public: |
| 117 AesGcmImplementation() : AesAlgorithm("GCM") {} | 118 AesGcmImplementation() : AesAlgorithm("GCM") {} |
| 118 | 119 |
| 119 virtual Status Encrypt(const blink::WebCryptoAlgorithm& algorithm, | 120 virtual Status Encrypt(const blink::WebCryptoAlgorithm& algorithm, |
| 120 const blink::WebCryptoKey& key, | 121 const blink::WebCryptoKey& key, |
| 121 const CryptoData& data, | 122 const CryptoData& data, |
| 122 std::vector<uint8>* buffer) const OVERRIDE { | 123 std::vector<uint8_t>* buffer) const OVERRIDE { |
| 123 return AesGcmEncryptDecrypt(ENCRYPT, algorithm, key, data, buffer); | 124 return AesGcmEncryptDecrypt(ENCRYPT, algorithm, key, data, buffer); |
| 124 } | 125 } |
| 125 | 126 |
| 126 virtual Status Decrypt(const blink::WebCryptoAlgorithm& algorithm, | 127 virtual Status Decrypt(const blink::WebCryptoAlgorithm& algorithm, |
| 127 const blink::WebCryptoKey& key, | 128 const blink::WebCryptoKey& key, |
| 128 const CryptoData& data, | 129 const CryptoData& data, |
| 129 std::vector<uint8>* buffer) const OVERRIDE { | 130 std::vector<uint8_t>* buffer) const OVERRIDE { |
| 130 return AesGcmEncryptDecrypt(DECRYPT, algorithm, key, data, buffer); | 131 return AesGcmEncryptDecrypt(DECRYPT, algorithm, key, data, buffer); |
| 131 } | 132 } |
| 132 }; | 133 }; |
| 133 | 134 |
| 134 } // namespace | 135 } // namespace |
| 135 | 136 |
| 136 AlgorithmImplementation* CreatePlatformAesGcmImplementation() { | 137 AlgorithmImplementation* CreatePlatformAesGcmImplementation() { |
| 137 return new AesGcmImplementation; | 138 return new AesGcmImplementation; |
| 138 } | 139 } |
| 139 | 140 |
| 140 } // namespace webcrypto | 141 } // namespace webcrypto |
| 141 | 142 |
| 142 } // namespace content | 143 } // namespace content |
| OLD | NEW |