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

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: Split out crypto functionality from abstract result class from Blink. 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 bool WebCryptoImpl::digestInternal(
17 const WebKit::WebCryptoAlgorithm& algorithm,
18 const unsigned char* data,
19 size_t data_size,
20 WebKit::WebArrayBuffer* buffer) {
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 return false;
42 }
43
44 crypto::EnsureNSSInit();
45
46 HASHContext* context = HASH_Create(hash_type);
47 if (!context) {
48 return false;
49 }
50
51 HASH_Begin(context);
52
53 HASH_Update(context, data, data_size);
54
55 size_t hash_result_length = HASH_ResultLenContext(context);
56 DCHECK_LE(hash_result_length, static_cast<size_t>(HASH_LENGTH_MAX));
57
58 *buffer = WebKit::WebArrayBuffer::create(hash_result_length, 1);
59
60 unsigned char* digest = reinterpret_cast<unsigned char*>(buffer->data());
61
62 uint32 result_length = 0;
63 HASH_End(context, digest, &result_length, hash_result_length);
64
65 HASH_Destroy(context);
66
67 return result_length == hash_result_length;
68 }
69
70 } // 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