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 <cryptohi.h> | 5 #include <cryptohi.h> |
6 #include <keyhi.h> | 6 #include <keyhi.h> |
7 #include <pk11pub.h> | 7 #include <pk11pub.h> |
8 #include <secerr.h> | 8 #include <secerr.h> |
9 #include <sechash.h> | 9 #include <sechash.h> |
10 | 10 |
| 11 #include "base/stl_util.h" |
11 #include "content/child/webcrypto/crypto_data.h" | 12 #include "content/child/webcrypto/crypto_data.h" |
12 #include "content/child/webcrypto/nss/key_nss.h" | 13 #include "content/child/webcrypto/nss/key_nss.h" |
13 #include "content/child/webcrypto/nss/rsa_key_nss.h" | 14 #include "content/child/webcrypto/nss/rsa_key_nss.h" |
14 #include "content/child/webcrypto/nss/util_nss.h" | 15 #include "content/child/webcrypto/nss/util_nss.h" |
15 #include "content/child/webcrypto/status.h" | 16 #include "content/child/webcrypto/status.h" |
16 #include "content/child/webcrypto/webcrypto_util.h" | 17 #include "content/child/webcrypto/webcrypto_util.h" |
17 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h" | 18 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h" |
18 #include "third_party/WebKit/public/platform/WebCryptoKeyAlgorithm.h" | 19 #include "third_party/WebKit/public/platform/WebCryptoKeyAlgorithm.h" |
19 | 20 |
20 namespace content { | 21 namespace content { |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 CK_RSA_PKCS_OAEP_PARAMS oaep_params = {0}; | 90 CK_RSA_PKCS_OAEP_PARAMS oaep_params = {0}; |
90 if (!InitializeRsaOaepParams(hash, label, &oaep_params)) | 91 if (!InitializeRsaOaepParams(hash, label, &oaep_params)) |
91 return Status::ErrorUnsupported(); | 92 return Status::ErrorUnsupported(); |
92 | 93 |
93 SECItem param; | 94 SECItem param; |
94 param.type = siBuffer; | 95 param.type = siBuffer; |
95 param.data = reinterpret_cast<unsigned char*>(&oaep_params); | 96 param.data = reinterpret_cast<unsigned char*>(&oaep_params); |
96 param.len = sizeof(oaep_params); | 97 param.len = sizeof(oaep_params); |
97 | 98 |
98 buffer->resize(SECKEY_PublicKeyStrength(key)); | 99 buffer->resize(SECKEY_PublicKeyStrength(key)); |
99 unsigned char* buffer_data = Uint8VectorStart(buffer); | 100 unsigned char* buffer_data = vector_as_array(buffer); |
100 unsigned int output_len; | 101 unsigned int output_len; |
101 if (NssRuntimeSupport::Get()->pk11_pub_encrypt_func()(key, | 102 if (NssRuntimeSupport::Get()->pk11_pub_encrypt_func()(key, |
102 CKM_RSA_PKCS_OAEP, | 103 CKM_RSA_PKCS_OAEP, |
103 ¶m, | 104 ¶m, |
104 buffer_data, | 105 buffer_data, |
105 &output_len, | 106 &output_len, |
106 buffer->size(), | 107 buffer->size(), |
107 data.bytes(), | 108 data.bytes(), |
108 data.byte_length(), | 109 data.byte_length(), |
109 NULL) != SECSuccess) { | 110 NULL) != SECSuccess) { |
(...skipping 22 matching lines...) Expand all Loading... |
132 param.type = siBuffer; | 133 param.type = siBuffer; |
133 param.data = reinterpret_cast<unsigned char*>(&oaep_params); | 134 param.data = reinterpret_cast<unsigned char*>(&oaep_params); |
134 param.len = sizeof(oaep_params); | 135 param.len = sizeof(oaep_params); |
135 | 136 |
136 const int modulus_length_bytes = PK11_GetPrivateModulusLen(key); | 137 const int modulus_length_bytes = PK11_GetPrivateModulusLen(key); |
137 if (modulus_length_bytes <= 0) | 138 if (modulus_length_bytes <= 0) |
138 return Status::ErrorUnexpected(); | 139 return Status::ErrorUnexpected(); |
139 | 140 |
140 buffer->resize(modulus_length_bytes); | 141 buffer->resize(modulus_length_bytes); |
141 | 142 |
142 unsigned char* buffer_data = Uint8VectorStart(buffer); | 143 unsigned char* buffer_data = vector_as_array(buffer); |
143 unsigned int output_len; | 144 unsigned int output_len; |
144 if (NssRuntimeSupport::Get()->pk11_priv_decrypt_func()(key, | 145 if (NssRuntimeSupport::Get()->pk11_priv_decrypt_func()(key, |
145 CKM_RSA_PKCS_OAEP, | 146 CKM_RSA_PKCS_OAEP, |
146 ¶m, | 147 ¶m, |
147 buffer_data, | 148 buffer_data, |
148 &output_len, | 149 &output_len, |
149 buffer->size(), | 150 buffer->size(), |
150 data.bytes(), | 151 data.bytes(), |
151 data.byte_length()) != | 152 data.byte_length()) != |
152 SECSuccess) { | 153 SECSuccess) { |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 | 238 |
238 } // namespace | 239 } // namespace |
239 | 240 |
240 AlgorithmImplementation* CreatePlatformRsaOaepImplementation() { | 241 AlgorithmImplementation* CreatePlatformRsaOaepImplementation() { |
241 return new RsaOaepImplementation; | 242 return new RsaOaepImplementation; |
242 } | 243 } |
243 | 244 |
244 } // namespace webcrypto | 245 } // namespace webcrypto |
245 | 246 |
246 } // namespace content | 247 } // namespace content |
OLD | NEW |