tools/../../3rdparty/rfc6234/sha224-256.c

Switch to Source codePreprocessed file
LineSource CodeCoverage
1static int SHA224_256Reset(SHA256Context *context, ::quint32 *H0); -
2static void SHA224_256ProcessMessageBlock(SHA256Context *context); -
3static void SHA224_256Finalize(SHA256Context *context, -
4 ::quint8 Pad_Byte); -
5static void SHA224_256PadMessage(SHA256Context *context, -
6 ::quint8 Pad_Byte); -
7static int SHA224_256ResultN(SHA256Context *context, -
8 ::quint8 Message_Digest[ ], int HashSize); -
9 -
10 -
11static ::quint32 SHA224_H0[SHA256HashSize/4] = { -
12 0xC1059ED8, 0x367CD507, 0x3070DD17, 0xF70E5939, -
13 0xFFC00B31, 0x68581511, 0x64F98FA7, 0xBEFA4FA4 -
14}; -
15 -
16 -
17static ::quint32 SHA256_H0[SHA256HashSize/4] = { -
18 0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A, -
19 0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19 -
20}; -
21int SHA224Reset(SHA224Context *context) -
22{ -
23 return SHA224_256Reset(context, SHA224_H0);
executed: return SHA224_256Reset(context, SHA224_H0);
Execution Count:4
4
24} -
25int SHA224Input(SHA224Context *context, const ::quint8 *message_array, -
26 unsigned int length) -
27{ -
28 return SHA256Input(context, message_array, length);
executed: return SHA256Input(context, message_array, length);
Execution Count:4
4
29} -
30int SHA224FinalBits(SHA224Context *context, -
31 ::quint8 message_bits, unsigned int length) -
32{ -
33 return SHA256FinalBits(context, message_bits, length);
never executed: return SHA256FinalBits(context, message_bits, length);
0
34} -
35int SHA224Result(SHA224Context *context, -
36 ::quint8 Message_Digest[SHA224HashSize]) -
37{ -
38 return SHA224_256ResultN(context, Message_Digest, SHA224HashSize);
executed: return SHA224_256ResultN(context, Message_Digest, SHA224HashSize);
Execution Count:4
4
39} -
40int SHA256Reset(SHA256Context *context) -
41{ -
42 return SHA224_256Reset(context, SHA256_H0);
executed: return SHA224_256Reset(context, SHA256_H0);
Execution Count:4
4
43} -
44int SHA256Input(SHA256Context *context, const ::quint8 *message_array, -
45 unsigned int length) -
46{ -
47 if (!context) return shaNull;
partially evaluated: !context
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:8
never executed: return shaNull;
0-8
48 if (!length) return shaSuccess;
partially evaluated: !length
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:8
never executed: return shaSuccess;
0-8
49 if (!message_array) return shaNull;
partially evaluated: !message_array
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:8
never executed: return shaNull;
0-8
50 if (context->Computed) return context->Corrupted = shaStateError;
partially evaluated: context->Computed
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:8
never executed: return context->Corrupted = shaStateError;
0-8
51 if (context->Corrupted) return context->Corrupted;
partially evaluated: context->Corrupted
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:8
never executed: return context->Corrupted;
0-8
52 -
53 while (length--) {
evaluated: length--
TRUEFALSE
yes
Evaluation Count:24
yes
Evaluation Count:8
8-24
54 context->Message_Block[context->Message_Block_Index++] = -
55 *message_array; -
56 -
57 if ((SHA224_256AddLength(context, 8) == shaSuccess) &&
partially evaluated: (SHA224_256AddLength(context, 8) == shaSuccess)
TRUEFALSE
yes
Evaluation Count:24
no
Evaluation Count:0
0-24
58 (context->Message_Block_Index == SHA256_Message_Block_Size))
partially evaluated: (context->Message_Block_Index == SHA256_Message_Block_Size)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:24
0-24
59 SHA224_256ProcessMessageBlock(context);
never executed: SHA224_256ProcessMessageBlock(context);
0
60 -
61 message_array++; -
62 }
executed: }
Execution Count:24
24
63 -
64 return context->Corrupted;
executed: return context->Corrupted;
Execution Count:8
8
65 -
66} -
67int SHA256FinalBits(SHA256Context *context, -
68 ::quint8 message_bits, unsigned int length) -
69{ -
70 static ::quint8 masks[8] = { -
71 0x00, 0x80, -
72 0xC0, 0xE0, -
73 0xF0, 0xF8, -
74 0xFC, 0xFE -
75 }; -
76 static ::quint8 markbit[8] = { -
77 0x80, 0x40, -
78 0x20, 0x10, -
79 0x08, 0x04, -
80 0x02, 0x01 -
81 }; -
82 -
83 if (!context) return shaNull;
never executed: return shaNull;
never evaluated: !context
0
84 if (!length) return shaSuccess;
never executed: return shaSuccess;
never evaluated: !length
0
85 if (context->Corrupted) return context->Corrupted;
never executed: return context->Corrupted;
never evaluated: context->Corrupted
0
86 if (context->Computed) return context->Corrupted = shaStateError;
never executed: return context->Corrupted = shaStateError;
never evaluated: context->Computed
0
87 if (length >= 8) return context->Corrupted = shaBadParam;
never executed: return context->Corrupted = shaBadParam;
never evaluated: length >= 8
0
88 -
89 SHA224_256AddLength(context, length); -
90 SHA224_256Finalize(context, (::quint8) -
91 ((message_bits & masks[length]) | markbit[length])); -
92 -
93 return context->Corrupted;
never executed: return context->Corrupted;
0
94} -
95int SHA256Result(SHA256Context *context, -
96 ::quint8 Message_Digest[SHA256HashSize]) -
97{ -
98 return SHA224_256ResultN(context, Message_Digest, SHA256HashSize);
executed: return SHA224_256ResultN(context, Message_Digest, SHA256HashSize);
Execution Count:4
4
99} -
100static int SHA224_256Reset(SHA256Context *context, ::quint32 *H0) -
101{ -
102 if (!context) return shaNull;
never executed: return shaNull;
partially evaluated: !context
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:8
0-8
103 -
104 context->Length_High = context->Length_Low = 0; -
105 context->Message_Block_Index = 0; -
106 -
107 context->Intermediate_Hash[0] = H0[0]; -
108 context->Intermediate_Hash[1] = H0[1]; -
109 context->Intermediate_Hash[2] = H0[2]; -
110 context->Intermediate_Hash[3] = H0[3]; -
111 context->Intermediate_Hash[4] = H0[4]; -
112 context->Intermediate_Hash[5] = H0[5]; -
113 context->Intermediate_Hash[6] = H0[6]; -
114 context->Intermediate_Hash[7] = H0[7]; -
115 -
116 context->Computed = 0; -
117 context->Corrupted = shaSuccess; -
118 -
119 return shaSuccess;
executed: return shaSuccess;
Execution Count:8
8
120} -
121static void SHA224_256ProcessMessageBlock(SHA256Context *context) -
122{ -
123 -
124 static const ::quint32 K[64] = { -
125 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, -
126 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, -
127 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, -
128 0xc19bf174, 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, -
129 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 0x983e5152, -
130 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, -
131 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, -
132 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, -
133 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, -
134 0xd6990624, 0xf40e3585, 0x106aa070, 0x19a4c116, 0x1e376c08, -
135 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, -
136 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, -
137 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 -
138 }; -
139 int t, t4; -
140 ::quint32 temp1, temp2; -
141 ::quint32 W[64]; -
142 ::quint32 A, B, C, D, E, F, G, H; -
143 -
144 -
145 -
146 -
147 for (t = t4 = 0; t < 16; t++, t4 += 4)
evaluated: t < 16
TRUEFALSE
yes
Evaluation Count:128
yes
Evaluation Count:8
8-128
148 W[t] = (((::quint32)context->Message_Block[t4]) << 24) | 128
149 (((::quint32)context->Message_Block[t4 + 1]) << 16) | 128
150 (((::quint32)context->Message_Block[t4 + 2]) << 8) | 128
151 (((::quint32)context->Message_Block[t4 + 3]));
executed: W[t] = (((::quint32)context->Message_Block[t4]) << 24) | (((::quint32)context->Message_Block[t4 + 1]) << 16) | (((::quint32)context->Message_Block[t4 + 2]) << 8) | (((::quint32)context->Message_Block[t4 + 3]));
Execution Count:128
128
152 -
153 for (t = 16; t < 64; t++)
evaluated: t < 64
TRUEFALSE
yes
Evaluation Count:384
yes
Evaluation Count:8
8-384
154 W[t] = ((((W[t-2]) >> (17)) | ((W[t-2]) << (32-(17)))) ^ (((W[t-2]) >> (19)) | ((W[t-2]) << (32-(19)))) ^ ((W[t-2]) >> (10))) + W[t-7] + 384
155 ((((W[t-15]) >> (7)) | ((W[t-15]) << (32-(7)))) ^ (((W[t-15]) >> (18)) | ((W[t-15]) << (32-(18)))) ^ ((W[t-15]) >> (3))) + W[t-16];
executed: W[t] = ((((W[t-2]) >> (17)) | ((W[t-2]) << (32-(17)))) ^ (((W[t-2]) >> (19)) | ((W[t-2]) << (32-(19)))) ^ ((W[t-2]) >> (10))) + W[t-7] + ((((W[t-15]) >> (7)) | ((W[t-15]) << (32-(7)))) ^ (((W[t-15]) >> (18)) | ((W[t-15]) << (32-(18)))) ^ ((W[t-15]) >> (3))) + W[t-16];
Execution Count:384
384
156 -
157 A = context->Intermediate_Hash[0]; -
158 B = context->Intermediate_Hash[1]; -
159 C = context->Intermediate_Hash[2]; -
160 D = context->Intermediate_Hash[3]; -
161 E = context->Intermediate_Hash[4]; -
162 F = context->Intermediate_Hash[5]; -
163 G = context->Intermediate_Hash[6]; -
164 H = context->Intermediate_Hash[7]; -
165 -
166 for (t = 0; t < 64; t++) {
evaluated: t < 64
TRUEFALSE
yes
Evaluation Count:512
yes
Evaluation Count:8
8-512
167 temp1 = H + ((((E) >> (6)) | ((E) << (32-(6)))) ^ (((E) >> (11)) | ((E) << (32-(11)))) ^ (((E) >> (25)) | ((E) << (32-(25))))) + (((E) & (F)) ^ ((~(E)) & (G))) + K[t] + W[t]; -
168 temp2 = ((((A) >> (2)) | ((A) << (32-(2)))) ^ (((A) >> (13)) | ((A) << (32-(13)))) ^ (((A) >> (22)) | ((A) << (32-(22))))) + (((A) & (B)) ^ ((A) & (C)) ^ ((B) & (C))); -
169 H = G; -
170 G = F; -
171 F = E; -
172 E = D + temp1; -
173 D = C; -
174 C = B; -
175 B = A; -
176 A = temp1 + temp2; -
177 }
executed: }
Execution Count:512
512
178 -
179 context->Intermediate_Hash[0] += A; -
180 context->Intermediate_Hash[1] += B; -
181 context->Intermediate_Hash[2] += C; -
182 context->Intermediate_Hash[3] += D; -
183 context->Intermediate_Hash[4] += E; -
184 context->Intermediate_Hash[5] += F; -
185 context->Intermediate_Hash[6] += G; -
186 context->Intermediate_Hash[7] += H; -
187 -
188 context->Message_Block_Index = 0; -
189}
executed: }
Execution Count:8
8
190static void SHA224_256Finalize(SHA256Context *context, -
191 ::quint8 Pad_Byte) -
192{ -
193 int i; -
194 SHA224_256PadMessage(context, Pad_Byte); -
195 -
196 for (i = 0; i < SHA256_Message_Block_Size; ++i)
evaluated: i < SHA256_Message_Block_Size
TRUEFALSE
yes
Evaluation Count:512
yes
Evaluation Count:8
8-512
197 context->Message_Block[i] = 0;
executed: context->Message_Block[i] = 0;
Execution Count:512
512
198 context->Length_High = 0; -
199 context->Length_Low = 0; -
200 context->Computed = 1; -
201}
executed: }
Execution Count:8
8
202static void SHA224_256PadMessage(SHA256Context *context, -
203 ::quint8 Pad_Byte) -
204{ -
205 -
206 -
207 -
208 -
209 -
210 -
211 if (context->Message_Block_Index >= (SHA256_Message_Block_Size-8)) {
partially evaluated: context->Message_Block_Index >= (SHA256_Message_Block_Size-8)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:8
0-8
212 context->Message_Block[context->Message_Block_Index++] = Pad_Byte; -
213 while (context->Message_Block_Index < SHA256_Message_Block_Size)
never evaluated: context->Message_Block_Index < SHA256_Message_Block_Size
0
214 context->Message_Block[context->Message_Block_Index++] = 0;
never executed: context->Message_Block[context->Message_Block_Index++] = 0;
0
215 SHA224_256ProcessMessageBlock(context); -
216 } else
never executed: }
0
217 context->Message_Block[context->Message_Block_Index++] = Pad_Byte;
executed: context->Message_Block[context->Message_Block_Index++] = Pad_Byte;
Execution Count:8
8
218 -
219 while (context->Message_Block_Index < (SHA256_Message_Block_Size-8))
evaluated: context->Message_Block_Index < (SHA256_Message_Block_Size-8)
TRUEFALSE
yes
Evaluation Count:410
yes
Evaluation Count:8
8-410
220 context->Message_Block[context->Message_Block_Index++] = 0;
executed: context->Message_Block[context->Message_Block_Index++] = 0;
Execution Count:410
410
221 -
222 -
223 -
224 -
225 context->Message_Block[56] = (::quint8)(context->Length_High >> 24); -
226 context->Message_Block[57] = (::quint8)(context->Length_High >> 16); -
227 context->Message_Block[58] = (::quint8)(context->Length_High >> 8); -
228 context->Message_Block[59] = (::quint8)(context->Length_High); -
229 context->Message_Block[60] = (::quint8)(context->Length_Low >> 24); -
230 context->Message_Block[61] = (::quint8)(context->Length_Low >> 16); -
231 context->Message_Block[62] = (::quint8)(context->Length_Low >> 8); -
232 context->Message_Block[63] = (::quint8)(context->Length_Low); -
233 -
234 SHA224_256ProcessMessageBlock(context); -
235}
executed: }
Execution Count:8
8
236static int SHA224_256ResultN(SHA256Context *context, -
237 ::quint8 Message_Digest[ ], int HashSize) -
238{ -
239 int i; -
240 -
241 if (!context) return shaNull;
never executed: return shaNull;
partially evaluated: !context
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:8
0-8
242 if (!Message_Digest) return shaNull;
never executed: return shaNull;
partially evaluated: !Message_Digest
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:8
0-8
243 if (context->Corrupted) return context->Corrupted;
never executed: return context->Corrupted;
partially evaluated: context->Corrupted
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:8
0-8
244 -
245 if (!context->Computed)
partially evaluated: !context->Computed
TRUEFALSE
yes
Evaluation Count:8
no
Evaluation Count:0
0-8
246 SHA224_256Finalize(context, 0x80);
executed: SHA224_256Finalize(context, 0x80);
Execution Count:8
8
247 -
248 for (i = 0; i < HashSize; ++i)
evaluated: i < HashSize
TRUEFALSE
yes
Evaluation Count:240
yes
Evaluation Count:8
8-240
249 Message_Digest[i] = (::quint8) 240
250 (context->Intermediate_Hash[i>>2] >> 8 * ( 3 - ( i & 0x03 ) ));
executed: Message_Digest[i] = (::quint8) (context->Intermediate_Hash[i>>2] >> 8 * ( 3 - ( i & 0x03 ) ));
Execution Count:240
240
251 -
252 return shaSuccess;
executed: return shaSuccess;
Execution Count:8
8
253} -
254 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial