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 "content/child/webcrypto/webcrypto_util.h" | 5 #include "content/child/webcrypto/webcrypto_util.h" |
6 | 6 |
7 #include "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "content/child/webcrypto/status.h" | 10 #include "content/child/webcrypto/status.h" |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 bool CreateSecretKeyAlgorithm(const blink::WebCryptoAlgorithm& algorithm, | 198 bool CreateSecretKeyAlgorithm(const blink::WebCryptoAlgorithm& algorithm, |
199 unsigned int keylen_bytes, | 199 unsigned int keylen_bytes, |
200 blink::WebCryptoKeyAlgorithm* key_algorithm) { | 200 blink::WebCryptoKeyAlgorithm* key_algorithm) { |
201 switch (algorithm.id()) { | 201 switch (algorithm.id()) { |
202 case blink::WebCryptoAlgorithmIdHmac: { | 202 case blink::WebCryptoAlgorithmIdHmac: { |
203 blink::WebCryptoAlgorithm hash = GetInnerHashAlgorithm(algorithm); | 203 blink::WebCryptoAlgorithm hash = GetInnerHashAlgorithm(algorithm); |
204 if (hash.isNull()) | 204 if (hash.isNull()) |
205 return false; | 205 return false; |
206 if (keylen_bytes > UINT_MAX / 8) | 206 if (keylen_bytes > UINT_MAX / 8) |
207 return false; | 207 return false; |
208 *key_algorithm = blink::WebCryptoKeyAlgorithm::adoptParamsAndCreate( | 208 *key_algorithm = |
209 algorithm.id(), | 209 blink::WebCryptoKeyAlgorithm::createHmac(hash.id(), keylen_bytes * 8); |
210 new blink::WebCryptoHmacKeyAlgorithmParams(hash, keylen_bytes * 8)); | |
211 return true; | 210 return true; |
212 } | 211 } |
213 case blink::WebCryptoAlgorithmIdAesKw: | 212 case blink::WebCryptoAlgorithmIdAesKw: |
214 case blink::WebCryptoAlgorithmIdAesCbc: | 213 case blink::WebCryptoAlgorithmIdAesCbc: |
215 case blink::WebCryptoAlgorithmIdAesCtr: | 214 case blink::WebCryptoAlgorithmIdAesCtr: |
216 case blink::WebCryptoAlgorithmIdAesGcm: | 215 case blink::WebCryptoAlgorithmIdAesGcm: |
217 *key_algorithm = blink::WebCryptoKeyAlgorithm::adoptParamsAndCreate( | 216 *key_algorithm = blink::WebCryptoKeyAlgorithm::createAes( |
218 algorithm.id(), | 217 algorithm.id(), keylen_bytes * 8); |
219 new blink::WebCryptoAesKeyAlgorithmParams(keylen_bytes * 8)); | |
220 return true; | 218 return true; |
221 default: | 219 default: |
222 return false; | 220 return false; |
223 } | 221 } |
224 } | 222 } |
225 | 223 |
226 } // namespace webcrypto | 224 } // namespace webcrypto |
227 | 225 |
228 } // namespace content | 226 } // namespace content |
OLD | NEW |