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

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

Issue 19757011: WebCrypto: Implement digest() using NSS (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix gyp conditions and dependencies. Created 7 years, 4 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/renderer/webcrypto_impl.cc ('k') | content/renderer/webcrypto_impl_openssl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/renderer/webcrypto_impl.h"
6
7 #include <sechash.h>
8
9 #include "base/logging.h"
10 #include "crypto/nss_util.h"
11 #include "third_party/WebKit/public/platform/WebArrayBuffer.h"
12 #include "third_party/WebKit/public/platform/WebCryptoAlgorithm.h"
13
14 namespace content {
15
16 void WebCryptoImpl::digest(
17 const WebKit::WebCryptoAlgorithm& algorithm,
18 const unsigned char* data,
19 size_t data_size,
20 WebKit::WebCryptoResult result) {
21 HASH_HashType hash_type = HASH_AlgNULL;
22
23 switch (algorithm.id()) {
24 case WebKit::WebCryptoAlgorithmIdSha1:
25 hash_type = HASH_AlgSHA1;
26 break;
27 case WebKit::WebCryptoAlgorithmIdSha224:
28 hash_type = HASH_AlgSHA224;
29 break;
30 case WebKit::WebCryptoAlgorithmIdSha256:
31 hash_type = HASH_AlgSHA256;
32 break;
33 case WebKit::WebCryptoAlgorithmIdSha384:
34 hash_type = HASH_AlgSHA384;
35 break;
36 case WebKit::WebCryptoAlgorithmIdSha512:
37 hash_type = HASH_AlgSHA512;
38 break;
39 default:
40 // Not a digest algorithm.
41 result.completeWithError();
42 return;
43 }
44
45 crypto::EnsureNSSInit();
46
47 HASHContext* context = HASH_Create(hash_type);
48 if (!context) {
49 result.completeWithError();
50 return;
51 }
52
53 HASH_Begin(context);
54
55 HASH_Update(context, data, data_size);
56
57 size_t hash_result_length = HASH_ResultLenContext(context);
58 DCHECK(hash_result_length <= HASH_LENGTH_MAX);
59
60 WebKit::WebArrayBuffer buffer(
61 WebKit::WebArrayBuffer::create(hash_result_length, 1));
62
63 unsigned char* digest = reinterpret_cast<unsigned char*>(buffer.data());
64
65 uint32 result_length = 0;
66 HASH_End(context, digest, &result_length, hash_result_length);
67 if (result_length != hash_result_length) {
68 result.completeWithError();
69 return;
70 }
71
eroman 2013/08/22 22:59:01 I believe the HASHContext* is getting leaked (not
Bryan Eyler 2013/08/22 23:07:06 Done.
72 result.completeWithBuffer(buffer);
73 }
74
75 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/webcrypto_impl.cc ('k') | content/renderer/webcrypto_impl_openssl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698