17ANONYMOUS_NAMESPACE_BEGIN
20using CryptoPP::word32;
21using CryptoPP::rotlConstant;
24using CryptoPP::GetBlock;
25using CryptoPP::BigEndian;
29 return X ^ rotlConstant<9>(X) ^ rotlConstant<17>(X);
34 return X ^ rotlConstant<15>(X) ^ rotlConstant<23>(X);
39 return P1(W0 ^ W7 ^ rotlConstant<15>(W13)) ^ rotlConstant<7>(W3) ^ W10;
44 return (X & Y) | ((X | Y) & Z);
49 return ((Z ^ (X & (Y ^ Z))));
55 const word32 A12 = rotlConstant<12>(A);
56 const word32 TT0 = rotlConstant<7>(A12 + E + TJ);
57 const word32 TT1 = (A ^ B ^ C) + D + (TT0 ^ A12) + Wj;
58 const word32 TT2 = (E ^ F ^ G) + H + TT0 + Wi;
60 B = rotlConstant<9>(B); D = TT1;
61 F = rotlConstant<19>(F); H = P0(TT2);
67 const word32 A12 = rotlConstant<12>(A);
68 const word32 TT0 = rotlConstant<7>(A12 + E + TJ);
69 const word32 TT1 = FF(A, B, C) + D + (TT0 ^ A12) + Wj;
70 const word32 TT2 = GG(E, F, G) + H + TT0 + Wi;
72 B = rotlConstant<9>(B); D = TT1;
73 F = rotlConstant<19>(F); H = P0(TT2);
77size_t SM3_HashMultipleBlocks_CXX(
word32 *state,
const word32 *data,
size_t length)
81 word32 A = state[0], B = state[1], C = state[2], D = state[3];
82 word32 E = state[4], F = state[5], G = state[6], H = state[7];
84 while (length >= SM3::BLOCKSIZE)
90 word32 W00, W01, W02, W03, W04, W05, W06, W07, W08, W09, W10, W11, W12, W13, W14, W15;
91 iblk(W00)(W01)(W02)(W03)(W04)(W05)(W06)(W07)(W08)(W09)(W10)(W11)(W12)(W13)(W14)(W15);
93 R1(A, B, C, D, E, F, G, H, 0x79CC4519, W00, W00 ^ W04);
94 W00 = EE(W00, W07, W13, W03, W10);
95 R1(D, A, B, C, H, E, F, G, 0xF3988A32, W01, W01 ^ W05);
96 W01 = EE(W01, W08, W14, W04, W11);
97 R1(C, D, A, B, G, H, E, F, 0xE7311465, W02, W02 ^ W06);
98 W02 = EE(W02, W09, W15, W05, W12);
99 R1(B, C, D, A, F, G, H, E, 0xCE6228CB, W03, W03 ^ W07);
100 W03 = EE(W03, W10, W00, W06, W13);
101 R1(A, B, C, D, E, F, G, H, 0x9CC45197, W04, W04 ^ W08);
102 W04 = EE(W04, W11, W01, W07, W14);
103 R1(D, A, B, C, H, E, F, G, 0x3988A32F, W05, W05 ^ W09);
104 W05 = EE(W05, W12, W02, W08, W15);
105 R1(C, D, A, B, G, H, E, F, 0x7311465E, W06, W06 ^ W10);
106 W06 = EE(W06, W13, W03, W09, W00);
107 R1(B, C, D, A, F, G, H, E, 0xE6228CBC, W07, W07 ^ W11);
108 W07 = EE(W07, W14, W04, W10, W01);
109 R1(A, B, C, D, E, F, G, H, 0xCC451979, W08, W08 ^ W12);
110 W08 = EE(W08, W15, W05, W11, W02);
111 R1(D, A, B, C, H, E, F, G, 0x988A32F3, W09, W09 ^ W13);
112 W09 = EE(W09, W00, W06, W12, W03);
113 R1(C, D, A, B, G, H, E, F, 0x311465E7, W10, W10 ^ W14);
114 W10 = EE(W10, W01, W07, W13, W04);
115 R1(B, C, D, A, F, G, H, E, 0x6228CBCE, W11, W11 ^ W15);
116 W11 = EE(W11, W02, W08, W14, W05);
117 R1(A, B, C, D, E, F, G, H, 0xC451979C, W12, W12 ^ W00);
118 W12 = EE(W12, W03, W09, W15, W06);
119 R1(D, A, B, C, H, E, F, G, 0x88A32F39, W13, W13 ^ W01);
120 W13 = EE(W13, W04, W10, W00, W07);
121 R1(C, D, A, B, G, H, E, F, 0x11465E73, W14, W14 ^ W02);
122 W14 = EE(W14, W05, W11, W01, W08);
123 R1(B, C, D, A, F, G, H, E, 0x228CBCE6, W15, W15 ^ W03);
124 W15 = EE(W15, W06, W12, W02, W09);
125 R2(A, B, C, D, E, F, G, H, 0x9D8A7A87, W00, W00 ^ W04);
126 W00 = EE(W00, W07, W13, W03, W10);
127 R2(D, A, B, C, H, E, F, G, 0x3B14F50F, W01, W01 ^ W05);
128 W01 = EE(W01, W08, W14, W04, W11);
129 R2(C, D, A, B, G, H, E, F, 0x7629EA1E, W02, W02 ^ W06);
130 W02 = EE(W02, W09, W15, W05, W12);
131 R2(B, C, D, A, F, G, H, E, 0xEC53D43C, W03, W03 ^ W07);
132 W03 = EE(W03, W10, W00, W06, W13);
133 R2(A, B, C, D, E, F, G, H, 0xD8A7A879, W04, W04 ^ W08);
134 W04 = EE(W04, W11, W01, W07, W14);
135 R2(D, A, B, C, H, E, F, G, 0xB14F50F3, W05, W05 ^ W09);
136 W05 = EE(W05, W12, W02, W08, W15);
137 R2(C, D, A, B, G, H, E, F, 0x629EA1E7, W06, W06 ^ W10);
138 W06 = EE(W06, W13, W03, W09, W00);
139 R2(B, C, D, A, F, G, H, E, 0xC53D43CE, W07, W07 ^ W11);
140 W07 = EE(W07, W14, W04, W10, W01);
141 R2(A, B, C, D, E, F, G, H, 0x8A7A879D, W08, W08 ^ W12);
142 W08 = EE(W08, W15, W05, W11, W02);
143 R2(D, A, B, C, H, E, F, G, 0x14F50F3B, W09, W09 ^ W13);
144 W09 = EE(W09, W00, W06, W12, W03);
145 R2(C, D, A, B, G, H, E, F, 0x29EA1E76, W10, W10 ^ W14);
146 W10 = EE(W10, W01, W07, W13, W04);
147 R2(B, C, D, A, F, G, H, E, 0x53D43CEC, W11, W11 ^ W15);
148 W11 = EE(W11, W02, W08, W14, W05);
149 R2(A, B, C, D, E, F, G, H, 0xA7A879D8, W12, W12 ^ W00);
150 W12 = EE(W12, W03, W09, W15, W06);
151 R2(D, A, B, C, H, E, F, G, 0x4F50F3B1, W13, W13 ^ W01);
152 W13 = EE(W13, W04, W10, W00, W07);
153 R2(C, D, A, B, G, H, E, F, 0x9EA1E762, W14, W14 ^ W02);
154 W14 = EE(W14, W05, W11, W01, W08);
155 R2(B, C, D, A, F, G, H, E, 0x3D43CEC5, W15, W15 ^ W03);
156 W15 = EE(W15, W06, W12, W02, W09);
157 R2(A, B, C, D, E, F, G, H, 0x7A879D8A, W00, W00 ^ W04);
158 W00 = EE(W00, W07, W13, W03, W10);
159 R2(D, A, B, C, H, E, F, G, 0xF50F3B14, W01, W01 ^ W05);
160 W01 = EE(W01, W08, W14, W04, W11);
161 R2(C, D, A, B, G, H, E, F, 0xEA1E7629, W02, W02 ^ W06);
162 W02 = EE(W02, W09, W15, W05, W12);
163 R2(B, C, D, A, F, G, H, E, 0xD43CEC53, W03, W03 ^ W07);
164 W03 = EE(W03, W10, W00, W06, W13);
165 R2(A, B, C, D, E, F, G, H, 0xA879D8A7, W04, W04 ^ W08);
166 W04 = EE(W04, W11, W01, W07, W14);
167 R2(D, A, B, C, H, E, F, G, 0x50F3B14F, W05, W05 ^ W09);
168 W05 = EE(W05, W12, W02, W08, W15);
169 R2(C, D, A, B, G, H, E, F, 0xA1E7629E, W06, W06 ^ W10);
170 W06 = EE(W06, W13, W03, W09, W00);
171 R2(B, C, D, A, F, G, H, E, 0x43CEC53D, W07, W07 ^ W11);
172 W07 = EE(W07, W14, W04, W10, W01);
173 R2(A, B, C, D, E, F, G, H, 0x879D8A7A, W08, W08 ^ W12);
174 W08 = EE(W08, W15, W05, W11, W02);
175 R2(D, A, B, C, H, E, F, G, 0x0F3B14F5, W09, W09 ^ W13);
176 W09 = EE(W09, W00, W06, W12, W03);
177 R2(C, D, A, B, G, H, E, F, 0x1E7629EA, W10, W10 ^ W14);
178 W10 = EE(W10, W01, W07, W13, W04);
179 R2(B, C, D, A, F, G, H, E, 0x3CEC53D4, W11, W11 ^ W15);
180 W11 = EE(W11, W02, W08, W14, W05);
181 R2(A, B, C, D, E, F, G, H, 0x79D8A7A8, W12, W12 ^ W00);
182 W12 = EE(W12, W03, W09, W15, W06);
183 R2(D, A, B, C, H, E, F, G, 0xF3B14F50, W13, W13 ^ W01);
184 W13 = EE(W13, W04, W10, W00, W07);
185 R2(C, D, A, B, G, H, E, F, 0xE7629EA1, W14, W14 ^ W02);
186 W14 = EE(W14, W05, W11, W01, W08);
187 R2(B, C, D, A, F, G, H, E, 0xCEC53D43, W15, W15 ^ W03);
188 W15 = EE(W15, W06, W12, W02, W09);
189 R2(A, B, C, D, E, F, G, H, 0x9D8A7A87, W00, W00 ^ W04);
190 W00 = EE(W00, W07, W13, W03, W10);
191 R2(D, A, B, C, H, E, F, G, 0x3B14F50F, W01, W01 ^ W05);
192 W01 = EE(W01, W08, W14, W04, W11);
193 R2(C, D, A, B, G, H, E, F, 0x7629EA1E, W02, W02 ^ W06);
194 W02 = EE(W02, W09, W15, W05, W12);
195 R2(B, C, D, A, F, G, H, E, 0xEC53D43C, W03, W03 ^ W07);
196 W03 = EE(W03, W10, W00, W06, W13);
197 R2(A, B, C, D, E, F, G, H, 0xD8A7A879, W04, W04 ^ W08);
198 R2(D, A, B, C, H, E, F, G, 0xB14F50F3, W05, W05 ^ W09);
199 R2(C, D, A, B, G, H, E, F, 0x629EA1E7, W06, W06 ^ W10);
200 R2(B, C, D, A, F, G, H, E, 0xC53D43CE, W07, W07 ^ W11);
201 R2(A, B, C, D, E, F, G, H, 0x8A7A879D, W08, W08 ^ W12);
202 R2(D, A, B, C, H, E, F, G, 0x14F50F3B, W09, W09 ^ W13);
203 R2(C, D, A, B, G, H, E, F, 0x29EA1E76, W10, W10 ^ W14);
204 R2(B, C, D, A, F, G, H, E, 0x53D43CEC, W11, W11 ^ W15);
205 R2(A, B, C, D, E, F, G, H, 0xA7A879D8, W12, W12 ^ W00);
206 R2(D, A, B, C, H, E, F, G, 0x4F50F3B1, W13, W13 ^ W01);
207 R2(C, D, A, B, G, H, E, F, 0x9EA1E762, W14, W14 ^ W02);
208 R2(B, C, D, A, F, G, H, E, 0x3D43CEC5, W15, W15 ^ W03);
219 data += SM3::BLOCKSIZE/
sizeof(
word32);
220 length -= SM3::BLOCKSIZE;
226ANONYMOUS_NAMESPACE_END
230void
SM3::InitState(HashWordType *state)
233 0x7380166f, 0x4914b2b9, 0x172442d7, 0xda8a0600,
234 0xa96f30bc, 0x163138aa, 0xe38dee4d, 0xb0fb0e4e
237 std::memcpy(state, s,
sizeof(s));
245 SM3_HashMultipleBlocks_CXX(state, data, SM3::BLOCKSIZE);
248size_t SM3::HashMultipleBlocks(
const HashWordType *input,
size_t length)
250 const size_t res = length & (SM3::BLOCKSIZE - 1);
251 SM3_HashMultipleBlocks_CXX(m_state, input, length-res);
Access a block of memory.
static void Transform(HashWordType *digest, const HashWordType *data)
Operate the hash.
Library configuration file.
unsigned int word32
32-bit unsigned datatype
Functions for CPU features and intrinsics.
Utility functions for the Crypto++ library.
Crypto++ library namespace.
Classes for the SM3 hash function.
#define CRYPTOPP_ASSERT(exp)
Debugging and diagnostic assertion.