sha1 static method
Implementation
static Uint8List sha1(List<int> message) {
final List<int> padded = List<int>.from(message)..add(0x80);
while (padded.length % 64 != 56) {
padded.add(0);
}
final int bitLength = message.length * 8;
for (int i = 7; i >= 0; i--) {
padded.add((bitLength >>> (8 * i)) & 0xFF);
}
int h0 = 0x67452301;
int h1 = 0xEFCDAB89;
int h2 = 0x98BADCFE;
int h3 = 0x10325476;
int h4 = 0xC3D2E1F0;
final List<int> words = List<int>.filled(80, 0);
for (int chunk = 0; chunk < padded.length; chunk += 64) {
for (int i = 0; i < 16; i++) {
words[i] = (padded[chunk + i * 4] << 24) | (padded[chunk + i * 4 + 1] << 16) | (padded[chunk + i * 4 + 2] << 8) | padded[chunk + i * 4 + 3];
}
for (int i = 16; i < 80; i++) {
final int value = words[i - 3] ^ words[i - 8] ^ words[i - 14] ^ words[i - 16];
words[i] = ((value << 1) | (value >>> 31)) & 0xFFFFFFFF;
}
int a = h0;
int b = h1;
int c = h2;
int d = h3;
int e = h4;
for (int i = 0; i < 80; i++) {
int f;
int k;
if (i < 20) {
f = (b & c) | (~b & d);
k = 0x5A827999;
} else if (i < 40) {
f = b ^ c ^ d;
k = 0x6ED9EBA1;
} else if (i < 60) {
f = (b & c) | (b & d) | (c & d);
k = 0x8F1BBCDC;
} else {
f = b ^ c ^ d;
k = 0xCA62C1D6;
}
final int temp = (((a << 5) | (a >>> 27)) + (f & 0xFFFFFFFF) + e + k + words[i]) & 0xFFFFFFFF;
e = d;
d = c;
c = ((b << 30) | (b >>> 2)) & 0xFFFFFFFF;
b = a;
a = temp;
}
h0 = (h0 + a) & 0xFFFFFFFF;
h1 = (h1 + b) & 0xFFFFFFFF;
h2 = (h2 + c) & 0xFFFFFFFF;
h3 = (h3 + d) & 0xFFFFFFFF;
h4 = (h4 + e) & 0xFFFFFFFF;
}
final Uint8List out = Uint8List(20);
final List<int> values = <int>[h0, h1, h2, h3, h4];
for (int i = 0; i < 5; i++) {
out[i * 4] = (values[i] >>> 24) & 0xFF;
out[i * 4 + 1] = (values[i] >>> 16) & 0xFF;
out[i * 4 + 2] = (values[i] >>> 8) & 0xFF;
out[i * 4 + 3] = values[i] & 0xFF;
}
return out;
}