| 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 <openssl/evp.h> | 5 #include <openssl/evp.h> |
| 6 | 6 |
| 7 #include "base/stl_util.h" | 7 #include "base/stl_util.h" |
| 8 #include "content/child/webcrypto/crypto_data.h" | 8 #include "content/child/webcrypto/crypto_data.h" |
| 9 #include "content/child/webcrypto/openssl/key_openssl.h" | 9 #include "content/child/webcrypto/openssl/key_openssl.h" |
| 10 #include "content/child/webcrypto/openssl/rsa_key_openssl.h" | 10 #include "content/child/webcrypto/openssl/rsa_key_openssl.h" |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 } | 96 } |
| 97 | 97 |
| 98 class RsaOaepImplementation : public RsaHashedAlgorithm { | 98 class RsaOaepImplementation : public RsaHashedAlgorithm { |
| 99 public: | 99 public: |
| 100 RsaOaepImplementation() | 100 RsaOaepImplementation() |
| 101 : RsaHashedAlgorithm( | 101 : RsaHashedAlgorithm( |
| 102 blink::WebCryptoKeyUsageEncrypt | blink::WebCryptoKeyUsageWrapKey, | 102 blink::WebCryptoKeyUsageEncrypt | blink::WebCryptoKeyUsageWrapKey, |
| 103 blink::WebCryptoKeyUsageDecrypt | | 103 blink::WebCryptoKeyUsageDecrypt | |
| 104 blink::WebCryptoKeyUsageUnwrapKey) {} | 104 blink::WebCryptoKeyUsageUnwrapKey) {} |
| 105 | 105 |
| 106 virtual const char* GetJwkAlgorithm( | 106 const char* GetJwkAlgorithm( |
| 107 const blink::WebCryptoAlgorithmId hash) const override { | 107 const blink::WebCryptoAlgorithmId hash) const override { |
| 108 switch (hash) { | 108 switch (hash) { |
| 109 case blink::WebCryptoAlgorithmIdSha1: | 109 case blink::WebCryptoAlgorithmIdSha1: |
| 110 return "RSA-OAEP"; | 110 return "RSA-OAEP"; |
| 111 case blink::WebCryptoAlgorithmIdSha256: | 111 case blink::WebCryptoAlgorithmIdSha256: |
| 112 return "RSA-OAEP-256"; | 112 return "RSA-OAEP-256"; |
| 113 case blink::WebCryptoAlgorithmIdSha384: | 113 case blink::WebCryptoAlgorithmIdSha384: |
| 114 return "RSA-OAEP-384"; | 114 return "RSA-OAEP-384"; |
| 115 case blink::WebCryptoAlgorithmIdSha512: | 115 case blink::WebCryptoAlgorithmIdSha512: |
| 116 return "RSA-OAEP-512"; | 116 return "RSA-OAEP-512"; |
| 117 default: | 117 default: |
| 118 return NULL; | 118 return NULL; |
| 119 } | 119 } |
| 120 } | 120 } |
| 121 | 121 |
| 122 virtual Status Encrypt(const blink::WebCryptoAlgorithm& algorithm, | 122 Status Encrypt(const blink::WebCryptoAlgorithm& algorithm, |
| 123 const blink::WebCryptoKey& key, | 123 const blink::WebCryptoKey& key, |
| 124 const CryptoData& data, | 124 const CryptoData& data, |
| 125 std::vector<uint8_t>* buffer) const override { | 125 std::vector<uint8_t>* buffer) const override { |
| 126 if (key.type() != blink::WebCryptoKeyTypePublic) | 126 if (key.type() != blink::WebCryptoKeyTypePublic) |
| 127 return Status::ErrorUnexpectedKeyType(); | 127 return Status::ErrorUnexpectedKeyType(); |
| 128 | 128 |
| 129 return CommonEncryptDecrypt( | 129 return CommonEncryptDecrypt( |
| 130 EVP_PKEY_encrypt_init, EVP_PKEY_encrypt, algorithm, key, data, buffer); | 130 EVP_PKEY_encrypt_init, EVP_PKEY_encrypt, algorithm, key, data, buffer); |
| 131 } | 131 } |
| 132 | 132 |
| 133 virtual Status Decrypt(const blink::WebCryptoAlgorithm& algorithm, | 133 Status Decrypt(const blink::WebCryptoAlgorithm& algorithm, |
| 134 const blink::WebCryptoKey& key, | 134 const blink::WebCryptoKey& key, |
| 135 const CryptoData& data, | 135 const CryptoData& data, |
| 136 std::vector<uint8_t>* buffer) const override { | 136 std::vector<uint8_t>* buffer) const override { |
| 137 if (key.type() != blink::WebCryptoKeyTypePrivate) | 137 if (key.type() != blink::WebCryptoKeyTypePrivate) |
| 138 return Status::ErrorUnexpectedKeyType(); | 138 return Status::ErrorUnexpectedKeyType(); |
| 139 | 139 |
| 140 return CommonEncryptDecrypt( | 140 return CommonEncryptDecrypt( |
| 141 EVP_PKEY_decrypt_init, EVP_PKEY_decrypt, algorithm, key, data, buffer); | 141 EVP_PKEY_decrypt_init, EVP_PKEY_decrypt, algorithm, key, data, buffer); |
| 142 } | 142 } |
| 143 }; | 143 }; |
| 144 | 144 |
| 145 } // namespace | 145 } // namespace |
| 146 | 146 |
| 147 AlgorithmImplementation* CreatePlatformRsaOaepImplementation() { | 147 AlgorithmImplementation* CreatePlatformRsaOaepImplementation() { |
| 148 return new RsaOaepImplementation; | 148 return new RsaOaepImplementation; |
| 149 } | 149 } |
| 150 | 150 |
| 151 } // namespace webcrypto | 151 } // namespace webcrypto |
| 152 | 152 |
| 153 } // namespace content | 153 } // namespace content |
| OLD | NEW |