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" |
11 | 11 |
12 namespace content { | 12 namespace content { |
13 | 13 |
14 namespace webcrypto { | 14 namespace webcrypto { |
15 | 15 |
16 namespace { | 16 namespace { |
17 | 17 |
18 blink::WebCryptoAlgorithm CreateAesKeyGenAlgorithm( | |
19 blink::WebCryptoAlgorithmId aes_alg_id, | |
20 unsigned short length) { | |
21 return blink::WebCryptoAlgorithm::adoptParamsAndCreate( | |
22 aes_alg_id, new blink::WebCryptoAesKeyGenParams(length)); | |
23 } | |
24 | |
25 bool IsHashAlgorithm(blink::WebCryptoAlgorithmId alg_id) { | 18 bool IsHashAlgorithm(blink::WebCryptoAlgorithmId alg_id) { |
26 return alg_id == blink::WebCryptoAlgorithmIdSha1 || | 19 return alg_id == blink::WebCryptoAlgorithmIdSha1 || |
27 alg_id == blink::WebCryptoAlgorithmIdSha224 || | 20 alg_id == blink::WebCryptoAlgorithmIdSha224 || |
28 alg_id == blink::WebCryptoAlgorithmIdSha256 || | 21 alg_id == blink::WebCryptoAlgorithmIdSha256 || |
29 alg_id == blink::WebCryptoAlgorithmIdSha384 || | 22 alg_id == blink::WebCryptoAlgorithmIdSha384 || |
30 alg_id == blink::WebCryptoAlgorithmIdSha512; | 23 alg_id == blink::WebCryptoAlgorithmIdSha512; |
31 } | 24 } |
32 | 25 |
33 } // namespace | 26 } // namespace |
34 | 27 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 blink::WebCryptoAlgorithmIdAesCbc, | 146 blink::WebCryptoAlgorithmIdAesCbc, |
154 new blink::WebCryptoAesGcmParams(Uint8VectorStart(iv), | 147 new blink::WebCryptoAesGcmParams(Uint8VectorStart(iv), |
155 iv.size(), | 148 iv.size(), |
156 additional_data.size() != 0, | 149 additional_data.size() != 0, |
157 Uint8VectorStart(additional_data), | 150 Uint8VectorStart(additional_data), |
158 additional_data.size(), | 151 additional_data.size(), |
159 tag_length_bytes != 0, | 152 tag_length_bytes != 0, |
160 tag_length_bytes)); | 153 tag_length_bytes)); |
161 } | 154 } |
162 | 155 |
163 blink::WebCryptoAlgorithm CreateAesCbcKeyGenAlgorithm( | |
164 unsigned short key_length_bits) { | |
165 return CreateAesKeyGenAlgorithm(blink::WebCryptoAlgorithmIdAesCbc, | |
166 key_length_bits); | |
167 } | |
168 | |
169 blink::WebCryptoAlgorithm CreateAesGcmKeyGenAlgorithm( | |
170 unsigned short key_length_bits) { | |
171 return CreateAesKeyGenAlgorithm(blink::WebCryptoAlgorithmIdAesGcm, | |
172 key_length_bits); | |
173 } | |
174 | |
175 unsigned int ShaBlockSizeBytes(blink::WebCryptoAlgorithmId hash_id) { | 156 unsigned int ShaBlockSizeBytes(blink::WebCryptoAlgorithmId hash_id) { |
176 switch (hash_id) { | 157 switch (hash_id) { |
177 case blink::WebCryptoAlgorithmIdSha1: | 158 case blink::WebCryptoAlgorithmIdSha1: |
178 case blink::WebCryptoAlgorithmIdSha224: | 159 case blink::WebCryptoAlgorithmIdSha224: |
179 case blink::WebCryptoAlgorithmIdSha256: | 160 case blink::WebCryptoAlgorithmIdSha256: |
180 return 64; | 161 return 64; |
181 case blink::WebCryptoAlgorithmIdSha384: | 162 case blink::WebCryptoAlgorithmIdSha384: |
182 case blink::WebCryptoAlgorithmIdSha512: | 163 case blink::WebCryptoAlgorithmIdSha512: |
183 return 128; | 164 return 128; |
184 default: | 165 default: |
185 NOTREACHED(); | 166 NOTREACHED(); |
186 return 0; | 167 return 0; |
187 } | 168 } |
188 } | 169 } |
189 | 170 |
190 } // namespace webcrypto | 171 } // namespace webcrypto |
191 | 172 |
192 } // namespace content | 173 } // namespace content |
OLD | NEW |