OLD | NEW |
---|---|
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> | |
Bryan Eyler
2013/09/18 21:36:21
Following style of _nss.cc, leave a space between
Ryan Sleevi
2013/09/18 22:05:36
http://www.chromium.org/developers/coding-style#TO
padolph
2013/09/18 22:50:07
Done.
| |
8 #include "base/logging.h" | |
9 #include "crypto/openssl_util.h" | |
10 #include "third_party/WebKit/public/platform/WebArrayBuffer.h" | |
11 #include "third_party/WebKit/public/platform/WebCryptoAlgorithm.h" | |
12 | |
7 namespace content { | 13 namespace content { |
8 | 14 |
9 void WebCryptoImpl::Init() { | 15 void WebCryptoImpl::Init() { |
16 crypto::EnsureOpenSSLInit(); | |
10 } | 17 } |
11 | 18 |
12 bool WebCryptoImpl::DigestInternal( | 19 bool WebCryptoImpl::DigestInternal( |
13 const WebKit::WebCryptoAlgorithm& algorithm, | 20 const WebKit::WebCryptoAlgorithm& algorithm, |
14 const unsigned char* data, | 21 const unsigned char* data, |
15 unsigned data_size, | 22 unsigned data_size, |
16 WebKit::WebArrayBuffer* buffer) { | 23 WebKit::WebArrayBuffer* buffer) { |
17 // TODO(bryaneyler): Placeholder for OpenSSL implementation. | 24 |
18 // Issue http://crbug.com/267888. | 25 crypto::OpenSSLErrStackTracer(FROM_HERE); |
Bryan Eyler
2013/09/18 21:36:21
Two-space indentation throughout this function - h
padolph
2013/09/18 22:50:07
Done.
| |
19 return false; | 26 |
27 const EVP_MD * digAlg; | |
Ryan Sleevi
2013/09/18 22:05:36
STYLE: "const EVP_MD *" -> "const EVP_MD* " (see h
padolph
2013/09/18 22:50:07
Done.
| |
28 switch (algorithm.id()) { | |
29 case WebKit::WebCryptoAlgorithmIdSha1: | |
30 digAlg = EVP_sha1(); | |
31 break; | |
32 case WebKit::WebCryptoAlgorithmIdSha224: | |
33 digAlg = EVP_sha224(); | |
34 break; | |
35 case WebKit::WebCryptoAlgorithmIdSha256: | |
36 digAlg = EVP_sha256(); | |
37 break; | |
38 case WebKit::WebCryptoAlgorithmIdSha384: | |
39 digAlg = EVP_sha384(); | |
40 break; | |
41 case WebKit::WebCryptoAlgorithmIdSha512: | |
42 digAlg = EVP_sha512(); | |
43 break; | |
44 default: | |
45 // Not a digest algorithm. | |
46 return false; | |
47 } | |
48 | |
49 crypto::ScopedOpenSSL<EVP_MD_CTX, EVP_MD_CTX_destroy> | |
50 digCtx(EVP_MD_CTX_create()); | |
Bryan Eyler
2013/09/18 21:36:21
Naming: Don't abbreviate and use underscores to se
padolph
2013/09/18 22:50:07
Done.
| |
51 if (!digCtx.get()) | |
52 return false; | |
53 | |
54 if (!EVP_DigestInit_ex(digCtx.get(), digAlg, NULL)) | |
55 return false; | |
56 | |
57 if (!EVP_DigestUpdate(digCtx.get(), data, data_size)) | |
Ryan Sleevi
2013/09/18 22:05:36
STYLE NIT (eg: not critical, but perhaps more cons
padolph
2013/09/18 22:50:07
Done.
| |
58 return false; | |
59 | |
60 const size_t hashResultSize = EVP_MD_CTX_size(digCtx.get()); | |
Ryan Sleevi
2013/09/18 22:05:36
CORRECTNESS: EVP_MD_CTX_size returns an int, not a
padolph
2013/09/18 22:50:07
Done.
| |
61 DCHECK_LE(hashResultSize, static_cast<size_t>(EVP_MAX_MD_SIZE)); | |
62 | |
63 *buffer = WebKit::WebArrayBuffer::create(hashResultSize, 1); | |
64 unsigned char* const hashBuf = | |
Ryan Sleevi
2013/09/18 22:05:36
STYLE: hashBuf -> hash_buffer / result_buffer
padolph
2013/09/18 22:50:07
Done.
| |
65 reinterpret_cast<unsigned char* const>(buffer->data()); | |
66 | |
67 unsigned int hashSize = 0; | |
Ryan Sleevi
2013/09/18 22:05:36
STYLE: hashSize -> hash_size
padolph
2013/09/18 22:50:07
Done.
| |
68 if (!(EVP_DigestFinal_ex(digCtx.get(), hashBuf, &hashSize))) | |
Ryan Sleevi
2013/09/18 22:05:36
STYLE: unnecessary added ()
STYLE NIT (eg: not cri
padolph
2013/09/18 22:50:07
Done.
Also, I realized I should release buffer (b
| |
69 return false; | |
70 | |
71 return hashResultSize == hashSize; | |
20 } | 72 } |
21 | 73 |
22 } // namespace content | 74 } // namespace content |
OLD | NEW |