| 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 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 return false; | 78 return false; |
| 79 } | 79 } |
| 80 | 80 |
| 81 return true; | 81 return true; |
| 82 } | 82 } |
| 83 | 83 |
| 84 Status EncryptRsaOaep(SECKEYPublicKey* key, | 84 Status EncryptRsaOaep(SECKEYPublicKey* key, |
| 85 const blink::WebCryptoAlgorithm& hash, | 85 const blink::WebCryptoAlgorithm& hash, |
| 86 const CryptoData& label, | 86 const CryptoData& label, |
| 87 const CryptoData& data, | 87 const CryptoData& data, |
| 88 std::vector<uint8>* buffer) { | 88 std::vector<uint8_t>* buffer) { |
| 89 CK_RSA_PKCS_OAEP_PARAMS oaep_params = {0}; | 89 CK_RSA_PKCS_OAEP_PARAMS oaep_params = {0}; |
| 90 if (!InitializeRsaOaepParams(hash, label, &oaep_params)) | 90 if (!InitializeRsaOaepParams(hash, label, &oaep_params)) |
| 91 return Status::ErrorUnsupported(); | 91 return Status::ErrorUnsupported(); |
| 92 | 92 |
| 93 SECItem param; | 93 SECItem param; |
| 94 param.type = siBuffer; | 94 param.type = siBuffer; |
| 95 param.data = reinterpret_cast<unsigned char*>(&oaep_params); | 95 param.data = reinterpret_cast<unsigned char*>(&oaep_params); |
| 96 param.len = sizeof(oaep_params); | 96 param.len = sizeof(oaep_params); |
| 97 | 97 |
| 98 buffer->resize(SECKEY_PublicKeyStrength(key)); | 98 buffer->resize(SECKEY_PublicKeyStrength(key)); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 112 | 112 |
| 113 CHECK_LE(output_len, buffer->size()); | 113 CHECK_LE(output_len, buffer->size()); |
| 114 buffer->resize(output_len); | 114 buffer->resize(output_len); |
| 115 return Status::Success(); | 115 return Status::Success(); |
| 116 } | 116 } |
| 117 | 117 |
| 118 Status DecryptRsaOaep(SECKEYPrivateKey* key, | 118 Status DecryptRsaOaep(SECKEYPrivateKey* key, |
| 119 const blink::WebCryptoAlgorithm& hash, | 119 const blink::WebCryptoAlgorithm& hash, |
| 120 const CryptoData& label, | 120 const CryptoData& label, |
| 121 const CryptoData& data, | 121 const CryptoData& data, |
| 122 std::vector<uint8>* buffer) { | 122 std::vector<uint8_t>* buffer) { |
| 123 Status status = NssSupportsRsaOaep(); | 123 Status status = NssSupportsRsaOaep(); |
| 124 if (status.IsError()) | 124 if (status.IsError()) |
| 125 return status; | 125 return status; |
| 126 | 126 |
| 127 CK_RSA_PKCS_OAEP_PARAMS oaep_params = {0}; | 127 CK_RSA_PKCS_OAEP_PARAMS oaep_params = {0}; |
| 128 if (!InitializeRsaOaepParams(hash, label, &oaep_params)) | 128 if (!InitializeRsaOaepParams(hash, label, &oaep_params)) |
| 129 return Status::ErrorUnsupported(); | 129 return Status::ErrorUnsupported(); |
| 130 | 130 |
| 131 SECItem param; | 131 SECItem param; |
| 132 param.type = siBuffer; | 132 param.type = siBuffer; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 case blink::WebCryptoAlgorithmIdSha512: | 200 case blink::WebCryptoAlgorithmIdSha512: |
| 201 return "RSA-OAEP-512"; | 201 return "RSA-OAEP-512"; |
| 202 default: | 202 default: |
| 203 return NULL; | 203 return NULL; |
| 204 } | 204 } |
| 205 } | 205 } |
| 206 | 206 |
| 207 virtual Status Encrypt(const blink::WebCryptoAlgorithm& algorithm, | 207 virtual Status Encrypt(const blink::WebCryptoAlgorithm& algorithm, |
| 208 const blink::WebCryptoKey& key, | 208 const blink::WebCryptoKey& key, |
| 209 const CryptoData& data, | 209 const CryptoData& data, |
| 210 std::vector<uint8>* buffer) const OVERRIDE { | 210 std::vector<uint8_t>* buffer) const OVERRIDE { |
| 211 if (key.type() != blink::WebCryptoKeyTypePublic) | 211 if (key.type() != blink::WebCryptoKeyTypePublic) |
| 212 return Status::ErrorUnexpectedKeyType(); | 212 return Status::ErrorUnexpectedKeyType(); |
| 213 | 213 |
| 214 return EncryptRsaOaep( | 214 return EncryptRsaOaep( |
| 215 PublicKeyNss::Cast(key)->key(), | 215 PublicKeyNss::Cast(key)->key(), |
| 216 key.algorithm().rsaHashedParams()->hash(), | 216 key.algorithm().rsaHashedParams()->hash(), |
| 217 CryptoData(algorithm.rsaOaepParams()->optionalLabel()), | 217 CryptoData(algorithm.rsaOaepParams()->optionalLabel()), |
| 218 data, | 218 data, |
| 219 buffer); | 219 buffer); |
| 220 } | 220 } |
| 221 | 221 |
| 222 virtual Status Decrypt(const blink::WebCryptoAlgorithm& algorithm, | 222 virtual Status Decrypt(const blink::WebCryptoAlgorithm& algorithm, |
| 223 const blink::WebCryptoKey& key, | 223 const blink::WebCryptoKey& key, |
| 224 const CryptoData& data, | 224 const CryptoData& data, |
| 225 std::vector<uint8>* buffer) const OVERRIDE { | 225 std::vector<uint8_t>* buffer) const OVERRIDE { |
| 226 if (key.type() != blink::WebCryptoKeyTypePrivate) | 226 if (key.type() != blink::WebCryptoKeyTypePrivate) |
| 227 return Status::ErrorUnexpectedKeyType(); | 227 return Status::ErrorUnexpectedKeyType(); |
| 228 | 228 |
| 229 return DecryptRsaOaep( | 229 return DecryptRsaOaep( |
| 230 PrivateKeyNss::Cast(key)->key(), | 230 PrivateKeyNss::Cast(key)->key(), |
| 231 key.algorithm().rsaHashedParams()->hash(), | 231 key.algorithm().rsaHashedParams()->hash(), |
| 232 CryptoData(algorithm.rsaOaepParams()->optionalLabel()), | 232 CryptoData(algorithm.rsaOaepParams()->optionalLabel()), |
| 233 data, | 233 data, |
| 234 buffer); | 234 buffer); |
| 235 } | 235 } |
| 236 }; | 236 }; |
| 237 | 237 |
| 238 } // namespace | 238 } // namespace |
| 239 | 239 |
| 240 AlgorithmImplementation* CreatePlatformRsaOaepImplementation() { | 240 AlgorithmImplementation* CreatePlatformRsaOaepImplementation() { |
| 241 return new RsaOaepImplementation; | 241 return new RsaOaepImplementation; |
| 242 } | 242 } |
| 243 | 243 |
| 244 } // namespace webcrypto | 244 } // namespace webcrypto |
| 245 | 245 |
| 246 } // namespace content | 246 } // namespace content |
| OLD | NEW |