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

Side by Side Diff: content/child/webcrypto/openssl/aes_key_openssl.cc

Issue 512023002: Refactor the interface for generating keys. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Run git-cl format Created 6 years, 2 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
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 "content/child/webcrypto/openssl/aes_key_openssl.h" 5 #include "content/child/webcrypto/openssl/aes_key_openssl.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "content/child/webcrypto/crypto_data.h" 8 #include "content/child/webcrypto/crypto_data.h"
9 #include "content/child/webcrypto/jwk.h" 9 #include "content/child/webcrypto/jwk.h"
10 #include "content/child/webcrypto/openssl/key_openssl.h" 10 #include "content/child/webcrypto/openssl/key_openssl.h"
(...skipping 12 matching lines...) Expand all
23 } 23 }
24 24
25 AesAlgorithm::AesAlgorithm(const std::string& jwk_suffix) 25 AesAlgorithm::AesAlgorithm(const std::string& jwk_suffix)
26 : all_key_usages_(blink::WebCryptoKeyUsageEncrypt | 26 : all_key_usages_(blink::WebCryptoKeyUsageEncrypt |
27 blink::WebCryptoKeyUsageDecrypt | 27 blink::WebCryptoKeyUsageDecrypt |
28 blink::WebCryptoKeyUsageWrapKey | 28 blink::WebCryptoKeyUsageWrapKey |
29 blink::WebCryptoKeyUsageUnwrapKey), 29 blink::WebCryptoKeyUsageUnwrapKey),
30 jwk_suffix_(jwk_suffix) { 30 jwk_suffix_(jwk_suffix) {
31 } 31 }
32 32
33 Status AesAlgorithm::VerifyKeyUsagesBeforeGenerateKey( 33 Status AesAlgorithm::GenerateKey(const blink::WebCryptoAlgorithm& algorithm,
34 blink::WebCryptoKeyUsageMask usage_mask) const { 34 bool extractable,
35 return CheckKeyCreationUsages(all_key_usages_, usage_mask); 35 blink::WebCryptoKeyUsageMask usage_mask,
36 } 36 GenerateKeyResult* result) const {
37 37 Status status = CheckKeyCreationUsages(all_key_usages_, usage_mask);
38 Status AesAlgorithm::GenerateSecretKey(
39 const blink::WebCryptoAlgorithm& algorithm,
40 bool extractable,
41 blink::WebCryptoKeyUsageMask usage_mask,
42 blink::WebCryptoKey* key) const {
43 unsigned int keylen_bits;
44 Status status =
45 GetAesKeyGenLengthInBits(algorithm.aesKeyGenParams(), &keylen_bits);
46 if (status.IsError()) 38 if (status.IsError())
47 return status; 39 return status;
48 40
41 unsigned int keylen_bits;
42 status = GetAesKeyGenLengthInBits(algorithm.aesKeyGenParams(), &keylen_bits);
43 if (status.IsError())
44 return status;
45
49 return GenerateSecretKeyOpenSsl( 46 return GenerateSecretKeyOpenSsl(
50 blink::WebCryptoKeyAlgorithm::createAes(algorithm.id(), keylen_bits), 47 blink::WebCryptoKeyAlgorithm::createAes(algorithm.id(), keylen_bits),
51 extractable, 48 extractable,
52 usage_mask, 49 usage_mask,
53 keylen_bits / 8, 50 keylen_bits / 8,
54 key); 51 result);
55 } 52 }
56 53
57 Status AesAlgorithm::VerifyKeyUsagesBeforeImportKey( 54 Status AesAlgorithm::VerifyKeyUsagesBeforeImportKey(
58 blink::WebCryptoKeyFormat format, 55 blink::WebCryptoKeyFormat format,
59 blink::WebCryptoKeyUsageMask usage_mask) const { 56 blink::WebCryptoKeyUsageMask usage_mask) const {
60 switch (format) { 57 switch (format) {
61 case blink::WebCryptoKeyFormatRaw: 58 case blink::WebCryptoKeyFormatRaw:
62 case blink::WebCryptoKeyFormatJwk: 59 case blink::WebCryptoKeyFormatJwk:
63 return CheckKeyCreationUsages(all_key_usages_, usage_mask); 60 return CheckKeyCreationUsages(all_key_usages_, usage_mask);
64 default: 61 default:
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 key.extractable(), 115 key.extractable(),
119 key.usages(), 116 key.usages(),
120 buffer); 117 buffer);
121 118
122 return Status::Success(); 119 return Status::Success();
123 } 120 }
124 121
125 } // namespace webcrypto 122 } // namespace webcrypto
126 123
127 } // namespace content 124 } // namespace content
OLDNEW
« no previous file with comments | « content/child/webcrypto/openssl/aes_key_openssl.h ('k') | content/child/webcrypto/openssl/hmac_openssl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698