Merge pull request #8761 from valeriosetti/issue4681
Re-introduce enum-like checks from CHECK_PARAMS
This commit is contained in:
commit
137e0c1a02
10 changed files with 34 additions and 164 deletions
|
@ -678,7 +678,6 @@ int MBEDTLS_DEPRECATED mbedtls_cipher_setup_psa(mbedtls_cipher_context_t *ctx,
|
|||
static inline unsigned int mbedtls_cipher_get_block_size(
|
||||
const mbedtls_cipher_context_t *ctx)
|
||||
{
|
||||
MBEDTLS_INTERNAL_VALIDATE_RET(ctx != NULL, 0);
|
||||
if (ctx->MBEDTLS_PRIVATE(cipher_info) == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
@ -698,7 +697,6 @@ static inline unsigned int mbedtls_cipher_get_block_size(
|
|||
static inline mbedtls_cipher_mode_t mbedtls_cipher_get_cipher_mode(
|
||||
const mbedtls_cipher_context_t *ctx)
|
||||
{
|
||||
MBEDTLS_INTERNAL_VALIDATE_RET(ctx != NULL, MBEDTLS_MODE_NONE);
|
||||
if (ctx->MBEDTLS_PRIVATE(cipher_info) == NULL) {
|
||||
return MBEDTLS_MODE_NONE;
|
||||
}
|
||||
|
@ -719,7 +717,6 @@ static inline mbedtls_cipher_mode_t mbedtls_cipher_get_cipher_mode(
|
|||
static inline int mbedtls_cipher_get_iv_size(
|
||||
const mbedtls_cipher_context_t *ctx)
|
||||
{
|
||||
MBEDTLS_INTERNAL_VALIDATE_RET(ctx != NULL, 0);
|
||||
if (ctx->MBEDTLS_PRIVATE(cipher_info) == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
@ -743,8 +740,6 @@ static inline int mbedtls_cipher_get_iv_size(
|
|||
static inline mbedtls_cipher_type_t mbedtls_cipher_get_type(
|
||||
const mbedtls_cipher_context_t *ctx)
|
||||
{
|
||||
MBEDTLS_INTERNAL_VALIDATE_RET(
|
||||
ctx != NULL, MBEDTLS_CIPHER_NONE);
|
||||
if (ctx->MBEDTLS_PRIVATE(cipher_info) == NULL) {
|
||||
return MBEDTLS_CIPHER_NONE;
|
||||
}
|
||||
|
@ -764,7 +759,6 @@ static inline mbedtls_cipher_type_t mbedtls_cipher_get_type(
|
|||
static inline const char *mbedtls_cipher_get_name(
|
||||
const mbedtls_cipher_context_t *ctx)
|
||||
{
|
||||
MBEDTLS_INTERNAL_VALIDATE_RET(ctx != NULL, 0);
|
||||
if (ctx->MBEDTLS_PRIVATE(cipher_info) == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
@ -784,8 +778,6 @@ static inline const char *mbedtls_cipher_get_name(
|
|||
static inline int mbedtls_cipher_get_key_bitlen(
|
||||
const mbedtls_cipher_context_t *ctx)
|
||||
{
|
||||
MBEDTLS_INTERNAL_VALIDATE_RET(
|
||||
ctx != NULL, MBEDTLS_KEY_LENGTH_NONE);
|
||||
if (ctx->MBEDTLS_PRIVATE(cipher_info) == NULL) {
|
||||
return MBEDTLS_KEY_LENGTH_NONE;
|
||||
}
|
||||
|
@ -805,8 +797,6 @@ static inline int mbedtls_cipher_get_key_bitlen(
|
|||
static inline mbedtls_operation_t mbedtls_cipher_get_operation(
|
||||
const mbedtls_cipher_context_t *ctx)
|
||||
{
|
||||
MBEDTLS_INTERNAL_VALIDATE_RET(
|
||||
ctx != NULL, MBEDTLS_OPERATION_NONE);
|
||||
if (ctx->MBEDTLS_PRIVATE(cipher_info) == NULL) {
|
||||
return MBEDTLS_OPERATION_NONE;
|
||||
}
|
||||
|
|
|
@ -23,10 +23,6 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Internal macros meant to be called only from within the library. */
|
||||
#define MBEDTLS_INTERNAL_VALIDATE_RET(cond, ret) do { } while (0)
|
||||
#define MBEDTLS_INTERNAL_VALIDATE(cond) do { } while (0)
|
||||
|
||||
/* Internal helper macros for deprecating API constants. */
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
#if defined(MBEDTLS_DEPRECATED_WARNING)
|
||||
|
|
|
@ -25,12 +25,6 @@
|
|||
|
||||
#include "mbedtls/platform_util.h"
|
||||
|
||||
/* Parameter validation macros */
|
||||
#define ARIA_VALIDATE_RET(cond) \
|
||||
MBEDTLS_INTERNAL_VALIDATE_RET(cond, MBEDTLS_ERR_ARIA_BAD_INPUT_DATA)
|
||||
#define ARIA_VALIDATE(cond) \
|
||||
MBEDTLS_INTERNAL_VALIDATE(cond)
|
||||
|
||||
/*
|
||||
* modify byte order: ( A B C D ) -> ( B A D C ), i.e. swap pairs of bytes
|
||||
*
|
||||
|
@ -363,8 +357,6 @@ int mbedtls_aria_setkey_enc(mbedtls_aria_context *ctx,
|
|||
|
||||
int i;
|
||||
uint32_t w[4][4], *w2;
|
||||
ARIA_VALIDATE_RET(ctx != NULL);
|
||||
ARIA_VALIDATE_RET(key != NULL);
|
||||
|
||||
if (keybits != 128 && keybits != 192 && keybits != 256) {
|
||||
return MBEDTLS_ERR_ARIA_BAD_INPUT_DATA;
|
||||
|
@ -418,8 +410,6 @@ int mbedtls_aria_setkey_dec(mbedtls_aria_context *ctx,
|
|||
const unsigned char *key, unsigned int keybits)
|
||||
{
|
||||
int i, j, k, ret;
|
||||
ARIA_VALIDATE_RET(ctx != NULL);
|
||||
ARIA_VALIDATE_RET(key != NULL);
|
||||
|
||||
ret = mbedtls_aria_setkey_enc(ctx, key, keybits);
|
||||
if (ret != 0) {
|
||||
|
@ -455,9 +445,6 @@ int mbedtls_aria_crypt_ecb(mbedtls_aria_context *ctx,
|
|||
int i;
|
||||
|
||||
uint32_t a, b, c, d;
|
||||
ARIA_VALIDATE_RET(ctx != NULL);
|
||||
ARIA_VALIDATE_RET(input != NULL);
|
||||
ARIA_VALIDATE_RET(output != NULL);
|
||||
|
||||
a = MBEDTLS_GET_UINT32_LE(input, 0);
|
||||
b = MBEDTLS_GET_UINT32_LE(input, 4);
|
||||
|
@ -505,7 +492,6 @@ int mbedtls_aria_crypt_ecb(mbedtls_aria_context *ctx,
|
|||
/* Initialize context */
|
||||
void mbedtls_aria_init(mbedtls_aria_context *ctx)
|
||||
{
|
||||
ARIA_VALIDATE(ctx != NULL);
|
||||
memset(ctx, 0, sizeof(mbedtls_aria_context));
|
||||
}
|
||||
|
||||
|
@ -532,12 +518,9 @@ int mbedtls_aria_crypt_cbc(mbedtls_aria_context *ctx,
|
|||
{
|
||||
unsigned char temp[MBEDTLS_ARIA_BLOCKSIZE];
|
||||
|
||||
ARIA_VALIDATE_RET(ctx != NULL);
|
||||
ARIA_VALIDATE_RET(mode == MBEDTLS_ARIA_ENCRYPT ||
|
||||
mode == MBEDTLS_ARIA_DECRYPT);
|
||||
ARIA_VALIDATE_RET(length == 0 || input != NULL);
|
||||
ARIA_VALIDATE_RET(length == 0 || output != NULL);
|
||||
ARIA_VALIDATE_RET(iv != NULL);
|
||||
if ((mode != MBEDTLS_ARIA_ENCRYPT) && (mode != MBEDTLS_ARIA_DECRYPT)) {
|
||||
return MBEDTLS_ERR_ARIA_BAD_INPUT_DATA;
|
||||
}
|
||||
|
||||
if (length % MBEDTLS_ARIA_BLOCKSIZE) {
|
||||
return MBEDTLS_ERR_ARIA_INVALID_INPUT_LENGTH;
|
||||
|
@ -588,19 +571,14 @@ int mbedtls_aria_crypt_cfb128(mbedtls_aria_context *ctx,
|
|||
unsigned char c;
|
||||
size_t n;
|
||||
|
||||
ARIA_VALIDATE_RET(ctx != NULL);
|
||||
ARIA_VALIDATE_RET(mode == MBEDTLS_ARIA_ENCRYPT ||
|
||||
mode == MBEDTLS_ARIA_DECRYPT);
|
||||
ARIA_VALIDATE_RET(length == 0 || input != NULL);
|
||||
ARIA_VALIDATE_RET(length == 0 || output != NULL);
|
||||
ARIA_VALIDATE_RET(iv != NULL);
|
||||
ARIA_VALIDATE_RET(iv_off != NULL);
|
||||
if ((mode != MBEDTLS_ARIA_ENCRYPT) && (mode != MBEDTLS_ARIA_DECRYPT)) {
|
||||
return MBEDTLS_ERR_ARIA_BAD_INPUT_DATA;
|
||||
}
|
||||
|
||||
n = *iv_off;
|
||||
|
||||
/* An overly large value of n can lead to an unlimited
|
||||
* buffer overflow. Therefore, guard against this
|
||||
* outside of parameter validation. */
|
||||
* buffer overflow. */
|
||||
if (n >= MBEDTLS_ARIA_BLOCKSIZE) {
|
||||
return MBEDTLS_ERR_ARIA_BAD_INPUT_DATA;
|
||||
}
|
||||
|
@ -650,17 +628,9 @@ int mbedtls_aria_crypt_ctr(mbedtls_aria_context *ctx,
|
|||
int c, i;
|
||||
size_t n;
|
||||
|
||||
ARIA_VALIDATE_RET(ctx != NULL);
|
||||
ARIA_VALIDATE_RET(length == 0 || input != NULL);
|
||||
ARIA_VALIDATE_RET(length == 0 || output != NULL);
|
||||
ARIA_VALIDATE_RET(nonce_counter != NULL);
|
||||
ARIA_VALIDATE_RET(stream_block != NULL);
|
||||
ARIA_VALIDATE_RET(nc_off != NULL);
|
||||
|
||||
n = *nc_off;
|
||||
/* An overly large value of n can lead to an unlimited
|
||||
* buffer overflow. Therefore, guard against this
|
||||
* outside of parameter validation. */
|
||||
* buffer overflow. */
|
||||
if (n >= MBEDTLS_ARIA_BLOCKSIZE) {
|
||||
return MBEDTLS_ERR_ARIA_BAD_INPUT_DATA;
|
||||
}
|
||||
|
|
|
@ -37,11 +37,6 @@
|
|||
|
||||
#include "mbedtls/platform.h"
|
||||
|
||||
#define MPI_VALIDATE_RET(cond) \
|
||||
MBEDTLS_INTERNAL_VALIDATE_RET(cond, MBEDTLS_ERR_MPI_BAD_INPUT_DATA)
|
||||
#define MPI_VALIDATE(cond) \
|
||||
MBEDTLS_INTERNAL_VALIDATE(cond)
|
||||
|
||||
/*
|
||||
* Compare signed values in constant time
|
||||
*/
|
||||
|
@ -51,10 +46,6 @@ int mbedtls_mpi_lt_mpi_ct(const mbedtls_mpi *X,
|
|||
{
|
||||
mbedtls_ct_condition_t different_sign, X_is_negative, Y_is_negative, result;
|
||||
|
||||
MPI_VALIDATE_RET(X != NULL);
|
||||
MPI_VALIDATE_RET(Y != NULL);
|
||||
MPI_VALIDATE_RET(ret != NULL);
|
||||
|
||||
if (X->n != Y->n) {
|
||||
return MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
|
||||
}
|
||||
|
@ -115,8 +106,6 @@ int mbedtls_mpi_safe_cond_assign(mbedtls_mpi *X,
|
|||
unsigned char assign)
|
||||
{
|
||||
int ret = 0;
|
||||
MPI_VALIDATE_RET(X != NULL);
|
||||
MPI_VALIDATE_RET(Y != NULL);
|
||||
|
||||
MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, Y->n));
|
||||
|
||||
|
@ -149,8 +138,6 @@ int mbedtls_mpi_safe_cond_swap(mbedtls_mpi *X,
|
|||
{
|
||||
int ret = 0;
|
||||
int s;
|
||||
MPI_VALIDATE_RET(X != NULL);
|
||||
MPI_VALIDATE_RET(Y != NULL);
|
||||
|
||||
if (X == Y) {
|
||||
return 0;
|
||||
|
@ -179,8 +166,6 @@ cleanup:
|
|||
*/
|
||||
void mbedtls_mpi_init(mbedtls_mpi *X)
|
||||
{
|
||||
MPI_VALIDATE(X != NULL);
|
||||
|
||||
X->s = 1;
|
||||
X->n = 0;
|
||||
X->p = NULL;
|
||||
|
@ -210,7 +195,6 @@ void mbedtls_mpi_free(mbedtls_mpi *X)
|
|||
int mbedtls_mpi_grow(mbedtls_mpi *X, size_t nblimbs)
|
||||
{
|
||||
mbedtls_mpi_uint *p;
|
||||
MPI_VALIDATE_RET(X != NULL);
|
||||
|
||||
if (nblimbs > MBEDTLS_MPI_MAX_LIMBS) {
|
||||
return MBEDTLS_ERR_MPI_ALLOC_FAILED;
|
||||
|
@ -243,7 +227,6 @@ int mbedtls_mpi_shrink(mbedtls_mpi *X, size_t nblimbs)
|
|||
{
|
||||
mbedtls_mpi_uint *p;
|
||||
size_t i;
|
||||
MPI_VALIDATE_RET(X != NULL);
|
||||
|
||||
if (nblimbs > MBEDTLS_MPI_MAX_LIMBS) {
|
||||
return MBEDTLS_ERR_MPI_ALLOC_FAILED;
|
||||
|
@ -312,8 +295,6 @@ int mbedtls_mpi_copy(mbedtls_mpi *X, const mbedtls_mpi *Y)
|
|||
{
|
||||
int ret = 0;
|
||||
size_t i;
|
||||
MPI_VALIDATE_RET(X != NULL);
|
||||
MPI_VALIDATE_RET(Y != NULL);
|
||||
|
||||
if (X == Y) {
|
||||
return 0;
|
||||
|
@ -355,8 +336,6 @@ cleanup:
|
|||
void mbedtls_mpi_swap(mbedtls_mpi *X, mbedtls_mpi *Y)
|
||||
{
|
||||
mbedtls_mpi T;
|
||||
MPI_VALIDATE(X != NULL);
|
||||
MPI_VALIDATE(Y != NULL);
|
||||
|
||||
memcpy(&T, X, sizeof(mbedtls_mpi));
|
||||
memcpy(X, Y, sizeof(mbedtls_mpi));
|
||||
|
@ -385,7 +364,6 @@ static inline mbedtls_mpi_uint mpi_sint_abs(mbedtls_mpi_sint z)
|
|||
int mbedtls_mpi_lset(mbedtls_mpi *X, mbedtls_mpi_sint z)
|
||||
{
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
MPI_VALIDATE_RET(X != NULL);
|
||||
|
||||
MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, 1));
|
||||
memset(X->p, 0, X->n * ciL);
|
||||
|
@ -403,8 +381,6 @@ cleanup:
|
|||
*/
|
||||
int mbedtls_mpi_get_bit(const mbedtls_mpi *X, size_t pos)
|
||||
{
|
||||
MPI_VALIDATE_RET(X != NULL);
|
||||
|
||||
if (X->n * biL <= pos) {
|
||||
return 0;
|
||||
}
|
||||
|
@ -420,7 +396,6 @@ int mbedtls_mpi_set_bit(mbedtls_mpi *X, size_t pos, unsigned char val)
|
|||
int ret = 0;
|
||||
size_t off = pos / biL;
|
||||
size_t idx = pos % biL;
|
||||
MPI_VALIDATE_RET(X != NULL);
|
||||
|
||||
if (val != 0 && val != 1) {
|
||||
return MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
|
||||
|
@ -448,7 +423,6 @@ cleanup:
|
|||
size_t mbedtls_mpi_lsb(const mbedtls_mpi *X)
|
||||
{
|
||||
size_t i;
|
||||
MBEDTLS_INTERNAL_VALIDATE_RET(X != NULL, 0);
|
||||
|
||||
#if defined(__has_builtin)
|
||||
#if (MBEDTLS_MPI_UINT_MAX == UINT_MAX) && __has_builtin(__builtin_ctz)
|
||||
|
@ -530,8 +504,6 @@ int mbedtls_mpi_read_string(mbedtls_mpi *X, int radix, const char *s)
|
|||
int sign = 1;
|
||||
mbedtls_mpi_uint d;
|
||||
mbedtls_mpi T;
|
||||
MPI_VALIDATE_RET(X != NULL);
|
||||
MPI_VALIDATE_RET(s != NULL);
|
||||
|
||||
if (radix < 2 || radix > 16) {
|
||||
return MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
|
||||
|
@ -634,9 +606,6 @@ int mbedtls_mpi_write_string(const mbedtls_mpi *X, int radix,
|
|||
size_t n;
|
||||
char *p;
|
||||
mbedtls_mpi T;
|
||||
MPI_VALIDATE_RET(X != NULL);
|
||||
MPI_VALIDATE_RET(olen != NULL);
|
||||
MPI_VALIDATE_RET(buflen == 0 || buf != NULL);
|
||||
|
||||
if (radix < 2 || radix > 16) {
|
||||
return MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
|
||||
|
@ -726,9 +695,6 @@ int mbedtls_mpi_read_file(mbedtls_mpi *X, int radix, FILE *fin)
|
|||
*/
|
||||
char s[MBEDTLS_MPI_RW_BUFFER_SIZE];
|
||||
|
||||
MPI_VALIDATE_RET(X != NULL);
|
||||
MPI_VALIDATE_RET(fin != NULL);
|
||||
|
||||
if (radix < 2 || radix > 16) {
|
||||
return MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
|
||||
}
|
||||
|
@ -772,7 +738,6 @@ int mbedtls_mpi_write_file(const char *p, const mbedtls_mpi *X, int radix, FILE
|
|||
* newline characters and '\0'
|
||||
*/
|
||||
char s[MBEDTLS_MPI_RW_BUFFER_SIZE];
|
||||
MPI_VALIDATE_RET(X != NULL);
|
||||
|
||||
if (radix < 2 || radix > 16) {
|
||||
return MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
|
||||
|
@ -844,9 +809,6 @@ int mbedtls_mpi_read_binary(mbedtls_mpi *X, const unsigned char *buf, size_t buf
|
|||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
const size_t limbs = CHARS_TO_LIMBS(buflen);
|
||||
|
||||
MPI_VALIDATE_RET(X != NULL);
|
||||
MPI_VALIDATE_RET(buflen == 0 || buf != NULL);
|
||||
|
||||
/* Ensure that target MPI has exactly the necessary number of limbs */
|
||||
MBEDTLS_MPI_CHK(mbedtls_mpi_resize_clear(X, limbs));
|
||||
|
||||
|
@ -887,7 +849,6 @@ int mbedtls_mpi_shift_l(mbedtls_mpi *X, size_t count)
|
|||
{
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
size_t i;
|
||||
MPI_VALIDATE_RET(X != NULL);
|
||||
|
||||
i = mbedtls_mpi_bitlen(X) + count;
|
||||
|
||||
|
@ -908,7 +869,6 @@ cleanup:
|
|||
*/
|
||||
int mbedtls_mpi_shift_r(mbedtls_mpi *X, size_t count)
|
||||
{
|
||||
MPI_VALIDATE_RET(X != NULL);
|
||||
if (X->n != 0) {
|
||||
mbedtls_mpi_core_shift_r(X->p, X->n, count);
|
||||
}
|
||||
|
@ -921,8 +881,6 @@ int mbedtls_mpi_shift_r(mbedtls_mpi *X, size_t count)
|
|||
int mbedtls_mpi_cmp_abs(const mbedtls_mpi *X, const mbedtls_mpi *Y)
|
||||
{
|
||||
size_t i, j;
|
||||
MPI_VALIDATE_RET(X != NULL);
|
||||
MPI_VALIDATE_RET(Y != NULL);
|
||||
|
||||
for (i = X->n; i > 0; i--) {
|
||||
if (X->p[i - 1] != 0) {
|
||||
|
@ -964,8 +922,6 @@ int mbedtls_mpi_cmp_abs(const mbedtls_mpi *X, const mbedtls_mpi *Y)
|
|||
int mbedtls_mpi_cmp_mpi(const mbedtls_mpi *X, const mbedtls_mpi *Y)
|
||||
{
|
||||
size_t i, j;
|
||||
MPI_VALIDATE_RET(X != NULL);
|
||||
MPI_VALIDATE_RET(Y != NULL);
|
||||
|
||||
for (i = X->n; i > 0; i--) {
|
||||
if (X->p[i - 1] != 0) {
|
||||
|
@ -1016,7 +972,6 @@ int mbedtls_mpi_cmp_int(const mbedtls_mpi *X, mbedtls_mpi_sint z)
|
|||
{
|
||||
mbedtls_mpi Y;
|
||||
mbedtls_mpi_uint p[1];
|
||||
MPI_VALIDATE_RET(X != NULL);
|
||||
|
||||
*p = mpi_sint_abs(z);
|
||||
Y.s = TO_SIGN(z);
|
||||
|
@ -1035,9 +990,6 @@ int mbedtls_mpi_add_abs(mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi
|
|||
size_t j;
|
||||
mbedtls_mpi_uint *p;
|
||||
mbedtls_mpi_uint c;
|
||||
MPI_VALIDATE_RET(X != NULL);
|
||||
MPI_VALIDATE_RET(A != NULL);
|
||||
MPI_VALIDATE_RET(B != NULL);
|
||||
|
||||
if (X == B) {
|
||||
const mbedtls_mpi *T = A; A = X; B = T;
|
||||
|
@ -1098,9 +1050,6 @@ int mbedtls_mpi_sub_abs(mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi
|
|||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
size_t n;
|
||||
mbedtls_mpi_uint carry;
|
||||
MPI_VALIDATE_RET(X != NULL);
|
||||
MPI_VALIDATE_RET(A != NULL);
|
||||
MPI_VALIDATE_RET(B != NULL);
|
||||
|
||||
for (n = B->n; n > 0; n--) {
|
||||
if (B->p[n - 1] != 0) {
|
||||
|
@ -1152,9 +1101,6 @@ static int add_sub_mpi(mbedtls_mpi *X,
|
|||
int flip_B)
|
||||
{
|
||||
int ret, s;
|
||||
MPI_VALIDATE_RET(X != NULL);
|
||||
MPI_VALIDATE_RET(A != NULL);
|
||||
MPI_VALIDATE_RET(B != NULL);
|
||||
|
||||
s = A->s;
|
||||
if (A->s * B->s * flip_B < 0) {
|
||||
|
@ -1203,8 +1149,6 @@ int mbedtls_mpi_add_int(mbedtls_mpi *X, const mbedtls_mpi *A, mbedtls_mpi_sint b
|
|||
{
|
||||
mbedtls_mpi B;
|
||||
mbedtls_mpi_uint p[1];
|
||||
MPI_VALIDATE_RET(X != NULL);
|
||||
MPI_VALIDATE_RET(A != NULL);
|
||||
|
||||
p[0] = mpi_sint_abs(b);
|
||||
B.s = TO_SIGN(b);
|
||||
|
@ -1221,8 +1165,6 @@ int mbedtls_mpi_sub_int(mbedtls_mpi *X, const mbedtls_mpi *A, mbedtls_mpi_sint b
|
|||
{
|
||||
mbedtls_mpi B;
|
||||
mbedtls_mpi_uint p[1];
|
||||
MPI_VALIDATE_RET(X != NULL);
|
||||
MPI_VALIDATE_RET(A != NULL);
|
||||
|
||||
p[0] = mpi_sint_abs(b);
|
||||
B.s = TO_SIGN(b);
|
||||
|
@ -1241,9 +1183,6 @@ int mbedtls_mpi_mul_mpi(mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi
|
|||
size_t i, j;
|
||||
mbedtls_mpi TA, TB;
|
||||
int result_is_zero = 0;
|
||||
MPI_VALIDATE_RET(X != NULL);
|
||||
MPI_VALIDATE_RET(A != NULL);
|
||||
MPI_VALIDATE_RET(B != NULL);
|
||||
|
||||
mbedtls_mpi_init(&TA);
|
||||
mbedtls_mpi_init(&TB);
|
||||
|
@ -1300,9 +1239,6 @@ cleanup:
|
|||
*/
|
||||
int mbedtls_mpi_mul_int(mbedtls_mpi *X, const mbedtls_mpi *A, mbedtls_mpi_uint b)
|
||||
{
|
||||
MPI_VALIDATE_RET(X != NULL);
|
||||
MPI_VALIDATE_RET(A != NULL);
|
||||
|
||||
size_t n = A->n;
|
||||
while (n > 0 && A->p[n - 1] == 0) {
|
||||
--n;
|
||||
|
@ -1448,8 +1384,6 @@ int mbedtls_mpi_div_mpi(mbedtls_mpi *Q, mbedtls_mpi *R, const mbedtls_mpi *A,
|
|||
size_t i, n, t, k;
|
||||
mbedtls_mpi X, Y, Z, T1, T2;
|
||||
mbedtls_mpi_uint TP2[3];
|
||||
MPI_VALIDATE_RET(A != NULL);
|
||||
MPI_VALIDATE_RET(B != NULL);
|
||||
|
||||
if (mbedtls_mpi_cmp_int(B, 0) == 0) {
|
||||
return MBEDTLS_ERR_MPI_DIVISION_BY_ZERO;
|
||||
|
@ -1572,7 +1506,6 @@ int mbedtls_mpi_div_int(mbedtls_mpi *Q, mbedtls_mpi *R,
|
|||
{
|
||||
mbedtls_mpi B;
|
||||
mbedtls_mpi_uint p[1];
|
||||
MPI_VALIDATE_RET(A != NULL);
|
||||
|
||||
p[0] = mpi_sint_abs(b);
|
||||
B.s = TO_SIGN(b);
|
||||
|
@ -1588,9 +1521,6 @@ int mbedtls_mpi_div_int(mbedtls_mpi *Q, mbedtls_mpi *R,
|
|||
int mbedtls_mpi_mod_mpi(mbedtls_mpi *R, const mbedtls_mpi *A, const mbedtls_mpi *B)
|
||||
{
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
MPI_VALIDATE_RET(R != NULL);
|
||||
MPI_VALIDATE_RET(A != NULL);
|
||||
MPI_VALIDATE_RET(B != NULL);
|
||||
|
||||
if (mbedtls_mpi_cmp_int(B, 0) < 0) {
|
||||
return MBEDTLS_ERR_MPI_NEGATIVE_VALUE;
|
||||
|
@ -1618,8 +1548,6 @@ int mbedtls_mpi_mod_int(mbedtls_mpi_uint *r, const mbedtls_mpi *A, mbedtls_mpi_s
|
|||
{
|
||||
size_t i;
|
||||
mbedtls_mpi_uint x, y, z;
|
||||
MPI_VALIDATE_RET(r != NULL);
|
||||
MPI_VALIDATE_RET(A != NULL);
|
||||
|
||||
if (b == 0) {
|
||||
return MBEDTLS_ERR_MPI_DIVISION_BY_ZERO;
|
||||
|
@ -1763,11 +1691,6 @@ int mbedtls_mpi_exp_mod(mbedtls_mpi *X, const mbedtls_mpi *A,
|
|||
mbedtls_mpi RR, T, W[(size_t) 1 << MBEDTLS_MPI_WINDOW_SIZE], WW, Apos;
|
||||
int neg;
|
||||
|
||||
MPI_VALIDATE_RET(X != NULL);
|
||||
MPI_VALIDATE_RET(A != NULL);
|
||||
MPI_VALIDATE_RET(E != NULL);
|
||||
MPI_VALIDATE_RET(N != NULL);
|
||||
|
||||
if (mbedtls_mpi_cmp_int(N, 0) <= 0 || (N->p[0] & 1) == 0) {
|
||||
return MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
|
||||
}
|
||||
|
@ -2054,10 +1977,6 @@ int mbedtls_mpi_gcd(mbedtls_mpi *G, const mbedtls_mpi *A, const mbedtls_mpi *B)
|
|||
size_t lz, lzt;
|
||||
mbedtls_mpi TA, TB;
|
||||
|
||||
MPI_VALIDATE_RET(G != NULL);
|
||||
MPI_VALIDATE_RET(A != NULL);
|
||||
MPI_VALIDATE_RET(B != NULL);
|
||||
|
||||
mbedtls_mpi_init(&TA); mbedtls_mpi_init(&TB);
|
||||
|
||||
MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&TA, A));
|
||||
|
@ -2168,9 +2087,6 @@ int mbedtls_mpi_fill_random(mbedtls_mpi *X, size_t size,
|
|||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
const size_t limbs = CHARS_TO_LIMBS(size);
|
||||
|
||||
MPI_VALIDATE_RET(X != NULL);
|
||||
MPI_VALIDATE_RET(f_rng != NULL);
|
||||
|
||||
/* Ensure that target MPI has exactly the necessary number of limbs */
|
||||
MBEDTLS_MPI_CHK(mbedtls_mpi_resize_clear(X, limbs));
|
||||
if (size == 0) {
|
||||
|
@ -2214,9 +2130,6 @@ int mbedtls_mpi_inv_mod(mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi
|
|||
{
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
mbedtls_mpi G, TA, TU, U1, U2, TB, TV, V1, V2;
|
||||
MPI_VALIDATE_RET(X != NULL);
|
||||
MPI_VALIDATE_RET(A != NULL);
|
||||
MPI_VALIDATE_RET(N != NULL);
|
||||
|
||||
if (mbedtls_mpi_cmp_int(N, 1) <= 0) {
|
||||
return MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
|
||||
|
@ -2372,9 +2285,6 @@ static int mpi_miller_rabin(const mbedtls_mpi *X, size_t rounds,
|
|||
size_t i, j, k, s;
|
||||
mbedtls_mpi W, R, T, A, RR;
|
||||
|
||||
MPI_VALIDATE_RET(X != NULL);
|
||||
MPI_VALIDATE_RET(f_rng != NULL);
|
||||
|
||||
mbedtls_mpi_init(&W); mbedtls_mpi_init(&R);
|
||||
mbedtls_mpi_init(&T); mbedtls_mpi_init(&A);
|
||||
mbedtls_mpi_init(&RR);
|
||||
|
@ -2462,8 +2372,6 @@ int mbedtls_mpi_is_prime_ext(const mbedtls_mpi *X, int rounds,
|
|||
{
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
mbedtls_mpi XX;
|
||||
MPI_VALIDATE_RET(X != NULL);
|
||||
MPI_VALIDATE_RET(f_rng != NULL);
|
||||
|
||||
XX.s = 1;
|
||||
XX.n = X->n;
|
||||
|
@ -2513,9 +2421,6 @@ int mbedtls_mpi_gen_prime(mbedtls_mpi *X, size_t nbits, int flags,
|
|||
mbedtls_mpi_uint r;
|
||||
mbedtls_mpi Y;
|
||||
|
||||
MPI_VALIDATE_RET(X != NULL);
|
||||
MPI_VALIDATE_RET(f_rng != NULL);
|
||||
|
||||
if (nbits < 3 || nbits > MBEDTLS_MPI_MAX_BITS) {
|
||||
return MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
|
||||
}
|
||||
|
|
|
@ -23,12 +23,6 @@
|
|||
|
||||
#if !defined(MBEDTLS_ECP_ALT)
|
||||
|
||||
/* Parameter validation macros based on platform_util.h */
|
||||
#define ECP_VALIDATE_RET(cond) \
|
||||
MBEDTLS_INTERNAL_VALIDATE_RET(cond, MBEDTLS_ERR_ECP_BAD_INPUT_DATA)
|
||||
#define ECP_VALIDATE(cond) \
|
||||
MBEDTLS_INTERNAL_VALIDATE(cond)
|
||||
|
||||
#define ECP_MPI_INIT(_p, _n) { .p = (mbedtls_mpi_uint *) (_p), .s = 1, .n = (_n) }
|
||||
|
||||
#define ECP_MPI_INIT_ARRAY(x) \
|
||||
|
@ -4722,7 +4716,6 @@ cleanup:
|
|||
*/
|
||||
int mbedtls_ecp_group_load(mbedtls_ecp_group *grp, mbedtls_ecp_group_id id)
|
||||
{
|
||||
ECP_VALIDATE_RET(grp != NULL);
|
||||
mbedtls_ecp_group_free(grp);
|
||||
|
||||
mbedtls_ecp_group_init(grp);
|
||||
|
|
|
@ -28,12 +28,6 @@
|
|||
|
||||
#if !defined(MBEDTLS_ECP_ALT)
|
||||
|
||||
/* Parameter validation macros based on platform_util.h */
|
||||
#define ECP_VALIDATE_RET(cond) \
|
||||
MBEDTLS_INTERNAL_VALIDATE_RET(cond, MBEDTLS_ERR_ECP_BAD_INPUT_DATA)
|
||||
#define ECP_VALIDATE(cond) \
|
||||
MBEDTLS_INTERNAL_VALIDATE(cond)
|
||||
|
||||
#define ECP_MPI_INIT(_p, _n) { .p = (mbedtls_mpi_uint *) (_p), .s = 1, .n = (_n) }
|
||||
|
||||
#define ECP_MPI_INIT_ARRAY(x) \
|
||||
|
@ -4764,7 +4758,6 @@ cleanup:
|
|||
*/
|
||||
int mbedtls_ecp_group_load(mbedtls_ecp_group *grp, mbedtls_ecp_group_id id)
|
||||
{
|
||||
ECP_VALIDATE_RET(grp != NULL);
|
||||
mbedtls_ecp_group_free(grp);
|
||||
|
||||
mbedtls_ecp_group_init(grp);
|
||||
|
|
|
@ -93,8 +93,6 @@ static void *(*const volatile memset_func)(void *, int, size_t) = memset;
|
|||
|
||||
void mbedtls_platform_zeroize(void *buf, size_t len)
|
||||
{
|
||||
MBEDTLS_INTERNAL_VALIDATE(len == 0 || buf != NULL);
|
||||
|
||||
if (len > 0) {
|
||||
#if defined(MBEDTLS_PLATFORM_HAS_EXPLICIT_BZERO)
|
||||
explicit_bzero(buf, len);
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
* END_DEPENDENCIES
|
||||
*/
|
||||
|
||||
/* BEGIN_CASE depends_on:NOT_DEFINED */
|
||||
/* BEGIN_CASE */
|
||||
void aria_invalid_param()
|
||||
{
|
||||
mbedtls_aria_context ctx;
|
||||
|
@ -52,8 +52,10 @@ void aria_invalid_param()
|
|||
output));
|
||||
#endif /* MBEDTLS_CIPHER_MODE_CFB */
|
||||
|
||||
#if defined(MBEDTLS_CIPHER_MODE_CBC) || defined(MBEDTLS_CIPHER_MODE_CFB)
|
||||
exit:
|
||||
return;
|
||||
#endif
|
||||
|
||||
}
|
||||
/* END_CASE */
|
||||
|
|
|
@ -143,6 +143,26 @@ exit:
|
|||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mpi_zero_length_buffer_is_null()
|
||||
{
|
||||
mbedtls_mpi X;
|
||||
size_t olen;
|
||||
|
||||
mbedtls_mpi_init(&X);
|
||||
|
||||
/* Simply test that the following functions do not crash when a NULL buffer
|
||||
* pointer and 0 length is passed. We don't care much about the return value. */
|
||||
TEST_EQUAL(mbedtls_mpi_read_binary(&X, NULL, 0), 0);
|
||||
TEST_EQUAL(mbedtls_mpi_read_binary_le(&X, NULL, 0), 0);
|
||||
TEST_EQUAL(mbedtls_mpi_write_string(&X, 16, NULL, 0, &olen), MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL);
|
||||
TEST_EQUAL(mbedtls_mpi_write_binary(&X, NULL, 0), 0);
|
||||
|
||||
exit:
|
||||
mbedtls_mpi_free(&X);
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mpi_read_binary(data_t *buf, char *input_A)
|
||||
{
|
||||
|
|
|
@ -82,6 +82,9 @@ mpi_read_write_string:16:"":2:"0":4:0:0
|
|||
Test mpi_write_string #10 (Negative hex with odd number of digits)
|
||||
mpi_read_write_string:16:"-1":16:"":3:0:MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL
|
||||
|
||||
Provide NULL buffer with 0 length
|
||||
mpi_zero_length_buffer_is_null
|
||||
|
||||
Base test mbedtls_mpi_read_binary #1
|
||||
mpi_read_binary:"0941379d00fed1491fe15df284dfde4a142f68aa8d412023195cee66883e6290ffe703f4ea5963bf212713cee46b107c09182b5edcd955adac418bf4918e2889af48e1099d513830cec85c26ac1e158b52620e33ba8692f893efbb2f958b4424":"0941379D00FED1491FE15DF284DFDE4A142F68AA8D412023195CEE66883E6290FFE703F4EA5963BF212713CEE46B107C09182B5EDCD955ADAC418BF4918E2889AF48E1099D513830CEC85C26AC1E158B52620E33BA8692F893EFBB2F958B4424"
|
||||
|
||||
|
|
Loading…
Reference in a new issue