tools/../../3rdparty/sha1/sha1.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
1 -
2 -
3 -
4 -
5 -
6 -
7struct Sha1State -
8{ -
9 quint32 h0; -
10 quint32 h1; -
11 quint32 h2; -
12 quint32 h3; -
13 quint32 h4; -
14 -
15 quint64 messageSize; -
16 unsigned char buffer[64]; -
17}; -
18 -
19 -
20typedef union -
21{ -
22 quint8 bytes[64]; -
23 quint32 words[16]; -
24} Sha1Chunk; -
25 -
26static inline quint32 rol32(quint32 value, unsigned int shift) -
27{ -
28 -
29 -
30 -
31 return ((value << shift) | (value >> (32 - shift)));
executed: return ((value << shift) | (value >> (32 - shift)));
Execution Count:3638656
3638656
32 -
33} -
34 -
35static inline quint32 sha1Word(Sha1Chunk *chunk, const uint position) -
36{ -
37 return (chunk->words[position & 0xf] = rol32( chunk->words[(position+13) & 0xf] 1039616
38 ^ chunk->words[(position+ 8) & 0xf] 1039616
39 ^ chunk->words[(position+ 2) & 0xf] 1039616
40 ^ chunk->words[(position) & 0xf], 1));
executed: return (chunk->words[position & 0xf] = rol32( chunk->words[(position+13) & 0xf] ^ chunk->words[(position+ 8) & 0xf] ^ chunk->words[(position+ 2) & 0xf] ^ chunk->words[(position) & 0xf], 1));
Execution Count:1039616
1039616
41} -
42 -
43static inline void sha1Round0(Sha1Chunk *chunk, const uint position, -
44 quint32 &v, quint32 &w, quint32 &x, quint32 &y, quint32 &z) -
45{ -
46 z += ((( w & (x ^ y)) ^ y) + chunk->words[position] + 0x5A827999 + rol32(v, 5)); -
47 w = rol32(w, 30); -
48}
executed: }
Execution Count:259904
259904
49 -
50static inline void sha1Round1(Sha1Chunk *chunk, const uint position, -
51 quint32 &v, quint32 &w, quint32 &x, quint32 &y, quint32 &z) -
52{ -
53 z += ((( w & (x ^ y)) ^ y) + sha1Word(chunk,position) + 0x5A827999 + rol32(v, 5)); -
54 w = rol32(w, 30); -
55}
executed: }
Execution Count:64976
64976
56 -
57static inline void sha1Round2(Sha1Chunk *chunk, const uint position, -
58 quint32 &v, quint32 &w, quint32 &x, quint32 &y, quint32 &z) -
59{ -
60 z += (( w ^ x ^ y) + sha1Word(chunk, position) + 0x6ED9EBA1 + rol32(v, 5)); -
61 w = rol32(w, 30); -
62}
executed: }
Execution Count:324880
324880
63 -
64static inline void sha1Round3(Sha1Chunk *chunk, const uint position, -
65 quint32 &v, quint32 &w, quint32 &x, quint32 &y, quint32 &z) -
66{ -
67 z += (((( w | x) & y) | (w & x)) + sha1Word(chunk, position) + 0x8F1BBCDC + rol32(v, 5)); -
68 w = rol32(w, 30); -
69}
executed: }
Execution Count:324880
324880
70 -
71static inline void sha1Round4(Sha1Chunk *chunk, const uint position, -
72 quint32 &v, quint32 &w, quint32 &x, quint32 &y, quint32 &z) -
73{ -
74 z += ((w ^ x ^ y) + sha1Word(chunk, position) + 0xCA62C1D6 + rol32(v, 5)); -
75 w = rol32(w, 30); -
76}
executed: }
Execution Count:324880
324880
77 -
78static inline void sha1ProcessChunk(Sha1State *state, const unsigned char *buffer) -
79{ -
80 -
81 quint32 a = state->h0; -
82 quint32 b = state->h1; -
83 quint32 c = state->h2; -
84 quint32 d = state->h3; -
85 quint32 e = state->h4; -
86 -
87 quint8 chunkBuffer[64]; -
88 memcpy(chunkBuffer, buffer, 64); -
89 -
90 Sha1Chunk *chunk = reinterpret_cast<Sha1Chunk*>(&chunkBuffer); -
91 -
92 for (int i = 0; i < 16; ++i)
evaluated: i < 16
TRUEFALSE
yes
Evaluation Count:259904
yes
Evaluation Count:16244
16244-259904
93 chunk->words[i] = qFromBigEndian(chunk->words[i]);
executed: chunk->words[i] = qFromBigEndian(chunk->words[i]);
Execution Count:259904
259904
94 -
95 sha1Round0(chunk, 0, a,b,c,d,e); sha1Round0(chunk, 1, e,a,b,c,d); sha1Round0(chunk, 2, d,e,a,b,c); sha1Round0(chunk, 3, c,d,e,a,b); -
96 sha1Round0(chunk, 4, b,c,d,e,a); sha1Round0(chunk, 5, a,b,c,d,e); sha1Round0(chunk, 6, e,a,b,c,d); sha1Round0(chunk, 7, d,e,a,b,c); -
97 sha1Round0(chunk, 8, c,d,e,a,b); sha1Round0(chunk, 9, b,c,d,e,a); sha1Round0(chunk, 10, a,b,c,d,e); sha1Round0(chunk, 11, e,a,b,c,d); -
98 sha1Round0(chunk, 12, d,e,a,b,c); sha1Round0(chunk, 13, c,d,e,a,b); sha1Round0(chunk, 14, b,c,d,e,a); sha1Round0(chunk, 15, a,b,c,d,e); -
99 sha1Round1(chunk, 16, e,a,b,c,d); sha1Round1(chunk, 17, d,e,a,b,c); sha1Round1(chunk, 18, c,d,e,a,b); sha1Round1(chunk, 19, b,c,d,e,a); -
100 sha1Round2(chunk, 20, a,b,c,d,e); sha1Round2(chunk, 21, e,a,b,c,d); sha1Round2(chunk, 22, d,e,a,b,c); sha1Round2(chunk, 23, c,d,e,a,b); -
101 sha1Round2(chunk, 24, b,c,d,e,a); sha1Round2(chunk, 25, a,b,c,d,e); sha1Round2(chunk, 26, e,a,b,c,d); sha1Round2(chunk, 27, d,e,a,b,c); -
102 sha1Round2(chunk, 28, c,d,e,a,b); sha1Round2(chunk, 29, b,c,d,e,a); sha1Round2(chunk, 30, a,b,c,d,e); sha1Round2(chunk, 31, e,a,b,c,d); -
103 sha1Round2(chunk, 32, d,e,a,b,c); sha1Round2(chunk, 33, c,d,e,a,b); sha1Round2(chunk, 34, b,c,d,e,a); sha1Round2(chunk, 35, a,b,c,d,e); -
104 sha1Round2(chunk, 36, e,a,b,c,d); sha1Round2(chunk, 37, d,e,a,b,c); sha1Round2(chunk, 38, c,d,e,a,b); sha1Round2(chunk, 39, b,c,d,e,a); -
105 sha1Round3(chunk, 40, a,b,c,d,e); sha1Round3(chunk, 41, e,a,b,c,d); sha1Round3(chunk, 42, d,e,a,b,c); sha1Round3(chunk, 43, c,d,e,a,b); -
106 sha1Round3(chunk, 44, b,c,d,e,a); sha1Round3(chunk, 45, a,b,c,d,e); sha1Round3(chunk, 46, e,a,b,c,d); sha1Round3(chunk, 47, d,e,a,b,c); -
107 sha1Round3(chunk, 48, c,d,e,a,b); sha1Round3(chunk, 49, b,c,d,e,a); sha1Round3(chunk, 50, a,b,c,d,e); sha1Round3(chunk, 51, e,a,b,c,d); -
108 sha1Round3(chunk, 52, d,e,a,b,c); sha1Round3(chunk, 53, c,d,e,a,b); sha1Round3(chunk, 54, b,c,d,e,a); sha1Round3(chunk, 55, a,b,c,d,e); -
109 sha1Round3(chunk, 56, e,a,b,c,d); sha1Round3(chunk, 57, d,e,a,b,c); sha1Round3(chunk, 58, c,d,e,a,b); sha1Round3(chunk, 59, b,c,d,e,a); -
110 sha1Round4(chunk, 60, a,b,c,d,e); sha1Round4(chunk, 61, e,a,b,c,d); sha1Round4(chunk, 62, d,e,a,b,c); sha1Round4(chunk, 63, c,d,e,a,b); -
111 sha1Round4(chunk, 64, b,c,d,e,a); sha1Round4(chunk, 65, a,b,c,d,e); sha1Round4(chunk, 66, e,a,b,c,d); sha1Round4(chunk, 67, d,e,a,b,c); -
112 sha1Round4(chunk, 68, c,d,e,a,b); sha1Round4(chunk, 69, b,c,d,e,a); sha1Round4(chunk, 70, a,b,c,d,e); sha1Round4(chunk, 71, e,a,b,c,d); -
113 sha1Round4(chunk, 72, d,e,a,b,c); sha1Round4(chunk, 73, c,d,e,a,b); sha1Round4(chunk, 74, b,c,d,e,a); sha1Round4(chunk, 75, a,b,c,d,e); -
114 sha1Round4(chunk, 76, e,a,b,c,d); sha1Round4(chunk, 77, d,e,a,b,c); sha1Round4(chunk, 78, c,d,e,a,b); sha1Round4(chunk, 79, b,c,d,e,a); -
115 -
116 -
117 state->h0 += a; -
118 state->h1 += b; -
119 state->h2 += c; -
120 state->h3 += d; -
121 state->h4 += e; -
122 -
123 -
124 -
125 a = b = c = d = e = 0; -
126 memset(chunkBuffer, 0, 64); -
127 -
128}
executed: }
Execution Count:16244
16244
129 -
130static inline void sha1InitState(Sha1State *state) -
131{ -
132 state->h0 = 0x67452301; -
133 state->h1 = 0xEFCDAB89; -
134 state->h2 = 0x98BADCFE; -
135 state->h3 = 0x10325476; -
136 state->h4 = 0xC3D2E1F0; -
137 -
138 state->messageSize = 0; -
139}
executed: }
Execution Count:361
361
140 -
141static inline void sha1Update(Sha1State *state, const unsigned char *data, qint64 len) -
142{ -
143 quint32 rest = static_cast<quint32>(state->messageSize & static_cast<unsigned long long>(63ULL)); -
144 -
145 quint64 availableData = static_cast<quint64>(len) + static_cast<quint64>(rest); -
146 state->messageSize += len; -
147 -
148 if (availableData < static_cast<unsigned long long>(64ULL)) {
evaluated: availableData < static_cast<unsigned long long>(64ULL)
TRUEFALSE
yes
Evaluation Count:855
yes
Evaluation Count:592
592-855
149 memcpy(&state->buffer[rest], &data[0], len); -
150 -
151 } else {
executed: }
Execution Count:855
855
152 qint64 i = static_cast<qint64>(64 - rest); -
153 memcpy(&state->buffer[rest], &data[0], static_cast<qint32>(i)); -
154 sha1ProcessChunk(state, state->buffer); -
155 -
156 qint64 lastI = len - ((len + rest) & static_cast<long long>(63LL)); -
157 for( ; i < lastI; i += 64)
evaluated: i < lastI
TRUEFALSE
yes
Evaluation Count:15652
yes
Evaluation Count:592
592-15652
158 sha1ProcessChunk(state, &data[i]);
executed: sha1ProcessChunk(state, &data[i]);
Execution Count:15652
15652
159 -
160 memcpy(&state->buffer[0], &data[i], len - i); -
161 }
executed: }
Execution Count:592
592
162} -
163 -
164static inline void sha1FinalizeState(Sha1State *state) -
165{ -
166 quint64 messageSize = state->messageSize; -
167 unsigned char sizeInBits[8]; -
168 qToBigEndian(messageSize << 3, sizeInBits); -
169 -
170 sha1Update(state, (const unsigned char *)"\200", 1); -
171 -
172 unsigned char zero[64]; -
173 memset(zero, 0, 64); -
174 if (static_cast<int>(messageSize & 63) > 56 - 1) {
evaluated: static_cast<int>(messageSize & 63) > 56 - 1
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:360
1-360
175 sha1Update(state, zero, 64 - 1 - static_cast<int>(messageSize & 63)); -
176 sha1Update(state, zero, 64 - 8); -
177 } else {
executed: }
Execution Count:1
1
178 sha1Update(state, zero, 64 - 1 - 8 - static_cast<int>(messageSize & 63)); -
179 }
executed: }
Execution Count:360
360
180 -
181 sha1Update(state, sizeInBits, 8); -
182 -
183 memset(state->buffer, 0, 64); -
184 memset(zero, 0, 64); -
185 state->messageSize = 0; -
186 -
187}
executed: }
Execution Count:361
361
188 -
189static inline void sha1ToHash(Sha1State *state, unsigned char* buffer) -
190{ -
191 qToBigEndian(state->h0, buffer); -
192 qToBigEndian(state->h1, buffer + 4); -
193 qToBigEndian(state->h2, buffer + 8); -
194 qToBigEndian(state->h3, buffer + 12); -
195 qToBigEndian(state->h4, buffer + 16); -
196}
executed: }
Execution Count:361
361
197 -
198 -
199 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial