1
1
/*
2
- * Copyright (c) 2017-2018 Ribose Inc.
2
+ * Copyright (c) 2017-2021 Ribose Inc.
3
3
* Copyright (c) 2012 Alistair Crooks <agc@NetBSD.org>
4
4
* All rights reserved.
5
5
*
27
27
#include " bn.h"
28
28
#include < botan/ffi.h>
29
29
#include < stdlib.h>
30
+ #include < assert.h>
30
31
#include " utils.h"
31
32
32
- /* *************************************************************************/
33
-
34
33
/* essentiually, these are just wrappers around the botan functions */
35
34
/* usually the order of args changes */
36
35
/* the bignum_t API tends to have more const poisoning */
39
38
bignum_t *
40
39
bn_bin2bn (const uint8_t *data, int len, bignum_t *ret)
41
40
{
42
- if (data == NULL ) {
43
- return bn_new ();
41
+ assert (data);
42
+ if (!data) {
43
+ RNP_LOG (" NULL data." );
44
+ return NULL ;
44
45
}
45
- if (ret == NULL ) {
46
+ if (! ret) {
46
47
ret = bn_new ();
47
48
}
48
-
49
- if (ret == NULL ) {
49
+ if (!ret) {
50
50
return NULL ;
51
51
}
52
-
53
- return (botan_mp_from_bin (ret->mp , data, len) == 0 ) ? ret : NULL ;
52
+ return !botan_mp_from_bin (ret->mp , data, len) ? ret : NULL ;
54
53
}
55
54
56
55
/* store in unsigned [big endian] format */
57
56
int
58
57
bn_bn2bin (const bignum_t *a, unsigned char *b)
59
58
{
60
- if (a == NULL || b == NULL ) {
59
+ if (!a || !b ) {
61
60
return -1 ;
62
61
}
63
-
64
62
return botan_mp_to_bin (a->mp , b);
65
63
}
66
64
67
65
bignum_t *
68
66
bn_new (void )
69
67
{
70
- bignum_t *a;
71
-
72
- a = (bignum_t *) calloc (1 , sizeof (*a));
73
- if (a == NULL ) {
68
+ bignum_t *a = (bignum_t *) calloc (1 , sizeof (*a));
69
+ if (!a) {
74
70
return NULL ;
75
71
}
76
72
botan_mp_init (&a->mp );
@@ -80,7 +76,7 @@ bn_new(void)
80
76
void
81
77
bn_free (bignum_t *a)
82
78
{
83
- if (a != NULL ) {
79
+ if (a) {
84
80
botan_mp_destroy (a->mp );
85
81
free (a);
86
82
}
@@ -89,10 +85,7 @@ bn_free(bignum_t *a)
89
85
bool
90
86
bn_num_bits (const bignum_t *a, size_t *bits)
91
87
{
92
- if (!a || botan_mp_num_bits (a->mp , bits)) {
93
- return false ;
94
- }
95
- return true ;
88
+ return a && !botan_mp_num_bits (a->mp , bits);
96
89
}
97
90
98
91
bool
0 commit comments