Line | Source | Count |
1 | | - |
2 | | - |
3 | | - |
4 | | - |
5 | | - |
6 | | - |
7 | | - |
8 | int CRYPTO_xts128_encrypt(const XTS128_CONTEXT *ctx, const unsigned char iv[16], | - |
9 | const unsigned char *inp, unsigned char *out, | - |
10 | size_t len, int enc) | - |
11 | { | - |
12 | union { u64 u[2]; u32 d[4]; u8 c[16]; } tweak, scratch; | - |
13 | unsigned int i; | - |
14 | | - |
15 | if (len<16TRUE | never evaluated | FALSE | never evaluated |
) returnnever executed: return -1; -1;never executed: return -1; | 0 |
16 | | - |
17 | memcpy(tweak.c, iv, 16); | - |
18 | | - |
19 | (*ctx->block2)(tweak.c,tweak.c,ctx->key2); | - |
20 | | - |
21 | if (!encTRUE | never evaluated | FALSE | never evaluated |
&& (TRUE | never evaluated | FALSE | never evaluated |
len%16)TRUE | never evaluated | FALSE | never evaluated |
) len-=16;never executed: len-=16; | 0 |
22 | | - |
23 | while (len>=16TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
24 | | - |
25 | | - |
26 | | - |
27 | | - |
28 | | - |
29 | scratch.u[0] = ((u64*)inp)[0]^tweak.u[0]; | - |
30 | scratch.u[1] = ((u64*)inp)[1]^tweak.u[1]; | - |
31 | | - |
32 | (*ctx->block1)(scratch.c,scratch.c,ctx->key1); | - |
33 | | - |
34 | | - |
35 | | - |
36 | | - |
37 | | - |
38 | ((u64*)out)[0] = scratch.u[0]^=tweak.u[0]; | - |
39 | ((u64*)out)[1] = scratch.u[1]^=tweak.u[1]; | - |
40 | | - |
41 | inp += 16; | - |
42 | out += 16; | - |
43 | len -= 16; | - |
44 | | - |
45 | if (len==0TRUE | never evaluated | FALSE | never evaluated |
) returnnever executed: return 0; 0;never executed: return 0; | 0 |
46 | | - |
47 | | - |
48 | unsigned int carry,res; | - |
49 | | - |
50 | res = 0x87&(((int)tweak.d[3])>>31); | - |
51 | carry = (unsigned int)(tweak.u[0]>>63); | - |
52 | tweak.u[0] = (tweak.u[0]<<1)^res; | - |
53 | tweak.u[1] = (tweak.u[1]<<1)|carry; | - |
54 | } never executed: end of block | 0 |
55 | if (encTRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
56 | for (i=0;i<lenTRUE | never evaluated | FALSE | never evaluated |
;++i) { | 0 |
57 | u8 c = inp[i]; | - |
58 | out[i] = scratch.c[i]; | - |
59 | scratch.c[i] = c; | - |
60 | } never executed: end of block | 0 |
61 | scratch.u[0] ^= tweak.u[0]; | - |
62 | scratch.u[1] ^= tweak.u[1]; | - |
63 | (*ctx->block1)(scratch.c,scratch.c,ctx->key1); | - |
64 | scratch.u[0] ^= tweak.u[0]; | - |
65 | scratch.u[1] ^= tweak.u[1]; | - |
66 | memcpy(out-16,scratch.c,16); | - |
67 | } never executed: end of block | 0 |
68 | else { | - |
69 | union { u64 u[2]; u8 c[16]; } tweak1; | - |
70 | | - |
71 | | - |
72 | unsigned int carry,res; | - |
73 | | - |
74 | res = 0x87&(((int)tweak.d[3])>>31); | - |
75 | carry = (unsigned int)(tweak.u[0]>>63); | - |
76 | tweak1.u[0] = (tweak.u[0]<<1)^res; | - |
77 | tweak1.u[1] = (tweak.u[1]<<1)|carry; | - |
78 | scratch.u[0] = ((u64*)inp)[0]^tweak1.u[0]; | - |
79 | scratch.u[1] = ((u64*)inp)[1]^tweak1.u[1]; | - |
80 | | - |
81 | (*ctx->block1)(scratch.c,scratch.c,ctx->key1); | - |
82 | scratch.u[0] ^= tweak1.u[0]; | - |
83 | scratch.u[1] ^= tweak1.u[1]; | - |
84 | | - |
85 | for (i=0;i<lenTRUE | never evaluated | FALSE | never evaluated |
;++i) { | 0 |
86 | u8 c = inp[16+i]; | - |
87 | out[16+i] = scratch.c[i]; | - |
88 | scratch.c[i] = c; | - |
89 | } never executed: end of block | 0 |
90 | scratch.u[0] ^= tweak.u[0]; | - |
91 | scratch.u[1] ^= tweak.u[1]; | - |
92 | (*ctx->block1)(scratch.c,scratch.c,ctx->key1); | - |
93 | | - |
94 | | - |
95 | | - |
96 | | - |
97 | | - |
98 | ((u64*)out)[0] = scratch.u[0]^tweak.u[0]; | - |
99 | ((u64*)out)[1] = scratch.u[1]^tweak.u[1]; | - |
100 | | - |
101 | } never executed: end of block | 0 |
102 | | - |
103 | return never executed: return 0; 0;never executed: return 0; | 0 |
104 | } | - |
| | |