OpenCoverage

bn_shift.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/bn/bn_shift.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/*-
2 * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.-
3 *-
4 * Licensed under the OpenSSL license (the "License"). You may not use-
5 * this file except in compliance with the License. You can obtain a copy-
6 * in the file LICENSE in the source distribution or at-
7 * https://www.openssl.org/source/license.html-
8 */-
9-
10#include "internal/cryptlib.h"-
11#include "bn_lcl.h"-
12-
13int BN_lshift1(BIGNUM *r, const BIGNUM *a)-
14{-
15 register BN_ULONG *ap, *rp, t, c;-
16 int i;-
17-
18 bn_check_top(r);-
19 bn_check_top(a);-
20-
21 if (r != a) {
r != aDescription
TRUEevaluated 515226 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 1968061 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
515226-1968061
22 r->neg = a->neg;-
23 if (bn_wexpand(r, a->top + 1) == NULL)
bn_wexpand(r, ...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 515226 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
0-515226
24 return 0;
never executed: return 0;
0
25 r->top = a->top;-
26 } else {
executed 515226 times by 2 tests: end of block
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
515226
27 if (bn_wexpand(r, a->top + 1) == NULL)
bn_wexpand(r, ...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 1968061 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
0-1968061
28 return 0;
never executed: return 0;
0
29 }
executed 1968061 times by 2 tests: end of block
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
1968061
30 ap = a->d;-
31 rp = r->d;-
32 c = 0;-
33 for (i = 0; i < a->top; i++) {
i < a->topDescription
TRUEevaluated 14493324 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 2483287 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
2483287-14493324
34 t = *(ap++);-
35 *(rp++) = ((t << 1) | c) & BN_MASK2;-
36 c = (t & BN_TBIT) ? 1 : 0;
(t & ((unsigne...(8 * 8) - 1)))Description
TRUEevaluated 6873524 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 7619800 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
6873524-7619800
37 }
executed 14493324 times by 2 tests: end of block
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
14493324
38 if (c) {
cDescription
TRUEevaluated 795961 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 1687326 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
795961-1687326
39 *rp = 1;-
40 r->top++;-
41 }
executed 795961 times by 2 tests: end of block
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
795961
42 bn_check_top(r);-
43 return 1;
executed 2483287 times by 2 tests: return 1;
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
2483287
44}-
45-
46int BN_rshift1(BIGNUM *r, const BIGNUM *a)-
47{-
48 BN_ULONG *ap, *rp, t, c;-
49 int i, j;-
50-
51 bn_check_top(r);-
52 bn_check_top(a);-
53-
54 if (BN_is_zero(a)) {
BN_is_zero(a)Description
TRUEevaluated 27 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 5356044 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
27-5356044
55 BN_zero(r);-
56 return 1;
executed 27 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
27
57 }-
58 i = a->top;-
59 ap = a->d;-
60 j = i - (ap[i - 1] == 1);-
61 if (a != r) {
a != rDescription
TRUEevaluated 56338 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 5299706 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
56338-5299706
62 if (bn_wexpand(r, j) == NULL)
bn_wexpand(r, ...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 56338 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
0-56338
63 return 0;
never executed: return 0;
0
64 r->neg = a->neg;-
65 }
executed 56338 times by 2 tests: end of block
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
56338
66 rp = r->d;-
67 t = ap[--i];-
68 c = (t & 1) ? BN_TBIT : 0;
(t & 1)Description
TRUEevaluated 3236349 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 2119695 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
2119695-3236349
69 if (t >>= 1)
t >>= 1Description
TRUEevaluated 3516924 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 1839120 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
1839120-3516924
70 rp[i] = t;
executed 3516924 times by 2 tests: rp[i] = t;
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
3516924
71 while (i > 0) {
i > 0Description
TRUEevaluated 10396202 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 5356044 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
5356044-10396202
72 t = ap[--i];-
73 rp[i] = ((t >> 1) & BN_MASK2) | c;-
74 c = (t & 1) ? BN_TBIT : 0;
(t & 1)Description
TRUEevaluated 2358710 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 8037492 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
2358710-8037492
75 }
executed 10396202 times by 2 tests: end of block
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
10396202
76 r->top = j;-
77 if (!r->top)
!r->topDescription
TRUEevaluated 7 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 5356037 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
7-5356037
78 r->neg = 0; /* don't allow negative zero */
executed 7 times by 1 test: r->neg = 0;
Executed by:
  • libcrypto.so.1.1
7
79 bn_check_top(r);-
80 return 1;
executed 5356044 times by 2 tests: return 1;
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
5356044
81}-
82-
83int BN_lshift(BIGNUM *r, const BIGNUM *a, int n)-
84{-
85 int i, nw, lb, rb;-
86 BN_ULONG *t, *f;-
87 BN_ULONG l;-
88-
89 bn_check_top(r);-
90 bn_check_top(a);-
91-
92 if (n < 0) {
n < 0Description
TRUEnever evaluated
FALSEevaluated 14793446 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
0-14793446
93 BNerr(BN_F_BN_LSHIFT, BN_R_INVALID_SHIFT);-
94 return 0;
never executed: return 0;
0
95 }-
96-
97 nw = n / BN_BITS2;-
98 if (bn_wexpand(r, a->top + nw + 1) == NULL)
bn_wexpand(r, ...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 14793446 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
0-14793446
99 return 0;
never executed: return 0;
0
100 r->neg = a->neg;-
101 lb = n % BN_BITS2;-
102 rb = BN_BITS2 - lb;-
103 f = a->d;-
104 t = r->d;-
105 t[a->top + nw] = 0;-
106 if (lb == 0)
lb == 0Description
TRUEevaluated 653604 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 14139842 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
653604-14139842
107 for (i = a->top - 1; i >= 0; i--)
i >= 0Description
TRUEevaluated 5503450 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 653604 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
653604-5503450
108 t[nw + i] = f[i];
executed 5503450 times by 2 tests: t[nw + i] = f[i];
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
5503450
109 else-
110 for (i = a->top - 1; i >= 0; i--) {
i >= 0Description
TRUEevaluated 122548139 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 14139842 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
14139842-122548139
111 l = f[i];-
112 t[nw + i + 1] |= (l >> rb) & BN_MASK2;-
113 t[nw + i] = (l << lb) & BN_MASK2;-
114 }
executed 122548139 times by 2 tests: end of block
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
122548139
115 memset(t, 0, sizeof(*t) * nw);-
116 r->top = a->top + nw + 1;-
117 bn_correct_top(r);-
118 bn_check_top(r);-
119 return 1;
executed 14793446 times by 2 tests: return 1;
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
14793446
120}-
121-
122int BN_rshift(BIGNUM *r, const BIGNUM *a, int n)-
123{-
124 int i, j, nw, lb, rb;-
125 BN_ULONG *t, *f;-
126 BN_ULONG l, tmp;-
127-
128 bn_check_top(r);-
129 bn_check_top(a);-
130-
131 if (n < 0) {
n < 0Description
TRUEnever evaluated
FALSEevaluated 11958314 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
0-11958314
132 BNerr(BN_F_BN_RSHIFT, BN_R_INVALID_SHIFT);-
133 return 0;
never executed: return 0;
0
134 }-
135-
136 nw = n / BN_BITS2;-
137 rb = n % BN_BITS2;-
138 lb = BN_BITS2 - rb;-
139 if (nw >= a->top || a->top == 0) {
nw >= a->topDescription
TRUEevaluated 33371 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 11924943 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
a->top == 0Description
TRUEnever evaluated
FALSEevaluated 11924943 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
0-11924943
140 BN_zero(r);-
141 return 1;
executed 33371 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
33371
142 }-
143 i = (BN_num_bits(a) - n + (BN_BITS2 - 1)) / BN_BITS2;-
144 if (r != a) {
r != aDescription
TRUEevaluated 7084646 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 4840297 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
4840297-7084646
145 if (bn_wexpand(r, i) == NULL)
bn_wexpand(r, ...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 7084646 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
0-7084646
146 return 0;
never executed: return 0;
0
147 r->neg = a->neg;-
148 } else {
executed 7084646 times by 2 tests: end of block
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
7084646
149 if (n == 0)
n == 0Description
TRUEevaluated 70216 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 4770081 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
70216-4770081
150 return 1; /* or the copying loop will go berserk */
executed 70216 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
70216
151 }
executed 4770081 times by 2 tests: end of block
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
4770081
152-
153 f = &(a->d[nw]);-
154 t = r->d;-
155 j = a->top - nw;-
156 r->top = i;-
157-
158 if (rb == 0) {
rb == 0Description
TRUEevaluated 340750 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 11513977 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
340750-11513977
159 for (i = j; i != 0; i--)
i != 0Description
TRUEevaluated 3128235 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 340750 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
340750-3128235
160 *(t++) = *(f++);
executed 3128235 times by 2 tests: *(t++) = *(f++);
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
3128235
161 } else {
executed 340750 times by 2 tests: end of block
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
340750
162 l = *(f++);-
163 for (i = j - 1; i != 0; i--) {
i != 0Description
TRUEevaluated 48326049 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 11513977 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
11513977-48326049
164 tmp = (l >> rb) & BN_MASK2;-
165 l = *(f++);-
166 *(t++) = (tmp | (l << lb)) & BN_MASK2;-
167 }
executed 48326049 times by 2 tests: end of block
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
48326049
168 if ((l = (l >> rb) & BN_MASK2))
(l = (l >> rb)...fffffffffffL))Description
TRUEevaluated 11344942 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 169035 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
169035-11344942
169 *(t) = l;
executed 11344942 times by 2 tests: *(t) = l;
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
11344942
170 }
executed 11513977 times by 2 tests: end of block
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
11513977
171 if (!r->top)
!r->topDescription
TRUEevaluated 464 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 11854263 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
464-11854263
172 r->neg = 0; /* don't allow negative zero */
executed 464 times by 1 test: r->neg = 0;
Executed by:
  • libcrypto.so.1.1
464
173 bn_check_top(r);-
174 return 1;
executed 11854727 times by 2 tests: return 1;
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
11854727
175}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.2