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

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 // 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 #library("crypto");
6
7 #source("sha1.dart");
8
9 // Helpers used implementing the different crypto algorithms.
10
11 final int _BITS_PER_BYTE = 8;
12 final int _BYTES_PER_WORD = 4;
13 final int _BITS_PER_WORD = _BITS_PER_BYTE * _BYTES_PER_WORD;
14 final int _MASK_32 = 0xffffffff;
15
16 int _roundUp(int val, int n) {
17 return (val + n - 1) & -n;
18 }
19
20 // Rotate left limiting to unsigned 32-bit values.
21 int _rotl32(int val, int shift) {
22 var mod_shift = shift & 31;
23 return ((val << mod_shift) & _MASK_32) |
24 ((val & _MASK_32) >> (32 - mod_shift));
25 }
26
27 // Add limiting to unsigned 32-bit values.
28 int _add32(int left, int right) {
29 return (left + right) & _MASK_32;
30 }
31
32 void _bytesToWords(List<int> input,
33 int in_offset,
34 int in_len,
35 List<int> output,
36 int out_offset,
37 int out_len) {
38 var cur = in_offset;
39 var end = in_offset + in_len;
40 var cur_out = out_offset;
41 var unroll_loop_end = in_len ~/ _BYTES_PER_WORD;
42
43 while (cur_out < unroll_loop_end) {
44 var word = (input[cur++] & 0xff) << 24;
45 word |= (input[cur++] & 0xff) << 16;
46 word |= (input[cur++] & 0xff) << 8;
47 word |= (input[cur++] & 0xff);
48 output[cur_out++] = word;
49 }
50 // Fill the rest of the output with the remaining bytes or zeros if no more
51 // data is available.
52 while (cur_out < (out_offset + out_len)) {
53 var word = 0;
54 var bit_shift = (_BYTES_PER_WORD - 1) * _BITS_PER_BYTE;
55 while (cur < end) {
56 word |= (input[cur++] & 0xff) << bit_shift;
57 bit_shift -= _BITS_PER_BYTE;
58 }
59 output[cur_out++] = word;
60 }
61 }
62
63 List<int> _wordsToBytes(List<int> input) {
64 var len = input.length;
65 var output = new List<int>(len * _BYTES_PER_WORD);
66 var cur = 0;
67 for (var word in input) {
68 output[cur++] = word >> 24;
69 output[cur++] = (word >> 16) & 0xff;
70 output[cur++] = (word >> 8) & 0xff;
71 output[cur++] = word & 0xff;
72 }
73 return output;
74 }
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