Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/modes/ctr128.c |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||||||||
2 | - | |||||||||||||||||||
3 | - | |||||||||||||||||||
4 | - | |||||||||||||||||||
5 | - | |||||||||||||||||||
6 | - | |||||||||||||||||||
7 | - | |||||||||||||||||||
8 | - | |||||||||||||||||||
9 | static void ctr128_inc(unsigned char *counter) | - | ||||||||||||||||||
10 | { | - | ||||||||||||||||||
11 | u32 n = 16, c = 1; | - | ||||||||||||||||||
12 | - | |||||||||||||||||||
13 | do { | - | ||||||||||||||||||
14 | --n; | - | ||||||||||||||||||
15 | c += counter[n]; | - | ||||||||||||||||||
16 | counter[n] = (u8)c; | - | ||||||||||||||||||
17 | c >>= 8; | - | ||||||||||||||||||
18 | } executed 78624 times by 1 test: while (nend of block Executed by:
| 4914-78624 | ||||||||||||||||||
19 | } executed 4914 times by 1 test: end of block Executed by:
| 4914 | ||||||||||||||||||
20 | - | |||||||||||||||||||
21 | - | |||||||||||||||||||
22 | static void ctr128_inc_aligned(unsigned char *counter) | - | ||||||||||||||||||
23 | { | - | ||||||||||||||||||
24 | size_t *data, c, d, n; | - | ||||||||||||||||||
25 | const union { | - | ||||||||||||||||||
26 | long one; | - | ||||||||||||||||||
27 | char little; | - | ||||||||||||||||||
28 | } is_endian = { | - | ||||||||||||||||||
29 | 1 | - | ||||||||||||||||||
30 | }; | - | ||||||||||||||||||
31 | - | |||||||||||||||||||
32 | if (is_endian.little
| 0-4914 | ||||||||||||||||||
33 | ctr128_inc(counter); | - | ||||||||||||||||||
34 | return; executed 4914 times by 1 test: return; Executed by:
| 4914 | ||||||||||||||||||
35 | } | - | ||||||||||||||||||
36 | - | |||||||||||||||||||
37 | data = (size_t *)counter; | - | ||||||||||||||||||
38 | c = 1; | - | ||||||||||||||||||
39 | n = 16 / sizeof(size_t); | - | ||||||||||||||||||
40 | do { | - | ||||||||||||||||||
41 | --n; | - | ||||||||||||||||||
42 | d = data[n] += c; | - | ||||||||||||||||||
43 | - | |||||||||||||||||||
44 | c = ((d - c) & ~d) >> (sizeof(size_t) * 8 - 1); | - | ||||||||||||||||||
45 | } never executed: while (nend of block
| 0 | ||||||||||||||||||
46 | } never executed: end of block | 0 | ||||||||||||||||||
47 | void CRYPTO_ctr128_encrypt(const unsigned char *in, unsigned char *out, | - | ||||||||||||||||||
48 | size_t len, const void *key, | - | ||||||||||||||||||
49 | unsigned char ivec[16], | - | ||||||||||||||||||
50 | unsigned char ecount_buf[16], unsigned int *num, | - | ||||||||||||||||||
51 | block128_f block) | - | ||||||||||||||||||
52 | { | - | ||||||||||||||||||
53 | unsigned int n; | - | ||||||||||||||||||
54 | size_t l = 0; | - | ||||||||||||||||||
55 | - | |||||||||||||||||||
56 | n = *num; | - | ||||||||||||||||||
57 | - | |||||||||||||||||||
58 | - | |||||||||||||||||||
59 | if (16 % sizeof(size_t) == 0
| 0-694 | ||||||||||||||||||
60 | do { | - | ||||||||||||||||||
61 | while (n
| 44-3722 | ||||||||||||||||||
62 | *(out++) = *(in++) ^ ecount_buf[n]; | - | ||||||||||||||||||
63 | --len; | - | ||||||||||||||||||
64 | n = (n + 1) % 16; | - | ||||||||||||||||||
65 | } executed 3678 times by 1 test: end of block Executed by:
| 3678 | ||||||||||||||||||
66 | - | |||||||||||||||||||
67 | - | |||||||||||||||||||
68 | - | |||||||||||||||||||
69 | - | |||||||||||||||||||
70 | - | |||||||||||||||||||
71 | - | |||||||||||||||||||
72 | while (len >= 16
| 694-4440 | ||||||||||||||||||
73 | (*block) (ivec, ecount_buf, key); | - | ||||||||||||||||||
74 | ctr128_inc_aligned(ivec); | - | ||||||||||||||||||
75 | for (n = 0; n < 16
| 4440-8880 | ||||||||||||||||||
76 | *( executed 8880 times by 1 test: size_t *)(out + n) =*(size_t *)(out + n) = *(size_t *)(in + n) ^ *(size_t *)(ecount_buf + n); Executed by:
executed 8880 times by 1 test: *(size_t *)(out + n) = *(size_t *)(in + n) ^ *(size_t *)(ecount_buf + n); Executed by:
| 8880 | ||||||||||||||||||
77 | *(size_t *)(in + n) ^ *(size_t *)(ecount_buf + n); executed 8880 times by 1 test: *(size_t *)(out + n) = *(size_t *)(in + n) ^ *(size_t *)(ecount_buf + n); Executed by:
| 8880 | ||||||||||||||||||
78 | len -= 16; | - | ||||||||||||||||||
79 | out += 16; | - | ||||||||||||||||||
80 | in += 16; | - | ||||||||||||||||||
81 | n = 0; | - | ||||||||||||||||||
82 | } executed 4440 times by 1 test: end of block Executed by:
| 4440 | ||||||||||||||||||
83 | if (len
| 220-474 | ||||||||||||||||||
84 | (*block) (ivec, ecount_buf, key); | - | ||||||||||||||||||
85 | ctr128_inc_aligned(ivec); | - | ||||||||||||||||||
86 | while (len--
| 474-3346 | ||||||||||||||||||
87 | out[n] = in[n] ^ ecount_buf[n]; | - | ||||||||||||||||||
88 | ++n; | - | ||||||||||||||||||
89 | } executed 3346 times by 1 test: end of block Executed by:
| 3346 | ||||||||||||||||||
90 | } executed 474 times by 1 test: end of block Executed by:
| 474 | ||||||||||||||||||
91 | *num = n; | - | ||||||||||||||||||
92 | return; executed 694 times by 1 test: return; Executed by:
| 694 | ||||||||||||||||||
93 | } while (0); | - | ||||||||||||||||||
94 | } never executed: end of block | 0 | ||||||||||||||||||
95 | - | |||||||||||||||||||
96 | - | |||||||||||||||||||
97 | while (l < len
| 0 | ||||||||||||||||||
98 | if (n == 0
| 0 | ||||||||||||||||||
99 | (*block) (ivec, ecount_buf, key); | - | ||||||||||||||||||
100 | ctr128_inc(ivec); | - | ||||||||||||||||||
101 | } never executed: end of block | 0 | ||||||||||||||||||
102 | out[l] = in[l] ^ ecount_buf[n]; | - | ||||||||||||||||||
103 | ++l; | - | ||||||||||||||||||
104 | n = (n + 1) % 16; | - | ||||||||||||||||||
105 | } never executed: end of block | 0 | ||||||||||||||||||
106 | - | |||||||||||||||||||
107 | *num = n; | - | ||||||||||||||||||
108 | } never executed: end of block | 0 | ||||||||||||||||||
109 | - | |||||||||||||||||||
110 | - | |||||||||||||||||||
111 | static void ctr96_inc(unsigned char *counter) | - | ||||||||||||||||||
112 | { | - | ||||||||||||||||||
113 | u32 n = 12, c = 1; | - | ||||||||||||||||||
114 | - | |||||||||||||||||||
115 | do { | - | ||||||||||||||||||
116 | --n; | - | ||||||||||||||||||
117 | c += counter[n]; | - | ||||||||||||||||||
118 | counter[n] = (u8)c; | - | ||||||||||||||||||
119 | c >>= 8; | - | ||||||||||||||||||
120 | } executed 144 times by 1 test: while (nend of block Executed by:
| 12-144 | ||||||||||||||||||
121 | } executed 12 times by 1 test: end of block Executed by:
| 12 | ||||||||||||||||||
122 | - | |||||||||||||||||||
123 | void CRYPTO_ctr128_encrypt_ctr32(const unsigned char *in, unsigned char *out, | - | ||||||||||||||||||
124 | size_t len, const void *key, | - | ||||||||||||||||||
125 | unsigned char ivec[16], | - | ||||||||||||||||||
126 | unsigned char ecount_buf[16], | - | ||||||||||||||||||
127 | unsigned int *num, ctr128_f func) | - | ||||||||||||||||||
128 | { | - | ||||||||||||||||||
129 | unsigned int n, ctr32; | - | ||||||||||||||||||
130 | - | |||||||||||||||||||
131 | n = *num; | - | ||||||||||||||||||
132 | - | |||||||||||||||||||
133 | while (n
| 42-62514 | ||||||||||||||||||
134 | *(out++) = *(in++) ^ ecount_buf[n]; | - | ||||||||||||||||||
135 | --len; | - | ||||||||||||||||||
136 | n = (n + 1) % 16; | - | ||||||||||||||||||
137 | } executed 62472 times by 1 test: end of block Executed by:
| 62472 | ||||||||||||||||||
138 | - | |||||||||||||||||||
139 | ctr32 = ({ u32 ret_=(*(const u32 *)(ivec + 12)); asm ("bswapl %0" : "+r"(ret_)); ret_; }); | - | ||||||||||||||||||
140 | while (len >= 16
| 18324-18678 | ||||||||||||||||||
141 | size_t blocks = len / 16; | - | ||||||||||||||||||
142 | - | |||||||||||||||||||
143 | - | |||||||||||||||||||
144 | - | |||||||||||||||||||
145 | - | |||||||||||||||||||
146 | - | |||||||||||||||||||
147 | if (sizeof(size_t) > sizeof(unsigned int)
| 0-18324 | ||||||||||||||||||
148 | blocks = (1U << 28); never executed: blocks = (1U << 28); | 0 | ||||||||||||||||||
149 | - | |||||||||||||||||||
150 | - | |||||||||||||||||||
151 | - | |||||||||||||||||||
152 | - | |||||||||||||||||||
153 | - | |||||||||||||||||||
154 | - | |||||||||||||||||||
155 | ctr32 += (u32)blocks; | - | ||||||||||||||||||
156 | if (ctr32 < blocks
| 6-18318 | ||||||||||||||||||
157 | blocks -= ctr32; | - | ||||||||||||||||||
158 | ctr32 = 0; | - | ||||||||||||||||||
159 | } executed 6 times by 1 test: end of block Executed by:
| 6 | ||||||||||||||||||
160 | (*func) (in, out, blocks, key, ivec); | - | ||||||||||||||||||
161 | - | |||||||||||||||||||
162 | *(u32 *)(ivec + 12) = ({ u32 ret_=(ctr32); asm ("bswapl %0" : "+r"(ret_)); ret_; }); | - | ||||||||||||||||||
163 | - | |||||||||||||||||||
164 | if (ctr32 == 0
| 6-18318 | ||||||||||||||||||
165 | ctr96_inc(ivec); executed 6 times by 1 test: ctr96_inc(ivec); Executed by:
| 6 | ||||||||||||||||||
166 | blocks *= 16; | - | ||||||||||||||||||
167 | len -= blocks; | - | ||||||||||||||||||
168 | out += blocks; | - | ||||||||||||||||||
169 | in += blocks; | - | ||||||||||||||||||
170 | } executed 18324 times by 1 test: end of block Executed by:
| 18324 | ||||||||||||||||||
171 | if (len
| 7812-10866 | ||||||||||||||||||
172 | memset(ecount_buf, 0, 16); | - | ||||||||||||||||||
173 | (*func) (ecount_buf, ecount_buf, 1, key, ivec); | - | ||||||||||||||||||
174 | ++ctr32; | - | ||||||||||||||||||
175 | *(u32 *)(ivec + 12) = ({ u32 ret_=(ctr32); asm ("bswapl %0" : "+r"(ret_)); ret_; }); | - | ||||||||||||||||||
176 | if (ctr32 == 0
| 6-7806 | ||||||||||||||||||
177 | ctr96_inc(ivec); executed 6 times by 1 test: ctr96_inc(ivec); Executed by:
| 6 | ||||||||||||||||||
178 | while (len--
| 7812-62040 | ||||||||||||||||||
179 | out[n] = in[n] ^ ecount_buf[n]; | - | ||||||||||||||||||
180 | ++n; | - | ||||||||||||||||||
181 | } executed 62040 times by 1 test: end of block Executed by:
| 62040 | ||||||||||||||||||
182 | } executed 7812 times by 1 test: end of block Executed by:
| 7812 | ||||||||||||||||||
183 | - | |||||||||||||||||||
184 | *num = n; | - | ||||||||||||||||||
185 | } executed 18678 times by 1 test: end of block Executed by:
| 18678 | ||||||||||||||||||
Switch to Source code | Preprocessed file |