Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/bn/bn_word.c |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||||||||||||||
2 | unsigned long BN_mod_word(const BIGNUM *a, unsigned long w) | - | ||||||||||||||||||||||||
3 | { | - | ||||||||||||||||||||||||
4 | - | |||||||||||||||||||||||||
5 | unsigned long ret = 0; | - | ||||||||||||||||||||||||
6 | - | |||||||||||||||||||||||||
7 | - | |||||||||||||||||||||||||
8 | - | |||||||||||||||||||||||||
9 | int i; | - | ||||||||||||||||||||||||
10 | - | |||||||||||||||||||||||||
11 | if (w == 0
| 0-7022607 | ||||||||||||||||||||||||
12 | return never executed: (unsigned long)-1;return (unsigned long)-1; never executed: return (unsigned long)-1; | 0 | ||||||||||||||||||||||||
13 | - | |||||||||||||||||||||||||
14 | - | |||||||||||||||||||||||||
15 | - | |||||||||||||||||||||||||
16 | - | |||||||||||||||||||||||||
17 | - | |||||||||||||||||||||||||
18 | - | |||||||||||||||||||||||||
19 | if (w > ((unsigned long)1 << 32)
| 103-7022504 | ||||||||||||||||||||||||
20 | BIGNUM *tmp = BN_dup(a); | - | ||||||||||||||||||||||||
21 | if (tmp ==
| 0-103 | ||||||||||||||||||||||||
22 | ((void *)0)
| 0-103 | ||||||||||||||||||||||||
23 | ) | - | ||||||||||||||||||||||||
24 | return never executed: (unsigned long)-1;return (unsigned long)-1; never executed: return (unsigned long)-1; | 0 | ||||||||||||||||||||||||
25 | - | |||||||||||||||||||||||||
26 | ret = BN_div_word(tmp, w); | - | ||||||||||||||||||||||||
27 | BN_free(tmp); | - | ||||||||||||||||||||||||
28 | - | |||||||||||||||||||||||||
29 | return executed 103 times by 1 test: ret;return ret; Executed by:
executed 103 times by 1 test: return ret; Executed by:
| 103 | ||||||||||||||||||||||||
30 | } | - | ||||||||||||||||||||||||
31 | - | |||||||||||||||||||||||||
32 | - | |||||||||||||||||||||||||
33 | ; | - | ||||||||||||||||||||||||
34 | w &= (0xffffffffffffffffL); | - | ||||||||||||||||||||||||
35 | for (i = a->top - 1; i >= 0
| 7022504-141244951 | ||||||||||||||||||||||||
36 | - | |||||||||||||||||||||||||
37 | - | |||||||||||||||||||||||||
38 | - | |||||||||||||||||||||||||
39 | - | |||||||||||||||||||||||||
40 | - | |||||||||||||||||||||||||
41 | - | |||||||||||||||||||||||||
42 | ret = ((ret << 32) | ((a->d[i] >> 32) & (0xffffffffL))) % w; | - | ||||||||||||||||||||||||
43 | ret = ((ret << 32) | (a->d[i] & (0xffffffffL))) % w; | - | ||||||||||||||||||||||||
44 | - | |||||||||||||||||||||||||
45 | - | |||||||||||||||||||||||||
46 | - | |||||||||||||||||||||||||
47 | - | |||||||||||||||||||||||||
48 | } executed 141244951 times by 1 test: end of block Executed by:
| 141244951 | ||||||||||||||||||||||||
49 | return executed 7022504 times by 1 test: (unsigned long)ret;return (unsigned long)ret; Executed by:
executed 7022504 times by 1 test: return (unsigned long)ret; Executed by:
| 7022504 | ||||||||||||||||||||||||
50 | } | - | ||||||||||||||||||||||||
51 | - | |||||||||||||||||||||||||
52 | unsigned long BN_div_word(BIGNUM *a, unsigned long w) | - | ||||||||||||||||||||||||
53 | { | - | ||||||||||||||||||||||||
54 | unsigned long ret = 0; | - | ||||||||||||||||||||||||
55 | int i, j; | - | ||||||||||||||||||||||||
56 | - | |||||||||||||||||||||||||
57 | ; | - | ||||||||||||||||||||||||
58 | w &= (0xffffffffffffffffL); | - | ||||||||||||||||||||||||
59 | - | |||||||||||||||||||||||||
60 | if (!w
| 0-35819 | ||||||||||||||||||||||||
61 | - | |||||||||||||||||||||||||
62 | return never executed: (unsigned long)-1;return (unsigned long)-1; never executed: return (unsigned long)-1; | 0 | ||||||||||||||||||||||||
63 | if (a->top == 0
| 0-35819 | ||||||||||||||||||||||||
64 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
65 | - | |||||||||||||||||||||||||
66 | - | |||||||||||||||||||||||||
67 | j = (8 * 8) - BN_num_bits_word(w); | - | ||||||||||||||||||||||||
68 | w <<= j; | - | ||||||||||||||||||||||||
69 | if (!BN_lshift(a, a, j)
| 0-35819 | ||||||||||||||||||||||||
70 | return never executed: (unsigned long)-1;return (unsigned long)-1; never executed: return (unsigned long)-1; | 0 | ||||||||||||||||||||||||
71 | - | |||||||||||||||||||||||||
72 | for (i = a->top - 1; i >= 0
| 35819-95669 | ||||||||||||||||||||||||
73 | unsigned long l, d; | - | ||||||||||||||||||||||||
74 | - | |||||||||||||||||||||||||
75 | l = a->d[i]; | - | ||||||||||||||||||||||||
76 | d = bn_div_words(ret, l, w); | - | ||||||||||||||||||||||||
77 | ret = (l - ((d * w) & (0xffffffffffffffffL))) & (0xffffffffffffffffL); | - | ||||||||||||||||||||||||
78 | a->d[i] = d; | - | ||||||||||||||||||||||||
79 | } executed 95669 times by 1 test: end of block Executed by:
| 95669 | ||||||||||||||||||||||||
80 | if ((
| 0-35819 | ||||||||||||||||||||||||
81 | a->top--; executed 34752 times by 1 test: a->top--; Executed by:
| 34752 | ||||||||||||||||||||||||
82 | ret >>= j; | - | ||||||||||||||||||||||||
83 | if (!a->top
| 17143-18676 | ||||||||||||||||||||||||
84 | a->neg = 0; executed 17143 times by 1 test: a->neg = 0; Executed by:
| 17143 | ||||||||||||||||||||||||
85 | ; | - | ||||||||||||||||||||||||
86 | return executed 35819 times by 1 test: ret;return ret; Executed by:
executed 35819 times by 1 test: return ret; Executed by:
| 35819 | ||||||||||||||||||||||||
87 | } | - | ||||||||||||||||||||||||
88 | - | |||||||||||||||||||||||||
89 | int BN_add_word(BIGNUM *a, unsigned long w) | - | ||||||||||||||||||||||||
90 | { | - | ||||||||||||||||||||||||
91 | unsigned long l; | - | ||||||||||||||||||||||||
92 | int i; | - | ||||||||||||||||||||||||
93 | - | |||||||||||||||||||||||||
94 | ; | - | ||||||||||||||||||||||||
95 | w &= (0xffffffffffffffffL); | - | ||||||||||||||||||||||||
96 | - | |||||||||||||||||||||||||
97 | - | |||||||||||||||||||||||||
98 | if (!w
| 48980-208788 | ||||||||||||||||||||||||
99 | return executed 48980 times by 1 test: 1;return 1; Executed by:
executed 48980 times by 1 test: return 1; Executed by:
| 48980 | ||||||||||||||||||||||||
100 | - | |||||||||||||||||||||||||
101 | if (BN_is_zero(a)
| 1305-207483 | ||||||||||||||||||||||||
102 | return executed 1305 times by 1 test: BN_set_word(a, w);return BN_set_word(a, w); Executed by:
executed 1305 times by 1 test: return BN_set_word(a, w); Executed by:
| 1305 | ||||||||||||||||||||||||
103 | - | |||||||||||||||||||||||||
104 | if (a->neg
| 0-207483 | ||||||||||||||||||||||||
105 | a->neg = 0; | - | ||||||||||||||||||||||||
106 | i = BN_sub_word(a, w); | - | ||||||||||||||||||||||||
107 | if (!BN_is_zero(a)
| 0 | ||||||||||||||||||||||||
108 | a->neg = !(a->neg); never executed: a->neg = !(a->neg); | 0 | ||||||||||||||||||||||||
109 | return never executed: i;return i; never executed: return i; | 0 | ||||||||||||||||||||||||
110 | } | - | ||||||||||||||||||||||||
111 | for (i = 0; w != 0
| 269-217503 | ||||||||||||||||||||||||
112 | a->d[i] = l = (a->d[i] + w) & (0xffffffffffffffffL); | - | ||||||||||||||||||||||||
113 | w = (
| 10020-207214 | ||||||||||||||||||||||||
114 | } executed 217234 times by 2 tests: end of block Executed by:
| 217234 | ||||||||||||||||||||||||
115 | if (w
| 0-207214 | ||||||||||||||||||||||||
116 | if (bn_wexpand(a, a->top + 1) ==
| 0-269 | ||||||||||||||||||||||||
117 | ((void *)0)
| 0-269 | ||||||||||||||||||||||||
118 | ) | - | ||||||||||||||||||||||||
119 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
120 | a->top++; | - | ||||||||||||||||||||||||
121 | a->d[i] = w; | - | ||||||||||||||||||||||||
122 | } executed 269 times by 1 test: end of block Executed by:
| 269 | ||||||||||||||||||||||||
123 | ; | - | ||||||||||||||||||||||||
124 | return executed 207483 times by 2 tests: 1;return 1; Executed by:
executed 207483 times by 2 tests: return 1; Executed by:
| 207483 | ||||||||||||||||||||||||
125 | } | - | ||||||||||||||||||||||||
126 | - | |||||||||||||||||||||||||
127 | int BN_sub_word(BIGNUM *a, unsigned long w) | - | ||||||||||||||||||||||||
128 | { | - | ||||||||||||||||||||||||
129 | int i; | - | ||||||||||||||||||||||||
130 | - | |||||||||||||||||||||||||
131 | ; | - | ||||||||||||||||||||||||
132 | w &= (0xffffffffffffffffL); | - | ||||||||||||||||||||||||
133 | - | |||||||||||||||||||||||||
134 | - | |||||||||||||||||||||||||
135 | if (!w
| 3-88354 | ||||||||||||||||||||||||
136 | return executed 3 times by 1 test: 1;return 1; Executed by:
executed 3 times by 1 test: return 1; Executed by:
| 3 | ||||||||||||||||||||||||
137 | - | |||||||||||||||||||||||||
138 | if (BN_is_zero(a)
| 6-88348 | ||||||||||||||||||||||||
139 | i = BN_set_word(a, w); | - | ||||||||||||||||||||||||
140 | if (i != 0
| 0-6 | ||||||||||||||||||||||||
141 | BN_set_negative(a, 1); executed 6 times by 1 test: BN_set_negative(a, 1); Executed by:
| 6 | ||||||||||||||||||||||||
142 | return executed 6 times by 1 test: i;return i; Executed by:
executed 6 times by 1 test: return i; Executed by:
| 6 | ||||||||||||||||||||||||
143 | } | - | ||||||||||||||||||||||||
144 | - | |||||||||||||||||||||||||
145 | if (a->neg
| 0-88348 | ||||||||||||||||||||||||
146 | a->neg = 0; | - | ||||||||||||||||||||||||
147 | i = BN_add_word(a, w); | - | ||||||||||||||||||||||||
148 | a->neg = 1; | - | ||||||||||||||||||||||||
149 | return never executed: i;return i; never executed: return i; | 0 | ||||||||||||||||||||||||
150 | } | - | ||||||||||||||||||||||||
151 | - | |||||||||||||||||||||||||
152 | if ((
| 0-87847 | ||||||||||||||||||||||||
153 | a->d[0] = w - a->d[0]; | - | ||||||||||||||||||||||||
154 | a->neg = 1; | - | ||||||||||||||||||||||||
155 | return never executed: 1;return 1; never executed: return 1; | 0 | ||||||||||||||||||||||||
156 | } | - | ||||||||||||||||||||||||
157 | i = 0; | - | ||||||||||||||||||||||||
158 | for (;;) { | - | ||||||||||||||||||||||||
159 | if (a->d[i] >= w
| 80712-88348 | ||||||||||||||||||||||||
160 | a->d[i] -= w; | - | ||||||||||||||||||||||||
161 | break; executed 88348 times by 2 tests: break; Executed by:
| 88348 | ||||||||||||||||||||||||
162 | } else { | - | ||||||||||||||||||||||||
163 | a->d[i] = (a->d[i] - w) & (0xffffffffffffffffL); | - | ||||||||||||||||||||||||
164 | i++; | - | ||||||||||||||||||||||||
165 | w = 1; | - | ||||||||||||||||||||||||
166 | } executed 80712 times by 2 tests: end of block Executed by:
| 80712 | ||||||||||||||||||||||||
167 | } | - | ||||||||||||||||||||||||
168 | if ((
| 991-63545 | ||||||||||||||||||||||||
169 | a->top--; executed 23812 times by 1 test: a->top--; Executed by:
| 23812 | ||||||||||||||||||||||||
170 | ; | - | ||||||||||||||||||||||||
171 | return executed 88348 times by 2 tests: 1;return 1; Executed by:
executed 88348 times by 2 tests: return 1; Executed by:
| 88348 | ||||||||||||||||||||||||
172 | } | - | ||||||||||||||||||||||||
173 | - | |||||||||||||||||||||||||
174 | int BN_mul_word(BIGNUM *a, unsigned long w) | - | ||||||||||||||||||||||||
175 | { | - | ||||||||||||||||||||||||
176 | unsigned long ll; | - | ||||||||||||||||||||||||
177 | - | |||||||||||||||||||||||||
178 | ; | - | ||||||||||||||||||||||||
179 | w &= (0xffffffffffffffffL); | - | ||||||||||||||||||||||||
180 | if (a->top
| 590-142222 | ||||||||||||||||||||||||
181 | if (w == 0
| 0-142222 | ||||||||||||||||||||||||
182 | ( never executed: BN_set_word((a),0));(BN_set_word((a),0)); never executed: (BN_set_word((a),0)); | 0 | ||||||||||||||||||||||||
183 | else { | - | ||||||||||||||||||||||||
184 | ll = bn_mul_words(a->d, a->d, a->top, w); | - | ||||||||||||||||||||||||
185 | if (ll
| 10816-131406 | ||||||||||||||||||||||||
186 | if (bn_wexpand(a, a->top + 1) ==
| 0-131406 | ||||||||||||||||||||||||
187 | ((void *)0)
| 0-131406 | ||||||||||||||||||||||||
188 | ) | - | ||||||||||||||||||||||||
189 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
190 | a->d[a->top++] = ll; | - | ||||||||||||||||||||||||
191 | } executed 131406 times by 1 test: end of block Executed by:
| 131406 | ||||||||||||||||||||||||
192 | } executed 142222 times by 1 test: end of block Executed by:
| 142222 | ||||||||||||||||||||||||
193 | } | - | ||||||||||||||||||||||||
194 | ; | - | ||||||||||||||||||||||||
195 | return executed 142812 times by 1 test: 1;return 1; Executed by:
executed 142812 times by 1 test: return 1; Executed by:
| 142812 | ||||||||||||||||||||||||
196 | } | - | ||||||||||||||||||||||||
Switch to Source code | Preprocessed file |