code
stringlengths
14
2.05k
label
int64
0
1
programming_language
stringclasses
7 values
cwe_id
stringlengths
6
14
cwe_name
stringlengths
5
98
description
stringlengths
36
379
url
stringlengths
36
48
label_name
stringclasses
2 values
size_t bn_ham(const bn_t a) { int c = 0; for (int i = 0; i < bn_bits(a); i++) { c += bn_get_bit(a, i); } return c; }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void bn_rand(bn_t a, int sign, size_t bits) { int digits; RLC_RIP(bits, digits, bits); digits += (bits > 0 ? 1 : 0); bn_grow(a, digits); rand_bytes((uint8_t *)a->dp, digits * sizeof(dig_t)); a->used = digits; a->sign = sign; if (bits > 0) { dig_t mask = ((dig_t)1 << (dig_t)bits) - 1; a->dp[a->used - 1] &= mask; } bn_trim(a); }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void bn_write_str(char *str, size_t len, const bn_t a, unsigned int radix) { bn_t t; dig_t d; int digits, l, i, j; char c; bn_null(t); l = bn_size_str(a, radix); if (len < l) { RLC_THROW(ERR_NO_BUFFER); return; } if (radix < 2 || radix > 64) { RLC_THROW(ERR_NO_VALID); return; } if (bn_is_zero(a) == 1) { *str++ = '0'; *str = '\0'; return; } RLC_TRY { bn_new(t); bn_copy(t, a); j = 0; if (t->sign == RLC_NEG) { str[j] = '-'; j++; t->sign = RLC_POS; } digits = 0; while (!bn_is_zero(t) && j < len) { bn_div_rem_dig(t, &d, t, (dig_t)radix); str[j] = util_conv_char(d); digits++; j++; } /* Reverse the digits of the string. */ i = 0; if (str[0] == '-') { i = 1; } j = l - 2; while (i < j) { c = str[i]; str[i] = str[j]; str[j] = c; ++i; --j; } str[l - 1] = '\0'; } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { bn_free(t); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void bn_read_bin(bn_t a, const uint8_t *bin, size_t len) { int i, j; dig_t d = (RLC_DIG / 8); int digs = (len % d == 0 ? len / d : len / d + 1); bn_grow(a, digs); bn_zero(a); a->used = digs; for (i = 0; i < digs - 1; i++) { d = 0; for (j = (RLC_DIG / 8) - 1; j >= 0; j--) { d = d << 8; d |= bin[len - 1 - (i * (RLC_DIG / 8) + j)]; } a->dp[i] = d; } d = 0; for (j = (RLC_DIG / 8) - 1; j >= 0; j--) { if ((int)(i * (RLC_DIG / 8) + j) < len) { d = d << 8; d |= bin[len - 1 - (i * (RLC_DIG / 8) + j)]; } } a->dp[i] = d; a->sign = RLC_POS; bn_trim(a); }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
size_t bn_size_bin(const bn_t a) { dig_t d; int digits; digits = (a->used - 1) * (RLC_DIG / 8); d = a->dp[a->used - 1]; while (d != 0) { d = d >> 8; digits++; } return digits; }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
int bn_get_bit(const bn_t a, size_t bit) { int d; if (bit < 0) { RLC_THROW(ERR_NO_VALID); return 0; } if (bit > bn_bits(a)) { return 0; } RLC_RIP(bit, d, bit); if (d >= a->used) { return 0; } else { return (a->dp[d] >> bit) & (dig_t)1; } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void bn_write_bin(uint8_t *bin, size_t len, const bn_t a) { int size, k; dig_t d; size = bn_size_bin(a); if (len < size) { RLC_THROW(ERR_NO_BUFFER); return; } k = 0; for (int i = 0; i < a->used - 1; i++) { d = a->dp[i]; for (int j = 0; j < (int)(RLC_DIG / 8); j++) { bin[len - 1 - k++] = d & 0xFF; d = d >> 8; } } d = a->dp[a->used - 1]; while (d != 0) { bin[len - 1 - k++] = d & 0xFF; d = d >> 8; } while (k < len) { bin[len - 1 - k++] = 0; } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void bn_read_str(bn_t a, const char *str, size_t len, unsigned int radix) { int sign, i, j; char c; bn_zero(a); if (radix < 2 || radix > 64) { RLC_THROW(ERR_NO_VALID); return; } j = 0; if (str[0] == '-') { j++; sign = RLC_NEG; } else { sign = RLC_POS; } RLC_TRY { bn_grow(a, RLC_CEIL(len * util_bits_dig(radix), RLC_DIG)); while (j < len) { if (str[j] == 0) { break; } c = (char)((radix < 36) ? RLC_UPP(str[j]) : str[j]); for (i = 0; i < 64; i++) { if (c == util_conv_char(i)) { break; } } if (i < radix) { bn_mul_dig(a, a, (dig_t)radix); bn_add_dig(a, a, (dig_t)i); } else { break; } j++; } a->sign = sign; bn_trim(a); } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
int cp_bls_sig(g1_t s, const uint8_t *msg, size_t len, const bn_t d) { g1_t p; int result = RLC_OK; g1_null(p); RLC_TRY { g1_new(p); g1_map(p, msg, len); g1_mul_key(s, p, d); } RLC_CATCH_ANY { result = RLC_ERR; } RLC_FINALLY { g1_free(p); } return result; }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
int cp_cmlhs_sig(g1_t sig, g2_t z, g1_t a, g1_t c, g1_t r, g2_t s, const bn_t msg, const char *data, int label, const bn_t x, const g1_t h, const uint8_t prf[], size_t plen, const bn_t d, const bn_t sk, int bls) { bn_t k, m, n; g1_t t; uint8_t mac[RLC_MD_LEN]; size_t len, dlen = strlen(data); uint8_t *buf = RLC_ALLOCA(uint8_t, 1 + 8 * RLC_PC_BYTES + dlen); int result = RLC_OK; bn_null(k); bn_null(m); bn_null(n); g1_null(t); RLC_TRY { bn_new(k); bn_new(m); bn_new(n); g1_new(t); if (buf == NULL) { RLC_THROW(ERR_NO_MEMORY); } pc_get_ord(n); /* Generate r and s. */ bn_rand_mod(k, n); bn_rand_mod(m, n); /* Compute S = -g2^s, C = g1^s. */ g2_mul_gen(s, m); g2_neg(s, s); g1_mul_gen(c, m); /* Compute R = g1^(r - ys). */ bn_mul(m, d, m); bn_mod(m, m, n); bn_sub(m, k, m); bn_mod(m, m, n); g1_mul_gen(r, m); /* Compute A = g1^(x + r) * \prod H_j^(y * m_j). */ bn_add(k, x, k); bn_mod(k, k, n); g1_mul_gen(a, k); bn_mul(k, d, msg); bn_mod(k, k, n); g1_mul(t, h, k); g1_add(a, a, t); g1_norm(a, a); /* Compute z = F_K(delta), Z = g2^z, A = A^(1/z). */ md_hmac(mac, (const uint8_t *)data, dlen, prf, plen); bn_read_bin(k, mac, RLC_MD_LEN); bn_mod(k, k, n); g2_mul_gen(z, k); bn_mod_inv(k, k, n); g1_mul(a, a, k); /* Compute C = C * sum H_j^m_j. */ bn_mod(k, msg, n); g1_mul(t, h, k); g1_add(c, c, t); g1_norm(c, c); len = g2_size_bin(z, 0); g2_write_bin(buf, len, z, 0); memcpy(buf + len, data, dlen); if (bls) { cp_bls_sig(sig, buf, len + dlen, sk); } else { cp_ecdsa_sig(m, n, buf, len + dlen, 0, sk); fp_prime_conv(sig->x, m); fp_prime_conv(sig->y, n); fp_set_dig(sig->z, 1); } } RLC_CATCH_ANY { result = RLC_ERR; } RLC_FINALLY { bn_free(k); bn_free(m); bn_free(n); g1_free(t); RLC_FREE(buf); } return result; }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
int cp_cmlhs_ver(const g1_t r, const g2_t s, const g1_t sig[], const g2_t z[], const g1_t a[], const g1_t c[], const bn_t msg, const char *data, const g1_t h, const int label[], const gt_t *hs[], const dig_t *f[], const size_t flen[], const g2_t y[], const g2_t pk[], size_t slen, int bls) { g1_t g1; g2_t g2; gt_t e, u, v; bn_t k, n; size_t len, dlen = strlen(data); uint8_t *buf = RLC_ALLOCA(uint8_t, 1 + 8 * RLC_PC_BYTES + dlen); int result = 1; g1_null(g1); g2_null(g2); gt_null(e); gt_null(u); gt_null(v); bn_null(k); bn_null(n); RLC_TRY { g1_new(g1); g2_new(g2); gt_new(e); gt_new(u); gt_new(v); bn_new(k); bn_new(n); if (buf == NULL) { RLC_THROW(ERR_NO_MEMORY); } for (int i = 0; i < slen; i++) { len = g2_size_bin(z[i], 0); g2_write_bin(buf, len, z[i], 0); memcpy(buf + len, data, dlen); if (bls) { result &= cp_bls_ver(sig[i], buf, len + dlen, pk[i]); } else { fp_prime_back(k, sig[i]->x); fp_prime_back(n, sig[i]->y); fp_copy(g1->x, pk[i]->x[0]); fp_copy(g1->y, pk[i]->y[0]); fp_set_dig(g1->z, 1); result &= cp_ecdsa_ver(k, n, buf, len + dlen, 0, g1); } } pc_get_ord(n); g1_get_gen(g1); g2_get_gen(g2); pc_map_sim(e, a, z, slen); pc_map_sim(u, c, y, slen); pc_map(v, r, g2); gt_mul(u, u, v); for (int i = 0; i < slen; i++) { for (int j = 0; j < flen[i]; j++) { gt_exp_dig(v, hs[i][label[j]], f[i][j]); gt_mul(u, u, v); } } if (gt_cmp(e, u) != RLC_EQ) { result = 0; } pc_map(e, g1, s); g1_set_infty(g1); for (int i = 0; i < slen; i++) { g1_add(g1, g1, c[i]); } g1_norm(g1, g1); pc_map(u, g1, g2); gt_mul(e, e, u); g1_mul(g1, h, msg); pc_map(v, g1, g2); if (gt_cmp(e, v) != RLC_EQ) { result = 0; } } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { g1_free(g1); g2_free(g2); gt_free(e); gt_free(u); gt_free(v); bn_free(k); bn_free(n); RLC_FREE(buf); } return result; }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
int cp_cmlhs_gen(bn_t x[], gt_t hs[], size_t len, uint8_t prf[], size_t plen, bn_t sk, g2_t pk, bn_t d, g2_t y, int bls) { g1_t g1; g2_t g2; gt_t gt; bn_t n; int result = RLC_OK; g1_null(g1); g2_null(g2); gt_null(gt); bn_null(n); RLC_TRY { bn_new(n); g1_new(g1); g2_new(g2); gt_new(gt); pc_get_ord(n); g1_get_gen(g1); g2_get_gen(g2); pc_map(gt, g1, g2); rand_bytes(prf, plen); bn_rand_mod(d, n); g2_mul_gen(y, d); /* Generate elements for n tags. */ for (int i = 0; i < len; i++) { bn_rand_mod(x[i], n); gt_exp(hs[i], gt, x[i]); } if (bls) { result = cp_bls_gen(sk, pk); } else { if (cp_ecdsa_gen(sk, g1) == RLC_OK) { fp_copy(pk->x[0], g1->x); fp_copy(pk->y[0], g1->y); } else { result = RLC_ERR; } } } RLC_CATCH_ANY { result = RLC_ERR; } RLC_FINALLY { g1_free(g1); g2_free(g2); gt_free(gt); bn_free(n); } return result; }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
int cp_cmlhs_onv(const g1_t r, const g2_t s, const g1_t sig[], const g2_t z[], const g1_t a[], const g1_t c[], const bn_t msg, const char *data, const g1_t h, const gt_t vk, const g2_t y[], const g2_t pk[], size_t slen, int bls) { g1_t g1; g2_t g2; gt_t e, u, v; bn_t k, n; size_t len, dlen = strlen(data); uint8_t *buf = RLC_ALLOCA(uint8_t, 1 + 8 * RLC_FP_BYTES + dlen); int result = 1; g1_null(g1); g2_null(g2); gt_null(e); gt_null(u); gt_null(v); bn_null(k); bn_null(n); RLC_TRY { g1_new(g1); g2_new(g2); gt_new(e); gt_new(u); gt_new(v); bn_new(k); bn_new(n); if (buf == NULL) { RLC_THROW(ERR_NO_MEMORY); } for (int i = 0; i < slen; i++) { len = g2_size_bin(z[i], 0); g2_write_bin(buf, len, z[i], 0); memcpy(buf + len, data, dlen); if (bls) { result &= cp_bls_ver(sig[i], buf, len + dlen, pk[i]); } else { fp_prime_back(k, sig[i]->x); fp_prime_back(n, sig[i]->y); fp_copy(g1->x, pk[i]->x[0]); fp_copy(g1->y, pk[i]->y[0]); fp_set_dig(g1->z, 1); result &= cp_ecdsa_ver(k, n, buf, len + dlen, 0, g1); } } pc_get_ord(n); g1_get_gen(g1); g2_get_gen(g2); pc_map_sim(e, a, z, slen); pc_map_sim(u, c, y, slen); pc_map(v, r, g2); gt_mul(u, u, v); gt_mul(u, u, vk); if (gt_cmp(e, u) != RLC_EQ) { result = 0; } pc_map(e, g1, s); g1_set_infty(g1); for (int i = 0; i < slen; i++) { g1_add(g1, g1, c[i]); } g1_norm(g1, g1); pc_map(u, g1, g2); gt_mul(e, e, u); g1_mul(g1, h, msg); pc_map(v, g1, g2); if (gt_cmp(e, v) != RLC_EQ) { result = 0; } } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { g1_free(g1); g2_free(g2); gt_free(e); gt_free(u); gt_free(v); bn_free(k); bn_free(n); RLC_FREE(buf); } return result; }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
int cp_pbpsi_ask(g2_t d[], bn_t r, const bn_t x[], const g2_t s[], size_t m) { int i, result = RLC_OK; bn_t t, q, *p = RLC_ALLOCA(bn_t, m + 1), *_x = RLC_ALLOCA(bn_t, m + 1); bn_null(q); bn_null(t); RLC_TRY { bn_new(q); bn_new(t); if (p == NULL) { RLC_THROW(ERR_NO_MEMORY); } for (i = 0; i <= m; i++) { bn_null(p[i]); bn_new(p[i]); bn_null(_x[i]); bn_new(_x[i]); } pc_get_ord(q); bn_rand_mod(r, q); if (m == 0) { g2_mul_gen(d[0], r); } else { bn_lag(p, x, q, m); g2_mul_sim_lot(d[0], s, p, m + 1); g2_mul(d[0], d[0], r); for (i = 0; i < m; i++) { bn_copy(_x[i], x[i]); } for (i = 0; i < m; i++) { bn_copy(t, _x[i]); bn_copy(_x[i], _x[m - 1]); bn_lag(p, _x, q, m - 1); g2_mul_sim_lot(d[i + 1], s, p, m); g2_mul(d[i + 1], d[i + 1], r); bn_copy(_x[i], t); } } } RLC_CATCH_ANY { result = RLC_ERR; } RLC_FINALLY { bn_free(q); bn_free(t); for (i = 0; i <= m; i++) { bn_free(p[i]); bn_free(_x[i]); } RLC_FREE(p); RLC_FREE(_x); } return result; }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
int cp_rsa_gen(rsa_t pub, rsa_t prv, size_t bits) { bn_t t, r; int result = RLC_OK; if (pub == NULL || prv == NULL || bits == 0) { return RLC_ERR; } bn_null(t); bn_null(r); RLC_TRY { bn_new(t); bn_new(r); /* Generate different primes p and q. */ do { bn_gen_prime(prv->crt->p, bits / 2); bn_gen_prime(prv->crt->q, bits / 2); } while (bn_cmp(prv->crt->p, prv->crt->q) == RLC_EQ); /* Swap p and q so that p is smaller. */ if (bn_cmp(prv->crt->p, prv->crt->q) != RLC_LT) { bn_copy(t, prv->crt->p); bn_copy(prv->crt->p, prv->crt->q); bn_copy(prv->crt->q, t); } /* n = pq. */ bn_mul(pub->crt->n, prv->crt->p, prv->crt->q); bn_copy(prv->crt->n, pub->crt->n); bn_sub_dig(prv->crt->p, prv->crt->p, 1); bn_sub_dig(prv->crt->q, prv->crt->q, 1); /* phi(n) = (p - 1)(q - 1). */ bn_mul(t, prv->crt->p, prv->crt->q); bn_set_2b(pub->e, 16); bn_add_dig(pub->e, pub->e, 1); #if !defined(CP_CRT) /* d = e^(-1) mod phi(n). */ bn_gcd_ext(r, prv->d, NULL, pub->e, t); if (bn_sign(prv->d) == RLC_NEG) { bn_add(prv->d, prv->d, t); } if (bn_cmp_dig(r, 1) == RLC_EQ) { /* Restore p and q. */ bn_add_dig(prv->crt->p, prv->crt->p, 1); bn_add_dig(prv->crt->q, prv->crt->q, 1); result = RLC_OK; } #else /* d = e^(-1) mod phi(n). */ bn_gcd_ext(r, prv->d, NULL, pub->e, t); if (bn_sign(prv->d) == RLC_NEG) { bn_add(prv->d, prv->d, t); } if (bn_cmp_dig(r, 1) == RLC_EQ) { /* dP = d mod (p - 1). */ bn_mod(prv->crt->dp, prv->d, prv->crt->p); /* dQ = d mod (q - 1). */ bn_mod(prv->crt->dq, prv->d, prv->crt->q); /* Restore p and q. */ bn_add_dig(prv->crt->p, prv->crt->p, 1); bn_add_dig(prv->crt->q, prv->crt->q, 1); /* qInv = q^(-1) mod p. */ bn_mod_inv(prv->crt->qi, prv->crt->q, prv->crt->p); result = RLC_OK; } #endif /* CP_CRT */ } RLC_CATCH_ANY { result = RLC_ERR; } RLC_FINALLY { bn_free(t); bn_free(r); } return result; }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
int cp_sokaka_key(uint8_t *key, size_t key_len, const char *id1, const sokaka_t k, const char *id2) { size_t size, len1 = strlen(id1), len2 = strlen(id2); int first = 0, result = RLC_OK; uint8_t *buf; g1_t p; g2_t q; gt_t e; g1_null(p); g2_null(q); gt_null(e); RLC_TRY { g1_new(p); g2_new(q); gt_new(e); size = gt_size_bin(e, 0); buf = RLC_ALLOCA(uint8_t, size); if (buf == NULL) { RLC_THROW(ERR_NO_MEMORY); } if (len1 == len2) { if (strncmp(id1, id2, len1) == 0) { RLC_THROW(ERR_NO_VALID); } first = (strncmp(id1, id2, len1) < 0 ? 1 : 2); } else { if (len1 < len2) { if (strncmp(id1, id2, len1) == 0) { first = 1; } else { first = (strncmp(id1, id2, len1) < 0 ? 1 : 2); } } else { if (strncmp(id1, id2, len2) == 0) { first = 2; } else { first = (strncmp(id1, id2, len2) < 0 ? 1 : 2); } } } if (pc_map_is_type1()) { g2_map(q, (uint8_t *)id2, len2); pc_map(e, k->s1, q); } else { if (first == 1) { g2_map(q, (uint8_t *)id2, len2); pc_map(e, k->s1, q); } else { g1_map(p, (uint8_t *)id2, len2); pc_map(e, p, k->s2); } } /* Allocate size for storing the output. */ gt_write_bin(buf, size, e, 0); md_kdf(key, key_len, buf, size); } RLC_CATCH_ANY { result = RLC_ERR; } RLC_FINALLY { g1_free(p); g2_free(q); gt_free(e); RLC_FREE(buf); } return result; }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
int cp_vbnn_gen_prv(bn_t sk, ec_t pk, const bn_t msk, const uint8_t *id, size_t id_len) { uint8_t hash[RLC_MD_LEN]; size_t len; uint8_t *buf = NULL; bn_t n, r; int result = RLC_OK; /* zero variables */ bn_null(n); bn_null(r); RLC_TRY { /* initialize variables */ bn_new(n); bn_new(r); /* get order of ECC group */ ec_curve_get_ord(n); /* extract user key from id */ bn_rand_mod(r, n); /* calculate R part of the user key */ ec_mul_gen(pk, r); /* calculate s part of the user key */ len = id_len + ec_size_bin(pk, 1); buf = RLC_ALLOCA(uint8_t, len); if (buf == NULL) { RLC_THROW(ERR_NO_MEMORY); } memcpy(buf, id, id_len); ec_write_bin(buf + id_len, ec_size_bin(pk, 1), pk, 1); md_map(hash, buf, len); bn_read_bin(sk, hash, RLC_MD_LEN); bn_mod(sk, sk, n); bn_mul(sk, sk, msk); bn_add(sk, sk, r); bn_mod(sk, sk, n); } RLC_CATCH_ANY { result = RLC_ERR; } RLC_FINALLY { /* free variables */ bn_free(n); bn_free(r); RLC_FREE(buf); } return result; }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
int cp_vbnn_sig(ec_t r, bn_t z, bn_t h, const uint8_t *id, size_t id_len, const uint8_t *msg, int msg_len, const bn_t sk, const ec_t pk) { size_t len; uint8_t *buf = NULL, *buf_i, hash[RLC_MD_LEN]; bn_t n, y; ec_t t; int result = RLC_OK; /* zero variables */ bn_null(n); bn_null(y); ec_null(t); RLC_TRY { bn_new(n); bn_new(y); ec_new(t); /* get order of ECC group */ ec_curve_get_ord(n); bn_rand_mod(y, n); ec_mul_gen(t, y); /* calculate h part of the signature */ len = id_len + msg_len + ec_size_bin(t, 1) + ec_size_bin(pk, 1); buf = RLC_ALLOCA(uint8_t, len); if (buf == NULL) { RLC_THROW(ERR_NO_MEMORY); } buf_i = buf; memcpy(buf_i, id, id_len); buf_i += id_len; memcpy(buf_i, msg, msg_len); buf_i += msg_len; ec_write_bin(buf_i, ec_size_bin(pk, 1), pk, 1); buf_i += ec_size_bin(pk, 1); ec_write_bin(buf_i, ec_size_bin(t, 1), t, 1); md_map(hash, buf, len); bn_read_bin(h, hash, RLC_MD_LEN); bn_mod(h, h, n); /* calculate z part of the signature */ bn_mul(z, h, sk); bn_add(z, z, y); bn_mod(z, z, n); /* calculate R part of the signature */ ec_copy(r, pk); } RLC_CATCH_ANY { result = RLC_ERR; } RLC_FINALLY { /* free variables */ bn_free(n); bn_free(y); ec_free(t); RLC_FREE(buf); } return result; }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
int cp_vbnn_ver(const ec_t r, const bn_t z, const bn_t h, const uint8_t *id, size_t id_len, const uint8_t *msg, int msg_len, const ec_t mpk) { size_t len; uint8_t *buf = NULL, *buf_i, hash[RLC_MD_LEN]; bn_t n, c, _h; ec_t Z, t; int result = 0; /* zero variables */ bn_null(n); bn_null(c); bn_null(_h); ec_null(Z); ec_null(t); RLC_TRY { bn_new(n); bn_new(c); bn_new(_h); ec_new(Z); ec_new(t); /* calculate c */ len = id_len + msg_len + 2 * ec_size_bin(r, 1); buf = RLC_ALLOCA(uint8_t, len); if (buf == NULL) { RLC_THROW(ERR_NO_MEMORY); } /* get order of ECC group */ ec_curve_get_ord(n); buf_i = buf; memcpy(buf_i, id, id_len); buf_i += id_len; ec_write_bin(buf_i, ec_size_bin(r, 1), r, 1); len = id_len + ec_size_bin(r, 1); md_map(hash, buf, len); bn_read_bin(c, hash, RLC_MD_LEN); bn_mod(c, c, n); /* calculate Z */ ec_mul_gen(Z, z); ec_mul(t, mpk, c); ec_add(t, t, r); ec_norm(t, t); ec_mul(t, t, h); ec_sub(Z, Z, t); ec_norm(Z, Z); /* calculate h_verify */ buf_i = buf; memcpy(buf_i, id, id_len); buf_i += id_len; memcpy(buf_i, msg, msg_len); buf_i += msg_len; ec_write_bin(buf_i, ec_size_bin(r, 1), r, 1); buf_i += ec_size_bin(r, 1); ec_write_bin(buf_i, ec_size_bin(Z, 1), Z, 1); len = id_len + msg_len + ec_size_bin(r, 1) + ec_size_bin(Z, 1); md_map(hash, buf, len); bn_read_bin(_h, hash, RLC_MD_LEN); bn_mod(_h, _h, n); RLC_FREE(buf); if (bn_cmp(h, _h) == RLC_EQ) { result = 1; } else { result = 0; } } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { /* free variables */ bn_free(n); bn_free(c); bn_free(_h); ec_free(Z); ec_free(t); RLC_FREE(buf); } return result; }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void eb_map(eb_t p, const uint8_t *msg, size_t len) { bn_t k; fb_t t0, t1; int i; uint8_t digest[RLC_MD_LEN]; bn_null(k); fb_null(t0); fb_null(t1); RLC_TRY { bn_new(k); fb_new(t0); fb_new(t1); md_map(digest, msg, len); bn_read_bin(k, digest, RLC_MIN(RLC_FB_BYTES, RLC_MD_LEN)); fb_set_dig(p->z, 1); i = 0; while (1) { bn_add_dig(k, k, 1); bn_mod_2b(k, k, RLC_FB_BITS); dv_copy(p->x, k->dp, RLC_FB_DIGS); eb_rhs(t1, p); /* t0 = 1/x1^2. */ fb_sqr(t0, p->x); fb_inv(t0, t0); /* t0 = t1/x1^2. */ fb_mul(t0, t0, t1); /* Solve t1^2 + t1 = t0. */ if (fb_trc(t0) != 0) { i++; } else { fb_slv(t1, t0); /* x3 = x1, y3 = t1 * x1, z3 = 1. */ fb_mul(p->y, t1, p->x); fb_set_dig(p->z, 1); p->coord = BASIC; break; } } /* Now, multiply by cofactor to get the correct group. */ eb_curve_get_cof(k); if (bn_bits(k) < RLC_DIG) { eb_mul_dig(p, p, k->dp[0]); } else { eb_mul(p, p, k); } } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { bn_free(k); fb_free(t0); fb_free(t1); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
static void eb_mul_lnaf_imp(eb_t r, const eb_t p, const bn_t k) { int i, n; int8_t naf[RLC_FB_BITS + 1]; eb_t t[1 << (EB_WIDTH - 2)]; size_t l; RLC_TRY { /* Prepare the precomputation table. */ for (i = 0; i < (1 << (EB_WIDTH - 2)); i++) { eb_null(t[i]); eb_new(t[i]); eb_set_infty(t[i]); fb_set_dig(t[i]->z, 1); t[i]->coord = BASIC; } /* Compute the precomputation table. */ eb_tab(t, p, EB_WIDTH); /* Compute the w-NAF representation of k. */ l = sizeof(naf); bn_rec_naf(naf, &l, k, EB_WIDTH); n = naf[l - 1]; if (n > 0) { eb_copy(r, t[n / 2]); } for (i = l - 2; i >= 0; i--) { eb_dbl(r, r); n = naf[i]; if (n > 0) { eb_add(r, r, t[n / 2]); } if (n < 0) { eb_sub(r, r, t[-n / 2]); } } /* Convert r to affine coordinates. */ eb_norm(r, r); if (bn_sign(k) == RLC_NEG) { eb_neg(r, r); } } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { /* Free the precomputation table. */ for (i = 0; i < (1 << (EB_WIDTH - 2)); i++) { eb_free(t[i]); } } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
static void eb_mul_ltnaf_imp(eb_t r, const eb_t p, const bn_t k) { int i, n; int8_t tnaf[RLC_FB_BITS + 8], u; eb_t t[1 << (EB_WIDTH - 2)]; size_t l; if (eb_curve_opt_a() == RLC_ZERO) { u = -1; } else { u = 1; } RLC_TRY { /* Prepare the precomputation table. */ for (i = 0; i < (1 << (EB_WIDTH - 2)); i++) { eb_null(t[i]); eb_new(t[i]); } /* Compute the precomputation table. */ eb_tab(t, p, EB_WIDTH); /* Compute the w-TNAF representation of k. */ l = sizeof(tnaf); bn_rec_tnaf(tnaf, &l, k, u, RLC_FB_BITS, EB_WIDTH); n = tnaf[l - 1]; if (n > 0) { eb_copy(r, t[n / 2]); } else { eb_neg(r, t[-n / 2]); } for (i = l - 2; i >= 0; i--) { eb_frb(r, r); n = tnaf[i]; if (n > 0) { eb_add(r, r, t[n / 2]); } if (n < 0) { eb_sub(r, r, t[-n / 2]); } } /* Convert r to affine coordinates. */ eb_norm(r, r); if (bn_sign(k) == RLC_NEG) { eb_neg(r, r); } } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { /* Free the precomputation table. */ for (i = 0; i < (1 << (EB_WIDTH - 2)); i++) { eb_free(t[i]); } } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void eb_mul_sim_joint(eb_t r, const eb_t p, const bn_t k, const eb_t q, const bn_t m) { eb_t t[5]; int i, u_i, offset; int8_t jsf[2 * (RLC_FB_BITS + 1)]; size_t len; if (bn_is_zero(k) || eb_is_infty(p)) { eb_mul(r, q, m); return; } if (bn_is_zero(m) || eb_is_infty(q)) { eb_mul(r, p, k); return; } RLC_TRY { for (i = 0; i < 5; i++) { eb_null(t[i]); eb_new(t[i]); } eb_set_infty(t[0]); eb_copy(t[1], q); if (bn_sign(m) == RLC_NEG) { eb_neg(t[1], t[1]); } eb_copy(t[2], p); if (bn_sign(k) == RLC_NEG) { eb_neg(t[2], t[2]); } eb_add(t[3], t[2], t[1]); eb_sub(t[4], t[2], t[1]); #if defined(EB_MIXED) eb_norm_sim(t + 3, (const eb_t*)(t + 3), 2); #endif len = 2 * (RLC_FB_BITS + 1); bn_rec_jsf(jsf, &len, k, m); eb_set_infty(r); offset = RLC_MAX(bn_bits(k), bn_bits(m)) + 1; for (i = len - 1; i >= 0; i--) { eb_dbl(r, r); if (jsf[i] != 0 && jsf[i] == -jsf[i + offset]) { u_i = jsf[i] * 2 + jsf[i + offset]; if (u_i < 0) { eb_sub(r, r, t[4]); } else { eb_add(r, r, t[4]); } } else { u_i = jsf[i] * 2 + jsf[i + offset]; if (u_i < 0) { eb_sub(r, r, t[-u_i]); } else { eb_add(r, r, t[u_i]); } } } eb_norm(r, r); } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { for (i = 0; i < 5; i++) { eb_free(t[i]); } } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void eb_mul_sim_trick(eb_t r, const eb_t p, const bn_t k, const eb_t q, const bn_t m) { eb_t t0[1 << (EB_WIDTH / 2)], t1[1 << (EB_WIDTH / 2)], t[1 << EB_WIDTH]; size_t l0, l1, w = EB_WIDTH / 2; uint8_t w0[RLC_FB_BITS], w1[RLC_FB_BITS]; bn_t n; bn_null(n); if (bn_is_zero(k) || eb_is_infty(p)) { eb_mul(r, q, m); return; } if (bn_is_zero(m) || eb_is_infty(q)) { eb_mul(r, p, k); return; } RLC_TRY { bn_new(n); eb_curve_get_ord(n); for (int i = 0; i < (1 << w); i++) { eb_null(t0[i]); eb_null(t1[i]); eb_new(t0[i]); eb_new(t1[i]); } for (int i = 0; i < (1 << EB_WIDTH); i++) { eb_null(t[i]); eb_new(t[i]); } eb_set_infty(t0[0]); eb_copy(t0[1], p); if (bn_sign(k) == RLC_NEG) { eb_neg(t0[1], t0[1]); } for (int i = 2; i < (1 << w); i++) { eb_add(t0[i], t0[i - 1], t0[1]); } eb_set_infty(t1[0]); eb_copy(t1[1], q); if (bn_sign(m) == RLC_NEG) { eb_neg(t1[1], t1[1]); } for (int i = 2; i < (1 << w); i++) { eb_add(t1[i], t1[i - 1], t1[1]); } for (int i = 0; i < (1 << w); i++) { for (int j = 0; j < (1 << w); j++) { eb_add(t[(i << w) + j], t0[i], t1[j]); } } #if EB_WIDTH > 2 && defined(EB_MIXED) eb_norm_sim(t + 1, (const eb_t *)(t + 1), (1 << EB_WIDTH) - 1); #endif l0 = l1 = RLC_CEIL(RLC_FB_BITS + 1, w); bn_rec_win(w0, &l0, k, w); bn_rec_win(w1, &l1, m, w); for (int i = l0; i < l1; i++) { w0[i] = 0; } for (int i = l1; i < l0; i++) { w1[i] = 0; } eb_set_infty(r); for (int i = RLC_MAX(l0, l1) - 1; i >= 0; i--) { for (int j = 0; j < w; j++) { eb_dbl(r, r); } eb_add(r, r, t[(w0[i] << w) + w1[i]]); } eb_norm(r, r); } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { bn_free(n); for (int i = 0; i < (1 << w); i++) { eb_free(t0[i]); eb_free(t1[i]); } for (int i = 0; i < (1 << EB_WIDTH); i++) { eb_free(t[i]); } } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
static void eb_mul_sim_plain(eb_t r, const eb_t p, const bn_t k, const eb_t q, const bn_t m, const eb_t *t) { int i, n0, n1, w, g; int8_t naf0[RLC_FB_BITS + 1], naf1[RLC_FB_BITS + 1], *_k, *_m; eb_t t0[1 << (EB_WIDTH - 2)]; eb_t t1[1 << (EB_WIDTH - 2)]; size_t l, l0, l1; for (i = 0; i < (1 << (EB_WIDTH - 2)); i++) { eb_null(t0[i]); eb_null(t1[i]); } RLC_TRY { g = (t == NULL ? 0 : 1); if (!g) { for (i = 0; i < (1 << (EB_WIDTH - 2)); i++) { eb_new(t0[i]); } eb_tab(t0, p, EB_WIDTH); t = (const eb_t *)t0; } /* Prepare the precomputation table. */ for (i = 0; i < (1 << (EB_WIDTH - 2)); i++) { eb_new(t1[i]); } /* Compute the precomputation table. */ eb_tab(t1, q, EB_WIDTH); /* Compute the w-NAF representation of k. */ if (g) { w = EB_DEPTH; } else { w = EB_WIDTH; } l0 = l1 = RLC_FB_BITS + 1; bn_rec_naf(naf0, &l0, k, w); bn_rec_naf(naf1, &l1, m, EB_WIDTH); l = RLC_MAX(l0, l1); if (bn_sign(k) == RLC_NEG) { for (i = 0; i < l0; i++) { naf0[i] = -naf0[i]; } } if (bn_sign(m) == RLC_NEG) { for (i = 0; i < l1; i++) { naf1[i] = -naf1[i]; } } _k = naf0 + l - 1; _m = naf1 + l - 1; eb_set_infty(r); for (i = l - 1; i >= 0; i--, _k--, _m--) { eb_dbl(r, r); n0 = *_k; n1 = *_m; if (n0 > 0) { eb_add(r, r, t[n0 / 2]); } if (n0 < 0) { eb_sub(r, r, t[-n0 / 2]); } if (n1 > 0) { eb_add(r, r, t1[n1 / 2]); } if (n1 < 0) { eb_sub(r, r, t1[-n1 / 2]); } } /* Convert r to affine coordinates. */ eb_norm(r, r); } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { /* Free the precomputation tables. */ if (!g) { for (i = 0; i < 1 << (EB_WIDTH - 2); i++) { eb_free(t0[i]); } } for (i = 0; i < 1 << (EB_WIDTH - 2); i++) { eb_free(t1[i]); } } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void eb_read_bin(eb_t a, const uint8_t *bin, size_t len) { if (len == 1) { if (bin[0] == 0) { eb_set_infty(a); return; } else { RLC_THROW(ERR_NO_BUFFER); return; } } if (len != (RLC_FB_BYTES + 1) && len != (2 * RLC_FB_BYTES + 1)) { RLC_THROW(ERR_NO_BUFFER); return; } a->coord = BASIC; fb_set_dig(a->z, 1); fb_read_bin(a->x, bin + 1, RLC_FB_BYTES); if (len == RLC_FB_BYTES + 1) { switch(bin[0]) { case 2: fb_zero(a->y); break; case 3: fb_zero(a->y); fb_set_bit(a->y, 0, 1); break; default: RLC_THROW(ERR_NO_VALID); break; } eb_upk(a, a); } if (len == 2 * RLC_FB_BYTES + 1) { if (bin[0] == 4) { fb_read_bin(a->y, bin + RLC_FB_BYTES + 1, RLC_FB_BYTES); } else { RLC_THROW(ERR_NO_VALID); return; } } if (!eb_on_curve(a)) { RLC_THROW(ERR_NO_VALID); return; } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void eb_write_bin(uint8_t *bin, size_t len, const eb_t a, int pack) { eb_t t; eb_null(t); memset(bin, 0, len); if (eb_is_infty(a)) { if (len < 1) { RLC_THROW(ERR_NO_BUFFER); return; } else { return; } } RLC_TRY { eb_new(t); eb_norm(t, a); if (pack) { if (len < RLC_FB_BYTES + 1) { RLC_THROW(ERR_NO_BUFFER); } else { eb_pck(t, t); bin[0] = 2 | fb_get_bit(t->y, 0); fb_write_bin(bin + 1, RLC_FB_BYTES, t->x); } } else { if (len < 2 * RLC_FB_BYTES + 1) { RLC_THROW(ERR_NO_BUFFER); } else { bin[0] = 4; fb_write_bin(bin + 1, RLC_FB_BYTES, t->x); fb_write_bin(bin + RLC_FB_BYTES + 1, RLC_FB_BYTES, t->y); } } } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { eb_free(t); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void ed_map(ed_t p, const uint8_t *msg, size_t len) { ed_map_dst(p, msg, len, (const uint8_t *)"RELIC", 5); }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void ed_map_dst(ed_t p, const uint8_t *msg, size_t len, const uint8_t *dst, size_t dst_len) { bn_t k; fp_t t; ed_t q; /* enough space for two field elements plus extra bytes for uniformity */ const int len_per_elm = (FP_PRIME + ed_param_level() + 7) / 8; uint8_t *pseudo_random_bytes = RLC_ALLOCA(uint8_t, 2 * len_per_elm); bn_null(k); fp_null(t); ed_null(q); RLC_TRY { bn_new(k); fp_new(t); ed_new(q); /* pseudorandom string */ md_xmd(pseudo_random_bytes, 2 * len_per_elm, msg, len, dst, dst_len); #define ED_MAP_CONVERT_BYTES(IDX) \ do { \ bn_read_bin(k, pseudo_random_bytes + IDX * len_per_elm, len_per_elm); \ fp_prime_conv(t, k); \ } while (0) /* first map invocation */ ED_MAP_CONVERT_BYTES(0); ed_map_ell2_5mod8(p, t); /* second map invocation */ ED_MAP_CONVERT_BYTES(1); ed_map_ell2_5mod8(q, t); #undef ED_MAP_CONVERT_BYTES ed_add(p, p, q); /* clear cofactor */ switch (ed_param_get()) { case CURVE_ED25519: ed_dbl(p, p); ed_dbl(p, p); ed_dbl(p, p); break; default: RLC_THROW(ERR_NO_VALID); break; } ed_norm(p, p); #if ED_ADD == EXTND fp_mul(p->t, p->x, p->y); #endif p->coord = BASIC; } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { bn_free(k); fp_free(t); ed_free(q); RLC_FREE(pseudo_random_bytes); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
static void ed_mul_reg_imp(ed_t r, const ed_t p, const bn_t k) { bn_t _k; int i, j, n; int8_t s, reg[RLC_CEIL(RLC_FP_BITS + 1, ED_WIDTH - 1)]; ed_t t[1 << (ED_WIDTH - 2)], u, v; size_t l; bn_null(_k); if (bn_is_zero(k)) { ed_set_infty(r); return; } RLC_TRY { bn_new(_k); ed_new(u); ed_new(v); /* Prepare the precomputation table. */ for (i = 0; i < (1 << (ED_WIDTH - 2)); i++) { ed_null(t[i]); ed_new(t[i]); } /* Compute the precomputation table. */ ed_tab(t, p, ED_WIDTH); /* Make a copy of the scalar for processing. */ bn_abs(_k, k); _k->dp[0] |= bn_is_even(_k); /* Compute the w-NAF representation of k. */ l = RLC_CEIL(RLC_FP_BITS + 1, ED_WIDTH - 1); bn_rec_reg(reg, &l, _k, RLC_FP_BITS, ED_WIDTH); ed_set_infty(r); for (i = l - 1; i >= 0; i--) { for (j = 0; j < ED_WIDTH - 1; j++) { #if ED_ADD == EXTND r->coord = EXTND; #endif ed_dbl(r, r); } n = reg[i]; s = (n >> 7); n = ((n ^ s) - s) >> 1; for (j = 0; j < (1 << (EP_WIDTH - 2)); j++) { dv_copy_cond(u->x, t[j]->x, RLC_FP_DIGS, j == n); dv_copy_cond(u->y, t[j]->y, RLC_FP_DIGS, j == n); dv_copy_cond(u->z, t[j]->z, RLC_FP_DIGS, j == n); } ed_neg(v, u); dv_copy_cond(u->x, v->x, RLC_FP_DIGS, s != 0); ed_add(r, r, u); } /* t[0] has an unmodified copy of p. */ ed_sub(u, r, t[0]); dv_copy_cond(r->x, u->x, RLC_FP_DIGS, bn_is_even(k)); dv_copy_cond(r->y, u->y, RLC_FP_DIGS, bn_is_even(k)); dv_copy_cond(r->z, u->z, RLC_FP_DIGS, bn_is_even(k)); /* Convert r to affine coordinates. */ ed_norm(r, r); ed_neg(u, r); dv_copy_cond(r->x, u->x, RLC_FP_DIGS, bn_sign(k) == RLC_NEG); } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { /* Free the precomputation table. */ for (i = 0; i < (1 << (ED_WIDTH - 2)); i++) { ed_free(t[i]); } bn_free(_k); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void ed_mul_slide(ed_t r, const ed_t p, const bn_t k) { ed_t t[1 << (EP_WIDTH - 1)], q; uint8_t win[RLC_FP_BITS + 1]; size_t l; ed_null(q); if (bn_is_zero(k) || ed_is_infty(p)) { ed_set_infty(r); return; } RLC_TRY { for (size_t i = 0; i < (1 << (EP_WIDTH - 1)); i ++) { ed_null(t[i]); ed_new(t[i]); } ed_new(q); ed_copy(t[0], p); ed_dbl(q, p); #if defined(EP_MIXED) ed_norm(q, q); #endif /* Create table. */ for (size_t i = 1; i < (1 << (EP_WIDTH - 1)); i++) { ed_add(t[i], t[i - 1], q); } #if defined(EP_MIXED) ed_norm_sim(t + 1, (const ed_t *)t + 1, (1 << (EP_WIDTH - 1)) - 1); #endif ed_set_infty(q); l = RLC_FP_BITS + 1; bn_rec_slw(win, &l, k, EP_WIDTH); for (size_t i = 0; i < l; i++) { if (win[i] == 0) { ed_dbl(q, q); } else { for (size_t j = 0; j < util_bits_dig(win[i]); j++) { ed_dbl(q, q); } ed_add(q, q, t[win[i] >> 1]); } } ed_norm(r, q); if (bn_sign(k) == RLC_NEG) { ed_neg(r, r); } } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { for (size_t i = 0; i < (1 << (EP_WIDTH - 1)); i++) { ed_free(t[i]); } ed_free(q); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void ed_mul_dig(ed_t r, const ed_t p, dig_t k) { ed_t t; bn_t _k; int8_t u, naf[RLC_DIG + 1]; size_t l; ed_null(t); bn_null(_k); if (k == 0 || ed_is_infty(p)) { ed_set_infty(r); return; } RLC_TRY { ed_new(t); bn_new(_k); bn_set_dig(_k, k); l = RLC_DIG + 1; bn_rec_naf(naf, &l, _k, 2); ed_set_infty(t); for (int i = l - 1; i >= 0; i--) { ed_dbl(t, t); u = naf[i]; if (u > 0) { ed_add(t, t, p); } else if (u < 0) { ed_sub(t, t, p); } } ed_norm(r, t); } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { ed_free(t); bn_free(_k); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
static void ed_mul_naf_imp(ed_t r, const ed_t p, const bn_t k) { int i, n; int8_t naf[RLC_FP_BITS + 1]; ed_t t[1 << (ED_WIDTH - 2)]; size_t l; if (bn_is_zero(k)) { ed_set_infty(r); return; } RLC_TRY { /* Prepare the precomputation table. */ for (i = 0; i < (1 << (ED_WIDTH - 2)); i++) { ed_null(t[i]); ed_new(t[i]); } /* Compute the precomputation table. */ ed_tab(t, p, ED_WIDTH); /* Compute the w-NAF representation of k. */ l = sizeof(naf); bn_rec_naf(naf, &l, k, EP_WIDTH); ed_set_infty(r); for (i = l - 1; i > 0; i--) { n = naf[i]; if (n == 0) { /* This point will be doubled in the next iteration. */ #if ED_ADD == EXTND r->coord = EXTND; #endif } ed_dbl(r, r); if (n > 0) { ed_add(r, r, t[n / 2]); } else if (n < 0) { ed_sub(r, r, t[-n / 2]); } } /* Last iteration. */ n = naf[0]; ed_dbl(r, r); if (n > 0) { ed_add(r, r, t[n / 2]); } else if (n < 0) { ed_sub(r, r, t[-n / 2]); } /* Convert r to affine coordinates. */ ed_norm(r, r); if (bn_sign(k) == RLC_NEG) { ed_neg(r, r); } } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { /* Free the precomputation table. */ for (i = 0; i < (1 << (ED_WIDTH - 2)); i++) { ed_free(t[i]); } } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
static void ed_mul_fix_plain(ed_t r, const ed_t * t, const bn_t k) { int i, n; int8_t naf[RLC_FP_BITS + 1], *_k; size_t l; /* Compute the w-TNAF representation of k. */ l = RLC_FP_BITS + 1; bn_rec_naf(naf, &l, k, ED_DEPTH); _k = naf + l - 1; ed_set_infty(r); for (i = l - 1; i >= 0; i--, _k--) { n = *_k; if (n == 0) { /* doubling is followed by another doubling */ if (i > 0) { r->coord = EXTND; ed_dbl(r, r); } else { /* use full extended coordinate doubling for last step */ ed_dbl(r, r); } } else { ed_dbl(r, r); if (n > 0) { ed_add(r, r, t[n / 2]); } else if (n < 0) { ed_sub(r, r, t[-n / 2]); } } } /* Convert r to affine coordinates. */ ed_norm(r, r); if (bn_sign(k) == RLC_NEG) { ed_neg(r, r); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void ed_mul_sim_lot(ed_t r, const ed_t p[], const bn_t k[], int n) { int i, j; int8_t *naf = NULL; ed_t *_p = RLC_ALLOCA(ed_t, n); size_t l, *_l = RLC_ALLOCA(size_t, n); RLC_TRY { l = 0; for (i = 0; i < n; i++) { l = RLC_MAX(l, bn_bits(k[i]) + 1); } naf = RLC_ALLOCA(int8_t, n * l); if (naf == NULL || _p == NULL || _l == NULL) { RLC_THROW(ERR_NO_MEMORY); } for (i = 0; i < n; i++) { ed_null(_p[i]); ed_new(_p[i]); } for (i = 0; i < n; i++) { _l[i] = l; ed_norm(_p[i], p[i]); bn_rec_naf(&naf[i*l], &_l[i], k[i], 2); if (bn_sign(k[i]) == RLC_NEG) { ed_neg(_p[i], _p[i]); } } ed_set_infty(r); for (i = l - 1; i >= 0; i--) { ed_dbl(r, r); for (j = 0; j < n; j++) { if (naf[j*l + i] > 0) { ed_add(r, r, _p[j]); } if (naf[j*l + i] < 0) { ed_sub(r, r, _p[j]); } } } /* Convert r to affine coordinates. */ ed_norm(r, r); } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { for (i = 0; i < n; i++) { ed_free(_p[i]); } RLC_FREE(_l); RLC_FREE(_p); RLC_FREE(naf); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void ed_mul_sim_joint(ed_t r, const ed_t p, const bn_t k, const ed_t q, const bn_t m) { ed_t t[5]; int i, u_i, offset; int8_t jsf[2 * (RLC_FP_BITS + 1)]; size_t l; if (bn_is_zero(k) || ed_is_infty(p)) { ed_mul(r, q, m); return; } if (bn_is_zero(m) || ed_is_infty(q)) { ed_mul(r, p, k); return; } RLC_TRY { for (i = 0; i < 5; i++) { ed_null(t[i]); ed_new(t[i]); } ed_set_infty(t[0]); ed_copy(t[1], q); if (bn_sign(m) == RLC_NEG) { ed_neg(t[1], t[1]); } ed_copy(t[2], p); if (bn_sign(k) == RLC_NEG) { ed_neg(t[2], t[2]); } ed_add(t[3], t[2], t[1]); ed_sub(t[4], t[2], t[1]); #if defined(ED_MIXED) ed_norm_sim(t + 3, (const ed_t *)t + 3, 2); #endif l = 2 * (RLC_FP_BITS + 1); bn_rec_jsf(jsf, &l, k, m); ed_set_infty(r); offset = RLC_MAX(bn_bits(k), bn_bits(m)) + 1; for (i = l - 1; i >= 0; i--) { ed_dbl(r, r); if (jsf[i] != 0 && jsf[i] == -jsf[i + offset]) { u_i = jsf[i] * 2 + jsf[i + offset]; if (u_i < 0) { ed_sub(r, r, t[4]); } else { ed_add(r, r, t[4]); } } else { u_i = jsf[i] * 2 + jsf[i + offset]; if (u_i < 0) { ed_sub(r, r, t[-u_i]); } else { ed_add(r, r, t[u_i]); } } } ed_norm(r, r); } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { for (i = 0; i < 5; i++) { ed_free(t[i]); } } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
static void ed_mul_sim_plain(ed_t r, const ed_t p, const bn_t k, const ed_t q, const bn_t m, const ed_t *t) { int i, n0, n1, w, gen; int8_t naf0[RLC_FP_BITS + 1], naf1[RLC_FP_BITS + 1], *_k, *_m; ed_t t0[1 << (ED_WIDTH - 2)]; ed_t t1[1 << (ED_WIDTH - 2)]; size_t l, l0, l1; RLC_TRY { gen = (t == NULL ? 0 : 1); if (!gen) { for (i = 0; i < (1 << (ED_WIDTH - 2)); i++) { ed_null(t0[i]); ed_new(t0[i]); } ed_tab(t0, p, ED_WIDTH); t = (const ed_t *)t0; } /* Prepare the precomputation table. */ for (i = 0; i < (1 << (ED_WIDTH - 2)); i++) { ed_null(t1[i]); ed_new(t1[i]); } /* Compute the precomputation table. */ ed_tab(t1, q, ED_WIDTH); /* Compute the w-TNAF representation of k. */ if (gen) { w = ED_DEPTH; } else { w = ED_WIDTH; } l0 = l1 = RLC_FP_BITS + 1; bn_rec_naf(naf0, &l0, k, w); bn_rec_naf(naf1, &l1, m, ED_WIDTH); l = RLC_MAX(l0, l1); if (bn_sign(k) == RLC_NEG) { for (i = 0; i < l0; i++) { naf0[i] = -naf0[i]; } } if (bn_sign(m) == RLC_NEG) { for (i = 0; i < l1; i++) { naf1[i] = -naf1[i]; } } _k = naf0 + l - 1; _m = naf1 + l - 1; ed_set_infty(r); for (i = l - 1; i >= 0; i--, _k--, _m--) { ed_dbl(r, r); n0 = *_k; n1 = *_m; if (n0 > 0) { ed_add(r, r, t[n0 / 2]); } if (n0 < 0) { ed_sub(r, r, t[-n0 / 2]); } if (n1 > 0) { ed_add(r, r, t1[n1 / 2]); } if (n1 < 0) { ed_sub(r, r, t1[-n1 / 2]); } } /* Convert r to affine coordinates. */ ed_norm(r, r); } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { /* Free the precomputation tables. */ if (!gen) { for (i = 0; i < 1 << (ED_WIDTH - 2); i++) { ed_free(t0[i]); } } for (i = 0; i < 1 << (ED_WIDTH - 2); i++) { ed_free(t1[i]); } } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void ed_mul_sim_trick(ed_t r, const ed_t p, const bn_t k, const ed_t q, const bn_t m) { ed_t t0[1 << (ED_WIDTH / 2)], t1[1 << (ED_WIDTH / 2)], t[1 << ED_WIDTH]; bn_t n; size_t l0, l1, w = ED_WIDTH / 2; uint8_t w0[RLC_FP_BITS + 1], w1[RLC_FP_BITS + 1]; bn_null(n); if (bn_is_zero(k) || ed_is_infty(p)) { ed_mul(r, q, m); return; } if (bn_is_zero(m) || ed_is_infty(q)) { ed_mul(r, p, k); return; } RLC_TRY { bn_new(n); ed_curve_get_ord(n); for (int i = 0; i < (1 << w); i++) { ed_null(t0[i]); ed_null(t1[i]); ed_new(t0[i]); ed_new(t1[i]); } for (int i = 0; i < (1 << ED_WIDTH); i++) { ed_null(t[i]); ed_new(t[i]); } ed_set_infty(t0[0]); ed_copy(t0[1], p); if (bn_sign(k) == RLC_NEG) { ed_neg(t0[1], t0[1]); } for (int i = 2; i < (1 << w); i++) { ed_add(t0[i], t0[i - 1], t0[1]); } ed_set_infty(t1[0]); ed_copy(t1[1], q); if (bn_sign(m) == RLC_NEG) { ed_neg(t1[1], t1[1]); } for (int i = 1; i < (1 << w); i++) { ed_add(t1[i], t1[i - 1], t1[1]); } for (int i = 0; i < (1 << w); i++) { for (int j = 0; j < (1 << w); j++) { ed_add(t[(i << w) + j], t0[i], t1[j]); } } #if defined(ED_MIXED) ed_norm_sim(t + 1, (const ed_t *)t + 1, (1 << (ED_WIDTH)) - 1); #endif l0 = l1 = RLC_CEIL(RLC_FP_BITS, w); bn_rec_win(w0, &l0, k, w); bn_rec_win(w1, &l1, m, w); for (int i = l0; i < l1; i++) { w0[i] = 0; } for (int i = l1; i < l0; i++) { w1[i] = 0; } ed_set_infty(r); for (int i = RLC_MAX(l0, l1) - 1; i >= 0; i--) { for (int j = 0; j < w; j++) { ed_dbl(r, r); } ed_add(r, r, t[(w0[i] << w) + w1[i]]); } ed_norm(r, r); } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { bn_free(n); for (int i = 0; i < (1 << w); i++) { ed_free(t0[i]); ed_free(t1[i]); } for (int i = 0; i < (1 << ED_WIDTH); i++) { ed_free(t[i]); } } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void ed_write_bin(uint8_t *bin, size_t len, const ed_t a, int pack) { ed_t t; ed_null(t); memset(bin, 0, len); if (ed_is_infty(a)) { if (len < 1) { RLC_THROW(ERR_NO_BUFFER); return; } else { return; } } RLC_TRY { ed_new(t); ed_norm(t, a); if (pack) { if (len < RLC_FP_BYTES + 1) { RLC_THROW(ERR_NO_BUFFER); } else { ed_pck(t, t); bin[0] = 2 | fp_get_bit(t->x, 0); fp_write_bin(bin + 1, RLC_FP_BYTES, t->y); } } else { if (len < 2 * RLC_FP_BYTES + 1) { RLC_THROW(ERR_NO_BUFFER); } else { bin[0] = 4; fp_write_bin(bin + 1, RLC_FP_BYTES, t->y); fp_write_bin(bin + RLC_FP_BYTES + 1, RLC_FP_BYTES, t->x); } } } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { ed_free(t); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void ed_read_bin(ed_t a, const uint8_t *bin, size_t len) { if (len == 1) { if (bin[0] == 0) { ed_set_infty(a); return; } else { RLC_THROW(ERR_NO_BUFFER); return; } } if (len != (RLC_FP_BYTES + 1) && len != (2 * RLC_FP_BYTES + 1)) { RLC_THROW(ERR_NO_BUFFER); return; } a->coord = BASIC; fp_set_dig(a->z, 1); fp_read_bin(a->y, bin + 1, RLC_FP_BYTES); if (len == RLC_FP_BYTES + 1) { switch (bin[0]) { case 2: fp_zero(a->x); break; case 3: fp_zero(a->x); fp_set_bit(a->x, 0, 1); break; default: RLC_THROW(ERR_NO_VALID); break; } ed_upk(a, a); } if (len == 2 * RLC_FP_BYTES + 1) { if (bin[0] == 4) { fp_read_bin(a->x, bin + RLC_FP_BYTES + 1, RLC_FP_BYTES); } else { RLC_THROW(ERR_NO_VALID); return; } } #if ED_ADD == EXTND fp_mul(a->t, a->x, a->y); fp_mul(a->x, a->x, a->z); fp_mul(a->y, a->y, a->z); fp_sqr(a->z, a->z); #endif if (!ed_on_curve(a)) { RLC_THROW(ERR_NO_VALID); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void ep_map_dst(ep_t p, const uint8_t *msg, size_t len, const uint8_t *dst, size_t dst_len) { /* enough space for two field elements plus extra bytes for uniformity */ const int len_per_elm = (FP_PRIME + ep_param_level() + 7) / 8; uint8_t *pseudo_random_bytes = RLC_ALLOCA(uint8_t, 2 * len_per_elm); RLC_TRY { /* for hash_to_field, need to hash to a pseudorandom string */ /* XXX(rsw) the below assumes that we want to use MD_MAP for hashing. * Consider making the hash function a per-curve option! */ md_xmd(pseudo_random_bytes, 2 * len_per_elm, msg, len, dst, dst_len); ep_map_from_field(p, pseudo_random_bytes, 2 * len_per_elm); } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { RLC_FREE(pseudo_random_bytes); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void ep_map(ep_t p, const uint8_t *msg, size_t len) { ep_map_dst(p, msg, len, (const uint8_t *)"RELIC", 5); }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
static void ep_mul_naf_imp(ep_t r, const ep_t p, const bn_t k) { /* Some of the supported prime curves have order > field. */ int8_t u, naf[RLC_FP_BITS + 2]; ep_t t[1 << (EP_WIDTH - 2)]; bn_t _k, n; size_t l; bn_null(n); bn_null(_k); RLC_TRY { bn_new(n); bn_new(_k); /* Prepare the precomputation table. */ for (int i = 0; i < (1 << (EP_WIDTH - 2)); i++) { ep_null(t[i]); ep_new(t[i]); } ep_curve_get_ord(n); bn_mod(_k, k, n); /* Compute the precomputation table. */ ep_tab(t, p, EP_WIDTH); /* Compute the w-NAF representation of k. */ l = RLC_FP_BITS + 2; bn_rec_naf(naf, &l, _k, EP_WIDTH); ep_set_infty(r); for (int i = l - 1; i >= 0; i--) { ep_dbl(r, r); u = naf[i]; if (u > 0) { ep_add(r, r, t[u / 2]); } else if (u < 0) { ep_sub(r, r, t[-u / 2]); } } /* Convert r to affine coordinates. */ ep_norm(r, r); if (bn_sign(_k) == RLC_NEG) { ep_neg(r, r); } } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { bn_free(n); bn_free(_k); /* Free the precomputation table. */ for (int i = 0; i < (1 << (EP_WIDTH - 2)); i++) { ep_free(t[i]); } } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void ep_mul_slide(ep_t r, const ep_t p, const bn_t k) { bn_t _k, n; ep_t t[1 << (EP_WIDTH - 1)], q; uint8_t win[RLC_FP_BITS + 1]; size_t l; if (bn_is_zero(k) || ep_is_infty(p)) { ep_set_infty(r); return; } ep_null(q); bn_null(n); bn_null(_k); RLC_TRY { bn_new(n); bn_new(_k); for (size_t i = 0; i < (1 << (EP_WIDTH - 1)); i ++) { ep_null(t[i]); ep_new(t[i]); } ep_new(q); ep_copy(t[0], p); ep_dbl(q, p); #if defined(EP_MIXED) ep_norm(q, q); #endif ep_curve_get_ord(n); bn_mod(_k, k, n); /* Create table. */ for (size_t i = 1; i < (1 << (EP_WIDTH - 1)); i++) { ep_add(t[i], t[i - 1], q); } #if defined(EP_MIXED) ep_norm_sim(t + 1, (const ep_t *)t + 1, (1 << (EP_WIDTH - 1)) - 1); #endif ep_set_infty(q); l = RLC_FP_BITS + 1; bn_rec_slw(win, &l, _k, EP_WIDTH); for (size_t i = 0; i < l; i++) { if (win[i] == 0) { ep_dbl(q, q); } else { for (size_t j = 0; j < util_bits_dig(win[i]); j++) { ep_dbl(q, q); } ep_add(q, q, t[win[i] >> 1]); } } ep_norm(r, q); if (bn_sign(_k) == RLC_NEG) { ep_neg(r, r); } } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { bn_free(n); bn_free(_k); for (size_t i = 0; i < (1 << (EP_WIDTH - 1)); i++) { ep_free(t[i]); } ep_free(q); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void ep_mul_monty(ep_t r, const ep_t p, const bn_t k) { ep_t t[2]; bn_t n, l, _k; size_t bits; bn_null(n); bn_null(l); bn_null(_k); ep_null(t[0]); ep_null(t[1]); if (bn_is_zero(k) || ep_is_infty(p)) { ep_set_infty(r); return; } RLC_TRY { bn_new(n); bn_new(l); bn_new(_k); ep_new(t[0]); ep_new(t[1]); ep_curve_get_ord(n); bits = bn_bits(n); bn_mod(_k, k, n); bn_abs(l, _k); bn_add(l, l, n); bn_add(n, l, n); dv_swap_cond(l->dp, n->dp, RLC_MAX(l->used, n->used), bn_get_bit(l, bits) == 0); l->used = RLC_SEL(l->used, n->used, bn_get_bit(l, bits) == 0); ep_norm(t[0], p); ep_dbl(t[1], t[0]); /* Blind both points independently. */ ep_blind(t[0], t[0]); ep_blind(t[1], t[1]); for (int i = bits - 1; i >= 0; i--) { int j = bn_get_bit(l, i); dv_swap_cond(t[0]->x, t[1]->x, RLC_FP_DIGS, j ^ 1); dv_swap_cond(t[0]->y, t[1]->y, RLC_FP_DIGS, j ^ 1); dv_swap_cond(t[0]->z, t[1]->z, RLC_FP_DIGS, j ^ 1); ep_add(t[0], t[0], t[1]); ep_dbl(t[1], t[1]); dv_swap_cond(t[0]->x, t[1]->x, RLC_FP_DIGS, j ^ 1); dv_swap_cond(t[0]->y, t[1]->y, RLC_FP_DIGS, j ^ 1); dv_swap_cond(t[0]->z, t[1]->z, RLC_FP_DIGS, j ^ 1); } ep_norm(r, t[0]); ep_neg(t[0], r); dv_copy_cond(r->y, t[0]->y, RLC_FP_DIGS, bn_sign(_k) == RLC_NEG); } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { bn_free(n); bn_free(l); bn_free(_k); ep_free(t[1]); ep_free(t[0]); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void ep_mul_dig(ep_t r, const ep_t p, dig_t k) { ep_t t; bn_t _k; int8_t u, naf[RLC_DIG + 1]; size_t l; ep_null(t); bn_null(_k); if (k == 0 || ep_is_infty(p)) { ep_set_infty(r); return; } RLC_TRY { ep_new(t); bn_new(_k); bn_set_dig(_k, k); l = RLC_DIG + 1; bn_rec_naf(naf, &l, _k, 2); ep_set_infty(t); for (int i = l - 1; i >= 0; i--) { ep_dbl(t, t); u = naf[i]; if (u > 0) { ep_add(t, t, p); } else if (u < 0) { ep_sub(t, t, p); } } ep_norm(r, t); } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { ep_free(t); bn_free(_k); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
static void ep_mul_glv_imp(ep_t r, const ep_t p, const bn_t k) { int i, n0, n1, s0, s1; int8_t naf0[RLC_FP_BITS + 1], naf1[RLC_FP_BITS + 1], *t0, *t1; bn_t n, _k, k0, k1, v1[3], v2[3]; ep_t q, t[1 << (EP_WIDTH - 2)]; size_t l, l0, l1; bn_null(n); bn_null(_k); bn_null(k0); bn_null(k1); ep_null(q); RLC_TRY { bn_new(n); bn_new(_k); bn_new(k0); bn_new(k1); ep_new(q); for (i = 0; i < (1 << (EP_WIDTH - 2)); i++) { ep_null(t[i]); ep_new(t[i]); } for (i = 0; i < 3; i++) { bn_null(v1[i]); bn_null(v2[i]); bn_new(v1[i]); bn_new(v2[i]); } ep_curve_get_ord(n); ep_curve_get_v1(v1); ep_curve_get_v2(v2); bn_mod(_k, k, n); bn_rec_glv(k0, k1, _k, n, (const bn_t *)v1, (const bn_t *)v2); s0 = bn_sign(k0); s1 = bn_sign(k1); bn_abs(k0, k0); bn_abs(k1, k1); if (s0 == RLC_POS) { ep_tab(t, p, EP_WIDTH); } else { ep_neg(q, p); ep_tab(t, q, EP_WIDTH); } l0 = l1 = RLC_FP_BITS + 1; bn_rec_naf(naf0, &l0, k0, EP_WIDTH); bn_rec_naf(naf1, &l1, k1, EP_WIDTH); l = RLC_MAX(l0, l1); t0 = naf0 + l - 1; t1 = naf1 + l - 1; ep_set_infty(r); for (i = l - 1; i >= 0; i--, t0--, t1--) { ep_dbl(r, r); n0 = *t0; n1 = *t1; if (n0 > 0) { ep_add(r, r, t[n0 / 2]); } if (n0 < 0) { ep_sub(r, r, t[-n0 / 2]); } if (n1 > 0) { ep_psi(q, t[n1 / 2]); if (s0 != s1) { ep_neg(q, q); } ep_add(r, r, q); } if (n1 < 0) { ep_psi(q, t[-n1 / 2]); if (s0 != s1) { ep_neg(q, q); } ep_sub(r, r, q); } } /* Convert r to affine coordinates. */ ep_norm(r, r); if (bn_sign(_k) == RLC_NEG) { ep_neg(r, r); } } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { bn_free(n); bn_free(_k); bn_free(k0); bn_free(k1); bn_free(n) ep_free(q); for (i = 0; i < 1 << (EP_WIDTH - 2); i++) { ep_free(t[i]); } for (i = 0; i < 3; i++) { bn_free(v1[i]); bn_free(v2[i]); } } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
static void ep_mul_reg_imp(ep_t r, const ep_t p, const bn_t k) { bn_t _k; int i, j, n; int8_t s, reg[1 + RLC_CEIL(RLC_FP_BITS + 1, EP_WIDTH - 1)]; ep_t t[1 << (EP_WIDTH - 2)], u, v; size_t l; if (bn_is_zero(k)) { ep_set_infty(r); return; } bn_null(_k); RLC_TRY { bn_new(_k); ep_new(u); ep_new(v); /* Prepare the precomputation table. */ for (i = 0; i < (1 << (EP_WIDTH - 2)); i++) { ep_null(t[i]); ep_new(t[i]); } /* Compute the precomputation table. */ ep_tab(t, p, EP_WIDTH); ep_curve_get_ord(_k); n = bn_bits(_k); /* Make a copy of the scalar for processing. */ bn_abs(_k, k); _k->dp[0] |= 1; /* Compute the regular w-NAF representation of k. */ l = RLC_CEIL(n, EP_WIDTH - 1) + 1; bn_rec_reg(reg, &l, _k, n, EP_WIDTH); #if defined(EP_MIXED) fp_set_dig(u->z, 1); u->coord = BASIC; #else u->coord = EP_ADD; #endif ep_set_infty(r); for (i = l - 1; i >= 0; i--) { for (j = 0; j < EP_WIDTH - 1; j++) { ep_dbl(r, r); } n = reg[i]; s = (n >> 7); n = ((n ^ s) - s) >> 1; for (j = 0; j < (1 << (EP_WIDTH - 2)); j++) { dv_copy_cond(u->x, t[j]->x, RLC_FP_DIGS, j == n); dv_copy_cond(u->y, t[j]->y, RLC_FP_DIGS, j == n); #if !defined(EP_MIXED) dv_copy_cond(u->z, t[j]->z, RLC_FP_DIGS, j == n); #endif } ep_neg(v, u); dv_copy_cond(u->y, v->y, RLC_FP_DIGS, s != 0); ep_add(r, r, u); } /* t[0] has an unmodified copy of p. */ ep_sub(u, r, t[0]); dv_copy_cond(r->x, u->x, RLC_FP_DIGS, bn_is_even(k)); dv_copy_cond(r->y, u->y, RLC_FP_DIGS, bn_is_even(k)); dv_copy_cond(r->z, u->z, RLC_FP_DIGS, bn_is_even(k)); /* Convert r to affine coordinates. */ ep_norm(r, r); ep_neg(u, r); dv_copy_cond(r->y, u->y, RLC_FP_DIGS, bn_sign(k) == RLC_NEG); } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { /* Free the precomputation table. */ for (i = 0; i < (1 << (EP_WIDTH - 2)); i++) { ep_free(t[i]); } bn_free(_k); ep_free(u); ep_free(v); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
static void ep_mul_fix_plain(ep_t r, const ep_t *t, const bn_t k) { int i, n; int8_t naf[RLC_FP_BITS + 1]; size_t l; /* Compute the w-TNAF representation of k. */ l = RLC_FP_BITS + 1; bn_rec_naf(naf, &l, k, EP_DEPTH); n = naf[l - 1]; if (n > 0) { ep_copy(r, t[n / 2]); } else { ep_neg(r, t[-n / 2]); } for (i = l - 2; i >= 0; i--) { ep_dbl(r, r); n = naf[i]; if (n > 0) { ep_add(r, r, t[n / 2]); } if (n < 0) { ep_sub(r, r, t[-n / 2]); } } /* Convert r to affine coordinates. */ ep_norm(r, r); if (bn_sign(k) == RLC_NEG) { ep_neg(r, r); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
static void ep_mul_sim_plain(ep_t r, const ep_t p, const bn_t k, const ep_t q, const bn_t m, const ep_t *t) { int i, w, gen; int8_t naf0[RLC_FP_BITS + 1], naf1[RLC_FP_BITS + 1], n0, n1, *u, *v; ep_t t0[1 << (EP_WIDTH - 2)]; ep_t t1[1 << (EP_WIDTH - 2)]; size_t l, l0, l1; RLC_TRY { gen = (t == NULL ? 0 : 1); if (!gen) { for (i = 0; i < (1 << (EP_WIDTH - 2)); i++) { ep_null(t0[i]); ep_new(t0[i]); } ep_tab(t0, p, EP_WIDTH); t = (const ep_t *)t0; } /* Prepare the precomputation table. */ for (i = 0; i < (1 << (EP_WIDTH - 2)); i++) { ep_null(t1[i]); ep_new(t1[i]); } /* Compute the precomputation table. */ ep_tab(t1, q, EP_WIDTH); /* Compute the w-TNAF representation of k. */ if (gen) { w = EP_DEPTH; } else { w = EP_WIDTH; } l0 = l1 = RLC_FP_BITS + 1; bn_rec_naf(naf0, &l0, k, w); bn_rec_naf(naf1, &l1, m, EP_WIDTH); l = RLC_MAX(l0, l1); if (bn_sign(k) == RLC_NEG) { for (i = 0; i < l0; i++) { naf0[i] = -naf0[i]; } } if (bn_sign(m) == RLC_NEG) { for (i = 0; i < l1; i++) { naf1[i] = -naf1[i]; } } u = naf0 + l - 1; v = naf1 + l - 1; ep_set_infty(r); for (i = l - 1; i >= 0; i--, u--, v--) { ep_dbl(r, r); n0 = *u; n1 = *v; if (n0 > 0) { ep_add(r, r, t[n0 / 2]); } if (n0 < 0) { ep_sub(r, r, t[-n0 / 2]); } if (n1 > 0) { ep_add(r, r, t1[n1 / 2]); } if (n1 < 0) { ep_sub(r, r, t1[-n1 / 2]); } } /* Convert r to affine coordinates. */ ep_norm(r, r); } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { /* Free the precomputation tables. */ if (!gen) { for (i = 0; i < 1 << (EP_WIDTH - 2); i++) { ep_free(t0[i]); } } for (i = 0; i < 1 << (EP_WIDTH - 2); i++) { ep_free(t1[i]); } } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void ep_mul_sim_joint(ep_t r, const ep_t p, const bn_t k, const ep_t q, const bn_t m) { bn_t n, _k, _m; ep_t t[5]; int i, u_i, offset; int8_t jsf[2 * (RLC_FP_BITS + 1)]; size_t l; if (bn_is_zero(k) || ep_is_infty(p)) { ep_mul(r, q, m); return; } if (bn_is_zero(m) || ep_is_infty(q)) { ep_mul(r, p, k); return; } bn_null(n); bn_null(_k); bn_null(_m); RLC_TRY { bn_new(n); bn_new(_k); bn_new(_m); for (i = 0; i < 5; i++) { ep_null(t[i]); ep_new(t[i]); } ep_curve_get_ord(n); bn_mod(_k, k, n); bn_mod(_m, m, n); ep_set_infty(t[0]); ep_copy(t[1], q); if (bn_sign(_m) == RLC_NEG) { ep_neg(t[1], t[1]); } ep_copy(t[2], p); if (bn_sign(_k) == RLC_NEG) { ep_neg(t[2], t[2]); } ep_add(t[3], t[2], t[1]); ep_sub(t[4], t[2], t[1]); #if defined(EP_MIXED) ep_norm_sim(t + 3, (const ep_t *)t + 3, 2); #endif l = 2 * (RLC_FP_BITS + 1); bn_rec_jsf(jsf, &l, _k, _m); ep_set_infty(r); offset = RLC_MAX(bn_bits(_k), bn_bits(_m)) + 1; for (i = l - 1; i >= 0; i--) { ep_dbl(r, r); if (jsf[i] != 0 && jsf[i] == -jsf[i + offset]) { u_i = jsf[i] * 2 + jsf[i + offset]; if (u_i < 0) { ep_sub(r, r, t[4]); } else { ep_add(r, r, t[4]); } } else { u_i = jsf[i] * 2 + jsf[i + offset]; if (u_i < 0) { ep_sub(r, r, t[-u_i]); } else { ep_add(r, r, t[u_i]); } } } ep_norm(r, r); } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { bn_free(n); bn_free(_k); bn_free(_m); for (i = 0; i < 5; i++) { ep_free(t[i]); } } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void ep_mul_sim_trick(ep_t r, const ep_t p, const bn_t k, const ep_t q, const bn_t m) { ep_t t0[1 << (EP_WIDTH / 2)], t1[1 << (EP_WIDTH / 2)], t[1 << EP_WIDTH]; bn_t n, _k, _m; size_t l0, l1, w = EP_WIDTH / 2; uint8_t w0[RLC_FP_BITS + 1], w1[RLC_FP_BITS + 1]; if (bn_is_zero(k) || ep_is_infty(p)) { ep_mul(r, q, m); return; } if (bn_is_zero(m) || ep_is_infty(q)) { ep_mul(r, p, k); return; } bn_null(n); bn_null(_k); bn_null(_m); RLC_TRY { bn_new(n); bn_new(_k); bn_new(_m); for (int i = 0; i < (1 << w); i++) { ep_null(t0[i]); ep_null(t1[i]); ep_new(t0[i]); ep_new(t1[i]); } for (int i = 0; i < (1 << EP_WIDTH); i++) { ep_null(t[i]); ep_new(t[i]); } ep_curve_get_ord(n); bn_mod(_k, k, n); bn_mod(_m, m, n); ep_set_infty(t0[0]); ep_copy(t0[1], p); if (bn_sign(_k) == RLC_NEG) { ep_neg(t0[1], t0[1]); } for (int i = 2; i < (1 << w); i++) { ep_add(t0[i], t0[i - 1], t0[1]); } ep_set_infty(t1[0]); ep_copy(t1[1], q); if (bn_sign(_m) == RLC_NEG) { ep_neg(t1[1], t1[1]); } for (int i = 2; i < (1 << w); i++) { ep_add(t1[i], t1[i - 1], t1[1]); } for (int i = 0; i < (1 << w); i++) { for (int j = 0; j < (1 << w); j++) { ep_add(t[(i << w) + j], t0[i], t1[j]); } } #if EP_WIDTH > 2 && defined(EP_MIXED) ep_norm_sim(t + 1, (const ep_t *)(t + 1), (1 << EP_WIDTH) - 1); #endif l0 = l1 = RLC_CEIL(RLC_FP_BITS + 1, w); bn_rec_win(w0, &l0, _k, w); bn_rec_win(w1, &l1, _m, w); for (int i = l0; i < l1; i++) { w0[i] = 0; } for (int i = l1; i < l0; i++) { w1[i] = 0; } ep_set_infty(r); for (int i = RLC_MAX(l0, l1) - 1; i >= 0; i--) { for (int j = 0; j < w; j++) { ep_dbl(r, r); } ep_add(r, r, t[(w0[i] << w) + w1[i]]); } ep_norm(r, r); } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { bn_free(n); bn_free(_k); bn_free(_m); for (int i = 0; i < (1 << w); i++) { ep_free(t0[i]); ep_free(t1[i]); } for (int i = 0; i < (1 << EP_WIDTH); i++) { ep_free(t[i]); } } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void ep_mul_sim_lot_plain(ep_t r, const ep_t p[], const bn_t k[], int n) { int i, j; int8_t *naf = NULL; ep_t *_p = RLC_ALLOCA(ep_t, n); size_t l, *_l = RLC_ALLOCA(size_t, n); RLC_TRY { l = 0; for (i = 0; i < n; i++) { l = RLC_MAX(l, bn_bits(k[i]) + 1); } naf = RLC_ALLOCA(int8_t, n * l); if (naf == NULL || _p == NULL || _l == NULL) { RLC_THROW(ERR_NO_MEMORY); } for (i = 0; i < n; i++) { ep_null(_p[i]); ep_new(_p[i]); } for (i = 0; i < n; i++) { _l[i] = l; ep_norm(_p[i], p[i]); bn_rec_naf(&naf[i*l], &_l[i], k[i], 2); if (bn_sign(k[i]) == RLC_NEG) { ep_neg(_p[i], _p[i]); } } ep_set_infty(r); for (i = l - 1; i >= 0; i--) { ep_dbl(r, r); for (j = 0; j < n; j++) { if (naf[j*l + i] > 0) { ep_add(r, r, _p[j]); } if (naf[j*l + i] < 0) { ep_sub(r, r, _p[j]); } } } /* Convert r to affine coordinates. */ ep_norm(r, r); } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { for (i = 0; i < n; i++) { ep_free(_p[i]); } RLC_FREE(_l); RLC_FREE(_p); RLC_FREE(naf); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void ep_read_bin(ep_t a, const uint8_t *bin, size_t len) { if (len == 1) { if (bin[0] == 0) { ep_set_infty(a); return; } else { RLC_THROW(ERR_NO_BUFFER); return; } } if (len != (RLC_FP_BYTES + 1) && len != (2 * RLC_FP_BYTES + 1)) { RLC_THROW(ERR_NO_BUFFER); return; } a->coord = BASIC; fp_set_dig(a->z, 1); fp_read_bin(a->x, bin + 1, RLC_FP_BYTES); if (len == RLC_FP_BYTES + 1) { switch(bin[0]) { case 2: fp_zero(a->y); break; case 3: fp_zero(a->y); fp_set_bit(a->y, 0, 1); break; default: RLC_THROW(ERR_NO_VALID); break; } ep_upk(a, a); } if (len == 2 * RLC_FP_BYTES + 1) { if (bin[0] == 4) { fp_read_bin(a->y, bin + RLC_FP_BYTES + 1, RLC_FP_BYTES); } else { RLC_THROW(ERR_NO_VALID); return; } } if (!ep_on_curve(a)) { RLC_THROW(ERR_NO_VALID); return; } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void ep_write_bin(uint8_t *bin, size_t len, const ep_t a, int pack) { ep_t t; ep_null(t); memset(bin, 0, len); if (ep_is_infty(a)) { if (len < 1) { RLC_THROW(ERR_NO_BUFFER); return; } else { return; } } RLC_TRY { ep_new(t); ep_norm(t, a); if (pack) { if (len < RLC_FP_BYTES + 1) { RLC_THROW(ERR_NO_BUFFER); } else { ep_pck(t, t); bin[0] = 2 | fp_get_bit(t->y, 0); fp_write_bin(bin + 1, RLC_FP_BYTES, t->x); } } else { if (len < 2 * RLC_FP_BYTES + 1) { RLC_THROW(ERR_NO_BUFFER); } else { bin[0] = 4; fp_write_bin(bin + 1, RLC_FP_BYTES, t->x); fp_write_bin(bin + RLC_FP_BYTES + 1, RLC_FP_BYTES, t->y); } } } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { ep_free(t); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void ep2_map(ep2_t p, const uint8_t *msg, size_t len) { ep2_map_dst(p, msg, len, (const uint8_t *)"RELIC", 5); }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void ep2_map_dst(ep2_t p, const uint8_t *msg, size_t len, const uint8_t *dst, size_t dst_len) { /* enough space for two field elements plus extra bytes for uniformity */ const int lpe = (FP_PRIME + ep_param_level() + 7) / 8; uint8_t *pseudo_random_bytes = RLC_ALLOCA(uint8_t, 4 * lpe); RLC_TRY { /* XXX(rsw) See note in ep/relic_ep_map.c about using MD_MAP. */ /* hash to a pseudorandom string using md_xmd */ md_xmd(pseudo_random_bytes, 4 * lpe, msg, len, dst, dst_len); ep2_map_from_field(p, pseudo_random_bytes, 2 * lpe); } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { RLC_FREE(pseudo_random_bytes); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void ep2_mul_dig(ep2_t r, const ep2_t p, const dig_t k) { ep2_t t; bn_t _k; int8_t u, naf[RLC_DIG + 1]; size_t l; ep2_null(t); bn_null(_k); if (k == 0 || ep2_is_infty(p)) { ep2_set_infty(r); return; } RLC_TRY { ep2_new(t); bn_new(_k); bn_set_dig(_k, k); l = RLC_DIG + 1; bn_rec_naf(naf, &l, _k, 2); ep2_set_infty(t); for (int i = l - 1; i >= 0; i--) { ep2_dbl(t, t); u = naf[i]; if (u > 0) { ep2_add(t, t, p); } else if (u < 0) { ep2_sub(t, t, p); } } ep2_norm(r, t); } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { ep2_free(t); bn_free(_k); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void ep2_mul_basic(ep2_t r, const ep2_t p, const bn_t k) { size_t l; ep2_t t; ep2_null(t); if (bn_is_zero(k) || ep2_is_infty(p)) { ep2_set_infty(r); return; } RLC_TRY { ep2_new(t); l = bn_bits(k); if (bn_get_bit(k, l - 1)) { ep2_copy(t, p); } else { ep2_set_infty(t); } for (int i = l - 2; i >= 0; i--) { ep2_dbl(t, t); if (bn_get_bit(k, i)) { ep2_add(t, t, p); } } ep2_copy(r, t); ep2_norm(r, r); if (bn_sign(k) == RLC_NEG) { ep2_neg(r, r); } } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { ep2_free(t); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void ep2_mul_slide(ep2_t r, const ep2_t p, const bn_t k) { ep2_t t[1 << (EP_WIDTH - 1)], q; uint8_t win[RLC_FP_BITS + 1]; size_t l; ep2_null(q); if (bn_is_zero(k) || ep2_is_infty(p)) { ep2_set_infty(r); return; } RLC_TRY { for (int i = 0; i < (1 << (EP_WIDTH - 1)); i ++) { ep2_null(t[i]); ep2_new(t[i]); } ep2_new(q); ep2_copy(t[0], p); ep2_dbl(q, p); #if defined(EP_MIXED) ep2_norm(q, q); #endif /* Create table. */ for (size_t i = 1; i < (1 << (EP_WIDTH - 1)); i++) { ep2_add(t[i], t[i - 1], q); } #if defined(EP_MIXED) ep2_norm_sim(t + 1, t + 1, (1 << (EP_WIDTH - 1)) - 1); #endif ep2_set_infty(q); l = RLC_FP_BITS + 1; bn_rec_slw(win, &l, k, EP_WIDTH); for (size_t i = 0; i < l; i++) { if (win[i] == 0) { ep2_dbl(q, q); } else { for (size_t j = 0; j < util_bits_dig(win[i]); j++) { ep2_dbl(q, q); } ep2_add(q, q, t[win[i] >> 1]); } } ep2_norm(r, q); if (bn_sign(k) == RLC_NEG) { ep2_neg(r, r); } } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { for (size_t i = 0; i < (1 << (EP_WIDTH - 1)); i++) { ep2_free(t[i]); } ep2_free(q); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
static void ep2_mul_naf_imp(ep2_t r, const ep2_t p, const bn_t k) { size_t l, n; int8_t naf[RLC_FP_BITS + 1]; ep2_t t[1 << (EP_WIDTH - 2)]; RLC_TRY { /* Prepare the precomputation table. */ for (int i = 0; i < (1 << (EP_WIDTH - 2)); i++) { ep2_null(t[i]); ep2_new(t[i]); } /* Compute the precomputation table. */ ep2_tab(t, p, EP_WIDTH); /* Compute the w-NAF representation of k. */ l = sizeof(naf); bn_rec_naf(naf, &l, k, EP_WIDTH); ep2_set_infty(r); for (int i = l - 1; i >= 0; i--) { ep2_dbl(r, r); n = naf[i]; if (n > 0) { ep2_add(r, r, t[n / 2]); } if (n < 0) { ep2_sub(r, r, t[-n / 2]); } } /* Convert r to affine coordinates. */ ep2_norm(r, r); if (bn_sign(k) == RLC_NEG) { ep2_neg(r, r); } } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { /* Free the precomputation table. */ for (int i = 0; i < (1 << (EP_WIDTH - 2)); i++) { ep2_free(t[i]); } } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
static void ep2_mul_glv_imp(ep2_t r, const ep2_t p, const bn_t k) { size_t l, _l[4]; bn_t n, _k[4], u; int8_t naf[4][RLC_FP_BITS + 1]; ep2_t q[4]; bn_null(n); bn_null(u); RLC_TRY { bn_new(n); bn_new(u); for (int i = 0; i < 4; i++) { bn_null(_k[i]); ep2_null(q[i]); bn_new(_k[i]); ep2_new(q[i]); } ep2_curve_get_ord(n); fp_prime_get_par(u); bn_mod(_k[0], k, n); bn_rec_frb(_k, 4, _k[0], u, n, ep_curve_is_pairf() == EP_BN); ep2_norm(q[0], p); ep2_frb(q[1], q[0], 1); ep2_frb(q[2], q[1], 1); ep2_frb(q[3], q[2], 1); l = 0; for (int i = 0; i < 4; i++) { if (bn_sign(_k[i]) == RLC_NEG) { ep2_neg(q[i], q[i]); } _l[i] = RLC_FP_BITS + 1; bn_rec_naf(naf[i], &_l[i], _k[i], 2); l = RLC_MAX(l, _l[i]); } ep2_set_infty(r); for (int j = l - 1; j >= 0; j--) { ep2_dbl(r, r); for (int i = 0; i < 4; i++) { if (naf[i][j] > 0) { ep2_add(r, r, q[i]); } if (naf[i][j] < 0) { ep2_sub(r, r, q[i]); } } } /* Convert r to affine coordinates. */ ep2_norm(r, r); } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { bn_free(n); bn_free(u); for (int i = 0; i < 4; i++) { bn_free(_k[i]); ep2_free(q[i]); } } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
static void ep2_mul_fix_plain(ep2_t r, const ep2_t *table, const bn_t k) { int8_t naf[2 * RLC_FP_BITS + 1], *t; size_t len; int n; if (bn_is_zero(k)) { ep2_set_infty(r); return; } /* Compute the w-TNAF representation of k. */ len = 2 * RLC_FP_BITS + 1; bn_rec_naf(naf, &len, k, EP_DEPTH); t = naf + len - 1; ep2_set_infty(r); for (int i = len - 1; i >= 0; i--, t--) { ep2_dbl(r, r); n = *t; if (n > 0) { ep2_add(r, r, table[n / 2]); } if (n < 0) { ep2_sub(r, r, table[-n / 2]); } } /* Convert r to affine coordinates. */ ep2_norm(r, r); if (bn_sign(k) == RLC_NEG) { ep2_neg(r, r); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void ep2_mul_sim_dig(ep2_t r, const ep2_t p[], const dig_t k[], size_t len) { ep2_t t; int max; ep2_null(t); max = util_bits_dig(k[0]); for (int i = 1; i < len; i++) { max = RLC_MAX(max, util_bits_dig(k[i])); } RLC_TRY { ep2_new(t); ep2_set_infty(t); for (int i = max - 1; i >= 0; i--) { ep2_dbl(t, t); for (int j = 0; j < len; j++) { if (k[j] & ((dig_t)1 << i)) { ep2_add(t, t, p[j]); } } } ep2_norm(r, t); } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { ep2_free(t); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
static void ep2_mul_sim_plain(ep2_t r, const ep2_t p, const bn_t k, const ep2_t q, const bn_t m, const ep2_t *t) { int i, n0, n1, w, gen; int8_t naf0[2 * RLC_FP_BITS + 1], naf1[2 * RLC_FP_BITS + 1], *_k, *_m; ep2_t t0[1 << (EP_WIDTH - 2)]; ep2_t t1[1 << (EP_WIDTH - 2)]; size_t l, l0, l1; RLC_TRY { gen = (t == NULL ? 0 : 1); if (!gen) { for (i = 0; i < (1 << (EP_WIDTH - 2)); i++) { ep2_null(t0[i]); ep2_new(t0[i]); } ep2_tab(t0, p, EP_WIDTH); t = (ep2_t *)t0; } /* Prepare the precomputation table. */ for (i = 0; i < (1 << (EP_WIDTH - 2)); i++) { ep2_null(t1[i]); ep2_new(t1[i]); } /* Compute the precomputation table. */ ep2_tab(t1, q, EP_WIDTH); /* Compute the w-TNAF representation of k. */ if (gen) { w = EP_DEPTH; } else { w = EP_WIDTH; } l0 = l1 = 2 * RLC_FP_BITS + 1; bn_rec_naf(naf0, &l0, k, w); bn_rec_naf(naf1, &l1, m, EP_WIDTH); l = RLC_MAX(l0, l1); _k = naf0 + l - 1; _m = naf1 + l - 1; if (bn_sign(k) == RLC_NEG) { for (i = 0; i < l0; i++) { naf0[i] = -naf0[i]; } } if (bn_sign(m) == RLC_NEG) { for (i = 0; i < l1; i++) { naf1[i] = -naf1[i]; } } ep2_set_infty(r); for (i = l - 1; i >= 0; i--, _k--, _m--) { ep2_dbl(r, r); n0 = *_k; n1 = *_m; if (n0 > 0) { ep2_add(r, r, t[n0 / 2]); } if (n0 < 0) { ep2_sub(r, r, t[-n0 / 2]); } if (n1 > 0) { ep2_add(r, r, t1[n1 / 2]); } if (n1 < 0) { ep2_sub(r, r, t1[-n1 / 2]); } } /* Convert r to affine coordinates. */ ep2_norm(r, r); } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { /* Free the precomputation tables. */ if (!gen) { for (i = 0; i < (1 << (EP_WIDTH - 2)); i++) { ep2_free(t0[i]); } } for (i = 0; i < (1 << (EP_WIDTH - 2)); i++) { ep2_free(t1[i]); } } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
static void ep2_mul_sim_endom(ep2_t r, const ep2_t p, const bn_t k, ep2_t q, const bn_t m) { size_t l, _l[4]; bn_t _k[4], _m[4], n, u; int8_t naf0[4][RLC_FP_BITS + 1]; int8_t naf1[4][RLC_FP_BITS + 1]; ep2_t _p[4], _q[4]; bn_null(n); bn_null(u); RLC_TRY { bn_new(n); bn_new(u); for (int i = 0; i < 4; i++) { bn_null(_k[i]); bn_new(_k[i]); bn_null(_m[i]); bn_new(_m[i]); ep2_null(_p[i]); ep2_null(_q[i]); ep2_new(_p[i]); ep2_new(_q[i]); } ep2_norm(_p[0], p); ep2_frb(_p[1], _p[0], 1); ep2_frb(_p[2], _p[1], 1); ep2_frb(_p[3], _p[2], 1); ep2_norm(_q[0], q); ep2_frb(_q[1], _q[0], 1); ep2_frb(_q[2], _q[1], 1); ep2_frb(_q[3], _q[2], 1); ep2_curve_get_ord(n); fp_prime_get_par(u); bn_mod(_k[0], k, n); bn_rec_frb(_k, 4, _k[0], u, n, ep_curve_is_pairf() == EP_BN); bn_mod(_m[0], m, n); bn_rec_frb(_m, 4, _m[0], u, n, ep_curve_is_pairf() == EP_BN); l = 0; for (int i = 0; i < 4; i++) { _l[i] = RLC_FP_BITS + 1; bn_rec_naf(naf0[i], &_l[i], _k[i], 2); if (bn_sign(_k[i]) == RLC_NEG) { ep2_neg(_p[i], _p[i]); } l = RLC_MAX(l, _l[i]); _l[i] = RLC_FP_BITS + 1; bn_rec_naf(naf1[i], &_l[i], _m[i], 2); if (bn_sign(_m[i]) == RLC_NEG) { ep2_neg(_q[i], _q[i]); } l = RLC_MAX(l, _l[i]); } ep2_set_infty(r); for (int i = l - 1; i >= 0; i--) { ep2_dbl(r, r); for (int j = 0; j < 4; j++) { if (naf0[j][i] > 0) { ep2_add(r, r, _p[j]); } if (naf0[j][i] < 0) { ep2_sub(r, r, _p[j]); } if (naf1[j][i] > 0) { ep2_add(r, r, _q[j]); } if (naf1[j][i] < 0) { ep2_sub(r, r, _q[j]); } } } /* Convert r to affine coordinates. */ ep2_norm(r, r); } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { bn_free(n); bn_free(u); for (int i = 0; i < 4; i++) { bn_free(_k[i]); bn_free(_m[i]); ep2_free(_p[i]); ep2_free(_q[i]); } } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void ep2_mul_sim_joint(ep2_t r, const ep2_t p, const bn_t k, const ep2_t q, const bn_t m) { bn_t n, _k, _m; ep2_t t[5]; int i, u_i, offset; int8_t jsf[2 * (RLC_FP_BITS + 1)]; size_t l; if (bn_is_zero(k) || ep2_is_infty(p)) { ep2_mul(r, q, m); return; } if (bn_is_zero(m) || ep2_is_infty(q)) { ep2_mul(r, p, k); return; } bn_null(n); bn_null(_k); bn_null(_m); RLC_TRY { bn_new(n); bn_new(_k); bn_new(_m); for (i = 0; i < 5; i++) { ep2_null(t[i]); ep2_new(t[i]); } ep2_curve_get_ord(n); bn_mod(_k, k, n); bn_mod(_m, m, n); ep2_set_infty(t[0]); ep2_copy(t[1], q); if (bn_sign(_m) == RLC_NEG) { ep2_neg(t[1], t[1]); } ep2_copy(t[2], p); if (bn_sign(_k) == RLC_NEG) { ep2_neg(t[2], t[2]); } ep2_add(t[3], t[2], t[1]); ep2_sub(t[4], t[2], t[1]); #if defined(EP_MIXED) ep2_norm_sim(t + 3, t + 3, 2); #endif l = 2 * (RLC_FP_BITS + 1); bn_rec_jsf(jsf, &l, _k, _m); ep2_set_infty(r); offset = RLC_MAX(bn_bits(_k), bn_bits(_m)) + 1; for (i = l - 1; i >= 0; i--) { ep2_dbl(r, r); if (jsf[i] != 0 && jsf[i] == -jsf[i + offset]) { u_i = jsf[i] * 2 + jsf[i + offset]; if (u_i < 0) { ep2_sub(r, r, t[4]); } else { ep2_add(r, r, t[4]); } } else { u_i = jsf[i] * 2 + jsf[i + offset]; if (u_i < 0) { ep2_sub(r, r, t[-u_i]); } else { ep2_add(r, r, t[u_i]); } } } ep2_norm(r, r); } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { bn_free(n); bn_free(_k); bn_free(_m); for (i = 0; i < 5; i++) { ep2_free(t[i]); } } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void ep2_write_bin(uint8_t *bin, size_t len, const ep2_t a, int pack) { ep2_t t; ep2_null(t); memset(bin, 0, len); if (ep2_is_infty(a)) { if (len < 1) { RLC_THROW(ERR_NO_BUFFER); return; } else { return; } } RLC_TRY { ep2_new(t); ep2_norm(t, a); if (pack) { if (len < 2 * RLC_FP_BYTES + 1) { RLC_THROW(ERR_NO_BUFFER); } else { ep2_pck(t, t); bin[0] = 2 | fp_get_bit(t->y[0], 0); fp2_write_bin(bin + 1, 2 * RLC_FP_BYTES, t->x, 0); } } else { if (len < 4 * RLC_FP_BYTES + 1) { RLC_THROW(ERR_NO_BUFFER); } else { bin[0] = 4; fp2_write_bin(bin + 1, 2 * RLC_FP_BYTES, t->x, 0); fp2_write_bin(bin + 2 * RLC_FP_BYTES + 1, 2 * RLC_FP_BYTES, t->y, 0); } } } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { ep2_free(t); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void ep2_read_bin(ep2_t a, const uint8_t *bin, size_t len) { if (len == 1) { if (bin[0] == 0) { ep2_set_infty(a); return; } else { RLC_THROW(ERR_NO_BUFFER); return; } } if (len != (2 * RLC_FP_BYTES + 1) && len != (4 * RLC_FP_BYTES + 1)) { RLC_THROW(ERR_NO_BUFFER); return; } a->coord = BASIC; fp2_set_dig(a->z, 1); fp2_read_bin(a->x, bin + 1, 2 * RLC_FP_BYTES); if (len == 2 * RLC_FP_BYTES + 1) { switch(bin[0]) { case 2: fp2_zero(a->y); break; case 3: fp2_zero(a->y); fp_set_bit(a->y[0], 0, 1); fp_zero(a->y[1]); break; default: RLC_THROW(ERR_NO_VALID); break; } ep2_upk(a, a); } if (len == 4 * RLC_FP_BYTES + 1) { if (bin[0] == 4) { fp2_read_bin(a->y, bin + 2 * RLC_FP_BYTES + 1, 2 * RLC_FP_BYTES); } else { RLC_THROW(ERR_NO_VALID); return; } } if (!ep2_on_curve(a)) { RLC_THROW(ERR_NO_VALID); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void ep4_map(ep4_t p, const uint8_t *msg, size_t len) { bn_t x; fp4_t t0; uint8_t digest[RLC_MD_LEN]; bn_null(x); fp4_null(t0); RLC_TRY { bn_new(x); fp4_new(t0); md_map(digest, msg, len); bn_read_bin(x, digest, RLC_MIN(RLC_FP_BYTES, RLC_MD_LEN)); fp4_zero(p->x); fp_prime_conv(p->x[0][0], x); fp4_set_dig(p->z, 1); while (1) { ep4_rhs(t0, p); if (fp4_srt(p->y, t0)) { p->coord = BASIC; break; } fp_add_dig(p->x[0][0], p->x[0][0], 1); } ep4_mul_cof(p, p); } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { bn_free(x); fp4_free(t0); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
static void ep4_mul_naf_imp(ep4_t r, const ep4_t p, const bn_t k) { int i, n; int8_t naf[RLC_FP_BITS + 1]; ep4_t t[1 << (EP_WIDTH - 2)]; size_t l; RLC_TRY { /* Prepare the precomputation table. */ for (i = 0; i < (1 << (EP_WIDTH - 2)); i++) { ep4_null(t[i]); ep4_new(t[i]); } /* Compute the precomputation table. */ ep4_tab(t, p, EP_WIDTH); /* Compute the w-NAF representation of k. */ l = sizeof(naf); bn_rec_naf(naf, &l, k, EP_WIDTH); ep4_set_infty(r); for (i = l - 1; i >= 0; i--) { ep4_dbl(r, r); n = naf[i]; if (n > 0) { ep4_add(r, r, t[n / 2]); } if (n < 0) { ep4_sub(r, r, t[-n / 2]); } } /* Convert r to affine coordinates. */ ep4_norm(r, r); if (bn_sign(k) == RLC_NEG) { ep4_neg(r, r); } } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { /* Free the precomputation table. */ for (i = 0; i < (1 << (EP_WIDTH - 2)); i++) { ep4_free(t[i]); } } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
static void ep4_mul_glv_imp(ep4_t r, const ep4_t p, const bn_t k) { int sign, i, j; bn_t n, _k[8], u, v; int8_t naf[8][RLC_FP_BITS + 1]; ep4_t q[8]; size_t l, _l[8]; bn_null(n); bn_null(u); bn_null(v); RLC_TRY { bn_new(n); bn_new(u); bn_new(v); for (i = 0; i < 8; i++) { bn_null(_k[i]); ep4_null(q[i]); bn_new(_k[i]); ep4_new(q[i]); } bn_abs(v, k); ep4_curve_get_ord(n); if (bn_cmp_abs(v, n) == RLC_GT) { bn_mod(v, v, n); } fp_prime_get_par(u); sign = bn_sign(u); bn_abs(u, u); ep4_norm(q[0], p); for (i = 0; i < 8; i++) { bn_mod(_k[i], v, u); bn_div(v, v, u); if ((sign == RLC_NEG) && (i % 2 != 0)) { bn_neg(_k[i], _k[i]); } if (bn_sign(k) == RLC_NEG) { bn_neg(_k[i], _k[i]); } if (i > 0) { ep4_frb(q[i], q[i - 1], 1); } } l = 0; for (i = 0; i < 8; i++) { if (bn_sign(_k[i]) == RLC_NEG) { ep4_neg(q[i], q[i]); } _l[i] = RLC_FP_BITS + 1; bn_rec_naf(naf[i], &_l[i], _k[i], 2); l = RLC_MAX(l, _l[i]); } ep4_set_infty(r); for (j = l - 1; j >= 0; j--) { ep4_dbl(r, r); for (i = 0; i < 8; i++) { if (naf[i][j] > 0) { ep4_add(r, r, q[i]); } if (naf[i][j] < 0) { ep4_sub(r, r, q[i]); } } } /* Convert r to affine coordinates. */ ep4_norm(r, r); } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { bn_free(n); bn_free(u); bn_free(v); for (i = 0; i < 8; i++) { bn_free(_k[i]); ep4_free(q[i]); } } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void ep4_mul_slide(ep4_t r, const ep4_t p, const bn_t k) { ep4_t t[1 << (EP_WIDTH - 1)], q; uint8_t win[RLC_FP_BITS + 1]; size_t l; ep4_null(q); if (bn_is_zero(k) || ep4_is_infty(p)) { ep4_set_infty(r); return; } RLC_TRY { for (size_t i = 0; i < (1 << (EP_WIDTH - 1)); i ++) { ep4_null(t[i]); ep4_new(t[i]); } ep4_new(q); ep4_copy(t[0], p); ep4_dbl(q, p); #if defined(EP_MIXED) ep4_norm(q, q); #endif /* Create table. */ for (size_t i = 1; i < (1 << (EP_WIDTH - 1)); i++) { ep4_add(t[i], t[i - 1], q); } #if defined(EP_MIXED) ep4_norm_sim(t + 1, t + 1, (1 << (EP_WIDTH - 1)) - 1); #endif ep4_set_infty(q); l = RLC_FP_BITS + 1; bn_rec_slw(win, &l, k, EP_WIDTH); for (size_t i = 0; i < l; i++) { if (win[i] == 0) { ep4_dbl(q, q); } else { for (size_t j = 0; j < util_bits_dig(win[i]); j++) { ep4_dbl(q, q); } ep4_add(q, q, t[win[i] >> 1]); } } ep4_norm(r, q); if (bn_sign(k) == RLC_NEG) { ep4_neg(r, r); } } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { for (size_t i = 0; i < (1 << (EP_WIDTH - 1)); i++) { ep4_free(t[i]); } ep4_free(q); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
static void ep4_mul_pre_ordin(ep4_t *t, const ep4_t p) { ep4_dbl(t[0], p); #if defined(EP_MIXED) ep4_norm(t[0], t[0]); #endif #if EP_DEPTH > 2 ep4_add(t[1], t[0], p); for (int i = 2; i < (1 << (EP_DEPTH - 2)); i++) { ep4_add(t[i], t[i - 1], t[0]); } #if defined(EP_MIXED) for (int i = 1; i < (1 << (EP_DEPTH - 2)); i++) { ep4_norm(t[i], t[i]); } #endif #endif ep4_copy(t[0], p); }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
static void ep4_mul_fix_ordin(ep4_t r, const ep4_t *table, const bn_t k) { int8_t naf[2 * RLC_FP_BITS + 1], *t; size_t len; int n; if (bn_is_zero(k)) { ep4_set_infty(r); return; } /* Compute the w-TNAF representation of k. */ len = 2 * RLC_FP_BITS + 1; bn_rec_naf(naf, &len, k, EP_DEPTH); t = naf + len - 1; ep4_set_infty(r); for (int i = len - 1; i >= 0; i--, t--) { ep4_dbl(r, r); n = *t; if (n > 0) { ep4_add(r, r, table[n / 2]); } if (n < 0) { ep4_sub(r, r, table[-n / 2]); } } /* Convert r to affine coordinates. */ ep4_norm(r, r); if (bn_sign(k) == RLC_NEG) { ep4_neg(r, r); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void ep4_mul_sim_trick(ep4_t r, const ep4_t p, const bn_t k, const ep4_t q, const bn_t m) { ep4_t t0[1 << (EP_WIDTH / 2)]; ep4_t t1[1 << (EP_WIDTH / 2)]; ep4_t t[1 << EP_WIDTH]; bn_t n; size_t l0, l1, w = EP_WIDTH / 2; uint8_t w0[2 * RLC_FP_BITS], w1[2 * RLC_FP_BITS]; bn_null(n); if (bn_is_zero(k) || ep4_is_infty(p)) { ep4_mul(r, q, m); return; } if (bn_is_zero(m) || ep4_is_infty(q)) { ep4_mul(r, p, k); return; } RLC_TRY { bn_new(n); ep4_curve_get_ord(n); for (int i = 0; i < (1 << w); i++) { ep4_null(t0[i]); ep4_null(t1[i]); ep4_new(t0[i]); ep4_new(t1[i]); } for (int i = 0; i < (1 << EP_WIDTH); i++) { ep4_null(t[i]); ep4_new(t[i]); } ep4_set_infty(t0[0]); ep4_copy(t0[1], p); if (bn_sign(k) == RLC_NEG) { ep4_neg(t0[1], t0[1]); } for (int i = 2; i < (1 << w); i++) { ep4_add(t0[i], t0[i - 1], t0[1]); } ep4_set_infty(t1[0]); ep4_copy(t1[1], q); if (bn_sign(m) == RLC_NEG) { ep4_neg(t1[1], t1[1]); } for (int i = 1; i < (1 << w); i++) { ep4_add(t1[i], t1[i - 1], t1[1]); } for (int i = 0; i < (1 << w); i++) { for (int j = 0; j < (1 << w); j++) { ep4_add(t[(i << w) + j], t0[i], t1[j]); } } #if defined(EP_MIXED) ep4_norm_sim(t + 1, t + 1, (1 << (EP_WIDTH)) - 1); #endif l0 = l1 = RLC_CEIL(2 * RLC_FP_BITS, w); bn_rec_win(w0, &l0, k, w); bn_rec_win(w1, &l1, m, w); for (int i = l0; i < l1; i++) { w0[i] = 0; } for (int i = l1; i < l0; i++) { w1[i] = 0; } ep4_set_infty(r); for (int i = RLC_MAX(l0, l1) - 1; i >= 0; i--) { for (int j = 0; j < w; j++) { ep4_dbl(r, r); } ep4_add(r, r, t[(w0[i] << w) + w1[i]]); } ep4_norm(r, r); } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { bn_free(n); for (int i = 0; i < (1 << w); i++) { ep4_free(t0[i]); ep4_free(t1[i]); } for (int i = 0; i < (1 << EP_WIDTH); i++) { ep4_free(t[i]); } } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void ep4_mul_sim_dig(ep4_t r, const ep4_t p[], const dig_t k[], size_t len) { ep4_t t; int max; ep4_null(t); max = util_bits_dig(k[0]); for (int i = 1; i < len; i++) { max = RLC_MAX(max, util_bits_dig(k[i])); } RLC_TRY { ep4_new(t); ep4_set_infty(t); for (int i = max - 1; i >= 0; i--) { ep4_dbl(t, t); for (int j = 0; j < len; j++) { if (k[j] & ((dig_t)1 << i)) { ep4_add(t, t, p[j]); } } } ep4_norm(r, t); } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { ep4_free(t); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void ep4_mul_sim_joint(ep4_t r, const ep4_t p, const bn_t k, const ep4_t q, const bn_t m) { ep4_t t[5]; int i, u_i, offset; int8_t jsf[4 * (RLC_FP_BITS + 1)]; size_t l; if (bn_is_zero(k) || ep4_is_infty(p)) { ep4_mul(r, q, m); return; } if (bn_is_zero(m) || ep4_is_infty(q)) { ep4_mul(r, p, k); return; } RLC_TRY { for (i = 0; i < 5; i++) { ep4_null(t[i]); ep4_new(t[i]); } ep4_set_infty(t[0]); ep4_copy(t[1], q); if (bn_sign(m) == RLC_NEG) { ep4_neg(t[1], t[1]); } ep4_copy(t[2], p); if (bn_sign(k) == RLC_NEG) { ep4_neg(t[2], t[2]); } ep4_add(t[3], t[2], t[1]); ep4_sub(t[4], t[2], t[1]); #if defined(EP_MIXED) ep4_norm_sim(t + 3, t + 3, 2); #endif l = 4 * (RLC_FP_BITS + 1); bn_rec_jsf(jsf, &l, k, m); ep4_set_infty(r); offset = RLC_MAX(bn_bits(k), bn_bits(m)) + 1; for (i = l - 1; i >= 0; i--) { ep4_dbl(r, r); if (jsf[i] != 0 && jsf[i] == -jsf[i + offset]) { u_i = jsf[i] * 2 + jsf[i + offset]; if (u_i < 0) { ep4_sub(r, r, t[4]); } else { ep4_add(r, r, t[4]); } } else { u_i = jsf[i] * 2 + jsf[i + offset]; if (u_i < 0) { ep4_sub(r, r, t[-u_i]); } else { ep4_add(r, r, t[u_i]); } } } ep4_norm(r, r); } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { for (i = 0; i < 5; i++) { ep4_free(t[i]); } } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
static void ep4_mul_sim_plain(ep4_t r, const ep4_t p, const bn_t k, const ep4_t q, const bn_t m, ep4_t *t) { int i, n0, n1, w, gen; int8_t naf0[2 * RLC_FP_BITS + 1], naf1[2 * RLC_FP_BITS + 1], *_k, *_m; ep4_t t0[1 << (EP_WIDTH - 2)]; ep4_t t1[1 << (EP_WIDTH - 2)]; size_t l, l0, l1; RLC_TRY { gen = (t == NULL ? 0 : 1); if (!gen) { for (i = 0; i < (1 << (EP_WIDTH - 2)); i++) { ep4_null(t0[i]); ep4_new(t0[i]); } ep4_tab(t0, p, EP_WIDTH); t = (ep4_t *)t0; } /* Prepare the precomputation table. */ for (i = 0; i < (1 << (EP_WIDTH - 2)); i++) { ep4_null(t1[i]); ep4_new(t1[i]); } /* Compute the precomputation table. */ ep4_tab(t1, q, EP_WIDTH); /* Compute the w-TNAF representation of k. */ if (gen) { w = EP_DEPTH; } else { w = EP_WIDTH; } l0 = l1 = 2 * RLC_FP_BITS + 1; bn_rec_naf(naf0, &l0, k, w); bn_rec_naf(naf1, &l1, m, EP_WIDTH); l = RLC_MAX(l0, l1); _k = naf0 + l - 1; _m = naf1 + l - 1; if (bn_sign(k) == RLC_NEG) { for (i = 0; i < l0; i++) { naf0[i] = -naf0[i]; } } if (bn_sign(m) == RLC_NEG) { for (i = 0; i < l1; i++) { naf1[i] = -naf1[i]; } } ep4_set_infty(r); for (i = l - 1; i >= 0; i--, _k--, _m--) { ep4_dbl(r, r); n0 = *_k; n1 = *_m; if (n0 > 0) { ep4_add(r, r, t[n0 / 2]); } if (n0 < 0) { ep4_sub(r, r, t[-n0 / 2]); } if (n1 > 0) { ep4_add(r, r, t1[n1 / 2]); } if (n1 < 0) { ep4_sub(r, r, t1[-n1 / 2]); } } /* Convert r to affine coordinates. */ ep4_norm(r, r); } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { /* Free the precomputation tables. */ if (!gen) { for (i = 0; i < (1 << (EP_WIDTH - 2)); i++) { ep4_free(t0[i]); } } for (i = 0; i < (1 << (EP_WIDTH - 2)); i++) { ep4_free(t1[i]); } } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void ep4_read_bin(ep4_t a, const uint8_t *bin, size_t len) { if (len == 1) { if (bin[0] == 0) { ep4_set_infty(a); return; } else { RLC_THROW(ERR_NO_BUFFER); return; } } if (len != (8 * RLC_FP_BYTES + 1)) { RLC_THROW(ERR_NO_BUFFER); return; } a->coord = BASIC; fp4_set_dig(a->z, 1); fp4_read_bin(a->x, bin + 1, 4 * RLC_FP_BYTES); if (len == 8 * RLC_FP_BYTES + 1) { if (bin[0] == 4) { fp4_read_bin(a->y, bin + 4 * RLC_FP_BYTES + 1, 4 * RLC_FP_BYTES); } else { RLC_THROW(ERR_NO_VALID); return; } } if (!ep4_on_curve(a)) { RLC_THROW(ERR_NO_VALID); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void ep4_write_bin(uint8_t *bin, size_t len, const ep4_t a, int pack) { ep4_t t; ep4_null(t); memset(bin, 0, len); if (ep4_is_infty(a)) { if (len < 1) { RLC_THROW(ERR_NO_BUFFER); return; } else { return; } } RLC_TRY { ep4_new(t); ep4_norm(t, a); if (len < 8 * RLC_FP_BYTES + 1) { RLC_THROW(ERR_NO_BUFFER); } else { bin[0] = 4; fp4_write_bin(bin + 1, 4 * RLC_FP_BYTES, t->x); fp4_write_bin(bin + 4 * RLC_FP_BYTES + 1, 4 * RLC_FP_BYTES, t->y); } } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { ep4_free(t); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void fb_exp_basic(fb_t c, const fb_t a, const bn_t b) { size_t l; fb_t r; if (bn_is_zero(b)) { fb_set_dig(c, 1); return; } fb_null(r); RLC_TRY { fb_new(r); l = bn_bits(b); fb_copy(r, a); for (int i = l - 2; i >= 0; i--) { fb_sqr(r, r); if (bn_get_bit(b, i)) { fb_mul(r, r, a); } } if (bn_sign(b) == RLC_NEG) { fb_inv(c, r); } else { fb_copy(c, r); } } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { fb_free(r); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void fb_exp_slide(fb_t c, const fb_t a, const bn_t b) { fb_t t[1 << (FB_WIDTH - 1)], r; uint8_t win[RLC_FB_BITS + 1]; size_t l; fb_null(r); if (bn_is_zero(b)) { fb_set_dig(c, 1); return; } /* Initialize table. */ for (size_t i = 0; i < (1 << (FB_WIDTH - 1)); i++) { fb_null(t[i]); } RLC_TRY { for (size_t i = 0; i < (1 << (FB_WIDTH - 1)); i ++) { fb_new(t[i]); } fb_new(r); fb_copy(t[0], a); fb_sqr(r, a); /* Create table. */ for (size_t i = 1; i < 1 << (FB_WIDTH - 1); i++) { fb_mul(t[i], t[i - 1], r); } fb_set_dig(r, 1); l = RLC_FB_BITS + 1; bn_rec_slw(win, &l, b, FB_WIDTH); for (size_t i = 0; i < l; i++) { if (win[i] == 0) { fb_sqr(r, r); } else { for (size_t j = 0; j < util_bits_dig(win[i]); j++) { fb_sqr(r, r); } fb_mul(r, r, t[win[i] >> 1]); } } if (bn_sign(b) == RLC_NEG) { fb_inv(c, r); } else { fb_copy(c, r); } } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { for (size_t i = 0; i < (1 << (FB_WIDTH - 1)); i++) { fb_free(t[i]); } fb_free(r); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
static int valid_radix(unsigned int radix) { while (radix > 0) { if (radix != 1 && radix % 2 == 1) return 0; radix = radix / 2; } return 1; }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
size_t fb_size_str(const fb_t a, unsigned int radix) { bn_t t; size_t digits = 0; bn_null(t); if (!valid_radix(radix)) { RLC_THROW(ERR_NO_VALID); return 0; } RLC_TRY { bn_new(t); bn_read_raw(t, a, RLC_FB_DIGS); digits = bn_size_str(t, radix); } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { bn_free(t); } return digits; }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void fb_print(const fb_t a) { /* Suppress possible unused parameter warning. */ (void)a; for (int i = RLC_FB_DIGS - 1; i > 0; i--) { util_print_dig(a[i], 1); util_print(" "); } util_print_dig(a[0], 1); util_print("\n"); }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void fb_write_bin(uint8_t *bin, size_t len, const fb_t a) { bn_t t; bn_null(t); if (len != RLC_FB_BYTES) { RLC_THROW(ERR_NO_BUFFER); return; } RLC_TRY { bn_new(t); bn_read_raw(t, a, RLC_FB_DIGS); bn_write_bin(bin, len, t); } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { bn_free(t); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void fb_set_bit(fb_t a, size_t bit, int value) { int d; dig_t mask; RLC_RIP(bit, d, bit); mask = (dig_t)1 << bit; if (value == 1) { a[d] |= mask; } else { a[d] &= ~mask; } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
static int log_radix(unsigned int radix) { int l = 0; while (radix > 0) { radix = radix / 2; l++; } return --l; }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void fb_read_bin(fb_t a, const uint8_t *bin, size_t len) { bn_t t; bn_null(t); if (len != RLC_FB_BYTES) { RLC_THROW(ERR_NO_BUFFER); return; } RLC_TRY { bn_new(t); bn_read_bin(t, bin, len); fb_copy(a, t->dp); } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { bn_free(t); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void fb_rand(fb_t a) { size_t bits, digits; rand_bytes((uint8_t *)a, RLC_FB_DIGS * sizeof(dig_t)); RLC_RIP(bits, digits, RLC_FB_BITS); if (bits > 0) { dig_t mask = RLC_MASK(bits); a[RLC_FB_DIGS - 1] &= mask; } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void fb_write_str(char *str, size_t len, const fb_t a, unsigned int radix) { fb_t t; int d, l, i, j; char c; fb_null(t); l = fb_size_str(a, radix); if (len < l) { RLC_THROW(ERR_NO_BUFFER); return; } len = l; l = log_radix(radix); if (!valid_radix(radix)) { RLC_THROW(ERR_NO_VALID); return; } if (fb_is_zero(a) == 1) { *str++ = '0'; *str = '\0'; return; } RLC_TRY { fb_new(t); fb_copy(t, a); j = 0; while (!fb_is_zero(t)) { d = t[0] % radix; fb_rshb_low(t, t, l); str[j] = util_conv_char(d); j++; } /* Reverse the digits of the string. */ i = 0; j = len - 2; while (i < j) { c = str[i]; str[i] = str[j]; str[j] = c; ++i; --j; } str[len - 1] = '\0'; } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { fb_free(t); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
int fb_get_bit(const fb_t a, size_t bit) { int d; RLC_RIP(bit, d, bit); return (a[d] >> bit) & 1; }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
size_t fb_bits(const fb_t a) { int i = RLC_FB_DIGS - 1; while (i >= 0 && a[i] == 0) { i--; } if (i > 0) { return (i << RLC_DIG_LOG) + util_bits_dig(a[i]); } else { return util_bits_dig(a[0]); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void fb_read_str(fb_t a, const char *str, size_t len, unsigned int radix) { bn_t t; bn_null(t); if (!valid_radix(radix)) { RLC_THROW(ERR_NO_VALID); } RLC_TRY { bn_new(t); bn_read_str(t, str, len, radix); if (bn_bits(t) > RLC_FB_BITS) { RLC_THROW(ERR_NO_BUFFER); } fb_zero(a); dv_copy(a, t->dp, t->used); } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { bn_free(t); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void fp_exp_basic(fp_t c, const fp_t a, const bn_t b) { size_t l; fp_t r; fp_null(r); if (bn_is_zero(b)) { fp_set_dig(c, 1); return; } RLC_TRY { fp_new(r); l = bn_bits(b); fp_copy(r, a); for (int i = l - 2; i >= 0; i--) { fp_sqr(r, r); if (bn_get_bit(b, i)) { fp_mul(r, r, a); } } if (bn_sign(b) == RLC_NEG) { fp_inv(c, r); } else { fp_copy(c, r); } } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { fp_free(r); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void fp_exp_slide(fp_t c, const fp_t a, const bn_t b) { fp_t t[1 << (FP_WIDTH - 1)], r; uint8_t win[RLC_FP_BITS + 1]; size_t l; fp_null(r); if (bn_is_zero(b)) { fp_set_dig(c, 1); return; } /* Initialize table. */ for (size_t i = 0; i < (1 << (FP_WIDTH - 1)); i++) { fp_null(t[i]); } RLC_TRY { for (size_t i = 0; i < (1 << (FP_WIDTH - 1)); i ++) { fp_new(t[i]); } fp_new(r); fp_copy(t[0], a); fp_sqr(r, a); /* Create table. */ for (size_t i = 1; i < 1 << (FP_WIDTH - 1); i++) { fp_mul(t[i], t[i - 1], r); } fp_set_dig(r, 1); l = RLC_FP_BITS + 1; bn_rec_slw(win, &l, b, FP_WIDTH); for (size_t i = 0; i < l; i++) { if (win[i] == 0) { fp_sqr(r, r); } else { for (size_t j = 0; j < util_bits_dig(win[i]); j++) { fp_sqr(r, r); } fp_mul(r, r, t[win[i] >> 1]); } } if (bn_sign(b) == RLC_NEG) { fp_inv(c, r); } else { fp_copy(c, r); } } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { for (size_t i = 0; i < (1 << (FP_WIDTH - 1)); i++) { fp_free(t[i]); } fp_free(r); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void fp_prime_set_pmers(const int *f, size_t len) { bn_t p, t; bn_null(p); bn_null(t); RLC_TRY { bn_new(p); bn_new(t); if (len >= RLC_TERMS) { RLC_THROW(ERR_NO_VALID); return; } bn_set_2b(p, f[len - 1]); for (int i = len - 2; i > 0; i--) { if (f[i] > 0) { bn_set_2b(t, f[i]); bn_add(p, p, t); } else { bn_set_2b(t, -f[i]); bn_sub(p, p, t); } } if (f[0] > 0) { bn_add_dig(p, p, f[0]); } else { bn_sub_dig(p, p, -f[0]); } #if FP_RDC == QUICK || !defined(STRIP) ctx_t *ctx = core_get(); for (int i = 0; i < len; i++) { ctx->sps[i] = f[i]; } ctx->sps[len] = 0; ctx->sps_len = len; #endif /* FP_RDC == QUICK */ fp_prime_set(p); } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { bn_free(p); bn_free(t); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void fp_write_str(char *str, size_t len, const fp_t a, unsigned int radix) { bn_t t; bn_null(t); RLC_TRY { bn_new(t); fp_prime_back(t, a); bn_write_str(str, len, t, radix); } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { bn_free(t); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe
void fp_read_bin(fp_t a, const uint8_t *bin, size_t len) { bn_t t; bn_null(t); if (len != RLC_FP_BYTES) { RLC_THROW(ERR_NO_BUFFER); return; } RLC_TRY { bn_new(t); bn_read_bin(t, bin, len); /* Reject values out of bounds. */ if (bn_sign(t) == RLC_NEG || bn_cmp(t, &core_get()->prime) != RLC_LT) { RLC_THROW(ERR_NO_VALID); } else { if (bn_is_zero(t)) { fp_zero(a); } else { if (t->used == 1) { fp_prime_conv_dig(a, t->dp[0]); } else { fp_prime_conv(a, t); } } } } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { bn_free(t); } }
1
C
CWE-190
Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
https://cwe.mitre.org/data/definitions/190.html
safe