mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2024-12-27 12:16:07 +00:00
Fix use of sizeof without brackets
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
This commit is contained in:
parent
24c6f49530
commit
6dd757a8ba
@ -659,7 +659,7 @@ int mbedtls_ccm_self_test(int verbose)
|
||||
mbedtls_ccm_init(&ctx);
|
||||
|
||||
if (mbedtls_ccm_setkey(&ctx, MBEDTLS_CIPHER_ID_AES, key_test_data,
|
||||
8 * sizeof key_test_data) != 0) {
|
||||
8 * sizeof(key_test_data)) != 0) {
|
||||
if (verbose != 0) {
|
||||
mbedtls_printf(" CCM: setup failed");
|
||||
}
|
||||
|
@ -4507,7 +4507,7 @@ static const mbedtls_ecp_point brainpoolP512r1_T[32] = {
|
||||
defined(MBEDTLS_ECP_DP_CURVE448_ENABLED)
|
||||
/*
|
||||
* Create an MPI from embedded constants
|
||||
* (assumes len is an exact multiple of sizeof mbedtls_mpi_uint)
|
||||
* (assumes len is an exact multiple of sizeof(mbedtls_mpi_uint))
|
||||
*/
|
||||
static inline void ecp_mpi_load(mbedtls_mpi *X, const mbedtls_mpi_uint *p, size_t len)
|
||||
{
|
||||
@ -5370,7 +5370,7 @@ static inline int ecp_mod_koblitz(mbedtls_mpi *N, mbedtls_mpi_uint *Rp, size_t p
|
||||
if (M.n > p_limbs + adjust) {
|
||||
M.n = p_limbs + adjust;
|
||||
}
|
||||
memset(Mp, 0, sizeof Mp);
|
||||
memset(Mp, 0, sizeof(Mp));
|
||||
memcpy(Mp, N->p + p_limbs - adjust, M.n * sizeof(mbedtls_mpi_uint));
|
||||
if (shift != 0) {
|
||||
MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&M, shift));
|
||||
@ -5396,7 +5396,7 @@ static inline int ecp_mod_koblitz(mbedtls_mpi *N, mbedtls_mpi_uint *Rp, size_t p
|
||||
if (M.n > p_limbs + adjust) {
|
||||
M.n = p_limbs + adjust;
|
||||
}
|
||||
memset(Mp, 0, sizeof Mp);
|
||||
memset(Mp, 0, sizeof(Mp));
|
||||
memcpy(Mp, N->p + p_limbs - adjust, M.n * sizeof(mbedtls_mpi_uint));
|
||||
if (shift != 0) {
|
||||
MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&M, shift));
|
||||
|
@ -677,7 +677,7 @@ int mbedtls_entropy_self_test(int verbose)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if ((ret = mbedtls_entropy_update_manual(&ctx, buf, sizeof buf)) != 0) {
|
||||
if ((ret = mbedtls_entropy_update_manual(&ctx, buf, sizeof(buf))) != 0) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
|
@ -456,7 +456,7 @@ int mbedtls_ripemd160_self_test(int verbose)
|
||||
int i, ret = 0;
|
||||
unsigned char output[20];
|
||||
|
||||
memset(output, 0, sizeof output);
|
||||
memset(output, 0, sizeof(output));
|
||||
|
||||
for (i = 0; i < TESTS; i++) {
|
||||
if (verbose != 0) {
|
||||
|
@ -1652,10 +1652,10 @@ cleanup:
|
||||
memset(&sb, 0, sizeof(sb));
|
||||
|
||||
while ((entry = readdir(dir)) != NULL) {
|
||||
snp_ret = mbedtls_snprintf(entry_name, sizeof entry_name,
|
||||
snp_ret = mbedtls_snprintf(entry_name, sizeof(entry_name),
|
||||
"%s/%s", path, entry->d_name);
|
||||
|
||||
if (snp_ret < 0 || (size_t) snp_ret >= sizeof entry_name) {
|
||||
if (snp_ret < 0 || (size_t) snp_ret >= sizeof(entry_name)) {
|
||||
ret = MBEDTLS_ERR_X509_BUFFER_TOO_SMALL;
|
||||
goto cleanup;
|
||||
} else if (stat(entry_name, &sb) == -1) {
|
||||
|
@ -74,7 +74,7 @@ int main(int argc, char *argv[])
|
||||
if ((ret = mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func,
|
||||
&entropy,
|
||||
(const unsigned char *) pers,
|
||||
sizeof pers)) != 0) {
|
||||
sizeof(pers))) != 0) {
|
||||
mbedtls_printf(" failed\n ! mbedtls_ctr_drbg_seed returned %d\n",
|
||||
ret);
|
||||
goto exit;
|
||||
|
@ -73,7 +73,7 @@ static void dump_pubkey(const char *title, mbedtls_ecdsa_context *key)
|
||||
size_t len;
|
||||
|
||||
if (mbedtls_ecp_point_write_binary(&key->MBEDTLS_PRIVATE(grp), &key->MBEDTLS_PRIVATE(Q),
|
||||
MBEDTLS_ECP_PF_UNCOMPRESSED, &len, buf, sizeof buf) != 0) {
|
||||
MBEDTLS_ECP_PF_UNCOMPRESSED, &len, buf, sizeof(buf)) != 0) {
|
||||
mbedtls_printf("internal error\n");
|
||||
return;
|
||||
}
|
||||
|
@ -284,7 +284,7 @@ void ctr_drbg_entropy_usage(int entropy_nonce_len)
|
||||
}
|
||||
TEST_EQUAL(test_offset_idx, expected_idx);
|
||||
|
||||
/* Call update with too much data (sizeof entropy > MAX(_SEED)_INPUT).
|
||||
/* Call update with too much data (sizeof(entropy) > MAX(_SEED)_INPUT).
|
||||
* Make sure it's detected as an error and doesn't cause memory
|
||||
* corruption. */
|
||||
TEST_ASSERT(mbedtls_ctr_drbg_update(
|
||||
|
@ -10,8 +10,8 @@ void md5_text(char *text_src_string, data_t *hash)
|
||||
unsigned char src_str[100];
|
||||
unsigned char output[16];
|
||||
|
||||
memset(src_str, 0x00, sizeof src_str);
|
||||
memset(output, 0x00, sizeof output);
|
||||
memset(src_str, 0x00, sizeof(src_str));
|
||||
memset(output, 0x00, sizeof(output));
|
||||
|
||||
strncpy((char *) src_str, text_src_string, sizeof(src_str) - 1);
|
||||
|
||||
@ -19,7 +19,7 @@ void md5_text(char *text_src_string, data_t *hash)
|
||||
TEST_ASSERT(ret == 0);
|
||||
|
||||
TEST_ASSERT(mbedtls_test_hexcmp(output, hash->x,
|
||||
sizeof output, hash->len) == 0);
|
||||
sizeof(output), hash->len) == 0);
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
@ -30,8 +30,8 @@ void ripemd160_text(char *text_src_string, data_t *hash)
|
||||
unsigned char src_str[100];
|
||||
unsigned char output[20];
|
||||
|
||||
memset(src_str, 0x00, sizeof src_str);
|
||||
memset(output, 0x00, sizeof output);
|
||||
memset(src_str, 0x00, sizeof(src_str));
|
||||
memset(output, 0x00, sizeof(output));
|
||||
|
||||
strncpy((char *) src_str, text_src_string, sizeof(src_str) - 1);
|
||||
|
||||
@ -39,7 +39,7 @@ void ripemd160_text(char *text_src_string, data_t *hash)
|
||||
TEST_ASSERT(ret == 0);
|
||||
|
||||
TEST_ASSERT(mbedtls_test_hexcmp(output, hash->x,
|
||||
sizeof output, hash->len) == 0);
|
||||
sizeof(output), hash->len) == 0);
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
|
@ -726,7 +726,7 @@ void pk_sign_verify_restart(int pk_type, int grp_id, char *d_str,
|
||||
|
||||
slen = sizeof(sig);
|
||||
ret = mbedtls_pk_sign_restartable(&prv, md_alg, hash->x, hash->len,
|
||||
sig, sizeof sig, &slen,
|
||||
sig, sizeof(sig), &slen,
|
||||
mbedtls_test_rnd_std_rand, NULL,
|
||||
&rs_ctx);
|
||||
TEST_ASSERT(ret == MBEDTLS_ERR_ECP_IN_PROGRESS);
|
||||
@ -763,15 +763,15 @@ void pk_sign_verify(int type, int parameter, int sign_ret, int verify_ret)
|
||||
mbedtls_pk_init(&pk);
|
||||
USE_PSA_INIT();
|
||||
|
||||
memset(hash, 0x2a, sizeof hash);
|
||||
memset(sig, 0, sizeof sig);
|
||||
memset(hash, 0x2a, sizeof(hash));
|
||||
memset(sig, 0, sizeof(sig));
|
||||
|
||||
TEST_ASSERT(mbedtls_pk_setup(&pk, mbedtls_pk_info_from_type(type)) == 0);
|
||||
TEST_ASSERT(pk_genkey(&pk, parameter) == 0);
|
||||
|
||||
TEST_ASSERT(mbedtls_pk_sign_restartable(&pk, MBEDTLS_MD_SHA256,
|
||||
hash, hash_len,
|
||||
sig, sizeof sig, &sig_len,
|
||||
sig, sizeof(sig), &sig_len,
|
||||
mbedtls_test_rnd_std_rand, NULL,
|
||||
rs_ctx) == sign_ret);
|
||||
if (sign_ret == 0) {
|
||||
@ -796,7 +796,7 @@ void pk_sign_verify(int type, int parameter, int sign_ret, int verify_ret)
|
||||
}
|
||||
|
||||
TEST_ASSERT(mbedtls_pk_sign(&pk, MBEDTLS_MD_SHA256, hash, hash_len,
|
||||
sig, sizeof sig, &sig_len,
|
||||
sig, sizeof(sig), &sig_len,
|
||||
mbedtls_test_rnd_std_rand,
|
||||
NULL) == sign_ret);
|
||||
if (sign_ret == 0) {
|
||||
@ -811,12 +811,12 @@ void pk_sign_verify(int type, int parameter, int sign_ret, int verify_ret)
|
||||
if (verify_ret == 0) {
|
||||
hash[0]++;
|
||||
TEST_ASSERT(mbedtls_pk_verify_restartable(&pk, MBEDTLS_MD_SHA256,
|
||||
hash, sizeof hash, sig, sig_len, rs_ctx) != 0);
|
||||
hash, sizeof(hash), sig, sig_len, rs_ctx) != 0);
|
||||
hash[0]--;
|
||||
|
||||
sig[0]++;
|
||||
TEST_ASSERT(mbedtls_pk_verify_restartable(&pk, MBEDTLS_MD_SHA256,
|
||||
hash, sizeof hash, sig, sig_len, rs_ctx) != 0);
|
||||
hash, sizeof(hash), sig, sig_len, rs_ctx) != 0);
|
||||
sig[0]--;
|
||||
}
|
||||
|
||||
@ -1068,8 +1068,8 @@ void pk_rsa_overflow()
|
||||
return;
|
||||
}
|
||||
|
||||
memset(hash, 0x2a, sizeof hash);
|
||||
memset(sig, 0, sizeof sig);
|
||||
memset(hash, 0x2a, sizeof(hash));
|
||||
memset(sig, 0, sizeof(sig));
|
||||
|
||||
mbedtls_pk_init(&pk);
|
||||
|
||||
@ -1086,7 +1086,7 @@ void pk_rsa_overflow()
|
||||
sig, sig_len) == MBEDTLS_ERR_PK_BAD_INPUT_DATA);
|
||||
|
||||
TEST_ASSERT(mbedtls_pk_sign(&pk, MBEDTLS_MD_NONE, hash, hash_len,
|
||||
sig, sizeof sig, &sig_len,
|
||||
sig, sizeof(sig), &sig_len,
|
||||
mbedtls_test_rnd_std_rand, NULL)
|
||||
== MBEDTLS_ERR_PK_BAD_INPUT_DATA);
|
||||
|
||||
@ -1116,11 +1116,11 @@ void pk_rsa_alt()
|
||||
mbedtls_rsa_init(&raw);
|
||||
mbedtls_pk_init(&rsa); mbedtls_pk_init(&alt);
|
||||
|
||||
memset(hash, 0x2a, sizeof hash);
|
||||
memset(sig, 0, sizeof sig);
|
||||
memset(msg, 0x2a, sizeof msg);
|
||||
memset(ciph, 0, sizeof ciph);
|
||||
memset(test, 0, sizeof test);
|
||||
memset(hash, 0x2a, sizeof(hash));
|
||||
memset(sig, 0, sizeof(sig));
|
||||
memset(msg, 0x2a, sizeof(msg));
|
||||
memset(ciph, 0, sizeof(ciph));
|
||||
memset(test, 0, sizeof(test));
|
||||
|
||||
/* Initialize PK RSA context with random key */
|
||||
TEST_ASSERT(mbedtls_pk_setup(&rsa,
|
||||
@ -1145,34 +1145,34 @@ void pk_rsa_alt()
|
||||
/* Test signature */
|
||||
#if SIZE_MAX > UINT_MAX
|
||||
TEST_ASSERT(mbedtls_pk_sign(&alt, MBEDTLS_MD_NONE, hash, SIZE_MAX,
|
||||
sig, sizeof sig, &sig_len,
|
||||
sig, sizeof(sig), &sig_len,
|
||||
mbedtls_test_rnd_std_rand, NULL)
|
||||
== MBEDTLS_ERR_PK_BAD_INPUT_DATA);
|
||||
#endif /* SIZE_MAX > UINT_MAX */
|
||||
TEST_ASSERT(mbedtls_pk_sign(&alt, MBEDTLS_MD_NONE, hash, sizeof hash,
|
||||
sig, sizeof sig, &sig_len,
|
||||
TEST_ASSERT(mbedtls_pk_sign(&alt, MBEDTLS_MD_NONE, hash, sizeof(hash),
|
||||
sig, sizeof(sig), &sig_len,
|
||||
mbedtls_test_rnd_std_rand, NULL)
|
||||
== 0);
|
||||
TEST_ASSERT(sig_len == RSA_KEY_LEN);
|
||||
TEST_ASSERT(mbedtls_pk_verify(&rsa, MBEDTLS_MD_NONE,
|
||||
hash, sizeof hash, sig, sig_len) == 0);
|
||||
hash, sizeof(hash), sig, sig_len) == 0);
|
||||
|
||||
/* Test decrypt */
|
||||
TEST_ASSERT(mbedtls_pk_encrypt(&rsa, msg, sizeof msg,
|
||||
ciph, &ciph_len, sizeof ciph,
|
||||
TEST_ASSERT(mbedtls_pk_encrypt(&rsa, msg, sizeof(msg),
|
||||
ciph, &ciph_len, sizeof(ciph),
|
||||
mbedtls_test_rnd_std_rand, NULL) == 0);
|
||||
TEST_ASSERT(mbedtls_pk_decrypt(&alt, ciph, ciph_len,
|
||||
test, &test_len, sizeof test,
|
||||
test, &test_len, sizeof(test),
|
||||
mbedtls_test_rnd_std_rand, NULL) == 0);
|
||||
TEST_ASSERT(test_len == sizeof msg);
|
||||
TEST_ASSERT(test_len == sizeof(msg));
|
||||
TEST_ASSERT(memcmp(test, msg, test_len) == 0);
|
||||
|
||||
/* Test forbidden operations */
|
||||
TEST_ASSERT(mbedtls_pk_encrypt(&alt, msg, sizeof msg,
|
||||
ciph, &ciph_len, sizeof ciph,
|
||||
TEST_ASSERT(mbedtls_pk_encrypt(&alt, msg, sizeof(msg),
|
||||
ciph, &ciph_len, sizeof(ciph),
|
||||
mbedtls_test_rnd_std_rand, NULL) == ret);
|
||||
TEST_ASSERT(mbedtls_pk_verify(&alt, MBEDTLS_MD_NONE,
|
||||
hash, sizeof hash, sig, sig_len) == ret);
|
||||
hash, sizeof(hash), sig, sig_len) == ret);
|
||||
TEST_ASSERT(mbedtls_pk_debug(&alt, dbg_items) == ret);
|
||||
|
||||
exit:
|
||||
@ -1260,11 +1260,11 @@ void pk_psa_sign(int parameter_arg,
|
||||
TEST_EQUAL(psa_get_key_lifetime(&attributes),
|
||||
PSA_KEY_LIFETIME_VOLATILE);
|
||||
|
||||
memset(hash, 0x2a, sizeof hash);
|
||||
memset(sig, 0, sizeof sig);
|
||||
memset(hash, 0x2a, sizeof(hash));
|
||||
memset(sig, 0, sizeof(sig));
|
||||
|
||||
TEST_ASSERT(mbedtls_pk_sign(&pk, MBEDTLS_MD_SHA256,
|
||||
hash, sizeof hash, sig, sizeof sig, &sig_len,
|
||||
hash, sizeof(hash), sig, sizeof(sig), &sig_len,
|
||||
NULL, NULL) == 0);
|
||||
|
||||
/* Export underlying public key for re-importing in a psa context. */
|
||||
@ -1285,7 +1285,7 @@ void pk_psa_sign(int parameter_arg,
|
||||
TEST_ASSERT(mbedtls_pk_parse_public_key(&pk, pkey_legacy_start,
|
||||
klen_legacy) == 0);
|
||||
TEST_ASSERT(mbedtls_pk_verify(&pk, MBEDTLS_MD_SHA256,
|
||||
hash, sizeof hash, sig, sig_len) == 0);
|
||||
hash, sizeof(hash), sig, sig_len) == 0);
|
||||
|
||||
exit:
|
||||
/*
|
||||
|
@ -1217,9 +1217,9 @@ void mbedtls_x509_crt_verify_max(char *ca_file, char *chain_dir, int nb_int,
|
||||
|
||||
/* Load a chain with nb_int intermediates (from 01 to nb_int),
|
||||
* plus one "end-entity" cert (nb_int + 1) */
|
||||
ret = mbedtls_snprintf(file_buf, sizeof file_buf, "%s/c%02d.pem", chain_dir,
|
||||
ret = mbedtls_snprintf(file_buf, sizeof(file_buf), "%s/c%02d.pem", chain_dir,
|
||||
nb_int + 1);
|
||||
TEST_ASSERT(ret > 0 && (size_t) ret < sizeof file_buf);
|
||||
TEST_ASSERT(ret > 0 && (size_t) ret < sizeof(file_buf));
|
||||
TEST_ASSERT(mbedtls_x509_crt_parse_file(&chain, file_buf) == 0);
|
||||
|
||||
/* Try to verify that chain */
|
||||
@ -1312,13 +1312,13 @@ void x509_oid_numstr(data_t *oid_buf, char *numstr, int blen, int ret)
|
||||
mbedtls_x509_buf oid;
|
||||
char num_buf[100];
|
||||
|
||||
memset(num_buf, 0x2a, sizeof num_buf);
|
||||
memset(num_buf, 0x2a, sizeof(num_buf));
|
||||
|
||||
oid.tag = MBEDTLS_ASN1_OID;
|
||||
oid.p = oid_buf->x;
|
||||
oid.len = oid_buf->len;
|
||||
|
||||
TEST_ASSERT((size_t) blen <= sizeof num_buf);
|
||||
TEST_ASSERT((size_t) blen <= sizeof(num_buf));
|
||||
|
||||
TEST_ASSERT(mbedtls_oid_get_numeric_string(num_buf, blen, &oid) == ret);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user