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