Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/libressl/src/crypto/bn/bn_recp.c |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||
2 | - | |||||||||||||
3 | - | |||||||||||||
4 | void | - | ||||||||||||
5 | BN_RECP_CTX_init(BN_RECP_CTX *recp) | - | ||||||||||||
6 | { | - | ||||||||||||
7 | BN_init(&(recp->N)); | - | ||||||||||||
8 | BN_init(&(recp->Nr)); | - | ||||||||||||
9 | recp->num_bits = 0; | - | ||||||||||||
10 | recp->flags = 0; | - | ||||||||||||
11 | } executed 304 times by 2 tests: end of block Executed by:
| 304 | ||||||||||||
12 | - | |||||||||||||
13 | BN_RECP_CTX * | - | ||||||||||||
14 | BN_RECP_CTX_new(void) | - | ||||||||||||
15 | { | - | ||||||||||||
16 | BN_RECP_CTX *ret; | - | ||||||||||||
17 | - | |||||||||||||
18 | if ((
| 0 | ||||||||||||
19 | ((void *)0)
| 0 | ||||||||||||
20 | ) | - | ||||||||||||
21 | return never executed: (return ( ((void *)0) ); never executed: return ( ((void *)0) ); | 0 | ||||||||||||
22 | ((void *)0) never executed: return ( ((void *)0) ); | 0 | ||||||||||||
23 | ); never executed: return ( ((void *)0) ); | 0 | ||||||||||||
24 | - | |||||||||||||
25 | BN_RECP_CTX_init(ret); | - | ||||||||||||
26 | ret->flags = 0x01; | - | ||||||||||||
27 | return never executed: (ret);return (ret); never executed: return (ret); | 0 | ||||||||||||
28 | } | - | ||||||||||||
29 | - | |||||||||||||
30 | void | - | ||||||||||||
31 | BN_RECP_CTX_free(BN_RECP_CTX *recp) | - | ||||||||||||
32 | { | - | ||||||||||||
33 | if (recp ==
| 1-304 | ||||||||||||
34 | ((void *)0)
| 1-304 | ||||||||||||
35 | ) | - | ||||||||||||
36 | return; executed 1 time by 1 test: return; Executed by:
| 1 | ||||||||||||
37 | - | |||||||||||||
38 | BN_free(&(recp->N)); | - | ||||||||||||
39 | BN_free(&(recp->Nr)); | - | ||||||||||||
40 | if (recp->flags & 0x01
| 0-304 | ||||||||||||
41 | free(recp); never executed: free(recp); | 0 | ||||||||||||
42 | } executed 304 times by 2 tests: end of block Executed by:
| 304 | ||||||||||||
43 | - | |||||||||||||
44 | int | - | ||||||||||||
45 | BN_RECP_CTX_set(BN_RECP_CTX *recp, const BIGNUM *d, BN_CTX *ctx) | - | ||||||||||||
46 | { | - | ||||||||||||
47 | if (!BN_copy(&(recp->N), d)
| 0-453 | ||||||||||||
48 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
49 | (BN_set_word((&(recp->Nr)),0)); | - | ||||||||||||
50 | recp->num_bits = BN_num_bits(d); | - | ||||||||||||
51 | recp->shift = 0; | - | ||||||||||||
52 | return executed 453 times by 2 tests: (1);return (1); Executed by:
executed 453 times by 2 tests: return (1); Executed by:
| 453 | ||||||||||||
53 | } | - | ||||||||||||
54 | - | |||||||||||||
55 | int | - | ||||||||||||
56 | BN_mod_mul_reciprocal(BIGNUM *r, const BIGNUM *x, const BIGNUM *y, | - | ||||||||||||
57 | BN_RECP_CTX *recp, BN_CTX *ctx) | - | ||||||||||||
58 | { | - | ||||||||||||
59 | int ret = 0; | - | ||||||||||||
60 | BIGNUM *a; | - | ||||||||||||
61 | const BIGNUM *ca; | - | ||||||||||||
62 | - | |||||||||||||
63 | BN_CTX_start(ctx); | - | ||||||||||||
64 | if ((
| 0-138216 | ||||||||||||
65 | ((void *)0)
| 0-138216 | ||||||||||||
66 | ) | - | ||||||||||||
67 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
68 | if (y !=
| 0-138216 | ||||||||||||
69 | ((void *)0)
| 0-138216 | ||||||||||||
70 | ) { | - | ||||||||||||
71 | if (x == y
| 23732-114484 | ||||||||||||
72 | if (!BN_sqr(a, x, ctx)
| 0-114484 | ||||||||||||
73 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
74 | } executed 114484 times by 2 tests: else {end of block Executed by:
| 114484 | ||||||||||||
75 | if (!BN_mul(a, x, y, ctx)
| 0-23732 | ||||||||||||
76 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
77 | } executed 23732 times by 2 tests: end of block Executed by:
| 23732 | ||||||||||||
78 | ca = a; | - | ||||||||||||
79 | } executed 138216 times by 2 tests: elseend of block Executed by:
| 138216 | ||||||||||||
80 | ca = x; never executed: ca = x; | 0 | ||||||||||||
81 | - | |||||||||||||
82 | ret = BN_div_recp( | - | ||||||||||||
83 | ((void *)0) | - | ||||||||||||
84 | , r, ca, recp, ctx); | - | ||||||||||||
85 | - | |||||||||||||
86 | err: code before this statement executed 138216 times by 2 tests: err: Executed by:
| 138216 | ||||||||||||
87 | BN_CTX_end(ctx); | - | ||||||||||||
88 | ; | - | ||||||||||||
89 | return executed 138216 times by 2 tests: (ret);return (ret); Executed by:
executed 138216 times by 2 tests: return (ret); Executed by:
| 138216 | ||||||||||||
90 | } | - | ||||||||||||
91 | - | |||||||||||||
92 | int | - | ||||||||||||
93 | BN_div_recp(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, BN_RECP_CTX *recp, | - | ||||||||||||
94 | BN_CTX *ctx) | - | ||||||||||||
95 | { | - | ||||||||||||
96 | int i, j, ret = 0; | - | ||||||||||||
97 | BIGNUM *a, *b, *d, *r; | - | ||||||||||||
98 | - | |||||||||||||
99 | BN_CTX_start(ctx); | - | ||||||||||||
100 | a = BN_CTX_get(ctx); | - | ||||||||||||
101 | b = BN_CTX_get(ctx); | - | ||||||||||||
102 | if (dv !=
| 150-138216 | ||||||||||||
103 | ((void *)0)
| 150-138216 | ||||||||||||
104 | ) | - | ||||||||||||
105 | d = dv; executed 150 times by 1 test: d = dv; Executed by:
| 150 | ||||||||||||
106 | else | - | ||||||||||||
107 | d = BN_CTX_get(ctx); executed 138216 times by 2 tests: d = BN_CTX_get(ctx); Executed by:
| 138216 | ||||||||||||
108 | if (rem !=
| 0-138366 | ||||||||||||
109 | ((void *)0)
| 0-138366 | ||||||||||||
110 | ) | - | ||||||||||||
111 | r = rem; executed 138366 times by 2 tests: r = rem; Executed by:
| 138366 | ||||||||||||
112 | else | - | ||||||||||||
113 | r = BN_CTX_get(ctx); never executed: r = BN_CTX_get(ctx); | 0 | ||||||||||||
114 | if (a ==
| 0-138366 | ||||||||||||
115 | ((void *)0)
| 0-138366 | ||||||||||||
116 | || b ==
| 0-138366 | ||||||||||||
117 | ((void *)0)
| 0-138366 | ||||||||||||
118 | || d ==
| 0-138366 | ||||||||||||
119 | ((void *)0)
| 0-138366 | ||||||||||||
120 | || r ==
| 0-138366 | ||||||||||||
121 | ((void *)0)
| 0-138366 | ||||||||||||
122 | ) | - | ||||||||||||
123 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
124 | - | |||||||||||||
125 | if (BN_ucmp(m, &(recp->N)) < 0
| 343-138023 | ||||||||||||
126 | (BN_set_word((d),0)); | - | ||||||||||||
127 | if (!BN_copy(r, m)
| 0-343 | ||||||||||||
128 | BN_CTX_end(ctx); | - | ||||||||||||
129 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
130 | } | - | ||||||||||||
131 | BN_CTX_end(ctx); | - | ||||||||||||
132 | return executed 343 times by 2 tests: (1);return (1); Executed by:
executed 343 times by 2 tests: return (1); Executed by:
| 343 | ||||||||||||
133 | } | - | ||||||||||||
134 | i = BN_num_bits(m); | - | ||||||||||||
135 | j = recp->num_bits << 1; | - | ||||||||||||
136 | if (j > i
| 16061-121962 | ||||||||||||
137 | i = j; executed 121962 times by 2 tests: i = j; Executed by:
| 121962 | ||||||||||||
138 | - | |||||||||||||
139 | - | |||||||||||||
140 | if (i != recp->shift
| 450-137573 | ||||||||||||
141 | recp->shift = BN_reciprocal(&(recp->Nr), &(recp->N), i, ctx); executed 450 times by 2 tests: recp->shift = BN_reciprocal(&(recp->Nr), &(recp->N), i, ctx); Executed by:
| 450 | ||||||||||||
142 | - | |||||||||||||
143 | - | |||||||||||||
144 | if (recp->shift == -1
| 0-138023 | ||||||||||||
145 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
146 | - | |||||||||||||
147 | - | |||||||||||||
148 | - | |||||||||||||
149 | - | |||||||||||||
150 | - | |||||||||||||
151 | - | |||||||||||||
152 | if (!BN_rshift(a, m, recp->num_bits)
| 0-138023 | ||||||||||||
153 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
154 | if (!BN_mul(b, a,&(recp->Nr), ctx)
| 0-138023 | ||||||||||||
155 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
156 | if (!BN_rshift(d, b, i - recp->num_bits)
| 0-138023 | ||||||||||||
157 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
158 | d->neg = 0; | - | ||||||||||||
159 | - | |||||||||||||
160 | if (!BN_mul(b, &(recp->N), d, ctx)
| 0-138023 | ||||||||||||
161 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
162 | if (!BN_usub(r, m, b)
| 0-138023 | ||||||||||||
163 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
164 | r->neg = 0; | - | ||||||||||||
165 | - | |||||||||||||
166 | - | |||||||||||||
167 | j = 0; | - | ||||||||||||
168 | while (BN_ucmp(r, &(recp->N)) >= 0
| 97174-138023 | ||||||||||||
169 | if (j++ > 2
| 0-97174 | ||||||||||||
170 | ERR_put_error(3,(0xfff),(101),__FILE__,215); | - | ||||||||||||
171 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
172 | } | - | ||||||||||||
173 | if (!BN_usub(r, r, &(recp->N))
| 0-97174 | ||||||||||||
174 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
175 | if (!BN_add_word(d, 1)
| 0-97174 | ||||||||||||
176 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
177 | } executed 97174 times by 2 tests: end of block Executed by:
| 97174 | ||||||||||||
178 | - | |||||||||||||
179 | - | |||||||||||||
180 | r->neg = ((
| 1-138022 | ||||||||||||
181 | d->neg = m->neg^recp->N.neg; | - | ||||||||||||
182 | ret = 1; | - | ||||||||||||
183 | - | |||||||||||||
184 | err: code before this statement executed 138023 times by 2 tests: err: Executed by:
| 138023 | ||||||||||||
185 | BN_CTX_end(ctx); | - | ||||||||||||
186 | ; | - | ||||||||||||
187 | ; | - | ||||||||||||
188 | return executed 138023 times by 2 tests: (ret);return (ret); Executed by:
executed 138023 times by 2 tests: return (ret); Executed by:
| 138023 | ||||||||||||
189 | } | - | ||||||||||||
190 | - | |||||||||||||
191 | - | |||||||||||||
192 | - | |||||||||||||
193 | - | |||||||||||||
194 | - | |||||||||||||
195 | - | |||||||||||||
196 | int | - | ||||||||||||
197 | BN_reciprocal(BIGNUM *r, const BIGNUM *m, int len, BN_CTX *ctx) | - | ||||||||||||
198 | { | - | ||||||||||||
199 | int ret = -1; | - | ||||||||||||
200 | BIGNUM *t; | - | ||||||||||||
201 | - | |||||||||||||
202 | BN_CTX_start(ctx); | - | ||||||||||||
203 | if ((
| 0-450 | ||||||||||||
204 | ((void *)0)
| 0-450 | ||||||||||||
205 | ) | - | ||||||||||||
206 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
207 | - | |||||||||||||
208 | if (!BN_set_bit(t, len)
| 0-450 | ||||||||||||
209 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
210 | - | |||||||||||||
211 | if (!BN_div_ct(r,
| 0-450 | ||||||||||||
212 | ((void *)0)
| 0-450 | ||||||||||||
213 | , t,m, ctx)
| 0-450 | ||||||||||||
214 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
215 | - | |||||||||||||
216 | ret = len; | - | ||||||||||||
217 | - | |||||||||||||
218 | err: code before this statement executed 450 times by 2 tests: err: Executed by:
| 450 | ||||||||||||
219 | ; | - | ||||||||||||
220 | BN_CTX_end(ctx); | - | ||||||||||||
221 | return executed 450 times by 2 tests: (ret);return (ret); Executed by:
executed 450 times by 2 tests: return (ret); Executed by:
| 450 | ||||||||||||
222 | } | - | ||||||||||||
Switch to Source code | Preprocessed file |