tools/../../3rdparty/rfc6234/sha384-512.c

Switch to Source codePreprocessed file
LineSource CodeCoverage
1static int SHA384_512Reset(SHA512Context *context, -
2 ::quint64 H0[SHA512HashSize/8]); -
3static void SHA384_512ProcessMessageBlock(SHA512Context *context); -
4static void SHA384_512Finalize(SHA512Context *context, -
5 ::quint8 Pad_Byte); -
6static void SHA384_512PadMessage(SHA512Context *context, -
7 ::quint8 Pad_Byte); -
8static int SHA384_512ResultN(SHA512Context *context, -
9 ::quint8 Message_Digest[ ], int HashSize); -
10 -
11 -
12static ::quint64 SHA384_H0[ ] = { -
13 0xCBBB9D5DC1059ED8ll, 0x629A292A367CD507ll, 0x9159015A3070DD17ll, -
14 0x152FECD8F70E5939ll, 0x67332667FFC00B31ll, 0x8EB44A8768581511ll, -
15 0xDB0C2E0D64F98FA7ll, 0x47B5481DBEFA4FA4ll -
16}; -
17static ::quint64 SHA512_H0[ ] = { -
18 0x6A09E667F3BCC908ll, 0xBB67AE8584CAA73Bll, 0x3C6EF372FE94F82Bll, -
19 0xA54FF53A5F1D36F1ll, 0x510E527FADE682D1ll, 0x9B05688C2B3E6C1Fll, -
20 0x1F83D9ABFB41BD6Bll, 0x5BE0CD19137E2179ll -
21}; -
22int SHA384Reset(SHA384Context *context) -
23{ -
24 return SHA384_512Reset(context, SHA384_H0);
executed: return SHA384_512Reset(context, SHA384_H0);
Execution Count:4
4
25} -
26int SHA384Input(SHA384Context *context, -
27 const ::quint8 *message_array, unsigned int length) -
28{ -
29 return SHA512Input(context, message_array, length);
executed: return SHA512Input(context, message_array, length);
Execution Count:4
4
30} -
31int SHA384FinalBits(SHA384Context *context, -
32 ::quint8 message_bits, unsigned int length) -
33{ -
34 return SHA512FinalBits(context, message_bits, length);
never executed: return SHA512FinalBits(context, message_bits, length);
0
35} -
36int SHA384Result(SHA384Context *context, -
37 ::quint8 Message_Digest[SHA384HashSize]) -
38{ -
39 return SHA384_512ResultN(context, Message_Digest, SHA384HashSize);
executed: return SHA384_512ResultN(context, Message_Digest, SHA384HashSize);
Execution Count:4
4
40} -
41int SHA512Reset(SHA512Context *context) -
42{ -
43 return SHA384_512Reset(context, SHA512_H0);
executed: return SHA384_512Reset(context, SHA512_H0);
Execution Count:4
4
44} -
45int SHA512Input(SHA512Context *context, -
46 const ::quint8 *message_array, -
47 unsigned int length) -
48{ -
49 if (!context) return shaNull;
partially evaluated: !context
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:8
never executed: return shaNull;
0-8
50 if (!length) return shaSuccess;
partially evaluated: !length
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:8
never executed: return shaSuccess;
0-8
51 if (!message_array) return shaNull;
partially evaluated: !message_array
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:8
never executed: return shaNull;
0-8
52 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
53 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
54 -
55 while (length--) {
evaluated: length--
TRUEFALSE
yes
Evaluation Count:24
yes
Evaluation Count:8
8-24
56 context->Message_Block[context->Message_Block_Index++] = -
57 *message_array; -
58 -
59 if ((SHA384_512AddLength(context, 8) == shaSuccess) &&
partially evaluated: (SHA384_512AddLength(context, 8) == shaSuccess)
TRUEFALSE
yes
Evaluation Count:24
no
Evaluation Count:0
0-24
60 (context->Message_Block_Index == SHA512_Message_Block_Size))
partially evaluated: (context->Message_Block_Index == SHA512_Message_Block_Size)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:24
0-24
61 SHA384_512ProcessMessageBlock(context);
never executed: SHA384_512ProcessMessageBlock(context);
0
62 -
63 message_array++; -
64 }
executed: }
Execution Count:24
24
65 -
66 return context->Corrupted;
executed: return context->Corrupted;
Execution Count:8
8
67} -
68int SHA512FinalBits(SHA512Context *context, -
69 ::quint8 message_bits, unsigned int length) -
70{ -
71 static ::quint8 masks[8] = { -
72 0x00, 0x80, -
73 0xC0, 0xE0, -
74 0xF0, 0xF8, -
75 0xFC, 0xFE -
76 }; -
77 static ::quint8 markbit[8] = { -
78 0x80, 0x40, -
79 0x20, 0x10, -
80 0x08, 0x04, -
81 0x02, 0x01 -
82 }; -
83 -
84 if (!context) return shaNull;
never executed: return shaNull;
never evaluated: !context
0
85 if (!length) return shaSuccess;
never executed: return shaSuccess;
never evaluated: !length
0
86 if (context->Corrupted) return context->Corrupted;
never executed: return context->Corrupted;
never evaluated: context->Corrupted
0
87 if (context->Computed) return context->Corrupted = shaStateError;
never executed: return context->Corrupted = shaStateError;
never evaluated: context->Computed
0
88 if (length >= 8) return context->Corrupted = shaBadParam;
never executed: return context->Corrupted = shaBadParam;
never evaluated: length >= 8
0
89 -
90 SHA384_512AddLength(context, length); -
91 SHA384_512Finalize(context, (::quint8) -
92 ((message_bits & masks[length]) | markbit[length])); -
93 -
94 return context->Corrupted;
never executed: return context->Corrupted;
0
95} -
96int SHA512Result(SHA512Context *context, -
97 ::quint8 Message_Digest[SHA512HashSize]) -
98{ -
99 return SHA384_512ResultN(context, Message_Digest, SHA512HashSize);
executed: return SHA384_512ResultN(context, Message_Digest, SHA512HashSize);
Execution Count:4
4
100} -
101static int SHA384_512Reset(SHA512Context *context, -
102 ::quint64 H0[SHA512HashSize/8]) -
103 -
104{ -
105 int i; -
106 if (!context) return shaNull;
never executed: return shaNull;
partially evaluated: !context
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:8
0-8
107 -
108 context->Message_Block_Index = 0; -
109 context->Length_High = context->Length_Low = 0; -
110 -
111 for (i = 0; i < SHA512HashSize/8; i++)
evaluated: i < SHA512HashSize/8
TRUEFALSE
yes
Evaluation Count:64
yes
Evaluation Count:8
8-64
112 context->Intermediate_Hash[i] = H0[i];
executed: context->Intermediate_Hash[i] = H0[i];
Execution Count:64
64
113 -
114 -
115 context->Computed = 0; -
116 context->Corrupted = shaSuccess; -
117 -
118 return shaSuccess;
executed: return shaSuccess;
Execution Count:8
8
119} -
120static void SHA384_512ProcessMessageBlock(SHA512Context *context) -
121{ -
122 static const ::quint64 K[80] = { -
123 0x428A2F98D728AE22ll, 0x7137449123EF65CDll, 0xB5C0FBCFEC4D3B2Fll, -
124 0xE9B5DBA58189DBBCll, 0x3956C25BF348B538ll, 0x59F111F1B605D019ll, -
125 0x923F82A4AF194F9Bll, 0xAB1C5ED5DA6D8118ll, 0xD807AA98A3030242ll, -
126 0x12835B0145706FBEll, 0x243185BE4EE4B28Cll, 0x550C7DC3D5FFB4E2ll, -
127 0x72BE5D74F27B896Fll, 0x80DEB1FE3B1696B1ll, 0x9BDC06A725C71235ll, -
128 0xC19BF174CF692694ll, 0xE49B69C19EF14AD2ll, 0xEFBE4786384F25E3ll, -
129 0x0FC19DC68B8CD5B5ll, 0x240CA1CC77AC9C65ll, 0x2DE92C6F592B0275ll, -
130 0x4A7484AA6EA6E483ll, 0x5CB0A9DCBD41FBD4ll, 0x76F988DA831153B5ll, -
131 0x983E5152EE66DFABll, 0xA831C66D2DB43210ll, 0xB00327C898FB213Fll, -
132 0xBF597FC7BEEF0EE4ll, 0xC6E00BF33DA88FC2ll, 0xD5A79147930AA725ll, -
133 0x06CA6351E003826Fll, 0x142929670A0E6E70ll, 0x27B70A8546D22FFCll, -
134 0x2E1B21385C26C926ll, 0x4D2C6DFC5AC42AEDll, 0x53380D139D95B3DFll, -
135 0x650A73548BAF63DEll, 0x766A0ABB3C77B2A8ll, 0x81C2C92E47EDAEE6ll, -
136 0x92722C851482353Bll, 0xA2BFE8A14CF10364ll, 0xA81A664BBC423001ll, -
137 0xC24B8B70D0F89791ll, 0xC76C51A30654BE30ll, 0xD192E819D6EF5218ll, -
138 0xD69906245565A910ll, 0xF40E35855771202All, 0x106AA07032BBD1B8ll, -
139 0x19A4C116B8D2D0C8ll, 0x1E376C085141AB53ll, 0x2748774CDF8EEB99ll, -
140 0x34B0BCB5E19B48A8ll, 0x391C0CB3C5C95A63ll, 0x4ED8AA4AE3418ACBll, -
141 0x5B9CCA4F7763E373ll, 0x682E6FF3D6B2B8A3ll, 0x748F82EE5DEFB2FCll, -
142 0x78A5636F43172F60ll, 0x84C87814A1F0AB72ll, 0x8CC702081A6439ECll, -
143 0x90BEFFFA23631E28ll, 0xA4506CEBDE82BDE9ll, 0xBEF9A3F7B2C67915ll, -
144 0xC67178F2E372532Bll, 0xCA273ECEEA26619Cll, 0xD186B8C721C0C207ll, -
145 0xEADA7DD6CDE0EB1Ell, 0xF57D4F7FEE6ED178ll, 0x06F067AA72176FBAll, -
146 0x0A637DC5A2C898A6ll, 0x113F9804BEF90DAEll, 0x1B710B35131C471Bll, -
147 0x28DB77F523047D84ll, 0x32CAAB7B40C72493ll, 0x3C9EBE0A15C9BEBCll, -
148 0x431D67C49C100D4Cll, 0x4CC5D4BECB3E42B6ll, 0x597F299CFC657E2All, -
149 0x5FCB6FAB3AD6FAECll, 0x6C44198C4A475817ll -
150 }; -
151 int t, t8; -
152 ::quint64 temp1, temp2; -
153 ::quint64 W[80]; -
154 ::quint64 A, B, C, D, E, F, G, H; -
155 -
156 -
157 -
158 -
159 for (t = t8 = 0; t < 16; t++, t8 += 8)
evaluated: t < 16
TRUEFALSE
yes
Evaluation Count:128
yes
Evaluation Count:8
8-128
160 W[t] = ((::quint64)(context->Message_Block[t8 ]) << 56) | 128
161 ((::quint64)(context->Message_Block[t8 + 1]) << 48) | 128
162 ((::quint64)(context->Message_Block[t8 + 2]) << 40) | 128
163 ((::quint64)(context->Message_Block[t8 + 3]) << 32) | 128
164 ((::quint64)(context->Message_Block[t8 + 4]) << 24) | 128
165 ((::quint64)(context->Message_Block[t8 + 5]) << 16) | 128
166 ((::quint64)(context->Message_Block[t8 + 6]) << 8) | 128
167 ((::quint64)(context->Message_Block[t8 + 7]));
executed: W[t] = ((::quint64)(context->Message_Block[t8 ]) << 56) | ((::quint64)(context->Message_Block[t8 + 1]) << 48) | ((::quint64)(context->Message_Block[t8 + 2]) << 40) | ((::quint64)(context->Message_Block[t8 + 3]) << 32) | ((::quint64)(context->Message_Block[t8 + 4]) << 24) | ((::quint64)(context->Message_Block[t8 + 5]) << 16) | ((::quint64)(context->Message_Block[t8 + 6]) << 8) | ((::quint64)(context->Message_Block[t8 + 7]));
Execution Count:128
128
168 -
169 for (t = 16; t < 80; t++)
evaluated: t < 80
TRUEFALSE
yes
Evaluation Count:512
yes
Evaluation Count:8
8-512
170 W[t] = (((((::quint64)(W[t-2])) >> (19)) | (((::quint64)(W[t-2])) << (64-(19)))) ^ ((((::quint64)(W[t-2])) >> (61)) | (((::quint64)(W[t-2])) << (64-(61)))) ^ (((::quint64)(W[t-2])) >> (6))) + W[t-7] + 512
171 (((((::quint64)(W[t-15])) >> (1)) | (((::quint64)(W[t-15])) << (64-(1)))) ^ ((((::quint64)(W[t-15])) >> (8)) | (((::quint64)(W[t-15])) << (64-(8)))) ^ (((::quint64)(W[t-15])) >> (7))) + W[t-16];
executed: W[t] = (((((::quint64)(W[t-2])) >> (19)) | (((::quint64)(W[t-2])) << (64-(19)))) ^ ((((::quint64)(W[t-2])) >> (61)) | (((::quint64)(W[t-2])) << (64-(61)))) ^ (((::quint64)(W[t-2])) >> (6))) + W[t-7] + (((((::quint64)(W[t-15])) >> (1)) | (((::quint64)(W[t-15])) << (64-(1)))) ^ ((((::quint64)(W[t-15])) >> (8)) | (((::quint64)(W[t-15])) << (64-(8)))) ^ (((::quint64)(W[t-15])) >> (7))) + W[t-16];
Execution Count:512
512
172 A = context->Intermediate_Hash[0]; -
173 B = context->Intermediate_Hash[1]; -
174 C = context->Intermediate_Hash[2]; -
175 D = context->Intermediate_Hash[3]; -
176 E = context->Intermediate_Hash[4]; -
177 F = context->Intermediate_Hash[5]; -
178 G = context->Intermediate_Hash[6]; -
179 H = context->Intermediate_Hash[7]; -
180 -
181 for (t = 0; t < 80; t++) {
evaluated: t < 80
TRUEFALSE
yes
Evaluation Count:640
yes
Evaluation Count:8
8-640
182 temp1 = H + (((((::quint64)(E)) >> (14)) | (((::quint64)(E)) << (64-(14)))) ^ ((((::quint64)(E)) >> (18)) | (((::quint64)(E)) << (64-(18)))) ^ ((((::quint64)(E)) >> (41)) | (((::quint64)(E)) << (64-(41))))) + (((E) & (F)) ^ ((~(E)) & (G))) + K[t] + W[t]; -
183 temp2 = (((((::quint64)(A)) >> (28)) | (((::quint64)(A)) << (64-(28)))) ^ ((((::quint64)(A)) >> (34)) | (((::quint64)(A)) << (64-(34)))) ^ ((((::quint64)(A)) >> (39)) | (((::quint64)(A)) << (64-(39))))) + (((A) & (B)) ^ ((A) & (C)) ^ ((B) & (C))); -
184 H = G; -
185 G = F; -
186 F = E; -
187 E = D + temp1; -
188 D = C; -
189 C = B; -
190 B = A; -
191 A = temp1 + temp2; -
192 }
executed: }
Execution Count:640
640
193 -
194 context->Intermediate_Hash[0] += A; -
195 context->Intermediate_Hash[1] += B; -
196 context->Intermediate_Hash[2] += C; -
197 context->Intermediate_Hash[3] += D; -
198 context->Intermediate_Hash[4] += E; -
199 context->Intermediate_Hash[5] += F; -
200 context->Intermediate_Hash[6] += G; -
201 context->Intermediate_Hash[7] += H; -
202 -
203 -
204 context->Message_Block_Index = 0; -
205}
executed: }
Execution Count:8
8
206static void SHA384_512Finalize(SHA512Context *context, -
207 ::quint8 Pad_Byte) -
208{ -
209 ::qint16 i; -
210 SHA384_512PadMessage(context, Pad_Byte); -
211 -
212 for (i = 0; i < SHA512_Message_Block_Size; ++i)
evaluated: i < SHA512_Message_Block_Size
TRUEFALSE
yes
Evaluation Count:1024
yes
Evaluation Count:8
8-1024
213 context->Message_Block[i] = 0;
executed: context->Message_Block[i] = 0;
Execution Count:1024
1024
214 -
215 -
216 -
217 -
218 context->Length_High = context->Length_Low = 0; -
219 -
220 context->Computed = 1; -
221}
executed: }
Execution Count:8
8
222static void SHA384_512PadMessage(SHA512Context *context, -
223 ::quint8 Pad_Byte) -
224{ -
225 -
226 -
227 -
228 -
229 -
230 -
231 if (context->Message_Block_Index >= (SHA512_Message_Block_Size-16)) {
partially evaluated: context->Message_Block_Index >= (SHA512_Message_Block_Size-16)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:8
0-8
232 context->Message_Block[context->Message_Block_Index++] = Pad_Byte; -
233 while (context->Message_Block_Index < SHA512_Message_Block_Size)
never evaluated: context->Message_Block_Index < SHA512_Message_Block_Size
0
234 context->Message_Block[context->Message_Block_Index++] = 0;
never executed: context->Message_Block[context->Message_Block_Index++] = 0;
0
235 -
236 SHA384_512ProcessMessageBlock(context); -
237 } else
never executed: }
0
238 context->Message_Block[context->Message_Block_Index++] = Pad_Byte;
executed: context->Message_Block[context->Message_Block_Index++] = Pad_Byte;
Execution Count:8
8
239 -
240 while (context->Message_Block_Index < (SHA512_Message_Block_Size-16))
evaluated: context->Message_Block_Index < (SHA512_Message_Block_Size-16)
TRUEFALSE
yes
Evaluation Count:858
yes
Evaluation Count:8
8-858
241 context->Message_Block[context->Message_Block_Index++] = 0;
executed: context->Message_Block[context->Message_Block_Index++] = 0;
Execution Count:858
858
242 context->Message_Block[112] = (::quint8)(context->Length_High >> 56); -
243 context->Message_Block[113] = (::quint8)(context->Length_High >> 48); -
244 context->Message_Block[114] = (::quint8)(context->Length_High >> 40); -
245 context->Message_Block[115] = (::quint8)(context->Length_High >> 32); -
246 context->Message_Block[116] = (::quint8)(context->Length_High >> 24); -
247 context->Message_Block[117] = (::quint8)(context->Length_High >> 16); -
248 context->Message_Block[118] = (::quint8)(context->Length_High >> 8); -
249 context->Message_Block[119] = (::quint8)(context->Length_High); -
250 -
251 context->Message_Block[120] = (::quint8)(context->Length_Low >> 56); -
252 context->Message_Block[121] = (::quint8)(context->Length_Low >> 48); -
253 context->Message_Block[122] = (::quint8)(context->Length_Low >> 40); -
254 context->Message_Block[123] = (::quint8)(context->Length_Low >> 32); -
255 context->Message_Block[124] = (::quint8)(context->Length_Low >> 24); -
256 context->Message_Block[125] = (::quint8)(context->Length_Low >> 16); -
257 context->Message_Block[126] = (::quint8)(context->Length_Low >> 8); -
258 context->Message_Block[127] = (::quint8)(context->Length_Low); -
259 -
260 -
261 SHA384_512ProcessMessageBlock(context); -
262}
executed: }
Execution Count:8
8
263static int SHA384_512ResultN(SHA512Context *context, -
264 ::quint8 Message_Digest[ ], int HashSize) -
265{ -
266 int i; -
267 -
268 -
269 -
270 -
271 if (!context) return shaNull;
never executed: return shaNull;
partially evaluated: !context
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:8
0-8
272 if (!Message_Digest) return shaNull;
never executed: return shaNull;
partially evaluated: !Message_Digest
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:8
0-8
273 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
274 -
275 if (!context->Computed)
partially evaluated: !context->Computed
TRUEFALSE
yes
Evaluation Count:8
no
Evaluation Count:0
0-8
276 SHA384_512Finalize(context, 0x80);
executed: SHA384_512Finalize(context, 0x80);
Execution Count:8
8
277 for (i = 0; i < HashSize; ++i)
evaluated: i < HashSize
TRUEFALSE
yes
Evaluation Count:448
yes
Evaluation Count:8
8-448
278 Message_Digest[i] = (::quint8) 448
279 (context->Intermediate_Hash[i>>3] >> 8 * ( 7 - ( i % 8 ) ));
executed: Message_Digest[i] = (::quint8) (context->Intermediate_Hash[i>>3] >> 8 * ( 7 - ( i % 8 ) ));
Execution Count:448
448
280 -
281 -
282 return shaSuccess;
executed: return shaSuccess;
Execution Count:8
8
283} -
284 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial