Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/libressl/src/crypto/modes/ccm128.c |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | void CRYPTO_ccm128_init(CCM128_CONTEXT *ctx, | - | ||||||||||||||||||
2 | unsigned int M,unsigned int L,void *key,block128_f block) | - | ||||||||||||||||||
3 | { | - | ||||||||||||||||||
4 | memset(ctx->nonce.c,0,sizeof(ctx->nonce.c)); | - | ||||||||||||||||||
5 | ctx->nonce.c[0] = ((u8)(L-1)&7) | (u8)(((M-2)/2)&7)<<3; | - | ||||||||||||||||||
6 | ctx->blocks = 0; | - | ||||||||||||||||||
7 | ctx->block = block; | - | ||||||||||||||||||
8 | ctx->key = key; | - | ||||||||||||||||||
9 | } never executed: end of block | 0 | ||||||||||||||||||
10 | - | |||||||||||||||||||
11 | - | |||||||||||||||||||
12 | - | |||||||||||||||||||
13 | - | |||||||||||||||||||
14 | int CRYPTO_ccm128_setiv(CCM128_CONTEXT *ctx, | - | ||||||||||||||||||
15 | const unsigned char *nonce,size_t nlen,size_t mlen) | - | ||||||||||||||||||
16 | { | - | ||||||||||||||||||
17 | unsigned int L = ctx->nonce.c[0]&7; | - | ||||||||||||||||||
18 | - | |||||||||||||||||||
19 | if (nlen<(14-L)
never executed: -1;return -1; never executed: return -1; | 0 | ||||||||||||||||||
20 | - | |||||||||||||||||||
21 | if (sizeof(mlen)==8
| 0 | ||||||||||||||||||
22 | ctx->nonce.c[8] = (u8)(mlen>>(56%(sizeof(mlen)*8))); | - | ||||||||||||||||||
23 | ctx->nonce.c[9] = (u8)(mlen>>(48%(sizeof(mlen)*8))); | - | ||||||||||||||||||
24 | ctx->nonce.c[10] = (u8)(mlen>>(40%(sizeof(mlen)*8))); | - | ||||||||||||||||||
25 | ctx->nonce.c[11] = (u8)(mlen>>(32%(sizeof(mlen)*8))); | - | ||||||||||||||||||
26 | } never executed: end of block | 0 | ||||||||||||||||||
27 | else | - | ||||||||||||||||||
28 | ctx->nonce.u[1] = 0; never executed: ctx->nonce.u[1] = 0; | 0 | ||||||||||||||||||
29 | - | |||||||||||||||||||
30 | ctx->nonce.c[12] = (u8)(mlen>>24); | - | ||||||||||||||||||
31 | ctx->nonce.c[13] = (u8)(mlen>>16); | - | ||||||||||||||||||
32 | ctx->nonce.c[14] = (u8)(mlen>>8); | - | ||||||||||||||||||
33 | ctx->nonce.c[15] = (u8)mlen; | - | ||||||||||||||||||
34 | - | |||||||||||||||||||
35 | ctx->nonce.c[0] &= ~0x40; | - | ||||||||||||||||||
36 | memcpy(&ctx->nonce.c[1],nonce,14-L); | - | ||||||||||||||||||
37 | - | |||||||||||||||||||
38 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
39 | } | - | ||||||||||||||||||
40 | - | |||||||||||||||||||
41 | - | |||||||||||||||||||
42 | void CRYPTO_ccm128_aad(CCM128_CONTEXT *ctx, | - | ||||||||||||||||||
43 | const unsigned char *aad,size_t alen) | - | ||||||||||||||||||
44 | { unsigned int i; | - | ||||||||||||||||||
45 | block128_f block = ctx->block; | - | ||||||||||||||||||
46 | - | |||||||||||||||||||
47 | if (alen==0
never executed: return; | 0 | ||||||||||||||||||
48 | - | |||||||||||||||||||
49 | ctx->nonce.c[0] |= 0x40; | - | ||||||||||||||||||
50 | (*block)(ctx->nonce.c,ctx->cmac.c,ctx->key), | - | ||||||||||||||||||
51 | ctx->blocks++; | - | ||||||||||||||||||
52 | - | |||||||||||||||||||
53 | if (alen<(0x10000-0x100)
| 0 | ||||||||||||||||||
54 | ctx->cmac.c[0] ^= (u8)(alen>>8); | - | ||||||||||||||||||
55 | ctx->cmac.c[1] ^= (u8)alen; | - | ||||||||||||||||||
56 | i=2; | - | ||||||||||||||||||
57 | } never executed: end of block | 0 | ||||||||||||||||||
58 | else if (sizeof(alen)==8
| 0 | ||||||||||||||||||
59 | ctx->cmac.c[0] ^= 0xFF; | - | ||||||||||||||||||
60 | ctx->cmac.c[1] ^= 0xFF; | - | ||||||||||||||||||
61 | ctx->cmac.c[2] ^= (u8)(alen>>(56%(sizeof(alen)*8))); | - | ||||||||||||||||||
62 | ctx->cmac.c[3] ^= (u8)(alen>>(48%(sizeof(alen)*8))); | - | ||||||||||||||||||
63 | ctx->cmac.c[4] ^= (u8)(alen>>(40%(sizeof(alen)*8))); | - | ||||||||||||||||||
64 | ctx->cmac.c[5] ^= (u8)(alen>>(32%(sizeof(alen)*8))); | - | ||||||||||||||||||
65 | ctx->cmac.c[6] ^= (u8)(alen>>24); | - | ||||||||||||||||||
66 | ctx->cmac.c[7] ^= (u8)(alen>>16); | - | ||||||||||||||||||
67 | ctx->cmac.c[8] ^= (u8)(alen>>8); | - | ||||||||||||||||||
68 | ctx->cmac.c[9] ^= (u8)alen; | - | ||||||||||||||||||
69 | i=10; | - | ||||||||||||||||||
70 | } never executed: end of block | 0 | ||||||||||||||||||
71 | else { | - | ||||||||||||||||||
72 | ctx->cmac.c[0] ^= 0xFF; | - | ||||||||||||||||||
73 | ctx->cmac.c[1] ^= 0xFE; | - | ||||||||||||||||||
74 | ctx->cmac.c[2] ^= (u8)(alen>>24); | - | ||||||||||||||||||
75 | ctx->cmac.c[3] ^= (u8)(alen>>16); | - | ||||||||||||||||||
76 | ctx->cmac.c[4] ^= (u8)(alen>>8); | - | ||||||||||||||||||
77 | ctx->cmac.c[5] ^= (u8)alen; | - | ||||||||||||||||||
78 | i=6; | - | ||||||||||||||||||
79 | } never executed: end of block | 0 | ||||||||||||||||||
80 | - | |||||||||||||||||||
81 | do { | - | ||||||||||||||||||
82 | for(;i<16
| 0 | ||||||||||||||||||
83 | ctx->cmac.c[i] ^= *aad; never executed: ctx->cmac.c[i] ^= *aad; | 0 | ||||||||||||||||||
84 | (*block)(ctx->cmac.c,ctx->cmac.c,ctx->key), | - | ||||||||||||||||||
85 | ctx->blocks++; | - | ||||||||||||||||||
86 | i=0; | - | ||||||||||||||||||
87 | } never executed: while (alenend of block
| 0 | ||||||||||||||||||
88 | } never executed: end of block | 0 | ||||||||||||||||||
89 | - | |||||||||||||||||||
90 | - | |||||||||||||||||||
91 | - | |||||||||||||||||||
92 | - | |||||||||||||||||||
93 | - | |||||||||||||||||||
94 | static void ctr64_inc(unsigned char *counter) { | - | ||||||||||||||||||
95 | unsigned int n=8; | - | ||||||||||||||||||
96 | u8 c; | - | ||||||||||||||||||
97 | - | |||||||||||||||||||
98 | counter += 8; | - | ||||||||||||||||||
99 | do { | - | ||||||||||||||||||
100 | --n; | - | ||||||||||||||||||
101 | c = counter[n]; | - | ||||||||||||||||||
102 | ++c; | - | ||||||||||||||||||
103 | counter[n] = c; | - | ||||||||||||||||||
104 | if (c
never executed: return; | 0 | ||||||||||||||||||
105 | } never executed: while (nend of block
| 0 | ||||||||||||||||||
106 | } never executed: end of block | 0 | ||||||||||||||||||
107 | - | |||||||||||||||||||
108 | int CRYPTO_ccm128_encrypt(CCM128_CONTEXT *ctx, | - | ||||||||||||||||||
109 | const unsigned char *inp, unsigned char *out, | - | ||||||||||||||||||
110 | size_t len) | - | ||||||||||||||||||
111 | { | - | ||||||||||||||||||
112 | size_t n; | - | ||||||||||||||||||
113 | unsigned int i,L; | - | ||||||||||||||||||
114 | unsigned char flags0 = ctx->nonce.c[0]; | - | ||||||||||||||||||
115 | block128_f block = ctx->block; | - | ||||||||||||||||||
116 | void * key = ctx->key; | - | ||||||||||||||||||
117 | union { u64 u[2]; u8 c[16]; } scratch; | - | ||||||||||||||||||
118 | - | |||||||||||||||||||
119 | if (!(flags0&0x40)
| 0 | ||||||||||||||||||
120 | (* never executed: block)(ctx->nonce.c,ctx->cmac.c,key),(*block)(ctx->nonce.c,ctx->cmac.c,key), ctx->blocks++; never executed: (*block)(ctx->nonce.c,ctx->cmac.c,key), ctx->blocks++; | 0 | ||||||||||||||||||
121 | ctx->blocks++; never executed: (*block)(ctx->nonce.c,ctx->cmac.c,key), ctx->blocks++; | 0 | ||||||||||||||||||
122 | - | |||||||||||||||||||
123 | ctx->nonce.c[0] = L = flags0&7; | - | ||||||||||||||||||
124 | for (n=0,i=15-L;i<15
| 0 | ||||||||||||||||||
125 | n |= ctx->nonce.c[i]; | - | ||||||||||||||||||
126 | ctx->nonce.c[i]=0; | - | ||||||||||||||||||
127 | n <<= 8; | - | ||||||||||||||||||
128 | } never executed: end of block | 0 | ||||||||||||||||||
129 | n |= ctx->nonce.c[15]; | - | ||||||||||||||||||
130 | ctx->nonce.c[15]=1; | - | ||||||||||||||||||
131 | - | |||||||||||||||||||
132 | if (n!=len
never executed: -1;return -1; never executed: return -1; | 0 | ||||||||||||||||||
133 | - | |||||||||||||||||||
134 | ctx->blocks += ((len+15)>>3)|1; | - | ||||||||||||||||||
135 | if (ctx->blocks > (1UL<<61)
never executed: -2;return -2; never executed: return -2; | 0 | ||||||||||||||||||
136 | - | |||||||||||||||||||
137 | while (len>=16
| 0 | ||||||||||||||||||
138 | - | |||||||||||||||||||
139 | - | |||||||||||||||||||
140 | - | |||||||||||||||||||
141 | - | |||||||||||||||||||
142 | - | |||||||||||||||||||
143 | - | |||||||||||||||||||
144 | - | |||||||||||||||||||
145 | ctx->cmac.u[0] ^= ((u64*)inp)[0]; | - | ||||||||||||||||||
146 | ctx->cmac.u[1] ^= ((u64*)inp)[1]; | - | ||||||||||||||||||
147 | - | |||||||||||||||||||
148 | (*block)(ctx->cmac.c,ctx->cmac.c,key); | - | ||||||||||||||||||
149 | (*block)(ctx->nonce.c,scratch.c,key); | - | ||||||||||||||||||
150 | ctr64_inc(ctx->nonce.c); | - | ||||||||||||||||||
151 | - | |||||||||||||||||||
152 | - | |||||||||||||||||||
153 | - | |||||||||||||||||||
154 | - | |||||||||||||||||||
155 | - | |||||||||||||||||||
156 | ((u64*)out)[0] = scratch.u[0]^((u64*)inp)[0]; | - | ||||||||||||||||||
157 | ((u64*)out)[1] = scratch.u[1]^((u64*)inp)[1]; | - | ||||||||||||||||||
158 | - | |||||||||||||||||||
159 | inp += 16; | - | ||||||||||||||||||
160 | out += 16; | - | ||||||||||||||||||
161 | len -= 16; | - | ||||||||||||||||||
162 | } never executed: end of block | 0 | ||||||||||||||||||
163 | - | |||||||||||||||||||
164 | if (len
| 0 | ||||||||||||||||||
165 | for (i=0; i<len
never executed: ctx->cmac.c[i] ^= inp[i]; | 0 | ||||||||||||||||||
166 | (*block)(ctx->cmac.c,ctx->cmac.c,key); | - | ||||||||||||||||||
167 | (*block)(ctx->nonce.c,scratch.c,key); | - | ||||||||||||||||||
168 | for (i=0; i<len
never executed: out[i] = scratch.c[i]^inp[i]; | 0 | ||||||||||||||||||
169 | } never executed: end of block | 0 | ||||||||||||||||||
170 | - | |||||||||||||||||||
171 | for (i=15-L;i<16
| 0 | ||||||||||||||||||
172 | ctx->nonce.c[i]=0; never executed: ctx->nonce.c[i]=0; | 0 | ||||||||||||||||||
173 | - | |||||||||||||||||||
174 | (*block)(ctx->nonce.c,scratch.c,key); | - | ||||||||||||||||||
175 | ctx->cmac.u[0] ^= scratch.u[0]; | - | ||||||||||||||||||
176 | ctx->cmac.u[1] ^= scratch.u[1]; | - | ||||||||||||||||||
177 | - | |||||||||||||||||||
178 | ctx->nonce.c[0] = flags0; | - | ||||||||||||||||||
179 | - | |||||||||||||||||||
180 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
181 | } | - | ||||||||||||||||||
182 | - | |||||||||||||||||||
183 | int CRYPTO_ccm128_decrypt(CCM128_CONTEXT *ctx, | - | ||||||||||||||||||
184 | const unsigned char *inp, unsigned char *out, | - | ||||||||||||||||||
185 | size_t len) | - | ||||||||||||||||||
186 | { | - | ||||||||||||||||||
187 | size_t n; | - | ||||||||||||||||||
188 | unsigned int i,L; | - | ||||||||||||||||||
189 | unsigned char flags0 = ctx->nonce.c[0]; | - | ||||||||||||||||||
190 | block128_f block = ctx->block; | - | ||||||||||||||||||
191 | void * key = ctx->key; | - | ||||||||||||||||||
192 | union { u64 u[2]; u8 c[16]; } scratch; | - | ||||||||||||||||||
193 | - | |||||||||||||||||||
194 | if (!(flags0&0x40)
| 0 | ||||||||||||||||||
195 | (* never executed: block)(ctx->nonce.c,ctx->cmac.c,key);(*block)(ctx->nonce.c,ctx->cmac.c,key); never executed: (*block)(ctx->nonce.c,ctx->cmac.c,key); | 0 | ||||||||||||||||||
196 | - | |||||||||||||||||||
197 | ctx->nonce.c[0] = L = flags0&7; | - | ||||||||||||||||||
198 | for (n=0,i=15-L;i<15
| 0 | ||||||||||||||||||
199 | n |= ctx->nonce.c[i]; | - | ||||||||||||||||||
200 | ctx->nonce.c[i]=0; | - | ||||||||||||||||||
201 | n <<= 8; | - | ||||||||||||||||||
202 | } never executed: end of block | 0 | ||||||||||||||||||
203 | n |= ctx->nonce.c[15]; | - | ||||||||||||||||||
204 | ctx->nonce.c[15]=1; | - | ||||||||||||||||||
205 | - | |||||||||||||||||||
206 | if (n!=len
never executed: -1;return -1; never executed: return -1; | 0 | ||||||||||||||||||
207 | - | |||||||||||||||||||
208 | while (len>=16
| 0 | ||||||||||||||||||
209 | - | |||||||||||||||||||
210 | - | |||||||||||||||||||
211 | - | |||||||||||||||||||
212 | (*block)(ctx->nonce.c,scratch.c,key); | - | ||||||||||||||||||
213 | ctr64_inc(ctx->nonce.c); | - | ||||||||||||||||||
214 | - | |||||||||||||||||||
215 | - | |||||||||||||||||||
216 | - | |||||||||||||||||||
217 | - | |||||||||||||||||||
218 | - | |||||||||||||||||||
219 | - | |||||||||||||||||||
220 | ctx->cmac.u[0] ^= (((u64*)out)[0] = scratch.u[0]^((u64*)inp)[0]); | - | ||||||||||||||||||
221 | ctx->cmac.u[1] ^= (((u64*)out)[1] = scratch.u[1]^((u64*)inp)[1]); | - | ||||||||||||||||||
222 | - | |||||||||||||||||||
223 | (*block)(ctx->cmac.c,ctx->cmac.c,key); | - | ||||||||||||||||||
224 | - | |||||||||||||||||||
225 | inp += 16; | - | ||||||||||||||||||
226 | out += 16; | - | ||||||||||||||||||
227 | len -= 16; | - | ||||||||||||||||||
228 | } never executed: end of block | 0 | ||||||||||||||||||
229 | - | |||||||||||||||||||
230 | if (len
| 0 | ||||||||||||||||||
231 | (*block)(ctx->nonce.c,scratch.c,key); | - | ||||||||||||||||||
232 | for (i=0; i<len
| 0 | ||||||||||||||||||
233 | ctx->cmac.c[i] ^= (out[i] = scratch.c[i]^inp[i]); never executed: ctx->cmac.c[i] ^= (out[i] = scratch.c[i]^inp[i]); | 0 | ||||||||||||||||||
234 | (*block)(ctx->cmac.c,ctx->cmac.c,key); | - | ||||||||||||||||||
235 | } never executed: end of block | 0 | ||||||||||||||||||
236 | - | |||||||||||||||||||
237 | for (i=15-L;i<16
| 0 | ||||||||||||||||||
238 | ctx->nonce.c[i]=0; never executed: ctx->nonce.c[i]=0; | 0 | ||||||||||||||||||
239 | - | |||||||||||||||||||
240 | (*block)(ctx->nonce.c,scratch.c,key); | - | ||||||||||||||||||
241 | ctx->cmac.u[0] ^= scratch.u[0]; | - | ||||||||||||||||||
242 | ctx->cmac.u[1] ^= scratch.u[1]; | - | ||||||||||||||||||
243 | - | |||||||||||||||||||
244 | ctx->nonce.c[0] = flags0; | - | ||||||||||||||||||
245 | - | |||||||||||||||||||
246 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
247 | } | - | ||||||||||||||||||
248 | - | |||||||||||||||||||
249 | static void ctr64_add (unsigned char *counter,size_t inc) | - | ||||||||||||||||||
250 | { size_t n=8, val=0; | - | ||||||||||||||||||
251 | - | |||||||||||||||||||
252 | counter += 8; | - | ||||||||||||||||||
253 | do { | - | ||||||||||||||||||
254 | --n; | - | ||||||||||||||||||
255 | val += counter[n] + (inc&0xff); | - | ||||||||||||||||||
256 | counter[n] = (unsigned char)val; | - | ||||||||||||||||||
257 | val >>= 8; | - | ||||||||||||||||||
258 | inc >>= 8; | - | ||||||||||||||||||
259 | } never executed: while(nend of block
| 0 | ||||||||||||||||||
260 | } never executed: end of block | 0 | ||||||||||||||||||
261 | - | |||||||||||||||||||
262 | int CRYPTO_ccm128_encrypt_ccm64(CCM128_CONTEXT *ctx, | - | ||||||||||||||||||
263 | const unsigned char *inp, unsigned char *out, | - | ||||||||||||||||||
264 | size_t len,ccm128_f stream) | - | ||||||||||||||||||
265 | { | - | ||||||||||||||||||
266 | size_t n; | - | ||||||||||||||||||
267 | unsigned int i,L; | - | ||||||||||||||||||
268 | unsigned char flags0 = ctx->nonce.c[0]; | - | ||||||||||||||||||
269 | block128_f block = ctx->block; | - | ||||||||||||||||||
270 | void * key = ctx->key; | - | ||||||||||||||||||
271 | union { u64 u[2]; u8 c[16]; } scratch; | - | ||||||||||||||||||
272 | - | |||||||||||||||||||
273 | if (!(flags0&0x40)
| 0 | ||||||||||||||||||
274 | (* never executed: block)(ctx->nonce.c,ctx->cmac.c,key),(*block)(ctx->nonce.c,ctx->cmac.c,key), ctx->blocks++; never executed: (*block)(ctx->nonce.c,ctx->cmac.c,key), ctx->blocks++; | 0 | ||||||||||||||||||
275 | ctx->blocks++; never executed: (*block)(ctx->nonce.c,ctx->cmac.c,key), ctx->blocks++; | 0 | ||||||||||||||||||
276 | - | |||||||||||||||||||
277 | ctx->nonce.c[0] = L = flags0&7; | - | ||||||||||||||||||
278 | for (n=0,i=15-L;i<15
| 0 | ||||||||||||||||||
279 | n |= ctx->nonce.c[i]; | - | ||||||||||||||||||
280 | ctx->nonce.c[i]=0; | - | ||||||||||||||||||
281 | n <<= 8; | - | ||||||||||||||||||
282 | } never executed: end of block | 0 | ||||||||||||||||||
283 | n |= ctx->nonce.c[15]; | - | ||||||||||||||||||
284 | ctx->nonce.c[15]=1; | - | ||||||||||||||||||
285 | - | |||||||||||||||||||
286 | if (n!=len
never executed: -1;return -1; never executed: return -1; | 0 | ||||||||||||||||||
287 | - | |||||||||||||||||||
288 | ctx->blocks += ((len+15)>>3)|1; | - | ||||||||||||||||||
289 | if (ctx->blocks > (1UL<<61)
never executed: -2;return -2; never executed: return -2; | 0 | ||||||||||||||||||
290 | - | |||||||||||||||||||
291 | if ((
| 0 | ||||||||||||||||||
292 | (*stream)(inp,out,n,key,ctx->nonce.c,ctx->cmac.c); | - | ||||||||||||||||||
293 | n *= 16; | - | ||||||||||||||||||
294 | inp += n; | - | ||||||||||||||||||
295 | out += n; | - | ||||||||||||||||||
296 | len -= n; | - | ||||||||||||||||||
297 | if (len
never executed: ctr64_add(ctx->nonce.c,n/16); | 0 | ||||||||||||||||||
298 | } never executed: end of block | 0 | ||||||||||||||||||
299 | - | |||||||||||||||||||
300 | if (len
| 0 | ||||||||||||||||||
301 | for (i=0; i<len
never executed: ctx->cmac.c[i] ^= inp[i]; | 0 | ||||||||||||||||||
302 | (*block)(ctx->cmac.c,ctx->cmac.c,key); | - | ||||||||||||||||||
303 | (*block)(ctx->nonce.c,scratch.c,key); | - | ||||||||||||||||||
304 | for (i=0; i<len
never executed: out[i] = scratch.c[i]^inp[i]; | 0 | ||||||||||||||||||
305 | } never executed: end of block | 0 | ||||||||||||||||||
306 | - | |||||||||||||||||||
307 | for (i=15-L;i<16
| 0 | ||||||||||||||||||
308 | ctx->nonce.c[i]=0; never executed: ctx->nonce.c[i]=0; | 0 | ||||||||||||||||||
309 | - | |||||||||||||||||||
310 | (*block)(ctx->nonce.c,scratch.c,key); | - | ||||||||||||||||||
311 | ctx->cmac.u[0] ^= scratch.u[0]; | - | ||||||||||||||||||
312 | ctx->cmac.u[1] ^= scratch.u[1]; | - | ||||||||||||||||||
313 | - | |||||||||||||||||||
314 | ctx->nonce.c[0] = flags0; | - | ||||||||||||||||||
315 | - | |||||||||||||||||||
316 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
317 | } | - | ||||||||||||||||||
318 | - | |||||||||||||||||||
319 | int CRYPTO_ccm128_decrypt_ccm64(CCM128_CONTEXT *ctx, | - | ||||||||||||||||||
320 | const unsigned char *inp, unsigned char *out, | - | ||||||||||||||||||
321 | size_t len,ccm128_f stream) | - | ||||||||||||||||||
322 | { | - | ||||||||||||||||||
323 | size_t n; | - | ||||||||||||||||||
324 | unsigned int i,L; | - | ||||||||||||||||||
325 | unsigned char flags0 = ctx->nonce.c[0]; | - | ||||||||||||||||||
326 | block128_f block = ctx->block; | - | ||||||||||||||||||
327 | void * key = ctx->key; | - | ||||||||||||||||||
328 | union { u64 u[2]; u8 c[16]; } scratch; | - | ||||||||||||||||||
329 | - | |||||||||||||||||||
330 | if (!(flags0&0x40)
| 0 | ||||||||||||||||||
331 | (* never executed: block)(ctx->nonce.c,ctx->cmac.c,key);(*block)(ctx->nonce.c,ctx->cmac.c,key); never executed: (*block)(ctx->nonce.c,ctx->cmac.c,key); | 0 | ||||||||||||||||||
332 | - | |||||||||||||||||||
333 | ctx->nonce.c[0] = L = flags0&7; | - | ||||||||||||||||||
334 | for (n=0,i=15-L;i<15
| 0 | ||||||||||||||||||
335 | n |= ctx->nonce.c[i]; | - | ||||||||||||||||||
336 | ctx->nonce.c[i]=0; | - | ||||||||||||||||||
337 | n <<= 8; | - | ||||||||||||||||||
338 | } never executed: end of block | 0 | ||||||||||||||||||
339 | n |= ctx->nonce.c[15]; | - | ||||||||||||||||||
340 | ctx->nonce.c[15]=1; | - | ||||||||||||||||||
341 | - | |||||||||||||||||||
342 | if (n!=len
never executed: -1;return -1; never executed: return -1; | 0 | ||||||||||||||||||
343 | - | |||||||||||||||||||
344 | if ((
| 0 | ||||||||||||||||||
345 | (*stream)(inp,out,n,key,ctx->nonce.c,ctx->cmac.c); | - | ||||||||||||||||||
346 | n *= 16; | - | ||||||||||||||||||
347 | inp += n; | - | ||||||||||||||||||
348 | out += n; | - | ||||||||||||||||||
349 | len -= n; | - | ||||||||||||||||||
350 | if (len
never executed: ctr64_add(ctx->nonce.c,n/16); | 0 | ||||||||||||||||||
351 | } never executed: end of block | 0 | ||||||||||||||||||
352 | - | |||||||||||||||||||
353 | if (len
| 0 | ||||||||||||||||||
354 | (*block)(ctx->nonce.c,scratch.c,key); | - | ||||||||||||||||||
355 | for (i=0; i<len
| 0 | ||||||||||||||||||
356 | ctx->cmac.c[i] ^= (out[i] = scratch.c[i]^inp[i]); never executed: ctx->cmac.c[i] ^= (out[i] = scratch.c[i]^inp[i]); | 0 | ||||||||||||||||||
357 | (*block)(ctx->cmac.c,ctx->cmac.c,key); | - | ||||||||||||||||||
358 | } never executed: end of block | 0 | ||||||||||||||||||
359 | - | |||||||||||||||||||
360 | for (i=15-L;i<16
| 0 | ||||||||||||||||||
361 | ctx->nonce.c[i]=0; never executed: ctx->nonce.c[i]=0; | 0 | ||||||||||||||||||
362 | - | |||||||||||||||||||
363 | (*block)(ctx->nonce.c,scratch.c,key); | - | ||||||||||||||||||
364 | ctx->cmac.u[0] ^= scratch.u[0]; | - | ||||||||||||||||||
365 | ctx->cmac.u[1] ^= scratch.u[1]; | - | ||||||||||||||||||
366 | - | |||||||||||||||||||
367 | ctx->nonce.c[0] = flags0; | - | ||||||||||||||||||
368 | - | |||||||||||||||||||
369 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
370 | } | - | ||||||||||||||||||
371 | - | |||||||||||||||||||
372 | size_t CRYPTO_ccm128_tag(CCM128_CONTEXT *ctx,unsigned char *tag,size_t len) | - | ||||||||||||||||||
373 | { unsigned int M = (ctx->nonce.c[0]>>3)&7; | - | ||||||||||||||||||
374 | - | |||||||||||||||||||
375 | M *= 2; M += 2; | - | ||||||||||||||||||
376 | if (len<M
never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
377 | memcpy(tag,ctx->cmac.c,M); | - | ||||||||||||||||||
378 | return never executed: M;return M; never executed: return M; | 0 | ||||||||||||||||||
379 | } | - | ||||||||||||||||||
Switch to Source code | Preprocessed file |