Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/libressl/src/crypto/gost/gostr341194.c |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||
---|---|---|---|---|---|---|---|---|
1 | - | |||||||
2 | - | |||||||
3 | - | |||||||
4 | - | |||||||
5 | - | |||||||
6 | - | |||||||
7 | - | |||||||
8 | static void | - | ||||||
9 | swap_bytes(unsigned char *w, unsigned char *k) | - | ||||||
10 | { | - | ||||||
11 | int i, j; | - | ||||||
12 | - | |||||||
13 | for (i = 0; i < 4
| 25628-102512 | ||||||
14 | for (j = 0; j < 8
| 102512-820096 | ||||||
15 | k[i + 4 * j] = w[8 * i + j]; executed 820096 times by 3 tests: k[i + 4 * j] = w[8 * i + j]; Executed by:
| 820096 | ||||||
16 | } executed 25628 times by 3 tests: end of block Executed by:
| 25628 | ||||||
17 | - | |||||||
18 | - | |||||||
19 | static void | - | ||||||
20 | circle_xor8(const unsigned char *w, unsigned char *k) | - | ||||||
21 | { | - | ||||||
22 | unsigned char buf[8]; | - | ||||||
23 | int i; | - | ||||||
24 | - | |||||||
25 | memcpy(buf, w, 8); | - | ||||||
26 | memmove(k, w + 8, 24); | - | ||||||
27 | for (i = 0; i < 8
| 57663-461304 | ||||||
28 | k[i + 24] = buf[i] ^ k[i]; executed 461304 times by 3 tests: k[i + 24] = buf[i] ^ k[i]; Executed by:
| 461304 | ||||||
29 | } executed 57663 times by 3 tests: end of block Executed by:
| 57663 | ||||||
30 | - | |||||||
31 | - | |||||||
32 | static void | - | ||||||
33 | transform_3(unsigned char *data) | - | ||||||
34 | { | - | ||||||
35 | unsigned short int acc; | - | ||||||
36 | - | |||||||
37 | acc = (data[0] ^ data[2] ^ data[4] ^ data[6] ^ data[24] ^ data[30]) | | - | ||||||
38 | ((data[1] ^ data[3] ^ data[5] ^ data[7] ^ data[25] ^ data[31]) << 8); | - | ||||||
39 | memmove(data, data + 2, 30); | - | ||||||
40 | data[30] = acc & 0xff; | - | ||||||
41 | data[31] = acc >> 8; | - | ||||||
42 | } executed 474118 times by 3 tests: end of block Executed by:
| 474118 | ||||||
43 | - | |||||||
44 | - | |||||||
45 | static int | - | ||||||
46 | add_blocks(int n, unsigned char *left, const unsigned char *right) | - | ||||||
47 | { | - | ||||||
48 | int i; | - | ||||||
49 | int carry = 0; | - | ||||||
50 | int sum; | - | ||||||
51 | - | |||||||
52 | for (i = 0; i < n
| 3799-121568 | ||||||
53 | sum = (int)left[i] + (int)right[i] + carry; | - | ||||||
54 | left[i] = sum & 0xff; | - | ||||||
55 | carry = sum >> 8; | - | ||||||
56 | } executed 121568 times by 2 tests: end of block Executed by:
| 121568 | ||||||
57 | return executed 3799 times by 2 tests: carry;return carry; Executed by:
executed 3799 times by 2 tests: return carry; Executed by:
| 3799 | ||||||
58 | } | - | ||||||
59 | - | |||||||
60 | - | |||||||
61 | static void | - | ||||||
62 | xor_blocks(unsigned char *result, const unsigned char *a, | - | ||||||
63 | const unsigned char *b, size_t len) | - | ||||||
64 | { | - | ||||||
65 | size_t i; | - | ||||||
66 | - | |||||||
67 | for (i = 0; i < len
| 38442-1230144 | ||||||
68 | result[i] = a[i] ^ b[i]; executed 1230144 times by 3 tests: result[i] = a[i] ^ b[i]; Executed by:
| 1230144 | ||||||
69 | } executed 38442 times by 3 tests: end of block Executed by:
| 38442 | ||||||
70 | - | |||||||
71 | - | |||||||
72 | - | |||||||
73 | - | |||||||
74 | - | |||||||
75 | static int | - | ||||||
76 | hash_step(GOSTR341194_CTX *c, unsigned char *H, const unsigned char *M) | - | ||||||
77 | { | - | ||||||
78 | unsigned char U[32], W[32], V[32], S[32], Key[32]; | - | ||||||
79 | int i; | - | ||||||
80 | - | |||||||
81 | - | |||||||
82 | xor_blocks(W, H, M, 32); | - | ||||||
83 | swap_bytes(W, Key); | - | ||||||
84 | - | |||||||
85 | Gost2814789_set_key(&c->cipher, Key, 256); | - | ||||||
86 | Gost2814789_encrypt(H, S, &c->cipher); | - | ||||||
87 | - | |||||||
88 | - | |||||||
89 | circle_xor8(H, U); | - | ||||||
90 | circle_xor8(M, V); | - | ||||||
91 | circle_xor8(V, V); | - | ||||||
92 | xor_blocks(W, U, V, 32); | - | ||||||
93 | swap_bytes(W, Key); | - | ||||||
94 | - | |||||||
95 | Gost2814789_set_key(&c->cipher, Key, 256); | - | ||||||
96 | Gost2814789_encrypt(H+8, S+8, &c->cipher); | - | ||||||
97 | - | |||||||
98 | - | |||||||
99 | circle_xor8(U, U); | - | ||||||
100 | U[31] = ~U[31]; | - | ||||||
101 | U[29] = ~U[29]; | - | ||||||
102 | U[28] = ~U[28]; | - | ||||||
103 | U[24] = ~U[24]; | - | ||||||
104 | U[23] = ~U[23]; | - | ||||||
105 | U[20] = ~U[20]; | - | ||||||
106 | U[18] = ~U[18]; | - | ||||||
107 | U[17] = ~U[17]; | - | ||||||
108 | U[14] = ~U[14]; | - | ||||||
109 | U[12] = ~U[12]; | - | ||||||
110 | U[10] = ~U[10]; | - | ||||||
111 | U[8] = ~U[8]; | - | ||||||
112 | U[7] = ~U[7]; | - | ||||||
113 | U[5] = ~U[5]; | - | ||||||
114 | U[3] = ~U[3]; | - | ||||||
115 | U[1] = ~U[1]; | - | ||||||
116 | circle_xor8(V, V); | - | ||||||
117 | circle_xor8(V, V); | - | ||||||
118 | xor_blocks(W, U, V, 32); | - | ||||||
119 | swap_bytes(W, Key); | - | ||||||
120 | - | |||||||
121 | Gost2814789_set_key(&c->cipher, Key, 256); | - | ||||||
122 | Gost2814789_encrypt(H+16, S+16, &c->cipher); | - | ||||||
123 | - | |||||||
124 | - | |||||||
125 | circle_xor8(U, U); | - | ||||||
126 | circle_xor8(V, V); | - | ||||||
127 | circle_xor8(V, V); | - | ||||||
128 | xor_blocks(W, U, V, 32); | - | ||||||
129 | swap_bytes(W, Key); | - | ||||||
130 | - | |||||||
131 | Gost2814789_set_key(&c->cipher, Key, 256); | - | ||||||
132 | Gost2814789_encrypt(H+24, S+24, &c->cipher); | - | ||||||
133 | - | |||||||
134 | for (i = 0; i < 12
| 6407-76884 | ||||||
135 | transform_3(S); executed 76884 times by 3 tests: transform_3(S); Executed by:
| 76884 | ||||||
136 | xor_blocks(S, S, M, 32); | - | ||||||
137 | transform_3(S); | - | ||||||
138 | xor_blocks(S, S, H, 32); | - | ||||||
139 | for (i = 0; i < 61
| 6407-390827 | ||||||
140 | transform_3(S); executed 390827 times by 3 tests: transform_3(S); Executed by:
| 390827 | ||||||
141 | memcpy(H, S, 32); | - | ||||||
142 | return executed 6407 times by 3 tests: 1;return 1; Executed by:
executed 6407 times by 3 tests: return 1; Executed by:
| 6407 | ||||||
143 | } | - | ||||||
144 | - | |||||||
145 | int | - | ||||||
146 | GOSTR341194_Init(GOSTR341194_CTX *c, int nid) | - | ||||||
147 | { | - | ||||||
148 | memset(c, 0, sizeof(*c)); | - | ||||||
149 | return executed 1304 times by 3 tests: Gost2814789_set_sbox(&c->cipher, nid);return Gost2814789_set_sbox(&c->cipher, nid); Executed by:
executed 1304 times by 3 tests: return Gost2814789_set_sbox(&c->cipher, nid); Executed by:
| 1304 | ||||||
150 | } | - | ||||||
151 | - | |||||||
152 | static void | - | ||||||
153 | GOSTR341194_block_data_order(GOSTR341194_CTX *ctx, const unsigned char *p, | - | ||||||
154 | size_t num) | - | ||||||
155 | { | - | ||||||
156 | int i; | - | ||||||
157 | - | |||||||
158 | for (i = 0; i < num
| 3328 | ||||||
159 | hash_step(ctx, ctx->H, p); | - | ||||||
160 | add_blocks(32, ctx->S, p); | - | ||||||
161 | p += 32; | - | ||||||
162 | } executed 3328 times by 1 test: end of block Executed by:
| 3328 | ||||||
163 | } executed 3328 times by 1 test: end of block Executed by:
| 3328 | ||||||
164 | - | |||||||
165 | int | - | ||||||
166 | GOSTR341194_Final(unsigned char *md, GOSTR341194_CTX * c) | - | ||||||
167 | { | - | ||||||
168 | unsigned char *p = (unsigned char *)c->data; | - | ||||||
169 | unsigned char T[32]; | - | ||||||
170 | - | |||||||
171 | if (c->num > 0
| 471-833 | ||||||
172 | memset(p + c->num, 0, 32 - c->num); | - | ||||||
173 | hash_step(c, c->H, p); | - | ||||||
174 | add_blocks(32, c->S, p); | - | ||||||
175 | } executed 471 times by 2 tests: end of block Executed by:
| 471 | ||||||
176 | - | |||||||
177 | p = T; | - | ||||||
178 | (*((unsigned int *)(p))=(c->Nl), (p)+=4); | - | ||||||
179 | (*((unsigned int *)(p))=(c->Nh), (p)+=4); | - | ||||||
180 | memset(p, 0, 32 - 8); | - | ||||||
181 | hash_step(c, c->H, T); | - | ||||||
182 | hash_step(c, c->H, c->S); | - | ||||||
183 | - | |||||||
184 | memcpy(md, c->H, 32); | - | ||||||
185 | - | |||||||
186 | return executed 1304 times by 3 tests: 1;return 1; Executed by:
executed 1304 times by 3 tests: return 1; Executed by:
| 1304 | ||||||
187 | } | - | ||||||
188 | - | |||||||
189 | unsigned char * | - | ||||||
190 | GOSTR341194(const unsigned char *d, size_t n, unsigned char *md, int nid) | - | ||||||
191 | { | - | ||||||
192 | GOSTR341194_CTX c; | - | ||||||
193 | static unsigned char m[32]; | - | ||||||
194 | - | |||||||
195 | if (md ==
| 0 | ||||||
196 | ((void *)0)
| 0 | ||||||
197 | ) | - | ||||||
198 | md = m; never executed: md = m; | 0 | ||||||
199 | if (!GOSTR341194_Init(&c, nid)
| 0 | ||||||
200 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||
201 | GOSTR341194_Update(&c, d, n); | - | ||||||
202 | GOSTR341194_Final(md, &c); | - | ||||||
203 | explicit_bzero(&c, sizeof(c)); | - | ||||||
204 | return never executed: (md);return (md); never executed: return (md); | 0 | ||||||
205 | } | - | ||||||
Switch to Source code | Preprocessed file |