OLD | NEW |
---|---|
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library crypto.utils; | 5 library crypto.utils; |
6 | 6 |
7 /// A bitmask that limits an integer to 8 bits. | 7 /// A bitmask that limits an integer to 32 bits. |
8 const MASK_8 = 0xff; | 8 const mask32 = 0XFFFFFFFF; |
Bob Nystrom
2015/09/18 17:15:48
Lowercase "x".
nweiz
2015/09/18 19:37:21
Done.
| |
9 | 9 |
10 /// A bitmask that limits an integer to 32 bits. | 10 /// The highest value representable by a 64-bit unsigned integer. |
11 const MASK_32 = 0xffffffff; | 11 const maxUint64 = 0xFFFFFFFFFFFFFFFF; |
12 | 12 |
13 /// The number of bits in a byte. | 13 /// The number of bits in a byte. |
14 const BITS_PER_BYTE = 8; | 14 const bitsPerByte = 8; |
15 | 15 |
16 /// The number of bytes in a 32-bit word. | 16 /// The number of bytes in a 32-bit word. |
17 const BYTES_PER_WORD = 4; | 17 const bytesPerWord = 4; |
18 | 18 |
19 /// Adds [x] and [y] with 32-bit overflow semantics. | 19 /// Adds [x] and [y] with 32-bit overflow semantics. |
20 int add32(x, y) => (x + y) & MASK_32; | 20 int add32(int x, int y) => (x + y) & mask32; |
21 | 21 |
22 /// Bitwise rotates [val] to the left by [shift], obeying 32-bit overflow | 22 /// Bitwise rotates [val] to the left by [shift], obeying 32-bit overflow |
23 /// semantics. | 23 /// semantics. |
24 int rotl32(int val, int shift) { | 24 int rotl32(int val, int shift) { |
25 var mod_shift = shift & 31; | 25 var modShift = shift & 31; |
26 return ((val << mod_shift) & MASK_32) | | 26 return ((val << modShift) & mask32) | |
27 ((val & MASK_32) >> (32 - mod_shift)); | 27 ((val & mask32) >> (32 - modShift)); |
28 } | 28 } |
OLD | NEW |