Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/ec/curve448/f_generic.c |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||
2 | static const gf MODULUS = { | - | ||||||||||||
3 | {{((0xffffffffffffff) & ((1 << 28) - 1)), ((0xffffffffffffff) >> 28), ((0xffffffffffffff) & ((1 << 28) - 1)), ((0xffffffffffffff) >> 28), ((0xffffffffffffff) & ((1 << 28) - 1)), ((0xffffffffffffff) >> 28), ((0xffffffffffffff) & ((1 << 28) - 1)), ((0xffffffffffffff) >> 28), ((0xfffffffffffffe) & ((1 << 28) - 1)), ((0xfffffffffffffe) >> 28), ((0xffffffffffffff) & ((1 << 28) - 1)), ((0xffffffffffffff) >> 28), ((0xffffffffffffff) & ((1 << 28) - 1)), ((0xffffffffffffff) >> 28), ((0xffffffffffffff) & ((1 << 28) - 1)), ((0xffffffffffffff) >> 28)}} | - | ||||||||||||
4 | - | |||||||||||||
5 | - | |||||||||||||
6 | }; | - | ||||||||||||
7 | - | |||||||||||||
8 | - | |||||||||||||
9 | void gf_serialize(uint8_t serial[56], const gf x, int with_hibit) | - | ||||||||||||
10 | { | - | ||||||||||||
11 | unsigned int j = 0, fill = 0; | - | ||||||||||||
12 | dword_t buffer = 0; | - | ||||||||||||
13 | int i; | - | ||||||||||||
14 | gf red; | - | ||||||||||||
15 | - | |||||||||||||
16 | gf_copy(red, x); | - | ||||||||||||
17 | gf_strong_reduce(red); | - | ||||||||||||
18 | if (!with_hibit
| 0-1136 | ||||||||||||
19 | - | |||||||||||||
20 | (( never executed: void) (0))((void) (0)) ; never executed: ((void) (0)) ; | 0 | ||||||||||||
21 | ; never executed: ((void) (0)) ; | 0 | ||||||||||||
22 | - | |||||||||||||
23 | for (i = 0; i < (with_hibit ? 56 : 56)
| 1136-63616 | ||||||||||||
24 | if (fill < 8
| 0-45440 | ||||||||||||
25 | buffer |= ((dword_t) red->limb[(j)]) << fill; | - | ||||||||||||
26 | fill += 28; | - | ||||||||||||
27 | j++; | - | ||||||||||||
28 | } executed 18176 times by 2 tests: end of block Executed by:
| 18176 | ||||||||||||
29 | serial[i] = (uint8_t)buffer; | - | ||||||||||||
30 | fill -= 8; | - | ||||||||||||
31 | buffer >>= 8; | - | ||||||||||||
32 | } executed 63616 times by 2 tests: end of block Executed by:
| 63616 | ||||||||||||
33 | } executed 1136 times by 2 tests: end of block Executed by:
| 1136 | ||||||||||||
34 | - | |||||||||||||
35 | - | |||||||||||||
36 | mask_t gf_hibit(const gf x) | - | ||||||||||||
37 | { | - | ||||||||||||
38 | gf y; | - | ||||||||||||
39 | - | |||||||||||||
40 | gf_add(y, x, x); | - | ||||||||||||
41 | gf_strong_reduce(y); | - | ||||||||||||
42 | return never executed: 0 - (y->limb[0] & 1);return 0 - (y->limb[0] & 1); never executed: return 0 - (y->limb[0] & 1); | 0 | ||||||||||||
43 | } | - | ||||||||||||
44 | - | |||||||||||||
45 | - | |||||||||||||
46 | mask_t gf_lobit(const gf x) | - | ||||||||||||
47 | { | - | ||||||||||||
48 | gf y; | - | ||||||||||||
49 | - | |||||||||||||
50 | gf_copy(y, x); | - | ||||||||||||
51 | gf_strong_reduce(y); | - | ||||||||||||
52 | return executed 81 times by 2 tests: 0 - (y->limb[0] & 1);return 0 - (y->limb[0] & 1); Executed by:
executed 81 times by 2 tests: return 0 - (y->limb[0] & 1); Executed by:
| 81 | ||||||||||||
53 | } | - | ||||||||||||
54 | - | |||||||||||||
55 | - | |||||||||||||
56 | mask_t gf_deserialize(gf x, const uint8_t serial[56], int with_hibit, | - | ||||||||||||
57 | uint8_t hi_nmask) | - | ||||||||||||
58 | { | - | ||||||||||||
59 | unsigned int j = 0, fill = 0; | - | ||||||||||||
60 | dword_t buffer = 0; | - | ||||||||||||
61 | dsword_t scarry = 0; | - | ||||||||||||
62 | const unsigned nbytes = with_hibit
| 0-1032 | ||||||||||||
63 | unsigned int i; | - | ||||||||||||
64 | mask_t succ; | - | ||||||||||||
65 | - | |||||||||||||
66 | for (i = 0; i < (64/sizeof(word_t))
| 1032-16512 | ||||||||||||
67 | while (fill < 28
| 0-57792 | ||||||||||||
68 | uint8_t sj; | - | ||||||||||||
69 | - | |||||||||||||
70 | sj = serial[j]; | - | ||||||||||||
71 | if (j == nbytes - 1
| 1032-56760 | ||||||||||||
72 | sj &= ~hi_nmask; executed 1032 times by 2 tests: sj &= ~hi_nmask; Executed by:
| 1032 | ||||||||||||
73 | buffer |= ((dword_t) sj) << fill; | - | ||||||||||||
74 | fill += 8; | - | ||||||||||||
75 | j++; | - | ||||||||||||
76 | } executed 57792 times by 2 tests: end of block Executed by:
| 57792 | ||||||||||||
77 | x->limb[(i)] = (word_t) | - | ||||||||||||
78 | ((
| 1032-15480 | ||||||||||||
79 | fill -= 28; | - | ||||||||||||
80 | buffer >>= 28; | - | ||||||||||||
81 | scarry = | - | ||||||||||||
82 | (scarry + x->limb[(i)] - | - | ||||||||||||
83 | MODULUS->limb[(i)]) >> (8 * sizeof(word_t)); | - | ||||||||||||
84 | } executed 16512 times by 2 tests: end of block Executed by:
| 16512 | ||||||||||||
85 | succ = with_hibit
| 0-1032 | ||||||||||||
86 | return executed 1032 times by 2 tests: succ & constant_time_is_zero_32((word_t)buffer) & ~constant_time_is_zero_32((word_t)scarry);return succ & constant_time_is_zero_32((word_t)buffer) & ~constant_time_is_zero_32((word_t)scarry); Executed by:
executed 1032 times by 2 tests: return succ & constant_time_is_zero_32((word_t)buffer) & ~constant_time_is_zero_32((word_t)scarry); Executed by:
| 1032 | ||||||||||||
87 | } | - | ||||||||||||
88 | - | |||||||||||||
89 | - | |||||||||||||
90 | void gf_strong_reduce(gf a) | - | ||||||||||||
91 | { | - | ||||||||||||
92 | dsword_t scarry; | - | ||||||||||||
93 | word_t scarry_0; | - | ||||||||||||
94 | dword_t carry = 0; | - | ||||||||||||
95 | unsigned int i; | - | ||||||||||||
96 | - | |||||||||||||
97 | - | |||||||||||||
98 | gf_weak_reduce(a); | - | ||||||||||||
99 | - | |||||||||||||
100 | - | |||||||||||||
101 | - | |||||||||||||
102 | - | |||||||||||||
103 | scarry = 0; | - | ||||||||||||
104 | for (i = 0; i < (64/sizeof(word_t))
| 3394-54304 | ||||||||||||
105 | scarry = scarry + a->limb[(i)] - MODULUS->limb[(i)]; | - | ||||||||||||
106 | a->limb[(i)] = scarry & (((1)<<28)-1); | - | ||||||||||||
107 | scarry >>= 28; | - | ||||||||||||
108 | } executed 54304 times by 2 tests: end of block Executed by:
| 54304 | ||||||||||||
109 | - | |||||||||||||
110 | - | |||||||||||||
111 | - | |||||||||||||
112 | - | |||||||||||||
113 | - | |||||||||||||
114 | - | |||||||||||||
115 | - | |||||||||||||
116 | ((void) (0)) | - | ||||||||||||
117 | ; | - | ||||||||||||
118 | - | |||||||||||||
119 | scarry_0 = (word_t)scarry; | - | ||||||||||||
120 | - | |||||||||||||
121 | - | |||||||||||||
122 | for (i = 0; i < (64/sizeof(word_t))
| 3394-54304 | ||||||||||||
123 | carry = | - | ||||||||||||
124 | carry + a->limb[(i)] + | - | ||||||||||||
125 | (scarry_0 & MODULUS->limb[(i)]); | - | ||||||||||||
126 | a->limb[(i)] = carry & (((1)<<28)-1); | - | ||||||||||||
127 | carry >>= 28; | - | ||||||||||||
128 | } executed 54304 times by 2 tests: end of block Executed by:
| 54304 | ||||||||||||
129 | - | |||||||||||||
130 | - | |||||||||||||
131 | ((void) (0)) | - | ||||||||||||
132 | ; | - | ||||||||||||
133 | } executed 3394 times by 2 tests: end of block Executed by:
| 3394 | ||||||||||||
134 | - | |||||||||||||
135 | - | |||||||||||||
136 | void gf_sub(gf d, const gf a, const gf b) | - | ||||||||||||
137 | { | - | ||||||||||||
138 | gf_sub_RAW(d, a, b); | - | ||||||||||||
139 | gf_bias(d, 2); | - | ||||||||||||
140 | gf_weak_reduce(d); | - | ||||||||||||
141 | } executed 13765 times by 2 tests: end of block Executed by:
| 13765 | ||||||||||||
142 | - | |||||||||||||
143 | - | |||||||||||||
144 | void gf_add(gf d, const gf a, const gf b) | - | ||||||||||||
145 | { | - | ||||||||||||
146 | gf_add_RAW(d, a, b); | - | ||||||||||||
147 | gf_weak_reduce(d); | - | ||||||||||||
148 | } executed 536 times by 2 tests: end of block Executed by:
| 536 | ||||||||||||
149 | - | |||||||||||||
150 | - | |||||||||||||
151 | mask_t gf_eq(const gf a, const gf b) | - | ||||||||||||
152 | { | - | ||||||||||||
153 | gf c; | - | ||||||||||||
154 | mask_t ret = 0; | - | ||||||||||||
155 | unsigned int i; | - | ||||||||||||
156 | - | |||||||||||||
157 | gf_sub(c, a, b); | - | ||||||||||||
158 | gf_strong_reduce(c); | - | ||||||||||||
159 | - | |||||||||||||
160 | for (i = 0; i < (64/sizeof(word_t))
| 2177-34832 | ||||||||||||
161 | ret |= c->limb[(i)]; executed 34832 times by 2 tests: ret |= c->limb[(i)]; Executed by:
| 34832 | ||||||||||||
162 | - | |||||||||||||
163 | return executed 2177 times by 2 tests: constant_time_is_zero_32(ret);return constant_time_is_zero_32(ret); Executed by:
executed 2177 times by 2 tests: return constant_time_is_zero_32(ret); Executed by:
| 2177 | ||||||||||||
164 | } | - | ||||||||||||
165 | - | |||||||||||||
166 | mask_t gf_isr(gf a, const gf x) | - | ||||||||||||
167 | { | - | ||||||||||||
168 | gf L0, L1, L2; | - | ||||||||||||
169 | - | |||||||||||||
170 | gf_sqr(L1, x); | - | ||||||||||||
171 | gf_mul(L2, x, L1); | - | ||||||||||||
172 | gf_sqr(L1, L2); | - | ||||||||||||
173 | gf_mul(L2, x, L1); | - | ||||||||||||
174 | gf_sqrn(L1, L2, 3); | - | ||||||||||||
175 | gf_mul(L0, L2, L1); | - | ||||||||||||
176 | gf_sqrn(L1, L0, 3); | - | ||||||||||||
177 | gf_mul(L0, L2, L1); | - | ||||||||||||
178 | gf_sqrn(L2, L0, 9); | - | ||||||||||||
179 | gf_mul(L1, L0, L2); | - | ||||||||||||
180 | gf_sqr(L0, L1); | - | ||||||||||||
181 | gf_mul(L2, x, L0); | - | ||||||||||||
182 | gf_sqrn(L0, L2, 18); | - | ||||||||||||
183 | gf_mul(L2, L1, L0); | - | ||||||||||||
184 | gf_sqrn(L0, L2, 37); | - | ||||||||||||
185 | gf_mul(L1, L2, L0); | - | ||||||||||||
186 | gf_sqrn(L0, L1, 37); | - | ||||||||||||
187 | gf_mul(L1, L2, L0); | - | ||||||||||||
188 | gf_sqrn(L0, L1, 111); | - | ||||||||||||
189 | gf_mul(L2, L1, L0); | - | ||||||||||||
190 | gf_sqr(L0, L2); | - | ||||||||||||
191 | gf_mul(L1, x, L0); | - | ||||||||||||
192 | gf_sqrn(L0, L1, 223); | - | ||||||||||||
193 | gf_mul(L1, L2, L0); | - | ||||||||||||
194 | gf_sqr(L2, L1); | - | ||||||||||||
195 | gf_mul(L0, L2, x); | - | ||||||||||||
196 | gf_copy(a, L1); | - | ||||||||||||
197 | return executed 1154 times by 2 tests: gf_eq(L0, ONE);return gf_eq(L0, ONE); Executed by:
executed 1154 times by 2 tests: return gf_eq(L0, ONE); Executed by:
| 1154 | ||||||||||||
198 | } | - | ||||||||||||
Switch to Source code | Preprocessed file |