OpenCoverage

bn_mpi.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/bn/bn_mpi.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 <stdio.h>-
11#include "internal/cryptlib.h"-
12#include "bn_lcl.h"-
13-
14int BN_bn2mpi(const BIGNUM *a, unsigned char *d)-
15{-
16 int bits;-
17 int num = 0;-
18 int ext = 0;-
19 long l;-
20-
21 bits = BN_num_bits(a);-
22 num = (bits + 7) / 8;-
23 if (bits > 0) {
bits > 0Description
TRUEevaluated 10 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
2-10
24 ext = ((bits & 0x07) == 0);-
25 }
executed 10 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
10
26 if (d == NULL)
d == ((void *)0)Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 6 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
6
27 return (num + 4 + ext);
executed 6 times by 1 test: return (num + 4 + ext);
Executed by:
  • libcrypto.so.1.1
6
28-
29 l = num + ext;-
30 d[0] = (unsigned char)(l >> 24) & 0xff;-
31 d[1] = (unsigned char)(l >> 16) & 0xff;-
32 d[2] = (unsigned char)(l >> 8) & 0xff;-
33 d[3] = (unsigned char)(l) & 0xff;-
34 if (ext)
extDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 5 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
1-5
35 d[4] = 0;
executed 1 time by 1 test: d[4] = 0;
Executed by:
  • libcrypto.so.1.1
1
36 num = BN_bn2bin(a, &(d[4 + ext]));-
37 if (a->neg)
a->negDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
2-4
38 d[4] |= 0x80;
executed 2 times by 1 test: d[4] |= 0x80;
Executed by:
  • libcrypto.so.1.1
2
39 return (num + 4 + ext);
executed 6 times by 1 test: return (num + 4 + ext);
Executed by:
  • libcrypto.so.1.1
6
40}-
41-
42BIGNUM *BN_mpi2bn(const unsigned char *d, int n, BIGNUM *ain)-
43{-
44 long len;-
45 int neg = 0;-
46 BIGNUM *a = NULL;-
47-
48 if (n < 4) {
n < 4Description
TRUEnever evaluated
FALSEevaluated 6 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-6
49 BNerr(BN_F_BN_MPI2BN, BN_R_INVALID_LENGTH);-
50 return NULL;
never executed: return ((void *)0) ;
0
51 }-
52 len = ((long)d[0] << 24) | ((long)d[1] << 16) | ((int)d[2] << 8) | (int)-
53 d[3];-
54 if ((len + 4) != n) {
(len + 4) != nDescription
TRUEnever evaluated
FALSEevaluated 6 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-6
55 BNerr(BN_F_BN_MPI2BN, BN_R_ENCODING_ERROR);-
56 return NULL;
never executed: return ((void *)0) ;
0
57 }-
58-
59 if (ain == NULL)
ain == ((void *)0)Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-6
60 a = BN_new();
executed 6 times by 1 test: a = BN_new();
Executed by:
  • libcrypto.so.1.1
6
61 else-
62 a = ain;
never executed: a = ain;
0
63-
64 if (a == NULL)
a == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 6 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-6
65 return NULL;
never executed: return ((void *)0) ;
0
66-
67 if (len == 0) {
len == 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 5 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
1-5
68 a->neg = 0;-
69 a->top = 0;-
70 return a;
executed 1 time by 1 test: return a;
Executed by:
  • libcrypto.so.1.1
1
71 }-
72 d += 4;-
73 if ((*d) & 0x80)
(*d) & 0x80Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 3 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
2-3
74 neg = 1;
executed 2 times by 1 test: neg = 1;
Executed by:
  • libcrypto.so.1.1
2
75 if (BN_bin2bn(d, (int)len, a) == NULL) {
BN_bin2bn(d, (...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 5 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-5
76 if (ain == NULL)
ain == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
77 BN_free(a);
never executed: BN_free(a);
0
78 return NULL;
never executed: return ((void *)0) ;
0
79 }-
80 a->neg = neg;-
81 if (neg) {
negDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 3 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
2-3
82 BN_clear_bit(a, BN_num_bits(a) - 1);-
83 }
executed 2 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
2
84 bn_check_top(a);-
85 return a;
executed 5 times by 1 test: return a;
Executed by:
  • libcrypto.so.1.1
5
86}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.2