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

Side by Side Diff: crypto/crypto.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 | « no previous file | crypto/sha1.dart » ('j') | crypto/sha1.dart » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #library("crypto");
Mads Ager (google) 2012/04/24 09:57:46 Copyright.
Ivan Posva 2012/04/24 13:02:36 Done.
2
3 #source("sha1.dart");
4
5 // Helpers used implementing the different crypto algorithms.
Ivan Posva 2012/04/24 09:23:53 We might want to move these helpers into their own
Mads Ager (google) 2012/04/24 09:57:46 Yes, I can do that in the next round.
6
7 final int _BITS_PER_BYTE = 8;
8 final int _BYTES_PER_WORD = 4;
9 final int _BITS_PER_WORD = _BITS_PER_BYTE * _BYTES_PER_WORD;
10 final int _MASK_32 = 0xffffffff;
11
12 int _roundUp(int val, int n) {
13 return (val + n - 1) & -n;
14 }
15
16 // Rotate left limiting to unsigned 32-bit values.
17 int _rotl32(int val, int shift) {
18 var mod_shift = shift & 31;
19 return ((val << mod_shift) & _MASK_32) | ((val & _MASK_32) >> (32 - mod_shift) );
Mads Ager (google) 2012/04/24 09:57:46 Long line.
Ivan Posva 2012/04/24 13:02:36 Done.
20 }
21
22 // Add limiting to unsigned 32-bit values.
23 int _add32(int left, int right) {
24 return (left + right) & _MASK_32;
25 }
26
27 void _bytesToWords(List<int> input,
28 int in_offset,
29 int in_len,
30 List<int> output,
31 int out_offset,
32 int out_len) {
33 var cur = in_offset;
34 var end = in_offset + in_len;
35 var cur_out = out_offset;
36 var unroll_loop_end = in_len ~/ _BYTES_PER_WORD;
37
38 while (cur_out < unroll_loop_end) {
39 var word = (input[cur++] & 0xff) << 24;
40 word |= (input[cur++] & 0xff) << 16;
41 word |= (input[cur++] & 0xff) << 8;
42 word |= (input[cur++] & 0xff);
43 output[cur_out++] = word;
44 }
45 // Fill the rest of the output with the remaining bytes or zeros if no more
46 // data is available.
47 while (cur_out < (out_offset + out_len)) {
48 var word = 0;
49 var bit_shift = (_BYTES_PER_WORD - 1) * _BITS_PER_BYTE;
50 while (cur < end) {
51 word |= (input[cur++] & 0xff) << bit_shift;
52 bit_shift -= _BITS_PER_BYTE;
53 }
54 output[cur_out++] = word;
55 }
56 }
57
58 List<int> _wordsToBytes(List<int> input) {
Ivan Posva 2012/04/24 09:23:53 This should change to take an output target, as we
59 var len = input.length;
60 var output = new List<int>(len * _BYTES_PER_WORD);
61 var cur = 0;
62 for (var word in input) {
63 output[cur++] = word >> 24;
64 output[cur++] = (word >> 16) & 0xff;
65 output[cur++] = (word >> 8) & 0xff;
66 output[cur++] = word & 0xff;
67 }
68 return output;
69 }
OLDNEW
« no previous file with comments | « no previous file | crypto/sha1.dart » ('j') | crypto/sha1.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698