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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | crypto/sha1.dart » ('j') | crypto/sha1.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: crypto/crypto.dart
===================================================================
--- crypto/crypto.dart (revision 0)
+++ crypto/crypto.dart (revision 0)
@@ -0,0 +1,69 @@
+#library("crypto");
Mads Ager (google) 2012/04/24 09:57:46 Copyright.
Ivan Posva 2012/04/24 13:02:36 Done.
+
+#source("sha1.dart");
+
+// 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.
+
+final int _BITS_PER_BYTE = 8;
+final int _BYTES_PER_WORD = 4;
+final int _BITS_PER_WORD = _BITS_PER_BYTE * _BYTES_PER_WORD;
+final int _MASK_32 = 0xffffffff;
+
+int _roundUp(int val, int n) {
+ return (val + n - 1) & -n;
+}
+
+// Rotate left limiting to unsigned 32-bit values.
+int _rotl32(int val, int shift) {
+ var mod_shift = shift & 31;
+ 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.
+}
+
+// Add limiting to unsigned 32-bit values.
+int _add32(int left, int right) {
+ return (left + right) & _MASK_32;
+}
+
+void _bytesToWords(List<int> input,
+ int in_offset,
+ int in_len,
+ List<int> output,
+ int out_offset,
+ int out_len) {
+ var cur = in_offset;
+ var end = in_offset + in_len;
+ var cur_out = out_offset;
+ var unroll_loop_end = in_len ~/ _BYTES_PER_WORD;
+
+ while (cur_out < unroll_loop_end) {
+ var word = (input[cur++] & 0xff) << 24;
+ word |= (input[cur++] & 0xff) << 16;
+ word |= (input[cur++] & 0xff) << 8;
+ word |= (input[cur++] & 0xff);
+ output[cur_out++] = word;
+ }
+ // Fill the rest of the output with the remaining bytes or zeros if no more
+ // data is available.
+ while (cur_out < (out_offset + out_len)) {
+ var word = 0;
+ var bit_shift = (_BYTES_PER_WORD - 1) * _BITS_PER_BYTE;
+ while (cur < end) {
+ word |= (input[cur++] & 0xff) << bit_shift;
+ bit_shift -= _BITS_PER_BYTE;
+ }
+ output[cur_out++] = word;
+ }
+}
+
+List<int> _wordsToBytes(List<int> input) {
Ivan Posva 2012/04/24 09:23:53 This should change to take an output target, as we
+ var len = input.length;
+ var output = new List<int>(len * _BYTES_PER_WORD);
+ var cur = 0;
+ for (var word in input) {
+ output[cur++] = word >> 24;
+ output[cur++] = (word >> 16) & 0xff;
+ output[cur++] = (word >> 8) & 0xff;
+ output[cur++] = word & 0xff;
+ }
+ return output;
+}
« 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