Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/libressl/src/crypto/poly1305/poly1305-donna.c |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||
2 | - | |||||||||||||
3 | - | |||||||||||||
4 | - | |||||||||||||
5 | - | |||||||||||||
6 | - | |||||||||||||
7 | - | |||||||||||||
8 | - | |||||||||||||
9 | static inline void poly1305_init(poly1305_context *ctx, | - | ||||||||||||
10 | const unsigned char key[32]); | - | ||||||||||||
11 | static inline void poly1305_update(poly1305_context *ctx, | - | ||||||||||||
12 | const unsigned char *m, size_t bytes); | - | ||||||||||||
13 | static inline void poly1305_finish(poly1305_context *ctx, | - | ||||||||||||
14 | unsigned char mac[16]); | - | ||||||||||||
15 | typedef struct poly1305_state_internal_t { | - | ||||||||||||
16 | unsigned long r[5]; | - | ||||||||||||
17 | unsigned long h[5]; | - | ||||||||||||
18 | unsigned long pad[4]; | - | ||||||||||||
19 | size_t leftover; | - | ||||||||||||
20 | unsigned char buffer[16]; | - | ||||||||||||
21 | unsigned char final; | - | ||||||||||||
22 | } poly1305_state_internal_t; | - | ||||||||||||
23 | - | |||||||||||||
24 | - | |||||||||||||
25 | static unsigned long | - | ||||||||||||
26 | U8TO32(const unsigned char *p) | - | ||||||||||||
27 | { | - | ||||||||||||
28 | return executed 22834 times by 4 tests: (((unsigned long)(p[0] & 0xff)) |return (((unsigned long)(p[0] & 0xff)) | ((unsigned long)(p[1] & 0xff) << 8) | ((unsigned long)(p[2] & 0xff) << 16) | ((unsigned long)(p[3] & 0xff) << 24)); Executed by:
executed 22834 times by 4 tests: return (((unsigned long)(p[0] & 0xff)) | ((unsigned long)(p[1] & 0xff) << 8) | ((unsigned long)(p[2] & 0xff) << 16) | ((unsigned long)(p[3] & 0xff) << 24)); Executed by:
| 22834 | ||||||||||||
29 | ((unsigned long)(p[1] & 0xff) << 8) | executed 22834 times by 4 tests: return (((unsigned long)(p[0] & 0xff)) | ((unsigned long)(p[1] & 0xff) << 8) | ((unsigned long)(p[2] & 0xff) << 16) | ((unsigned long)(p[3] & 0xff) << 24)); Executed by:
| 22834 | ||||||||||||
30 | ((unsigned long)(p[2] & 0xff) << 16) | executed 22834 times by 4 tests: return (((unsigned long)(p[0] & 0xff)) | ((unsigned long)(p[1] & 0xff) << 8) | ((unsigned long)(p[2] & 0xff) << 16) | ((unsigned long)(p[3] & 0xff) << 24)); Executed by:
| 22834 | ||||||||||||
31 | ((unsigned long)(p[3] & 0xff) << 24)); executed 22834 times by 4 tests: return (((unsigned long)(p[0] & 0xff)) | ((unsigned long)(p[1] & 0xff) << 8) | ((unsigned long)(p[2] & 0xff) << 16) | ((unsigned long)(p[3] & 0xff) << 24)); Executed by:
| 22834 | ||||||||||||
32 | } | - | ||||||||||||
33 | - | |||||||||||||
34 | - | |||||||||||||
35 | static void | - | ||||||||||||
36 | U32TO8(unsigned char *p, unsigned long v) | - | ||||||||||||
37 | { | - | ||||||||||||
38 | p[0] = (v) & 0xff; | - | ||||||||||||
39 | p[1] = (v >> 8) & 0xff; | - | ||||||||||||
40 | p[2] = (v >> 16) & 0xff; | - | ||||||||||||
41 | p[3] = (v >> 24) & 0xff; | - | ||||||||||||
42 | } executed 1704 times by 4 tests: end of block Executed by:
| 1704 | ||||||||||||
43 | - | |||||||||||||
44 | static inline void | - | ||||||||||||
45 | poly1305_init(poly1305_context *ctx, const unsigned char key[32]) | - | ||||||||||||
46 | { | - | ||||||||||||
47 | poly1305_state_internal_t *st = (poly1305_state_internal_t *)ctx; | - | ||||||||||||
48 | - | |||||||||||||
49 | - | |||||||||||||
50 | st->r[0] = (U8TO32(&key[0])) & 0x3ffffff; | - | ||||||||||||
51 | st->r[1] = (U8TO32(&key[3]) >> 2) & 0x3ffff03; | - | ||||||||||||
52 | st->r[2] = (U8TO32(&key[6]) >> 4) & 0x3ffc0ff; | - | ||||||||||||
53 | st->r[3] = (U8TO32(&key[9]) >> 6) & 0x3f03fff; | - | ||||||||||||
54 | st->r[4] = (U8TO32(&key[12]) >> 8) & 0x00fffff; | - | ||||||||||||
55 | - | |||||||||||||
56 | - | |||||||||||||
57 | st->h[0] = 0; | - | ||||||||||||
58 | st->h[1] = 0; | - | ||||||||||||
59 | st->h[2] = 0; | - | ||||||||||||
60 | st->h[3] = 0; | - | ||||||||||||
61 | st->h[4] = 0; | - | ||||||||||||
62 | - | |||||||||||||
63 | - | |||||||||||||
64 | st->pad[0] = U8TO32(&key[16]); | - | ||||||||||||
65 | st->pad[1] = U8TO32(&key[20]); | - | ||||||||||||
66 | st->pad[2] = U8TO32(&key[24]); | - | ||||||||||||
67 | st->pad[3] = U8TO32(&key[28]); | - | ||||||||||||
68 | - | |||||||||||||
69 | st->leftover = 0; | - | ||||||||||||
70 | st->final = 0; | - | ||||||||||||
71 | } executed 426 times by 4 tests: end of block Executed by:
| 426 | ||||||||||||
72 | - | |||||||||||||
73 | static void | - | ||||||||||||
74 | poly1305_blocks(poly1305_state_internal_t *st, const unsigned char *m, size_t bytes) | - | ||||||||||||
75 | { | - | ||||||||||||
76 | const unsigned long hibit = (
| 242-1009 | ||||||||||||
77 | unsigned long r0, r1, r2, r3, r4; | - | ||||||||||||
78 | unsigned long s1, s2, s3, s4; | - | ||||||||||||
79 | unsigned long h0, h1, h2, h3, h4; | - | ||||||||||||
80 | unsigned long long d0, d1, d2, d3, d4; | - | ||||||||||||
81 | unsigned long c; | - | ||||||||||||
82 | - | |||||||||||||
83 | r0 = st->r[0]; | - | ||||||||||||
84 | r1 = st->r[1]; | - | ||||||||||||
85 | r2 = st->r[2]; | - | ||||||||||||
86 | r3 = st->r[3]; | - | ||||||||||||
87 | r4 = st->r[4]; | - | ||||||||||||
88 | - | |||||||||||||
89 | s1 = r1 * 5; | - | ||||||||||||
90 | s2 = r2 * 5; | - | ||||||||||||
91 | s3 = r3 * 5; | - | ||||||||||||
92 | s4 = r4 * 5; | - | ||||||||||||
93 | - | |||||||||||||
94 | h0 = st->h[0]; | - | ||||||||||||
95 | h1 = st->h[1]; | - | ||||||||||||
96 | h2 = st->h[2]; | - | ||||||||||||
97 | h3 = st->h[3]; | - | ||||||||||||
98 | h4 = st->h[4]; | - | ||||||||||||
99 | - | |||||||||||||
100 | while (bytes >= 16
| 1251-3800 | ||||||||||||
101 | - | |||||||||||||
102 | h0 += (U8TO32(m + 0)) & 0x3ffffff; | - | ||||||||||||
103 | h1 += (U8TO32(m + 3) >> 2) & 0x3ffffff; | - | ||||||||||||
104 | h2 += (U8TO32(m + 6) >> 4) & 0x3ffffff; | - | ||||||||||||
105 | h3 += (U8TO32(m + 9) >> 6) & 0x3ffffff; | - | ||||||||||||
106 | h4 += (U8TO32(m + 12) >> 8) | hibit; | - | ||||||||||||
107 | - | |||||||||||||
108 | - | |||||||||||||
109 | d0 = ((unsigned long long)h0 * r0) + | - | ||||||||||||
110 | ((unsigned long long)h1 * s4) + | - | ||||||||||||
111 | ((unsigned long long)h2 * s3) + | - | ||||||||||||
112 | ((unsigned long long)h3 * s2) + | - | ||||||||||||
113 | ((unsigned long long)h4 * s1); | - | ||||||||||||
114 | d1 = ((unsigned long long)h0 * r1) + | - | ||||||||||||
115 | ((unsigned long long)h1 * r0) + | - | ||||||||||||
116 | ((unsigned long long)h2 * s4) + | - | ||||||||||||
117 | ((unsigned long long)h3 * s3) + | - | ||||||||||||
118 | ((unsigned long long)h4 * s2); | - | ||||||||||||
119 | d2 = ((unsigned long long)h0 * r2) + | - | ||||||||||||
120 | ((unsigned long long)h1 * r1) + | - | ||||||||||||
121 | ((unsigned long long)h2 * r0) + | - | ||||||||||||
122 | ((unsigned long long)h3 * s4) + | - | ||||||||||||
123 | ((unsigned long long)h4 * s3); | - | ||||||||||||
124 | d3 = ((unsigned long long)h0 * r3) + | - | ||||||||||||
125 | ((unsigned long long)h1 * r2) + | - | ||||||||||||
126 | ((unsigned long long)h2 * r1) + | - | ||||||||||||
127 | ((unsigned long long)h3 * r0) + | - | ||||||||||||
128 | ((unsigned long long)h4 * s4); | - | ||||||||||||
129 | d4 = ((unsigned long long)h0 * r4) + | - | ||||||||||||
130 | ((unsigned long long)h1 * r3) + | - | ||||||||||||
131 | ((unsigned long long)h2 * r2) + | - | ||||||||||||
132 | ((unsigned long long)h3 * r1) + | - | ||||||||||||
133 | ((unsigned long long)h4 * r0); | - | ||||||||||||
134 | - | |||||||||||||
135 | - | |||||||||||||
136 | c = (unsigned long)(d0 >> 26); | - | ||||||||||||
137 | h0 = (unsigned long)d0 & 0x3ffffff; | - | ||||||||||||
138 | d1 += c; | - | ||||||||||||
139 | c = (unsigned long)(d1 >> 26); | - | ||||||||||||
140 | h1 = (unsigned long)d1 & 0x3ffffff; | - | ||||||||||||
141 | d2 += c; | - | ||||||||||||
142 | c = (unsigned long)(d2 >> 26); | - | ||||||||||||
143 | h2 = (unsigned long)d2 & 0x3ffffff; | - | ||||||||||||
144 | d3 += c; | - | ||||||||||||
145 | c = (unsigned long)(d3 >> 26); | - | ||||||||||||
146 | h3 = (unsigned long)d3 & 0x3ffffff; | - | ||||||||||||
147 | d4 += c; | - | ||||||||||||
148 | c = (unsigned long)(d4 >> 26); | - | ||||||||||||
149 | h4 = (unsigned long)d4 & 0x3ffffff; | - | ||||||||||||
150 | h0 += c * 5; | - | ||||||||||||
151 | c = (h0 >> 26); | - | ||||||||||||
152 | h0 = h0 & 0x3ffffff; | - | ||||||||||||
153 | h1 += c; | - | ||||||||||||
154 | - | |||||||||||||
155 | m += 16; | - | ||||||||||||
156 | bytes -= 16; | - | ||||||||||||
157 | } executed 3800 times by 4 tests: end of block Executed by:
| 3800 | ||||||||||||
158 | - | |||||||||||||
159 | st->h[0] = h0; | - | ||||||||||||
160 | st->h[1] = h1; | - | ||||||||||||
161 | st->h[2] = h2; | - | ||||||||||||
162 | st->h[3] = h3; | - | ||||||||||||
163 | st->h[4] = h4; | - | ||||||||||||
164 | } executed 1251 times by 4 tests: end of block Executed by:
| 1251 | ||||||||||||
165 | - | |||||||||||||
166 | static inline void | - | ||||||||||||
167 | poly1305_update(poly1305_context *ctx, const unsigned char *m, size_t bytes) | - | ||||||||||||
168 | { | - | ||||||||||||
169 | poly1305_state_internal_t *st = (poly1305_state_internal_t *)ctx; | - | ||||||||||||
170 | size_t i; | - | ||||||||||||
171 | - | |||||||||||||
172 | - | |||||||||||||
173 | if (st->leftover
| 381-1017 | ||||||||||||
174 | size_t want = (16 - st->leftover); | - | ||||||||||||
175 | if (want > bytes
| 5-376 | ||||||||||||
176 | want = bytes; executed 5 times by 1 test: want = bytes; Executed by:
| 5 | ||||||||||||
177 | for (i = 0; i < want
| 381-2420 | ||||||||||||
178 | st->buffer[st->leftover + i] = m[i]; executed 2420 times by 4 tests: st->buffer[st->leftover + i] = m[i]; Executed by:
| 2420 | ||||||||||||
179 | bytes -= want; | - | ||||||||||||
180 | m += want; | - | ||||||||||||
181 | st->leftover += want; | - | ||||||||||||
182 | if (st->leftover < 16
| 5-376 | ||||||||||||
183 | return; executed 5 times by 1 test: return; Executed by:
| 5 | ||||||||||||
184 | poly1305_blocks(st, st->buffer, 16); | - | ||||||||||||
185 | st->leftover = 0; | - | ||||||||||||
186 | } executed 376 times by 4 tests: end of block Executed by:
| 376 | ||||||||||||
187 | - | |||||||||||||
188 | - | |||||||||||||
189 | if (bytes >= 16
| 633-760 | ||||||||||||
190 | size_t want = (bytes & ~(16 - 1)); | - | ||||||||||||
191 | poly1305_blocks(st, m, want); | - | ||||||||||||
192 | m += want; | - | ||||||||||||
193 | bytes -= want; | - | ||||||||||||
194 | } executed 633 times by 4 tests: end of block Executed by:
| 633 | ||||||||||||
195 | - | |||||||||||||
196 | - | |||||||||||||
197 | if (bytes
| 618-775 | ||||||||||||
198 | for (i = 0; i < bytes
| 618-5522 | ||||||||||||
199 | st->buffer[st->leftover + i] = m[i]; executed 5522 times by 4 tests: st->buffer[st->leftover + i] = m[i]; Executed by:
| 5522 | ||||||||||||
200 | st->leftover += bytes; | - | ||||||||||||
201 | } executed 618 times by 4 tests: end of block Executed by:
| 618 | ||||||||||||
202 | } executed 1393 times by 4 tests: end of block Executed by:
| 1393 | ||||||||||||
203 | - | |||||||||||||
204 | static inline void | - | ||||||||||||
205 | poly1305_finish(poly1305_context *ctx, unsigned char mac[16]) | - | ||||||||||||
206 | { | - | ||||||||||||
207 | poly1305_state_internal_t *st = (poly1305_state_internal_t *)ctx; | - | ||||||||||||
208 | unsigned long h0, h1, h2, h3, h4, c; | - | ||||||||||||
209 | unsigned long g0, g1, g2, g3, g4; | - | ||||||||||||
210 | unsigned long long f; | - | ||||||||||||
211 | unsigned long mask; | - | ||||||||||||
212 | - | |||||||||||||
213 | - | |||||||||||||
214 | if (st->leftover
| 184-242 | ||||||||||||
215 | size_t i = st->leftover; | - | ||||||||||||
216 | st->buffer[i++] = 1; | - | ||||||||||||
217 | for (; i < 16
| 242-1704 | ||||||||||||
218 | st->buffer[i] = 0; executed 1704 times by 1 test: st->buffer[i] = 0; Executed by:
| 1704 | ||||||||||||
219 | st->final = 1; | - | ||||||||||||
220 | poly1305_blocks(st, st->buffer, 16); | - | ||||||||||||
221 | } executed 242 times by 1 test: end of block Executed by:
| 242 | ||||||||||||
222 | - | |||||||||||||
223 | - | |||||||||||||
224 | h0 = st->h[0]; | - | ||||||||||||
225 | h1 = st->h[1]; | - | ||||||||||||
226 | h2 = st->h[2]; | - | ||||||||||||
227 | h3 = st->h[3]; | - | ||||||||||||
228 | h4 = st->h[4]; | - | ||||||||||||
229 | - | |||||||||||||
230 | c = h1 >> 26; | - | ||||||||||||
231 | h1 = h1 & 0x3ffffff; | - | ||||||||||||
232 | h2 += c; | - | ||||||||||||
233 | c = h2 >> 26; | - | ||||||||||||
234 | h2 = h2 & 0x3ffffff; | - | ||||||||||||
235 | h3 += c; | - | ||||||||||||
236 | c = h3 >> 26; | - | ||||||||||||
237 | h3 = h3 & 0x3ffffff; | - | ||||||||||||
238 | h4 += c; | - | ||||||||||||
239 | c = h4 >> 26; | - | ||||||||||||
240 | h4 = h4 & 0x3ffffff; | - | ||||||||||||
241 | h0 += c * 5; | - | ||||||||||||
242 | c = h0 >> 26; | - | ||||||||||||
243 | h0 = h0 & 0x3ffffff; | - | ||||||||||||
244 | h1 += c; | - | ||||||||||||
245 | - | |||||||||||||
246 | - | |||||||||||||
247 | g0 = h0 + 5; | - | ||||||||||||
248 | c = g0 >> 26; | - | ||||||||||||
249 | g0 &= 0x3ffffff; | - | ||||||||||||
250 | g1 = h1 + c; | - | ||||||||||||
251 | c = g1 >> 26; | - | ||||||||||||
252 | g1 &= 0x3ffffff; | - | ||||||||||||
253 | g2 = h2 + c; | - | ||||||||||||
254 | c = g2 >> 26; | - | ||||||||||||
255 | g2 &= 0x3ffffff; | - | ||||||||||||
256 | g3 = h3 + c; | - | ||||||||||||
257 | c = g3 >> 26; | - | ||||||||||||
258 | g3 &= 0x3ffffff; | - | ||||||||||||
259 | g4 = h4 + c - (1 << 26); | - | ||||||||||||
260 | - | |||||||||||||
261 | - | |||||||||||||
262 | mask = (g4 >> ((sizeof(unsigned long) * 8) - 1)) - 1; | - | ||||||||||||
263 | g0 &= mask; | - | ||||||||||||
264 | g1 &= mask; | - | ||||||||||||
265 | g2 &= mask; | - | ||||||||||||
266 | g3 &= mask; | - | ||||||||||||
267 | g4 &= mask; | - | ||||||||||||
268 | mask = ~mask; | - | ||||||||||||
269 | h0 = (h0 & mask) | g0; | - | ||||||||||||
270 | h1 = (h1 & mask) | g1; | - | ||||||||||||
271 | h2 = (h2 & mask) | g2; | - | ||||||||||||
272 | h3 = (h3 & mask) | g3; | - | ||||||||||||
273 | h4 = (h4 & mask) | g4; | - | ||||||||||||
274 | - | |||||||||||||
275 | - | |||||||||||||
276 | h0 = ((h0) | (h1 << 26)) & 0xffffffff; | - | ||||||||||||
277 | h1 = ((h1 >> 6) | (h2 << 20)) & 0xffffffff; | - | ||||||||||||
278 | h2 = ((h2 >> 12) | (h3 << 14)) & 0xffffffff; | - | ||||||||||||
279 | h3 = ((h3 >> 18) | (h4 << 8)) & 0xffffffff; | - | ||||||||||||
280 | - | |||||||||||||
281 | - | |||||||||||||
282 | f = (unsigned long long)h0 + st->pad[0]; | - | ||||||||||||
283 | h0 = (unsigned long)f; | - | ||||||||||||
284 | f = (unsigned long long)h1 + st->pad[1] + (f >> 32); | - | ||||||||||||
285 | h1 = (unsigned long)f; | - | ||||||||||||
286 | f = (unsigned long long)h2 + st->pad[2] + (f >> 32); | - | ||||||||||||
287 | h2 = (unsigned long)f; | - | ||||||||||||
288 | f = (unsigned long long)h3 + st->pad[3] + (f >> 32); | - | ||||||||||||
289 | h3 = (unsigned long)f; | - | ||||||||||||
290 | - | |||||||||||||
291 | U32TO8(mac + 0, h0); | - | ||||||||||||
292 | U32TO8(mac + 4, h1); | - | ||||||||||||
293 | U32TO8(mac + 8, h2); | - | ||||||||||||
294 | U32TO8(mac + 12, h3); | - | ||||||||||||
295 | - | |||||||||||||
296 | - | |||||||||||||
297 | st->h[0] = 0; | - | ||||||||||||
298 | st->h[1] = 0; | - | ||||||||||||
299 | st->h[2] = 0; | - | ||||||||||||
300 | st->h[3] = 0; | - | ||||||||||||
301 | st->h[4] = 0; | - | ||||||||||||
302 | st->r[0] = 0; | - | ||||||||||||
303 | st->r[1] = 0; | - | ||||||||||||
304 | st->r[2] = 0; | - | ||||||||||||
305 | st->r[3] = 0; | - | ||||||||||||
306 | st->r[4] = 0; | - | ||||||||||||
307 | st->pad[0] = 0; | - | ||||||||||||
308 | st->pad[1] = 0; | - | ||||||||||||
309 | st->pad[2] = 0; | - | ||||||||||||
310 | st->pad[3] = 0; | - | ||||||||||||
311 | } executed 426 times by 4 tests: end of block Executed by:
| 426 | ||||||||||||
Switch to Source code | Preprocessed file |