22void
SHA_256::compress_digest_armv8(
digest_type& digest, std::span<const uint8_t> input8,
size_t blocks) {
23 alignas(64)
static const uint32_t K[] = {
24 0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5, 0x3956C25B, 0x59F111F1, 0x923F82A4, 0xAB1C5ED5,
25 0xD807AA98, 0x12835B01, 0x243185BE, 0x550C7DC3, 0x72BE5D74, 0x80DEB1FE, 0x9BDC06A7, 0xC19BF174,
26 0xE49B69C1, 0xEFBE4786, 0x0FC19DC6, 0x240CA1CC, 0x2DE92C6F, 0x4A7484AA, 0x5CB0A9DC, 0x76F988DA,
27 0x983E5152, 0xA831C66D, 0xB00327C8, 0xBF597FC7, 0xC6E00BF3, 0xD5A79147, 0x06CA6351, 0x14292967,
28 0x27B70A85, 0x2E1B2138, 0x4D2C6DFC, 0x53380D13, 0x650A7354, 0x766A0ABB, 0x81C2C92E, 0x92722C85,
29 0xA2BFE8A1, 0xA81A664B, 0xC24B8B70, 0xC76C51A3, 0xD192E819, 0xD6990624, 0xF40E3585, 0x106AA070,
30 0x19A4C116, 0x1E376C08, 0x2748774C, 0x34B0BCB5, 0x391C0CB3, 0x4ED8AA4A, 0x5B9CCA4F, 0x682E6FF3,
31 0x748F82EE, 0x78A5636F, 0x84C87814, 0x8CC70208, 0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2,
35 uint32x4_t STATE0 = vld1q_u32(&digest[0]);
36 uint32x4_t STATE1 = vld1q_u32(&digest[4]);
39 const uint32_t* input32 =
reinterpret_cast<const uint32_t*
>(
reinterpret_cast<const void*
>(input8.data()));
43 const uint32x4_t ABCD_SAVE = STATE0;
44 const uint32x4_t EFGH_SAVE = STATE1;
46 uint32x4_t MSG0 = vld1q_u32(input32 + 0);
47 uint32x4_t MSG1 = vld1q_u32(input32 + 4);
48 uint32x4_t MSG2 = vld1q_u32(input32 + 8);
49 uint32x4_t MSG3 = vld1q_u32(input32 + 12);
51 MSG0 = vreinterpretq_u32_u8(vrev32q_u8(vreinterpretq_u8_u32(MSG0)));
52 MSG1 = vreinterpretq_u32_u8(vrev32q_u8(vreinterpretq_u8_u32(MSG1)));
53 MSG2 = vreinterpretq_u32_u8(vrev32q_u8(vreinterpretq_u8_u32(MSG2)));
54 MSG3 = vreinterpretq_u32_u8(vrev32q_u8(vreinterpretq_u8_u32(MSG3)));
56 uint32x4_t MSG_K, TSTATE;
59 MSG_K = vaddq_u32(MSG0, vld1q_u32(&K[4 * 0]));
60 TSTATE = vsha256hq_u32(STATE0, STATE1, MSG_K);
61 STATE1 = vsha256h2q_u32(STATE1, STATE0, MSG_K);
63 MSG0 = vsha256su1q_u32(vsha256su0q_u32(MSG0, MSG1), MSG2, MSG3);
66 MSG_K = vaddq_u32(MSG1, vld1q_u32(&K[4 * 1]));
67 TSTATE = vsha256hq_u32(STATE0, STATE1, MSG_K);
68 STATE1 = vsha256h2q_u32(STATE1, STATE0, MSG_K);
70 MSG1 = vsha256su1q_u32(vsha256su0q_u32(MSG1, MSG2), MSG3, MSG0);
73 MSG_K = vaddq_u32(MSG2, vld1q_u32(&K[4 * 2]));
74 TSTATE = vsha256hq_u32(STATE0, STATE1, MSG_K);
75 STATE1 = vsha256h2q_u32(STATE1, STATE0, MSG_K);
77 MSG2 = vsha256su1q_u32(vsha256su0q_u32(MSG2, MSG3), MSG0, MSG1);
80 MSG_K = vaddq_u32(MSG3, vld1q_u32(&K[4 * 3]));
81 TSTATE = vsha256hq_u32(STATE0, STATE1, MSG_K);
82 STATE1 = vsha256h2q_u32(STATE1, STATE0, MSG_K);
84 MSG3 = vsha256su1q_u32(vsha256su0q_u32(MSG3, MSG0), MSG1, MSG2);
87 MSG_K = vaddq_u32(MSG0, vld1q_u32(&K[4 * 4]));
88 TSTATE = vsha256hq_u32(STATE0, STATE1, MSG_K);
89 STATE1 = vsha256h2q_u32(STATE1, STATE0, MSG_K);
91 MSG0 = vsha256su1q_u32(vsha256su0q_u32(MSG0, MSG1), MSG2, MSG3);
94 MSG_K = vaddq_u32(MSG1, vld1q_u32(&K[4 * 5]));
95 TSTATE = vsha256hq_u32(STATE0, STATE1, MSG_K);
96 STATE1 = vsha256h2q_u32(STATE1, STATE0, MSG_K);
98 MSG1 = vsha256su1q_u32(vsha256su0q_u32(MSG1, MSG2), MSG3, MSG0);
101 MSG_K = vaddq_u32(MSG2, vld1q_u32(&K[4 * 6]));
102 TSTATE = vsha256hq_u32(STATE0, STATE1, MSG_K);
103 STATE1 = vsha256h2q_u32(STATE1, STATE0, MSG_K);
105 MSG2 = vsha256su1q_u32(vsha256su0q_u32(MSG2, MSG3), MSG0, MSG1);
108 MSG_K = vaddq_u32(MSG3, vld1q_u32(&K[4 * 7]));
109 TSTATE = vsha256hq_u32(STATE0, STATE1, MSG_K);
110 STATE1 = vsha256h2q_u32(STATE1, STATE0, MSG_K);
112 MSG3 = vsha256su1q_u32(vsha256su0q_u32(MSG3, MSG0), MSG1, MSG2);
115 MSG_K = vaddq_u32(MSG0, vld1q_u32(&K[4 * 8]));
116 TSTATE = vsha256hq_u32(STATE0, STATE1, MSG_K);
117 STATE1 = vsha256h2q_u32(STATE1, STATE0, MSG_K);
119 MSG0 = vsha256su1q_u32(vsha256su0q_u32(MSG0, MSG1), MSG2, MSG3);
122 MSG_K = vaddq_u32(MSG1, vld1q_u32(&K[4 * 9]));
123 TSTATE = vsha256hq_u32(STATE0, STATE1, MSG_K);
124 STATE1 = vsha256h2q_u32(STATE1, STATE0, MSG_K);
126 MSG1 = vsha256su1q_u32(vsha256su0q_u32(MSG1, MSG2), MSG3, MSG0);
129 MSG_K = vaddq_u32(MSG2, vld1q_u32(&K[4 * 10]));
130 TSTATE = vsha256hq_u32(STATE0, STATE1, MSG_K);
131 STATE1 = vsha256h2q_u32(STATE1, STATE0, MSG_K);
133 MSG2 = vsha256su1q_u32(vsha256su0q_u32(MSG2, MSG3), MSG0, MSG1);
136 MSG_K = vaddq_u32(MSG3, vld1q_u32(&K[4 * 11]));
137 TSTATE = vsha256hq_u32(STATE0, STATE1, MSG_K);
138 STATE1 = vsha256h2q_u32(STATE1, STATE0, MSG_K);
140 MSG3 = vsha256su1q_u32(vsha256su0q_u32(MSG3, MSG0), MSG1, MSG2);
143 MSG_K = vaddq_u32(MSG0, vld1q_u32(&K[4 * 12]));
144 TSTATE = vsha256hq_u32(STATE0, STATE1, MSG_K);
145 STATE1 = vsha256h2q_u32(STATE1, STATE0, MSG_K);
149 MSG_K = vaddq_u32(MSG1, vld1q_u32(&K[4 * 13]));
150 TSTATE = vsha256hq_u32(STATE0, STATE1, MSG_K);
151 STATE1 = vsha256h2q_u32(STATE1, STATE0, MSG_K);
155 MSG_K = vaddq_u32(MSG2, vld1q_u32(&K[4 * 14]));
156 TSTATE = vsha256hq_u32(STATE0, STATE1, MSG_K);
157 STATE1 = vsha256h2q_u32(STATE1, STATE0, MSG_K);
161 MSG_K = vaddq_u32(MSG3, vld1q_u32(&K[4 * 15]));
162 TSTATE = vsha256hq_u32(STATE0, STATE1, MSG_K);
163 STATE1 = vsha256h2q_u32(STATE1, STATE0, MSG_K);
167 STATE0 = vaddq_u32(STATE0, ABCD_SAVE);
168 STATE1 = vaddq_u32(STATE1, EFGH_SAVE);
175 vst1q_u32(&digest[0], STATE0);
176 vst1q_u32(&digest[4], STATE1);