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

Side by Side Diff: content/renderer/webcrypto_impl_openssl.cc

Issue 23621050: Added WebCypto digest OpenSSL implementation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: for openssl, #ifdef disable all tests except digest Created 7 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
« no previous file with comments | « content/content_tests.gypi ('k') | content/renderer/webcrypto_impl_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/renderer/webcrypto_impl.h" 5 #include "content/renderer/webcrypto_impl.h"
6 6
7 #include <openssl/evp.h>
8
9 #include "base/logging.h"
10 #include "crypto/openssl_util.h"
11 #include "third_party/WebKit/public/platform/WebArrayBuffer.h"
12 #include "third_party/WebKit/public/platform/WebCryptoAlgorithm.h"
13
7 namespace content { 14 namespace content {
8 15
9 void WebCryptoImpl::Init() { 16 void WebCryptoImpl::Init() { crypto::EnsureOpenSSLInit(); }
10 }
11 17
12 bool WebCryptoImpl::DigestInternal( 18 bool WebCryptoImpl::DigestInternal(const WebKit::WebCryptoAlgorithm& algorithm,
13 const WebKit::WebCryptoAlgorithm& algorithm, 19 const unsigned char* data,
14 const unsigned char* data, 20 unsigned data_size,
15 unsigned data_size, 21 WebKit::WebArrayBuffer* buffer) {
16 WebKit::WebArrayBuffer* buffer) { 22
17 // TODO(bryaneyler): Placeholder for OpenSSL implementation. 23 crypto::OpenSSLErrStackTracer(FROM_HERE);
18 // Issue http://crbug.com/267888. 24
19 return false; 25 const EVP_MD* digest_algorithm;
26 switch (algorithm.id()) {
27 case WebKit::WebCryptoAlgorithmIdSha1:
28 digest_algorithm = EVP_sha1();
29 break;
30 case WebKit::WebCryptoAlgorithmIdSha224:
31 digest_algorithm = EVP_sha224();
32 break;
33 case WebKit::WebCryptoAlgorithmIdSha256:
34 digest_algorithm = EVP_sha256();
35 break;
36 case WebKit::WebCryptoAlgorithmIdSha384:
37 digest_algorithm = EVP_sha384();
38 break;
39 case WebKit::WebCryptoAlgorithmIdSha512:
40 digest_algorithm = EVP_sha512();
41 break;
42 default:
43 // Not a digest algorithm.
44 return false;
45 }
46
47 crypto::ScopedOpenSSL<EVP_MD_CTX, EVP_MD_CTX_destroy> digest_context(
48 EVP_MD_CTX_create());
49 if (!digest_context.get()) {
50 return false;
51 }
52
53 if (!EVP_DigestInit_ex(digest_context.get(), digest_algorithm, NULL) ||
54 !EVP_DigestUpdate(digest_context.get(), data, data_size)) {
55 return false;
56 }
57
58 const int hash_expected_size = EVP_MD_CTX_size(digest_context.get());
59 if (hash_expected_size <= 0) {
Bryan Eyler 2013/09/25 22:33:05 Would this be better as a DCHECK, since this shoul
padolph 2013/09/25 22:48:39 Probably, but I'm not sure we can define exact pro
60 return false;
61 }
62 DCHECK_LE(hash_expected_size, EVP_MAX_MD_SIZE);
63
64 *buffer = WebKit::WebArrayBuffer::create(hash_expected_size, 1);
65 unsigned char* const hash_buffer =
66 reinterpret_cast<unsigned char* const>(buffer->data());
67
68 unsigned hash_size = 0;
69 if (!EVP_DigestFinal_ex(digest_context.get(), hash_buffer, &hash_size) ||
70 static_cast<int>(hash_size) != hash_expected_size) {
71 buffer->reset();
72 return false;
73 }
74
75 return true;
20 } 76 }
21 77
22 bool WebCryptoImpl::ImportKeyInternal( 78 bool WebCryptoImpl::ImportKeyInternal(
23 WebKit::WebCryptoKeyFormat format, 79 WebKit::WebCryptoKeyFormat format,
24 const unsigned char* key_data, 80 const unsigned char* key_data,
25 unsigned key_data_size, 81 unsigned key_data_size,
26 const WebKit::WebCryptoAlgorithm& algorithm, 82 const WebKit::WebCryptoAlgorithm& algorithm,
27 WebKit::WebCryptoKeyUsageMask usage_mask, 83 WebKit::WebCryptoKeyUsageMask usage_mask,
28 scoped_ptr<WebKit::WebCryptoKeyHandle>* handle, 84 scoped_ptr<WebKit::WebCryptoKeyHandle>* handle,
29 WebKit::WebCryptoKeyType* type) { 85 WebKit::WebCryptoKeyType* type) {
30 // TODO(bryaneyler): Placeholder for OpenSSL implementation. 86 // TODO(bryaneyler): Placeholder for OpenSSL implementation.
31 // Issue http://crbug.com/267888. 87 // Issue http://crbug.com/267888.
32 return false; 88 return false;
33 } 89 }
34 90
35 bool WebCryptoImpl::SignInternal( 91 bool WebCryptoImpl::SignInternal(
36 const WebKit::WebCryptoAlgorithm& algorithm, 92 const WebKit::WebCryptoAlgorithm& algorithm,
37 const WebKit::WebCryptoKey& key, 93 const WebKit::WebCryptoKey& key,
38 const unsigned char* data, 94 const unsigned char* data,
39 unsigned data_size, 95 unsigned data_size,
40 WebKit::WebArrayBuffer* buffer) { 96 WebKit::WebArrayBuffer* buffer) {
41 // TODO(bryaneyler): Placeholder for OpenSSL implementation. 97 // TODO(bryaneyler): Placeholder for OpenSSL implementation.
42 // Issue http://crbug.com/267888. 98 // Issue http://crbug.com/267888.
43 return false; 99 return false;
44 } 100 }
45 101
46 } // namespace content 102 } // namespace content
OLDNEW
« no previous file with comments | « content/content_tests.gypi ('k') | content/renderer/webcrypto_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698