Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssh/src/smult_curve25519_ref.c |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | int crypto_scalarmult_curve25519(unsigned char *, const unsigned char *, const unsigned char *); | - | ||||||||||||
2 | - | |||||||||||||
3 | static void add(unsigned int out[32],const unsigned int a[32],const unsigned int b[32]) | - | ||||||||||||
4 | { | - | ||||||||||||
5 | unsigned int j; | - | ||||||||||||
6 | unsigned int u; | - | ||||||||||||
7 | u = 0; | - | ||||||||||||
8 | for (j = 0;j < 31
executed 2532080 times by 1 test: end of block Executed by:
| 81680-2532080 | ||||||||||||
9 | u += a[31] + b[31]; out[31] = u; | - | ||||||||||||
10 | } executed 81680 times by 1 test: end of block Executed by:
| 81680 | ||||||||||||
11 | - | |||||||||||||
12 | static void sub(unsigned int out[32],const unsigned int a[32],const unsigned int b[32]) | - | ||||||||||||
13 | { | - | ||||||||||||
14 | unsigned int j; | - | ||||||||||||
15 | unsigned int u; | - | ||||||||||||
16 | u = 218; | - | ||||||||||||
17 | for (j = 0;j < 31
| 81600-2529600 | ||||||||||||
18 | u += a[j] + 65280 - b[j]; | - | ||||||||||||
19 | out[j] = u & 255; | - | ||||||||||||
20 | u >>= 8; | - | ||||||||||||
21 | } executed 2529600 times by 1 test: end of block Executed by:
| 2529600 | ||||||||||||
22 | u += a[31] - b[31]; | - | ||||||||||||
23 | out[31] = u; | - | ||||||||||||
24 | } executed 81600 times by 1 test: end of block Executed by:
| 81600 | ||||||||||||
25 | - | |||||||||||||
26 | static void squeeze(unsigned int a[32]) | - | ||||||||||||
27 | { | - | ||||||||||||
28 | unsigned int j; | - | ||||||||||||
29 | unsigned int u; | - | ||||||||||||
30 | u = 0; | - | ||||||||||||
31 | for (j = 0;j < 31
executed 6351280 times by 1 test: end of block Executed by:
| 204880-6351280 | ||||||||||||
32 | u += a[31]; a[31] = u & 127; | - | ||||||||||||
33 | u = 19 * (u >> 7); | - | ||||||||||||
34 | for (j = 0;j < 31
executed 6351280 times by 1 test: end of block Executed by:
| 204880-6351280 | ||||||||||||
35 | u += a[31]; a[31] = u; | - | ||||||||||||
36 | } executed 204880 times by 1 test: end of block Executed by:
| 204880 | ||||||||||||
37 | - | |||||||||||||
38 | static const unsigned int minusp[32] = { | - | ||||||||||||
39 | 19, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128 | - | ||||||||||||
40 | } ; | - | ||||||||||||
41 | - | |||||||||||||
42 | static void freeze(unsigned int a[32]) | - | ||||||||||||
43 | { | - | ||||||||||||
44 | unsigned int aorig[32]; | - | ||||||||||||
45 | unsigned int j; | - | ||||||||||||
46 | unsigned int negative; | - | ||||||||||||
47 | - | |||||||||||||
48 | for (j = 0;j < 32
executed 2560 times by 1 test: aorig[j] = a[j]; Executed by:
| 80-2560 | ||||||||||||
49 | add(a,a,minusp); | - | ||||||||||||
50 | negative = -((a[31] >> 7) & 1); | - | ||||||||||||
51 | for (j = 0;j < 32
executed 2560 times by 1 test: a[j] ^= negative & (aorig[j] ^ a[j]); Executed by:
| 80-2560 | ||||||||||||
52 | } executed 80 times by 1 test: end of block Executed by:
| 80 | ||||||||||||
53 | - | |||||||||||||
54 | static void mult(unsigned int out[32],const unsigned int a[32],const unsigned int b[32]) | - | ||||||||||||
55 | { | - | ||||||||||||
56 | unsigned int i; | - | ||||||||||||
57 | unsigned int j; | - | ||||||||||||
58 | unsigned int u; | - | ||||||||||||
59 | - | |||||||||||||
60 | for (i = 0;i < 32
| 102960-3294720 | ||||||||||||
61 | u = 0; | - | ||||||||||||
62 | for (j = 0;j <= i
executed 54362880 times by 1 test: u += a[j] * b[i - j]; Executed by:
| 3294720-54362880 | ||||||||||||
63 | for (j = i + 1;j < 32
executed 51068160 times by 1 test: u += 38 * a[j] * b[i + 32 - j]; Executed by:
| 3294720-51068160 | ||||||||||||
64 | out[i] = u; | - | ||||||||||||
65 | } executed 3294720 times by 1 test: end of block Executed by:
| 3294720 | ||||||||||||
66 | squeeze(out); | - | ||||||||||||
67 | } executed 102960 times by 1 test: end of block Executed by:
| 102960 | ||||||||||||
68 | - | |||||||||||||
69 | static void mult121665(unsigned int out[32],const unsigned int a[32]) | - | ||||||||||||
70 | { | - | ||||||||||||
71 | unsigned int j; | - | ||||||||||||
72 | unsigned int u; | - | ||||||||||||
73 | - | |||||||||||||
74 | u = 0; | - | ||||||||||||
75 | for (j = 0;j < 31
executed 632400 times by 1 test: end of block Executed by:
| 20400-632400 | ||||||||||||
76 | u += 121665 * a[31]; out[31] = u & 127; | - | ||||||||||||
77 | u = 19 * (u >> 7); | - | ||||||||||||
78 | for (j = 0;j < 31
executed 632400 times by 1 test: end of block Executed by:
| 20400-632400 | ||||||||||||
79 | u += out[j]; out[j] = u; | - | ||||||||||||
80 | } executed 20400 times by 1 test: end of block Executed by:
| 20400 | ||||||||||||
81 | - | |||||||||||||
82 | static void square(unsigned int out[32],const unsigned int a[32]) | - | ||||||||||||
83 | { | - | ||||||||||||
84 | unsigned int i; | - | ||||||||||||
85 | unsigned int j; | - | ||||||||||||
86 | unsigned int u; | - | ||||||||||||
87 | - | |||||||||||||
88 | for (i = 0;i < 32
| 101920-3261440 | ||||||||||||
89 | u = 0; | - | ||||||||||||
90 | for (j = 0;j < i - j
executed 26091520 times by 1 test: u += a[j] * a[i - j]; Executed by:
| 3261440-26091520 | ||||||||||||
91 | for (j = i + 1;j < i + 32 - j
executed 24460800 times by 1 test: u += 38 * a[j] * a[i + 32 - j]; Executed by:
| 3261440-24460800 | ||||||||||||
92 | u *= 2; | - | ||||||||||||
93 | if ((
| 1630720 | ||||||||||||
94 | u += a[i / 2] * a[i / 2]; | - | ||||||||||||
95 | u += 38 * a[i / 2 + 16] * a[i / 2 + 16]; | - | ||||||||||||
96 | } executed 1630720 times by 1 test: end of block Executed by:
| 1630720 | ||||||||||||
97 | out[i] = u; | - | ||||||||||||
98 | } executed 3261440 times by 1 test: end of block Executed by:
| 3261440 | ||||||||||||
99 | squeeze(out); | - | ||||||||||||
100 | } executed 101920 times by 1 test: end of block Executed by:
| 101920 | ||||||||||||
101 | - | |||||||||||||
102 | static void select(unsigned int p[64],unsigned int q[64],const unsigned int r[64],const unsigned int s[64],unsigned int b) | - | ||||||||||||
103 | { | - | ||||||||||||
104 | unsigned int j; | - | ||||||||||||
105 | unsigned int t; | - | ||||||||||||
106 | unsigned int bminus1; | - | ||||||||||||
107 | - | |||||||||||||
108 | bminus1 = b - 1; | - | ||||||||||||
109 | for (j = 0;j < 64
| 40800-2611200 | ||||||||||||
110 | t = bminus1 & (r[j] ^ s[j]); | - | ||||||||||||
111 | p[j] = s[j] ^ t; | - | ||||||||||||
112 | q[j] = r[j] ^ t; | - | ||||||||||||
113 | } executed 2611200 times by 1 test: end of block Executed by:
| 2611200 | ||||||||||||
114 | } executed 40800 times by 1 test: end of block Executed by:
| 40800 | ||||||||||||
115 | - | |||||||||||||
116 | static void mainloop(unsigned int work[64],const unsigned char e[32]) | - | ||||||||||||
117 | { | - | ||||||||||||
118 | unsigned int xzm1[64]; | - | ||||||||||||
119 | unsigned int xzm[64]; | - | ||||||||||||
120 | unsigned int xzmb[64]; | - | ||||||||||||
121 | unsigned int xzm1b[64]; | - | ||||||||||||
122 | unsigned int xznb[64]; | - | ||||||||||||
123 | unsigned int xzn1b[64]; | - | ||||||||||||
124 | unsigned int a0[64]; | - | ||||||||||||
125 | unsigned int a1[64]; | - | ||||||||||||
126 | unsigned int b0[64]; | - | ||||||||||||
127 | unsigned int b1[64]; | - | ||||||||||||
128 | unsigned int c1[64]; | - | ||||||||||||
129 | unsigned int r[32]; | - | ||||||||||||
130 | unsigned int s[32]; | - | ||||||||||||
131 | unsigned int t[32]; | - | ||||||||||||
132 | unsigned int u[32]; | - | ||||||||||||
133 | unsigned int j; | - | ||||||||||||
134 | unsigned int b; | - | ||||||||||||
135 | int pos; | - | ||||||||||||
136 | - | |||||||||||||
137 | for (j = 0;j < 32
executed 2560 times by 1 test: xzm1[j] = work[j]; Executed by:
| 80-2560 | ||||||||||||
138 | xzm1[32] = 1; | - | ||||||||||||
139 | for (j = 33;j < 64
executed 2480 times by 1 test: xzm1[j] = 0; Executed by:
| 80-2480 | ||||||||||||
140 | - | |||||||||||||
141 | xzm[0] = 1; | - | ||||||||||||
142 | for (j = 1;j < 64
executed 5040 times by 1 test: xzm[j] = 0; Executed by:
| 80-5040 | ||||||||||||
143 | - | |||||||||||||
144 | for (pos = 254;pos >= 0
| 80-20400 | ||||||||||||
145 | b = e[pos / 8] >> (pos & 7); | - | ||||||||||||
146 | b &= 1; | - | ||||||||||||
147 | select(xzmb,xzm1b,xzm,xzm1,b); | - | ||||||||||||
148 | add(a0,xzmb,xzmb + 32); | - | ||||||||||||
149 | sub(a0 + 32,xzmb,xzmb + 32); | - | ||||||||||||
150 | add(a1,xzm1b,xzm1b + 32); | - | ||||||||||||
151 | sub(a1 + 32,xzm1b,xzm1b + 32); | - | ||||||||||||
152 | square(b0,a0); | - | ||||||||||||
153 | square(b0 + 32,a0 + 32); | - | ||||||||||||
154 | mult(b1,a1,a0 + 32); | - | ||||||||||||
155 | mult(b1 + 32,a1 + 32,a0); | - | ||||||||||||
156 | add(c1,b1,b1 + 32); | - | ||||||||||||
157 | sub(c1 + 32,b1,b1 + 32); | - | ||||||||||||
158 | square(r,c1 + 32); | - | ||||||||||||
159 | sub(s,b0,b0 + 32); | - | ||||||||||||
160 | mult121665(t,s); | - | ||||||||||||
161 | add(u,t,b0); | - | ||||||||||||
162 | mult(xznb,b0,b0 + 32); | - | ||||||||||||
163 | mult(xznb + 32,s,u); | - | ||||||||||||
164 | square(xzn1b,c1); | - | ||||||||||||
165 | mult(xzn1b + 32,r,work); | - | ||||||||||||
166 | select(xzm,xzm1,xznb,xzn1b,b); | - | ||||||||||||
167 | } executed 20400 times by 1 test: end of block Executed by:
| 20400 | ||||||||||||
168 | - | |||||||||||||
169 | for (j = 0;j < 64
executed 5120 times by 1 test: work[j] = xzm[j]; Executed by:
| 80-5120 | ||||||||||||
170 | } executed 80 times by 1 test: end of block Executed by:
| 80 | ||||||||||||
171 | - | |||||||||||||
172 | static void recip(unsigned int out[32],const unsigned int z[32]) | - | ||||||||||||
173 | { | - | ||||||||||||
174 | unsigned int z2[32]; | - | ||||||||||||
175 | unsigned int z9[32]; | - | ||||||||||||
176 | unsigned int z11[32]; | - | ||||||||||||
177 | unsigned int z2_5_0[32]; | - | ||||||||||||
178 | unsigned int z2_10_0[32]; | - | ||||||||||||
179 | unsigned int z2_20_0[32]; | - | ||||||||||||
180 | unsigned int z2_50_0[32]; | - | ||||||||||||
181 | unsigned int z2_100_0[32]; | - | ||||||||||||
182 | unsigned int t0[32]; | - | ||||||||||||
183 | unsigned int t1[32]; | - | ||||||||||||
184 | int i; | - | ||||||||||||
185 | - | |||||||||||||
186 | square(z2,z); | - | ||||||||||||
187 | square(t1,z2); | - | ||||||||||||
188 | square(t0,t1); | - | ||||||||||||
189 | mult(z9,t0,z); | - | ||||||||||||
190 | mult(z11,z9,z2); | - | ||||||||||||
191 | square(t0,z11); | - | ||||||||||||
192 | mult(z2_5_0,t0,z9); | - | ||||||||||||
193 | - | |||||||||||||
194 | square(t0,z2_5_0); | - | ||||||||||||
195 | square(t1,t0); | - | ||||||||||||
196 | square(t0,t1); | - | ||||||||||||
197 | square(t1,t0); | - | ||||||||||||
198 | square(t0,t1); | - | ||||||||||||
199 | mult(z2_10_0,t0,z2_5_0); | - | ||||||||||||
200 | - | |||||||||||||
201 | square(t0,z2_10_0); | - | ||||||||||||
202 | square(t1,t0); | - | ||||||||||||
203 | for (i = 2;i < 10
executed 320 times by 1 test: end of block Executed by:
| 80-320 | ||||||||||||
204 | mult(z2_20_0,t1,z2_10_0); | - | ||||||||||||
205 | - | |||||||||||||
206 | square(t0,z2_20_0); | - | ||||||||||||
207 | square(t1,t0); | - | ||||||||||||
208 | for (i = 2;i < 20
executed 720 times by 1 test: end of block Executed by:
| 80-720 | ||||||||||||
209 | mult(t0,t1,z2_20_0); | - | ||||||||||||
210 | - | |||||||||||||
211 | square(t1,t0); | - | ||||||||||||
212 | square(t0,t1); | - | ||||||||||||
213 | for (i = 2;i < 10
executed 320 times by 1 test: end of block Executed by:
| 80-320 | ||||||||||||
214 | mult(z2_50_0,t0,z2_10_0); | - | ||||||||||||
215 | - | |||||||||||||
216 | square(t0,z2_50_0); | - | ||||||||||||
217 | square(t1,t0); | - | ||||||||||||
218 | for (i = 2;i < 50
executed 1920 times by 1 test: end of block Executed by:
| 80-1920 | ||||||||||||
219 | mult(z2_100_0,t1,z2_50_0); | - | ||||||||||||
220 | - | |||||||||||||
221 | square(t1,z2_100_0); | - | ||||||||||||
222 | square(t0,t1); | - | ||||||||||||
223 | for (i = 2;i < 100
executed 3920 times by 1 test: end of block Executed by:
| 80-3920 | ||||||||||||
224 | mult(t1,t0,z2_100_0); | - | ||||||||||||
225 | - | |||||||||||||
226 | square(t0,t1); | - | ||||||||||||
227 | square(t1,t0); | - | ||||||||||||
228 | for (i = 2;i < 50
executed 1920 times by 1 test: end of block Executed by:
| 80-1920 | ||||||||||||
229 | mult(t0,t1,z2_50_0); | - | ||||||||||||
230 | - | |||||||||||||
231 | square(t1,t0); | - | ||||||||||||
232 | square(t0,t1); | - | ||||||||||||
233 | square(t1,t0); | - | ||||||||||||
234 | square(t0,t1); | - | ||||||||||||
235 | square(t1,t0); | - | ||||||||||||
236 | mult(out,t1,z11); | - | ||||||||||||
237 | } executed 80 times by 1 test: end of block Executed by:
| 80 | ||||||||||||
238 | - | |||||||||||||
239 | int crypto_scalarmult_curve25519(unsigned char *q, | - | ||||||||||||
240 | const unsigned char *n, | - | ||||||||||||
241 | const unsigned char *p) | - | ||||||||||||
242 | { | - | ||||||||||||
243 | unsigned int work[96]; | - | ||||||||||||
244 | unsigned char e[32]; | - | ||||||||||||
245 | unsigned int i; | - | ||||||||||||
246 | for (i = 0;i < 32
executed 2560 times by 1 test: e[i] = n[i]; Executed by:
| 80-2560 | ||||||||||||
247 | e[0] &= 248; | - | ||||||||||||
248 | e[31] &= 127; | - | ||||||||||||
249 | e[31] |= 64; | - | ||||||||||||
250 | for (i = 0;i < 32
executed 2560 times by 1 test: work[i] = p[i]; Executed by:
| 80-2560 | ||||||||||||
251 | mainloop(work,e); | - | ||||||||||||
252 | recip(work + 32,work + 32); | - | ||||||||||||
253 | mult(work + 64,work,work + 32); | - | ||||||||||||
254 | freeze(work + 64); | - | ||||||||||||
255 | for (i = 0;i < 32
executed 2560 times by 1 test: q[i] = work[64 + i]; Executed by:
| 80-2560 | ||||||||||||
256 | return executed 80 times by 1 test: 0;return 0; Executed by:
executed 80 times by 1 test: return 0; Executed by:
| 80 | ||||||||||||
257 | } | - | ||||||||||||
Switch to Source code | Preprocessed file |