| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/renderer/webcrypto/webcrypto_util.h" | 5 #include "content/renderer/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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 return algorithm.rsaSsaParams()->hash(); | 81 return algorithm.rsaSsaParams()->hash(); |
| 82 if (algorithm.rsaOaepParams()) | 82 if (algorithm.rsaOaepParams()) |
| 83 return algorithm.rsaOaepParams()->hash(); | 83 return algorithm.rsaOaepParams()->hash(); |
| 84 return blink::WebCryptoAlgorithm::createNull(); | 84 return blink::WebCryptoAlgorithm::createNull(); |
| 85 } | 85 } |
| 86 | 86 |
| 87 blink::WebCryptoAlgorithm CreateAlgorithm(blink::WebCryptoAlgorithmId id) { | 87 blink::WebCryptoAlgorithm CreateAlgorithm(blink::WebCryptoAlgorithmId id) { |
| 88 return blink::WebCryptoAlgorithm::adoptParamsAndCreate(id, NULL); | 88 return blink::WebCryptoAlgorithm::adoptParamsAndCreate(id, NULL); |
| 89 } | 89 } |
| 90 | 90 |
| 91 blink::WebCryptoAlgorithm CreateHmacAlgorithmByHashOutputLen( | |
| 92 unsigned short hash_output_length_bits) { | |
| 93 blink::WebCryptoAlgorithmId hash_id; | |
| 94 switch (hash_output_length_bits) { | |
| 95 case 160: | |
| 96 hash_id = blink::WebCryptoAlgorithmIdSha1; | |
| 97 break; | |
| 98 case 224: | |
| 99 hash_id = blink::WebCryptoAlgorithmIdSha224; | |
| 100 break; | |
| 101 case 256: | |
| 102 hash_id = blink::WebCryptoAlgorithmIdSha256; | |
| 103 break; | |
| 104 case 384: | |
| 105 hash_id = blink::WebCryptoAlgorithmIdSha384; | |
| 106 break; | |
| 107 case 512: | |
| 108 hash_id = blink::WebCryptoAlgorithmIdSha512; | |
| 109 break; | |
| 110 default: | |
| 111 NOTREACHED(); | |
| 112 return blink::WebCryptoAlgorithm::createNull(); | |
| 113 } | |
| 114 return blink::WebCryptoAlgorithm::adoptParamsAndCreate( | |
| 115 blink::WebCryptoAlgorithmIdHmac, | |
| 116 new blink::WebCryptoHmacParams(CreateAlgorithm(hash_id))); | |
| 117 } | |
| 118 | |
| 119 blink::WebCryptoAlgorithm CreateHmacAlgorithmByHashId( | 91 blink::WebCryptoAlgorithm CreateHmacAlgorithmByHashId( |
| 120 blink::WebCryptoAlgorithmId hash_id) { | 92 blink::WebCryptoAlgorithmId hash_id) { |
| 121 DCHECK(IsHashAlgorithm(hash_id)); | 93 DCHECK(IsHashAlgorithm(hash_id)); |
| 122 return blink::WebCryptoAlgorithm::adoptParamsAndCreate( | 94 return blink::WebCryptoAlgorithm::adoptParamsAndCreate( |
| 123 blink::WebCryptoAlgorithmIdHmac, | 95 blink::WebCryptoAlgorithmIdHmac, |
| 124 new blink::WebCryptoHmacParams(CreateAlgorithm(hash_id))); | 96 new blink::WebCryptoHmacParams(CreateAlgorithm(hash_id))); |
| 125 } | 97 } |
| 126 | 98 |
| 127 blink::WebCryptoAlgorithm CreateHmacKeyGenAlgorithm( | 99 blink::WebCryptoAlgorithm CreateHmacKeyGenAlgorithm( |
| 128 blink::WebCryptoAlgorithmId hash_id, | 100 blink::WebCryptoAlgorithmId hash_id, |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 | 168 |
| 197 blink::WebCryptoAlgorithm CreateAesGcmKeyGenAlgorithm( | 169 blink::WebCryptoAlgorithm CreateAesGcmKeyGenAlgorithm( |
| 198 unsigned short key_length_bits) { | 170 unsigned short key_length_bits) { |
| 199 return CreateAesKeyGenAlgorithm(blink::WebCryptoAlgorithmIdAesGcm, | 171 return CreateAesKeyGenAlgorithm(blink::WebCryptoAlgorithmIdAesGcm, |
| 200 key_length_bits); | 172 key_length_bits); |
| 201 } | 173 } |
| 202 | 174 |
| 203 } // namespace webcrypto | 175 } // namespace webcrypto |
| 204 | 176 |
| 205 } // namespace content | 177 } // namespace content |
| OLD | NEW |