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; | |
6 | |
7 /// A bitmask that limits an integer to 32 bits. | 5 /// A bitmask that limits an integer to 32 bits. |
8 const mask32 = 0xFFFFFFFF; | 6 const mask32 = 0xFFFFFFFF; |
9 | 7 |
10 /// The highest value representable by a 64-bit unsigned integer. | 8 /// The highest value representable by a 64-bit unsigned integer. |
11 const maxUint64 = 0xFFFFFFFFFFFFFFFF; | 9 const maxUint64 = 0xFFFFFFFFFFFFFFFF; |
12 | 10 |
13 /// The number of bits in a byte. | 11 /// The number of bits in a byte. |
14 const bitsPerByte = 8; | 12 const bitsPerByte = 8; |
15 | 13 |
16 /// The number of bytes in a 32-bit word. | 14 /// The number of bytes in a 32-bit word. |
17 const bytesPerWord = 4; | 15 const bytesPerWord = 4; |
18 | 16 |
19 /// Adds [x] and [y] with 32-bit overflow semantics. | 17 /// Adds [x] and [y] with 32-bit overflow semantics. |
20 int add32(int x, int y) => (x + y) & mask32; | 18 int add32(int x, int y) => (x + y) & mask32; |
21 | 19 |
22 /// Bitwise rotates [val] to the left by [shift], obeying 32-bit overflow | 20 /// Bitwise rotates [val] to the left by [shift], obeying 32-bit overflow |
23 /// semantics. | 21 /// semantics. |
24 int rotl32(int val, int shift) { | 22 int rotl32(int val, int shift) { |
25 var modShift = shift & 31; | 23 var modShift = shift & 31; |
26 return ((val << modShift) & mask32) | | 24 return ((val << modShift) & mask32) | |
27 ((val & mask32) >> (32 - modShift)); | 25 ((val & mask32) >> (32 - modShift)); |
28 } | 26 } |
OLD | NEW |