Chromium Code Reviews| Index: content/renderer/webcrypto_impl_openssl.cc |
| diff --git a/content/renderer/webcrypto_impl_openssl.cc b/content/renderer/webcrypto_impl_openssl.cc |
| index 343eb7251076093623182568b6ed3e75e02eddc0..3fa8fd34ec4fd6b23880bfa61eac87f4e47fd873 100644 |
| --- a/content/renderer/webcrypto_impl_openssl.cc |
| +++ b/content/renderer/webcrypto_impl_openssl.cc |
| @@ -4,19 +4,73 @@ |
| #include "content/renderer/webcrypto_impl.h" |
| +#include <openssl/evp.h> |
| + |
| +#include "base/logging.h" |
| +#include "crypto/openssl_util.h" |
| +#include "third_party/WebKit/public/platform/WebArrayBuffer.h" |
| +#include "third_party/WebKit/public/platform/WebCryptoAlgorithm.h" |
| + |
| namespace content { |
| -void WebCryptoImpl::Init() { |
| -} |
| +void WebCryptoImpl::Init() { crypto::EnsureOpenSSLInit(); } |
| + |
| +bool WebCryptoImpl::DigestInternal(const WebKit::WebCryptoAlgorithm& algorithm, |
| + const unsigned char* data, |
| + unsigned data_size, |
| + WebKit::WebArrayBuffer* buffer) { |
| + |
| + crypto::OpenSSLErrStackTracer(FROM_HERE); |
| + |
| + const EVP_MD* digest_algorithm; |
| + switch (algorithm.id()) { |
| + case WebKit::WebCryptoAlgorithmIdSha1: |
| + digest_algorithm = EVP_sha1(); |
| + break; |
| + case WebKit::WebCryptoAlgorithmIdSha224: |
| + digest_algorithm = EVP_sha224(); |
| + break; |
| + case WebKit::WebCryptoAlgorithmIdSha256: |
| + digest_algorithm = EVP_sha256(); |
| + break; |
| + case WebKit::WebCryptoAlgorithmIdSha384: |
| + digest_algorithm = EVP_sha384(); |
| + break; |
| + case WebKit::WebCryptoAlgorithmIdSha512: |
| + digest_algorithm = EVP_sha512(); |
| + break; |
| + default: |
| + // Not a digest algorithm. |
| + return false; |
| + } |
| + |
| + crypto::ScopedOpenSSL<EVP_MD_CTX, EVP_MD_CTX_destroy> digest_context( |
| + EVP_MD_CTX_create()); |
| + if (!digest_context.get()) return false; |
|
Bryan Eyler
2013/09/23 21:45:51
For consistency (with EVP_Digest* ops and hash_exp
padolph
2013/09/23 22:08:31
Done.
|
| + |
| + if (!EVP_DigestInit_ex(digest_context.get(), digest_algorithm, NULL) || |
| + !EVP_DigestUpdate(digest_context.get(), data, data_size)) { |
| + return false; |
| + } |
| + |
| + const int hash_expected_size = EVP_MD_CTX_size(digest_context.get()); |
| + if (hash_expected_size <= 0) { |
| + return false; |
| + } |
| + DCHECK_LE(hash_expected_size, EVP_MAX_MD_SIZE); |
| + |
| + *buffer = WebKit::WebArrayBuffer::create(hash_expected_size, 1); |
| + unsigned char* const hash_buffer = |
| + reinterpret_cast<unsigned char* const>(buffer->data()); |
| + |
| + unsigned int hash_size = 0; |
|
Bryan Eyler
2013/09/23 21:45:51
I believe Chromium style is to just use "unsigned"
padolph
2013/09/23 22:08:31
Done.
|
| + if (!EVP_DigestFinal_ex(digest_context.get(), hash_buffer, &hash_size) || |
| + static_cast<int>(hash_size) != hash_expected_size) { |
| + buffer->reset(); |
| + return false; |
| + } |
| -bool WebCryptoImpl::DigestInternal( |
| - const WebKit::WebCryptoAlgorithm& algorithm, |
| - const unsigned char* data, |
| - unsigned data_size, |
| - WebKit::WebArrayBuffer* buffer) { |
| - // TODO(bryaneyler): Placeholder for OpenSSL implementation. |
| - // Issue http://crbug.com/267888. |
| - return false; |
| + return true; |
| } |
| } // namespace content |