Line | Source | Count |
1 | | - |
2 | | - |
3 | | - |
4 | | - |
5 | | - |
6 | | - |
7 | | - |
8 | | - |
9 | | - |
10 | | - |
11 | | - |
12 | | - |
13 | | - |
14 | | - |
15 | | - |
16 | | - |
17 | | - |
18 | | - |
19 | | - |
20 | | - |
21 | | - |
22 | | - |
23 | | - |
24 | | - |
25 | | - |
26 | | - |
27 | | - |
28 | | - |
29 | | - |
30 | | - |
31 | | - |
32 | | - |
33 | | - |
34 | | - |
35 | | - |
36 | | - |
37 | | - |
38 | | - |
39 | | - |
40 | | - |
41 | | - |
42 | | - |
43 | | - |
44 | | - |
45 | | - |
46 | | - |
47 | | - |
48 | | - |
49 | | - |
50 | | - |
51 | #include <machine/endian.h> | - |
52 | #include <openssl/crypto.h> | - |
53 | #include "modes_lcl.h" | - |
54 | #include <string.h> | - |
55 | | - |
56 | #ifndef MODES_DEBUG | - |
57 | # ifndef NDEBUG | - |
58 | # define NDEBUG | - |
59 | # endif | - |
60 | #endif | - |
61 | | - |
62 | int CRYPTO_xts128_encrypt(const XTS128_CONTEXT *ctx, const unsigned char iv[16], | - |
63 | const unsigned char *inp, unsigned char *out, | - |
64 | size_t len, int enc) | - |
65 | { | - |
66 | union { u64 u[2]; u32 d[4]; u8 c[16]; } tweak, scratch; | - |
67 | unsigned int i; | - |
68 | | - |
69 | if (len<16) return -1; never executed: return -1; TRUE | never evaluated | FALSE | never evaluated |
| 0 |
70 | | - |
71 | memcpy(tweak.c, iv, 16); | - |
72 | | - |
73 | (*ctx->block2)(tweak.c,tweak.c,ctx->key2); | - |
74 | | - |
75 | if (!enc && (len%16)) len-=16; never executed: len-=16; TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
76 | | - |
77 | while (len>=16) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
78 | #ifdef __STRICT_ALIGNMENT | - |
79 | memcpy(scratch.c,inp,16); | - |
80 | scratch.u[0] ^= tweak.u[0]; | - |
81 | scratch.u[1] ^= tweak.u[1]; | - |
82 | #else | - |
83 | scratch.u[0] = ((u64*)inp)[0]^tweak.u[0]; | - |
84 | scratch.u[1] = ((u64*)inp)[1]^tweak.u[1]; | - |
85 | #endif | - |
86 | (*ctx->block1)(scratch.c,scratch.c,ctx->key1); | - |
87 | #ifdef __STRICT_ALIGNMENT | - |
88 | scratch.u[0] ^= tweak.u[0]; | - |
89 | scratch.u[1] ^= tweak.u[1]; | - |
90 | memcpy(out,scratch.c,16); | - |
91 | #else | - |
92 | ((u64*)out)[0] = scratch.u[0]^=tweak.u[0]; | - |
93 | ((u64*)out)[1] = scratch.u[1]^=tweak.u[1]; | - |
94 | #endif | - |
95 | inp += 16; | - |
96 | out += 16; | - |
97 | len -= 16; | - |
98 | | - |
99 | if (len==0) return 0; never executed: return 0; TRUE | never evaluated | FALSE | never evaluated |
| 0 |
100 | | - |
101 | #if BYTE_ORDER == LITTLE_ENDIAN | - |
102 | unsigned int carry,res; | - |
103 | | - |
104 | res = 0x87&(((int)tweak.d[3])>>31); | - |
105 | carry = (unsigned int)(tweak.u[0]>>63); | - |
106 | tweak.u[0] = (tweak.u[0]<<1)^res; | - |
107 | tweak.u[1] = (tweak.u[1]<<1)|carry; | - |
108 | #else /* BIG_ENDIAN */ | - |
109 | size_t c; | - |
110 | | - |
111 | for (c=0,i=0;i<16;++i) { | - |
112 | | - |
113 | c += ((size_t)tweak.c[i])<<1; | - |
114 | tweak.c[i] = (u8)c; | - |
115 | c = c>>8; | - |
116 | } | - |
117 | tweak.c[0] ^= (u8)(0x87&(0-c)); | - |
118 | #endif | - |
119 | } never executed: end of block | 0 |
120 | if (enc) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
121 | for (i=0;i<len;++i) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
122 | u8 c = inp[i]; | - |
123 | out[i] = scratch.c[i]; | - |
124 | scratch.c[i] = c; | - |
125 | } never executed: end of block | 0 |
126 | scratch.u[0] ^= tweak.u[0]; | - |
127 | scratch.u[1] ^= tweak.u[1]; | - |
128 | (*ctx->block1)(scratch.c,scratch.c,ctx->key1); | - |
129 | scratch.u[0] ^= tweak.u[0]; | - |
130 | scratch.u[1] ^= tweak.u[1]; | - |
131 | memcpy(out-16,scratch.c,16); | - |
132 | } never executed: end of block | 0 |
133 | else { | - |
134 | union { u64 u[2]; u8 c[16]; } tweak1; | - |
135 | | - |
136 | #if BYTE_ORDER == LITTLE_ENDIAN | - |
137 | unsigned int carry,res; | - |
138 | | - |
139 | res = 0x87&(((int)tweak.d[3])>>31); | - |
140 | carry = (unsigned int)(tweak.u[0]>>63); | - |
141 | tweak1.u[0] = (tweak.u[0]<<1)^res; | - |
142 | tweak1.u[1] = (tweak.u[1]<<1)|carry; | - |
143 | #else | - |
144 | size_t c; | - |
145 | | - |
146 | for (c=0,i=0;i<16;++i) { | - |
147 | | - |
148 | c += ((size_t)tweak.c[i])<<1; | - |
149 | tweak1.c[i] = (u8)c; | - |
150 | c = c>>8; | - |
151 | } | - |
152 | tweak1.c[0] ^= (u8)(0x87&(0-c)); | - |
153 | #endif | - |
154 | #ifdef __STRICT_ALIGNMENT | - |
155 | memcpy(scratch.c,inp,16); | - |
156 | scratch.u[0] ^= tweak1.u[0]; | - |
157 | scratch.u[1] ^= tweak1.u[1]; | - |
158 | #else | - |
159 | scratch.u[0] = ((u64*)inp)[0]^tweak1.u[0]; | - |
160 | scratch.u[1] = ((u64*)inp)[1]^tweak1.u[1]; | - |
161 | #endif | - |
162 | (*ctx->block1)(scratch.c,scratch.c,ctx->key1); | - |
163 | scratch.u[0] ^= tweak1.u[0]; | - |
164 | scratch.u[1] ^= tweak1.u[1]; | - |
165 | | - |
166 | for (i=0;i<len;++i) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
167 | u8 c = inp[16+i]; | - |
168 | out[16+i] = scratch.c[i]; | - |
169 | scratch.c[i] = c; | - |
170 | } never executed: end of block | 0 |
171 | scratch.u[0] ^= tweak.u[0]; | - |
172 | scratch.u[1] ^= tweak.u[1]; | - |
173 | (*ctx->block1)(scratch.c,scratch.c,ctx->key1); | - |
174 | #ifdef __STRICT_ALIGNMENT | - |
175 | scratch.u[0] ^= tweak.u[0]; | - |
176 | scratch.u[1] ^= tweak.u[1]; | - |
177 | memcpy (out,scratch.c,16); | - |
178 | #else | - |
179 | ((u64*)out)[0] = scratch.u[0]^tweak.u[0]; | - |
180 | ((u64*)out)[1] = scratch.u[1]^tweak.u[1]; | - |
181 | #endif | - |
182 | } never executed: end of block | 0 |
183 | | - |
184 | return 0; never executed: return 0; | 0 |
185 | } | - |
| | |