| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/bn/bn_shift.c |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 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 | - | |||||||||||||
| 13 | int 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) {
| 515226-1968061 | ||||||||||||
| 22 | r->neg = a->neg; | - | ||||||||||||
| 23 | if (bn_wexpand(r, a->top + 1) == NULL)
| 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 blockExecuted by:
| 515226 | ||||||||||||
| 27 | if (bn_wexpand(r, a->top + 1) == NULL)
| 0-1968061 | ||||||||||||
| 28 | return 0; never executed: return 0; | 0 | ||||||||||||
| 29 | } executed 1968061 times by 2 tests: end of blockExecuted by:
| 1968061 | ||||||||||||
| 30 | ap = a->d; | - | ||||||||||||
| 31 | rp = r->d; | - | ||||||||||||
| 32 | c = 0; | - | ||||||||||||
| 33 | for (i = 0; i < a->top; i++) {
| 2483287-14493324 | ||||||||||||
| 34 | t = *(ap++); | - | ||||||||||||
| 35 | *(rp++) = ((t << 1) | c) & BN_MASK2; | - | ||||||||||||
| 36 | c = (t & BN_TBIT) ? 1 : 0;
| 6873524-7619800 | ||||||||||||
| 37 | } executed 14493324 times by 2 tests: end of blockExecuted by:
| 14493324 | ||||||||||||
| 38 | if (c) {
| 795961-1687326 | ||||||||||||
| 39 | *rp = 1; | - | ||||||||||||
| 40 | r->top++; | - | ||||||||||||
| 41 | } executed 795961 times by 2 tests: end of blockExecuted by:
| 795961 | ||||||||||||
| 42 | bn_check_top(r); | - | ||||||||||||
| 43 | return 1; executed 2483287 times by 2 tests: return 1;Executed by:
| 2483287 | ||||||||||||
| 44 | } | - | ||||||||||||
| 45 | - | |||||||||||||
| 46 | int 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)) {
| 27-5356044 | ||||||||||||
| 55 | BN_zero(r); | - | ||||||||||||
| 56 | return 1; executed 27 times by 1 test: return 1;Executed by:
| 27 | ||||||||||||
| 57 | } | - | ||||||||||||
| 58 | i = a->top; | - | ||||||||||||
| 59 | ap = a->d; | - | ||||||||||||
| 60 | j = i - (ap[i - 1] == 1); | - | ||||||||||||
| 61 | if (a != r) {
| 56338-5299706 | ||||||||||||
| 62 | if (bn_wexpand(r, j) == NULL)
| 0-56338 | ||||||||||||
| 63 | return 0; never executed: return 0; | 0 | ||||||||||||
| 64 | r->neg = a->neg; | - | ||||||||||||
| 65 | } executed 56338 times by 2 tests: end of blockExecuted by:
| 56338 | ||||||||||||
| 66 | rp = r->d; | - | ||||||||||||
| 67 | t = ap[--i]; | - | ||||||||||||
| 68 | c = (t & 1) ? BN_TBIT : 0;
| 2119695-3236349 | ||||||||||||
| 69 | if (t >>= 1)
| 1839120-3516924 | ||||||||||||
| 70 | rp[i] = t; executed 3516924 times by 2 tests: rp[i] = t;Executed by:
| 3516924 | ||||||||||||
| 71 | while (i > 0) {
| 5356044-10396202 | ||||||||||||
| 72 | t = ap[--i]; | - | ||||||||||||
| 73 | rp[i] = ((t >> 1) & BN_MASK2) | c; | - | ||||||||||||
| 74 | c = (t & 1) ? BN_TBIT : 0;
| 2358710-8037492 | ||||||||||||
| 75 | } executed 10396202 times by 2 tests: end of blockExecuted by:
| 10396202 | ||||||||||||
| 76 | r->top = j; | - | ||||||||||||
| 77 | if (!r->top)
| 7-5356037 | ||||||||||||
| 78 | r->neg = 0; /* don't allow negative zero */ executed 7 times by 1 test: r->neg = 0;Executed by:
| 7 | ||||||||||||
| 79 | bn_check_top(r); | - | ||||||||||||
| 80 | return 1; executed 5356044 times by 2 tests: return 1;Executed by:
| 5356044 | ||||||||||||
| 81 | } | - | ||||||||||||
| 82 | - | |||||||||||||
| 83 | int 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) {
| 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)
| 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)
| 653604-14139842 | ||||||||||||
| 107 | for (i = a->top - 1; i >= 0; i--)
| 653604-5503450 | ||||||||||||
| 108 | t[nw + i] = f[i]; executed 5503450 times by 2 tests: t[nw + i] = f[i];Executed by:
| 5503450 | ||||||||||||
| 109 | else | - | ||||||||||||
| 110 | for (i = a->top - 1; i >= 0; i--) {
| 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 blockExecuted by:
| 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:
| 14793446 | ||||||||||||
| 120 | } | - | ||||||||||||
| 121 | - | |||||||||||||
| 122 | int 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) {
| 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) {
| 0-11924943 | ||||||||||||
| 140 | BN_zero(r); | - | ||||||||||||
| 141 | return 1; executed 33371 times by 1 test: return 1;Executed by:
| 33371 | ||||||||||||
| 142 | } | - | ||||||||||||
| 143 | i = (BN_num_bits(a) - n + (BN_BITS2 - 1)) / BN_BITS2; | - | ||||||||||||
| 144 | if (r != a) {
| 4840297-7084646 | ||||||||||||
| 145 | if (bn_wexpand(r, i) == NULL)
| 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 blockExecuted by:
| 7084646 | ||||||||||||
| 149 | if (n == 0)
| 70216-4770081 | ||||||||||||
| 150 | return 1; /* or the copying loop will go berserk */ executed 70216 times by 1 test: return 1;Executed by:
| 70216 | ||||||||||||
| 151 | } executed 4770081 times by 2 tests: end of blockExecuted by:
| 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) {
| 340750-11513977 | ||||||||||||
| 159 | for (i = j; i != 0; i--)
| 340750-3128235 | ||||||||||||
| 160 | *(t++) = *(f++); executed 3128235 times by 2 tests: *(t++) = *(f++);Executed by:
| 3128235 | ||||||||||||
| 161 | } else { executed 340750 times by 2 tests: end of blockExecuted by:
| 340750 | ||||||||||||
| 162 | l = *(f++); | - | ||||||||||||
| 163 | for (i = j - 1; i != 0; i--) {
| 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 blockExecuted by:
| 48326049 | ||||||||||||
| 168 | if ((l = (l >> rb) & BN_MASK2))
| 169035-11344942 | ||||||||||||
| 169 | *(t) = l; executed 11344942 times by 2 tests: *(t) = l;Executed by:
| 11344942 | ||||||||||||
| 170 | } executed 11513977 times by 2 tests: end of blockExecuted by:
| 11513977 | ||||||||||||
| 171 | if (!r->top)
| 464-11854263 | ||||||||||||
| 172 | r->neg = 0; /* don't allow negative zero */ executed 464 times by 1 test: r->neg = 0;Executed by:
| 464 | ||||||||||||
| 173 | bn_check_top(r); | - | ||||||||||||
| 174 | return 1; executed 11854727 times by 2 tests: return 1;Executed by:
| 11854727 | ||||||||||||
| 175 | } | - | ||||||||||||
| Source code | Switch to Preprocessed file |