Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/libressl/src/crypto/modes/gcm128.c |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | static void gcm_init_4bit(u128 Htable[16], u64 H[2]) | - | ||||||||||||||||||
2 | { | - | ||||||||||||||||||
3 | u128 V; | - | ||||||||||||||||||
4 | - | |||||||||||||||||||
5 | - | |||||||||||||||||||
6 | - | |||||||||||||||||||
7 | - | |||||||||||||||||||
8 | Htable[0].hi = 0; | - | ||||||||||||||||||
9 | Htable[0].lo = 0; | - | ||||||||||||||||||
10 | V.hi = H[0]; | - | ||||||||||||||||||
11 | V.lo = H[1]; | - | ||||||||||||||||||
12 | Htable[8] = V; | - | ||||||||||||||||||
13 | do { if (sizeof(size_t)==8
executed 48 times by 3 tests: else { u32 T = 0xe1000000U & (0-(u32)(V.lo&1)); V.lo = (V.hi<<63)|(V.lo>>1); V.hi = (V.hi>>1 )^((u64)T<<32); }end of block Executed by:
never executed: } while(0);end of block | 0-48 | ||||||||||||||||||
14 | Htable[4] = V; | - | ||||||||||||||||||
15 | do { if (sizeof(size_t)==8
executed 48 times by 3 tests: else { u32 T = 0xe1000000U & (0-(u32)(V.lo&1)); V.lo = (V.hi<<63)|(V.lo>>1); V.hi = (V.hi>>1 )^((u64)T<<32); }end of block Executed by:
never executed: } while(0);end of block | 0-48 | ||||||||||||||||||
16 | Htable[2] = V; | - | ||||||||||||||||||
17 | do { if (sizeof(size_t)==8
executed 48 times by 3 tests: else { u32 T = 0xe1000000U & (0-(u32)(V.lo&1)); V.lo = (V.hi<<63)|(V.lo>>1); V.hi = (V.hi>>1 )^((u64)T<<32); }end of block Executed by:
never executed: } while(0);end of block | 0-48 | ||||||||||||||||||
18 | Htable[1] = V; | - | ||||||||||||||||||
19 | Htable[3].hi = V.hi^Htable[2].hi, Htable[3].lo = V.lo^Htable[2].lo; | - | ||||||||||||||||||
20 | V=Htable[4]; | - | ||||||||||||||||||
21 | Htable[5].hi = V.hi^Htable[1].hi, Htable[5].lo = V.lo^Htable[1].lo; | - | ||||||||||||||||||
22 | Htable[6].hi = V.hi^Htable[2].hi, Htable[6].lo = V.lo^Htable[2].lo; | - | ||||||||||||||||||
23 | Htable[7].hi = V.hi^Htable[3].hi, Htable[7].lo = V.lo^Htable[3].lo; | - | ||||||||||||||||||
24 | V=Htable[8]; | - | ||||||||||||||||||
25 | Htable[9].hi = V.hi^Htable[1].hi, Htable[9].lo = V.lo^Htable[1].lo; | - | ||||||||||||||||||
26 | Htable[10].hi = V.hi^Htable[2].hi, Htable[10].lo = V.lo^Htable[2].lo; | - | ||||||||||||||||||
27 | Htable[11].hi = V.hi^Htable[3].hi, Htable[11].lo = V.lo^Htable[3].lo; | - | ||||||||||||||||||
28 | Htable[12].hi = V.hi^Htable[4].hi, Htable[12].lo = V.lo^Htable[4].lo; | - | ||||||||||||||||||
29 | Htable[13].hi = V.hi^Htable[5].hi, Htable[13].lo = V.lo^Htable[5].lo; | - | ||||||||||||||||||
30 | Htable[14].hi = V.hi^Htable[6].hi, Htable[14].lo = V.lo^Htable[6].lo; | - | ||||||||||||||||||
31 | Htable[15].hi = V.hi^Htable[7].hi, Htable[15].lo = V.lo^Htable[7].lo; | - | ||||||||||||||||||
32 | } executed 48 times by 3 tests: end of block Executed by:
| 48 | ||||||||||||||||||
33 | void gcm_gmult_4bit(u64 Xi[2],const u128 Htable[16]); | - | ||||||||||||||||||
34 | void gcm_ghash_4bit(u64 Xi[2],const u128 Htable[16],const u8 *inp,size_t len); | - | ||||||||||||||||||
35 | void gcm_init_clmul(u128 Htable[16],const u64 Xi[2]); | - | ||||||||||||||||||
36 | void gcm_gmult_clmul(u64 Xi[2],const u128 Htable[16]); | - | ||||||||||||||||||
37 | void gcm_ghash_clmul(u64 Xi[2],const u128 Htable[16],const u8 *inp,size_t len); | - | ||||||||||||||||||
38 | void CRYPTO_gcm128_init(GCM128_CONTEXT *ctx,void *key,block128_f block) | - | ||||||||||||||||||
39 | { | - | ||||||||||||||||||
40 | memset(ctx,0,sizeof(*ctx)); | - | ||||||||||||||||||
41 | ctx->block = block; | - | ||||||||||||||||||
42 | ctx->key = key; | - | ||||||||||||||||||
43 | - | |||||||||||||||||||
44 | (*block)(ctx->H.c,ctx->H.c,key); | - | ||||||||||||||||||
45 | - | |||||||||||||||||||
46 | - | |||||||||||||||||||
47 | - | |||||||||||||||||||
48 | - | |||||||||||||||||||
49 | ctx->H.u[0] = ({ u64 ret=(ctx->H.u[0]); asm ("bswapq %0" : "+r"(ret)); ret; }); | - | ||||||||||||||||||
50 | ctx->H.u[1] = ({ u64 ret=(ctx->H.u[1]); asm ("bswapq %0" : "+r"(ret)); ret; }); | - | ||||||||||||||||||
51 | if ((
| 0-48 | ||||||||||||||||||
52 | ((1 << 24) | (1ULL << (32 + 1)))
| 0-48 | ||||||||||||||||||
53 | gcm_init_clmul(ctx->Htable,ctx->H.u); | - | ||||||||||||||||||
54 | ctx->gmult = gcm_gmult_clmul; | - | ||||||||||||||||||
55 | ctx->ghash = gcm_ghash_clmul; | - | ||||||||||||||||||
56 | return; never executed: return; | 0 | ||||||||||||||||||
57 | } | - | ||||||||||||||||||
58 | - | |||||||||||||||||||
59 | gcm_init_4bit(ctx->Htable,ctx->H.u); | - | ||||||||||||||||||
60 | ctx->gmult = gcm_gmult_4bit; | - | ||||||||||||||||||
61 | ctx->ghash = gcm_ghash_4bit; | - | ||||||||||||||||||
62 | } executed 48 times by 3 tests: end of block Executed by:
| 48 | ||||||||||||||||||
63 | - | |||||||||||||||||||
64 | void CRYPTO_gcm128_setiv(GCM128_CONTEXT *ctx,const unsigned char *iv,size_t len) | - | ||||||||||||||||||
65 | { | - | ||||||||||||||||||
66 | unsigned int ctr; | - | ||||||||||||||||||
67 | - | |||||||||||||||||||
68 | void (*gcm_gmult_p)(u64 Xi[2],const u128 Htable[16]) = ctx->gmult; | - | ||||||||||||||||||
69 | - | |||||||||||||||||||
70 | - | |||||||||||||||||||
71 | ctx->Yi.u[0] = 0; | - | ||||||||||||||||||
72 | ctx->Yi.u[1] = 0; | - | ||||||||||||||||||
73 | ctx->Xi.u[0] = 0; | - | ||||||||||||||||||
74 | ctx->Xi.u[1] = 0; | - | ||||||||||||||||||
75 | ctx->len.u[0] = 0; | - | ||||||||||||||||||
76 | ctx->len.u[1] = 0; | - | ||||||||||||||||||
77 | ctx->ares = 0; | - | ||||||||||||||||||
78 | ctx->mres = 0; | - | ||||||||||||||||||
79 | - | |||||||||||||||||||
80 | if (len==12
| 14-98 | ||||||||||||||||||
81 | memcpy(ctx->Yi.c,iv,12); | - | ||||||||||||||||||
82 | ctx->Yi.c[15]=1; | - | ||||||||||||||||||
83 | ctr=1; | - | ||||||||||||||||||
84 | } executed 98 times by 3 tests: end of block Executed by:
| 98 | ||||||||||||||||||
85 | else { | - | ||||||||||||||||||
86 | size_t i; | - | ||||||||||||||||||
87 | u64 len0 = len; | - | ||||||||||||||||||
88 | - | |||||||||||||||||||
89 | while (len>=16
| 14-26 | ||||||||||||||||||
90 | for (i=0; i<16
executed 416 times by 1 test: ctx->Yi.c[i] ^= iv[i]; Executed by:
| 26-416 | ||||||||||||||||||
91 | (*gcm_gmult_p)(ctx->Yi.u,ctx->Htable); | - | ||||||||||||||||||
92 | iv += 16; | - | ||||||||||||||||||
93 | len -= 16; | - | ||||||||||||||||||
94 | } executed 26 times by 1 test: end of block Executed by:
| 26 | ||||||||||||||||||
95 | if (len
| 2-12 | ||||||||||||||||||
96 | for (i=0; i<len
executed 120 times by 1 test: ctx->Yi.c[i] ^= iv[i]; Executed by:
| 12-120 | ||||||||||||||||||
97 | (*gcm_gmult_p)(ctx->Yi.u,ctx->Htable); | - | ||||||||||||||||||
98 | } executed 12 times by 1 test: end of block Executed by:
| 12 | ||||||||||||||||||
99 | len0 <<= 3; | - | ||||||||||||||||||
100 | - | |||||||||||||||||||
101 | - | |||||||||||||||||||
102 | ctx->Yi.u[1] ^= ({ u64 ret=(len0); asm ("bswapq %0" : "+r"(ret)); ret; }); | - | ||||||||||||||||||
103 | (*gcm_gmult_p)(ctx->Yi.u,ctx->Htable); | - | ||||||||||||||||||
104 | - | |||||||||||||||||||
105 | - | |||||||||||||||||||
106 | - | |||||||||||||||||||
107 | ctr = ({ u32 ret=(ctx->Yi.d[3]); asm ("bswapl %0" : "+r"(ret)); ret; }); | - | ||||||||||||||||||
108 | - | |||||||||||||||||||
109 | - | |||||||||||||||||||
110 | - | |||||||||||||||||||
111 | - | |||||||||||||||||||
112 | - | |||||||||||||||||||
113 | - | |||||||||||||||||||
114 | } executed 14 times by 1 test: end of block Executed by:
| 14 | ||||||||||||||||||
115 | - | |||||||||||||||||||
116 | (*ctx->block)(ctx->Yi.c,ctx->EK0.c,ctx->key); | - | ||||||||||||||||||
117 | ++ctr; | - | ||||||||||||||||||
118 | - | |||||||||||||||||||
119 | - | |||||||||||||||||||
120 | ctx->Yi.d[3] = ({ u32 ret=(ctr); asm ("bswapl %0" : "+r"(ret)); ret; }); | - | ||||||||||||||||||
121 | - | |||||||||||||||||||
122 | - | |||||||||||||||||||
123 | - | |||||||||||||||||||
124 | - | |||||||||||||||||||
125 | - | |||||||||||||||||||
126 | - | |||||||||||||||||||
127 | } executed 112 times by 3 tests: end of block Executed by:
| 112 | ||||||||||||||||||
128 | - | |||||||||||||||||||
129 | int CRYPTO_gcm128_aad(GCM128_CONTEXT *ctx,const unsigned char *aad,size_t len) | - | ||||||||||||||||||
130 | { | - | ||||||||||||||||||
131 | size_t i; | - | ||||||||||||||||||
132 | unsigned int n; | - | ||||||||||||||||||
133 | u64 alen = ctx->len.u[0]; | - | ||||||||||||||||||
134 | - | |||||||||||||||||||
135 | void (*gcm_gmult_p)(u64 Xi[2],const u128 Htable[16]) = ctx->gmult; | - | ||||||||||||||||||
136 | - | |||||||||||||||||||
137 | void (*gcm_ghash_p)(u64 Xi[2],const u128 Htable[16], | - | ||||||||||||||||||
138 | const u8 *inp,size_t len) = ctx->ghash; | - | ||||||||||||||||||
139 | - | |||||||||||||||||||
140 | - | |||||||||||||||||||
141 | - | |||||||||||||||||||
142 | if (ctx->len.u[1]
never executed: -2;return -2; never executed: return -2; | 0-92 | ||||||||||||||||||
143 | - | |||||||||||||||||||
144 | alen += len; | - | ||||||||||||||||||
145 | if (alen>(1UL<<61)
| 0-92 | ||||||||||||||||||
146 | return never executed: -1;return -1; never executed: return -1; | 0 | ||||||||||||||||||
147 | ctx->len.u[0] = alen; | - | ||||||||||||||||||
148 | - | |||||||||||||||||||
149 | n = ctx->ares; | - | ||||||||||||||||||
150 | if (n
| 0-92 | ||||||||||||||||||
151 | while (n
| 0 | ||||||||||||||||||
152 | ctx->Xi.c[n] ^= *(aad++); | - | ||||||||||||||||||
153 | --len; | - | ||||||||||||||||||
154 | n = (n+1)%16; | - | ||||||||||||||||||
155 | } never executed: end of block | 0 | ||||||||||||||||||
156 | if (n==0
never executed: gcm_gmult_p)(ctx->Xi.u,ctx->Htable);(*gcm_gmult_p)(ctx->Xi.u,ctx->Htable); never executed: (*gcm_gmult_p)(ctx->Xi.u,ctx->Htable); | 0 | ||||||||||||||||||
157 | else { | - | ||||||||||||||||||
158 | ctx->ares = n; | - | ||||||||||||||||||
159 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
160 | } | - | ||||||||||||||||||
161 | } | - | ||||||||||||||||||
162 | - | |||||||||||||||||||
163 | - | |||||||||||||||||||
164 | if ((
| 32-60 | ||||||||||||||||||
165 | (*gcm_ghash_p)(ctx->Xi.u,ctx->Htable,aad,i); | - | ||||||||||||||||||
166 | aad += i; | - | ||||||||||||||||||
167 | len -= i; | - | ||||||||||||||||||
168 | } executed 32 times by 2 tests: end of block Executed by:
| 32 | ||||||||||||||||||
169 | if (len
| 2-90 | ||||||||||||||||||
170 | n = (unsigned int)len; | - | ||||||||||||||||||
171 | for (i=0; i<len
executed 882 times by 3 tests: ctx->Xi.c[i] ^= aad[i]; Executed by:
| 90-882 | ||||||||||||||||||
172 | } executed 90 times by 3 tests: end of block Executed by:
| 90 | ||||||||||||||||||
173 | - | |||||||||||||||||||
174 | ctx->ares = n; | - | ||||||||||||||||||
175 | return executed 92 times by 3 tests: 0;return 0; Executed by:
executed 92 times by 3 tests: return 0; Executed by:
| 92 | ||||||||||||||||||
176 | } | - | ||||||||||||||||||
177 | - | |||||||||||||||||||
178 | int CRYPTO_gcm128_encrypt(GCM128_CONTEXT *ctx, | - | ||||||||||||||||||
179 | const unsigned char *in, unsigned char *out, | - | ||||||||||||||||||
180 | size_t len) | - | ||||||||||||||||||
181 | { | - | ||||||||||||||||||
182 | unsigned int n, ctr; | - | ||||||||||||||||||
183 | size_t i; | - | ||||||||||||||||||
184 | u64 mlen = ctx->len.u[1]; | - | ||||||||||||||||||
185 | block128_f block = ctx->block; | - | ||||||||||||||||||
186 | void *key = ctx->key; | - | ||||||||||||||||||
187 | - | |||||||||||||||||||
188 | void (*gcm_gmult_p)(u64 Xi[2],const u128 Htable[16]) = ctx->gmult; | - | ||||||||||||||||||
189 | - | |||||||||||||||||||
190 | void (*gcm_ghash_p)(u64 Xi[2],const u128 Htable[16], | - | ||||||||||||||||||
191 | const u8 *inp,size_t len) = ctx->ghash; | - | ||||||||||||||||||
192 | - | |||||||||||||||||||
193 | - | |||||||||||||||||||
194 | - | |||||||||||||||||||
195 | mlen += len; | - | ||||||||||||||||||
196 | if (mlen>((1UL<<36)-32)
| 0-16 | ||||||||||||||||||
197 | return never executed: -1;return -1; never executed: return -1; | 0 | ||||||||||||||||||
198 | ctx->len.u[1] = mlen; | - | ||||||||||||||||||
199 | - | |||||||||||||||||||
200 | if (ctx->ares
| 7-9 | ||||||||||||||||||
201 | - | |||||||||||||||||||
202 | (*gcm_gmult_p)(ctx->Xi.u,ctx->Htable); | - | ||||||||||||||||||
203 | ctx->ares = 0; | - | ||||||||||||||||||
204 | } executed 9 times by 1 test: end of block Executed by:
| 9 | ||||||||||||||||||
205 | - | |||||||||||||||||||
206 | - | |||||||||||||||||||
207 | - | |||||||||||||||||||
208 | ctr = ({ u32 ret=(ctx->Yi.d[3]); asm ("bswapl %0" : "+r"(ret)); ret; }); | - | ||||||||||||||||||
209 | - | |||||||||||||||||||
210 | - | |||||||||||||||||||
211 | - | |||||||||||||||||||
212 | - | |||||||||||||||||||
213 | - | |||||||||||||||||||
214 | - | |||||||||||||||||||
215 | - | |||||||||||||||||||
216 | n = ctx->mres; | - | ||||||||||||||||||
217 | - | |||||||||||||||||||
218 | if (16%sizeof(size_t) == 0
| 0-16 | ||||||||||||||||||
219 | if (n
| 0-16 | ||||||||||||||||||
220 | while (n
| 0 | ||||||||||||||||||
221 | ctx->Xi.c[n] ^= *(out++) = *(in++)^ctx->EKi.c[n]; | - | ||||||||||||||||||
222 | --len; | - | ||||||||||||||||||
223 | n = (n+1)%16; | - | ||||||||||||||||||
224 | } never executed: end of block | 0 | ||||||||||||||||||
225 | if (n==0
never executed: gcm_gmult_p)(ctx->Xi.u,ctx->Htable);(*gcm_gmult_p)(ctx->Xi.u,ctx->Htable); never executed: (*gcm_gmult_p)(ctx->Xi.u,ctx->Htable); | 0 | ||||||||||||||||||
226 | else { | - | ||||||||||||||||||
227 | ctx->mres = n; | - | ||||||||||||||||||
228 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
229 | } | - | ||||||||||||||||||
230 | } | - | ||||||||||||||||||
231 | - | |||||||||||||||||||
232 | - | |||||||||||||||||||
233 | - | |||||||||||||||||||
234 | - | |||||||||||||||||||
235 | - | |||||||||||||||||||
236 | while (len>=(3*1024)
| 0-16 | ||||||||||||||||||
237 | size_t j=(3*1024); | - | ||||||||||||||||||
238 | - | |||||||||||||||||||
239 | while (j
| 0 | ||||||||||||||||||
240 | size_t *out_t=(size_t *)out; | - | ||||||||||||||||||
241 | const size_t *in_t=(const size_t *)in; | - | ||||||||||||||||||
242 | - | |||||||||||||||||||
243 | (*block)(ctx->Yi.c,ctx->EKi.c,key); | - | ||||||||||||||||||
244 | ++ctr; | - | ||||||||||||||||||
245 | - | |||||||||||||||||||
246 | - | |||||||||||||||||||
247 | ctx->Yi.d[3] = ({ u32 ret=(ctr); asm ("bswapl %0" : "+r"(ret)); ret; }); | - | ||||||||||||||||||
248 | - | |||||||||||||||||||
249 | - | |||||||||||||||||||
250 | - | |||||||||||||||||||
251 | - | |||||||||||||||||||
252 | - | |||||||||||||||||||
253 | - | |||||||||||||||||||
254 | for (i=0; i<16/sizeof(size_t)
| 0 | ||||||||||||||||||
255 | out_t[i] = in_t[i] ^ ctx->EKi.t[i]; never executed: out_t[i] = in_t[i] ^ ctx->EKi.t[i]; | 0 | ||||||||||||||||||
256 | out += 16; | - | ||||||||||||||||||
257 | in += 16; | - | ||||||||||||||||||
258 | j -= 16; | - | ||||||||||||||||||
259 | } never executed: end of block | 0 | ||||||||||||||||||
260 | (*gcm_ghash_p)(ctx->Xi.u,ctx->Htable,out-(3*1024),(3*1024)); | - | ||||||||||||||||||
261 | len -= (3*1024); | - | ||||||||||||||||||
262 | } never executed: end of block | 0 | ||||||||||||||||||
263 | if ((
| 0-16 | ||||||||||||||||||
264 | size_t j=i; | - | ||||||||||||||||||
265 | - | |||||||||||||||||||
266 | while (len>=16
| 16-60 | ||||||||||||||||||
267 | size_t *out_t=(size_t *)out; | - | ||||||||||||||||||
268 | const size_t *in_t=(const size_t *)in; | - | ||||||||||||||||||
269 | - | |||||||||||||||||||
270 | (*block)(ctx->Yi.c,ctx->EKi.c,key); | - | ||||||||||||||||||
271 | ++ctr; | - | ||||||||||||||||||
272 | - | |||||||||||||||||||
273 | - | |||||||||||||||||||
274 | ctx->Yi.d[3] = ({ u32 ret=(ctr); asm ("bswapl %0" : "+r"(ret)); ret; }); | - | ||||||||||||||||||
275 | - | |||||||||||||||||||
276 | - | |||||||||||||||||||
277 | - | |||||||||||||||||||
278 | - | |||||||||||||||||||
279 | - | |||||||||||||||||||
280 | - | |||||||||||||||||||
281 | for (i=0; i<16/sizeof(size_t)
| 60-120 | ||||||||||||||||||
282 | out_t[i] = in_t[i] ^ ctx->EKi.t[i]; executed 120 times by 1 test: out_t[i] = in_t[i] ^ ctx->EKi.t[i]; Executed by:
| 120 | ||||||||||||||||||
283 | out += 16; | - | ||||||||||||||||||
284 | in += 16; | - | ||||||||||||||||||
285 | len -= 16; | - | ||||||||||||||||||
286 | } executed 60 times by 1 test: end of block Executed by:
| 60 | ||||||||||||||||||
287 | (*gcm_ghash_p)(ctx->Xi.u,ctx->Htable,out-j,j); | - | ||||||||||||||||||
288 | } executed 16 times by 1 test: end of block Executed by:
| 16 | ||||||||||||||||||
289 | if (len
| 7-9 | ||||||||||||||||||
290 | (*block)(ctx->Yi.c,ctx->EKi.c,key); | - | ||||||||||||||||||
291 | ++ctr; | - | ||||||||||||||||||
292 | - | |||||||||||||||||||
293 | - | |||||||||||||||||||
294 | ctx->Yi.d[3] = ({ u32 ret=(ctr); asm ("bswapl %0" : "+r"(ret)); ret; }); | - | ||||||||||||||||||
295 | - | |||||||||||||||||||
296 | - | |||||||||||||||||||
297 | - | |||||||||||||||||||
298 | - | |||||||||||||||||||
299 | - | |||||||||||||||||||
300 | - | |||||||||||||||||||
301 | while (len--
| 9-108 | ||||||||||||||||||
302 | ctx->Xi.c[n] ^= out[n] = in[n]^ctx->EKi.c[n]; | - | ||||||||||||||||||
303 | ++n; | - | ||||||||||||||||||
304 | } executed 108 times by 1 test: end of block Executed by:
| 108 | ||||||||||||||||||
305 | } executed 9 times by 1 test: end of block Executed by:
| 9 | ||||||||||||||||||
306 | - | |||||||||||||||||||
307 | ctx->mres = n; | - | ||||||||||||||||||
308 | return executed 16 times by 1 test: 0;return 0; Executed by:
executed 16 times by 1 test: return 0; Executed by:
| 16 | ||||||||||||||||||
309 | } never executed: while(0);end of block | 0 | ||||||||||||||||||
310 | - | |||||||||||||||||||
311 | for (i=0;i<len
| 0 | ||||||||||||||||||
312 | if (n==0
| 0 | ||||||||||||||||||
313 | (*block)(ctx->Yi.c,ctx->EKi.c,key); | - | ||||||||||||||||||
314 | ++ctr; | - | ||||||||||||||||||
315 | - | |||||||||||||||||||
316 | - | |||||||||||||||||||
317 | ctx->Yi.d[3] = ({ u32 ret=(ctr); asm ("bswapl %0" : "+r"(ret)); ret; }); | - | ||||||||||||||||||
318 | - | |||||||||||||||||||
319 | - | |||||||||||||||||||
320 | - | |||||||||||||||||||
321 | - | |||||||||||||||||||
322 | - | |||||||||||||||||||
323 | - | |||||||||||||||||||
324 | } never executed: end of block | 0 | ||||||||||||||||||
325 | ctx->Xi.c[n] ^= out[i] = in[i]^ctx->EKi.c[n]; | - | ||||||||||||||||||
326 | n = (n+1)%16; | - | ||||||||||||||||||
327 | if (n==0
| 0 | ||||||||||||||||||
328 | (* never executed: gcm_gmult_p)(ctx->Xi.u,ctx->Htable);(*gcm_gmult_p)(ctx->Xi.u,ctx->Htable); never executed: (*gcm_gmult_p)(ctx->Xi.u,ctx->Htable); | 0 | ||||||||||||||||||
329 | } never executed: end of block | 0 | ||||||||||||||||||
330 | - | |||||||||||||||||||
331 | ctx->mres = n; | - | ||||||||||||||||||
332 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
333 | } | - | ||||||||||||||||||
334 | - | |||||||||||||||||||
335 | int CRYPTO_gcm128_decrypt(GCM128_CONTEXT *ctx, | - | ||||||||||||||||||
336 | const unsigned char *in, unsigned char *out, | - | ||||||||||||||||||
337 | size_t len) | - | ||||||||||||||||||
338 | { | - | ||||||||||||||||||
339 | unsigned int n, ctr; | - | ||||||||||||||||||
340 | size_t i; | - | ||||||||||||||||||
341 | u64 mlen = ctx->len.u[1]; | - | ||||||||||||||||||
342 | block128_f block = ctx->block; | - | ||||||||||||||||||
343 | void *key = ctx->key; | - | ||||||||||||||||||
344 | - | |||||||||||||||||||
345 | void (*gcm_gmult_p)(u64 Xi[2],const u128 Htable[16]) = ctx->gmult; | - | ||||||||||||||||||
346 | - | |||||||||||||||||||
347 | void (*gcm_ghash_p)(u64 Xi[2],const u128 Htable[16], | - | ||||||||||||||||||
348 | const u8 *inp,size_t len) = ctx->ghash; | - | ||||||||||||||||||
349 | - | |||||||||||||||||||
350 | - | |||||||||||||||||||
351 | - | |||||||||||||||||||
352 | mlen += len; | - | ||||||||||||||||||
353 | if (mlen>((1UL<<36)-32)
| 0-16 | ||||||||||||||||||
354 | return never executed: -1;return -1; never executed: return -1; | 0 | ||||||||||||||||||
355 | ctx->len.u[1] = mlen; | - | ||||||||||||||||||
356 | - | |||||||||||||||||||
357 | if (ctx->ares
| 7-9 | ||||||||||||||||||
358 | - | |||||||||||||||||||
359 | (*gcm_gmult_p)(ctx->Xi.u,ctx->Htable); | - | ||||||||||||||||||
360 | ctx->ares = 0; | - | ||||||||||||||||||
361 | } executed 9 times by 1 test: end of block Executed by:
| 9 | ||||||||||||||||||
362 | - | |||||||||||||||||||
363 | - | |||||||||||||||||||
364 | - | |||||||||||||||||||
365 | ctr = ({ u32 ret=(ctx->Yi.d[3]); asm ("bswapl %0" : "+r"(ret)); ret; }); | - | ||||||||||||||||||
366 | - | |||||||||||||||||||
367 | - | |||||||||||||||||||
368 | - | |||||||||||||||||||
369 | - | |||||||||||||||||||
370 | - | |||||||||||||||||||
371 | - | |||||||||||||||||||
372 | - | |||||||||||||||||||
373 | n = ctx->mres; | - | ||||||||||||||||||
374 | - | |||||||||||||||||||
375 | if (16%sizeof(size_t) == 0
| 0-16 | ||||||||||||||||||
376 | if (n
| 0-16 | ||||||||||||||||||
377 | while (n
| 0 | ||||||||||||||||||
378 | u8 c = *(in++); | - | ||||||||||||||||||
379 | *(out++) = c^ctx->EKi.c[n]; | - | ||||||||||||||||||
380 | ctx->Xi.c[n] ^= c; | - | ||||||||||||||||||
381 | --len; | - | ||||||||||||||||||
382 | n = (n+1)%16; | - | ||||||||||||||||||
383 | } never executed: end of block | 0 | ||||||||||||||||||
384 | if (n==0
never executed: gcm_gmult_p)(ctx->Xi.u,ctx->Htable);(*gcm_gmult_p)(ctx->Xi.u,ctx->Htable); never executed: (*gcm_gmult_p)(ctx->Xi.u,ctx->Htable); | 0 | ||||||||||||||||||
385 | else { | - | ||||||||||||||||||
386 | ctx->mres = n; | - | ||||||||||||||||||
387 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
388 | } | - | ||||||||||||||||||
389 | } | - | ||||||||||||||||||
390 | - | |||||||||||||||||||
391 | - | |||||||||||||||||||
392 | - | |||||||||||||||||||
393 | - | |||||||||||||||||||
394 | - | |||||||||||||||||||
395 | while (len>=(3*1024)
| 0-16 | ||||||||||||||||||
396 | size_t j=(3*1024); | - | ||||||||||||||||||
397 | - | |||||||||||||||||||
398 | (*gcm_ghash_p)(ctx->Xi.u,ctx->Htable,in,(3*1024)); | - | ||||||||||||||||||
399 | while (j
| 0 | ||||||||||||||||||
400 | size_t *out_t=(size_t *)out; | - | ||||||||||||||||||
401 | const size_t *in_t=(const size_t *)in; | - | ||||||||||||||||||
402 | - | |||||||||||||||||||
403 | (*block)(ctx->Yi.c,ctx->EKi.c,key); | - | ||||||||||||||||||
404 | ++ctr; | - | ||||||||||||||||||
405 | - | |||||||||||||||||||
406 | - | |||||||||||||||||||
407 | ctx->Yi.d[3] = ({ u32 ret=(ctr); asm ("bswapl %0" : "+r"(ret)); ret; }); | - | ||||||||||||||||||
408 | - | |||||||||||||||||||
409 | - | |||||||||||||||||||
410 | - | |||||||||||||||||||
411 | - | |||||||||||||||||||
412 | - | |||||||||||||||||||
413 | - | |||||||||||||||||||
414 | for (i=0; i<16/sizeof(size_t)
| 0 | ||||||||||||||||||
415 | out_t[i] = in_t[i]^ctx->EKi.t[i]; never executed: out_t[i] = in_t[i]^ctx->EKi.t[i]; | 0 | ||||||||||||||||||
416 | out += 16; | - | ||||||||||||||||||
417 | in += 16; | - | ||||||||||||||||||
418 | j -= 16; | - | ||||||||||||||||||
419 | } never executed: end of block | 0 | ||||||||||||||||||
420 | len -= (3*1024); | - | ||||||||||||||||||
421 | } never executed: end of block | 0 | ||||||||||||||||||
422 | if ((
| 0-16 | ||||||||||||||||||
423 | (*gcm_ghash_p)(ctx->Xi.u,ctx->Htable,in,i); | - | ||||||||||||||||||
424 | while (len>=16
| 16-60 | ||||||||||||||||||
425 | size_t *out_t=(size_t *)out; | - | ||||||||||||||||||
426 | const size_t *in_t=(const size_t *)in; | - | ||||||||||||||||||
427 | - | |||||||||||||||||||
428 | (*block)(ctx->Yi.c,ctx->EKi.c,key); | - | ||||||||||||||||||
429 | ++ctr; | - | ||||||||||||||||||
430 | - | |||||||||||||||||||
431 | - | |||||||||||||||||||
432 | ctx->Yi.d[3] = ({ u32 ret=(ctr); asm ("bswapl %0" : "+r"(ret)); ret; }); | - | ||||||||||||||||||
433 | - | |||||||||||||||||||
434 | - | |||||||||||||||||||
435 | - | |||||||||||||||||||
436 | - | |||||||||||||||||||
437 | - | |||||||||||||||||||
438 | - | |||||||||||||||||||
439 | for (i=0; i<16/sizeof(size_t)
| 60-120 | ||||||||||||||||||
440 | out_t[i] = in_t[i]^ctx->EKi.t[i]; executed 120 times by 1 test: out_t[i] = in_t[i]^ctx->EKi.t[i]; Executed by:
| 120 | ||||||||||||||||||
441 | out += 16; | - | ||||||||||||||||||
442 | in += 16; | - | ||||||||||||||||||
443 | len -= 16; | - | ||||||||||||||||||
444 | } executed 60 times by 1 test: end of block Executed by:
| 60 | ||||||||||||||||||
445 | } executed 16 times by 1 test: end of block Executed by:
| 16 | ||||||||||||||||||
446 | if (len
| 7-9 | ||||||||||||||||||
447 | (*block)(ctx->Yi.c,ctx->EKi.c,key); | - | ||||||||||||||||||
448 | ++ctr; | - | ||||||||||||||||||
449 | - | |||||||||||||||||||
450 | - | |||||||||||||||||||
451 | ctx->Yi.d[3] = ({ u32 ret=(ctr); asm ("bswapl %0" : "+r"(ret)); ret; }); | - | ||||||||||||||||||
452 | - | |||||||||||||||||||
453 | - | |||||||||||||||||||
454 | - | |||||||||||||||||||
455 | - | |||||||||||||||||||
456 | - | |||||||||||||||||||
457 | - | |||||||||||||||||||
458 | while (len--
| 9-108 | ||||||||||||||||||
459 | u8 c = in[n]; | - | ||||||||||||||||||
460 | ctx->Xi.c[n] ^= c; | - | ||||||||||||||||||
461 | out[n] = c^ctx->EKi.c[n]; | - | ||||||||||||||||||
462 | ++n; | - | ||||||||||||||||||
463 | } executed 108 times by 1 test: end of block Executed by:
| 108 | ||||||||||||||||||
464 | } executed 9 times by 1 test: end of block Executed by:
| 9 | ||||||||||||||||||
465 | - | |||||||||||||||||||
466 | ctx->mres = n; | - | ||||||||||||||||||
467 | return executed 16 times by 1 test: 0;return 0; Executed by:
executed 16 times by 1 test: return 0; Executed by:
| 16 | ||||||||||||||||||
468 | } never executed: while(0);end of block | 0 | ||||||||||||||||||
469 | - | |||||||||||||||||||
470 | for (i=0;i<len
| 0 | ||||||||||||||||||
471 | u8 c; | - | ||||||||||||||||||
472 | if (n==0
| 0 | ||||||||||||||||||
473 | (*block)(ctx->Yi.c,ctx->EKi.c,key); | - | ||||||||||||||||||
474 | ++ctr; | - | ||||||||||||||||||
475 | - | |||||||||||||||||||
476 | - | |||||||||||||||||||
477 | ctx->Yi.d[3] = ({ u32 ret=(ctr); asm ("bswapl %0" : "+r"(ret)); ret; }); | - | ||||||||||||||||||
478 | - | |||||||||||||||||||
479 | - | |||||||||||||||||||
480 | - | |||||||||||||||||||
481 | - | |||||||||||||||||||
482 | - | |||||||||||||||||||
483 | - | |||||||||||||||||||
484 | } never executed: end of block | 0 | ||||||||||||||||||
485 | c = in[i]; | - | ||||||||||||||||||
486 | out[i] = c^ctx->EKi.c[n]; | - | ||||||||||||||||||
487 | ctx->Xi.c[n] ^= c; | - | ||||||||||||||||||
488 | n = (n+1)%16; | - | ||||||||||||||||||
489 | if (n==0
| 0 | ||||||||||||||||||
490 | (* never executed: gcm_gmult_p)(ctx->Xi.u,ctx->Htable);(*gcm_gmult_p)(ctx->Xi.u,ctx->Htable); never executed: (*gcm_gmult_p)(ctx->Xi.u,ctx->Htable); | 0 | ||||||||||||||||||
491 | } never executed: end of block | 0 | ||||||||||||||||||
492 | - | |||||||||||||||||||
493 | ctx->mres = n; | - | ||||||||||||||||||
494 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
495 | } | - | ||||||||||||||||||
496 | - | |||||||||||||||||||
497 | int CRYPTO_gcm128_encrypt_ctr32(GCM128_CONTEXT *ctx, | - | ||||||||||||||||||
498 | const unsigned char *in, unsigned char *out, | - | ||||||||||||||||||
499 | size_t len, ctr128_f stream) | - | ||||||||||||||||||
500 | { | - | ||||||||||||||||||
501 | unsigned int n, ctr; | - | ||||||||||||||||||
502 | size_t i; | - | ||||||||||||||||||
503 | u64 mlen = ctx->len.u[1]; | - | ||||||||||||||||||
504 | void *key = ctx->key; | - | ||||||||||||||||||
505 | - | |||||||||||||||||||
506 | void (*gcm_gmult_p)(u64 Xi[2],const u128 Htable[16]) = ctx->gmult; | - | ||||||||||||||||||
507 | - | |||||||||||||||||||
508 | void (*gcm_ghash_p)(u64 Xi[2],const u128 Htable[16], | - | ||||||||||||||||||
509 | const u8 *inp,size_t len) = ctx->ghash; | - | ||||||||||||||||||
510 | - | |||||||||||||||||||
511 | - | |||||||||||||||||||
512 | - | |||||||||||||||||||
513 | mlen += len; | - | ||||||||||||||||||
514 | if (mlen>((1UL<<36)-32)
| 0-40 | ||||||||||||||||||
515 | return never executed: -1;return -1; never executed: return -1; | 0 | ||||||||||||||||||
516 | ctx->len.u[1] = mlen; | - | ||||||||||||||||||
517 | - | |||||||||||||||||||
518 | if (ctx->ares
| 0-40 | ||||||||||||||||||
519 | - | |||||||||||||||||||
520 | (*gcm_gmult_p)(ctx->Xi.u,ctx->Htable); | - | ||||||||||||||||||
521 | ctx->ares = 0; | - | ||||||||||||||||||
522 | } executed 40 times by 2 tests: end of block Executed by:
| 40 | ||||||||||||||||||
523 | - | |||||||||||||||||||
524 | - | |||||||||||||||||||
525 | - | |||||||||||||||||||
526 | ctr = ({ u32 ret=(ctx->Yi.d[3]); asm ("bswapl %0" : "+r"(ret)); ret; }); | - | ||||||||||||||||||
527 | - | |||||||||||||||||||
528 | - | |||||||||||||||||||
529 | - | |||||||||||||||||||
530 | - | |||||||||||||||||||
531 | - | |||||||||||||||||||
532 | - | |||||||||||||||||||
533 | - | |||||||||||||||||||
534 | n = ctx->mres; | - | ||||||||||||||||||
535 | if (n
| 0-40 | ||||||||||||||||||
536 | while (n
| 0 | ||||||||||||||||||
537 | ctx->Xi.c[n] ^= *(out++) = *(in++)^ctx->EKi.c[n]; | - | ||||||||||||||||||
538 | --len; | - | ||||||||||||||||||
539 | n = (n+1)%16; | - | ||||||||||||||||||
540 | } never executed: end of block | 0 | ||||||||||||||||||
541 | if (n==0
never executed: gcm_gmult_p)(ctx->Xi.u,ctx->Htable);(*gcm_gmult_p)(ctx->Xi.u,ctx->Htable); never executed: (*gcm_gmult_p)(ctx->Xi.u,ctx->Htable); | 0 | ||||||||||||||||||
542 | else { | - | ||||||||||||||||||
543 | ctx->mres = n; | - | ||||||||||||||||||
544 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
545 | } | - | ||||||||||||||||||
546 | } | - | ||||||||||||||||||
547 | - | |||||||||||||||||||
548 | while (len>=(3*1024)
| 0-40 | ||||||||||||||||||
549 | (*stream)(in,out,(3*1024)/16,key,ctx->Yi.c); | - | ||||||||||||||||||
550 | ctr += (3*1024)/16; | - | ||||||||||||||||||
551 | - | |||||||||||||||||||
552 | - | |||||||||||||||||||
553 | ctx->Yi.d[3] = ({ u32 ret=(ctr); asm ("bswapl %0" : "+r"(ret)); ret; }); | - | ||||||||||||||||||
554 | - | |||||||||||||||||||
555 | - | |||||||||||||||||||
556 | - | |||||||||||||||||||
557 | - | |||||||||||||||||||
558 | - | |||||||||||||||||||
559 | - | |||||||||||||||||||
560 | (*gcm_ghash_p)(ctx->Xi.u,ctx->Htable,out,(3*1024)); | - | ||||||||||||||||||
561 | out += (3*1024); | - | ||||||||||||||||||
562 | in += (3*1024); | - | ||||||||||||||||||
563 | len -= (3*1024); | - | ||||||||||||||||||
564 | } never executed: end of block | 0 | ||||||||||||||||||
565 | - | |||||||||||||||||||
566 | if ((
| 14-26 | ||||||||||||||||||
567 | size_t j=i/16; | - | ||||||||||||||||||
568 | - | |||||||||||||||||||
569 | (*stream)(in,out,j,key,ctx->Yi.c); | - | ||||||||||||||||||
570 | ctr += (unsigned int)j; | - | ||||||||||||||||||
571 | - | |||||||||||||||||||
572 | - | |||||||||||||||||||
573 | ctx->Yi.d[3] = ({ u32 ret=(ctr); asm ("bswapl %0" : "+r"(ret)); ret; }); | - | ||||||||||||||||||
574 | - | |||||||||||||||||||
575 | - | |||||||||||||||||||
576 | - | |||||||||||||||||||
577 | - | |||||||||||||||||||
578 | - | |||||||||||||||||||
579 | - | |||||||||||||||||||
580 | in += i; | - | ||||||||||||||||||
581 | len -= i; | - | ||||||||||||||||||
582 | - | |||||||||||||||||||
583 | (*gcm_ghash_p)(ctx->Xi.u,ctx->Htable,out,i); | - | ||||||||||||||||||
584 | out += i; | - | ||||||||||||||||||
585 | - | |||||||||||||||||||
586 | - | |||||||||||||||||||
587 | - | |||||||||||||||||||
588 | - | |||||||||||||||||||
589 | - | |||||||||||||||||||
590 | - | |||||||||||||||||||
591 | - | |||||||||||||||||||
592 | } executed 26 times by 2 tests: end of block Executed by:
| 26 | ||||||||||||||||||
593 | if (len
| 14-26 | ||||||||||||||||||
594 | (*ctx->block)(ctx->Yi.c,ctx->EKi.c,key); | - | ||||||||||||||||||
595 | ++ctr; | - | ||||||||||||||||||
596 | - | |||||||||||||||||||
597 | - | |||||||||||||||||||
598 | ctx->Yi.d[3] = ({ u32 ret=(ctr); asm ("bswapl %0" : "+r"(ret)); ret; }); | - | ||||||||||||||||||
599 | - | |||||||||||||||||||
600 | - | |||||||||||||||||||
601 | - | |||||||||||||||||||
602 | - | |||||||||||||||||||
603 | - | |||||||||||||||||||
604 | - | |||||||||||||||||||
605 | while (len--
| 14-54 | ||||||||||||||||||
606 | ctx->Xi.c[n] ^= out[n] = in[n]^ctx->EKi.c[n]; | - | ||||||||||||||||||
607 | ++n; | - | ||||||||||||||||||
608 | } executed 54 times by 2 tests: end of block Executed by:
| 54 | ||||||||||||||||||
609 | } executed 14 times by 2 tests: end of block Executed by:
| 14 | ||||||||||||||||||
610 | - | |||||||||||||||||||
611 | ctx->mres = n; | - | ||||||||||||||||||
612 | return executed 40 times by 2 tests: 0;return 0; Executed by:
executed 40 times by 2 tests: return 0; Executed by:
| 40 | ||||||||||||||||||
613 | } | - | ||||||||||||||||||
614 | - | |||||||||||||||||||
615 | int CRYPTO_gcm128_decrypt_ctr32(GCM128_CONTEXT *ctx, | - | ||||||||||||||||||
616 | const unsigned char *in, unsigned char *out, | - | ||||||||||||||||||
617 | size_t len,ctr128_f stream) | - | ||||||||||||||||||
618 | { | - | ||||||||||||||||||
619 | unsigned int n, ctr; | - | ||||||||||||||||||
620 | size_t i; | - | ||||||||||||||||||
621 | u64 mlen = ctx->len.u[1]; | - | ||||||||||||||||||
622 | void *key = ctx->key; | - | ||||||||||||||||||
623 | - | |||||||||||||||||||
624 | void (*gcm_gmult_p)(u64 Xi[2],const u128 Htable[16]) = ctx->gmult; | - | ||||||||||||||||||
625 | - | |||||||||||||||||||
626 | void (*gcm_ghash_p)(u64 Xi[2],const u128 Htable[16], | - | ||||||||||||||||||
627 | const u8 *inp,size_t len) = ctx->ghash; | - | ||||||||||||||||||
628 | - | |||||||||||||||||||
629 | - | |||||||||||||||||||
630 | - | |||||||||||||||||||
631 | mlen += len; | - | ||||||||||||||||||
632 | if (mlen>((1UL<<36)-32)
| 0-32 | ||||||||||||||||||
633 | return never executed: -1;return -1; never executed: return -1; | 0 | ||||||||||||||||||
634 | ctx->len.u[1] = mlen; | - | ||||||||||||||||||
635 | - | |||||||||||||||||||
636 | if (ctx->ares
| 0-32 | ||||||||||||||||||
637 | - | |||||||||||||||||||
638 | (*gcm_gmult_p)(ctx->Xi.u,ctx->Htable); | - | ||||||||||||||||||
639 | ctx->ares = 0; | - | ||||||||||||||||||
640 | } executed 32 times by 2 tests: end of block Executed by:
| 32 | ||||||||||||||||||
641 | - | |||||||||||||||||||
642 | - | |||||||||||||||||||
643 | - | |||||||||||||||||||
644 | ctr = ({ u32 ret=(ctx->Yi.d[3]); asm ("bswapl %0" : "+r"(ret)); ret; }); | - | ||||||||||||||||||
645 | - | |||||||||||||||||||
646 | - | |||||||||||||||||||
647 | - | |||||||||||||||||||
648 | - | |||||||||||||||||||
649 | - | |||||||||||||||||||
650 | - | |||||||||||||||||||
651 | - | |||||||||||||||||||
652 | n = ctx->mres; | - | ||||||||||||||||||
653 | if (n
| 0-32 | ||||||||||||||||||
654 | while (n
| 0 | ||||||||||||||||||
655 | u8 c = *(in++); | - | ||||||||||||||||||
656 | *(out++) = c^ctx->EKi.c[n]; | - | ||||||||||||||||||
657 | ctx->Xi.c[n] ^= c; | - | ||||||||||||||||||
658 | --len; | - | ||||||||||||||||||
659 | n = (n+1)%16; | - | ||||||||||||||||||
660 | } never executed: end of block | 0 | ||||||||||||||||||
661 | if (n==0
never executed: gcm_gmult_p)(ctx->Xi.u,ctx->Htable);(*gcm_gmult_p)(ctx->Xi.u,ctx->Htable); never executed: (*gcm_gmult_p)(ctx->Xi.u,ctx->Htable); | 0 | ||||||||||||||||||
662 | else { | - | ||||||||||||||||||
663 | ctx->mres = n; | - | ||||||||||||||||||
664 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
665 | } | - | ||||||||||||||||||
666 | } | - | ||||||||||||||||||
667 | - | |||||||||||||||||||
668 | while (len>=(3*1024)
| 0-32 | ||||||||||||||||||
669 | (*gcm_ghash_p)(ctx->Xi.u,ctx->Htable,in,(3*1024)); | - | ||||||||||||||||||
670 | (*stream)(in,out,(3*1024)/16,key,ctx->Yi.c); | - | ||||||||||||||||||
671 | ctr += (3*1024)/16; | - | ||||||||||||||||||
672 | - | |||||||||||||||||||
673 | - | |||||||||||||||||||
674 | ctx->Yi.d[3] = ({ u32 ret=(ctr); asm ("bswapl %0" : "+r"(ret)); ret; }); | - | ||||||||||||||||||
675 | - | |||||||||||||||||||
676 | - | |||||||||||||||||||
677 | - | |||||||||||||||||||
678 | - | |||||||||||||||||||
679 | - | |||||||||||||||||||
680 | - | |||||||||||||||||||
681 | out += (3*1024); | - | ||||||||||||||||||
682 | in += (3*1024); | - | ||||||||||||||||||
683 | len -= (3*1024); | - | ||||||||||||||||||
684 | } never executed: end of block | 0 | ||||||||||||||||||
685 | - | |||||||||||||||||||
686 | if ((
| 4-28 | ||||||||||||||||||
687 | size_t j=i/16; | - | ||||||||||||||||||
688 | - | |||||||||||||||||||
689 | - | |||||||||||||||||||
690 | (*gcm_ghash_p)(ctx->Xi.u,ctx->Htable,in,i); | - | ||||||||||||||||||
691 | (*stream)(in,out,j,key,ctx->Yi.c); | - | ||||||||||||||||||
692 | ctr += (unsigned int)j; | - | ||||||||||||||||||
693 | - | |||||||||||||||||||
694 | - | |||||||||||||||||||
695 | ctx->Yi.d[3] = ({ u32 ret=(ctr); asm ("bswapl %0" : "+r"(ret)); ret; }); | - | ||||||||||||||||||
696 | - | |||||||||||||||||||
697 | - | |||||||||||||||||||
698 | - | |||||||||||||||||||
699 | - | |||||||||||||||||||
700 | - | |||||||||||||||||||
701 | - | |||||||||||||||||||
702 | out += i; | - | ||||||||||||||||||
703 | in += i; | - | ||||||||||||||||||
704 | len -= i; | - | ||||||||||||||||||
705 | } executed 28 times by 2 tests: end of block Executed by:
| 28 | ||||||||||||||||||
706 | if (len
| 4-28 | ||||||||||||||||||
707 | (*ctx->block)(ctx->Yi.c,ctx->EKi.c,key); | - | ||||||||||||||||||
708 | ++ctr; | - | ||||||||||||||||||
709 | - | |||||||||||||||||||
710 | - | |||||||||||||||||||
711 | ctx->Yi.d[3] = ({ u32 ret=(ctr); asm ("bswapl %0" : "+r"(ret)); ret; }); | - | ||||||||||||||||||
712 | - | |||||||||||||||||||
713 | - | |||||||||||||||||||
714 | - | |||||||||||||||||||
715 | - | |||||||||||||||||||
716 | - | |||||||||||||||||||
717 | - | |||||||||||||||||||
718 | while (len--
| 4-60 | ||||||||||||||||||
719 | u8 c = in[n]; | - | ||||||||||||||||||
720 | ctx->Xi.c[n] ^= c; | - | ||||||||||||||||||
721 | out[n] = c^ctx->EKi.c[n]; | - | ||||||||||||||||||
722 | ++n; | - | ||||||||||||||||||
723 | } executed 60 times by 1 test: end of block Executed by:
| 60 | ||||||||||||||||||
724 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||
725 | - | |||||||||||||||||||
726 | ctx->mres = n; | - | ||||||||||||||||||
727 | return executed 32 times by 2 tests: 0;return 0; Executed by:
executed 32 times by 2 tests: return 0; Executed by:
| 32 | ||||||||||||||||||
728 | } | - | ||||||||||||||||||
729 | - | |||||||||||||||||||
730 | int CRYPTO_gcm128_finish(GCM128_CONTEXT *ctx,const unsigned char *tag, | - | ||||||||||||||||||
731 | size_t len) | - | ||||||||||||||||||
732 | { | - | ||||||||||||||||||
733 | u64 alen = ctx->len.u[0]<<3; | - | ||||||||||||||||||
734 | u64 clen = ctx->len.u[1]<<3; | - | ||||||||||||||||||
735 | - | |||||||||||||||||||
736 | void (*gcm_gmult_p)(u64 Xi[2],const u128 Htable[16]) = ctx->gmult; | - | ||||||||||||||||||
737 | - | |||||||||||||||||||
738 | - | |||||||||||||||||||
739 | if (ctx->mres
| 0-76 | ||||||||||||||||||
740 | (* executed 36 times by 3 tests: gcm_gmult_p)(ctx->Xi.u,ctx->Htable);(*gcm_gmult_p)(ctx->Xi.u,ctx->Htable); Executed by:
executed 36 times by 3 tests: (*gcm_gmult_p)(ctx->Xi.u,ctx->Htable); Executed by:
| 36 | ||||||||||||||||||
741 | - | |||||||||||||||||||
742 | - | |||||||||||||||||||
743 | - | |||||||||||||||||||
744 | alen = ({ u64 ret=(alen); asm ("bswapq %0" : "+r"(ret)); ret; }); | - | ||||||||||||||||||
745 | clen = ({ u64 ret=(clen); asm ("bswapq %0" : "+r"(ret)); ret; }); | - | ||||||||||||||||||
746 | ctx->Xi.u[0] ^= alen; | - | ||||||||||||||||||
747 | ctx->Xi.u[1] ^= clen; | - | ||||||||||||||||||
748 | (*gcm_gmult_p)(ctx->Xi.u,ctx->Htable); | - | ||||||||||||||||||
749 | - | |||||||||||||||||||
750 | ctx->Xi.u[0] ^= ctx->EK0.u[0]; | - | ||||||||||||||||||
751 | ctx->Xi.u[1] ^= ctx->EK0.u[1]; | - | ||||||||||||||||||
752 | - | |||||||||||||||||||
753 | if (tag
| 0-72 | ||||||||||||||||||
754 | return executed 40 times by 1 test: memcmp(ctx->Xi.c,tag,len);return memcmp(ctx->Xi.c,tag,len); Executed by:
executed 40 times by 1 test: return memcmp(ctx->Xi.c,tag,len); Executed by:
| 40 | ||||||||||||||||||
755 | else | - | ||||||||||||||||||
756 | return executed 72 times by 2 tests: -1;return -1; Executed by:
executed 72 times by 2 tests: return -1; Executed by:
| 72 | ||||||||||||||||||
757 | } | - | ||||||||||||||||||
758 | - | |||||||||||||||||||
759 | void CRYPTO_gcm128_tag(GCM128_CONTEXT *ctx, unsigned char *tag, size_t len) | - | ||||||||||||||||||
760 | { | - | ||||||||||||||||||
761 | CRYPTO_gcm128_finish(ctx, | - | ||||||||||||||||||
762 | ((void *)0) | - | ||||||||||||||||||
763 | , 0); | - | ||||||||||||||||||
764 | memcpy(tag, ctx->Xi.c, len<=sizeof(ctx->Xi.c)?len:sizeof(ctx->Xi.c)); | - | ||||||||||||||||||
765 | } executed 72 times by 2 tests: end of block Executed by:
| 72 | ||||||||||||||||||
766 | - | |||||||||||||||||||
767 | GCM128_CONTEXT *CRYPTO_gcm128_new(void *key, block128_f block) | - | ||||||||||||||||||
768 | { | - | ||||||||||||||||||
769 | GCM128_CONTEXT *ret; | - | ||||||||||||||||||
770 | - | |||||||||||||||||||
771 | if ((
| 0 | ||||||||||||||||||
772 | CRYPTO_gcm128_init(ret,key,block); never executed: CRYPTO_gcm128_init(ret,key,block); | 0 | ||||||||||||||||||
773 | - | |||||||||||||||||||
774 | return never executed: ret;return ret; never executed: return ret; | 0 | ||||||||||||||||||
775 | } | - | ||||||||||||||||||
776 | - | |||||||||||||||||||
777 | void CRYPTO_gcm128_release(GCM128_CONTEXT *ctx) | - | ||||||||||||||||||
778 | { | - | ||||||||||||||||||
779 | freezero(ctx, sizeof(*ctx)); | - | ||||||||||||||||||
780 | } never executed: end of block | 0 | ||||||||||||||||||
Switch to Source code | Preprocessed file |