Chromium Code Reviews| 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 "third_party/WebKit/public/platform/WebCryptoAlgorithm.h" | 9 #include "third_party/WebKit/public/platform/WebCryptoAlgorithm.h" |
| 10 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h" | 10 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h" |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 249 } | 249 } |
| 250 | 250 |
| 251 blink::WebCryptoAlgorithm CreateHmacImportAlgorithm( | 251 blink::WebCryptoAlgorithm CreateHmacImportAlgorithm( |
| 252 blink::WebCryptoAlgorithmId hash_id) { | 252 blink::WebCryptoAlgorithmId hash_id) { |
| 253 DCHECK(IsHashAlgorithm(hash_id)); | 253 DCHECK(IsHashAlgorithm(hash_id)); |
| 254 return blink::WebCryptoAlgorithm::adoptParamsAndCreate( | 254 return blink::WebCryptoAlgorithm::adoptParamsAndCreate( |
| 255 blink::WebCryptoAlgorithmIdHmac, | 255 blink::WebCryptoAlgorithmIdHmac, |
| 256 new blink::WebCryptoHmacImportParams(CreateAlgorithm(hash_id))); | 256 new blink::WebCryptoHmacImportParams(CreateAlgorithm(hash_id))); |
| 257 } | 257 } |
| 258 | 258 |
| 259 blink::WebCryptoAlgorithm CreateRsaHashedImportAlgorithm( | |
| 260 blink::WebCryptoAlgorithmId id, | |
| 261 blink::WebCryptoAlgorithmId hash_id) { | |
| 262 DCHECK(IsHashAlgorithm(hash_id)); | |
| 263 DCHECK(id == blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5 || | |
| 264 id == blink::WebCryptoAlgorithmIdRsaOaep); | |
|
Ryan Sleevi
2014/03/14 20:54:11
No PSS?
eroman
2014/03/14 21:16:25
Not yet defined in blink, so no ID for such. Will
| |
| 265 return blink::WebCryptoAlgorithm::adoptParamsAndCreate( | |
| 266 id, new blink::WebCryptoRsaHashedImportParams(CreateAlgorithm(hash_id))); | |
| 267 } | |
| 268 | |
| 259 blink::WebCryptoAlgorithm CreateRsaSsaImportAlgorithm( | 269 blink::WebCryptoAlgorithm CreateRsaSsaImportAlgorithm( |
| 260 blink::WebCryptoAlgorithmId hash_id) { | 270 blink::WebCryptoAlgorithmId hash_id) { |
| 261 DCHECK(IsHashAlgorithm(hash_id)); | 271 return CreateRsaHashedImportAlgorithm( |
| 262 return blink::WebCryptoAlgorithm::adoptParamsAndCreate( | 272 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, hash_id); |
| 263 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, | |
| 264 new blink::WebCryptoRsaHashedImportParams(CreateAlgorithm(hash_id))); | |
| 265 } | 273 } |
| 266 | 274 |
| 267 blink::WebCryptoAlgorithm CreateRsaOaepImportAlgorithm( | 275 blink::WebCryptoAlgorithm CreateRsaOaepImportAlgorithm( |
| 268 blink::WebCryptoAlgorithmId hash_id) { | 276 blink::WebCryptoAlgorithmId hash_id) { |
| 269 DCHECK(IsHashAlgorithm(hash_id)); | 277 return CreateRsaHashedImportAlgorithm(blink::WebCryptoAlgorithmIdRsaOaep, |
| 270 return blink::WebCryptoAlgorithm::adoptParamsAndCreate( | 278 hash_id); |
| 271 blink::WebCryptoAlgorithmIdRsaOaep, | |
| 272 new blink::WebCryptoRsaHashedImportParams(CreateAlgorithm(hash_id))); | |
| 273 } | 279 } |
| 274 | 280 |
| 275 unsigned int ShaBlockSizeBytes(blink::WebCryptoAlgorithmId hash_id) { | 281 unsigned int ShaBlockSizeBytes(blink::WebCryptoAlgorithmId hash_id) { |
| 276 switch (hash_id) { | 282 switch (hash_id) { |
| 277 case blink::WebCryptoAlgorithmIdSha1: | 283 case blink::WebCryptoAlgorithmIdSha1: |
| 278 case blink::WebCryptoAlgorithmIdSha224: | 284 case blink::WebCryptoAlgorithmIdSha224: |
| 279 case blink::WebCryptoAlgorithmIdSha256: | 285 case blink::WebCryptoAlgorithmIdSha256: |
| 280 return 64; | 286 return 64; |
| 281 case blink::WebCryptoAlgorithmIdSha384: | 287 case blink::WebCryptoAlgorithmIdSha384: |
| 282 case blink::WebCryptoAlgorithmIdSha512: | 288 case blink::WebCryptoAlgorithmIdSha512: |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 308 new blink::WebCryptoAesKeyAlgorithmParams(keylen_bytes * 8)); | 314 new blink::WebCryptoAesKeyAlgorithmParams(keylen_bytes * 8)); |
| 309 return true; | 315 return true; |
| 310 default: | 316 default: |
| 311 return false; | 317 return false; |
| 312 } | 318 } |
| 313 } | 319 } |
| 314 | 320 |
| 315 } // namespace webcrypto | 321 } // namespace webcrypto |
| 316 | 322 |
| 317 } // namespace content | 323 } // namespace content |
| OLD | NEW |