Merge pull request #358 from fperrad/20191006_lint some linting
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
diff --git a/bn_mp_from_sbin.c b/bn_mp_from_sbin.c
index 780639a..20e4597 100644
--- a/bn_mp_from_sbin.c
+++ b/bn_mp_from_sbin.c
@@ -4,17 +4,17 @@
/* SPDX-License-Identifier: Unlicense */
/* read signed bin, big endian, first byte is 0==positive or 1==negative */
-mp_err mp_from_sbin(mp_int *a, const unsigned char *b, size_t c)
+mp_err mp_from_sbin(mp_int *a, const unsigned char *buf, size_t size)
{
mp_err err;
/* read magnitude */
- if ((err = mp_from_ubin(a, b + 1, c - 1u)) != MP_OKAY) {
+ if ((err = mp_from_ubin(a, buf + 1, size - 1u)) != MP_OKAY) {
return err;
}
/* first byte is 0 for positive, non-zero for negative */
- if (b[0] == (unsigned char)0) {
+ if (buf[0] == (unsigned char)0) {
a->sign = MP_ZPOS;
} else {
a->sign = MP_NEG;
diff --git a/bn_mp_from_ubin.c b/bn_mp_from_ubin.c
index 78a4cf1..7f73cbc 100644
--- a/bn_mp_from_ubin.c
+++ b/bn_mp_from_ubin.c
@@ -4,7 +4,7 @@
/* SPDX-License-Identifier: Unlicense */
/* reads a unsigned char array, assumes the msb is stored first [big endian] */
-mp_err mp_from_ubin(mp_int *a, const unsigned char *b, size_t size)
+mp_err mp_from_ubin(mp_int *a, const unsigned char *buf, size_t size)
{
mp_err err;
@@ -25,11 +25,11 @@ mp_err mp_from_ubin(mp_int *a, const unsigned char *b, size_t size)
}
#ifndef MP_8BIT
- a->dp[0] |= *b++;
+ a->dp[0] |= *buf++;
a->used += 1;
#else
- a->dp[0] = (*b & MP_MASK);
- a->dp[1] |= ((*b++ >> 7) & 1u);
+ a->dp[0] = (*buf & MP_MASK);
+ a->dp[1] |= ((*buf++ >> 7) & 1u);
a->used += 2;
#endif
}
diff --git a/bn_mp_to_sbin.c b/bn_mp_to_sbin.c
index b736f98..e28dcce 100644
--- a/bn_mp_to_sbin.c
+++ b/bn_mp_to_sbin.c
@@ -4,20 +4,20 @@
/* SPDX-License-Identifier: Unlicense */
/* store in signed [big endian] format */
-mp_err mp_to_sbin(const mp_int *a, unsigned char *b, size_t maxlen, size_t *written)
+mp_err mp_to_sbin(const mp_int *a, unsigned char *buf, size_t maxlen, size_t *written)
{
mp_err err;
if (maxlen == 0u) {
return MP_VAL;
}
- if ((err = mp_to_ubin(a, b + 1, maxlen - 1u, written)) != MP_OKAY) {
+ if ((err = mp_to_ubin(a, buf + 1, maxlen - 1u, written)) != MP_OKAY) {
return err;
}
if (written != NULL) {
(*written)++;
}
- b[0] = (a->sign == MP_ZPOS) ? (unsigned char)0 : (unsigned char)1;
+ buf[0] = (a->sign == MP_ZPOS) ? (unsigned char)0 : (unsigned char)1;
return MP_OKAY;
}
#endif
diff --git a/bn_mp_to_ubin.c b/bn_mp_to_ubin.c
index 80c14ab..d359986 100644
--- a/bn_mp_to_ubin.c
+++ b/bn_mp_to_ubin.c
@@ -4,13 +4,13 @@
/* SPDX-License-Identifier: Unlicense */
/* store in unsigned [big endian] format */
-mp_err mp_to_ubin(const mp_int *a, unsigned char *b, size_t maxlen, size_t *written)
+mp_err mp_to_ubin(const mp_int *a, unsigned char *buf, size_t maxlen, size_t *written)
{
size_t x;
mp_err err;
mp_int t;
- if (b == NULL) {
+ if (buf == NULL) {
return MP_MEM;
}
@@ -26,20 +26,19 @@ mp_err mp_to_ubin(const mp_int *a, unsigned char *b, size_t maxlen, size_t *writ
while (!MP_IS_ZERO(&t)) {
if (maxlen == 0u) {
err = MP_VAL;
- break;
+ goto LBL_ERR;
}
maxlen--;
#ifndef MP_8BIT
- b[x++] = (unsigned char)(t.dp[0] & 255u);
+ buf[x++] = (unsigned char)(t.dp[0] & 255u);
#else
- b[x++] = (unsigned char)(t.dp[0] | ((t.dp[1] & 1u) << 7));
+ buf[x++] = (unsigned char)(t.dp[0] | ((t.dp[1] & 1u) << 7));
#endif
if ((err = mp_div_2d(&t, 8, &t, NULL)) != MP_OKAY) {
goto LBL_ERR;
}
}
- s_mp_reverse(b, x);
- err = MP_OKAY;
+ s_mp_reverse(buf, x);
if (written != NULL) {
*written = x;
diff --git a/bn_mp_ubin_size.c b/bn_mp_ubin_size.c
index f32e190..21230b4 100644
--- a/bn_mp_ubin_size.c
+++ b/bn_mp_ubin_size.c
@@ -6,8 +6,7 @@
/* get the size for an unsigned equivalent */
size_t mp_ubin_size(const mp_int *a)
{
- int size = mp_count_bits(a);
- size = (size / 8) + ((((unsigned)size & 7u) != 0u) ? 1 : 0);
- return (size_t)size;
+ size_t size = (size_t)mp_count_bits(a);
+ return (size / 8u) + (((size & 7u) != 0u) ? 1u : 0u);
}
#endif
diff --git a/bn_s_mp_reverse.c b/bn_s_mp_reverse.c
index 623d51e..c549e60 100644
--- a/bn_s_mp_reverse.c
+++ b/bn_s_mp_reverse.c
@@ -9,8 +9,8 @@ void s_mp_reverse(unsigned char *s, size_t len)
size_t ix, iy;
unsigned char t;
- ix = 0;
- iy = len - 1;
+ ix = 0u;
+ iy = len - 1u;
while (ix < iy) {
t = s[ix];
s[ix] = s[iy];