Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(453)

Side by Side Diff: components/webcrypto/algorithms/aes.cc

Issue 1355923002: [refactor] Misc post-NSS WebCrypto cleanups. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@util_split
Patch Set: add an explicit size_t --> unsigned cast Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/webcrypto/algorithm_dispatch.cc ('k') | components/webcrypto/algorithms/aes_cbc.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/aes.h" 5 #include "components/webcrypto/algorithms/aes.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "components/webcrypto/algorithms/secret_key_util.h" 8 #include "components/webcrypto/algorithms/secret_key_util.h"
9 #include "components/webcrypto/crypto_data.h" 9 #include "components/webcrypto/crypto_data.h"
10 #include "components/webcrypto/jwk.h" 10 #include "components/webcrypto/jwk.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 Status AesAlgorithm::GenerateKey(const blink::WebCryptoAlgorithm& algorithm, 49 Status AesAlgorithm::GenerateKey(const blink::WebCryptoAlgorithm& algorithm,
50 bool extractable, 50 bool extractable,
51 blink::WebCryptoKeyUsageMask usages, 51 blink::WebCryptoKeyUsageMask usages,
52 GenerateKeyResult* result) const { 52 GenerateKeyResult* result) const {
53 Status status = CheckKeyCreationUsages(all_key_usages_, usages, false); 53 Status status = CheckKeyCreationUsages(all_key_usages_, usages, false);
54 if (status.IsError()) 54 if (status.IsError())
55 return status; 55 return status;
56 56
57 unsigned int keylen_bits = algorithm.aesKeyGenParams()->lengthBits(); 57 unsigned int keylen_bits = algorithm.aesKeyGenParams()->lengthBits();
58 58
59 // BoringSSL does not support 192-bit AES. 59 // 192-bit AES is intentionally unsupported (http://crbug.com/533699).
60 if (keylen_bits == 192) 60 if (keylen_bits == 192)
61 return Status::ErrorAes192BitUnsupported(); 61 return Status::ErrorAes192BitUnsupported();
62 62
63 if (keylen_bits != 128 && keylen_bits != 256) 63 if (keylen_bits != 128 && keylen_bits != 256)
64 return Status::ErrorGenerateAesKeyLength(); 64 return Status::ErrorGenerateAesKeyLength();
65 65
66 return GenerateWebCryptoSecretKey( 66 return GenerateWebCryptoSecretKey(
67 blink::WebCryptoKeyAlgorithm::createAes(algorithm.id(), keylen_bits), 67 blink::WebCryptoKeyAlgorithm::createAes(algorithm.id(), keylen_bits),
68 extractable, usages, keylen_bits, result); 68 extractable, usages, keylen_bits, result);
69 } 69 }
(...skipping 10 matching lines...) Expand all
80 } 80 }
81 } 81 }
82 82
83 Status AesAlgorithm::ImportKeyRaw(const CryptoData& key_data, 83 Status AesAlgorithm::ImportKeyRaw(const CryptoData& key_data,
84 const blink::WebCryptoAlgorithm& algorithm, 84 const blink::WebCryptoAlgorithm& algorithm,
85 bool extractable, 85 bool extractable,
86 blink::WebCryptoKeyUsageMask usages, 86 blink::WebCryptoKeyUsageMask usages,
87 blink::WebCryptoKey* key) const { 87 blink::WebCryptoKey* key) const {
88 const unsigned int keylen_bytes = key_data.byte_length(); 88 const unsigned int keylen_bytes = key_data.byte_length();
89 89
90 // BoringSSL does not support 192-bit AES. 90 // 192-bit AES is intentionally unsupported (http://crbug.com/533699).
91 if (keylen_bytes == 24) 91 if (keylen_bytes == 24)
92 return Status::ErrorAes192BitUnsupported(); 92 return Status::ErrorAes192BitUnsupported();
93 93
94 if (keylen_bytes != 16 && keylen_bytes != 32) 94 if (keylen_bytes != 16 && keylen_bytes != 32)
95 return Status::ErrorImportAesKeyLength(); 95 return Status::ErrorImportAesKeyLength();
96 96
97 // No possibility of overflow. 97 // No possibility of overflow.
98 unsigned int keylen_bits = keylen_bytes * 8; 98 unsigned int keylen_bits = keylen_bytes * 8;
99 99
100 return CreateWebCryptoSecretKey( 100 return CreateWebCryptoSecretKey(
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 Status AesAlgorithm::GetKeyLength( 171 Status AesAlgorithm::GetKeyLength(
172 const blink::WebCryptoAlgorithm& key_length_algorithm, 172 const blink::WebCryptoAlgorithm& key_length_algorithm,
173 bool* has_length_bits, 173 bool* has_length_bits,
174 unsigned int* length_bits) const { 174 unsigned int* length_bits) const {
175 *has_length_bits = true; 175 *has_length_bits = true;
176 *length_bits = key_length_algorithm.aesDerivedKeyParams()->lengthBits(); 176 *length_bits = key_length_algorithm.aesDerivedKeyParams()->lengthBits();
177 177
178 if (*length_bits == 128 || *length_bits == 256) 178 if (*length_bits == 128 || *length_bits == 256)
179 return Status::Success(); 179 return Status::Success();
180 180
181 // BoringSSL does not support 192-bit AES. 181 // 192-bit AES is intentionally unsupported (http://crbug.com/533699).
182 if (*length_bits == 192) 182 if (*length_bits == 192)
183 return Status::ErrorAes192BitUnsupported(); 183 return Status::ErrorAes192BitUnsupported();
184 184
185 return Status::ErrorGetAesKeyLength(); 185 return Status::ErrorGetAesKeyLength();
186 } 186 }
187 187
188 } // namespace webcrypto 188 } // namespace webcrypto
OLDNEW
« no previous file with comments | « components/webcrypto/algorithm_dispatch.cc ('k') | components/webcrypto/algorithms/aes_cbc.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698