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

Side by Side Diff: base/sha1_portable.cc

Issue 6661025: Add base::SHA1HashBytes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Actually, base/sha1_win.cc is not used, so don't touch it Created 9 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/sha1.h" 5 #include "base/sha1.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include <cstring>
wtc 2011/03/11 18:46:15 1. Nit: I recommend including the C header <string
hans 2011/03/13 19:48:16 done
8 9
9 namespace base { 10 namespace base {
10 11
11 // Implementation of SHA-1. Only handles data in byte-sized blocks, 12 // Implementation of SHA-1. Only handles data in byte-sized blocks,
12 // which simplifies the code a fair bit. 13 // which simplifies the code a fair bit.
13 14
14 // Identifier names follow notation in FIPS PUB 180-3, where you'll 15 // Identifier names follow notation in FIPS PUB 180-3, where you'll
15 // also find a description of the algorithm: 16 // also find a description of the algorithm:
16 // http://csrc.nist.gov/publications/fips/fips180-3/fips180-3_final.pdf 17 // http://csrc.nist.gov/publications/fips/fips180-3/fips180-3_final.pdf
17 18
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 // e. 188 // e.
188 H[0] += A; 189 H[0] += A;
189 H[1] += B; 190 H[1] += B;
190 H[2] += C; 191 H[2] += C;
191 H[3] += D; 192 H[3] += D;
192 H[4] += E; 193 H[4] += E;
193 194
194 cursor = 0; 195 cursor = 0;
195 } 196 }
196 197
197 std::string SHA1HashString(const std::string& str) { 198 std::string SHA1HashString(const std::string& str) {
wtc 2011/03/11 18:46:15 Nit: ideally this function should be reimplemented
hans 2011/03/13 19:48:16 Done.
198 SecureHashAlgorithm sha; 199 SecureHashAlgorithm sha;
199 sha.Update(str.c_str(), str.length()); 200 sha.Update(str.c_str(), str.length());
200 sha.Final(); 201 sha.Final();
201 std::string out(reinterpret_cast<const char*>(sha.Digest()), 202 std::string out(reinterpret_cast<const char*>(sha.Digest()),
202 SecureHashAlgorithm::kDigestSizeBytes); 203 SecureHashAlgorithm::kDigestSizeBytes);
203 return out; 204 return out;
204 } 205 }
205 206
207 void SHA1HashBytes(const unsigned char* data, size_t len,
208 unsigned char* hash_array) {
209 SecureHashAlgorithm sha;
210 sha.Update(data, len);
211 sha.Final();
212
213 std::memcpy(hash_array, sha.Digest(), SecureHashAlgorithm::kDigestSizeBytes);
214 }
215
206 } // namespace base 216 } // namespace base
OLDNEW
« base/sha1.h ('K') | « base/sha1.h ('k') | base/sha1_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698