-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathsha256.cpp
35 lines (34 loc) · 2.66 KB
/
sha256.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "sha256.h"
#pragma clang diagnostic push
#pragma ide diagnostic ignored "OCDFAInspection"
void sha256(unsigned input[], unsigned output[])
{
INPUT_16() INPUT_17() INPUT_18_21(18) INPUT_18_21(19) INPUT_18_21(20) INPUT_18_21(21) INPUT(22) INPUT(23)
INPUT_24() INPUT_25_29(25) INPUT_25_29(26) INPUT_25_29(27) INPUT_25_29(28) INPUT_25_29(29) INPUT_30() INPUT(31)
INPUT(32) INPUT(33) INPUT(34) INPUT(35) INPUT(36) INPUT(37) INPUT(38) INPUT(39)
INPUT(40) INPUT(41) INPUT(42) INPUT(43) INPUT(44) INPUT(45) INPUT(46) INPUT(47)
INPUT(48) INPUT(49) INPUT(50) INPUT(51) INPUT(52) INPUT(53) INPUT(54) INPUT(55)
INPUT(56) INPUT(57) INPUT(58) INPUT(59) INPUT(60) INPUT(61) INPUT(62) INPUT(63)
unsigned words[8], temp1, temp2;
output[0] = words[0] = 0x6A09E667; output[1] = words[1] = 0xBB67AE85; output[2] = words[2] = 0x3C6EF372; output[3] = words[3] = 0xA54FF53A;
output[4] = words[4] = 0x510E527F; output[5] = words[5] = 0x9B05688C; output[6] = words[6] = 0x1F83D9AB; output[7] = words[7] = 0x5BE0CD19;
ROUND(0, 0x428A2F98) ROUND(1, 0x71374491) ROUND(2, 0xB5C0FBCF) ROUND(3, 0xE9B5DBA5)
ROUND(4, 0x3956C25B) ROUND(5, 0x59F111F1) ROUND(6, 0x923F82A4) ROUND(7, 0xAB1C5ED5)
ROUND(8, 0xD807AA98) ROUND(9, 0x12835B01) ROUND(10, 0x243185BE) ROUND(11, 0x550C7DC3)
ROUND(12, 0x72BE5D74) ROUND(13, 0x80DEB1FE) ROUND(14, 0x9BDC06A7) ROUND(15, 0xC19BF174)
ROUND(16, 0xE49B69C1) ROUND(17, 0xEFBE4786) ROUND(18, 0x0FC19DC6) ROUND(19, 0x240CA1CC)
ROUND(20, 0x2DE92C6F) ROUND(21, 0x4A7484AA) ROUND(22, 0x5CB0A9DC) ROUND(23, 0x76F988DA)
ROUND(24, 0x983E5152) ROUND(25, 0xA831C66D) ROUND(26, 0xB00327C8) ROUND(27, 0xBF597FC7)
ROUND(28, 0xC6E00BF3) ROUND(29, 0xD5A79147) ROUND(30, 0x06CA6351) ROUND(31, 0x14292967)
ROUND(32, 0x27B70A85) ROUND(33, 0x2E1B2138) ROUND(34, 0x4D2C6DFC) ROUND(35, 0x53380D13)
ROUND(36, 0x650A7354) ROUND(37, 0x766A0ABB) ROUND(38, 0x81C2C92E) ROUND(39, 0x92722C85)
ROUND(40, 0xA2BFE8A1) ROUND(41, 0xA81A664B) ROUND(42, 0xC24B8B70) ROUND(43, 0xC76C51A3)
ROUND(44, 0xD192E819) ROUND(45, 0xD6990624) ROUND(46, 0xF40E3585) ROUND(47, 0x106AA070)
ROUND(48, 0x19A4C116) ROUND(49, 0x1E376C08) ROUND(50, 0x2748774C) ROUND(51, 0x34B0BCB5)
ROUND(52, 0x391C0CB3) ROUND(53, 0x4ED8AA4A) ROUND(54, 0x5B9CCA4F) ROUND(55, 0x682E6FF3)
ROUND(56, 0x748F82EE) ROUND(57, 0x78A5636F) ROUND(58, 0x84C87814) ROUND(59, 0x8CC70208)
ROUND(60, 0x90BEFFFA) ROUND(61, 0xA4506CEB) ROUND(62, 0xBEF9A3F7) ROUND(63, 0xC67178F2)
output[0] += words[0]; output[1] += words[1]; output[2] += words[2]; output[3] += words[3];
output[4] += words[4]; output[5] += words[5]; output[6] += words[6]; output[7] += words[7];
}
#pragma clang diagnostic pop