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

Side by Side Diff: crypto/sha1.dart

Issue 10196011: - Add lib/crypto. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/lib/
Patch Set: Created 8 years, 8 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
« no previous file with comments | « crypto/crypto.dart ('k') | no next file » | 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) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 class SHA1 {
6 static List<int> digest(List<int> input,
7 [int offset = 0,
8 int len = null]) {
9 var input_len = input.length;
10 if ((offset < 0) || (offset > input_len)) {
11 throw new IllegalArgumentException("Invalid offset ($offset).");
12 }
13 if (len == null) {
14 len = input_len - offset;
15 }
16 if ((len < 0) || ((offset + len) > input_len)) {
17 throw new IllegalArgumentException("Invalid length ($len) for "
18 "offset ($offset) and input length (input_len).");
19 }
20
21 // Round up to 512 bit size.
22 var m_len = _roundUp((len * _BITS_PER_BYTE) + 65, _BITS_PER_CHUNK);
23 m_len = m_len ~/ _BITS_PER_WORD;
24 var m = new List<int>(m_len);
25
26 _bytesToWords(input, offset, len, m, 0, m_len);
27
28 var l = len * 8;
29 var w = new List<int>(80);
30 var H0 = 0x67452301;
31 var H1 = 0xEFCDAB89;
32 var H2 = 0x98BADCFE;
33 var H3 = 0x10325476;
34 var H4 = 0xC3D2E1F0;
35
36 // TODO(iposva): Deal with lengths longer than 32-bits once arrays can
Søren Gjesse 2012/04/24 13:14:11 When we change to an interface where you can call
37 // grow to this size.
38 m[l >> 5] |= 0x80 << (24 - l % 32);
39 m[(((l + 64) >> 9) << 4) + 15] = l;
40
41 for (var i = 0; i < m_len; i += 16) {
42 var a = H0;
43 var b = H1;
44 var c = H2;
45 var d = H3;
46 var e = H4;
47
48 for (var j = 0; j < 80; j++) {
49 if (j < 16) {
50 w[j] = m[i + j];
51 } else {
52 var n = w[j - 3] ^ w[j - 8] ^ w[j - 14] ^ w[j - 16];
53 w[j] = _rotl32(n, 1);
54 }
55
56 var t = _rotl32(a, 5) + e + w[j];
57 if (j < 20) {
58 t += (((b & c) | (~b & d)) + 0x5A827999);
59 } else if (j < 40) {
60 t += ((b ^ c ^ d) + 0x6ED9EBA1);
61 } else if (j < 60) {
62 t += (((b & c) | (b & d) | (c & d)) + 0x8F1BBCDC);
63 } else {
64 t += ((b ^ c ^ d) + 0xCA62C1D6);
65 }
66
67 e = d;
68 d = c;
69 c = _rotl32(b, 30);
70 b = a;
71 a = t & _MASK_32;
72 }
73 H0 = _add32(H0, a);
74 H1 = _add32(H1, b);
75 H2 = _add32(H2, c);
76 H3 = _add32(H3, d);
77 H4 = _add32(H4, e);
78 }
79 return _wordsToBytes([H0, H1, H2, H3, H4]);
80 }
81
82 static final int _BITS_PER_CHUNK = 512;
83 }
84
OLDNEW
« no previous file with comments | « crypto/crypto.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698