diff --git a/3rdparty/everest/library/Hacl_Curve25519.c b/3rdparty/everest/library/Hacl_Curve25519.c index 450b9f8ddf..153a11a980 100644 --- a/3rdparty/everest/library/Hacl_Curve25519.c +++ b/3rdparty/everest/library/Hacl_Curve25519.c @@ -115,7 +115,7 @@ Hacl_Bignum_Fmul_mul_shift_reduce_(uint128_t *output, uint64_t *input, uint64_t inline static void Hacl_Bignum_Fmul_fmul(uint64_t *output, uint64_t *input, uint64_t *input2) { uint64_t tmp[5U] = { 0U }; - memcpy(tmp, input, (uint32_t)5U * sizeof input[0U]); + memcpy(tmp, input, (uint32_t)5U * sizeof(input[0U])); KRML_CHECK_SIZE(sizeof (uint128_t), (uint32_t)5U); { uint128_t t[5U]; @@ -223,7 +223,7 @@ Hacl_Bignum_Fsquare_fsquare_times(uint64_t *output, uint64_t *input, uint32_t co for (_i = 0U; _i < (uint32_t)5U; ++_i) t[_i] = (uint128_t)(uint64_t)0U; } - memcpy(output, input, (uint32_t)5U * sizeof input[0U]); + memcpy(output, input, (uint32_t)5U * sizeof(input[0U])); Hacl_Bignum_Fsquare_fsquare_times_(output, t, count1); } } @@ -305,7 +305,7 @@ inline static void Hacl_Bignum_fdifference(uint64_t *a, uint64_t *b) uint64_t b2; uint64_t b3; uint64_t b4; - memcpy(tmp, b, (uint32_t)5U * sizeof b[0U]); + memcpy(tmp, b, (uint32_t)5U * sizeof(b[0U])); b0 = tmp[0U]; b1 = tmp[1U]; b2 = tmp[2U]; @@ -406,7 +406,7 @@ static void Hacl_EC_Point_swap_conditional(uint64_t *a, uint64_t *b, uint64_t is static void Hacl_EC_Point_copy(uint64_t *output, uint64_t *input) { - memcpy(output, input, (uint32_t)5U * sizeof input[0U]); + memcpy(output, input, (uint32_t)5U * sizeof(input[0U])); memcpy(output + (uint32_t)5U, input + (uint32_t)5U, (uint32_t)5U * sizeof (input + (uint32_t)5U)[0U]); @@ -600,10 +600,10 @@ Hacl_EC_AddAndDouble_fmonty( uint64_t *xx; uint64_t *zz; uint64_t scalar; - memcpy(origx, x, (uint32_t)5U * sizeof x[0U]); + memcpy(origx, x, (uint32_t)5U * sizeof(x[0U])); Hacl_Bignum_fsum(x, z); Hacl_Bignum_fdifference(z, origx); - memcpy(origxprime0, xprime, (uint32_t)5U * sizeof xprime[0U]); + memcpy(origxprime0, xprime, (uint32_t)5U * sizeof(xprime[0U])); Hacl_Bignum_fsum(xprime, zprime); Hacl_Bignum_fdifference(zprime, origxprime0); Hacl_Bignum_fmul(xxprime0, xprime, z); @@ -614,7 +614,7 @@ Hacl_EC_AddAndDouble_fmonty( xxprime = buf + (uint32_t)25U; zzprime = buf + (uint32_t)30U; zzzprime = buf + (uint32_t)35U; - memcpy(origxprime, xxprime, (uint32_t)5U * sizeof xxprime[0U]); + memcpy(origxprime, xxprime, (uint32_t)5U * sizeof(xxprime[0U])); Hacl_Bignum_fsum(xxprime, zzprime); Hacl_Bignum_fdifference(zzprime, origxprime); Hacl_Bignum_Fsquare_fsquare_times(x3, xxprime, (uint32_t)1U); @@ -738,7 +738,7 @@ void Hacl_Curve25519_crypto_scalarmult(uint8_t *mypublic, uint8_t *secret, uint8 uint8_t e311; uint8_t e312; uint8_t *scalar; - memcpy(e, secret, (uint32_t)32U * sizeof secret[0U]); + memcpy(e, secret, (uint32_t)32U * sizeof(secret[0U])); e0 = e[0U]; e31 = e[31U]; e01 = e0 & (uint8_t)248U; diff --git a/3rdparty/everest/library/legacy/Hacl_Curve25519.c b/3rdparty/everest/library/legacy/Hacl_Curve25519.c index babebe4f11..bce912025a 100644 --- a/3rdparty/everest/library/legacy/Hacl_Curve25519.c +++ b/3rdparty/everest/library/legacy/Hacl_Curve25519.c @@ -127,7 +127,7 @@ Hacl_Bignum_Fmul_mul_shift_reduce_( inline static void Hacl_Bignum_Fmul_fmul(uint64_t *output, uint64_t *input, uint64_t *input2) { uint64_t tmp[5U] = { 0U }; - memcpy(tmp, input, (uint32_t)5U * sizeof input[0U]); + memcpy(tmp, input, (uint32_t)5U * sizeof(input[0U])); KRML_CHECK_SIZE(sizeof (FStar_UInt128_uint128), (uint32_t)5U); { FStar_UInt128_uint128 t[5U]; @@ -265,7 +265,7 @@ Hacl_Bignum_Fsquare_fsquare_times(uint64_t *output, uint64_t *input, uint32_t co for (_i = 0U; _i < (uint32_t)5U; ++_i) t[_i] = FStar_UInt128_uint64_to_uint128((uint64_t)0U); } - memcpy(output, input, (uint32_t)5U * sizeof input[0U]); + memcpy(output, input, (uint32_t)5U * sizeof(input[0U])); Hacl_Bignum_Fsquare_fsquare_times_(output, t, count1); } } @@ -347,7 +347,7 @@ inline static void Hacl_Bignum_fdifference(uint64_t *a, uint64_t *b) uint64_t b2; uint64_t b3; uint64_t b4; - memcpy(tmp, b, (uint32_t)5U * sizeof b[0U]); + memcpy(tmp, b, (uint32_t)5U * sizeof(b[0U])); b0 = tmp[0U]; b1 = tmp[1U]; b2 = tmp[2U]; @@ -451,7 +451,7 @@ static void Hacl_EC_Point_swap_conditional(uint64_t *a, uint64_t *b, uint64_t is static void Hacl_EC_Point_copy(uint64_t *output, uint64_t *input) { - memcpy(output, input, (uint32_t)5U * sizeof input[0U]); + memcpy(output, input, (uint32_t)5U * sizeof(input[0U])); memcpy(output + (uint32_t)5U, input + (uint32_t)5U, (uint32_t)5U * sizeof (input + (uint32_t)5U)[0U]); @@ -645,10 +645,10 @@ Hacl_EC_AddAndDouble_fmonty( uint64_t *xx; uint64_t *zz; uint64_t scalar; - memcpy(origx, x, (uint32_t)5U * sizeof x[0U]); + memcpy(origx, x, (uint32_t)5U * sizeof(x[0U])); Hacl_Bignum_fsum(x, z); Hacl_Bignum_fdifference(z, origx); - memcpy(origxprime0, xprime, (uint32_t)5U * sizeof xprime[0U]); + memcpy(origxprime0, xprime, (uint32_t)5U * sizeof(xprime[0U])); Hacl_Bignum_fsum(xprime, zprime); Hacl_Bignum_fdifference(zprime, origxprime0); Hacl_Bignum_fmul(xxprime0, xprime, z); @@ -659,7 +659,7 @@ Hacl_EC_AddAndDouble_fmonty( xxprime = buf + (uint32_t)25U; zzprime = buf + (uint32_t)30U; zzzprime = buf + (uint32_t)35U; - memcpy(origxprime, xxprime, (uint32_t)5U * sizeof xxprime[0U]); + memcpy(origxprime, xxprime, (uint32_t)5U * sizeof(xxprime[0U])); Hacl_Bignum_fsum(xxprime, zzprime); Hacl_Bignum_fdifference(zzprime, origxprime); Hacl_Bignum_Fsquare_fsquare_times(x3, xxprime, (uint32_t)1U); @@ -783,7 +783,7 @@ void Hacl_Curve25519_crypto_scalarmult(uint8_t *mypublic, uint8_t *secret, uint8 uint8_t e311; uint8_t e312; uint8_t *scalar; - memcpy(e, secret, (uint32_t)32U * sizeof secret[0U]); + memcpy(e, secret, (uint32_t)32U * sizeof(secret[0U])); e0 = e[0U]; e31 = e[31U]; e01 = e0 & (uint8_t)248U; diff --git a/3rdparty/everest/library/x25519.c b/3rdparty/everest/library/x25519.c index 9faa9ab7d8..9eef4ab674 100644 --- a/3rdparty/everest/library/x25519.c +++ b/3rdparty/everest/library/x25519.c @@ -70,7 +70,7 @@ int mbedtls_x25519_make_params( mbedtls_x25519_context *ctx, size_t *olen, *olen = MBEDTLS_X25519_KEY_SIZE_BYTES + 4; if( blen < *olen ) - return( MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL ); + return MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL ; *buf++ = MBEDTLS_ECP_TLS_NAMED_CURVE; *buf++ = MBEDTLS_ECP_TLS_CURVE25519 >> 8; @@ -84,21 +84,21 @@ int mbedtls_x25519_make_params( mbedtls_x25519_context *ctx, size_t *olen, if( memcmp( buf, base, MBEDTLS_X25519_KEY_SIZE_BYTES) == 0 ) return MBEDTLS_ERR_ECP_RANDOM_FAILED; - return( 0 ); + return 0 ; } int mbedtls_x25519_read_params( mbedtls_x25519_context *ctx, const unsigned char **buf, const unsigned char *end ) { if( end - *buf < MBEDTLS_X25519_KEY_SIZE_BYTES + 1 ) - return( MBEDTLS_ERR_ECP_BAD_INPUT_DATA ); + return MBEDTLS_ERR_ECP_BAD_INPUT_DATA ; if( ( *(*buf)++ != MBEDTLS_X25519_KEY_SIZE_BYTES ) ) - return( MBEDTLS_ERR_ECP_BAD_INPUT_DATA ); + return MBEDTLS_ERR_ECP_BAD_INPUT_DATA ; memcpy( ctx->peer_point, *buf, MBEDTLS_X25519_KEY_SIZE_BYTES ); *buf += MBEDTLS_X25519_KEY_SIZE_BYTES; - return( 0 ); + return 0 ; } int mbedtls_x25519_get_params( mbedtls_x25519_context *ctx, const mbedtls_ecp_keypair *key, @@ -112,7 +112,7 @@ int mbedtls_x25519_get_params( mbedtls_x25519_context *ctx, const mbedtls_ecp_ke case MBEDTLS_X25519_ECDH_OURS: return mbedtls_mpi_write_binary_le( &key->d, ctx->our_secret, MBEDTLS_X25519_KEY_SIZE_BYTES ); default: - return( MBEDTLS_ERR_ECP_BAD_INPUT_DATA ); + return MBEDTLS_ERR_ECP_BAD_INPUT_DATA ; } } @@ -129,7 +129,7 @@ int mbedtls_x25519_calc_secret( mbedtls_x25519_context *ctx, size_t *olen, *olen = MBEDTLS_X25519_KEY_SIZE_BYTES; if( blen < *olen ) - return( MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL ); + return MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL ; Hacl_Curve25519_crypto_scalarmult( buf, ctx->our_secret, ctx->peer_point); @@ -139,7 +139,7 @@ int mbedtls_x25519_calc_secret( mbedtls_x25519_context *ctx, size_t *olen, if( memcmp( buf, ctx->our_secret, MBEDTLS_X25519_KEY_SIZE_BYTES) == 0 ) return MBEDTLS_ERR_ECP_RANDOM_FAILED; - return( 0 ); + return 0 ; } int mbedtls_x25519_make_public( mbedtls_x25519_context *ctx, size_t *olen, @@ -151,14 +151,14 @@ int mbedtls_x25519_make_public( mbedtls_x25519_context *ctx, size_t *olen, unsigned char base[MBEDTLS_X25519_KEY_SIZE_BYTES] = { 0 }; if( ctx == NULL ) - return( MBEDTLS_ERR_ECP_BAD_INPUT_DATA ); + return MBEDTLS_ERR_ECP_BAD_INPUT_DATA ; if( ( ret = f_rng( p_rng, ctx->our_secret, MBEDTLS_X25519_KEY_SIZE_BYTES ) ) != 0 ) return ret; *olen = MBEDTLS_X25519_KEY_SIZE_BYTES + 1; if( blen < *olen ) - return(MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL); + return MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL; *buf++ = MBEDTLS_X25519_KEY_SIZE_BYTES; base[0] = 9; @@ -168,18 +168,18 @@ int mbedtls_x25519_make_public( mbedtls_x25519_context *ctx, size_t *olen, if( memcmp( buf, base, MBEDTLS_X25519_KEY_SIZE_BYTES ) == 0 ) return MBEDTLS_ERR_ECP_RANDOM_FAILED; - return( ret ); + return ret ; } int mbedtls_x25519_read_public( mbedtls_x25519_context *ctx, const unsigned char *buf, size_t blen ) { if( blen < MBEDTLS_X25519_KEY_SIZE_BYTES + 1 ) - return(MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL); + return MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL; if( (*buf++ != MBEDTLS_X25519_KEY_SIZE_BYTES) ) - return(MBEDTLS_ERR_ECP_BAD_INPUT_DATA); + return MBEDTLS_ERR_ECP_BAD_INPUT_DATA; memcpy( ctx->peer_point, buf, MBEDTLS_X25519_KEY_SIZE_BYTES ); - return( 0 ); + return 0 ; } diff --git a/include/mbedtls/asn1write.h b/include/mbedtls/asn1write.h index d60ca0daa9..7a57f15ef5 100644 --- a/include/mbedtls/asn1write.h +++ b/include/mbedtls/asn1write.h @@ -30,7 +30,7 @@ do \ { \ if( ( ret = (f) ) < 0 ) \ - return( ret ); \ + return ret ; \ else \ (g) += ret; \ } while( 0 ) diff --git a/include/mbedtls/error.h b/include/mbedtls/error.h index 27420ce4fc..b546d4de9e 100644 --- a/include/mbedtls/error.h +++ b/include/mbedtls/error.h @@ -163,7 +163,7 @@ static inline int mbedtls_error_add( int high, int low, (void)file; (void)line; - return( high + low ); + return high + low ; } /** diff --git a/include/mbedtls/pk.h b/include/mbedtls/pk.h index ded52225f2..15d1a39985 100644 --- a/include/mbedtls/pk.h +++ b/include/mbedtls/pk.h @@ -390,7 +390,7 @@ size_t mbedtls_pk_get_bitlen( const mbedtls_pk_context *ctx ); */ static inline size_t mbedtls_pk_get_len( const mbedtls_pk_context *ctx ) { - return( ( mbedtls_pk_get_bitlen( ctx ) + 7 ) / 8 ); + return ( mbedtls_pk_get_bitlen( ctx ) + 7 ) / 8 ; } /** diff --git a/include/mbedtls/psa_util.h b/include/mbedtls/psa_util.h index f6f2e58054..1584ef2987 100644 --- a/include/mbedtls/psa_util.h +++ b/include/mbedtls/psa_util.h @@ -57,7 +57,7 @@ static inline psa_key_type_t mbedtls_psa_translate_cipher_type( case MBEDTLS_CIPHER_AES_128_CBC: case MBEDTLS_CIPHER_AES_192_CBC: case MBEDTLS_CIPHER_AES_256_CBC: - return( PSA_KEY_TYPE_AES ); + return PSA_KEY_TYPE_AES ; /* ARIA not yet supported in PSA. */ /* case MBEDTLS_CIPHER_ARIA_128_CCM: @@ -69,10 +69,10 @@ static inline psa_key_type_t mbedtls_psa_translate_cipher_type( case MBEDTLS_CIPHER_ARIA_128_CBC: case MBEDTLS_CIPHER_ARIA_192_CBC: case MBEDTLS_CIPHER_ARIA_256_CBC: - return( PSA_KEY_TYPE_ARIA ); */ + return PSA_KEY_TYPE_ARIA ; */ default: - return( 0 ); + return 0 ; } } @@ -82,18 +82,18 @@ static inline psa_algorithm_t mbedtls_psa_translate_cipher_mode( switch( mode ) { case MBEDTLS_MODE_ECB: - return( PSA_ALG_ECB_NO_PADDING ); + return PSA_ALG_ECB_NO_PADDING ; case MBEDTLS_MODE_GCM: - return( PSA_ALG_AEAD_WITH_SHORTENED_TAG( PSA_ALG_GCM, taglen ) ); + return PSA_ALG_AEAD_WITH_SHORTENED_TAG( PSA_ALG_GCM, taglen ) ; case MBEDTLS_MODE_CCM: - return( PSA_ALG_AEAD_WITH_SHORTENED_TAG( PSA_ALG_CCM, taglen ) ); + return PSA_ALG_AEAD_WITH_SHORTENED_TAG( PSA_ALG_CCM, taglen ) ; case MBEDTLS_MODE_CBC: if( taglen == 0 ) - return( PSA_ALG_CBC_NO_PADDING ); + return PSA_ALG_CBC_NO_PADDING ; else - return( 0 ); + return 0 ; default: - return( 0 ); + return 0 ; } } @@ -103,11 +103,11 @@ static inline psa_key_usage_t mbedtls_psa_translate_cipher_operation( switch( op ) { case MBEDTLS_ENCRYPT: - return( PSA_KEY_USAGE_ENCRYPT ); + return PSA_KEY_USAGE_ENCRYPT ; case MBEDTLS_DECRYPT: - return( PSA_KEY_USAGE_DECRYPT ); + return PSA_KEY_USAGE_DECRYPT ; default: - return( 0 ); + return 0 ; } } @@ -119,36 +119,36 @@ static inline psa_algorithm_t mbedtls_psa_translate_md( mbedtls_md_type_t md_alg { #if defined(MBEDTLS_MD5_C) case MBEDTLS_MD_MD5: - return( PSA_ALG_MD5 ); + return PSA_ALG_MD5 ; #endif #if defined(MBEDTLS_SHA1_C) case MBEDTLS_MD_SHA1: - return( PSA_ALG_SHA_1 ); + return PSA_ALG_SHA_1 ; #endif #if defined(MBEDTLS_SHA224_C) case MBEDTLS_MD_SHA224: - return( PSA_ALG_SHA_224 ); + return PSA_ALG_SHA_224 ; #endif #if defined(MBEDTLS_SHA256_C) case MBEDTLS_MD_SHA256: - return( PSA_ALG_SHA_256 ); + return PSA_ALG_SHA_256 ; #endif #if defined(MBEDTLS_SHA384_C) case MBEDTLS_MD_SHA384: - return( PSA_ALG_SHA_384 ); + return PSA_ALG_SHA_384 ; #endif #if defined(MBEDTLS_SHA512_C) case MBEDTLS_MD_SHA512: - return( PSA_ALG_SHA_512 ); + return PSA_ALG_SHA_512 ; #endif #if defined(MBEDTLS_RIPEMD160_C) case MBEDTLS_MD_RIPEMD160: - return( PSA_ALG_RIPEMD160 ); + return PSA_ALG_RIPEMD160 ; #endif case MBEDTLS_MD_NONE: - return( 0 ); + return 0 ; default: - return( 0 ); + return 0 ; } } @@ -167,31 +167,31 @@ static inline int mbedtls_psa_get_ecc_oid_from_id( case 192: *oid = MBEDTLS_OID_EC_GRP_SECP192R1; *oid_len = MBEDTLS_OID_SIZE( MBEDTLS_OID_EC_GRP_SECP192R1 ); - return( 0 ); + return 0 ; #endif /* MBEDTLS_ECP_DP_SECP192R1_ENABLED */ #if defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED) case 224: *oid = MBEDTLS_OID_EC_GRP_SECP224R1; *oid_len = MBEDTLS_OID_SIZE( MBEDTLS_OID_EC_GRP_SECP224R1 ); - return( 0 ); + return 0 ; #endif /* MBEDTLS_ECP_DP_SECP224R1_ENABLED */ #if defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED) case 256: *oid = MBEDTLS_OID_EC_GRP_SECP256R1; *oid_len = MBEDTLS_OID_SIZE( MBEDTLS_OID_EC_GRP_SECP256R1 ); - return( 0 ); + return 0 ; #endif /* MBEDTLS_ECP_DP_SECP256R1_ENABLED */ #if defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED) case 384: *oid = MBEDTLS_OID_EC_GRP_SECP384R1; *oid_len = MBEDTLS_OID_SIZE( MBEDTLS_OID_EC_GRP_SECP384R1 ); - return( 0 ); + return 0 ; #endif /* MBEDTLS_ECP_DP_SECP384R1_ENABLED */ #if defined(MBEDTLS_ECP_DP_SECP521R1_ENABLED) case 521: *oid = MBEDTLS_OID_EC_GRP_SECP521R1; *oid_len = MBEDTLS_OID_SIZE( MBEDTLS_OID_EC_GRP_SECP521R1 ); - return( 0 ); + return 0 ; #endif /* MBEDTLS_ECP_DP_SECP521R1_ENABLED */ } break; @@ -202,19 +202,19 @@ static inline int mbedtls_psa_get_ecc_oid_from_id( case 192: *oid = MBEDTLS_OID_EC_GRP_SECP192K1; *oid_len = MBEDTLS_OID_SIZE( MBEDTLS_OID_EC_GRP_SECP192K1 ); - return( 0 ); + return 0 ; #endif /* MBEDTLS_ECP_DP_SECP192K1_ENABLED */ #if defined(MBEDTLS_ECP_DP_SECP224K1_ENABLED) case 224: *oid = MBEDTLS_OID_EC_GRP_SECP224K1; *oid_len = MBEDTLS_OID_SIZE( MBEDTLS_OID_EC_GRP_SECP224K1 ); - return( 0 ); + return 0 ; #endif /* MBEDTLS_ECP_DP_SECP224K1_ENABLED */ #if defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED) case 256: *oid = MBEDTLS_OID_EC_GRP_SECP256K1; *oid_len = MBEDTLS_OID_SIZE( MBEDTLS_OID_EC_GRP_SECP256K1 ); - return( 0 ); + return 0 ; #endif /* MBEDTLS_ECP_DP_SECP256K1_ENABLED */ } break; @@ -225,26 +225,26 @@ static inline int mbedtls_psa_get_ecc_oid_from_id( case 256: *oid = MBEDTLS_OID_EC_GRP_BP256R1; *oid_len = MBEDTLS_OID_SIZE( MBEDTLS_OID_EC_GRP_BP256R1 ); - return( 0 ); + return 0 ; #endif /* MBEDTLS_ECP_DP_BP256R1_ENABLED */ #if defined(MBEDTLS_ECP_DP_BP384R1_ENABLED) case 384: *oid = MBEDTLS_OID_EC_GRP_BP384R1; *oid_len = MBEDTLS_OID_SIZE( MBEDTLS_OID_EC_GRP_BP384R1 ); - return( 0 ); + return 0 ; #endif /* MBEDTLS_ECP_DP_BP384R1_ENABLED */ #if defined(MBEDTLS_ECP_DP_BP512R1_ENABLED) case 512: *oid = MBEDTLS_OID_EC_GRP_BP512R1; *oid_len = MBEDTLS_OID_SIZE( MBEDTLS_OID_EC_GRP_BP512R1 ); - return( 0 ); + return 0 ; #endif /* MBEDTLS_ECP_DP_BP512R1_ENABLED */ } break; } (void) oid; (void) oid_len; - return( -1 ); + return -1 ; } #define MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH 1 @@ -334,24 +334,24 @@ static inline int mbedtls_psa_err_translate_pk( psa_status_t status ) switch( status ) { case PSA_SUCCESS: - return( 0 ); + return 0 ; case PSA_ERROR_NOT_SUPPORTED: - return( MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE ; case PSA_ERROR_INSUFFICIENT_MEMORY: - return( MBEDTLS_ERR_PK_ALLOC_FAILED ); + return MBEDTLS_ERR_PK_ALLOC_FAILED ; case PSA_ERROR_INSUFFICIENT_ENTROPY: - return( MBEDTLS_ERR_ECP_RANDOM_FAILED ); + return MBEDTLS_ERR_ECP_RANDOM_FAILED ; case PSA_ERROR_BAD_STATE: - return( MBEDTLS_ERR_PK_BAD_INPUT_DATA ); + return MBEDTLS_ERR_PK_BAD_INPUT_DATA ; /* All other failures */ case PSA_ERROR_COMMUNICATION_FAILURE: case PSA_ERROR_HARDWARE_FAILURE: case PSA_ERROR_CORRUPTION_DETECTED: - return( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED ); + return MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED ; default: /* We return the same as for the 'other failures', * but list them separately nonetheless to indicate * which failure conditions we have considered. */ - return( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED ); + return MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED ; } } @@ -367,7 +367,7 @@ static inline psa_key_type_t mbedtls_psa_parse_tls_ecc_group( const mbedtls_ecp_curve_info *curve_info = mbedtls_ecp_curve_info_from_tls_id( tls_ecc_grp_reg_id ); if( curve_info == NULL ) - return( 0 ); + return 0 ; return( PSA_KEY_TYPE_ECC_KEY_PAIR( mbedtls_ecc_group_to_psa( curve_info->MBEDTLS_PRIVATE(grp_id), bits ) ) ); } @@ -390,7 +390,7 @@ static inline int mbedtls_psa_tls_psa_ec_to_ecpoint( unsigned char *src, { *dst = src; *dstlen = srclen; - return( 0 ); + return 0 ; } /* This function takes a buffer holding an ECPoint structure @@ -405,11 +405,11 @@ static inline int mbedtls_psa_tls_ecpoint_to_psa_ec( unsigned char const *src, size_t *olen ) { if( srclen > dstlen ) - return( MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL ); + return MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL ; memcpy( dst, src, srclen ); *olen = srclen; - return( 0 ); + return 0 ; } #endif /* MBEDTLS_USE_PSA_CRYPTO */ diff --git a/include/mbedtls/ssl.h b/include/mbedtls/ssl.h index 221cee3379..c0f25290e0 100644 --- a/include/mbedtls/ssl.h +++ b/include/mbedtls/ssl.h @@ -3146,16 +3146,16 @@ static inline const char *mbedtls_ssl_get_srtp_profile_as_string( mbedtls_ssl_sr switch( profile ) { case MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_80: - return( "MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_80" ); + return "MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_80" ; case MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_32: - return( "MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_32" ); + return "MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_32" ; case MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_80: - return( "MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_80" ); + return "MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_80" ; case MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_32: - return( "MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_32" ); + return "MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_32" ; default: break; } - return( "" ); + return "" ; } #endif /* MBEDTLS_DEBUG_C */ /** diff --git a/include/mbedtls/ssl_ciphersuites.h b/include/mbedtls/ssl_ciphersuites.h index 812560c8a1..abaa642cfe 100644 --- a/include/mbedtls/ssl_ciphersuites.h +++ b/include/mbedtls/ssl_ciphersuites.h @@ -398,10 +398,10 @@ static inline int mbedtls_ssl_ciphersuite_has_pfs( const mbedtls_ssl_ciphersuite case MBEDTLS_KEY_EXCHANGE_ECDHE_PSK: case MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA: case MBEDTLS_KEY_EXCHANGE_ECJPAKE: - return( 1 ); + return 1 ; default: - return( 0 ); + return 0 ; } } #endif /* MBEDTLS_KEY_EXCHANGE_SOME_PFS_ENABLED */ @@ -416,10 +416,10 @@ static inline int mbedtls_ssl_ciphersuite_no_pfs( const mbedtls_ssl_ciphersuite_ case MBEDTLS_KEY_EXCHANGE_RSA: case MBEDTLS_KEY_EXCHANGE_PSK: case MBEDTLS_KEY_EXCHANGE_RSA_PSK: - return( 1 ); + return 1 ; default: - return( 0 ); + return 0 ; } } #endif /* MBEDTLS_KEY_EXCHANGE_SOME_NON_PFS_ENABLED */ @@ -431,10 +431,10 @@ static inline int mbedtls_ssl_ciphersuite_uses_ecdh( const mbedtls_ssl_ciphersui { case MBEDTLS_KEY_EXCHANGE_ECDH_RSA: case MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA: - return( 1 ); + return 1 ; default: - return( 0 ); + return 0 ; } } #endif /* MBEDTLS_KEY_EXCHANGE_SOME_ECDH_ENABLED */ @@ -449,10 +449,10 @@ static inline int mbedtls_ssl_ciphersuite_cert_req_allowed( const mbedtls_ssl_ci case MBEDTLS_KEY_EXCHANGE_ECDHE_RSA: case MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA: case MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA: - return( 1 ); + return 1 ; default: - return( 0 ); + return 0 ; } } @@ -467,10 +467,10 @@ static inline int mbedtls_ssl_ciphersuite_uses_srv_cert( const mbedtls_ssl_ciphe case MBEDTLS_KEY_EXCHANGE_ECDHE_RSA: case MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA: case MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA: - return( 1 ); + return 1 ; default: - return( 0 ); + return 0 ; } } @@ -481,10 +481,10 @@ static inline int mbedtls_ssl_ciphersuite_uses_dhe( const mbedtls_ssl_ciphersuit { case MBEDTLS_KEY_EXCHANGE_DHE_RSA: case MBEDTLS_KEY_EXCHANGE_DHE_PSK: - return( 1 ); + return 1 ; default: - return( 0 ); + return 0 ; } } #endif /* MBEDTLS_KEY_EXCHANGE_SOME_DHE_ENABLED) */ @@ -497,10 +497,10 @@ static inline int mbedtls_ssl_ciphersuite_uses_ecdhe( const mbedtls_ssl_ciphersu case MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA: case MBEDTLS_KEY_EXCHANGE_ECDHE_RSA: case MBEDTLS_KEY_EXCHANGE_ECDHE_PSK: - return( 1 ); + return 1 ; default: - return( 0 ); + return 0 ; } } #endif /* MBEDTLS_KEY_EXCHANGE_SOME_ECDHE_ENABLED) */ @@ -513,10 +513,10 @@ static inline int mbedtls_ssl_ciphersuite_uses_server_signature( const mbedtls_s case MBEDTLS_KEY_EXCHANGE_DHE_RSA: case MBEDTLS_KEY_EXCHANGE_ECDHE_RSA: case MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA: - return( 1 ); + return 1 ; default: - return( 0 ); + return 0 ; } } #endif /* MBEDTLS_KEY_EXCHANGE_WITH_SERVER_SIGNATURE_ENABLED */ diff --git a/include/mbedtls/x509.h b/include/mbedtls/x509.h index df187cb098..233cc85270 100644 --- a/include/mbedtls/x509.h +++ b/include/mbedtls/x509.h @@ -354,7 +354,7 @@ int mbedtls_x509_write_sig( unsigned char **p, unsigned char *start, #define MBEDTLS_X509_SAFE_SNPRINTF \ do { \ if( ret < 0 || (size_t) ret >= n ) \ - return( MBEDTLS_ERR_X509_BUFFER_TOO_SMALL ); \ + return MBEDTLS_ERR_X509_BUFFER_TOO_SMALL ; \ \ n -= (size_t) ret; \ p += (size_t) ret; \ diff --git a/include/psa/crypto_compat.h b/include/psa/crypto_compat.h index 1d3253cb28..ca35a2f276 100644 --- a/include/psa/crypto_compat.h +++ b/include/psa/crypto_compat.h @@ -52,7 +52,7 @@ typedef mbedtls_svc_key_id_t psa_key_handle_t; */ static inline int psa_key_handle_is_null( psa_key_handle_t handle ) { - return( mbedtls_svc_key_id_is_null( handle ) ); + return mbedtls_svc_key_id_is_null( handle ) ; } /** Open a handle to an existing persistent key. diff --git a/include/psa/crypto_extra.h b/include/psa/crypto_extra.h index 2c0b1067c8..aa50dc9e83 100644 --- a/include/psa/crypto_extra.h +++ b/include/psa/crypto_extra.h @@ -596,46 +596,46 @@ static inline psa_ecc_family_t mbedtls_ecc_group_to_psa( mbedtls_ecp_group_id gr { case MBEDTLS_ECP_DP_SECP192R1: *bits = 192; - return( PSA_ECC_FAMILY_SECP_R1 ); + return PSA_ECC_FAMILY_SECP_R1 ; case MBEDTLS_ECP_DP_SECP224R1: *bits = 224; - return( PSA_ECC_FAMILY_SECP_R1 ); + return PSA_ECC_FAMILY_SECP_R1 ; case MBEDTLS_ECP_DP_SECP256R1: *bits = 256; - return( PSA_ECC_FAMILY_SECP_R1 ); + return PSA_ECC_FAMILY_SECP_R1 ; case MBEDTLS_ECP_DP_SECP384R1: *bits = 384; - return( PSA_ECC_FAMILY_SECP_R1 ); + return PSA_ECC_FAMILY_SECP_R1 ; case MBEDTLS_ECP_DP_SECP521R1: *bits = 521; - return( PSA_ECC_FAMILY_SECP_R1 ); + return PSA_ECC_FAMILY_SECP_R1 ; case MBEDTLS_ECP_DP_BP256R1: *bits = 256; - return( PSA_ECC_FAMILY_BRAINPOOL_P_R1 ); + return PSA_ECC_FAMILY_BRAINPOOL_P_R1 ; case MBEDTLS_ECP_DP_BP384R1: *bits = 384; - return( PSA_ECC_FAMILY_BRAINPOOL_P_R1 ); + return PSA_ECC_FAMILY_BRAINPOOL_P_R1 ; case MBEDTLS_ECP_DP_BP512R1: *bits = 512; - return( PSA_ECC_FAMILY_BRAINPOOL_P_R1 ); + return PSA_ECC_FAMILY_BRAINPOOL_P_R1 ; case MBEDTLS_ECP_DP_CURVE25519: *bits = 255; - return( PSA_ECC_FAMILY_MONTGOMERY ); + return PSA_ECC_FAMILY_MONTGOMERY ; case MBEDTLS_ECP_DP_SECP192K1: *bits = 192; - return( PSA_ECC_FAMILY_SECP_K1 ); + return PSA_ECC_FAMILY_SECP_K1 ; case MBEDTLS_ECP_DP_SECP224K1: *bits = 224; - return( PSA_ECC_FAMILY_SECP_K1 ); + return PSA_ECC_FAMILY_SECP_K1 ; case MBEDTLS_ECP_DP_SECP256K1: *bits = 256; - return( PSA_ECC_FAMILY_SECP_K1 ); + return PSA_ECC_FAMILY_SECP_K1 ; case MBEDTLS_ECP_DP_CURVE448: *bits = 448; - return( PSA_ECC_FAMILY_MONTGOMERY ); + return PSA_ECC_FAMILY_MONTGOMERY ; default: *bits = 0; - return( 0 ); + return 0 ; } } @@ -1754,7 +1754,7 @@ struct psa_pake_cipher_suite_s static inline psa_algorithm_t psa_pake_cs_get_algorithm( const psa_pake_cipher_suite_t *cipher_suite) { - return(cipher_suite->algorithm); + return cipher_suite->algorithm; } static inline void psa_pake_cs_set_algorithm( @@ -1786,7 +1786,7 @@ static inline void psa_pake_cs_set_primitive( static inline psa_algorithm_t psa_pake_cs_get_hash( const psa_pake_cipher_suite_t *cipher_suite) { - return(cipher_suite->hash); + return cipher_suite->hash; } static inline void psa_pake_cs_set_hash( @@ -1814,7 +1814,7 @@ struct psa_pake_operation_s static inline struct psa_pake_operation_s psa_pake_operation_init(void) { const struct psa_pake_operation_s v = PSA_PAKE_OPERATION_INIT; - return(v); + return v; } #ifdef __cplusplus diff --git a/include/psa/crypto_platform.h b/include/psa/crypto_platform.h index 4787e44b6c..5f1e5c02ca 100644 --- a/include/psa/crypto_platform.h +++ b/include/psa/crypto_platform.h @@ -73,7 +73,7 @@ typedef int32_t mbedtls_key_owner_id_t; static inline int mbedtls_key_owner_id_equal( mbedtls_key_owner_id_t id1, mbedtls_key_owner_id_t id2 ) { - return( id1 == id2 ); + return id1 == id2 ; } #endif /* MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER */ diff --git a/include/psa/crypto_struct.h b/include/psa/crypto_struct.h index 381abf9605..ae732c3eea 100644 --- a/include/psa/crypto_struct.h +++ b/include/psa/crypto_struct.h @@ -93,7 +93,7 @@ struct psa_hash_operation_s static inline struct psa_hash_operation_s psa_hash_operation_init( void ) { const struct psa_hash_operation_s v = PSA_HASH_OPERATION_INIT; - return( v ); + return v ; } struct psa_cipher_operation_s @@ -118,7 +118,7 @@ struct psa_cipher_operation_s static inline struct psa_cipher_operation_s psa_cipher_operation_init( void ) { const struct psa_cipher_operation_s v = PSA_CIPHER_OPERATION_INIT; - return( v ); + return v ; } /* Include the context definition for the compiled-in drivers for the composite @@ -143,7 +143,7 @@ struct psa_mac_operation_s static inline struct psa_mac_operation_s psa_mac_operation_init( void ) { const struct psa_mac_operation_s v = PSA_MAC_OPERATION_INIT; - return( v ); + return v ; } struct psa_aead_operation_s @@ -164,7 +164,7 @@ struct psa_aead_operation_s static inline struct psa_aead_operation_s psa_aead_operation_init( void ) { const struct psa_aead_operation_s v = PSA_AEAD_OPERATION_INIT; - return( v ); + return v ; } #if defined(MBEDTLS_PSA_BUILTIN_ALG_HKDF) @@ -251,7 +251,7 @@ static inline struct psa_key_derivation_s psa_key_derivation_operation_init( void ) { const struct psa_key_derivation_s v = PSA_KEY_DERIVATION_OPERATION_INIT; - return( v ); + return v ; } struct psa_key_policy_s @@ -266,7 +266,7 @@ typedef struct psa_key_policy_s psa_key_policy_t; static inline struct psa_key_policy_s psa_key_policy_init( void ) { const struct psa_key_policy_s v = PSA_KEY_POLICY_INIT; - return( v ); + return v ; } /* The type used internally for key sizes. @@ -339,7 +339,7 @@ struct psa_key_attributes_s static inline struct psa_key_attributes_s psa_key_attributes_init( void ) { const struct psa_key_attributes_s v = PSA_KEY_ATTRIBUTES_INIT; - return( v ); + return v ; } static inline void psa_set_key_id( psa_key_attributes_t *attributes, diff --git a/include/psa/crypto_values.h b/include/psa/crypto_values.h index daef9416cc..0bf90985a4 100644 --- a/include/psa/crypto_values.h +++ b/include/psa/crypto_values.h @@ -2094,7 +2094,7 @@ static inline mbedtls_svc_key_id_t mbedtls_svc_key_id_make( { (void)unused; - return( key_id ); + return key_id ; } /** Compare two key identifiers. @@ -2107,7 +2107,7 @@ static inline mbedtls_svc_key_id_t mbedtls_svc_key_id_make( static inline int mbedtls_svc_key_id_equal( mbedtls_svc_key_id_t id1, mbedtls_svc_key_id_t id2 ) { - return( id1 == id2 ); + return id1 == id2 ; } /** Check whether a key identifier is null. @@ -2118,7 +2118,7 @@ static inline int mbedtls_svc_key_id_equal( mbedtls_svc_key_id_t id1, */ static inline int mbedtls_svc_key_id_is_null( mbedtls_svc_key_id_t key ) { - return( key == 0 ); + return key == 0 ; } #else /* MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER */ @@ -2161,7 +2161,7 @@ static inline int mbedtls_svc_key_id_equal( mbedtls_svc_key_id_t id1, */ static inline int mbedtls_svc_key_id_is_null( mbedtls_svc_key_id_t key ) { - return( key.MBEDTLS_PRIVATE(key_id) == 0 ); + return key.MBEDTLS_PRIVATE(key_id) == 0 ; } #endif /* !MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER */ diff --git a/library/aes.c b/library/aes.c index a15a80924a..d18278e927 100644 --- a/library/aes.c +++ b/library/aes.c @@ -562,7 +562,7 @@ int mbedtls_aes_setkey_enc( mbedtls_aes_context *ctx, const unsigned char *key, case 128: ctx->nr = 10; break; case 192: ctx->nr = 12; break; case 256: ctx->nr = 14; break; - default : return( MBEDTLS_ERR_AES_INVALID_KEY_LENGTH ); + default : return MBEDTLS_ERR_AES_INVALID_KEY_LENGTH ; } #if !defined(MBEDTLS_AES_ROM_TABLES) @@ -585,7 +585,7 @@ int mbedtls_aes_setkey_enc( mbedtls_aes_context *ctx, const unsigned char *key, #if defined(MBEDTLS_AESNI_C) && defined(MBEDTLS_HAVE_X86_64) if( mbedtls_aesni_has_support( MBEDTLS_AESNI_AES ) ) - return( mbedtls_aesni_setkey_enc( (unsigned char *) ctx->rk, key, keybits ) ); + return mbedtls_aesni_setkey_enc( (unsigned char *) ctx->rk, key, keybits ) ; #endif for( i = 0; i < ( keybits >> 5 ); i++ ) @@ -656,7 +656,7 @@ int mbedtls_aes_setkey_enc( mbedtls_aes_context *ctx, const unsigned char *key, break; } - return( 0 ); + return 0 ; } #endif /* !MBEDTLS_AES_SETKEY_ENC_ALT */ @@ -728,7 +728,7 @@ int mbedtls_aes_setkey_dec( mbedtls_aes_context *ctx, const unsigned char *key, exit: mbedtls_aes_free( &cty ); - return( ret ); + return ret ; } #endif /* !MBEDTLS_AES_SETKEY_DEC_ALT */ @@ -747,7 +747,7 @@ static int mbedtls_aes_xts_decode_keys( const unsigned char *key, { case 256: break; case 512: break; - default : return( MBEDTLS_ERR_AES_INVALID_KEY_LENGTH ); + default : return MBEDTLS_ERR_AES_INVALID_KEY_LENGTH ; } *key1bits = half_keybits; @@ -772,12 +772,12 @@ int mbedtls_aes_xts_setkey_enc( mbedtls_aes_xts_context *ctx, ret = mbedtls_aes_xts_decode_keys( key, keybits, &key1, &key1bits, &key2, &key2bits ); if( ret != 0 ) - return( ret ); + return ret ; /* Set the tweak key. Always set tweak key for the encryption mode. */ ret = mbedtls_aes_setkey_enc( &ctx->tweak, key2, key2bits ); if( ret != 0 ) - return( ret ); + return ret ; /* Set crypt key for encryption. */ return mbedtls_aes_setkey_enc( &ctx->crypt, key1, key1bits ); @@ -797,12 +797,12 @@ int mbedtls_aes_xts_setkey_dec( mbedtls_aes_xts_context *ctx, ret = mbedtls_aes_xts_decode_keys( key, keybits, &key1, &key1bits, &key2, &key2bits ); if( ret != 0 ) - return( ret ); + return ret ; /* Set the tweak key. Always set tweak key for encryption. */ ret = mbedtls_aes_setkey_enc( &ctx->tweak, key2, key2bits ); if( ret != 0 ) - return( ret ); + return ret ; /* Set crypt key for decryption. */ return mbedtls_aes_setkey_dec( &ctx->crypt, key1, key1bits ); @@ -917,7 +917,7 @@ int mbedtls_internal_aes_encrypt( mbedtls_aes_context *ctx, mbedtls_platform_zeroize( &t, sizeof( t ) ); - return( 0 ); + return 0 ; } #endif /* !MBEDTLS_AES_ENCRYPT_ALT */ @@ -981,7 +981,7 @@ int mbedtls_internal_aes_decrypt( mbedtls_aes_context *ctx, mbedtls_platform_zeroize( &t, sizeof( t ) ); - return( 0 ); + return 0 ; } #endif /* !MBEDTLS_AES_DECRYPT_ALT */ @@ -1001,14 +1001,14 @@ int mbedtls_aes_crypt_ecb( mbedtls_aes_context *ctx, #if defined(MBEDTLS_AESNI_C) && defined(MBEDTLS_HAVE_X86_64) if( mbedtls_aesni_has_support( MBEDTLS_AESNI_AES ) ) - return( mbedtls_aesni_crypt_ecb( ctx, mode, input, output ) ); + return mbedtls_aesni_crypt_ecb( ctx, mode, input, output ) ; #endif #if defined(MBEDTLS_PADLOCK_C) && defined(MBEDTLS_HAVE_X86) if( aes_padlock_ace > 0) { if( mbedtls_padlock_xcryptecb( ctx, mode, input, output ) == 0 ) - return( 0 ); + return 0 ; // If padlock data misaligned, we just fall back to // unaccelerated mode @@ -1017,9 +1017,9 @@ int mbedtls_aes_crypt_ecb( mbedtls_aes_context *ctx, #endif if( mode == MBEDTLS_AES_ENCRYPT ) - return( mbedtls_internal_aes_encrypt( ctx, input, output ) ); + return mbedtls_internal_aes_encrypt( ctx, input, output ) ; else - return( mbedtls_internal_aes_decrypt( ctx, input, output ) ); + return mbedtls_internal_aes_decrypt( ctx, input, output ) ; } #if defined(MBEDTLS_CIPHER_MODE_CBC) @@ -1044,13 +1044,13 @@ int mbedtls_aes_crypt_cbc( mbedtls_aes_context *ctx, AES_VALIDATE_RET( output != NULL ); if( length % 16 ) - return( MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH ); + return MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH ; #if defined(MBEDTLS_PADLOCK_C) && defined(MBEDTLS_HAVE_X86) if( aes_padlock_ace > 0 ) { if( mbedtls_padlock_xcryptcbc( ctx, mode, length, iv, input, output ) == 0 ) - return( 0 ); + return 0 ; // If padlock data misaligned, we just fall back to // unaccelerated mode @@ -1091,7 +1091,7 @@ int mbedtls_aes_crypt_cbc( mbedtls_aes_context *ctx, } } - return( 0 ); + return 0 ; } #endif /* MBEDTLS_CIPHER_MODE_CBC */ @@ -1187,7 +1187,7 @@ int mbedtls_aes_crypt_xts( mbedtls_aes_xts_context *ctx, ret = mbedtls_aes_crypt_ecb( &ctx->tweak, MBEDTLS_AES_ENCRYPT, data_unit, tweak ); if( ret != 0 ) - return( ret ); + return ret ; while( blocks-- ) { @@ -1209,7 +1209,7 @@ int mbedtls_aes_crypt_xts( mbedtls_aes_xts_context *ctx, ret = mbedtls_aes_crypt_ecb( &ctx->crypt, mode, tmp, tmp ); if( ret != 0 ) - return( ret ); + return ret ; for( i = 0; i < 16; i++ ) output[i] = tmp[i] ^ tweak[i]; @@ -1257,7 +1257,7 @@ int mbedtls_aes_crypt_xts( mbedtls_aes_xts_context *ctx, prev_output[i] = tmp[i] ^ t[i]; } - return( 0 ); + return 0 ; } #endif /* MBEDTLS_CIPHER_MODE_XTS */ @@ -1287,7 +1287,7 @@ int mbedtls_aes_crypt_cfb128( mbedtls_aes_context *ctx, n = *iv_off; if( n > 15 ) - return( MBEDTLS_ERR_AES_BAD_INPUT_DATA ); + return MBEDTLS_ERR_AES_BAD_INPUT_DATA ; if( mode == MBEDTLS_AES_DECRYPT ) { @@ -1318,7 +1318,7 @@ int mbedtls_aes_crypt_cfb128( mbedtls_aes_context *ctx, *iv_off = n; - return( 0 ); + return 0 ; } /* @@ -1356,7 +1356,7 @@ int mbedtls_aes_crypt_cfb8( mbedtls_aes_context *ctx, memcpy( iv, ov + 1, 16 ); } - return( 0 ); + return 0 ; } #endif /* MBEDTLS_CIPHER_MODE_CFB */ @@ -1383,7 +1383,7 @@ int mbedtls_aes_crypt_ofb( mbedtls_aes_context *ctx, n = *iv_off; if( n > 15 ) - return( MBEDTLS_ERR_AES_BAD_INPUT_DATA ); + return MBEDTLS_ERR_AES_BAD_INPUT_DATA ; while( length-- ) { @@ -1401,7 +1401,7 @@ int mbedtls_aes_crypt_ofb( mbedtls_aes_context *ctx, *iv_off = n; exit: - return( ret ); + return ret ; } #endif /* MBEDTLS_CIPHER_MODE_OFB */ @@ -1430,7 +1430,7 @@ int mbedtls_aes_crypt_ctr( mbedtls_aes_context *ctx, n = *nc_off; if ( n > 0x0F ) - return( MBEDTLS_ERR_AES_BAD_INPUT_DATA ); + return MBEDTLS_ERR_AES_BAD_INPUT_DATA ; while( length-- ) { @@ -1449,7 +1449,7 @@ int mbedtls_aes_crypt_ctr( mbedtls_aes_context *ctx, *nc_off = n; - return( 0 ); + return 0 ; } #endif /* MBEDTLS_CIPHER_MODE_CTR */ @@ -2187,7 +2187,7 @@ exit: mbedtls_aes_free( &ctx ); - return( ret ); + return ret ; } #endif /* MBEDTLS_SELF_TEST */ diff --git a/library/aesni.c b/library/aesni.c index be226c9c00..09a9e9a163 100644 --- a/library/aesni.c +++ b/library/aesni.c @@ -60,7 +60,7 @@ int mbedtls_aesni_has_support( unsigned int what ) done = 1; } - return( ( c & what ) != 0 ); + return ( c & what ) != 0 ; } /* @@ -131,7 +131,7 @@ int mbedtls_aesni_crypt_ecb( mbedtls_aes_context *ctx, : "memory", "cc", "xmm0", "xmm1" ); - return( 0 ); + return 0 ; } /* @@ -453,10 +453,10 @@ int mbedtls_aesni_setkey_enc( unsigned char *rk, case 128: aesni_setkey_enc_128( rk, key ); break; case 192: aesni_setkey_enc_192( rk, key ); break; case 256: aesni_setkey_enc_256( rk, key ); break; - default : return( MBEDTLS_ERR_AES_INVALID_KEY_LENGTH ); + default : return MBEDTLS_ERR_AES_INVALID_KEY_LENGTH ; } - return( 0 ); + return 0 ; } #endif /* MBEDTLS_HAVE_X86_64 */ diff --git a/library/aria.c b/library/aria.c index a5786b37ab..0a47373a54 100644 --- a/library/aria.c +++ b/library/aria.c @@ -96,7 +96,7 @@ static inline uint32_t aria_p1( uint32_t x ) { uint32_t r; __asm( "rev16 %0, %1" : "=l" (r) : "l" (x) ); - return( r ); + return r ; } #define ARIA_P1 aria_p1 #elif defined(__ARMCC_VERSION) && __ARMCC_VERSION < 6000000 && \ @@ -105,7 +105,7 @@ static inline uint32_t aria_p1( uint32_t x ) { uint32_t r; __asm( "rev16 r, x" ); - return( r ); + return r ; } #define ARIA_P1 aria_p1 #endif @@ -147,7 +147,7 @@ static inline uint32_t aria_p3( uint32_t x ) { uint32_t r; __asm( "rev %0, %1" : "=l" (r) : "l" (x) ); - return( r ); + return r ; } #define ARIA_P3 aria_p3 #elif defined(__ARMCC_VERSION) && __ARMCC_VERSION < 6000000 && \ @@ -156,7 +156,7 @@ static inline uint32_t aria_p3( uint32_t x ) { uint32_t r; __asm( "rev r, x" ); - return( r ); + return r ; } #define ARIA_P3 aria_p3 #endif @@ -166,7 +166,7 @@ static inline uint32_t aria_p3( uint32_t x ) static inline uint32_t aria_p3( uint32_t x ) { __asm( "bswap %0" : "=r" (x) : "0" (x) ); - return( x ); + return x ; } #define ARIA_P3 aria_p3 #endif /* x86 gnuc */ @@ -453,7 +453,7 @@ int mbedtls_aria_setkey_enc( mbedtls_aria_context *ctx, ARIA_VALIDATE_RET( key != NULL ); if( keybits != 128 && keybits != 192 && keybits != 256 ) - return( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA ); + return MBEDTLS_ERR_ARIA_BAD_INPUT_DATA ; /* Copy key to W0 (and potential remainder to W1) */ GET_UINT32_LE( w[0][0], key, 0 ); @@ -495,7 +495,7 @@ int mbedtls_aria_setkey_enc( mbedtls_aria_context *ctx, /* w holds enough info to reconstruct the round keys */ mbedtls_platform_zeroize( w, sizeof( w ) ); - return( 0 ); + return 0 ; } /* @@ -510,7 +510,7 @@ int mbedtls_aria_setkey_dec( mbedtls_aria_context *ctx, ret = mbedtls_aria_setkey_enc( ctx, key, keybits ); if( ret != 0 ) - return( ret ); + return ret ; /* flip the order of round keys */ for( i = 0, j = ctx->nr; i < j; i++, j-- ) @@ -530,7 +530,7 @@ int mbedtls_aria_setkey_dec( mbedtls_aria_context *ctx, &ctx->rk[i][2], &ctx->rk[i][3] ); } - return( 0 ); + return 0 ; } /* @@ -587,7 +587,7 @@ int mbedtls_aria_crypt_ecb( mbedtls_aria_context *ctx, PUT_UINT32_LE( c, output, 8 ); PUT_UINT32_LE( d, output, 12 ); - return( 0 ); + return 0 ; } /* Initialize context */ @@ -628,7 +628,7 @@ int mbedtls_aria_crypt_cbc( mbedtls_aria_context *ctx, ARIA_VALIDATE_RET( iv != NULL ); if( length % MBEDTLS_ARIA_BLOCKSIZE ) - return( MBEDTLS_ERR_ARIA_INVALID_INPUT_LENGTH ); + return MBEDTLS_ERR_ARIA_INVALID_INPUT_LENGTH ; if( mode == MBEDTLS_ARIA_DECRYPT ) { @@ -663,7 +663,7 @@ int mbedtls_aria_crypt_cbc( mbedtls_aria_context *ctx, } } - return( 0 ); + return 0 ; } #endif /* MBEDTLS_CIPHER_MODE_CBC */ @@ -696,7 +696,7 @@ int mbedtls_aria_crypt_cfb128( mbedtls_aria_context *ctx, * buffer overflow. Therefore, guard against this * outside of parameter validation. */ if( n >= MBEDTLS_ARIA_BLOCKSIZE ) - return( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA ); + return MBEDTLS_ERR_ARIA_BAD_INPUT_DATA ; if( mode == MBEDTLS_ARIA_DECRYPT ) { @@ -727,7 +727,7 @@ int mbedtls_aria_crypt_cfb128( mbedtls_aria_context *ctx, *iv_off = n; - return( 0 ); + return 0 ; } #endif /* MBEDTLS_CIPHER_MODE_CFB */ @@ -758,7 +758,7 @@ int mbedtls_aria_crypt_ctr( mbedtls_aria_context *ctx, * buffer overflow. Therefore, guard against this * outside of parameter validation. */ if( n >= MBEDTLS_ARIA_BLOCKSIZE ) - return( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA ); + return MBEDTLS_ERR_ARIA_BAD_INPUT_DATA ; while( length-- ) { @@ -778,7 +778,7 @@ int mbedtls_aria_crypt_ctr( mbedtls_aria_context *ctx, *nc_off = n; - return( 0 ); + return 0 ; } #endif /* MBEDTLS_CIPHER_MODE_CTR */ #endif /* !MBEDTLS_ARIA_ALT */ @@ -1072,7 +1072,7 @@ int mbedtls_aria_self_test( int verbose ) exit: mbedtls_aria_free( &ctx ); - return( ret ); + return ret ; } #endif /* MBEDTLS_SELF_TEST */ diff --git a/library/asn1parse.c b/library/asn1parse.c index 83c7c58a12..67c162a6ae 100644 --- a/library/asn1parse.c +++ b/library/asn1parse.c @@ -47,7 +47,7 @@ int mbedtls_asn1_get_len( unsigned char **p, size_t *len ) { if( ( end - *p ) < 1 ) - return( MBEDTLS_ERR_ASN1_OUT_OF_DATA ); + return MBEDTLS_ERR_ASN1_OUT_OF_DATA ; if( ( **p & 0x80 ) == 0 ) *len = *(*p)++; @@ -57,7 +57,7 @@ int mbedtls_asn1_get_len( unsigned char **p, { case 1: if( ( end - *p ) < 2 ) - return( MBEDTLS_ERR_ASN1_OUT_OF_DATA ); + return MBEDTLS_ERR_ASN1_OUT_OF_DATA ; *len = (*p)[1]; (*p) += 2; @@ -65,7 +65,7 @@ int mbedtls_asn1_get_len( unsigned char **p, case 2: if( ( end - *p ) < 3 ) - return( MBEDTLS_ERR_ASN1_OUT_OF_DATA ); + return MBEDTLS_ERR_ASN1_OUT_OF_DATA ; *len = ( (size_t)(*p)[1] << 8 ) | (*p)[2]; (*p) += 3; @@ -73,7 +73,7 @@ int mbedtls_asn1_get_len( unsigned char **p, case 3: if( ( end - *p ) < 4 ) - return( MBEDTLS_ERR_ASN1_OUT_OF_DATA ); + return MBEDTLS_ERR_ASN1_OUT_OF_DATA ; *len = ( (size_t)(*p)[1] << 16 ) | ( (size_t)(*p)[2] << 8 ) | (*p)[3]; @@ -82,7 +82,7 @@ int mbedtls_asn1_get_len( unsigned char **p, case 4: if( ( end - *p ) < 5 ) - return( MBEDTLS_ERR_ASN1_OUT_OF_DATA ); + return MBEDTLS_ERR_ASN1_OUT_OF_DATA ; *len = ( (size_t)(*p)[1] << 24 ) | ( (size_t)(*p)[2] << 16 ) | ( (size_t)(*p)[3] << 8 ) | (*p)[4]; @@ -90,14 +90,14 @@ int mbedtls_asn1_get_len( unsigned char **p, break; default: - return( MBEDTLS_ERR_ASN1_INVALID_LENGTH ); + return MBEDTLS_ERR_ASN1_INVALID_LENGTH ; } } if( *len > (size_t) ( end - *p ) ) - return( MBEDTLS_ERR_ASN1_OUT_OF_DATA ); + return MBEDTLS_ERR_ASN1_OUT_OF_DATA ; - return( 0 ); + return 0 ; } int mbedtls_asn1_get_tag( unsigned char **p, @@ -105,14 +105,14 @@ int mbedtls_asn1_get_tag( unsigned char **p, size_t *len, int tag ) { if( ( end - *p ) < 1 ) - return( MBEDTLS_ERR_ASN1_OUT_OF_DATA ); + return MBEDTLS_ERR_ASN1_OUT_OF_DATA ; if( **p != tag ) - return( MBEDTLS_ERR_ASN1_UNEXPECTED_TAG ); + return MBEDTLS_ERR_ASN1_UNEXPECTED_TAG ; (*p)++; - return( mbedtls_asn1_get_len( p, end, len ) ); + return mbedtls_asn1_get_len( p, end, len ) ; } int mbedtls_asn1_get_bool( unsigned char **p, @@ -123,15 +123,15 @@ int mbedtls_asn1_get_bool( unsigned char **p, size_t len; if( ( ret = mbedtls_asn1_get_tag( p, end, &len, MBEDTLS_ASN1_BOOLEAN ) ) != 0 ) - return( ret ); + return ret ; if( len != 1 ) - return( MBEDTLS_ERR_ASN1_INVALID_LENGTH ); + return MBEDTLS_ERR_ASN1_INVALID_LENGTH ; *val = ( **p != 0 ) ? 1 : 0; (*p)++; - return( 0 ); + return 0 ; } static int asn1_get_tagged_int( unsigned char **p, @@ -142,17 +142,17 @@ static int asn1_get_tagged_int( unsigned char **p, size_t len; if( ( ret = mbedtls_asn1_get_tag( p, end, &len, tag ) ) != 0 ) - return( ret ); + return ret ; /* * len==0 is malformed (0 must be represented as 020100 for INTEGER, * or 0A0100 for ENUMERATED tags */ if( len == 0 ) - return( MBEDTLS_ERR_ASN1_INVALID_LENGTH ); + return MBEDTLS_ERR_ASN1_INVALID_LENGTH ; /* This is a cryptography library. Reject negative integers. */ if( ( **p & 0x80 ) != 0 ) - return( MBEDTLS_ERR_ASN1_INVALID_LENGTH ); + return MBEDTLS_ERR_ASN1_INVALID_LENGTH ; /* Skip leading zeros. */ while( len > 0 && **p == 0 ) @@ -164,9 +164,9 @@ static int asn1_get_tagged_int( unsigned char **p, /* Reject integers that don't fit in an int. This code assumes that * the int type has no padding bit. */ if( len > sizeof( int ) ) - return( MBEDTLS_ERR_ASN1_INVALID_LENGTH ); + return MBEDTLS_ERR_ASN1_INVALID_LENGTH ; if( len == sizeof( int ) && ( **p & 0x80 ) != 0 ) - return( MBEDTLS_ERR_ASN1_INVALID_LENGTH ); + return MBEDTLS_ERR_ASN1_INVALID_LENGTH ; *val = 0; while( len-- > 0 ) @@ -175,21 +175,21 @@ static int asn1_get_tagged_int( unsigned char **p, (*p)++; } - return( 0 ); + return 0 ; } int mbedtls_asn1_get_int( unsigned char **p, const unsigned char *end, int *val ) { - return( asn1_get_tagged_int( p, end, MBEDTLS_ASN1_INTEGER, val) ); + return asn1_get_tagged_int( p, end, MBEDTLS_ASN1_INTEGER, val) ; } int mbedtls_asn1_get_enum( unsigned char **p, const unsigned char *end, int *val ) { - return( asn1_get_tagged_int( p, end, MBEDTLS_ASN1_ENUMERATED, val) ); + return asn1_get_tagged_int( p, end, MBEDTLS_ASN1_ENUMERATED, val) ; } #if defined(MBEDTLS_BIGNUM_C) @@ -201,13 +201,13 @@ int mbedtls_asn1_get_mpi( unsigned char **p, size_t len; if( ( ret = mbedtls_asn1_get_tag( p, end, &len, MBEDTLS_ASN1_INTEGER ) ) != 0 ) - return( ret ); + return ret ; ret = mbedtls_mpi_read_binary( X, *p, len ); *p += len; - return( ret ); + return ret ; } #endif /* MBEDTLS_BIGNUM_C */ @@ -218,17 +218,17 @@ int mbedtls_asn1_get_bitstring( unsigned char **p, const unsigned char *end, /* Certificate type is a single byte bitstring */ if( ( ret = mbedtls_asn1_get_tag( p, end, &bs->len, MBEDTLS_ASN1_BIT_STRING ) ) != 0 ) - return( ret ); + return ret ; /* Check length, subtract one for actual bit string length */ if( bs->len < 1 ) - return( MBEDTLS_ERR_ASN1_OUT_OF_DATA ); + return MBEDTLS_ERR_ASN1_OUT_OF_DATA ; bs->len -= 1; /* Get number of unused bits, ensure unused bits <= 7 */ bs->unused_bits = **p; if( bs->unused_bits > 7 ) - return( MBEDTLS_ERR_ASN1_INVALID_LENGTH ); + return MBEDTLS_ERR_ASN1_INVALID_LENGTH ; (*p)++; /* Get actual bitstring */ @@ -236,9 +236,9 @@ int mbedtls_asn1_get_bitstring( unsigned char **p, const unsigned char *end, *p += bs->len; if( *p != end ) - return( MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ); + return MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ; - return( 0 ); + return 0 ; } /* @@ -261,21 +261,21 @@ int mbedtls_asn1_traverse_sequence_of( if( ( ret = mbedtls_asn1_get_tag( p, end, &len, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 ) { - return( ret ); + return ret ; } if( *p + len != end ) - return( MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ); + return MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ; while( *p < end ) { unsigned char const tag = *(*p)++; if( ( tag & tag_must_mask ) != tag_must_val ) - return( MBEDTLS_ERR_ASN1_UNEXPECTED_TAG ); + return MBEDTLS_ERR_ASN1_UNEXPECTED_TAG ; if( ( ret = mbedtls_asn1_get_len( p, end, &len ) ) != 0 ) - return( ret ); + return ret ; if( ( tag & tag_may_mask ) == tag_may_val ) { @@ -283,14 +283,14 @@ int mbedtls_asn1_traverse_sequence_of( { ret = cb( ctx, tag, *p, len ); if( ret != 0 ) - return( ret ); + return ret ; } } *p += len; } - return( 0 ); + return 0 ; } /* @@ -302,17 +302,17 @@ int mbedtls_asn1_get_bitstring_null( unsigned char **p, const unsigned char *end int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; if( ( ret = mbedtls_asn1_get_tag( p, end, len, MBEDTLS_ASN1_BIT_STRING ) ) != 0 ) - return( ret ); + return ret ; if( *len == 0 ) - return( MBEDTLS_ERR_ASN1_INVALID_DATA ); + return MBEDTLS_ERR_ASN1_INVALID_DATA ; --( *len ); if( **p != 0 ) - return( MBEDTLS_ERR_ASN1_INVALID_DATA ); + return MBEDTLS_ERR_ASN1_INVALID_DATA ; ++( *p ); - return( 0 ); + return 0 ; } void mbedtls_asn1_sequence_free( mbedtls_asn1_sequence *seq ) @@ -348,7 +348,7 @@ static int asn1_get_sequence_of_cb( void *ctx, mbedtls_calloc( 1, sizeof( mbedtls_asn1_sequence ) ); if( cur->next == NULL ) - return( MBEDTLS_ERR_ASN1_ALLOC_FAILED ); + return MBEDTLS_ERR_ASN1_ALLOC_FAILED ; cur = cur->next; } @@ -358,7 +358,7 @@ static int asn1_get_sequence_of_cb( void *ctx, cur->buf.tag = tag; cb_ctx->cur = cur; - return( 0 ); + return 0 ; } /* @@ -385,16 +385,16 @@ int mbedtls_asn1_get_alg( unsigned char **p, if( ( ret = mbedtls_asn1_get_tag( p, end, &len, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 ) - return( ret ); + return ret ; if( ( end - *p ) < 1 ) - return( MBEDTLS_ERR_ASN1_OUT_OF_DATA ); + return MBEDTLS_ERR_ASN1_OUT_OF_DATA ; alg->tag = **p; end = *p + len; if( ( ret = mbedtls_asn1_get_tag( p, end, &alg->len, MBEDTLS_ASN1_OID ) ) != 0 ) - return( ret ); + return ret ; alg->p = *p; *p += alg->len; @@ -402,22 +402,22 @@ int mbedtls_asn1_get_alg( unsigned char **p, if( *p == end ) { mbedtls_platform_zeroize( params, sizeof(mbedtls_asn1_buf) ); - return( 0 ); + return 0 ; } params->tag = **p; (*p)++; if( ( ret = mbedtls_asn1_get_len( p, end, ¶ms->len ) ) != 0 ) - return( ret ); + return ret ; params->p = *p; *p += params->len; if( *p != end ) - return( MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ); + return MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ; - return( 0 ); + return 0 ; } int mbedtls_asn1_get_alg_null( unsigned char **p, @@ -430,12 +430,12 @@ int mbedtls_asn1_get_alg_null( unsigned char **p, memset( ¶ms, 0, sizeof(mbedtls_asn1_buf) ); if( ( ret = mbedtls_asn1_get_alg( p, end, alg, ¶ms ) ) != 0 ) - return( ret ); + return ret ; if( ( params.tag != MBEDTLS_ASN1_NULL && params.tag != 0 ) || params.len != 0 ) - return( MBEDTLS_ERR_ASN1_INVALID_DATA ); + return MBEDTLS_ERR_ASN1_INVALID_DATA ; - return( 0 ); + return 0 ; } void mbedtls_asn1_free_named_data( mbedtls_asn1_named_data *cur ) @@ -475,7 +475,7 @@ const mbedtls_asn1_named_data *mbedtls_asn1_find_named_data( const mbedtls_asn1_ list = list->next; } - return( list ); + return list ; } #endif /* MBEDTLS_ASN1_PARSE_C */ diff --git a/library/asn1write.c b/library/asn1write.c index 0289e89491..8391e80505 100644 --- a/library/asn1write.c +++ b/library/asn1write.c @@ -39,43 +39,43 @@ int mbedtls_asn1_write_len( unsigned char **p, const unsigned char *start, size_ if( len < 0x80 ) { if( *p - start < 1 ) - return( MBEDTLS_ERR_ASN1_BUF_TOO_SMALL ); + return MBEDTLS_ERR_ASN1_BUF_TOO_SMALL ; *--(*p) = (unsigned char) len; - return( 1 ); + return 1 ; } if( len <= 0xFF ) { if( *p - start < 2 ) - return( MBEDTLS_ERR_ASN1_BUF_TOO_SMALL ); + return MBEDTLS_ERR_ASN1_BUF_TOO_SMALL ; *--(*p) = (unsigned char) len; *--(*p) = 0x81; - return( 2 ); + return 2 ; } if( len <= 0xFFFF ) { if( *p - start < 3 ) - return( MBEDTLS_ERR_ASN1_BUF_TOO_SMALL ); + return MBEDTLS_ERR_ASN1_BUF_TOO_SMALL ; *--(*p) = ( len ) & 0xFF; *--(*p) = ( len >> 8 ) & 0xFF; *--(*p) = 0x82; - return( 3 ); + return 3 ; } if( len <= 0xFFFFFF ) { if( *p - start < 4 ) - return( MBEDTLS_ERR_ASN1_BUF_TOO_SMALL ); + return MBEDTLS_ERR_ASN1_BUF_TOO_SMALL ; *--(*p) = ( len ) & 0xFF; *--(*p) = ( len >> 8 ) & 0xFF; *--(*p) = ( len >> 16 ) & 0xFF; *--(*p) = 0x83; - return( 4 ); + return 4 ; } #if SIZE_MAX > 0xFFFFFFFF @@ -83,29 +83,29 @@ int mbedtls_asn1_write_len( unsigned char **p, const unsigned char *start, size_ #endif { if( *p - start < 5 ) - return( MBEDTLS_ERR_ASN1_BUF_TOO_SMALL ); + return MBEDTLS_ERR_ASN1_BUF_TOO_SMALL ; *--(*p) = ( len ) & 0xFF; *--(*p) = ( len >> 8 ) & 0xFF; *--(*p) = ( len >> 16 ) & 0xFF; *--(*p) = ( len >> 24 ) & 0xFF; *--(*p) = 0x84; - return( 5 ); + return 5 ; } #if SIZE_MAX > 0xFFFFFFFF - return( MBEDTLS_ERR_ASN1_INVALID_LENGTH ); + return MBEDTLS_ERR_ASN1_INVALID_LENGTH ; #endif } int mbedtls_asn1_write_tag( unsigned char **p, const unsigned char *start, unsigned char tag ) { if( *p - start < 1 ) - return( MBEDTLS_ERR_ASN1_BUF_TOO_SMALL ); + return MBEDTLS_ERR_ASN1_BUF_TOO_SMALL ; *--(*p) = tag; - return( 1 ); + return 1 ; } int mbedtls_asn1_write_raw_buffer( unsigned char **p, const unsigned char *start, @@ -114,13 +114,13 @@ int mbedtls_asn1_write_raw_buffer( unsigned char **p, const unsigned char *start size_t len = 0; if( *p < start || (size_t)( *p - start ) < size ) - return( MBEDTLS_ERR_ASN1_BUF_TOO_SMALL ); + return MBEDTLS_ERR_ASN1_BUF_TOO_SMALL ; len = size; (*p) -= len; memcpy( *p, buf, len ); - return( (int) len ); + return (int) len ; } #if defined(MBEDTLS_BIGNUM_C) @@ -134,7 +134,7 @@ int mbedtls_asn1_write_mpi( unsigned char **p, const unsigned char *start, const len = mbedtls_mpi_size( X ); if( *p < start || (size_t)( *p - start ) < len ) - return( MBEDTLS_ERR_ASN1_BUF_TOO_SMALL ); + return MBEDTLS_ERR_ASN1_BUF_TOO_SMALL ; (*p) -= len; MBEDTLS_MPI_CHK( mbedtls_mpi_write_binary( X, *p, len ) ); @@ -145,7 +145,7 @@ int mbedtls_asn1_write_mpi( unsigned char **p, const unsigned char *start, const if( X->s ==1 && **p & 0x80 ) { if( *p - start < 1 ) - return( MBEDTLS_ERR_ASN1_BUF_TOO_SMALL ); + return MBEDTLS_ERR_ASN1_BUF_TOO_SMALL ; *--(*p) = 0x00; len += 1; @@ -157,7 +157,7 @@ int mbedtls_asn1_write_mpi( unsigned char **p, const unsigned char *start, const ret = (int) len; cleanup: - return( ret ); + return ret ; } #endif /* MBEDTLS_BIGNUM_C */ @@ -171,7 +171,7 @@ int mbedtls_asn1_write_null( unsigned char **p, const unsigned char *start ) MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( p, start, 0) ); MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( p, start, MBEDTLS_ASN1_NULL ) ); - return( (int) len ); + return (int) len ; } int mbedtls_asn1_write_oid( unsigned char **p, const unsigned char *start, @@ -185,7 +185,7 @@ int mbedtls_asn1_write_oid( unsigned char **p, const unsigned char *start, MBEDTLS_ASN1_CHK_ADD( len , mbedtls_asn1_write_len( p, start, len ) ); MBEDTLS_ASN1_CHK_ADD( len , mbedtls_asn1_write_tag( p, start, MBEDTLS_ASN1_OID ) ); - return( (int) len ); + return (int) len ; } int mbedtls_asn1_write_algorithm_identifier( unsigned char **p, const unsigned char *start, @@ -206,7 +206,7 @@ int mbedtls_asn1_write_algorithm_identifier( unsigned char **p, const unsigned c MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( p, start, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ); - return( (int) len ); + return (int) len ; } int mbedtls_asn1_write_bool( unsigned char **p, const unsigned char *start, int boolean ) @@ -215,7 +215,7 @@ int mbedtls_asn1_write_bool( unsigned char **p, const unsigned char *start, int size_t len = 0; if( *p - start < 1 ) - return( MBEDTLS_ERR_ASN1_BUF_TOO_SMALL ); + return MBEDTLS_ERR_ASN1_BUF_TOO_SMALL ; *--(*p) = (boolean) ? 255 : 0; len++; @@ -223,7 +223,7 @@ int mbedtls_asn1_write_bool( unsigned char **p, const unsigned char *start, int MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( p, start, len ) ); MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( p, start, MBEDTLS_ASN1_BOOLEAN ) ); - return( (int) len ); + return (int) len ; } static int asn1_write_tagged_int( unsigned char **p, const unsigned char *start, int val, int tag ) @@ -234,7 +234,7 @@ static int asn1_write_tagged_int( unsigned char **p, const unsigned char *start, do { if( *p - start < 1 ) - return( MBEDTLS_ERR_ASN1_BUF_TOO_SMALL ); + return MBEDTLS_ERR_ASN1_BUF_TOO_SMALL ; len += 1; *--(*p) = val & 0xff; val >>= 8; @@ -244,7 +244,7 @@ static int asn1_write_tagged_int( unsigned char **p, const unsigned char *start, if( **p & 0x80 ) { if( *p - start < 1 ) - return( MBEDTLS_ERR_ASN1_BUF_TOO_SMALL ); + return MBEDTLS_ERR_ASN1_BUF_TOO_SMALL ; *--(*p) = 0x00; len += 1; } @@ -252,17 +252,17 @@ static int asn1_write_tagged_int( unsigned char **p, const unsigned char *start, MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( p, start, len ) ); MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( p, start, tag ) ); - return( (int) len ); + return (int) len ; } int mbedtls_asn1_write_int( unsigned char **p, const unsigned char *start, int val ) { - return( asn1_write_tagged_int( p, start, val, MBEDTLS_ASN1_INTEGER ) ); + return asn1_write_tagged_int( p, start, val, MBEDTLS_ASN1_INTEGER ) ; } int mbedtls_asn1_write_enum( unsigned char **p, const unsigned char *start, int val ) { - return( asn1_write_tagged_int( p, start, val, MBEDTLS_ASN1_ENUMERATED ) ); + return asn1_write_tagged_int( p, start, val, MBEDTLS_ASN1_ENUMERATED ) ; } int mbedtls_asn1_write_tagged_string( unsigned char **p, const unsigned char *start, int tag, @@ -277,25 +277,25 @@ int mbedtls_asn1_write_tagged_string( unsigned char **p, const unsigned char *st MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( p, start, len ) ); MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( p, start, tag ) ); - return( (int) len ); + return (int) len ; } int mbedtls_asn1_write_utf8_string( unsigned char **p, const unsigned char *start, const char *text, size_t text_len ) { - return( mbedtls_asn1_write_tagged_string(p, start, MBEDTLS_ASN1_UTF8_STRING, text, text_len) ); + return mbedtls_asn1_write_tagged_string(p, start, MBEDTLS_ASN1_UTF8_STRING, text, text_len) ; } int mbedtls_asn1_write_printable_string( unsigned char **p, const unsigned char *start, const char *text, size_t text_len ) { - return( mbedtls_asn1_write_tagged_string(p, start, MBEDTLS_ASN1_PRINTABLE_STRING, text, text_len) ); + return mbedtls_asn1_write_tagged_string(p, start, MBEDTLS_ASN1_PRINTABLE_STRING, text, text_len) ; } int mbedtls_asn1_write_ia5_string( unsigned char **p, const unsigned char *start, const char *text, size_t text_len ) { - return( mbedtls_asn1_write_tagged_string(p, start, MBEDTLS_ASN1_IA5_STRING, text, text_len) ); + return mbedtls_asn1_write_tagged_string(p, start, MBEDTLS_ASN1_IA5_STRING, text, text_len) ; } int mbedtls_asn1_write_named_bitstring( unsigned char **p, @@ -338,7 +338,7 @@ int mbedtls_asn1_write_named_bitstring( unsigned char **p, } } - return( mbedtls_asn1_write_bitstring( p, start, buf, bits ) ); + return mbedtls_asn1_write_bitstring( p, start, buf, bits ) ; } int mbedtls_asn1_write_bitstring( unsigned char **p, const unsigned char *start, @@ -352,7 +352,7 @@ int mbedtls_asn1_write_bitstring( unsigned char **p, const unsigned char *start, unused_bits = ( byte_len * 8 ) - bits; if( *p < start || (size_t)( *p - start ) < byte_len + 1 ) - return( MBEDTLS_ERR_ASN1_BUF_TOO_SMALL ); + return MBEDTLS_ERR_ASN1_BUF_TOO_SMALL ; len = byte_len + 1; @@ -371,7 +371,7 @@ int mbedtls_asn1_write_bitstring( unsigned char **p, const unsigned char *start, MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( p, start, len ) ); MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( p, start, MBEDTLS_ASN1_BIT_STRING ) ); - return( (int) len ); + return (int) len ; } int mbedtls_asn1_write_octet_string( unsigned char **p, const unsigned char *start, @@ -385,7 +385,7 @@ int mbedtls_asn1_write_octet_string( unsigned char **p, const unsigned char *sta MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( p, start, len ) ); MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( p, start, MBEDTLS_ASN1_OCTET_STRING ) ); - return( (int) len ); + return (int) len ; } @@ -406,7 +406,7 @@ static mbedtls_asn1_named_data *asn1_find_named_data( list = list->next; } - return( list ); + return list ; } mbedtls_asn1_named_data *mbedtls_asn1_store_named_data( @@ -424,14 +424,14 @@ mbedtls_asn1_named_data *mbedtls_asn1_store_named_data( cur = (mbedtls_asn1_named_data*)mbedtls_calloc( 1, sizeof(mbedtls_asn1_named_data) ); if( cur == NULL ) - return( NULL ); + return NULL ; cur->oid.len = oid_len; cur->oid.p = mbedtls_calloc( 1, oid_len ); if( cur->oid.p == NULL ) { mbedtls_free( cur ); - return( NULL ); + return NULL ; } memcpy( cur->oid.p, oid, oid_len ); @@ -444,7 +444,7 @@ mbedtls_asn1_named_data *mbedtls_asn1_store_named_data( { mbedtls_free( cur->oid.p ); mbedtls_free( cur ); - return( NULL ); + return NULL ; } } @@ -465,7 +465,7 @@ mbedtls_asn1_named_data *mbedtls_asn1_store_named_data( */ void *p = mbedtls_calloc( 1, val_len ); if( p == NULL ) - return( NULL ); + return NULL ; mbedtls_free( cur->val.p ); cur->val.p = p; @@ -475,6 +475,6 @@ mbedtls_asn1_named_data *mbedtls_asn1_store_named_data( if( val != NULL ) memcpy( cur->val.p, val, val_len ); - return( cur ); + return cur ; } #endif /* MBEDTLS_ASN1_WRITE_C */ diff --git a/library/base64.c b/library/base64.c index 1a05226efa..f78a29b84d 100644 --- a/library/base64.c +++ b/library/base64.c @@ -171,7 +171,7 @@ int mbedtls_base64_encode( unsigned char *dst, size_t dlen, size_t *olen, if( slen == 0 ) { *olen = 0; - return( 0 ); + return 0 ; } n = slen / 3 + ( slen % 3 != 0 ); @@ -179,7 +179,7 @@ int mbedtls_base64_encode( unsigned char *dst, size_t dlen, size_t *olen, if( n > ( BASE64_SIZE_T_MAX - 1 ) / 4 ) { *olen = BASE64_SIZE_T_MAX; - return( MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL ); + return MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL ; } n *= 4; @@ -187,7 +187,7 @@ int mbedtls_base64_encode( unsigned char *dst, size_t dlen, size_t *olen, if( ( dlen < n + 1 ) || ( NULL == dst ) ) { *olen = n + 1; - return( MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL ); + return MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL ; } n = ( slen / 3 ) * 3; @@ -233,7 +233,7 @@ int mbedtls_base64_encode( unsigned char *dst, size_t dlen, size_t *olen, *olen = p - dst; *p = 0; - return( 0 ); + return 0 ; } /* @@ -271,18 +271,18 @@ int mbedtls_base64_decode( unsigned char *dst, size_t dlen, size_t *olen, /* Space inside a line is an error */ if( x != 0 ) - return( MBEDTLS_ERR_BASE64_INVALID_CHARACTER ); + return MBEDTLS_ERR_BASE64_INVALID_CHARACTER ; if( src[i] == '=' && ++j > 2 ) - return( MBEDTLS_ERR_BASE64_INVALID_CHARACTER ); + return MBEDTLS_ERR_BASE64_INVALID_CHARACTER ; dec_map_lookup = mbedtls_base64_table_lookup( base64_dec_map, sizeof( base64_dec_map ), src[i] ); if( src[i] > 127 || dec_map_lookup == 127 ) - return( MBEDTLS_ERR_BASE64_INVALID_CHARACTER ); + return MBEDTLS_ERR_BASE64_INVALID_CHARACTER ; if( dec_map_lookup < 64 && j != 0 ) - return( MBEDTLS_ERR_BASE64_INVALID_CHARACTER ); + return MBEDTLS_ERR_BASE64_INVALID_CHARACTER ; n++; } @@ -290,7 +290,7 @@ int mbedtls_base64_decode( unsigned char *dst, size_t dlen, size_t *olen, if( n == 0 ) { *olen = 0; - return( 0 ); + return 0 ; } /* The following expression is to calculate the following formula without @@ -303,7 +303,7 @@ int mbedtls_base64_decode( unsigned char *dst, size_t dlen, size_t *olen, if( dst == NULL || dlen < n ) { *olen = n; - return( MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL ); + return MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL ; } for( j = 3, n = x = 0, p = dst; i > 0; i--, src++ ) @@ -327,7 +327,7 @@ int mbedtls_base64_decode( unsigned char *dst, size_t dlen, size_t *olen, *olen = p - dst; - return( 0 ); + return 0 ; } #if defined(MBEDTLS_SELF_TEST) @@ -368,7 +368,7 @@ int mbedtls_base64_self_test( int verbose ) if( verbose != 0 ) mbedtls_printf( "failed\n" ); - return( 1 ); + return 1 ; } if( verbose != 0 ) @@ -382,13 +382,13 @@ int mbedtls_base64_self_test( int verbose ) if( verbose != 0 ) mbedtls_printf( "failed\n" ); - return( 1 ); + return 1 ; } if( verbose != 0 ) mbedtls_printf( "passed\n\n" ); - return( 0 ); + return 0 ; } #endif /* MBEDTLS_SELF_TEST */ diff --git a/library/bignum.c b/library/bignum.c index 42ec7ac314..46bd6d0f2e 100644 --- a/library/bignum.c +++ b/library/bignum.c @@ -118,12 +118,12 @@ int mbedtls_mpi_grow( mbedtls_mpi *X, size_t nblimbs ) MPI_VALIDATE_RET( X != NULL ); if( nblimbs > MBEDTLS_MPI_MAX_LIMBS ) - return( MBEDTLS_ERR_MPI_ALLOC_FAILED ); + return MBEDTLS_ERR_MPI_ALLOC_FAILED ; if( X->n < nblimbs ) { if( ( p = (mbedtls_mpi_uint*)mbedtls_calloc( nblimbs, ciL ) ) == NULL ) - return( MBEDTLS_ERR_MPI_ALLOC_FAILED ); + return MBEDTLS_ERR_MPI_ALLOC_FAILED ; if( X->p != NULL ) { @@ -136,7 +136,7 @@ int mbedtls_mpi_grow( mbedtls_mpi *X, size_t nblimbs ) X->p = p; } - return( 0 ); + return 0 ; } /* @@ -150,11 +150,11 @@ int mbedtls_mpi_shrink( mbedtls_mpi *X, size_t nblimbs ) MPI_VALIDATE_RET( X != NULL ); if( nblimbs > MBEDTLS_MPI_MAX_LIMBS ) - return( MBEDTLS_ERR_MPI_ALLOC_FAILED ); + return MBEDTLS_ERR_MPI_ALLOC_FAILED ; /* Actually resize up if there are currently fewer than nblimbs limbs. */ if( X->n <= nblimbs ) - return( mbedtls_mpi_grow( X, nblimbs ) ); + return mbedtls_mpi_grow( X, nblimbs ) ; /* After this point, then X->n > nblimbs and in particular X->n > 0. */ for( i = X->n - 1; i > 0; i-- ) @@ -166,7 +166,7 @@ int mbedtls_mpi_shrink( mbedtls_mpi *X, size_t nblimbs ) i = nblimbs; if( ( p = (mbedtls_mpi_uint*)mbedtls_calloc( i, ciL ) ) == NULL ) - return( MBEDTLS_ERR_MPI_ALLOC_FAILED ); + return MBEDTLS_ERR_MPI_ALLOC_FAILED ; if( X->p != NULL ) { @@ -178,7 +178,7 @@ int mbedtls_mpi_shrink( mbedtls_mpi *X, size_t nblimbs ) X->n = i; X->p = p; - return( 0 ); + return 0 ; } /* Resize X to have exactly n limbs and set it to 0. */ @@ -187,18 +187,18 @@ static int mbedtls_mpi_resize_clear( mbedtls_mpi *X, size_t limbs ) if( limbs == 0 ) { mbedtls_mpi_free( X ); - return( 0 ); + return 0 ; } else if( X->n == limbs ) { memset( X->p, 0, limbs * ciL ); X->s = 1; - return( 0 ); + return 0 ; } else { mbedtls_mpi_free( X ); - return( mbedtls_mpi_grow( X, limbs ) ); + return mbedtls_mpi_grow( X, limbs ) ; } } @@ -219,7 +219,7 @@ int mbedtls_mpi_copy( mbedtls_mpi *X, const mbedtls_mpi *Y ) MPI_VALIDATE_RET( Y != NULL ); if( X == Y ) - return( 0 ); + return 0 ; if( Y->n == 0 ) { @@ -228,7 +228,7 @@ int mbedtls_mpi_copy( mbedtls_mpi *X, const mbedtls_mpi *Y ) X->s = 1; memset( X->p, 0, X->n * ciL ); } - return( 0 ); + return 0 ; } for( i = Y->n - 1; i > 0; i-- ) @@ -251,7 +251,7 @@ int mbedtls_mpi_copy( mbedtls_mpi *X, const mbedtls_mpi *Y ) cleanup: - return( ret ); + return ret ; } /* @@ -295,7 +295,7 @@ static int mpi_safe_cond_select_sign( int a, int b, unsigned char second ) unsigned ur = ( ua & ~mask ) | ( ub & mask ); /* ur is now 0 or 2, convert back to -1 or +1 */ - return( (int) ur - 1 ); + return (int) ur - 1 ; } /* @@ -368,7 +368,7 @@ int mbedtls_mpi_safe_cond_assign( mbedtls_mpi *X, const mbedtls_mpi *Y, unsigned X->p[i] &= ~limb_mask; cleanup: - return( ret ); + return ret ; } /* @@ -387,7 +387,7 @@ int mbedtls_mpi_safe_cond_swap( mbedtls_mpi *X, mbedtls_mpi *Y, unsigned char sw MPI_VALIDATE_RET( Y != NULL ); if( X == Y ) - return( 0 ); + return 0 ; /* MSVC has a warning about unary minus on unsigned integer types, * but this is well-defined and precisely what we want to do here. */ @@ -421,7 +421,7 @@ int mbedtls_mpi_safe_cond_swap( mbedtls_mpi *X, mbedtls_mpi *Y, unsigned char sw } cleanup: - return( ret ); + return ret ; } /* @@ -440,7 +440,7 @@ int mbedtls_mpi_lset( mbedtls_mpi *X, mbedtls_mpi_sint z ) cleanup: - return( ret ); + return ret ; } /* @@ -451,9 +451,9 @@ int mbedtls_mpi_get_bit( const mbedtls_mpi *X, size_t pos ) MPI_VALIDATE_RET( X != NULL ); if( X->n * biL <= pos ) - return( 0 ); + return 0 ; - return( ( X->p[pos / biL] >> ( pos % biL ) ) & 0x01 ); + return ( X->p[pos / biL] >> ( pos % biL ) ) & 0x01 ; } /* Get a specific byte, without range checks. */ @@ -471,12 +471,12 @@ int mbedtls_mpi_set_bit( mbedtls_mpi *X, size_t pos, unsigned char val ) MPI_VALIDATE_RET( X != NULL ); if( val != 0 && val != 1 ) - return( MBEDTLS_ERR_MPI_BAD_INPUT_DATA ); + return MBEDTLS_ERR_MPI_BAD_INPUT_DATA ; if( X->n * biL <= pos ) { if( val == 0 ) - return( 0 ); + return 0 ; MBEDTLS_MPI_CHK( mbedtls_mpi_grow( X, off + 1 ) ); } @@ -486,7 +486,7 @@ int mbedtls_mpi_set_bit( mbedtls_mpi *X, size_t pos, unsigned char val ) cleanup: - return( ret ); + return ret ; } /* @@ -500,9 +500,9 @@ size_t mbedtls_mpi_lsb( const mbedtls_mpi *X ) for( i = 0; i < X->n; i++ ) for( j = 0; j < biL; j++, count++ ) if( ( ( X->p[i] >> j ) & 1 ) != 0 ) - return( count ); + return count ; - return( 0 ); + return 0 ; } /* @@ -531,7 +531,7 @@ size_t mbedtls_mpi_bitlen( const mbedtls_mpi *X ) size_t i, j; if( X->n == 0 ) - return( 0 ); + return 0 ; for( i = X->n - 1; i > 0; i-- ) if( X->p[i] != 0 ) @@ -539,7 +539,7 @@ size_t mbedtls_mpi_bitlen( const mbedtls_mpi *X ) j = biL - mbedtls_clz( X->p[i] ); - return( ( i * biL ) + j ); + return ( i * biL ) + j ; } /* @@ -547,7 +547,7 @@ size_t mbedtls_mpi_bitlen( const mbedtls_mpi *X ) */ size_t mbedtls_mpi_size( const mbedtls_mpi *X ) { - return( ( mbedtls_mpi_bitlen( X ) + 7 ) >> 3 ); + return ( mbedtls_mpi_bitlen( X ) + 7 ) >> 3 ; } /* @@ -562,9 +562,9 @@ static int mpi_get_digit( mbedtls_mpi_uint *d, int radix, char c ) if( c >= 0x61 && c <= 0x66 ) *d = c - 0x57; if( *d >= (mbedtls_mpi_uint) radix ) - return( MBEDTLS_ERR_MPI_INVALID_CHARACTER ); + return MBEDTLS_ERR_MPI_INVALID_CHARACTER ; - return( 0 ); + return 0 ; } /* @@ -581,14 +581,14 @@ int mbedtls_mpi_read_string( mbedtls_mpi *X, int radix, const char *s ) MPI_VALIDATE_RET( s != NULL ); if( radix < 2 || radix > 16 ) - return( MBEDTLS_ERR_MPI_BAD_INPUT_DATA ); + return MBEDTLS_ERR_MPI_BAD_INPUT_DATA ; mbedtls_mpi_init( &T ); if( s[0] == 0 ) { mbedtls_mpi_free( X ); - return( 0 ); + return 0 ; } if( s[0] == '-' ) @@ -602,7 +602,7 @@ int mbedtls_mpi_read_string( mbedtls_mpi *X, int radix, const char *s ) if( radix == 16 ) { if( slen > MPI_SIZE_T_MAX >> 2 ) - return( MBEDTLS_ERR_MPI_BAD_INPUT_DATA ); + return MBEDTLS_ERR_MPI_BAD_INPUT_DATA ; n = BITS_TO_LIMBS( slen << 2 ); @@ -634,7 +634,7 @@ cleanup: mbedtls_mpi_free( &T ); - return( ret ); + return ret ; } /* @@ -652,7 +652,7 @@ static int mpi_write_hlp( mbedtls_mpi *X, int radix, { if( length >= buflen ) { - return( MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL ); + return MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL ; } MBEDTLS_MPI_CHK( mbedtls_mpi_mod_int( &r, X, radix ) ); @@ -673,7 +673,7 @@ static int mpi_write_hlp( mbedtls_mpi *X, int radix, cleanup: - return( ret ); + return ret ; } /* @@ -691,7 +691,7 @@ int mbedtls_mpi_write_string( const mbedtls_mpi *X, int radix, MPI_VALIDATE_RET( buflen == 0 || buf != NULL ); if( radix < 2 || radix > 16 ) - return( MBEDTLS_ERR_MPI_BAD_INPUT_DATA ); + return MBEDTLS_ERR_MPI_BAD_INPUT_DATA ; n = mbedtls_mpi_bitlen( X ); /* Number of bits necessary to present `n`. */ if( radix >= 4 ) n >>= 1; /* Number of 4-adic digits necessary to present @@ -711,7 +711,7 @@ int mbedtls_mpi_write_string( const mbedtls_mpi *X, int radix, if( buflen < n ) { *olen = n; - return( MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL ); + return MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL ; } p = buf; @@ -760,7 +760,7 @@ cleanup: mbedtls_mpi_free( &T ); - return( ret ); + return ret ; } #if defined(MBEDTLS_FS_IO) @@ -782,15 +782,15 @@ int mbedtls_mpi_read_file( mbedtls_mpi *X, int radix, FILE *fin ) MPI_VALIDATE_RET( fin != NULL ); if( radix < 2 || radix > 16 ) - return( MBEDTLS_ERR_MPI_BAD_INPUT_DATA ); + return MBEDTLS_ERR_MPI_BAD_INPUT_DATA ; memset( s, 0, sizeof( s ) ); if( fgets( s, sizeof( s ) - 1, fin ) == NULL ) - return( MBEDTLS_ERR_MPI_FILE_IO_ERROR ); + return MBEDTLS_ERR_MPI_FILE_IO_ERROR ; slen = strlen( s ); if( slen == sizeof( s ) - 2 ) - return( MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL ); + return MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL ; if( slen > 0 && s[slen - 1] == '\n' ) { slen--; s[slen] = '\0'; } if( slen > 0 && s[slen - 1] == '\r' ) { slen--; s[slen] = '\0'; } @@ -800,7 +800,7 @@ int mbedtls_mpi_read_file( mbedtls_mpi *X, int radix, FILE *fin ) if( mpi_get_digit( &d, radix, *p ) != 0 ) break; - return( mbedtls_mpi_read_string( X, radix, p + 1 ) ); + return mbedtls_mpi_read_string( X, radix, p + 1 ) ; } /* @@ -818,7 +818,7 @@ int mbedtls_mpi_write_file( const char *p, const mbedtls_mpi *X, int radix, FILE MPI_VALIDATE_RET( X != NULL ); if( radix < 2 || radix > 16 ) - return( MBEDTLS_ERR_MPI_BAD_INPUT_DATA ); + return MBEDTLS_ERR_MPI_BAD_INPUT_DATA ; memset( s, 0, sizeof( s ) ); @@ -835,14 +835,14 @@ int mbedtls_mpi_write_file( const char *p, const mbedtls_mpi *X, int radix, FILE { if( fwrite( p, 1, plen, fout ) != plen || fwrite( s, 1, slen, fout ) != slen ) - return( MBEDTLS_ERR_MPI_FILE_IO_ERROR ); + return MBEDTLS_ERR_MPI_FILE_IO_ERROR ; } else mbedtls_printf( "%s%s", p, s ); cleanup: - return( ret ); + return ret ; } #endif /* MBEDTLS_FS_IO */ @@ -862,7 +862,7 @@ static mbedtls_mpi_uint mpi_uint_bigendian_to_host_c( mbedtls_mpi_uint x ) tmp |= (mbedtls_mpi_uint) *x_ptr; } - return( tmp ); + return tmp ; } static mbedtls_mpi_uint mpi_uint_bigendian_to_host( mbedtls_mpi_uint x ) @@ -871,7 +871,7 @@ static mbedtls_mpi_uint mpi_uint_bigendian_to_host( mbedtls_mpi_uint x ) /* Nothing to do on bigendian systems. */ #if ( __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ ) - return( x ); + return x ; #endif /* __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ */ #if ( __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ ) @@ -895,9 +895,9 @@ static mbedtls_mpi_uint mpi_uint_bigendian_to_host( mbedtls_mpi_uint x ) switch( sizeof(mbedtls_mpi_uint) ) { case 4: - return( __builtin_bswap32(x) ); + return __builtin_bswap32(x) ; case 8: - return( __builtin_bswap64(x) ); + return __builtin_bswap64(x) ; } #endif #endif /* __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ */ @@ -905,7 +905,7 @@ static mbedtls_mpi_uint mpi_uint_bigendian_to_host( mbedtls_mpi_uint x ) /* Fall back to C-based reordering if we don't know the byte order * or we couldn't use a compiler-specific builtin. */ - return( mpi_uint_bigendian_to_host_c( x ) ); + return mpi_uint_bigendian_to_host_c( x ) ; } static void mpi_bigendian_to_host( mbedtls_mpi_uint * const p, size_t limbs ) @@ -960,7 +960,7 @@ cleanup: * upon failure is not necessary because failure only can happen before any * input is copied. */ - return( ret ); + return ret ; } /* @@ -996,7 +996,7 @@ cleanup: * upon failure is not necessary because failure only can happen before any * input is copied. */ - return( ret ); + return ret ; } /* @@ -1022,7 +1022,7 @@ int mbedtls_mpi_write_binary_le( const mbedtls_mpi *X, for( i = bytes_to_copy; i < stored_bytes; i++ ) { if( GET_BYTE( X, i ) != 0 ) - return( MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL ); + return MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL ; } } @@ -1035,7 +1035,7 @@ int mbedtls_mpi_write_binary_le( const mbedtls_mpi *X, memset( buf + stored_bytes, 0, buflen - stored_bytes ); } - return( 0 ); + return 0 ; } /* @@ -1074,14 +1074,14 @@ int mbedtls_mpi_write_binary( const mbedtls_mpi *X, for( i = bytes_to_copy; i < stored_bytes; i++ ) { if( GET_BYTE( X, i ) != 0 ) - return( MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL ); + return MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL ; } } for( i = 0; i < bytes_to_copy; i++ ) p[bytes_to_copy - i - 1] = GET_BYTE( X, i ); - return( 0 ); + return 0 ; } /* @@ -1132,7 +1132,7 @@ int mbedtls_mpi_shift_l( mbedtls_mpi *X, size_t count ) cleanup: - return( ret ); + return ret ; } /* @@ -1176,7 +1176,7 @@ int mbedtls_mpi_shift_r( mbedtls_mpi *X, size_t count ) } } - return( 0 ); + return 0 ; } /* @@ -1197,18 +1197,18 @@ int mbedtls_mpi_cmp_abs( const mbedtls_mpi *X, const mbedtls_mpi *Y ) break; if( i == 0 && j == 0 ) - return( 0 ); + return 0 ; - if( i > j ) return( 1 ); - if( j > i ) return( -1 ); + if( i > j ) return 1 ; + if( j > i ) return -1 ; for( ; i > 0; i-- ) { - if( X->p[i - 1] > Y->p[i - 1] ) return( 1 ); - if( X->p[i - 1] < Y->p[i - 1] ) return( -1 ); + if( X->p[i - 1] > Y->p[i - 1] ) return 1 ; + if( X->p[i - 1] < Y->p[i - 1] ) return -1 ; } - return( 0 ); + return 0 ; } /* @@ -1229,21 +1229,21 @@ int mbedtls_mpi_cmp_mpi( const mbedtls_mpi *X, const mbedtls_mpi *Y ) break; if( i == 0 && j == 0 ) - return( 0 ); + return 0 ; - if( i > j ) return( X->s ); - if( j > i ) return( -Y->s ); + if( i > j ) return X->s ; + if( j > i ) return -Y->s ; - if( X->s > 0 && Y->s < 0 ) return( 1 ); - if( Y->s > 0 && X->s < 0 ) return( -1 ); + if( X->s > 0 && Y->s < 0 ) return 1 ; + if( Y->s > 0 && X->s < 0 ) return -1 ; for( ; i > 0; i-- ) { - if( X->p[i - 1] > Y->p[i - 1] ) return( X->s ); - if( X->p[i - 1] < Y->p[i - 1] ) return( -X->s ); + if( X->p[i - 1] > Y->p[i - 1] ) return X->s ; + if( X->p[i - 1] < Y->p[i - 1] ) return -X->s ; } - return( 0 ); + return 0 ; } /** Decide if an integer is less than the other, without branches. @@ -1344,7 +1344,7 @@ int mbedtls_mpi_lt_mpi_ct( const mbedtls_mpi *X, const mbedtls_mpi *Y, done |= cond; } - return( 0 ); + return 0 ; } /* @@ -1361,7 +1361,7 @@ int mbedtls_mpi_cmp_int( const mbedtls_mpi *X, mbedtls_mpi_sint z ) Y.n = 1; Y.p = p; - return( mbedtls_mpi_cmp_mpi( X, &Y ) ); + return mbedtls_mpi_cmp_mpi( X, &Y ) ; } /* @@ -1420,7 +1420,7 @@ int mbedtls_mpi_add_abs( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi cleanup: - return( ret ); + return ret ; } /** @@ -1454,7 +1454,7 @@ static mbedtls_mpi_uint mpi_sub_hlp( size_t n, c = ( t < r[i] ) + z; d[i] = t - r[i]; } - return( c ); + return c ; } /* @@ -1509,7 +1509,7 @@ int mbedtls_mpi_sub_abs( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi X->s = 1; cleanup: - return( ret ); + return ret ; } /* @@ -1544,7 +1544,7 @@ int mbedtls_mpi_add_mpi( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi cleanup: - return( ret ); + return ret ; } /* @@ -1579,7 +1579,7 @@ int mbedtls_mpi_sub_mpi( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi cleanup: - return( ret ); + return ret ; } /* @@ -1597,7 +1597,7 @@ int mbedtls_mpi_add_int( mbedtls_mpi *X, const mbedtls_mpi *A, mbedtls_mpi_sint B.n = 1; B.p = p; - return( mbedtls_mpi_add_mpi( X, A, &B ) ); + return mbedtls_mpi_add_mpi( X, A, &B ) ; } /* @@ -1615,7 +1615,7 @@ int mbedtls_mpi_sub_int( mbedtls_mpi *X, const mbedtls_mpi *A, mbedtls_mpi_sint B.n = 1; B.p = p; - return( mbedtls_mpi_sub_mpi( X, A, &B ) ); + return mbedtls_mpi_sub_mpi( X, A, &B ) ; } /** Helper for mbedtls_mpi multiplication. @@ -1755,7 +1755,7 @@ cleanup: mbedtls_mpi_free( &TB ); mbedtls_mpi_free( &TA ); - return( ret ); + return ret ; } /* @@ -1775,7 +1775,7 @@ int mbedtls_mpi_mul_int( mbedtls_mpi *X, const mbedtls_mpi *A, mbedtls_mpi_uint * calculating the result is trivial in those cases. */ if( b == 0 || n == 0 ) { - return( mbedtls_mpi_lset( X, 0 ) ); + return mbedtls_mpi_lset( X, 0 ) ; } /* Calculate A*b as A + A*(b-1) to take advantage of mpi_mul_hlp */ @@ -1793,7 +1793,7 @@ int mbedtls_mpi_mul_int( mbedtls_mpi *X, const mbedtls_mpi *A, mbedtls_mpi_uint mpi_mul_hlp( n, A->p, X->p, b - 1 ); cleanup: - return( ret ); + return ret ; } /* @@ -1820,7 +1820,7 @@ static mbedtls_mpi_uint mbedtls_int_div_int( mbedtls_mpi_uint u1, { if (r != NULL) *r = ~0; - return ( ~0 ); + return ~0 ; } #if defined(MBEDTLS_HAVE_UDBL) @@ -1906,7 +1906,7 @@ int mbedtls_mpi_div_mpi( mbedtls_mpi *Q, mbedtls_mpi *R, const mbedtls_mpi *A, MPI_VALIDATE_RET( B != NULL ); if( mbedtls_mpi_cmp_int( B, 0 ) == 0 ) - return( MBEDTLS_ERR_MPI_DIVISION_BY_ZERO ); + return MBEDTLS_ERR_MPI_DIVISION_BY_ZERO ; mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y ); mbedtls_mpi_init( &Z ); mbedtls_mpi_init( &T1 ); @@ -1925,7 +1925,7 @@ int mbedtls_mpi_div_mpi( mbedtls_mpi *Q, mbedtls_mpi *R, const mbedtls_mpi *A, { if( Q != NULL ) MBEDTLS_MPI_CHK( mbedtls_mpi_lset( Q, 0 ) ); if( R != NULL ) MBEDTLS_MPI_CHK( mbedtls_mpi_copy( R, A ) ); - return( 0 ); + return 0 ; } MBEDTLS_MPI_CHK( mbedtls_mpi_copy( &X, A ) ); @@ -2017,7 +2017,7 @@ cleanup: mbedtls_mpi_free( &T1 ); mbedtls_platform_zeroize( TP2, sizeof( TP2 ) ); - return( ret ); + return ret ; } /* @@ -2036,7 +2036,7 @@ int mbedtls_mpi_div_int( mbedtls_mpi *Q, mbedtls_mpi *R, B.n = 1; B.p = p; - return( mbedtls_mpi_div_mpi( Q, R, A, &B ) ); + return mbedtls_mpi_div_mpi( Q, R, A, &B ) ; } /* @@ -2050,7 +2050,7 @@ int mbedtls_mpi_mod_mpi( mbedtls_mpi *R, const mbedtls_mpi *A, const mbedtls_mpi MPI_VALIDATE_RET( B != NULL ); if( mbedtls_mpi_cmp_int( B, 0 ) < 0 ) - return( MBEDTLS_ERR_MPI_NEGATIVE_VALUE ); + return MBEDTLS_ERR_MPI_NEGATIVE_VALUE ; MBEDTLS_MPI_CHK( mbedtls_mpi_div_mpi( NULL, R, A, B ) ); @@ -2062,7 +2062,7 @@ int mbedtls_mpi_mod_mpi( mbedtls_mpi *R, const mbedtls_mpi *A, const mbedtls_mpi cleanup: - return( ret ); + return ret ; } /* @@ -2076,10 +2076,10 @@ int mbedtls_mpi_mod_int( mbedtls_mpi_uint *r, const mbedtls_mpi *A, mbedtls_mpi_ MPI_VALIDATE_RET( A != NULL ); if( b == 0 ) - return( MBEDTLS_ERR_MPI_DIVISION_BY_ZERO ); + return MBEDTLS_ERR_MPI_DIVISION_BY_ZERO ; if( b < 0 ) - return( MBEDTLS_ERR_MPI_NEGATIVE_VALUE ); + return MBEDTLS_ERR_MPI_NEGATIVE_VALUE ; /* * handle trivial cases @@ -2087,13 +2087,13 @@ int mbedtls_mpi_mod_int( mbedtls_mpi_uint *r, const mbedtls_mpi *A, mbedtls_mpi_ if( b == 1 ) { *r = 0; - return( 0 ); + return 0 ; } if( b == 2 ) { *r = A->p[0] & 1; - return( 0 ); + return 0 ; } /* @@ -2121,7 +2121,7 @@ int mbedtls_mpi_mod_int( mbedtls_mpi_uint *r, const mbedtls_mpi *A, mbedtls_mpi_ *r = y; - return( 0 ); + return 0 ; } /* @@ -2260,7 +2260,7 @@ static size_t mbedtls_mpi_cf_bool_eq( size_t x, size_t y ) /* diff1 = (x != y) ? 1 : 0 */ const size_t diff1 = diff_msb >> ( sizeof( diff_msb ) * 8 - 1 ); - return( 1 ^ diff1 ); + return 1 ^ diff1 ; } /** @@ -2289,7 +2289,7 @@ static int mpi_select( mbedtls_mpi *R, const mbedtls_mpi *T, size_t T_size, size } cleanup: - return( ret ); + return ret ; } /* @@ -2313,14 +2313,14 @@ int mbedtls_mpi_exp_mod( mbedtls_mpi *X, const mbedtls_mpi *A, 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 ); + return MBEDTLS_ERR_MPI_BAD_INPUT_DATA ; if( mbedtls_mpi_cmp_int( E, 0 ) < 0 ) - return( MBEDTLS_ERR_MPI_BAD_INPUT_DATA ); + return MBEDTLS_ERR_MPI_BAD_INPUT_DATA ; if( mbedtls_mpi_bitlen( E ) > MBEDTLS_MPI_MAX_BITS || mbedtls_mpi_bitlen( N ) > MBEDTLS_MPI_MAX_BITS ) - return ( MBEDTLS_ERR_MPI_BAD_INPUT_DATA ); + return MBEDTLS_ERR_MPI_BAD_INPUT_DATA ; /* * Init temps and window size @@ -2526,7 +2526,7 @@ cleanup: if( prec_RR == NULL || prec_RR->p == NULL ) mbedtls_mpi_free( &RR ); - return( ret ); + return ret ; } /* @@ -2640,7 +2640,7 @@ cleanup: mbedtls_mpi_free( &TA ); mbedtls_mpi_free( &TB ); - return( ret ); + return ret ; } /* Fill X with n_bytes random bytes. @@ -2659,7 +2659,7 @@ static int mpi_fill_random_internal( const size_t overhead = ( limbs * ciL ) - n_bytes; if( X->n < limbs ) - return( MBEDTLS_ERR_MPI_BAD_INPUT_DATA ); + return MBEDTLS_ERR_MPI_BAD_INPUT_DATA ; memset( X->p, 0, overhead ); memset( (unsigned char *) X->p + limbs * ciL, 0, ( X->n - limbs ) * ciL ); @@ -2667,7 +2667,7 @@ static int mpi_fill_random_internal( mpi_bigendian_to_host( X->p, limbs ); cleanup: - return( ret ); + return ret ; } /* @@ -2690,12 +2690,12 @@ int mbedtls_mpi_fill_random( mbedtls_mpi *X, size_t size, /* Ensure that target MPI has exactly the necessary number of limbs */ MBEDTLS_MPI_CHK( mbedtls_mpi_resize_clear( X, limbs ) ); if( size == 0 ) - return( 0 ); + return 0 ; ret = mpi_fill_random_internal( X, size, f_rng, p_rng ); cleanup: - return( ret ); + return ret ; } int mbedtls_mpi_random( mbedtls_mpi *X, @@ -2712,9 +2712,9 @@ int mbedtls_mpi_random( mbedtls_mpi *X, mbedtls_mpi lower_bound; if( min < 0 ) - return( MBEDTLS_ERR_MPI_BAD_INPUT_DATA ); + return MBEDTLS_ERR_MPI_BAD_INPUT_DATA ; if( mbedtls_mpi_cmp_int( N, min ) <= 0 ) - return( MBEDTLS_ERR_MPI_BAD_INPUT_DATA ); + return MBEDTLS_ERR_MPI_BAD_INPUT_DATA ; /* * When min == 0, each try has at worst a probability 1/2 of failing @@ -2770,7 +2770,7 @@ int mbedtls_mpi_random( mbedtls_mpi *X, cleanup: mbedtls_mpi_free( &lower_bound ); - return( ret ); + return ret ; } /* @@ -2785,7 +2785,7 @@ int mbedtls_mpi_inv_mod( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi MPI_VALIDATE_RET( N != NULL ); if( mbedtls_mpi_cmp_int( N, 1 ) <= 0 ) - return( MBEDTLS_ERR_MPI_BAD_INPUT_DATA ); + return MBEDTLS_ERR_MPI_BAD_INPUT_DATA ; mbedtls_mpi_init( &TA ); mbedtls_mpi_init( &TU ); mbedtls_mpi_init( &U1 ); mbedtls_mpi_init( &U2 ); mbedtls_mpi_init( &G ); mbedtls_mpi_init( &TB ); mbedtls_mpi_init( &TV ); @@ -2868,7 +2868,7 @@ cleanup: mbedtls_mpi_free( &G ); mbedtls_mpi_free( &TB ); mbedtls_mpi_free( &TV ); mbedtls_mpi_free( &V1 ); mbedtls_mpi_free( &V2 ); - return( ret ); + return ret ; } #if defined(MBEDTLS_GENPRIME) @@ -2914,21 +2914,21 @@ static int mpi_check_small_factors( const mbedtls_mpi *X ) mbedtls_mpi_uint r; if( ( X->p[0] & 1 ) == 0 ) - return( MBEDTLS_ERR_MPI_NOT_ACCEPTABLE ); + return MBEDTLS_ERR_MPI_NOT_ACCEPTABLE ; for( i = 0; small_prime[i] > 0; i++ ) { if( mbedtls_mpi_cmp_int( X, small_prime[i] ) <= 0 ) - return( 1 ); + return 1 ; MBEDTLS_MPI_CHK( mbedtls_mpi_mod_int( &r, X, small_prime[i] ) ); if( r == 0 ) - return( MBEDTLS_ERR_MPI_NOT_ACCEPTABLE ); + return MBEDTLS_ERR_MPI_NOT_ACCEPTABLE ; } cleanup: - return( ret ); + return ret ; } /* @@ -3021,7 +3021,7 @@ cleanup: mbedtls_mpi_free( &T ); mbedtls_mpi_free( &A ); mbedtls_mpi_free( &RR ); - return( ret ); + return ret ; } /* @@ -3042,20 +3042,20 @@ int mbedtls_mpi_is_prime_ext( const mbedtls_mpi *X, int rounds, if( mbedtls_mpi_cmp_int( &XX, 0 ) == 0 || mbedtls_mpi_cmp_int( &XX, 1 ) == 0 ) - return( MBEDTLS_ERR_MPI_NOT_ACCEPTABLE ); + return MBEDTLS_ERR_MPI_NOT_ACCEPTABLE ; if( mbedtls_mpi_cmp_int( &XX, 2 ) == 0 ) - return( 0 ); + return 0 ; if( ( ret = mpi_check_small_factors( &XX ) ) != 0 ) { if( ret == 1 ) - return( 0 ); + return 0 ; - return( ret ); + return ret ; } - return( mpi_miller_rabin( &XX, rounds, f_rng, p_rng ) ); + return mpi_miller_rabin( &XX, rounds, f_rng, p_rng ) ; } /* @@ -3086,7 +3086,7 @@ int mbedtls_mpi_gen_prime( mbedtls_mpi *X, size_t nbits, int flags, MPI_VALIDATE_RET( f_rng != NULL ); if( nbits < 3 || nbits > MBEDTLS_MPI_MAX_BITS ) - return( MBEDTLS_ERR_MPI_BAD_INPUT_DATA ); + return MBEDTLS_ERR_MPI_BAD_INPUT_DATA ; mbedtls_mpi_init( &Y ); @@ -3182,7 +3182,7 @@ cleanup: mbedtls_mpi_free( &Y ); - return( ret ); + return ret ; } #endif /* MBEDTLS_GENPRIME */ @@ -3356,7 +3356,7 @@ cleanup: if( verbose != 0 ) mbedtls_printf( "\n" ); - return( ret ); + return ret ; } #endif /* MBEDTLS_SELF_TEST */ diff --git a/library/camellia.c b/library/camellia.c index f7e013611b..34c8a10441 100644 --- a/library/camellia.c +++ b/library/camellia.c @@ -361,7 +361,7 @@ int mbedtls_camellia_setkey_enc( mbedtls_camellia_context *ctx, case 128: ctx->nr = 3; idx = 0; break; case 192: case 256: ctx->nr = 4; idx = 1; break; - default : return( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA ); + default : return MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA ; } for( i = 0; i < keybits / 8; ++i ) @@ -439,7 +439,7 @@ int mbedtls_camellia_setkey_enc( mbedtls_camellia_context *ctx, } } - return( 0 ); + return 0 ; } /* @@ -490,7 +490,7 @@ int mbedtls_camellia_setkey_dec( mbedtls_camellia_context *ctx, exit: mbedtls_camellia_free( &cty ); - return( ret ); + return ret ; } /* @@ -557,7 +557,7 @@ int mbedtls_camellia_crypt_ecb( mbedtls_camellia_context *ctx, PUT_UINT32_BE( X[0], output, 8 ); PUT_UINT32_BE( X[1], output, 12 ); - return( 0 ); + return 0 ; } #if defined(MBEDTLS_CIPHER_MODE_CBC) @@ -581,7 +581,7 @@ int mbedtls_camellia_crypt_cbc( mbedtls_camellia_context *ctx, CAMELLIA_VALIDATE_RET( length == 0 || output != NULL ); if( length % 16 ) - return( MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH ); + return MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH ; if( mode == MBEDTLS_CAMELLIA_DECRYPT ) { @@ -616,7 +616,7 @@ int mbedtls_camellia_crypt_cbc( mbedtls_camellia_context *ctx, } } - return( 0 ); + return 0 ; } #endif /* MBEDTLS_CIPHER_MODE_CBC */ @@ -644,7 +644,7 @@ int mbedtls_camellia_crypt_cfb128( mbedtls_camellia_context *ctx, n = *iv_off; if( n >= 16 ) - return( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA ); + return MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA ; if( mode == MBEDTLS_CAMELLIA_DECRYPT ) { @@ -675,7 +675,7 @@ int mbedtls_camellia_crypt_cfb128( mbedtls_camellia_context *ctx, *iv_off = n; - return( 0 ); + return 0 ; } #endif /* MBEDTLS_CIPHER_MODE_CFB */ @@ -702,7 +702,7 @@ int mbedtls_camellia_crypt_ctr( mbedtls_camellia_context *ctx, n = *nc_off; if( n >= 16 ) - return( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA ); + return MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA ; while( length-- ) { @@ -722,7 +722,7 @@ int mbedtls_camellia_crypt_ctr( mbedtls_camellia_context *ctx, *nc_off = n; - return( 0 ); + return 0 ; } #endif /* MBEDTLS_CIPHER_MODE_CTR */ #endif /* !MBEDTLS_CAMELLIA_ALT */ @@ -1102,7 +1102,7 @@ int mbedtls_camellia_self_test( int verbose ) exit: mbedtls_camellia_free( &ctx ); - return( ret ); + return ret ; } #endif /* MBEDTLS_SELF_TEST */ diff --git a/library/ccm.c b/library/ccm.c index 424ee77b69..f4a40cf8e9 100644 --- a/library/ccm.c +++ b/library/ccm.c @@ -78,23 +78,23 @@ int mbedtls_ccm_setkey( mbedtls_ccm_context *ctx, cipher_info = mbedtls_cipher_info_from_values( cipher, keybits, MBEDTLS_MODE_ECB ); if( cipher_info == NULL ) - return( MBEDTLS_ERR_CCM_BAD_INPUT ); + return MBEDTLS_ERR_CCM_BAD_INPUT ; if( cipher_info->block_size != 16 ) - return( MBEDTLS_ERR_CCM_BAD_INPUT ); + return MBEDTLS_ERR_CCM_BAD_INPUT ; mbedtls_cipher_free( &ctx->cipher_ctx ); if( ( ret = mbedtls_cipher_setup( &ctx->cipher_ctx, cipher_info ) ) != 0 ) - return( ret ); + return ret ; if( ( ret = mbedtls_cipher_setkey( &ctx->cipher_ctx, key, keybits, MBEDTLS_ENCRYPT ) ) != 0 ) { - return( ret ); + return ret ; } - return( 0 ); + return 0 ; } /* @@ -122,7 +122,7 @@ void mbedtls_ccm_free( mbedtls_ccm_context *ctx ) y[i] ^= b[i]; \ \ if( ( ret = mbedtls_cipher_update( &ctx->cipher_ctx, y, 16, y, &olen ) ) != 0 ) \ - return( ret ); + return ret ; /* * Encrypt or decrypt a partial block with CTR @@ -135,7 +135,7 @@ void mbedtls_ccm_free( mbedtls_ccm_context *ctx ) if( ( ret = mbedtls_cipher_update( &ctx->cipher_ctx, ctr, \ 16, b, &olen ) ) != 0 ) \ { \ - return( ret ); \ + return ret ; \ } \ \ for( i = 0; i < (len); i++ ) \ @@ -169,14 +169,14 @@ static int ccm_auth_crypt( mbedtls_ccm_context *ctx, int mode, size_t length, * Also, loosen the requirements to enable support for CCM* (IEEE 802.15.4). */ if( tag_len == 2 || tag_len > 16 || tag_len % 2 != 0 ) - return( MBEDTLS_ERR_CCM_BAD_INPUT ); + return MBEDTLS_ERR_CCM_BAD_INPUT ; /* Also implies q is within bounds */ if( iv_len < 7 || iv_len > 13 ) - return( MBEDTLS_ERR_CCM_BAD_INPUT ); + return MBEDTLS_ERR_CCM_BAD_INPUT ; if( add_len >= 0xFF00 ) - return( MBEDTLS_ERR_CCM_BAD_INPUT ); + return MBEDTLS_ERR_CCM_BAD_INPUT ; q = 16 - 1 - (unsigned char) iv_len; @@ -203,7 +203,7 @@ static int ccm_auth_crypt( mbedtls_ccm_context *ctx, int mode, size_t length, b[15-i] = (unsigned char)( len_left & 0xFF ); if( len_left > 0 ) - return( MBEDTLS_ERR_CCM_BAD_INPUT ); + return MBEDTLS_ERR_CCM_BAD_INPUT ; /* Start CBC-MAC with first block */ @@ -311,7 +311,7 @@ static int ccm_auth_crypt( mbedtls_ccm_context *ctx, int mode, size_t length, CTR_CRYPT( y, y, 16 ); memcpy( tag, y, tag_len ); - return( 0 ); + return 0 ; } /* @@ -346,7 +346,7 @@ int mbedtls_ccm_encrypt_and_tag( mbedtls_ccm_context *ctx, size_t length, CCM_VALIDATE_RET( length == 0 || output != NULL ); CCM_VALIDATE_RET( tag_len == 0 || tag != NULL ); if( tag_len == 0 ) - return( MBEDTLS_ERR_CCM_BAD_INPUT ); + return MBEDTLS_ERR_CCM_BAD_INPUT ; return( mbedtls_ccm_star_encrypt_and_tag( ctx, length, iv, iv_len, add, add_len, input, output, tag, tag_len ) ); @@ -377,7 +377,7 @@ int mbedtls_ccm_star_auth_decrypt( mbedtls_ccm_context *ctx, size_t length, iv, iv_len, add, add_len, input, output, check_tag, tag_len ) ) != 0 ) { - return( ret ); + return ret ; } /* Check tag in "constant-time" */ @@ -387,10 +387,10 @@ int mbedtls_ccm_star_auth_decrypt( mbedtls_ccm_context *ctx, size_t length, if( diff != 0 ) { mbedtls_platform_zeroize( output, length ); - return( MBEDTLS_ERR_CCM_AUTH_FAILED ); + return MBEDTLS_ERR_CCM_AUTH_FAILED ; } - return( 0 ); + return 0 ; } int mbedtls_ccm_auth_decrypt( mbedtls_ccm_context *ctx, size_t length, @@ -407,7 +407,7 @@ int mbedtls_ccm_auth_decrypt( mbedtls_ccm_context *ctx, size_t length, CCM_VALIDATE_RET( tag_len == 0 || tag != NULL ); if( tag_len == 0 ) - return( MBEDTLS_ERR_CCM_BAD_INPUT ); + return MBEDTLS_ERR_CCM_BAD_INPUT ; return( mbedtls_ccm_star_auth_decrypt( ctx, length, iv, iv_len, add, add_len, input, output, tag, tag_len ) ); @@ -479,12 +479,12 @@ 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" ); - return( 1 ); + return 1 ; } for( i = 0; i < NB_TESTS; i++ ) @@ -510,7 +510,7 @@ int mbedtls_ccm_self_test( int verbose ) if( verbose != 0 ) mbedtls_printf( "failed\n" ); - return( 1 ); + return 1 ; } memset( plaintext, 0, CCM_SELFTEST_PT_MAX_LEN ); @@ -527,7 +527,7 @@ int mbedtls_ccm_self_test( int verbose ) if( verbose != 0 ) mbedtls_printf( "failed\n" ); - return( 1 ); + return 1 ; } if( verbose != 0 ) @@ -539,7 +539,7 @@ int mbedtls_ccm_self_test( int verbose ) if( verbose != 0 ) mbedtls_printf( "\n" ); - return( 0 ); + return 0 ; } #endif /* MBEDTLS_SELF_TEST && MBEDTLS_AES_C */ diff --git a/library/chacha20.c b/library/chacha20.c index 78467d3fc6..87553bb7c6 100644 --- a/library/chacha20.c +++ b/library/chacha20.c @@ -221,7 +221,7 @@ int mbedtls_chacha20_setkey( mbedtls_chacha20_context *ctx, ctx->state[10] = BYTES_TO_U32_LE( key, 24 ); ctx->state[11] = BYTES_TO_U32_LE( key, 28 ); - return( 0 ); + return 0 ; } int mbedtls_chacha20_starts( mbedtls_chacha20_context* ctx, @@ -244,7 +244,7 @@ int mbedtls_chacha20_starts( mbedtls_chacha20_context* ctx, /* Initially, there's no keystream bytes available */ ctx->keystream_bytes_used = CHACHA20_BLOCK_SIZE_BYTES; - return( 0 ); + return 0 ; } int mbedtls_chacha20_update( mbedtls_chacha20_context *ctx, @@ -309,7 +309,7 @@ int mbedtls_chacha20_update( mbedtls_chacha20_context *ctx, } - return( 0 ); + return 0 ; } int mbedtls_chacha20_crypt( const unsigned char key[32], @@ -341,7 +341,7 @@ int mbedtls_chacha20_crypt( const unsigned char key[32], cleanup: mbedtls_chacha20_free( &ctx ); - return( ret ); + return ret ; } #endif /* !MBEDTLS_CHACHA20_ALT */ @@ -525,7 +525,7 @@ static const size_t test_lengths[2] = if( verbose != 0 ) \ mbedtls_printf args; \ \ - return( -1 ); \ + return -1 ; \ } \ } \ while( 0 ) @@ -560,7 +560,7 @@ int mbedtls_chacha20_self_test( int verbose ) if( verbose != 0 ) mbedtls_printf( "\n" ); - return( 0 ); + return 0 ; } #endif /* MBEDTLS_SELF_TEST */ diff --git a/library/chachapoly.c b/library/chachapoly.c index 77d547731c..ffa074bc33 100644 --- a/library/chachapoly.c +++ b/library/chachapoly.c @@ -61,7 +61,7 @@ static int chachapoly_pad_aad( mbedtls_chachapoly_context *ctx ) unsigned char zeroes[15]; if( partial_block_len == 0U ) - return( 0 ); + return 0 ; memset( zeroes, 0, sizeof( zeroes ) ); @@ -81,7 +81,7 @@ static int chachapoly_pad_ciphertext( mbedtls_chachapoly_context *ctx ) unsigned char zeroes[15]; if( partial_block_len == 0U ) - return( 0 ); + return 0 ; memset( zeroes, 0, sizeof( zeroes ) ); return( mbedtls_poly1305_update( &ctx->poly1305_ctx, @@ -123,7 +123,7 @@ int mbedtls_chachapoly_setkey( mbedtls_chachapoly_context *ctx, ret = mbedtls_chacha20_setkey( &ctx->chacha20_ctx, key ); - return( ret ); + return ret ; } int mbedtls_chachapoly_starts( mbedtls_chachapoly_context *ctx, @@ -163,7 +163,7 @@ int mbedtls_chachapoly_starts( mbedtls_chachapoly_context *ctx, cleanup: mbedtls_platform_zeroize( poly1305_key, 64U ); - return( ret ); + return ret ; } int mbedtls_chachapoly_update_aad( mbedtls_chachapoly_context *ctx, @@ -174,11 +174,11 @@ int mbedtls_chachapoly_update_aad( mbedtls_chachapoly_context *ctx, CHACHAPOLY_VALIDATE_RET( aad_len == 0 || aad != NULL ); if( ctx->state != CHACHAPOLY_STATE_AAD ) - return( MBEDTLS_ERR_CHACHAPOLY_BAD_STATE ); + return MBEDTLS_ERR_CHACHAPOLY_BAD_STATE ; ctx->aad_len += aad_len; - return( mbedtls_poly1305_update( &ctx->poly1305_ctx, aad, aad_len ) ); + return mbedtls_poly1305_update( &ctx->poly1305_ctx, aad, aad_len ) ; } int mbedtls_chachapoly_update( mbedtls_chachapoly_context *ctx, @@ -194,7 +194,7 @@ int mbedtls_chachapoly_update( mbedtls_chachapoly_context *ctx, if( ( ctx->state != CHACHAPOLY_STATE_AAD ) && ( ctx->state != CHACHAPOLY_STATE_CIPHERTEXT ) ) { - return( MBEDTLS_ERR_CHACHAPOLY_BAD_STATE ); + return MBEDTLS_ERR_CHACHAPOLY_BAD_STATE ; } if( ctx->state == CHACHAPOLY_STATE_AAD ) @@ -203,7 +203,7 @@ int mbedtls_chachapoly_update( mbedtls_chachapoly_context *ctx, ret = chachapoly_pad_aad( ctx ); if( ret != 0 ) - return( ret ); + return ret ; } ctx->ciphertext_len += len; @@ -212,24 +212,24 @@ int mbedtls_chachapoly_update( mbedtls_chachapoly_context *ctx, { ret = mbedtls_chacha20_update( &ctx->chacha20_ctx, len, input, output ); if( ret != 0 ) - return( ret ); + return ret ; ret = mbedtls_poly1305_update( &ctx->poly1305_ctx, output, len ); if( ret != 0 ) - return( ret ); + return ret ; } else /* DECRYPT */ { ret = mbedtls_poly1305_update( &ctx->poly1305_ctx, input, len ); if( ret != 0 ) - return( ret ); + return ret ; ret = mbedtls_chacha20_update( &ctx->chacha20_ctx, len, input, output ); if( ret != 0 ) - return( ret ); + return ret ; } - return( 0 ); + return 0 ; } int mbedtls_chachapoly_finish( mbedtls_chachapoly_context *ctx, @@ -242,20 +242,20 @@ int mbedtls_chachapoly_finish( mbedtls_chachapoly_context *ctx, if( ctx->state == CHACHAPOLY_STATE_INIT ) { - return( MBEDTLS_ERR_CHACHAPOLY_BAD_STATE ); + return MBEDTLS_ERR_CHACHAPOLY_BAD_STATE ; } if( ctx->state == CHACHAPOLY_STATE_AAD ) { ret = chachapoly_pad_aad( ctx ); if( ret != 0 ) - return( ret ); + return ret ; } else if( ctx->state == CHACHAPOLY_STATE_CIPHERTEXT ) { ret = chachapoly_pad_ciphertext( ctx ); if( ret != 0 ) - return( ret ); + return ret ; } ctx->state = CHACHAPOLY_STATE_FINISHED; @@ -282,11 +282,11 @@ int mbedtls_chachapoly_finish( mbedtls_chachapoly_context *ctx, ret = mbedtls_poly1305_update( &ctx->poly1305_ctx, len_block, 16U ); if( ret != 0 ) - return( ret ); + return ret ; ret = mbedtls_poly1305_finish( &ctx->poly1305_ctx, mac ); - return( ret ); + return ret ; } static int chachapoly_crypt_and_tag( mbedtls_chachapoly_context *ctx, @@ -316,7 +316,7 @@ static int chachapoly_crypt_and_tag( mbedtls_chachapoly_context *ctx, ret = mbedtls_chachapoly_finish( ctx, tag ); cleanup: - return( ret ); + return ret ; } int mbedtls_chachapoly_encrypt_and_tag( mbedtls_chachapoly_context *ctx, @@ -364,7 +364,7 @@ int mbedtls_chachapoly_auth_decrypt( mbedtls_chachapoly_context *ctx, MBEDTLS_CHACHAPOLY_DECRYPT, length, nonce, aad, aad_len, input, output, check_tag ) ) != 0 ) { - return( ret ); + return ret ; } /* Check tag in "constant-time" */ @@ -374,10 +374,10 @@ int mbedtls_chachapoly_auth_decrypt( mbedtls_chachapoly_context *ctx, if( diff != 0 ) { mbedtls_platform_zeroize( output, length ); - return( MBEDTLS_ERR_CHACHAPOLY_AUTH_FAILED ); + return MBEDTLS_ERR_CHACHAPOLY_AUTH_FAILED ; } - return( 0 ); + return 0 ; } #endif /* MBEDTLS_CHACHAPOLY_ALT */ @@ -481,7 +481,7 @@ static const unsigned char test_mac[1][16] = if( verbose != 0 ) \ mbedtls_printf args; \ \ - return( -1 ); \ + return -1 ; \ } \ } \ while( 0 ) @@ -530,7 +530,7 @@ int mbedtls_chachapoly_self_test( int verbose ) if( verbose != 0 ) mbedtls_printf( "\n" ); - return( 0 ); + return 0 ; } #endif /* MBEDTLS_SELF_TEST */ diff --git a/library/cipher.c b/library/cipher.c index 546cace552..203a5876d2 100644 --- a/library/cipher.c +++ b/library/cipher.c @@ -91,7 +91,7 @@ static int mbedtls_constant_time_memcmp( const void *v1, const void *v2, for( diff = 0, i = 0; i < len; i++ ) diff |= p1[i] ^ p2[i]; - return( (int)diff ); + return (int)diff ; } #endif /* MBEDTLS_GCM_C || MBEDTLS_CHACHAPOLY_C */ @@ -115,7 +115,7 @@ const int *mbedtls_cipher_list( void ) supported_init = 1; } - return( mbedtls_cipher_supported ); + return mbedtls_cipher_supported ; } const mbedtls_cipher_info_t *mbedtls_cipher_info_from_type( @@ -125,9 +125,9 @@ const mbedtls_cipher_info_t *mbedtls_cipher_info_from_type( for( def = mbedtls_cipher_definitions; def->info != NULL; def++ ) if( def->type == cipher_type ) - return( def->info ); + return def->info ; - return( NULL ); + return NULL ; } const mbedtls_cipher_info_t *mbedtls_cipher_info_from_string( @@ -136,13 +136,13 @@ const mbedtls_cipher_info_t *mbedtls_cipher_info_from_string( const mbedtls_cipher_definition_t *def; if( NULL == cipher_name ) - return( NULL ); + return NULL ; for( def = mbedtls_cipher_definitions; def->info != NULL; def++ ) if( ! strcmp( def->info->name, cipher_name ) ) - return( def->info ); + return def->info ; - return( NULL ); + return NULL ; } const mbedtls_cipher_info_t *mbedtls_cipher_info_from_values( @@ -156,9 +156,9 @@ const mbedtls_cipher_info_t *mbedtls_cipher_info_from_values( if( def->info->base->cipher == cipher_id && def->info->key_bitlen == (unsigned) key_bitlen && def->info->mode == mode ) - return( def->info ); + return def->info ; - return( NULL ); + return NULL ; } void mbedtls_cipher_init( mbedtls_cipher_context_t *ctx ) @@ -215,12 +215,12 @@ int mbedtls_cipher_setup( mbedtls_cipher_context_t *ctx, { CIPHER_VALIDATE_RET( ctx != NULL ); if( cipher_info == NULL ) - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ; memset( ctx, 0, sizeof( mbedtls_cipher_context_t ) ); if( NULL == ( ctx->cipher_ctx = cipher_info->base->ctx_alloc_func() ) ) - return( MBEDTLS_ERR_CIPHER_ALLOC_FAILED ); + return MBEDTLS_ERR_CIPHER_ALLOC_FAILED ; ctx->cipher_info = cipher_info; @@ -235,7 +235,7 @@ int mbedtls_cipher_setup( mbedtls_cipher_context_t *ctx, #endif #endif /* MBEDTLS_CIPHER_MODE_WITH_PADDING */ - return( 0 ); + return 0 ; } #if defined(MBEDTLS_USE_PSA_CRYPTO) @@ -247,26 +247,26 @@ int mbedtls_cipher_setup_psa( mbedtls_cipher_context_t *ctx, mbedtls_cipher_context_psa *cipher_psa; if( NULL == cipher_info || NULL == ctx ) - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ; /* Check that the underlying cipher mode and cipher type are * supported by the underlying PSA Crypto implementation. */ alg = mbedtls_psa_translate_cipher_mode( cipher_info->mode, taglen ); if( alg == 0 ) - return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ; if( mbedtls_psa_translate_cipher_type( cipher_info->type ) == 0 ) - return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ; memset( ctx, 0, sizeof( mbedtls_cipher_context_t ) ); cipher_psa = mbedtls_calloc( 1, sizeof(mbedtls_cipher_context_psa ) ); if( cipher_psa == NULL ) - return( MBEDTLS_ERR_CIPHER_ALLOC_FAILED ); + return MBEDTLS_ERR_CIPHER_ALLOC_FAILED ; cipher_psa->alg = alg; ctx->cipher_ctx = cipher_psa; ctx->cipher_info = cipher_info; ctx->psa_enabled = 1; - return( 0 ); + return 0 ; } #endif /* MBEDTLS_USE_PSA_CRYPTO */ @@ -280,7 +280,7 @@ int mbedtls_cipher_setkey( mbedtls_cipher_context_t *ctx, CIPHER_VALIDATE_RET( operation == MBEDTLS_ENCRYPT || operation == MBEDTLS_DECRYPT ); if( ctx->cipher_info == NULL ) - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ; #if defined(MBEDTLS_USE_PSA_CRYPTO) if( ctx->psa_enabled == 1 ) @@ -296,16 +296,16 @@ int mbedtls_cipher_setkey( mbedtls_cipher_context_t *ctx, /* PSA Crypto API only accepts byte-aligned keys. */ if( key_bitlen % 8 != 0 ) - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ; /* Don't allow keys to be set multiple times. */ if( cipher_psa->slot_state != MBEDTLS_CIPHER_PSA_KEY_UNSET ) - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ; key_type = mbedtls_psa_translate_cipher_type( ctx->cipher_info->type ); if( key_type == 0 ) - return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ; psa_set_key_type( &attributes, key_type ); /* Mbed TLS' cipher layer doesn't enforce the mode of operation @@ -324,11 +324,11 @@ int mbedtls_cipher_setkey( mbedtls_cipher_context_t *ctx, case PSA_SUCCESS: break; case PSA_ERROR_INSUFFICIENT_MEMORY: - return( MBEDTLS_ERR_CIPHER_ALLOC_FAILED ); + return MBEDTLS_ERR_CIPHER_ALLOC_FAILED ; case PSA_ERROR_NOT_SUPPORTED: - return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ; default: - return( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED ); + return MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED ; } /* Indicate that we own the key slot and need to * destroy it in mbedtls_cipher_free(). */ @@ -336,14 +336,14 @@ int mbedtls_cipher_setkey( mbedtls_cipher_context_t *ctx, ctx->key_bitlen = key_bitlen; ctx->operation = operation; - return( 0 ); + return 0 ; } #endif /* MBEDTLS_USE_PSA_CRYPTO */ if( ( ctx->cipher_info->flags & MBEDTLS_CIPHER_VARIABLE_KEY_LEN ) == 0 && (int) ctx->cipher_info->key_bitlen != key_bitlen ) { - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ; } ctx->key_bitlen = key_bitlen; @@ -365,7 +365,7 @@ int mbedtls_cipher_setkey( mbedtls_cipher_context_t *ctx, return( ctx->cipher_info->base->setkey_dec_func( ctx->cipher_ctx, key, ctx->key_bitlen ) ); - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ; } int mbedtls_cipher_set_iv( mbedtls_cipher_context_t *ctx, @@ -377,20 +377,20 @@ int mbedtls_cipher_set_iv( mbedtls_cipher_context_t *ctx, CIPHER_VALIDATE_RET( ctx != NULL ); CIPHER_VALIDATE_RET( iv_len == 0 || iv != NULL ); if( ctx->cipher_info == NULL ) - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ; #if defined(MBEDTLS_USE_PSA_CRYPTO) if( ctx->psa_enabled == 1 ) { /* While PSA Crypto has an API for multipart * operations, we currently don't make it * accessible through the cipher layer. */ - return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ; } #endif /* MBEDTLS_USE_PSA_CRYPTO */ /* avoid buffer overflow in ctx->iv */ if( iv_len > MBEDTLS_MAX_IV_LENGTH ) - return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ; if( ( ctx->cipher_info->flags & MBEDTLS_CIPHER_VARIABLE_IV_LEN ) != 0 ) actual_iv_size = iv_len; @@ -400,7 +400,7 @@ int mbedtls_cipher_set_iv( mbedtls_cipher_context_t *ctx, /* avoid reading past the end of input buffer */ if( actual_iv_size > iv_len ) - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ; } #if defined(MBEDTLS_CHACHA20_C) @@ -410,7 +410,7 @@ int mbedtls_cipher_set_iv( mbedtls_cipher_context_t *ctx, iv, 0U ) ) /* Initial counter value */ { - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ; } } #endif @@ -430,27 +430,27 @@ int mbedtls_cipher_set_iv( mbedtls_cipher_context_t *ctx, ctx->iv_size = actual_iv_size; } - return( 0 ); + return 0 ; } int mbedtls_cipher_reset( mbedtls_cipher_context_t *ctx ) { CIPHER_VALIDATE_RET( ctx != NULL ); if( ctx->cipher_info == NULL ) - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ; #if defined(MBEDTLS_USE_PSA_CRYPTO) if( ctx->psa_enabled == 1 ) { /* We don't support resetting PSA-based * cipher contexts, yet. */ - return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ; } #endif /* MBEDTLS_USE_PSA_CRYPTO */ ctx->unprocessed_len = 0; - return( 0 ); + return 0 ; } #if defined(MBEDTLS_GCM_C) || defined(MBEDTLS_CHACHAPOLY_C) @@ -460,7 +460,7 @@ int mbedtls_cipher_update_ad( mbedtls_cipher_context_t *ctx, CIPHER_VALIDATE_RET( ctx != NULL ); CIPHER_VALIDATE_RET( ad_len == 0 || ad != NULL ); if( ctx->cipher_info == NULL ) - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ; #if defined(MBEDTLS_USE_PSA_CRYPTO) if( ctx->psa_enabled == 1 ) @@ -468,7 +468,7 @@ int mbedtls_cipher_update_ad( mbedtls_cipher_context_t *ctx, /* While PSA Crypto has an API for multipart * operations, we currently don't make it * accessible through the cipher layer. */ - return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ; } #endif /* MBEDTLS_USE_PSA_CRYPTO */ @@ -494,14 +494,14 @@ int mbedtls_cipher_update_ad( mbedtls_cipher_context_t *ctx, ctx->iv, mode ); if ( result != 0 ) - return( result ); + return result ; return( mbedtls_chachapoly_update_aad( (mbedtls_chachapoly_context*) ctx->cipher_ctx, ad, ad_len ) ); } #endif - return( 0 ); + return 0 ; } #endif /* MBEDTLS_GCM_C || MBEDTLS_CHACHAPOLY_C */ @@ -516,7 +516,7 @@ int mbedtls_cipher_update( mbedtls_cipher_context_t *ctx, const unsigned char *i CIPHER_VALIDATE_RET( output != NULL ); CIPHER_VALIDATE_RET( olen != NULL ); if( ctx->cipher_info == NULL ) - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ; #if defined(MBEDTLS_USE_PSA_CRYPTO) if( ctx->psa_enabled == 1 ) @@ -524,7 +524,7 @@ int mbedtls_cipher_update( mbedtls_cipher_context_t *ctx, const unsigned char *i /* While PSA Crypto has an API for multipart * operations, we currently don't make it * accessible through the cipher layer. */ - return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ; } #endif /* MBEDTLS_USE_PSA_CRYPTO */ @@ -532,23 +532,23 @@ int mbedtls_cipher_update( mbedtls_cipher_context_t *ctx, const unsigned char *i block_size = mbedtls_cipher_get_block_size( ctx ); if ( 0 == block_size ) { - return( MBEDTLS_ERR_CIPHER_INVALID_CONTEXT ); + return MBEDTLS_ERR_CIPHER_INVALID_CONTEXT ; } if( ctx->cipher_info->mode == MBEDTLS_MODE_ECB ) { if( ilen != block_size ) - return( MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED ); + return MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED ; *olen = ilen; if( 0 != ( ret = ctx->cipher_info->base->ecb_func( ctx->cipher_ctx, ctx->operation, input, output ) ) ) { - return( ret ); + return ret ; } - return( 0 ); + return 0 ; } #if defined(MBEDTLS_GCM_C) @@ -572,7 +572,7 @@ int mbedtls_cipher_update( mbedtls_cipher_context_t *ctx, const unsigned char *i if( input == output && ( ctx->unprocessed_len != 0 || ilen % block_size ) ) { - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ; } #if defined(MBEDTLS_CIPHER_MODE_CBC) @@ -594,7 +594,7 @@ int mbedtls_cipher_update( mbedtls_cipher_context_t *ctx, const unsigned char *i ilen ); ctx->unprocessed_len += ilen; - return( 0 ); + return 0 ; } /* @@ -611,7 +611,7 @@ int mbedtls_cipher_update( mbedtls_cipher_context_t *ctx, const unsigned char *i ctx->operation, block_size, ctx->iv, ctx->unprocessed_data, output ) ) ) { - return( ret ); + return ret ; } *olen += block_size; @@ -654,13 +654,13 @@ int mbedtls_cipher_update( mbedtls_cipher_context_t *ctx, const unsigned char *i if( 0 != ( ret = ctx->cipher_info->base->cbc_func( ctx->cipher_ctx, ctx->operation, ilen, ctx->iv, input, output ) ) ) { - return( ret ); + return ret ; } *olen += ilen; } - return( 0 ); + return 0 ; } #endif /* MBEDTLS_CIPHER_MODE_CBC */ @@ -671,12 +671,12 @@ int mbedtls_cipher_update( mbedtls_cipher_context_t *ctx, const unsigned char *i ctx->operation, ilen, &ctx->unprocessed_len, ctx->iv, input, output ) ) ) { - return( ret ); + return ret ; } *olen = ilen; - return( 0 ); + return 0 ; } #endif /* MBEDTLS_CIPHER_MODE_CFB */ @@ -686,12 +686,12 @@ int mbedtls_cipher_update( mbedtls_cipher_context_t *ctx, const unsigned char *i if( 0 != ( ret = ctx->cipher_info->base->ofb_func( ctx->cipher_ctx, ilen, &ctx->unprocessed_len, ctx->iv, input, output ) ) ) { - return( ret ); + return ret ; } *olen = ilen; - return( 0 ); + return 0 ; } #endif /* MBEDTLS_CIPHER_MODE_OFB */ @@ -702,12 +702,12 @@ int mbedtls_cipher_update( mbedtls_cipher_context_t *ctx, const unsigned char *i ilen, &ctx->unprocessed_len, ctx->iv, ctx->unprocessed_data, input, output ) ) ) { - return( ret ); + return ret ; } *olen = ilen; - return( 0 ); + return 0 ; } #endif /* MBEDTLS_CIPHER_MODE_CTR */ @@ -716,19 +716,19 @@ int mbedtls_cipher_update( mbedtls_cipher_context_t *ctx, const unsigned char *i { if( ctx->unprocessed_len > 0 ) { /* We can only process an entire data unit at a time. */ - return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ; } ret = ctx->cipher_info->base->xts_func( ctx->cipher_ctx, ctx->operation, ilen, ctx->iv, input, output ); if( ret != 0 ) { - return( ret ); + return ret ; } *olen = ilen; - return( 0 ); + return 0 ; } #endif /* MBEDTLS_CIPHER_MODE_XTS */ @@ -738,16 +738,16 @@ int mbedtls_cipher_update( mbedtls_cipher_context_t *ctx, const unsigned char *i if( 0 != ( ret = ctx->cipher_info->base->stream_func( ctx->cipher_ctx, ilen, input, output ) ) ) { - return( ret ); + return ret ; } *olen = ilen; - return( 0 ); + return 0 ; } #endif /* MBEDTLS_CIPHER_MODE_STREAM */ - return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ; } #if defined(MBEDTLS_CIPHER_MODE_WITH_PADDING) @@ -772,7 +772,7 @@ static int get_pkcs_padding( unsigned char *input, size_t input_len, unsigned char padding_len, bad = 0; if( NULL == input || NULL == data_len ) - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ; padding_len = input[input_len - 1]; *data_len = input_len - padding_len; @@ -787,7 +787,7 @@ static int get_pkcs_padding( unsigned char *input, size_t input_len, for( i = 0; i < input_len; i++ ) bad |= ( input[i] ^ padding_len ) * ( i >= pad_idx ); - return( MBEDTLS_ERR_CIPHER_INVALID_PADDING * ( bad != 0 ) ); + return MBEDTLS_ERR_CIPHER_INVALID_PADDING * ( bad != 0 ) ; } #endif /* MBEDTLS_CIPHER_PADDING_PKCS7 */ @@ -813,7 +813,7 @@ static int get_one_and_zeros_padding( unsigned char *input, size_t input_len, unsigned char done = 0, prev_done, bad; if( NULL == input || NULL == data_len ) - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ; bad = 0x80; *data_len = 0; @@ -825,7 +825,7 @@ static int get_one_and_zeros_padding( unsigned char *input, size_t input_len, bad ^= input[i - 1] * ( done != prev_done ); } - return( MBEDTLS_ERR_CIPHER_INVALID_PADDING * ( bad != 0 ) ); + return MBEDTLS_ERR_CIPHER_INVALID_PADDING * ( bad != 0 ) ; } #endif /* MBEDTLS_CIPHER_PADDING_ONE_AND_ZEROS */ @@ -852,7 +852,7 @@ static int get_zeros_and_len_padding( unsigned char *input, size_t input_len, unsigned char padding_len, bad = 0; if( NULL == input || NULL == data_len ) - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ; padding_len = input[input_len - 1]; *data_len = input_len - padding_len; @@ -866,7 +866,7 @@ static int get_zeros_and_len_padding( unsigned char *input, size_t input_len, for( i = 0; i < input_len - 1; i++ ) bad |= input[i] * ( i >= pad_idx ); - return( MBEDTLS_ERR_CIPHER_INVALID_PADDING * ( bad != 0 ) ); + return MBEDTLS_ERR_CIPHER_INVALID_PADDING * ( bad != 0 ) ; } #endif /* MBEDTLS_CIPHER_PADDING_ZEROS_AND_LEN */ @@ -890,7 +890,7 @@ static int get_zeros_padding( unsigned char *input, size_t input_len, unsigned char done = 0, prev_done; if( NULL == input || NULL == data_len ) - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ; *data_len = 0; for( i = input_len; i > 0; i-- ) @@ -900,7 +900,7 @@ static int get_zeros_padding( unsigned char *input, size_t input_len, *data_len |= i * ( done != prev_done ); } - return( 0 ); + return 0 ; } #endif /* MBEDTLS_CIPHER_PADDING_ZEROS */ @@ -914,11 +914,11 @@ static int get_no_padding( unsigned char *input, size_t input_len, size_t *data_len ) { if( NULL == input || NULL == data_len ) - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ; *data_len = input_len; - return( 0 ); + return 0 ; } #endif /* MBEDTLS_CIPHER_MODE_WITH_PADDING */ @@ -929,7 +929,7 @@ int mbedtls_cipher_finish( mbedtls_cipher_context_t *ctx, CIPHER_VALIDATE_RET( output != NULL ); CIPHER_VALIDATE_RET( olen != NULL ); if( ctx->cipher_info == NULL ) - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ; #if defined(MBEDTLS_USE_PSA_CRYPTO) if( ctx->psa_enabled == 1 ) @@ -937,7 +937,7 @@ int mbedtls_cipher_finish( mbedtls_cipher_context_t *ctx, /* While PSA Crypto has an API for multipart * operations, we currently don't make it * accessible through the cipher layer. */ - return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ; } #endif /* MBEDTLS_USE_PSA_CRYPTO */ @@ -950,21 +950,21 @@ int mbedtls_cipher_finish( mbedtls_cipher_context_t *ctx, MBEDTLS_MODE_XTS == ctx->cipher_info->mode || MBEDTLS_MODE_STREAM == ctx->cipher_info->mode ) { - return( 0 ); + return 0 ; } if ( ( MBEDTLS_CIPHER_CHACHA20 == ctx->cipher_info->type ) || ( MBEDTLS_CIPHER_CHACHA20_POLY1305 == ctx->cipher_info->type ) ) { - return( 0 ); + return 0 ; } if( MBEDTLS_MODE_ECB == ctx->cipher_info->mode ) { if( ctx->unprocessed_len != 0 ) - return( MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED ); + return MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED ; - return( 0 ); + return 0 ; } #if defined(MBEDTLS_CIPHER_MODE_CBC) @@ -978,9 +978,9 @@ int mbedtls_cipher_finish( mbedtls_cipher_context_t *ctx, if( NULL == ctx->add_padding ) { if( 0 != ctx->unprocessed_len ) - return( MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED ); + return MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED ; - return( 0 ); + return 0 ; } ctx->add_padding( ctx->unprocessed_data, mbedtls_cipher_get_iv_size( ctx ), @@ -993,9 +993,9 @@ int mbedtls_cipher_finish( mbedtls_cipher_context_t *ctx, * or an empty block if no padding */ if( NULL == ctx->add_padding && 0 == ctx->unprocessed_len ) - return( 0 ); + return 0 ; - return( MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED ); + return MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED ; } /* cipher block */ @@ -1003,7 +1003,7 @@ int mbedtls_cipher_finish( mbedtls_cipher_context_t *ctx, ctx->operation, mbedtls_cipher_get_block_size( ctx ), ctx->iv, ctx->unprocessed_data, output ) ) ) { - return( ret ); + return ret ; } /* Set output size for decryption */ @@ -1013,13 +1013,13 @@ int mbedtls_cipher_finish( mbedtls_cipher_context_t *ctx, /* Set output size for encryption */ *olen = mbedtls_cipher_get_block_size( ctx ); - return( 0 ); + return 0 ; } #else ((void) output); #endif /* MBEDTLS_CIPHER_MODE_CBC */ - return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ; } #if defined(MBEDTLS_CIPHER_MODE_WITH_PADDING) @@ -1030,7 +1030,7 @@ int mbedtls_cipher_set_padding_mode( mbedtls_cipher_context_t *ctx, if( NULL == ctx->cipher_info || MBEDTLS_MODE_CBC != ctx->cipher_info->mode ) { - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ; } #if defined(MBEDTLS_USE_PSA_CRYPTO) @@ -1040,9 +1040,9 @@ int mbedtls_cipher_set_padding_mode( mbedtls_cipher_context_t *ctx, * schemes, we currently don't make them * accessible through the cipher layer. */ if( mode != MBEDTLS_PADDING_NONE ) - return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ; - return( 0 ); + return 0 ; } #endif /* MBEDTLS_USE_PSA_CRYPTO */ @@ -1078,10 +1078,10 @@ int mbedtls_cipher_set_padding_mode( mbedtls_cipher_context_t *ctx, break; default: - return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ; } - return( 0 ); + return 0 ; } #endif /* MBEDTLS_CIPHER_MODE_WITH_PADDING */ @@ -1092,10 +1092,10 @@ int mbedtls_cipher_write_tag( mbedtls_cipher_context_t *ctx, CIPHER_VALIDATE_RET( ctx != NULL ); CIPHER_VALIDATE_RET( tag_len == 0 || tag != NULL ); if( ctx->cipher_info == NULL ) - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ; if( MBEDTLS_ENCRYPT != ctx->operation ) - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ; #if defined(MBEDTLS_USE_PSA_CRYPTO) if( ctx->psa_enabled == 1 ) @@ -1103,7 +1103,7 @@ int mbedtls_cipher_write_tag( mbedtls_cipher_context_t *ctx, /* While PSA Crypto has an API for multipart * operations, we currently don't make it * accessible through the cipher layer. */ - return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ; } #endif /* MBEDTLS_USE_PSA_CRYPTO */ @@ -1124,14 +1124,14 @@ int mbedtls_cipher_write_tag( mbedtls_cipher_context_t *ctx, { /* Don't allow truncated MAC for Poly1305 */ if ( tag_len != 16U ) - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ; return( mbedtls_chachapoly_finish( (mbedtls_chachapoly_context*) ctx->cipher_ctx, tag ) ); } #endif - return( 0 ); + return 0 ; } int mbedtls_cipher_check_tag( mbedtls_cipher_context_t *ctx, @@ -1143,11 +1143,11 @@ int mbedtls_cipher_check_tag( mbedtls_cipher_context_t *ctx, CIPHER_VALIDATE_RET( ctx != NULL ); CIPHER_VALIDATE_RET( tag_len == 0 || tag != NULL ); if( ctx->cipher_info == NULL ) - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ; if( MBEDTLS_DECRYPT != ctx->operation ) { - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ; } #if defined(MBEDTLS_USE_PSA_CRYPTO) @@ -1156,7 +1156,7 @@ int mbedtls_cipher_check_tag( mbedtls_cipher_context_t *ctx, /* While PSA Crypto has an API for multipart * operations, we currently don't make it * accessible through the cipher layer. */ - return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ; } #endif /* MBEDTLS_USE_PSA_CRYPTO */ @@ -1168,21 +1168,21 @@ int mbedtls_cipher_check_tag( mbedtls_cipher_context_t *ctx, * that can delay up to a block of output. */ if( tag_len > sizeof( check_tag ) ) - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ; if( 0 != ( ret = mbedtls_gcm_finish( (mbedtls_gcm_context *) ctx->cipher_ctx, NULL, 0, &output_length, check_tag, tag_len ) ) ) { - return( ret ); + return ret ; } /* Check the tag in "constant-time" */ if( mbedtls_constant_time_memcmp( tag, check_tag, tag_len ) != 0 ) - return( MBEDTLS_ERR_CIPHER_AUTH_FAILED ); + return MBEDTLS_ERR_CIPHER_AUTH_FAILED ; - return( 0 ); + return 0 ; } #endif /* MBEDTLS_GCM_C */ @@ -1191,24 +1191,24 @@ int mbedtls_cipher_check_tag( mbedtls_cipher_context_t *ctx, { /* Don't allow truncated MAC for Poly1305 */ if ( tag_len != sizeof( check_tag ) ) - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ; ret = mbedtls_chachapoly_finish( (mbedtls_chachapoly_context*) ctx->cipher_ctx, check_tag ); if ( ret != 0 ) { - return( ret ); + return ret ; } /* Check the tag in "constant-time" */ if( mbedtls_constant_time_memcmp( tag, check_tag, tag_len ) != 0 ) - return( MBEDTLS_ERR_CIPHER_AUTH_FAILED ); + return MBEDTLS_ERR_CIPHER_AUTH_FAILED ; - return( 0 ); + return 0 ; } #endif /* MBEDTLS_CHACHAPOLY_C */ - return( 0 ); + return 0 ; } #endif /* MBEDTLS_GCM_C || MBEDTLS_CHACHAPOLY_C */ @@ -1257,53 +1257,53 @@ int mbedtls_cipher_crypt( mbedtls_cipher_context_t *ctx, cipher_psa->alg ); } else - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ; /* In the following, we can immediately return on an error, * because the PSA Crypto API guarantees that cipher operations * are terminated by unsuccessful calls to psa_cipher_update(), * and by any call to psa_cipher_finish(). */ if( status != PSA_SUCCESS ) - return( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED ); + return MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED ; status = psa_cipher_set_iv( &cipher_op, iv, iv_len ); if( status != PSA_SUCCESS ) - return( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED ); + return MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED ; status = psa_cipher_update( &cipher_op, input, ilen, output, ilen, olen ); if( status != PSA_SUCCESS ) - return( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED ); + return MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED ; status = psa_cipher_finish( &cipher_op, output + *olen, ilen - *olen, &part_len ); if( status != PSA_SUCCESS ) - return( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED ); + return MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED ; *olen += part_len; - return( 0 ); + return 0 ; } #endif /* MBEDTLS_USE_PSA_CRYPTO */ if( ( ret = mbedtls_cipher_set_iv( ctx, iv, iv_len ) ) != 0 ) - return( ret ); + return ret ; if( ( ret = mbedtls_cipher_reset( ctx ) ) != 0 ) - return( ret ); + return ret ; if( ( ret = mbedtls_cipher_update( ctx, input, ilen, output, olen ) ) != 0 ) - return( ret ); + return ret ; if( ( ret = mbedtls_cipher_finish( ctx, output + *olen, &finish_olen ) ) != 0 ) - return( ret ); + return ret ; *olen += finish_olen; - return( 0 ); + return 0 ; } #if defined(MBEDTLS_CIPHER_MODE_AEAD) @@ -1334,7 +1334,7 @@ static int mbedtls_cipher_aead_encrypt( mbedtls_cipher_context_t *ctx, /* PSA Crypto API always writes the authentication tag * at the end of the encrypted message. */ if( output == NULL || tag != output + ilen ) - return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ; status = psa_aead_encrypt( cipher_psa->slot, cipher_psa->alg, @@ -1343,10 +1343,10 @@ static int mbedtls_cipher_aead_encrypt( mbedtls_cipher_context_t *ctx, input, ilen, output, ilen + tag_len, olen ); if( status != PSA_SUCCESS ) - return( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED ); + return MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED ; *olen -= tag_len; - return( 0 ); + return 0 ; } #endif /* MBEDTLS_USE_PSA_CRYPTO */ @@ -1375,7 +1375,7 @@ static int mbedtls_cipher_aead_encrypt( mbedtls_cipher_context_t *ctx, if ( ( iv_len != ctx->cipher_info->iv_size ) || ( tag_len != 16U ) ) { - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ; } *olen = ilen; @@ -1384,7 +1384,7 @@ static int mbedtls_cipher_aead_encrypt( mbedtls_cipher_context_t *ctx, } #endif /* MBEDTLS_CHACHAPOLY_C */ - return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ; } /* @@ -1414,7 +1414,7 @@ static int mbedtls_cipher_aead_decrypt( mbedtls_cipher_context_t *ctx, /* PSA Crypto API always writes the authentication tag * at the end of the encrypted message. */ if( input == NULL || tag != input + ilen ) - return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ; status = psa_aead_decrypt( cipher_psa->slot, cipher_psa->alg, @@ -1423,11 +1423,11 @@ static int mbedtls_cipher_aead_decrypt( mbedtls_cipher_context_t *ctx, input, ilen + tag_len, output, ilen, olen ); if( status == PSA_ERROR_INVALID_SIGNATURE ) - return( MBEDTLS_ERR_CIPHER_AUTH_FAILED ); + return MBEDTLS_ERR_CIPHER_AUTH_FAILED ; else if( status != PSA_SUCCESS ) - return( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED ); + return MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED ; - return( 0 ); + return 0 ; } #endif /* MBEDTLS_USE_PSA_CRYPTO */ @@ -1444,7 +1444,7 @@ static int mbedtls_cipher_aead_decrypt( mbedtls_cipher_context_t *ctx, if( ret == MBEDTLS_ERR_GCM_AUTH_FAILED ) ret = MBEDTLS_ERR_CIPHER_AUTH_FAILED; - return( ret ); + return ret ; } #endif /* MBEDTLS_GCM_C */ #if defined(MBEDTLS_CCM_C) @@ -1460,7 +1460,7 @@ static int mbedtls_cipher_aead_decrypt( mbedtls_cipher_context_t *ctx, if( ret == MBEDTLS_ERR_CCM_AUTH_FAILED ) ret = MBEDTLS_ERR_CIPHER_AUTH_FAILED; - return( ret ); + return ret ; } #endif /* MBEDTLS_CCM_C */ #if defined(MBEDTLS_CHACHAPOLY_C) @@ -1472,7 +1472,7 @@ static int mbedtls_cipher_aead_decrypt( mbedtls_cipher_context_t *ctx, if ( ( iv_len != ctx->cipher_info->iv_size ) || ( tag_len != 16U ) ) { - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ; } *olen = ilen; @@ -1482,11 +1482,11 @@ static int mbedtls_cipher_aead_decrypt( mbedtls_cipher_context_t *ctx, if( ret == MBEDTLS_ERR_CHACHAPOLY_AUTH_FAILED ) ret = MBEDTLS_ERR_CIPHER_AUTH_FAILED; - return( ret ); + return ret ; } #endif /* MBEDTLS_CHACHAPOLY_C */ - return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ; } #endif /* MBEDTLS_CIPHER_MODE_AEAD */ @@ -1522,7 +1522,7 @@ int mbedtls_cipher_auth_encrypt_ext( mbedtls_cipher_context_t *ctx, /* There is no iv, tag or ad associated with KW and KWP, * so these length should be 0 as documented. */ if( iv_len != 0 || tag_len != 0 || ad_len != 0 ) - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ; (void) iv; (void) ad; @@ -1535,15 +1535,15 @@ int mbedtls_cipher_auth_encrypt_ext( mbedtls_cipher_context_t *ctx, #if defined(MBEDTLS_CIPHER_MODE_AEAD) /* AEAD case: check length before passing on to shared function */ if( output_len < ilen + tag_len ) - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ; int ret = mbedtls_cipher_aead_encrypt( ctx, iv, iv_len, ad, ad_len, input, ilen, output, olen, output + ilen, tag_len ); *olen += tag_len; - return( ret ); + return ret ; #else - return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ; #endif /* MBEDTLS_CIPHER_MODE_AEAD */ } @@ -1578,7 +1578,7 @@ int mbedtls_cipher_auth_decrypt_ext( mbedtls_cipher_context_t *ctx, /* There is no iv, tag or ad associated with KW and KWP, * so these length should be 0 as documented. */ if( iv_len != 0 || tag_len != 0 || ad_len != 0 ) - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ; (void) iv; (void) ad; @@ -1591,13 +1591,13 @@ int mbedtls_cipher_auth_decrypt_ext( mbedtls_cipher_context_t *ctx, #if defined(MBEDTLS_CIPHER_MODE_AEAD) /* AEAD case: check length before passing on to shared function */ if( ilen < tag_len || output_len < ilen - tag_len ) - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ; return( mbedtls_cipher_aead_decrypt( ctx, iv, iv_len, ad, ad_len, input, ilen - tag_len, output, olen, input + ilen - tag_len, tag_len ) ); #else - return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ; #endif /* MBEDTLS_CIPHER_MODE_AEAD */ } #endif /* MBEDTLS_CIPHER_MODE_AEAD || MBEDTLS_NIST_KW_C */ diff --git a/library/cipher_wrap.c b/library/cipher_wrap.c index 5776d5e45d..3c55045964 100644 --- a/library/cipher_wrap.c +++ b/library/cipher_wrap.c @@ -85,7 +85,7 @@ static void *gcm_ctx_alloc( void ) if( ctx != NULL ) mbedtls_gcm_init( (mbedtls_gcm_context *) ctx ); - return( ctx ); + return ctx ; } static void gcm_ctx_free( void *ctx ) @@ -104,7 +104,7 @@ static void *ccm_ctx_alloc( void ) if( ctx != NULL ) mbedtls_ccm_init( (mbedtls_ccm_context *) ctx ); - return( ctx ); + return ctx ; } static void ccm_ctx_free( void *ctx ) @@ -204,11 +204,11 @@ static void * aes_ctx_alloc( void ) mbedtls_aes_context *aes = mbedtls_calloc( 1, sizeof( mbedtls_aes_context ) ); if( aes == NULL ) - return( NULL ); + return NULL ; mbedtls_aes_init( aes ); - return( aes ); + return aes ; } static void aes_ctx_free( void *ctx ) @@ -422,14 +422,14 @@ static int xts_aes_setkey_enc_wrap( void *ctx, const unsigned char *key, unsigned int key_bitlen ) { mbedtls_aes_xts_context *xts_ctx = ctx; - return( mbedtls_aes_xts_setkey_enc( xts_ctx, key, key_bitlen ) ); + return mbedtls_aes_xts_setkey_enc( xts_ctx, key, key_bitlen ) ; } static int xts_aes_setkey_dec_wrap( void *ctx, const unsigned char *key, unsigned int key_bitlen ) { mbedtls_aes_xts_context *xts_ctx = ctx; - return( mbedtls_aes_xts_setkey_dec( xts_ctx, key, key_bitlen ) ); + return mbedtls_aes_xts_setkey_dec( xts_ctx, key, key_bitlen ) ; } static void *xts_aes_ctx_alloc( void ) @@ -439,7 +439,7 @@ static void *xts_aes_ctx_alloc( void ) if( xts_ctx != NULL ) mbedtls_aes_xts_init( xts_ctx ); - return( xts_ctx ); + return xts_ctx ; } static void xts_aes_ctx_free( void *ctx ) @@ -700,11 +700,11 @@ static void * camellia_ctx_alloc( void ) ctx = mbedtls_calloc( 1, sizeof( mbedtls_camellia_context ) ); if( ctx == NULL ) - return( NULL ); + return NULL ; mbedtls_camellia_init( ctx ); - return( ctx ); + return ctx ; } static void camellia_ctx_free( void *ctx ) @@ -1076,11 +1076,11 @@ static void * aria_ctx_alloc( void ) ctx = mbedtls_calloc( 1, sizeof( mbedtls_aria_context ) ); if( ctx == NULL ) - return( NULL ); + return NULL ; mbedtls_aria_init( ctx ); - return( ctx ); + return ctx ; } static void aria_ctx_free( void *ctx ) @@ -1481,11 +1481,11 @@ static void * des_ctx_alloc( void ) mbedtls_des_context *des = mbedtls_calloc( 1, sizeof( mbedtls_des_context ) ); if( des == NULL ) - return( NULL ); + return NULL ; mbedtls_des_init( des ); - return( des ); + return des ; } static void des_ctx_free( void *ctx ) @@ -1500,11 +1500,11 @@ static void * des3_ctx_alloc( void ) des3 = mbedtls_calloc( 1, sizeof( mbedtls_des3_context ) ); if( des3 == NULL ) - return( NULL ); + return NULL ; mbedtls_des3_init( des3 ); - return( des3 ); + return des3 ; } static void des3_ctx_free( void *ctx ) @@ -1672,12 +1672,12 @@ static int chacha20_setkey_wrap( void *ctx, const unsigned char *key, unsigned int key_bitlen ) { if( key_bitlen != 256U ) - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ; if ( 0 != mbedtls_chacha20_setkey( (mbedtls_chacha20_context*)ctx, key ) ) - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ; - return( 0 ); + return 0 ; } static int chacha20_stream_wrap( void *ctx, size_t length, @@ -1688,9 +1688,9 @@ static int chacha20_stream_wrap( void *ctx, size_t length, ret = mbedtls_chacha20_update( ctx, length, input, output ); if( ret == MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA ) - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ; - return( ret ); + return ret ; } static void * chacha20_ctx_alloc( void ) @@ -1699,11 +1699,11 @@ static void * chacha20_ctx_alloc( void ) ctx = mbedtls_calloc( 1, sizeof( mbedtls_chacha20_context ) ); if( ctx == NULL ) - return( NULL ); + return NULL ; mbedtls_chacha20_init( ctx ); - return( ctx ); + return ctx ; } static void chacha20_ctx_free( void *ctx ) @@ -1757,12 +1757,12 @@ static int chachapoly_setkey_wrap( void *ctx, unsigned int key_bitlen ) { if( key_bitlen != 256U ) - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ; if ( 0 != mbedtls_chachapoly_setkey( (mbedtls_chachapoly_context*)ctx, key ) ) - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ; - return( 0 ); + return 0 ; } static void * chachapoly_ctx_alloc( void ) @@ -1771,11 +1771,11 @@ static void * chachapoly_ctx_alloc( void ) ctx = mbedtls_calloc( 1, sizeof( mbedtls_chachapoly_context ) ); if( ctx == NULL ) - return( NULL ); + return NULL ; mbedtls_chachapoly_init( ctx ); - return( ctx ); + return ctx ; } static void chachapoly_ctx_free( void *ctx ) @@ -1829,7 +1829,7 @@ static int null_crypt_stream( void *ctx, size_t length, { ((void) ctx); memmove( output, input, length ); - return( 0 ); + return 0 ; } static int null_setkey( void *ctx, const unsigned char *key, @@ -1839,12 +1839,12 @@ static int null_setkey( void *ctx, const unsigned char *key, ((void) key); ((void) key_bitlen); - return( 0 ); + return 0 ; } static void * null_ctx_alloc( void ) { - return( (void *) 1 ); + return (void *) 1 ; } static void null_ctx_free( void *ctx ) @@ -1899,7 +1899,7 @@ static void *kw_ctx_alloc( void ) if( ctx != NULL ) mbedtls_nist_kw_init( (mbedtls_nist_kw_context *) ctx ); - return( ctx ); + return ctx ; } static void kw_ctx_free( void *ctx ) diff --git a/library/cmac.c b/library/cmac.c index 3cc49d10cc..1070b03055 100644 --- a/library/cmac.c +++ b/library/cmac.c @@ -83,7 +83,7 @@ static int cmac_multiply_by_u( unsigned char *output, } else { - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ; } for( i = (int)blocksize - 1; i >= 0; i-- ) @@ -108,7 +108,7 @@ static int cmac_multiply_by_u( unsigned char *output, output[ blocksize - 1 ] ^= R_n & mask; - return( 0 ); + return 0 ; } /* @@ -143,7 +143,7 @@ static int cmac_generate_subkeys( mbedtls_cipher_context_t *ctx, exit: mbedtls_platform_zeroize( L, sizeof( L ) ); - return( ret ); + return ret ; } #endif /* !defined(MBEDTLS_CMAC_ALT) || defined(MBEDTLS_SELF_TEST) */ @@ -190,11 +190,11 @@ int mbedtls_cipher_cmac_starts( mbedtls_cipher_context_t *ctx, int retval; if( ctx == NULL || ctx->cipher_info == NULL || key == NULL ) - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ; if( ( retval = mbedtls_cipher_setkey( ctx, key, (int)keybits, MBEDTLS_ENCRYPT ) ) != 0 ) - return( retval ); + return retval ; type = ctx->cipher_info->type; @@ -206,14 +206,14 @@ int mbedtls_cipher_cmac_starts( mbedtls_cipher_context_t *ctx, case MBEDTLS_CIPHER_DES_EDE3_ECB: break; default: - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ; } /* Allocated and initialise in the cipher context memory for the CMAC * context */ cmac_ctx = mbedtls_calloc( 1, sizeof( mbedtls_cmac_context_t ) ); if( cmac_ctx == NULL ) - return( MBEDTLS_ERR_CIPHER_ALLOC_FAILED ); + return MBEDTLS_ERR_CIPHER_ALLOC_FAILED ; ctx->cmac_ctx = cmac_ctx; @@ -232,7 +232,7 @@ int mbedtls_cipher_cmac_update( mbedtls_cipher_context_t *ctx, if( ctx == NULL || ctx->cipher_info == NULL || input == NULL || ctx->cmac_ctx == NULL ) - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ; cmac_ctx = ctx->cmac_ctx; block_size = ctx->cipher_info->block_size; @@ -287,7 +287,7 @@ int mbedtls_cipher_cmac_update( mbedtls_cipher_context_t *ctx, } exit: - return( ret ); + return ret ; } int mbedtls_cipher_cmac_finish( mbedtls_cipher_context_t *ctx, @@ -303,7 +303,7 @@ int mbedtls_cipher_cmac_finish( mbedtls_cipher_context_t *ctx, if( ctx == NULL || ctx->cipher_info == NULL || ctx->cmac_ctx == NULL || output == NULL ) - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ; cmac_ctx = ctx->cmac_ctx; block_size = ctx->cipher_info->block_size; @@ -348,7 +348,7 @@ exit: sizeof( cmac_ctx->unprocessed_block ) ); mbedtls_platform_zeroize( state, MBEDTLS_CIPHER_BLKSIZE_MAX ); - return( ret ); + return ret ; } int mbedtls_cipher_cmac_reset( mbedtls_cipher_context_t *ctx ) @@ -356,7 +356,7 @@ int mbedtls_cipher_cmac_reset( mbedtls_cipher_context_t *ctx ) mbedtls_cmac_context_t* cmac_ctx; if( ctx == NULL || ctx->cipher_info == NULL || ctx->cmac_ctx == NULL ) - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ; cmac_ctx = ctx->cmac_ctx; @@ -367,7 +367,7 @@ int mbedtls_cipher_cmac_reset( mbedtls_cipher_context_t *ctx ) mbedtls_platform_zeroize( cmac_ctx->state, sizeof( cmac_ctx->state ) ); - return( 0 ); + return 0 ; } int mbedtls_cipher_cmac( const mbedtls_cipher_info_t *cipher_info, @@ -379,7 +379,7 @@ int mbedtls_cipher_cmac( const mbedtls_cipher_info_t *cipher_info, int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; if( cipher_info == NULL || key == NULL || input == NULL || output == NULL ) - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ; mbedtls_cipher_init( &ctx ); @@ -399,7 +399,7 @@ int mbedtls_cipher_cmac( const mbedtls_cipher_info_t *cipher_info, exit: mbedtls_cipher_free( &ctx ); - return( ret ); + return ret ; } #if defined(MBEDTLS_AES_C) @@ -416,7 +416,7 @@ int mbedtls_aes_cmac_prf_128( const unsigned char *key, size_t key_length, unsigned char int_key[MBEDTLS_AES_BLOCK_SIZE]; if( key == NULL || input == NULL || output == NULL ) - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ; cipher_info = mbedtls_cipher_info_from_type( MBEDTLS_CIPHER_AES_128_ECB ); if( cipher_info == NULL ) @@ -447,7 +447,7 @@ int mbedtls_aes_cmac_prf_128( const unsigned char *key, size_t key_length, exit: mbedtls_platform_zeroize( int_key, sizeof( int_key ) ); - return( ret ); + return ret ; } #endif /* MBEDTLS_AES_C */ @@ -760,7 +760,7 @@ static int cmac_test_subkeys( int verbose, if( cipher_info == NULL ) { /* Failing at this point must be due to a build issue */ - return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ; } for( i = 0; i < num_tests; i++ ) @@ -831,7 +831,7 @@ cleanup: mbedtls_cipher_free( &ctx ); exit: - return( ret ); + return ret ; } static int cmac_test_wth_cipher( int verbose, @@ -896,7 +896,7 @@ static int cmac_test_wth_cipher( int verbose, ret = 0; exit: - return( ret ); + return ret ; } #if defined(MBEDTLS_AES_C) @@ -917,14 +917,14 @@ static int test_aes128_cmac_prf( int verbose ) if( verbose != 0 ) mbedtls_printf( "failed\n" ); - return( ret ); + return ret ; } else if( verbose != 0 ) { mbedtls_printf( "passed\n" ); } } - return( ret ); + return ret ; } #endif /* MBEDTLS_AES_C */ @@ -943,7 +943,7 @@ int mbedtls_cmac_self_test( int verbose ) MBEDTLS_AES_BLOCK_SIZE, NB_CMAC_TESTS_PER_KEY ) ) != 0 ) { - return( ret ); + return ret ; } if( ( ret = cmac_test_wth_cipher( verbose, @@ -957,7 +957,7 @@ int mbedtls_cmac_self_test( int verbose ) MBEDTLS_AES_BLOCK_SIZE, NB_CMAC_TESTS_PER_KEY ) ) != 0 ) { - return( ret ); + return ret ; } /* AES-192 */ @@ -970,7 +970,7 @@ int mbedtls_cmac_self_test( int verbose ) MBEDTLS_AES_BLOCK_SIZE, NB_CMAC_TESTS_PER_KEY ) ) != 0 ) { - return( ret ); + return ret ; } if( ( ret = cmac_test_wth_cipher( verbose, @@ -984,7 +984,7 @@ int mbedtls_cmac_self_test( int verbose ) MBEDTLS_AES_BLOCK_SIZE, NB_CMAC_TESTS_PER_KEY ) ) != 0 ) { - return( ret ); + return ret ; } /* AES-256 */ @@ -997,7 +997,7 @@ int mbedtls_cmac_self_test( int verbose ) MBEDTLS_AES_BLOCK_SIZE, NB_CMAC_TESTS_PER_KEY ) ) != 0 ) { - return( ret ); + return ret ; } if( ( ret = cmac_test_wth_cipher ( verbose, @@ -1011,7 +1011,7 @@ int mbedtls_cmac_self_test( int verbose ) MBEDTLS_AES_BLOCK_SIZE, NB_CMAC_TESTS_PER_KEY ) ) != 0 ) { - return( ret ); + return ret ; } #endif /* MBEDTLS_AES_C */ @@ -1026,7 +1026,7 @@ int mbedtls_cmac_self_test( int verbose ) MBEDTLS_DES3_BLOCK_SIZE, NB_CMAC_TESTS_PER_KEY ) ) != 0 ) { - return( ret ); + return ret ; } if( ( ret = cmac_test_wth_cipher( verbose, @@ -1040,7 +1040,7 @@ int mbedtls_cmac_self_test( int verbose ) MBEDTLS_DES3_BLOCK_SIZE, NB_CMAC_TESTS_PER_KEY ) ) != 0 ) { - return( ret ); + return ret ; } /* 3DES 3 key */ @@ -1053,7 +1053,7 @@ int mbedtls_cmac_self_test( int verbose ) MBEDTLS_DES3_BLOCK_SIZE, NB_CMAC_TESTS_PER_KEY ) ) != 0 ) { - return( ret ); + return ret ; } if( ( ret = cmac_test_wth_cipher( verbose, @@ -1067,19 +1067,19 @@ int mbedtls_cmac_self_test( int verbose ) MBEDTLS_DES3_BLOCK_SIZE, NB_CMAC_TESTS_PER_KEY ) ) != 0 ) { - return( ret ); + return ret ; } #endif /* MBEDTLS_DES_C */ #if defined(MBEDTLS_AES_C) if( ( ret = test_aes128_cmac_prf( verbose ) ) != 0 ) - return( ret ); + return ret ; #endif /* MBEDTLS_AES_C */ if( verbose != 0 ) mbedtls_printf( "\n" ); - return( 0 ); + return 0 ; } #endif /* MBEDTLS_SELF_TEST */ diff --git a/library/ctr_drbg.c b/library/ctr_drbg.c index b664fb0fc7..59275145b8 100644 --- a/library/ctr_drbg.c +++ b/library/ctr_drbg.c @@ -96,16 +96,16 @@ int mbedtls_ctr_drbg_set_nonce_len( mbedtls_ctr_drbg_context *ctx, /* If mbedtls_ctr_drbg_seed() has already been called, it's * too late. Return the error code that's closest to making sense. */ if( ctx->f_entropy != NULL ) - return( MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED ); + return MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED ; if( len > MBEDTLS_CTR_DRBG_MAX_SEED_INPUT ) - return( MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG ); + return MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG ; #if SIZE_MAX > INT_MAX /* This shouldn't be an issue because * MBEDTLS_CTR_DRBG_MAX_SEED_INPUT < INT_MAX in any sensible * configuration, but make sure anyway. */ if( len > INT_MAX ) - return( MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG ); + return MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG ; #endif /* For backward compatibility with Mbed TLS <= 2.19, store the @@ -113,7 +113,7 @@ int mbedtls_ctr_drbg_set_nonce_len( mbedtls_ctr_drbg_context *ctx, * used until after the initial seeding. */ /* Due to the capping of len above, the value fits in an int. */ ctx->reseed_counter = (int) len; - return( 0 ); + return 0 ; } void mbedtls_ctr_drbg_set_reseed_interval( mbedtls_ctr_drbg_context *ctx, @@ -138,7 +138,7 @@ static int block_cipher_df( unsigned char *output, size_t buf_len, use_len; if( data_len > MBEDTLS_CTR_DRBG_MAX_SEED_INPUT ) - return( MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG ); + return MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG ; memset( buf, 0, MBEDTLS_CTR_DRBG_MAX_SEED_INPUT + MBEDTLS_CTR_DRBG_BLOCKSIZE + 16 ); @@ -242,7 +242,7 @@ exit: mbedtls_platform_zeroize( output, MBEDTLS_CTR_DRBG_SEEDLEN ); } - return( ret ); + return ret ; } /* CTR_DRBG_Update (SP 800-90A §10.2.1.2) @@ -300,7 +300,7 @@ static int ctr_drbg_update_internal( mbedtls_ctr_drbg_context *ctx, exit: mbedtls_platform_zeroize( tmp, sizeof( tmp ) ); - return( ret ); + return ret ; } /* CTR_DRBG_Instantiate with derivation function (SP 800-90A §10.2.1.3.2) @@ -323,7 +323,7 @@ int mbedtls_ctr_drbg_update( mbedtls_ctr_drbg_context *ctx, int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; if( add_len == 0 ) - return( 0 ); + return 0 ; if( ( ret = block_cipher_df( add_input, additional, add_len ) ) != 0 ) goto exit; @@ -332,7 +332,7 @@ int mbedtls_ctr_drbg_update( mbedtls_ctr_drbg_context *ctx, exit: mbedtls_platform_zeroize( add_input, sizeof( add_input ) ); - return( ret ); + return ret ; } /* CTR_DRBG_Reseed with derivation function (SP 800-90A §10.2.1.4.2) @@ -358,18 +358,18 @@ static int mbedtls_ctr_drbg_reseed_internal( mbedtls_ctr_drbg_context *ctx, int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; if( ctx->entropy_len > MBEDTLS_CTR_DRBG_MAX_SEED_INPUT ) - return( MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG ); + return MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG ; if( nonce_len > MBEDTLS_CTR_DRBG_MAX_SEED_INPUT - ctx->entropy_len ) - return( MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG ); + return MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG ; if( len > MBEDTLS_CTR_DRBG_MAX_SEED_INPUT - ctx->entropy_len - nonce_len ) - return( MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG ); + return MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG ; memset( seed, 0, MBEDTLS_CTR_DRBG_MAX_SEED_INPUT ); /* Gather entropy_len bytes of entropy to seed state. */ if( 0 != ctx->f_entropy( ctx->p_entropy, seed, ctx->entropy_len ) ) { - return( MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED ); + return MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED ; } seedlen += ctx->entropy_len; @@ -378,7 +378,7 @@ static int mbedtls_ctr_drbg_reseed_internal( mbedtls_ctr_drbg_context *ctx, { if( 0 != ctx->f_entropy( ctx->p_entropy, seed + seedlen, nonce_len ) ) { - return( MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED ); + return MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED ; } seedlen += nonce_len; } @@ -401,13 +401,13 @@ static int mbedtls_ctr_drbg_reseed_internal( mbedtls_ctr_drbg_context *ctx, exit: mbedtls_platform_zeroize( seed, sizeof( seed ) ); - return( ret ); + return ret ; } int mbedtls_ctr_drbg_reseed( mbedtls_ctr_drbg_context *ctx, const unsigned char *additional, size_t len ) { - return( mbedtls_ctr_drbg_reseed_internal( ctx, additional, len, 0 ) ); + return mbedtls_ctr_drbg_reseed_internal( ctx, additional, len, 0 ) ; } /* Return a "good" nonce length for CTR_DRBG. The chosen nonce length @@ -418,9 +418,9 @@ int mbedtls_ctr_drbg_reseed( mbedtls_ctr_drbg_context *ctx, static size_t good_nonce_len( size_t entropy_len ) { if( entropy_len >= MBEDTLS_CTR_DRBG_KEYSIZE * 3 / 2 ) - return( 0 ); + return 0 ; else - return( ( entropy_len + 1 ) / 2 ); + return ( entropy_len + 1 ) / 2 ; } /* CTR_DRBG_Instantiate with derivation function (SP 800-90A §10.2.1.3.2) @@ -470,16 +470,16 @@ int mbedtls_ctr_drbg_seed( mbedtls_ctr_drbg_context *ctx, if( ( ret = mbedtls_aes_setkey_enc( &ctx->aes_ctx, key, MBEDTLS_CTR_DRBG_KEYBITS ) ) != 0 ) { - return( ret ); + return ret ; } /* Do the initial seeding. */ if( ( ret = mbedtls_ctr_drbg_reseed_internal( ctx, custom, len, nonce_len ) ) != 0 ) { - return( ret ); + return ret ; } - return( 0 ); + return 0 ; } /* CTR_DRBG_Generate with derivation function (SP 800-90A §10.2.1.5.2) @@ -514,10 +514,10 @@ int mbedtls_ctr_drbg_random_with_add( void *p_rng, size_t use_len; if( output_len > MBEDTLS_CTR_DRBG_MAX_REQUEST ) - return( MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG ); + return MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG ; if( add_len > MBEDTLS_CTR_DRBG_MAX_INPUT ) - return( MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG ); + return MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG ; memset( add_input, 0, MBEDTLS_CTR_DRBG_SEEDLEN ); @@ -526,7 +526,7 @@ int mbedtls_ctr_drbg_random_with_add( void *p_rng, { if( ( ret = mbedtls_ctr_drbg_reseed( ctx, additional, add_len ) ) != 0 ) { - return( ret ); + return ret ; } add_len = 0; } @@ -575,7 +575,7 @@ int mbedtls_ctr_drbg_random_with_add( void *p_rng, exit: mbedtls_platform_zeroize( add_input, sizeof( add_input ) ); mbedtls_platform_zeroize( tmp, sizeof( tmp ) ); - return( ret ); + return ret ; } int mbedtls_ctr_drbg_random( void *p_rng, unsigned char *output, @@ -586,17 +586,17 @@ int mbedtls_ctr_drbg_random( void *p_rng, unsigned char *output, #if defined(MBEDTLS_THREADING_C) if( ( ret = mbedtls_mutex_lock( &ctx->mutex ) ) != 0 ) - return( ret ); + return ret ; #endif ret = mbedtls_ctr_drbg_random_with_add( ctx, output, output_len, NULL, 0 ); #if defined(MBEDTLS_THREADING_C) if( mbedtls_mutex_unlock( &ctx->mutex ) != 0 ) - return( MBEDTLS_ERR_THREADING_MUTEX_ERROR ); + return MBEDTLS_ERR_THREADING_MUTEX_ERROR ; #endif - return( ret ); + return ret ; } #if defined(MBEDTLS_FS_IO) @@ -608,7 +608,7 @@ int mbedtls_ctr_drbg_write_seed_file( mbedtls_ctr_drbg_context *ctx, unsigned char buf[ MBEDTLS_CTR_DRBG_MAX_INPUT ]; if( ( f = fopen( path, "wb" ) ) == NULL ) - return( MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR ); + return MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR ; if( ( ret = mbedtls_ctr_drbg_random( ctx, buf, MBEDTLS_CTR_DRBG_MAX_INPUT ) ) != 0 ) @@ -628,7 +628,7 @@ exit: mbedtls_platform_zeroize( buf, sizeof( buf ) ); fclose( f ); - return( ret ); + return ret ; } int mbedtls_ctr_drbg_update_seed_file( mbedtls_ctr_drbg_context *ctx, @@ -641,7 +641,7 @@ int mbedtls_ctr_drbg_update_seed_file( mbedtls_ctr_drbg_context *ctx, unsigned char c; if( ( f = fopen( path, "rb" ) ) == NULL ) - return( MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR ); + return MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR ; n = fread( buf, 1, sizeof( buf ), f ); if( fread( &c, 1, 1, f ) != 0 ) @@ -664,8 +664,8 @@ exit: if( f != NULL ) fclose( f ); if( ret != 0 ) - return( ret ); - return( mbedtls_ctr_drbg_write_seed_file( ctx, path ) ); + return ret ; + return mbedtls_ctr_drbg_write_seed_file( ctx, path ) ; } #endif /* MBEDTLS_FS_IO */ @@ -808,14 +808,14 @@ static int ctr_drbg_self_test_entropy( void *data, unsigned char *buf, const unsigned char *p = data; memcpy( buf, p + test_offset, len ); test_offset += len; - return( 0 ); + return 0 ; } #define CHK( c ) if( (c) != 0 ) \ { \ if( verbose != 0 ) \ mbedtls_printf( "failed\n" ); \ - return( 1 ); \ + return 1 ; \ } #define SELF_TEST_OUPUT_DISCARD_LENGTH 64 @@ -881,7 +881,7 @@ int mbedtls_ctr_drbg_self_test( int verbose ) if( verbose != 0 ) mbedtls_printf( "\n" ); - return( 0 ); + return 0 ; } #endif /* MBEDTLS_SELF_TEST */ diff --git a/library/des.c b/library/des.c index eddf55e789..9908582337 100644 --- a/library/des.c +++ b/library/des.c @@ -357,9 +357,9 @@ int mbedtls_des_key_check_key_parity( const unsigned char key[MBEDTLS_DES_KEY_SI for( i = 0; i < MBEDTLS_DES_KEY_SIZE; i++ ) if( key[i] != odd_parity_table[key[i] / 2] ) - return( 1 ); + return 1 ; - return( 0 ); + return 0 ; } /* @@ -412,9 +412,9 @@ int mbedtls_des_key_check_weak( const unsigned char key[MBEDTLS_DES_KEY_SIZE] ) for( i = 0; i < WEAK_KEY_COUNT; i++ ) if( memcmp( weak_key_table[i], key, MBEDTLS_DES_KEY_SIZE) == 0 ) - return( 1 ); + return 1 ; - return( 0 ); + return 0 ; } #if !defined(MBEDTLS_DES_SETKEY_ALT) @@ -495,7 +495,7 @@ int mbedtls_des_setkey_enc( mbedtls_des_context *ctx, const unsigned char key[MB { mbedtls_des_setkey( ctx->sk, key ); - return( 0 ); + return 0 ; } /* @@ -513,7 +513,7 @@ int mbedtls_des_setkey_dec( mbedtls_des_context *ctx, const unsigned char key[MB SWAP( ctx->sk[i + 1], ctx->sk[31 - i] ); } - return( 0 ); + return 0 ; } static void des3_set2key( uint32_t esk[96], @@ -552,7 +552,7 @@ int mbedtls_des3_set2key_enc( mbedtls_des3_context *ctx, des3_set2key( ctx->sk, sk, key ); mbedtls_platform_zeroize( sk, sizeof( sk ) ); - return( 0 ); + return 0 ; } /* @@ -566,7 +566,7 @@ int mbedtls_des3_set2key_dec( mbedtls_des3_context *ctx, des3_set2key( sk, ctx->sk, key ); mbedtls_platform_zeroize( sk, sizeof( sk ) ); - return( 0 ); + return 0 ; } static void des3_set3key( uint32_t esk[96], @@ -603,7 +603,7 @@ int mbedtls_des3_set3key_enc( mbedtls_des3_context *ctx, des3_set3key( ctx->sk, sk, key ); mbedtls_platform_zeroize( sk, sizeof( sk ) ); - return( 0 ); + return 0 ; } /* @@ -617,7 +617,7 @@ int mbedtls_des3_set3key_dec( mbedtls_des3_context *ctx, des3_set3key( sk, ctx->sk, key ); mbedtls_platform_zeroize( sk, sizeof( sk ) ); - return( 0 ); + return 0 ; } /* @@ -649,7 +649,7 @@ int mbedtls_des_crypt_ecb( mbedtls_des_context *ctx, PUT_UINT32_BE( Y, output, 0 ); PUT_UINT32_BE( X, output, 4 ); - return( 0 ); + return 0 ; } #endif /* !MBEDTLS_DES_CRYPT_ECB_ALT */ @@ -668,7 +668,7 @@ int mbedtls_des_crypt_cbc( mbedtls_des_context *ctx, unsigned char temp[8]; if( length % 8 ) - return( MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH ); + return MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH ; if( mode == MBEDTLS_DES_ENCRYPT ) { @@ -703,7 +703,7 @@ int mbedtls_des_crypt_cbc( mbedtls_des_context *ctx, } } - return( 0 ); + return 0 ; } #endif /* MBEDTLS_CIPHER_MODE_CBC */ @@ -748,7 +748,7 @@ int mbedtls_des3_crypt_ecb( mbedtls_des3_context *ctx, PUT_UINT32_BE( Y, output, 0 ); PUT_UINT32_BE( X, output, 4 ); - return( 0 ); + return 0 ; } #endif /* !MBEDTLS_DES3_CRYPT_ECB_ALT */ @@ -767,7 +767,7 @@ int mbedtls_des3_crypt_cbc( mbedtls_des3_context *ctx, unsigned char temp[8]; if( length % 8 ) - return( MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH ); + return MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH ; if( mode == MBEDTLS_DES_ENCRYPT ) { @@ -802,7 +802,7 @@ int mbedtls_des3_crypt_cbc( mbedtls_des3_context *ctx, } } - return( 0 ); + return 0 ; } #endif /* MBEDTLS_CIPHER_MODE_CBC */ @@ -919,7 +919,7 @@ int mbedtls_des_self_test( int verbose ) break; default: - return( 1 ); + return 1 ; } for( j = 0; j < 100; j++ ) @@ -994,7 +994,7 @@ int mbedtls_des_self_test( int verbose ) break; default: - return( 1 ); + return 1 ; } if( v == MBEDTLS_DES_DECRYPT ) @@ -1050,7 +1050,7 @@ exit: mbedtls_des_free( &ctx ); mbedtls_des3_free( &ctx3 ); - return( ret ); + return ret ; } #endif /* MBEDTLS_SELF_TEST */ diff --git a/library/dhm.c b/library/dhm.c index 29ce75598c..322119555d 100644 --- a/library/dhm.c +++ b/library/dhm.c @@ -70,20 +70,20 @@ static int dhm_read_bignum( mbedtls_mpi *X, int ret, n; if( end - *p < 2 ) - return( MBEDTLS_ERR_DHM_BAD_INPUT_DATA ); + return MBEDTLS_ERR_DHM_BAD_INPUT_DATA ; n = ( (*p)[0] << 8 ) | (*p)[1]; (*p) += 2; if( (int)( end - *p ) < n ) - return( MBEDTLS_ERR_DHM_BAD_INPUT_DATA ); + return MBEDTLS_ERR_DHM_BAD_INPUT_DATA ; if( ( ret = mbedtls_mpi_read_binary( X, *p, n ) ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_DHM_READ_PARAMS_FAILED, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_DHM_READ_PARAMS_FAILED, ret ) ; (*p) += n; - return( 0 ); + return 0 ; } /* @@ -115,7 +115,7 @@ static int dhm_check_range( const mbedtls_mpi *param, const mbedtls_mpi *P ) cleanup: mbedtls_mpi_free( &U ); - return( ret ); + return ret ; } void mbedtls_dhm_init( mbedtls_dhm_context *ctx ) @@ -126,12 +126,12 @@ void mbedtls_dhm_init( mbedtls_dhm_context *ctx ) size_t mbedtls_dhm_get_bitlen( const mbedtls_dhm_context *ctx ) { - return( mbedtls_mpi_bitlen( &ctx->P ) ); + return mbedtls_mpi_bitlen( &ctx->P ) ; } size_t mbedtls_dhm_get_len( const mbedtls_dhm_context *ctx ) { - return( mbedtls_mpi_size( &ctx->P ) ); + return mbedtls_mpi_size( &ctx->P ) ; } int mbedtls_dhm_get_value( const mbedtls_dhm_context *ctx, @@ -160,9 +160,9 @@ int mbedtls_dhm_get_value( const mbedtls_dhm_context *ctx, src = &ctx->K; break; default: - return( MBEDTLS_ERR_DHM_BAD_INPUT_DATA ); + return MBEDTLS_ERR_DHM_BAD_INPUT_DATA ; } - return( mbedtls_mpi_copy( dest, src ) ); + return mbedtls_mpi_copy( dest, src ) ; } /* @@ -180,12 +180,12 @@ int mbedtls_dhm_read_params( mbedtls_dhm_context *ctx, if( ( ret = dhm_read_bignum( &ctx->P, p, end ) ) != 0 || ( ret = dhm_read_bignum( &ctx->G, p, end ) ) != 0 || ( ret = dhm_read_bignum( &ctx->GY, p, end ) ) != 0 ) - return( ret ); + return ret ; if( ( ret = dhm_check_range( &ctx->GY, &ctx->P ) ) != 0 ) - return( ret ); + return ret ; - return( 0 ); + return 0 ; } /* @@ -200,7 +200,7 @@ static int dhm_random_below( mbedtls_mpi *R, const mbedtls_mpi *M, MBEDTLS_MPI_CHK( mbedtls_mpi_sub_int( R, R, 1 ) ); cleanup: - return( ret ); + return ret ; } static int dhm_make_common( mbedtls_dhm_context *ctx, int x_size, @@ -210,9 +210,9 @@ static int dhm_make_common( mbedtls_dhm_context *ctx, int x_size, int ret = 0; if( mbedtls_mpi_cmp_int( &ctx->P, 0 ) == 0 ) - return( MBEDTLS_ERR_DHM_BAD_INPUT_DATA ); + return MBEDTLS_ERR_DHM_BAD_INPUT_DATA ; if( x_size < 0 ) - return( MBEDTLS_ERR_DHM_BAD_INPUT_DATA ); + return MBEDTLS_ERR_DHM_BAD_INPUT_DATA ; if( (unsigned) x_size < mbedtls_mpi_size( &ctx->P ) ) { @@ -223,9 +223,9 @@ static int dhm_make_common( mbedtls_dhm_context *ctx, int x_size, /* Generate X as large as possible ( <= P - 2 ) */ ret = dhm_random_below( &ctx->X, &ctx->P, f_rng, p_rng ); if( ret == MBEDTLS_ERR_MPI_NOT_ACCEPTABLE ) - return( MBEDTLS_ERR_DHM_MAKE_PARAMS_FAILED ); + return MBEDTLS_ERR_DHM_MAKE_PARAMS_FAILED ; if( ret != 0 ) - return( ret ); + return ret ; } /* @@ -235,10 +235,10 @@ static int dhm_make_common( mbedtls_dhm_context *ctx, int x_size, &ctx->P , &ctx->RP ) ); if( ( ret = dhm_check_range( &ctx->GX, &ctx->P ) ) != 0 ) - return( ret ); + return ret ; cleanup: - return( ret ); + return ret ; } /* @@ -289,7 +289,7 @@ int mbedtls_dhm_make_params( mbedtls_dhm_context *ctx, int x_size, cleanup: if( ret != 0 && ret > -128 ) ret = MBEDTLS_ERROR_ADD( MBEDTLS_ERR_DHM_MAKE_PARAMS_FAILED, ret ); - return( ret ); + return ret ; } /* @@ -307,10 +307,10 @@ int mbedtls_dhm_set_group( mbedtls_dhm_context *ctx, if( ( ret = mbedtls_mpi_copy( &ctx->P, P ) ) != 0 || ( ret = mbedtls_mpi_copy( &ctx->G, G ) ) != 0 ) { - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_DHM_SET_GROUP_FAILED, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_DHM_SET_GROUP_FAILED, ret ) ; } - return( 0 ); + return 0 ; } /* @@ -324,12 +324,12 @@ int mbedtls_dhm_read_public( mbedtls_dhm_context *ctx, DHM_VALIDATE_RET( input != NULL ); if( ilen < 1 || ilen > mbedtls_dhm_get_len( ctx ) ) - return( MBEDTLS_ERR_DHM_BAD_INPUT_DATA ); + return MBEDTLS_ERR_DHM_BAD_INPUT_DATA ; if( ( ret = mbedtls_mpi_read_binary( &ctx->GY, input, ilen ) ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_DHM_READ_PUBLIC_FAILED, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_DHM_READ_PUBLIC_FAILED, ret ) ; - return( 0 ); + return 0 ; } /* @@ -346,11 +346,11 @@ int mbedtls_dhm_make_public( mbedtls_dhm_context *ctx, int x_size, DHM_VALIDATE_RET( f_rng != NULL ); if( olen < 1 || olen > mbedtls_dhm_get_len( ctx ) ) - return( MBEDTLS_ERR_DHM_BAD_INPUT_DATA ); + return MBEDTLS_ERR_DHM_BAD_INPUT_DATA ; ret = dhm_make_common( ctx, x_size, f_rng, p_rng ); if( ret == MBEDTLS_ERR_DHM_MAKE_PARAMS_FAILED ) - return( MBEDTLS_ERR_DHM_MAKE_PUBLIC_FAILED ); + return MBEDTLS_ERR_DHM_MAKE_PUBLIC_FAILED ; if( ret != 0 ) goto cleanup; @@ -359,7 +359,7 @@ int mbedtls_dhm_make_public( mbedtls_dhm_context *ctx, int x_size, cleanup: if( ret != 0 && ret > -128 ) ret = MBEDTLS_ERROR_ADD( MBEDTLS_ERR_DHM_MAKE_PUBLIC_FAILED, ret ); - return( ret ); + return ret ; } @@ -387,7 +387,7 @@ static int dhm_update_blinding( mbedtls_dhm_context *ctx, MBEDTLS_MPI_CHK( mbedtls_mpi_lset( &ctx->Vi, 1 ) ); MBEDTLS_MPI_CHK( mbedtls_mpi_lset( &ctx->Vf, 1 ) ); - return( 0 ); + return 0 ; } /* @@ -402,7 +402,7 @@ static int dhm_update_blinding( mbedtls_dhm_context *ctx, MBEDTLS_MPI_CHK( mbedtls_mpi_mul_mpi( &ctx->Vf, &ctx->Vf, &ctx->Vf ) ); MBEDTLS_MPI_CHK( mbedtls_mpi_mod_mpi( &ctx->Vf, &ctx->Vf, &ctx->P ) ); - return( 0 ); + return 0 ; } /* @@ -427,7 +427,7 @@ static int dhm_update_blinding( mbedtls_dhm_context *ctx, cleanup: mbedtls_mpi_free( &R ); - return( ret ); + return ret ; } /* @@ -445,13 +445,13 @@ int mbedtls_dhm_calc_secret( mbedtls_dhm_context *ctx, DHM_VALIDATE_RET( olen != NULL ); if( f_rng == NULL ) - return( MBEDTLS_ERR_DHM_BAD_INPUT_DATA ); + return MBEDTLS_ERR_DHM_BAD_INPUT_DATA ; if( output_size < mbedtls_dhm_get_len( ctx ) ) - return( MBEDTLS_ERR_DHM_BAD_INPUT_DATA ); + return MBEDTLS_ERR_DHM_BAD_INPUT_DATA ; if( ( ret = dhm_check_range( &ctx->GY, &ctx->P ) ) != 0 ) - return( ret ); + return ret ; mbedtls_mpi_init( &GYb ); @@ -477,9 +477,9 @@ cleanup: mbedtls_mpi_free( &GYb ); if( ret != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_DHM_CALC_SECRET_FAILED, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_DHM_CALC_SECRET_FAILED, ret ) ; - return( 0 ); + return 0 ; } /* @@ -602,7 +602,7 @@ exit: if( ret != 0 ) mbedtls_dhm_free( dhm ); - return( ret ); + return ret ; } #if defined(MBEDTLS_FS_IO) @@ -619,13 +619,13 @@ static int load_file( const char *path, unsigned char **buf, size_t *n ) long size; if( ( f = fopen( path, "rb" ) ) == NULL ) - return( MBEDTLS_ERR_DHM_FILE_IO_ERROR ); + return MBEDTLS_ERR_DHM_FILE_IO_ERROR ; fseek( f, 0, SEEK_END ); if( ( size = ftell( f ) ) == -1 ) { fclose( f ); - return( MBEDTLS_ERR_DHM_FILE_IO_ERROR ); + return MBEDTLS_ERR_DHM_FILE_IO_ERROR ; } fseek( f, 0, SEEK_SET ); @@ -635,7 +635,7 @@ static int load_file( const char *path, unsigned char **buf, size_t *n ) ( *buf = mbedtls_calloc( 1, *n + 1 ) ) == NULL ) { fclose( f ); - return( MBEDTLS_ERR_DHM_ALLOC_FAILED ); + return MBEDTLS_ERR_DHM_ALLOC_FAILED ; } if( fread( *buf, 1, *n, f ) != *n ) @@ -645,7 +645,7 @@ static int load_file( const char *path, unsigned char **buf, size_t *n ) mbedtls_platform_zeroize( *buf, *n + 1 ); mbedtls_free( *buf ); - return( MBEDTLS_ERR_DHM_FILE_IO_ERROR ); + return MBEDTLS_ERR_DHM_FILE_IO_ERROR ; } fclose( f ); @@ -655,7 +655,7 @@ static int load_file( const char *path, unsigned char **buf, size_t *n ) if( strstr( (const char *) *buf, "-----BEGIN " ) != NULL ) ++*n; - return( 0 ); + return 0 ; } /* @@ -670,14 +670,14 @@ int mbedtls_dhm_parse_dhmfile( mbedtls_dhm_context *dhm, const char *path ) DHM_VALIDATE_RET( path != NULL ); if( ( ret = load_file( path, &buf, &n ) ) != 0 ) - return( ret ); + return ret ; ret = mbedtls_dhm_parse_dhm( dhm, buf, n ); mbedtls_platform_zeroize( buf, n ); mbedtls_free( buf ); - return( ret ); + return ret ; } #endif /* MBEDTLS_FS_IO */ #endif /* MBEDTLS_ASN1_PARSE_C */ @@ -740,7 +740,7 @@ int mbedtls_dhm_self_test( int verbose ) exit: mbedtls_dhm_free( &dhm ); - return( ret ); + return ret ; } #endif /* MBEDTLS_SELF_TEST */ diff --git a/library/ecdh.c b/library/ecdh.c index 9dfa868063..b578db5a1c 100644 --- a/library/ecdh.c +++ b/library/ecdh.c @@ -48,9 +48,9 @@ static mbedtls_ecp_group_id mbedtls_ecdh_grp_id( const mbedtls_ecdh_context *ctx ) { #if defined(MBEDTLS_ECDH_LEGACY_CONTEXT) - return( ctx->grp.id ); + return ctx->grp.id ; #else - return( ctx->grp_id ); + return ctx->grp_id ; #endif } @@ -58,7 +58,7 @@ int mbedtls_ecdh_can_do( mbedtls_ecp_group_id gid ) { /* At this time, all groups support ECDH. */ (void) gid; - return( 1 ); + return 1 ; } #if !defined(MBEDTLS_ECDH_GEN_PUBLIC_ALT) @@ -87,7 +87,7 @@ static int ecdh_gen_public_restartable( mbedtls_ecp_group *grp, f_rng, p_rng, rs_ctx ) ); cleanup: - return( ret ); + return ret ; } /* @@ -101,7 +101,7 @@ int mbedtls_ecdh_gen_public( mbedtls_ecp_group *grp, mbedtls_mpi *d, mbedtls_ecp ECDH_VALIDATE_RET( d != NULL ); ECDH_VALIDATE_RET( Q != NULL ); ECDH_VALIDATE_RET( f_rng != NULL ); - return( ecdh_gen_public_restartable( grp, d, Q, f_rng, p_rng, NULL ) ); + return ecdh_gen_public_restartable( grp, d, Q, f_rng, p_rng, NULL ) ; } #endif /* !MBEDTLS_ECDH_GEN_PUBLIC_ALT */ @@ -135,7 +135,7 @@ static int ecdh_compute_shared_restartable( mbedtls_ecp_group *grp, cleanup: mbedtls_ecp_point_free( &P ); - return( ret ); + return ret ; } /* @@ -199,10 +199,10 @@ static int ecdh_setup_internal( mbedtls_ecdh_context_mbed *ctx, ret = mbedtls_ecp_group_load( &ctx->grp, grp_id ); if( ret != 0 ) { - return( MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE ; } - return( 0 ); + return 0 ; } /* @@ -213,7 +213,7 @@ int mbedtls_ecdh_setup( mbedtls_ecdh_context *ctx, mbedtls_ecp_group_id grp_id ) ECDH_VALIDATE_RET( ctx != NULL ); #if defined(MBEDTLS_ECDH_LEGACY_CONTEXT) - return( ecdh_setup_internal( ctx, grp_id ) ); + return ecdh_setup_internal( ctx, grp_id ) ; #else switch( grp_id ) { @@ -222,14 +222,14 @@ int mbedtls_ecdh_setup( mbedtls_ecdh_context *ctx, mbedtls_ecp_group_id grp_id ) ctx->point_format = MBEDTLS_ECP_PF_COMPRESSED; ctx->var = MBEDTLS_ECDH_VARIANT_EVEREST; ctx->grp_id = grp_id; - return( mbedtls_everest_setup( &ctx->ctx.everest_ecdh, grp_id ) ); + return mbedtls_everest_setup( &ctx->ctx.everest_ecdh, grp_id ) ; #endif default: ctx->point_format = MBEDTLS_ECP_PF_UNCOMPRESSED; ctx->var = MBEDTLS_ECDH_VARIANT_MBEDTLS_2_0; ctx->grp_id = grp_id; ecdh_init_internal( &ctx->ctx.mbed_ecdh ); - return( ecdh_setup_internal( &ctx->ctx.mbed_ecdh, grp_id ) ); + return ecdh_setup_internal( &ctx->ctx.mbed_ecdh, grp_id ) ; } #endif } @@ -309,7 +309,7 @@ static int ecdh_make_params_internal( mbedtls_ecdh_context_mbed *ctx, #endif if( ctx->grp.pbits == 0 ) - return( MBEDTLS_ERR_ECP_BAD_INPUT_DATA ); + return MBEDTLS_ERR_ECP_BAD_INPUT_DATA ; #if defined(MBEDTLS_ECP_RESTARTABLE) if( restart_enabled ) @@ -322,26 +322,26 @@ static int ecdh_make_params_internal( mbedtls_ecdh_context_mbed *ctx, #if defined(MBEDTLS_ECP_RESTARTABLE) if( ( ret = ecdh_gen_public_restartable( &ctx->grp, &ctx->d, &ctx->Q, f_rng, p_rng, rs_ctx ) ) != 0 ) - return( ret ); + return ret ; #else if( ( ret = mbedtls_ecdh_gen_public( &ctx->grp, &ctx->d, &ctx->Q, f_rng, p_rng ) ) != 0 ) - return( ret ); + return ret ; #endif /* MBEDTLS_ECP_RESTARTABLE */ if( ( ret = mbedtls_ecp_tls_write_group( &ctx->grp, &grp_len, buf, blen ) ) != 0 ) - return( ret ); + return ret ; buf += grp_len; blen -= grp_len; if( ( ret = mbedtls_ecp_tls_write_point( &ctx->grp, &ctx->Q, point_format, &pt_len, buf, blen ) ) != 0 ) - return( ret ); + return ret ; *olen = grp_len + pt_len; - return( 0 ); + return 0 ; } /* @@ -418,13 +418,13 @@ int mbedtls_ecdh_read_params( mbedtls_ecdh_context *ctx, if( ( ret = mbedtls_ecp_tls_read_group_id( &grp_id, buf, end - *buf ) ) != 0 ) - return( ret ); + return ret ; if( ( ret = mbedtls_ecdh_setup( ctx, grp_id ) ) != 0 ) - return( ret ); + return ret ; #if defined(MBEDTLS_ECDH_LEGACY_CONTEXT) - return( ecdh_read_params_internal( ctx, buf, end ) ); + return ecdh_read_params_internal( ctx, buf, end ) ; #else switch( ctx->var ) { @@ -450,17 +450,17 @@ static int ecdh_get_params_internal( mbedtls_ecdh_context_mbed *ctx, /* If it's not our key, just import the public part as Qp */ if( side == MBEDTLS_ECDH_THEIRS ) - return( mbedtls_ecp_copy( &ctx->Qp, &key->Q ) ); + return mbedtls_ecp_copy( &ctx->Qp, &key->Q ) ; /* Our key: import public (as Q) and private parts */ if( side != MBEDTLS_ECDH_OURS ) - return( MBEDTLS_ERR_ECP_BAD_INPUT_DATA ); + return MBEDTLS_ERR_ECP_BAD_INPUT_DATA ; if( ( ret = mbedtls_ecp_copy( &ctx->Q, &key->Q ) ) != 0 || ( ret = mbedtls_mpi_copy( &ctx->d, &key->d ) ) != 0 ) - return( ret ); + return ret ; - return( 0 ); + return 0 ; } /* @@ -481,7 +481,7 @@ int mbedtls_ecdh_get_params( mbedtls_ecdh_context *ctx, /* This is the first call to get_params(). Set up the context * for use with the group. */ if( ( ret = mbedtls_ecdh_setup( ctx, key->grp.id ) ) != 0 ) - return( ret ); + return ret ; } else { @@ -489,11 +489,11 @@ int mbedtls_ecdh_get_params( mbedtls_ecdh_context *ctx, * current key's group is the same as the context's, which was set * from the first key's group. */ if( mbedtls_ecdh_grp_id( ctx ) != key->grp.id ) - return( MBEDTLS_ERR_ECP_BAD_INPUT_DATA ); + return MBEDTLS_ERR_ECP_BAD_INPUT_DATA ; } #if defined(MBEDTLS_ECDH_LEGACY_CONTEXT) - return( ecdh_get_params_internal( ctx, key, side ) ); + return ecdh_get_params_internal( ctx, key, side ) ; #else switch( ctx->var ) { @@ -531,7 +531,7 @@ static int ecdh_make_public_internal( mbedtls_ecdh_context_mbed *ctx, #endif if( ctx->grp.pbits == 0 ) - return( MBEDTLS_ERR_ECP_BAD_INPUT_DATA ); + return MBEDTLS_ERR_ECP_BAD_INPUT_DATA ; #if defined(MBEDTLS_ECP_RESTARTABLE) if( restart_enabled ) @@ -543,11 +543,11 @@ static int ecdh_make_public_internal( mbedtls_ecdh_context_mbed *ctx, #if defined(MBEDTLS_ECP_RESTARTABLE) if( ( ret = ecdh_gen_public_restartable( &ctx->grp, &ctx->d, &ctx->Q, f_rng, p_rng, rs_ctx ) ) != 0 ) - return( ret ); + return ret ; #else if( ( ret = mbedtls_ecdh_gen_public( &ctx->grp, &ctx->d, &ctx->Q, f_rng, p_rng ) ) != 0 ) - return( ret ); + return ret ; #endif /* MBEDTLS_ECP_RESTARTABLE */ return mbedtls_ecp_tls_write_point( &ctx->grp, &ctx->Q, point_format, olen, @@ -602,12 +602,12 @@ static int ecdh_read_public_internal( mbedtls_ecdh_context_mbed *ctx, if( ( ret = mbedtls_ecp_tls_read_point( &ctx->grp, &ctx->Qp, &p, blen ) ) != 0 ) - return( ret ); + return ret ; if( (size_t)( p - buf ) != blen ) - return( MBEDTLS_ERR_ECP_BAD_INPUT_DATA ); + return MBEDTLS_ERR_ECP_BAD_INPUT_DATA ; - return( 0 ); + return 0 ; } /* @@ -620,7 +620,7 @@ int mbedtls_ecdh_read_public( mbedtls_ecdh_context *ctx, ECDH_VALIDATE_RET( buf != NULL ); #if defined(MBEDTLS_ECDH_LEGACY_CONTEXT) - return( ecdh_read_public_internal( ctx, buf, blen ) ); + return ecdh_read_public_internal( ctx, buf, blen ) ; #else switch( ctx->var ) { @@ -653,7 +653,7 @@ static int ecdh_calc_secret_internal( mbedtls_ecdh_context_mbed *ctx, #endif if( ctx == NULL || ctx->grp.pbits == 0 ) - return( MBEDTLS_ERR_ECP_BAD_INPUT_DATA ); + return MBEDTLS_ERR_ECP_BAD_INPUT_DATA ; #if defined(MBEDTLS_ECP_RESTARTABLE) if( restart_enabled ) @@ -667,18 +667,18 @@ static int ecdh_calc_secret_internal( mbedtls_ecdh_context_mbed *ctx, &ctx->d, f_rng, p_rng, rs_ctx ) ) != 0 ) { - return( ret ); + return ret ; } #else if( ( ret = mbedtls_ecdh_compute_shared( &ctx->grp, &ctx->z, &ctx->Qp, &ctx->d, f_rng, p_rng ) ) != 0 ) { - return( ret ); + return ret ; } #endif /* MBEDTLS_ECP_RESTARTABLE */ if( mbedtls_mpi_size( &ctx->z ) > blen ) - return( MBEDTLS_ERR_ECP_BAD_INPUT_DATA ); + return MBEDTLS_ERR_ECP_BAD_INPUT_DATA ; *olen = ctx->grp.pbits / 8 + ( ( ctx->grp.pbits % 8 ) != 0 ); @@ -721,7 +721,7 @@ int mbedtls_ecdh_calc_secret( mbedtls_ecdh_context *ctx, size_t *olen, blen, f_rng, p_rng, restart_enabled ) ); default: - return( MBEDTLS_ERR_ECP_BAD_INPUT_DATA ); + return MBEDTLS_ERR_ECP_BAD_INPUT_DATA ; } #endif } diff --git a/library/ecdsa.c b/library/ecdsa.c index 0b612ce8af..1364c9e8e3 100644 --- a/library/ecdsa.c +++ b/library/ecdsa.c @@ -185,7 +185,7 @@ static void ecdsa_restart_det_free( mbedtls_ecdsa_restart_det_ctx *ctx ) { \ rs_ctx->SUB = mbedtls_calloc( 1, sizeof( *rs_ctx->SUB ) ); \ if( rs_ctx->SUB == NULL ) \ - return( MBEDTLS_ERR_ECP_ALLOC_FAILED ); \ + return MBEDTLS_ERR_ECP_ALLOC_FAILED ; \ \ ecdsa_restart_## SUB ##_init( rs_ctx->SUB ); \ } \ @@ -240,7 +240,7 @@ static int derive_mpi( const mbedtls_ecp_group *grp, mbedtls_mpi *x, MBEDTLS_MPI_CHK( mbedtls_mpi_sub_mpi( x, x, &grp->N ) ); cleanup: - return( ret ); + return ret ; } #endif /* ECDSA_DETERMINISTIC || !ECDSA_SIGN_ALT || !ECDSA_VERIFY_ALT */ @@ -265,11 +265,11 @@ static int ecdsa_sign_restartable( mbedtls_ecp_group *grp, /* Fail cleanly on curves such as Curve25519 that can't be used for ECDSA */ if( ! mbedtls_ecdsa_can_do( grp->id ) || grp->N.p == NULL ) - return( MBEDTLS_ERR_ECP_BAD_INPUT_DATA ); + return MBEDTLS_ERR_ECP_BAD_INPUT_DATA ; /* Make sure d is in range 1..n-1 */ if( mbedtls_mpi_cmp_int( d, 1 ) < 0 || mbedtls_mpi_cmp_mpi( d, &grp->N ) >= 0 ) - return( MBEDTLS_ERR_ECP_INVALID_KEY ); + return MBEDTLS_ERR_ECP_INVALID_KEY ; mbedtls_ecp_point_init( &R ); mbedtls_mpi_init( &k ); mbedtls_mpi_init( &e ); mbedtls_mpi_init( &t ); @@ -380,7 +380,7 @@ cleanup: ECDSA_RS_LEAVE( sig ); - return( ret ); + return ret ; } int mbedtls_ecdsa_can_do( mbedtls_ecp_group_id gid ) @@ -441,7 +441,7 @@ static int ecdsa_sign_det_restartable( mbedtls_ecp_group *grp, mbedtls_mpi h; if( ( md_info = mbedtls_md_info_from_type( md_alg ) ) == NULL ) - return( MBEDTLS_ERR_ECP_BAD_INPUT_DATA ); + return MBEDTLS_ERR_ECP_BAD_INPUT_DATA ; mbedtls_mpi_init( &h ); mbedtls_hmac_drbg_init( &rng_ctx ); @@ -489,7 +489,7 @@ cleanup: ECDSA_RS_LEAVE( det ); - return( ret ); + return ret ; } /* @@ -537,7 +537,7 @@ static int ecdsa_verify_restartable( mbedtls_ecp_group *grp, /* Fail cleanly on curves such as Curve25519 that can't be used for ECDSA */ if( ! mbedtls_ecdsa_can_do( grp->id ) || grp->N.p == NULL ) - return( MBEDTLS_ERR_ECP_BAD_INPUT_DATA ); + return MBEDTLS_ERR_ECP_BAD_INPUT_DATA ; ECDSA_RS_ENTER( ver ); @@ -622,7 +622,7 @@ cleanup: ECDSA_RS_LEAVE( ver ); - return( ret ); + return ret ; } /* @@ -640,7 +640,7 @@ int mbedtls_ecdsa_verify( mbedtls_ecp_group *grp, ECDSA_VALIDATE_RET( s != NULL ); ECDSA_VALIDATE_RET( buf != NULL || blen == 0 ); - return( ecdsa_verify_restartable( grp, buf, blen, Q, r, s, NULL ) ); + return ecdsa_verify_restartable( grp, buf, blen, Q, r, s, NULL ) ; } #endif /* !MBEDTLS_ECDSA_VERIFY_ALT */ @@ -664,12 +664,12 @@ static int ecdsa_signature_to_asn1( const mbedtls_mpi *r, const mbedtls_mpi *s, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ); if( len > sig_size ) - return( MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL ); + return MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL ; memcpy( sig, p, len ); *slen = len; - return( 0 ); + return 0 ; } /* @@ -691,7 +691,7 @@ int mbedtls_ecdsa_write_signature_restartable( mbedtls_ecdsa_context *ctx, ECDSA_VALIDATE_RET( slen != NULL ); if( f_rng == NULL ) - return( MBEDTLS_ERR_ECP_BAD_INPUT_DATA ); + return MBEDTLS_ERR_ECP_BAD_INPUT_DATA ; mbedtls_mpi_init( &r ); mbedtls_mpi_init( &s ); @@ -722,7 +722,7 @@ cleanup: mbedtls_mpi_free( &r ); mbedtls_mpi_free( &s ); - return( ret ); + return ret ; } /* @@ -820,7 +820,7 @@ cleanup: mbedtls_mpi_free( &r ); mbedtls_mpi_free( &s ); - return( ret ); + return ret ; } #if !defined(MBEDTLS_ECDSA_GENKEY_ALT) @@ -836,7 +836,7 @@ int mbedtls_ecdsa_genkey( mbedtls_ecdsa_context *ctx, mbedtls_ecp_group_id gid, ret = mbedtls_ecp_group_load( &ctx->grp, gid ); if( ret != 0 ) - return( ret ); + return ret ; return( mbedtls_ecp_gen_keypair( &ctx->grp, &ctx->d, &ctx->Q, f_rng, p_rng ) ); @@ -859,7 +859,7 @@ int mbedtls_ecdsa_from_keypair( mbedtls_ecdsa_context *ctx, const mbedtls_ecp_ke mbedtls_ecdsa_free( ctx ); } - return( ret ); + return ret ; } /* diff --git a/library/ecjpake.c b/library/ecjpake.c index d229311420..cda3c9fafe 100644 --- a/library/ecjpake.c +++ b/library/ecjpake.c @@ -115,7 +115,7 @@ int mbedtls_ecjpake_setup( mbedtls_ecjpake_context *ctx, ctx->role = role; if( ( ctx->md_info = mbedtls_md_info_from_type( hash ) ) == NULL ) - return( MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE ; MBEDTLS_MPI_CHK( mbedtls_ecp_group_load( &ctx->grp, curve ) ); @@ -125,7 +125,7 @@ cleanup: if( ret != 0 ) mbedtls_ecjpake_free( ctx ); - return( ret ); + return ret ; } int mbedtls_ecjpake_set_point_format( mbedtls_ecjpake_context *ctx, @@ -136,9 +136,9 @@ int mbedtls_ecjpake_set_point_format( mbedtls_ecjpake_context *ctx, case MBEDTLS_ECP_PF_UNCOMPRESSED: case MBEDTLS_ECP_PF_COMPRESSED: ctx->point_format = point_format; - return( 0 ); + return 0 ; default: - return( MBEDTLS_ERR_ECP_BAD_INPUT_DATA ); + return MBEDTLS_ERR_ECP_BAD_INPUT_DATA ; } } @@ -153,10 +153,10 @@ int mbedtls_ecjpake_check( const mbedtls_ecjpake_context *ctx ) ctx->grp.id == MBEDTLS_ECP_DP_NONE || ctx->s.p == NULL ) { - return( MBEDTLS_ERR_ECP_BAD_INPUT_DATA ); + return MBEDTLS_ERR_ECP_BAD_INPUT_DATA ; } - return( 0 ); + return 0 ; } /* @@ -173,12 +173,12 @@ static int ecjpake_write_len_point( unsigned char **p, /* Need at least 4 for length plus 1 for point */ if( end < *p || end - *p < 5 ) - return( MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL ); + return MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL ; ret = mbedtls_ecp_point_write_binary( grp, P, pf, &len, *p + 4, end - ( *p + 4 ) ); if( ret != 0 ) - return( ret ); + return ret ; (*p)[0] = (unsigned char)( ( len >> 24 ) & 0xFF ); (*p)[1] = (unsigned char)( ( len >> 16 ) & 0xFF ); @@ -187,7 +187,7 @@ static int ecjpake_write_len_point( unsigned char **p, *p += 4 + len; - return( 0 ); + return 0 ; } /* @@ -221,7 +221,7 @@ static int ecjpake_hash( const mbedtls_md_info_t *md_info, MBEDTLS_MPI_CHK( ecjpake_write_len_point( &p, end, grp, pf, X ) ); if( end - p < 4 ) - return( MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL ); + return MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL ; *p++ = (unsigned char)( ( id_len >> 24 ) & 0xFF ); *p++ = (unsigned char)( ( id_len >> 16 ) & 0xFF ); @@ -229,7 +229,7 @@ static int ecjpake_hash( const mbedtls_md_info_t *md_info, *p++ = (unsigned char)( ( id_len ) & 0xFF ); if( end < p || (size_t)( end - p ) < id_len ) - return( MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL ); + return MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL ; memcpy( p, id, id_len ); p += id_len; @@ -243,7 +243,7 @@ static int ecjpake_hash( const mbedtls_md_info_t *md_info, MBEDTLS_MPI_CHK( mbedtls_mpi_mod_mpi( h, h, &grp->N ) ); cleanup: - return( ret ); + return ret ; } /* @@ -275,7 +275,7 @@ static int ecjpake_zkp_read( const mbedtls_md_info_t *md_info, * } ECSchnorrZKP; */ if( end < *p ) - return( MBEDTLS_ERR_ECP_BAD_INPUT_DATA ); + return MBEDTLS_ERR_ECP_BAD_INPUT_DATA ; MBEDTLS_MPI_CHK( mbedtls_ecp_tls_read_point( grp, &V, p, end - *p ) ); @@ -315,7 +315,7 @@ cleanup: mbedtls_mpi_free( &r ); mbedtls_mpi_free( &h ); - return( ret ); + return ret ; } /* @@ -340,7 +340,7 @@ static int ecjpake_zkp_write( const mbedtls_md_info_t *md_info, size_t len; if( end < *p ) - return( MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL ); + return MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL ; mbedtls_ecp_point_init( &V ); mbedtls_mpi_init( &v ); @@ -375,7 +375,7 @@ cleanup: mbedtls_mpi_free( &v ); mbedtls_mpi_free( &h ); - return( ret ); + return ret ; } /* @@ -394,7 +394,7 @@ static int ecjpake_kkp_read( const mbedtls_md_info_t *md_info, int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; if( end < *p ) - return( MBEDTLS_ERR_ECP_BAD_INPUT_DATA ); + return MBEDTLS_ERR_ECP_BAD_INPUT_DATA ; /* * struct { @@ -412,7 +412,7 @@ static int ecjpake_kkp_read( const mbedtls_md_info_t *md_info, MBEDTLS_MPI_CHK( ecjpake_zkp_read( md_info, grp, pf, G, X, id, p, end ) ); cleanup: - return( ret ); + return ret ; } /* @@ -435,7 +435,7 @@ static int ecjpake_kkp_write( const mbedtls_md_info_t *md_info, size_t len; if( end < *p ) - return( MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL ); + return MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL ; /* Generate key (7.4.2.3.1) and write it out */ MBEDTLS_MPI_CHK( mbedtls_ecp_gen_keypair_base( (mbedtls_ecp_group *) grp, G, x, X, @@ -449,7 +449,7 @@ static int ecjpake_kkp_write( const mbedtls_md_info_t *md_info, p, end, f_rng, p_rng ) ); cleanup: - return( ret ); + return ret ; } /* @@ -482,7 +482,7 @@ static int ecjpake_kkpp_read( const mbedtls_md_info_t *md_info, ret = MBEDTLS_ERR_ECP_BAD_INPUT_DATA; cleanup: - return( ret ); + return ret ; } /* @@ -516,7 +516,7 @@ static int ecjpake_kkpp_write( const mbedtls_md_info_t *md_info, *olen = p - buf; cleanup: - return( ret ); + return ret ; } /* @@ -574,7 +574,7 @@ static int ecjpake_ecp_add3( mbedtls_ecp_group *grp, mbedtls_ecp_point *R, cleanup: mbedtls_mpi_free( &one ); - return( ret ); + return ret ; } /* @@ -635,7 +635,7 @@ cleanup: mbedtls_ecp_group_free( &grp ); mbedtls_ecp_point_free( &G ); - return( ret ); + return ret ; } /* @@ -666,7 +666,7 @@ static int ecjpake_mul_secret( mbedtls_mpi *R, int sign, cleanup: mbedtls_mpi_free( &b ); - return( ret ); + return ret ; } /* @@ -748,7 +748,7 @@ cleanup: mbedtls_ecp_point_free( &Xm ); mbedtls_mpi_free( &xm ); - return( ret ); + return ret ; } /* @@ -772,7 +772,7 @@ int mbedtls_ecjpake_derive_secret( mbedtls_ecjpake_context *ctx, *olen = mbedtls_md_get_size( ctx->md_info ); if( len < *olen ) - return( MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL ); + return MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL ; mbedtls_ecp_point_init( &K ); mbedtls_mpi_init( &m_xm2_s ); @@ -803,7 +803,7 @@ cleanup: mbedtls_mpi_free( &m_xm2_s ); mbedtls_mpi_free( &one ); - return( ret ); + return ret ; } #undef ID_MINE @@ -825,7 +825,7 @@ cleanup: int mbedtls_ecjpake_self_test( int verbose ) { (void) verbose; - return( 0 ); + return 0 ; } #else @@ -981,7 +981,7 @@ static int self_test_rng( void *ctx, unsigned char *out, size_t len ) out[i] = (unsigned char) state; } - return( 0 ); + return 0 ; } /* Load my private keys and generate the corresponding public keys */ @@ -999,7 +999,7 @@ static int ecjpake_test_load( mbedtls_ecjpake_context *ctx, &ctx->grp.G, self_test_rng, NULL ) ); cleanup: - return( ret ); + return ret ; } #endif /* ! MBEDTLS_ECJPAKE_ALT */ @@ -1020,7 +1020,7 @@ static int ecjpake_lgc( void *p, unsigned char *out, size_t len ) len -= use_len; } - return( 0 ); + return 0 ; } #define TEST_ASSERT( x ) \ @@ -1170,7 +1170,7 @@ cleanup: if( verbose != 0 ) mbedtls_printf( "\n" ); - return( ret ); + return ret ; } #undef TEST_ASSERT diff --git a/library/ecp.c b/library/ecp.c index b608ff1bd7..de213ecd52 100644 --- a/library/ecp.c +++ b/library/ecp.c @@ -141,7 +141,7 @@ void mbedtls_ecp_set_max_ops( unsigned max_ops ) */ int mbedtls_ecp_restart_is_enabled( void ) { - return( ecp_max_ops != 0 ); + return ecp_max_ops != 0 ; } /* @@ -292,14 +292,14 @@ int mbedtls_ecp_check_budget( const mbedtls_ecp_group *grp, ( rs_ctx->ops_done > ecp_max_ops || ops > ecp_max_ops - rs_ctx->ops_done ) ) { - return( MBEDTLS_ERR_ECP_IN_PROGRESS ); + return MBEDTLS_ERR_ECP_IN_PROGRESS ; } /* update running count */ rs_ctx->ops_done += ops; } - return( 0 ); + return 0 ; } /* Call this when entering a function that needs its own sub-context */ @@ -314,7 +314,7 @@ int mbedtls_ecp_check_budget( const mbedtls_ecp_group *grp, { \ rs_ctx->SUB = mbedtls_calloc( 1, sizeof( *rs_ctx->SUB ) ); \ if( rs_ctx->SUB == NULL ) \ - return( MBEDTLS_ERR_ECP_ALLOC_FAILED ); \ + return MBEDTLS_ERR_ECP_ALLOC_FAILED ; \ \ ecp_restart_## SUB ##_init( rs_ctx->SUB ); \ } \ @@ -408,7 +408,7 @@ static mbedtls_ecp_group_id ecp_supported_grp_id[ECP_NB_CURVES]; */ const mbedtls_ecp_curve_info *mbedtls_ecp_curve_list( void ) { - return( ecp_supported_curves ); + return ecp_supported_curves ; } /* @@ -434,7 +434,7 @@ const mbedtls_ecp_group_id *mbedtls_ecp_grp_id_list( void ) init_done = 1; } - return( ecp_supported_grp_id ); + return ecp_supported_grp_id ; } /* @@ -449,10 +449,10 @@ const mbedtls_ecp_curve_info *mbedtls_ecp_curve_info_from_grp_id( mbedtls_ecp_gr curve_info++ ) { if( curve_info->grp_id == grp_id ) - return( curve_info ); + return curve_info ; } - return( NULL ); + return NULL ; } /* @@ -467,10 +467,10 @@ const mbedtls_ecp_curve_info *mbedtls_ecp_curve_info_from_tls_id( uint16_t tls_i curve_info++ ) { if( curve_info->tls_id == tls_id ) - return( curve_info ); + return curve_info ; } - return( NULL ); + return NULL ; } /* @@ -481,17 +481,17 @@ const mbedtls_ecp_curve_info *mbedtls_ecp_curve_info_from_name( const char *name const mbedtls_ecp_curve_info *curve_info; if( name == NULL ) - return( NULL ); + return NULL ; for( curve_info = mbedtls_ecp_curve_list(); curve_info->grp_id != MBEDTLS_ECP_DP_NONE; curve_info++ ) { if( strcmp( curve_info->name, name ) == 0 ) - return( curve_info ); + return curve_info ; } - return( NULL ); + return NULL ; } /* @@ -500,12 +500,12 @@ const mbedtls_ecp_curve_info *mbedtls_ecp_curve_info_from_name( const char *name mbedtls_ecp_curve_type mbedtls_ecp_get_type( const mbedtls_ecp_group *grp ) { if( grp->G.X.p == NULL ) - return( MBEDTLS_ECP_TYPE_NONE ); + return MBEDTLS_ECP_TYPE_NONE ; if( grp->G.Y.p == NULL ) - return( MBEDTLS_ECP_TYPE_MONTGOMERY ); + return MBEDTLS_ECP_TYPE_MONTGOMERY ; else - return( MBEDTLS_ECP_TYPE_SHORT_WEIERSTRASS ); + return MBEDTLS_ECP_TYPE_SHORT_WEIERSTRASS ; } /* @@ -637,7 +637,7 @@ int mbedtls_ecp_copy( mbedtls_ecp_point *P, const mbedtls_ecp_point *Q ) MBEDTLS_MPI_CHK( mbedtls_mpi_copy( &P->Z, &Q->Z ) ); cleanup: - return( ret ); + return ret ; } /* @@ -648,7 +648,7 @@ int mbedtls_ecp_group_copy( mbedtls_ecp_group *dst, const mbedtls_ecp_group *src ECP_VALIDATE_RET( dst != NULL ); ECP_VALIDATE_RET( src != NULL ); - return( mbedtls_ecp_group_load( dst, src->id ) ); + return mbedtls_ecp_group_load( dst, src->id ) ; } /* @@ -664,7 +664,7 @@ int mbedtls_ecp_set_zero( mbedtls_ecp_point *pt ) MBEDTLS_MPI_CHK( mbedtls_mpi_lset( &pt->Z , 0 ) ); cleanup: - return( ret ); + return ret ; } /* @@ -674,7 +674,7 @@ int mbedtls_ecp_is_zero( mbedtls_ecp_point *pt ) { ECP_VALIDATE_RET( pt != NULL ); - return( mbedtls_mpi_cmp_int( &pt->Z, 0 ) == 0 ); + return mbedtls_mpi_cmp_int( &pt->Z, 0 ) == 0 ; } /* @@ -690,10 +690,10 @@ int mbedtls_ecp_point_cmp( const mbedtls_ecp_point *P, mbedtls_mpi_cmp_mpi( &P->Y, &Q->Y ) == 0 && mbedtls_mpi_cmp_mpi( &P->Z, &Q->Z ) == 0 ) { - return( 0 ); + return 0 ; } - return( MBEDTLS_ERR_ECP_BAD_INPUT_DATA ); + return MBEDTLS_ERR_ECP_BAD_INPUT_DATA ; } /* @@ -712,7 +712,7 @@ int mbedtls_ecp_point_read_string( mbedtls_ecp_point *P, int radix, MBEDTLS_MPI_CHK( mbedtls_mpi_lset( &P->Z, 1 ) ); cleanup: - return( ret ); + return ret ; } /* @@ -740,7 +740,7 @@ int mbedtls_ecp_point_write_binary( const mbedtls_ecp_group *grp, { *olen = plen; if( buflen < *olen ) - return( MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL ); + return MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL ; MBEDTLS_MPI_CHK( mbedtls_mpi_write_binary_le( &P->X, buf, plen ) ); } @@ -754,12 +754,12 @@ int mbedtls_ecp_point_write_binary( const mbedtls_ecp_group *grp, if( mbedtls_mpi_cmp_int( &P->Z, 0 ) == 0 ) { if( buflen < 1 ) - return( MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL ); + return MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL ; buf[0] = 0x00; *olen = 1; - return( 0 ); + return 0 ; } if( format == MBEDTLS_ECP_PF_UNCOMPRESSED ) @@ -767,7 +767,7 @@ int mbedtls_ecp_point_write_binary( const mbedtls_ecp_group *grp, *olen = 2 * plen + 1; if( buflen < *olen ) - return( MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL ); + return MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL ; buf[0] = 0x04; MBEDTLS_MPI_CHK( mbedtls_mpi_write_binary( &P->X, buf + 1, plen ) ); @@ -778,7 +778,7 @@ int mbedtls_ecp_point_write_binary( const mbedtls_ecp_group *grp, *olen = plen + 1; if( buflen < *olen ) - return( MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL ); + return MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL ; buf[0] = 0x02 + mbedtls_mpi_get_bit( &P->Y, 0 ); MBEDTLS_MPI_CHK( mbedtls_mpi_write_binary( &P->X, buf + 1, plen ) ); @@ -787,7 +787,7 @@ int mbedtls_ecp_point_write_binary( const mbedtls_ecp_group *grp, #endif cleanup: - return( ret ); + return ret ; } /* @@ -804,7 +804,7 @@ int mbedtls_ecp_point_read_binary( const mbedtls_ecp_group *grp, ECP_VALIDATE_RET( buf != NULL ); if( ilen < 1 ) - return( MBEDTLS_ERR_ECP_BAD_INPUT_DATA ); + return MBEDTLS_ERR_ECP_BAD_INPUT_DATA ; plen = mbedtls_mpi_size( &grp->P ); @@ -812,7 +812,7 @@ int mbedtls_ecp_point_read_binary( const mbedtls_ecp_group *grp, if( mbedtls_ecp_get_type( grp ) == MBEDTLS_ECP_TYPE_MONTGOMERY ) { if( plen != ilen ) - return( MBEDTLS_ERR_ECP_BAD_INPUT_DATA ); + return MBEDTLS_ERR_ECP_BAD_INPUT_DATA ; MBEDTLS_MPI_CHK( mbedtls_mpi_read_binary_le( &pt->X, buf, plen ) ); mbedtls_mpi_free( &pt->Y ); @@ -830,16 +830,16 @@ int mbedtls_ecp_point_read_binary( const mbedtls_ecp_group *grp, if( buf[0] == 0x00 ) { if( ilen == 1 ) - return( mbedtls_ecp_set_zero( pt ) ); + return mbedtls_ecp_set_zero( pt ) ; else - return( MBEDTLS_ERR_ECP_BAD_INPUT_DATA ); + return MBEDTLS_ERR_ECP_BAD_INPUT_DATA ; } if( buf[0] != 0x04 ) - return( MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE ; if( ilen != 2 * plen + 1 ) - return( MBEDTLS_ERR_ECP_BAD_INPUT_DATA ); + return MBEDTLS_ERR_ECP_BAD_INPUT_DATA ; MBEDTLS_MPI_CHK( mbedtls_mpi_read_binary( &pt->X, buf + 1, plen ) ); MBEDTLS_MPI_CHK( mbedtls_mpi_read_binary( &pt->Y, @@ -849,7 +849,7 @@ int mbedtls_ecp_point_read_binary( const mbedtls_ecp_group *grp, #endif cleanup: - return( ret ); + return ret ; } /* @@ -873,11 +873,11 @@ int mbedtls_ecp_tls_read_point( const mbedtls_ecp_group *grp, * We must have at least two bytes (1 for length, at least one for data) */ if( buf_len < 2 ) - return( MBEDTLS_ERR_ECP_BAD_INPUT_DATA ); + return MBEDTLS_ERR_ECP_BAD_INPUT_DATA ; data_len = *(*buf)++; if( data_len < 1 || data_len > buf_len - 1 ) - return( MBEDTLS_ERR_ECP_BAD_INPUT_DATA ); + return MBEDTLS_ERR_ECP_BAD_INPUT_DATA ; /* * Save buffer start for read_binary and update buf @@ -885,7 +885,7 @@ int mbedtls_ecp_tls_read_point( const mbedtls_ecp_group *grp, buf_start = *buf; *buf += data_len; - return( mbedtls_ecp_point_read_binary( grp, pt, buf_start, data_len ) ); + return mbedtls_ecp_point_read_binary( grp, pt, buf_start, data_len ) ; } /* @@ -910,11 +910,11 @@ int mbedtls_ecp_tls_write_point( const mbedtls_ecp_group *grp, const mbedtls_ecp * buffer length must be at least one, for our length byte */ if( blen < 1 ) - return( MBEDTLS_ERR_ECP_BAD_INPUT_DATA ); + return MBEDTLS_ERR_ECP_BAD_INPUT_DATA ; if( ( ret = mbedtls_ecp_point_write_binary( grp, pt, format, olen, buf + 1, blen - 1) ) != 0 ) - return( ret ); + return ret ; /* * write length to the first byte and update total length @@ -922,7 +922,7 @@ int mbedtls_ecp_tls_write_point( const mbedtls_ecp_group *grp, const mbedtls_ecp buf[0] = (unsigned char) *olen; ++*olen; - return( 0 ); + return 0 ; } /* @@ -938,9 +938,9 @@ int mbedtls_ecp_tls_read_group( mbedtls_ecp_group *grp, ECP_VALIDATE_RET( *buf != NULL ); if( ( ret = mbedtls_ecp_tls_read_group_id( &grp_id, buf, len ) ) != 0 ) - return( ret ); + return ret ; - return( mbedtls_ecp_group_load( grp, grp_id ) ); + return mbedtls_ecp_group_load( grp, grp_id ) ; } /* @@ -960,13 +960,13 @@ int mbedtls_ecp_tls_read_group_id( mbedtls_ecp_group_id *grp, * We expect at least three bytes (see below) */ if( len < 3 ) - return( MBEDTLS_ERR_ECP_BAD_INPUT_DATA ); + return MBEDTLS_ERR_ECP_BAD_INPUT_DATA ; /* * First byte is curve_type; only named_curve is handled */ if( *(*buf)++ != MBEDTLS_ECP_TLS_NAMED_CURVE ) - return( MBEDTLS_ERR_ECP_BAD_INPUT_DATA ); + return MBEDTLS_ERR_ECP_BAD_INPUT_DATA ; /* * Next two bytes are the namedcurve value @@ -976,11 +976,11 @@ int mbedtls_ecp_tls_read_group_id( mbedtls_ecp_group_id *grp, tls_id |= *(*buf)++; if( ( curve_info = mbedtls_ecp_curve_info_from_tls_id( tls_id ) ) == NULL ) - return( MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE ; *grp = curve_info->grp_id; - return( 0 ); + return 0 ; } /* @@ -995,14 +995,14 @@ int mbedtls_ecp_tls_write_group( const mbedtls_ecp_group *grp, size_t *olen, ECP_VALIDATE_RET( olen != NULL ); if( ( curve_info = mbedtls_ecp_curve_info_from_grp_id( grp->id ) ) == NULL ) - return( MBEDTLS_ERR_ECP_BAD_INPUT_DATA ); + return MBEDTLS_ERR_ECP_BAD_INPUT_DATA ; /* * We are going to write 3 bytes (see below) */ *olen = 3; if( blen < *olen ) - return( MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL ); + return MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL ; /* * First byte is curve_type, always named_curve @@ -1015,7 +1015,7 @@ int mbedtls_ecp_tls_write_group( const mbedtls_ecp_group *grp, size_t *olen, buf[0] = curve_info->tls_id >> 8; buf[1] = curve_info->tls_id & 0xFF; - return( 0 ); + return 0 ; } /* @@ -1029,13 +1029,13 @@ static int ecp_modp( mbedtls_mpi *N, const mbedtls_ecp_group *grp ) int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; if( grp->modp == NULL ) - return( mbedtls_mpi_mod_mpi( N, N, &grp->P ) ); + return mbedtls_mpi_mod_mpi( N, N, &grp->P ) ; /* N->s < 0 is a much faster test, which fails only if N is 0 */ if( ( N->s < 0 && mbedtls_mpi_cmp_int( N, 0 ) != 0 ) || mbedtls_mpi_bitlen( N ) > 2 * grp->pbits ) { - return( MBEDTLS_ERR_ECP_BAD_INPUT_DATA ); + return MBEDTLS_ERR_ECP_BAD_INPUT_DATA ; } MBEDTLS_MPI_CHK( grp->modp( N ) ); @@ -1049,7 +1049,7 @@ static int ecp_modp( mbedtls_mpi *N, const mbedtls_ecp_group *grp ) MBEDTLS_MPI_CHK( mbedtls_mpi_sub_abs( N, N, &grp->P ) ); cleanup: - return( ret ); + return ret ; } /* @@ -1087,7 +1087,7 @@ static inline int mbedtls_mpi_mul_mod( const mbedtls_ecp_group *grp, MBEDTLS_MPI_CHK( mbedtls_mpi_mul_mpi( X, A, B ) ); MOD_MUL( *X ); cleanup: - return( ret ); + return ret ; } /* @@ -1114,7 +1114,7 @@ static inline int mbedtls_mpi_sub_mod( const mbedtls_ecp_group *grp, MBEDTLS_MPI_CHK( mbedtls_mpi_sub_mpi( X, A, B ) ); MOD_SUB( *X ); cleanup: - return( ret ); + return ret ; } #endif /* All functions referencing mbedtls_mpi_sub_mod() are alt-implemented without fallback */ @@ -1136,7 +1136,7 @@ static inline int mbedtls_mpi_add_mod( const mbedtls_ecp_group *grp, MBEDTLS_MPI_CHK( mbedtls_mpi_add_mpi( X, A, B ) ); MOD_ADD( *X ); cleanup: - return( ret ); + return ret ; } #if defined(MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED) && \ @@ -1151,7 +1151,7 @@ static inline int mbedtls_mpi_shift_l_mod( const mbedtls_ecp_group *grp, MBEDTLS_MPI_CHK( mbedtls_mpi_shift_l( X, count ) ); MOD_ADD( *X ); cleanup: - return( ret ); + return ret ; } #endif /* All functions referencing mbedtls_mpi_shift_l_mod() are alt-implemented without fallback */ @@ -1171,15 +1171,15 @@ cleanup: static int ecp_normalize_jac( const mbedtls_ecp_group *grp, mbedtls_ecp_point *pt ) { if( mbedtls_mpi_cmp_int( &pt->Z, 0 ) == 0 ) - return( 0 ); + return 0 ; #if defined(MBEDTLS_ECP_NORMALIZE_JAC_ALT) if( mbedtls_internal_ecp_grp_capable( grp ) ) - return( mbedtls_internal_ecp_normalize_jac( grp, pt ) ); + return mbedtls_internal_ecp_normalize_jac( grp, pt ) ; #endif /* MBEDTLS_ECP_NORMALIZE_JAC_ALT */ #if defined(MBEDTLS_ECP_NO_FALLBACK) && defined(MBEDTLS_ECP_NORMALIZE_JAC_ALT) - return( MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE ; #else int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; mbedtls_mpi Zi, ZZi; @@ -1207,7 +1207,7 @@ cleanup: mbedtls_mpi_free( &Zi ); mbedtls_mpi_free( &ZZi ); - return( ret ); + return ret ; #endif /* !defined(MBEDTLS_ECP_NO_FALLBACK) || !defined(MBEDTLS_ECP_NORMALIZE_JAC_ALT) */ } @@ -1226,22 +1226,22 @@ static int ecp_normalize_jac_many( const mbedtls_ecp_group *grp, mbedtls_ecp_point *T[], size_t T_size ) { if( T_size < 2 ) - return( ecp_normalize_jac( grp, *T ) ); + return ecp_normalize_jac( grp, *T ) ; #if defined(MBEDTLS_ECP_NORMALIZE_JAC_MANY_ALT) if( mbedtls_internal_ecp_grp_capable( grp ) ) - return( mbedtls_internal_ecp_normalize_jac_many( grp, T, T_size ) ); + return mbedtls_internal_ecp_normalize_jac_many( grp, T, T_size ) ; #endif #if defined(MBEDTLS_ECP_NO_FALLBACK) && defined(MBEDTLS_ECP_NORMALIZE_JAC_MANY_ALT) - return( MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE ; #else int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; size_t i; mbedtls_mpi *c, u, Zi, ZZi; if( ( c = mbedtls_calloc( T_size, sizeof( mbedtls_mpi ) ) ) == NULL ) - return( MBEDTLS_ERR_ECP_ALLOC_FAILED ); + return MBEDTLS_ERR_ECP_ALLOC_FAILED ; for( i = 0; i < T_size; i++ ) mbedtls_mpi_init( &c[i] ); @@ -1306,7 +1306,7 @@ cleanup: mbedtls_mpi_free( &c[i] ); mbedtls_free( c ); - return( ret ); + return ret ; #endif /* !defined(MBEDTLS_ECP_NO_FALLBACK) || !defined(MBEDTLS_ECP_NORMALIZE_JAC_MANY_ALT) */ } @@ -1332,7 +1332,7 @@ static int ecp_safe_invert_jac( const mbedtls_ecp_group *grp, cleanup: mbedtls_mpi_free( &mQY ); - return( ret ); + return ret ; } /* @@ -1358,11 +1358,11 @@ static int ecp_double_jac( const mbedtls_ecp_group *grp, mbedtls_ecp_point *R, #if defined(MBEDTLS_ECP_DOUBLE_JAC_ALT) if( mbedtls_internal_ecp_grp_capable( grp ) ) - return( mbedtls_internal_ecp_double_jac( grp, R, P ) ); + return mbedtls_internal_ecp_double_jac( grp, R, P ) ; #endif /* MBEDTLS_ECP_DOUBLE_JAC_ALT */ #if defined(MBEDTLS_ECP_NO_FALLBACK) && defined(MBEDTLS_ECP_DOUBLE_JAC_ALT) - return( MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE ; #else int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; mbedtls_mpi M, S, T, U; @@ -1427,7 +1427,7 @@ static int ecp_double_jac( const mbedtls_ecp_group *grp, mbedtls_ecp_point *R, cleanup: mbedtls_mpi_free( &M ); mbedtls_mpi_free( &S ); mbedtls_mpi_free( &T ); mbedtls_mpi_free( &U ); - return( ret ); + return ret ; #endif /* !defined(MBEDTLS_ECP_NO_FALLBACK) || !defined(MBEDTLS_ECP_DOUBLE_JAC_ALT) */ } @@ -1458,11 +1458,11 @@ static int ecp_add_mixed( const mbedtls_ecp_group *grp, mbedtls_ecp_point *R, #if defined(MBEDTLS_ECP_ADD_MIXED_ALT) if( mbedtls_internal_ecp_grp_capable( grp ) ) - return( mbedtls_internal_ecp_add_mixed( grp, R, P, Q ) ); + return mbedtls_internal_ecp_add_mixed( grp, R, P, Q ) ; #endif /* MBEDTLS_ECP_ADD_MIXED_ALT */ #if defined(MBEDTLS_ECP_NO_FALLBACK) && defined(MBEDTLS_ECP_ADD_MIXED_ALT) - return( MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE ; #else int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; mbedtls_mpi T1, T2, T3, T4, X, Y, Z; @@ -1471,16 +1471,16 @@ static int ecp_add_mixed( const mbedtls_ecp_group *grp, mbedtls_ecp_point *R, * Trivial cases: P == 0 or Q == 0 (case 1) */ if( mbedtls_mpi_cmp_int( &P->Z, 0 ) == 0 ) - return( mbedtls_ecp_copy( R, Q ) ); + return mbedtls_ecp_copy( R, Q ) ; if( Q->Z.p != NULL && mbedtls_mpi_cmp_int( &Q->Z, 0 ) == 0 ) - return( mbedtls_ecp_copy( R, P ) ); + return mbedtls_ecp_copy( R, P ) ; /* * Make sure Q coordinates are normalized */ if( Q->Z.p != NULL && mbedtls_mpi_cmp_int( &Q->Z, 1 ) != 0 ) - return( MBEDTLS_ERR_ECP_BAD_INPUT_DATA ); + return MBEDTLS_ERR_ECP_BAD_INPUT_DATA ; mbedtls_mpi_init( &T1 ); mbedtls_mpi_init( &T2 ); mbedtls_mpi_init( &T3 ); mbedtls_mpi_init( &T4 ); mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y ); mbedtls_mpi_init( &Z ); @@ -1530,7 +1530,7 @@ cleanup: mbedtls_mpi_free( &T1 ); mbedtls_mpi_free( &T2 ); mbedtls_mpi_free( &T3 ); mbedtls_mpi_free( &T4 ); mbedtls_mpi_free( &X ); mbedtls_mpi_free( &Y ); mbedtls_mpi_free( &Z ); - return( ret ); + return ret ; #endif /* !defined(MBEDTLS_ECP_NO_FALLBACK) || !defined(MBEDTLS_ECP_ADD_MIXED_ALT) */ } @@ -1546,11 +1546,11 @@ static int ecp_randomize_jac( const mbedtls_ecp_group *grp, mbedtls_ecp_point *p { #if defined(MBEDTLS_ECP_RANDOMIZE_JAC_ALT) if( mbedtls_internal_ecp_grp_capable( grp ) ) - return( mbedtls_internal_ecp_randomize_jac( grp, pt, f_rng, p_rng ) ); + return mbedtls_internal_ecp_randomize_jac( grp, pt, f_rng, p_rng ) ; #endif /* MBEDTLS_ECP_RANDOMIZE_JAC_ALT */ #if defined(MBEDTLS_ECP_NO_FALLBACK) && defined(MBEDTLS_ECP_RANDOMIZE_JAC_ALT) - return( MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE ; #else int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; mbedtls_mpi l, ll; @@ -1576,7 +1576,7 @@ cleanup: if( ret == MBEDTLS_ERR_MPI_NOT_ACCEPTABLE ) ret = MBEDTLS_ERR_ECP_RANDOM_FAILED; - return( ret ); + return ret ; #endif /* !defined(MBEDTLS_ECP_NO_FALLBACK) || !defined(MBEDTLS_ECP_RANDOMIZE_JAC_ALT) */ } @@ -1833,7 +1833,7 @@ cleanup: } #endif - return( ret ); + return ret ; } /* @@ -1862,7 +1862,7 @@ static int ecp_select_comb( const mbedtls_ecp_group *grp, mbedtls_ecp_point *R, MBEDTLS_MPI_CHK( ecp_safe_invert_jac( grp, R, i >> 7 ) ); cleanup: - return( ret ); + return ret ; } /* @@ -1936,7 +1936,7 @@ cleanup: } #endif - return( ret ); + return ret ; } /* @@ -1966,7 +1966,7 @@ static int ecp_comb_recode_scalar( const mbedtls_ecp_group *grp, /* N is always odd (see above), just make extra sure */ if( mbedtls_mpi_get_bit( &grp->N, 0 ) != 1 ) - return( MBEDTLS_ERR_ECP_BAD_INPUT_DATA ); + return MBEDTLS_ERR_ECP_BAD_INPUT_DATA ; /* do we need the parity trick? */ *parity_trick = ( mbedtls_mpi_get_bit( m, 0 ) == 0 ); @@ -1983,7 +1983,7 @@ cleanup: mbedtls_mpi_free( &mm ); mbedtls_mpi_free( &M ); - return( ret ); + return ret ; } /* @@ -2054,7 +2054,7 @@ final_norm: #endif cleanup: - return( ret ); + return ret ; } /* @@ -2096,7 +2096,7 @@ static unsigned char ecp_pick_window_size( const mbedtls_ecp_group *grp, if( w >= grp->nbits ) w = 2; - return( w ); + return w ; } /* @@ -2230,7 +2230,7 @@ cleanup: ECP_RS_LEAVE( rsm ); - return( ret ); + return ret ; } #endif /* MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED */ @@ -2252,11 +2252,11 @@ static int ecp_normalize_mxz( const mbedtls_ecp_group *grp, mbedtls_ecp_point *P { #if defined(MBEDTLS_ECP_NORMALIZE_MXZ_ALT) if( mbedtls_internal_ecp_grp_capable( grp ) ) - return( mbedtls_internal_ecp_normalize_mxz( grp, P ) ); + return mbedtls_internal_ecp_normalize_mxz( grp, P ) ; #endif /* MBEDTLS_ECP_NORMALIZE_MXZ_ALT */ #if defined(MBEDTLS_ECP_NO_FALLBACK) && defined(MBEDTLS_ECP_NORMALIZE_MXZ_ALT) - return( MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE ; #else int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; MBEDTLS_MPI_CHK( mbedtls_mpi_inv_mod( &P->Z, &P->Z, &grp->P ) ); @@ -2264,7 +2264,7 @@ static int ecp_normalize_mxz( const mbedtls_ecp_group *grp, mbedtls_ecp_point *P MBEDTLS_MPI_CHK( mbedtls_mpi_lset( &P->Z, 1 ) ); cleanup: - return( ret ); + return ret ; #endif /* !defined(MBEDTLS_ECP_NO_FALLBACK) || !defined(MBEDTLS_ECP_NORMALIZE_MXZ_ALT) */ } @@ -2281,11 +2281,11 @@ static int ecp_randomize_mxz( const mbedtls_ecp_group *grp, mbedtls_ecp_point *P { #if defined(MBEDTLS_ECP_RANDOMIZE_MXZ_ALT) if( mbedtls_internal_ecp_grp_capable( grp ) ) - return( mbedtls_internal_ecp_randomize_mxz( grp, P, f_rng, p_rng ) ); + return mbedtls_internal_ecp_randomize_mxz( grp, P, f_rng, p_rng ) ; #endif /* MBEDTLS_ECP_RANDOMIZE_MXZ_ALT */ #if defined(MBEDTLS_ECP_NO_FALLBACK) && defined(MBEDTLS_ECP_RANDOMIZE_MXZ_ALT) - return( MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE ; #else int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; mbedtls_mpi l; @@ -2302,7 +2302,7 @@ cleanup: if( ret == MBEDTLS_ERR_MPI_NOT_ACCEPTABLE ) ret = MBEDTLS_ERR_ECP_RANDOM_FAILED; - return( ret ); + return ret ; #endif /* !defined(MBEDTLS_ECP_NO_FALLBACK) || !defined(MBEDTLS_ECP_RANDOMIZE_MXZ_ALT) */ } @@ -2328,11 +2328,11 @@ static int ecp_double_add_mxz( const mbedtls_ecp_group *grp, { #if defined(MBEDTLS_ECP_DOUBLE_ADD_MXZ_ALT) if( mbedtls_internal_ecp_grp_capable( grp ) ) - return( mbedtls_internal_ecp_double_add_mxz( grp, R, S, P, Q, d ) ); + return mbedtls_internal_ecp_double_add_mxz( grp, R, S, P, Q, d ) ; #endif /* MBEDTLS_ECP_DOUBLE_ADD_MXZ_ALT */ #if defined(MBEDTLS_ECP_NO_FALLBACK) && defined(MBEDTLS_ECP_DOUBLE_ADD_MXZ_ALT) - return( MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE ; #else int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; mbedtls_mpi A, AA, B, BB, E, C, D, DA, CB; @@ -2365,7 +2365,7 @@ cleanup: mbedtls_mpi_free( &BB ); mbedtls_mpi_free( &E ); mbedtls_mpi_free( &C ); mbedtls_mpi_free( &D ); mbedtls_mpi_free( &DA ); mbedtls_mpi_free( &CB ); - return( ret ); + return ret ; #endif /* !defined(MBEDTLS_ECP_NO_FALLBACK) || !defined(MBEDTLS_ECP_DOUBLE_ADD_MXZ_ALT) */ } @@ -2386,7 +2386,7 @@ static int ecp_mul_mxz( mbedtls_ecp_group *grp, mbedtls_ecp_point *R, mbedtls_ecp_point_init( &RP ); mbedtls_mpi_init( &PX ); if( f_rng == NULL ) - return( MBEDTLS_ERR_ECP_BAD_INPUT_DATA ); + return MBEDTLS_ERR_ECP_BAD_INPUT_DATA ; /* Save PX and read from P before writing to R, in case P == R */ MBEDTLS_MPI_CHK( mbedtls_mpi_copy( &PX, &P->X ) ); @@ -2439,7 +2439,7 @@ static int ecp_mul_mxz( mbedtls_ecp_group *grp, mbedtls_ecp_point *R, cleanup: mbedtls_ecp_point_free( &RP ); mbedtls_mpi_free( &PX ); - return( ret ); + return ret ; } #endif /* MBEDTLS_ECP_MONTGOMERY_ENABLED */ @@ -2508,7 +2508,7 @@ cleanup: rs_ctx->depth--; #endif - return( ret ); + return ret ; } /* @@ -2525,9 +2525,9 @@ int mbedtls_ecp_mul_restartable( mbedtls_ecp_group *grp, mbedtls_ecp_point *R, ECP_VALIDATE_RET( P != NULL ); if( f_rng == NULL ) - return( MBEDTLS_ERR_ECP_BAD_INPUT_DATA ); + return MBEDTLS_ERR_ECP_BAD_INPUT_DATA ; - return( ecp_mul_restartable_internal( grp, R, m, P, f_rng, p_rng, rs_ctx ) ); + return ecp_mul_restartable_internal( grp, R, m, P, f_rng, p_rng, rs_ctx ) ; } /* @@ -2541,7 +2541,7 @@ int mbedtls_ecp_mul( mbedtls_ecp_group *grp, mbedtls_ecp_point *R, ECP_VALIDATE_RET( R != NULL ); ECP_VALIDATE_RET( m != NULL ); ECP_VALIDATE_RET( P != NULL ); - return( mbedtls_ecp_mul_restartable( grp, R, m, P, f_rng, p_rng, NULL ) ); + return mbedtls_ecp_mul_restartable( grp, R, m, P, f_rng, p_rng, NULL ) ; } #if defined(MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED) @@ -2559,7 +2559,7 @@ static int ecp_check_pubkey_sw( const mbedtls_ecp_group *grp, const mbedtls_ecp_ mbedtls_mpi_cmp_int( &pt->Y, 0 ) < 0 || mbedtls_mpi_cmp_mpi( &pt->X, &grp->P ) >= 0 || mbedtls_mpi_cmp_mpi( &pt->Y, &grp->P ) >= 0 ) - return( MBEDTLS_ERR_ECP_INVALID_KEY ); + return MBEDTLS_ERR_ECP_INVALID_KEY ; mbedtls_mpi_init( &YY ); mbedtls_mpi_init( &RHS ); @@ -2590,7 +2590,7 @@ cleanup: mbedtls_mpi_free( &YY ); mbedtls_mpi_free( &RHS ); - return( ret ); + return ret ; } #endif /* MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED */ @@ -2628,7 +2628,7 @@ static int mbedtls_ecp_mul_shortcuts( mbedtls_ecp_group *grp, } cleanup: - return( ret ); + return ret ; } /* @@ -2656,7 +2656,7 @@ int mbedtls_ecp_muladd_restartable( ECP_VALIDATE_RET( Q != NULL ); if( mbedtls_ecp_get_type( grp ) != MBEDTLS_ECP_TYPE_SHORT_WEIERSTRASS ) - return( MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE ; mbedtls_ecp_point_init( &mP ); @@ -2725,7 +2725,7 @@ cleanup: ECP_RS_LEAVE( ma ); - return( ret ); + return ret ; } /* @@ -2742,7 +2742,7 @@ int mbedtls_ecp_muladd( mbedtls_ecp_group *grp, mbedtls_ecp_point *R, ECP_VALIDATE_RET( P != NULL ); ECP_VALIDATE_RET( n != NULL ); ECP_VALIDATE_RET( Q != NULL ); - return( mbedtls_ecp_muladd_restartable( grp, R, m, P, n, Q, NULL ) ); + return mbedtls_ecp_muladd_restartable( grp, R, m, P, n, Q, NULL ) ; } #endif /* MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED */ @@ -2835,7 +2835,7 @@ static int ecp_check_bad_points_mx( const mbedtls_mpi *X, const mbedtls_mpi *P, cleanup: mbedtls_mpi_free( &XmP ); - return( ret ); + return ret ; } /* @@ -2847,15 +2847,15 @@ static int ecp_check_pubkey_mx( const mbedtls_ecp_group *grp, const mbedtls_ecp_ /* Allow any public value, if it's too big then we'll just reduce it mod p * (RFC 7748 sec. 5 para. 3). */ if( mbedtls_mpi_size( &pt->X ) > ( grp->nbits + 7 ) / 8 ) - return( MBEDTLS_ERR_ECP_INVALID_KEY ); + return MBEDTLS_ERR_ECP_INVALID_KEY ; /* Implicit in all standards (as they don't consider negative numbers): * X must be non-negative. This is normally ensured by the way it's * encoded for transmission, but let's be extra sure. */ if( mbedtls_mpi_cmp_int( &pt->X, 0 ) < 0 ) - return( MBEDTLS_ERR_ECP_INVALID_KEY ); + return MBEDTLS_ERR_ECP_INVALID_KEY ; - return( ecp_check_bad_points_mx( &pt->X, &grp->P, grp->id ) ); + return ecp_check_bad_points_mx( &pt->X, &grp->P, grp->id ) ; } #endif /* MBEDTLS_ECP_MONTGOMERY_ENABLED */ @@ -2870,17 +2870,17 @@ int mbedtls_ecp_check_pubkey( const mbedtls_ecp_group *grp, /* Must use affine coordinates */ if( mbedtls_mpi_cmp_int( &pt->Z, 1 ) != 0 ) - return( MBEDTLS_ERR_ECP_INVALID_KEY ); + return MBEDTLS_ERR_ECP_INVALID_KEY ; #if defined(MBEDTLS_ECP_MONTGOMERY_ENABLED) if( mbedtls_ecp_get_type( grp ) == MBEDTLS_ECP_TYPE_MONTGOMERY ) - return( ecp_check_pubkey_mx( grp, pt ) ); + return ecp_check_pubkey_mx( grp, pt ) ; #endif #if defined(MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED) if( mbedtls_ecp_get_type( grp ) == MBEDTLS_ECP_TYPE_SHORT_WEIERSTRASS ) - return( ecp_check_pubkey_sw( grp, pt ) ); + return ecp_check_pubkey_sw( grp, pt ) ; #endif - return( MBEDTLS_ERR_ECP_BAD_INPUT_DATA ); + return MBEDTLS_ERR_ECP_BAD_INPUT_DATA ; } /* @@ -2899,13 +2899,13 @@ int mbedtls_ecp_check_privkey( const mbedtls_ecp_group *grp, if( mbedtls_mpi_get_bit( d, 0 ) != 0 || mbedtls_mpi_get_bit( d, 1 ) != 0 || mbedtls_mpi_bitlen( d ) - 1 != grp->nbits ) /* mbedtls_mpi_bitlen is one-based! */ - return( MBEDTLS_ERR_ECP_INVALID_KEY ); + return MBEDTLS_ERR_ECP_INVALID_KEY ; /* see [Curve25519] page 5 */ if( grp->nbits == 254 && mbedtls_mpi_get_bit( d, 2 ) != 0 ) - return( MBEDTLS_ERR_ECP_INVALID_KEY ); + return MBEDTLS_ERR_ECP_INVALID_KEY ; - return( 0 ); + return 0 ; } #endif /* MBEDTLS_ECP_MONTGOMERY_ENABLED */ #if defined(MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED) @@ -2914,13 +2914,13 @@ int mbedtls_ecp_check_privkey( const mbedtls_ecp_group *grp, /* see SEC1 3.2 */ if( mbedtls_mpi_cmp_int( d, 1 ) < 0 || mbedtls_mpi_cmp_mpi( d, &grp->N ) >= 0 ) - return( MBEDTLS_ERR_ECP_INVALID_KEY ); + return MBEDTLS_ERR_ECP_INVALID_KEY ; else - return( 0 ); + return 0 ; } #endif /* MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED */ - return( MBEDTLS_ERR_ECP_BAD_INPUT_DATA ); + return MBEDTLS_ERR_ECP_BAD_INPUT_DATA ; } #if defined(MBEDTLS_ECP_MONTGOMERY_ENABLED) @@ -2953,7 +2953,7 @@ int mbedtls_ecp_gen_privkey_mx( size_t high_bit, } cleanup: - return( ret ); + return ret ; } #endif /* MBEDTLS_ECP_MONTGOMERY_ENABLED */ @@ -2966,9 +2966,9 @@ static int mbedtls_ecp_gen_privkey_sw( switch( ret ) { case MBEDTLS_ERR_MPI_NOT_ACCEPTABLE: - return( MBEDTLS_ERR_ECP_RANDOM_FAILED ); + return MBEDTLS_ERR_ECP_RANDOM_FAILED ; default: - return( ret ); + return ret ; } } #endif /* MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED */ @@ -2987,15 +2987,15 @@ int mbedtls_ecp_gen_privkey( const mbedtls_ecp_group *grp, #if defined(MBEDTLS_ECP_MONTGOMERY_ENABLED) if( mbedtls_ecp_get_type( grp ) == MBEDTLS_ECP_TYPE_MONTGOMERY ) - return( mbedtls_ecp_gen_privkey_mx( grp->nbits, d, f_rng, p_rng ) ); + return mbedtls_ecp_gen_privkey_mx( grp->nbits, d, f_rng, p_rng ) ; #endif /* MBEDTLS_ECP_MONTGOMERY_ENABLED */ #if defined(MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED) if( mbedtls_ecp_get_type( grp ) == MBEDTLS_ECP_TYPE_SHORT_WEIERSTRASS ) - return( mbedtls_ecp_gen_privkey_sw( &grp->N, d, f_rng, p_rng ) ); + return mbedtls_ecp_gen_privkey_sw( &grp->N, d, f_rng, p_rng ) ; #endif /* MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED */ - return( MBEDTLS_ERR_ECP_BAD_INPUT_DATA ); + return MBEDTLS_ERR_ECP_BAD_INPUT_DATA ; } /* @@ -3018,7 +3018,7 @@ int mbedtls_ecp_gen_keypair_base( mbedtls_ecp_group *grp, MBEDTLS_MPI_CHK( mbedtls_ecp_mul( grp, Q, d, G, f_rng, p_rng ) ); cleanup: - return( ret ); + return ret ; } /* @@ -3034,7 +3034,7 @@ int mbedtls_ecp_gen_keypair( mbedtls_ecp_group *grp, ECP_VALIDATE_RET( Q != NULL ); ECP_VALIDATE_RET( f_rng != NULL ); - return( mbedtls_ecp_gen_keypair_base( grp, &grp->G, d, Q, f_rng, p_rng ) ); + return mbedtls_ecp_gen_keypair_base( grp, &grp->G, d, Q, f_rng, p_rng ) ; } /* @@ -3048,9 +3048,9 @@ int mbedtls_ecp_gen_key( mbedtls_ecp_group_id grp_id, mbedtls_ecp_keypair *key, ECP_VALIDATE_RET( f_rng != NULL ); if( ( ret = mbedtls_ecp_group_load( &key->grp, grp_id ) ) != 0 ) - return( ret ); + return ret ; - return( mbedtls_ecp_gen_keypair( &key->grp, &key->d, &key->Q, f_rng, p_rng ) ); + return mbedtls_ecp_gen_keypair( &key->grp, &key->d, &key->Q, f_rng, p_rng ) ; } #define ECP_CURVE25519_KEY_SIZE 32 @@ -3067,7 +3067,7 @@ int mbedtls_ecp_read_key( mbedtls_ecp_group_id grp_id, mbedtls_ecp_keypair *key, ECP_VALIDATE_RET( buf != NULL ); if( ( ret = mbedtls_ecp_group_load( &key->grp, grp_id ) ) != 0 ) - return( ret ); + return ret ; ret = MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE; @@ -3080,7 +3080,7 @@ int mbedtls_ecp_read_key( mbedtls_ecp_group_id grp_id, mbedtls_ecp_keypair *key, if( grp_id == MBEDTLS_ECP_DP_CURVE25519 ) { if( buflen != ECP_CURVE25519_KEY_SIZE ) - return( MBEDTLS_ERR_ECP_INVALID_KEY ); + return MBEDTLS_ERR_ECP_INVALID_KEY ; MBEDTLS_MPI_CHK( mbedtls_mpi_read_binary_le( &key->d, buf, buflen ) ); @@ -3104,7 +3104,7 @@ int mbedtls_ecp_read_key( mbedtls_ecp_group_id grp_id, mbedtls_ecp_keypair *key, else if( grp_id == MBEDTLS_ECP_DP_CURVE448 ) { if( buflen != ECP_CURVE448_KEY_SIZE ) - return( MBEDTLS_ERR_ECP_INVALID_KEY ); + return MBEDTLS_ERR_ECP_INVALID_KEY ; MBEDTLS_MPI_CHK( mbedtls_mpi_read_binary_le( &key->d, buf, buflen ) ); @@ -3135,7 +3135,7 @@ cleanup: if( ret != 0 ) mbedtls_mpi_free( &key->d ); - return( ret ); + return ret ; } /* @@ -3155,13 +3155,13 @@ int mbedtls_ecp_write_key( mbedtls_ecp_keypair *key, if( key->grp.id == MBEDTLS_ECP_DP_CURVE25519 ) { if( buflen < ECP_CURVE25519_KEY_SIZE ) - return( MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL ); + return MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL ; } else if( key->grp.id == MBEDTLS_ECP_DP_CURVE448 ) { if( buflen < ECP_CURVE448_KEY_SIZE ) - return( MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL ); + return MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL ; } MBEDTLS_MPI_CHK( mbedtls_mpi_write_binary_le( &key->d, buf, buflen ) ); } @@ -3175,7 +3175,7 @@ int mbedtls_ecp_write_key( mbedtls_ecp_keypair *key, #endif cleanup: - return( ret ); + return ret ; } @@ -3198,7 +3198,7 @@ int mbedtls_ecp_check_pub_priv( mbedtls_mpi_cmp_mpi( &pub->Q.Y, &prv->Q.Y ) || mbedtls_mpi_cmp_mpi( &pub->Q.Z, &prv->Q.Z ) ) { - return( MBEDTLS_ERR_ECP_BAD_INPUT_DATA ); + return MBEDTLS_ERR_ECP_BAD_INPUT_DATA ; } mbedtls_ecp_point_init( &Q ); @@ -3222,7 +3222,7 @@ cleanup: mbedtls_ecp_point_free( &Q ); mbedtls_ecp_group_free( &grp ); - return( ret ); + return ret ; } #if defined(MBEDTLS_SELF_TEST) @@ -3246,7 +3246,7 @@ static int self_test_rng( void *ctx, unsigned char *out, size_t len ) out[i] = (unsigned char) state; } - return( 0 ); + return 0 ; } /* Adjust the exponent to be a valid private point for the specified curve. @@ -3282,7 +3282,7 @@ static int self_test_adjust_exponent( const mbedtls_ecp_group *grp, goto cleanup; } cleanup: - return( ret ); + return ret ; } /* Calculate R = m.P for each m in exponents. Check that the number of @@ -3336,7 +3336,7 @@ cleanup: else mbedtls_printf( "passed\n" ); } - return( ret ); + return ret ; } /* @@ -3448,7 +3448,7 @@ cleanup: if( verbose != 0 ) mbedtls_printf( "\n" ); - return( ret ); + return ret ; } #endif /* MBEDTLS_SELF_TEST */ diff --git a/library/ecp_curves.c b/library/ecp_curves.c index 421a067bbf..280e4c8d1b 100644 --- a/library/ecp_curves.c +++ b/library/ecp_curves.c @@ -4509,7 +4509,7 @@ static const mbedtls_ecp_point brainpoolP512r1_T[32] = { #if defined(ECP_LOAD_GROUP) /* * 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 ) { @@ -4561,7 +4561,7 @@ static int ecp_group_load( mbedtls_ecp_group *grp, */ grp->T_size = 0; - return( 0 ); + return 0 ; } #endif /* ECP_LOAD_GROUP */ @@ -4669,7 +4669,7 @@ cleanup: if( ret != 0 ) mbedtls_ecp_group_free( grp ); - return( ret ); + return ret ; } #endif /* MBEDTLS_ECP_DP_CURVE25519_ENABLED */ @@ -4724,7 +4724,7 @@ cleanup: if( ret != 0 ) mbedtls_ecp_group_free( grp ); - return( ret ); + return ret ; } #endif /* MBEDTLS_ECP_DP_CURVE448_ENABLED */ @@ -4743,81 +4743,81 @@ int mbedtls_ecp_group_load( mbedtls_ecp_group *grp, mbedtls_ecp_group_id id ) #if defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED) case MBEDTLS_ECP_DP_SECP192R1: NIST_MODP( p192 ); - return( LOAD_GROUP( secp192r1 ) ); + return LOAD_GROUP( secp192r1 ) ; #endif /* MBEDTLS_ECP_DP_SECP192R1_ENABLED */ #if defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED) case MBEDTLS_ECP_DP_SECP224R1: NIST_MODP( p224 ); - return( LOAD_GROUP( secp224r1 ) ); + return LOAD_GROUP( secp224r1 ) ; #endif /* MBEDTLS_ECP_DP_SECP224R1_ENABLED */ #if defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED) case MBEDTLS_ECP_DP_SECP256R1: NIST_MODP( p256 ); - return( LOAD_GROUP( secp256r1 ) ); + return LOAD_GROUP( secp256r1 ) ; #endif /* MBEDTLS_ECP_DP_SECP256R1_ENABLED */ #if defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED) case MBEDTLS_ECP_DP_SECP384R1: NIST_MODP( p384 ); - return( LOAD_GROUP( secp384r1 ) ); + return LOAD_GROUP( secp384r1 ) ; #endif /* MBEDTLS_ECP_DP_SECP384R1_ENABLED */ #if defined(MBEDTLS_ECP_DP_SECP521R1_ENABLED) case MBEDTLS_ECP_DP_SECP521R1: NIST_MODP( p521 ); - return( LOAD_GROUP( secp521r1 ) ); + return LOAD_GROUP( secp521r1 ) ; #endif /* MBEDTLS_ECP_DP_SECP521R1_ENABLED */ #if defined(MBEDTLS_ECP_DP_SECP192K1_ENABLED) case MBEDTLS_ECP_DP_SECP192K1: grp->modp = ecp_mod_p192k1; - return( LOAD_GROUP_A( secp192k1 ) ); + return LOAD_GROUP_A( secp192k1 ) ; #endif /* MBEDTLS_ECP_DP_SECP192K1_ENABLED */ #if defined(MBEDTLS_ECP_DP_SECP224K1_ENABLED) case MBEDTLS_ECP_DP_SECP224K1: grp->modp = ecp_mod_p224k1; - return( LOAD_GROUP_A( secp224k1 ) ); + return LOAD_GROUP_A( secp224k1 ) ; #endif /* MBEDTLS_ECP_DP_SECP224K1_ENABLED */ #if defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED) case MBEDTLS_ECP_DP_SECP256K1: grp->modp = ecp_mod_p256k1; - return( LOAD_GROUP_A( secp256k1 ) ); + return LOAD_GROUP_A( secp256k1 ) ; #endif /* MBEDTLS_ECP_DP_SECP256K1_ENABLED */ #if defined(MBEDTLS_ECP_DP_BP256R1_ENABLED) case MBEDTLS_ECP_DP_BP256R1: - return( LOAD_GROUP_A( brainpoolP256r1 ) ); + return LOAD_GROUP_A( brainpoolP256r1 ) ; #endif /* MBEDTLS_ECP_DP_BP256R1_ENABLED */ #if defined(MBEDTLS_ECP_DP_BP384R1_ENABLED) case MBEDTLS_ECP_DP_BP384R1: - return( LOAD_GROUP_A( brainpoolP384r1 ) ); + return LOAD_GROUP_A( brainpoolP384r1 ) ; #endif /* MBEDTLS_ECP_DP_BP384R1_ENABLED */ #if defined(MBEDTLS_ECP_DP_BP512R1_ENABLED) case MBEDTLS_ECP_DP_BP512R1: - return( LOAD_GROUP_A( brainpoolP512r1 ) ); + return LOAD_GROUP_A( brainpoolP512r1 ) ; #endif /* MBEDTLS_ECP_DP_BP512R1_ENABLED */ #if defined(MBEDTLS_ECP_DP_CURVE25519_ENABLED) case MBEDTLS_ECP_DP_CURVE25519: grp->modp = ecp_mod_p255; - return( ecp_use_curve25519( grp ) ); + return ecp_use_curve25519( grp ) ; #endif /* MBEDTLS_ECP_DP_CURVE25519_ENABLED */ #if defined(MBEDTLS_ECP_DP_CURVE448_ENABLED) case MBEDTLS_ECP_DP_CURVE448: grp->modp = ecp_mod_p448; - return( ecp_use_curve448( grp ) ); + return ecp_use_curve448( grp ) ; #endif /* MBEDTLS_ECP_DP_CURVE448_ENABLED */ default: grp->id = MBEDTLS_ECP_DP_NONE; - return( MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE ; } } @@ -4895,7 +4895,7 @@ static int ecp_mod_p192( mbedtls_mpi *N ) ADD( 4 ); ADD( 5 ); LAST; // A2 += A4 + A5 cleanup: - return( ret ); + return ret ; } #undef WIDTH @@ -5048,7 +5048,7 @@ static int ecp_mod_p224( mbedtls_mpi *N ) SUB( 13 ); ADD( 10 ); LAST; // A6 += -A13 + A10 cleanup: - return( ret ); + return ret ; } #endif /* MBEDTLS_ECP_DP_SECP224R1_ENABLED */ @@ -5085,7 +5085,7 @@ static int ecp_mod_p256( mbedtls_mpi *N ) SUB( 10 ); SUB( 11 ); SUB( 12 ); SUB( 13 ); LAST; // A7 cleanup: - return( ret ); + return ret ; } #endif /* MBEDTLS_ECP_DP_SECP256R1_ENABLED */ @@ -5134,7 +5134,7 @@ static int ecp_mod_p384( mbedtls_mpi *N ) SUB( 22 ); LAST; // A11 cleanup: - return( ret ); + return ret ; } #endif /* MBEDTLS_ECP_DP_SECP384R1_ENABLED */ @@ -5177,7 +5177,7 @@ static int ecp_mod_p521( mbedtls_mpi *N ) * P521_WIDTH + 1. Otherwise P521_WIDTH is enough. */ if( N->n < P521_WIDTH ) - return( 0 ); + return 0 ; /* M = A1 */ M.s = 1; @@ -5197,7 +5197,7 @@ static int ecp_mod_p521( mbedtls_mpi *N ) MBEDTLS_MPI_CHK( mbedtls_mpi_add_abs( N, N, &M ) ); cleanup: - return( ret ); + return ret ; } #undef P521_WIDTH @@ -5223,15 +5223,15 @@ static int ecp_mod_p255( mbedtls_mpi *N ) mbedtls_mpi_uint Mp[P255_WIDTH + 2]; if( N->n < P255_WIDTH ) - return( 0 ); + return 0 ; /* M = A1 */ M.s = 1; M.n = N->n - ( P255_WIDTH - 1 ); if( M.n > P255_WIDTH + 1 ) - return( MBEDTLS_ERR_ECP_BAD_INPUT_DATA ); + return MBEDTLS_ERR_ECP_BAD_INPUT_DATA ; M.p = Mp; - memset( Mp, 0, sizeof Mp ); + memset( Mp, 0, sizeof(Mp) ); memcpy( Mp, N->p + P255_WIDTH - 1, M.n * sizeof( mbedtls_mpi_uint ) ); MBEDTLS_MPI_CHK( mbedtls_mpi_shift_r( &M, 255 % ( 8 * sizeof( mbedtls_mpi_uint ) ) ) ); M.n++; /* Make room for multiplication by 19 */ @@ -5246,7 +5246,7 @@ static int ecp_mod_p255( mbedtls_mpi *N ) MBEDTLS_MPI_CHK( mbedtls_mpi_add_abs( N, N, &M ) ); cleanup: - return( ret ); + return ret ; } #endif /* MBEDTLS_ECP_DP_CURVE25519_ENABLED */ @@ -5280,14 +5280,14 @@ static int ecp_mod_p448( mbedtls_mpi *N ) mbedtls_mpi_uint Mp[P448_WIDTH + 1], Qp[P448_WIDTH]; if( N->n <= P448_WIDTH ) - return( 0 ); + return 0 ; /* M = A1 */ M.s = 1; M.n = N->n - ( P448_WIDTH ); if( M.n > P448_WIDTH ) /* Shouldn't be called with N larger than 2^896! */ - return( MBEDTLS_ERR_ECP_BAD_INPUT_DATA ); + return MBEDTLS_ERR_ECP_BAD_INPUT_DATA ; M.p = Mp; memset( Mp, 0, sizeof( Mp ) ); memcpy( Mp, N->p + P448_WIDTH, M.n * sizeof( mbedtls_mpi_uint ) ); @@ -5317,7 +5317,7 @@ static int ecp_mod_p448( mbedtls_mpi *N ) MBEDTLS_MPI_CHK( mbedtls_mpi_add_mpi( N, N, &M ) ); cleanup: - return( ret ); + return ret ; } #endif /* MBEDTLS_ECP_DP_CURVE448_ENABLED */ @@ -5342,7 +5342,7 @@ static inline int ecp_mod_koblitz( mbedtls_mpi *N, mbedtls_mpi_uint *Rp, size_t mbedtls_mpi_uint Mp[P_KOBLITZ_MAX + P_KOBLITZ_R + 1]; if( N->n < p_limbs ) - return( 0 ); + return 0 ; /* Init R */ R.s = 1; @@ -5357,7 +5357,7 @@ static inline int ecp_mod_koblitz( mbedtls_mpi *N, mbedtls_mpi_uint *Rp, size_t M.n = N->n - ( p_limbs - adjust ); 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 ) ); @@ -5379,7 +5379,7 @@ static inline int ecp_mod_koblitz( mbedtls_mpi *N, mbedtls_mpi_uint *Rp, size_t M.n = N->n - ( p_limbs - adjust ); 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 MBEDTLS_MPI_CHK( mbedtls_mpi_add_abs( N, N, &M ) ); cleanup: - return( ret ); + return ret ; } #endif /* MBEDTLS_ECP_DP_SECP192K1_ENABLED) || MBEDTLS_ECP_DP_SECP224K1_ENABLED) || @@ -5430,7 +5430,7 @@ static int ecp_mod_p224k1( mbedtls_mpi *N ) 0x00 ) }; #if defined(MBEDTLS_HAVE_INT64) - return( ecp_mod_koblitz( N, Rp, 4, 1, 32, 0xFFFFFFFF ) ); + return ecp_mod_koblitz( N, Rp, 4, 1, 32, 0xFFFFFFFF ) ; #else return( ecp_mod_koblitz( N, Rp, 224 / 8 / sizeof( mbedtls_mpi_uint ), 0, 0, 0 ) ); diff --git a/library/entropy.c b/library/entropy.c index 9e31f8491e..4b39231a43 100644 --- a/library/entropy.c +++ b/library/entropy.c @@ -118,7 +118,7 @@ int mbedtls_entropy_add_source( mbedtls_entropy_context *ctx, #if defined(MBEDTLS_THREADING_C) if( ( ret = mbedtls_mutex_lock( &ctx->mutex ) ) != 0 ) - return( ret ); + return ret ; #endif idx = ctx->source_count; @@ -138,10 +138,10 @@ int mbedtls_entropy_add_source( mbedtls_entropy_context *ctx, exit: #if defined(MBEDTLS_THREADING_C) if( mbedtls_mutex_unlock( &ctx->mutex ) != 0 ) - return( MBEDTLS_ERR_THREADING_MUTEX_ERROR ); + return MBEDTLS_ERR_THREADING_MUTEX_ERROR ; #endif - return( ret ); + return ret ; } /* @@ -200,7 +200,7 @@ static int entropy_update( mbedtls_entropy_context *ctx, unsigned char source_id cleanup: mbedtls_platform_zeroize( tmp, sizeof( tmp ) ); - return( ret ); + return ret ; } int mbedtls_entropy_update_manual( mbedtls_entropy_context *ctx, @@ -210,17 +210,17 @@ int mbedtls_entropy_update_manual( mbedtls_entropy_context *ctx, #if defined(MBEDTLS_THREADING_C) if( ( ret = mbedtls_mutex_lock( &ctx->mutex ) ) != 0 ) - return( ret ); + return ret ; #endif ret = entropy_update( ctx, MBEDTLS_ENTROPY_SOURCE_MANUAL, data, len ); #if defined(MBEDTLS_THREADING_C) if( mbedtls_mutex_unlock( &ctx->mutex ) != 0 ) - return( MBEDTLS_ERR_THREADING_MUTEX_ERROR ); + return MBEDTLS_ERR_THREADING_MUTEX_ERROR ; #endif - return( ret ); + return ret ; } /* @@ -235,7 +235,7 @@ static int entropy_gather_internal( mbedtls_entropy_context *ctx ) size_t olen; if( ctx->source_count == 0 ) - return( MBEDTLS_ERR_ENTROPY_NO_SOURCES_DEFINED ); + return MBEDTLS_ERR_ENTROPY_NO_SOURCES_DEFINED ; /* * Run through our entropy sources @@ -259,7 +259,7 @@ static int entropy_gather_internal( mbedtls_entropy_context *ctx ) { if( ( ret = entropy_update( ctx, (unsigned char) i, buf, olen ) ) != 0 ) - return( ret ); + return ret ; ctx->source[i].size += olen; } } @@ -270,7 +270,7 @@ static int entropy_gather_internal( mbedtls_entropy_context *ctx ) cleanup: mbedtls_platform_zeroize( buf, sizeof( buf ) ); - return( ret ); + return ret ; } /* @@ -282,17 +282,17 @@ int mbedtls_entropy_gather( mbedtls_entropy_context *ctx ) #if defined(MBEDTLS_THREADING_C) if( ( ret = mbedtls_mutex_lock( &ctx->mutex ) ) != 0 ) - return( ret ); + return ret ; #endif ret = entropy_gather_internal( ctx ); #if defined(MBEDTLS_THREADING_C) if( mbedtls_mutex_unlock( &ctx->mutex ) != 0 ) - return( MBEDTLS_ERR_THREADING_MUTEX_ERROR ); + return MBEDTLS_ERR_THREADING_MUTEX_ERROR ; #endif - return( ret ); + return ret ; } int mbedtls_entropy_func( void *data, unsigned char *output, size_t len ) @@ -303,7 +303,7 @@ int mbedtls_entropy_func( void *data, unsigned char *output, size_t len ) unsigned char buf[MBEDTLS_ENTROPY_BLOCK_SIZE]; if( len > MBEDTLS_ENTROPY_BLOCK_SIZE ) - return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED ); + return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED ; #if defined(MBEDTLS_ENTROPY_NV_SEED) /* Update the NV entropy seed before generating any entropy for outside @@ -313,13 +313,13 @@ int mbedtls_entropy_func( void *data, unsigned char *output, size_t len ) { ctx->initial_entropy_run = 1; if( ( ret = mbedtls_entropy_update_nv_seed( ctx ) ) != 0 ) - return( ret ); + return ret ; } #endif #if defined(MBEDTLS_THREADING_C) if( ( ret = mbedtls_mutex_lock( &ctx->mutex ) ) != 0 ) - return( ret ); + return ret ; #endif /* @@ -411,10 +411,10 @@ exit: #if defined(MBEDTLS_THREADING_C) if( mbedtls_mutex_unlock( &ctx->mutex ) != 0 ) - return( MBEDTLS_ERR_THREADING_MUTEX_ERROR ); + return MBEDTLS_ERR_THREADING_MUTEX_ERROR ; #endif - return( ret ); + return ret ; } #if defined(MBEDTLS_ENTROPY_NV_SEED) @@ -425,16 +425,16 @@ int mbedtls_entropy_update_nv_seed( mbedtls_entropy_context *ctx ) /* Read new seed and write it to NV */ if( ( ret = mbedtls_entropy_func( ctx, buf, MBEDTLS_ENTROPY_BLOCK_SIZE ) ) != 0 ) - return( ret ); + return ret ; if( mbedtls_nv_seed_write( buf, MBEDTLS_ENTROPY_BLOCK_SIZE ) < 0 ) - return( MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR ); + return MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR ; /* Manually update the remaining stream with a separator value to diverge */ memset( buf, 0, MBEDTLS_ENTROPY_BLOCK_SIZE ); ret = mbedtls_entropy_update_manual( ctx, buf, MBEDTLS_ENTROPY_BLOCK_SIZE ); - return( ret ); + return ret ; } #endif /* MBEDTLS_ENTROPY_NV_SEED */ @@ -471,7 +471,7 @@ exit: if( f != NULL ) fclose( f ); - return( ret ); + return ret ; } int mbedtls_entropy_update_seed_file( mbedtls_entropy_context *ctx, const char *path ) @@ -482,7 +482,7 @@ int mbedtls_entropy_update_seed_file( mbedtls_entropy_context *ctx, const char * unsigned char buf[ MBEDTLS_ENTROPY_MAX_SEED_SIZE ]; if( ( f = fopen( path, "rb" ) ) == NULL ) - return( MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR ); + return MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR ; fseek( f, 0, SEEK_END ); n = (size_t) ftell( f ); @@ -501,9 +501,9 @@ int mbedtls_entropy_update_seed_file( mbedtls_entropy_context *ctx, const char * mbedtls_platform_zeroize( buf, sizeof( buf ) ); if( ret != 0 ) - return( ret ); + return ret ; - return( mbedtls_entropy_write_seed_file( ctx, path ) ); + return mbedtls_entropy_write_seed_file( ctx, path ) ; } #endif /* MBEDTLS_FS_IO */ @@ -519,7 +519,7 @@ static int entropy_dummy_source( void *data, unsigned char *output, memset( output, 0x2a, len ); *olen = len; - return( 0 ); + return 0 ; } #if defined(MBEDTLS_ENTROPY_HARDWARE_ALT) @@ -535,7 +535,7 @@ static int mbedtls_entropy_source_self_test_gather( unsigned char *buf, size_t b { if( ( ret = mbedtls_hardware_poll( NULL, buf + entropy_len, buf_len - entropy_len, &olen ) ) != 0 ) - return( ret ); + return ret ; entropy_len += olen; attempts--; @@ -546,7 +546,7 @@ static int mbedtls_entropy_source_self_test_gather( unsigned char *buf, size_t b ret = 1; } - return( ret ); + return ret ; } @@ -563,7 +563,7 @@ static int mbedtls_entropy_source_self_test_check_bits( const unsigned char *buf unset |= buf[i]; } - return( set == 0xFF || unset == 0x00 ); + return set == 0xFF || unset == 0x00 ; } /* @@ -615,7 +615,7 @@ cleanup: mbedtls_printf( "\n" ); } - return( ret != 0 ); + return ret != 0 ; } #endif /* MBEDTLS_ENTROPY_HARDWARE_ALT */ @@ -647,7 +647,7 @@ int mbedtls_entropy_self_test( int verbose ) if( ret != 0 ) 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; /* @@ -694,7 +694,7 @@ cleanup: mbedtls_printf( "\n" ); } - return( ret != 0 ); + return ret != 0 ; } #endif /* MBEDTLS_SELF_TEST */ diff --git a/library/entropy_poll.c b/library/entropy_poll.c index 058c307dfb..7153e664dc 100644 --- a/library/entropy_poll.c +++ b/library/entropy_poll.c @@ -65,19 +65,19 @@ int mbedtls_platform_entropy_poll( void *data, unsigned char *output, size_t len if( CryptAcquireContext( &provider, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT ) == FALSE ) { - return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED ); + return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED ; } if( CryptGenRandom( provider, (DWORD) len, output ) == FALSE ) { CryptReleaseContext( provider, 0 ); - return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED ); + return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED ; } CryptReleaseContext( provider, 0 ); *olen = len; - return( 0 ); + return 0 ; } #else /* _WIN32 && !EFIX64 && !EFI32 */ @@ -101,7 +101,7 @@ static int getrandom_wrapper( void *buf, size_t buflen, unsigned int flags ) memset( buf, 0, buflen ); #endif #endif - return( syscall( SYS_getrandom, buf, buflen, flags ) ); + return syscall( SYS_getrandom, buf, buflen, flags ) ; } #endif /* SYS_getrandom */ #endif /* __linux__ || __midipix__ */ @@ -147,11 +147,11 @@ static int sysctl_arnd_wrapper( unsigned char *buf, size_t buflen ) { len = buflen > 256 ? 256 : buflen; if( sysctl(name, 2, buf, &len, NULL, 0) == -1 ) - return( -1 ); + return -1 ; buflen -= len; buf += len; } - return( 0 ); + return 0 ; } #endif /* KERN_ARND */ #endif /* __FreeBSD__ || __NetBSD__ */ @@ -171,10 +171,10 @@ int mbedtls_platform_entropy_poll( void *data, if( ret >= 0 ) { *olen = ret; - return( 0 ); + return 0 ; } else if( errno != ENOSYS ) - return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED ); + return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED ; /* Fall through if the system call isn't known. */ #else ((void) ret); @@ -184,28 +184,28 @@ int mbedtls_platform_entropy_poll( void *data, ((void) file); ((void) read_len); if( sysctl_arnd_wrapper( output, len ) == -1 ) - return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED ); + return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED ; *olen = len; - return( 0 ); + return 0 ; #else *olen = 0; file = fopen( "/dev/urandom", "rb" ); if( file == NULL ) - return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED ); + return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED ; read_len = fread( output, 1, len, file ); if( read_len != len ) { fclose( file ); - return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED ); + return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED ; } fclose( file ); *olen = len; - return( 0 ); + return 0 ; #endif /* HAVE_SYSCTL_ARND */ } #endif /* _WIN32 && !EFIX64 && !EFI32 */ @@ -222,7 +222,7 @@ int mbedtls_nv_seed_poll( void *data, memset( buf, 0, MBEDTLS_ENTROPY_BLOCK_SIZE ); if( mbedtls_nv_seed_read( buf, MBEDTLS_ENTROPY_BLOCK_SIZE ) < 0 ) - return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED ); + return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED ; if( len < use_len ) use_len = len; @@ -230,7 +230,7 @@ int mbedtls_nv_seed_poll( void *data, memcpy( output, buf, use_len ); *olen = use_len; - return( 0 ); + return 0 ; } #endif /* MBEDTLS_ENTROPY_NV_SEED */ diff --git a/library/gcm.c b/library/gcm.c index 835b1b2853..123777de47 100644 --- a/library/gcm.c +++ b/library/gcm.c @@ -108,7 +108,7 @@ static int gcm_gen_table( mbedtls_gcm_context *ctx ) memset( h, 0, 16 ); if( ( ret = mbedtls_cipher_update( &ctx->cipher_ctx, h, 16, h, &olen ) ) != 0 ) - return( ret ); + return ret ; /* pack h as two 64-bits ints, big-endian */ GET_UINT32_BE( hi, h, 0 ); @@ -126,7 +126,7 @@ static int gcm_gen_table( mbedtls_gcm_context *ctx ) #if defined(MBEDTLS_AESNI_C) && defined(MBEDTLS_HAVE_X86_64) /* With CLMUL support, we need only h, not the rest of the table */ if( mbedtls_aesni_has_support( MBEDTLS_AESNI_CLMUL ) ) - return( 0 ); + return 0 ; #endif /* 0 corresponds to 0 in GF(2^128) */ @@ -155,7 +155,7 @@ static int gcm_gen_table( mbedtls_gcm_context *ctx ) } } - return( 0 ); + return 0 ; } int mbedtls_gcm_setkey( mbedtls_gcm_context *ctx, @@ -173,26 +173,26 @@ int mbedtls_gcm_setkey( mbedtls_gcm_context *ctx, cipher_info = mbedtls_cipher_info_from_values( cipher, keybits, MBEDTLS_MODE_ECB ); if( cipher_info == NULL ) - return( MBEDTLS_ERR_GCM_BAD_INPUT ); + return MBEDTLS_ERR_GCM_BAD_INPUT ; if( cipher_info->block_size != 16 ) - return( MBEDTLS_ERR_GCM_BAD_INPUT ); + return MBEDTLS_ERR_GCM_BAD_INPUT ; mbedtls_cipher_free( &ctx->cipher_ctx ); if( ( ret = mbedtls_cipher_setup( &ctx->cipher_ctx, cipher_info ) ) != 0 ) - return( ret ); + return ret ; if( ( ret = mbedtls_cipher_setkey( &ctx->cipher_ctx, key, keybits, MBEDTLS_ENCRYPT ) ) != 0 ) { - return( ret ); + return ret ; } if( ( ret = gcm_gen_table( ctx ) ) != 0 ) - return( ret ); + return ret ; - return( 0 ); + return 0 ; } /* @@ -284,7 +284,7 @@ int mbedtls_gcm_starts( mbedtls_gcm_context *ctx, /* IV is limited to 2^64 bits, so 2^61 bytes */ /* IV is not allowed to be zero length */ if( iv_len == 0 || (uint64_t) iv_len >> 61 != 0 ) - return( MBEDTLS_ERR_GCM_BAD_INPUT ); + return MBEDTLS_ERR_GCM_BAD_INPUT ; memset( ctx->y, 0x00, sizeof(ctx->y) ); memset( ctx->buf, 0x00, sizeof(ctx->buf) ); @@ -326,10 +326,10 @@ int mbedtls_gcm_starts( mbedtls_gcm_context *ctx, if( ( ret = mbedtls_cipher_update( &ctx->cipher_ctx, ctx->y, 16, ctx->base_ectr, &olen ) ) != 0 ) { - return( ret ); + return ret ; } - return( 0 ); + return 0 ; } /** @@ -359,7 +359,7 @@ int mbedtls_gcm_update_ad( mbedtls_gcm_context *ctx, /* IV is limited to 2^64 bits, so 2^61 bytes */ if( (uint64_t) add_len >> 61 != 0 ) - return( MBEDTLS_ERR_GCM_BAD_INPUT ); + return MBEDTLS_ERR_GCM_BAD_INPUT ; offset = ctx->add_len % 16; p = add; @@ -400,7 +400,7 @@ int mbedtls_gcm_update_ad( mbedtls_gcm_context *ctx, ctx->buf[i] ^= p[i]; } - return( 0 ); + return 0 ; } /* Increment the counter. */ @@ -428,7 +428,7 @@ static int gcm_mask( mbedtls_gcm_context *ctx, &olen ) ) != 0 ) { mbedtls_platform_zeroize( ectr, 16 ); - return( ret ); + return ret ; } for( i = 0; i < use_len; i++ ) @@ -439,7 +439,7 @@ static int gcm_mask( mbedtls_gcm_context *ctx, if( ctx->mode == MBEDTLS_GCM_ENCRYPT ) ctx->buf[offset + i] ^= output[i]; } - return( 0 ); + return 0 ; } int mbedtls_gcm_update( mbedtls_gcm_context *ctx, @@ -454,7 +454,7 @@ int mbedtls_gcm_update( mbedtls_gcm_context *ctx, unsigned char ectr[16]; if( output_size < input_length ) - return( MBEDTLS_ERR_GCM_BAD_INPUT ); + return MBEDTLS_ERR_GCM_BAD_INPUT ; GCM_VALIDATE_RET( output_length != NULL ); *output_length = input_length; @@ -463,21 +463,21 @@ int mbedtls_gcm_update( mbedtls_gcm_context *ctx, * Returning early also means that the last partial block of AD remains * untouched for mbedtls_gcm_finish */ if( input_length == 0 ) - return( 0 ); + return 0 ; GCM_VALIDATE_RET( ctx != NULL ); GCM_VALIDATE_RET( input != NULL ); GCM_VALIDATE_RET( output != NULL ); if( output > input && (size_t) ( output - input ) < input_length ) - return( MBEDTLS_ERR_GCM_BAD_INPUT ); + return MBEDTLS_ERR_GCM_BAD_INPUT ; /* Total length is restricted to 2^39 - 256 bits, ie 2^36 - 2^5 bytes * Also check for possible overflow */ if( ctx->len + input_length < ctx->len || (uint64_t) ctx->len + input_length > 0xFFFFFFFE0ull ) { - return( MBEDTLS_ERR_GCM_BAD_INPUT ); + return MBEDTLS_ERR_GCM_BAD_INPUT ; } if( ctx->len == 0 && ctx->add_len % 16 != 0 ) @@ -493,7 +493,7 @@ int mbedtls_gcm_update( mbedtls_gcm_context *ctx, use_len = input_length; if( ( ret = gcm_mask( ctx, ectr, offset, use_len, p, out_p ) ) != 0 ) - return( ret ); + return ret ; if( offset + use_len == 16 ) gcm_mult( ctx, ctx->buf, ctx->buf ); @@ -510,7 +510,7 @@ int mbedtls_gcm_update( mbedtls_gcm_context *ctx, { gcm_incr( ctx->y ); if( ( ret = gcm_mask( ctx, ectr, 0, 16, p, out_p ) ) != 0 ) - return( ret ); + return ret ; gcm_mult( ctx, ctx->buf, ctx->buf ); @@ -523,11 +523,11 @@ int mbedtls_gcm_update( mbedtls_gcm_context *ctx, { gcm_incr( ctx->y ); if( ( ret = gcm_mask( ctx, ectr, 0, input_length, p, out_p ) ) != 0 ) - return( ret ); + return ret ; } mbedtls_platform_zeroize( ectr, sizeof( ectr ) ); - return( 0 ); + return 0 ; } int mbedtls_gcm_finish( mbedtls_gcm_context *ctx, @@ -558,7 +558,7 @@ int mbedtls_gcm_finish( mbedtls_gcm_context *ctx, } if( tag_len > 16 || tag_len < 4 ) - return( MBEDTLS_ERR_GCM_BAD_INPUT ); + return MBEDTLS_ERR_GCM_BAD_INPUT ; if( ctx->len % 16 != 0 ) gcm_mult( ctx, ctx->buf, ctx->buf ); @@ -583,7 +583,7 @@ int mbedtls_gcm_finish( mbedtls_gcm_context *ctx, tag[i] ^= ctx->buf[i]; } - return( 0 ); + return 0 ; } int mbedtls_gcm_crypt_and_tag( mbedtls_gcm_context *ctx, @@ -609,19 +609,19 @@ int mbedtls_gcm_crypt_and_tag( mbedtls_gcm_context *ctx, GCM_VALIDATE_RET( tag != NULL ); if( ( ret = mbedtls_gcm_starts( ctx, mode, iv, iv_len ) ) != 0 ) - return( ret ); + return ret ; if( ( ret = mbedtls_gcm_update_ad( ctx, add, add_len ) ) != 0 ) - return( ret ); + return ret ; if( ( ret = mbedtls_gcm_update( ctx, input, length, output, length, &olen ) ) != 0 ) - return( ret ); + return ret ; if( ( ret = mbedtls_gcm_finish( ctx, NULL, 0, &olen, tag, tag_len ) ) != 0 ) - return( ret ); + return ret ; - return( 0 ); + return 0 ; } int mbedtls_gcm_auth_decrypt( mbedtls_gcm_context *ctx, @@ -651,7 +651,7 @@ int mbedtls_gcm_auth_decrypt( mbedtls_gcm_context *ctx, iv, iv_len, add, add_len, input, output, tag_len, check_tag ) ) != 0 ) { - return( ret ); + return ret ; } /* Check tag in "constant-time" */ @@ -661,10 +661,10 @@ int mbedtls_gcm_auth_decrypt( mbedtls_gcm_context *ctx, if( diff != 0 ) { mbedtls_platform_zeroize( output, length ); - return( MBEDTLS_ERR_GCM_AUTH_FAILED ); + return MBEDTLS_ERR_GCM_AUTH_FAILED ; } - return( 0 ); + return 0 ; } void mbedtls_gcm_free( mbedtls_gcm_context *ctx ) @@ -1174,7 +1174,7 @@ exit: mbedtls_gcm_free( &ctx ); } - return( ret ); + return ret ; } #endif /* MBEDTLS_SELF_TEST && MBEDTLS_AES_C */ diff --git a/library/hkdf.c b/library/hkdf.c index 5013729d2a..6c7082bf3b 100644 --- a/library/hkdf.c +++ b/library/hkdf.c @@ -43,7 +43,7 @@ int mbedtls_hkdf( const mbedtls_md_info_t *md, const unsigned char *salt, mbedtls_platform_zeroize( prk, sizeof( prk ) ); - return( ret ); + return ret ; } int mbedtls_hkdf_extract( const mbedtls_md_info_t *md, @@ -73,7 +73,7 @@ int mbedtls_hkdf_extract( const mbedtls_md_info_t *md, salt_len = hash_len; } - return( mbedtls_md_hmac( md, salt, salt_len, ikm, ikm_len, prk ) ); + return mbedtls_md_hmac( md, salt, salt_len, ikm, ikm_len, prk ) ; } int mbedtls_hkdf_expand( const mbedtls_md_info_t *md, const unsigned char *prk, @@ -91,14 +91,14 @@ int mbedtls_hkdf_expand( const mbedtls_md_info_t *md, const unsigned char *prk, if( okm == NULL ) { - return( MBEDTLS_ERR_HKDF_BAD_INPUT_DATA ); + return MBEDTLS_ERR_HKDF_BAD_INPUT_DATA ; } hash_len = mbedtls_md_get_size( md ); if( prk_len < hash_len || hash_len == 0 ) { - return( MBEDTLS_ERR_HKDF_BAD_INPUT_DATA ); + return MBEDTLS_ERR_HKDF_BAD_INPUT_DATA ; } if( info == NULL ) @@ -120,7 +120,7 @@ int mbedtls_hkdf_expand( const mbedtls_md_info_t *md, const unsigned char *prk, */ if( n > 255 ) { - return( MBEDTLS_ERR_HKDF_BAD_INPUT_DATA ); + return MBEDTLS_ERR_HKDF_BAD_INPUT_DATA ; } mbedtls_md_init( &ctx ); @@ -183,7 +183,7 @@ exit: mbedtls_md_free( &ctx ); mbedtls_platform_zeroize( t, sizeof( t ) ); - return( ret ); + return ret ; } #endif /* MBEDTLS_HKDF_C */ diff --git a/library/hmac_drbg.c b/library/hmac_drbg.c index ab353bfd58..954d08871d 100644 --- a/library/hmac_drbg.c +++ b/library/hmac_drbg.c @@ -101,7 +101,7 @@ int mbedtls_hmac_drbg_update( mbedtls_hmac_drbg_context *ctx, exit: mbedtls_platform_zeroize( K, sizeof( K ) ); - return( ret ); + return ret ; } /* @@ -114,7 +114,7 @@ int mbedtls_hmac_drbg_seed_buf( mbedtls_hmac_drbg_context *ctx, int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; if( ( ret = mbedtls_md_setup( &ctx->md_ctx, md_info, 1 ) ) != 0 ) - return( ret ); + return ret ; #if defined(MBEDTLS_THREADING_C) mbedtls_mutex_init( &ctx->mutex ); @@ -127,13 +127,13 @@ int mbedtls_hmac_drbg_seed_buf( mbedtls_hmac_drbg_context *ctx, */ if( ( ret = mbedtls_md_hmac_starts( &ctx->md_ctx, ctx->V, mbedtls_md_get_size( md_info ) ) ) != 0 ) - return( ret ); + return ret ; memset( ctx->V, 0x01, mbedtls_md_get_size( md_info ) ); if( ( ret = mbedtls_hmac_drbg_update( ctx, data, data_len ) ) != 0 ) - return( ret ); + return ret ; - return( 0 ); + return 0 ; } /* @@ -161,7 +161,7 @@ static int hmac_drbg_reseed_core( mbedtls_hmac_drbg_context *ctx, if( len > MBEDTLS_HMAC_DRBG_MAX_INPUT || total_entropy_len + len > MBEDTLS_HMAC_DRBG_MAX_SEED_INPUT ) { - return( MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG ); + return MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG ; } } @@ -171,7 +171,7 @@ static int hmac_drbg_reseed_core( mbedtls_hmac_drbg_context *ctx, if( ( ret = ctx->f_entropy( ctx->p_entropy, seed, ctx->entropy_len ) ) != 0 ) { - return( MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED ); + return MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED ; } seedlen += ctx->entropy_len; @@ -190,7 +190,7 @@ static int hmac_drbg_reseed_core( mbedtls_hmac_drbg_context *ctx, seed + seedlen, ctx->entropy_len / 2 ) ) != 0 ) { - return( MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED ); + return MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED ; } seedlen += ctx->entropy_len / 2; @@ -214,7 +214,7 @@ static int hmac_drbg_reseed_core( mbedtls_hmac_drbg_context *ctx, exit: /* 4. Done */ mbedtls_platform_zeroize( seed, seedlen ); - return( ret ); + return ret ; } /* @@ -223,7 +223,7 @@ exit: int mbedtls_hmac_drbg_reseed( mbedtls_hmac_drbg_context *ctx, const unsigned char *additional, size_t len ) { - return( hmac_drbg_reseed_core( ctx, additional, len, 0 ) ); + return hmac_drbg_reseed_core( ctx, additional, len, 0 ) ; } /* @@ -243,7 +243,7 @@ int mbedtls_hmac_drbg_seed( mbedtls_hmac_drbg_context *ctx, size_t md_size; if( ( ret = mbedtls_md_setup( &ctx->md_ctx, md_info, 1 ) ) != 0 ) - return( ret ); + return ret ; /* The mutex is initialized iff the md context is set up. */ #if defined(MBEDTLS_THREADING_C) @@ -258,7 +258,7 @@ int mbedtls_hmac_drbg_seed( mbedtls_hmac_drbg_context *ctx, * MD context with an all-zero key. Then set V to its initial value. */ if( ( ret = mbedtls_md_hmac_starts( &ctx->md_ctx, ctx->V, md_size ) ) != 0 ) - return( ret ); + return ret ; memset( ctx->V, 0x01, md_size ); ctx->f_entropy = f_entropy; @@ -281,10 +281,10 @@ int mbedtls_hmac_drbg_seed( mbedtls_hmac_drbg_context *ctx, if( ( ret = hmac_drbg_reseed_core( ctx, custom, len, 1 /* add nonce */ ) ) != 0 ) { - return( ret ); + return ret ; } - return( 0 ); + return 0 ; } /* @@ -328,11 +328,11 @@ int mbedtls_hmac_drbg_random_with_add( void *p_rng, /* II. Check request length */ if( out_len > MBEDTLS_HMAC_DRBG_MAX_REQUEST ) - return( MBEDTLS_ERR_HMAC_DRBG_REQUEST_TOO_BIG ); + return MBEDTLS_ERR_HMAC_DRBG_REQUEST_TOO_BIG ; /* III. Check input length */ if( add_len > MBEDTLS_HMAC_DRBG_MAX_INPUT ) - return( MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG ); + return MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG ; /* 1. (aka VII and IX) Check reseed counter and PR */ if( ctx->f_entropy != NULL && /* For no-reseeding instances */ @@ -340,7 +340,7 @@ int mbedtls_hmac_drbg_random_with_add( void *p_rng, ctx->reseed_counter > ctx->reseed_interval ) ) { if( ( ret = mbedtls_hmac_drbg_reseed( ctx, additional, add_len ) ) != 0 ) - return( ret ); + return ret ; add_len = 0; /* VII.4 */ } @@ -381,7 +381,7 @@ int mbedtls_hmac_drbg_random_with_add( void *p_rng, exit: /* 8. Done */ - return( ret ); + return ret ; } /* @@ -394,17 +394,17 @@ int mbedtls_hmac_drbg_random( void *p_rng, unsigned char *output, size_t out_len #if defined(MBEDTLS_THREADING_C) if( ( ret = mbedtls_mutex_lock( &ctx->mutex ) ) != 0 ) - return( ret ); + return ret ; #endif ret = mbedtls_hmac_drbg_random_with_add( ctx, output, out_len, NULL, 0 ); #if defined(MBEDTLS_THREADING_C) if( mbedtls_mutex_unlock( &ctx->mutex ) != 0 ) - return( MBEDTLS_ERR_THREADING_MUTEX_ERROR ); + return MBEDTLS_ERR_THREADING_MUTEX_ERROR ; #endif - return( ret ); + return ret ; } /* @@ -434,7 +434,7 @@ int mbedtls_hmac_drbg_write_seed_file( mbedtls_hmac_drbg_context *ctx, const cha unsigned char buf[ MBEDTLS_HMAC_DRBG_MAX_INPUT ]; if( ( f = fopen( path, "wb" ) ) == NULL ) - return( MBEDTLS_ERR_HMAC_DRBG_FILE_IO_ERROR ); + return MBEDTLS_ERR_HMAC_DRBG_FILE_IO_ERROR ; if( ( ret = mbedtls_hmac_drbg_random( ctx, buf, sizeof( buf ) ) ) != 0 ) goto exit; @@ -451,7 +451,7 @@ exit: fclose( f ); mbedtls_platform_zeroize( buf, sizeof( buf ) ); - return( ret ); + return ret ; } int mbedtls_hmac_drbg_update_seed_file( mbedtls_hmac_drbg_context *ctx, const char *path ) @@ -463,7 +463,7 @@ int mbedtls_hmac_drbg_update_seed_file( mbedtls_hmac_drbg_context *ctx, const ch unsigned char c; if( ( f = fopen( path, "rb" ) ) == NULL ) - return( MBEDTLS_ERR_HMAC_DRBG_FILE_IO_ERROR ); + return MBEDTLS_ERR_HMAC_DRBG_FILE_IO_ERROR ; n = fread( buf, 1, sizeof( buf ), f ); if( fread( &c, 1, 1, f ) != 0 ) @@ -486,8 +486,8 @@ exit: if( f != NULL ) fclose( f ); if( ret != 0 ) - return( ret ); - return( mbedtls_hmac_drbg_write_seed_file( ctx, path ) ); + return ret ; + return mbedtls_hmac_drbg_write_seed_file( ctx, path ) ; } #endif /* MBEDTLS_FS_IO */ @@ -499,7 +499,7 @@ exit: int mbedtls_hmac_drbg_self_test( int verbose ) { (void) verbose; - return( 0 ); + return 0 ; } #else @@ -544,14 +544,14 @@ static int hmac_drbg_self_test_entropy( void *data, const unsigned char *p = data; memcpy( buf, p + test_offset, len ); test_offset += len; - return( 0 ); + return 0 ; } #define CHK( c ) if( (c) != 0 ) \ { \ if( verbose != 0 ) \ mbedtls_printf( "failed\n" ); \ - return( 1 ); \ + return 1 ; \ } /* @@ -612,7 +612,7 @@ int mbedtls_hmac_drbg_self_test( int verbose ) if( verbose != 0 ) mbedtls_printf( "\n" ); - return( 0 ); + return 0 ; } #endif /* MBEDTLS_SHA1_C */ #endif /* MBEDTLS_SELF_TEST */ diff --git a/library/md.c b/library/md.c index a228789653..6d27e08d2f 100644 --- a/library/md.c +++ b/library/md.c @@ -150,13 +150,13 @@ static const int supported_digests[] = { const int *mbedtls_md_list( void ) { - return( supported_digests ); + return supported_digests ; } const mbedtls_md_info_t *mbedtls_md_info_from_string( const char *md_name ) { if( NULL == md_name ) - return( NULL ); + return NULL ; /* Get the appropriate digest information */ #if defined(MBEDTLS_MD5_C) @@ -187,7 +187,7 @@ const mbedtls_md_info_t *mbedtls_md_info_from_string( const char *md_name ) if( !strcmp( "SHA512", md_name ) ) return mbedtls_md_info_from_type( MBEDTLS_MD_SHA512 ); #endif - return( NULL ); + return NULL ; } const mbedtls_md_info_t *mbedtls_md_info_from_type( mbedtls_md_type_t md_type ) @@ -196,34 +196,34 @@ const mbedtls_md_info_t *mbedtls_md_info_from_type( mbedtls_md_type_t md_type ) { #if defined(MBEDTLS_MD5_C) case MBEDTLS_MD_MD5: - return( &mbedtls_md5_info ); + return &mbedtls_md5_info ; #endif #if defined(MBEDTLS_RIPEMD160_C) case MBEDTLS_MD_RIPEMD160: - return( &mbedtls_ripemd160_info ); + return &mbedtls_ripemd160_info ; #endif #if defined(MBEDTLS_SHA1_C) case MBEDTLS_MD_SHA1: - return( &mbedtls_sha1_info ); + return &mbedtls_sha1_info ; #endif #if defined(MBEDTLS_SHA224_C) case MBEDTLS_MD_SHA224: - return( &mbedtls_sha224_info ); + return &mbedtls_sha224_info ; #endif #if defined(MBEDTLS_SHA256_C) case MBEDTLS_MD_SHA256: - return( &mbedtls_sha256_info ); + return &mbedtls_sha256_info ; #endif #if defined(MBEDTLS_SHA384_C) case MBEDTLS_MD_SHA384: - return( &mbedtls_sha384_info ); + return &mbedtls_sha384_info ; #endif #if defined(MBEDTLS_SHA512_C) case MBEDTLS_MD_SHA512: - return( &mbedtls_sha512_info ); + return &mbedtls_sha512_info ; #endif default: - return( NULL ); + return NULL ; } } @@ -300,7 +300,7 @@ int mbedtls_md_clone( mbedtls_md_context_t *dst, src == NULL || src->md_info == NULL || dst->md_info != src->md_info ) { - return( MBEDTLS_ERR_MD_BAD_INPUT_DATA ); + return MBEDTLS_ERR_MD_BAD_INPUT_DATA ; } switch( src->md_info->type ) @@ -341,17 +341,17 @@ int mbedtls_md_clone( mbedtls_md_context_t *dst, break; #endif default: - return( MBEDTLS_ERR_MD_BAD_INPUT_DATA ); + return MBEDTLS_ERR_MD_BAD_INPUT_DATA ; } - return( 0 ); + return 0 ; } #define ALLOC( type ) \ do { \ ctx->md_ctx = mbedtls_calloc( 1, sizeof( mbedtls_##type##_context ) ); \ if( ctx->md_ctx == NULL ) \ - return( MBEDTLS_ERR_MD_ALLOC_FAILED ); \ + return MBEDTLS_ERR_MD_ALLOC_FAILED ; \ mbedtls_##type##_init( ctx->md_ctx ); \ } \ while( 0 ) @@ -359,7 +359,7 @@ int mbedtls_md_clone( mbedtls_md_context_t *dst, int mbedtls_md_setup( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info, int hmac ) { if( md_info == NULL || ctx == NULL ) - return( MBEDTLS_ERR_MD_BAD_INPUT_DATA ); + return MBEDTLS_ERR_MD_BAD_INPUT_DATA ; ctx->md_info = md_info; ctx->md_ctx = NULL; @@ -403,7 +403,7 @@ int mbedtls_md_setup( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_inf break; #endif default: - return( MBEDTLS_ERR_MD_BAD_INPUT_DATA ); + return MBEDTLS_ERR_MD_BAD_INPUT_DATA ; } if( hmac != 0 ) @@ -412,131 +412,131 @@ int mbedtls_md_setup( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_inf if( ctx->hmac_ctx == NULL ) { mbedtls_md_free( ctx ); - return( MBEDTLS_ERR_MD_ALLOC_FAILED ); + return MBEDTLS_ERR_MD_ALLOC_FAILED ; } } - return( 0 ); + return 0 ; } #undef ALLOC int mbedtls_md_starts( mbedtls_md_context_t *ctx ) { if( ctx == NULL || ctx->md_info == NULL ) - return( MBEDTLS_ERR_MD_BAD_INPUT_DATA ); + return MBEDTLS_ERR_MD_BAD_INPUT_DATA ; switch( ctx->md_info->type ) { #if defined(MBEDTLS_MD5_C) case MBEDTLS_MD_MD5: - return( mbedtls_md5_starts( ctx->md_ctx ) ); + return mbedtls_md5_starts( ctx->md_ctx ) ; #endif #if defined(MBEDTLS_RIPEMD160_C) case MBEDTLS_MD_RIPEMD160: - return( mbedtls_ripemd160_starts( ctx->md_ctx ) ); + return mbedtls_ripemd160_starts( ctx->md_ctx ) ; #endif #if defined(MBEDTLS_SHA1_C) case MBEDTLS_MD_SHA1: - return( mbedtls_sha1_starts( ctx->md_ctx ) ); + return mbedtls_sha1_starts( ctx->md_ctx ) ; #endif #if defined(MBEDTLS_SHA224_C) case MBEDTLS_MD_SHA224: - return( mbedtls_sha256_starts( ctx->md_ctx, 1 ) ); + return mbedtls_sha256_starts( ctx->md_ctx, 1 ) ; #endif #if defined(MBEDTLS_SHA256_C) case MBEDTLS_MD_SHA256: - return( mbedtls_sha256_starts( ctx->md_ctx, 0 ) ); + return mbedtls_sha256_starts( ctx->md_ctx, 0 ) ; #endif #if defined(MBEDTLS_SHA384_C) case MBEDTLS_MD_SHA384: - return( mbedtls_sha512_starts( ctx->md_ctx, 1 ) ); + return mbedtls_sha512_starts( ctx->md_ctx, 1 ) ; #endif #if defined(MBEDTLS_SHA512_C) case MBEDTLS_MD_SHA512: - return( mbedtls_sha512_starts( ctx->md_ctx, 0 ) ); + return mbedtls_sha512_starts( ctx->md_ctx, 0 ) ; #endif default: - return( MBEDTLS_ERR_MD_BAD_INPUT_DATA ); + return MBEDTLS_ERR_MD_BAD_INPUT_DATA ; } } int mbedtls_md_update( mbedtls_md_context_t *ctx, const unsigned char *input, size_t ilen ) { if( ctx == NULL || ctx->md_info == NULL ) - return( MBEDTLS_ERR_MD_BAD_INPUT_DATA ); + return MBEDTLS_ERR_MD_BAD_INPUT_DATA ; switch( ctx->md_info->type ) { #if defined(MBEDTLS_MD5_C) case MBEDTLS_MD_MD5: - return( mbedtls_md5_update( ctx->md_ctx, input, ilen ) ); + return mbedtls_md5_update( ctx->md_ctx, input, ilen ) ; #endif #if defined(MBEDTLS_RIPEMD160_C) case MBEDTLS_MD_RIPEMD160: - return( mbedtls_ripemd160_update( ctx->md_ctx, input, ilen ) ); + return mbedtls_ripemd160_update( ctx->md_ctx, input, ilen ) ; #endif #if defined(MBEDTLS_SHA1_C) case MBEDTLS_MD_SHA1: - return( mbedtls_sha1_update( ctx->md_ctx, input, ilen ) ); + return mbedtls_sha1_update( ctx->md_ctx, input, ilen ) ; #endif #if defined(MBEDTLS_SHA224_C) case MBEDTLS_MD_SHA224: - return( mbedtls_sha256_update( ctx->md_ctx, input, ilen ) ); + return mbedtls_sha256_update( ctx->md_ctx, input, ilen ) ; #endif #if defined(MBEDTLS_SHA256_C) case MBEDTLS_MD_SHA256: - return( mbedtls_sha256_update( ctx->md_ctx, input, ilen ) ); + return mbedtls_sha256_update( ctx->md_ctx, input, ilen ) ; #endif #if defined(MBEDTLS_SHA384_C) case MBEDTLS_MD_SHA384: - return( mbedtls_sha512_update( ctx->md_ctx, input, ilen ) ); + return mbedtls_sha512_update( ctx->md_ctx, input, ilen ) ; #endif #if defined(MBEDTLS_SHA512_C) case MBEDTLS_MD_SHA512: - return( mbedtls_sha512_update( ctx->md_ctx, input, ilen ) ); + return mbedtls_sha512_update( ctx->md_ctx, input, ilen ) ; #endif default: - return( MBEDTLS_ERR_MD_BAD_INPUT_DATA ); + return MBEDTLS_ERR_MD_BAD_INPUT_DATA ; } } int mbedtls_md_finish( mbedtls_md_context_t *ctx, unsigned char *output ) { if( ctx == NULL || ctx->md_info == NULL ) - return( MBEDTLS_ERR_MD_BAD_INPUT_DATA ); + return MBEDTLS_ERR_MD_BAD_INPUT_DATA ; switch( ctx->md_info->type ) { #if defined(MBEDTLS_MD5_C) case MBEDTLS_MD_MD5: - return( mbedtls_md5_finish( ctx->md_ctx, output ) ); + return mbedtls_md5_finish( ctx->md_ctx, output ) ; #endif #if defined(MBEDTLS_RIPEMD160_C) case MBEDTLS_MD_RIPEMD160: - return( mbedtls_ripemd160_finish( ctx->md_ctx, output ) ); + return mbedtls_ripemd160_finish( ctx->md_ctx, output ) ; #endif #if defined(MBEDTLS_SHA1_C) case MBEDTLS_MD_SHA1: - return( mbedtls_sha1_finish( ctx->md_ctx, output ) ); + return mbedtls_sha1_finish( ctx->md_ctx, output ) ; #endif #if defined(MBEDTLS_SHA224_C) case MBEDTLS_MD_SHA224: - return( mbedtls_sha256_finish( ctx->md_ctx, output ) ); + return mbedtls_sha256_finish( ctx->md_ctx, output ) ; #endif #if defined(MBEDTLS_SHA256_C) case MBEDTLS_MD_SHA256: - return( mbedtls_sha256_finish( ctx->md_ctx, output ) ); + return mbedtls_sha256_finish( ctx->md_ctx, output ) ; #endif #if defined(MBEDTLS_SHA384_C) case MBEDTLS_MD_SHA384: - return( mbedtls_sha512_finish( ctx->md_ctx, output ) ); + return mbedtls_sha512_finish( ctx->md_ctx, output ) ; #endif #if defined(MBEDTLS_SHA512_C) case MBEDTLS_MD_SHA512: - return( mbedtls_sha512_finish( ctx->md_ctx, output ) ); + return mbedtls_sha512_finish( ctx->md_ctx, output ) ; #endif default: - return( MBEDTLS_ERR_MD_BAD_INPUT_DATA ); + return MBEDTLS_ERR_MD_BAD_INPUT_DATA ; } } @@ -544,40 +544,40 @@ int mbedtls_md( const mbedtls_md_info_t *md_info, const unsigned char *input, si unsigned char *output ) { if( md_info == NULL ) - return( MBEDTLS_ERR_MD_BAD_INPUT_DATA ); + return MBEDTLS_ERR_MD_BAD_INPUT_DATA ; switch( md_info->type ) { #if defined(MBEDTLS_MD5_C) case MBEDTLS_MD_MD5: - return( mbedtls_md5( input, ilen, output ) ); + return mbedtls_md5( input, ilen, output ) ; #endif #if defined(MBEDTLS_RIPEMD160_C) case MBEDTLS_MD_RIPEMD160: - return( mbedtls_ripemd160( input, ilen, output ) ); + return mbedtls_ripemd160( input, ilen, output ) ; #endif #if defined(MBEDTLS_SHA1_C) case MBEDTLS_MD_SHA1: - return( mbedtls_sha1( input, ilen, output ) ); + return mbedtls_sha1( input, ilen, output ) ; #endif #if defined(MBEDTLS_SHA224_C) case MBEDTLS_MD_SHA224: - return( mbedtls_sha256( input, ilen, output, 1 ) ); + return mbedtls_sha256( input, ilen, output, 1 ) ; #endif #if defined(MBEDTLS_SHA256_C) case MBEDTLS_MD_SHA256: - return( mbedtls_sha256( input, ilen, output, 0 ) ); + return mbedtls_sha256( input, ilen, output, 0 ) ; #endif #if defined(MBEDTLS_SHA384_C) case MBEDTLS_MD_SHA384: - return( mbedtls_sha512( input, ilen, output, 1 ) ); + return mbedtls_sha512( input, ilen, output, 1 ) ; #endif #if defined(MBEDTLS_SHA512_C) case MBEDTLS_MD_SHA512: - return( mbedtls_sha512( input, ilen, output, 0 ) ); + return mbedtls_sha512( input, ilen, output, 0 ) ; #endif default: - return( MBEDTLS_ERR_MD_BAD_INPUT_DATA ); + return MBEDTLS_ERR_MD_BAD_INPUT_DATA ; } } @@ -591,10 +591,10 @@ int mbedtls_md_file( const mbedtls_md_info_t *md_info, const char *path, unsigne unsigned char buf[1024]; if( md_info == NULL ) - return( MBEDTLS_ERR_MD_BAD_INPUT_DATA ); + return MBEDTLS_ERR_MD_BAD_INPUT_DATA ; if( ( f = fopen( path, "rb" ) ) == NULL ) - return( MBEDTLS_ERR_MD_FILE_IO_ERROR ); + return MBEDTLS_ERR_MD_FILE_IO_ERROR ; mbedtls_md_init( &ctx ); @@ -618,7 +618,7 @@ cleanup: fclose( f ); mbedtls_md_free( &ctx ); - return( ret ); + return ret ; } #endif /* MBEDTLS_FS_IO */ @@ -630,7 +630,7 @@ int mbedtls_md_hmac_starts( mbedtls_md_context_t *ctx, const unsigned char *key, size_t i; if( ctx == NULL || ctx->md_info == NULL || ctx->hmac_ctx == NULL ) - return( MBEDTLS_ERR_MD_BAD_INPUT_DATA ); + return MBEDTLS_ERR_MD_BAD_INPUT_DATA ; if( keylen > (size_t) ctx->md_info->block_size ) { @@ -666,15 +666,15 @@ int mbedtls_md_hmac_starts( mbedtls_md_context_t *ctx, const unsigned char *key, cleanup: mbedtls_platform_zeroize( sum, sizeof( sum ) ); - return( ret ); + return ret ; } int mbedtls_md_hmac_update( mbedtls_md_context_t *ctx, const unsigned char *input, size_t ilen ) { if( ctx == NULL || ctx->md_info == NULL || ctx->hmac_ctx == NULL ) - return( MBEDTLS_ERR_MD_BAD_INPUT_DATA ); + return MBEDTLS_ERR_MD_BAD_INPUT_DATA ; - return( mbedtls_md_update( ctx, input, ilen ) ); + return mbedtls_md_update( ctx, input, ilen ) ; } int mbedtls_md_hmac_finish( mbedtls_md_context_t *ctx, unsigned char *output ) @@ -684,21 +684,21 @@ int mbedtls_md_hmac_finish( mbedtls_md_context_t *ctx, unsigned char *output ) unsigned char *opad; if( ctx == NULL || ctx->md_info == NULL || ctx->hmac_ctx == NULL ) - return( MBEDTLS_ERR_MD_BAD_INPUT_DATA ); + return MBEDTLS_ERR_MD_BAD_INPUT_DATA ; opad = (unsigned char *) ctx->hmac_ctx + ctx->md_info->block_size; if( ( ret = mbedtls_md_finish( ctx, tmp ) ) != 0 ) - return( ret ); + return ret ; if( ( ret = mbedtls_md_starts( ctx ) ) != 0 ) - return( ret ); + return ret ; if( ( ret = mbedtls_md_update( ctx, opad, ctx->md_info->block_size ) ) != 0 ) - return( ret ); + return ret ; if( ( ret = mbedtls_md_update( ctx, tmp, ctx->md_info->size ) ) != 0 ) - return( ret ); - return( mbedtls_md_finish( ctx, output ) ); + return ret ; + return mbedtls_md_finish( ctx, output ) ; } int mbedtls_md_hmac_reset( mbedtls_md_context_t *ctx ) @@ -707,13 +707,13 @@ int mbedtls_md_hmac_reset( mbedtls_md_context_t *ctx ) unsigned char *ipad; if( ctx == NULL || ctx->md_info == NULL || ctx->hmac_ctx == NULL ) - return( MBEDTLS_ERR_MD_BAD_INPUT_DATA ); + return MBEDTLS_ERR_MD_BAD_INPUT_DATA ; ipad = (unsigned char *) ctx->hmac_ctx; if( ( ret = mbedtls_md_starts( ctx ) ) != 0 ) - return( ret ); - return( mbedtls_md_update( ctx, ipad, ctx->md_info->block_size ) ); + return ret ; + return mbedtls_md_update( ctx, ipad, ctx->md_info->block_size ) ; } int mbedtls_md_hmac( const mbedtls_md_info_t *md_info, @@ -725,7 +725,7 @@ int mbedtls_md_hmac( const mbedtls_md_info_t *md_info, int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; if( md_info == NULL ) - return( MBEDTLS_ERR_MD_BAD_INPUT_DATA ); + return MBEDTLS_ERR_MD_BAD_INPUT_DATA ; mbedtls_md_init( &ctx ); @@ -742,53 +742,53 @@ int mbedtls_md_hmac( const mbedtls_md_info_t *md_info, cleanup: mbedtls_md_free( &ctx ); - return( ret ); + return ret ; } int mbedtls_md_process( mbedtls_md_context_t *ctx, const unsigned char *data ) { if( ctx == NULL || ctx->md_info == NULL ) - return( MBEDTLS_ERR_MD_BAD_INPUT_DATA ); + return MBEDTLS_ERR_MD_BAD_INPUT_DATA ; switch( ctx->md_info->type ) { #if defined(MBEDTLS_MD5_C) case MBEDTLS_MD_MD5: - return( mbedtls_internal_md5_process( ctx->md_ctx, data ) ); + return mbedtls_internal_md5_process( ctx->md_ctx, data ) ; #endif #if defined(MBEDTLS_RIPEMD160_C) case MBEDTLS_MD_RIPEMD160: - return( mbedtls_internal_ripemd160_process( ctx->md_ctx, data ) ); + return mbedtls_internal_ripemd160_process( ctx->md_ctx, data ) ; #endif #if defined(MBEDTLS_SHA1_C) case MBEDTLS_MD_SHA1: - return( mbedtls_internal_sha1_process( ctx->md_ctx, data ) ); + return mbedtls_internal_sha1_process( ctx->md_ctx, data ) ; #endif #if defined(MBEDTLS_SHA224_C) case MBEDTLS_MD_SHA224: - return( mbedtls_internal_sha256_process( ctx->md_ctx, data ) ); + return mbedtls_internal_sha256_process( ctx->md_ctx, data ) ; #endif #if defined(MBEDTLS_SHA256_C) case MBEDTLS_MD_SHA256: - return( mbedtls_internal_sha256_process( ctx->md_ctx, data ) ); + return mbedtls_internal_sha256_process( ctx->md_ctx, data ) ; #endif #if defined(MBEDTLS_SHA384_C) case MBEDTLS_MD_SHA384: - return( mbedtls_internal_sha512_process( ctx->md_ctx, data ) ); + return mbedtls_internal_sha512_process( ctx->md_ctx, data ) ; #endif #if defined(MBEDTLS_SHA512_C) case MBEDTLS_MD_SHA512: - return( mbedtls_internal_sha512_process( ctx->md_ctx, data ) ); + return mbedtls_internal_sha512_process( ctx->md_ctx, data ) ; #endif default: - return( MBEDTLS_ERR_MD_BAD_INPUT_DATA ); + return MBEDTLS_ERR_MD_BAD_INPUT_DATA ; } } unsigned char mbedtls_md_get_size( const mbedtls_md_info_t *md_info ) { if( md_info == NULL ) - return( 0 ); + return 0 ; return md_info->size; } @@ -796,7 +796,7 @@ unsigned char mbedtls_md_get_size( const mbedtls_md_info_t *md_info ) mbedtls_md_type_t mbedtls_md_get_type( const mbedtls_md_info_t *md_info ) { if( md_info == NULL ) - return( MBEDTLS_MD_NONE ); + return MBEDTLS_MD_NONE ; return md_info->type; } @@ -804,7 +804,7 @@ mbedtls_md_type_t mbedtls_md_get_type( const mbedtls_md_info_t *md_info ) const char *mbedtls_md_get_name( const mbedtls_md_info_t *md_info ) { if( md_info == NULL ) - return( NULL ); + return NULL ; return md_info->name; } diff --git a/library/md5.c b/library/md5.c index d7f8cee468..9761316034 100644 --- a/library/md5.c +++ b/library/md5.c @@ -98,7 +98,7 @@ int mbedtls_md5_starts( mbedtls_md5_context *ctx ) ctx->state[2] = 0x98BADCFE; ctx->state[3] = 0x10325476; - return( 0 ); + return 0 ; } #if !defined(MBEDTLS_MD5_PROCESS_ALT) @@ -234,7 +234,7 @@ int mbedtls_internal_md5_process( mbedtls_md5_context *ctx, /* Zeroise variables to clear sensitive data from memory. */ mbedtls_platform_zeroize( &local, sizeof( local ) ); - return( 0 ); + return 0 ; } #endif /* !MBEDTLS_MD5_PROCESS_ALT */ @@ -251,7 +251,7 @@ int mbedtls_md5_update( mbedtls_md5_context *ctx, uint32_t left; if( ilen == 0 ) - return( 0 ); + return 0 ; left = ctx->total[0] & 0x3F; fill = 64 - left; @@ -266,7 +266,7 @@ int mbedtls_md5_update( mbedtls_md5_context *ctx, { memcpy( (void *) (ctx->buffer + left), input, fill ); if( ( ret = mbedtls_internal_md5_process( ctx, ctx->buffer ) ) != 0 ) - return( ret ); + return ret ; input += fill; ilen -= fill; @@ -276,7 +276,7 @@ int mbedtls_md5_update( mbedtls_md5_context *ctx, while( ilen >= 64 ) { if( ( ret = mbedtls_internal_md5_process( ctx, input ) ) != 0 ) - return( ret ); + return ret ; input += 64; ilen -= 64; @@ -287,7 +287,7 @@ int mbedtls_md5_update( mbedtls_md5_context *ctx, memcpy( (void *) (ctx->buffer + left), input, ilen ); } - return( 0 ); + return 0 ; } /* @@ -318,7 +318,7 @@ int mbedtls_md5_finish( mbedtls_md5_context *ctx, memset( ctx->buffer + used, 0, 64 - used ); if( ( ret = mbedtls_internal_md5_process( ctx, ctx->buffer ) ) != 0 ) - return( ret ); + return ret ; memset( ctx->buffer, 0, 56 ); } @@ -334,7 +334,7 @@ int mbedtls_md5_finish( mbedtls_md5_context *ctx, PUT_UINT32_LE( high, ctx->buffer, 60 ); if( ( ret = mbedtls_internal_md5_process( ctx, ctx->buffer ) ) != 0 ) - return( ret ); + return ret ; /* * Output final state @@ -344,7 +344,7 @@ int mbedtls_md5_finish( mbedtls_md5_context *ctx, PUT_UINT32_LE( ctx->state[2], output, 8 ); PUT_UINT32_LE( ctx->state[3], output, 12 ); - return( 0 ); + return 0 ; } #endif /* !MBEDTLS_MD5_ALT */ @@ -373,7 +373,7 @@ int mbedtls_md5( const unsigned char *input, exit: mbedtls_md5_free( &ctx ); - return( ret ); + return ret ; } #if defined(MBEDTLS_SELF_TEST) @@ -444,13 +444,13 @@ int mbedtls_md5_self_test( int verbose ) if( verbose != 0 ) mbedtls_printf( "\n" ); - return( 0 ); + return 0 ; fail: if( verbose != 0 ) mbedtls_printf( "failed\n" ); - return( ret ); + return ret ; } #endif /* MBEDTLS_SELF_TEST */ diff --git a/library/memory_buffer_alloc.c b/library/memory_buffer_alloc.c index 0d5d27d3de..54377b505e 100644 --- a/library/memory_buffer_alloc.c +++ b/library/memory_buffer_alloc.c @@ -132,7 +132,7 @@ static int verify_header( memory_header *hdr ) #if defined(MBEDTLS_MEMORY_DEBUG) mbedtls_fprintf( stderr, "FATAL: MAGIC1 mismatch\n" ); #endif - return( 1 ); + return 1 ; } if( hdr->magic2 != MAGIC2 ) @@ -140,7 +140,7 @@ static int verify_header( memory_header *hdr ) #if defined(MBEDTLS_MEMORY_DEBUG) mbedtls_fprintf( stderr, "FATAL: MAGIC2 mismatch\n" ); #endif - return( 1 ); + return 1 ; } if( hdr->alloc > 1 ) @@ -148,7 +148,7 @@ static int verify_header( memory_header *hdr ) #if defined(MBEDTLS_MEMORY_DEBUG) mbedtls_fprintf( stderr, "FATAL: alloc has illegal value\n" ); #endif - return( 1 ); + return 1 ; } if( hdr->prev != NULL && hdr->prev == hdr->next ) @@ -156,7 +156,7 @@ static int verify_header( memory_header *hdr ) #if defined(MBEDTLS_MEMORY_DEBUG) mbedtls_fprintf( stderr, "FATAL: prev == next\n" ); #endif - return( 1 ); + return 1 ; } if( hdr->prev_free != NULL && hdr->prev_free == hdr->next_free ) @@ -164,10 +164,10 @@ static int verify_header( memory_header *hdr ) #if defined(MBEDTLS_MEMORY_DEBUG) mbedtls_fprintf( stderr, "FATAL: prev_free == next_free\n" ); #endif - return( 1 ); + return 1 ; } - return( 0 ); + return 0 ; } static int verify_chain( void ) @@ -180,7 +180,7 @@ static int verify_chain( void ) mbedtls_fprintf( stderr, "FATAL: verification of first header " "failed\n" ); #endif - return( 1 ); + return 1 ; } if( heap.first->prev != NULL ) @@ -189,7 +189,7 @@ static int verify_chain( void ) mbedtls_fprintf( stderr, "FATAL: verification failed: " "first->prev != NULL\n" ); #endif - return( 1 ); + return 1 ; } cur = heap.first->next; @@ -202,7 +202,7 @@ static int verify_chain( void ) mbedtls_fprintf( stderr, "FATAL: verification of header " "failed\n" ); #endif - return( 1 ); + return 1 ; } if( cur->prev != prv ) @@ -211,14 +211,14 @@ static int verify_chain( void ) mbedtls_fprintf( stderr, "FATAL: verification failed: " "cur->prev != prv\n" ); #endif - return( 1 ); + return 1 ; } prv = cur; cur = cur->next; } - return( 0 ); + return 0 ; } static void *buffer_alloc_calloc( size_t n, size_t size ) @@ -233,14 +233,14 @@ static void *buffer_alloc_calloc( size_t n, size_t size ) #endif if( heap.buf == NULL || heap.first == NULL ) - return( NULL ); + return NULL ; original_len = len = n * size; if( n == 0 || size == 0 || len / n != size ) - return( NULL ); + return NULL ; else if( len > (size_t)-MBEDTLS_MEMORY_ALIGN_MULTIPLE ) - return( NULL ); + return NULL ; if( len % MBEDTLS_MEMORY_ALIGN_MULTIPLE ) { @@ -259,7 +259,7 @@ static void *buffer_alloc_calloc( size_t n, size_t size ) } if( cur == NULL ) - return( NULL ); + return NULL ; if( cur->alloc != 0 ) { @@ -311,7 +311,7 @@ static void *buffer_alloc_calloc( size_t n, size_t size ) ret = (unsigned char *) cur + sizeof( memory_header ); memset( ret, 0, original_len ); - return( ret ); + return ret ; } p = ( (unsigned char *) cur ) + sizeof(memory_header) + len; @@ -369,7 +369,7 @@ static void *buffer_alloc_calloc( size_t n, size_t size ) ret = (unsigned char *) cur + sizeof( memory_header ); memset( ret, 0, original_len ); - return( ret ); + return ret ; } static void buffer_alloc_free( void *ptr ) @@ -546,11 +546,11 @@ static void *buffer_alloc_calloc_mutexed( size_t n, size_t size ) { void *buf; if( mbedtls_mutex_lock( &heap.mutex ) != 0 ) - return( NULL ); + return NULL ; buf = buffer_alloc_calloc( n, size ); if( mbedtls_mutex_unlock( &heap.mutex ) ) - return( NULL ); - return( buf ); + return NULL ; + return buf ; } static void buffer_alloc_free_mutexed( void *ptr ) @@ -611,12 +611,12 @@ void mbedtls_memory_buffer_alloc_free( void ) static int check_pointer( void *p ) { if( p == NULL ) - return( -1 ); + return -1 ; if( (size_t) p % MBEDTLS_MEMORY_ALIGN_MULTIPLE != 0 ) - return( -1 ); + return -1 ; - return( 0 ); + return 0 ; } static int check_all_free( void ) @@ -628,10 +628,10 @@ static int check_all_free( void ) heap.first != heap.first_free || (void *) heap.first != (void *) heap.buf ) { - return( -1 ); + return -1 ; } - return( 0 ); + return 0 ; } #define TEST_ASSERT( condition ) \ @@ -737,7 +737,7 @@ int mbedtls_memory_buffer_alloc_self_test( int verbose ) cleanup: mbedtls_memory_buffer_alloc_free( ); - return( ret ); + return ret ; } #endif /* MBEDTLS_SELF_TEST */ diff --git a/library/mps_reader.c b/library/mps_reader.c index 9af5073cc9..c8129c47b1 100644 --- a/library/mps_reader.c +++ b/library/mps_reader.c @@ -76,23 +76,23 @@ static inline int mps_reader_is_accumulating( { mbedtls_mps_size_t acc_remaining; if( rd->acc == NULL ) - return( 0 ); + return 0 ; acc_remaining = rd->acc_share.acc_remaining; - return( acc_remaining > 0 ); + return acc_remaining > 0 ; } static inline int mps_reader_is_producing( mbedtls_mps_reader const *rd ) { unsigned char *frag = rd->frag; - return( frag == NULL ); + return frag == NULL ; } static inline int mps_reader_is_consuming( mbedtls_mps_reader const *rd ) { - return( !mps_reader_is_producing( rd ) ); + return !mps_reader_is_producing( rd ) ; } static inline mbedtls_mps_size_t mps_reader_get_fragment_offset( @@ -102,10 +102,10 @@ static inline mbedtls_mps_size_t mps_reader_get_fragment_offset( mbedtls_mps_size_t frag_offset; if( acc == NULL ) - return( 0 ); + return 0 ; frag_offset = rd->acc_share.frag_offset; - return( frag_offset ); + return frag_offset ; } static inline mbedtls_mps_size_t mps_reader_serving_from_accumulator( @@ -116,7 +116,7 @@ static inline mbedtls_mps_size_t mps_reader_serving_from_accumulator( frag_offset = mps_reader_get_fragment_offset( rd ); end = rd->end; - return( end < frag_offset ); + return end < frag_offset ; } static inline void mps_reader_zero( mbedtls_mps_reader *rd ) diff --git a/library/mps_trace.h b/library/mps_trace.h index 7c2360118a..f6786d463f 100644 --- a/library/mps_trace.h +++ b/library/mps_trace.h @@ -159,7 +159,7 @@ void mbedtls_mps_trace_print_msg( int id, int line, const char *format, ... ); /* Breaks tail recursion. */ \ int ret__ = val; \ MBEDTLS_MPS_TRACE_END( ret__ ); \ - return( ret__ ); \ + return ret__ ; \ } while( 0 ) #else /* MBEDTLS_MPS_TRACE */ @@ -168,7 +168,7 @@ void mbedtls_mps_trace_print_msg( int id, int line, const char *format, ... ); #define MBEDTLS_MPS_TRACE_INIT( ... ) do { } while( 0 ) #define MBEDTLS_MPS_TRACE_END do { } while( 0 ) -#define MBEDTLS_MPS_TRACE_RETURN( val ) return( val ); +#define MBEDTLS_MPS_TRACE_RETURN( val ) return val ; #endif /* MBEDTLS_MPS_TRACE */ diff --git a/library/net_sockets.c b/library/net_sockets.c index 17a9e4a576..fc4024e14c 100644 --- a/library/net_sockets.c +++ b/library/net_sockets.c @@ -123,7 +123,7 @@ static int net_prepare( void ) if( wsa_init_done == 0 ) { if( WSAStartup( MAKEWORD(2,0), &wsaData ) != 0 ) - return( MBEDTLS_ERR_NET_SOCKET_FAILED ); + return MBEDTLS_ERR_NET_SOCKET_FAILED ; wsa_init_done = 1; } @@ -132,7 +132,7 @@ static int net_prepare( void ) signal( SIGPIPE, SIG_IGN ); #endif #endif - return( 0 ); + return 0 ; } /* @@ -143,7 +143,7 @@ static int net_prepare( void ) static int check_fd( int fd, int for_select ) { if( fd < 0 ) - return( MBEDTLS_ERR_NET_INVALID_CONTEXT ); + return MBEDTLS_ERR_NET_INVALID_CONTEXT ; #if (defined(_WIN32) || defined(_WIN32_WCE)) && !defined(EFIX64) && \ !defined(EFI32) @@ -154,10 +154,10 @@ static int check_fd( int fd, int for_select ) * fd_set type. Error out early, because attempting to call FD_SET on a * large file descriptor is a buffer overflow on typical platforms. */ if( for_select && fd >= FD_SETSIZE ) - return( MBEDTLS_ERR_NET_POLL_FAILED ); + return MBEDTLS_ERR_NET_POLL_FAILED ; #endif - return( 0 ); + return 0 ; } /* @@ -178,7 +178,7 @@ int mbedtls_net_connect( mbedtls_net_context *ctx, const char *host, struct addrinfo hints, *addr_list, *cur; if( ( ret = net_prepare() ) != 0 ) - return( ret ); + return ret ; /* Do name resolution with both IPv6 and IPv4 */ memset( &hints, 0, sizeof( hints ) ); @@ -187,7 +187,7 @@ int mbedtls_net_connect( mbedtls_net_context *ctx, const char *host, hints.ai_protocol = proto == MBEDTLS_NET_PROTO_UDP ? IPPROTO_UDP : IPPROTO_TCP; if( getaddrinfo( host, port, &hints, &addr_list ) != 0 ) - return( MBEDTLS_ERR_NET_UNKNOWN_HOST ); + return MBEDTLS_ERR_NET_UNKNOWN_HOST ; /* Try the sockaddrs until a connection succeeds */ ret = MBEDTLS_ERR_NET_UNKNOWN_HOST; @@ -213,7 +213,7 @@ int mbedtls_net_connect( mbedtls_net_context *ctx, const char *host, freeaddrinfo( addr_list ); - return( ret ); + return ret ; } /* @@ -225,7 +225,7 @@ int mbedtls_net_bind( mbedtls_net_context *ctx, const char *bind_ip, const char struct addrinfo hints, *addr_list, *cur; if( ( ret = net_prepare() ) != 0 ) - return( ret ); + return ret ; /* Bind to IPv6 and/or IPv4, but only in the desired protocol */ memset( &hints, 0, sizeof( hints ) ); @@ -236,7 +236,7 @@ int mbedtls_net_bind( mbedtls_net_context *ctx, const char *bind_ip, const char hints.ai_flags = AI_PASSIVE; if( getaddrinfo( bind_ip, port, &hints, &addr_list ) != 0 ) - return( MBEDTLS_ERR_NET_UNKNOWN_HOST ); + return MBEDTLS_ERR_NET_UNKNOWN_HOST ; /* Try the sockaddrs until a binding succeeds */ ret = MBEDTLS_ERR_NET_UNKNOWN_HOST; @@ -284,7 +284,7 @@ int mbedtls_net_bind( mbedtls_net_context *ctx, const char *bind_ip, const char freeaddrinfo( addr_list ); - return( ret ); + return ret ; } @@ -297,7 +297,7 @@ int mbedtls_net_bind( mbedtls_net_context *ctx, const char *bind_ip, const char static int net_would_block( const mbedtls_net_context *ctx ) { ((void) ctx); - return( WSAGetLastError() == WSAEWOULDBLOCK ); + return WSAGetLastError() == WSAEWOULDBLOCK ; } #else /* @@ -316,7 +316,7 @@ static int net_would_block( const mbedtls_net_context *ctx ) if( ( fcntl( ctx->fd, F_GETFL ) & O_NONBLOCK ) != O_NONBLOCK ) { errno = err; - return( 0 ); + return 0 ; } switch( errno = err ) @@ -327,9 +327,9 @@ static int net_would_block( const mbedtls_net_context *ctx ) #if defined EWOULDBLOCK && EWOULDBLOCK != EAGAIN case EWOULDBLOCK: #endif - return( 1 ); + return 1 ; } - return( 0 ); + return 0 ; } #endif /* ( _WIN32 || _WIN32_WCE ) && !EFIX64 && !EFI32 */ @@ -360,7 +360,7 @@ int mbedtls_net_accept( mbedtls_net_context *bind_ctx, (void *) &type, &type_len ) != 0 || ( type != SOCK_STREAM && type != SOCK_DGRAM ) ) { - return( MBEDTLS_ERR_NET_ACCEPT_FAILED ); + return MBEDTLS_ERR_NET_ACCEPT_FAILED ; } if( type == SOCK_STREAM ) @@ -390,9 +390,9 @@ int mbedtls_net_accept( mbedtls_net_context *bind_ctx, if( ret < 0 ) { if( net_would_block( bind_ctx ) != 0 ) - return( MBEDTLS_ERR_SSL_WANT_READ ); + return MBEDTLS_ERR_SSL_WANT_READ ; - return( MBEDTLS_ERR_NET_ACCEPT_FAILED ); + return MBEDTLS_ERR_NET_ACCEPT_FAILED ; } /* UDP: hijack the listening socket to communicate with the client, @@ -403,7 +403,7 @@ int mbedtls_net_accept( mbedtls_net_context *bind_ctx, int one = 1; if( connect( bind_ctx->fd, (struct sockaddr *) &client_addr, n ) != 0 ) - return( MBEDTLS_ERR_NET_ACCEPT_FAILED ); + return MBEDTLS_ERR_NET_ACCEPT_FAILED ; client_ctx->fd = bind_ctx->fd; bind_ctx->fd = -1; /* In case we exit early */ @@ -416,12 +416,12 @@ int mbedtls_net_accept( mbedtls_net_context *bind_ctx, setsockopt( bind_ctx->fd, SOL_SOCKET, SO_REUSEADDR, (const char *) &one, sizeof( one ) ) != 0 ) { - return( MBEDTLS_ERR_NET_SOCKET_FAILED ); + return MBEDTLS_ERR_NET_SOCKET_FAILED ; } if( bind( bind_ctx->fd, (struct sockaddr *) &local_addr, n ) != 0 ) { - return( MBEDTLS_ERR_NET_BIND_FAILED ); + return MBEDTLS_ERR_NET_BIND_FAILED ; } } @@ -433,7 +433,7 @@ int mbedtls_net_accept( mbedtls_net_context *bind_ctx, *ip_len = sizeof( addr4->sin_addr.s_addr ); if( buf_size < *ip_len ) - return( MBEDTLS_ERR_NET_BUFFER_TOO_SMALL ); + return MBEDTLS_ERR_NET_BUFFER_TOO_SMALL ; memcpy( client_ip, &addr4->sin_addr.s_addr, *ip_len ); } @@ -443,13 +443,13 @@ int mbedtls_net_accept( mbedtls_net_context *bind_ctx, *ip_len = sizeof( addr6->sin6_addr.s6_addr ); if( buf_size < *ip_len ) - return( MBEDTLS_ERR_NET_BUFFER_TOO_SMALL ); + return MBEDTLS_ERR_NET_BUFFER_TOO_SMALL ; memcpy( client_ip, &addr6->sin6_addr.s6_addr, *ip_len); } } - return( 0 ); + return 0 ; } /* @@ -460,9 +460,9 @@ int mbedtls_net_set_block( mbedtls_net_context *ctx ) #if ( defined(_WIN32) || defined(_WIN32_WCE) ) && !defined(EFIX64) && \ !defined(EFI32) u_long n = 0; - return( ioctlsocket( ctx->fd, FIONBIO, &n ) ); + return ioctlsocket( ctx->fd, FIONBIO, &n ) ; #else - return( fcntl( ctx->fd, F_SETFL, fcntl( ctx->fd, F_GETFL ) & ~O_NONBLOCK ) ); + return fcntl( ctx->fd, F_SETFL, fcntl( ctx->fd, F_GETFL ) & ~O_NONBLOCK ) ; #endif } @@ -471,9 +471,9 @@ int mbedtls_net_set_nonblock( mbedtls_net_context *ctx ) #if ( defined(_WIN32) || defined(_WIN32_WCE) ) && !defined(EFIX64) && \ !defined(EFI32) u_long n = 1; - return( ioctlsocket( ctx->fd, FIONBIO, &n ) ); + return ioctlsocket( ctx->fd, FIONBIO, &n ) ; #else - return( fcntl( ctx->fd, F_SETFL, fcntl( ctx->fd, F_GETFL ) | O_NONBLOCK ) ); + return fcntl( ctx->fd, F_SETFL, fcntl( ctx->fd, F_GETFL ) | O_NONBLOCK ) ; #endif } @@ -493,7 +493,7 @@ int mbedtls_net_poll( mbedtls_net_context *ctx, uint32_t rw, uint32_t timeout ) ret = check_fd( fd, 1 ); if( ret != 0 ) - return( ret ); + return ret ; #if defined(__has_feature) #if __has_feature(memory_sanitizer) @@ -520,7 +520,7 @@ int mbedtls_net_poll( mbedtls_net_context *ctx, uint32_t rw, uint32_t timeout ) } if( rw != 0 ) - return( MBEDTLS_ERR_NET_BAD_INPUT_DATA ); + return MBEDTLS_ERR_NET_BAD_INPUT_DATA ; tv.tv_sec = timeout / 1000; tv.tv_usec = ( timeout % 1000 ) * 1000; @@ -533,7 +533,7 @@ int mbedtls_net_poll( mbedtls_net_context *ctx, uint32_t rw, uint32_t timeout ) while( IS_EINTR( ret ) ); if( ret < 0 ) - return( MBEDTLS_ERR_NET_POLL_FAILED ); + return MBEDTLS_ERR_NET_POLL_FAILED ; ret = 0; if( FD_ISSET( fd, &read_fds ) ) @@ -541,7 +541,7 @@ int mbedtls_net_poll( mbedtls_net_context *ctx, uint32_t rw, uint32_t timeout ) if( FD_ISSET( fd, &write_fds ) ) ret |= MBEDTLS_NET_POLL_WRITE; - return( ret ); + return ret ; } /* @@ -574,31 +574,31 @@ int mbedtls_net_recv( void *ctx, unsigned char *buf, size_t len ) ret = check_fd( fd, 0 ); if( ret != 0 ) - return( ret ); + return ret ; ret = (int) read( fd, buf, len ); if( ret < 0 ) { if( net_would_block( ctx ) != 0 ) - return( MBEDTLS_ERR_SSL_WANT_READ ); + return MBEDTLS_ERR_SSL_WANT_READ ; #if ( defined(_WIN32) || defined(_WIN32_WCE) ) && !defined(EFIX64) && \ !defined(EFI32) if( WSAGetLastError() == WSAECONNRESET ) - return( MBEDTLS_ERR_NET_CONN_RESET ); + return MBEDTLS_ERR_NET_CONN_RESET ; #else if( errno == EPIPE || errno == ECONNRESET ) - return( MBEDTLS_ERR_NET_CONN_RESET ); + return MBEDTLS_ERR_NET_CONN_RESET ; if( errno == EINTR ) - return( MBEDTLS_ERR_SSL_WANT_READ ); + return MBEDTLS_ERR_SSL_WANT_READ ; #endif - return( MBEDTLS_ERR_NET_RECV_FAILED ); + return MBEDTLS_ERR_NET_RECV_FAILED ; } - return( ret ); + return ret ; } /* @@ -614,7 +614,7 @@ int mbedtls_net_recv_timeout( void *ctx, unsigned char *buf, ret = check_fd( fd, 1 ); if( ret != 0 ) - return( ret ); + return ret ; FD_ZERO( &read_fds ); FD_SET( fd, &read_fds ); @@ -626,24 +626,24 @@ int mbedtls_net_recv_timeout( void *ctx, unsigned char *buf, /* Zero fds ready means we timed out */ if( ret == 0 ) - return( MBEDTLS_ERR_SSL_TIMEOUT ); + return MBEDTLS_ERR_SSL_TIMEOUT ; if( ret < 0 ) { #if ( defined(_WIN32) || defined(_WIN32_WCE) ) && !defined(EFIX64) && \ !defined(EFI32) if( WSAGetLastError() == WSAEINTR ) - return( MBEDTLS_ERR_SSL_WANT_READ ); + return MBEDTLS_ERR_SSL_WANT_READ ; #else if( errno == EINTR ) - return( MBEDTLS_ERR_SSL_WANT_READ ); + return MBEDTLS_ERR_SSL_WANT_READ ; #endif - return( MBEDTLS_ERR_NET_RECV_FAILED ); + return MBEDTLS_ERR_NET_RECV_FAILED ; } /* This call will not block */ - return( mbedtls_net_recv( ctx, buf, len ) ); + return mbedtls_net_recv( ctx, buf, len ) ; } /* @@ -656,31 +656,31 @@ int mbedtls_net_send( void *ctx, const unsigned char *buf, size_t len ) ret = check_fd( fd, 0 ); if( ret != 0 ) - return( ret ); + return ret ; ret = (int) write( fd, buf, len ); if( ret < 0 ) { if( net_would_block( ctx ) != 0 ) - return( MBEDTLS_ERR_SSL_WANT_WRITE ); + return MBEDTLS_ERR_SSL_WANT_WRITE ; #if ( defined(_WIN32) || defined(_WIN32_WCE) ) && !defined(EFIX64) && \ !defined(EFI32) if( WSAGetLastError() == WSAECONNRESET ) - return( MBEDTLS_ERR_NET_CONN_RESET ); + return MBEDTLS_ERR_NET_CONN_RESET ; #else if( errno == EPIPE || errno == ECONNRESET ) - return( MBEDTLS_ERR_NET_CONN_RESET ); + return MBEDTLS_ERR_NET_CONN_RESET ; if( errno == EINTR ) - return( MBEDTLS_ERR_SSL_WANT_WRITE ); + return MBEDTLS_ERR_SSL_WANT_WRITE ; #endif - return( MBEDTLS_ERR_NET_SEND_FAILED ); + return MBEDTLS_ERR_NET_SEND_FAILED ; } - return( ret ); + return ret ; } /* diff --git a/library/nist_kw.c b/library/nist_kw.c index 5054ca206b..33b98d025a 100644 --- a/library/nist_kw.c +++ b/library/nist_kw.c @@ -69,7 +69,7 @@ static inline unsigned char mbedtls_nist_kw_safer_memcmp( const void *a, const v diff |= x ^ y; } - return( diff ); + return diff ; } /*! The 64-bit default integrity check value (ICV) for KW mode. */ @@ -118,10 +118,10 @@ int mbedtls_nist_kw_setkey( mbedtls_nist_kw_context *ctx, keybits, MBEDTLS_MODE_ECB ); if( cipher_info == NULL ) - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ; if( cipher_info->block_size != 16 ) - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ; /* * SP 800-38F currently defines AES cipher as the only block cipher allowed: @@ -133,22 +133,22 @@ int mbedtls_nist_kw_setkey( mbedtls_nist_kw_context *ctx, * such as Camellia and Aria. */ if( cipher != MBEDTLS_CIPHER_ID_AES ) - return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ; mbedtls_cipher_free( &ctx->cipher_ctx ); if( ( ret = mbedtls_cipher_setup( &ctx->cipher_ctx, cipher_info ) ) != 0 ) - return( ret ); + return ret ; if( ( ret = mbedtls_cipher_setkey( &ctx->cipher_ctx, key, keybits, is_wrap ? MBEDTLS_ENCRYPT : MBEDTLS_DECRYPT ) ) != 0 ) { - return( ret ); + return ret ; } - return( 0 ); + return 0 ; } /* @@ -198,7 +198,7 @@ int mbedtls_nist_kw_wrap( mbedtls_nist_kw_context *ctx, { if( out_size < in_len + KW_SEMIBLOCK_LENGTH ) { - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ; } /* @@ -211,7 +211,7 @@ int mbedtls_nist_kw_wrap( mbedtls_nist_kw_context *ctx, #endif in_len % KW_SEMIBLOCK_LENGTH != 0 ) { - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ; } memcpy( output, NIST_KW_ICV1, KW_SEMIBLOCK_LENGTH ); @@ -226,7 +226,7 @@ int mbedtls_nist_kw_wrap( mbedtls_nist_kw_context *ctx, if( out_size < in_len + KW_SEMIBLOCK_LENGTH + padlen ) { - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ; } /* @@ -239,7 +239,7 @@ int mbedtls_nist_kw_wrap( mbedtls_nist_kw_context *ctx, #endif ) { - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ; } memcpy( output, NIST_KW_ICV2, KW_SEMIBLOCK_LENGTH / 2 ); @@ -308,7 +308,7 @@ cleanup: mbedtls_platform_zeroize( inbuff, KW_SEMIBLOCK_LENGTH * 2 ); mbedtls_platform_zeroize( outbuff, KW_SEMIBLOCK_LENGTH * 2 ); - return( ret ); + return ret ; } /* @@ -335,7 +335,7 @@ static int unwrap( mbedtls_nist_kw_context *ctx, if( semiblocks < MIN_SEMIBLOCKS_COUNT ) { - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ; } memcpy( A, input, KW_SEMIBLOCK_LENGTH ); @@ -374,7 +374,7 @@ cleanup: mbedtls_platform_zeroize( inbuff, sizeof( inbuff ) ); mbedtls_platform_zeroize( outbuff, sizeof( outbuff ) ); - return( ret ); + return ret ; } /* @@ -394,7 +394,7 @@ int mbedtls_nist_kw_unwrap( mbedtls_nist_kw_context *ctx, *out_len = 0; if( out_size < in_len - KW_SEMIBLOCK_LENGTH ) { - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ; } if( mode == MBEDTLS_KW_MODE_KW ) @@ -409,7 +409,7 @@ int mbedtls_nist_kw_unwrap( mbedtls_nist_kw_context *ctx, #endif in_len % KW_SEMIBLOCK_LENGTH != 0 ) { - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ; } ret = unwrap( ctx, input, in_len / KW_SEMIBLOCK_LENGTH, @@ -441,7 +441,7 @@ int mbedtls_nist_kw_unwrap( mbedtls_nist_kw_context *ctx, #endif in_len % KW_SEMIBLOCK_LENGTH != 0 ) { - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ; } if( in_len == KW_SEMIBLOCK_LENGTH * 2 ) @@ -526,7 +526,7 @@ cleanup: mbedtls_platform_zeroize( &diff, sizeof( diff ) ); mbedtls_platform_zeroize( A, sizeof( A ) ); - return( ret ); + return ret ; } #endif /* !MBEDTLS_NIST_KW_ALT */ @@ -744,7 +744,7 @@ end: if( verbose != 0 ) mbedtls_printf( "\n" ); - return( ret ); + return ret ; } #endif /* MBEDTLS_SELF_TEST && MBEDTLS_AES_C */ diff --git a/library/oid.c b/library/oid.c index f70ceea566..3a58a3f3d3 100644 --- a/library/oid.c +++ b/library/oid.c @@ -63,16 +63,16 @@ const TYPE_T *p = (LIST); \ const mbedtls_oid_descriptor_t *cur = \ (const mbedtls_oid_descriptor_t *) p; \ - if( p == NULL || oid == NULL ) return( NULL ); \ + if( p == NULL || oid == NULL ) return NULL ; \ while( cur->asn1 != NULL ) { \ if( cur->asn1_len == oid->len && \ memcmp( cur->asn1, oid->p, oid->len ) == 0 ) { \ - return( p ); \ + return p ; \ } \ p++; \ cur = (const mbedtls_oid_descriptor_t *) p; \ } \ - return( NULL ); \ + return NULL ; \ } #if !defined(MBEDTLS_X509_REMOVE_INFO) @@ -84,9 +84,9 @@ int FN_NAME( const mbedtls_asn1_buf *oid, ATTR1_TYPE * ATTR1 ) \ { \ const TYPE_T *data = oid_ ## TYPE_NAME ## _from_asn1( oid ); \ - if( data == NULL ) return( MBEDTLS_ERR_OID_NOT_FOUND ); \ + if( data == NULL ) return MBEDTLS_ERR_OID_NOT_FOUND ; \ *ATTR1 = data->descriptor.ATTR1; \ - return( 0 ); \ + return 0 ; \ } #endif /* MBEDTLS_X509_REMOVE_INFO */ @@ -98,9 +98,9 @@ int FN_NAME( const mbedtls_asn1_buf *oid, ATTR1_TYPE * ATTR1 ) int FN_NAME( const mbedtls_asn1_buf *oid, ATTR1_TYPE * ATTR1 ) \ { \ const TYPE_T *data = oid_ ## TYPE_NAME ## _from_asn1( oid ); \ - if( data == NULL ) return( MBEDTLS_ERR_OID_NOT_FOUND ); \ + if( data == NULL ) return MBEDTLS_ERR_OID_NOT_FOUND ; \ *ATTR1 = data->ATTR1; \ - return( 0 ); \ + return 0 ; \ } /* @@ -113,10 +113,10 @@ int FN_NAME( const mbedtls_asn1_buf *oid, ATTR1_TYPE * ATTR1, \ ATTR2_TYPE * ATTR2 ) \ { \ const TYPE_T *data = oid_ ## TYPE_NAME ## _from_asn1( oid ); \ - if( data == NULL ) return( MBEDTLS_ERR_OID_NOT_FOUND ); \ + if( data == NULL ) return MBEDTLS_ERR_OID_NOT_FOUND ; \ *(ATTR1) = data->ATTR1; \ *(ATTR2) = data->ATTR2; \ - return( 0 ); \ + return 0 ; \ } /* @@ -131,11 +131,11 @@ int FN_NAME( ATTR1_TYPE ATTR1, const char **oid, size_t *olen ) \ if( cur->ATTR1 == (ATTR1) ) { \ *oid = cur->descriptor.asn1; \ *olen = cur->descriptor.asn1_len; \ - return( 0 ); \ + return 0 ; \ } \ cur++; \ } \ - return( MBEDTLS_ERR_OID_NOT_FOUND ); \ + return MBEDTLS_ERR_OID_NOT_FOUND ; \ } /* @@ -152,11 +152,11 @@ int FN_NAME( ATTR1_TYPE ATTR1, ATTR2_TYPE ATTR2, const char **oid , \ if( cur->ATTR1 == (ATTR1) && cur->ATTR2 == (ATTR2) ) { \ *oid = cur->descriptor.asn1; \ *olen = cur->descriptor.asn1_len; \ - return( 0 ); \ + return 0 ; \ } \ cur++; \ } \ - return( MBEDTLS_ERR_OID_NOT_FOUND ); \ + return MBEDTLS_ERR_OID_NOT_FOUND ; \ } /* @@ -732,7 +732,7 @@ FN_OID_GET_ATTR2(mbedtls_oid_get_pkcs12_pbe_alg, oid_pkcs12_pbe_alg_t, pkcs12_pb #define OID_SAFE_SNPRINTF \ do { \ if( ret < 0 || (size_t) ret >= n ) \ - return( MBEDTLS_ERR_OID_BUF_TOO_SMALL ); \ + return MBEDTLS_ERR_OID_BUF_TOO_SMALL ; \ \ n -= (size_t) ret; \ p += (size_t) ret; \ @@ -762,7 +762,7 @@ int mbedtls_oid_get_numeric_string( char *buf, size_t size, { /* Prevent overflow in value. */ if( ( ( value << 7 ) >> 7 ) != value ) - return( MBEDTLS_ERR_OID_BUF_TOO_SMALL ); + return MBEDTLS_ERR_OID_BUF_TOO_SMALL ; value <<= 7; value += oid->p[i] & 0x7F; diff --git a/library/padlock.c b/library/padlock.c index b8ba1058a8..a034238a80 100644 --- a/library/padlock.c +++ b/library/padlock.c @@ -65,7 +65,7 @@ int mbedtls_padlock_has_support( int feature ) flags = edx; } - return( flags & feature ); + return flags & feature ; } /* @@ -105,7 +105,7 @@ int mbedtls_padlock_xcryptecb( mbedtls_aes_context *ctx, memcpy( output, blk, 16 ); - return( 0 ); + return 0 ; } /* @@ -127,7 +127,7 @@ int mbedtls_padlock_xcryptcbc( mbedtls_aes_context *ctx, if( ( (long) input & 15 ) != 0 || ( (long) output & 15 ) != 0 ) - return( MBEDTLS_ERR_PADLOCK_DATA_MISALIGNED ); + return MBEDTLS_ERR_PADLOCK_DATA_MISALIGNED ; rk = ctx->rk; iw = MBEDTLS_PADLOCK_ALIGN16( buf ); @@ -156,7 +156,7 @@ int mbedtls_padlock_xcryptcbc( mbedtls_aes_context *ctx, memcpy( iv, iw, 16 ); - return( 0 ); + return 0 ; } #endif /* MBEDTLS_HAVE_X86 */ diff --git a/library/pem.c b/library/pem.c index 1b40e5e558..f63716623a 100644 --- a/library/pem.c +++ b/library/pem.c @@ -63,14 +63,14 @@ static int pem_get_iv( const unsigned char *s, unsigned char *iv, if( *s >= '0' && *s <= '9' ) j = *s - '0'; else if( *s >= 'A' && *s <= 'F' ) j = *s - '7'; else if( *s >= 'a' && *s <= 'f' ) j = *s - 'W'; else - return( MBEDTLS_ERR_PEM_INVALID_ENC_IV ); + return MBEDTLS_ERR_PEM_INVALID_ENC_IV ; k = ( ( i & 1 ) != 0 ) ? j : j << 4; iv[i >> 1] = (unsigned char)( iv[i >> 1] | k ); } - return( 0 ); + return 0 ; } static int pem_pbkdf1( unsigned char *key, size_t keylen, @@ -128,7 +128,7 @@ exit: mbedtls_md5_free( &md5_ctx ); mbedtls_platform_zeroize( md5sum, 16 ); - return( ret ); + return ret ; } #if defined(MBEDTLS_DES_C) @@ -157,7 +157,7 @@ exit: mbedtls_des_free( &des_ctx ); mbedtls_platform_zeroize( des_key, 8 ); - return( ret ); + return ret ; } /* @@ -185,7 +185,7 @@ exit: mbedtls_des3_free( &des3_ctx ); mbedtls_platform_zeroize( des3_key, 24 ); - return( ret ); + return ret ; } #endif /* MBEDTLS_DES_C */ @@ -215,7 +215,7 @@ exit: mbedtls_aes_free( &aes_ctx ); mbedtls_platform_zeroize( aes_key, keylen ); - return( ret ); + return ret ; } #endif /* MBEDTLS_AES_C */ @@ -241,23 +241,23 @@ int mbedtls_pem_read_buffer( mbedtls_pem_context *ctx, const char *header, const ( MBEDTLS_AES_C || MBEDTLS_DES_C ) */ if( ctx == NULL ) - return( MBEDTLS_ERR_PEM_BAD_INPUT_DATA ); + return MBEDTLS_ERR_PEM_BAD_INPUT_DATA ; s1 = (unsigned char *) strstr( (const char *) data, header ); if( s1 == NULL ) - return( MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT ); + return MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT ; s2 = (unsigned char *) strstr( (const char *) data, footer ); if( s2 == NULL || s2 <= s1 ) - return( MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT ); + return MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT ; s1 += strlen( header ); if( *s1 == ' ' ) s1++; if( *s1 == '\r' ) s1++; if( *s1 == '\n' ) s1++; - else return( MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT ); + else return MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT ; end = s2; end += strlen( footer ); @@ -277,7 +277,7 @@ int mbedtls_pem_read_buffer( mbedtls_pem_context *ctx, const char *header, const s1 += 22; if( *s1 == '\r' ) s1++; if( *s1 == '\n' ) s1++; - else return( MBEDTLS_ERR_PEM_INVALID_DATA ); + else return MBEDTLS_ERR_PEM_INVALID_DATA ; #if defined(MBEDTLS_DES_C) @@ -287,7 +287,7 @@ int mbedtls_pem_read_buffer( mbedtls_pem_context *ctx, const char *header, const s1 += 23; if( s2 - s1 < 16 || pem_get_iv( s1, pem_iv, 8 ) != 0 ) - return( MBEDTLS_ERR_PEM_INVALID_ENC_IV ); + return MBEDTLS_ERR_PEM_INVALID_ENC_IV ; s1 += 16; } @@ -297,7 +297,7 @@ int mbedtls_pem_read_buffer( mbedtls_pem_context *ctx, const char *header, const s1 += 18; if( s2 - s1 < 16 || pem_get_iv( s1, pem_iv, 8) != 0 ) - return( MBEDTLS_ERR_PEM_INVALID_ENC_IV ); + return MBEDTLS_ERR_PEM_INVALID_ENC_IV ; s1 += 16; } @@ -307,7 +307,7 @@ int mbedtls_pem_read_buffer( mbedtls_pem_context *ctx, const char *header, const if( s2 - s1 >= 14 && memcmp( s1, "DEK-Info: AES-", 14 ) == 0 ) { if( s2 - s1 < 22 ) - return( MBEDTLS_ERR_PEM_UNKNOWN_ENC_ALG ); + return MBEDTLS_ERR_PEM_UNKNOWN_ENC_ALG ; else if( memcmp( s1, "DEK-Info: AES-128-CBC,", 22 ) == 0 ) enc_alg = MBEDTLS_CIPHER_AES_128_CBC; else if( memcmp( s1, "DEK-Info: AES-192-CBC,", 22 ) == 0 ) @@ -315,44 +315,44 @@ int mbedtls_pem_read_buffer( mbedtls_pem_context *ctx, const char *header, const else if( memcmp( s1, "DEK-Info: AES-256-CBC,", 22 ) == 0 ) enc_alg = MBEDTLS_CIPHER_AES_256_CBC; else - return( MBEDTLS_ERR_PEM_UNKNOWN_ENC_ALG ); + return MBEDTLS_ERR_PEM_UNKNOWN_ENC_ALG ; s1 += 22; if( s2 - s1 < 32 || pem_get_iv( s1, pem_iv, 16 ) != 0 ) - return( MBEDTLS_ERR_PEM_INVALID_ENC_IV ); + return MBEDTLS_ERR_PEM_INVALID_ENC_IV ; s1 += 32; } #endif /* MBEDTLS_AES_C */ if( enc_alg == MBEDTLS_CIPHER_NONE ) - return( MBEDTLS_ERR_PEM_UNKNOWN_ENC_ALG ); + return MBEDTLS_ERR_PEM_UNKNOWN_ENC_ALG ; if( *s1 == '\r' ) s1++; if( *s1 == '\n' ) s1++; - else return( MBEDTLS_ERR_PEM_INVALID_DATA ); + else return MBEDTLS_ERR_PEM_INVALID_DATA ; #else - return( MBEDTLS_ERR_PEM_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_PEM_FEATURE_UNAVAILABLE ; #endif /* MBEDTLS_MD5_C && MBEDTLS_CIPHER_MODE_CBC && ( MBEDTLS_AES_C || MBEDTLS_DES_C ) */ } if( s1 >= s2 ) - return( MBEDTLS_ERR_PEM_INVALID_DATA ); + return MBEDTLS_ERR_PEM_INVALID_DATA ; ret = mbedtls_base64_decode( NULL, 0, &len, s1, s2 - s1 ); if( ret == MBEDTLS_ERR_BASE64_INVALID_CHARACTER ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PEM_INVALID_DATA, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PEM_INVALID_DATA, ret ) ; if( ( buf = mbedtls_calloc( 1, len ) ) == NULL ) - return( MBEDTLS_ERR_PEM_ALLOC_FAILED ); + return MBEDTLS_ERR_PEM_ALLOC_FAILED ; if( ( ret = mbedtls_base64_decode( buf, len, &len, s1, s2 - s1 ) ) != 0 ) { mbedtls_platform_zeroize( buf, len ); mbedtls_free( buf ); - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PEM_INVALID_DATA, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PEM_INVALID_DATA, ret ) ; } if( enc != 0 ) @@ -363,7 +363,7 @@ int mbedtls_pem_read_buffer( mbedtls_pem_context *ctx, const char *header, const { mbedtls_platform_zeroize( buf, len ); mbedtls_free( buf ); - return( MBEDTLS_ERR_PEM_PASSWORD_REQUIRED ); + return MBEDTLS_ERR_PEM_PASSWORD_REQUIRED ; } ret = 0; @@ -387,7 +387,7 @@ int mbedtls_pem_read_buffer( mbedtls_pem_context *ctx, const char *header, const if( ret != 0 ) { mbedtls_free( buf ); - return( ret ); + return ret ; } /* @@ -400,12 +400,12 @@ int mbedtls_pem_read_buffer( mbedtls_pem_context *ctx, const char *header, const { mbedtls_platform_zeroize( buf, len ); mbedtls_free( buf ); - return( MBEDTLS_ERR_PEM_PASSWORD_MISMATCH ); + return MBEDTLS_ERR_PEM_PASSWORD_MISMATCH ; } #else mbedtls_platform_zeroize( buf, len ); mbedtls_free( buf ); - return( MBEDTLS_ERR_PEM_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_PEM_FEATURE_UNAVAILABLE ; #endif /* MBEDTLS_MD5_C && MBEDTLS_CIPHER_MODE_CBC && ( MBEDTLS_AES_C || MBEDTLS_DES_C ) */ } @@ -413,7 +413,7 @@ int mbedtls_pem_read_buffer( mbedtls_pem_context *ctx, const char *header, const ctx->buf = buf; ctx->buflen = len; - return( 0 ); + return 0 ; } void mbedtls_pem_free( mbedtls_pem_context *ctx ) @@ -444,18 +444,18 @@ int mbedtls_pem_write_buffer( const char *header, const char *footer, if( use_len + add_len > buf_len ) { *olen = use_len + add_len; - return( MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL ); + return MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL ; } if( use_len != 0 && ( ( encode_buf = mbedtls_calloc( 1, use_len ) ) == NULL ) ) - return( MBEDTLS_ERR_PEM_ALLOC_FAILED ); + return MBEDTLS_ERR_PEM_ALLOC_FAILED ; if( ( ret = mbedtls_base64_encode( encode_buf, use_len, &use_len, der_data, der_len ) ) != 0 ) { mbedtls_free( encode_buf ); - return( ret ); + return ret ; } memcpy( p, header, strlen( header ) ); @@ -482,7 +482,7 @@ int mbedtls_pem_write_buffer( const char *header, const char *footer, memset( buf + *olen, 0, buf_len - *olen ); mbedtls_free( encode_buf ); - return( 0 ); + return 0 ; } #endif /* MBEDTLS_PEM_WRITE_C */ #endif /* MBEDTLS_PEM_PARSE_C || MBEDTLS_PEM_WRITE_C */ diff --git a/library/pk.c b/library/pk.c index ea4869c14a..752357f908 100644 --- a/library/pk.c +++ b/library/pk.c @@ -111,21 +111,21 @@ const mbedtls_pk_info_t * mbedtls_pk_info_from_type( mbedtls_pk_type_t pk_type ) switch( pk_type ) { #if defined(MBEDTLS_RSA_C) case MBEDTLS_PK_RSA: - return( &mbedtls_rsa_info ); + return &mbedtls_rsa_info ; #endif #if defined(MBEDTLS_ECP_C) case MBEDTLS_PK_ECKEY: - return( &mbedtls_eckey_info ); + return &mbedtls_eckey_info ; case MBEDTLS_PK_ECKEY_DH: - return( &mbedtls_eckeydh_info ); + return &mbedtls_eckeydh_info ; #endif #if defined(MBEDTLS_ECDSA_C) case MBEDTLS_PK_ECDSA: - return( &mbedtls_ecdsa_info ); + return &mbedtls_ecdsa_info ; #endif /* MBEDTLS_PK_RSA_ALT omitted on purpose */ default: - return( NULL ); + return NULL ; } } @@ -136,14 +136,14 @@ int mbedtls_pk_setup( mbedtls_pk_context *ctx, const mbedtls_pk_info_t *info ) { PK_VALIDATE_RET( ctx != NULL ); if( info == NULL || ctx->pk_info != NULL ) - return( MBEDTLS_ERR_PK_BAD_INPUT_DATA ); + return MBEDTLS_ERR_PK_BAD_INPUT_DATA ; if( ( ctx->pk_ctx = info->ctx_alloc_func() ) == NULL ) - return( MBEDTLS_ERR_PK_ALLOC_FAILED ); + return MBEDTLS_ERR_PK_ALLOC_FAILED ; ctx->pk_info = info; - return( 0 ); + return 0 ; } #if defined(MBEDTLS_USE_PSA_CRYPTO) @@ -159,10 +159,10 @@ int mbedtls_pk_setup_opaque( mbedtls_pk_context *ctx, psa_key_type_t type; if( ctx == NULL || ctx->pk_info != NULL ) - return( MBEDTLS_ERR_PK_BAD_INPUT_DATA ); + return MBEDTLS_ERR_PK_BAD_INPUT_DATA ; if( PSA_SUCCESS != psa_get_key_attributes( key, &attributes ) ) - return( MBEDTLS_ERR_PK_BAD_INPUT_DATA ); + return MBEDTLS_ERR_PK_BAD_INPUT_DATA ; type = psa_get_key_type( &attributes ); psa_reset_key_attributes( &attributes ); @@ -171,14 +171,14 @@ int mbedtls_pk_setup_opaque( mbedtls_pk_context *ctx, return( MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE) ; if( ( ctx->pk_ctx = info->ctx_alloc_func() ) == NULL ) - return( MBEDTLS_ERR_PK_ALLOC_FAILED ); + return MBEDTLS_ERR_PK_ALLOC_FAILED ; ctx->pk_info = info; pk_ctx = (psa_key_id_t *) ctx->pk_ctx; *pk_ctx = key; - return( 0 ); + return 0 ; } #endif /* MBEDTLS_USE_PSA_CRYPTO */ @@ -196,10 +196,10 @@ int mbedtls_pk_setup_rsa_alt( mbedtls_pk_context *ctx, void * key, PK_VALIDATE_RET( ctx != NULL ); if( ctx->pk_info != NULL ) - return( MBEDTLS_ERR_PK_BAD_INPUT_DATA ); + return MBEDTLS_ERR_PK_BAD_INPUT_DATA ; if( ( ctx->pk_ctx = info->ctx_alloc_func() ) == NULL ) - return( MBEDTLS_ERR_PK_ALLOC_FAILED ); + return MBEDTLS_ERR_PK_ALLOC_FAILED ; ctx->pk_info = info; @@ -210,7 +210,7 @@ int mbedtls_pk_setup_rsa_alt( mbedtls_pk_context *ctx, void * key, rsa_alt->sign_func = sign_func; rsa_alt->key_len_func = key_len_func; - return( 0 ); + return 0 ; } #endif /* MBEDTLS_PK_RSA_ALT_SUPPORT */ @@ -223,9 +223,9 @@ int mbedtls_pk_can_do( const mbedtls_pk_context *ctx, mbedtls_pk_type_t type ) * For backward compatibility, also accept NULL instead of a context * pointer. */ if( ctx == NULL || ctx->pk_info == NULL ) - return( 0 ); + return 0 ; - return( ctx->pk_info->can_do( type ) ); + return ctx->pk_info->can_do( type ) ; } /* @@ -236,13 +236,13 @@ static inline int pk_hashlen_helper( mbedtls_md_type_t md_alg, size_t *hash_len const mbedtls_md_info_t *md_info; if( *hash_len != 0 ) - return( 0 ); + return 0 ; if( ( md_info = mbedtls_md_info_from_type( md_alg ) ) == NULL ) - return( -1 ); + return -1 ; *hash_len = mbedtls_md_get_size( md_info ); - return( 0 ); + return 0 ; } #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE) @@ -254,18 +254,18 @@ static int pk_restart_setup( mbedtls_pk_restart_ctx *ctx, { /* Don't do anything if already set up or invalid */ if( ctx == NULL || ctx->pk_info != NULL ) - return( 0 ); + return 0 ; /* Should never happen when we're called */ if( info->rs_alloc_func == NULL || info->rs_free_func == NULL ) - return( MBEDTLS_ERR_PK_BAD_INPUT_DATA ); + return MBEDTLS_ERR_PK_BAD_INPUT_DATA ; if( ( ctx->rs_ctx = info->rs_alloc_func() ) == NULL ) - return( MBEDTLS_ERR_PK_ALLOC_FAILED ); + return MBEDTLS_ERR_PK_ALLOC_FAILED ; ctx->pk_info = info; - return( 0 ); + return 0 ; } #endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */ @@ -285,7 +285,7 @@ int mbedtls_pk_verify_restartable( mbedtls_pk_context *ctx, if( ctx->pk_info == NULL || pk_hashlen_helper( md_alg, &hash_len ) != 0 ) - return( MBEDTLS_ERR_PK_BAD_INPUT_DATA ); + return MBEDTLS_ERR_PK_BAD_INPUT_DATA ; #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE) /* optimization: use non-restartable version if restart disabled */ @@ -296,7 +296,7 @@ int mbedtls_pk_verify_restartable( mbedtls_pk_context *ctx, int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; if( ( ret = pk_restart_setup( rs_ctx, ctx->pk_info ) ) != 0 ) - return( ret ); + return ret ; ret = ctx->pk_info->verify_rs_func( ctx->pk_ctx, md_alg, hash, hash_len, sig, sig_len, rs_ctx->rs_ctx ); @@ -304,14 +304,14 @@ int mbedtls_pk_verify_restartable( mbedtls_pk_context *ctx, if( ret != MBEDTLS_ERR_ECP_IN_PROGRESS ) mbedtls_pk_restart_free( rs_ctx ); - return( ret ); + return ret ; } #else /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */ (void) rs_ctx; #endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */ if( ctx->pk_info->verify_func == NULL ) - return( MBEDTLS_ERR_PK_TYPE_MISMATCH ); + return MBEDTLS_ERR_PK_TYPE_MISMATCH ; return( ctx->pk_info->verify_func( ctx->pk_ctx, md_alg, hash, hash_len, sig, sig_len ) ); @@ -342,10 +342,10 @@ int mbedtls_pk_verify_ext( mbedtls_pk_type_t type, const void *options, PK_VALIDATE_RET( sig != NULL ); if( ctx->pk_info == NULL ) - return( MBEDTLS_ERR_PK_BAD_INPUT_DATA ); + return MBEDTLS_ERR_PK_BAD_INPUT_DATA ; if( ! mbedtls_pk_can_do( ctx, type ) ) - return( MBEDTLS_ERR_PK_TYPE_MISMATCH ); + return MBEDTLS_ERR_PK_TYPE_MISMATCH ; if( type == MBEDTLS_PK_RSASSA_PSS ) { @@ -355,16 +355,16 @@ int mbedtls_pk_verify_ext( mbedtls_pk_type_t type, const void *options, #if SIZE_MAX > UINT_MAX if( md_alg == MBEDTLS_MD_NONE && UINT_MAX < hash_len ) - return( MBEDTLS_ERR_PK_BAD_INPUT_DATA ); + return MBEDTLS_ERR_PK_BAD_INPUT_DATA ; #endif /* SIZE_MAX > UINT_MAX */ if( options == NULL ) - return( MBEDTLS_ERR_PK_BAD_INPUT_DATA ); + return MBEDTLS_ERR_PK_BAD_INPUT_DATA ; pss_opts = (const mbedtls_pk_rsassa_pss_options *) options; if( sig_len < mbedtls_pk_get_len( ctx ) ) - return( MBEDTLS_ERR_RSA_VERIFY_FAILED ); + return MBEDTLS_ERR_RSA_VERIFY_FAILED ; ret = mbedtls_rsa_rsassa_pss_verify_ext( mbedtls_pk_rsa( *ctx ), md_alg, (unsigned int) hash_len, hash, @@ -372,22 +372,22 @@ int mbedtls_pk_verify_ext( mbedtls_pk_type_t type, const void *options, pss_opts->expected_salt_len, sig ); if( ret != 0 ) - return( ret ); + return ret ; if( sig_len > mbedtls_pk_get_len( ctx ) ) - return( MBEDTLS_ERR_PK_SIG_LEN_MISMATCH ); + return MBEDTLS_ERR_PK_SIG_LEN_MISMATCH ; - return( 0 ); + return 0 ; #else - return( MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE ; #endif /* MBEDTLS_RSA_C && MBEDTLS_PKCS1_V21 */ } /* General case: no options */ if( options != NULL ) - return( MBEDTLS_ERR_PK_BAD_INPUT_DATA ); + return MBEDTLS_ERR_PK_BAD_INPUT_DATA ; - return( mbedtls_pk_verify( ctx, md_alg, hash, hash_len, sig, sig_len ) ); + return mbedtls_pk_verify( ctx, md_alg, hash, hash_len, sig, sig_len ) ; } /* @@ -407,7 +407,7 @@ int mbedtls_pk_sign_restartable( mbedtls_pk_context *ctx, if( ctx->pk_info == NULL || pk_hashlen_helper( md_alg, &hash_len ) != 0 ) - return( MBEDTLS_ERR_PK_BAD_INPUT_DATA ); + return MBEDTLS_ERR_PK_BAD_INPUT_DATA ; #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE) /* optimization: use non-restartable version if restart disabled */ @@ -418,7 +418,7 @@ int mbedtls_pk_sign_restartable( mbedtls_pk_context *ctx, int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; if( ( ret = pk_restart_setup( rs_ctx, ctx->pk_info ) ) != 0 ) - return( ret ); + return ret ; ret = ctx->pk_info->sign_rs_func( ctx->pk_ctx, md_alg, hash, hash_len, @@ -428,14 +428,14 @@ int mbedtls_pk_sign_restartable( mbedtls_pk_context *ctx, if( ret != MBEDTLS_ERR_ECP_IN_PROGRESS ) mbedtls_pk_restart_free( rs_ctx ); - return( ret ); + return ret ; } #else /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */ (void) rs_ctx; #endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */ if( ctx->pk_info->sign_func == NULL ) - return( MBEDTLS_ERR_PK_TYPE_MISMATCH ); + return MBEDTLS_ERR_PK_TYPE_MISMATCH ; return( ctx->pk_info->sign_func( ctx->pk_ctx, md_alg, hash, hash_len, @@ -470,10 +470,10 @@ int mbedtls_pk_decrypt( mbedtls_pk_context *ctx, PK_VALIDATE_RET( olen != NULL ); if( ctx->pk_info == NULL ) - return( MBEDTLS_ERR_PK_BAD_INPUT_DATA ); + return MBEDTLS_ERR_PK_BAD_INPUT_DATA ; if( ctx->pk_info->decrypt_func == NULL ) - return( MBEDTLS_ERR_PK_TYPE_MISMATCH ); + return MBEDTLS_ERR_PK_TYPE_MISMATCH ; return( ctx->pk_info->decrypt_func( ctx->pk_ctx, input, ilen, output, olen, osize, f_rng, p_rng ) ); @@ -493,10 +493,10 @@ int mbedtls_pk_encrypt( mbedtls_pk_context *ctx, PK_VALIDATE_RET( olen != NULL ); if( ctx->pk_info == NULL ) - return( MBEDTLS_ERR_PK_BAD_INPUT_DATA ); + return MBEDTLS_ERR_PK_BAD_INPUT_DATA ; if( ctx->pk_info->encrypt_func == NULL ) - return( MBEDTLS_ERR_PK_TYPE_MISMATCH ); + return MBEDTLS_ERR_PK_TYPE_MISMATCH ; return( ctx->pk_info->encrypt_func( ctx->pk_ctx, input, ilen, output, olen, osize, f_rng, p_rng ) ); @@ -516,27 +516,27 @@ int mbedtls_pk_check_pair( const mbedtls_pk_context *pub, if( pub->pk_info == NULL || prv->pk_info == NULL ) { - return( MBEDTLS_ERR_PK_BAD_INPUT_DATA ); + return MBEDTLS_ERR_PK_BAD_INPUT_DATA ; } if( f_rng == NULL ) - return( MBEDTLS_ERR_PK_BAD_INPUT_DATA ); + return MBEDTLS_ERR_PK_BAD_INPUT_DATA ; if( prv->pk_info->check_pair_func == NULL ) - return( MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE ; if( prv->pk_info->type == MBEDTLS_PK_RSA_ALT ) { if( pub->pk_info->type != MBEDTLS_PK_RSA ) - return( MBEDTLS_ERR_PK_TYPE_MISMATCH ); + return MBEDTLS_ERR_PK_TYPE_MISMATCH ; } else { if( pub->pk_info != prv->pk_info ) - return( MBEDTLS_ERR_PK_TYPE_MISMATCH ); + return MBEDTLS_ERR_PK_TYPE_MISMATCH ; } - return( prv->pk_info->check_pair_func( pub->pk_ctx, prv->pk_ctx, f_rng, p_rng ) ); + return prv->pk_info->check_pair_func( pub->pk_ctx, prv->pk_ctx, f_rng, p_rng ) ; } /* @@ -547,9 +547,9 @@ size_t mbedtls_pk_get_bitlen( const mbedtls_pk_context *ctx ) /* For backward compatibility, accept NULL or a context that * isn't set up yet, and return a fake value that should be safe. */ if( ctx == NULL || ctx->pk_info == NULL ) - return( 0 ); + return 0 ; - return( ctx->pk_info->get_bitlen( ctx->pk_ctx ) ); + return ctx->pk_info->get_bitlen( ctx->pk_ctx ) ; } /* @@ -559,13 +559,13 @@ int mbedtls_pk_debug( const mbedtls_pk_context *ctx, mbedtls_pk_debug_item *item { PK_VALIDATE_RET( ctx != NULL ); if( ctx->pk_info == NULL ) - return( MBEDTLS_ERR_PK_BAD_INPUT_DATA ); + return MBEDTLS_ERR_PK_BAD_INPUT_DATA ; if( ctx->pk_info->debug_func == NULL ) - return( MBEDTLS_ERR_PK_TYPE_MISMATCH ); + return MBEDTLS_ERR_PK_TYPE_MISMATCH ; ctx->pk_info->debug_func( ctx->pk_ctx, items ); - return( 0 ); + return 0 ; } /* @@ -574,9 +574,9 @@ int mbedtls_pk_debug( const mbedtls_pk_context *ctx, mbedtls_pk_debug_item *item const char *mbedtls_pk_get_name( const mbedtls_pk_context *ctx ) { if( ctx == NULL || ctx->pk_info == NULL ) - return( "invalid PK" ); + return "invalid PK" ; - return( ctx->pk_info->name ); + return ctx->pk_info->name ; } /* @@ -585,9 +585,9 @@ const char *mbedtls_pk_get_name( const mbedtls_pk_context *ctx ) mbedtls_pk_type_t mbedtls_pk_get_type( const mbedtls_pk_context *ctx ) { if( ctx == NULL || ctx->pk_info == NULL ) - return( MBEDTLS_PK_NONE ); + return MBEDTLS_PK_NONE ; - return( ctx->pk_info->type ); + return ctx->pk_info->type ; } #if defined(MBEDTLS_USE_PSA_CRYPTO) @@ -605,7 +605,7 @@ int mbedtls_pk_wrap_as_opaque( mbedtls_pk_context *pk, ((void) pk); ((void) key); ((void) hash_alg); - return( MBEDTLS_ERR_PK_TYPE_MISMATCH ); + return MBEDTLS_ERR_PK_TYPE_MISMATCH ; #else const mbedtls_ecp_keypair *ec; unsigned char d[MBEDTLS_ECP_MAX_BYTES]; @@ -618,12 +618,12 @@ int mbedtls_pk_wrap_as_opaque( mbedtls_pk_context *pk, /* export the private key material in the format PSA wants */ if( mbedtls_pk_get_type( pk ) != MBEDTLS_PK_ECKEY ) - return( MBEDTLS_ERR_PK_TYPE_MISMATCH ); + return MBEDTLS_ERR_PK_TYPE_MISMATCH ; ec = mbedtls_pk_ec( *pk ); d_len = ( ec->grp.nbits + 7 ) / 8; if( ( ret = mbedtls_mpi_write_binary( &ec->d, d, d_len ) ) != 0 ) - return( ret ); + return ret ; curve_id = mbedtls_ecc_group_to_psa( ec->grp.id, &bits ); key_type = PSA_KEY_TYPE_ECC_KEY_PAIR( curve_id ); @@ -636,13 +636,13 @@ int mbedtls_pk_wrap_as_opaque( mbedtls_pk_context *pk, /* import private key into PSA */ if( PSA_SUCCESS != psa_import_key( &attributes, d, d_len, key ) ) - return( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED ); + return MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED ; /* make PK context wrap the key slot */ mbedtls_pk_free( pk ); mbedtls_pk_init( pk ); - return( mbedtls_pk_setup_opaque( pk, *key ) ); + return mbedtls_pk_setup_opaque( pk, *key ) ; #endif /* MBEDTLS_ECP_C */ } #endif /* MBEDTLS_USE_PSA_CRYPTO */ diff --git a/library/pk_wrap.c b/library/pk_wrap.c index 80c0aad27d..2b2b758ab7 100644 --- a/library/pk_wrap.c +++ b/library/pk_wrap.c @@ -71,7 +71,7 @@ static int rsa_can_do( mbedtls_pk_type_t type ) static size_t rsa_get_bitlen( const void *ctx ) { const mbedtls_rsa_context * rsa = (const mbedtls_rsa_context *) ctx; - return( 8 * mbedtls_rsa_get_len( rsa ) ); + return 8 * mbedtls_rsa_get_len( rsa ) ; } static int rsa_verify_wrap( void *ctx, mbedtls_md_type_t md_alg, @@ -84,16 +84,16 @@ static int rsa_verify_wrap( void *ctx, mbedtls_md_type_t md_alg, #if SIZE_MAX > UINT_MAX if( md_alg == MBEDTLS_MD_NONE && UINT_MAX < hash_len ) - return( MBEDTLS_ERR_PK_BAD_INPUT_DATA ); + return MBEDTLS_ERR_PK_BAD_INPUT_DATA ; #endif /* SIZE_MAX > UINT_MAX */ if( sig_len < rsa_len ) - return( MBEDTLS_ERR_RSA_VERIFY_FAILED ); + return MBEDTLS_ERR_RSA_VERIFY_FAILED ; if( ( ret = mbedtls_rsa_pkcs1_verify( rsa, md_alg, (unsigned int) hash_len, hash, sig ) ) != 0 ) - return( ret ); + return ret ; /* The buffer contains a valid signature followed by extra data. * We have a special error code for that so that so that callers can @@ -101,9 +101,9 @@ static int rsa_verify_wrap( void *ctx, mbedtls_md_type_t md_alg, * valid signature?" and not just "Does the buffer contain a valid * signature?". */ if( sig_len > rsa_len ) - return( MBEDTLS_ERR_PK_SIG_LEN_MISMATCH ); + return MBEDTLS_ERR_PK_SIG_LEN_MISMATCH ; - return( 0 ); + return 0 ; } static int rsa_sign_wrap( void *ctx, mbedtls_md_type_t md_alg, @@ -115,12 +115,12 @@ static int rsa_sign_wrap( void *ctx, mbedtls_md_type_t md_alg, #if SIZE_MAX > UINT_MAX if( md_alg == MBEDTLS_MD_NONE && UINT_MAX < hash_len ) - return( MBEDTLS_ERR_PK_BAD_INPUT_DATA ); + return MBEDTLS_ERR_PK_BAD_INPUT_DATA ; #endif /* SIZE_MAX > UINT_MAX */ *sig_len = mbedtls_rsa_get_len( rsa ); if( sig_size < *sig_len ) - return( MBEDTLS_ERR_PK_BUFFER_TOO_SMALL ); + return MBEDTLS_ERR_PK_BUFFER_TOO_SMALL ; return( mbedtls_rsa_pkcs1_sign( rsa, f_rng, p_rng, md_alg, (unsigned int) hash_len, @@ -135,7 +135,7 @@ static int rsa_decrypt_wrap( void *ctx, mbedtls_rsa_context * rsa = (mbedtls_rsa_context *) ctx; if( ilen != mbedtls_rsa_get_len( rsa ) ) - return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); + return MBEDTLS_ERR_RSA_BAD_INPUT_DATA ; return( mbedtls_rsa_pkcs1_decrypt( rsa, f_rng, p_rng, olen, input, output, osize ) ); @@ -150,7 +150,7 @@ static int rsa_encrypt_wrap( void *ctx, *olen = mbedtls_rsa_get_len( rsa ); if( *olen > osize ) - return( MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE ); + return MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE ; return( mbedtls_rsa_pkcs1_encrypt( rsa, f_rng, p_rng, ilen, input, output ) ); @@ -173,7 +173,7 @@ static void *rsa_alloc_wrap( void ) if( ctx != NULL ) mbedtls_rsa_init( (mbedtls_rsa_context *) ctx ); - return( ctx ); + return ctx ; } static void rsa_free_wrap( void *ctx ) @@ -238,7 +238,7 @@ static int eckey_can_do( mbedtls_pk_type_t type ) static size_t eckey_get_bitlen( const void *ctx ) { - return( ((mbedtls_ecp_keypair *) ctx)->grp.pbits ); + return ((mbedtls_ecp_keypair *) ctx)->grp.pbits ; } #if defined(MBEDTLS_ECDSA_C) @@ -266,7 +266,7 @@ static int eckey_verify_wrap( void *ctx, mbedtls_md_type_t md_alg, mbedtls_ecdsa_free( &ecdsa ); - return( ret ); + return ret ; } static int eckey_sign_wrap( void *ctx, mbedtls_md_type_t md_alg, @@ -286,7 +286,7 @@ static int eckey_sign_wrap( void *ctx, mbedtls_md_type_t md_alg, mbedtls_ecdsa_free( &ecdsa ); - return( ret ); + return ret ; } #if defined(MBEDTLS_ECP_RESTARTABLE) @@ -327,7 +327,7 @@ static void *eckey_rs_alloc( void ) mbedtls_ecdsa_init( &rs_ctx->ecdsa_ctx ); } - return( ctx ); + return ctx ; } static void eckey_rs_free( void *ctx ) @@ -354,7 +354,7 @@ static int eckey_verify_rs_wrap( void *ctx, mbedtls_md_type_t md_alg, /* Should never happen */ if( rs == NULL ) - return( MBEDTLS_ERR_PK_BAD_INPUT_DATA ); + return MBEDTLS_ERR_PK_BAD_INPUT_DATA ; /* set up our own sub-context if needed (that is, on first run) */ if( rs->ecdsa_ctx.grp.pbits == 0 ) @@ -365,7 +365,7 @@ static int eckey_verify_rs_wrap( void *ctx, mbedtls_md_type_t md_alg, sig, sig_len, &rs->ecdsa_rs ) ); cleanup: - return( ret ); + return ret ; } static int eckey_sign_rs_wrap( void *ctx, mbedtls_md_type_t md_alg, @@ -379,7 +379,7 @@ static int eckey_sign_rs_wrap( void *ctx, mbedtls_md_type_t md_alg, /* Should never happen */ if( rs == NULL ) - return( MBEDTLS_ERR_PK_BAD_INPUT_DATA ); + return MBEDTLS_ERR_PK_BAD_INPUT_DATA ; /* set up our own sub-context if needed (that is, on first run) */ if( rs->ecdsa_ctx.grp.pbits == 0 ) @@ -390,7 +390,7 @@ static int eckey_sign_rs_wrap( void *ctx, mbedtls_md_type_t md_alg, f_rng, p_rng, &rs->ecdsa_rs ) ); cleanup: - return( ret ); + return ret ; } #endif /* MBEDTLS_ECP_RESTARTABLE */ #endif /* MBEDTLS_ECDSA_C */ @@ -411,7 +411,7 @@ static void *eckey_alloc_wrap( void ) if( ctx != NULL ) mbedtls_ecp_keypair_init( ctx ); - return( ctx ); + return ctx ; } static void eckey_free_wrap( void *ctx ) @@ -491,7 +491,7 @@ const mbedtls_pk_info_t mbedtls_eckeydh_info = { #if defined(MBEDTLS_ECDSA_C) static int ecdsa_can_do( mbedtls_pk_type_t type ) { - return( type == MBEDTLS_PK_ECDSA ); + return type == MBEDTLS_PK_ECDSA ; } #if defined(MBEDTLS_USE_PSA_CRYPTO) @@ -508,7 +508,7 @@ static int extract_ecdsa_sig_int( unsigned char **from, const unsigned char *end if( ( ret = mbedtls_asn1_get_tag( from, end, &unpadded_len, MBEDTLS_ASN1_INTEGER ) ) != 0 ) { - return( ret ); + return ret ; } while( unpadded_len > 0 && **from == 0x00 ) @@ -518,14 +518,14 @@ static int extract_ecdsa_sig_int( unsigned char **from, const unsigned char *end } if( unpadded_len > to_len || unpadded_len == 0 ) - return( MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ); + return MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ; padding_len = to_len - unpadded_len; memset( to, 0x00, padding_len ); memcpy( to + padding_len, *from, unpadded_len ); ( *from ) += unpadded_len; - return( 0 ); + return 0 ; } /* @@ -541,16 +541,16 @@ static int extract_ecdsa_sig( unsigned char **p, const unsigned char *end, if( ( ret = mbedtls_asn1_get_tag( p, end, &tmp_size, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 ) - return( ret ); + return ret ; /* Extract r */ if( ( ret = extract_ecdsa_sig_int( p, end, sig, int_size ) ) != 0 ) - return( ret ); + return ret ; /* Extract s */ if( ( ret = extract_ecdsa_sig_int( p, end, sig + int_size, int_size ) ) != 0 ) - return( ret ); + return ret ; - return( 0 ); + return 0 ; } static int ecdsa_verify_wrap( void *ctx_arg, mbedtls_md_type_t md_alg, @@ -576,7 +576,7 @@ static int ecdsa_verify_wrap( void *ctx_arg, mbedtls_md_type_t md_alg, ((void) md_alg); if( curve == 0 ) - return( MBEDTLS_ERR_PK_BAD_INPUT_DATA ); + return MBEDTLS_ERR_PK_BAD_INPUT_DATA ; /* mbedtls_pk_write_pubkey() expects a full PK context; * re-construct one to make it happy */ @@ -585,7 +585,7 @@ static int ecdsa_verify_wrap( void *ctx_arg, mbedtls_md_type_t md_alg, p = buf + sizeof( buf ); key_len = mbedtls_pk_write_pubkey( &p, buf, &key ); if( key_len <= 0 ) - return( MBEDTLS_ERR_PK_BAD_INPUT_DATA ); + return MBEDTLS_ERR_PK_BAD_INPUT_DATA ; psa_set_key_type( &attributes, PSA_KEY_TYPE_ECC_PUBLIC_KEY( curve ) ); psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_VERIFY_HASH ); @@ -633,7 +633,7 @@ static int ecdsa_verify_wrap( void *ctx_arg, mbedtls_md_type_t md_alg, cleanup: psa_destroy_key( key_id ); - return( ret ); + return ret ; } #else /* MBEDTLS_USE_PSA_CRYPTO */ static int ecdsa_verify_wrap( void *ctx, mbedtls_md_type_t md_alg, @@ -647,9 +647,9 @@ static int ecdsa_verify_wrap( void *ctx, mbedtls_md_type_t md_alg, hash, hash_len, sig, sig_len ); if( ret == MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH ) - return( MBEDTLS_ERR_PK_SIG_LEN_MISMATCH ); + return MBEDTLS_ERR_PK_SIG_LEN_MISMATCH ; - return( ret ); + return ret ; } #endif /* MBEDTLS_USE_PSA_CRYPTO */ @@ -679,9 +679,9 @@ static int ecdsa_verify_rs_wrap( void *ctx, mbedtls_md_type_t md_alg, (mbedtls_ecdsa_restart_ctx *) rs_ctx ); if( ret == MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH ) - return( MBEDTLS_ERR_PK_SIG_LEN_MISMATCH ); + return MBEDTLS_ERR_PK_SIG_LEN_MISMATCH ; - return( ret ); + return ret ; } static int ecdsa_sign_rs_wrap( void *ctx, mbedtls_md_type_t md_alg, @@ -705,7 +705,7 @@ static void *ecdsa_alloc_wrap( void ) if( ctx != NULL ) mbedtls_ecdsa_init( (mbedtls_ecdsa_context *) ctx ); - return( ctx ); + return ctx ; } static void ecdsa_free_wrap( void *ctx ) @@ -722,7 +722,7 @@ static void *ecdsa_rs_alloc( void ) if( ctx != NULL ) mbedtls_ecdsa_restart_init( ctx ); - return( ctx ); + return ctx ; } static void ecdsa_rs_free( void *ctx ) @@ -763,14 +763,14 @@ const mbedtls_pk_info_t mbedtls_ecdsa_info = { static int rsa_alt_can_do( mbedtls_pk_type_t type ) { - return( type == MBEDTLS_PK_RSA ); + return type == MBEDTLS_PK_RSA ; } static size_t rsa_alt_get_bitlen( const void *ctx ) { const mbedtls_rsa_alt_context *rsa_alt = (const mbedtls_rsa_alt_context *) ctx; - return( 8 * rsa_alt->key_len_func( rsa_alt->key ) ); + return 8 * rsa_alt->key_len_func( rsa_alt->key ) ; } static int rsa_alt_sign_wrap( void *ctx, mbedtls_md_type_t md_alg, @@ -782,14 +782,14 @@ static int rsa_alt_sign_wrap( void *ctx, mbedtls_md_type_t md_alg, #if SIZE_MAX > UINT_MAX if( UINT_MAX < hash_len ) - return( MBEDTLS_ERR_PK_BAD_INPUT_DATA ); + return MBEDTLS_ERR_PK_BAD_INPUT_DATA ; #endif /* SIZE_MAX > UINT_MAX */ *sig_len = rsa_alt->key_len_func( rsa_alt->key ); if( *sig_len > MBEDTLS_PK_SIGNATURE_MAX_SIZE ) - return( MBEDTLS_ERR_PK_BAD_INPUT_DATA ); + return MBEDTLS_ERR_PK_BAD_INPUT_DATA ; if( *sig_len > sig_size ) - return( MBEDTLS_ERR_PK_BUFFER_TOO_SMALL ); + return MBEDTLS_ERR_PK_BUFFER_TOO_SMALL ; return( rsa_alt->sign_func( rsa_alt->key, f_rng, p_rng, md_alg, (unsigned int) hash_len, hash, sig ) ); @@ -806,7 +806,7 @@ static int rsa_alt_decrypt_wrap( void *ctx, ((void) p_rng); if( ilen != rsa_alt->key_len_func( rsa_alt->key ) ) - return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); + return MBEDTLS_ERR_RSA_BAD_INPUT_DATA ; return( rsa_alt->decrypt_func( rsa_alt->key, olen, input, output, osize ) ); @@ -823,7 +823,7 @@ static int rsa_alt_check_pair( const void *pub, const void *prv, int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; if( rsa_alt_get_bitlen( prv ) != rsa_get_bitlen( pub ) ) - return( MBEDTLS_ERR_RSA_KEY_CHECK_FAILED ); + return MBEDTLS_ERR_RSA_KEY_CHECK_FAILED ; memset( hash, 0x2a, sizeof( hash ) ); @@ -832,16 +832,16 @@ static int rsa_alt_check_pair( const void *pub, const void *prv, sig, sizeof( sig ), &sig_len, f_rng, p_rng ) ) != 0 ) { - return( ret ); + return ret ; } if( rsa_verify_wrap( (void *) pub, MBEDTLS_MD_NONE, hash, sizeof( hash ), sig, sig_len ) != 0 ) { - return( MBEDTLS_ERR_RSA_KEY_CHECK_FAILED ); + return MBEDTLS_ERR_RSA_KEY_CHECK_FAILED ; } - return( 0 ); + return 0 ; } #endif /* MBEDTLS_RSA_C */ @@ -852,7 +852,7 @@ static void *rsa_alt_alloc_wrap( void ) if( ctx != NULL ) memset( ctx, 0, sizeof( mbedtls_rsa_alt_context ) ); - return( ctx ); + return ctx ; } static void rsa_alt_free_wrap( void *ctx ) @@ -898,7 +898,7 @@ static void *pk_opaque_alloc_wrap( void ) /* no _init() function to call, an calloc() already zeroized */ - return( ctx ); + return ctx ; } static void pk_opaque_free_wrap( void *ctx ) @@ -914,11 +914,11 @@ static size_t pk_opaque_get_bitlen( const void *ctx ) psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; if( PSA_SUCCESS != psa_get_key_attributes( *key, &attributes ) ) - return( 0 ); + return 0 ; bits = psa_get_key_bits( &attributes ); psa_reset_key_attributes( &attributes ); - return( bits ); + return bits ; } static int pk_opaque_can_do( mbedtls_pk_type_t type ) @@ -948,7 +948,7 @@ static int asn1_write_mpibuf( unsigned char **p, unsigned char *start, size_t len = 0; if( (size_t)( *p - start ) < n_len ) - return( MBEDTLS_ERR_ASN1_BUF_TOO_SMALL ); + return MBEDTLS_ERR_ASN1_BUF_TOO_SMALL ; len = n_len; *p -= len; @@ -965,14 +965,14 @@ static int asn1_write_mpibuf( unsigned char **p, unsigned char *start, /* this is only reached if the signature was invalid */ if( len == 0 ) - return( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED ); + return MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED ; /* if the msb is 1, ASN.1 requires that we prepend a 0. * Neither r nor s can be 0, so we can assume len > 0 at all times. */ if( **p & 0x80 ) { if( *p - start < 1 ) - return( MBEDTLS_ERR_ASN1_BUF_TOO_SMALL ); + return MBEDTLS_ERR_ASN1_BUF_TOO_SMALL ; *--(*p) = 0x00; len += 1; @@ -982,7 +982,7 @@ static int asn1_write_mpibuf( unsigned char **p, unsigned char *start, MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( p, start, MBEDTLS_ASN1_INTEGER ) ); - return( (int) len ); + return (int) len ; } /* Transcode signature from PSA format to ASN.1 sequence. @@ -1011,7 +1011,7 @@ static int pk_ecdsa_sig_asn1_from_psa( unsigned char *sig, size_t *sig_len, memmove( sig, p, len ); *sig_len = len; - return( 0 ); + return 0 ; } #endif /* MBEDTLS_ECDSA_C */ @@ -1031,7 +1031,7 @@ static int pk_opaque_sign_wrap( void *ctx, mbedtls_md_type_t md_alg, ((void) sig_len); ((void) f_rng); ((void) p_rng); - return( MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE ; #else /* !MBEDTLS_ECDSA_C */ const psa_key_id_t *key = (const psa_key_id_t *) ctx; psa_algorithm_t alg = PSA_ALG_ECDSA( mbedtls_psa_translate_md( md_alg ) ); @@ -1045,10 +1045,10 @@ static int pk_opaque_sign_wrap( void *ctx, mbedtls_md_type_t md_alg, status = psa_sign_hash( *key, alg, hash, hash_len, sig, sig_size, sig_len ); if( status != PSA_SUCCESS ) - return( mbedtls_psa_err_translate_pk( status ) ); + return mbedtls_psa_err_translate_pk( status ) ; /* transcode it to ASN.1 sequence */ - return( pk_ecdsa_sig_asn1_from_psa( sig, sig_len, sig_size ) ); + return pk_ecdsa_sig_asn1_from_psa( sig, sig_len, sig_size ) ; #endif /* !MBEDTLS_ECDSA_C */ } diff --git a/library/pkcs12.c b/library/pkcs12.c index 04b1a6dab3..8e074dd056 100644 --- a/library/pkcs12.c +++ b/library/pkcs12.c @@ -60,19 +60,19 @@ static int pkcs12_parse_pbe_params( mbedtls_asn1_buf *params, MBEDTLS_ERR_ASN1_UNEXPECTED_TAG ) ); if( ( ret = mbedtls_asn1_get_tag( p, end, &salt->len, MBEDTLS_ASN1_OCTET_STRING ) ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PKCS12_PBE_INVALID_FORMAT, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PKCS12_PBE_INVALID_FORMAT, ret ) ; salt->p = *p; *p += salt->len; if( ( ret = mbedtls_asn1_get_int( p, end, iterations ) ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PKCS12_PBE_INVALID_FORMAT, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PKCS12_PBE_INVALID_FORMAT, ret ) ; if( *p != end ) return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PKCS12_PBE_INVALID_FORMAT, MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) ); - return( 0 ); + return 0 ; } #define PKCS12_MAX_PWDLEN 128 @@ -88,14 +88,14 @@ static int pkcs12_pbe_derive_key_iv( mbedtls_asn1_buf *pbe_params, mbedtls_md_ty unsigned char unipwd[PKCS12_MAX_PWDLEN * 2 + 2]; if( pwdlen > PKCS12_MAX_PWDLEN ) - return( MBEDTLS_ERR_PKCS12_BAD_INPUT_DATA ); + return MBEDTLS_ERR_PKCS12_BAD_INPUT_DATA ; memset( &salt, 0, sizeof(mbedtls_asn1_buf) ); memset( &unipwd, 0, sizeof(unipwd) ); if( ( ret = pkcs12_parse_pbe_params( pbe_params, &salt, &iterations ) ) != 0 ) - return( ret ); + return ret ; for( i = 0; i < pwdlen; i++ ) unipwd[i * 2 + 1] = pwd[i]; @@ -104,19 +104,19 @@ static int pkcs12_pbe_derive_key_iv( mbedtls_asn1_buf *pbe_params, mbedtls_md_ty salt.p, salt.len, md_type, MBEDTLS_PKCS12_DERIVE_KEY, iterations ) ) != 0 ) { - return( ret ); + return ret ; } if( iv == NULL || ivlen == 0 ) - return( 0 ); + return 0 ; if( ( ret = mbedtls_pkcs12_derivation( iv, ivlen, unipwd, pwdlen * 2 + 2, salt.p, salt.len, md_type, MBEDTLS_PKCS12_DERIVE_IV, iterations ) ) != 0 ) { - return( ret ); + return ret ; } - return( 0 ); + return 0 ; } #undef PKCS12_MAX_PWDLEN @@ -136,7 +136,7 @@ int mbedtls_pkcs12_pbe( mbedtls_asn1_buf *pbe_params, int mode, cipher_info = mbedtls_cipher_info_from_type( cipher_type ); if( cipher_info == NULL ) - return( MBEDTLS_ERR_PKCS12_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_PKCS12_FEATURE_UNAVAILABLE ; keylen = cipher_info->key_bitlen / 8; @@ -144,7 +144,7 @@ int mbedtls_pkcs12_pbe( mbedtls_asn1_buf *pbe_params, int mode, key, keylen, iv, cipher_info->iv_size ) ) != 0 ) { - return( ret ); + return ret ; } mbedtls_cipher_init( &cipher_ctx ); @@ -175,7 +175,7 @@ exit: mbedtls_platform_zeroize( iv, sizeof( iv ) ); mbedtls_cipher_free( &cipher_ctx ); - return( ret ); + return ret ; } #endif /* MBEDTLS_ASN1_PARSE_C */ @@ -216,16 +216,16 @@ int mbedtls_pkcs12_derivation( unsigned char *data, size_t datalen, // This version only allows max of 64 bytes of password or salt if( datalen > 128 || pwdlen > 64 || saltlen > 64 ) - return( MBEDTLS_ERR_PKCS12_BAD_INPUT_DATA ); + return MBEDTLS_ERR_PKCS12_BAD_INPUT_DATA ; md_info = mbedtls_md_info_from_type( md_type ); if( md_info == NULL ) - return( MBEDTLS_ERR_PKCS12_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_PKCS12_FEATURE_UNAVAILABLE ; mbedtls_md_init( &md_ctx ); if( ( ret = mbedtls_md_setup( &md_ctx, md_info, 0 ) ) != 0 ) - return( ret ); + return ret ; hlen = mbedtls_md_get_size( md_info ); if( hlen <= 32 ) @@ -309,7 +309,7 @@ exit: mbedtls_md_free( &md_ctx ); - return( ret ); + return ret ; } #endif /* MBEDTLS_PKCS12_C */ diff --git a/library/pkcs5.c b/library/pkcs5.c index 2b014d91c8..c7230bc1a0 100644 --- a/library/pkcs5.c +++ b/library/pkcs5.c @@ -73,37 +73,37 @@ static int pkcs5_parse_pbkdf2_params( const mbedtls_asn1_buf *params, */ if( ( ret = mbedtls_asn1_get_tag( &p, end, &salt->len, MBEDTLS_ASN1_OCTET_STRING ) ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PKCS5_INVALID_FORMAT, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PKCS5_INVALID_FORMAT, ret ) ; salt->p = p; p += salt->len; if( ( ret = mbedtls_asn1_get_int( &p, end, iterations ) ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PKCS5_INVALID_FORMAT, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PKCS5_INVALID_FORMAT, ret ) ; if( p == end ) - return( 0 ); + return 0 ; if( ( ret = mbedtls_asn1_get_int( &p, end, keylen ) ) != 0 ) { if( ret != MBEDTLS_ERR_ASN1_UNEXPECTED_TAG ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PKCS5_INVALID_FORMAT, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PKCS5_INVALID_FORMAT, ret ) ; } if( p == end ) - return( 0 ); + return 0 ; if( ( ret = mbedtls_asn1_get_alg_null( &p, end, &prf_alg_oid ) ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PKCS5_INVALID_FORMAT, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PKCS5_INVALID_FORMAT, ret ) ; if( mbedtls_oid_get_md_hmac( &prf_alg_oid, md_type ) != 0 ) - return( MBEDTLS_ERR_PKCS5_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_PKCS5_FEATURE_UNAVAILABLE ; if( p != end ) return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PKCS5_INVALID_FORMAT, MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) ); - return( 0 ); + return 0 ; } int mbedtls_pkcs5_pbes2( const mbedtls_asn1_buf *pbe_params, int mode, @@ -139,36 +139,36 @@ int mbedtls_pkcs5_pbes2( const mbedtls_asn1_buf *pbe_params, int mode, if( ( ret = mbedtls_asn1_get_alg( &p, end, &kdf_alg_oid, &kdf_alg_params ) ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PKCS5_INVALID_FORMAT, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PKCS5_INVALID_FORMAT, ret ) ; // Only PBKDF2 supported at the moment // if( MBEDTLS_OID_CMP( MBEDTLS_OID_PKCS5_PBKDF2, &kdf_alg_oid ) != 0 ) - return( MBEDTLS_ERR_PKCS5_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_PKCS5_FEATURE_UNAVAILABLE ; if( ( ret = pkcs5_parse_pbkdf2_params( &kdf_alg_params, &salt, &iterations, &keylen, &md_type ) ) != 0 ) { - return( ret ); + return ret ; } md_info = mbedtls_md_info_from_type( md_type ); if( md_info == NULL ) - return( MBEDTLS_ERR_PKCS5_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_PKCS5_FEATURE_UNAVAILABLE ; if( ( ret = mbedtls_asn1_get_alg( &p, end, &enc_scheme_oid, &enc_scheme_params ) ) != 0 ) { - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PKCS5_INVALID_FORMAT, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PKCS5_INVALID_FORMAT, ret ) ; } if( mbedtls_oid_get_cipher_alg( &enc_scheme_oid, &cipher_alg ) != 0 ) - return( MBEDTLS_ERR_PKCS5_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_PKCS5_FEATURE_UNAVAILABLE ; cipher_info = mbedtls_cipher_info_from_type( cipher_alg ); if( cipher_info == NULL ) - return( MBEDTLS_ERR_PKCS5_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_PKCS5_FEATURE_UNAVAILABLE ; /* * The value of keylen from pkcs5_parse_pbkdf2_params() is ignored @@ -179,7 +179,7 @@ int mbedtls_pkcs5_pbes2( const mbedtls_asn1_buf *pbe_params, int mode, if( enc_scheme_params.tag != MBEDTLS_ASN1_OCTET_STRING || enc_scheme_params.len != cipher_info->iv_size ) { - return( MBEDTLS_ERR_PKCS5_INVALID_FORMAT ); + return MBEDTLS_ERR_PKCS5_INVALID_FORMAT ; } mbedtls_md_init( &md_ctx ); @@ -211,7 +211,7 @@ exit: mbedtls_md_free( &md_ctx ); mbedtls_cipher_free( &cipher_ctx ); - return( ret ); + return ret ; } #endif /* MBEDTLS_ASN1_PARSE_C */ @@ -236,11 +236,11 @@ int mbedtls_pkcs5_pbkdf2_hmac( mbedtls_md_context_t *ctx, #if UINT_MAX > 0xFFFFFFFF if( iteration_count > 0xFFFFFFFF ) - return( MBEDTLS_ERR_PKCS5_BAD_INPUT_DATA ); + return MBEDTLS_ERR_PKCS5_BAD_INPUT_DATA ; #endif if( ( ret = mbedtls_md_hmac_starts( ctx, password, plen ) ) != 0 ) - return( ret ); + return ret ; while( key_length ) { // U1 ends up in work @@ -294,7 +294,7 @@ cleanup: mbedtls_platform_zeroize( work, MBEDTLS_MD_MAX_SIZE ); mbedtls_platform_zeroize( md1, MBEDTLS_MD_MAX_SIZE ); - return( ret ); + return ret ; } #if defined(MBEDTLS_SELF_TEST) @@ -305,7 +305,7 @@ int mbedtls_pkcs5_self_test( int verbose ) if( verbose != 0 ) mbedtls_printf( " PBKDF2 (SHA1): skipped\n\n" ); - return( 0 ); + return 0 ; } #else @@ -411,7 +411,7 @@ int mbedtls_pkcs5_self_test( int verbose ) exit: mbedtls_md_free( &sha1_ctx ); - return( ret ); + return ret ; } #endif /* MBEDTLS_SHA1_C */ diff --git a/library/pkparse.c b/library/pkparse.c index fe6aaca338..2b4916a13d 100644 --- a/library/pkparse.c +++ b/library/pkparse.c @@ -80,13 +80,13 @@ int mbedtls_pk_load_file( const char *path, unsigned char **buf, size_t *n ) PK_VALIDATE_RET( n != NULL ); if( ( f = fopen( path, "rb" ) ) == NULL ) - return( MBEDTLS_ERR_PK_FILE_IO_ERROR ); + return MBEDTLS_ERR_PK_FILE_IO_ERROR ; fseek( f, 0, SEEK_END ); if( ( size = ftell( f ) ) == -1 ) { fclose( f ); - return( MBEDTLS_ERR_PK_FILE_IO_ERROR ); + return MBEDTLS_ERR_PK_FILE_IO_ERROR ; } fseek( f, 0, SEEK_SET ); @@ -96,7 +96,7 @@ int mbedtls_pk_load_file( const char *path, unsigned char **buf, size_t *n ) ( *buf = mbedtls_calloc( 1, *n + 1 ) ) == NULL ) { fclose( f ); - return( MBEDTLS_ERR_PK_ALLOC_FAILED ); + return MBEDTLS_ERR_PK_ALLOC_FAILED ; } if( fread( *buf, 1, *n, f ) != *n ) @@ -106,7 +106,7 @@ int mbedtls_pk_load_file( const char *path, unsigned char **buf, size_t *n ) mbedtls_platform_zeroize( *buf, *n ); mbedtls_free( *buf ); - return( MBEDTLS_ERR_PK_FILE_IO_ERROR ); + return MBEDTLS_ERR_PK_FILE_IO_ERROR ; } fclose( f ); @@ -116,7 +116,7 @@ int mbedtls_pk_load_file( const char *path, unsigned char **buf, size_t *n ) if( strstr( (const char *) *buf, "-----BEGIN " ) != NULL ) ++*n; - return( 0 ); + return 0 ; } /* @@ -134,7 +134,7 @@ int mbedtls_pk_parse_keyfile( mbedtls_pk_context *ctx, PK_VALIDATE_RET( path != NULL ); if( ( ret = mbedtls_pk_load_file( path, &buf, &n ) ) != 0 ) - return( ret ); + return ret ; if( pwd == NULL ) ret = mbedtls_pk_parse_key( ctx, buf, n, NULL, 0, f_rng, p_rng ); @@ -145,7 +145,7 @@ int mbedtls_pk_parse_keyfile( mbedtls_pk_context *ctx, mbedtls_platform_zeroize( buf, n ); mbedtls_free( buf ); - return( ret ); + return ret ; } /* @@ -161,14 +161,14 @@ int mbedtls_pk_parse_public_keyfile( mbedtls_pk_context *ctx, const char *path ) PK_VALIDATE_RET( path != NULL ); if( ( ret = mbedtls_pk_load_file( path, &buf, &n ) ) != 0 ) - return( ret ); + return ret ; ret = mbedtls_pk_parse_public_key( ctx, buf, n ); mbedtls_platform_zeroize( buf, n ); mbedtls_free( buf ); - return( ret ); + return ret ; } #endif /* MBEDTLS_FS_IO */ @@ -204,7 +204,7 @@ static int pk_get_ecparams( unsigned char **p, const unsigned char *end, if( ( ret = mbedtls_asn1_get_tag( p, end, ¶ms->len, params->tag ) ) != 0 ) { - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ; } params->p = *p; @@ -214,7 +214,7 @@ static int pk_get_ecparams( unsigned char **p, const unsigned char *end, return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) ); - return( 0 ); + return 0 ; } #if defined(MBEDTLS_PK_PARSE_EC_EXTENDED) @@ -248,10 +248,10 @@ static int pk_group_from_specified( const mbedtls_asn1_buf *params, mbedtls_ecp_ /* SpecifiedECDomainVersion ::= INTEGER { 1, 2, 3 } */ if( ( ret = mbedtls_asn1_get_int( &p, end, &ver ) ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ; if( ver < 1 || ver > 3 ) - return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT ); + return MBEDTLS_ERR_PK_KEY_INVALID_FORMAT ; /* * FieldID { FIELD-ID:IOSet } ::= SEQUENCE { -- Finite field @@ -261,7 +261,7 @@ static int pk_group_from_specified( const mbedtls_asn1_buf *params, mbedtls_ecp_ */ if( ( ret = mbedtls_asn1_get_tag( &p, end, &len, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 ) - return( ret ); + return ret ; end_field = p + len; @@ -274,19 +274,19 @@ static int pk_group_from_specified( const mbedtls_asn1_buf *params, mbedtls_ecp_ * prime-field OBJECT IDENTIFIER ::= { id-fieldType 1 } */ if( ( ret = mbedtls_asn1_get_tag( &p, end_field, &len, MBEDTLS_ASN1_OID ) ) != 0 ) - return( ret ); + return ret ; if( len != MBEDTLS_OID_SIZE( MBEDTLS_OID_ANSI_X9_62_PRIME_FIELD ) || memcmp( p, MBEDTLS_OID_ANSI_X9_62_PRIME_FIELD, len ) != 0 ) { - return( MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE ; } p += len; /* Prime-p ::= INTEGER -- Field of size p. */ if( ( ret = mbedtls_asn1_get_mpi( &p, end_field, &grp->P ) ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ; grp->pbits = mbedtls_mpi_bitlen( &grp->P ); @@ -305,7 +305,7 @@ static int pk_group_from_specified( const mbedtls_asn1_buf *params, mbedtls_ecp_ */ if( ( ret = mbedtls_asn1_get_tag( &p, end, &len, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 ) - return( ret ); + return ret ; end_curve = p + len; @@ -316,7 +316,7 @@ static int pk_group_from_specified( const mbedtls_asn1_buf *params, mbedtls_ecp_ if( ( ret = mbedtls_asn1_get_tag( &p, end_curve, &len, MBEDTLS_ASN1_OCTET_STRING ) ) != 0 || ( ret = mbedtls_mpi_read_binary( &grp->A, p, len ) ) != 0 ) { - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ; } p += len; @@ -324,7 +324,7 @@ static int pk_group_from_specified( const mbedtls_asn1_buf *params, mbedtls_ecp_ if( ( ret = mbedtls_asn1_get_tag( &p, end_curve, &len, MBEDTLS_ASN1_OCTET_STRING ) ) != 0 || ( ret = mbedtls_mpi_read_binary( &grp->B, p, len ) ) != 0 ) { - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ; } p += len; @@ -341,7 +341,7 @@ static int pk_group_from_specified( const mbedtls_asn1_buf *params, mbedtls_ecp_ * ECPoint ::= OCTET STRING */ if( ( ret = mbedtls_asn1_get_tag( &p, end, &len, MBEDTLS_ASN1_OCTET_STRING ) ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ; if( ( ret = mbedtls_ecp_point_read_binary( grp, &grp->G, ( const unsigned char *) p, len ) ) != 0 ) @@ -357,7 +357,7 @@ static int pk_group_from_specified( const mbedtls_asn1_buf *params, mbedtls_ecp_ mbedtls_mpi_lset( &grp->G.Y, p[0] - 2 ) != 0 || mbedtls_mpi_lset( &grp->G.Z, 1 ) != 0 ) { - return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT ); + return MBEDTLS_ERR_PK_KEY_INVALID_FORMAT ; } } @@ -367,7 +367,7 @@ static int pk_group_from_specified( const mbedtls_asn1_buf *params, mbedtls_ecp_ * order INTEGER */ if( ( ret = mbedtls_asn1_get_mpi( &p, end, &grp->N ) ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ; grp->nbits = mbedtls_mpi_bitlen( &grp->N ); @@ -375,7 +375,7 @@ static int pk_group_from_specified( const mbedtls_asn1_buf *params, mbedtls_ecp_ * Allow optional elements by purposefully not enforcing p == end here. */ - return( 0 ); + return 0 ; } /* @@ -420,7 +420,7 @@ cleanup: if( ret == 0 && *id == MBEDTLS_ECP_DP_NONE ) ret = MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE; - return( ret ); + return ret ; } /* @@ -442,7 +442,7 @@ static int pk_group_id_from_specified( const mbedtls_asn1_buf *params, cleanup: mbedtls_ecp_group_free( &grp ); - return( ret ); + return ret ; } #endif /* MBEDTLS_PK_PARSE_EC_EXTENDED */ @@ -462,15 +462,15 @@ static int pk_use_ecparams( const mbedtls_asn1_buf *params, mbedtls_ecp_group *g if( params->tag == MBEDTLS_ASN1_OID ) { if( mbedtls_oid_get_ec_grp( params, &grp_id ) != 0 ) - return( MBEDTLS_ERR_PK_UNKNOWN_NAMED_CURVE ); + return MBEDTLS_ERR_PK_UNKNOWN_NAMED_CURVE ; } else { #if defined(MBEDTLS_PK_PARSE_EC_EXTENDED) if( ( ret = pk_group_id_from_specified( params, &grp_id ) ) != 0 ) - return( ret ); + return ret ; #else - return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT ); + return MBEDTLS_ERR_PK_KEY_INVALID_FORMAT ; #endif } @@ -478,12 +478,12 @@ static int pk_use_ecparams( const mbedtls_asn1_buf *params, mbedtls_ecp_group *g * grp may already be initilialized; if so, make sure IDs match */ if( grp->id != MBEDTLS_ECP_DP_NONE && grp->id != grp_id ) - return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT ); + return MBEDTLS_ERR_PK_KEY_INVALID_FORMAT ; if( ( ret = mbedtls_ecp_group_load( grp, grp_id ) ) != 0 ) - return( ret ); + return ret ; - return( 0 ); + return 0 ; } /* @@ -509,7 +509,7 @@ static int pk_get_ecpubkey( unsigned char **p, const unsigned char *end, */ *p = (unsigned char *) end; - return( ret ); + return ret ; } #endif /* MBEDTLS_ECP_C */ @@ -529,7 +529,7 @@ static int pk_get_rsapubkey( unsigned char **p, if( ( ret = mbedtls_asn1_get_tag( p, end, &len, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_INVALID_PUBKEY, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_INVALID_PUBKEY, ret ) ; if( *p + len != end ) return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_INVALID_PUBKEY, @@ -537,35 +537,35 @@ static int pk_get_rsapubkey( unsigned char **p, /* Import N */ if( ( ret = mbedtls_asn1_get_tag( p, end, &len, MBEDTLS_ASN1_INTEGER ) ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_INVALID_PUBKEY, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_INVALID_PUBKEY, ret ) ; if( ( ret = mbedtls_rsa_import_raw( rsa, *p, len, NULL, 0, NULL, 0, NULL, 0, NULL, 0 ) ) != 0 ) - return( MBEDTLS_ERR_PK_INVALID_PUBKEY ); + return MBEDTLS_ERR_PK_INVALID_PUBKEY ; *p += len; /* Import E */ if( ( ret = mbedtls_asn1_get_tag( p, end, &len, MBEDTLS_ASN1_INTEGER ) ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_INVALID_PUBKEY, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_INVALID_PUBKEY, ret ) ; if( ( ret = mbedtls_rsa_import_raw( rsa, NULL, 0, NULL, 0, NULL, 0, NULL, 0, *p, len ) ) != 0 ) - return( MBEDTLS_ERR_PK_INVALID_PUBKEY ); + return MBEDTLS_ERR_PK_INVALID_PUBKEY ; *p += len; if( mbedtls_rsa_complete( rsa ) != 0 || mbedtls_rsa_check_pubkey( rsa ) != 0 ) { - return( MBEDTLS_ERR_PK_INVALID_PUBKEY ); + return MBEDTLS_ERR_PK_INVALID_PUBKEY ; } if( *p != end ) return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_INVALID_PUBKEY, MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) ); - return( 0 ); + return 0 ; } #endif /* MBEDTLS_RSA_C */ @@ -585,10 +585,10 @@ static int pk_get_pk_alg( unsigned char **p, memset( params, 0, sizeof(mbedtls_asn1_buf) ); if( ( ret = mbedtls_asn1_get_alg( p, end, &alg_oid, params ) ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_INVALID_ALG, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_INVALID_ALG, ret ) ; if( mbedtls_oid_get_pk_alg( &alg_oid, pk_alg ) != 0 ) - return( MBEDTLS_ERR_PK_UNKNOWN_PK_ALG ); + return MBEDTLS_ERR_PK_UNKNOWN_PK_ALG ; /* * No parameters with RSA (only for EC) @@ -597,10 +597,10 @@ static int pk_get_pk_alg( unsigned char **p, ( ( params->tag != MBEDTLS_ASN1_NULL && params->tag != 0 ) || params->len != 0 ) ) { - return( MBEDTLS_ERR_PK_INVALID_ALG ); + return MBEDTLS_ERR_PK_INVALID_ALG ; } - return( 0 ); + return 0 ; } /* @@ -625,26 +625,26 @@ int mbedtls_pk_parse_subpubkey( unsigned char **p, const unsigned char *end, if( ( ret = mbedtls_asn1_get_tag( p, end, &len, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 ) { - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ; } end = *p + len; if( ( ret = pk_get_pk_alg( p, end, &pk_alg, &alg_params ) ) != 0 ) - return( ret ); + return ret ; if( ( ret = mbedtls_asn1_get_bitstring_null( p, end, &len ) ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_INVALID_PUBKEY, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_INVALID_PUBKEY, ret ) ; if( *p + len != end ) return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_INVALID_PUBKEY, MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) ); if( ( pk_info = mbedtls_pk_info_from_type( pk_alg ) ) == NULL ) - return( MBEDTLS_ERR_PK_UNKNOWN_PK_ALG ); + return MBEDTLS_ERR_PK_UNKNOWN_PK_ALG ; if( ( ret = mbedtls_pk_setup( pk, pk_info ) ) != 0 ) - return( ret ); + return ret ; #if defined(MBEDTLS_RSA_C) if( pk_alg == MBEDTLS_PK_RSA ) @@ -669,7 +669,7 @@ int mbedtls_pk_parse_subpubkey( unsigned char **p, const unsigned char *end, if( ret != 0 ) mbedtls_pk_free( pk ); - return( ret ); + return ret ; } #if defined(MBEDTLS_RSA_C) @@ -691,12 +691,12 @@ static int asn1_get_nonzero_mpi( unsigned char **p, ret = mbedtls_asn1_get_mpi( p, end, X ); if( ret != 0 ) - return( ret ); + return ret ; if( mbedtls_mpi_cmp_int( X, 0 ) == 0 ) - return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT ); + return MBEDTLS_ERR_PK_KEY_INVALID_FORMAT ; - return( 0 ); + return 0 ; } /* @@ -735,19 +735,19 @@ static int pk_parse_key_pkcs1_der( mbedtls_rsa_context *rsa, if( ( ret = mbedtls_asn1_get_tag( &p, end, &len, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 ) { - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ; } end = p + len; if( ( ret = mbedtls_asn1_get_int( &p, end, &version ) ) != 0 ) { - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ; } if( version != 0 ) { - return( MBEDTLS_ERR_PK_KEY_INVALID_VERSION ); + return MBEDTLS_ERR_PK_KEY_INVALID_VERSION ; } /* Import N */ @@ -851,7 +851,7 @@ cleanup: mbedtls_rsa_free( rsa ); } - return( ret ); + return ret ; } #endif /* MBEDTLS_RSA_C */ @@ -884,24 +884,24 @@ static int pk_parse_key_sec1_der( mbedtls_ecp_keypair *eck, if( ( ret = mbedtls_asn1_get_tag( &p, end, &len, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 ) { - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ; } end = p + len; if( ( ret = mbedtls_asn1_get_int( &p, end, &version ) ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ; if( version != 1 ) - return( MBEDTLS_ERR_PK_KEY_INVALID_VERSION ); + return MBEDTLS_ERR_PK_KEY_INVALID_VERSION ; if( ( ret = mbedtls_asn1_get_tag( &p, end, &len, MBEDTLS_ASN1_OCTET_STRING ) ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ; if( ( ret = mbedtls_mpi_read_binary( &eck->d, p, len ) ) != 0 ) { mbedtls_ecp_keypair_free( eck ); - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ; } p += len; @@ -919,13 +919,13 @@ static int pk_parse_key_sec1_der( mbedtls_ecp_keypair *eck, ( ret = pk_use_ecparams( ¶ms, &eck->grp ) ) != 0 ) { mbedtls_ecp_keypair_free( eck ); - return( ret ); + return ret ; } } else if( ret != MBEDTLS_ERR_ASN1_UNEXPECTED_TAG ) { mbedtls_ecp_keypair_free( eck ); - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ; } } @@ -941,7 +941,7 @@ static int pk_parse_key_sec1_der( mbedtls_ecp_keypair *eck, end2 = p + len; if( ( ret = mbedtls_asn1_get_bitstring_null( &p, end2, &len ) ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ; if( p + len != end2 ) return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, @@ -956,13 +956,13 @@ static int pk_parse_key_sec1_der( mbedtls_ecp_keypair *eck, * is if the point format is not recognized. */ if( ret != MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE ) - return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT ); + return MBEDTLS_ERR_PK_KEY_INVALID_FORMAT ; } } else if( ret != MBEDTLS_ERR_ASN1_UNEXPECTED_TAG ) { mbedtls_ecp_keypair_free( eck ); - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ; } } @@ -971,16 +971,16 @@ static int pk_parse_key_sec1_der( mbedtls_ecp_keypair *eck, f_rng, p_rng ) ) != 0 ) { mbedtls_ecp_keypair_free( eck ); - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ; } if( ( ret = mbedtls_ecp_check_privkey( &eck->grp, &eck->d ) ) != 0 ) { mbedtls_ecp_keypair_free( eck ); - return( ret ); + return ret ; } - return( 0 ); + return 0 ; } #endif /* MBEDTLS_ECP_C */ @@ -1034,34 +1034,34 @@ static int pk_parse_key_pkcs8_unencrypted_der( if( ( ret = mbedtls_asn1_get_tag( &p, end, &len, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 ) { - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ; } end = p + len; if( ( ret = mbedtls_asn1_get_int( &p, end, &version ) ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ; if( version != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_VERSION, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_VERSION, ret ) ; if( ( ret = pk_get_pk_alg( &p, end, &pk_alg, ¶ms ) ) != 0 ) { - return( ret ); + return ret ; } if( ( ret = mbedtls_asn1_get_tag( &p, end, &len, MBEDTLS_ASN1_OCTET_STRING ) ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ; if( len < 1 ) return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, MBEDTLS_ERR_ASN1_OUT_OF_DATA ) ); if( ( pk_info = mbedtls_pk_info_from_type( pk_alg ) ) == NULL ) - return( MBEDTLS_ERR_PK_UNKNOWN_PK_ALG ); + return MBEDTLS_ERR_PK_UNKNOWN_PK_ALG ; if( ( ret = mbedtls_pk_setup( pk, pk_info ) ) != 0 ) - return( ret ); + return ret ; #if defined(MBEDTLS_RSA_C) if( pk_alg == MBEDTLS_PK_RSA ) @@ -1069,7 +1069,7 @@ static int pk_parse_key_pkcs8_unencrypted_der( if( ( ret = pk_parse_key_pkcs1_der( mbedtls_pk_rsa( *pk ), p, len ) ) != 0 ) { mbedtls_pk_free( pk ); - return( ret ); + return ret ; } } else #endif /* MBEDTLS_RSA_C */ @@ -1080,13 +1080,13 @@ static int pk_parse_key_pkcs8_unencrypted_der( ( ret = pk_parse_key_sec1_der( mbedtls_pk_ec( *pk ), p, len, f_rng, p_rng ) ) != 0 ) { mbedtls_pk_free( pk ); - return( ret ); + return ret ; } } else #endif /* MBEDTLS_ECP_C */ - return( MBEDTLS_ERR_PK_UNKNOWN_PK_ALG ); + return MBEDTLS_ERR_PK_UNKNOWN_PK_ALG ; - return( 0 ); + return 0 ; } /* @@ -1119,7 +1119,7 @@ static int pk_parse_key_pkcs8_encrypted_der( end = p + keylen; if( pwdlen == 0 ) - return( MBEDTLS_ERR_PK_PASSWORD_REQUIRED ); + return MBEDTLS_ERR_PK_PASSWORD_REQUIRED ; /* * This function parses the EncryptedPrivateKeyInfo object (PKCS#8) @@ -1139,16 +1139,16 @@ static int pk_parse_key_pkcs8_encrypted_der( if( ( ret = mbedtls_asn1_get_tag( &p, end, &len, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 ) { - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ; } end = p + len; if( ( ret = mbedtls_asn1_get_alg( &p, end, &pbe_alg_oid, &pbe_params ) ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ; if( ( ret = mbedtls_asn1_get_tag( &p, end, &len, MBEDTLS_ASN1_OCTET_STRING ) ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ; buf = p; @@ -1163,9 +1163,9 @@ static int pk_parse_key_pkcs8_encrypted_der( pwd, pwdlen, p, len, buf ) ) != 0 ) { if( ret == MBEDTLS_ERR_PKCS12_PASSWORD_MISMATCH ) - return( MBEDTLS_ERR_PK_PASSWORD_MISMATCH ); + return MBEDTLS_ERR_PK_PASSWORD_MISMATCH ; - return( ret ); + return ret ; } decrypted = 1; @@ -1179,9 +1179,9 @@ static int pk_parse_key_pkcs8_encrypted_der( p, len, buf ) ) != 0 ) { if( ret == MBEDTLS_ERR_PKCS5_PASSWORD_MISMATCH ) - return( MBEDTLS_ERR_PK_PASSWORD_MISMATCH ); + return MBEDTLS_ERR_PK_PASSWORD_MISMATCH ; - return( ret ); + return ret ; } decrypted = 1; @@ -1193,9 +1193,9 @@ static int pk_parse_key_pkcs8_encrypted_der( } if( decrypted == 0 ) - return( MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE ; - return( pk_parse_key_pkcs8_unencrypted_der( pk, buf, len, f_rng, p_rng ) ); + return pk_parse_key_pkcs8_unencrypted_der( pk, buf, len, f_rng, p_rng ) ; } #endif /* MBEDTLS_PKCS12_C || MBEDTLS_PKCS5_C */ @@ -1216,7 +1216,7 @@ int mbedtls_pk_parse_key( mbedtls_pk_context *pk, PK_VALIDATE_RET( pk != NULL ); if( keylen == 0 ) - return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT ); + return MBEDTLS_ERR_PK_KEY_INVALID_FORMAT ; PK_VALIDATE_RET( key != NULL ); #if defined(MBEDTLS_PEM_PARSE_C) @@ -1243,14 +1243,14 @@ int mbedtls_pk_parse_key( mbedtls_pk_context *pk, } mbedtls_pem_free( &pem ); - return( ret ); + return ret ; } else if( ret == MBEDTLS_ERR_PEM_PASSWORD_MISMATCH ) - return( MBEDTLS_ERR_PK_PASSWORD_MISMATCH ); + return MBEDTLS_ERR_PK_PASSWORD_MISMATCH ; else if( ret == MBEDTLS_ERR_PEM_PASSWORD_REQUIRED ) - return( MBEDTLS_ERR_PK_PASSWORD_REQUIRED ); + return MBEDTLS_ERR_PK_PASSWORD_REQUIRED ; else if( ret != MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT ) - return( ret ); + return ret ; #endif /* MBEDTLS_RSA_C */ #if defined(MBEDTLS_ECP_C) @@ -1275,14 +1275,14 @@ int mbedtls_pk_parse_key( mbedtls_pk_context *pk, } mbedtls_pem_free( &pem ); - return( ret ); + return ret ; } else if( ret == MBEDTLS_ERR_PEM_PASSWORD_MISMATCH ) - return( MBEDTLS_ERR_PK_PASSWORD_MISMATCH ); + return MBEDTLS_ERR_PK_PASSWORD_MISMATCH ; else if( ret == MBEDTLS_ERR_PEM_PASSWORD_REQUIRED ) - return( MBEDTLS_ERR_PK_PASSWORD_REQUIRED ); + return MBEDTLS_ERR_PK_PASSWORD_REQUIRED ; else if( ret != MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT ) - return( ret ); + return ret ; #endif /* MBEDTLS_ECP_C */ /* Avoid calling mbedtls_pem_read_buffer() on non-null-terminated string */ @@ -1302,10 +1302,10 @@ int mbedtls_pk_parse_key( mbedtls_pk_context *pk, } mbedtls_pem_free( &pem ); - return( ret ); + return ret ; } else if( ret != MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT ) - return( ret ); + return ret ; #if defined(MBEDTLS_PKCS12_C) || defined(MBEDTLS_PKCS5_C) /* Avoid calling mbedtls_pem_read_buffer() on non-null-terminated string */ @@ -1325,10 +1325,10 @@ int mbedtls_pk_parse_key( mbedtls_pk_context *pk, } mbedtls_pem_free( &pem ); - return( ret ); + return ret ; } else if( ret != MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT ) - return( ret ); + return ret ; #endif /* MBEDTLS_PKCS12_C || MBEDTLS_PKCS5_C */ #else ((void) pwd); @@ -1347,7 +1347,7 @@ int mbedtls_pk_parse_key( mbedtls_pk_context *pk, unsigned char *key_copy; if( ( key_copy = mbedtls_calloc( 1, keylen ) ) == NULL ) - return( MBEDTLS_ERR_PK_ALLOC_FAILED ); + return MBEDTLS_ERR_PK_ALLOC_FAILED ; memcpy( key_copy, key, keylen ); @@ -1359,21 +1359,21 @@ int mbedtls_pk_parse_key( mbedtls_pk_context *pk, } if( ret == 0 ) - return( 0 ); + return 0 ; mbedtls_pk_free( pk ); mbedtls_pk_init( pk ); if( ret == MBEDTLS_ERR_PK_PASSWORD_MISMATCH ) { - return( ret ); + return ret ; } #endif /* MBEDTLS_PKCS12_C || MBEDTLS_PKCS5_C */ if( ( ret = pk_parse_key_pkcs8_unencrypted_der( pk, key, keylen, f_rng, p_rng ) ) == 0 ) { - return( 0 ); + return 0 ; } mbedtls_pk_free( pk ); @@ -1385,7 +1385,7 @@ int mbedtls_pk_parse_key( mbedtls_pk_context *pk, if( mbedtls_pk_setup( pk, pk_info ) == 0 && pk_parse_key_pkcs1_der( mbedtls_pk_rsa( *pk ), key, keylen ) == 0 ) { - return( 0 ); + return 0 ; } mbedtls_pk_free( pk ); @@ -1398,7 +1398,7 @@ int mbedtls_pk_parse_key( mbedtls_pk_context *pk, pk_parse_key_sec1_der( mbedtls_pk_ec( *pk ), key, keylen, f_rng, p_rng ) == 0 ) { - return( 0 ); + return 0 ; } mbedtls_pk_free( pk ); #endif /* MBEDTLS_ECP_C */ @@ -1413,7 +1413,7 @@ int mbedtls_pk_parse_key( mbedtls_pk_context *pk, * also ok and in line with the mbedtls_pk_free() calls * on failed PEM parsing attempts. */ - return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT ); + return MBEDTLS_ERR_PK_KEY_INVALID_FORMAT ; } /* @@ -1434,7 +1434,7 @@ int mbedtls_pk_parse_public_key( mbedtls_pk_context *ctx, PK_VALIDATE_RET( ctx != NULL ); if( keylen == 0 ) - return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT ); + return MBEDTLS_ERR_PK_KEY_INVALID_FORMAT ; PK_VALIDATE_RET( key != NULL || keylen == 0 ); #if defined(MBEDTLS_PEM_PARSE_C) @@ -1453,21 +1453,21 @@ int mbedtls_pk_parse_public_key( mbedtls_pk_context *ctx, { p = pem.buf; if( ( pk_info = mbedtls_pk_info_from_type( MBEDTLS_PK_RSA ) ) == NULL ) - return( MBEDTLS_ERR_PK_UNKNOWN_PK_ALG ); + return MBEDTLS_ERR_PK_UNKNOWN_PK_ALG ; if( ( ret = mbedtls_pk_setup( ctx, pk_info ) ) != 0 ) - return( ret ); + return ret ; if ( ( ret = pk_get_rsapubkey( &p, p + pem.buflen, mbedtls_pk_rsa( *ctx ) ) ) != 0 ) mbedtls_pk_free( ctx ); mbedtls_pem_free( &pem ); - return( ret ); + return ret ; } else if( ret != MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT ) { mbedtls_pem_free( &pem ); - return( ret ); + return ret ; } #endif /* MBEDTLS_RSA_C */ @@ -1489,41 +1489,41 @@ int mbedtls_pk_parse_public_key( mbedtls_pk_context *ctx, ret = mbedtls_pk_parse_subpubkey( &p, p + pem.buflen, ctx ); mbedtls_pem_free( &pem ); - return( ret ); + return ret ; } else if( ret != MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT ) { mbedtls_pem_free( &pem ); - return( ret ); + return ret ; } mbedtls_pem_free( &pem ); #endif /* MBEDTLS_PEM_PARSE_C */ #if defined(MBEDTLS_RSA_C) if( ( pk_info = mbedtls_pk_info_from_type( MBEDTLS_PK_RSA ) ) == NULL ) - return( MBEDTLS_ERR_PK_UNKNOWN_PK_ALG ); + return MBEDTLS_ERR_PK_UNKNOWN_PK_ALG ; if( ( ret = mbedtls_pk_setup( ctx, pk_info ) ) != 0 ) - return( ret ); + return ret ; p = (unsigned char *)key; ret = pk_get_rsapubkey( &p, p + keylen, mbedtls_pk_rsa( *ctx ) ); if( ret == 0 ) { - return( ret ); + return ret ; } mbedtls_pk_free( ctx ); if( ret != ( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_INVALID_PUBKEY, MBEDTLS_ERR_ASN1_UNEXPECTED_TAG ) ) ) { - return( ret ); + return ret ; } #endif /* MBEDTLS_RSA_C */ p = (unsigned char *) key; ret = mbedtls_pk_parse_subpubkey( &p, p + keylen, ctx ); - return( ret ); + return ret ; } #endif /* MBEDTLS_PK_PARSE_C */ diff --git a/library/pkwrite.c b/library/pkwrite.c index 71cc0f0c55..4e11a6de6a 100644 --- a/library/pkwrite.c +++ b/library/pkwrite.c @@ -94,13 +94,13 @@ end_of_export: mbedtls_mpi_free( &T ); if( ret < 0 ) - return( ret ); + return ret ; MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( p, start, len ) ); MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( p, start, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ); - return( (int) len ); + return (int) len ; } #endif /* MBEDTLS_RSA_C */ @@ -119,16 +119,16 @@ static int pk_write_ec_pubkey( unsigned char **p, unsigned char *start, MBEDTLS_ECP_PF_UNCOMPRESSED, &len, buf, sizeof( buf ) ) ) != 0 ) { - return( ret ); + return ret ; } if( *p < start || (size_t)( *p - start ) < len ) - return( MBEDTLS_ERR_ASN1_BUF_TOO_SMALL ); + return MBEDTLS_ERR_ASN1_BUF_TOO_SMALL ; *p -= len; memcpy( *p, buf, len ); - return( (int) len ); + return (int) len ; } /* @@ -145,11 +145,11 @@ static int pk_write_ec_param( unsigned char **p, unsigned char *start, size_t oid_len; if( ( ret = mbedtls_oid_get_oid_by_ec_grp( ec->grp.id, &oid, &oid_len ) ) != 0 ) - return( ret ); + return ret ; MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_oid( p, start, oid, oid_len ) ); - return( (int) len ); + return (int) len ; } /* @@ -169,7 +169,7 @@ static int pk_write_ec_private( unsigned char **p, unsigned char *start, exit: mbedtls_platform_zeroize( tmp, byte_length ); - return( ret ); + return ret ; } #endif /* MBEDTLS_ECP_C */ @@ -201,13 +201,13 @@ int mbedtls_pk_write_pubkey( unsigned char **p, unsigned char *start, psa_key_id_t* key_id = (psa_key_id_t*) key->pk_ctx; if ( *p < start ) - return( MBEDTLS_ERR_PK_BAD_INPUT_DATA ); + return MBEDTLS_ERR_PK_BAD_INPUT_DATA ; buffer_size = (size_t)( *p - start ); if ( psa_export_public_key( *key_id, start, buffer_size, &len ) != PSA_SUCCESS ) { - return( MBEDTLS_ERR_PK_BAD_INPUT_DATA ); + return MBEDTLS_ERR_PK_BAD_INPUT_DATA ; } else { @@ -217,9 +217,9 @@ int mbedtls_pk_write_pubkey( unsigned char **p, unsigned char *start, } else #endif /* MBEDTLS_USE_PSA_CRYPTO */ - return( MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE ; - return( (int) len ); + return (int) len ; } int mbedtls_pk_write_pubkey_der( const mbedtls_pk_context *key, unsigned char *buf, size_t size ) @@ -232,7 +232,7 @@ int mbedtls_pk_write_pubkey_der( const mbedtls_pk_context *key, unsigned char *b PK_VALIDATE_RET( key != NULL ); if( size == 0 ) - return( MBEDTLS_ERR_ASN1_BUF_TOO_SMALL ); + return MBEDTLS_ERR_ASN1_BUF_TOO_SMALL ; PK_VALIDATE_RET( buf != NULL ); c = buf + size; @@ -240,7 +240,7 @@ int mbedtls_pk_write_pubkey_der( const mbedtls_pk_context *key, unsigned char *b MBEDTLS_ASN1_CHK_ADD( len, mbedtls_pk_write_pubkey( &c, buf, key ) ); if( c - buf < 1 ) - return( MBEDTLS_ERR_ASN1_BUF_TOO_SMALL ); + return MBEDTLS_ERR_ASN1_BUF_TOO_SMALL ; /* * SubjectPublicKeyInfo ::= SEQUENCE { @@ -271,18 +271,18 @@ int mbedtls_pk_write_pubkey_der( const mbedtls_pk_context *key, unsigned char *b key_id = *((psa_key_id_t*) key->pk_ctx ); if( PSA_SUCCESS != psa_get_key_attributes( key_id, &attributes ) ) - return( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED ); + return MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED ; key_type = psa_get_key_type( &attributes ); bits = psa_get_key_bits( &attributes ); psa_reset_key_attributes( &attributes ); curve = PSA_KEY_TYPE_ECC_GET_FAMILY( key_type ); if( curve == 0 ) - return( MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE ; ret = mbedtls_psa_get_ecc_oid_from_id( curve, bits, &oid, &oid_len ); if( ret != 0 ) - return( MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE ; /* Write EC algorithm parameters; that's akin * to pk_write_ec_param() above. */ @@ -297,7 +297,7 @@ int mbedtls_pk_write_pubkey_der( const mbedtls_pk_context *key, unsigned char *b if( ( ret = mbedtls_oid_get_oid_by_pk_alg( pk_type, &oid, &oid_len ) ) != 0 ) { - return( ret ); + return ret ; } MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_algorithm_identifier( &c, buf, oid, oid_len, @@ -307,7 +307,7 @@ int mbedtls_pk_write_pubkey_der( const mbedtls_pk_context *key, unsigned char *b MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( &c, buf, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ); - return( (int) len ); + return (int) len ; } int mbedtls_pk_write_key_der( const mbedtls_pk_context *key, unsigned char *buf, size_t size ) @@ -318,7 +318,7 @@ int mbedtls_pk_write_key_der( const mbedtls_pk_context *key, unsigned char *buf, PK_VALIDATE_RET( key != NULL ); if( size == 0 ) - return( MBEDTLS_ERR_ASN1_BUF_TOO_SMALL ); + return MBEDTLS_ERR_ASN1_BUF_TOO_SMALL ; PK_VALIDATE_RET( buf != NULL ); c = buf + size; @@ -392,7 +392,7 @@ int mbedtls_pk_write_key_der( const mbedtls_pk_context *key, unsigned char *buf, mbedtls_mpi_free( &T ); if( ret < 0 ) - return( ret ); + return ret ; MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_int( &c, buf, 0 ) ); MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( &c, buf, len ) ); @@ -423,7 +423,7 @@ int mbedtls_pk_write_key_der( const mbedtls_pk_context *key, unsigned char *buf, MBEDTLS_ASN1_CHK_ADD( pub_len, pk_write_ec_pubkey( &c, buf, ec ) ); if( c - buf < 1 ) - return( MBEDTLS_ERR_ASN1_BUF_TOO_SMALL ); + return MBEDTLS_ERR_ASN1_BUF_TOO_SMALL ; *--c = 0; pub_len += 1; @@ -455,9 +455,9 @@ int mbedtls_pk_write_key_der( const mbedtls_pk_context *key, unsigned char *buf, } else #endif /* MBEDTLS_ECP_C */ - return( MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE ; - return( (int) len ); + return (int) len ; } #if defined(MBEDTLS_PEM_WRITE_C) @@ -565,17 +565,17 @@ int mbedtls_pk_write_pubkey_pem( const mbedtls_pk_context *key, unsigned char *b if( ( ret = mbedtls_pk_write_pubkey_der( key, output_buf, sizeof(output_buf) ) ) < 0 ) { - return( ret ); + return ret ; } if( ( ret = mbedtls_pem_write_buffer( PEM_BEGIN_PUBLIC_KEY, PEM_END_PUBLIC_KEY, output_buf + sizeof(output_buf) - ret, ret, buf, size, &olen ) ) != 0 ) { - return( ret ); + return ret ; } - return( 0 ); + return 0 ; } int mbedtls_pk_write_key_pem( const mbedtls_pk_context *key, unsigned char *buf, size_t size ) @@ -589,7 +589,7 @@ int mbedtls_pk_write_key_pem( const mbedtls_pk_context *key, unsigned char *buf, PK_VALIDATE_RET( buf != NULL || size == 0 ); if( ( ret = mbedtls_pk_write_key_der( key, output_buf, sizeof(output_buf) ) ) < 0 ) - return( ret ); + return ret ; #if defined(MBEDTLS_RSA_C) if( mbedtls_pk_get_type( key ) == MBEDTLS_PK_RSA ) @@ -607,16 +607,16 @@ int mbedtls_pk_write_key_pem( const mbedtls_pk_context *key, unsigned char *buf, } else #endif - return( MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE ; if( ( ret = mbedtls_pem_write_buffer( begin, end, output_buf + sizeof(output_buf) - ret, ret, buf, size, &olen ) ) != 0 ) { - return( ret ); + return ret ; } - return( 0 ); + return 0 ; } #endif /* MBEDTLS_PEM_WRITE_C */ diff --git a/library/platform.c b/library/platform.c index e742fde7cc..7ef6625706 100644 --- a/library/platform.c +++ b/library/platform.c @@ -38,7 +38,7 @@ static void *platform_calloc_uninit( size_t n, size_t size ) { ((void) n); ((void) size); - return( NULL ); + return NULL ; } #define MBEDTLS_PLATFORM_STD_CALLOC platform_calloc_uninit @@ -71,7 +71,7 @@ int mbedtls_platform_set_calloc_free( void * (*calloc_func)( size_t, size_t ), { mbedtls_calloc_func = calloc_func; mbedtls_free_func = free_func; - return( 0 ); + return 0 ; } #endif /* MBEDTLS_PLATFORM_MEMORY && !( defined(MBEDTLS_PLATFORM_CALLOC_MACRO) && @@ -88,7 +88,7 @@ int mbedtls_platform_win32_snprintf( char *s, size_t n, const char *fmt, ... ) ret = mbedtls_vsnprintf( s, n, fmt, argp ); va_end( argp ); - return( ret ); + return ret ; } #endif @@ -103,7 +103,7 @@ static int platform_snprintf_uninit( char * s, size_t n, ((void) s); ((void) n); ((void) format); - return( 0 ); + return 0 ; } #define MBEDTLS_PLATFORM_STD_SNPRINTF platform_snprintf_uninit @@ -118,7 +118,7 @@ int mbedtls_platform_set_snprintf( int (*snprintf_func)( char * s, size_t n, ... ) ) { mbedtls_snprintf = snprintf_func; - return( 0 ); + return 0 ; } #endif /* MBEDTLS_PLATFORM_SNPRINTF_ALT */ @@ -130,7 +130,7 @@ int mbedtls_platform_win32_vsnprintf( char *s, size_t n, const char *fmt, va_lis /* Avoid calling the invalid parameter handler by checking ourselves */ if( s == NULL || n == 0 || fmt == NULL ) - return( -1 ); + return -1 ; #if defined(_TRUNCATE) ret = vsnprintf_s( s, n, _TRUNCATE, fmt, arg ); @@ -143,7 +143,7 @@ int mbedtls_platform_win32_vsnprintf( char *s, size_t n, const char *fmt, va_lis } #endif - return( ret ); + return ret ; } #endif @@ -159,7 +159,7 @@ static int platform_vsnprintf_uninit( char * s, size_t n, ((void) n); ((void) format); ((void) arg); - return( -1 ); + return -1 ; } #define MBEDTLS_PLATFORM_STD_VSNPRINTF platform_vsnprintf_uninit @@ -174,7 +174,7 @@ int mbedtls_platform_set_vsnprintf( int (*vsnprintf_func)( char * s, size_t n, va_list arg ) ) { mbedtls_vsnprintf = vsnprintf_func; - return( 0 ); + return 0 ; } #endif /* MBEDTLS_PLATFORM_VSNPRINTF_ALT */ @@ -186,7 +186,7 @@ int mbedtls_platform_set_vsnprintf( int (*vsnprintf_func)( char * s, size_t n, static int platform_printf_uninit( const char *format, ... ) { ((void) format); - return( 0 ); + return 0 ; } #define MBEDTLS_PLATFORM_STD_PRINTF platform_printf_uninit @@ -197,7 +197,7 @@ int (*mbedtls_printf)( const char *, ... ) = MBEDTLS_PLATFORM_STD_PRINTF; int mbedtls_platform_set_printf( int (*printf_func)( const char *, ... ) ) { mbedtls_printf = printf_func; - return( 0 ); + return 0 ; } #endif /* MBEDTLS_PLATFORM_PRINTF_ALT */ @@ -210,7 +210,7 @@ static int platform_fprintf_uninit( FILE *stream, const char *format, ... ) { ((void) stream); ((void) format); - return( 0 ); + return 0 ; } #define MBEDTLS_PLATFORM_STD_FPRINTF platform_fprintf_uninit @@ -222,7 +222,7 @@ int (*mbedtls_fprintf)( FILE *, const char *, ... ) = int mbedtls_platform_set_fprintf( int (*fprintf_func)( FILE *, const char *, ... ) ) { mbedtls_fprintf = fprintf_func; - return( 0 ); + return 0 ; } #endif /* MBEDTLS_PLATFORM_FPRINTF_ALT */ @@ -244,7 +244,7 @@ void (*mbedtls_exit)( int status ) = MBEDTLS_PLATFORM_STD_EXIT; int mbedtls_platform_set_exit( void (*exit_func)( int status ) ) { mbedtls_exit = exit_func; - return( 0 ); + return 0 ; } #endif /* MBEDTLS_PLATFORM_EXIT_ALT */ @@ -258,7 +258,7 @@ int mbedtls_platform_set_exit( void (*exit_func)( int status ) ) static mbedtls_time_t platform_time_uninit( mbedtls_time_t* timer ) { ((void) timer); - return( 0 ); + return 0 ; } #define MBEDTLS_PLATFORM_STD_TIME platform_time_uninit @@ -269,7 +269,7 @@ mbedtls_time_t (*mbedtls_time)( mbedtls_time_t* timer ) = MBEDTLS_PLATFORM_STD_T int mbedtls_platform_set_time( mbedtls_time_t (*time_func)( mbedtls_time_t* timer ) ) { mbedtls_time = time_func; - return( 0 ); + return 0 ; } #endif /* MBEDTLS_PLATFORM_TIME_ALT */ @@ -286,17 +286,17 @@ int mbedtls_platform_std_nv_seed_read( unsigned char *buf, size_t buf_len ) size_t n; if( ( file = fopen( MBEDTLS_PLATFORM_STD_NV_SEED_FILE, "rb" ) ) == NULL ) - return( -1 ); + return -1 ; if( ( n = fread( buf, 1, buf_len, file ) ) != buf_len ) { fclose( file ); mbedtls_platform_zeroize( buf, buf_len ); - return( -1 ); + return -1 ; } fclose( file ); - return( (int)n ); + return (int)n ; } int mbedtls_platform_std_nv_seed_write( unsigned char *buf, size_t buf_len ) @@ -314,7 +314,7 @@ int mbedtls_platform_std_nv_seed_write( unsigned char *buf, size_t buf_len ) } fclose( file ); - return( (int)n ); + return (int)n ; } #endif /* MBEDTLS_PLATFORM_NO_STD_FUNCTIONS */ @@ -327,7 +327,7 @@ static int platform_nv_seed_read_uninit( unsigned char *buf, size_t buf_len ) { ((void) buf); ((void) buf_len); - return( -1 ); + return -1 ; } #define MBEDTLS_PLATFORM_STD_NV_SEED_READ platform_nv_seed_read_uninit @@ -341,7 +341,7 @@ static int platform_nv_seed_write_uninit( unsigned char *buf, size_t buf_len ) { ((void) buf); ((void) buf_len); - return( -1 ); + return -1 ; } #define MBEDTLS_PLATFORM_STD_NV_SEED_WRITE platform_nv_seed_write_uninit @@ -358,7 +358,7 @@ int mbedtls_platform_set_nv_seed( { mbedtls_nv_seed_read = nv_seed_read_func; mbedtls_nv_seed_write = nv_seed_write_func; - return( 0 ); + return 0 ; } #endif /* MBEDTLS_PLATFORM_NV_SEED_ALT */ #endif /* MBEDTLS_ENTROPY_NV_SEED */ @@ -371,7 +371,7 @@ int mbedtls_platform_setup( mbedtls_platform_context *ctx ) { (void)ctx; - return( 0 ); + return 0 ; } /* diff --git a/library/platform_util.c b/library/platform_util.c index 3d5cb5baa4..3c3ebcaead 100644 --- a/library/platform_util.c +++ b/library/platform_util.c @@ -104,15 +104,15 @@ struct tm *mbedtls_platform_gmtime_r( const mbedtls_time_t *tt, struct tm *tm_buf ) { #if defined(_WIN32) && !defined(EFIX64) && !defined(EFI32) - return( ( gmtime_s( tm_buf, tt ) == 0 ) ? tm_buf : NULL ); + return ( gmtime_s( tm_buf, tt ) == 0 ) ? tm_buf : NULL ; #elif !defined(PLATFORM_UTIL_USE_GMTIME) - return( gmtime_r( tt, tm_buf ) ); + return gmtime_r( tt, tm_buf ) ; #else struct tm *lt; #if defined(MBEDTLS_THREADING_C) if( mbedtls_mutex_lock( &mbedtls_threading_gmtime_mutex ) != 0 ) - return( NULL ); + return NULL ; #endif /* MBEDTLS_THREADING_C */ lt = gmtime( tt ); @@ -124,10 +124,10 @@ struct tm *mbedtls_platform_gmtime_r( const mbedtls_time_t *tt, #if defined(MBEDTLS_THREADING_C) if( mbedtls_mutex_unlock( &mbedtls_threading_gmtime_mutex ) != 0 ) - return( NULL ); + return NULL ; #endif /* MBEDTLS_THREADING_C */ - return( ( lt == NULL ) ? NULL : tm_buf ); + return ( lt == NULL ) ? NULL : tm_buf ; #endif /* _WIN32 && !EFIX64 && !EFI32 */ } #endif /* MBEDTLS_HAVE_TIME_DATE && MBEDTLS_PLATFORM_GMTIME_R_ALT */ diff --git a/library/poly1305.c b/library/poly1305.c index 492d1457d4..a81220bffb 100644 --- a/library/poly1305.c +++ b/library/poly1305.c @@ -82,7 +82,7 @@ static uint64_t mul64( uint32_t a, uint32_t b ) #else static inline uint64_t mul64( uint32_t a, uint32_t b ) { - return( (uint64_t) a * b ); + return (uint64_t) a * b ; } #endif @@ -318,7 +318,7 @@ int mbedtls_poly1305_starts( mbedtls_poly1305_context *ctx, mbedtls_platform_zeroize( ctx->queue, sizeof( ctx->queue ) ); ctx->queue_len = 0U; - return( 0 ); + return 0 ; } int mbedtls_poly1305_update( mbedtls_poly1305_context *ctx, @@ -382,7 +382,7 @@ int mbedtls_poly1305_update( mbedtls_poly1305_context *ctx, memcpy( ctx->queue, &input[offset], remaining ); } - return( 0 ); + return 0 ; } int mbedtls_poly1305_finish( mbedtls_poly1305_context *ctx, @@ -409,7 +409,7 @@ int mbedtls_poly1305_finish( mbedtls_poly1305_context *ctx, poly1305_compute_mac( ctx, mac ); - return( 0 ); + return 0 ; } int mbedtls_poly1305_mac( const unsigned char key[32], @@ -437,7 +437,7 @@ int mbedtls_poly1305_mac( const unsigned char key[32], cleanup: mbedtls_poly1305_free( &ctx ); - return( ret ); + return ret ; } #endif /* MBEDTLS_POLY1305_ALT */ @@ -518,7 +518,7 @@ static const unsigned char test_mac[2][16] = if( verbose != 0 ) \ mbedtls_printf args; \ \ - return( -1 ); \ + return -1 ; \ } \ } \ while( 0 ) @@ -549,7 +549,7 @@ int mbedtls_poly1305_self_test( int verbose ) if( verbose != 0 ) mbedtls_printf( "\n" ); - return( 0 ); + return 0 ; } #endif /* MBEDTLS_SELF_TEST */ diff --git a/library/psa_crypto.c b/library/psa_crypto.c index 3574b9842a..9253edee82 100644 --- a/library/psa_crypto.c +++ b/library/psa_crypto.c @@ -93,7 +93,7 @@ static int key_type_is_raw_bytes( psa_key_type_t type ) { - return( PSA_KEY_TYPE_IS_UNSTRUCTURED( type ) ); + return PSA_KEY_TYPE_IS_UNSTRUCTURED( type ) ; } /* Values for psa_global_data_t::rng_state */ @@ -117,7 +117,7 @@ mbedtls_psa_drbg_context_t *const mbedtls_psa_random_state = #define GUARD_MODULE_INITIALIZED \ if( global_data.initialized == 0 ) \ - return( PSA_ERROR_BAD_STATE ); + return PSA_ERROR_BAD_STATE ; psa_status_t mbedtls_to_psa_error( int ret ) { @@ -128,190 +128,190 @@ psa_status_t mbedtls_to_psa_error( int ret ) switch( low_level_ret != 0 ? low_level_ret : ret ) { case 0: - return( PSA_SUCCESS ); + return PSA_SUCCESS ; case MBEDTLS_ERR_AES_INVALID_KEY_LENGTH: case MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH: - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; case MBEDTLS_ERR_ASN1_OUT_OF_DATA: case MBEDTLS_ERR_ASN1_UNEXPECTED_TAG: case MBEDTLS_ERR_ASN1_INVALID_LENGTH: case MBEDTLS_ERR_ASN1_LENGTH_MISMATCH: case MBEDTLS_ERR_ASN1_INVALID_DATA: - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; case MBEDTLS_ERR_ASN1_ALLOC_FAILED: - return( PSA_ERROR_INSUFFICIENT_MEMORY ); + return PSA_ERROR_INSUFFICIENT_MEMORY ; case MBEDTLS_ERR_ASN1_BUF_TOO_SMALL: - return( PSA_ERROR_BUFFER_TOO_SMALL ); + return PSA_ERROR_BUFFER_TOO_SMALL ; #if defined(MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA) case MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA: #endif case MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH: - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; case MBEDTLS_ERR_CCM_BAD_INPUT: - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; case MBEDTLS_ERR_CCM_AUTH_FAILED: - return( PSA_ERROR_INVALID_SIGNATURE ); + return PSA_ERROR_INVALID_SIGNATURE ; case MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA: - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; case MBEDTLS_ERR_CHACHAPOLY_BAD_STATE: - return( PSA_ERROR_BAD_STATE ); + return PSA_ERROR_BAD_STATE ; case MBEDTLS_ERR_CHACHAPOLY_AUTH_FAILED: - return( PSA_ERROR_INVALID_SIGNATURE ); + return PSA_ERROR_INVALID_SIGNATURE ; case MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE: - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; case MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA: - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; case MBEDTLS_ERR_CIPHER_ALLOC_FAILED: - return( PSA_ERROR_INSUFFICIENT_MEMORY ); + return PSA_ERROR_INSUFFICIENT_MEMORY ; case MBEDTLS_ERR_CIPHER_INVALID_PADDING: - return( PSA_ERROR_INVALID_PADDING ); + return PSA_ERROR_INVALID_PADDING ; case MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED: - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; case MBEDTLS_ERR_CIPHER_AUTH_FAILED: - return( PSA_ERROR_INVALID_SIGNATURE ); + return PSA_ERROR_INVALID_SIGNATURE ; case MBEDTLS_ERR_CIPHER_INVALID_CONTEXT: - return( PSA_ERROR_CORRUPTION_DETECTED ); + return PSA_ERROR_CORRUPTION_DETECTED ; #if !( defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG) || \ defined(MBEDTLS_PSA_HMAC_DRBG_MD_TYPE) ) /* Only check CTR_DRBG error codes if underlying mbedtls_xxx * functions are passed a CTR_DRBG instance. */ case MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED: - return( PSA_ERROR_INSUFFICIENT_ENTROPY ); + return PSA_ERROR_INSUFFICIENT_ENTROPY ; case MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG: case MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG: - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; case MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR: - return( PSA_ERROR_INSUFFICIENT_ENTROPY ); + return PSA_ERROR_INSUFFICIENT_ENTROPY ; #endif case MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH: - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; case MBEDTLS_ERR_ENTROPY_NO_SOURCES_DEFINED: case MBEDTLS_ERR_ENTROPY_NO_STRONG_SOURCE: case MBEDTLS_ERR_ENTROPY_SOURCE_FAILED: - return( PSA_ERROR_INSUFFICIENT_ENTROPY ); + return PSA_ERROR_INSUFFICIENT_ENTROPY ; case MBEDTLS_ERR_GCM_AUTH_FAILED: - return( PSA_ERROR_INVALID_SIGNATURE ); + return PSA_ERROR_INVALID_SIGNATURE ; case MBEDTLS_ERR_GCM_BAD_INPUT: - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; #if !defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG) && \ defined(MBEDTLS_PSA_HMAC_DRBG_MD_TYPE) /* Only check HMAC_DRBG error codes if underlying mbedtls_xxx * functions are passed a HMAC_DRBG instance. */ case MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED: - return( PSA_ERROR_INSUFFICIENT_ENTROPY ); + return PSA_ERROR_INSUFFICIENT_ENTROPY ; case MBEDTLS_ERR_HMAC_DRBG_REQUEST_TOO_BIG: case MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG: - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; case MBEDTLS_ERR_HMAC_DRBG_FILE_IO_ERROR: - return( PSA_ERROR_INSUFFICIENT_ENTROPY ); + return PSA_ERROR_INSUFFICIENT_ENTROPY ; #endif case MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE: - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; case MBEDTLS_ERR_MD_BAD_INPUT_DATA: - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; case MBEDTLS_ERR_MD_ALLOC_FAILED: - return( PSA_ERROR_INSUFFICIENT_MEMORY ); + return PSA_ERROR_INSUFFICIENT_MEMORY ; case MBEDTLS_ERR_MD_FILE_IO_ERROR: - return( PSA_ERROR_STORAGE_FAILURE ); + return PSA_ERROR_STORAGE_FAILURE ; case MBEDTLS_ERR_MPI_FILE_IO_ERROR: - return( PSA_ERROR_STORAGE_FAILURE ); + return PSA_ERROR_STORAGE_FAILURE ; case MBEDTLS_ERR_MPI_BAD_INPUT_DATA: - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; case MBEDTLS_ERR_MPI_INVALID_CHARACTER: - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; case MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL: - return( PSA_ERROR_BUFFER_TOO_SMALL ); + return PSA_ERROR_BUFFER_TOO_SMALL ; case MBEDTLS_ERR_MPI_NEGATIVE_VALUE: - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; case MBEDTLS_ERR_MPI_DIVISION_BY_ZERO: - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; case MBEDTLS_ERR_MPI_NOT_ACCEPTABLE: - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; case MBEDTLS_ERR_MPI_ALLOC_FAILED: - return( PSA_ERROR_INSUFFICIENT_MEMORY ); + return PSA_ERROR_INSUFFICIENT_MEMORY ; case MBEDTLS_ERR_PK_ALLOC_FAILED: - return( PSA_ERROR_INSUFFICIENT_MEMORY ); + return PSA_ERROR_INSUFFICIENT_MEMORY ; case MBEDTLS_ERR_PK_TYPE_MISMATCH: case MBEDTLS_ERR_PK_BAD_INPUT_DATA: - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; case MBEDTLS_ERR_PK_FILE_IO_ERROR: - return( PSA_ERROR_STORAGE_FAILURE ); + return PSA_ERROR_STORAGE_FAILURE ; case MBEDTLS_ERR_PK_KEY_INVALID_VERSION: case MBEDTLS_ERR_PK_KEY_INVALID_FORMAT: - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; case MBEDTLS_ERR_PK_UNKNOWN_PK_ALG: - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; case MBEDTLS_ERR_PK_PASSWORD_REQUIRED: case MBEDTLS_ERR_PK_PASSWORD_MISMATCH: - return( PSA_ERROR_NOT_PERMITTED ); + return PSA_ERROR_NOT_PERMITTED ; case MBEDTLS_ERR_PK_INVALID_PUBKEY: - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; case MBEDTLS_ERR_PK_INVALID_ALG: case MBEDTLS_ERR_PK_UNKNOWN_NAMED_CURVE: case MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE: - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; case MBEDTLS_ERR_PK_SIG_LEN_MISMATCH: - return( PSA_ERROR_INVALID_SIGNATURE ); + return PSA_ERROR_INVALID_SIGNATURE ; case MBEDTLS_ERR_PK_BUFFER_TOO_SMALL: - return( PSA_ERROR_BUFFER_TOO_SMALL ); + return PSA_ERROR_BUFFER_TOO_SMALL ; case MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED: - return( PSA_ERROR_HARDWARE_FAILURE ); + return PSA_ERROR_HARDWARE_FAILURE ; case MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED: - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; case MBEDTLS_ERR_RSA_BAD_INPUT_DATA: - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; case MBEDTLS_ERR_RSA_INVALID_PADDING: - return( PSA_ERROR_INVALID_PADDING ); + return PSA_ERROR_INVALID_PADDING ; case MBEDTLS_ERR_RSA_KEY_GEN_FAILED: - return( PSA_ERROR_HARDWARE_FAILURE ); + return PSA_ERROR_HARDWARE_FAILURE ; case MBEDTLS_ERR_RSA_KEY_CHECK_FAILED: - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; case MBEDTLS_ERR_RSA_PUBLIC_FAILED: case MBEDTLS_ERR_RSA_PRIVATE_FAILED: - return( PSA_ERROR_CORRUPTION_DETECTED ); + return PSA_ERROR_CORRUPTION_DETECTED ; case MBEDTLS_ERR_RSA_VERIFY_FAILED: - return( PSA_ERROR_INVALID_SIGNATURE ); + return PSA_ERROR_INVALID_SIGNATURE ; case MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE: - return( PSA_ERROR_BUFFER_TOO_SMALL ); + return PSA_ERROR_BUFFER_TOO_SMALL ; case MBEDTLS_ERR_RSA_RNG_FAILED: - return( PSA_ERROR_INSUFFICIENT_ENTROPY ); + return PSA_ERROR_INSUFFICIENT_ENTROPY ; case MBEDTLS_ERR_ECP_BAD_INPUT_DATA: case MBEDTLS_ERR_ECP_INVALID_KEY: - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; case MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL: - return( PSA_ERROR_BUFFER_TOO_SMALL ); + return PSA_ERROR_BUFFER_TOO_SMALL ; case MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE: - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; case MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH: case MBEDTLS_ERR_ECP_VERIFY_FAILED: - return( PSA_ERROR_INVALID_SIGNATURE ); + return PSA_ERROR_INVALID_SIGNATURE ; case MBEDTLS_ERR_ECP_ALLOC_FAILED: - return( PSA_ERROR_INSUFFICIENT_MEMORY ); + return PSA_ERROR_INSUFFICIENT_MEMORY ; case MBEDTLS_ERR_ECP_RANDOM_FAILED: - return( PSA_ERROR_INSUFFICIENT_ENTROPY ); + return PSA_ERROR_INSUFFICIENT_ENTROPY ; case MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED: - return( PSA_ERROR_CORRUPTION_DETECTED ); + return PSA_ERROR_CORRUPTION_DETECTED ; default: - return( PSA_ERROR_GENERIC_ERROR ); + return PSA_ERROR_GENERIC_ERROR ; } } @@ -325,7 +325,7 @@ psa_status_t mbedtls_to_psa_error( int ret ) #if defined(MBEDTLS_PSA_CRYPTO_SE_C) static inline int psa_key_slot_is_external( const psa_key_slot_t *slot ) { - return( psa_key_lifetime_is_external( slot->attr.lifetime ) ); + return psa_key_lifetime_is_external( slot->attr.lifetime ) ; } #endif /* MBEDTLS_PSA_CRYPTO_SE_C */ @@ -349,26 +349,26 @@ mbedtls_ecp_group_id mbedtls_ecc_group_of_psa( psa_ecc_family_t curve, { #if defined(PSA_WANT_ECC_SECP_R1_192) case 192: - return( MBEDTLS_ECP_DP_SECP192R1 ); + return MBEDTLS_ECP_DP_SECP192R1 ; #endif #if defined(PSA_WANT_ECC_SECP_R1_224) case 224: - return( MBEDTLS_ECP_DP_SECP224R1 ); + return MBEDTLS_ECP_DP_SECP224R1 ; #endif #if defined(PSA_WANT_ECC_SECP_R1_256) case 256: - return( MBEDTLS_ECP_DP_SECP256R1 ); + return MBEDTLS_ECP_DP_SECP256R1 ; #endif #if defined(PSA_WANT_ECC_SECP_R1_384) case 384: - return( MBEDTLS_ECP_DP_SECP384R1 ); + return MBEDTLS_ECP_DP_SECP384R1 ; #endif #if defined(PSA_WANT_ECC_SECP_R1_521) case 521: - return( MBEDTLS_ECP_DP_SECP521R1 ); + return MBEDTLS_ECP_DP_SECP521R1 ; case 528: if( bits_is_sloppy ) - return( MBEDTLS_ECP_DP_SECP521R1 ); + return MBEDTLS_ECP_DP_SECP521R1 ; break; #endif } @@ -379,15 +379,15 @@ mbedtls_ecp_group_id mbedtls_ecc_group_of_psa( psa_ecc_family_t curve, { #if defined(PSA_WANT_ECC_BRAINPOOL_P_R1_256) case 256: - return( MBEDTLS_ECP_DP_BP256R1 ); + return MBEDTLS_ECP_DP_BP256R1 ; #endif #if defined(PSA_WANT_ECC_BRAINPOOL_P_R1_384) case 384: - return( MBEDTLS_ECP_DP_BP384R1 ); + return MBEDTLS_ECP_DP_BP384R1 ; #endif #if defined(PSA_WANT_ECC_BRAINPOOL_P_R1_512) case 512: - return( MBEDTLS_ECP_DP_BP512R1 ); + return MBEDTLS_ECP_DP_BP512R1 ; #endif } break; @@ -397,15 +397,15 @@ mbedtls_ecp_group_id mbedtls_ecc_group_of_psa( psa_ecc_family_t curve, { #if defined(PSA_WANT_ECC_MONTGOMERY_255) case 255: - return( MBEDTLS_ECP_DP_CURVE25519 ); + return MBEDTLS_ECP_DP_CURVE25519 ; case 256: if( bits_is_sloppy ) - return( MBEDTLS_ECP_DP_CURVE25519 ); + return MBEDTLS_ECP_DP_CURVE25519 ; break; #endif #if defined(PSA_WANT_ECC_MONTGOMERY_448) case 448: - return( MBEDTLS_ECP_DP_CURVE448 ); + return MBEDTLS_ECP_DP_CURVE448 ; #endif } break; @@ -415,22 +415,22 @@ mbedtls_ecp_group_id mbedtls_ecc_group_of_psa( psa_ecc_family_t curve, { #if defined(PSA_WANT_ECC_SECP_K1_192) case 192: - return( MBEDTLS_ECP_DP_SECP192K1 ); + return MBEDTLS_ECP_DP_SECP192K1 ; #endif #if defined(PSA_WANT_ECC_SECP_K1_224) case 224: - return( MBEDTLS_ECP_DP_SECP224K1 ); + return MBEDTLS_ECP_DP_SECP224K1 ; #endif #if defined(PSA_WANT_ECC_SECP_K1_256) case 256: - return( MBEDTLS_ECP_DP_SECP256K1 ); + return MBEDTLS_ECP_DP_SECP256K1 ; #endif } break; } (void) bits_is_sloppy; - return( MBEDTLS_ECP_DP_NONE ); + return MBEDTLS_ECP_DP_NONE ; } #endif /* defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR) || * defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_PUBLIC_KEY) || @@ -450,34 +450,34 @@ static psa_status_t validate_unstructured_key_bit_size( psa_key_type_t type, #if defined(PSA_WANT_KEY_TYPE_AES) case PSA_KEY_TYPE_AES: if( bits != 128 && bits != 192 && bits != 256 ) - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; break; #endif #if defined(PSA_WANT_KEY_TYPE_CAMELLIA) case PSA_KEY_TYPE_CAMELLIA: if( bits != 128 && bits != 192 && bits != 256 ) - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; break; #endif #if defined(PSA_WANT_KEY_TYPE_DES) case PSA_KEY_TYPE_DES: if( bits != 64 && bits != 128 && bits != 192 ) - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; break; #endif #if defined(PSA_WANT_KEY_TYPE_CHACHA20) case PSA_KEY_TYPE_CHACHA20: if( bits != 256 ) - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; break; #endif default: - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; } if( bits % 8 != 0 ) - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } /** Check whether a given key type is valid for use with a given MAC algorithm @@ -501,7 +501,7 @@ MBEDTLS_STATIC_TESTABLE psa_status_t psa_mac_key_can_do( if( PSA_ALG_IS_HMAC( algorithm ) ) { if( key_type == PSA_KEY_TYPE_HMAC ) - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } if( PSA_ALG_IS_BLOCK_CIPHER_MAC( algorithm ) ) @@ -514,25 +514,25 @@ MBEDTLS_STATIC_TESTABLE psa_status_t psa_mac_key_can_do( /* PSA_BLOCK_CIPHER_BLOCK_LENGTH returns 1 for stream ciphers and * the block length (larger than 1) for block ciphers. */ if( PSA_BLOCK_CIPHER_BLOCK_LENGTH( key_type ) > 1 ) - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } } - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; } psa_status_t psa_allocate_buffer_to_slot( psa_key_slot_t *slot, size_t buffer_length ) { if( slot->key.data != NULL ) - return( PSA_ERROR_ALREADY_EXISTS ); + return PSA_ERROR_ALREADY_EXISTS ; slot->key.data = mbedtls_calloc( 1, buffer_length ); if( slot->key.data == NULL ) - return( PSA_ERROR_INSUFFICIENT_MEMORY ); + return PSA_ERROR_INSUFFICIENT_MEMORY ; slot->key.bytes = buffer_length; - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } psa_status_t psa_copy_key_material_into_slot( psa_key_slot_t *slot, @@ -542,10 +542,10 @@ psa_status_t psa_copy_key_material_into_slot( psa_key_slot_t *slot, psa_status_t status = psa_allocate_buffer_to_slot( slot, data_length ); if( status != PSA_SUCCESS ) - return( status ); + return status ; memcpy( slot->key.data, data, data_length ); - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } psa_status_t psa_import_key_into_slot( @@ -559,7 +559,7 @@ psa_status_t psa_import_key_into_slot( /* zero-length keys are never supported. */ if( data_length == 0 ) - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; if( key_type_is_raw_bytes( type ) ) { @@ -567,23 +567,23 @@ psa_status_t psa_import_key_into_slot( /* Ensure that the bytes-to-bits conversion hasn't overflown. */ if( data_length > SIZE_MAX / 8 ) - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; /* Enforce a size limit, and in particular ensure that the bit * size fits in its representation type. */ if( ( *bits ) > PSA_MAX_KEY_BITS ) - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; status = validate_unstructured_key_bit_size( type, *bits ); if( status != PSA_SUCCESS ) - return( status ); + return status ; /* Copy the key material. */ memcpy( key_buffer, data, data_length ); *key_buffer_length = data_length; (void)key_buffer_size; - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } else if( PSA_KEY_TYPE_IS_ASYMMETRIC( type ) ) { @@ -613,7 +613,7 @@ psa_status_t psa_import_key_into_slot( * defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_PUBLIC_KEY) */ } - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; } /** Calculate the intersection of two algorithm usage policies. @@ -627,7 +627,7 @@ static psa_algorithm_t psa_key_policy_algorithm_intersection( { /* Common case: both sides actually specify the same policy. */ if( alg1 == alg2 ) - return( alg1 ); + return alg1 ; /* If the policies are from the same hash-and-sign family, check * if one is a wildcard. If so the other has the specific algorithm. */ if( PSA_ALG_IS_HASH_AND_SIGN( alg1 ) && @@ -635,9 +635,9 @@ static psa_algorithm_t psa_key_policy_algorithm_intersection( ( alg1 & ~PSA_ALG_HASH_MASK ) == ( alg2 & ~PSA_ALG_HASH_MASK ) ) { if( PSA_ALG_SIGN_GET_HASH( alg1 ) == PSA_ALG_ANY_HASH ) - return( alg2 ); + return alg2 ; if( PSA_ALG_SIGN_GET_HASH( alg2 ) == PSA_ALG_ANY_HASH ) - return( alg1 ); + return alg1 ; } /* If the policies are from the same AEAD family, check whether * one of them is a minimum-tag-length wildcard. Calculate the most @@ -661,12 +661,12 @@ static psa_algorithm_t psa_key_policy_algorithm_intersection( if( ( ( alg1 & PSA_ALG_AEAD_AT_LEAST_THIS_LENGTH_FLAG ) != 0 ) && ( alg1_len <= alg2_len ) ) { - return( alg2 ); + return alg2 ; } if( ( ( alg2 & PSA_ALG_AEAD_AT_LEAST_THIS_LENGTH_FLAG ) != 0 ) && ( alg2_len <= alg1_len ) ) { - return( alg1 ); + return alg1 ; } } /* If the policies are from the same MAC family, check whether one @@ -679,7 +679,7 @@ static psa_algorithm_t psa_key_policy_algorithm_intersection( /* Validate the combination of key type and algorithm. Since the base * algorithm of alg1 and alg2 are the same, we only need this once. */ if( PSA_SUCCESS != psa_mac_key_can_do( alg1, key_type ) ) - return( 0 ); + return 0 ; /* Get the (exact or at-least) output lengths for both sides of the * requested intersection. None of the currently supported algorithms @@ -697,7 +697,7 @@ static psa_algorithm_t psa_key_policy_algorithm_intersection( if( ( ( alg1 & PSA_ALG_MAC_AT_LEAST_THIS_LENGTH_FLAG ) != 0 ) && ( ( alg2 & PSA_ALG_MAC_AT_LEAST_THIS_LENGTH_FLAG ) != 0 ) ) { - return( PSA_ALG_AT_LEAST_THIS_LENGTH_MAC( alg1, restricted_len ) ); + return PSA_ALG_AT_LEAST_THIS_LENGTH_MAC( alg1, restricted_len ) ; } /* If only one is an at-least-this-length policy, the intersection would @@ -705,11 +705,11 @@ static psa_algorithm_t psa_key_policy_algorithm_intersection( * equal to or larger than the shortest allowed length. */ if( ( alg1 & PSA_ALG_MAC_AT_LEAST_THIS_LENGTH_FLAG ) != 0 ) { - return( ( alg1_len <= alg2_len ) ? alg2 : 0 ); + return ( alg1_len <= alg2_len ) ? alg2 : 0 ; } if( ( alg2 & PSA_ALG_MAC_AT_LEAST_THIS_LENGTH_FLAG ) != 0 ) { - return( ( alg2_len <= alg1_len ) ? alg1 : 0 ); + return ( alg2_len <= alg1_len ) ? alg1 : 0 ; } /* If none of them are wildcards, check whether they define the same tag @@ -717,10 +717,10 @@ static psa_algorithm_t psa_key_policy_algorithm_intersection( * the other specific-length. Ensure to always return the * specific-length version for the intersection. */ if( alg1_len == alg2_len ) - return( PSA_ALG_TRUNCATED_MAC( alg1, alg1_len ) ); + return PSA_ALG_TRUNCATED_MAC( alg1, alg1_len ) ; } /* If the policies are incompatible, allow nothing. */ - return( 0 ); + return 0 ; } static int psa_key_algorithm_permits( psa_key_type_t key_type, @@ -729,7 +729,7 @@ static int psa_key_algorithm_permits( psa_key_type_t key_type, { /* Common case: the policy only allows requested_alg. */ if( requested_alg == policy_alg ) - return( 1 ); + return 1 ; /* If policy_alg is a hash-and-sign with a wildcard for the hash, * and requested_alg is the same hash-and-sign family with any hash, * then requested_alg is compliant with policy_alg. */ @@ -761,7 +761,7 @@ static int psa_key_algorithm_permits( psa_key_type_t key_type, /* Validate the combination of key type and algorithm. Since the policy * and requested algorithms are the same, we only need this once. */ if( PSA_SUCCESS != psa_mac_key_can_do( policy_alg, key_type ) ) - return( 0 ); + return 0 ; /* Get both the requested output length for the algorithm which is to be * verified, and the default output length for the base algorithm. @@ -777,14 +777,14 @@ static int psa_key_algorithm_permits( psa_key_type_t key_type, /* If the policy is default-length, only allow an algorithm with * a declared exact-length matching the default. */ if( PSA_MAC_TRUNCATED_LENGTH( policy_alg ) == 0 ) - return( requested_output_length == default_output_length ); + return requested_output_length == default_output_length ; /* If the requested algorithm is default-length, allow it if the policy * length exactly matches the default length. */ if( PSA_MAC_TRUNCATED_LENGTH( requested_alg ) == 0 && PSA_MAC_TRUNCATED_LENGTH( policy_alg ) == default_output_length ) { - return( 1 ); + return 1 ; } /* If policy_alg is an at-least-this-length wildcard MAC algorithm, @@ -806,7 +806,7 @@ static int psa_key_algorithm_permits( psa_key_type_t key_type, policy_alg ); } /* If it isn't explicitly permitted, it's forbidden. */ - return( 0 ); + return 0 ; } /** Test whether a policy permits an algorithm. @@ -830,17 +830,17 @@ static psa_status_t psa_key_policy_permits( const psa_key_policy_t *policy, { /* '0' is not a valid algorithm */ if( alg == 0 ) - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; /* A requested algorithm cannot be a wildcard. */ if( PSA_ALG_IS_WILDCARD( alg ) ) - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; if( psa_key_algorithm_permits( key_type, policy->alg, alg ) || psa_key_algorithm_permits( key_type, policy->alg2, alg ) ) - return( PSA_SUCCESS ); + return PSA_SUCCESS ; else - return( PSA_ERROR_NOT_PERMITTED ); + return PSA_ERROR_NOT_PERMITTED ; } /** Restrict a key policy based on a constraint. @@ -873,13 +873,13 @@ static psa_status_t psa_restrict_key_policy( psa_key_policy_algorithm_intersection( key_type, policy->alg2, constraint->alg2 ); if( intersection_alg == 0 && policy->alg != 0 && constraint->alg != 0 ) - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; if( intersection_alg2 == 0 && policy->alg2 != 0 && constraint->alg2 != 0 ) - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; policy->usage &= constraint->usage; policy->alg = intersection_alg; policy->alg2 = intersection_alg2; - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } /** Get the description of a key given its identifier and policy constraints @@ -906,7 +906,7 @@ static psa_status_t psa_get_and_lock_key_slot_with_policy( status = psa_get_and_lock_key_slot( key, p_slot ); if( status != PSA_SUCCESS ) - return( status ); + return status ; slot = *p_slot; /* Enforce that usage policy for the key slot contains all the flags @@ -932,13 +932,13 @@ static psa_status_t psa_get_and_lock_key_slot_with_policy( goto error; } - return( PSA_SUCCESS ); + return PSA_SUCCESS ; error: *p_slot = NULL; psa_unlock_key_slot( slot ); - return( status ); + return status ; } /** Get a key slot containing a transparent key and lock it. @@ -963,16 +963,16 @@ static psa_status_t psa_get_and_lock_transparent_key_slot_with_policy( psa_status_t status = psa_get_and_lock_key_slot_with_policy( key, p_slot, usage, alg ); if( status != PSA_SUCCESS ) - return( status ); + return status ; if( psa_key_slot_is_external( *p_slot ) ) { psa_unlock_key_slot( *p_slot ); *p_slot = NULL; - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; } - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } #else /* MBEDTLS_PSA_CRYPTO_SE_C */ /* With no secure element support, all keys are transparent. */ @@ -991,7 +991,7 @@ psa_status_t psa_remove_key_data_from_memory( psa_key_slot_t *slot ) slot->key.data = NULL; slot->key.bytes = 0; - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } /** Completely wipe a slot in memory, including its policy. @@ -1023,7 +1023,7 @@ psa_status_t psa_wipe_key_slot( psa_key_slot_t *slot ) * been wiped. Clear remaining metadata. We can call memset and not * zeroize because the metadata is not particularly sensitive. */ memset( slot, 0, sizeof( *slot ) ); - return( status ); + return status ; } psa_status_t psa_destroy_key( mbedtls_svc_key_id_t key ) @@ -1036,7 +1036,7 @@ psa_status_t psa_destroy_key( mbedtls_svc_key_id_t key ) #endif /* MBEDTLS_PSA_CRYPTO_SE_C */ if( mbedtls_svc_key_id_is_null( key ) ) - return( PSA_SUCCESS ); + return PSA_SUCCESS ; /* * Get the description of the key in a key slot. In case of a persistent @@ -1047,7 +1047,7 @@ psa_status_t psa_destroy_key( mbedtls_svc_key_id_t key ) */ status = psa_get_and_lock_key_slot( key, &slot ); if( status != PSA_SUCCESS ) - return( status ); + return status ; /* * If the key slot containing the key description is under access by the @@ -1059,7 +1059,7 @@ psa_status_t psa_destroy_key( mbedtls_svc_key_id_t key ) if( slot->lock_count > 1 ) { psa_unlock_key_slot( slot ); - return( PSA_ERROR_GENERIC_ERROR ); + return PSA_ERROR_GENERIC_ERROR ; } if( PSA_KEY_LIFETIME_IS_READ_ONLY( slot->attr.lifetime ) ) @@ -1139,7 +1139,7 @@ exit: /* Prioritize CORRUPTION_DETECTED from wiping over a storage error */ if( status != PSA_SUCCESS ) overall_status = status; - return( overall_status ); + return overall_status ; } #if defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_KEY_PAIR) || \ @@ -1181,7 +1181,7 @@ exit: mbedtls_mpi_free( &mpi ); if( ret != 0 ) mbedtls_free( buffer ); - return( mbedtls_to_psa_error( ret ) ); + return mbedtls_to_psa_error( ret ) ; } #endif /* defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_KEY_PAIR) || * defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_PUBLIC_KEY) */ @@ -1199,7 +1199,7 @@ psa_status_t psa_get_key_attributes( mbedtls_svc_key_id_t key, status = psa_get_and_lock_key_slot_with_policy( key, &slot, 0, 0 ); if( status != PSA_SUCCESS ) - return( status ); + return status ; attributes->core = slot->attr; attributes->core.flags &= ( MBEDTLS_PSA_KA_MASK_EXTERNAL_ONLY | @@ -1254,7 +1254,7 @@ psa_status_t psa_get_key_attributes( mbedtls_svc_key_id_t key, unlock_status = psa_unlock_key_slot( slot ); - return( ( status == PSA_SUCCESS ) ? unlock_status : status ); + return ( status == PSA_SUCCESS ) ? unlock_status : status ; } #if defined(MBEDTLS_PSA_CRYPTO_SE_C) @@ -1265,10 +1265,10 @@ psa_status_t psa_get_key_slot_number( if( attributes->core.flags & MBEDTLS_PSA_KA_FLAG_HAS_SLOT_NUMBER ) { *slot_number = attributes->slot_number; - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } else - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; } #endif /* MBEDTLS_PSA_CRYPTO_SE_C */ @@ -1279,12 +1279,12 @@ static psa_status_t psa_export_key_buffer_internal( const uint8_t *key_buffer, size_t *data_length ) { if( key_buffer_size > data_size ) - return( PSA_ERROR_BUFFER_TOO_SMALL ); + return PSA_ERROR_BUFFER_TOO_SMALL ; memcpy( data, key_buffer, key_buffer_size ); memset( data + key_buffer_size, 0, data_size - key_buffer_size ); *data_length = key_buffer_size; - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } psa_status_t psa_export_key_internal( @@ -1307,7 +1307,7 @@ psa_status_t psa_export_key_internal( /* This shouldn't happen in the reference implementation, but it is valid for a special-purpose implementation to omit support for exporting certain key types. */ - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; } } @@ -1324,7 +1324,7 @@ psa_status_t psa_export_key( mbedtls_svc_key_id_t key, * valid key representation. This way we know that data must be a valid * pointer and we can do things like memset(data, ..., data_size). */ if( data_size == 0 ) - return( PSA_ERROR_BUFFER_TOO_SMALL ); + return PSA_ERROR_BUFFER_TOO_SMALL ; /* Set the key to empty now, so that even when there are errors, we always * set data_length to a value between 0 and data_size. On error, setting @@ -1339,7 +1339,7 @@ psa_status_t psa_export_key( mbedtls_svc_key_id_t key, status = psa_get_and_lock_key_slot_with_policy( key, &slot, PSA_KEY_USAGE_EXPORT, 0 ); if( status != PSA_SUCCESS ) - return( status ); + return status ; psa_key_attributes_t attributes = { .core = slot->attr @@ -1350,7 +1350,7 @@ psa_status_t psa_export_key( mbedtls_svc_key_id_t key, unlock_status = psa_unlock_key_slot( slot ); - return( ( status == PSA_SUCCESS ) ? unlock_status : status ); + return ( status == PSA_SUCCESS ) ? unlock_status : status ; } psa_status_t psa_export_public_key_internal( @@ -1385,7 +1385,7 @@ psa_status_t psa_export_public_key_internal( data_length ) ); #else /* We don't know how to convert a private RSA key to public. */ - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; #endif /* defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_KEY_PAIR) || * defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_PUBLIC_KEY) */ } @@ -1401,7 +1401,7 @@ psa_status_t psa_export_public_key_internal( data_length ) ); #else /* We don't know how to convert a private ECC key to public */ - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; #endif /* defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR) || * defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_PUBLIC_KEY) */ } @@ -1411,7 +1411,7 @@ psa_status_t psa_export_public_key_internal( /* This shouldn't happen in the reference implementation, but it is valid for a special-purpose implementation to omit support for exporting certain key types. */ - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; } } @@ -1428,7 +1428,7 @@ psa_status_t psa_export_public_key( mbedtls_svc_key_id_t key, * valid key representation. This way we know that data must be a valid * pointer and we can do things like memset(data, ..., data_size). */ if( data_size == 0 ) - return( PSA_ERROR_BUFFER_TOO_SMALL ); + return PSA_ERROR_BUFFER_TOO_SMALL ; /* Set the key to empty now, so that even when there are errors, we always * set data_length to a value between 0 and data_size. On error, setting @@ -1439,7 +1439,7 @@ psa_status_t psa_export_public_key( mbedtls_svc_key_id_t key, /* Exporting a public key doesn't require a usage flag. */ status = psa_get_and_lock_key_slot_with_policy( key, &slot, 0, 0 ); if( status != PSA_SUCCESS ) - return( status ); + return status ; if( ! PSA_KEY_TYPE_IS_ASYMMETRIC( slot->attr.type ) ) { @@ -1457,7 +1457,7 @@ psa_status_t psa_export_public_key( mbedtls_svc_key_id_t key, exit: unlock_status = psa_unlock_key_slot( slot ); - return( ( status == PSA_SUCCESS ) ? unlock_status : status ); + return ( status == PSA_SUCCESS ) ? unlock_status : status ; } #if defined(static_assert) @@ -1487,9 +1487,9 @@ static psa_status_t psa_validate_key_policy( const psa_key_policy_t *policy ) PSA_KEY_USAGE_VERIFY_HASH | PSA_KEY_USAGE_VERIFY_DERIVATION | PSA_KEY_USAGE_DERIVE ) ) != 0 ) - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } /** Validate the internal consistency of key attributes. @@ -1515,40 +1515,40 @@ static psa_status_t psa_validate_key_attributes( status = psa_validate_key_location( lifetime, p_drv ); if( status != PSA_SUCCESS ) - return( status ); + return status ; status = psa_validate_key_persistence( lifetime ); if( status != PSA_SUCCESS ) - return( status ); + return status ; if ( PSA_KEY_LIFETIME_IS_VOLATILE( lifetime ) ) { if( MBEDTLS_SVC_KEY_ID_GET_KEY_ID( key ) != 0 ) - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; } else { if( !psa_is_valid_key_id( psa_get_key_id( attributes ), 0 ) ) - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; } status = psa_validate_key_policy( &attributes->core.policy ); if( status != PSA_SUCCESS ) - return( status ); + return status ; /* Refuse to create overly large keys. * Note that this doesn't trigger on import if the attributes don't * explicitly specify a size (so psa_get_key_bits returns 0), so * psa_import_key() needs its own checks. */ if( psa_get_key_bits( attributes ) > PSA_MAX_KEY_BITS ) - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; /* Reject invalid flags. These should not be reachable through the API. */ if( attributes->core.flags & ~ ( MBEDTLS_PSA_KA_MASK_EXTERNAL_ONLY | MBEDTLS_PSA_KA_MASK_DUAL_USE ) ) - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } /** Prepare a key slot to receive key material. @@ -1595,11 +1595,11 @@ static psa_status_t psa_start_key_creation( status = psa_validate_key_attributes( attributes, p_drv ); if( status != PSA_SUCCESS ) - return( status ); + return status ; status = psa_get_empty_key_slot( &volatile_key_id, p_slot ); if( status != PSA_SUCCESS ) - return( status ); + return status ; slot = *p_slot; /* We're storing the declared bit-size of the key. It's up to each @@ -1651,7 +1651,7 @@ static psa_status_t psa_start_key_creation( status = psa_find_se_slot_for_key( attributes, method, *p_drv, &slot_number ); if( status != PSA_SUCCESS ) - return( status ); + return status ; if( ! PSA_KEY_LIFETIME_IS_VOLATILE( attributes->core.lifetime ) ) { @@ -1663,7 +1663,7 @@ static psa_status_t psa_start_key_creation( if( status != PSA_SUCCESS ) { (void) psa_crypto_stop_transaction( ); - return( status ); + return status ; } } @@ -1674,11 +1674,11 @@ static psa_status_t psa_start_key_creation( if( *p_drv == NULL && method == PSA_KEY_CREATION_REGISTER ) { /* Key registration only makes sense with a secure element. */ - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; } #endif /* MBEDTLS_PSA_CRYPTO_SE_C */ - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } /** Finalize the creation of a key once its key material has been set. @@ -1765,7 +1765,7 @@ static psa_status_t psa_finish_key_creation( if( status != PSA_SUCCESS ) { psa_destroy_persistent_key( slot->attr.id ); - return( status ); + return status ; } status = psa_crypto_stop_transaction( ); } @@ -1779,7 +1779,7 @@ static psa_status_t psa_finish_key_creation( *key = MBEDTLS_SVC_KEY_ID_INIT; } - return( status ); + return status ; } /** Abort the creation of a key. @@ -1838,7 +1838,7 @@ static psa_status_t psa_validate_optional_attributes( if( attributes->core.type != 0 ) { if( attributes->core.type != slot->attr.type ) - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; } if( attributes->domain_parameters_size != 0 ) @@ -1857,7 +1857,7 @@ static psa_status_t psa_validate_optional_attributes( slot->key.bytes, &rsa ); if( status != PSA_SUCCESS ) - return( status ); + return status ; mbedtls_mpi_init( &actual ); mbedtls_mpi_init( &required ); @@ -1878,23 +1878,23 @@ static psa_status_t psa_validate_optional_attributes( mbedtls_mpi_free( &actual ); mbedtls_mpi_free( &required ); if( ret != 0) - return( mbedtls_to_psa_error( ret ) ); + return mbedtls_to_psa_error( ret ) ; } else #endif /* defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_KEY_PAIR) || * defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_PUBLIC_KEY) */ { - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; } } if( attributes->core.bits != 0 ) { if( attributes->core.bits != slot->attr.bits ) - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; } - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } psa_status_t psa_import_key( const psa_key_attributes_t *attributes, @@ -1913,7 +1913,7 @@ psa_status_t psa_import_key( const psa_key_attributes_t *attributes, * This also rejects any key which might be encoded as an empty string, * which is never valid. */ if( data_length == 0 ) - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; status = psa_start_key_creation( PSA_KEY_CREATION_IMPORT, attributes, &slot, &driver ); @@ -1957,7 +1957,7 @@ exit: if( status != PSA_SUCCESS ) psa_fail_key_creation( slot, driver ); - return( status ); + return status ; } #if defined(MBEDTLS_PSA_CRYPTO_SE_C) @@ -1974,9 +1974,9 @@ psa_status_t mbedtls_psa_register_se_key( * secure element, but not all secure elements support this * and the driver HAL doesn't currently support it. */ if( psa_get_key_type( attributes ) == PSA_KEY_TYPE_NONE ) - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; if( psa_get_key_bits( attributes ) == 0 ) - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; status = psa_start_key_creation( PSA_KEY_CREATION_REGISTER, attributes, &slot, &driver ); @@ -1991,7 +1991,7 @@ exit: /* Registration doesn't keep the key in RAM. */ psa_close_key( key ); - return( status ); + return status ; } #endif /* MBEDTLS_PSA_CRYPTO_SE_C */ @@ -2002,12 +2002,12 @@ static psa_status_t psa_copy_key_material( const psa_key_slot_t *source, source->key.data, source->key.bytes ); if( status != PSA_SUCCESS ) - return( status ); + return status ; target->attr.type = source->attr.type; target->attr.bits = source->attr.bits; - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } psa_status_t psa_copy_key( mbedtls_svc_key_id_t source_key, @@ -2075,7 +2075,7 @@ exit: unlock_status = psa_unlock_key_slot( source_slot ); - return( ( status == PSA_SUCCESS ) ? unlock_status : status ); + return ( status == PSA_SUCCESS ) ? unlock_status : status ; } @@ -2088,12 +2088,12 @@ psa_status_t psa_hash_abort( psa_hash_operation_t *operation ) { /* Aborting a non-active operation is allowed */ if( operation->id == 0 ) - return( PSA_SUCCESS ); + return PSA_SUCCESS ; psa_status_t status = psa_driver_wrapper_hash_abort( operation ); operation->id = 0; - return( status ); + return status ; } psa_status_t psa_hash_setup( psa_hash_operation_t *operation, @@ -2142,7 +2142,7 @@ psa_status_t psa_hash_update( psa_hash_operation_t *operation, /* Don't require hash implementations to behave correctly on a * zero-length input, which may have an invalid pointer. */ if( input_length == 0 ) - return( PSA_SUCCESS ); + return PSA_SUCCESS ; status = psa_driver_wrapper_hash_update( operation, input, input_length ); @@ -2150,7 +2150,7 @@ exit: if( status != PSA_SUCCESS ) psa_hash_abort( operation ); - return( status ); + return status ; } psa_status_t psa_hash_finish( psa_hash_operation_t *operation, @@ -2160,12 +2160,12 @@ psa_status_t psa_hash_finish( psa_hash_operation_t *operation, { *hash_length = 0; if( operation->id == 0 ) - return( PSA_ERROR_BAD_STATE ); + return PSA_ERROR_BAD_STATE ; psa_status_t status = psa_driver_wrapper_hash_finish( operation, hash, hash_size, hash_length ); psa_hash_abort( operation ); - return( status ); + return status ; } psa_status_t psa_hash_verify( psa_hash_operation_t *operation, @@ -2195,7 +2195,7 @@ exit: if( status != PSA_SUCCESS ) psa_hash_abort(operation); - return( status ); + return status ; } psa_status_t psa_hash_compute( psa_algorithm_t alg, @@ -2205,7 +2205,7 @@ psa_status_t psa_hash_compute( psa_algorithm_t alg, { *hash_length = 0; if( !PSA_ALG_IS_HASH( alg ) ) - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; return( psa_driver_wrapper_hash_compute( alg, input, input_length, hash, hash_size, hash_length ) ); @@ -2219,19 +2219,19 @@ psa_status_t psa_hash_compare( psa_algorithm_t alg, size_t actual_hash_length; if( !PSA_ALG_IS_HASH( alg ) ) - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; psa_status_t status = psa_driver_wrapper_hash_compute( alg, input, input_length, actual_hash, sizeof(actual_hash), &actual_hash_length ); if( status != PSA_SUCCESS ) - return( status ); + return status ; if( actual_hash_length != hash_length ) - return( PSA_ERROR_INVALID_SIGNATURE ); + return PSA_ERROR_INVALID_SIGNATURE ; if( mbedtls_psa_safer_memcmp( hash, actual_hash, actual_hash_length ) != 0 ) - return( PSA_ERROR_INVALID_SIGNATURE ); - return( PSA_SUCCESS ); + return PSA_ERROR_INVALID_SIGNATURE ; + return PSA_SUCCESS ; } psa_status_t psa_hash_clone( const psa_hash_operation_t *source_operation, @@ -2240,7 +2240,7 @@ psa_status_t psa_hash_clone( const psa_hash_operation_t *source_operation, if( source_operation->id == 0 || target_operation->id != 0 ) { - return( PSA_ERROR_BAD_STATE ); + return PSA_ERROR_BAD_STATE ; } psa_status_t status = psa_driver_wrapper_hash_clone( source_operation, @@ -2248,7 +2248,7 @@ psa_status_t psa_hash_clone( const psa_hash_operation_t *source_operation, if( status != PSA_SUCCESS ) psa_hash_abort( target_operation ); - return( status ); + return status ; } @@ -2260,14 +2260,14 @@ psa_status_t psa_mac_abort( psa_mac_operation_t *operation ) { /* Aborting a non-active operation is allowed */ if( operation->id == 0 ) - return( PSA_SUCCESS ); + return PSA_SUCCESS ; psa_status_t status = psa_driver_wrapper_mac_abort( operation ); operation->mac_size = 0; operation->is_sign = 0; operation->id = 0; - return( status ); + return status ; } static psa_status_t psa_mac_finalize_alg_and_key_validation( @@ -2280,12 +2280,12 @@ static psa_status_t psa_mac_finalize_alg_and_key_validation( size_t key_bits = psa_get_key_bits( attributes ); if( ! PSA_ALG_IS_MAC( alg ) ) - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; /* Validate the combination of key type and algorithm */ status = psa_mac_key_can_do( alg, key_type ); if( status != PSA_SUCCESS ) - return( status ); + return status ; /* Get the output length for the algorithm and key combination */ *mac_size = PSA_MAC_LENGTH( key_type, key_bits, alg ); @@ -2296,7 +2296,7 @@ static psa_status_t psa_mac_finalize_alg_and_key_validation( * brute-forced. Ancient protocols with 32-bit MACs do exist, * so we make this our minimum, even though 32 bits is still * too small for security. */ - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; } if( *mac_size > PSA_MAC_LENGTH( key_type, key_bits, @@ -2304,10 +2304,10 @@ static psa_status_t psa_mac_finalize_alg_and_key_validation( { /* It's impossible to "truncate" to a larger length than the full length * of the algorithm. */ - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; } - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } static psa_status_t psa_mac_setup( psa_mac_operation_t *operation, @@ -2368,21 +2368,21 @@ exit: unlock_status = psa_unlock_key_slot( slot ); - return( ( status == PSA_SUCCESS ) ? unlock_status : status ); + return ( status == PSA_SUCCESS ) ? unlock_status : status ; } psa_status_t psa_mac_sign_setup( psa_mac_operation_t *operation, mbedtls_svc_key_id_t key, psa_algorithm_t alg ) { - return( psa_mac_setup( operation, key, alg, 1 ) ); + return psa_mac_setup( operation, key, alg, 1 ) ; } psa_status_t psa_mac_verify_setup( psa_mac_operation_t *operation, mbedtls_svc_key_id_t key, psa_algorithm_t alg ) { - return( psa_mac_setup( operation, key, alg, 0 ) ); + return psa_mac_setup( operation, key, alg, 0 ) ; } psa_status_t psa_mac_update( psa_mac_operation_t *operation, @@ -2390,19 +2390,19 @@ psa_status_t psa_mac_update( psa_mac_operation_t *operation, size_t input_length ) { if( operation->id == 0 ) - return( PSA_ERROR_BAD_STATE ); + return PSA_ERROR_BAD_STATE ; /* Don't require hash implementations to behave correctly on a * zero-length input, which may have an invalid pointer. */ if( input_length == 0 ) - return( PSA_SUCCESS ); + return PSA_SUCCESS ; psa_status_t status = psa_driver_wrapper_mac_update( operation, input, input_length ); if( status != PSA_SUCCESS ) psa_mac_abort( operation ); - return( status ); + return status ; } psa_status_t psa_mac_sign_finish( psa_mac_operation_t *operation, @@ -2462,7 +2462,7 @@ exit: abort_status = psa_mac_abort( operation ); - return( status == PSA_SUCCESS ? abort_status : status ); + return status == PSA_SUCCESS ? abort_status : status ; } psa_status_t psa_mac_verify_finish( psa_mac_operation_t *operation, @@ -2496,7 +2496,7 @@ psa_status_t psa_mac_verify_finish( psa_mac_operation_t *operation, exit: abort_status = psa_mac_abort( operation ); - return( status == PSA_SUCCESS ? abort_status : status ); + return status == PSA_SUCCESS ? abort_status : status ; } static psa_status_t psa_mac_compute_internal( mbedtls_svc_key_id_t key, @@ -2559,7 +2559,7 @@ exit: unlock_status = psa_unlock_key_slot( slot ); - return( ( status == PSA_SUCCESS ) ? unlock_status : status ); + return ( status == PSA_SUCCESS ) ? unlock_status : status ; } psa_status_t psa_mac_compute( mbedtls_svc_key_id_t key, @@ -2607,7 +2607,7 @@ psa_status_t psa_mac_verify( mbedtls_svc_key_id_t key, exit: mbedtls_platform_zeroize( actual_mac, sizeof( actual_mac ) ); - return ( status ); + return status ; } /****************************************************************/ @@ -2620,21 +2620,21 @@ static psa_status_t psa_sign_verify_check_alg( int input_is_message, if( input_is_message ) { if( ! PSA_ALG_IS_SIGN_MESSAGE( alg ) ) - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; if ( PSA_ALG_IS_HASH_AND_SIGN( alg ) ) { if( ! PSA_ALG_IS_HASH( PSA_ALG_SIGN_GET_HASH( alg ) ) ) - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; } } else { if( ! PSA_ALG_IS_HASH_AND_SIGN( alg ) ) - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; } - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } static psa_status_t psa_sign_internal( mbedtls_svc_key_id_t key, @@ -2661,7 +2661,7 @@ static psa_status_t psa_sign_internal( mbedtls_svc_key_id_t key, * buffer can in principle be empty since it doesn't actually have * to be a hash.) */ if( signature_size == 0 ) - return( PSA_ERROR_BUFFER_TOO_SMALL ); + return PSA_ERROR_BUFFER_TOO_SMALL ; status = psa_get_and_lock_key_slot_with_policy( key, &slot, @@ -2714,7 +2714,7 @@ exit: unlock_status = psa_unlock_key_slot( slot ); - return( ( status == PSA_SUCCESS ) ? unlock_status : status ); + return ( status == PSA_SUCCESS ) ? unlock_status : status ; } static psa_status_t psa_verify_internal( mbedtls_svc_key_id_t key, @@ -2740,7 +2740,7 @@ static psa_status_t psa_verify_internal( mbedtls_svc_key_id_t key, alg ); if( status != PSA_SUCCESS ) - return( status ); + return status ; psa_key_attributes_t attributes = { .core = slot->attr @@ -2763,7 +2763,7 @@ static psa_status_t psa_verify_internal( mbedtls_svc_key_id_t key, unlock_status = psa_unlock_key_slot( slot ); - return( ( status == PSA_SUCCESS ) ? unlock_status : status ); + return ( status == PSA_SUCCESS ) ? unlock_status : status ; } @@ -2799,7 +2799,7 @@ psa_status_t psa_sign_message_builtin( signature, signature_size, signature_length ); } - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; } psa_status_t psa_sign_message( mbedtls_svc_key_id_t key, @@ -2846,7 +2846,7 @@ psa_status_t psa_verify_message_builtin( signature, signature_length ); } - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; } psa_status_t psa_verify_message( mbedtls_svc_key_id_t key, @@ -2884,7 +2884,7 @@ psa_status_t psa_sign_hash_builtin( } else { - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; } } else @@ -2904,7 +2904,7 @@ psa_status_t psa_sign_hash_builtin( } else { - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; } } @@ -2916,7 +2916,7 @@ psa_status_t psa_sign_hash_builtin( (void)signature_size; (void)signature_length; - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; } psa_status_t psa_sign_hash( mbedtls_svc_key_id_t key, @@ -2955,7 +2955,7 @@ psa_status_t psa_verify_hash_builtin( } else { - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; } } else @@ -2975,7 +2975,7 @@ psa_status_t psa_verify_hash_builtin( } else { - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; } } @@ -2986,7 +2986,7 @@ psa_status_t psa_verify_hash_builtin( (void)signature; (void)signature_length; - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; } psa_status_t psa_verify_hash( mbedtls_svc_key_id_t key, @@ -3009,7 +3009,7 @@ static int psa_rsa_oaep_set_padding_mode( psa_algorithm_t alg, const mbedtls_md_info_t *md_info = mbedtls_md_info_from_psa( hash_alg ); mbedtls_md_type_t md_alg = mbedtls_md_get_type( md_info ); - return( mbedtls_rsa_set_padding( rsa, MBEDTLS_RSA_PKCS_V21, md_alg ) ); + return mbedtls_rsa_set_padding( rsa, MBEDTLS_RSA_PKCS_V21, md_alg ) ; } #endif /* defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_OAEP) */ @@ -3036,12 +3036,12 @@ psa_status_t psa_asymmetric_encrypt( mbedtls_svc_key_id_t key, *output_length = 0; if( ! PSA_ALG_IS_RSA_OAEP( alg ) && salt_length != 0 ) - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; status = psa_get_and_lock_transparent_key_slot_with_policy( key, &slot, PSA_KEY_USAGE_ENCRYPT, alg ); if( status != PSA_SUCCESS ) - return( status ); + return status ; if( ! ( PSA_KEY_TYPE_IS_PUBLIC_KEY( slot->attr.type ) || PSA_KEY_TYPE_IS_KEY_PAIR( slot->attr.type ) ) ) { @@ -3119,7 +3119,7 @@ rsa_exit: exit: unlock_status = psa_unlock_key_slot( slot ); - return( ( status == PSA_SUCCESS ) ? unlock_status : status ); + return ( status == PSA_SUCCESS ) ? unlock_status : status ; } psa_status_t psa_asymmetric_decrypt( mbedtls_svc_key_id_t key, @@ -3145,12 +3145,12 @@ psa_status_t psa_asymmetric_decrypt( mbedtls_svc_key_id_t key, *output_length = 0; if( ! PSA_ALG_IS_RSA_OAEP( alg ) && salt_length != 0 ) - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; status = psa_get_and_lock_transparent_key_slot_with_policy( key, &slot, PSA_KEY_USAGE_DECRYPT, alg ); if( status != PSA_SUCCESS ) - return( status ); + return status ; if( ! PSA_KEY_TYPE_IS_KEY_PAIR( slot->attr.type ) ) { status = PSA_ERROR_INVALID_ARGUMENT; @@ -3227,7 +3227,7 @@ rsa_exit: exit: unlock_status = psa_unlock_key_slot( slot ); - return( ( status == PSA_SUCCESS ) ? unlock_status : status ); + return ( status == PSA_SUCCESS ) ? unlock_status : status ; } @@ -3300,21 +3300,21 @@ exit: unlock_status = psa_unlock_key_slot( slot ); - return( ( status == PSA_SUCCESS ) ? unlock_status : status ); + return ( status == PSA_SUCCESS ) ? unlock_status : status ; } psa_status_t psa_cipher_encrypt_setup( psa_cipher_operation_t *operation, mbedtls_svc_key_id_t key, psa_algorithm_t alg ) { - return( psa_cipher_setup( operation, key, alg, MBEDTLS_ENCRYPT ) ); + return psa_cipher_setup( operation, key, alg, MBEDTLS_ENCRYPT ) ; } psa_status_t psa_cipher_decrypt_setup( psa_cipher_operation_t *operation, mbedtls_svc_key_id_t key, psa_algorithm_t alg ) { - return( psa_cipher_setup( operation, key, alg, MBEDTLS_DECRYPT ) ); + return psa_cipher_setup( operation, key, alg, MBEDTLS_DECRYPT ) ; } psa_status_t psa_cipher_generate_iv( psa_cipher_operation_t *operation, @@ -3361,7 +3361,7 @@ exit: else psa_cipher_abort( operation ); - return( status ); + return status ; } psa_status_t psa_cipher_set_iv( psa_cipher_operation_t *operation, @@ -3397,7 +3397,7 @@ exit: operation->iv_set = 1; else psa_cipher_abort( operation ); - return( status ); + return status ; } psa_status_t psa_cipher_update( psa_cipher_operation_t *operation, @@ -3432,7 +3432,7 @@ exit: if( status != PSA_SUCCESS ) psa_cipher_abort( operation ); - return( status ); + return status ; } psa_status_t psa_cipher_finish( psa_cipher_operation_t *operation, @@ -3461,13 +3461,13 @@ psa_status_t psa_cipher_finish( psa_cipher_operation_t *operation, exit: if( status == PSA_SUCCESS ) - return( psa_cipher_abort( operation ) ); + return psa_cipher_abort( operation ) ; else { *output_length = 0; (void) psa_cipher_abort( operation ); - return( status ); + return status ; } } @@ -3478,7 +3478,7 @@ psa_status_t psa_cipher_abort( psa_cipher_operation_t *operation ) /* The object has (apparently) been initialized but it is not (yet) * in use. It's ok to call abort on such an object, and there's * nothing to do. */ - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } psa_driver_wrapper_cipher_abort( operation ); @@ -3487,7 +3487,7 @@ psa_status_t psa_cipher_abort( psa_cipher_operation_t *operation ) operation->iv_set = 0; operation->iv_required = 0; - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } psa_status_t psa_cipher_encrypt( mbedtls_svc_key_id_t key, @@ -3507,13 +3507,13 @@ psa_status_t psa_cipher_encrypt( mbedtls_svc_key_id_t key, *output_length = 0; if( ! PSA_ALG_IS_CIPHER( alg ) ) - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; status = psa_get_and_lock_key_slot_with_policy( key, &slot, PSA_KEY_USAGE_ENCRYPT, alg ); if( status != PSA_SUCCESS ) - return( status ); + return status ; psa_key_attributes_t attributes = { .core = slot->attr @@ -3543,7 +3543,7 @@ psa_status_t psa_cipher_encrypt( mbedtls_svc_key_id_t key, exit: unlock_status = psa_unlock_key_slot( slot ); - return( ( status == PSA_SUCCESS ) ? unlock_status : status ); + return ( status == PSA_SUCCESS ) ? unlock_status : status ; } psa_status_t psa_cipher_decrypt( mbedtls_svc_key_id_t key, @@ -3561,13 +3561,13 @@ psa_status_t psa_cipher_decrypt( mbedtls_svc_key_id_t key, *output_length = 0; if( ! PSA_ALG_IS_CIPHER( alg ) ) - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; status = psa_get_and_lock_key_slot_with_policy( key, &slot, PSA_KEY_USAGE_DECRYPT, alg ); if( status != PSA_SUCCESS ) - return( status ); + return status ; psa_key_attributes_t attributes = { .core = slot->attr @@ -3587,7 +3587,7 @@ psa_status_t psa_cipher_decrypt( mbedtls_svc_key_id_t key, exit: unlock_status = psa_unlock_key_slot( slot ); - return( ( status == PSA_SUCCESS ) ? unlock_status : status ); + return ( status == PSA_SUCCESS ) ? unlock_status : status ; } @@ -3613,12 +3613,12 @@ psa_status_t psa_aead_encrypt( mbedtls_svc_key_id_t key, *ciphertext_length = 0; if( !PSA_ALG_IS_AEAD( alg ) || PSA_ALG_IS_WILDCARD( alg ) ) - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; status = psa_get_and_lock_key_slot_with_policy( key, &slot, PSA_KEY_USAGE_ENCRYPT, alg ); if( status != PSA_SUCCESS ) - return( status ); + return status ; psa_key_attributes_t attributes = { .core = slot->attr @@ -3637,7 +3637,7 @@ psa_status_t psa_aead_encrypt( mbedtls_svc_key_id_t key, psa_unlock_key_slot( slot ); - return( status ); + return status ; } psa_status_t psa_aead_decrypt( mbedtls_svc_key_id_t key, @@ -3658,12 +3658,12 @@ psa_status_t psa_aead_decrypt( mbedtls_svc_key_id_t key, *plaintext_length = 0; if( !PSA_ALG_IS_AEAD( alg ) || PSA_ALG_IS_WILDCARD( alg ) ) - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; status = psa_get_and_lock_key_slot_with_policy( key, &slot, PSA_KEY_USAGE_DECRYPT, alg ); if( status != PSA_SUCCESS ) - return( status ); + return status ; psa_key_attributes_t attributes = { .core = slot->attr @@ -3682,7 +3682,7 @@ psa_status_t psa_aead_decrypt( mbedtls_svc_key_id_t key, psa_unlock_key_slot( slot ); - return( status ); + return status ; } /****************************************************************/ @@ -3719,7 +3719,7 @@ static psa_status_t psa_key_derivation_start_hmac( PSA_ALG_HMAC( hash_alg ) ); psa_reset_key_attributes( &attributes ); - return( status ); + return status ; } #endif /* KDF algorithms reliant on HMAC */ @@ -3732,9 +3732,9 @@ static psa_algorithm_t psa_key_derivation_get_kdf_alg( const psa_key_derivation_operation_t *operation ) { if ( PSA_ALG_IS_KEY_AGREEMENT( operation->alg ) ) - return( PSA_ALG_KEY_AGREEMENT_GET_KDF( operation->alg ) ); + return PSA_ALG_KEY_AGREEMENT_GET_KDF( operation->alg ) ; else - return( operation->alg ); + return operation->alg ; } psa_status_t psa_key_derivation_abort( psa_key_derivation_operation_t *operation ) @@ -3795,7 +3795,7 @@ psa_status_t psa_key_derivation_abort( psa_key_derivation_operation_t *operation status = PSA_ERROR_BAD_STATE; } mbedtls_platform_zeroize( operation, sizeof( *operation ) ); - return( status ); + return status ; } psa_status_t psa_key_derivation_get_capacity(const psa_key_derivation_operation_t *operation, @@ -3804,22 +3804,22 @@ psa_status_t psa_key_derivation_get_capacity(const psa_key_derivation_operation_ if( operation->alg == 0 ) { /* This is a blank key derivation operation. */ - return( PSA_ERROR_BAD_STATE ); + return PSA_ERROR_BAD_STATE ; } *capacity = operation->capacity; - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } psa_status_t psa_key_derivation_set_capacity( psa_key_derivation_operation_t *operation, size_t capacity ) { if( operation->alg == 0 ) - return( PSA_ERROR_BAD_STATE ); + return PSA_ERROR_BAD_STATE ; if( capacity > operation->capacity ) - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; operation->capacity = capacity; - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } #if defined(MBEDTLS_PSA_BUILTIN_ALG_HKDF) @@ -3835,7 +3835,7 @@ static psa_status_t psa_key_derivation_hkdf_read( psa_hkdf_key_derivation_t *hkd psa_status_t status; if( hkdf->state < HKDF_STATE_KEYED || ! hkdf->info_set ) - return( PSA_ERROR_BAD_STATE ); + return PSA_ERROR_BAD_STATE ; hkdf->state = HKDF_STATE_OUTPUT; while( output_length != 0 ) @@ -3856,7 +3856,7 @@ static psa_status_t psa_key_derivation_hkdf_read( psa_hkdf_key_derivation_t *hkd * object was corrupted or if this function is called directly * inside the library. */ if( hkdf->block_number == 0xff ) - return( PSA_ERROR_BAD_STATE ); + return PSA_ERROR_BAD_STATE ; /* We need a new block */ ++hkdf->block_number; @@ -3867,7 +3867,7 @@ static psa_status_t psa_key_derivation_hkdf_read( psa_hkdf_key_derivation_t *hkd hkdf->prk, hash_length ); if( status != PSA_SUCCESS ) - return( status ); + return status ; if( hkdf->block_number != 1 ) { @@ -3875,26 +3875,26 @@ static psa_status_t psa_key_derivation_hkdf_read( psa_hkdf_key_derivation_t *hkd hkdf->output_block, hash_length ); if( status != PSA_SUCCESS ) - return( status ); + return status ; } status = psa_mac_update( &hkdf->hmac, hkdf->info, hkdf->info_length ); if( status != PSA_SUCCESS ) - return( status ); + return status ; status = psa_mac_update( &hkdf->hmac, &hkdf->block_number, 1 ); if( status != PSA_SUCCESS ) - return( status ); + return status ; status = psa_mac_sign_finish( &hkdf->hmac, hkdf->output_block, sizeof( hkdf->output_block ), &hmac_output_length ); if( status != PSA_SUCCESS ) - return( status ); + return status ; } - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } #endif /* MBEDTLS_PSA_BUILTIN_ALG_HKDF */ @@ -3916,7 +3916,7 @@ static psa_status_t psa_key_derivation_tls12_prf_generate_next_block( * object was corrupted or if this function is called directly * inside the library. */ if( tls12_prf->block_number == 0xff ) - return( PSA_ERROR_CORRUPTION_DETECTED ); + return PSA_ERROR_CORRUPTION_DETECTED ; /* We need a new block */ ++tls12_prf->block_number; @@ -4007,7 +4007,7 @@ cleanup: if( status == PSA_SUCCESS && cleanup_status != PSA_SUCCESS ) status = cleanup_status; - return( status ); + return status ; } static psa_status_t psa_key_derivation_tls12_prf_read( @@ -4029,7 +4029,7 @@ static psa_status_t psa_key_derivation_tls12_prf_read( case PSA_TLS12_PRF_STATE_OUTPUT: break; default: - return( PSA_ERROR_BAD_STATE ); + return PSA_ERROR_BAD_STATE ; } while( output_length != 0 ) @@ -4040,7 +4040,7 @@ static psa_status_t psa_key_derivation_tls12_prf_read( status = psa_key_derivation_tls12_prf_generate_next_block( tls12_prf, alg ); if( status != PSA_SUCCESS ) - return( status ); + return status ; continue; } @@ -4057,7 +4057,7 @@ static psa_status_t psa_key_derivation_tls12_prf_read( tls12_prf->left_in_block -= length; } - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } #endif /* MBEDTLS_PSA_BUILTIN_ALG_TLS12_PRF || * MBEDTLS_PSA_BUILTIN_ALG_TLS12_PSK_TO_MS */ @@ -4073,7 +4073,7 @@ psa_status_t psa_key_derivation_output_bytes( if( operation->alg == 0 ) { /* This is a blank operation. */ - return( PSA_ERROR_BAD_STATE ); + return PSA_ERROR_BAD_STATE ; } if( output_length > operation->capacity ) @@ -4092,7 +4092,7 @@ psa_status_t psa_key_derivation_output_bytes( * INSUFFICIENT_CAPACITY, which is right for a finished * operation, for consistency with the case when * output_length > 0. */ - return( PSA_ERROR_INSUFFICIENT_DATA ); + return PSA_ERROR_INSUFFICIENT_DATA ; } operation->capacity -= output_length; @@ -4119,7 +4119,7 @@ psa_status_t psa_key_derivation_output_bytes( * MBEDTLS_PSA_BUILTIN_ALG_TLS12_PSK_TO_MS */ { (void) kdf_alg; - return( PSA_ERROR_BAD_STATE ); + return PSA_ERROR_BAD_STATE ; } exit: @@ -4134,7 +4134,7 @@ exit: operation->alg = alg; memset( output, '!', output_length ); } - return( status ); + return status ; } #if defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_DES) @@ -4159,12 +4159,12 @@ static psa_status_t psa_generate_derived_key_internal( psa_status_t status; if( ! key_type_is_raw_bytes( slot->attr.type ) ) - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; if( bits % 8 != 0 ) - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; data = mbedtls_calloc( 1, bytes ); if( data == NULL ) - return( PSA_ERROR_INSUFFICIENT_MEMORY ); + return PSA_ERROR_INSUFFICIENT_MEMORY ; status = psa_key_derivation_output_bytes( operation, data, bytes ); if( status != PSA_SUCCESS ) @@ -4193,7 +4193,7 @@ static psa_status_t psa_generate_derived_key_internal( exit: mbedtls_free( data ); - return( status ); + return status ; } psa_status_t psa_key_derivation_output_key( const psa_key_attributes_t *attributes, @@ -4209,10 +4209,10 @@ psa_status_t psa_key_derivation_output_key( const psa_key_attributes_t *attribut /* Reject any attempt to create a zero-length key so that we don't * risk tripping up later, e.g. on a malloc(0) that returns NULL. */ if( psa_get_key_bits( attributes ) == 0 ) - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; if( ! operation->can_output_key ) - return( PSA_ERROR_NOT_PERMITTED ); + return PSA_ERROR_NOT_PERMITTED ; status = psa_start_key_creation( PSA_KEY_CREATION_DERIVE, attributes, &slot, &driver ); @@ -4234,7 +4234,7 @@ psa_status_t psa_key_derivation_output_key( const psa_key_attributes_t *attribut if( status != PSA_SUCCESS ) psa_fail_key_creation( slot, driver ); - return( status ); + return status ; } @@ -4277,18 +4277,18 @@ static psa_status_t psa_key_derivation_setup_kdf( psa_algorithm_t hash_alg = PSA_ALG_HKDF_GET_HASH( kdf_alg ); size_t hash_size = PSA_HASH_LENGTH( hash_alg ); if( hash_size == 0 ) - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; if( ( PSA_ALG_IS_TLS12_PRF( kdf_alg ) || PSA_ALG_IS_TLS12_PSK_TO_MS( kdf_alg ) ) && ! ( hash_alg == PSA_ALG_SHA_256 || hash_alg == PSA_ALG_SHA_384 ) ) { - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; } operation->capacity = 255 * hash_size; - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; } #endif /* AT_LEAST_ONE_BUILTIN_KDF */ @@ -4298,17 +4298,17 @@ psa_status_t psa_key_derivation_setup( psa_key_derivation_operation_t *operation psa_status_t status; if( operation->alg != 0 ) - return( PSA_ERROR_BAD_STATE ); + return PSA_ERROR_BAD_STATE ; if( PSA_ALG_IS_RAW_KEY_AGREEMENT( alg ) ) - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; else if( PSA_ALG_IS_KEY_AGREEMENT( alg ) ) { #if defined(AT_LEAST_ONE_BUILTIN_KDF) psa_algorithm_t kdf_alg = PSA_ALG_KEY_AGREEMENT_GET_KDF( alg ); status = psa_key_derivation_setup_kdf( operation, kdf_alg ); #else - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; #endif /* AT_LEAST_ONE_BUILTIN_KDF */ } else if( PSA_ALG_IS_KEY_DERIVATION( alg ) ) @@ -4316,15 +4316,15 @@ psa_status_t psa_key_derivation_setup( psa_key_derivation_operation_t *operation #if defined(AT_LEAST_ONE_BUILTIN_KDF) status = psa_key_derivation_setup_kdf( operation, alg ); #else - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; #endif /* AT_LEAST_ONE_BUILTIN_KDF */ } else - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; if( status == PSA_SUCCESS ) operation->alg = alg; - return( status ); + return status ; } #if defined(MBEDTLS_PSA_BUILTIN_ALG_HKDF) @@ -4339,16 +4339,16 @@ static psa_status_t psa_hkdf_input( psa_hkdf_key_derivation_t *hkdf, { case PSA_KEY_DERIVATION_INPUT_SALT: if( hkdf->state != HKDF_STATE_INIT ) - return( PSA_ERROR_BAD_STATE ); + return PSA_ERROR_BAD_STATE ; else { status = psa_key_derivation_start_hmac( &hkdf->hmac, hash_alg, data, data_length ); if( status != PSA_SUCCESS ) - return( status ); + return status ; hkdf->state = HKDF_STATE_STARTED; - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } case PSA_KEY_DERIVATION_INPUT_SECRET: /* If no salt was provided, use an empty salt. */ @@ -4358,42 +4358,42 @@ static psa_status_t psa_hkdf_input( psa_hkdf_key_derivation_t *hkdf, hash_alg, NULL, 0 ); if( status != PSA_SUCCESS ) - return( status ); + return status ; hkdf->state = HKDF_STATE_STARTED; } if( hkdf->state != HKDF_STATE_STARTED ) - return( PSA_ERROR_BAD_STATE ); + return PSA_ERROR_BAD_STATE ; status = psa_mac_update( &hkdf->hmac, data, data_length ); if( status != PSA_SUCCESS ) - return( status ); + return status ; status = psa_mac_sign_finish( &hkdf->hmac, hkdf->prk, sizeof( hkdf->prk ), &data_length ); if( status != PSA_SUCCESS ) - return( status ); + return status ; hkdf->offset_in_block = PSA_HASH_LENGTH( hash_alg ); hkdf->block_number = 0; hkdf->state = HKDF_STATE_KEYED; - return( PSA_SUCCESS ); + return PSA_SUCCESS ; case PSA_KEY_DERIVATION_INPUT_INFO: if( hkdf->state == HKDF_STATE_OUTPUT ) - return( PSA_ERROR_BAD_STATE ); + return PSA_ERROR_BAD_STATE ; if( hkdf->info_set ) - return( PSA_ERROR_BAD_STATE ); + return PSA_ERROR_BAD_STATE ; hkdf->info_length = data_length; if( data_length != 0 ) { hkdf->info = mbedtls_calloc( 1, data_length ); if( hkdf->info == NULL ) - return( PSA_ERROR_INSUFFICIENT_MEMORY ); + return PSA_ERROR_INSUFFICIENT_MEMORY ; memcpy( hkdf->info, data, data_length ); } hkdf->info_set = 1; - return( PSA_SUCCESS ); + return PSA_SUCCESS ; default: - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; } } #endif /* MBEDTLS_PSA_BUILTIN_ALG_HKDF */ @@ -4405,13 +4405,13 @@ static psa_status_t psa_tls12_prf_set_seed( psa_tls12_prf_key_derivation_t *prf, size_t data_length ) { if( prf->state != PSA_TLS12_PRF_STATE_INIT ) - return( PSA_ERROR_BAD_STATE ); + return PSA_ERROR_BAD_STATE ; if( data_length != 0 ) { prf->seed = mbedtls_calloc( 1, data_length ); if( prf->seed == NULL ) - return( PSA_ERROR_INSUFFICIENT_MEMORY ); + return PSA_ERROR_INSUFFICIENT_MEMORY ; memcpy( prf->seed, data, data_length ); prf->seed_length = data_length; @@ -4419,7 +4419,7 @@ static psa_status_t psa_tls12_prf_set_seed( psa_tls12_prf_key_derivation_t *prf, prf->state = PSA_TLS12_PRF_STATE_SEED_SET; - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } static psa_status_t psa_tls12_prf_set_key( psa_tls12_prf_key_derivation_t *prf, @@ -4427,13 +4427,13 @@ static psa_status_t psa_tls12_prf_set_key( psa_tls12_prf_key_derivation_t *prf, size_t data_length ) { if( prf->state != PSA_TLS12_PRF_STATE_SEED_SET ) - return( PSA_ERROR_BAD_STATE ); + return PSA_ERROR_BAD_STATE ; if( data_length != 0 ) { prf->secret = mbedtls_calloc( 1, data_length ); if( prf->secret == NULL ) - return( PSA_ERROR_INSUFFICIENT_MEMORY ); + return PSA_ERROR_INSUFFICIENT_MEMORY ; memcpy( prf->secret, data, data_length ); prf->secret_length = data_length; @@ -4441,7 +4441,7 @@ static psa_status_t psa_tls12_prf_set_key( psa_tls12_prf_key_derivation_t *prf, prf->state = PSA_TLS12_PRF_STATE_KEY_SET; - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } static psa_status_t psa_tls12_prf_set_label( psa_tls12_prf_key_derivation_t *prf, @@ -4449,13 +4449,13 @@ static psa_status_t psa_tls12_prf_set_label( psa_tls12_prf_key_derivation_t *prf size_t data_length ) { if( prf->state != PSA_TLS12_PRF_STATE_KEY_SET ) - return( PSA_ERROR_BAD_STATE ); + return PSA_ERROR_BAD_STATE ; if( data_length != 0 ) { prf->label = mbedtls_calloc( 1, data_length ); if( prf->label == NULL ) - return( PSA_ERROR_INSUFFICIENT_MEMORY ); + return PSA_ERROR_INSUFFICIENT_MEMORY ; memcpy( prf->label, data, data_length ); prf->label_length = data_length; @@ -4463,7 +4463,7 @@ static psa_status_t psa_tls12_prf_set_label( psa_tls12_prf_key_derivation_t *prf prf->state = PSA_TLS12_PRF_STATE_LABEL_SET; - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } static psa_status_t psa_tls12_prf_input( psa_tls12_prf_key_derivation_t *prf, @@ -4474,13 +4474,13 @@ static psa_status_t psa_tls12_prf_input( psa_tls12_prf_key_derivation_t *prf, switch( step ) { case PSA_KEY_DERIVATION_INPUT_SEED: - return( psa_tls12_prf_set_seed( prf, data, data_length ) ); + return psa_tls12_prf_set_seed( prf, data, data_length ) ; case PSA_KEY_DERIVATION_INPUT_SECRET: - return( psa_tls12_prf_set_key( prf, data, data_length ) ); + return psa_tls12_prf_set_key( prf, data, data_length ) ; case PSA_KEY_DERIVATION_INPUT_LABEL: - return( psa_tls12_prf_set_label( prf, data, data_length ) ); + return psa_tls12_prf_set_label( prf, data, data_length ) ; default: - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; } } #endif /* MBEDTLS_PSA_BUILTIN_ALG_TLS12_PRF) || @@ -4497,7 +4497,7 @@ static psa_status_t psa_tls12_prf_psk_to_ms_set_key( uint8_t *cur = pms; if( data_length > PSA_TLS12_PSK_TO_MS_PSK_MAX_SIZE ) - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; /* Quoting RFC 4279, Section 2: * @@ -4518,7 +4518,7 @@ static psa_status_t psa_tls12_prf_psk_to_ms_set_key( status = psa_tls12_prf_set_key( prf, pms, cur - pms ); mbedtls_platform_zeroize( pms, sizeof( pms ) ); - return( status ); + return status ; } static psa_status_t psa_tls12_prf_psk_to_ms_input( @@ -4533,7 +4533,7 @@ static psa_status_t psa_tls12_prf_psk_to_ms_input( data, data_length ) ); } - return( psa_tls12_prf_input( prf, step, data, data_length ) ); + return psa_tls12_prf_input( prf, step, data, data_length ) ; } #endif /* MBEDTLS_PSA_BUILTIN_ALG_TLS12_PSK_TO_MS */ @@ -4554,21 +4554,21 @@ static int psa_key_derivation_check_input_type( { case PSA_KEY_DERIVATION_INPUT_SECRET: if( key_type == PSA_KEY_TYPE_DERIVE ) - return( PSA_SUCCESS ); + return PSA_SUCCESS ; if( key_type == PSA_KEY_TYPE_NONE ) - return( PSA_SUCCESS ); + return PSA_SUCCESS ; break; case PSA_KEY_DERIVATION_INPUT_LABEL: case PSA_KEY_DERIVATION_INPUT_SALT: case PSA_KEY_DERIVATION_INPUT_INFO: case PSA_KEY_DERIVATION_INPUT_SEED: if( key_type == PSA_KEY_TYPE_RAW_DATA ) - return( PSA_SUCCESS ); + return PSA_SUCCESS ; if( key_type == PSA_KEY_TYPE_NONE ) - return( PSA_SUCCESS ); + return PSA_SUCCESS ; break; } - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; } static psa_status_t psa_key_derivation_input_internal( @@ -4615,13 +4615,13 @@ static psa_status_t psa_key_derivation_input_internal( (void) data; (void) data_length; (void) kdf_alg; - return( PSA_ERROR_BAD_STATE ); + return PSA_ERROR_BAD_STATE ; } exit: if( status != PSA_SUCCESS ) psa_key_derivation_abort( operation ); - return( status ); + return status ; } psa_status_t psa_key_derivation_input_bytes( @@ -4649,7 +4649,7 @@ psa_status_t psa_key_derivation_input_key( if( status != PSA_SUCCESS ) { psa_key_derivation_abort( operation ); - return( status ); + return status ; } /* Passing a key object as a SECRET input unlocks the permission @@ -4664,7 +4664,7 @@ psa_status_t psa_key_derivation_input_key( unlock_status = psa_unlock_key_slot( slot ); - return( ( status == PSA_SUCCESS ) ? unlock_status : status ); + return ( status == PSA_SUCCESS ) ? unlock_status : status ; } @@ -4724,7 +4724,7 @@ exit: mbedtls_ecp_keypair_free( their_key ); mbedtls_free( their_key ); - return( status ); + return status ; } #endif /* MBEDTLS_PSA_BUILTIN_ALG_ECDH */ @@ -4743,7 +4743,7 @@ static psa_status_t psa_key_agreement_raw_internal( psa_algorithm_t alg, #if defined(MBEDTLS_PSA_BUILTIN_ALG_ECDH) case PSA_ALG_ECDH: if( ! PSA_KEY_TYPE_IS_ECC_KEY_PAIR( private_key->attr.type ) ) - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; mbedtls_ecp_keypair *ecp = NULL; psa_status_t status = mbedtls_psa_ecp_load_representation( private_key->attr.type, @@ -4752,14 +4752,14 @@ static psa_status_t psa_key_agreement_raw_internal( psa_algorithm_t alg, private_key->key.bytes, &ecp ); if( status != PSA_SUCCESS ) - return( status ); + return status ; status = psa_key_agreement_ecdh( peer_key, peer_key_length, ecp, shared_secret, shared_secret_size, shared_secret_length ); mbedtls_ecp_keypair_free( ecp ); mbedtls_free( ecp ); - return( status ); + return status ; #endif /* MBEDTLS_PSA_BUILTIN_ALG_ECDH */ default: (void) private_key; @@ -4768,7 +4768,7 @@ static psa_status_t psa_key_agreement_raw_internal( psa_algorithm_t alg, (void) shared_secret; (void) shared_secret_size; (void) shared_secret_length; - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; } } @@ -4806,7 +4806,7 @@ static psa_status_t psa_key_agreement_internal( psa_key_derivation_operation_t * shared_secret_length ); exit: mbedtls_platform_zeroize( shared_secret, shared_secret_length ); - return( status ); + return status ; } psa_status_t psa_key_derivation_key_agreement( psa_key_derivation_operation_t *operation, @@ -4820,11 +4820,11 @@ psa_status_t psa_key_derivation_key_agreement( psa_key_derivation_operation_t *o psa_key_slot_t *slot; if( ! PSA_ALG_IS_KEY_AGREEMENT( operation->alg ) ) - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; status = psa_get_and_lock_transparent_key_slot_with_policy( private_key, &slot, PSA_KEY_USAGE_DERIVE, operation->alg ); if( status != PSA_SUCCESS ) - return( status ); + return status ; status = psa_key_agreement_internal( operation, step, slot, peer_key, peer_key_length ); @@ -4840,7 +4840,7 @@ psa_status_t psa_key_derivation_key_agreement( psa_key_derivation_operation_t *o unlock_status = psa_unlock_key_slot( slot ); - return( ( status == PSA_SUCCESS ) ? unlock_status : status ); + return ( status == PSA_SUCCESS ) ? unlock_status : status ; } psa_status_t psa_raw_key_agreement( psa_algorithm_t alg, @@ -4886,7 +4886,7 @@ exit: unlock_status = psa_unlock_key_slot( slot ); - return( ( status == PSA_SUCCESS ) ? unlock_status : status ); + return ( status == PSA_SUCCESS ) ? unlock_status : status ; } @@ -4944,7 +4944,7 @@ static psa_status_t mbedtls_psa_random_seed( mbedtls_psa_random_context_t *rng ) #if defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG) /* Do nothing: the external RNG seeds itself. */ (void) rng; - return( PSA_SUCCESS ); + return PSA_SUCCESS ; #else /* MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG */ const unsigned char drbg_seed[] = "PSA"; int ret = mbedtls_psa_drbg_seed( &rng->entropy, @@ -4965,12 +4965,12 @@ psa_status_t psa_generate_random( uint8_t *output, output, output_size, &output_length ); if( status != PSA_SUCCESS ) - return( status ); + return status ; /* Breaking up a request into smaller chunks is currently not supported * for the extrernal RNG interface. */ if( output_length != output_size ) - return( PSA_ERROR_INSUFFICIENT_ENTROPY ); - return( PSA_SUCCESS ); + return PSA_ERROR_INSUFFICIENT_ENTROPY ; + return PSA_SUCCESS ; #else /* MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG */ @@ -4983,11 +4983,11 @@ psa_status_t psa_generate_random( uint8_t *output, int ret = mbedtls_psa_get_random( MBEDTLS_PSA_RANDOM_STATE, output, request_size ); if( ret != 0 ) - return( mbedtls_to_psa_error( ret ) ); + return mbedtls_to_psa_error( ret ) ; output_size -= request_size; output += request_size; } - return( PSA_SUCCESS ); + return PSA_SUCCESS ; #endif /* MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG */ } @@ -5017,9 +5017,9 @@ int mbedtls_psa_get_random( void *p_rng, (void) p_rng; psa_status_t status = psa_generate_random( output, output_size ); if( status == PSA_SUCCESS ) - return( 0 ); + return 0 ; else - return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED ); + return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED ; } #endif /* MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG */ @@ -5030,14 +5030,14 @@ psa_status_t mbedtls_psa_inject_entropy( const uint8_t *seed, size_t seed_size ) { if( global_data.initialized ) - return( PSA_ERROR_NOT_PERMITTED ); + return PSA_ERROR_NOT_PERMITTED ; if( ( ( seed_size < MBEDTLS_ENTROPY_MIN_PLATFORM ) || ( seed_size < MBEDTLS_ENTROPY_BLOCK_SIZE ) ) || ( seed_size > MBEDTLS_ENTROPY_MAX_SEED_SIZE ) ) - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; - return( mbedtls_psa_storage_inject_entropy( seed, seed_size ) ); + return mbedtls_psa_storage_inject_entropy( seed, seed_size ) ; } #endif /* MBEDTLS_PSA_INJECT_ENTROPY */ @@ -5063,19 +5063,19 @@ static psa_status_t psa_validate_key_type_and_size_for_key_generation( { status = validate_unstructured_key_bit_size( type, bits ); if( status != PSA_SUCCESS ) - return( status ); + return status ; } else #if defined(PSA_WANT_KEY_TYPE_RSA_KEY_PAIR) if( PSA_KEY_TYPE_IS_RSA( type ) && PSA_KEY_TYPE_IS_KEY_PAIR( type ) ) { if( bits > PSA_VENDOR_RSA_MAX_KEY_BITS ) - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; /* Accept only byte-aligned keys, for the same reasons as * in psa_import_rsa_key(). */ if( bits % 8 != 0 ) - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; } else #endif /* defined(PSA_WANT_KEY_TYPE_RSA_KEY_PAIR) */ @@ -5084,15 +5084,15 @@ static psa_status_t psa_validate_key_type_and_size_for_key_generation( if( PSA_KEY_TYPE_IS_ECC( type ) && PSA_KEY_TYPE_IS_KEY_PAIR( type ) ) { /* To avoid empty block, return successfully here. */ - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } else #endif /* defined(PSA_WANT_KEY_TYPE_ECC_KEY_PAIR) */ { - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; } - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } psa_status_t psa_generate_key_internal( @@ -5104,13 +5104,13 @@ psa_status_t psa_generate_key_internal( if( ( attributes->domain_parameters == NULL ) && ( attributes->domain_parameters_size != 0 ) ) - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; if( key_type_is_raw_bytes( type ) ) { status = psa_generate_random( key_buffer, key_buffer_size ); if( status != PSA_SUCCESS ) - return( status ); + return status ; #if defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_DES) if( type == PSA_KEY_TYPE_DES ) @@ -5144,10 +5144,10 @@ psa_status_t psa_generate_key_internal( #endif /* defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR) */ { (void)key_buffer_length; - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; } - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } psa_status_t psa_generate_key( const psa_key_attributes_t *attributes, @@ -5163,7 +5163,7 @@ psa_status_t psa_generate_key( const psa_key_attributes_t *attributes, /* Reject any attempt to create a zero-length key so that we don't * risk tripping up later, e.g. on a malloc(0) that returns NULL. */ if( psa_get_key_bits( attributes ) == 0 ) - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; status = psa_start_key_creation( PSA_KEY_CREATION_GENERATE, attributes, &slot, &driver ); @@ -5213,7 +5213,7 @@ exit: if( status != PSA_SUCCESS ) psa_fail_key_creation( slot, driver ); - return( status ); + return status ; } /****************************************************************/ @@ -5226,10 +5226,10 @@ psa_status_t mbedtls_psa_crypto_configure_entropy_sources( void (* entropy_free )( mbedtls_entropy_context *ctx ) ) { if( global_data.rng_state != RNG_NOT_INITIALIZED ) - return( PSA_ERROR_BAD_STATE ); + return PSA_ERROR_BAD_STATE ; global_data.rng.entropy_init = entropy_init; global_data.rng.entropy_free = entropy_free; - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } #endif /* !defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG) */ @@ -5272,7 +5272,7 @@ static psa_status_t psa_crypto_recover_transaction( default: /* We found an unsupported transaction in the storage. * We don't know what state the storage is in. Give up. */ - return( PSA_ERROR_DATA_INVALID ); + return PSA_ERROR_DATA_INVALID ; } } #endif /* PSA_CRYPTO_STORAGE_HAS_TRANSACTIONS */ @@ -5283,7 +5283,7 @@ psa_status_t psa_crypto_init( void ) /* Double initialization is explicitly allowed. */ if( global_data.initialized != 0 ) - return( PSA_SUCCESS ); + return PSA_SUCCESS ; /* Initialize and seed the random generator. */ mbedtls_psa_random_init( &global_data.rng ); @@ -5325,7 +5325,7 @@ psa_status_t psa_crypto_init( void ) exit: if( status != PSA_SUCCESS ) mbedtls_psa_crypto_free( ); - return( status ); + return status ; } #endif /* MBEDTLS_PSA_CRYPTO_C */ diff --git a/library/psa_crypto_aead.c b/library/psa_crypto_aead.c index 356679c38f..8fca4953cd 100644 --- a/library/psa_crypto_aead.c +++ b/library/psa_crypto_aead.c @@ -91,7 +91,7 @@ static psa_status_t psa_aead_setup( attributes->core.type, key_bits, &cipher_id ); if( cipher_info == NULL ) - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; switch( PSA_ALG_AEAD_WITH_SHORTENED_TAG( alg, 0 ) ) { @@ -103,14 +103,14 @@ static psa_status_t psa_aead_setup( * The call to mbedtls_ccm_encrypt_and_tag or * mbedtls_ccm_auth_decrypt will validate the tag length. */ if( PSA_BLOCK_CIPHER_BLOCK_LENGTH( attributes->core.type ) != 16 ) - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; mbedtls_ccm_init( &operation->ctx.ccm ); status = mbedtls_to_psa_error( mbedtls_ccm_setkey( &operation->ctx.ccm, cipher_id, key_buffer, (unsigned int) key_bits ) ); if( status != PSA_SUCCESS ) - return( status ); + return status ; break; #endif /* MBEDTLS_PSA_BUILTIN_ALG_CCM */ @@ -122,14 +122,14 @@ static psa_status_t psa_aead_setup( * The call to mbedtls_gcm_crypt_and_tag or * mbedtls_gcm_auth_decrypt will validate the tag length. */ if( PSA_BLOCK_CIPHER_BLOCK_LENGTH( attributes->core.type ) != 16 ) - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; mbedtls_gcm_init( &operation->ctx.gcm ); status = mbedtls_to_psa_error( mbedtls_gcm_setkey( &operation->ctx.gcm, cipher_id, key_buffer, (unsigned int) key_bits ) ); if( status != PSA_SUCCESS ) - return( status ); + return status ; break; #endif /* MBEDTLS_PSA_BUILTIN_ALG_GCM */ @@ -139,31 +139,31 @@ static psa_status_t psa_aead_setup( full_tag_length = 16; /* We only support the default tag length. */ if( alg != PSA_ALG_CHACHA20_POLY1305 ) - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; mbedtls_chachapoly_init( &operation->ctx.chachapoly ); status = mbedtls_to_psa_error( mbedtls_chachapoly_setkey( &operation->ctx.chachapoly, key_buffer ) ); if( status != PSA_SUCCESS ) - return( status ); + return status ; break; #endif /* MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305 */ default: - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; } if( PSA_AEAD_TAG_LENGTH( attributes->core.type, key_bits, alg ) > full_tag_length ) - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; operation->tag_length = PSA_AEAD_TAG_LENGTH( attributes->core.type, key_bits, alg ); - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } psa_status_t mbedtls_psa_aead_encrypt( @@ -243,7 +243,7 @@ psa_status_t mbedtls_psa_aead_encrypt( #endif /* MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305 */ { (void) tag; - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; } if( status == PSA_SUCCESS ) @@ -252,7 +252,7 @@ psa_status_t mbedtls_psa_aead_encrypt( exit: psa_aead_abort_internal( &operation ); - return( status ); + return status ; } /* Locate the tag in a ciphertext buffer containing the encrypted data @@ -268,12 +268,12 @@ static psa_status_t psa_aead_unpadded_locate_tag( size_t tag_length, { size_t payload_length; if( tag_length > ciphertext_length ) - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; payload_length = ciphertext_length - tag_length; if( payload_length > plaintext_size ) - return( PSA_ERROR_BUFFER_TOO_SMALL ); + return PSA_ERROR_BUFFER_TOO_SMALL ; *p_tag = ciphertext + payload_length; - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } psa_status_t mbedtls_psa_aead_decrypt( @@ -349,7 +349,7 @@ psa_status_t mbedtls_psa_aead_decrypt( else #endif /* MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305 */ { - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; } if( status == PSA_SUCCESS ) @@ -360,7 +360,7 @@ exit: if( status == PSA_SUCCESS ) *plaintext_length = ciphertext_length - operation.tag_length; - return( status ); + return status ; } #endif /* MBEDTLS_PSA_CRYPTO_C */ diff --git a/library/psa_crypto_cipher.c b/library/psa_crypto_cipher.c index d8c722bb1b..67d3fd003a 100644 --- a/library/psa_crypto_cipher.c +++ b/library/psa_crypto_cipher.c @@ -102,13 +102,13 @@ const mbedtls_cipher_info_t *mbedtls_cipher_info_from_psa( mode = MBEDTLS_MODE_CHACHAPOLY; break; default: - return( NULL ); + return NULL ; } } else if( alg == PSA_ALG_CMAC ) mode = MBEDTLS_MODE_ECB; else - return( NULL ); + return NULL ; switch( key_type ) { @@ -135,7 +135,7 @@ const mbedtls_cipher_info_t *mbedtls_cipher_info_from_psa( cipher_id_tmp = MBEDTLS_CIPHER_ID_CHACHA20; break; default: - return( NULL ); + return NULL ; } if( cipher_id != NULL ) *cipher_id = cipher_id_tmp; @@ -167,7 +167,7 @@ static psa_status_t cipher_setup( cipher_info = mbedtls_cipher_info_from_psa( alg, key_type, key_bits, NULL ); if( cipher_info == NULL ) - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; ret = mbedtls_cipher_setup( &operation->ctx.cipher, cipher_info ); if( ret != 0 ) @@ -219,7 +219,7 @@ static psa_status_t cipher_setup( operation->iv_length = PSA_CIPHER_IV_LENGTH( key_type, alg ); exit: - return( mbedtls_to_psa_error( ret ) ); + return mbedtls_to_psa_error( ret ) ; } static psa_status_t cipher_encrypt_setup( @@ -248,7 +248,7 @@ static psa_status_t cipher_set_iv( mbedtls_psa_cipher_operation_t *operation, const uint8_t *iv, size_t iv_length ) { if( iv_length != operation->iv_length ) - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; return( mbedtls_to_psa_error( mbedtls_cipher_set_iv( &operation->ctx.cipher, @@ -340,7 +340,7 @@ static psa_status_t psa_cipher_update_ecb( status = PSA_SUCCESS; exit: - return( status ); + return status ; } static psa_status_t cipher_update( mbedtls_psa_cipher_operation_t *operation, @@ -369,7 +369,7 @@ static psa_status_t cipher_update( mbedtls_psa_cipher_operation_t *operation, } if( output_size < expected_output_size ) - return( PSA_ERROR_BUFFER_TOO_SMALL ); + return PSA_ERROR_BUFFER_TOO_SMALL ; if( operation->alg == PSA_ALG_ECB_NO_PADDING ) { @@ -390,10 +390,10 @@ static psa_status_t cipher_update( mbedtls_psa_cipher_operation_t *operation, input_length, output, output_length ) ); if( *output_length > output_size ) - return( PSA_ERROR_CORRUPTION_DETECTED ); + return PSA_ERROR_CORRUPTION_DETECTED ; } - return( status ); + return status ; } static psa_status_t cipher_finish( mbedtls_psa_cipher_operation_t *operation, @@ -432,7 +432,7 @@ exit: mbedtls_platform_zeroize( temp_output_buffer, sizeof( temp_output_buffer ) ); - return( status ); + return status ; } static psa_status_t cipher_abort( mbedtls_psa_cipher_operation_t *operation ) @@ -440,11 +440,11 @@ static psa_status_t cipher_abort( mbedtls_psa_cipher_operation_t *operation ) /* Sanity check (shouldn't happen: operation->alg should * always have been initialized to a valid value). */ if( ! PSA_ALG_IS_CIPHER( operation->alg ) ) - return( PSA_ERROR_BAD_STATE ); + return PSA_ERROR_BAD_STATE ; mbedtls_cipher_free( &operation->ctx.cipher ); - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } static psa_status_t cipher_encrypt( const psa_key_attributes_t *attributes, @@ -497,7 +497,7 @@ exit: status = cipher_abort( &operation ); else cipher_abort( &operation ); - return( status ); + return status ; } static psa_status_t cipher_decrypt( const psa_key_attributes_t *attributes, @@ -546,7 +546,7 @@ exit: status = cipher_abort( &operation ); else cipher_abort( &operation ); - return( status ); + return status ; } #endif /* MBEDTLS_PSA_BUILTIN_CIPHER || PSA_CRYPTO_DRIVER_TEST */ @@ -575,7 +575,7 @@ psa_status_t mbedtls_psa_cipher_set_iv( mbedtls_psa_cipher_operation_t *operatio const uint8_t *iv, size_t iv_length ) { - return( cipher_set_iv( operation, iv, iv_length ) ); + return cipher_set_iv( operation, iv, iv_length ) ; } psa_status_t mbedtls_psa_cipher_update( mbedtls_psa_cipher_operation_t *operation, @@ -594,12 +594,12 @@ psa_status_t mbedtls_psa_cipher_finish( mbedtls_psa_cipher_operation_t *operatio size_t output_size, size_t *output_length ) { - return( cipher_finish( operation, output, output_size, output_length ) ); + return cipher_finish( operation, output, output_size, output_length ) ; } psa_status_t mbedtls_psa_cipher_abort( mbedtls_psa_cipher_operation_t *operation ) { - return( cipher_abort( operation ) ); + return cipher_abort( operation ) ; } psa_status_t mbedtls_psa_cipher_encrypt( const psa_key_attributes_t *attributes, @@ -662,7 +662,7 @@ psa_status_t mbedtls_transparent_test_driver_cipher_set_iv( mbedtls_psa_cipher_operation_t *operation, const uint8_t *iv, size_t iv_length ) { - return( cipher_set_iv( operation, iv, iv_length ) ); + return cipher_set_iv( operation, iv, iv_length ) ; } psa_status_t mbedtls_transparent_test_driver_cipher_update( @@ -678,13 +678,13 @@ psa_status_t mbedtls_transparent_test_driver_cipher_finish( mbedtls_psa_cipher_operation_t *operation, uint8_t *output, size_t output_size, size_t *output_length ) { - return( cipher_finish( operation, output, output_size, output_length ) ); + return cipher_finish( operation, output, output_size, output_length ) ; } psa_status_t mbedtls_transparent_test_driver_cipher_abort( mbedtls_psa_cipher_operation_t *operation ) { - return( cipher_abort( operation ) ); + return cipher_abort( operation ) ; } psa_status_t mbedtls_transparent_test_driver_cipher_encrypt( diff --git a/library/psa_crypto_client.c b/library/psa_crypto_client.c index 629feb7dfa..7dc36a83ab 100644 --- a/library/psa_crypto_client.c +++ b/library/psa_crypto_client.c @@ -47,7 +47,7 @@ psa_status_t psa_set_key_domain_parameters( psa_key_attributes_t *attributes, { copy = mbedtls_calloc( 1, data_length ); if( copy == NULL ) - return( PSA_ERROR_INSUFFICIENT_MEMORY ); + return PSA_ERROR_INSUFFICIENT_MEMORY ; memcpy( copy, data, data_length ); } /* After this point, this function is guaranteed to succeed, so it @@ -63,7 +63,7 @@ psa_status_t psa_set_key_domain_parameters( psa_key_attributes_t *attributes, attributes->domain_parameters = copy; attributes->domain_parameters_size = data_length; attributes->core.type = type; - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } psa_status_t psa_get_key_domain_parameters( @@ -71,12 +71,12 @@ psa_status_t psa_get_key_domain_parameters( uint8_t *data, size_t data_size, size_t *data_length ) { if( attributes->domain_parameters_size > data_size ) - return( PSA_ERROR_BUFFER_TOO_SMALL ); + return PSA_ERROR_BUFFER_TOO_SMALL ; *data_length = attributes->domain_parameters_size; if( attributes->domain_parameters_size != 0 ) memcpy( data, attributes->domain_parameters, attributes->domain_parameters_size ); - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } #endif /* MBEDTLS_PSA_CRYPTO_CLIENT */ diff --git a/library/psa_crypto_core.h b/library/psa_crypto_core.h index 91757b5fdb..32650228b7 100644 --- a/library/psa_crypto_core.h +++ b/library/psa_crypto_core.h @@ -43,7 +43,7 @@ static inline int mbedtls_psa_safer_memcmp( for( i = 0; i < n; i++ ) diff |= a[i] ^ b[i]; - return( diff ); + return diff ; } /** The data structure representing a key slot, containing key material @@ -103,7 +103,7 @@ typedef struct */ static inline int psa_is_key_slot_occupied( const psa_key_slot_t *slot ) { - return( slot->attr.type != 0 ); + return slot->attr.type != 0 ; } /** Test whether a key slot is locked. @@ -116,7 +116,7 @@ static inline int psa_is_key_slot_occupied( const psa_key_slot_t *slot ) */ static inline int psa_is_key_slot_locked( const psa_key_slot_t *slot ) { - return( slot->lock_count > 0 ); + return slot->lock_count > 0 ; } /** Retrieve flags from psa_key_slot_t::attr::core::flags. @@ -130,7 +130,7 @@ static inline int psa_is_key_slot_locked( const psa_key_slot_t *slot ) static inline uint16_t psa_key_slot_get_flags( const psa_key_slot_t *slot, uint16_t mask ) { - return( slot->attr.flags & mask ); + return slot->attr.flags & mask ; } /** Set flags in psa_key_slot_t::attr::core::flags. diff --git a/library/psa_crypto_driver_wrappers.c b/library/psa_crypto_driver_wrappers.c index 38d0e300e2..2d5095e598 100644 --- a/library/psa_crypto_driver_wrappers.c +++ b/library/psa_crypto_driver_wrappers.c @@ -102,7 +102,7 @@ psa_status_t psa_driver_wrapper_sign_message( signature_length ); /* Declared with fallback == true */ if( status != PSA_ERROR_NOT_SUPPORTED ) - return( status ); + return status ; #endif /* PSA_CRYPTO_DRIVER_TEST */ #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ break; @@ -122,7 +122,7 @@ psa_status_t psa_driver_wrapper_sign_message( signature_size, signature_length ); if( status != PSA_ERROR_NOT_SUPPORTED ) - return( status ); + return status ; break; #endif /* PSA_CRYPTO_DRIVER_TEST */ #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ @@ -175,7 +175,7 @@ psa_status_t psa_driver_wrapper_verify_message( signature_length ); /* Declared with fallback == true */ if( status != PSA_ERROR_NOT_SUPPORTED ) - return( status ); + return status ; #endif /* PSA_CRYPTO_DRIVER_TEST */ #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ break; @@ -194,7 +194,7 @@ psa_status_t psa_driver_wrapper_verify_message( signature, signature_length ) ); if( status != PSA_ERROR_NOT_SUPPORTED ) - return( status ); + return status ; break; #endif /* PSA_CRYPTO_DRIVER_TEST */ #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ @@ -231,7 +231,7 @@ psa_status_t psa_driver_wrapper_sign_hash( drv->asymmetric->p_sign == NULL ) { /* Key is defined in SE, but we have no way to exercise it */ - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; } return( drv->asymmetric->p_sign( drv_context, *( (psa_key_slot_number_t *)key_buffer ), @@ -262,7 +262,7 @@ psa_status_t psa_driver_wrapper_sign_hash( signature_length ); /* Declared with fallback == true */ if( status != PSA_ERROR_NOT_SUPPORTED ) - return( status ); + return status ; #endif /* PSA_CRYPTO_DRIVER_TEST */ #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ /* Fell through, meaning no accelerator supports this operation */ @@ -294,7 +294,7 @@ psa_status_t psa_driver_wrapper_sign_hash( default: /* Key is declared with a lifetime not known to us */ (void)status; - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; } } @@ -315,7 +315,7 @@ psa_status_t psa_driver_wrapper_verify_hash( drv->asymmetric->p_verify == NULL ) { /* Key is defined in SE, but we have no way to exercise it */ - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; } return( drv->asymmetric->p_verify( drv_context, *( (psa_key_slot_number_t *)key_buffer ), @@ -346,7 +346,7 @@ psa_status_t psa_driver_wrapper_verify_hash( signature_length ); /* Declared with fallback == true */ if( status != PSA_ERROR_NOT_SUPPORTED ) - return( status ); + return status ; #endif /* PSA_CRYPTO_DRIVER_TEST */ #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ @@ -376,7 +376,7 @@ psa_status_t psa_driver_wrapper_verify_hash( default: /* Key is declared with a lifetime not known to us */ (void)status; - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; } } @@ -415,7 +415,7 @@ psa_status_t psa_driver_wrapper_get_key_buffer_size( psa_get_key_id( attributes ) ) ) ) { *key_buffer_size = sizeof( psa_drv_slot_number_t ); - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } #endif /* MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS */ *key_buffer_size = mbedtls_test_size_function( key_type, key_bits ); @@ -426,7 +426,7 @@ psa_status_t psa_driver_wrapper_get_key_buffer_size( default: (void)key_type; (void)key_bits; - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; } } @@ -450,7 +450,7 @@ psa_status_t psa_driver_wrapper_generate_key( drv->key_management->p_generate == NULL ) { /* Key is defined as being in SE, but we have no way to generate it */ - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; } return( drv->key_management->p_generate( drv_context, @@ -499,7 +499,7 @@ psa_status_t psa_driver_wrapper_generate_key( break; } - return( status ); + return status ; } psa_status_t psa_driver_wrapper_import_key( @@ -524,7 +524,7 @@ psa_status_t psa_driver_wrapper_import_key( { if( drv->key_management == NULL || drv->key_management->p_import == NULL ) - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; /* The driver should set the number of key bits, however in * case it doesn't, we initialize bits to an invalid value. */ @@ -535,12 +535,12 @@ psa_status_t psa_driver_wrapper_import_key( attributes, data, data_length, bits ); if( status != PSA_SUCCESS ) - return( status ); + return status ; if( (*bits) > PSA_MAX_KEY_BITS ) - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } #endif /* PSA_CRYPTO_SE_C */ @@ -558,7 +558,7 @@ psa_status_t psa_driver_wrapper_import_key( key_buffer_length, bits ); /* Declared with fallback == true */ if( status != PSA_ERROR_NOT_SUPPORTED ) - return( status ); + return status ; #endif /* PSA_CRYPTO_DRIVER_TEST */ #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ /* Fell through, meaning no accelerator supports this operation */ @@ -571,7 +571,7 @@ psa_status_t psa_driver_wrapper_import_key( /* Importing a key with external storage in not yet supported. * Return in error indicating that the lifetime is not valid. */ (void)status; - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; } } @@ -596,7 +596,7 @@ psa_status_t psa_driver_wrapper_export_key( if( ( drv->key_management == NULL ) || ( drv->key_management->p_export == NULL ) ) { - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; } return( drv->key_management->p_export( @@ -630,7 +630,7 @@ psa_status_t psa_driver_wrapper_export_key( #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ default: /* Key is declared with a lifetime not known to us */ - return( status ); + return status ; } } @@ -654,7 +654,7 @@ psa_status_t psa_driver_wrapper_export_public_key( if( ( drv->key_management == NULL ) || ( drv->key_management->p_export_public == NULL ) ) { - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; } return( drv->key_management->p_export_public( @@ -680,7 +680,7 @@ psa_status_t psa_driver_wrapper_export_public_key( data_length ); /* Declared with fallback == true */ if( status != PSA_ERROR_NOT_SUPPORTED ) - return( status ); + return status ; #endif /* PSA_CRYPTO_DRIVER_TEST */ #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ /* Fell through, meaning no accelerator supports this operation */ @@ -705,7 +705,7 @@ psa_status_t psa_driver_wrapper_export_public_key( #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ default: /* Key is declared with a lifetime not known to us */ - return( status ); + return status ; } } @@ -729,7 +729,7 @@ psa_status_t psa_driver_wrapper_get_builtin_key( (void) key_buffer; (void) key_buffer_size; (void) key_buffer_length; - return( PSA_ERROR_DOES_NOT_EXIST ); + return PSA_ERROR_DOES_NOT_EXIST ; } } @@ -769,7 +769,7 @@ psa_status_t psa_driver_wrapper_cipher_encrypt( output_length ); /* Declared with fallback == true */ if( status != PSA_ERROR_NOT_SUPPORTED ) - return( status ); + return status ; #endif /* PSA_CRYPTO_DRIVER_TEST */ #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ @@ -784,7 +784,7 @@ psa_status_t psa_driver_wrapper_cipher_encrypt( output_size, output_length ) ); #else - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; #endif /* MBEDTLS_PSA_BUILTIN_CIPHER */ /* Add cases for opaque driver here */ @@ -814,7 +814,7 @@ psa_status_t psa_driver_wrapper_cipher_encrypt( (void)output; (void)output_size; (void)output_length; - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; } } @@ -851,7 +851,7 @@ psa_status_t psa_driver_wrapper_cipher_decrypt( output_length ); /* Declared with fallback == true */ if( status != PSA_ERROR_NOT_SUPPORTED ) - return( status ); + return status ; #endif /* PSA_CRYPTO_DRIVER_TEST */ #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ @@ -866,7 +866,7 @@ psa_status_t psa_driver_wrapper_cipher_decrypt( output_size, output_length ) ); #else - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; #endif /* MBEDTLS_PSA_BUILTIN_CIPHER */ /* Add cases for opaque driver here */ @@ -896,7 +896,7 @@ psa_status_t psa_driver_wrapper_cipher_decrypt( (void)output; (void)output_size; (void)output_length; - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; } } @@ -928,7 +928,7 @@ psa_status_t psa_driver_wrapper_cipher_encrypt_setup( operation->id = PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID; if( status != PSA_ERROR_NOT_SUPPORTED ) - return( status ); + return status ; #endif /* PSA_CRYPTO_DRIVER_TEST */ #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ #if defined(MBEDTLS_PSA_BUILTIN_CIPHER) @@ -942,9 +942,9 @@ psa_status_t psa_driver_wrapper_cipher_encrypt_setup( operation->id = PSA_CRYPTO_MBED_TLS_DRIVER_ID; if( status != PSA_ERROR_NOT_SUPPORTED ) - return( status ); + return status ; #endif /* MBEDTLS_PSA_BUILTIN_CIPHER */ - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; /* Add cases for opaque driver here */ #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) @@ -959,7 +959,7 @@ psa_status_t psa_driver_wrapper_cipher_encrypt_setup( if( status == PSA_SUCCESS ) operation->id = PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID; - return( status ); + return status ; #endif /* PSA_CRYPTO_DRIVER_TEST */ #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ default: @@ -968,7 +968,7 @@ psa_status_t psa_driver_wrapper_cipher_encrypt_setup( (void)key_buffer; (void)key_buffer_size; (void)alg; - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; } } @@ -1000,7 +1000,7 @@ psa_status_t psa_driver_wrapper_cipher_decrypt_setup( operation->id = PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID; if( status != PSA_ERROR_NOT_SUPPORTED ) - return( status ); + return status ; #endif /* PSA_CRYPTO_DRIVER_TEST */ #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ #if defined(MBEDTLS_PSA_BUILTIN_CIPHER) @@ -1013,9 +1013,9 @@ psa_status_t psa_driver_wrapper_cipher_decrypt_setup( if( status == PSA_SUCCESS ) operation->id = PSA_CRYPTO_MBED_TLS_DRIVER_ID; - return( status ); + return status ; #endif /* MBEDTLS_PSA_BUILTIN_CIPHER */ - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; /* Add cases for opaque driver here */ #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) @@ -1030,7 +1030,7 @@ psa_status_t psa_driver_wrapper_cipher_decrypt_setup( if( status == PSA_SUCCESS ) operation->id = PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID; - return( status ); + return status ; #endif /* PSA_CRYPTO_DRIVER_TEST */ #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ default: @@ -1039,7 +1039,7 @@ psa_status_t psa_driver_wrapper_cipher_decrypt_setup( (void)key_buffer; (void)key_buffer_size; (void)alg; - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; } } @@ -1075,7 +1075,7 @@ psa_status_t psa_driver_wrapper_cipher_set_iv( (void)iv; (void)iv_length; - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; } psa_status_t psa_driver_wrapper_cipher_update( @@ -1121,7 +1121,7 @@ psa_status_t psa_driver_wrapper_cipher_update( (void)output_size; (void)output_length; - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; } psa_status_t psa_driver_wrapper_cipher_finish( @@ -1159,7 +1159,7 @@ psa_status_t psa_driver_wrapper_cipher_finish( (void)output_size; (void)output_length; - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; } psa_status_t psa_driver_wrapper_cipher_abort( @@ -1171,7 +1171,7 @@ psa_status_t psa_driver_wrapper_cipher_abort( { #if defined(MBEDTLS_PSA_BUILTIN_CIPHER) case PSA_CRYPTO_MBED_TLS_DRIVER_ID: - return( mbedtls_psa_cipher_abort( &operation->ctx.mbedtls_ctx ) ); + return mbedtls_psa_cipher_abort( &operation->ctx.mbedtls_ctx ) ; #endif /* MBEDTLS_PSA_BUILTIN_CIPHER */ #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) @@ -1182,7 +1182,7 @@ psa_status_t psa_driver_wrapper_cipher_abort( mbedtls_platform_zeroize( &operation->ctx.transparent_test_driver_ctx, sizeof( operation->ctx.transparent_test_driver_ctx ) ); - return( status ); + return status ; case PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID: status = mbedtls_test_opaque_cipher_abort( @@ -1190,13 +1190,13 @@ psa_status_t psa_driver_wrapper_cipher_abort( mbedtls_platform_zeroize( &operation->ctx.opaque_test_driver_ctx, sizeof( operation->ctx.opaque_test_driver_ctx ) ); - return( status ); + return status ; #endif /* PSA_CRYPTO_DRIVER_TEST */ #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ } (void)status; - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; } /* @@ -1217,7 +1217,7 @@ psa_status_t psa_driver_wrapper_hash_compute( status = mbedtls_test_transparent_hash_compute( alg, input, input_length, hash, hash_size, hash_length ); if( status != PSA_ERROR_NOT_SUPPORTED ) - return( status ); + return status ; #endif /* If software fallback is compiled in, try fallback */ @@ -1225,7 +1225,7 @@ psa_status_t psa_driver_wrapper_hash_compute( status = mbedtls_psa_hash_compute( alg, input, input_length, hash, hash_size, hash_length ); if( status != PSA_ERROR_NOT_SUPPORTED ) - return( status ); + return status ; #endif (void) status; (void) alg; @@ -1235,7 +1235,7 @@ psa_status_t psa_driver_wrapper_hash_compute( (void) hash_size; (void) hash_length; - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; } psa_status_t psa_driver_wrapper_hash_setup( @@ -1252,7 +1252,7 @@ psa_status_t psa_driver_wrapper_hash_setup( operation->id = PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID; if( status != PSA_ERROR_NOT_SUPPORTED ) - return( status ); + return status ; #endif /* If software fallback is compiled in, try fallback */ @@ -1262,13 +1262,13 @@ psa_status_t psa_driver_wrapper_hash_setup( operation->id = PSA_CRYPTO_MBED_TLS_DRIVER_ID; if( status != PSA_ERROR_NOT_SUPPORTED ) - return( status ); + return status ; #endif /* Nothing left to try if we fall through here */ (void) status; (void) operation; (void) alg; - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; } psa_status_t psa_driver_wrapper_hash_clone( @@ -1292,7 +1292,7 @@ psa_status_t psa_driver_wrapper_hash_clone( #endif default: (void) target_operation; - return( PSA_ERROR_BAD_STATE ); + return PSA_ERROR_BAD_STATE ; } } @@ -1317,7 +1317,7 @@ psa_status_t psa_driver_wrapper_hash_update( default: (void) input; (void) input_length; - return( PSA_ERROR_BAD_STATE ); + return PSA_ERROR_BAD_STATE ; } } @@ -1344,7 +1344,7 @@ psa_status_t psa_driver_wrapper_hash_finish( (void) hash; (void) hash_size; (void) hash_length; - return( PSA_ERROR_BAD_STATE ); + return PSA_ERROR_BAD_STATE ; } } @@ -1355,7 +1355,7 @@ psa_status_t psa_driver_wrapper_hash_abort( { #if defined(MBEDTLS_PSA_BUILTIN_HASH) case PSA_CRYPTO_MBED_TLS_DRIVER_ID: - return( mbedtls_psa_hash_abort( &operation->ctx.mbedtls_ctx ) ); + return mbedtls_psa_hash_abort( &operation->ctx.mbedtls_ctx ) ; #endif #if defined(PSA_CRYPTO_DRIVER_TEST) case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: @@ -1363,7 +1363,7 @@ psa_status_t psa_driver_wrapper_hash_abort( &operation->ctx.test_driver_ctx ) ); #endif default: - return( PSA_ERROR_BAD_STATE ); + return PSA_ERROR_BAD_STATE ; } } @@ -1397,7 +1397,7 @@ psa_status_t psa_driver_wrapper_aead_encrypt( ciphertext, ciphertext_size, ciphertext_length ); /* Declared with fallback == true */ if( status != PSA_ERROR_NOT_SUPPORTED ) - return( status ); + return status ; #endif /* PSA_CRYPTO_DRIVER_TEST */ #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ @@ -1415,7 +1415,7 @@ psa_status_t psa_driver_wrapper_aead_encrypt( default: /* Key is declared with a lifetime not known to us */ (void)status; - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; } } @@ -1449,7 +1449,7 @@ psa_status_t psa_driver_wrapper_aead_decrypt( plaintext, plaintext_size, plaintext_length ); /* Declared with fallback == true */ if( status != PSA_ERROR_NOT_SUPPORTED ) - return( status ); + return status ; #endif /* PSA_CRYPTO_DRIVER_TEST */ #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ @@ -1467,7 +1467,7 @@ psa_status_t psa_driver_wrapper_aead_decrypt( default: /* Key is declared with a lifetime not known to us */ (void)status; - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; } } @@ -1503,7 +1503,7 @@ psa_status_t psa_driver_wrapper_mac_compute( mac, mac_size, mac_length ); /* Declared with fallback == true */ if( status != PSA_ERROR_NOT_SUPPORTED ) - return( status ); + return status ; #endif /* PSA_CRYPTO_DRIVER_TEST */ #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ #if defined(MBEDTLS_PSA_BUILTIN_MAC) @@ -1513,9 +1513,9 @@ psa_status_t psa_driver_wrapper_mac_compute( input, input_length, mac, mac_size, mac_length ); if( status != PSA_ERROR_NOT_SUPPORTED ) - return( status ); + return status ; #endif /* MBEDTLS_PSA_BUILTIN_MAC */ - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; /* Add cases for opaque driver here */ #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) @@ -1525,7 +1525,7 @@ psa_status_t psa_driver_wrapper_mac_compute( attributes, key_buffer, key_buffer_size, alg, input, input_length, mac, mac_size, mac_length ); - return( status ); + return status ; #endif /* PSA_CRYPTO_DRIVER_TEST */ #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ default: @@ -1539,7 +1539,7 @@ psa_status_t psa_driver_wrapper_mac_compute( (void) mac_size; (void) mac_length; (void) status; - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; } } @@ -1571,7 +1571,7 @@ psa_status_t psa_driver_wrapper_mac_sign_setup( operation->id = PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID; if( status != PSA_ERROR_NOT_SUPPORTED ) - return( status ); + return status ; #endif /* PSA_CRYPTO_DRIVER_TEST */ #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ #if defined(MBEDTLS_PSA_BUILTIN_MAC) @@ -1584,9 +1584,9 @@ psa_status_t psa_driver_wrapper_mac_sign_setup( operation->id = PSA_CRYPTO_MBED_TLS_DRIVER_ID; if( status != PSA_ERROR_NOT_SUPPORTED ) - return( status ); + return status ; #endif /* MBEDTLS_PSA_BUILTIN_MAC */ - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; /* Add cases for opaque driver here */ #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) @@ -1601,7 +1601,7 @@ psa_status_t psa_driver_wrapper_mac_sign_setup( if( status == PSA_SUCCESS ) operation->id = PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID; - return( status ); + return status ; #endif /* PSA_CRYPTO_DRIVER_TEST */ #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ default: @@ -1610,7 +1610,7 @@ psa_status_t psa_driver_wrapper_mac_sign_setup( (void) key_buffer; (void) key_buffer_size; (void) alg; - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; } } @@ -1642,7 +1642,7 @@ psa_status_t psa_driver_wrapper_mac_verify_setup( operation->id = PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID; if( status != PSA_ERROR_NOT_SUPPORTED ) - return( status ); + return status ; #endif /* PSA_CRYPTO_DRIVER_TEST */ #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ #if defined(MBEDTLS_PSA_BUILTIN_MAC) @@ -1655,9 +1655,9 @@ psa_status_t psa_driver_wrapper_mac_verify_setup( operation->id = PSA_CRYPTO_MBED_TLS_DRIVER_ID; if( status != PSA_ERROR_NOT_SUPPORTED ) - return( status ); + return status ; #endif /* MBEDTLS_PSA_BUILTIN_MAC */ - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; /* Add cases for opaque driver here */ #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) @@ -1672,7 +1672,7 @@ psa_status_t psa_driver_wrapper_mac_verify_setup( if( status == PSA_SUCCESS ) operation->id = PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID; - return( status ); + return status ; #endif /* PSA_CRYPTO_DRIVER_TEST */ #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ default: @@ -1681,7 +1681,7 @@ psa_status_t psa_driver_wrapper_mac_verify_setup( (void) key_buffer; (void) key_buffer_size; (void) alg; - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; } } @@ -1714,7 +1714,7 @@ psa_status_t psa_driver_wrapper_mac_update( default: (void) input; (void) input_length; - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; } } @@ -1749,7 +1749,7 @@ psa_status_t psa_driver_wrapper_mac_sign_finish( (void) mac; (void) mac_size; (void) mac_length; - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; } } @@ -1782,7 +1782,7 @@ psa_status_t psa_driver_wrapper_mac_verify_finish( default: (void) mac; (void) mac_length; - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; } } @@ -1793,7 +1793,7 @@ psa_status_t psa_driver_wrapper_mac_abort( { #if defined(MBEDTLS_PSA_BUILTIN_MAC) case PSA_CRYPTO_MBED_TLS_DRIVER_ID: - return( mbedtls_psa_mac_abort( &operation->ctx.mbedtls_ctx ) ); + return mbedtls_psa_mac_abort( &operation->ctx.mbedtls_ctx ) ; #endif /* MBEDTLS_PSA_BUILTIN_MAC */ #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) @@ -1807,7 +1807,7 @@ psa_status_t psa_driver_wrapper_mac_abort( #endif /* PSA_CRYPTO_DRIVER_TEST */ #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ default: - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; } } diff --git a/library/psa_crypto_ecp.c b/library/psa_crypto_ecp.c index 3ce232c6b2..f50898b59d 100644 --- a/library/psa_crypto_ecp.c +++ b/library/psa_crypto_ecp.c @@ -92,7 +92,7 @@ psa_status_t mbedtls_psa_ecp_load_representation( * So its data length is 2m+1 where m is the curve size in bits. */ if( ( data_length & 1 ) == 0 ) - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; curve_bytes = data_length / 2; /* Montgomery public keys are represented in compressed format, meaning @@ -106,7 +106,7 @@ psa_status_t mbedtls_psa_ecp_load_representation( { /* With an explicit bit-size, the data must have the matching length. */ if( curve_bytes != PSA_BITS_TO_BYTES( curve_bits ) ) - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; } else { @@ -119,7 +119,7 @@ psa_status_t mbedtls_psa_ecp_load_representation( /* Allocate and initialize a key representation. */ ecp = mbedtls_calloc( 1, sizeof( mbedtls_ecp_keypair ) ); if( ecp == NULL ) - return( PSA_ERROR_INSUFFICIENT_MEMORY ); + return PSA_ERROR_INSUFFICIENT_MEMORY ; mbedtls_ecp_keypair_init( ecp ); /* Load the group. */ @@ -179,7 +179,7 @@ exit: mbedtls_free( ecp ); } - return( status ); + return status ; } #endif /* defined(BUILTIN_KEY_TYPE_ECC_KEY_PAIR) || * defined(BUILTIN_KEY_TYPE_ECC_PUBLIC_KEY) || @@ -227,7 +227,7 @@ exit: mbedtls_ecp_keypair_free( ecp ); mbedtls_free( ecp ); - return( status ); + return status ; } psa_status_t mbedtls_psa_ecp_export_key( psa_key_type_t type, @@ -249,7 +249,7 @@ psa_status_t mbedtls_psa_ecp_export_key( psa_key_type_t type, mbedtls_psa_get_random, MBEDTLS_PSA_RANDOM_STATE ) ); if( status != PSA_SUCCESS ) - return( status ); + return status ; } status = mbedtls_to_psa_error( @@ -261,12 +261,12 @@ psa_status_t mbedtls_psa_ecp_export_key( psa_key_type_t type, if( status != PSA_SUCCESS ) memset( data, 0, data_size ); - return( status ); + return status ; } else { if( data_size < PSA_BITS_TO_BYTES( ecp->grp.nbits ) ) - return( PSA_ERROR_BUFFER_TOO_SMALL ); + return PSA_ERROR_BUFFER_TOO_SMALL ; status = mbedtls_to_psa_error( mbedtls_ecp_write_key( ecp, @@ -277,7 +277,7 @@ psa_status_t mbedtls_psa_ecp_export_key( psa_key_type_t type, else memset( data, 0, data_size ); - return( status ); + return status ; } } @@ -293,7 +293,7 @@ static psa_status_t ecp_export_public_key( attributes->core.type, attributes->core.bits, key_buffer, key_buffer_size, &ecp ); if( status != PSA_SUCCESS ) - return( status ); + return status ; status = mbedtls_psa_ecp_export_key( PSA_KEY_TYPE_ECC_PUBLIC_KEY( @@ -303,7 +303,7 @@ static psa_status_t ecp_export_public_key( mbedtls_ecp_keypair_free( ecp ); mbedtls_free( ecp ); - return( status ); + return status ; } #endif /* defined(BUILTIN_KEY_TYPE_ECC_KEY_PAIR) || * defined(BUILTIN_KEY_TYPE_ECC_PUBLIC_KEY) */ @@ -326,10 +326,10 @@ static psa_status_t ecp_generate_key( mbedtls_ecp_keypair ecp; if( attributes->domain_parameters_size != 0 ) - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; if( grp_id == MBEDTLS_ECP_DP_NONE || curve_info == NULL ) - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; mbedtls_ecp_keypair_init( &ecp ); ret = mbedtls_ecp_gen_key( grp_id, &ecp, @@ -338,7 +338,7 @@ static psa_status_t ecp_generate_key( if( ret != 0 ) { mbedtls_ecp_keypair_free( &ecp ); - return( mbedtls_to_psa_error( ret ) ); + return mbedtls_to_psa_error( ret ) ; } status = mbedtls_to_psa_error( @@ -349,7 +349,7 @@ static psa_status_t ecp_generate_key( if( status == PSA_SUCCESS ) *key_buffer_length = key_buffer_size; - return( status ); + return status ; } #endif /* defined(BUILTIN_KEY_TYPE_ECC_KEY_PAIR) */ @@ -377,7 +377,7 @@ static psa_status_t ecdsa_sign_hash( key_buffer_size, &ecp ); if( status != PSA_SUCCESS ) - return( status ); + return status ; curve_bytes = PSA_BITS_TO_BYTES( ecp->grp.pbits ); mbedtls_mpi_init( &r ); @@ -430,7 +430,7 @@ cleanup: mbedtls_ecp_keypair_free( ecp ); mbedtls_free( ecp ); - return( mbedtls_to_psa_error( ret ) ); + return mbedtls_to_psa_error( ret ) ; } static psa_status_t ecdsa_verify_hash( @@ -453,7 +453,7 @@ static psa_status_t ecdsa_verify_hash( key_buffer_size, &ecp ); if( status != PSA_SUCCESS ) - return( status ); + return status ; curve_bytes = PSA_BITS_TO_BYTES( ecp->grp.pbits ); mbedtls_mpi_init( &r ); @@ -489,7 +489,7 @@ cleanup: mbedtls_ecp_keypair_free( ecp ); mbedtls_free( ecp ); - return( mbedtls_to_psa_error( ret ) ); + return mbedtls_to_psa_error( ret ) ; } #endif /* defined(BUILTIN_ALG_ECDSA) || \ @@ -632,7 +632,7 @@ psa_status_t mbedtls_transparent_test_driver_ecdsa_sign_hash( (void)signature; (void)signature_size; (void)signature_length; - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; #endif } @@ -656,7 +656,7 @@ psa_status_t mbedtls_transparent_test_driver_ecdsa_verify_hash( (void)hash_length; (void)signature; (void)signature_length; - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; #endif } diff --git a/library/psa_crypto_hash.c b/library/psa_crypto_hash.c index 92dcbba96b..0093428bce 100644 --- a/library/psa_crypto_hash.c +++ b/library/psa_crypto_hash.c @@ -70,34 +70,34 @@ const mbedtls_md_info_t *mbedtls_md_info_from_psa( psa_algorithm_t alg ) { #if defined(MBEDTLS_MD5_C) case PSA_ALG_MD5: - return( &mbedtls_md5_info ); + return &mbedtls_md5_info ; #endif #if defined(MBEDTLS_RIPEMD160_C) case PSA_ALG_RIPEMD160: - return( &mbedtls_ripemd160_info ); + return &mbedtls_ripemd160_info ; #endif #if defined(MBEDTLS_SHA1_C) case PSA_ALG_SHA_1: - return( &mbedtls_sha1_info ); + return &mbedtls_sha1_info ; #endif #if defined(MBEDTLS_SHA224_C) case PSA_ALG_SHA_224: - return( &mbedtls_sha224_info ); + return &mbedtls_sha224_info ; #endif #if defined(MBEDTLS_SHA256_C) case PSA_ALG_SHA_256: - return( &mbedtls_sha256_info ); + return &mbedtls_sha256_info ; #endif #if defined(MBEDTLS_SHA384_C) case PSA_ALG_SHA_384: - return( &mbedtls_sha384_info ); + return &mbedtls_sha384_info ; #endif #if defined(MBEDTLS_SHA512_C) case PSA_ALG_SHA_512: - return( &mbedtls_sha512_info ); + return &mbedtls_sha512_info ; #endif default: - return( NULL ); + return NULL ; } } #endif /* defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_SIGN) || @@ -154,10 +154,10 @@ static psa_status_t hash_abort( break; #endif default: - return( PSA_ERROR_BAD_STATE ); + return PSA_ERROR_BAD_STATE ; } operation->alg = 0; - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } static psa_status_t hash_setup( @@ -169,7 +169,7 @@ static psa_status_t hash_setup( /* A context must be freshly initialized before it can be set up. */ if( operation->alg != 0 ) { - return( PSA_ERROR_BAD_STATE ); + return PSA_ERROR_BAD_STATE ; } switch( alg ) @@ -225,7 +225,7 @@ static psa_status_t hash_setup( operation->alg = alg; else hash_abort( operation ); - return( mbedtls_to_psa_error( ret ) ); + return mbedtls_to_psa_error( ret ) ; } static psa_status_t hash_clone( @@ -235,7 +235,7 @@ static psa_status_t hash_clone( switch( source_operation->alg ) { case 0: - return( PSA_ERROR_BAD_STATE ); + return PSA_ERROR_BAD_STATE ; #if defined(BUILTIN_ALG_MD5) case PSA_ALG_MD5: mbedtls_md5_clone( &target_operation->ctx.md5, @@ -281,11 +281,11 @@ static psa_status_t hash_clone( default: (void) source_operation; (void) target_operation; - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; } target_operation->alg = source_operation->alg; - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } static psa_status_t hash_update( @@ -342,10 +342,10 @@ static psa_status_t hash_update( default: (void) input; (void) input_length; - return( PSA_ERROR_BAD_STATE ); + return PSA_ERROR_BAD_STATE ; } - return( mbedtls_to_psa_error( ret ) ); + return mbedtls_to_psa_error( ret ) ; } static psa_status_t hash_finish( @@ -412,14 +412,14 @@ static psa_status_t hash_finish( #endif default: (void) hash; - return( PSA_ERROR_BAD_STATE ); + return PSA_ERROR_BAD_STATE ; } status = mbedtls_to_psa_error( ret ); exit: if( status == PSA_SUCCESS ) *hash_length = actual_hash_length; - return( status ); + return status ; } static psa_status_t hash_compute( @@ -448,9 +448,9 @@ static psa_status_t hash_compute( exit: abort_status = hash_abort( &operation ); if( status == PSA_SUCCESS ) - return( abort_status ); + return abort_status ; else - return( status ); + return status ; } #endif /* MBEDTLS_PSA_BUILTIN_HASH || PSA_CRYPTO_DRIVER_TEST */ @@ -472,14 +472,14 @@ psa_status_t mbedtls_psa_hash_setup( mbedtls_psa_hash_operation_t *operation, psa_algorithm_t alg ) { - return( hash_setup( operation, alg ) ); + return hash_setup( operation, alg ) ; } psa_status_t mbedtls_psa_hash_clone( const mbedtls_psa_hash_operation_t *source_operation, mbedtls_psa_hash_operation_t *target_operation ) { - return( hash_clone( source_operation, target_operation ) ); + return hash_clone( source_operation, target_operation ) ; } psa_status_t mbedtls_psa_hash_update( @@ -487,7 +487,7 @@ psa_status_t mbedtls_psa_hash_update( const uint8_t *input, size_t input_length ) { - return( hash_update( operation, input, input_length ) ); + return hash_update( operation, input, input_length ) ; } psa_status_t mbedtls_psa_hash_finish( @@ -496,13 +496,13 @@ psa_status_t mbedtls_psa_hash_finish( size_t hash_size, size_t *hash_length ) { - return( hash_finish( operation, hash, hash_size, hash_length ) ); + return hash_finish( operation, hash, hash_size, hash_length ) ; } psa_status_t mbedtls_psa_hash_abort( mbedtls_psa_hash_operation_t *operation ) { - return( hash_abort( operation ) ); + return hash_abort( operation ) ; } #endif /* MBEDTLS_PSA_BUILTIN_HASH */ @@ -517,34 +517,34 @@ static int is_hash_accelerated( psa_algorithm_t alg ) { #if defined(MBEDTLS_PSA_ACCEL_ALG_MD5) case PSA_ALG_MD5: - return( 1 ); + return 1 ; #endif #if defined(MBEDTLS_PSA_ACCEL_ALG_RIPEMD160) case PSA_ALG_RIPEMD160: - return( 1 ); + return 1 ; #endif #if defined(MBEDTLS_PSA_ACCEL_ALG_SHA_1) case PSA_ALG_SHA_1: - return( 1 ); + return 1 ; #endif #if defined(MBEDTLS_PSA_ACCEL_ALG_SHA_224) case PSA_ALG_SHA_224: - return( 1 ); + return 1 ; #endif #if defined(MBEDTLS_PSA_ACCEL_ALG_SHA_256) case PSA_ALG_SHA_256: - return( 1 ); + return 1 ; #endif #if defined(MBEDTLS_PSA_ACCEL_ALG_SHA_384) case PSA_ALG_SHA_384: - return( 1 ); + return 1 ; #endif #if defined(MBEDTLS_PSA_ACCEL_ALG_SHA_512) case PSA_ALG_SHA_512: - return( 1 ); + return 1 ; #endif default: - return( 0 ); + return 0 ; } } @@ -560,7 +560,7 @@ psa_status_t mbedtls_transparent_test_driver_hash_compute( return( hash_compute( alg, input, input_length, hash, hash_size, hash_length ) ); else - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; } psa_status_t mbedtls_transparent_test_driver_hash_setup( @@ -568,9 +568,9 @@ psa_status_t mbedtls_transparent_test_driver_hash_setup( psa_algorithm_t alg ) { if( is_hash_accelerated( alg ) ) - return( hash_setup( operation, alg ) ); + return hash_setup( operation, alg ) ; else - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; } psa_status_t mbedtls_transparent_test_driver_hash_clone( @@ -578,9 +578,9 @@ psa_status_t mbedtls_transparent_test_driver_hash_clone( mbedtls_transparent_test_driver_hash_operation_t *target_operation ) { if( is_hash_accelerated( source_operation->alg ) ) - return( hash_clone( source_operation, target_operation ) ); + return hash_clone( source_operation, target_operation ) ; else - return( PSA_ERROR_BAD_STATE ); + return PSA_ERROR_BAD_STATE ; } psa_status_t mbedtls_transparent_test_driver_hash_update( @@ -589,9 +589,9 @@ psa_status_t mbedtls_transparent_test_driver_hash_update( size_t input_length ) { if( is_hash_accelerated( operation->alg ) ) - return( hash_update( operation, input, input_length ) ); + return hash_update( operation, input, input_length ) ; else - return( PSA_ERROR_BAD_STATE ); + return PSA_ERROR_BAD_STATE ; } psa_status_t mbedtls_transparent_test_driver_hash_finish( @@ -601,15 +601,15 @@ psa_status_t mbedtls_transparent_test_driver_hash_finish( size_t *hash_length ) { if( is_hash_accelerated( operation->alg ) ) - return( hash_finish( operation, hash, hash_size, hash_length ) ); + return hash_finish( operation, hash, hash_size, hash_length ) ; else - return( PSA_ERROR_BAD_STATE ); + return PSA_ERROR_BAD_STATE ; } psa_status_t mbedtls_transparent_test_driver_hash_abort( mbedtls_transparent_test_driver_hash_operation_t *operation ) { - return( hash_abort( operation ) ); + return hash_abort( operation ) ; } #endif /* PSA_CRYPTO_DRIVER_TEST */ diff --git a/library/psa_crypto_mac.c b/library/psa_crypto_mac.c index 2c079d434f..0f87a8d3e0 100644 --- a/library/psa_crypto_mac.c +++ b/library/psa_crypto_mac.c @@ -47,21 +47,21 @@ static size_t psa_get_hash_block_size( psa_algorithm_t alg ) switch( alg ) { case PSA_ALG_MD5: - return( 64 ); + return 64 ; case PSA_ALG_RIPEMD160: - return( 64 ); + return 64 ; case PSA_ALG_SHA_1: - return( 64 ); + return 64 ; case PSA_ALG_SHA_224: - return( 64 ); + return 64 ; case PSA_ALG_SHA_256: - return( 64 ); + return 64 ; case PSA_ALG_SHA_384: - return( 128 ); + return 128 ; case PSA_ALG_SHA_512: - return( 128 ); + return 128 ; default: - return( 0 ); + return 0 ; } } @@ -69,7 +69,7 @@ static psa_status_t psa_hmac_abort_internal( mbedtls_psa_hmac_operation_t *hmac ) { mbedtls_platform_zeroize( hmac->opad, sizeof( hmac->opad ) ); - return( psa_hash_abort( &hmac->hash_ctx ) ); + return psa_hash_abort( &hmac->hash_ctx ) ; } static psa_status_t psa_hmac_setup_internal( @@ -93,11 +93,11 @@ static psa_status_t psa_hmac_setup_internal( * `block_size > sizeof( ipad ) || block_size > sizeof( hmac->opad )` * because that triggers -Wlogical-op on GCC 7.3. */ if( block_size > sizeof( ipad ) ) - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; if( block_size > sizeof( hmac->opad ) ) - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; if( block_size < hash_size ) - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; if( key_length > block_size ) { @@ -134,7 +134,7 @@ static psa_status_t psa_hmac_setup_internal( cleanup: mbedtls_platform_zeroize( ipad, sizeof( ipad ) ); - return( status ); + return status ; } static psa_status_t psa_hmac_update_internal( @@ -142,7 +142,7 @@ static psa_status_t psa_hmac_update_internal( const uint8_t *data, size_t data_length ) { - return( psa_hash_update( &hmac->hash_ctx, data, data_length ) ); + return psa_hash_update( &hmac->hash_ctx, data, data_length ) ; } static psa_status_t psa_hmac_finish_internal( @@ -158,7 +158,7 @@ static psa_status_t psa_hmac_finish_internal( status = psa_hash_finish( &hmac->hash_ctx, tmp, sizeof( tmp ), &hash_size ); if( status != PSA_SUCCESS ) - return( status ); + return status ; /* From here on, tmp needs to be wiped. */ status = psa_hash_setup( &hmac->hash_ctx, hash_alg ); @@ -181,7 +181,7 @@ static psa_status_t psa_hmac_finish_internal( exit: mbedtls_platform_zeroize( tmp, hash_size ); - return( status ); + return status ; } #endif /* BUILTIN_ALG_HMAC */ @@ -198,7 +198,7 @@ static psa_status_t cmac_setup( mbedtls_psa_mac_operation_t *operation, if( psa_get_key_type( attributes ) == PSA_KEY_TYPE_DES && ( psa_get_key_bits( attributes ) == 64 || psa_get_key_bits( attributes ) == 128 ) ) - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; #endif const mbedtls_cipher_info_t * cipher_info = @@ -209,7 +209,7 @@ static psa_status_t cmac_setup( mbedtls_psa_mac_operation_t *operation, NULL ); if( cipher_info == NULL ) - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; ret = mbedtls_cipher_setup( &operation->ctx.cmac, cipher_info ); if( ret != 0 ) @@ -219,7 +219,7 @@ static psa_status_t cmac_setup( mbedtls_psa_mac_operation_t *operation, key_buffer, psa_get_key_bits( attributes ) ); exit: - return( mbedtls_to_psa_error( ret ) ); + return mbedtls_to_psa_error( ret ) ; } #endif /* BUILTIN_ALG_CMAC */ @@ -260,7 +260,7 @@ static psa_status_t mac_init( if( status != PSA_SUCCESS ) memset( operation, 0, sizeof( *operation ) ); - return( status ); + return status ; } static psa_status_t mac_abort( mbedtls_psa_mac_operation_t *operation ) @@ -270,7 +270,7 @@ static psa_status_t mac_abort( mbedtls_psa_mac_operation_t *operation ) /* The object has (apparently) been initialized but it is not * in use. It's ok to call abort on such an object, and there's * nothing to do. */ - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } else #if defined(BUILTIN_ALG_CMAC) @@ -295,7 +295,7 @@ static psa_status_t mac_abort( mbedtls_psa_mac_operation_t *operation ) operation->alg = 0; - return( PSA_SUCCESS ); + return PSA_SUCCESS ; bad_state: /* If abort is called on an uninitialized object, we can't trust @@ -303,7 +303,7 @@ bad_state: * This may result in a memory leak if a pointer gets overwritten, * but it's too late to do anything about this. */ memset( operation, 0, sizeof( *operation ) ); - return( PSA_ERROR_BAD_STATE ); + return PSA_ERROR_BAD_STATE ; } static psa_status_t mac_setup( mbedtls_psa_mac_operation_t *operation, @@ -316,11 +316,11 @@ static psa_status_t mac_setup( mbedtls_psa_mac_operation_t *operation, /* A context must be freshly initialized before it can be set up. */ if( operation->alg != 0 ) - return( PSA_ERROR_BAD_STATE ); + return PSA_ERROR_BAD_STATE ; status = mac_init( operation, alg ); if( status != PSA_SUCCESS ) - return( status ); + return status ; #if defined(BUILTIN_ALG_CMAC) if( PSA_ALG_FULL_LENGTH_MAC( alg ) == PSA_ALG_CMAC ) @@ -352,7 +352,7 @@ static psa_status_t mac_setup( mbedtls_psa_mac_operation_t *operation, if( status != PSA_SUCCESS ) mac_abort( operation ); - return( status ); + return status ; } static psa_status_t mac_update( @@ -361,7 +361,7 @@ static psa_status_t mac_update( size_t input_length ) { if( operation->alg == 0 ) - return( PSA_ERROR_BAD_STATE ); + return PSA_ERROR_BAD_STATE ; #if defined(BUILTIN_ALG_CMAC) if( PSA_ALG_FULL_LENGTH_MAC( operation->alg ) == PSA_ALG_CMAC ) @@ -385,7 +385,7 @@ static psa_status_t mac_update( * a setup function. */ (void) input; (void) input_length; - return( PSA_ERROR_BAD_STATE ); + return PSA_ERROR_BAD_STATE ; } } @@ -401,7 +401,7 @@ static psa_status_t mac_finish_internal( mbedtls_psa_mac_operation_t *operation, if( ret == 0 ) memcpy( mac, tmp, mac_size ); mbedtls_platform_zeroize( tmp, sizeof( tmp ) ); - return( mbedtls_to_psa_error( ret ) ); + return mbedtls_to_psa_error( ret ) ; } else #endif /* BUILTIN_ALG_CMAC */ @@ -419,7 +419,7 @@ static psa_status_t mac_finish_internal( mbedtls_psa_mac_operation_t *operation, (void) operation; (void) mac; (void) mac_size; - return( PSA_ERROR_BAD_STATE ); + return PSA_ERROR_BAD_STATE ; } } @@ -432,14 +432,14 @@ static psa_status_t mac_sign_finish( psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED; if( operation->alg == 0 ) - return( PSA_ERROR_BAD_STATE ); + return PSA_ERROR_BAD_STATE ; status = mac_finish_internal( operation, mac, mac_size ); if( status == PSA_SUCCESS ) *mac_length = mac_size; - return( status ); + return status ; } static psa_status_t mac_verify_finish( @@ -451,11 +451,11 @@ static psa_status_t mac_verify_finish( psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED; if( operation->alg == 0 ) - return( PSA_ERROR_BAD_STATE ); + return PSA_ERROR_BAD_STATE ; /* Consistency check: requested MAC length fits our local buffer */ if( mac_length > sizeof( actual_mac ) ) - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; status = mac_finish_internal( operation, actual_mac, mac_length ); if( status != PSA_SUCCESS ) @@ -467,7 +467,7 @@ static psa_status_t mac_verify_finish( cleanup: mbedtls_platform_zeroize( actual_mac, sizeof( actual_mac ) ); - return( status ); + return status ; } static psa_status_t mac_compute( @@ -504,7 +504,7 @@ static psa_status_t mac_compute( exit: mac_abort( &operation ); - return( status ); + return status ; } #endif /* BUILTIN_ALG_HMAC || BUILTIN_ALG_CMAC */ @@ -553,7 +553,7 @@ psa_status_t mbedtls_psa_mac_update( const uint8_t *input, size_t input_length ) { - return( mac_update( operation, input, input_length ) ); + return mac_update( operation, input, input_length ) ; } psa_status_t mbedtls_psa_mac_sign_finish( @@ -562,7 +562,7 @@ psa_status_t mbedtls_psa_mac_sign_finish( size_t mac_size, size_t *mac_length ) { - return( mac_sign_finish( operation, mac, mac_size, mac_length ) ); + return mac_sign_finish( operation, mac, mac_size, mac_length ) ; } psa_status_t mbedtls_psa_mac_verify_finish( @@ -570,13 +570,13 @@ psa_status_t mbedtls_psa_mac_verify_finish( const uint8_t *mac, size_t mac_length ) { - return( mac_verify_finish( operation, mac, mac_length ) ); + return mac_verify_finish( operation, mac, mac_length ) ; } psa_status_t mbedtls_psa_mac_abort( mbedtls_psa_mac_operation_t *operation ) { - return( mac_abort( operation ) ); + return mac_abort( operation ) ; } #endif /* MBEDTLS_PSA_BUILTIN_MAC */ @@ -589,17 +589,17 @@ static int is_mac_accelerated( psa_algorithm_t alg ) { #if defined(MBEDTLS_PSA_ACCEL_ALG_HMAC) if( PSA_ALG_IS_HMAC( alg ) ) - return( 1 ); + return 1 ; #endif switch( PSA_ALG_FULL_LENGTH_MAC( alg ) ) { #if defined(MBEDTLS_PSA_ACCEL_ALG_CMAC) case PSA_ALG_CMAC: - return( 1 ); + return 1 ; #endif default: - return( 0 ); + return 0 ; } } @@ -619,7 +619,7 @@ psa_status_t mbedtls_transparent_test_driver_mac_compute( input, input_length, mac, mac_size, mac_length ) ); else - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; } psa_status_t mbedtls_transparent_test_driver_mac_sign_setup( @@ -633,7 +633,7 @@ psa_status_t mbedtls_transparent_test_driver_mac_sign_setup( return( mac_setup( operation, attributes, key_buffer, key_buffer_size, alg ) ); else - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; } psa_status_t mbedtls_transparent_test_driver_mac_verify_setup( @@ -647,7 +647,7 @@ psa_status_t mbedtls_transparent_test_driver_mac_verify_setup( return( mac_setup( operation, attributes, key_buffer, key_buffer_size, alg ) ); else - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; } psa_status_t mbedtls_transparent_test_driver_mac_update( @@ -656,9 +656,9 @@ psa_status_t mbedtls_transparent_test_driver_mac_update( size_t input_length ) { if( is_mac_accelerated( operation->alg ) ) - return( mac_update( operation, input, input_length ) ); + return mac_update( operation, input, input_length ) ; else - return( PSA_ERROR_BAD_STATE ); + return PSA_ERROR_BAD_STATE ; } psa_status_t mbedtls_transparent_test_driver_mac_sign_finish( @@ -668,9 +668,9 @@ psa_status_t mbedtls_transparent_test_driver_mac_sign_finish( size_t *mac_length ) { if( is_mac_accelerated( operation->alg ) ) - return( mac_sign_finish( operation, mac, mac_size, mac_length ) ); + return mac_sign_finish( operation, mac, mac_size, mac_length ) ; else - return( PSA_ERROR_BAD_STATE ); + return PSA_ERROR_BAD_STATE ; } psa_status_t mbedtls_transparent_test_driver_mac_verify_finish( @@ -679,15 +679,15 @@ psa_status_t mbedtls_transparent_test_driver_mac_verify_finish( size_t mac_length ) { if( is_mac_accelerated( operation->alg ) ) - return( mac_verify_finish( operation, mac, mac_length ) ); + return mac_verify_finish( operation, mac, mac_length ) ; else - return( PSA_ERROR_BAD_STATE ); + return PSA_ERROR_BAD_STATE ; } psa_status_t mbedtls_transparent_test_driver_mac_abort( mbedtls_transparent_test_driver_mac_operation_t *operation ) { - return( mac_abort( operation ) ); + return mac_abort( operation ) ; } psa_status_t mbedtls_opaque_test_driver_mac_compute( @@ -711,7 +711,7 @@ psa_status_t mbedtls_opaque_test_driver_mac_compute( (void) mac; (void) mac_size; (void) mac_length; - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; } psa_status_t mbedtls_opaque_test_driver_mac_sign_setup( @@ -727,7 +727,7 @@ psa_status_t mbedtls_opaque_test_driver_mac_sign_setup( (void) key_buffer; (void) key_buffer_size; (void) alg; - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; } psa_status_t mbedtls_opaque_test_driver_mac_verify_setup( @@ -743,7 +743,7 @@ psa_status_t mbedtls_opaque_test_driver_mac_verify_setup( (void) key_buffer; (void) key_buffer_size; (void) alg; - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; } psa_status_t mbedtls_opaque_test_driver_mac_update( @@ -755,7 +755,7 @@ psa_status_t mbedtls_opaque_test_driver_mac_update( (void) operation; (void) input; (void) input_length; - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; } psa_status_t mbedtls_opaque_test_driver_mac_sign_finish( @@ -769,7 +769,7 @@ psa_status_t mbedtls_opaque_test_driver_mac_sign_finish( (void) mac; (void) mac_size; (void) mac_length; - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; } psa_status_t mbedtls_opaque_test_driver_mac_verify_finish( @@ -781,7 +781,7 @@ psa_status_t mbedtls_opaque_test_driver_mac_verify_finish( (void) operation; (void) mac; (void) mac_length; - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; } psa_status_t mbedtls_opaque_test_driver_mac_abort( @@ -789,7 +789,7 @@ psa_status_t mbedtls_opaque_test_driver_mac_abort( { /* Opaque driver testing is not implemented yet through this mechanism. */ (void) operation; - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; } #endif /* PSA_CRYPTO_DRIVER_TEST */ diff --git a/library/psa_crypto_rsa.c b/library/psa_crypto_rsa.c index d85b86c45d..65233b0f46 100644 --- a/library/psa_crypto_rsa.c +++ b/library/psa_crypto_rsa.c @@ -93,7 +93,7 @@ static psa_status_t psa_check_rsa_key_byte_aligned( status = PSA_ERROR_NOT_SUPPORTED; } mbedtls_mpi_free( &n ); - return( status ); + return status ; } psa_status_t mbedtls_psa_rsa_load_representation( @@ -144,7 +144,7 @@ psa_status_t mbedtls_psa_rsa_load_representation( exit: mbedtls_pk_free( &ctx ); - return( status ); + return status ; } #endif /* defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_CRYPT) || * defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_OAEP) || @@ -189,7 +189,7 @@ exit: mbedtls_rsa_free( rsa ); mbedtls_free( rsa ); - return( status ); + return status ; } psa_status_t mbedtls_psa_rsa_export_key( psa_key_type_t type, @@ -219,7 +219,7 @@ psa_status_t mbedtls_psa_rsa_export_key( psa_key_type_t type, { /* Clean up in case pk_write failed halfway through. */ memset( data, 0, data_size ); - return( mbedtls_to_psa_error( ret ) ); + return mbedtls_to_psa_error( ret ) ; } /* The mbedtls_pk_xxx functions write to the end of the buffer. @@ -237,14 +237,14 @@ psa_status_t mbedtls_psa_rsa_export_key( psa_key_type_t type, } *data_length = ret; - return( PSA_SUCCESS ); + return PSA_SUCCESS ; #else (void) type; (void) rsa; (void) data; (void) data_size; (void) data_length; - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; #endif /* MBEDTLS_PK_WRITE_C */ } @@ -259,7 +259,7 @@ static psa_status_t rsa_export_public_key( status = mbedtls_psa_rsa_load_representation( attributes->core.type, key_buffer, key_buffer_size, &rsa ); if( status != PSA_SUCCESS ) - return( status ); + return status ; status = mbedtls_psa_rsa_export_key( PSA_KEY_TYPE_RSA_PUBLIC_KEY, rsa, @@ -270,7 +270,7 @@ static psa_status_t rsa_export_public_key( mbedtls_rsa_free( rsa ); mbedtls_free( rsa ); - return( status ); + return status ; } #endif /* defined(BUILTIN_KEY_TYPE_RSA_KEY_PAIR) || * defined(BUILTIN_KEY_TYPE_RSA_PUBLIC_KEY) */ @@ -287,20 +287,20 @@ static psa_status_t psa_rsa_read_exponent( const uint8_t *domain_parameters, if( domain_parameters_size == 0 ) { *exponent = 65537; - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } /* Mbed TLS encodes the public exponent as an int. For simplicity, only * support values that fit in a 32-bit integer, which is larger than * int on just about every platform anyway. */ if( domain_parameters_size > sizeof( acc ) ) - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; for( i = 0; i < domain_parameters_size; i++ ) acc = ( acc << 8 ) | domain_parameters[i]; if( acc > INT_MAX ) - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; *exponent = acc; - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } static psa_status_t rsa_generate_key( @@ -316,7 +316,7 @@ static psa_status_t rsa_generate_key( attributes->domain_parameters_size, &exponent ); if( status != PSA_SUCCESS ) - return( status ); + return status ; mbedtls_rsa_init( &rsa ); ret = mbedtls_rsa_gen_key( &rsa, @@ -325,14 +325,14 @@ static psa_status_t rsa_generate_key( (unsigned int)attributes->core.bits, exponent ); if( ret != 0 ) - return( mbedtls_to_psa_error( ret ) ); + return mbedtls_to_psa_error( ret ) ; status = mbedtls_psa_rsa_export_key( attributes->core.type, &rsa, key_buffer, key_buffer_size, key_buffer_length ); mbedtls_rsa_free( &rsa ); - return( status ); + return status ; } #endif /* defined(BUILTIN_KEY_TYPE_RSA_KEY_PAIR) * defined(MBEDTLS_GENPRIME) */ @@ -358,19 +358,19 @@ static psa_status_t psa_rsa_decode_md_type( psa_algorithm_t alg, * overflow later. */ #if SIZE_MAX > UINT_MAX if( hash_length > UINT_MAX ) - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; #endif /* For signatures using a hash, the hash length must be correct. */ if( alg != PSA_ALG_RSA_PKCS1V15_SIGN_RAW ) { if( md_info == NULL ) - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; if( mbedtls_md_get_size( md_info ) != hash_length ) - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; } - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } static psa_status_t rsa_sign_hash( @@ -389,7 +389,7 @@ static psa_status_t rsa_sign_hash( key_buffer_size, &rsa ); if( status != PSA_SUCCESS ) - return( status ); + return status ; status = psa_rsa_decode_md_type( alg, hash_length, &md_alg ); if( status != PSA_SUCCESS ) @@ -450,7 +450,7 @@ exit: mbedtls_rsa_free( rsa ); mbedtls_free( rsa ); - return( status ); + return status ; } static psa_status_t rsa_verify_hash( @@ -528,7 +528,7 @@ exit: mbedtls_rsa_free( rsa ); mbedtls_free( rsa ); - return( status ); + return status ; } #endif /* defined(BUILTIN_ALG_RSA_PKCS1V15_SIGN) || @@ -669,7 +669,7 @@ psa_status_t mbedtls_transparent_test_driver_rsa_sign_hash( (void)signature; (void)signature_size; (void)signature_length; - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; #endif } @@ -695,7 +695,7 @@ psa_status_t mbedtls_transparent_test_driver_rsa_verify_hash( (void)hash_length; (void)signature; (void)signature_length; - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; #endif } #endif /* defined(MBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_SIGN) || diff --git a/library/psa_crypto_se.c b/library/psa_crypto_se.c index 56678d6a90..8b185cfa7c 100644 --- a/library/psa_crypto_se.c +++ b/library/psa_crypto_se.c @@ -82,25 +82,25 @@ psa_se_drv_table_entry_t *psa_get_se_driver_entry( * (which designates transparent keys). Make sure we never return * a driver entry for location 0. */ if( location == 0 ) - return( NULL ); + return NULL ; for( i = 0; i < PSA_MAX_SE_DRIVERS; i++ ) { if( driver_table[i].location == location ) - return( &driver_table[i] ); + return &driver_table[i] ; } - return( NULL ); + return NULL ; } const psa_drv_se_t *psa_get_se_driver_methods( const psa_se_drv_table_entry_t *driver ) { - return( driver->methods ); + return driver->methods ; } psa_drv_se_context_t *psa_get_se_driver_context( psa_se_drv_table_entry_t *driver ) { - return( &driver->u.context ); + return &driver->u.context ; } int psa_get_se_driver( psa_key_lifetime_t lifetime, @@ -112,7 +112,7 @@ int psa_get_se_driver( psa_key_lifetime_t lifetime, *p_methods = ( driver ? driver->methods : NULL ); if( p_drv_context != NULL ) *p_drv_context = ( driver ? &driver->u.context : NULL ); - return( driver != NULL ); + return driver != NULL ; } @@ -126,17 +126,17 @@ static psa_status_t psa_get_se_driver_its_file_uid( psa_storage_uid_t *uid ) { if( driver->location > PSA_MAX_SE_LOCATION ) - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; #if SIZE_MAX > UINT32_MAX /* ITS file sizes are limited to 32 bits. */ if( driver->u.internal.persistent_data_size > UINT32_MAX ) - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; #endif /* See the documentation of PSA_CRYPTO_SE_DRIVER_ITS_UID_BASE. */ *uid = PSA_CRYPTO_SE_DRIVER_ITS_UID_BASE + driver->location; - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } psa_status_t psa_load_se_persistent_data( @@ -148,7 +148,7 @@ psa_status_t psa_load_se_persistent_data( status = psa_get_se_driver_its_file_uid( driver, &uid ); if( status != PSA_SUCCESS ) - return( status ); + return status ; /* Read the amount of persistent data that the driver requests. * If the data in storage is larger, it is truncated. If the data @@ -171,7 +171,7 @@ psa_status_t psa_save_se_persistent_data( status = psa_get_se_driver_its_file_uid( driver, &uid ); if( status != PSA_SUCCESS ) - return( status ); + return status ; /* psa_get_se_driver_its_file_uid ensures that the size_t * persistent_data_size is in range, but compilers don't know that, @@ -186,9 +186,9 @@ psa_status_t psa_destroy_se_persistent_data( psa_key_location_t location ) { psa_storage_uid_t uid; if( location > PSA_MAX_SE_LOCATION ) - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; uid = PSA_CRYPTO_SE_DRIVER_ITS_UID_BASE + location; - return( psa_its_remove( uid ) ); + return psa_its_remove( uid ) ; } psa_status_t psa_find_se_slot_for_key( @@ -203,11 +203,11 @@ psa_status_t psa_find_se_slot_for_key( /* If the location is wrong, it's a bug in the library. */ if( driver->location != key_location ) - return( PSA_ERROR_CORRUPTION_DETECTED ); + return PSA_ERROR_CORRUPTION_DETECTED ; /* If the driver doesn't support key creation in any way, give up now. */ if( driver->methods->key_management == NULL ) - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; if( psa_get_key_slot_number( attributes, slot_number ) == PSA_SUCCESS ) { @@ -218,7 +218,7 @@ psa_status_t psa_find_se_slot_for_key( psa_drv_se_validate_slot_number_t p_validate_slot_number = driver->methods->key_management->p_validate_slot_number; if( p_validate_slot_number == NULL ) - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; status = p_validate_slot_number( &driver->u.context, driver->u.internal.persistent_data, attributes, method, @@ -228,7 +228,7 @@ psa_status_t psa_find_se_slot_for_key( { /* The application didn't specify a slot number. This doesn't * make sense when registering a slot. */ - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; } else { @@ -237,13 +237,13 @@ psa_status_t psa_find_se_slot_for_key( psa_drv_se_allocate_key_t p_allocate = driver->methods->key_management->p_allocate; if( p_allocate == NULL ) - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; status = p_allocate( &driver->u.context, driver->u.internal.persistent_data, attributes, method, slot_number ); } - return( status ); + return status ; } psa_status_t psa_destroy_se_key( psa_se_drv_table_entry_t *driver, @@ -261,13 +261,13 @@ psa_status_t psa_destroy_se_key( psa_se_drv_table_entry_t *driver, * keys, it's really a lack of permission. */ if( driver->methods->key_management == NULL || driver->methods->key_management->p_destroy == NULL ) - return( PSA_ERROR_NOT_PERMITTED ); + return PSA_ERROR_NOT_PERMITTED ; status = driver->methods->key_management->p_destroy( &driver->u.context, driver->u.internal.persistent_data, slot_number ); storage_status = psa_save_se_persistent_data( driver ); - return( status == PSA_SUCCESS ? storage_status : status ); + return status == PSA_SUCCESS ? storage_status : status ; } psa_status_t psa_init_all_se_drivers( void ) @@ -286,13 +286,13 @@ psa_status_t psa_init_all_se_drivers( void ) driver->u.internal.persistent_data, driver->location ); if( status != PSA_SUCCESS ) - return( status ); + return status ; status = psa_save_se_persistent_data( driver ); if( status != PSA_SUCCESS ) - return( status ); + return status ; } } - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } @@ -309,7 +309,7 @@ psa_status_t psa_register_se_driver( psa_status_t status; if( methods->hal_version != PSA_DRV_SE_HAL_VERSION ) - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; /* Driver table entries are 0-initialized. 0 is not a valid driver * location because it means a transparent key. */ #if defined(static_assert) @@ -317,9 +317,9 @@ psa_status_t psa_register_se_driver( "Secure element support requires 0 to mean a local key" ); #endif if( location == PSA_KEY_LOCATION_LOCAL_STORAGE ) - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; if( location > PSA_MAX_SE_LOCATION ) - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; for( i = 0; i < PSA_MAX_SE_DRIVERS; i++ ) { @@ -329,10 +329,10 @@ psa_status_t psa_register_se_driver( * entry. Since entries are created in order and never deleted, * there can't be a used entry after the first free entry. */ if( driver_table[i].location == location ) - return( PSA_ERROR_ALREADY_EXISTS ); + return PSA_ERROR_ALREADY_EXISTS ; } if( i == PSA_MAX_SE_DRIVERS ) - return( PSA_ERROR_INSUFFICIENT_MEMORY ); + return PSA_ERROR_INSUFFICIENT_MEMORY ; driver_table[i].location = location; driver_table[i].methods = methods; @@ -356,11 +356,11 @@ psa_status_t psa_register_se_driver( goto error; } - return( PSA_SUCCESS ); + return PSA_SUCCESS ; error: memset( &driver_table[i], 0, sizeof( driver_table[i] ) ); - return( status ); + return status ; } void psa_unregister_all_se_drivers( void ) diff --git a/library/psa_crypto_slot_management.c b/library/psa_crypto_slot_management.c index a5c43b1b2c..942f8b4086 100644 --- a/library/psa_crypto_slot_management.c +++ b/library/psa_crypto_slot_management.c @@ -57,14 +57,14 @@ int psa_is_valid_key_id( mbedtls_svc_key_id_t key, int vendor_ok ) if( ( PSA_KEY_ID_USER_MIN <= key_id ) && ( key_id <= PSA_KEY_ID_USER_MAX ) ) - return( 1 ); + return 1 ; if( vendor_ok && ( PSA_KEY_ID_VENDOR_MIN <= key_id ) && ( key_id <= PSA_KEY_ID_VENDOR_MAX ) ) - return( 1 ); + return 1 ; - return( 0 ); + return 0 ; } /** Get the description in memory of a key given its identifier and lock it. @@ -124,7 +124,7 @@ static psa_status_t psa_get_and_lock_key_slot_in_memory( else { if ( !psa_is_valid_key_id( key, 1 ) ) - return( PSA_ERROR_INVALID_HANDLE ); + return PSA_ERROR_INVALID_HANDLE ; for( slot_idx = 0; slot_idx < MBEDTLS_PSA_KEY_SLOT_COUNT; slot_idx++ ) { @@ -143,7 +143,7 @@ static psa_status_t psa_get_and_lock_key_slot_in_memory( *p_slot = slot; } - return( status ); + return status ; } psa_status_t psa_initialize_key_slots( void ) @@ -152,7 +152,7 @@ psa_status_t psa_initialize_key_slots( void ) * guarantee that the key slots are initialized to all-zero, which * means that all the key slots are in a valid, empty state. */ global_data.key_slots_initialized = 1; - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } void psa_wipe_all_key_slots( void ) @@ -222,7 +222,7 @@ psa_status_t psa_get_empty_key_slot( psa_key_id_t *volatile_key_id, ( (psa_key_id_t)( selected_slot - global_data.key_slots ) ); *p_slot = selected_slot; - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } status = PSA_ERROR_INSUFFICIENT_MEMORY; @@ -230,7 +230,7 @@ error: *p_slot = NULL; *volatile_key_id = 0; - return( status ); + return status ; } #if defined(MBEDTLS_PSA_CRYPTO_STORAGE_C) @@ -270,7 +270,7 @@ static psa_status_t psa_load_persistent_key_into_slot( psa_key_slot_t *slot ) exit: psa_free_persistent_key_data( key_data, key_data_length ); - return( status ); + return status ; } #endif /* MBEDTLS_PSA_CRYPTO_STORAGE_C */ @@ -288,14 +288,14 @@ static psa_status_t psa_load_builtin_key_into_slot( psa_key_slot_t *slot ) if( ! psa_key_id_is_builtin( MBEDTLS_SVC_KEY_ID_GET_KEY_ID( slot->attr.id ) ) ) { - return( PSA_ERROR_DOES_NOT_EXIST ); + return PSA_ERROR_DOES_NOT_EXIST ; } /* Check the platform function to see whether this key actually exists */ status = mbedtls_psa_platform_get_builtin_key( slot->attr.id, &lifetime, &slot_number ); if( status != PSA_SUCCESS ) - return( status ); + return status ; /* Set required key attributes to ensure get_builtin_key can retrieve the * full attributes. */ @@ -312,7 +312,7 @@ static psa_status_t psa_load_builtin_key_into_slot( psa_key_slot_t *slot ) /* Builtin keys cannot be defined by the attributes alone */ if( status == PSA_SUCCESS ) status = PSA_ERROR_CORRUPTION_DETECTED; - return( status ); + return status ; } /* If the key should exist according to the platform, then ask the driver @@ -320,13 +320,13 @@ static psa_status_t psa_load_builtin_key_into_slot( psa_key_slot_t *slot ) status = psa_driver_wrapper_get_key_buffer_size( &attributes, &key_buffer_size ); if( status != PSA_SUCCESS ) - return( status ); + return status ; /* Allocate a buffer of the required size and load the builtin key directly * into the (now properly sized) slot buffer. */ status = psa_allocate_buffer_to_slot( slot, key_buffer_size ); if( status != PSA_SUCCESS ) - return( status ); + return status ; status = psa_driver_wrapper_get_builtin_key( slot_number, &attributes, @@ -341,7 +341,7 @@ static psa_status_t psa_load_builtin_key_into_slot( psa_key_slot_t *slot ) exit: if( status != PSA_SUCCESS ) psa_remove_key_data_from_memory( slot ); - return( status ); + return status ; } #endif /* MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS */ @@ -352,7 +352,7 @@ psa_status_t psa_get_and_lock_key_slot( mbedtls_svc_key_id_t key, *p_slot = NULL; if( ! global_data.key_slots_initialized ) - return( PSA_ERROR_BAD_STATE ); + return PSA_ERROR_BAD_STATE ; /* * On success, the pointer to the slot is passed directly to the caller @@ -360,7 +360,7 @@ psa_status_t psa_get_and_lock_key_slot( mbedtls_svc_key_id_t key, */ status = psa_get_and_lock_key_slot_in_memory( key, p_slot ); if( status != PSA_ERROR_DOES_NOT_EXIST ) - return( status ); + return status ; /* Loading keys from storage requires support for such a mechanism */ #if defined(MBEDTLS_PSA_CRYPTO_STORAGE_C) || \ @@ -369,7 +369,7 @@ psa_status_t psa_get_and_lock_key_slot( mbedtls_svc_key_id_t key, status = psa_get_empty_key_slot( &volatile_key_id, p_slot ); if( status != PSA_SUCCESS ) - return( status ); + return status ; (*p_slot)->attr.id = key; (*p_slot)->attr.lifetime = PSA_KEY_LIFETIME_PERSISTENT; @@ -395,21 +395,21 @@ psa_status_t psa_get_and_lock_key_slot( mbedtls_svc_key_id_t key, /* Add implicit usage flags. */ psa_extend_key_usage_flags( &(*p_slot)->attr.policy.usage ); - return( status ); + return status ; #else /* MBEDTLS_PSA_CRYPTO_STORAGE_C || MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS */ - return( PSA_ERROR_INVALID_HANDLE ); + return PSA_ERROR_INVALID_HANDLE ; #endif /* MBEDTLS_PSA_CRYPTO_STORAGE_C || MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS */ } psa_status_t psa_unlock_key_slot( psa_key_slot_t *slot ) { if( slot == NULL ) - return( PSA_SUCCESS ); + return PSA_SUCCESS ; if( slot->lock_count > 0 ) { slot->lock_count--; - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } /* @@ -421,7 +421,7 @@ psa_status_t psa_unlock_key_slot( psa_key_slot_t *slot ) * execution of the test suite is stopped in error if the assertion fails. */ MBEDTLS_TEST_HOOK_TEST_ASSERT( slot->lock_count > 0 ); - return( PSA_ERROR_CORRUPTION_DETECTED ); + return PSA_ERROR_CORRUPTION_DETECTED ; } psa_status_t psa_validate_key_location( psa_key_lifetime_t lifetime, @@ -436,7 +436,7 @@ psa_status_t psa_validate_key_location( psa_key_lifetime_t lifetime, { if (p_drv != NULL) *p_drv = driver; - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } #else /* MBEDTLS_PSA_CRYPTO_SE_C */ (void) p_drv; @@ -444,16 +444,16 @@ psa_status_t psa_validate_key_location( psa_key_lifetime_t lifetime, #if defined(MBEDTLS_PSA_CRYPTO_DRIVERS) /* Key location for external keys gets checked by the wrapper */ - return( PSA_SUCCESS ); + return PSA_SUCCESS ; #else /* MBEDTLS_PSA_CRYPTO_DRIVERS */ /* No support for external lifetimes at all, or dynamic interface * did not find driver for requested lifetime. */ - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; #endif /* MBEDTLS_PSA_CRYPTO_DRIVERS */ } else /* Local/internal keys are always valid */ - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } psa_status_t psa_validate_key_persistence( psa_key_lifetime_t lifetime ) @@ -461,18 +461,18 @@ psa_status_t psa_validate_key_persistence( psa_key_lifetime_t lifetime ) if ( PSA_KEY_LIFETIME_IS_VOLATILE( lifetime ) ) { /* Volatile keys are always supported */ - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } else { /* Persistent keys require storage support */ #if defined(MBEDTLS_PSA_CRYPTO_STORAGE_C) if( PSA_KEY_LIFETIME_IS_READ_ONLY( lifetime ) ) - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; else - return( PSA_SUCCESS ); + return PSA_SUCCESS ; #else /* MBEDTLS_PSA_CRYPTO_STORAGE_C */ - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; #endif /* !MBEDTLS_PSA_CRYPTO_STORAGE_C */ } } @@ -490,17 +490,17 @@ psa_status_t psa_open_key( mbedtls_svc_key_id_t key, psa_key_handle_t *handle ) if( status == PSA_ERROR_INVALID_HANDLE ) status = PSA_ERROR_DOES_NOT_EXIST; - return( status ); + return status ; } *handle = key; - return( psa_unlock_key_slot( slot ) ); + return psa_unlock_key_slot( slot ) ; #else /* defined(MBEDTLS_PSA_CRYPTO_STORAGE_C) */ (void) key; *handle = PSA_KEY_HANDLE_INIT; - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; #endif /* !defined(MBEDTLS_PSA_CRYPTO_STORAGE_C) */ } @@ -510,7 +510,7 @@ psa_status_t psa_close_key( psa_key_handle_t handle ) psa_key_slot_t *slot; if( psa_key_handle_is_null( handle ) ) - return( PSA_SUCCESS ); + return PSA_SUCCESS ; status = psa_get_and_lock_key_slot_in_memory( handle, &slot ); if( status != PSA_SUCCESS ) @@ -518,12 +518,12 @@ psa_status_t psa_close_key( psa_key_handle_t handle ) if( status == PSA_ERROR_DOES_NOT_EXIST ) status = PSA_ERROR_INVALID_HANDLE; - return( status ); + return status ; } if( slot->lock_count <= 1 ) - return( psa_wipe_key_slot( slot ) ); + return psa_wipe_key_slot( slot ) ; else - return( psa_unlock_key_slot( slot ) ); + return psa_unlock_key_slot( slot ) ; } psa_status_t psa_purge_key( mbedtls_svc_key_id_t key ) @@ -533,13 +533,13 @@ psa_status_t psa_purge_key( mbedtls_svc_key_id_t key ) status = psa_get_and_lock_key_slot_in_memory( key, &slot ); if( status != PSA_SUCCESS ) - return( status ); + return status ; if( ( ! PSA_KEY_LIFETIME_IS_VOLATILE( slot->attr.lifetime ) ) && ( slot->lock_count <= 1 ) ) - return( psa_wipe_key_slot( slot ) ); + return psa_wipe_key_slot( slot ) ; else - return( psa_unlock_key_slot( slot ) ); + return psa_unlock_key_slot( slot ) ; } void mbedtls_psa_get_stats( mbedtls_psa_stats_t *stats ) diff --git a/library/psa_crypto_slot_management.h b/library/psa_crypto_slot_management.h index d539bdd866..c81791e19f 100644 --- a/library/psa_crypto_slot_management.h +++ b/library/psa_crypto_slot_management.h @@ -140,11 +140,11 @@ psa_status_t psa_get_empty_key_slot( psa_key_id_t *volatile_key_id, static inline psa_status_t psa_lock_key_slot( psa_key_slot_t *slot ) { if( slot->lock_count >= SIZE_MAX ) - return( PSA_ERROR_CORRUPTION_DETECTED ); + return PSA_ERROR_CORRUPTION_DETECTED ; slot->lock_count++; - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } /** Unlock a key slot. diff --git a/library/psa_crypto_storage.c b/library/psa_crypto_storage.c index 09cbab4c4d..f6ec39c9e0 100644 --- a/library/psa_crypto_storage.c +++ b/library/psa_crypto_storage.c @@ -70,7 +70,7 @@ static psa_storage_uid_t psa_its_identifier_of_slot( mbedtls_svc_key_id_t key ) * psa_is_key_id_valid() in psa_crypto_slot_management.c * is responsible for ensuring that key identifiers do not have a * value that is reserved for non-key files. */ - return( key ); + return key ; #endif } @@ -101,13 +101,13 @@ static psa_status_t psa_crypto_storage_load( status = psa_its_get_info( data_identifier, &data_identifier_info ); if( status != PSA_SUCCESS ) - return( status ); + return status ; status = psa_its_get( data_identifier, 0, (uint32_t) data_size, data, &data_length ); if( data_size != data_length ) - return( PSA_ERROR_DATA_INVALID ); + return PSA_ERROR_DATA_INVALID ; - return( status ); + return status ; } int psa_is_key_present_in_storage( const mbedtls_svc_key_id_t key ) @@ -119,8 +119,8 @@ int psa_is_key_present_in_storage( const mbedtls_svc_key_id_t key ) ret = psa_its_get_info( data_identifier, &data_identifier_info ); if( ret == PSA_ERROR_DOES_NOT_EXIST ) - return( 0 ); - return( 1 ); + return 0 ; + return 1 ; } /** @@ -149,12 +149,12 @@ static psa_status_t psa_crypto_storage_store( const mbedtls_svc_key_id_t key, struct psa_storage_info_t data_identifier_info; if( psa_is_key_present_in_storage( key ) == 1 ) - return( PSA_ERROR_ALREADY_EXISTS ); + return PSA_ERROR_ALREADY_EXISTS ; status = psa_its_set( data_identifier, (uint32_t) data_length, data, 0 ); if( status != PSA_SUCCESS ) { - return( PSA_ERROR_DATA_INVALID ); + return PSA_ERROR_DATA_INVALID ; } status = psa_its_get_info( data_identifier, &data_identifier_info ); @@ -178,7 +178,7 @@ exit: * nothing else we can do. */ (void) psa_its_remove( data_identifier ); } - return( status ); + return status ; } psa_status_t psa_destroy_persistent_key( const mbedtls_svc_key_id_t key ) @@ -189,16 +189,16 @@ psa_status_t psa_destroy_persistent_key( const mbedtls_svc_key_id_t key ) ret = psa_its_get_info( data_identifier, &data_identifier_info ); if( ret == PSA_ERROR_DOES_NOT_EXIST ) - return( PSA_SUCCESS ); + return PSA_SUCCESS ; if( psa_its_remove( data_identifier ) != PSA_SUCCESS ) - return( PSA_ERROR_DATA_INVALID ); + return PSA_ERROR_DATA_INVALID ; ret = psa_its_get_info( data_identifier, &data_identifier_info ); if( ret != PSA_ERROR_DOES_NOT_EXIST ) - return( PSA_ERROR_DATA_INVALID ); + return PSA_ERROR_DATA_INVALID ; - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } /** @@ -223,11 +223,11 @@ static psa_status_t psa_crypto_storage_get_data_length( status = psa_its_get_info( data_identifier, &data_identifier_info ); if( status != PSA_SUCCESS ) - return( status ); + return status ; *data_length = (size_t) data_identifier_info.size; - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } /* @@ -313,8 +313,8 @@ static psa_status_t check_magic_header( const uint8_t *data ) { if( memcmp( data, PSA_KEY_STORAGE_MAGIC_HEADER, PSA_KEY_STORAGE_MAGIC_HEADER_LENGTH ) != 0 ) - return( PSA_ERROR_DATA_INVALID ); - return( PSA_SUCCESS ); + return PSA_ERROR_DATA_INVALID ; + return PSA_SUCCESS ; } psa_status_t psa_parse_key_data_from_storage( const uint8_t *storage_data, @@ -329,20 +329,20 @@ psa_status_t psa_parse_key_data_from_storage( const uint8_t *storage_data, uint32_t version; if( storage_data_length < sizeof(*storage_format) ) - return( PSA_ERROR_DATA_INVALID ); + return PSA_ERROR_DATA_INVALID ; status = check_magic_header( storage_data ); if( status != PSA_SUCCESS ) - return( status ); + return status ; GET_UINT32_LE( version, storage_format->version, 0 ); if( version != 0 ) - return( PSA_ERROR_DATA_INVALID ); + return PSA_ERROR_DATA_INVALID ; GET_UINT32_LE( *key_data_length, storage_format->data_len, 0 ); if( *key_data_length > ( storage_data_length - sizeof(*storage_format) ) || *key_data_length > PSA_CRYPTO_MAX_STORAGE_SIZE ) - return( PSA_ERROR_DATA_INVALID ); + return PSA_ERROR_DATA_INVALID ; if( *key_data_length == 0 ) { @@ -352,7 +352,7 @@ psa_status_t psa_parse_key_data_from_storage( const uint8_t *storage_data, { *key_data = mbedtls_calloc( 1, *key_data_length ); if( *key_data == NULL ) - return( PSA_ERROR_INSUFFICIENT_MEMORY ); + return PSA_ERROR_INSUFFICIENT_MEMORY ; memcpy( *key_data, storage_format->key_data, *key_data_length ); } @@ -363,7 +363,7 @@ psa_status_t psa_parse_key_data_from_storage( const uint8_t *storage_data, GET_UINT32_LE( attr->policy.alg, storage_format->policy, sizeof( uint32_t ) ); GET_UINT32_LE( attr->policy.alg2, storage_format->policy, 2 * sizeof( uint32_t ) ); - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } psa_status_t psa_save_persistent_key( const psa_core_key_attributes_t *attr, @@ -376,15 +376,15 @@ psa_status_t psa_save_persistent_key( const psa_core_key_attributes_t *attr, /* All keys saved to persistent storage always have a key context */ if( data == NULL || data_length == 0 ) - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; if( data_length > PSA_CRYPTO_MAX_STORAGE_SIZE ) - return( PSA_ERROR_INSUFFICIENT_STORAGE ); + return PSA_ERROR_INSUFFICIENT_STORAGE ; storage_data_length = data_length + sizeof( psa_persistent_key_storage_format ); storage_data = mbedtls_calloc( 1, storage_data_length ); if( storage_data == NULL ) - return( PSA_ERROR_INSUFFICIENT_MEMORY ); + return PSA_ERROR_INSUFFICIENT_MEMORY ; psa_format_key_data_for_storage( data, data_length, attr, storage_data ); @@ -393,7 +393,7 @@ psa_status_t psa_save_persistent_key( const psa_core_key_attributes_t *attr, mbedtls_free( storage_data ); - return( status ); + return status ; } void psa_free_persistent_key_data( uint8_t *key_data, size_t key_data_length ) @@ -416,12 +416,12 @@ psa_status_t psa_load_persistent_key( psa_core_key_attributes_t *attr, status = psa_crypto_storage_get_data_length( key, &storage_data_length ); if( status != PSA_SUCCESS ) - return( status ); + return status ; loaded_data = mbedtls_calloc( 1, storage_data_length ); if( loaded_data == NULL ) - return( PSA_ERROR_INSUFFICIENT_MEMORY ); + return PSA_ERROR_INSUFFICIENT_MEMORY ; status = psa_crypto_storage_load( key, loaded_data, storage_data_length ); if( status != PSA_SUCCESS ) @@ -437,7 +437,7 @@ psa_status_t psa_load_persistent_key( psa_core_key_attributes_t *attr, exit: mbedtls_free( loaded_data ); - return( status ); + return status ; } @@ -459,10 +459,10 @@ psa_status_t psa_crypto_save_transaction( void ) { /* This shouldn't happen: we're trying to start a transaction while * there is still a transaction that hasn't been replayed. */ - return( PSA_ERROR_CORRUPTION_DETECTED ); + return PSA_ERROR_CORRUPTION_DETECTED ; } else if( status != PSA_ERROR_DOES_NOT_EXIST ) - return( status ); + return status ; return( psa_its_set( PSA_CRYPTO_ITS_TRANSACTION_UID, sizeof( psa_crypto_transaction ), &psa_crypto_transaction, @@ -477,10 +477,10 @@ psa_status_t psa_crypto_load_transaction( void ) sizeof( psa_crypto_transaction ), &psa_crypto_transaction, &length ); if( status != PSA_SUCCESS ) - return( status ); + return status ; if( length != sizeof( psa_crypto_transaction ) ) - return( PSA_ERROR_DATA_INVALID ); - return( PSA_SUCCESS ); + return PSA_ERROR_DATA_INVALID ; + return PSA_SUCCESS ; } psa_status_t psa_crypto_stop_transaction( void ) @@ -490,7 +490,7 @@ psa_status_t psa_crypto_stop_transaction( void ) * finished now. It's too late to go back, so zero out the in-memory * data. */ memset( &psa_crypto_transaction, 0, sizeof( psa_crypto_transaction ) ); - return( status ); + return status ; } #endif /* PSA_CRYPTO_STORAGE_HAS_TRANSACTIONS */ @@ -519,7 +519,7 @@ psa_status_t mbedtls_psa_storage_inject_entropy( const unsigned char *seed, /* You should not be here. Seed needs to be injected only once */ status = PSA_ERROR_NOT_PERMITTED; } - return( status ); + return status ; } #endif /* MBEDTLS_PSA_INJECT_ENTROPY */ diff --git a/library/psa_its_file.c b/library/psa_its_file.c index 492be1c711..106d1c375f 100644 --- a/library/psa_its_file.c +++ b/library/psa_its_file.c @@ -100,14 +100,14 @@ static psa_status_t psa_its_read_file( psa_storage_uid_t uid, psa_its_fill_filename( uid, filename ); *p_stream = fopen( filename, "rb" ); if( *p_stream == NULL ) - return( PSA_ERROR_DOES_NOT_EXIST ); + return PSA_ERROR_DOES_NOT_EXIST ; n = fread( &header, 1, sizeof( header ), *p_stream ); if( n != sizeof( header ) ) - return( PSA_ERROR_DATA_CORRUPT ); + return PSA_ERROR_DATA_CORRUPT ; if( memcmp( header.magic, PSA_ITS_MAGIC_STRING, PSA_ITS_MAGIC_LENGTH ) != 0 ) - return( PSA_ERROR_DATA_CORRUPT ); + return PSA_ERROR_DATA_CORRUPT ; p_info->size = ( header.size[0] | header.size[1] << 8 | @@ -117,7 +117,7 @@ static psa_status_t psa_its_read_file( psa_storage_uid_t uid, header.flags[1] << 8 | header.flags[2] << 16 | header.flags[3] << 24 ); - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } psa_status_t psa_its_get_info( psa_storage_uid_t uid, @@ -128,7 +128,7 @@ psa_status_t psa_its_get_info( psa_storage_uid_t uid, status = psa_its_read_file( uid, p_info, &stream ); if( stream != NULL ) fclose( stream ); - return( status ); + return status ; } psa_status_t psa_its_get( psa_storage_uid_t uid, @@ -176,7 +176,7 @@ psa_status_t psa_its_get( psa_storage_uid_t uid, exit: if( stream != NULL ) fclose( stream ); - return( status ); + return status ; } psa_status_t psa_its_set( psa_storage_uid_t uid, @@ -235,7 +235,7 @@ exit: * temporary file doesn't exist and so remove() is expected to fail. * Thus we just ignore the return status of remove(). */ (void) remove( PSA_ITS_STORAGE_TEMP ); - return( status ); + return status ; } psa_status_t psa_its_remove( psa_storage_uid_t uid ) @@ -245,11 +245,11 @@ psa_status_t psa_its_remove( psa_storage_uid_t uid ) psa_its_fill_filename( uid, filename ); stream = fopen( filename, "rb" ); if( stream == NULL ) - return( PSA_ERROR_DOES_NOT_EXIST ); + return PSA_ERROR_DOES_NOT_EXIST ; fclose( stream ); if( remove( filename ) != 0 ) - return( PSA_ERROR_STORAGE_FAILURE ); - return( PSA_SUCCESS ); + return PSA_ERROR_STORAGE_FAILURE ; + return PSA_SUCCESS ; } #endif /* MBEDTLS_PSA_ITS_FILE_C */ diff --git a/library/ripemd160.c b/library/ripemd160.c index d2ccbbec47..1553558943 100644 --- a/library/ripemd160.c +++ b/library/ripemd160.c @@ -100,7 +100,7 @@ int mbedtls_ripemd160_starts( mbedtls_ripemd160_context *ctx ) ctx->state[3] = 0x10325476; ctx->state[4] = 0xC3D2E1F0; - return( 0 ); + return 0 ; } #if !defined(MBEDTLS_RIPEMD160_PROCESS_ALT) @@ -297,7 +297,7 @@ int mbedtls_internal_ripemd160_process( mbedtls_ripemd160_context *ctx, /* Zeroise variables to clear sensitive data from memory. */ mbedtls_platform_zeroize( &local, sizeof( local ) ); - return( 0 ); + return 0 ; } #endif /* !MBEDTLS_RIPEMD160_PROCESS_ALT */ @@ -314,7 +314,7 @@ int mbedtls_ripemd160_update( mbedtls_ripemd160_context *ctx, uint32_t left; if( ilen == 0 ) - return( 0 ); + return 0 ; left = ctx->total[0] & 0x3F; fill = 64 - left; @@ -330,7 +330,7 @@ int mbedtls_ripemd160_update( mbedtls_ripemd160_context *ctx, memcpy( (void *) (ctx->buffer + left), input, fill ); if( ( ret = mbedtls_internal_ripemd160_process( ctx, ctx->buffer ) ) != 0 ) - return( ret ); + return ret ; input += fill; ilen -= fill; @@ -340,7 +340,7 @@ int mbedtls_ripemd160_update( mbedtls_ripemd160_context *ctx, while( ilen >= 64 ) { if( ( ret = mbedtls_internal_ripemd160_process( ctx, input ) ) != 0 ) - return( ret ); + return ret ; input += 64; ilen -= 64; @@ -351,7 +351,7 @@ int mbedtls_ripemd160_update( mbedtls_ripemd160_context *ctx, memcpy( (void *) (ctx->buffer + left), input, ilen ); } - return( 0 ); + return 0 ; } static const unsigned char ripemd160_padding[64] = @@ -385,11 +385,11 @@ int mbedtls_ripemd160_finish( mbedtls_ripemd160_context *ctx, ret = mbedtls_ripemd160_update( ctx, ripemd160_padding, padn ); if( ret != 0 ) - return( ret ); + return ret ; ret = mbedtls_ripemd160_update( ctx, msglen, 8 ); if( ret != 0 ) - return( ret ); + return ret ; PUT_UINT32_LE( ctx->state[0], output, 0 ); PUT_UINT32_LE( ctx->state[1], output, 4 ); @@ -397,7 +397,7 @@ int mbedtls_ripemd160_finish( mbedtls_ripemd160_context *ctx, PUT_UINT32_LE( ctx->state[3], output, 12 ); PUT_UINT32_LE( ctx->state[4], output, 16 ); - return( 0 ); + return 0 ; } #endif /* ! MBEDTLS_RIPEMD160_ALT */ @@ -426,7 +426,7 @@ int mbedtls_ripemd160( const unsigned char *input, exit: mbedtls_ripemd160_free( &ctx ); - return( ret ); + return ret ; } #if defined(MBEDTLS_SELF_TEST) @@ -480,7 +480,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++ ) { @@ -505,13 +505,13 @@ int mbedtls_ripemd160_self_test( int verbose ) if( verbose != 0 ) mbedtls_printf( "\n" ); - return( 0 ); + return 0 ; fail: if( verbose != 0 ) mbedtls_printf( "failed\n" ); - return( ret ); + return ret ; } #endif /* MBEDTLS_SELF_TEST */ diff --git a/library/rsa.c b/library/rsa.c index e818e6daeb..5cded9caa8 100644 --- a/library/rsa.c +++ b/library/rsa.c @@ -84,7 +84,7 @@ static inline int mbedtls_safer_memcmp( const void *a, const void *b, size_t n ) for( i = 0; i < n; i++ ) diff |= A[i] ^ B[i]; - return( diff ); + return diff ; } #endif /* MBEDTLS_PKCS1_V15 */ @@ -102,13 +102,13 @@ int mbedtls_rsa_import( mbedtls_rsa_context *ctx, ( D != NULL && ( ret = mbedtls_mpi_copy( &ctx->D, D ) ) != 0 ) || ( E != NULL && ( ret = mbedtls_mpi_copy( &ctx->E, E ) ) != 0 ) ) { - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_RSA_BAD_INPUT_DATA, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_RSA_BAD_INPUT_DATA, ret ) ; } if( N != NULL ) ctx->len = mbedtls_mpi_size( &ctx->N ); - return( 0 ); + return 0 ; } int mbedtls_rsa_import_raw( mbedtls_rsa_context *ctx, @@ -142,9 +142,9 @@ int mbedtls_rsa_import_raw( mbedtls_rsa_context *ctx, cleanup: if( ret != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_RSA_BAD_INPUT_DATA, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_RSA_BAD_INPUT_DATA, ret ) ; - return( 0 ); + return 0 ; } /* @@ -164,7 +164,7 @@ static int rsa_check_context( mbedtls_rsa_context const *ctx, int is_priv, if( ctx->len != mbedtls_mpi_size( &ctx->N ) || ctx->len > MBEDTLS_MPI_MAX_SIZE ) { - return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); + return MBEDTLS_ERR_RSA_BAD_INPUT_DATA ; } /* @@ -176,7 +176,7 @@ static int rsa_check_context( mbedtls_rsa_context const *ctx, int is_priv, if( mbedtls_mpi_cmp_int( &ctx->N, 0 ) <= 0 || mbedtls_mpi_get_bit( &ctx->N, 0 ) == 0 ) { - return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); + return MBEDTLS_ERR_RSA_BAD_INPUT_DATA ; } #if !defined(MBEDTLS_RSA_NO_CRT) @@ -189,7 +189,7 @@ static int rsa_check_context( mbedtls_rsa_context const *ctx, int is_priv, mbedtls_mpi_cmp_int( &ctx->Q, 0 ) <= 0 || mbedtls_mpi_get_bit( &ctx->Q, 0 ) == 0 ) ) { - return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); + return MBEDTLS_ERR_RSA_BAD_INPUT_DATA ; } #endif /* !MBEDTLS_RSA_NO_CRT */ @@ -199,19 +199,19 @@ static int rsa_check_context( mbedtls_rsa_context const *ctx, int is_priv, /* Always need E for public key operations */ if( mbedtls_mpi_cmp_int( &ctx->E, 0 ) <= 0 ) - return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); + return MBEDTLS_ERR_RSA_BAD_INPUT_DATA ; #if defined(MBEDTLS_RSA_NO_CRT) /* For private key operations, use D or DP & DQ * as (unblinded) exponents. */ if( is_priv && mbedtls_mpi_cmp_int( &ctx->D, 0 ) <= 0 ) - return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); + return MBEDTLS_ERR_RSA_BAD_INPUT_DATA ; #else if( is_priv && ( mbedtls_mpi_cmp_int( &ctx->DP, 0 ) <= 0 || mbedtls_mpi_cmp_int( &ctx->DQ, 0 ) <= 0 ) ) { - return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); + return MBEDTLS_ERR_RSA_BAD_INPUT_DATA ; } #endif /* MBEDTLS_RSA_NO_CRT */ @@ -223,7 +223,7 @@ static int rsa_check_context( mbedtls_rsa_context const *ctx, int is_priv, ( mbedtls_mpi_cmp_int( &ctx->P, 0 ) <= 0 || mbedtls_mpi_cmp_int( &ctx->Q, 0 ) <= 0 ) ) { - return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); + return MBEDTLS_ERR_RSA_BAD_INPUT_DATA ; } #endif @@ -233,11 +233,11 @@ static int rsa_check_context( mbedtls_rsa_context const *ctx, int is_priv, if( is_priv && mbedtls_mpi_cmp_int( &ctx->QP, 0 ) <= 0 ) { - return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); + return MBEDTLS_ERR_RSA_BAD_INPUT_DATA ; } #endif - return( 0 ); + return 0 ; } int mbedtls_rsa_complete( mbedtls_rsa_context *ctx ) @@ -282,7 +282,7 @@ int mbedtls_rsa_complete( mbedtls_rsa_context *ctx ) is_priv = n_missing || pq_missing || d_missing; if( !is_priv && !is_pub ) - return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); + return MBEDTLS_ERR_RSA_BAD_INPUT_DATA ; /* * Step 1: Deduce N if P, Q are provided. @@ -293,7 +293,7 @@ int mbedtls_rsa_complete( mbedtls_rsa_context *ctx ) if( ( ret = mbedtls_mpi_mul_mpi( &ctx->N, &ctx->P, &ctx->Q ) ) != 0 ) { - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_RSA_BAD_INPUT_DATA, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_RSA_BAD_INPUT_DATA, ret ) ; } ctx->len = mbedtls_mpi_size( &ctx->N ); @@ -308,7 +308,7 @@ int mbedtls_rsa_complete( mbedtls_rsa_context *ctx ) ret = mbedtls_rsa_deduce_primes( &ctx->N, &ctx->E, &ctx->D, &ctx->P, &ctx->Q ); if( ret != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_RSA_BAD_INPUT_DATA, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_RSA_BAD_INPUT_DATA, ret ) ; } else if( d_missing ) @@ -318,7 +318,7 @@ int mbedtls_rsa_complete( mbedtls_rsa_context *ctx ) &ctx->E, &ctx->D ) ) != 0 ) { - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_RSA_BAD_INPUT_DATA, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_RSA_BAD_INPUT_DATA, ret ) ; } } @@ -333,7 +333,7 @@ int mbedtls_rsa_complete( mbedtls_rsa_context *ctx ) ret = mbedtls_rsa_deduce_crt( &ctx->P, &ctx->Q, &ctx->D, &ctx->DP, &ctx->DQ, &ctx->QP ); if( ret != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_RSA_BAD_INPUT_DATA, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_RSA_BAD_INPUT_DATA, ret ) ; } #endif /* MBEDTLS_RSA_NO_CRT */ @@ -341,7 +341,7 @@ int mbedtls_rsa_complete( mbedtls_rsa_context *ctx ) * Step 3: Basic sanity checks */ - return( rsa_check_context( ctx, is_priv, 1 ) ); + return rsa_check_context( ctx, is_priv, 1 ) ; } int mbedtls_rsa_export_raw( const mbedtls_rsa_context *ctx, @@ -368,7 +368,7 @@ int mbedtls_rsa_export_raw( const mbedtls_rsa_context *ctx, /* If we're trying to export private parameters for a public key, * something must be wrong. */ if( P != NULL || Q != NULL || D != NULL ) - return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); + return MBEDTLS_ERR_RSA_BAD_INPUT_DATA ; } @@ -389,7 +389,7 @@ int mbedtls_rsa_export_raw( const mbedtls_rsa_context *ctx, cleanup: - return( ret ); + return ret ; } int mbedtls_rsa_export( const mbedtls_rsa_context *ctx, @@ -413,7 +413,7 @@ int mbedtls_rsa_export( const mbedtls_rsa_context *ctx, /* If we're trying to export private parameters for a public key, * something must be wrong. */ if( P != NULL || Q != NULL || D != NULL ) - return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); + return MBEDTLS_ERR_RSA_BAD_INPUT_DATA ; } @@ -425,10 +425,10 @@ int mbedtls_rsa_export( const mbedtls_rsa_context *ctx, ( D != NULL && ( ret = mbedtls_mpi_copy( D, &ctx->D ) ) != 0 ) || ( E != NULL && ( ret = mbedtls_mpi_copy( E, &ctx->E ) ) != 0 ) ) { - return( ret ); + return ret ; } - return( 0 ); + return 0 ; } /* @@ -453,7 +453,7 @@ int mbedtls_rsa_export_crt( const mbedtls_rsa_context *ctx, mbedtls_mpi_cmp_int( &ctx->E, 0 ) != 0; if( !is_priv ) - return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); + return MBEDTLS_ERR_RSA_BAD_INPUT_DATA ; #if !defined(MBEDTLS_RSA_NO_CRT) /* Export all requested blinding parameters. */ @@ -461,17 +461,17 @@ int mbedtls_rsa_export_crt( const mbedtls_rsa_context *ctx, ( DQ != NULL && ( ret = mbedtls_mpi_copy( DQ, &ctx->DQ ) ) != 0 ) || ( QP != NULL && ( ret = mbedtls_mpi_copy( QP, &ctx->QP ) ) != 0 ) ) { - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_RSA_BAD_INPUT_DATA, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_RSA_BAD_INPUT_DATA, ret ) ; } #else if( ( ret = mbedtls_rsa_deduce_crt( &ctx->P, &ctx->Q, &ctx->D, DP, DQ, QP ) ) != 0 ) { - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_RSA_BAD_INPUT_DATA, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_RSA_BAD_INPUT_DATA, ret ) ; } #endif - return( 0 ); + return 0 ; } /* @@ -512,7 +512,7 @@ int mbedtls_rsa_set_padding( mbedtls_rsa_context *ctx, int padding, break; #endif default: - return( MBEDTLS_ERR_RSA_INVALID_PADDING ); + return MBEDTLS_ERR_RSA_INVALID_PADDING ; } if( ( padding == MBEDTLS_RSA_PKCS_V21 ) && @@ -522,13 +522,13 @@ int mbedtls_rsa_set_padding( mbedtls_rsa_context *ctx, int padding, md_info = mbedtls_md_info_from_type( hash_id ); if( md_info == NULL ) - return( MBEDTLS_ERR_RSA_INVALID_PADDING ); + return MBEDTLS_ERR_RSA_INVALID_PADDING ; } ctx->padding = padding; ctx->hash_id = hash_id; - return( 0 ); + return 0 ; } /* @@ -537,7 +537,7 @@ int mbedtls_rsa_set_padding( mbedtls_rsa_context *ctx, int padding, size_t mbedtls_rsa_get_len( const mbedtls_rsa_context *ctx ) { - return( ctx->len ); + return ctx->len ; } @@ -658,10 +658,10 @@ cleanup: if( ( -ret & ~0x7f ) == 0 ) ret = MBEDTLS_ERROR_ADD( MBEDTLS_ERR_RSA_KEY_GEN_FAILED, ret ); - return( ret ); + return ret ; } - return( 0 ); + return 0 ; } #endif /* MBEDTLS_GENPRIME */ @@ -674,21 +674,21 @@ int mbedtls_rsa_check_pubkey( const mbedtls_rsa_context *ctx ) RSA_VALIDATE_RET( ctx != NULL ); if( rsa_check_context( ctx, 0 /* public */, 0 /* no blinding */ ) != 0 ) - return( MBEDTLS_ERR_RSA_KEY_CHECK_FAILED ); + return MBEDTLS_ERR_RSA_KEY_CHECK_FAILED ; if( mbedtls_mpi_bitlen( &ctx->N ) < 128 ) { - return( MBEDTLS_ERR_RSA_KEY_CHECK_FAILED ); + return MBEDTLS_ERR_RSA_KEY_CHECK_FAILED ; } if( mbedtls_mpi_get_bit( &ctx->E, 0 ) == 0 || mbedtls_mpi_bitlen( &ctx->E ) < 2 || mbedtls_mpi_cmp_mpi( &ctx->E, &ctx->N ) >= 0 ) { - return( MBEDTLS_ERR_RSA_KEY_CHECK_FAILED ); + return MBEDTLS_ERR_RSA_KEY_CHECK_FAILED ; } - return( 0 ); + return 0 ; } /* @@ -701,24 +701,24 @@ int mbedtls_rsa_check_privkey( const mbedtls_rsa_context *ctx ) if( mbedtls_rsa_check_pubkey( ctx ) != 0 || rsa_check_context( ctx, 1 /* private */, 1 /* blinding */ ) != 0 ) { - return( MBEDTLS_ERR_RSA_KEY_CHECK_FAILED ); + return MBEDTLS_ERR_RSA_KEY_CHECK_FAILED ; } if( mbedtls_rsa_validate_params( &ctx->N, &ctx->P, &ctx->Q, &ctx->D, &ctx->E, NULL, NULL ) != 0 ) { - return( MBEDTLS_ERR_RSA_KEY_CHECK_FAILED ); + return MBEDTLS_ERR_RSA_KEY_CHECK_FAILED ; } #if !defined(MBEDTLS_RSA_NO_CRT) else if( mbedtls_rsa_validate_crt( &ctx->P, &ctx->Q, &ctx->D, &ctx->DP, &ctx->DQ, &ctx->QP ) != 0 ) { - return( MBEDTLS_ERR_RSA_KEY_CHECK_FAILED ); + return MBEDTLS_ERR_RSA_KEY_CHECK_FAILED ; } #endif - return( 0 ); + return 0 ; } /* @@ -733,16 +733,16 @@ int mbedtls_rsa_check_pub_priv( const mbedtls_rsa_context *pub, if( mbedtls_rsa_check_pubkey( pub ) != 0 || mbedtls_rsa_check_privkey( prv ) != 0 ) { - return( MBEDTLS_ERR_RSA_KEY_CHECK_FAILED ); + return MBEDTLS_ERR_RSA_KEY_CHECK_FAILED ; } if( mbedtls_mpi_cmp_mpi( &pub->N, &prv->N ) != 0 || mbedtls_mpi_cmp_mpi( &pub->E, &prv->E ) != 0 ) { - return( MBEDTLS_ERR_RSA_KEY_CHECK_FAILED ); + return MBEDTLS_ERR_RSA_KEY_CHECK_FAILED ; } - return( 0 ); + return 0 ; } /* @@ -760,13 +760,13 @@ int mbedtls_rsa_public( mbedtls_rsa_context *ctx, RSA_VALIDATE_RET( output != NULL ); if( rsa_check_context( ctx, 0 /* public */, 0 /* no blinding */ ) ) - return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); + return MBEDTLS_ERR_RSA_BAD_INPUT_DATA ; mbedtls_mpi_init( &T ); #if defined(MBEDTLS_THREADING_C) if( ( ret = mbedtls_mutex_lock( &ctx->mutex ) ) != 0 ) - return( ret ); + return ret ; #endif MBEDTLS_MPI_CHK( mbedtls_mpi_read_binary( &T, input, ctx->len ) ); @@ -784,15 +784,15 @@ int mbedtls_rsa_public( mbedtls_rsa_context *ctx, cleanup: #if defined(MBEDTLS_THREADING_C) if( mbedtls_mutex_unlock( &ctx->mutex ) != 0 ) - return( MBEDTLS_ERR_THREADING_MUTEX_ERROR ); + return MBEDTLS_ERR_THREADING_MUTEX_ERROR ; #endif mbedtls_mpi_free( &T ); if( ret != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_RSA_PUBLIC_FAILED, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_RSA_PUBLIC_FAILED, ret ) ; - return( 0 ); + return 0 ; } /* @@ -857,7 +857,7 @@ static int rsa_prepare_blinding( mbedtls_rsa_context *ctx, cleanup: mbedtls_mpi_free( &R ); - return( ret ); + return ret ; } /* @@ -930,17 +930,17 @@ int mbedtls_rsa_private( mbedtls_rsa_context *ctx, RSA_VALIDATE_RET( output != NULL ); if( f_rng == NULL ) - return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); + return MBEDTLS_ERR_RSA_BAD_INPUT_DATA ; if( rsa_check_context( ctx, 1 /* private key checks */, 1 /* blinding on */ ) != 0 ) { - return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); + return MBEDTLS_ERR_RSA_BAD_INPUT_DATA ; } #if defined(MBEDTLS_THREADING_C) if( ( ret = mbedtls_mutex_lock( &ctx->mutex ) ) != 0 ) - return( ret ); + return ret ; #endif /* MPI Initialization */ @@ -1073,7 +1073,7 @@ int mbedtls_rsa_private( mbedtls_rsa_context *ctx, cleanup: #if defined(MBEDTLS_THREADING_C) if( mbedtls_mutex_unlock( &ctx->mutex ) != 0 ) - return( MBEDTLS_ERR_THREADING_MUTEX_ERROR ); + return MBEDTLS_ERR_THREADING_MUTEX_ERROR ; #endif mbedtls_mpi_free( &P1 ); @@ -1097,9 +1097,9 @@ cleanup: mbedtls_mpi_free( &I ); if( ret != 0 && ret >= -0x007f ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_RSA_PRIVATE_FAILED, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_RSA_PRIVATE_FAILED, ret ) ; - return( ret ); + return ret ; } #if defined(MBEDTLS_PKCS1_V21) @@ -1156,7 +1156,7 @@ static int mgf_mask( unsigned char *dst, size_t dlen, unsigned char *src, exit: mbedtls_platform_zeroize( mask, sizeof( mask ) ); - return( ret ); + return ret ; } #endif /* MBEDTLS_PKCS1_V21 */ @@ -1185,18 +1185,18 @@ int mbedtls_rsa_rsaes_oaep_encrypt( mbedtls_rsa_context *ctx, RSA_VALIDATE_RET( label_len == 0 || label != NULL ); if( f_rng == NULL ) - return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); + return MBEDTLS_ERR_RSA_BAD_INPUT_DATA ; md_info = mbedtls_md_info_from_type( (mbedtls_md_type_t) ctx->hash_id ); if( md_info == NULL ) - return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); + return MBEDTLS_ERR_RSA_BAD_INPUT_DATA ; olen = ctx->len; hlen = mbedtls_md_get_size( md_info ); /* first comparison checks for overflow */ if( ilen + 2 * hlen + 2 < ilen || olen < ilen + 2 * hlen + 2 ) - return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); + return MBEDTLS_ERR_RSA_BAD_INPUT_DATA ; memset( output, 0, olen ); @@ -1204,13 +1204,13 @@ int mbedtls_rsa_rsaes_oaep_encrypt( mbedtls_rsa_context *ctx, /* Generate a random octet string seed */ if( ( ret = f_rng( p_rng, p, hlen ) ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_RSA_RNG_FAILED, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_RSA_RNG_FAILED, ret ) ; p += hlen; /* Construct DB */ if( ( ret = mbedtls_md( md_info, label, label_len, p ) ) != 0 ) - return( ret ); + return ret ; p += hlen; p += olen - 2 * hlen - 2 - ilen; *p++ = 1; @@ -1235,9 +1235,9 @@ exit: mbedtls_md_free( &md_ctx ); if( ret != 0 ) - return( ret ); + return ret ; - return( mbedtls_rsa_public( ctx, output, output ) ); + return mbedtls_rsa_public( ctx, output, output ) ; } #endif /* MBEDTLS_PKCS1_V21 */ @@ -1263,14 +1263,14 @@ int mbedtls_rsa_rsaes_pkcs1_v15_encrypt( mbedtls_rsa_context *ctx, /* first comparison checks for overflow */ if( ilen + 11 < ilen || olen < ilen + 11 ) - return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); + return MBEDTLS_ERR_RSA_BAD_INPUT_DATA ; nb_pad = olen - 3 - ilen; *p++ = 0; if( f_rng == NULL ) - return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); + return MBEDTLS_ERR_RSA_BAD_INPUT_DATA ; *p++ = MBEDTLS_RSA_CRYPT; @@ -1284,7 +1284,7 @@ int mbedtls_rsa_rsaes_pkcs1_v15_encrypt( mbedtls_rsa_context *ctx, /* Check if RNG failed to generate data */ if( rng_dl == 0 || ret != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_RSA_RNG_FAILED, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_RSA_RNG_FAILED, ret ) ; p++; } @@ -1293,7 +1293,7 @@ int mbedtls_rsa_rsaes_pkcs1_v15_encrypt( mbedtls_rsa_context *ctx, if( ilen != 0 ) memcpy( p, input, ilen ); - return( mbedtls_rsa_public( ctx, output, output ) ); + return mbedtls_rsa_public( ctx, output, output ) ; } #endif /* MBEDTLS_PKCS1_V15 */ @@ -1326,7 +1326,7 @@ int mbedtls_rsa_pkcs1_encrypt( mbedtls_rsa_context *ctx, #endif default: - return( MBEDTLS_ERR_RSA_INVALID_PADDING ); + return MBEDTLS_ERR_RSA_INVALID_PADDING ; } } @@ -1362,22 +1362,22 @@ int mbedtls_rsa_rsaes_oaep_decrypt( mbedtls_rsa_context *ctx, * Parameters sanity checks */ if( ctx->padding != MBEDTLS_RSA_PKCS_V21 ) - return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); + return MBEDTLS_ERR_RSA_BAD_INPUT_DATA ; ilen = ctx->len; if( ilen < 16 || ilen > sizeof( buf ) ) - return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); + return MBEDTLS_ERR_RSA_BAD_INPUT_DATA ; md_info = mbedtls_md_info_from_type( (mbedtls_md_type_t) ctx->hash_id ); if( md_info == NULL ) - return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); + return MBEDTLS_ERR_RSA_BAD_INPUT_DATA ; hlen = mbedtls_md_get_size( md_info ); // checking for integer underflow if( 2 * hlen + 2 > ilen ) - return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); + return MBEDTLS_ERR_RSA_BAD_INPUT_DATA ; /* * RSA operation @@ -1468,7 +1468,7 @@ cleanup: mbedtls_platform_zeroize( buf, sizeof( buf ) ); mbedtls_platform_zeroize( lhash, sizeof( lhash ) ); - return( ret ); + return ret ; } #endif /* MBEDTLS_PKCS1_V21 */ @@ -1605,10 +1605,10 @@ int mbedtls_rsa_rsaes_pkcs1_v15_decrypt( mbedtls_rsa_context *ctx, output_max_len ); if( ctx->padding != MBEDTLS_RSA_PKCS_V15 ) - return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); + return MBEDTLS_ERR_RSA_BAD_INPUT_DATA ; if( ilen < 16 || ilen > sizeof( buf ) ) - return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); + return MBEDTLS_ERR_RSA_BAD_INPUT_DATA ; ret = mbedtls_rsa_private( ctx, f_rng, p_rng, input, buf ); @@ -1711,7 +1711,7 @@ int mbedtls_rsa_rsaes_pkcs1_v15_decrypt( mbedtls_rsa_context *ctx, cleanup: mbedtls_platform_zeroize( buf, sizeof( buf ) ); - return( ret ); + return ret ; } #endif /* MBEDTLS_PKCS1_V15 */ @@ -1747,7 +1747,7 @@ int mbedtls_rsa_pkcs1_decrypt( mbedtls_rsa_context *ctx, #endif default: - return( MBEDTLS_ERR_RSA_INVALID_PADDING ); + return MBEDTLS_ERR_RSA_INVALID_PADDING ; } } @@ -1776,10 +1776,10 @@ static int rsa_rsassa_pss_sign( mbedtls_rsa_context *ctx, RSA_VALIDATE_RET( sig != NULL ); if( ctx->padding != MBEDTLS_RSA_PKCS_V21 ) - return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); + return MBEDTLS_ERR_RSA_BAD_INPUT_DATA ; if( f_rng == NULL ) - return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); + return MBEDTLS_ERR_RSA_BAD_INPUT_DATA ; olen = ctx->len; @@ -1788,15 +1788,15 @@ static int rsa_rsassa_pss_sign( mbedtls_rsa_context *ctx, /* Gather length of hash to sign */ md_info = mbedtls_md_info_from_type( md_alg ); if( md_info == NULL ) - return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); + return MBEDTLS_ERR_RSA_BAD_INPUT_DATA ; if( hashlen != mbedtls_md_get_size( md_info ) ) - return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); + return MBEDTLS_ERR_RSA_BAD_INPUT_DATA ; } md_info = mbedtls_md_info_from_type( (mbedtls_md_type_t) ctx->hash_id ); if( md_info == NULL ) - return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); + return MBEDTLS_ERR_RSA_BAD_INPUT_DATA ; hlen = mbedtls_md_get_size( md_info ); @@ -1811,7 +1811,7 @@ static int rsa_rsassa_pss_sign( mbedtls_rsa_context *ctx, * (PKCS#1 v2.2) §9.1.1 step 3. */ min_slen = hlen - 2; if( olen < hlen + min_slen + 2 ) - return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); + return MBEDTLS_ERR_RSA_BAD_INPUT_DATA ; else if( olen >= hlen + hlen + 2 ) slen = hlen; else @@ -1819,7 +1819,7 @@ static int rsa_rsassa_pss_sign( mbedtls_rsa_context *ctx, } else if ( (saltlen < 0) || (saltlen + hlen + 2 > olen) ) { - return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); + return MBEDTLS_ERR_RSA_BAD_INPUT_DATA ; } else { @@ -1836,7 +1836,7 @@ static int rsa_rsassa_pss_sign( mbedtls_rsa_context *ctx, /* Generate salt of length slen in place in the encoded message */ salt = p; if( ( ret = f_rng( p_rng, salt, slen ) ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_RSA_RNG_FAILED, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_RSA_RNG_FAILED, ret ) ; p += slen; @@ -1875,7 +1875,7 @@ exit: mbedtls_md_free( &md_ctx ); if( ret != 0 ) - return( ret ); + return ret ; return mbedtls_rsa_private( ctx, f_rng, p_rng, sig, sig ); } @@ -1952,20 +1952,20 @@ static int rsa_rsassa_pkcs1_v15_encode( mbedtls_md_type_t md_alg, { const mbedtls_md_info_t *md_info = mbedtls_md_info_from_type( md_alg ); if( md_info == NULL ) - return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); + return MBEDTLS_ERR_RSA_BAD_INPUT_DATA ; if( mbedtls_oid_get_oid_by_md( md_alg, &oid, &oid_size ) != 0 ) - return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); + return MBEDTLS_ERR_RSA_BAD_INPUT_DATA ; if( hashlen != mbedtls_md_get_size( md_info ) ) - return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); + return MBEDTLS_ERR_RSA_BAD_INPUT_DATA ; /* Double-check that 8 + hashlen + oid_size can be used as a * 1-byte ASN.1 length encoding and that there's no overflow. */ if( 8 + hashlen + oid_size >= 0x80 || 10 + hashlen < hashlen || 10 + hashlen + oid_size < 10 + hashlen ) - return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); + return MBEDTLS_ERR_RSA_BAD_INPUT_DATA ; /* * Static bounds check: @@ -1976,13 +1976,13 @@ static int rsa_rsassa_pkcs1_v15_encode( mbedtls_md_type_t md_alg, * - Need oid_size bytes for hash alg OID. */ if( nb_pad < 10 + hashlen + oid_size ) - return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); + return MBEDTLS_ERR_RSA_BAD_INPUT_DATA ; nb_pad -= 10 + hashlen + oid_size; } else { if( nb_pad < hashlen ) - return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); + return MBEDTLS_ERR_RSA_BAD_INPUT_DATA ; nb_pad -= hashlen; } @@ -1990,7 +1990,7 @@ static int rsa_rsassa_pkcs1_v15_encode( mbedtls_md_type_t md_alg, /* Need space for signature header and padding delimiter (3 bytes), * and 8 bytes for the minimal padding */ if( nb_pad < 3 + 8 ) - return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); + return MBEDTLS_ERR_RSA_BAD_INPUT_DATA ; nb_pad -= 3; /* Now nb_pad is the amount of memory to be filled @@ -2007,7 +2007,7 @@ static int rsa_rsassa_pkcs1_v15_encode( mbedtls_md_type_t md_alg, if( md_alg == MBEDTLS_MD_NONE ) { memcpy( p, hash, hashlen ); - return( 0 ); + return 0 ; } /* Signing hashed data, add corresponding ASN.1 structure @@ -2043,10 +2043,10 @@ static int rsa_rsassa_pkcs1_v15_encode( mbedtls_md_type_t md_alg, if( p != dst + dst_len ) { mbedtls_platform_zeroize( dst, dst_len ); - return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); + return MBEDTLS_ERR_RSA_BAD_INPUT_DATA ; } - return( 0 ); + return 0 ; } /* @@ -2070,7 +2070,7 @@ int mbedtls_rsa_rsassa_pkcs1_v15_sign( mbedtls_rsa_context *ctx, RSA_VALIDATE_RET( sig != NULL ); if( ctx->padding != MBEDTLS_RSA_PKCS_V15 ) - return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); + return MBEDTLS_ERR_RSA_BAD_INPUT_DATA ; /* * Prepare PKCS1-v1.5 encoding (padding and hash identifier) @@ -2078,7 +2078,7 @@ int mbedtls_rsa_rsassa_pkcs1_v15_sign( mbedtls_rsa_context *ctx, if( ( ret = rsa_rsassa_pkcs1_v15_encode( md_alg, hashlen, hash, ctx->len, sig ) ) != 0 ) - return( ret ); + return ret ; /* Private key operation * @@ -2088,13 +2088,13 @@ int mbedtls_rsa_rsassa_pkcs1_v15_sign( mbedtls_rsa_context *ctx, sig_try = mbedtls_calloc( 1, ctx->len ); if( sig_try == NULL ) - return( MBEDTLS_ERR_MPI_ALLOC_FAILED ); + return MBEDTLS_ERR_MPI_ALLOC_FAILED ; verif = mbedtls_calloc( 1, ctx->len ); if( verif == NULL ) { mbedtls_free( sig_try ); - return( MBEDTLS_ERR_MPI_ALLOC_FAILED ); + return MBEDTLS_ERR_MPI_ALLOC_FAILED ; } MBEDTLS_MPI_CHK( mbedtls_rsa_private( ctx, f_rng, p_rng, sig, sig_try ) ); @@ -2112,7 +2112,7 @@ cleanup: mbedtls_free( sig_try ); mbedtls_free( verif ); - return( ret ); + return ret ; } #endif /* MBEDTLS_PKCS1_V15 */ @@ -2148,7 +2148,7 @@ int mbedtls_rsa_pkcs1_sign( mbedtls_rsa_context *ctx, #endif default: - return( MBEDTLS_ERR_RSA_INVALID_PADDING ); + return MBEDTLS_ERR_RSA_INVALID_PADDING ; } } @@ -2185,32 +2185,32 @@ int mbedtls_rsa_rsassa_pss_verify_ext( mbedtls_rsa_context *ctx, siglen = ctx->len; if( siglen < 16 || siglen > sizeof( buf ) ) - return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); + return MBEDTLS_ERR_RSA_BAD_INPUT_DATA ; ret = mbedtls_rsa_public( ctx, sig, buf ); if( ret != 0 ) - return( ret ); + return ret ; p = buf; if( buf[siglen - 1] != 0xBC ) - return( MBEDTLS_ERR_RSA_INVALID_PADDING ); + return MBEDTLS_ERR_RSA_INVALID_PADDING ; if( md_alg != MBEDTLS_MD_NONE ) { /* Gather length of hash to sign */ md_info = mbedtls_md_info_from_type( md_alg ); if( md_info == NULL ) - return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); + return MBEDTLS_ERR_RSA_BAD_INPUT_DATA ; if( hashlen != mbedtls_md_get_size( md_info ) ) - return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); + return MBEDTLS_ERR_RSA_BAD_INPUT_DATA ; } md_info = mbedtls_md_info_from_type( mgf1_hash_id ); if( md_info == NULL ) - return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); + return MBEDTLS_ERR_RSA_BAD_INPUT_DATA ; hlen = mbedtls_md_get_size( md_info ); @@ -2222,7 +2222,7 @@ int mbedtls_rsa_rsassa_pss_verify_ext( mbedtls_rsa_context *ctx, msb = mbedtls_mpi_bitlen( &ctx->N ) - 1; if( buf[0] >> ( 8 - siglen * 8 + msb ) ) - return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); + return MBEDTLS_ERR_RSA_BAD_INPUT_DATA ; /* Compensate for boundary condition when applying mask */ if( msb % 8 == 0 ) @@ -2232,7 +2232,7 @@ int mbedtls_rsa_rsassa_pss_verify_ext( mbedtls_rsa_context *ctx, } if( siglen < hlen + 2 ) - return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); + return MBEDTLS_ERR_RSA_BAD_INPUT_DATA ; hash_start = p + siglen - hlen - 1; mbedtls_md_init( &md_ctx ); @@ -2291,7 +2291,7 @@ int mbedtls_rsa_rsassa_pss_verify_ext( mbedtls_rsa_context *ctx, exit: mbedtls_md_free( &md_ctx ); - return( ret ); + return ret ; } /* @@ -2393,7 +2393,7 @@ cleanup: mbedtls_free( encoded_expected ); } - return( ret ); + return ret ; } #endif /* MBEDTLS_PKCS1_V15 */ @@ -2427,7 +2427,7 @@ int mbedtls_rsa_pkcs1_verify( mbedtls_rsa_context *ctx, #endif default: - return( MBEDTLS_ERR_RSA_INVALID_PADDING ); + return MBEDTLS_ERR_RSA_INVALID_PADDING ; } } @@ -2469,7 +2469,7 @@ cleanup: if( ret != 0 ) mbedtls_rsa_free( dst ); - return( ret ); + return ret ; } /* @@ -2570,7 +2570,7 @@ static int myrand( void *rng_state, unsigned char *output, size_t len ) arc4random_buf( output, len ); #endif /* !OpenBSD && !NetBSD */ - return( 0 ); + return 0 ; } #endif /* MBEDTLS_PKCS1_V15 */ @@ -2672,7 +2672,7 @@ int mbedtls_rsa_self_test( int verbose ) if( verbose != 0 ) mbedtls_printf( "failed\n" ); - return( 1 ); + return 1 ; } if( mbedtls_rsa_pkcs1_sign( &rsa, myrand, NULL, @@ -2712,7 +2712,7 @@ cleanup: #else /* MBEDTLS_PKCS1_V15 */ ((void) verbose); #endif /* MBEDTLS_PKCS1_V15 */ - return( ret ); + return ret ; } #endif /* MBEDTLS_SELF_TEST */ diff --git a/library/rsa_alt_helpers.c b/library/rsa_alt_helpers.c index dff2d93451..34ae7e1d8a 100644 --- a/library/rsa_alt_helpers.c +++ b/library/rsa_alt_helpers.c @@ -86,7 +86,7 @@ int mbedtls_rsa_deduce_primes( mbedtls_mpi const *N, const size_t num_primes = sizeof( primes ) / sizeof( *primes ); if( P == NULL || Q == NULL || P->p != NULL || Q->p != NULL ) - return( MBEDTLS_ERR_MPI_BAD_INPUT_DATA ); + return MBEDTLS_ERR_MPI_BAD_INPUT_DATA ; if( mbedtls_mpi_cmp_int( N, 0 ) <= 0 || mbedtls_mpi_cmp_int( D, 1 ) <= 0 || @@ -94,7 +94,7 @@ int mbedtls_rsa_deduce_primes( mbedtls_mpi const *N, mbedtls_mpi_cmp_int( E, 1 ) <= 0 || mbedtls_mpi_cmp_mpi( E, N ) >= 0 ) { - return( MBEDTLS_ERR_MPI_BAD_INPUT_DATA ); + return MBEDTLS_ERR_MPI_BAD_INPUT_DATA ; } /* @@ -187,7 +187,7 @@ cleanup: mbedtls_mpi_free( &K ); mbedtls_mpi_free( &T ); - return( ret ); + return ret ; } /* @@ -203,13 +203,13 @@ int mbedtls_rsa_deduce_private_exponent( mbedtls_mpi const *P, mbedtls_mpi K, L; if( D == NULL || mbedtls_mpi_cmp_int( D, 0 ) != 0 ) - return( MBEDTLS_ERR_MPI_BAD_INPUT_DATA ); + return MBEDTLS_ERR_MPI_BAD_INPUT_DATA ; if( mbedtls_mpi_cmp_int( P, 1 ) <= 0 || mbedtls_mpi_cmp_int( Q, 1 ) <= 0 || mbedtls_mpi_cmp_int( E, 0 ) == 0 ) { - return( MBEDTLS_ERR_MPI_BAD_INPUT_DATA ); + return MBEDTLS_ERR_MPI_BAD_INPUT_DATA ; } mbedtls_mpi_init( &K ); @@ -234,7 +234,7 @@ cleanup: mbedtls_mpi_free( &K ); mbedtls_mpi_free( &L ); - return( ret ); + return ret ; } int mbedtls_rsa_deduce_crt( const mbedtls_mpi *P, const mbedtls_mpi *Q, @@ -268,7 +268,7 @@ int mbedtls_rsa_deduce_crt( const mbedtls_mpi *P, const mbedtls_mpi *Q, cleanup: mbedtls_mpi_free( &K ); - return( ret ); + return ret ; } /* @@ -392,7 +392,7 @@ cleanup: ret += MBEDTLS_ERR_RSA_KEY_CHECK_FAILED; } - return( ret ); + return ret ; } /* @@ -480,7 +480,7 @@ cleanup: mbedtls_mpi_free( &K ); mbedtls_mpi_free( &L ); - return( ret ); + return ret ; } #endif /* MBEDTLS_RSA_C */ diff --git a/library/sha1.c b/library/sha1.c index 545d093109..582b91bbc1 100644 --- a/library/sha1.c +++ b/library/sha1.c @@ -111,7 +111,7 @@ int mbedtls_sha1_starts( mbedtls_sha1_context *ctx ) ctx->state[3] = 0x10325476; ctx->state[4] = 0xC3D2E1F0; - return( 0 ); + return 0 ; } #if !defined(MBEDTLS_SHA1_PROCESS_ALT) @@ -284,7 +284,7 @@ int mbedtls_internal_sha1_process( mbedtls_sha1_context *ctx, /* Zeroise buffers and variables to clear sensitive data from memory. */ mbedtls_platform_zeroize( &local, sizeof( local ) ); - return( 0 ); + return 0 ; } #endif /* !MBEDTLS_SHA1_PROCESS_ALT */ @@ -304,7 +304,7 @@ int mbedtls_sha1_update( mbedtls_sha1_context *ctx, SHA1_VALIDATE_RET( ilen == 0 || input != NULL ); if( ilen == 0 ) - return( 0 ); + return 0 ; left = ctx->total[0] & 0x3F; fill = 64 - left; @@ -320,7 +320,7 @@ int mbedtls_sha1_update( mbedtls_sha1_context *ctx, memcpy( (void *) (ctx->buffer + left), input, fill ); if( ( ret = mbedtls_internal_sha1_process( ctx, ctx->buffer ) ) != 0 ) - return( ret ); + return ret ; input += fill; ilen -= fill; @@ -330,7 +330,7 @@ int mbedtls_sha1_update( mbedtls_sha1_context *ctx, while( ilen >= 64 ) { if( ( ret = mbedtls_internal_sha1_process( ctx, input ) ) != 0 ) - return( ret ); + return ret ; input += 64; ilen -= 64; @@ -339,7 +339,7 @@ int mbedtls_sha1_update( mbedtls_sha1_context *ctx, if( ilen > 0 ) memcpy( (void *) (ctx->buffer + left), input, ilen ); - return( 0 ); + return 0 ; } /* @@ -373,7 +373,7 @@ int mbedtls_sha1_finish( mbedtls_sha1_context *ctx, memset( ctx->buffer + used, 0, 64 - used ); if( ( ret = mbedtls_internal_sha1_process( ctx, ctx->buffer ) ) != 0 ) - return( ret ); + return ret ; memset( ctx->buffer, 0, 56 ); } @@ -389,7 +389,7 @@ int mbedtls_sha1_finish( mbedtls_sha1_context *ctx, PUT_UINT32_BE( low, ctx->buffer, 60 ); if( ( ret = mbedtls_internal_sha1_process( ctx, ctx->buffer ) ) != 0 ) - return( ret ); + return ret ; /* * Output final state @@ -400,7 +400,7 @@ int mbedtls_sha1_finish( mbedtls_sha1_context *ctx, PUT_UINT32_BE( ctx->state[3], output, 12 ); PUT_UINT32_BE( ctx->state[4], output, 16 ); - return( 0 ); + return 0 ; } #endif /* !MBEDTLS_SHA1_ALT */ @@ -432,7 +432,7 @@ int mbedtls_sha1( const unsigned char *input, exit: mbedtls_sha1_free( &ctx ); - return( ret ); + return ret ; } #if defined(MBEDTLS_SELF_TEST) @@ -528,7 +528,7 @@ fail: exit: mbedtls_sha1_free( &ctx ); - return( ret ); + return ret ; } #endif /* MBEDTLS_SELF_TEST */ diff --git a/library/sha256.c b/library/sha256.c index 6ec6da296a..017bac6259 100644 --- a/library/sha256.c +++ b/library/sha256.c @@ -142,7 +142,7 @@ int mbedtls_sha256_starts( mbedtls_sha256_context *ctx, int is224 ) ctx->is224 = is224; - return( 0 ); + return 0 ; } #if !defined(MBEDTLS_SHA256_PROCESS_ALT) @@ -277,7 +277,7 @@ int mbedtls_internal_sha256_process( mbedtls_sha256_context *ctx, /* Zeroise buffers and variables to clear sensitive data from memory. */ mbedtls_platform_zeroize( &local, sizeof( local ) ); - return( 0 ); + return 0 ; } #endif /* !MBEDTLS_SHA256_PROCESS_ALT */ @@ -297,7 +297,7 @@ int mbedtls_sha256_update( mbedtls_sha256_context *ctx, SHA256_VALIDATE_RET( ilen == 0 || input != NULL ); if( ilen == 0 ) - return( 0 ); + return 0 ; left = ctx->total[0] & 0x3F; fill = 64 - left; @@ -313,7 +313,7 @@ int mbedtls_sha256_update( mbedtls_sha256_context *ctx, memcpy( (void *) (ctx->buffer + left), input, fill ); if( ( ret = mbedtls_internal_sha256_process( ctx, ctx->buffer ) ) != 0 ) - return( ret ); + return ret ; input += fill; ilen -= fill; @@ -323,7 +323,7 @@ int mbedtls_sha256_update( mbedtls_sha256_context *ctx, while( ilen >= 64 ) { if( ( ret = mbedtls_internal_sha256_process( ctx, input ) ) != 0 ) - return( ret ); + return ret ; input += 64; ilen -= 64; @@ -332,7 +332,7 @@ int mbedtls_sha256_update( mbedtls_sha256_context *ctx, if( ilen > 0 ) memcpy( (void *) (ctx->buffer + left), input, ilen ); - return( 0 ); + return 0 ; } /* @@ -366,7 +366,7 @@ int mbedtls_sha256_finish( mbedtls_sha256_context *ctx, memset( ctx->buffer + used, 0, 64 - used ); if( ( ret = mbedtls_internal_sha256_process( ctx, ctx->buffer ) ) != 0 ) - return( ret ); + return ret ; memset( ctx->buffer, 0, 56 ); } @@ -382,7 +382,7 @@ int mbedtls_sha256_finish( mbedtls_sha256_context *ctx, PUT_UINT32_BE( low, ctx->buffer, 60 ); if( ( ret = mbedtls_internal_sha256_process( ctx, ctx->buffer ) ) != 0 ) - return( ret ); + return ret ; /* * Output final state @@ -400,7 +400,7 @@ int mbedtls_sha256_finish( mbedtls_sha256_context *ctx, #endif PUT_UINT32_BE( ctx->state[7], output, 28 ); - return( 0 ); + return 0 ; } #endif /* !MBEDTLS_SHA256_ALT */ @@ -439,7 +439,7 @@ int mbedtls_sha256( const unsigned char *input, exit: mbedtls_sha256_free( &ctx ); - return( ret ); + return ret ; } #if defined(MBEDTLS_SELF_TEST) @@ -509,7 +509,7 @@ int mbedtls_sha256_self_test( int verbose ) if( verbose != 0 ) mbedtls_printf( "Buffer allocation failed\n" ); - return( 1 ); + return 1 ; } mbedtls_sha256_init( &ctx ); @@ -572,7 +572,7 @@ exit: mbedtls_sha256_free( &ctx ); mbedtls_free( buf ); - return( ret ); + return ret ; } #endif /* MBEDTLS_SELF_TEST */ diff --git a/library/sha512.c b/library/sha512.c index 6511c6e36a..d3f36e35d1 100644 --- a/library/sha512.c +++ b/library/sha512.c @@ -150,7 +150,7 @@ int mbedtls_sha512_starts( mbedtls_sha512_context *ctx, int is384 ) else { #if !defined(MBEDTLS_SHA384_C) - return( MBEDTLS_ERR_SHA512_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SHA512_BAD_INPUT_DATA ; #else /* SHA-384 */ ctx->state[0] = UL64(0xCBBB9D5DC1059ED8); @@ -168,7 +168,7 @@ int mbedtls_sha512_starts( mbedtls_sha512_context *ctx, int is384 ) ctx->is384 = is384; #endif - return( 0 ); + return 0 ; } #if !defined(MBEDTLS_SHA512_PROCESS_ALT) @@ -319,7 +319,7 @@ int mbedtls_internal_sha512_process( mbedtls_sha512_context *ctx, /* Zeroise buffers and variables to clear sensitive data from memory. */ mbedtls_platform_zeroize( &local, sizeof( local ) ); - return( 0 ); + return 0 ; } #endif /* !MBEDTLS_SHA512_PROCESS_ALT */ @@ -339,7 +339,7 @@ int mbedtls_sha512_update( mbedtls_sha512_context *ctx, SHA512_VALIDATE_RET( ilen == 0 || input != NULL ); if( ilen == 0 ) - return( 0 ); + return 0 ; left = (unsigned int) (ctx->total[0] & 0x7F); fill = 128 - left; @@ -354,7 +354,7 @@ int mbedtls_sha512_update( mbedtls_sha512_context *ctx, memcpy( (void *) (ctx->buffer + left), input, fill ); if( ( ret = mbedtls_internal_sha512_process( ctx, ctx->buffer ) ) != 0 ) - return( ret ); + return ret ; input += fill; ilen -= fill; @@ -364,7 +364,7 @@ int mbedtls_sha512_update( mbedtls_sha512_context *ctx, while( ilen >= 128 ) { if( ( ret = mbedtls_internal_sha512_process( ctx, input ) ) != 0 ) - return( ret ); + return ret ; input += 128; ilen -= 128; @@ -373,7 +373,7 @@ int mbedtls_sha512_update( mbedtls_sha512_context *ctx, if( ilen > 0 ) memcpy( (void *) (ctx->buffer + left), input, ilen ); - return( 0 ); + return 0 ; } /* @@ -407,7 +407,7 @@ int mbedtls_sha512_finish( mbedtls_sha512_context *ctx, memset( ctx->buffer + used, 0, 128 - used ); if( ( ret = mbedtls_internal_sha512_process( ctx, ctx->buffer ) ) != 0 ) - return( ret ); + return ret ; memset( ctx->buffer, 0, 112 ); } @@ -423,7 +423,7 @@ int mbedtls_sha512_finish( mbedtls_sha512_context *ctx, sha512_put_uint64_be( low, ctx->buffer, 120 ); if( ( ret = mbedtls_internal_sha512_process( ctx, ctx->buffer ) ) != 0 ) - return( ret ); + return ret ; /* * Output final state @@ -443,7 +443,7 @@ int mbedtls_sha512_finish( mbedtls_sha512_context *ctx, sha512_put_uint64_be( ctx->state[7], output, 56 ); } - return( 0 ); + return 0 ; } #endif /* !MBEDTLS_SHA512_ALT */ @@ -481,7 +481,7 @@ int mbedtls_sha512( const unsigned char *input, exit: mbedtls_sha512_free( &ctx ); - return( ret ); + return ret ; } #if defined(MBEDTLS_SELF_TEST) @@ -574,7 +574,7 @@ int mbedtls_sha512_self_test( int verbose ) if( verbose != 0 ) mbedtls_printf( "Buffer allocation failed\n" ); - return( 1 ); + return 1 ; } mbedtls_sha512_init( &ctx ); @@ -639,7 +639,7 @@ exit: mbedtls_sha512_free( &ctx ); mbedtls_free( buf ); - return( ret ); + return ret ; } #undef ARRAY_LENGTH diff --git a/library/ssl_cache.c b/library/ssl_cache.c index fe4f30cf8d..a2ee0a2c72 100644 --- a/library/ssl_cache.c +++ b/library/ssl_cache.c @@ -85,7 +85,7 @@ static int ssl_cache_find_entry( mbedtls_ssl_cache_context *cache, ret = 0; } - return( ret ); + return ret ; } @@ -100,7 +100,7 @@ int mbedtls_ssl_cache_get( void *data, #if defined(MBEDTLS_THREADING_C) if( mbedtls_mutex_lock( &cache->mutex ) != 0 ) - return( 1 ); + return 1 ; #endif ret = ssl_cache_find_entry( cache, session_id, session_id_len, &entry ); @@ -121,7 +121,7 @@ exit: ret = 1; #endif - return( ret ); + return ret ; } static int ssl_cache_pick_writing_slot( mbedtls_ssl_cache_context *cache, @@ -188,7 +188,7 @@ static int ssl_cache_pick_writing_slot( mbedtls_ssl_cache_context *cache, /* Create new entry */ cur = mbedtls_calloc( 1, sizeof(mbedtls_ssl_cache_entry) ); if( cur == NULL ) - return( 1 ); + return 1 ; /* Append to the end of the linked list. */ if( last == NULL ) @@ -208,12 +208,12 @@ static int ssl_cache_pick_writing_slot( mbedtls_ssl_cache_context *cache, { /* This should only happen on an ill-configured cache * with max_entries == 0. */ - return( 1 ); + return 1 ; } #else /* MBEDTLS_HAVE_TIME */ /* Reuse first entry in chain, but move to last place. */ if( cache->chain == NULL ) - return( 1 ); + return 1 ; old = cache->chain; cache->chain = old->next; @@ -241,7 +241,7 @@ found: } *dst = cur; - return( 0 ); + return 0 ; } int mbedtls_ssl_cache_set( void *data, @@ -258,7 +258,7 @@ int mbedtls_ssl_cache_set( void *data, #if defined(MBEDTLS_THREADING_C) if( ( ret = mbedtls_mutex_lock( &cache->mutex ) ) != 0 ) - return( ret ); + return ret ; #endif ret = ssl_cache_pick_writing_slot( cache, @@ -314,7 +314,7 @@ exit: if( session_serialized != NULL ) mbedtls_platform_zeroize( session_serialized, session_serialized_len ); - return( ret ); + return ret ; } #if defined(MBEDTLS_HAVE_TIME) diff --git a/library/ssl_ciphersuites.c b/library/ssl_ciphersuites.c index a3ee157d50..e7eaee20f8 100644 --- a/library/ssl_ciphersuites.c +++ b/library/ssl_ciphersuites.c @@ -1905,7 +1905,7 @@ static const mbedtls_ssl_ciphersuite_t ciphersuite_definitions[] = #if defined(MBEDTLS_SSL_CIPHERSUITES) const int *mbedtls_ssl_list_ciphersuites( void ) { - return( ciphersuite_preference ); + return ciphersuite_preference ; } #else #define MAX_CIPHERSUITES sizeof( ciphersuite_definitions ) / \ @@ -1917,7 +1917,7 @@ static int ciphersuite_is_removed( const mbedtls_ssl_ciphersuite_t *cs_info ) { (void)cs_info; - return( 0 ); + return 0 ; } const int *mbedtls_ssl_list_ciphersuites( void ) @@ -1947,7 +1947,7 @@ const int *mbedtls_ssl_list_ciphersuites( void ) supported_init = 1; } - return( supported_ciphersuites ); + return supported_ciphersuites ; } #endif /* MBEDTLS_SSL_CIPHERSUITES */ @@ -1957,17 +1957,17 @@ const mbedtls_ssl_ciphersuite_t *mbedtls_ssl_ciphersuite_from_string( const mbedtls_ssl_ciphersuite_t *cur = ciphersuite_definitions; if( NULL == ciphersuite_name ) - return( NULL ); + return NULL ; while( cur->id != 0 ) { if( 0 == strcmp( cur->name, ciphersuite_name ) ) - return( cur ); + return cur ; cur++; } - return( NULL ); + return NULL ; } const mbedtls_ssl_ciphersuite_t *mbedtls_ssl_ciphersuite_from_id( int ciphersuite ) @@ -1977,12 +1977,12 @@ const mbedtls_ssl_ciphersuite_t *mbedtls_ssl_ciphersuite_from_id( int ciphersuit while( cur->id != 0 ) { if( cur->id == ciphersuite ) - return( cur ); + return cur ; cur++; } - return( NULL ); + return NULL ; } const char *mbedtls_ssl_get_ciphersuite_name( const int ciphersuite_id ) @@ -1992,9 +1992,9 @@ const char *mbedtls_ssl_get_ciphersuite_name( const int ciphersuite_id ) cur = mbedtls_ssl_ciphersuite_from_id( ciphersuite_id ); if( cur == NULL ) - return( "unknown" ); + return "unknown" ; - return( cur->name ); + return cur->name ; } int mbedtls_ssl_get_ciphersuite_id( const char *ciphersuite_name ) @@ -2004,9 +2004,9 @@ int mbedtls_ssl_get_ciphersuite_id( const char *ciphersuite_name ) cur = mbedtls_ssl_ciphersuite_from_string( ciphersuite_name ); if( cur == NULL ) - return( 0 ); + return 0 ; - return( cur->id ); + return cur->id ; } #if defined(MBEDTLS_PK_C) @@ -2018,17 +2018,17 @@ mbedtls_pk_type_t mbedtls_ssl_get_ciphersuite_sig_pk_alg( const mbedtls_ssl_ciph case MBEDTLS_KEY_EXCHANGE_DHE_RSA: case MBEDTLS_KEY_EXCHANGE_ECDHE_RSA: case MBEDTLS_KEY_EXCHANGE_RSA_PSK: - return( MBEDTLS_PK_RSA ); + return MBEDTLS_PK_RSA ; case MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA: - return( MBEDTLS_PK_ECDSA ); + return MBEDTLS_PK_ECDSA ; case MBEDTLS_KEY_EXCHANGE_ECDH_RSA: case MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA: - return( MBEDTLS_PK_ECKEY ); + return MBEDTLS_PK_ECKEY ; default: - return( MBEDTLS_PK_NONE ); + return MBEDTLS_PK_NONE ; } } @@ -2039,13 +2039,13 @@ mbedtls_pk_type_t mbedtls_ssl_get_ciphersuite_sig_alg( const mbedtls_ssl_ciphers case MBEDTLS_KEY_EXCHANGE_RSA: case MBEDTLS_KEY_EXCHANGE_DHE_RSA: case MBEDTLS_KEY_EXCHANGE_ECDHE_RSA: - return( MBEDTLS_PK_RSA ); + return MBEDTLS_PK_RSA ; case MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA: - return( MBEDTLS_PK_ECDSA ); + return MBEDTLS_PK_ECDSA ; default: - return( MBEDTLS_PK_NONE ); + return MBEDTLS_PK_NONE ; } } @@ -2063,10 +2063,10 @@ int mbedtls_ssl_ciphersuite_uses_ec( const mbedtls_ssl_ciphersuite_t *info ) case MBEDTLS_KEY_EXCHANGE_ECDH_RSA: case MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA: case MBEDTLS_KEY_EXCHANGE_ECJPAKE: - return( 1 ); + return 1 ; default: - return( 0 ); + return 0 ; } } #endif /* MBEDTLS_ECDH_C || MBEDTLS_ECDSA_C || MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED*/ @@ -2080,10 +2080,10 @@ int mbedtls_ssl_ciphersuite_uses_psk( const mbedtls_ssl_ciphersuite_t *info ) case MBEDTLS_KEY_EXCHANGE_RSA_PSK: case MBEDTLS_KEY_EXCHANGE_DHE_PSK: case MBEDTLS_KEY_EXCHANGE_ECDHE_PSK: - return( 1 ); + return 1 ; default: - return( 0 ); + return 0 ; } } #endif /* MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED */ diff --git a/library/ssl_cli.c b/library/ssl_cli.c index e0a1c24ec1..d9944cf3d5 100644 --- a/library/ssl_cli.c +++ b/library/ssl_cli.c @@ -56,18 +56,18 @@ static int ssl_conf_has_static_psk( mbedtls_ssl_config const *conf ) if( conf->psk_identity == NULL || conf->psk_identity_len == 0 ) { - return( 0 ); + return 0 ; } if( conf->psk != NULL && conf->psk_len != 0 ) - return( 1 ); + return 1 ; #if defined(MBEDTLS_USE_PSA_CRYPTO) if( ! mbedtls_svc_key_id_is_null( conf->psk_opaque ) ) - return( 1 ); + return 1 ; #endif /* MBEDTLS_USE_PSA_CRYPTO */ - return( 0 ); + return 0 ; } #if defined(MBEDTLS_USE_PSA_CRYPTO) @@ -76,13 +76,13 @@ static int ssl_conf_has_static_raw_psk( mbedtls_ssl_config const *conf ) if( conf->psk_identity == NULL || conf->psk_identity_len == 0 ) { - return( 0 ); + return 0 ; } if( conf->psk != NULL && conf->psk_len != 0 ) - return( 1 ); + return 1 ; - return( 0 ); + return 0 ; } #endif /* MBEDTLS_USE_PSA_CRYPTO */ @@ -100,7 +100,7 @@ static int ssl_write_hostname_ext( mbedtls_ssl_context *ssl, *olen = 0; if( ssl->hostname == NULL ) - return( 0 ); + return 0 ; MBEDTLS_SSL_DEBUG_MSG( 3, ( "client hello, adding server name extension: %s", @@ -153,7 +153,7 @@ static int ssl_write_hostname_ext( mbedtls_ssl_context *ssl, *olen = hostname_len + 9; - return( 0 ); + return 0 ; } #endif /* MBEDTLS_SSL_SERVER_NAME_INDICATION */ @@ -171,7 +171,7 @@ static int ssl_write_renegotiation_ext( mbedtls_ssl_context *ssl, * initial ClientHello, in which case also adding the renegotiation * info extension is NOT RECOMMENDED as per RFC 5746 Section 3.4. */ if( ssl->renego_status != MBEDTLS_SSL_RENEGOTIATION_IN_PROGRESS ) - return( 0 ); + return 0 ; MBEDTLS_SSL_DEBUG_MSG( 3, ( "client hello, adding renegotiation extension" ) ); @@ -194,7 +194,7 @@ static int ssl_write_renegotiation_ext( mbedtls_ssl_context *ssl, *olen = 5 + ssl->verify_data_len; - return( 0 ); + return 0 ; } #endif /* MBEDTLS_SSL_RENEGOTIATION */ @@ -219,13 +219,13 @@ static int ssl_write_signature_algorithms_ext( mbedtls_ssl_context *ssl, *olen = 0; if( ssl->conf->max_minor_ver != MBEDTLS_SSL_MINOR_VERSION_3 ) - return( 0 ); + return 0 ; MBEDTLS_SSL_DEBUG_MSG( 3, ( "client hello, adding signature_algorithms extension" ) ); if( ssl->conf->sig_hashes == NULL ) - return( MBEDTLS_ERR_SSL_BAD_CONFIG ); + return MBEDTLS_ERR_SSL_BAD_CONFIG ; for( md = ssl->conf->sig_hashes; *md != MBEDTLS_MD_NONE; md++ ) { @@ -239,13 +239,13 @@ static int ssl_write_signature_algorithms_ext( mbedtls_ssl_context *ssl, { MBEDTLS_SSL_DEBUG_MSG( 3, ( "length in bytes of sig-hash-alg extension too big" ) ); - return( MBEDTLS_ERR_SSL_BAD_CONFIG ); + return MBEDTLS_ERR_SSL_BAD_CONFIG ; } } /* Empty signature algorithms list, this is a configuration error. */ if( sig_alg_len == 0 ) - return( MBEDTLS_ERR_SSL_BAD_CONFIG ); + return MBEDTLS_ERR_SSL_BAD_CONFIG ; MBEDTLS_SSL_CHK_BUF_PTR( p, end, sig_alg_len + 6 ); @@ -294,7 +294,7 @@ static int ssl_write_signature_algorithms_ext( mbedtls_ssl_context *ssl, *olen = 6 + sig_alg_len; - return( 0 ); + return 0 ; } #endif /* MBEDTLS_SSL_PROTO_TLS1_2 && MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED */ @@ -318,7 +318,7 @@ static int ssl_write_supported_elliptic_curves_ext( mbedtls_ssl_context *ssl, ( "client hello, adding supported_elliptic_curves extension" ) ); if( ssl->conf->curve_list == NULL ) - return( MBEDTLS_ERR_SSL_BAD_CONFIG ); + return MBEDTLS_ERR_SSL_BAD_CONFIG ; for( grp_id = ssl->conf->curve_list; *grp_id != MBEDTLS_ECP_DP_NONE; @@ -329,7 +329,7 @@ static int ssl_write_supported_elliptic_curves_ext( mbedtls_ssl_context *ssl, { MBEDTLS_SSL_DEBUG_MSG( 1, ( "invalid curve in ssl configuration" ) ); - return( MBEDTLS_ERR_SSL_BAD_CONFIG ); + return MBEDTLS_ERR_SSL_BAD_CONFIG ; } elliptic_curve_len += 2; @@ -337,13 +337,13 @@ static int ssl_write_supported_elliptic_curves_ext( mbedtls_ssl_context *ssl, { MBEDTLS_SSL_DEBUG_MSG( 3, ( "malformed supported_elliptic_curves extension in config" ) ); - return( MBEDTLS_ERR_SSL_BAD_CONFIG ); + return MBEDTLS_ERR_SSL_BAD_CONFIG ; } } /* Empty elliptic curve list, this is a configuration error. */ if( elliptic_curve_len == 0 ) - return( MBEDTLS_ERR_SSL_BAD_CONFIG ); + return MBEDTLS_ERR_SSL_BAD_CONFIG ; MBEDTLS_SSL_CHK_BUF_PTR( p, end, 6 + elliptic_curve_len ); @@ -371,7 +371,7 @@ static int ssl_write_supported_elliptic_curves_ext( mbedtls_ssl_context *ssl, *olen = 6 + elliptic_curve_len; - return( 0 ); + return 0 ; } static int ssl_write_supported_point_formats_ext( mbedtls_ssl_context *ssl, @@ -401,7 +401,7 @@ static int ssl_write_supported_point_formats_ext( mbedtls_ssl_context *ssl, *olen = 6; - return( 0 ); + return 0 ; } #endif /* MBEDTLS_ECDH_C || MBEDTLS_ECDSA_C || MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED */ @@ -420,7 +420,7 @@ static int ssl_write_ecjpake_kkpp_ext( mbedtls_ssl_context *ssl, /* Skip costly extension if we can't use EC J-PAKE anyway */ if( mbedtls_ecjpake_check( &ssl->handshake->ecjpake_ctx ) != 0 ) - return( 0 ); + return 0 ; MBEDTLS_SSL_DEBUG_MSG( 3, ( "client hello, adding ecjpake_kkpp extension" ) ); @@ -447,14 +447,14 @@ static int ssl_write_ecjpake_kkpp_ext( mbedtls_ssl_context *ssl, { MBEDTLS_SSL_DEBUG_RET( 1 , "mbedtls_ecjpake_write_round_one", ret ); - return( ret ); + return ret ; } ssl->handshake->ecjpake_cache = mbedtls_calloc( 1, kkpp_len ); if( ssl->handshake->ecjpake_cache == NULL ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "allocation failed" ) ); - return( MBEDTLS_ERR_SSL_ALLOC_FAILED ); + return MBEDTLS_ERR_SSL_ALLOC_FAILED ; } memcpy( ssl->handshake->ecjpake_cache, p + 2, kkpp_len ); @@ -475,7 +475,7 @@ static int ssl_write_ecjpake_kkpp_ext( mbedtls_ssl_context *ssl, *olen = kkpp_len + 4; - return( 0 ); + return 0 ; } #endif /* MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED */ @@ -501,7 +501,7 @@ static int ssl_write_cid_ext( mbedtls_ssl_context *ssl, if( ssl->conf->transport != MBEDTLS_SSL_TRANSPORT_DATAGRAM || ssl->negotiate_cid == MBEDTLS_SSL_CID_DISABLED ) { - return( 0 ); + return 0 ; } MBEDTLS_SSL_DEBUG_MSG( 3, ( "client hello, adding CID extension" ) ); @@ -521,7 +521,7 @@ static int ssl_write_cid_ext( mbedtls_ssl_context *ssl, *olen = ssl->own_cid_len + 5; - return( 0 ); + return 0 ; } #endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */ @@ -536,7 +536,7 @@ static int ssl_write_max_fragment_length_ext( mbedtls_ssl_context *ssl, *olen = 0; if( ssl->conf->mfl_code == MBEDTLS_SSL_MAX_FRAG_LEN_NONE ) - return( 0 ); + return 0 ; MBEDTLS_SSL_DEBUG_MSG( 3, ( "client hello, adding max_fragment_length extension" ) ); @@ -555,7 +555,7 @@ static int ssl_write_max_fragment_length_ext( mbedtls_ssl_context *ssl, *olen = 5; - return( 0 ); + return 0 ; } #endif /* MBEDTLS_SSL_MAX_FRAGMENT_LENGTH */ @@ -570,7 +570,7 @@ static int ssl_write_encrypt_then_mac_ext( mbedtls_ssl_context *ssl, *olen = 0; if( ssl->conf->encrypt_then_mac == MBEDTLS_SSL_ETM_DISABLED ) - return( 0 ); + return 0 ; MBEDTLS_SSL_DEBUG_MSG( 3, ( "client hello, adding encrypt_then_mac extension" ) ); @@ -585,7 +585,7 @@ static int ssl_write_encrypt_then_mac_ext( mbedtls_ssl_context *ssl, *olen = 4; - return( 0 ); + return 0 ; } #endif /* MBEDTLS_SSL_ENCRYPT_THEN_MAC */ @@ -600,7 +600,7 @@ static int ssl_write_extended_ms_ext( mbedtls_ssl_context *ssl, *olen = 0; if( ssl->conf->extended_ms == MBEDTLS_SSL_EXTENDED_MS_DISABLED ) - return( 0 ); + return 0 ; MBEDTLS_SSL_DEBUG_MSG( 3, ( "client hello, adding extended_master_secret extension" ) ); @@ -617,7 +617,7 @@ static int ssl_write_extended_ms_ext( mbedtls_ssl_context *ssl, *olen = 4; - return( 0 ); + return 0 ; } #endif /* MBEDTLS_SSL_EXTENDED_MASTER_SECRET */ @@ -633,7 +633,7 @@ static int ssl_write_session_ticket_ext( mbedtls_ssl_context *ssl, *olen = 0; if( ssl->conf->session_tickets == MBEDTLS_SSL_SESSION_TICKETS_DISABLED ) - return( 0 ); + return 0 ; MBEDTLS_SSL_DEBUG_MSG( 3, ( "client hello, adding session ticket extension" ) ); @@ -650,7 +650,7 @@ static int ssl_write_session_ticket_ext( mbedtls_ssl_context *ssl, *olen = 4; if( ssl->session_negotiate->ticket == NULL || tlen == 0 ) - return( 0 ); + return 0 ; MBEDTLS_SSL_DEBUG_MSG( 3, ( "sending session ticket of length %" MBEDTLS_PRINTF_SIZET, tlen ) ); @@ -659,7 +659,7 @@ static int ssl_write_session_ticket_ext( mbedtls_ssl_context *ssl, *olen += tlen; - return( 0 ); + return 0 ; } #endif /* MBEDTLS_SSL_SESSION_TICKETS */ @@ -676,7 +676,7 @@ static int ssl_write_alpn_ext( mbedtls_ssl_context *ssl, *olen = 0; if( ssl->conf->alpn_list == NULL ) - return( 0 ); + return 0 ; MBEDTLS_SSL_DEBUG_MSG( 3, ( "client hello, adding alpn extension" ) ); @@ -720,7 +720,7 @@ static int ssl_write_alpn_ext( mbedtls_ssl_context *ssl, buf[2] = (unsigned char)( ( ( *olen - 4 ) >> 8 ) & 0xFF ); buf[3] = (unsigned char)( ( ( *olen - 4 ) ) & 0xFF ); - return( 0 ); + return 0 ; } #endif /* MBEDTLS_SSL_ALPN */ @@ -740,7 +740,7 @@ static int ssl_write_use_srtp_ext( mbedtls_ssl_context *ssl, ( ssl->conf->dtls_srtp_profile_list == NULL ) || ( ssl->conf->dtls_srtp_profile_list_len == 0 ) ) { - return( 0 ); + return 0 ; } /* RFC 5764 section 4.1.1 @@ -813,7 +813,7 @@ static int ssl_write_use_srtp_ext( mbedtls_ssl_context *ssl, "illegal DTLS-SRTP protection profile %d", ssl->conf->dtls_srtp_profile_list[protection_profiles_index] ) ); - return( MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED ); + return MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED ; } } @@ -840,7 +840,7 @@ static int ssl_write_use_srtp_ext( mbedtls_ssl_context *ssl, */ *olen = p - buf; - return( 0 ); + return 0 ; } #endif /* MBEDTLS_SSL_DTLS_SRTP */ @@ -862,7 +862,7 @@ static int ssl_generate_random( mbedtls_ssl_context *ssl ) if( ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM && ssl->handshake->verify_cookie != NULL ) { - return( 0 ); + return 0 ; } #endif @@ -877,15 +877,15 @@ static int ssl_generate_random( mbedtls_ssl_context *ssl ) (long long) t ) ); #else if( ( ret = ssl->conf->f_rng( ssl->conf->p_rng, p, 4 ) ) != 0 ) - return( ret ); + return ret ; p += 4; #endif /* MBEDTLS_HAVE_TIME */ if( ( ret = ssl->conf->f_rng( ssl->conf->p_rng, p, 28 ) ) != 0 ) - return( ret ); + return ret ; - return( 0 ); + return 0 ; } /** @@ -905,22 +905,22 @@ static int ssl_validate_ciphersuite( { (void) ssl; if( suite_info == NULL ) - return( 1 ); + return 1 ; if( suite_info->min_minor_ver > max_minor_ver || suite_info->max_minor_ver < min_minor_ver ) - return( 1 ); + return 1 ; #if defined(MBEDTLS_SSL_PROTO_DTLS) if( ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM && ( suite_info->flags & MBEDTLS_CIPHERSUITE_NODTLS ) ) - return( 1 ); + return 1 ; #endif #if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED) if( suite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECJPAKE && mbedtls_ecjpake_check( &ssl->handshake->ecjpake_ctx ) != 0 ) - return( 1 ); + return 1 ; #endif /* Don't suggest PSK-based ciphersuite if no PSK is available. */ @@ -928,11 +928,11 @@ static int ssl_validate_ciphersuite( if( mbedtls_ssl_ciphersuite_uses_psk( suite_info ) && ssl_conf_has_static_psk( ssl->conf ) == 0 ) { - return( 1 ); + return 1 ; } #endif /* MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED */ - return( 0 ); + return 0 ; } static int ssl_write_client_hello( mbedtls_ssl_context *ssl ) @@ -956,7 +956,7 @@ static int ssl_write_client_hello( mbedtls_ssl_context *ssl ) if( ssl->conf->f_rng == NULL ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "no RNG provided") ); - return( MBEDTLS_ERR_SSL_NO_RNG ); + return MBEDTLS_ERR_SSL_NO_RNG ; } #if defined(MBEDTLS_SSL_RENEGOTIATION) @@ -971,7 +971,7 @@ static int ssl_write_client_hello( mbedtls_ssl_context *ssl ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "configured max major version is invalid, consider using mbedtls_ssl_config_defaults()" ) ); - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; } buf = ssl->out_msg; @@ -1012,7 +1012,7 @@ static int ssl_write_client_hello( mbedtls_ssl_context *ssl ) if( ( ret = ssl_generate_random( ssl ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "ssl_generate_random", ret ); - return( ret ); + return ret ; } memcpy( p, ssl->handshake->randbytes, 32 ); @@ -1058,7 +1058,7 @@ static int ssl_write_client_hello( mbedtls_ssl_context *ssl ) ssl->session_negotiate->id, 32 ); if( ret != 0 ) - return( ret ); + return ret ; ssl->session_negotiate->id_len = n = 32; } @@ -1195,7 +1195,7 @@ static int ssl_write_client_hello( mbedtls_ssl_context *ssl ) end, &olen ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "ssl_write_hostname_ext", ret ); - return( ret ); + return ret ; } ext_len += olen; #endif @@ -1207,7 +1207,7 @@ static int ssl_write_client_hello( mbedtls_ssl_context *ssl ) end, &olen ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "ssl_write_renegotiation_ext", ret ); - return( ret ); + return ret ; } ext_len += olen; #endif @@ -1218,7 +1218,7 @@ static int ssl_write_client_hello( mbedtls_ssl_context *ssl ) end, &olen ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "ssl_write_signature_algorithms_ext", ret ); - return( ret ); + return ret ; } ext_len += olen; #endif @@ -1231,7 +1231,7 @@ static int ssl_write_client_hello( mbedtls_ssl_context *ssl ) end, &olen ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "ssl_write_supported_elliptic_curves_ext", ret ); - return( ret ); + return ret ; } ext_len += olen; @@ -1239,7 +1239,7 @@ static int ssl_write_client_hello( mbedtls_ssl_context *ssl ) end, &olen ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "ssl_write_supported_point_formats_ext", ret ); - return( ret ); + return ret ; } ext_len += olen; } @@ -1250,7 +1250,7 @@ static int ssl_write_client_hello( mbedtls_ssl_context *ssl ) end, &olen ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "ssl_write_ecjpake_kkpp_ext", ret ); - return( ret ); + return ret ; } ext_len += olen; #endif @@ -1259,7 +1259,7 @@ static int ssl_write_client_hello( mbedtls_ssl_context *ssl ) if( ( ret = ssl_write_cid_ext( ssl, p + 2 + ext_len, end, &olen ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "ssl_write_cid_ext", ret ); - return( ret ); + return ret ; } ext_len += olen; #endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */ @@ -1269,7 +1269,7 @@ static int ssl_write_client_hello( mbedtls_ssl_context *ssl ) end, &olen ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "ssl_write_max_fragment_length_ext", ret ); - return( ret ); + return ret ; } ext_len += olen; #endif @@ -1279,7 +1279,7 @@ static int ssl_write_client_hello( mbedtls_ssl_context *ssl ) end, &olen ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "ssl_write_encrypt_then_mac_ext", ret ); - return( ret ); + return ret ; } ext_len += olen; #endif @@ -1289,7 +1289,7 @@ static int ssl_write_client_hello( mbedtls_ssl_context *ssl ) end, &olen ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "ssl_write_extended_ms_ext", ret ); - return( ret ); + return ret ; } ext_len += olen; #endif @@ -1299,7 +1299,7 @@ static int ssl_write_client_hello( mbedtls_ssl_context *ssl ) end, &olen ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "ssl_write_alpn_ext", ret ); - return( ret ); + return ret ; } ext_len += olen; #endif @@ -1309,7 +1309,7 @@ static int ssl_write_client_hello( mbedtls_ssl_context *ssl ) end, &olen ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "ssl_write_use_srtp_ext", ret ); - return( ret ); + return ret ; } ext_len += olen; #endif @@ -1319,7 +1319,7 @@ static int ssl_write_client_hello( mbedtls_ssl_context *ssl ) end, &olen ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "ssl_write_session_ticket_ext", ret ); - return( ret ); + return ret ; } ext_len += olen; #endif @@ -1353,7 +1353,7 @@ static int ssl_write_client_hello( mbedtls_ssl_context *ssl ) if( ( ret = mbedtls_ssl_write_handshake_msg( ssl ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_write_handshake_msg", ret ); - return( ret ); + return ret ; } #if defined(MBEDTLS_SSL_PROTO_DTLS) @@ -1361,13 +1361,13 @@ static int ssl_write_client_hello( mbedtls_ssl_context *ssl ) ( ret = mbedtls_ssl_flight_transmit( ssl ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_flight_transmit", ret ); - return( ret ); + return ret ; } #endif /* MBEDTLS_SSL_PROTO_DTLS */ MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= write client hello" ) ); - return( 0 ); + return 0 ; } static int ssl_parse_renegotiation_info( mbedtls_ssl_context *ssl, @@ -1390,7 +1390,7 @@ static int ssl_parse_renegotiation_info( mbedtls_ssl_context *ssl, ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_HANDSHAKE_FAILURE ); - return( MBEDTLS_ERR_SSL_HANDSHAKE_FAILURE ); + return MBEDTLS_ERR_SSL_HANDSHAKE_FAILURE ; } } else @@ -1404,13 +1404,13 @@ static int ssl_parse_renegotiation_info( mbedtls_ssl_context *ssl, ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_HANDSHAKE_FAILURE ); - return( MBEDTLS_ERR_SSL_HANDSHAKE_FAILURE ); + return MBEDTLS_ERR_SSL_HANDSHAKE_FAILURE ; } ssl->secure_renegotiation = MBEDTLS_SSL_SECURE_RENEGOTIATION; } - return( 0 ); + return 0 ; } #if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH) @@ -1432,10 +1432,10 @@ static int ssl_parse_max_fragment_length_ext( mbedtls_ssl_context *ssl, ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_ILLEGAL_PARAMETER ); - return( MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER ); + return MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER ; } - return( 0 ); + return 0 ; } #endif /* MBEDTLS_SSL_MAX_FRAGMENT_LENGTH */ @@ -1454,7 +1454,7 @@ static int ssl_parse_cid_ext( mbedtls_ssl_context *ssl, MBEDTLS_SSL_DEBUG_MSG( 1, ( "CID extension unexpected" ) ); mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_UNSUPPORTED_EXT ); - return( MBEDTLS_ERR_SSL_UNSUPPORTED_EXTENSION ); + return MBEDTLS_ERR_SSL_UNSUPPORTED_EXTENSION ; } if( len == 0 ) @@ -1462,7 +1462,7 @@ static int ssl_parse_cid_ext( mbedtls_ssl_context *ssl, MBEDTLS_SSL_DEBUG_MSG( 1, ( "CID extension invalid" ) ); mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } peer_cid_len = *buf++; @@ -1473,7 +1473,7 @@ static int ssl_parse_cid_ext( mbedtls_ssl_context *ssl, MBEDTLS_SSL_DEBUG_MSG( 1, ( "CID extension invalid" ) ); mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_ILLEGAL_PARAMETER ); - return( MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER ); + return MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER ; } if( len != peer_cid_len ) @@ -1481,7 +1481,7 @@ static int ssl_parse_cid_ext( mbedtls_ssl_context *ssl, MBEDTLS_SSL_DEBUG_MSG( 1, ( "CID extension invalid" ) ); mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } ssl->handshake->cid_in_use = MBEDTLS_SSL_CID_ENABLED; @@ -1491,7 +1491,7 @@ static int ssl_parse_cid_ext( mbedtls_ssl_context *ssl, MBEDTLS_SSL_DEBUG_MSG( 3, ( "Use of CID extension negotiated" ) ); MBEDTLS_SSL_DEBUG_BUF( 3, "Server CID", buf, peer_cid_len ); - return( 0 ); + return 0 ; } #endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */ @@ -1509,14 +1509,14 @@ static int ssl_parse_encrypt_then_mac_ext( mbedtls_ssl_context *ssl, ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_UNSUPPORTED_EXT ); - return( MBEDTLS_ERR_SSL_UNSUPPORTED_EXTENSION ); + return MBEDTLS_ERR_SSL_UNSUPPORTED_EXTENSION ; } ((void) buf); ssl->session_negotiate->encrypt_then_mac = MBEDTLS_SSL_ETM_ENABLED; - return( 0 ); + return 0 ; } #endif /* MBEDTLS_SSL_ENCRYPT_THEN_MAC */ @@ -1534,14 +1534,14 @@ static int ssl_parse_extended_ms_ext( mbedtls_ssl_context *ssl, ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_UNSUPPORTED_EXT ); - return( MBEDTLS_ERR_SSL_UNSUPPORTED_EXTENSION ); + return MBEDTLS_ERR_SSL_UNSUPPORTED_EXTENSION ; } ((void) buf); ssl->handshake->extended_ms = MBEDTLS_SSL_EXTENDED_MS_ENABLED; - return( 0 ); + return 0 ; } #endif /* MBEDTLS_SSL_EXTENDED_MASTER_SECRET */ @@ -1559,14 +1559,14 @@ static int ssl_parse_session_ticket_ext( mbedtls_ssl_context *ssl, ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_UNSUPPORTED_EXT ); - return( MBEDTLS_ERR_SSL_UNSUPPORTED_EXTENSION ); + return MBEDTLS_ERR_SSL_UNSUPPORTED_EXTENSION ; } ((void) buf); ssl->handshake->new_session_ticket = 1; - return( 0 ); + return 0 ; } #endif /* MBEDTLS_SSL_SESSION_TICKETS */ @@ -1584,7 +1584,7 @@ static int ssl_parse_supported_point_formats_ext( mbedtls_ssl_context *ssl, MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad server hello message" ) ); mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } list_size = buf[0]; @@ -1602,7 +1602,7 @@ static int ssl_parse_supported_point_formats_ext( mbedtls_ssl_context *ssl, p[0] ); #endif MBEDTLS_SSL_DEBUG_MSG( 4, ( "point format selected: %d", p[0] ) ); - return( 0 ); + return 0 ; } list_size--; @@ -1612,7 +1612,7 @@ static int ssl_parse_supported_point_formats_ext( mbedtls_ssl_context *ssl, MBEDTLS_SSL_DEBUG_MSG( 1, ( "no point format in common" ) ); mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_HANDSHAKE_FAILURE ); - return( MBEDTLS_ERR_SSL_HANDSHAKE_FAILURE ); + return MBEDTLS_ERR_SSL_HANDSHAKE_FAILURE ; } #endif /* MBEDTLS_ECDH_C || MBEDTLS_ECDSA_C || MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED */ @@ -1628,7 +1628,7 @@ static int ssl_parse_ecjpake_kkpp( mbedtls_ssl_context *ssl, MBEDTLS_KEY_EXCHANGE_ECJPAKE ) { MBEDTLS_SSL_DEBUG_MSG( 3, ( "skip ecjpake kkpp extension" ) ); - return( 0 ); + return 0 ; } /* If we got here, we no longer need our cached extension */ @@ -1644,10 +1644,10 @@ static int ssl_parse_ecjpake_kkpp( mbedtls_ssl_context *ssl, ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_HANDSHAKE_FAILURE ); - return( ret ); + return ret ; } - return( 0 ); + return 0 ; } #endif /* MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED */ @@ -1666,7 +1666,7 @@ static int ssl_parse_alpn_ext( mbedtls_ssl_context *ssl, ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_UNSUPPORTED_EXT ); - return( MBEDTLS_ERR_SSL_UNSUPPORTED_EXTENSION ); + return MBEDTLS_ERR_SSL_UNSUPPORTED_EXTENSION ; } /* @@ -1684,7 +1684,7 @@ static int ssl_parse_alpn_ext( mbedtls_ssl_context *ssl, { mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } list_len = ( buf[0] << 8 ) | buf[1]; @@ -1692,7 +1692,7 @@ static int ssl_parse_alpn_ext( mbedtls_ssl_context *ssl, { mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } name_len = buf[2]; @@ -1700,7 +1700,7 @@ static int ssl_parse_alpn_ext( mbedtls_ssl_context *ssl, { mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } /* Check that the server chosen protocol was in our list and save it */ @@ -1710,14 +1710,14 @@ static int ssl_parse_alpn_ext( mbedtls_ssl_context *ssl, memcmp( buf + 3, *p, name_len ) == 0 ) { ssl->alpn_chosen = *p; - return( 0 ); + return 0 ; } } MBEDTLS_SSL_DEBUG_MSG( 1, ( "ALPN extension: no matching protocol" ) ); mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_HANDSHAKE_FAILURE ); - return( MBEDTLS_ERR_SSL_HANDSHAKE_FAILURE ); + return MBEDTLS_ERR_SSL_HANDSHAKE_FAILURE ; } #endif /* MBEDTLS_SSL_ALPN */ @@ -1734,7 +1734,7 @@ static int ssl_parse_use_srtp_ext( mbedtls_ssl_context *ssl, if( ( ssl->conf->transport != MBEDTLS_SSL_TRANSPORT_DATAGRAM ) || ( ssl->conf->dtls_srtp_profile_list == NULL ) || ( ssl->conf->dtls_srtp_profile_list_len == 0 ) ) - return( 0 ); + return 0 ; /* RFC 5764 section 4.1.1 * uint8 SRTPProtectionProfile[2]; @@ -1759,7 +1759,7 @@ static int ssl_parse_use_srtp_ext( mbedtls_ssl_context *ssl, * and optional srtp_mki */ if( ( len < 5 ) || ( len != ( buf[4] + 5u ) ) ) - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; /* * get the server protection profile @@ -1770,7 +1770,7 @@ static int ssl_parse_use_srtp_ext( mbedtls_ssl_context *ssl, * one protection profile in server Hello */ if( ( buf[0] != 0 ) || ( buf[1] != 2 ) ) - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; server_protection_profile_value = ( buf[2] << 8 ) | buf[3]; server_protection = mbedtls_ssl_check_srtp_profile_value( @@ -1804,7 +1804,7 @@ static int ssl_parse_use_srtp_ext( mbedtls_ssl_context *ssl, { mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_HANDSHAKE_FAILURE ); - return( MBEDTLS_ERR_SSL_HANDSHAKE_FAILURE ); + return MBEDTLS_ERR_SSL_HANDSHAKE_FAILURE ; } /* If server does not use mki in its reply, make sure the client won't keep @@ -1825,7 +1825,7 @@ static int ssl_parse_use_srtp_ext( mbedtls_ssl_context *ssl, { mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_ILLEGAL_PARAMETER ); - return( MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER ); + return MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER ; } #if defined (MBEDTLS_DEBUG_C) if( len > 5 ) @@ -1834,7 +1834,7 @@ static int ssl_parse_use_srtp_ext( mbedtls_ssl_context *ssl, ssl->dtls_srtp_info.mki_len ); } #endif - return( 0 ); + return 0 ; } #endif /* MBEDTLS_SSL_DTLS_SRTP */ @@ -1860,7 +1860,7 @@ static int ssl_parse_hello_verify_request( mbedtls_ssl_context *ssl ) ( "incoming HelloVerifyRequest message is too short" ) ); mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } /* @@ -1887,7 +1887,7 @@ static int ssl_parse_hello_verify_request( mbedtls_ssl_context *ssl ) mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_PROTOCOL_VERSION ); - return( MBEDTLS_ERR_SSL_BAD_PROTOCOL_VERSION ); + return MBEDTLS_ERR_SSL_BAD_PROTOCOL_VERSION ; } cookie_len = *p++; @@ -1897,7 +1897,7 @@ static int ssl_parse_hello_verify_request( mbedtls_ssl_context *ssl ) ( "cookie length does not match incoming message size" ) ); mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } MBEDTLS_SSL_DEBUG_BUF( 3, "cookie", p, cookie_len ); @@ -1907,7 +1907,7 @@ static int ssl_parse_hello_verify_request( mbedtls_ssl_context *ssl ) if( ssl->handshake->verify_cookie == NULL ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "alloc failed (%d bytes)", cookie_len ) ); - return( MBEDTLS_ERR_SSL_ALLOC_FAILED ); + return MBEDTLS_ERR_SSL_ALLOC_FAILED ; } memcpy( ssl->handshake->verify_cookie, p, cookie_len ); @@ -1921,7 +1921,7 @@ static int ssl_parse_hello_verify_request( mbedtls_ssl_context *ssl ) MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= parse hello verify request" ) ); - return( 0 ); + return 0 ; } #endif /* MBEDTLS_SSL_PROTO_DTLS */ @@ -1944,7 +1944,7 @@ static int ssl_parse_server_hello( mbedtls_ssl_context *ssl ) { /* No alert on a read error. */ MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_read_record", ret ); - return( ret ); + return ret ; } buf = ssl->in_msg; @@ -1961,14 +1961,14 @@ static int ssl_parse_server_hello( mbedtls_ssl_context *ssl ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "renegotiation requested, but not honored by server" ) ); - return( MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE ); + return MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE ; } MBEDTLS_SSL_DEBUG_MSG( 1, ( "non-handshake message during renegotiation" ) ); ssl->keep_current_message = 1; - return( MBEDTLS_ERR_SSL_WAITING_SERVER_HELLO_RENEGO ); + return MBEDTLS_ERR_SSL_WAITING_SERVER_HELLO_RENEGO ; } #endif /* MBEDTLS_SSL_RENEGOTIATION */ @@ -1977,7 +1977,7 @@ static int ssl_parse_server_hello( mbedtls_ssl_context *ssl ) ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_UNEXPECTED_MESSAGE ); - return( MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE ); + return MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE ; } #if defined(MBEDTLS_SSL_PROTO_DTLS) @@ -1987,7 +1987,7 @@ static int ssl_parse_server_hello( mbedtls_ssl_context *ssl ) { MBEDTLS_SSL_DEBUG_MSG( 2, ( "received hello verify request" ) ); MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= parse server hello" ) ); - return( ssl_parse_hello_verify_request( ssl ) ); + return ssl_parse_hello_verify_request( ssl ) ; } else { @@ -2005,7 +2005,7 @@ static int ssl_parse_server_hello( mbedtls_ssl_context *ssl ) MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad server hello message" ) ); mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } /* @@ -2042,7 +2042,7 @@ static int ssl_parse_server_hello( mbedtls_ssl_context *ssl ) mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_PROTOCOL_VERSION ); - return( MBEDTLS_ERR_SSL_BAD_PROTOCOL_VERSION ); + return MBEDTLS_ERR_SSL_BAD_PROTOCOL_VERSION ; } MBEDTLS_SSL_DEBUG_MSG( 3, ( "server hello, current time: %lu", @@ -2062,7 +2062,7 @@ static int ssl_parse_server_hello( mbedtls_ssl_context *ssl ) MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad server hello message" ) ); mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } if( ssl->in_hslen > mbedtls_ssl_hs_hdr_len( ssl ) + 39 + n ) @@ -2078,7 +2078,7 @@ static int ssl_parse_server_hello( mbedtls_ssl_context *ssl ) ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } } else if( ssl->in_hslen == mbedtls_ssl_hs_hdr_len( ssl ) + 38 + n ) @@ -2090,7 +2090,7 @@ static int ssl_parse_server_hello( mbedtls_ssl_context *ssl ) MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad server hello message" ) ); mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } /* ciphersuite (used later) */ @@ -2109,7 +2109,7 @@ static int ssl_parse_server_hello( mbedtls_ssl_context *ssl ) ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_ILLEGAL_PARAMETER ); - return( MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE ; } /* @@ -2122,7 +2122,7 @@ static int ssl_parse_server_hello( mbedtls_ssl_context *ssl ) ( "ciphersuite info for %04x not found", (unsigned int)i ) ); mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_INTERNAL_ERROR ); - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; } mbedtls_ssl_optimize_checksum( ssl, ssl->handshake->ciphersuite_info ); @@ -2163,7 +2163,7 @@ static int ssl_parse_server_hello( mbedtls_ssl_context *ssl ) ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_INTERNAL_ERROR ); - return( ret ); + return ret ; } } @@ -2187,7 +2187,7 @@ static int ssl_parse_server_hello( mbedtls_ssl_context *ssl ) ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_ILLEGAL_PARAMETER ); - return( MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER ); + return MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER ; } if( ssl->conf->ciphersuite_list[i++] == @@ -2207,7 +2207,7 @@ static int ssl_parse_server_hello( mbedtls_ssl_context *ssl ) ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_HANDSHAKE_FAILURE ); - return( MBEDTLS_ERR_SSL_HANDSHAKE_FAILURE ); + return MBEDTLS_ERR_SSL_HANDSHAKE_FAILURE ; } MBEDTLS_SSL_DEBUG_MSG( 3, @@ -2229,7 +2229,7 @@ static int ssl_parse_server_hello( mbedtls_ssl_context *ssl ) ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_ILLEGAL_PARAMETER ); - return( MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER ); + return MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER ; } ssl->session_negotiate->compression = comp; @@ -2251,7 +2251,7 @@ static int ssl_parse_server_hello( mbedtls_ssl_context *ssl ) mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } switch( ext_id ) @@ -2264,7 +2264,7 @@ static int ssl_parse_server_hello( mbedtls_ssl_context *ssl ) if( ( ret = ssl_parse_renegotiation_info( ssl, ext + 4, ext_size ) ) != 0 ) - return( ret ); + return ret ; break; @@ -2276,7 +2276,7 @@ static int ssl_parse_server_hello( mbedtls_ssl_context *ssl ) if( ( ret = ssl_parse_max_fragment_length_ext( ssl, ext + 4, ext_size ) ) != 0 ) { - return( ret ); + return ret ; } break; @@ -2290,7 +2290,7 @@ static int ssl_parse_server_hello( mbedtls_ssl_context *ssl ) ext + 4, ext_size ) ) != 0 ) { - return( ret ); + return ret ; } break; @@ -2303,7 +2303,7 @@ static int ssl_parse_server_hello( mbedtls_ssl_context *ssl ) if( ( ret = ssl_parse_encrypt_then_mac_ext( ssl, ext + 4, ext_size ) ) != 0 ) { - return( ret ); + return ret ; } break; @@ -2317,7 +2317,7 @@ static int ssl_parse_server_hello( mbedtls_ssl_context *ssl ) if( ( ret = ssl_parse_extended_ms_ext( ssl, ext + 4, ext_size ) ) != 0 ) { - return( ret ); + return ret ; } break; @@ -2330,7 +2330,7 @@ static int ssl_parse_server_hello( mbedtls_ssl_context *ssl ) if( ( ret = ssl_parse_session_ticket_ext( ssl, ext + 4, ext_size ) ) != 0 ) { - return( ret ); + return ret ; } break; @@ -2345,7 +2345,7 @@ static int ssl_parse_server_hello( mbedtls_ssl_context *ssl ) if( ( ret = ssl_parse_supported_point_formats_ext( ssl, ext + 4, ext_size ) ) != 0 ) { - return( ret ); + return ret ; } break; @@ -2359,7 +2359,7 @@ static int ssl_parse_server_hello( mbedtls_ssl_context *ssl ) if( ( ret = ssl_parse_ecjpake_kkpp( ssl, ext + 4, ext_size ) ) != 0 ) { - return( ret ); + return ret ; } break; @@ -2370,7 +2370,7 @@ static int ssl_parse_server_hello( mbedtls_ssl_context *ssl ) MBEDTLS_SSL_DEBUG_MSG( 3, ( "found alpn extension" ) ); if( ( ret = ssl_parse_alpn_ext( ssl, ext + 4, ext_size ) ) != 0 ) - return( ret ); + return ret ; break; #endif /* MBEDTLS_SSL_ALPN */ @@ -2380,7 +2380,7 @@ static int ssl_parse_server_hello( mbedtls_ssl_context *ssl ) MBEDTLS_SSL_DEBUG_MSG( 3, ( "found use_srtp extension" ) ); if( ( ret = ssl_parse_use_srtp_ext( ssl, ext + 4, ext_size ) ) != 0 ) - return( ret ); + return ret ; break; #endif /* MBEDTLS_SSL_DTLS_SRTP */ @@ -2396,7 +2396,7 @@ static int ssl_parse_server_hello( mbedtls_ssl_context *ssl ) if( ext_len > 0 && ext_len < 4 ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad server hello message" ) ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } } @@ -2444,12 +2444,12 @@ static int ssl_parse_server_hello( mbedtls_ssl_context *ssl ) ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_HANDSHAKE_FAILURE ); - return( MBEDTLS_ERR_SSL_HANDSHAKE_FAILURE ); + return MBEDTLS_ERR_SSL_HANDSHAKE_FAILURE ; } MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= parse server hello" ) ); - return( 0 ); + return 0 ; } #if defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED) || \ @@ -2474,7 +2474,7 @@ static int ssl_parse_server_dh_params( mbedtls_ssl_context *ssl, p, end ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 2, ( "mbedtls_dhm_read_params" ), ret ); - return( ret ); + return ret ; } dhm_actual_bitlen = mbedtls_dhm_get_bitlen( &ssl->handshake->dhm_ctx ); @@ -2483,14 +2483,14 @@ static int ssl_parse_server_dh_params( mbedtls_ssl_context *ssl, MBEDTLS_SSL_DEBUG_MSG( 1, ( "DHM prime too short: %" MBEDTLS_PRINTF_SIZET " < %u", dhm_actual_bitlen, ssl->conf->dhm_min_bitlen ) ); - return( MBEDTLS_ERR_SSL_HANDSHAKE_FAILURE ); + return MBEDTLS_ERR_SSL_HANDSHAKE_FAILURE ; } MBEDTLS_SSL_DEBUG_MPI( 3, "DHM: P ", &ssl->handshake->dhm_ctx.P ); MBEDTLS_SSL_DEBUG_MPI( 3, "DHM: G ", &ssl->handshake->dhm_ctx.G ); MBEDTLS_SSL_DEBUG_MPI( 3, "DHM: GY", &ssl->handshake->dhm_ctx.GY ); - return( ret ); + return ret ; } #endif /* MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED || MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED */ @@ -2514,7 +2514,7 @@ static int ssl_check_server_ecdh_params( const mbedtls_ssl_context *ssl ) if( curve_info == NULL ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) ); - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; } MBEDTLS_SSL_DEBUG_MSG( 2, ( "ECDH curve: %s", curve_info->name ) ); @@ -2525,12 +2525,12 @@ static int ssl_check_server_ecdh_params( const mbedtls_ssl_context *ssl ) if( ssl->handshake->ecdh_ctx.grp.nbits < 163 || ssl->handshake->ecdh_ctx.grp.nbits > 521 ) #endif - return( -1 ); + return -1 ; MBEDTLS_SSL_DEBUG_ECDH( 3, &ssl->handshake->ecdh_ctx, MBEDTLS_DEBUG_ECDH_QP ); - return( 0 ); + return 0 ; } #endif /* MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED || MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED || @@ -2555,11 +2555,11 @@ static int ssl_parse_server_ecdh_params_psa( mbedtls_ssl_context *ssl, */ if( end - *p < 4 ) - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; /* First byte is curve_type; only named_curve is handled */ if( *(*p)++ != MBEDTLS_ECP_TLS_NAMED_CURVE ) - return( MBEDTLS_ERR_SSL_HANDSHAKE_FAILURE ); + return MBEDTLS_ERR_SSL_HANDSHAKE_FAILURE ; /* Next two bytes are the namedcurve value */ tls_id = *(*p)++; @@ -2570,10 +2570,10 @@ static int ssl_parse_server_ecdh_params_psa( mbedtls_ssl_context *ssl, if( ( handshake->ecdh_psa_type = mbedtls_psa_parse_tls_ecc_group( tls_id, &ecdh_bits ) ) == 0 ) { - return( MBEDTLS_ERR_SSL_HANDSHAKE_FAILURE ); + return MBEDTLS_ERR_SSL_HANDSHAKE_FAILURE ; } if( ecdh_bits > 0xffff ) - return( MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER ); + return MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER ; handshake->ecdh_bits = (uint16_t) ecdh_bits; /* @@ -2582,7 +2582,7 @@ static int ssl_parse_server_ecdh_params_psa( mbedtls_ssl_context *ssl, ecpoint_len = *(*p)++; if( (size_t)( end - *p ) < ecpoint_len ) - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; if( mbedtls_psa_tls_ecpoint_to_psa_ec( *p, ecpoint_len, @@ -2590,11 +2590,11 @@ static int ssl_parse_server_ecdh_params_psa( mbedtls_ssl_context *ssl, sizeof( handshake->ecdh_psa_peerkey ), &handshake->ecdh_psa_peerkey_len ) != 0 ) { - return( MBEDTLS_ERR_SSL_HW_ACCEL_FAILED ); + return MBEDTLS_ERR_SSL_HW_ACCEL_FAILED ; } *p += ecpoint_len; - return( 0 ); + return 0 ; } #endif /* MBEDTLS_USE_PSA_CRYPTO && ( MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED || @@ -2625,17 +2625,17 @@ static int ssl_parse_server_ecdh_params( mbedtls_ssl_context *ssl, if( ret == MBEDTLS_ERR_ECP_IN_PROGRESS ) ret = MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS; #endif - return( ret ); + return ret ; } if( ssl_check_server_ecdh_params( ssl ) != 0 ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad server key exchange message (ECDHE curve)" ) ); - return( MBEDTLS_ERR_SSL_HANDSHAKE_FAILURE ); + return MBEDTLS_ERR_SSL_HANDSHAKE_FAILURE ; } - return( ret ); + return ret ; } #endif /* MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED || MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED || @@ -2659,7 +2659,7 @@ static int ssl_parse_server_psk_hint( mbedtls_ssl_context *ssl, { MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad server key exchange message (psk_identity_hint length)" ) ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } len = (*p)[0] << 8 | (*p)[1]; *p += 2; @@ -2668,7 +2668,7 @@ static int ssl_parse_server_psk_hint( mbedtls_ssl_context *ssl, { MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad server key exchange message (psk_identity_hint length)" ) ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } /* @@ -2679,7 +2679,7 @@ static int ssl_parse_server_psk_hint( mbedtls_ssl_context *ssl, *p += len; ret = 0; - return( ret ); + return ret ; } #endif /* MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED */ @@ -2700,7 +2700,7 @@ static int ssl_write_encrypted_pms( mbedtls_ssl_context *ssl, if( offset + len_bytes > MBEDTLS_SSL_OUT_CONTENT_LEN ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "buffer too small for encrypted pms" ) ); - return( MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL ); + return MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL ; } /* @@ -2717,7 +2717,7 @@ static int ssl_write_encrypted_pms( mbedtls_ssl_context *ssl, if( ( ret = ssl->conf->f_rng( ssl->conf->p_rng, p + 2, 46 ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "f_rng", ret ); - return( ret ); + return ret ; } ssl->handshake->pmslen = 48; @@ -2729,7 +2729,7 @@ static int ssl_write_encrypted_pms( mbedtls_ssl_context *ssl, { /* Should never happen */ MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) ); - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; } peer_pk = &ssl->session_negotiate->peer_cert->pk; #endif /* MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */ @@ -2740,7 +2740,7 @@ static int ssl_write_encrypted_pms( mbedtls_ssl_context *ssl, if( ! mbedtls_pk_can_do( peer_pk, MBEDTLS_PK_RSA ) ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "certificate key type mismatch" ) ); - return( MBEDTLS_ERR_SSL_PK_TYPE_MISMATCH ); + return MBEDTLS_ERR_SSL_PK_TYPE_MISMATCH ; } if( ( ret = mbedtls_pk_encrypt( peer_pk, @@ -2750,7 +2750,7 @@ static int ssl_write_encrypted_pms( mbedtls_ssl_context *ssl, ssl->conf->f_rng, ssl->conf->p_rng ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_rsa_pkcs1_encrypt", ret ); - return( ret ); + return ret ; } #if defined(MBEDTLS_SSL_PROTO_TLS1_2) @@ -2766,7 +2766,7 @@ static int ssl_write_encrypted_pms( mbedtls_ssl_context *ssl, /* We don't need the peer's public key anymore. Free it. */ mbedtls_pk_free( peer_pk ); #endif /* !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */ - return( 0 ); + return 0 ; } #endif /* MBEDTLS_KEY_EXCHANGE_RSA_ENABLED || MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED */ @@ -2788,11 +2788,11 @@ static int ssl_parse_signature_algorithm( mbedtls_ssl_context *ssl, /* Only in TLS 1.2 */ if( ssl->minor_ver != MBEDTLS_SSL_MINOR_VERSION_3 ) { - return( 0 ); + return 0 ; } if( (*p) + 2 > end ) - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; /* * Get hash algorithm @@ -2802,7 +2802,7 @@ static int ssl_parse_signature_algorithm( mbedtls_ssl_context *ssl, { MBEDTLS_SSL_DEBUG_MSG( 1, ( "Server used unsupported HashAlgorithm %d", *(p)[0] ) ); - return( MBEDTLS_ERR_SSL_HANDSHAKE_FAILURE ); + return MBEDTLS_ERR_SSL_HANDSHAKE_FAILURE ; } /* @@ -2813,7 +2813,7 @@ static int ssl_parse_signature_algorithm( mbedtls_ssl_context *ssl, { MBEDTLS_SSL_DEBUG_MSG( 1, ( "server used unsupported SignatureAlgorithm %d", (*p)[1] ) ); - return( MBEDTLS_ERR_SSL_HANDSHAKE_FAILURE ); + return MBEDTLS_ERR_SSL_HANDSHAKE_FAILURE ; } /* @@ -2823,7 +2823,7 @@ static int ssl_parse_signature_algorithm( mbedtls_ssl_context *ssl, { MBEDTLS_SSL_DEBUG_MSG( 1, ( "server used HashAlgorithm %d that was not offered", *(p)[0] ) ); - return( MBEDTLS_ERR_SSL_HANDSHAKE_FAILURE ); + return MBEDTLS_ERR_SSL_HANDSHAKE_FAILURE ; } MBEDTLS_SSL_DEBUG_MSG( 2, ( "Server used SignatureAlgorithm %d", @@ -2832,7 +2832,7 @@ static int ssl_parse_signature_algorithm( mbedtls_ssl_context *ssl, (*p)[0] ) ); *p += 2; - return( 0 ); + return 0 ; } #endif /* MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED || MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED || @@ -2854,7 +2854,7 @@ static int ssl_get_ecdh_params_from_cert( mbedtls_ssl_context *ssl ) { /* Should never happen */ MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) ); - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; } peer_pk = &ssl->session_negotiate->peer_cert->pk; #endif /* MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */ @@ -2862,7 +2862,7 @@ static int ssl_get_ecdh_params_from_cert( mbedtls_ssl_context *ssl ) if( ! mbedtls_pk_can_do( peer_pk, MBEDTLS_PK_ECKEY ) ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "server key not ECDH capable" ) ); - return( MBEDTLS_ERR_SSL_PK_TYPE_MISMATCH ); + return MBEDTLS_ERR_SSL_PK_TYPE_MISMATCH ; } peer_key = mbedtls_pk_ec( *peer_pk ); @@ -2871,13 +2871,13 @@ static int ssl_get_ecdh_params_from_cert( mbedtls_ssl_context *ssl ) MBEDTLS_ECDH_THEIRS ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, ( "mbedtls_ecdh_get_params" ), ret ); - return( ret ); + return ret ; } if( ssl_check_server_ecdh_params( ssl ) != 0 ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad server certificate (ECDH curve)" ) ); - return( MBEDTLS_ERR_SSL_BAD_CERTIFICATE ); + return MBEDTLS_ERR_SSL_BAD_CERTIFICATE ; } #if !defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE) @@ -2887,7 +2887,7 @@ static int ssl_get_ecdh_params_from_cert( mbedtls_ssl_context *ssl ) mbedtls_pk_free( peer_pk ); #endif /* !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */ - return( ret ); + return ret ; } #endif /* MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) || MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED */ @@ -2906,7 +2906,7 @@ static int ssl_parse_server_key_exchange( mbedtls_ssl_context *ssl ) { MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= skip parse server key exchange" ) ); ssl->state++; - return( 0 ); + return 0 ; } ((void) p); ((void) end); @@ -2924,12 +2924,12 @@ static int ssl_parse_server_key_exchange( mbedtls_ssl_context *ssl ) ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_HANDSHAKE_FAILURE ); - return( ret ); + return ret ; } MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= skip parse server key exchange" ) ); ssl->state++; - return( 0 ); + return 0 ; } ((void) p); ((void) end); @@ -2947,7 +2947,7 @@ static int ssl_parse_server_key_exchange( mbedtls_ssl_context *ssl ) if( ( ret = mbedtls_ssl_read_record( ssl, 1 ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_read_record", ret ); - return( ret ); + return ret ; } if( ssl->in_msgtype != MBEDTLS_SSL_MSG_HANDSHAKE ) @@ -2957,7 +2957,7 @@ static int ssl_parse_server_key_exchange( mbedtls_ssl_context *ssl ) ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_UNEXPECTED_MESSAGE ); - return( MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE ); + return MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE ; } /* @@ -2982,7 +2982,7 @@ static int ssl_parse_server_key_exchange( mbedtls_ssl_context *ssl ) MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_UNEXPECTED_MESSAGE ); - return( MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE ); + return MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE ; } #if defined(MBEDTLS_SSL_ECP_RESTARTABLE_ENABLED) @@ -3008,7 +3008,7 @@ start_processing: ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } } /* FALLTROUGH */ #endif /* MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED */ @@ -3033,7 +3033,7 @@ start_processing: ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_ILLEGAL_PARAMETER ); - return( MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER ); + return MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER ; } } else @@ -3052,7 +3052,7 @@ start_processing: ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_ILLEGAL_PARAMETER ); - return( MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER ); + return MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER ; } } else @@ -3073,7 +3073,7 @@ start_processing: ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_ILLEGAL_PARAMETER ); - return( MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER ); + return MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER ; } } else @@ -3092,14 +3092,14 @@ start_processing: ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_HANDSHAKE_FAILURE ); - return( MBEDTLS_ERR_SSL_HANDSHAKE_FAILURE ); + return MBEDTLS_ERR_SSL_HANDSHAKE_FAILURE ; } } else #endif /* MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED */ { MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) ); - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; } #if defined(MBEDTLS_KEY_EXCHANGE_WITH_SERVER_SIGNATURE_ENABLED) @@ -3130,7 +3130,7 @@ start_processing: ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_ILLEGAL_PARAMETER ); - return( MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER ); + return MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER ; } if( pk_alg != @@ -3142,14 +3142,14 @@ start_processing: ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_ILLEGAL_PARAMETER ); - return( MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER ); + return MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER ; } } else #endif /* MBEDTLS_SSL_PROTO_TLS1_2 */ { MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) ); - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; } /* @@ -3163,7 +3163,7 @@ start_processing: ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } sig_len = ( p[0] << 8 ) | p[1]; p += 2; @@ -3175,7 +3175,7 @@ start_processing: ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } MBEDTLS_SSL_DEBUG_BUF( 3, "signature", p, sig_len ); @@ -3190,13 +3190,13 @@ start_processing: params, params_len, md_alg ); if( ret != 0 ) - return( ret ); + return ret ; } else #endif /* MBEDTLS_SSL_PROTO_TLS1_2 */ { MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) ); - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; } MBEDTLS_SSL_DEBUG_BUF( 3, "parameters hash", hash, hashlen ); @@ -3208,7 +3208,7 @@ start_processing: { /* Should never happen */ MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) ); - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; } peer_pk = &ssl->session_negotiate->peer_cert->pk; #endif /* MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */ @@ -3223,7 +3223,7 @@ start_processing: ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_HANDSHAKE_FAILURE ); - return( MBEDTLS_ERR_SSL_PK_TYPE_MISMATCH ); + return MBEDTLS_ERR_SSL_PK_TYPE_MISMATCH ; } #if defined(MBEDTLS_SSL_ECP_RESTARTABLE_ENABLED) @@ -3246,7 +3246,7 @@ start_processing: if( ret == MBEDTLS_ERR_ECP_IN_PROGRESS ) ret = MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS; #endif - return( ret ); + return ret ; } #if !defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE) @@ -3263,7 +3263,7 @@ exit: MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= parse server key exchange" ) ); - return( 0 ); + return 0 ; } #if ! defined(MBEDTLS_KEY_EXCHANGE_CERT_REQ_ALLOWED_ENABLED) @@ -3278,11 +3278,11 @@ static int ssl_parse_certificate_request( mbedtls_ssl_context *ssl ) { MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= skip parse certificate request" ) ); ssl->state++; - return( 0 ); + return 0 ; } MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) ); - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; } #else /* MBEDTLS_KEY_EXCHANGE_CERT_REQ_ALLOWED_ENABLED */ static int ssl_parse_certificate_request( mbedtls_ssl_context *ssl ) @@ -3300,13 +3300,13 @@ static int ssl_parse_certificate_request( mbedtls_ssl_context *ssl ) { MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= skip parse certificate request" ) ); ssl->state++; - return( 0 ); + return 0 ; } if( ( ret = mbedtls_ssl_read_record( ssl, 1 ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_read_record", ret ); - return( ret ); + return ret ; } if( ssl->in_msgtype != MBEDTLS_SSL_MSG_HANDSHAKE ) @@ -3316,7 +3316,7 @@ static int ssl_parse_certificate_request( mbedtls_ssl_context *ssl ) ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_UNEXPECTED_MESSAGE ); - return( MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE ); + return MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE ; } ssl->state++; @@ -3364,7 +3364,7 @@ static int ssl_parse_certificate_request( mbedtls_ssl_context *ssl ) MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad certificate request message" ) ); mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } cert_type_len = buf[mbedtls_ssl_hs_hdr_len( ssl )]; n = cert_type_len; @@ -3384,7 +3384,7 @@ static int ssl_parse_certificate_request( mbedtls_ssl_context *ssl ) MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad certificate request message" ) ); mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } /* supported_signature_algorithms */ @@ -3419,7 +3419,7 @@ static int ssl_parse_certificate_request( mbedtls_ssl_context *ssl ) ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } #if defined(MBEDTLS_DEBUG_C) @@ -3446,13 +3446,13 @@ static int ssl_parse_certificate_request( mbedtls_ssl_context *ssl ) MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad certificate request message" ) ); mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } exit: MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= parse certificate request" ) ); - return( 0 ); + return 0 ; } #endif /* MBEDTLS_KEY_EXCHANGE_CERT_REQ_ALLOWED_ENABLED */ @@ -3465,13 +3465,13 @@ static int ssl_parse_server_hello_done( mbedtls_ssl_context *ssl ) if( ( ret = mbedtls_ssl_read_record( ssl, 1 ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_read_record", ret ); - return( ret ); + return ret ; } if( ssl->in_msgtype != MBEDTLS_SSL_MSG_HANDSHAKE ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad server hello done message" ) ); - return( MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE ); + return MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE ; } if( ssl->in_hslen != mbedtls_ssl_hs_hdr_len( ssl ) || @@ -3480,7 +3480,7 @@ static int ssl_parse_server_hello_done( mbedtls_ssl_context *ssl ) MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad server hello done message" ) ); mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } ssl->state++; @@ -3492,7 +3492,7 @@ static int ssl_parse_server_hello_done( mbedtls_ssl_context *ssl ) MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= parse server hello done" ) ); - return( 0 ); + return 0 ; } static int ssl_write_client_key_exchange( mbedtls_ssl_context *ssl ) @@ -3525,7 +3525,7 @@ static int ssl_write_client_key_exchange( mbedtls_ssl_context *ssl ) if( ret != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_dhm_make_public", ret ); - return( ret ); + return ret ; } MBEDTLS_SSL_DEBUG_MPI( 3, "DHM: X ", &ssl->handshake->dhm_ctx.X ); @@ -3538,7 +3538,7 @@ static int ssl_write_client_key_exchange( mbedtls_ssl_context *ssl ) ssl->conf->f_rng, ssl->conf->p_rng ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_dhm_calc_secret", ret ); - return( ret ); + return ret ; } MBEDTLS_SSL_DEBUG_MPI( 3, "DHM: K ", &ssl->handshake->dhm_ctx.K ); @@ -3586,7 +3586,7 @@ static int ssl_write_client_key_exchange( mbedtls_ssl_context *ssl ) status = psa_generate_key( &key_attributes, &handshake->ecdh_psa_privkey ); if( status != PSA_SUCCESS ) - return( MBEDTLS_ERR_SSL_HW_ACCEL_FAILED ); + return MBEDTLS_ERR_SSL_HW_ACCEL_FAILED ; /* Export the public part of the ECDH private key from PSA * and convert it to ECPoint format used in ClientKeyExchange. */ @@ -3594,14 +3594,14 @@ static int ssl_write_client_key_exchange( mbedtls_ssl_context *ssl ) own_pubkey, sizeof( own_pubkey ), &own_pubkey_len ); if( status != PSA_SUCCESS ) - return( MBEDTLS_ERR_SSL_HW_ACCEL_FAILED ); + return MBEDTLS_ERR_SSL_HW_ACCEL_FAILED ; if( mbedtls_psa_tls_psa_ec_to_ecpoint( own_pubkey, own_pubkey_len, &own_pubkey_ecpoint, &own_pubkey_ecpoint_len ) != 0 ) { - return( MBEDTLS_ERR_SSL_HW_ACCEL_FAILED ); + return MBEDTLS_ERR_SSL_HW_ACCEL_FAILED ; } /* Copy ECPoint structure to outgoing message buffer. */ @@ -3621,11 +3621,11 @@ static int ssl_write_client_key_exchange( mbedtls_ssl_context *ssl ) sizeof( ssl->handshake->premaster ), &ssl->handshake->pmslen ); if( status != PSA_SUCCESS ) - return( MBEDTLS_ERR_SSL_HW_ACCEL_FAILED ); + return MBEDTLS_ERR_SSL_HW_ACCEL_FAILED ; status = psa_destroy_key( handshake->ecdh_psa_privkey ); if( status != PSA_SUCCESS ) - return( MBEDTLS_ERR_SSL_HW_ACCEL_FAILED ); + return MBEDTLS_ERR_SSL_HW_ACCEL_FAILED ; handshake->ecdh_psa_privkey = MBEDTLS_SVC_KEY_ID_INIT; } else @@ -3667,7 +3667,7 @@ static int ssl_write_client_key_exchange( mbedtls_ssl_context *ssl ) if( ret == MBEDTLS_ERR_ECP_IN_PROGRESS ) ret = MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS; #endif - return( ret ); + return ret ; } MBEDTLS_SSL_DEBUG_ECDH( 3, &ssl->handshake->ecdh_ctx, @@ -3695,7 +3695,7 @@ ecdh_calc_secret: if( ret == MBEDTLS_ERR_ECP_IN_PROGRESS ) ret = MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS; #endif - return( ret ); + return ret ; } MBEDTLS_SSL_DEBUG_ECDH( 3, &ssl->handshake->ecdh_ctx, @@ -3717,7 +3717,7 @@ ecdh_calc_secret: /* We don't offer PSK suites if we don't have a PSK, * and we check that the server's choice is among the * ciphersuites we offered, so this should never happen. */ - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; } header_len = 4; @@ -3727,7 +3727,7 @@ ecdh_calc_secret: { MBEDTLS_SSL_DEBUG_MSG( 1, ( "psk identity too long or SSL buffer too short" ) ); - return( MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL ); + return MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL ; } ssl->out_msg[header_len++] = (unsigned char)( content_len >> 8 ); @@ -3751,12 +3751,12 @@ ecdh_calc_secret: #if defined(MBEDTLS_USE_PSA_CRYPTO) /* Opaque PSKs are currently only supported for PSK-only suites. */ if( ssl_conf_has_static_raw_psk( ssl->conf ) == 0 ) - return( MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE ; #endif /* MBEDTLS_USE_PSA_CRYPTO */ if( ( ret = ssl_write_encrypted_pms( ssl, header_len, &content_len, 2 ) ) != 0 ) - return( ret ); + return ret ; } else #endif @@ -3766,7 +3766,7 @@ ecdh_calc_secret: #if defined(MBEDTLS_USE_PSA_CRYPTO) /* Opaque PSKs are currently only supported for PSK-only suites. */ if( ssl_conf_has_static_raw_psk( ssl->conf ) == 0 ) - return( MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE ; #endif /* MBEDTLS_USE_PSA_CRYPTO */ /* @@ -3779,7 +3779,7 @@ ecdh_calc_secret: { MBEDTLS_SSL_DEBUG_MSG( 1, ( "psk identity or DHM size too long or SSL buffer too short" ) ); - return( MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL ); + return MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL ; } ssl->out_msg[header_len++] = (unsigned char)( content_len >> 8 ); @@ -3792,7 +3792,7 @@ ecdh_calc_secret: if( ret != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_dhm_make_public", ret ); - return( ret ); + return ret ; } } else @@ -3803,7 +3803,7 @@ ecdh_calc_secret: #if defined(MBEDTLS_USE_PSA_CRYPTO) /* Opaque PSKs are currently only supported for PSK-only suites. */ if( ssl_conf_has_static_raw_psk( ssl->conf ) == 0 ) - return( MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE ; #endif /* MBEDTLS_USE_PSA_CRYPTO */ /* @@ -3817,7 +3817,7 @@ ecdh_calc_secret: if( ret != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ecdh_make_public", ret ); - return( ret ); + return ret ; } MBEDTLS_SSL_DEBUG_ECDH( 3, &ssl->handshake->ecdh_ctx, @@ -3827,7 +3827,7 @@ ecdh_calc_secret: #endif /* MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED */ { MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) ); - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; } #if defined(MBEDTLS_USE_PSA_CRYPTO) && \ @@ -3847,7 +3847,7 @@ ecdh_calc_secret: { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_psk_derive_premaster", ret ); - return( ret ); + return ret ; } } else @@ -3858,7 +3858,7 @@ ecdh_calc_secret: header_len = 4; if( ( ret = ssl_write_encrypted_pms( ssl, header_len, &content_len, 0 ) ) != 0 ) - return( ret ); + return ret ; } else #endif /* MBEDTLS_KEY_EXCHANGE_RSA_ENABLED */ @@ -3875,7 +3875,7 @@ ecdh_calc_secret: if( ret != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ecjpake_write_round_two", ret ); - return( ret ); + return ret ; } ret = mbedtls_ecjpake_derive_secret( &ssl->handshake->ecjpake_ctx, @@ -3884,7 +3884,7 @@ ecdh_calc_secret: if( ret != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ecjpake_derive_secret", ret ); - return( ret ); + return ret ; } } else @@ -3892,7 +3892,7 @@ ecdh_calc_secret: { ((void) ciphersuite_info); MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) ); - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; } ssl->out_msglen = header_len + content_len; @@ -3904,12 +3904,12 @@ ecdh_calc_secret: if( ( ret = mbedtls_ssl_write_handshake_msg( ssl ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_write_handshake_msg", ret ); - return( ret ); + return ret ; } MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= write client key exchange" ) ); - return( 0 ); + return 0 ; } #if !defined(MBEDTLS_KEY_EXCHANGE_CERT_REQ_ALLOWED_ENABLED) @@ -3924,18 +3924,18 @@ static int ssl_write_certificate_verify( mbedtls_ssl_context *ssl ) if( ( ret = mbedtls_ssl_derive_keys( ssl ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_derive_keys", ret ); - return( ret ); + return ret ; } if( !mbedtls_ssl_ciphersuite_cert_req_allowed( ciphersuite_info ) ) { MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= skip write certificate verify" ) ); ssl->state++; - return( 0 ); + return 0 ; } MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) ); - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; } #else /* !MBEDTLS_KEY_EXCHANGE_CERT_REQ_ALLOWED_ENABLED */ static int ssl_write_certificate_verify( mbedtls_ssl_context *ssl ) @@ -3968,27 +3968,27 @@ static int ssl_write_certificate_verify( mbedtls_ssl_context *ssl ) if( ( ret = mbedtls_ssl_derive_keys( ssl ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_derive_keys", ret ); - return( ret ); + return ret ; } if( !mbedtls_ssl_ciphersuite_cert_req_allowed( ciphersuite_info ) ) { MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= skip write certificate verify" ) ); ssl->state++; - return( 0 ); + return 0 ; } if( ssl->client_auth == 0 || mbedtls_ssl_own_cert( ssl ) == NULL ) { MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= skip write certificate verify" ) ); ssl->state++; - return( 0 ); + return 0 ; } if( mbedtls_ssl_own_key( ssl ) == NULL ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "got no private key for certificate" ) ); - return( MBEDTLS_ERR_SSL_PRIVATE_KEY_REQUIRED ); + return MBEDTLS_ERR_SSL_PRIVATE_KEY_REQUIRED ; } /* @@ -4042,7 +4042,7 @@ sign: #endif /* MBEDTLS_SSL_PROTO_TLS1_2 */ { MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) ); - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; } #if defined(MBEDTLS_SSL_ECP_RESTARTABLE_ENABLED) @@ -4062,7 +4062,7 @@ sign: if( ret == MBEDTLS_ERR_ECP_IN_PROGRESS ) ret = MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS; #endif - return( ret ); + return ret ; } ssl->out_msg[4 + offset] = (unsigned char)( n >> 8 ); @@ -4077,12 +4077,12 @@ sign: if( ( ret = mbedtls_ssl_write_handshake_msg( ssl ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_write_handshake_msg", ret ); - return( ret ); + return ret ; } MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= write certificate verify" ) ); - return( ret ); + return ret ; } #endif /* MBEDTLS_KEY_EXCHANGE_CERT_REQ_ALLOWED_ENABLED */ @@ -4100,7 +4100,7 @@ static int ssl_parse_new_session_ticket( mbedtls_ssl_context *ssl ) if( ( ret = mbedtls_ssl_read_record( ssl, 1 ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_read_record", ret ); - return( ret ); + return ret ; } if( ssl->in_msgtype != MBEDTLS_SSL_MSG_HANDSHAKE ) @@ -4110,7 +4110,7 @@ static int ssl_parse_new_session_ticket( mbedtls_ssl_context *ssl ) ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_UNEXPECTED_MESSAGE ); - return( MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE ); + return MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE ; } /* @@ -4129,7 +4129,7 @@ static int ssl_parse_new_session_ticket( mbedtls_ssl_context *ssl ) MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad new session ticket message" ) ); mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } msg = ssl->in_msg + mbedtls_ssl_hs_hdr_len( ssl ); @@ -4144,7 +4144,7 @@ static int ssl_parse_new_session_ticket( mbedtls_ssl_context *ssl ) MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad new session ticket message" ) ); mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } MBEDTLS_SSL_DEBUG_MSG( 3, ( "ticket length: %" MBEDTLS_PRINTF_SIZET, ticket_len ) ); @@ -4158,7 +4158,7 @@ static int ssl_parse_new_session_ticket( mbedtls_ssl_context *ssl ) * to send a ticket after all, so just forget it */ if( ticket_len == 0 ) - return( 0 ); + return 0 ; if( ssl->session != NULL && ssl->session->ticket != NULL ) { @@ -4180,7 +4180,7 @@ static int ssl_parse_new_session_ticket( mbedtls_ssl_context *ssl ) MBEDTLS_SSL_DEBUG_MSG( 1, ( "ticket alloc failed" ) ); mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_INTERNAL_ERROR ); - return( MBEDTLS_ERR_SSL_ALLOC_FAILED ); + return MBEDTLS_ERR_SSL_ALLOC_FAILED ; } memcpy( ticket, msg + 6, ticket_len ); @@ -4199,7 +4199,7 @@ static int ssl_parse_new_session_ticket( mbedtls_ssl_context *ssl ) MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= parse new session ticket" ) ); - return( 0 ); + return 0 ; } #endif /* MBEDTLS_SSL_SESSION_TICKETS */ @@ -4211,19 +4211,19 @@ int mbedtls_ssl_handshake_client_step( mbedtls_ssl_context *ssl ) int ret = 0; if( ssl->state == MBEDTLS_SSL_HANDSHAKE_OVER || ssl->handshake == NULL ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; MBEDTLS_SSL_DEBUG_MSG( 2, ( "client state: %d", ssl->state ) ); if( ( ret = mbedtls_ssl_flush_output( ssl ) ) != 0 ) - return( ret ); + return ret ; #if defined(MBEDTLS_SSL_PROTO_DTLS) if( ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM && ssl->handshake->retransmit_state == MBEDTLS_SSL_RETRANS_SENDING ) { if( ( ret = mbedtls_ssl_flight_transmit( ssl ) ) != 0 ) - return( ret ); + return ret ; } #endif /* MBEDTLS_SSL_PROTO_DTLS */ @@ -4334,9 +4334,9 @@ int mbedtls_ssl_handshake_client_step( mbedtls_ssl_context *ssl ) default: MBEDTLS_SSL_DEBUG_MSG( 1, ( "invalid state %d", ssl->state ) ); - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; } - return( ret ); + return ret ; } #endif /* MBEDTLS_SSL_CLI_C */ diff --git a/library/ssl_cookie.c b/library/ssl_cookie.c index 40b8913b8b..f310a64adb 100644 --- a/library/ssl_cookie.c +++ b/library/ssl_cookie.c @@ -102,19 +102,19 @@ int mbedtls_ssl_cookie_setup( mbedtls_ssl_cookie_ctx *ctx, unsigned char key[COOKIE_MD_OUTLEN]; if( ( ret = f_rng( p_rng, key, sizeof( key ) ) ) != 0 ) - return( ret ); + return ret ; ret = mbedtls_md_setup( &ctx->hmac_ctx, mbedtls_md_info_from_type( COOKIE_MD ), 1 ); if( ret != 0 ) - return( ret ); + return ret ; ret = mbedtls_md_hmac_starts( &ctx->hmac_ctx, key, sizeof( key ) ); if( ret != 0 ) - return( ret ); + return ret ; mbedtls_platform_zeroize( key, sizeof( key ) ); - return( 0 ); + return 0 ; } /* @@ -134,13 +134,13 @@ static int ssl_cookie_hmac( mbedtls_md_context_t *hmac_ctx, mbedtls_md_hmac_update( hmac_ctx, cli_id, cli_id_len ) != 0 || mbedtls_md_hmac_finish( hmac_ctx, hmac_out ) != 0 ) { - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; } memcpy( *p, hmac_out, COOKIE_HMAC_LEN ); *p += COOKIE_HMAC_LEN; - return( 0 ); + return 0 ; } /* @@ -155,7 +155,7 @@ int mbedtls_ssl_cookie_write( void *p_ctx, unsigned long t; if( ctx == NULL || cli_id == NULL ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; MBEDTLS_SSL_CHK_BUF_PTR( *p, end, COOKIE_LEN ); @@ -173,7 +173,7 @@ int mbedtls_ssl_cookie_write( void *p_ctx, #if defined(MBEDTLS_THREADING_C) if( ( ret = mbedtls_mutex_lock( &ctx->mutex ) ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_SSL_INTERNAL_ERROR, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_SSL_INTERNAL_ERROR, ret ) ; #endif ret = ssl_cookie_hmac( &ctx->hmac_ctx, *p - 4, @@ -185,7 +185,7 @@ int mbedtls_ssl_cookie_write( void *p_ctx, MBEDTLS_ERR_THREADING_MUTEX_ERROR ) ); #endif - return( ret ); + return ret ; } /* @@ -202,14 +202,14 @@ int mbedtls_ssl_cookie_check( void *p_ctx, unsigned long cur_time, cookie_time; if( ctx == NULL || cli_id == NULL ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; if( cookie_len != COOKIE_LEN ) - return( -1 ); + return -1 ; #if defined(MBEDTLS_THREADING_C) if( ( ret = mbedtls_mutex_lock( &ctx->mutex ) ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_SSL_INTERNAL_ERROR, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_SSL_INTERNAL_ERROR, ret ) ; #endif if( ssl_cookie_hmac( &ctx->hmac_ctx, cookie, @@ -224,10 +224,10 @@ int mbedtls_ssl_cookie_check( void *p_ctx, #endif if( ret != 0 ) - return( ret ); + return ret ; if( mbedtls_ssl_safer_memcmp( cookie + 4, ref_hmac, sizeof( ref_hmac ) ) != 0 ) - return( -1 ); + return -1 ; #if defined(MBEDTLS_HAVE_TIME) cur_time = (unsigned long) mbedtls_time( NULL ); @@ -241,8 +241,8 @@ int mbedtls_ssl_cookie_check( void *p_ctx, ( (unsigned long) cookie[3] ); if( ctx->timeout != 0 && cur_time - cookie_time > ctx->timeout ) - return( -1 ); + return -1 ; - return( 0 ); + return 0 ; } #endif /* MBEDTLS_SSL_COOKIE_C */ diff --git a/library/ssl_misc.h b/library/ssl_misc.h index cc19f4723b..de33e4e76c 100644 --- a/library/ssl_misc.h +++ b/library/ssl_misc.h @@ -350,7 +350,7 @@ static inline int mbedtls_ssl_chk_buf_ptr( const uint8_t *cur, do { \ if( mbedtls_ssl_chk_buf_ptr( ( cur ), ( end ), ( need ) ) != 0 ) \ { \ - return( MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL ); \ + return MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL ; \ } \ } while( 0 ) @@ -753,10 +753,10 @@ static inline int mbedtls_ssl_transform_uses_aead( const mbedtls_ssl_transform *transform ) { #if defined(MBEDTLS_SSL_SOME_SUITES_USE_MAC) - return( transform->maclen == 0 && transform->taglen != 0 ); + return transform->maclen == 0 && transform->taglen != 0 ; #else (void) transform; - return( 1 ); + return 1 ; #endif } @@ -1015,10 +1015,10 @@ static inline int mbedtls_ssl_get_psk( const mbedtls_ssl_context *ssl, { *psk = NULL; *psk_len = 0; - return( MBEDTLS_ERR_SSL_PRIVATE_KEY_REQUIRED ); + return MBEDTLS_ERR_SSL_PRIVATE_KEY_REQUIRED ; } - return( 0 ); + return 0 ; } #if defined(MBEDTLS_USE_PSA_CRYPTO) @@ -1033,12 +1033,12 @@ static inline psa_key_id_t mbedtls_ssl_get_opaque_psk( const mbedtls_ssl_context *ssl ) { if( ! mbedtls_svc_key_id_is_null( ssl->handshake->psk_opaque ) ) - return( ssl->handshake->psk_opaque ); + return ssl->handshake->psk_opaque ; if( ! mbedtls_svc_key_id_is_null( ssl->conf->psk_opaque ) ) - return( ssl->conf->psk_opaque ); + return ssl->conf->psk_opaque ; - return( MBEDTLS_SVC_KEY_ID_INIT ); + return MBEDTLS_SVC_KEY_ID_INIT ; } #endif /* MBEDTLS_USE_PSA_CRYPTO */ @@ -1076,7 +1076,7 @@ static inline mbedtls_ssl_srtp_profile mbedtls_ssl_check_srtp_profile_value return srtp_profile_value; default: break; } - return( MBEDTLS_TLS_SRTP_UNSET ); + return MBEDTLS_TLS_SRTP_UNSET ; } #endif @@ -1090,7 +1090,7 @@ static inline mbedtls_pk_context *mbedtls_ssl_own_key( mbedtls_ssl_context *ssl else key_cert = ssl->conf->key_cert; - return( key_cert == NULL ? NULL : key_cert->key ); + return key_cert == NULL ? NULL : key_cert->key ; } static inline mbedtls_x509_crt *mbedtls_ssl_own_cert( mbedtls_ssl_context *ssl ) @@ -1102,7 +1102,7 @@ static inline mbedtls_x509_crt *mbedtls_ssl_own_cert( mbedtls_ssl_context *ssl ) else key_cert = ssl->conf->key_cert; - return( key_cert == NULL ? NULL : key_cert->cert ); + return key_cert == NULL ? NULL : key_cert->cert ; } /* @@ -1134,12 +1134,12 @@ static inline size_t mbedtls_ssl_in_hdr_len( const mbedtls_ssl_context *ssl ) #if defined(MBEDTLS_SSL_PROTO_DTLS) if( ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM ) { - return( 13 ); + return 13 ; } else #endif /* MBEDTLS_SSL_PROTO_DTLS */ { - return( 5 ); + return 5 ; } } @@ -1152,11 +1152,11 @@ static inline size_t mbedtls_ssl_hs_hdr_len( const mbedtls_ssl_context *ssl ) { #if defined(MBEDTLS_SSL_PROTO_DTLS) if( ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM ) - return( 12 ); + return 12 ; #else ((void) ssl); #endif - return( 4 ); + return 4 ; } #if defined(MBEDTLS_SSL_PROTO_DTLS) @@ -1192,7 +1192,7 @@ static inline int mbedtls_ssl_safer_memcmp( const void *a, const void *b, size_t diff |= x ^ y; } - return( diff ); + return diff ; } #if defined(MBEDTLS_SSL_PROTO_TLS1_2) @@ -1222,11 +1222,11 @@ static inline size_t mbedtls_ssl_ep_len( const mbedtls_ssl_context *ssl ) { #if defined(MBEDTLS_SSL_PROTO_DTLS) if( ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM ) - return( 2 ); + return 2 ; #else ((void) ssl); #endif - return( 0 ); + return 0 ; } #if defined(MBEDTLS_SSL_PROTO_DTLS) diff --git a/library/ssl_msg.c b/library/ssl_msg.c index 76cc2b17d4..df75e6d673 100644 --- a/library/ssl_msg.c +++ b/library/ssl_msg.c @@ -75,15 +75,15 @@ void mbedtls_ssl_set_timer( mbedtls_ssl_context *ssl, uint32_t millisecs ) int mbedtls_ssl_check_timer( mbedtls_ssl_context *ssl ) { if( ssl->f_get_timer == NULL ) - return( 0 ); + return 0 ; if( ssl->f_get_timer( ssl->p_timer ) == 2 ) { MBEDTLS_SSL_DEBUG_MSG( 3, ( "timer expired" ) ); - return( -1 ); + return -1 ; } - return( 0 ); + return 0 ; } static int ssl_parse_record_header( mbedtls_ssl_context const *ssl, @@ -145,7 +145,7 @@ exit: } MBEDTLS_SSL_DEBUG_MSG( 1, ( "<= mbedtls_ssl_check_record" ) ); - return( ret ); + return ret ; } #define SSL_DONT_FORCE_FLUSH 0 @@ -174,9 +174,9 @@ static size_t ssl_get_maximum_datagram_size( mbedtls_ssl_context const *ssl ) #endif if( mtu != 0 && mtu < out_buf_len ) - return( mtu ); + return mtu ; - return( out_buf_len ); + return out_buf_len ; } static int ssl_get_remaining_space_in_datagram( mbedtls_ssl_context const *ssl ) @@ -189,7 +189,7 @@ static int ssl_get_remaining_space_in_datagram( mbedtls_ssl_context const *ssl ) if( bytes_written > mtu ) { /* Should never happen... */ - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; } return( (int) ( mtu - bytes_written ) ); @@ -217,29 +217,29 @@ static int ssl_get_remaining_payload_in_datagram( mbedtls_ssl_context const *ssl * write datagrams larger than MFL + Record Expansion Overhead. */ if( max_len <= ssl->out_left ) - return( 0 ); + return 0 ; max_len -= ssl->out_left; #endif ret = ssl_get_remaining_space_in_datagram( ssl ); if( ret < 0 ) - return( ret ); + return ret ; remaining = (size_t) ret; ret = mbedtls_ssl_get_record_expansion( ssl ); if( ret < 0 ) - return( ret ); + return ret ; expansion = (size_t) ret; if( remaining <= expansion ) - return( 0 ); + return 0 ; remaining -= expansion; if( remaining >= max_len ) remaining = max_len; - return( (int) remaining ); + return (int) remaining ; } /* @@ -251,7 +251,7 @@ static int ssl_double_retransmit_timeout( mbedtls_ssl_context *ssl ) uint32_t new_timeout; if( ssl->handshake->retransmit_timeout >= ssl->conf->hs_timeout_max ) - return( -1 ); + return -1 ; /* Implement the final paragraph of RFC 6347 section 4.1.1.1 * in the following way: after the initial transmission and a first @@ -278,7 +278,7 @@ static int ssl_double_retransmit_timeout( mbedtls_ssl_context *ssl ) MBEDTLS_SSL_DEBUG_MSG( 3, ( "update timeout value to %lu millisecs", (unsigned long) ssl->handshake->retransmit_timeout ) ); - return( 0 ); + return 0 ; } static void ssl_reset_retransmit_timeout( mbedtls_ssl_context *ssl ) @@ -299,7 +299,7 @@ static void ssl_reset_retransmit_timeout( mbedtls_ssl_context *ssl ) static size_t ssl_compute_padding_length( size_t len, size_t granularity ) { - return( ( granularity - ( len + 1 ) % granularity ) % granularity ); + return ( granularity - ( len + 1 ) % granularity ) % granularity ; } /* This functions transforms a (D)TLS plaintext fragment and a record content @@ -340,19 +340,19 @@ static int ssl_build_inner_plaintext( unsigned char *content, /* Write real content type */ if( remaining == 0 ) - return( -1 ); + return -1 ; content[ len ] = rec_type; len++; remaining--; if( remaining < pad ) - return( -1 ); + return -1 ; memset( content + len, 0, pad ); len += pad; remaining -= pad; *content_size = len; - return( 0 ); + return 0 ; } /* This function parses a (D)TLSInnerPlaintext structure. @@ -367,14 +367,14 @@ static int ssl_parse_inner_plaintext( unsigned char const *content, do { if( remaining == 0 ) - return( -1 ); + return -1 ; remaining--; } while( content[ remaining ] == 0 ); *content_size = remaining; *rec_type = content[ remaining ]; - return( 0 ); + return 0 ; } #endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID || MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL */ @@ -452,7 +452,7 @@ static void ssl_extract_add_data_from_record( unsigned char* add_data, static int ssl_transform_aead_dynamic_iv_is_explicit( mbedtls_ssl_transform const *transform ) { - return( transform->ivlen != transform->fixed_ivlen ); + return transform->ivlen != transform->fixed_ivlen ; } /* Compute IV := ( fixed_iv || 0 ) XOR ( 0 || dynamic_IV ) @@ -529,7 +529,7 @@ int mbedtls_ssl_encrypt_buf( mbedtls_ssl_context *ssl, if( transform == NULL ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "no transform provided to encrypt_buf" ) ); - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; } if( rec == NULL || rec->buf == NULL @@ -541,7 +541,7 @@ int mbedtls_ssl_encrypt_buf( mbedtls_ssl_context *ssl, ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad record structure provided to encrypt_buf" ) ); - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; } data = rec->buf + rec->data_offset; @@ -557,7 +557,7 @@ int mbedtls_ssl_encrypt_buf( mbedtls_ssl_context *ssl, " too large, maximum %" MBEDTLS_PRINTF_SIZET, rec->data_len, (size_t) MBEDTLS_SSL_OUT_CONTENT_LEN ) ); - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; } /* The following two code paths implement the (D)TLSInnerPlaintext @@ -584,7 +584,7 @@ int mbedtls_ssl_encrypt_buf( mbedtls_ssl_context *ssl, rec->type, padding ) != 0 ) { - return( MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL ); + return MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL ; } rec->type = MBEDTLS_SSL_MSG_APPLICATION_DATA; @@ -617,7 +617,7 @@ int mbedtls_ssl_encrypt_buf( mbedtls_ssl_context *ssl, rec->type, padding ) != 0 ) { - return( MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL ); + return MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL ; } rec->type = MBEDTLS_SSL_MSG_CID; @@ -640,7 +640,7 @@ int mbedtls_ssl_encrypt_buf( mbedtls_ssl_context *ssl, if( post_avail < transform->maclen ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "Buffer provided for encrypted record not large enough" ) ); - return( MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL ); + return MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL ; } #if defined(MBEDTLS_SSL_PROTO_TLS1_2) unsigned char mac[MBEDTLS_SSL_MAC_ADD]; @@ -684,13 +684,13 @@ int mbedtls_ssl_encrypt_buf( mbedtls_ssl_context *ssl, data, &olen ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_cipher_crypt", ret ); - return( ret ); + return ret ; } if( rec->data_len != olen ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) ); - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; } } else @@ -714,7 +714,7 @@ int mbedtls_ssl_encrypt_buf( mbedtls_ssl_context *ssl, if( post_avail < transform->taglen ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "Buffer provided for encrypted record not large enough" ) ); - return( MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL ); + return MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL ; } /* @@ -769,7 +769,7 @@ int mbedtls_ssl_encrypt_buf( mbedtls_ssl_context *ssl, transform->taglen ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_cipher_auth_encrypt_ext", ret ); - return( ret ); + return ret ; } MBEDTLS_SSL_DEBUG_BUF( 4, "after encrypt: tag", data + rec->data_len - transform->taglen, @@ -785,7 +785,7 @@ int mbedtls_ssl_encrypt_buf( mbedtls_ssl_context *ssl, if( rec->data_offset < dynamic_iv_len ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "Buffer provided for encrypted record not large enough" ) ); - return( MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL ); + return MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL ; } memcpy( data - dynamic_iv_len, dynamic_iv, dynamic_iv_len ); @@ -814,7 +814,7 @@ int mbedtls_ssl_encrypt_buf( mbedtls_ssl_context *ssl, if( post_avail < padlen + 1 ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "Buffer provided for encrypted record not large enough" ) ); - return( MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL ); + return MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL ; } for( i = 0; i <= padlen; i++ ) @@ -831,13 +831,13 @@ int mbedtls_ssl_encrypt_buf( mbedtls_ssl_context *ssl, if( f_rng == NULL ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "No PRNG provided to encrypt_record routine" ) ); - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; } if( rec->data_offset < transform->ivlen ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "Buffer provided for encrypted record not large enough" ) ); - return( MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL ); + return MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL ; } /* @@ -845,7 +845,7 @@ int mbedtls_ssl_encrypt_buf( mbedtls_ssl_context *ssl, */ ret = f_rng( p_rng, transform->iv_enc, transform->ivlen ); if( ret != 0 ) - return( ret ); + return ret ; memcpy( data - transform->ivlen, transform->iv_enc, transform->ivlen ); #endif /* MBEDTLS_SSL_PROTO_TLS1_2 */ @@ -863,13 +863,13 @@ int mbedtls_ssl_encrypt_buf( mbedtls_ssl_context *ssl, data, &olen ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_cipher_crypt", ret ); - return( ret ); + return ret ; } if( rec->data_len != olen ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) ); - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; } data -= transform->ivlen; @@ -893,7 +893,7 @@ int mbedtls_ssl_encrypt_buf( mbedtls_ssl_context *ssl, if( post_avail < transform->maclen) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "Buffer provided for encrypted record not large enough" ) ); - return( MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL ); + return MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL ; } ssl_extract_add_data_from_record( add_data, &add_data_len, @@ -922,19 +922,19 @@ int mbedtls_ssl_encrypt_buf( mbedtls_ssl_context *ssl, #endif /* MBEDTLS_SSL_SOME_SUITES_USE_CBC) */ { MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) ); - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; } /* Make extra sure authentication was performed, exactly once */ if( auth_done != 1 ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) ); - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; } MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= encrypt buf" ) ); - return( 0 ); + return 0 ; } #if defined(MBEDTLS_SSL_SOME_SUITES_USE_TLS_CBC) @@ -985,7 +985,7 @@ static size_t mbedtls_ssl_cf_mask_lt( size_t x, size_t y ) /* mask = (x < y) ? 0xff... : 0x00... */ const size_t mask = mbedtls_ssl_cf_mask_from_bit( sub1 ); - return( mask ); + return mask ; } /* @@ -1001,7 +1001,7 @@ static size_t mbedtls_ssl_cf_mask_lt( size_t x, size_t y ) */ static size_t mbedtls_ssl_cf_mask_ge( size_t x, size_t y ) { - return( ~mbedtls_ssl_cf_mask_lt( x, y ) ); + return ~mbedtls_ssl_cf_mask_lt( x, y ) ; } /* @@ -1037,7 +1037,7 @@ static size_t mbedtls_ssl_cf_bool_eq( size_t x, size_t y ) /* diff1 = (x != y) ? 1 : 0 */ const size_t diff1 = diff_msb >> ( sizeof( diff_msb ) * 8 - 1 ); - return( 1 ^ diff1 ); + return 1 ^ diff1 ; } /* @@ -1148,7 +1148,7 @@ MBEDTLS_STATIC_TESTABLE int mbedtls_ssl_cf_hmac( cleanup: mbedtls_md_free( &aux ); - return( ret ); + return ret ; } /* @@ -1199,7 +1199,7 @@ int mbedtls_ssl_decrypt_buf( mbedtls_ssl_context const *ssl, rec->buf_len - rec->data_offset < rec->data_len ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad record structure provided to decrypt_buf" ) ); - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; } data = rec->buf + rec->data_offset; @@ -1212,7 +1212,7 @@ int mbedtls_ssl_decrypt_buf( mbedtls_ssl_context const *ssl, if( rec->cid_len != transform->in_cid_len || memcmp( rec->cid, transform->in_cid, rec->cid_len ) != 0 ) { - return( MBEDTLS_ERR_SSL_UNEXPECTED_CID ); + return MBEDTLS_ERR_SSL_UNEXPECTED_CID ; } #endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */ @@ -1227,13 +1227,13 @@ int mbedtls_ssl_decrypt_buf( mbedtls_ssl_context const *ssl, data, &olen ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_cipher_crypt", ret ); - return( ret ); + return ret ; } if( rec->data_len != olen ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) ); - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; } } else @@ -1266,7 +1266,7 @@ int mbedtls_ssl_decrypt_buf( mbedtls_ssl_context const *ssl, " ) < explicit_iv_len (%" MBEDTLS_PRINTF_SIZET ") ", rec->data_len, dynamic_iv_len ) ); - return( MBEDTLS_ERR_SSL_INVALID_MAC ); + return MBEDTLS_ERR_SSL_INVALID_MAC ; } dynamic_iv = data; @@ -1286,7 +1286,7 @@ int mbedtls_ssl_decrypt_buf( mbedtls_ssl_context const *ssl, ") < taglen (%" MBEDTLS_PRINTF_SIZET ") ", rec->data_len, transform->taglen ) ); - return( MBEDTLS_ERR_SSL_INVALID_MAC ); + return MBEDTLS_ERR_SSL_INVALID_MAC ; } rec->data_len -= transform->taglen; @@ -1331,9 +1331,9 @@ int mbedtls_ssl_decrypt_buf( mbedtls_ssl_context const *ssl, MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_cipher_auth_decrypt_ext", ret ); if( ret == MBEDTLS_ERR_CIPHER_AUTH_FAILED ) - return( MBEDTLS_ERR_SSL_INVALID_MAC ); + return MBEDTLS_ERR_SSL_INVALID_MAC ; - return( ret ); + return ret ; } auth_done++; @@ -1341,7 +1341,7 @@ int mbedtls_ssl_decrypt_buf( mbedtls_ssl_context const *ssl, if( olen != rec->data_len ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) ); - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; } } else @@ -1389,7 +1389,7 @@ int mbedtls_ssl_decrypt_buf( mbedtls_ssl_context const *ssl, "+ 1 ) ( + expl IV )", rec->data_len, transform->ivlen, transform->maclen ) ); - return( MBEDTLS_ERR_SSL_INVALID_MAC ); + return MBEDTLS_ERR_SSL_INVALID_MAC ; } /* @@ -1436,7 +1436,7 @@ int mbedtls_ssl_decrypt_buf( mbedtls_ssl_context const *ssl, transform->maclen ) != 0 ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "message mac does not match" ) ); - return( MBEDTLS_ERR_SSL_INVALID_MAC ); + return MBEDTLS_ERR_SSL_INVALID_MAC ; } auth_done++; } @@ -1454,7 +1454,7 @@ int mbedtls_ssl_decrypt_buf( mbedtls_ssl_context const *ssl, MBEDTLS_SSL_DEBUG_MSG( 1, ( "msglen (%" MBEDTLS_PRINTF_SIZET ") %% ivlen (%" MBEDTLS_PRINTF_SIZET ") != 0", rec->data_len, transform->ivlen ) ); - return( MBEDTLS_ERR_SSL_INVALID_MAC ); + return MBEDTLS_ERR_SSL_INVALID_MAC ; } #if defined(MBEDTLS_SSL_PROTO_TLS1_2) @@ -1476,14 +1476,14 @@ int mbedtls_ssl_decrypt_buf( mbedtls_ssl_context const *ssl, data, rec->data_len, data, &olen ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_cipher_crypt", ret ); - return( ret ); + return ret ; } /* Double-check that length hasn't changed during decryption. */ if( rec->data_len != olen ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) ); - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; } /* Safe since data_len >= minlen + maclen + 1, so after having @@ -1573,7 +1573,7 @@ int mbedtls_ssl_decrypt_buf( mbedtls_ssl_context const *ssl, #endif /* MBEDTLS_SSL_SOME_SUITES_USE_CBC */ { MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) ); - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; } #if defined(MBEDTLS_SSL_DEBUG_ALL) @@ -1629,7 +1629,7 @@ int mbedtls_ssl_decrypt_buf( mbedtls_ssl_context const *ssl, if( ret != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_cf_hmac", ret ); - return( ret ); + return ret ; } mbedtls_ssl_cf_memcpy_offset( mac_peer, data, @@ -1658,14 +1658,14 @@ int mbedtls_ssl_decrypt_buf( mbedtls_ssl_context const *ssl, * Finally check the correct flag */ if( correct == 0 ) - return( MBEDTLS_ERR_SSL_INVALID_MAC ); + return MBEDTLS_ERR_SSL_INVALID_MAC ; #endif /* MBEDTLS_SSL_SOME_SUITES_USE_MAC */ /* Make extra sure authentication was performed, exactly once */ if( auth_done != 1 ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) ); - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; } #if defined(MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL) @@ -1676,7 +1676,7 @@ int mbedtls_ssl_decrypt_buf( mbedtls_ssl_context const *ssl, &rec->type ); if( ret != 0 ) - return( MBEDTLS_ERR_SSL_INVALID_RECORD ); + return MBEDTLS_ERR_SSL_INVALID_RECORD ; } #endif /* MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL */ @@ -1686,13 +1686,13 @@ int mbedtls_ssl_decrypt_buf( mbedtls_ssl_context const *ssl, ret = ssl_parse_inner_plaintext( data, &rec->data_len, &rec->type ); if( ret != 0 ) - return( MBEDTLS_ERR_SSL_INVALID_RECORD ); + return MBEDTLS_ERR_SSL_INVALID_RECORD ; } #endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */ MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= decrypt buf" ) ); - return( 0 ); + return 0 ; } #undef MAC_NONE @@ -1730,13 +1730,13 @@ int mbedtls_ssl_fetch_input( mbedtls_ssl_context *ssl, size_t nb_want ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "Bad usage of mbedtls_ssl_set_bio() " "or mbedtls_ssl_set_bio()" ) ); - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; } if( nb_want > in_buf_len - (size_t)( ssl->in_hdr - ssl->in_buf ) ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "requesting more data than fits" ) ); - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; } #if defined(MBEDTLS_SSL_PROTO_DTLS) @@ -1759,7 +1759,7 @@ int mbedtls_ssl_fetch_input( mbedtls_ssl_context *ssl, size_t nb_want ) if( ssl->in_left < ssl->next_record_offset ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) ); - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; } ssl->in_left -= ssl->next_record_offset; @@ -1787,7 +1787,7 @@ int mbedtls_ssl_fetch_input( mbedtls_ssl_context *ssl, size_t nb_want ) if( nb_want <= ssl->in_left) { MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= fetch input" ) ); - return( 0 ); + return 0 ; } /* @@ -1798,7 +1798,7 @@ int mbedtls_ssl_fetch_input( mbedtls_ssl_context *ssl, size_t nb_want ) if( ssl->in_left != 0 ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) ); - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; } /* @@ -1831,7 +1831,7 @@ int mbedtls_ssl_fetch_input( mbedtls_ssl_context *ssl, size_t nb_want ) MBEDTLS_SSL_DEBUG_RET( 2, "ssl->f_recv(_timeout)", ret ); if( ret == 0 ) - return( MBEDTLS_ERR_SSL_CONN_EOF ); + return MBEDTLS_ERR_SSL_CONN_EOF ; } if( ret == MBEDTLS_ERR_SSL_TIMEOUT ) @@ -1844,16 +1844,16 @@ int mbedtls_ssl_fetch_input( mbedtls_ssl_context *ssl, size_t nb_want ) if( ssl_double_retransmit_timeout( ssl ) != 0 ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "handshake timeout" ) ); - return( MBEDTLS_ERR_SSL_TIMEOUT ); + return MBEDTLS_ERR_SSL_TIMEOUT ; } if( ( ret = mbedtls_ssl_resend( ssl ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_resend", ret ); - return( ret ); + return ret ; } - return( MBEDTLS_ERR_SSL_WANT_READ ); + return MBEDTLS_ERR_SSL_WANT_READ ; } #if defined(MBEDTLS_SSL_SRV_C) && defined(MBEDTLS_SSL_RENEGOTIATION) else if( ssl->conf->endpoint == MBEDTLS_SSL_IS_SERVER && @@ -1863,16 +1863,16 @@ int mbedtls_ssl_fetch_input( mbedtls_ssl_context *ssl, size_t nb_want ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_resend_hello_request", ret ); - return( ret ); + return ret ; } - return( MBEDTLS_ERR_SSL_WANT_READ ); + return MBEDTLS_ERR_SSL_WANT_READ ; } #endif /* MBEDTLS_SSL_SRV_C && MBEDTLS_SSL_RENEGOTIATION */ } if( ret < 0 ) - return( ret ); + return ret ; ssl->in_left = ret; } @@ -1910,17 +1910,17 @@ int mbedtls_ssl_fetch_input( mbedtls_ssl_context *ssl, size_t nb_want ) MBEDTLS_SSL_DEBUG_RET( 2, "ssl->f_recv(_timeout)", ret ); if( ret == 0 ) - return( MBEDTLS_ERR_SSL_CONN_EOF ); + return MBEDTLS_ERR_SSL_CONN_EOF ; if( ret < 0 ) - return( ret ); + return ret ; if ( (size_t)ret > len || ( INT_MAX > SIZE_MAX && ret > (int)SIZE_MAX ) ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "f_recv returned %d bytes but only %" MBEDTLS_PRINTF_SIZET " were requested", ret, len ) ); - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; } ssl->in_left += ret; @@ -1929,7 +1929,7 @@ int mbedtls_ssl_fetch_input( mbedtls_ssl_context *ssl, size_t nb_want ) MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= fetch input" ) ); - return( 0 ); + return 0 ; } /* @@ -1946,14 +1946,14 @@ int mbedtls_ssl_flush_output( mbedtls_ssl_context *ssl ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "Bad usage of mbedtls_ssl_set_bio() " "or mbedtls_ssl_set_bio()" ) ); - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; } /* Avoid incrementing counter if data is flushed */ if( ssl->out_left == 0 ) { MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= flush output" ) ); - return( 0 ); + return 0 ; } while( ssl->out_left > 0 ) @@ -1968,14 +1968,14 @@ int mbedtls_ssl_flush_output( mbedtls_ssl_context *ssl ) MBEDTLS_SSL_DEBUG_RET( 2, "ssl->f_send", ret ); if( ret <= 0 ) - return( ret ); + return ret ; if( (size_t)ret > ssl->out_left || ( INT_MAX > SIZE_MAX && ret > (int)SIZE_MAX ) ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "f_send returned %d bytes but only %" MBEDTLS_PRINTF_SIZET " bytes were sent", ret, ssl->out_left ) ); - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; } ssl->out_left -= ret; @@ -1995,7 +1995,7 @@ int mbedtls_ssl_flush_output( mbedtls_ssl_context *ssl ) MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= flush output" ) ); - return( 0 ); + return 0 ; } /* @@ -2017,7 +2017,7 @@ static int ssl_flight_append( mbedtls_ssl_context *ssl ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "alloc %" MBEDTLS_PRINTF_SIZET " bytes failed", sizeof( mbedtls_ssl_flight_item ) ) ); - return( MBEDTLS_ERR_SSL_ALLOC_FAILED ); + return MBEDTLS_ERR_SSL_ALLOC_FAILED ; } if( ( msg->p = mbedtls_calloc( 1, ssl->out_msglen ) ) == NULL ) @@ -2025,7 +2025,7 @@ static int ssl_flight_append( mbedtls_ssl_context *ssl ) MBEDTLS_SSL_DEBUG_MSG( 1, ( "alloc %" MBEDTLS_PRINTF_SIZET " bytes failed", ssl->out_msglen ) ); mbedtls_free( msg ); - return( MBEDTLS_ERR_SSL_ALLOC_FAILED ); + return MBEDTLS_ERR_SSL_ALLOC_FAILED ; } /* Copy current handshake message with headers */ @@ -2046,7 +2046,7 @@ static int ssl_flight_append( mbedtls_ssl_context *ssl ) } MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= ssl_flight_append" ) ); - return( 0 ); + return 0 ; } /* @@ -2079,7 +2079,7 @@ static int ssl_swap_epochs( mbedtls_ssl_context *ssl ) if( ssl->transform_out == ssl->handshake->alt_transform_out ) { MBEDTLS_SSL_DEBUG_MSG( 3, ( "skip swap epochs" ) ); - return( 0 ); + return 0 ; } MBEDTLS_SSL_DEBUG_MSG( 3, ( "swap epochs" ) ); @@ -2097,7 +2097,7 @@ static int ssl_swap_epochs( mbedtls_ssl_context *ssl ) /* Adjust to the newly activated transform */ mbedtls_ssl_update_out_pointers( ssl, ssl->transform_out ); - return( 0 ); + return 0 ; } /* @@ -2113,7 +2113,7 @@ int mbedtls_ssl_resend( mbedtls_ssl_context *ssl ) MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= mbedtls_ssl_resend" ) ); - return( ret ); + return ret ; } /* @@ -2136,7 +2136,7 @@ int mbedtls_ssl_flight_transmit( mbedtls_ssl_context *ssl ) ssl->handshake->cur_msg_p = ssl->handshake->flight->p + 12; ret = ssl_swap_epochs( ssl ); if( ret != 0 ) - return( ret ); + return ret ; ssl->handshake->retransmit_state = MBEDTLS_SSL_RETRANS_SENDING; } @@ -2161,12 +2161,12 @@ int mbedtls_ssl_flight_transmit( mbedtls_ssl_context *ssl ) MBEDTLS_SSL_DEBUG_MSG( 2, ( "swap epochs to send finished message" ) ); ret = ssl_swap_epochs( ssl ); if( ret != 0 ) - return( ret ); + return ret ; } ret = ssl_get_remaining_payload_in_datagram( ssl ); if( ret < 0 ) - return( ret ); + return ret ; max_frag_len = (size_t) ret; /* CCS is copied as is, while HS messages may need fragmentation */ @@ -2175,7 +2175,7 @@ int mbedtls_ssl_flight_transmit( mbedtls_ssl_context *ssl ) if( max_frag_len == 0 ) { if( ( ret = mbedtls_ssl_flush_output( ssl ) ) != 0 ) - return( ret ); + return ret ; continue; } @@ -2201,11 +2201,11 @@ int mbedtls_ssl_flight_transmit( mbedtls_ssl_context *ssl ) { ret = ssl_swap_epochs( ssl ); if( ret != 0 ) - return( ret ); + return ret ; } if( ( ret = mbedtls_ssl_flush_output( ssl ) ) != 0 ) - return( ret ); + return ret ; continue; } @@ -2264,12 +2264,12 @@ int mbedtls_ssl_flight_transmit( mbedtls_ssl_context *ssl ) if( ( ret = mbedtls_ssl_write_record( ssl, force_flush ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_write_record", ret ); - return( ret ); + return ret ; } } if( ( ret = mbedtls_ssl_flush_output( ssl ) ) != 0 ) - return( ret ); + return ret ; /* Update state and set timer */ if( ssl->state == MBEDTLS_SSL_HANDSHAKE_OVER ) @@ -2282,7 +2282,7 @@ int mbedtls_ssl_flight_transmit( mbedtls_ssl_context *ssl ) MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= mbedtls_ssl_flight_transmit" ) ); - return( 0 ); + return 0 ; } /* @@ -2375,7 +2375,7 @@ int mbedtls_ssl_write_handshake_msg( mbedtls_ssl_context *ssl ) ssl->out_msgtype != MBEDTLS_SSL_MSG_CHANGE_CIPHER_SPEC ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) ); - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; } /* Whenever we send anything different from a @@ -2385,7 +2385,7 @@ int mbedtls_ssl_write_handshake_msg( mbedtls_ssl_context *ssl ) ssl->handshake == NULL ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) ); - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; } #if defined(MBEDTLS_SSL_PROTO_DTLS) @@ -2394,7 +2394,7 @@ int mbedtls_ssl_write_handshake_msg( mbedtls_ssl_context *ssl ) ssl->handshake->retransmit_state == MBEDTLS_SSL_RETRANS_SENDING ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) ); - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; } #endif @@ -2413,7 +2413,7 @@ int mbedtls_ssl_write_handshake_msg( mbedtls_ssl_context *ssl ) ", maximum %" MBEDTLS_PRINTF_SIZET, ssl->out_msglen, (size_t) MBEDTLS_SSL_OUT_CONTENT_LEN ) ); - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; } /* @@ -2442,7 +2442,7 @@ int mbedtls_ssl_write_handshake_msg( mbedtls_ssl_context *ssl ) "size %" MBEDTLS_PRINTF_SIZET ", maximum %" MBEDTLS_PRINTF_SIZET, hs_len, (size_t) ( MBEDTLS_SSL_OUT_CONTENT_LEN - 12 ) ) ); - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; } memmove( ssl->out_msg + 12, ssl->out_msg + 4, hs_len ); @@ -2482,7 +2482,7 @@ int mbedtls_ssl_write_handshake_msg( mbedtls_ssl_context *ssl ) if( ( ret = ssl_flight_append( ssl ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "ssl_flight_append", ret ); - return( ret ); + return ret ; } } else @@ -2491,13 +2491,13 @@ int mbedtls_ssl_write_handshake_msg( mbedtls_ssl_context *ssl ) if( ( ret = mbedtls_ssl_write_record( ssl, SSL_FORCE_FLUSH ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "ssl_write_record", ret ); - return( ret ); + return ret ; } } MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= write handshake message" ) ); - return( 0 ); + return 0 ; } /* @@ -2562,13 +2562,13 @@ int mbedtls_ssl_write_record( mbedtls_ssl_context *ssl, uint8_t force_flush ) ssl->conf->f_rng, ssl->conf->p_rng ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "ssl_encrypt_buf", ret ); - return( ret ); + return ret ; } if( rec.data_offset != 0 ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) ); - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; } /* Update the record content type and CID. */ @@ -2590,12 +2590,12 @@ int mbedtls_ssl_write_record( mbedtls_ssl_context *ssl, uint8_t force_flush ) { ret = ssl_get_remaining_space_in_datagram( ssl ); if( ret < 0 ) - return( ret ); + return ret ; if( protected_record_size > (size_t) ret ) { /* Should never happen */ - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; } } #endif /* MBEDTLS_SSL_PROTO_DTLS */ @@ -2623,7 +2623,7 @@ int mbedtls_ssl_write_record( mbedtls_ssl_context *ssl, uint8_t force_flush ) if( i == mbedtls_ssl_ep_len( ssl ) ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "outgoing message counter would wrap" ) ); - return( MBEDTLS_ERR_SSL_COUNTER_WRAPPING ); + return MBEDTLS_ERR_SSL_COUNTER_WRAPPING ; } } @@ -2637,7 +2637,7 @@ int mbedtls_ssl_write_record( mbedtls_ssl_context *ssl, uint8_t force_flush ) { MBEDTLS_SSL_DEBUG_RET( 1, "ssl_get_remaining_payload_in_datagram", ret ); - return( ret ); + return ret ; } remaining = (size_t) ret; @@ -2656,12 +2656,12 @@ int mbedtls_ssl_write_record( mbedtls_ssl_context *ssl, uint8_t force_flush ) ( ret = mbedtls_ssl_flush_output( ssl ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_flush_output", ret ); - return( ret ); + return ret ; } MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= write record" ) ); - return( 0 ); + return 0 ; } #if defined(MBEDTLS_SSL_PROTO_DTLS) @@ -2672,9 +2672,9 @@ static int ssl_hs_is_proper_fragment( mbedtls_ssl_context *ssl ) memcmp( ssl->in_msg + 6, "\0\0\0", 3 ) != 0 || memcmp( ssl->in_msg + 9, ssl->in_msg + 1, 3 ) != 0 ) { - return( 1 ); + return 1 ; } - return( 0 ); + return 0 ; } static uint32_t ssl_get_hs_frag_len( mbedtls_ssl_context const *ssl ) @@ -2700,15 +2700,15 @@ static int ssl_check_hs_header( mbedtls_ssl_context const *ssl ) frag_len = ssl_get_hs_frag_len( ssl ); if( frag_off > msg_len ) - return( -1 ); + return -1 ; if( frag_len > msg_len - frag_off ) - return( -1 ); + return -1 ; if( frag_len + 12 > ssl->in_msglen ) - return( -1 ); + return -1 ; - return( 0 ); + return 0 ; } /* @@ -2763,13 +2763,13 @@ static int ssl_bitmask_check( unsigned char *mask, size_t len ) for( i = 0; i < len / 8; i++ ) if( mask[i] != 0xFF ) - return( -1 ); + return -1 ; for( i = 0; i < len % 8; i++ ) if( ( mask[len / 8] & ( 1 << ( 7 - i ) ) ) == 0 ) - return( -1 ); + return -1 ; - return( 0 ); + return 0 ; } /* msg_len does not include the handshake header */ @@ -2784,7 +2784,7 @@ static size_t ssl_get_reassembly_buffer_size( size_t msg_len, if( add_bitmap ) alloc_len += msg_len / 8 + ( msg_len % 8 != 0 ); /* Bitmap */ - return( alloc_len ); + return alloc_len ; } #endif /* MBEDTLS_SSL_PROTO_DTLS */ @@ -2802,7 +2802,7 @@ int mbedtls_ssl_prepare_handshake_record( mbedtls_ssl_context *ssl ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "handshake message too short: %" MBEDTLS_PRINTF_SIZET, ssl->in_msglen ) ); - return( MBEDTLS_ERR_SSL_INVALID_RECORD ); + return MBEDTLS_ERR_SSL_INVALID_RECORD ; } ssl->in_hslen = mbedtls_ssl_hs_hdr_len( ssl ) + ssl_get_hs_total_len( ssl ); @@ -2820,7 +2820,7 @@ int mbedtls_ssl_prepare_handshake_record( mbedtls_ssl_context *ssl ) if( ssl_check_hs_header( ssl ) != 0 ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "invalid handshake header" ) ); - return( MBEDTLS_ERR_SSL_INVALID_RECORD ); + return MBEDTLS_ERR_SSL_INVALID_RECORD ; } if( ssl->handshake != NULL && @@ -2834,7 +2834,7 @@ int mbedtls_ssl_prepare_handshake_record( mbedtls_ssl_context *ssl ) MBEDTLS_SSL_DEBUG_MSG( 2, ( "received future handshake message of sequence number %u (next %u)", recv_msg_seq, ssl->handshake->in_msg_seq ) ); - return( MBEDTLS_ERR_SSL_EARLY_MESSAGE ); + return MBEDTLS_ERR_SSL_EARLY_MESSAGE ; } /* Retransmit only on last message from previous flight, to avoid @@ -2851,7 +2851,7 @@ int mbedtls_ssl_prepare_handshake_record( mbedtls_ssl_context *ssl ) if( ( ret = mbedtls_ssl_resend( ssl ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_resend", ret ); - return( ret ); + return ret ; } } else @@ -2862,7 +2862,7 @@ int mbedtls_ssl_prepare_handshake_record( mbedtls_ssl_context *ssl ) ssl->handshake->in_msg_seq ) ); } - return( MBEDTLS_ERR_SSL_CONTINUE_PROCESSING ); + return MBEDTLS_ERR_SSL_CONTINUE_PROCESSING ; } /* Wait until message completion to increment in_msg_seq */ @@ -2873,7 +2873,7 @@ int mbedtls_ssl_prepare_handshake_record( mbedtls_ssl_context *ssl ) if( ssl_hs_is_proper_fragment( ssl ) == 1 ) { MBEDTLS_SSL_DEBUG_MSG( 2, ( "found fragmented DTLS handshake message" ) ); - return( MBEDTLS_ERR_SSL_EARLY_MESSAGE ); + return MBEDTLS_ERR_SSL_EARLY_MESSAGE ; } } else @@ -2882,10 +2882,10 @@ int mbedtls_ssl_prepare_handshake_record( mbedtls_ssl_context *ssl ) if( ssl->in_msglen < ssl->in_hslen ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "TLS handshake fragmentation not supported" ) ); - return( MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE ; } - return( 0 ); + return 0 ; } void mbedtls_ssl_update_handshake_status( mbedtls_ssl_context *ssl ) @@ -2984,20 +2984,20 @@ int mbedtls_ssl_dtls_replay_check( mbedtls_ssl_context const *ssl ) uint64_t bit; if( ssl->conf->anti_replay == MBEDTLS_SSL_ANTI_REPLAY_DISABLED ) - return( 0 ); + return 0 ; if( rec_seqnum > ssl->in_window_top ) - return( 0 ); + return 0 ; bit = ssl->in_window_top - rec_seqnum; if( bit >= 64 ) - return( -1 ); + return -1 ; if( ( ssl->in_window & ( (uint64_t) 1 << bit ) ) != 0 ) - return( -1 ); + return -1 ; - return( 0 ); + return 0 ; } /* @@ -3090,22 +3090,22 @@ static int ssl_check_dtls_clihlo_cookie( in[3] != 0 || in[4] != 0 || in[19] != 0 || in[20] != 0 || in[21] != 0 ) { - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } sid_len = in[59]; if( sid_len > in_len - 61 ) - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; cookie_len = in[60 + sid_len]; if( cookie_len > in_len - 60 ) - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; if( f_cookie_check( p_cookie, in + sid_len + 61, cookie_len, cli_id, cli_id_len ) == 0 ) { /* Valid cookie */ - return( 0 ); + return 0 ; } /* @@ -3129,7 +3129,7 @@ static int ssl_check_dtls_clihlo_cookie( * Minimum length is 28. */ if( buf_len < 28 ) - return( MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL ); + return MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL ; /* Copy most fields and adapt others */ memcpy( obuf, in, 25 ); @@ -3142,7 +3142,7 @@ static int ssl_check_dtls_clihlo_cookie( if( f_cookie_write( p_cookie, &p, obuf + buf_len, cli_id, cli_id_len ) != 0 ) { - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; } *olen = p - obuf; @@ -3157,7 +3157,7 @@ static int ssl_check_dtls_clihlo_cookie( obuf[11] = (unsigned char)( ( *olen - 13 ) >> 8 ); obuf[12] = (unsigned char)( ( *olen - 13 ) ); - return( MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED ); + return MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED ; } /* @@ -3192,7 +3192,7 @@ static int ssl_handle_possible_reconnect( mbedtls_ssl_context *ssl ) * drop the record. */ MBEDTLS_SSL_DEBUG_MSG( 1, ( "no cookie callbacks, " "can't check reconnect validity" ) ); - return( 0 ); + return 0 ; } ret = ssl_check_dtls_clihlo_cookie( @@ -3218,7 +3218,7 @@ static int ssl_handle_possible_reconnect( mbedtls_ssl_context *ssl ) MBEDTLS_SSL_DEBUG_RET( 2, "ssl->f_send", send_ret ); (void) send_ret; - return( 0 ); + return 0 ; } if( ret == 0 ) @@ -3227,13 +3227,13 @@ static int ssl_handle_possible_reconnect( mbedtls_ssl_context *ssl ) if( ( ret = mbedtls_ssl_session_reset_int( ssl, 1 ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "reset", ret ); - return( ret ); + return ret ; } - return( MBEDTLS_ERR_SSL_CLIENT_RECONNECT ); + return MBEDTLS_ERR_SSL_CLIENT_RECONNECT ; } - return( ret ); + return ret ; } #endif /* MBEDTLS_SSL_DTLS_CLIENT_PORT_REUSE && MBEDTLS_SSL_SRV_C */ @@ -3244,10 +3244,10 @@ static int ssl_check_record_type( uint8_t record_type ) record_type != MBEDTLS_SSL_MSG_CHANGE_CIPHER_SPEC && record_type != MBEDTLS_SSL_MSG_APPLICATION_DATA ) { - return( MBEDTLS_ERR_SSL_INVALID_RECORD ); + return MBEDTLS_ERR_SSL_INVALID_RECORD ; } - return( 0 ); + return 0 ; } /* @@ -3319,7 +3319,7 @@ static int ssl_parse_record_header( mbedtls_ssl_context const *ssl, MBEDTLS_SSL_DEBUG_MSG( 1, ( "datagram of length %u too small to hold DTLS record header of length %u", (unsigned) len, (unsigned)( rec_hdr_len_len + rec_hdr_len_len ) ) ); - return( MBEDTLS_ERR_SSL_INVALID_RECORD ); + return MBEDTLS_ERR_SSL_INVALID_RECORD ; } /* @@ -3359,7 +3359,7 @@ static int ssl_parse_record_header( mbedtls_ssl_context const *ssl, MBEDTLS_SSL_DEBUG_MSG( 1, ( "datagram of length %u too small to hold DTLS record header including CID, length %u", (unsigned) len, (unsigned)( rec_hdr_len_offset + rec_hdr_len_len ) ) ); - return( MBEDTLS_ERR_SSL_INVALID_RECORD ); + return MBEDTLS_ERR_SSL_INVALID_RECORD ; } /* configured CID len is guaranteed at most 255, see @@ -3374,7 +3374,7 @@ static int ssl_parse_record_header( mbedtls_ssl_context const *ssl, { MBEDTLS_SSL_DEBUG_MSG( 1, ( "unknown record type %u", (unsigned) rec->type ) ); - return( MBEDTLS_ERR_SSL_INVALID_RECORD ); + return MBEDTLS_ERR_SSL_INVALID_RECORD ; } } @@ -3391,13 +3391,13 @@ static int ssl_parse_record_header( mbedtls_ssl_context const *ssl, if( major_ver != ssl->major_ver ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "major version mismatch" ) ); - return( MBEDTLS_ERR_SSL_INVALID_RECORD ); + return MBEDTLS_ERR_SSL_INVALID_RECORD ; } if( minor_ver > ssl->conf->max_minor_ver ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "minor version mismatch" ) ); - return( MBEDTLS_ERR_SSL_INVALID_RECORD ); + return MBEDTLS_ERR_SSL_INVALID_RECORD ; } /* @@ -3436,7 +3436,7 @@ static int ssl_parse_record_header( mbedtls_ssl_context const *ssl, rec->buf_len = rec->data_offset + rec->data_len; if( rec->data_len == 0 ) - return( MBEDTLS_ERR_SSL_INVALID_RECORD ); + return MBEDTLS_ERR_SSL_INVALID_RECORD ; /* * DTLS-related tests. @@ -3462,7 +3462,7 @@ static int ssl_parse_record_header( mbedtls_ssl_context const *ssl, MBEDTLS_SSL_DEBUG_MSG( 1, ( "Datagram of length %u too small to contain record of advertised length %u.", (unsigned) len, (unsigned)( rec->data_offset + rec->data_len ) ) ); - return( MBEDTLS_ERR_SSL_INVALID_RECORD ); + return MBEDTLS_ERR_SSL_INVALID_RECORD ; } /* Records from other, non-matching epochs are silently discarded. @@ -3479,10 +3479,10 @@ static int ssl_parse_record_header( mbedtls_ssl_context const *ssl, if( rec_epoch == (unsigned) ssl->in_epoch + 1 ) { MBEDTLS_SSL_DEBUG_MSG( 2, ( "Consider record for buffering" ) ); - return( MBEDTLS_ERR_SSL_EARLY_MESSAGE ); + return MBEDTLS_ERR_SSL_EARLY_MESSAGE ; } - return( MBEDTLS_ERR_SSL_UNEXPECTED_RECORD ); + return MBEDTLS_ERR_SSL_UNEXPECTED_RECORD ; } #if defined(MBEDTLS_SSL_DTLS_ANTI_REPLAY) /* For records from the correct epoch, check whether their @@ -3491,13 +3491,13 @@ static int ssl_parse_record_header( mbedtls_ssl_context const *ssl, &rec->ctr[0] ) != 0 ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "replayed record" ) ); - return( MBEDTLS_ERR_SSL_UNEXPECTED_RECORD ); + return MBEDTLS_ERR_SSL_UNEXPECTED_RECORD ; } #endif } #endif /* MBEDTLS_SSL_PROTO_DTLS */ - return( 0 ); + return 0 ; } @@ -3521,10 +3521,10 @@ static int ssl_check_client_reconnect( mbedtls_ssl_context *ssl ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "possible client reconnect " "from the same port" ) ); - return( ssl_handle_possible_reconnect( ssl ) ); + return ssl_handle_possible_reconnect( ssl ) ; } - return( 0 ); + return 0 ; } #endif /* MBEDTLS_SSL_DTLS_CLIENT_PORT_REUSE && MBEDTLS_SSL_SRV_C */ @@ -3558,7 +3558,7 @@ static int ssl_prepare_record_content( mbedtls_ssl_context *ssl, } #endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */ - return( ret ); + return ret ; } if( old_msg_type != rec->type ) @@ -3581,7 +3581,7 @@ static int ssl_prepare_record_content( mbedtls_ssl_context *ssl, if( ssl_check_record_type( rec->type ) ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "unknown record type" ) ); - return( MBEDTLS_ERR_SSL_INVALID_RECORD ); + return MBEDTLS_ERR_SSL_INVALID_RECORD ; } #endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */ @@ -3593,7 +3593,7 @@ static int ssl_prepare_record_content( mbedtls_ssl_context *ssl, { /* TLS v1.2 explicitly disallows zero-length messages which are not application data */ MBEDTLS_SSL_DEBUG_MSG( 1, ( "invalid zero-length message type: %d", ssl->in_msgtype ) ); - return( MBEDTLS_ERR_SSL_INVALID_RECORD ); + return MBEDTLS_ERR_SSL_INVALID_RECORD ; } #endif /* MBEDTLS_SSL_PROTO_TLS1_2 */ @@ -3610,7 +3610,7 @@ static int ssl_prepare_record_content( mbedtls_ssl_context *ssl, /* Treat the records as if they were not properly authenticated, * thereby failing the connection if we see more than allowed * by the configured bad MAC threshold. */ - return( MBEDTLS_ERR_SSL_INVALID_MAC ); + return MBEDTLS_ERR_SSL_INVALID_MAC ; } } else @@ -3633,7 +3633,7 @@ static int ssl_prepare_record_content( mbedtls_ssl_context *ssl, if( i == mbedtls_ssl_ep_len( ssl ) ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "incoming message counter would wrap" ) ); - return( MBEDTLS_ERR_SSL_COUNTER_WRAPPING ); + return MBEDTLS_ERR_SSL_COUNTER_WRAPPING ; } } @@ -3651,10 +3651,10 @@ static int ssl_prepare_record_content( mbedtls_ssl_context *ssl, if( ssl->in_msglen > MBEDTLS_SSL_IN_CONTENT_LEN ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad message length" ) ); - return( MBEDTLS_ERR_SSL_INVALID_RECORD ); + return MBEDTLS_ERR_SSL_INVALID_RECORD ; } - return( 0 ); + return 0 ; } /* @@ -3683,7 +3683,7 @@ int mbedtls_ssl_read_record( mbedtls_ssl_context *ssl, ret = ssl_consume_current_message( ssl ); if( ret != 0 ) - return( ret ); + return ret ; if( ssl_record_is_in_progress( ssl ) == 0 ) { @@ -3709,7 +3709,7 @@ int mbedtls_ssl_read_record( mbedtls_ssl_context *ssl, if( ret != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, ( "ssl_get_next_record" ), ret ); - return( ret ); + return ret ; } } } @@ -3722,7 +3722,7 @@ int mbedtls_ssl_read_record( mbedtls_ssl_context *ssl, /* Buffer future message */ ret = ssl_buffer_message( ssl ); if( ret != 0 ) - return( ret ); + return ret ; ret = MBEDTLS_ERR_SSL_CONTINUE_PROCESSING; } @@ -3734,7 +3734,7 @@ int mbedtls_ssl_read_record( mbedtls_ssl_context *ssl, if( 0 != ret ) { MBEDTLS_SSL_DEBUG_RET( 1, ( "mbedtls_ssl_handle_message_type" ), ret ); - return( ret ); + return ret ; } if( ssl->in_msgtype == MBEDTLS_SSL_MSG_HANDSHAKE && @@ -3751,16 +3751,16 @@ int mbedtls_ssl_read_record( mbedtls_ssl_context *ssl, MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= read record" ) ); - return( 0 ); + return 0 ; } #if defined(MBEDTLS_SSL_PROTO_DTLS) static int ssl_next_record_is_in_datagram( mbedtls_ssl_context *ssl ) { if( ssl->in_left > ssl->next_record_offset ) - return( 1 ); + return 1 ; - return( 0 ); + return 0 ; } static int ssl_load_buffered_message( mbedtls_ssl_context *ssl ) @@ -3770,7 +3770,7 @@ static int ssl_load_buffered_message( mbedtls_ssl_context *ssl ) int ret = 0; if( hs == NULL ) - return( -1 ); + return -1 ; MBEDTLS_SSL_DEBUG_MSG( 2, ( "=> ssl_load_buffered_messsage" ) ); @@ -3831,7 +3831,7 @@ static int ssl_load_buffered_message( mbedtls_ssl_context *ssl ) if( msg_len + 12 > MBEDTLS_SSL_IN_CONTENT_LEN ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) ); - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; } MBEDTLS_SSL_DEBUG_MSG( 2, ( "Next handshake message has been buffered - load" ) ); @@ -3857,7 +3857,7 @@ static int ssl_load_buffered_message( mbedtls_ssl_context *ssl ) exit: MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= ssl_load_buffered_message" ) ); - return( ret ); + return ret ; } static int ssl_buffer_make_space( mbedtls_ssl_context *ssl, @@ -3876,7 +3876,7 @@ static int ssl_buffer_make_space( mbedtls_ssl_context *ssl, hs->buffering.total_bytes_buffered ) ) { MBEDTLS_SSL_DEBUG_MSG( 2, ( "Enough space available after freeing future epoch record" ) ); - return( 0 ); + return 0 ; } /* We don't have enough space to buffer the next expected handshake @@ -3895,11 +3895,11 @@ static int ssl_buffer_make_space( mbedtls_ssl_context *ssl, hs->buffering.total_bytes_buffered ) ) { MBEDTLS_SSL_DEBUG_MSG( 2, ( "Enough space available after freeing buffered HS messages" ) ); - return( 0 ); + return 0 ; } } - return( -1 ); + return -1 ; } static int ssl_buffer_message( mbedtls_ssl_context *ssl ) @@ -3908,7 +3908,7 @@ static int ssl_buffer_message( mbedtls_ssl_context *ssl ) mbedtls_ssl_handshake_params * const hs = ssl->handshake; if( hs == NULL ) - return( 0 ); + return 0 ; MBEDTLS_SSL_DEBUG_MSG( 2, ( "=> ssl_buffer_message" ) ); @@ -3932,7 +3932,7 @@ static int ssl_buffer_message( mbedtls_ssl_context *ssl ) if( recv_msg_seq < ssl->handshake->in_msg_seq ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) ); - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; } recv_msg_seq_offset = recv_msg_seq - ssl->handshake->in_msg_seq; @@ -3977,7 +3977,7 @@ static int ssl_buffer_message( mbedtls_ssl_context *ssl ) MBEDTLS_SSL_DTLS_MAX_BUFFERING ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) ); - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; } reassembly_buf_sz = ssl_get_reassembly_buffer_size( msg_len, @@ -4102,7 +4102,7 @@ static int ssl_buffer_message( mbedtls_ssl_context *ssl ) exit: MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= ssl_buffer_message" ) ); - return( ret ); + return ret ; } #endif /* MBEDTLS_SSL_PROTO_DTLS */ @@ -4139,7 +4139,7 @@ static int ssl_consume_current_message( mbedtls_ssl_context *ssl ) if( ssl->in_offt != NULL ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) ); - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; } /* @@ -4182,7 +4182,7 @@ static int ssl_consume_current_message( mbedtls_ssl_context *ssl ) /* Case (4): Application data */ else if( ssl->in_offt != NULL ) { - return( 0 ); + return 0 ; } /* Everything else (CCS & Alerts) */ else @@ -4190,15 +4190,15 @@ static int ssl_consume_current_message( mbedtls_ssl_context *ssl ) ssl->in_msglen = 0; } - return( 0 ); + return 0 ; } static int ssl_record_is_in_progress( mbedtls_ssl_context *ssl ) { if( ssl->in_msglen > 0 ) - return( 1 ); + return 1 ; - return( 0 ); + return 0 ; } #if defined(MBEDTLS_SSL_PROTO_DTLS) @@ -4231,22 +4231,22 @@ static int ssl_load_buffered_record( mbedtls_ssl_context *ssl ) size_t in_buf_len = MBEDTLS_SSL_IN_BUFFER_LEN; #endif if( ssl->conf->transport != MBEDTLS_SSL_TRANSPORT_DATAGRAM ) - return( 0 ); + return 0 ; if( hs == NULL ) - return( 0 ); + return 0 ; rec = hs->buffering.future_record.data; rec_len = hs->buffering.future_record.len; rec_epoch = hs->buffering.future_record.epoch; if( rec == NULL ) - return( 0 ); + return 0 ; /* Only consider loading future records if the * input buffer is empty. */ if( ssl_next_record_is_in_datagram( ssl ) == 1 ) - return( 0 ); + return 0 ; MBEDTLS_SSL_DEBUG_MSG( 2, ( "=> ssl_load_buffered_record" ) ); @@ -4262,7 +4262,7 @@ static int ssl_load_buffered_record( mbedtls_ssl_context *ssl ) if( rec_len > in_buf_len - (size_t)( ssl->in_hdr - ssl->in_buf ) ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) ); - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; } memcpy( ssl->in_hdr, rec, rec_len ); @@ -4273,7 +4273,7 @@ static int ssl_load_buffered_record( mbedtls_ssl_context *ssl ) exit: MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= ssl_load_buffered_record" ) ); - return( 0 ); + return 0 ; } static int ssl_buffer_future_record( mbedtls_ssl_context *ssl, @@ -4283,16 +4283,16 @@ static int ssl_buffer_future_record( mbedtls_ssl_context *ssl, /* Don't buffer future records outside handshakes. */ if( hs == NULL ) - return( 0 ); + return 0 ; /* Only buffer handshake records (we are only interested * in Finished messages). */ if( rec->type != MBEDTLS_SSL_MSG_HANDSHAKE ) - return( 0 ); + return 0 ; /* Don't buffer more than one future epoch record. */ if( hs->buffering.future_record.data != NULL ) - return( 0 ); + return 0 ; /* Don't buffer record if there's not enough buffering space remaining. */ if( rec->buf_len > ( MBEDTLS_SSL_DTLS_MAX_BUFFERING - @@ -4304,7 +4304,7 @@ static int ssl_buffer_future_record( mbedtls_ssl_context *ssl, " bytes buffered) -- ignore\n", rec->buf_len, (size_t) MBEDTLS_SSL_DTLS_MAX_BUFFERING, hs->buffering.total_bytes_buffered ) ); - return( 0 ); + return 0 ; } /* Buffer record */ @@ -4323,13 +4323,13 @@ static int ssl_buffer_future_record( mbedtls_ssl_context *ssl, { /* If we run out of RAM trying to buffer a * record from the next epoch, just ignore. */ - return( 0 ); + return 0 ; } memcpy( hs->buffering.future_record.data, rec->buf, rec->buf_len ); hs->buffering.total_bytes_buffered += rec->buf_len; - return( 0 ); + return 0 ; } #endif /* MBEDTLS_SSL_PROTO_DTLS */ @@ -4348,7 +4348,7 @@ static int ssl_get_next_record( mbedtls_ssl_context *ssl ) * essentially be no-ops. */ ret = ssl_load_buffered_record( ssl ); if( ret != 0 ) - return( ret ); + return ret ; #endif /* MBEDTLS_SSL_PROTO_DTLS */ /* Ensure that we have enough space available for the default form @@ -4358,7 +4358,7 @@ static int ssl_get_next_record( mbedtls_ssl_context *ssl ) if( ret != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_fetch_input", ret ); - return( ret ); + return ret ; } ret = ssl_parse_record_header( ssl, ssl->in_hdr, ssl->in_left, &rec ); @@ -4371,7 +4371,7 @@ static int ssl_get_next_record( mbedtls_ssl_context *ssl ) { ret = ssl_buffer_future_record( ssl, &rec ); if( ret != 0 ) - return( ret ); + return ret ; /* Fall through to handling of unexpected records */ ret = MBEDTLS_ERR_SSL_UNEXPECTED_RECORD; @@ -4396,7 +4396,7 @@ static int ssl_get_next_record( mbedtls_ssl_context *ssl ) ret = ssl_check_client_reconnect( ssl ); MBEDTLS_SSL_DEBUG_RET( 2, "ssl_check_client_reconnect", ret ); if( ret != 0 ) - return( ret ); + return ret ; #endif /* Skip unexpected record (but not whole datagram) */ @@ -4416,12 +4416,12 @@ static int ssl_get_next_record( mbedtls_ssl_context *ssl ) } /* Get next record */ - return( MBEDTLS_ERR_SSL_CONTINUE_PROCESSING ); + return MBEDTLS_ERR_SSL_CONTINUE_PROCESSING ; } else #endif { - return( ret ); + return ret ; } } @@ -4445,7 +4445,7 @@ static int ssl_get_next_record( mbedtls_ssl_context *ssl ) if( ret != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_fetch_input", ret ); - return( ret ); + return ret ; } ssl->in_left = 0; @@ -4477,14 +4477,14 @@ static int ssl_get_next_record( mbedtls_ssl_context *ssl ) MBEDTLS_SSL_ALERT_MSG_BAD_RECORD_MAC ); } #endif - return( ret ); + return ret ; } if( ssl->conf->badmac_limit != 0 && ++ssl->badmac_seen >= ssl->conf->badmac_limit ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "too many records with bad MAC" ) ); - return( MBEDTLS_ERR_SSL_INVALID_MAC ); + return MBEDTLS_ERR_SSL_INVALID_MAC ; } /* As above, invalid records cause @@ -4494,10 +4494,10 @@ static int ssl_get_next_record( mbedtls_ssl_context *ssl ) ssl->in_left = 0; MBEDTLS_SSL_DEBUG_MSG( 1, ( "discarding invalid record (mac)" ) ); - return( MBEDTLS_ERR_SSL_CONTINUE_PROCESSING ); + return MBEDTLS_ERR_SSL_CONTINUE_PROCESSING ; } - return( ret ); + return ret ; } else #endif @@ -4511,7 +4511,7 @@ static int ssl_get_next_record( mbedtls_ssl_context *ssl ) MBEDTLS_SSL_ALERT_MSG_BAD_RECORD_MAC ); } #endif - return( ret ); + return ret ; } } @@ -4538,7 +4538,7 @@ static int ssl_get_next_record( mbedtls_ssl_context *ssl ) ssl->in_len[0] = (unsigned char)( rec.data_len >> 8 ); ssl->in_len[1] = (unsigned char)( rec.data_len ); - return( 0 ); + return 0 ; } int mbedtls_ssl_handle_message_type( mbedtls_ssl_context *ssl ) @@ -4552,7 +4552,7 @@ int mbedtls_ssl_handle_message_type( mbedtls_ssl_context *ssl ) { if( ( ret = mbedtls_ssl_prepare_handshake_record( ssl ) ) != 0 ) { - return( ret ); + return ret ; } } @@ -4562,14 +4562,14 @@ int mbedtls_ssl_handle_message_type( mbedtls_ssl_context *ssl ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "invalid CCS message, len: %" MBEDTLS_PRINTF_SIZET, ssl->in_msglen ) ); - return( MBEDTLS_ERR_SSL_INVALID_RECORD ); + return MBEDTLS_ERR_SSL_INVALID_RECORD ; } if( ssl->in_msg[0] != 1 ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "invalid CCS message, content: %02x", ssl->in_msg[0] ) ); - return( MBEDTLS_ERR_SSL_INVALID_RECORD ); + return MBEDTLS_ERR_SSL_INVALID_RECORD ; } #if defined(MBEDTLS_SSL_PROTO_DTLS) @@ -4580,11 +4580,11 @@ int mbedtls_ssl_handle_message_type( mbedtls_ssl_context *ssl ) if( ssl->handshake == NULL ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "dropping ChangeCipherSpec outside handshake" ) ); - return( MBEDTLS_ERR_SSL_UNEXPECTED_RECORD ); + return MBEDTLS_ERR_SSL_UNEXPECTED_RECORD ; } MBEDTLS_SSL_DEBUG_MSG( 1, ( "received out-of-order ChangeCipherSpec - remember" ) ); - return( MBEDTLS_ERR_SSL_EARLY_MESSAGE ); + return MBEDTLS_ERR_SSL_EARLY_MESSAGE ; } #endif } @@ -4598,7 +4598,7 @@ int mbedtls_ssl_handle_message_type( mbedtls_ssl_context *ssl ) currently support this. */ MBEDTLS_SSL_DEBUG_MSG( 1, ( "invalid alert message, len: %" MBEDTLS_PRINTF_SIZET, ssl->in_msglen ) ); - return( MBEDTLS_ERR_SSL_INVALID_RECORD ); + return MBEDTLS_ERR_SSL_INVALID_RECORD ; } MBEDTLS_SSL_DEBUG_MSG( 2, ( "got an alert message, type: [%u:%u]", @@ -4611,14 +4611,14 @@ int mbedtls_ssl_handle_message_type( mbedtls_ssl_context *ssl ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "is a fatal alert message (msg %d)", ssl->in_msg[1] ) ); - return( MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE ); + return MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE ; } if( ssl->in_msg[0] == MBEDTLS_SSL_ALERT_LEVEL_WARNING && ssl->in_msg[1] == MBEDTLS_SSL_ALERT_MSG_CLOSE_NOTIFY ) { MBEDTLS_SSL_DEBUG_MSG( 2, ( "is a close notify message" ) ); - return( MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY ); + return MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY ; } #if defined(MBEDTLS_SSL_RENEGOTIATION_ENABLED) @@ -4627,7 +4627,7 @@ int mbedtls_ssl_handle_message_type( mbedtls_ssl_context *ssl ) { MBEDTLS_SSL_DEBUG_MSG( 2, ( "is a no renegotiation alert" ) ); /* Will be handled when trying to parse ServerHello */ - return( 0 ); + return 0 ; } #endif /* Silently ignore: fetch new message */ @@ -4648,7 +4648,7 @@ int mbedtls_ssl_handle_message_type( mbedtls_ssl_context *ssl ) ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "dropping unexpected ApplicationData" ) ); - return( MBEDTLS_ERR_SSL_NON_FATAL ); + return MBEDTLS_ERR_SSL_NON_FATAL ; } if( ssl->handshake != NULL && @@ -4659,7 +4659,7 @@ int mbedtls_ssl_handle_message_type( mbedtls_ssl_context *ssl ) } #endif /* MBEDTLS_SSL_PROTO_DTLS */ - return( 0 ); + return 0 ; } int mbedtls_ssl_send_fatal_handshake_failure( mbedtls_ssl_context *ssl ) @@ -4676,7 +4676,7 @@ int mbedtls_ssl_send_alert_message( mbedtls_ssl_context *ssl, int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; if( ssl == NULL || ssl->conf == NULL ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; MBEDTLS_SSL_DEBUG_MSG( 2, ( "=> send alert message" ) ); MBEDTLS_SSL_DEBUG_MSG( 3, ( "send alert level=%u message=%u", level, message )); @@ -4689,11 +4689,11 @@ int mbedtls_ssl_send_alert_message( mbedtls_ssl_context *ssl, if( ( ret = mbedtls_ssl_write_record( ssl, SSL_FORCE_FLUSH ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_write_record", ret ); - return( ret ); + return ret ; } MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= send alert message" ) ); - return( 0 ); + return 0 ; } int mbedtls_ssl_write_change_cipher_spec( mbedtls_ssl_context *ssl ) @@ -4711,12 +4711,12 @@ int mbedtls_ssl_write_change_cipher_spec( mbedtls_ssl_context *ssl ) if( ( ret = mbedtls_ssl_write_handshake_msg( ssl ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_write_handshake_msg", ret ); - return( ret ); + return ret ; } MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= write change cipher spec" ) ); - return( 0 ); + return 0 ; } int mbedtls_ssl_parse_change_cipher_spec( mbedtls_ssl_context *ssl ) @@ -4728,7 +4728,7 @@ int mbedtls_ssl_parse_change_cipher_spec( mbedtls_ssl_context *ssl ) if( ( ret = mbedtls_ssl_read_record( ssl, 1 ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_read_record", ret ); - return( ret ); + return ret ; } if( ssl->in_msgtype != MBEDTLS_SSL_MSG_CHANGE_CIPHER_SPEC ) @@ -4736,7 +4736,7 @@ int mbedtls_ssl_parse_change_cipher_spec( mbedtls_ssl_context *ssl ) MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad change cipher spec message" ) ); mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_UNEXPECTED_MESSAGE ); - return( MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE ); + return MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE ; } /* CCS records are only accepted if they have length 1 and content '1', @@ -4763,7 +4763,7 @@ int mbedtls_ssl_parse_change_cipher_spec( mbedtls_ssl_context *ssl ) MBEDTLS_SSL_DEBUG_MSG( 1, ( "DTLS epoch would wrap" ) ); /* This is highly unlikely to happen for legitimate reasons, so treat it as an attack and don't send an alert. */ - return( MBEDTLS_ERR_SSL_COUNTER_WRAPPING ); + return MBEDTLS_ERR_SSL_COUNTER_WRAPPING ; } } else @@ -4776,7 +4776,7 @@ int mbedtls_ssl_parse_change_cipher_spec( mbedtls_ssl_context *ssl ) MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= parse change cipher spec" ) ); - return( 0 ); + return 0 ; } /* Once ssl->out_hdr as the address of the beginning of the @@ -4791,9 +4791,9 @@ static size_t ssl_transform_get_explicit_iv_len( mbedtls_ssl_transform const *transform ) { if( transform->minor_ver < MBEDTLS_SSL_MINOR_VERSION_3 ) - return( 0 ); + return 0 ; - return( transform->ivlen - transform->fixed_ivlen ); + return transform->ivlen - transform->fixed_ivlen ; } void mbedtls_ssl_update_out_pointers( mbedtls_ssl_context *ssl, @@ -4911,7 +4911,7 @@ void mbedtls_ssl_reset_in_out_pointers( mbedtls_ssl_context *ssl ) */ size_t mbedtls_ssl_get_bytes_avail( const mbedtls_ssl_context *ssl ) { - return( ssl->in_offt == NULL ? 0 : ssl->in_msglen ); + return ssl->in_offt == NULL ? 0 : ssl->in_msglen ; } int mbedtls_ssl_check_pending( const mbedtls_ssl_context *ssl ) @@ -4924,7 +4924,7 @@ int mbedtls_ssl_check_pending( const mbedtls_ssl_context *ssl ) if( ssl->keep_current_message == 1 ) { MBEDTLS_SSL_DEBUG_MSG( 3, ( "ssl_check_pending: record held back for processing" ) ); - return( 1 ); + return 1 ; } /* @@ -4936,7 +4936,7 @@ int mbedtls_ssl_check_pending( const mbedtls_ssl_context *ssl ) ssl->in_left > ssl->next_record_offset ) { MBEDTLS_SSL_DEBUG_MSG( 3, ( "ssl_check_pending: more records within current datagram" ) ); - return( 1 ); + return 1 ; } #endif /* MBEDTLS_SSL_PROTO_DTLS */ @@ -4947,7 +4947,7 @@ int mbedtls_ssl_check_pending( const mbedtls_ssl_context *ssl ) if( ssl->in_hslen > 0 && ssl->in_hslen < ssl->in_msglen ) { MBEDTLS_SSL_DEBUG_MSG( 3, ( "ssl_check_pending: more handshake messages within current record" ) ); - return( 1 ); + return 1 ; } /* @@ -4956,7 +4956,7 @@ int mbedtls_ssl_check_pending( const mbedtls_ssl_context *ssl ) if( ssl->in_offt != NULL ) { MBEDTLS_SSL_DEBUG_MSG( 3, ( "ssl_check_pending: application data record is being processed" ) ); - return( 1 ); + return 1 ; } /* @@ -4966,7 +4966,7 @@ int mbedtls_ssl_check_pending( const mbedtls_ssl_context *ssl ) */ MBEDTLS_SSL_DEBUG_MSG( 3, ( "ssl_check_pending: nothing pending" ) ); - return( 0 ); + return 0 ; } @@ -4979,7 +4979,7 @@ int mbedtls_ssl_get_record_expansion( const mbedtls_ssl_context *ssl ) size_t out_hdr_len = mbedtls_ssl_out_hdr_len( ssl ); if( transform == NULL ) - return( (int) out_hdr_len ); + return (int) out_hdr_len ; switch( mbedtls_cipher_get_cipher_mode( &transform->cipher_ctx_enc ) ) { @@ -5013,7 +5013,7 @@ int mbedtls_ssl_get_record_expansion( const mbedtls_ssl_context *ssl ) default: MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) ); - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; } #if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID) @@ -5038,7 +5038,7 @@ static int ssl_check_ctr_renegotiate( mbedtls_ssl_context *ssl ) ssl->renego_status == MBEDTLS_SSL_RENEGOTIATION_PENDING || ssl->conf->disable_renegotiation == MBEDTLS_SSL_RENEGOTIATION_DISABLED ) { - return( 0 ); + return 0 ; } in_ctr_cmp = memcmp( ssl->in_ctr + ep_len, @@ -5048,11 +5048,11 @@ static int ssl_check_ctr_renegotiate( mbedtls_ssl_context *ssl ) if( in_ctr_cmp <= 0 && out_ctr_cmp <= 0 ) { - return( 0 ); + return 0 ; } MBEDTLS_SSL_DEBUG_MSG( 1, ( "record counter limit reached: renegotiate" ) ); - return( mbedtls_ssl_renegotiate( ssl ) ); + return mbedtls_ssl_renegotiate( ssl ) ; } #endif /* MBEDTLS_SSL_RENEGOTIATION */ @@ -5086,10 +5086,10 @@ static int ssl_handle_hs_message_post_handshake( mbedtls_ssl_context *ssl ) #if defined(MBEDTLS_SSL_PROTO_DTLS) if( ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM ) { - return( 0 ); + return 0 ; } #endif - return( MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE ); + return MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE ; } #endif /* MBEDTLS_SSL_CLI_C */ @@ -5103,10 +5103,10 @@ static int ssl_handle_hs_message_post_handshake( mbedtls_ssl_context *ssl ) #if defined(MBEDTLS_SSL_PROTO_DTLS) if( ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM ) { - return( 0 ); + return 0 ; } #endif - return( MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE ); + return MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE ; } #endif /* MBEDTLS_SSL_SRV_C */ @@ -5135,7 +5135,7 @@ static int ssl_handle_hs_message_post_handshake( mbedtls_ssl_context *ssl ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_start_renegotiation", ret ); - return( ret ); + return ret ; } } else @@ -5152,12 +5152,12 @@ static int ssl_handle_hs_message_post_handshake( mbedtls_ssl_context *ssl ) MBEDTLS_SSL_ALERT_LEVEL_WARNING, MBEDTLS_SSL_ALERT_MSG_NO_RENEGOTIATION ) ) != 0 ) { - return( ret ); + return ret ; } #endif /* MBEDTLS_SSL_PROTO_TLS1_2 */ } - return( 0 ); + return 0 ; } /* @@ -5169,7 +5169,7 @@ int mbedtls_ssl_read( mbedtls_ssl_context *ssl, unsigned char *buf, size_t len ) size_t n; if( ssl == NULL || ssl->conf == NULL ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; MBEDTLS_SSL_DEBUG_MSG( 2, ( "=> read" ) ); @@ -5177,13 +5177,13 @@ int mbedtls_ssl_read( mbedtls_ssl_context *ssl, unsigned char *buf, size_t len ) if( ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM ) { if( ( ret = mbedtls_ssl_flush_output( ssl ) ) != 0 ) - return( ret ); + return ret ; if( ssl->handshake != NULL && ssl->handshake->retransmit_state == MBEDTLS_SSL_RETRANS_SENDING ) { if( ( ret = mbedtls_ssl_flight_transmit( ssl ) ) != 0 ) - return( ret ); + return ret ; } } #endif @@ -5206,7 +5206,7 @@ int mbedtls_ssl_read( mbedtls_ssl_context *ssl, unsigned char *buf, size_t len ) ret != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "ssl_check_ctr_renegotiate", ret ); - return( ret ); + return ret ; } #endif @@ -5217,7 +5217,7 @@ int mbedtls_ssl_read( mbedtls_ssl_context *ssl, unsigned char *buf, size_t len ) ret != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_handshake", ret ); - return( ret ); + return ret ; } } @@ -5234,10 +5234,10 @@ int mbedtls_ssl_read( mbedtls_ssl_context *ssl, unsigned char *buf, size_t len ) if( ( ret = mbedtls_ssl_read_record( ssl, 1 ) ) != 0 ) { if( ret == MBEDTLS_ERR_SSL_CONN_EOF ) - return( 0 ); + return 0 ; MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_read_record", ret ); - return( ret ); + return ret ; } if( ssl->in_msglen == 0 && @@ -5249,10 +5249,10 @@ int mbedtls_ssl_read( mbedtls_ssl_context *ssl, unsigned char *buf, size_t len ) if( ( ret = mbedtls_ssl_read_record( ssl, 1 ) ) != 0 ) { if( ret == MBEDTLS_ERR_SSL_CONN_EOF ) - return( 0 ); + return 0 ; MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_read_record", ret ); - return( ret ); + return ret ; } } @@ -5263,7 +5263,7 @@ int mbedtls_ssl_read( mbedtls_ssl_context *ssl, unsigned char *buf, size_t len ) { MBEDTLS_SSL_DEBUG_RET( 1, "ssl_handle_hs_message_post_handshake", ret ); - return( ret ); + return ret ; } /* At this point, we don't know whether the renegotiation triggered @@ -5298,7 +5298,7 @@ int mbedtls_ssl_read( mbedtls_ssl_context *ssl, unsigned char *buf, size_t len ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "renegotiation requested, " "but not honored by client" ) ); - return( MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE ); + return MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE ; } } } @@ -5308,13 +5308,13 @@ int mbedtls_ssl_read( mbedtls_ssl_context *ssl, unsigned char *buf, size_t len ) if( ssl->in_msgtype == MBEDTLS_SSL_MSG_ALERT ) { MBEDTLS_SSL_DEBUG_MSG( 2, ( "ignoring non-fatal non-closure alert" ) ); - return( MBEDTLS_ERR_SSL_WANT_READ ); + return MBEDTLS_ERR_SSL_WANT_READ ; } if( ssl->in_msgtype != MBEDTLS_SSL_MSG_APPLICATION_DATA ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad application data message" ) ); - return( MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE ); + return MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE ; } ssl->in_offt = ssl->in_msg; @@ -5336,7 +5336,7 @@ int mbedtls_ssl_read( mbedtls_ssl_context *ssl, unsigned char *buf, size_t len ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_resend_hello_request", ret ); - return( ret ); + return ret ; } } #endif /* MBEDTLS_SSL_SRV_C && MBEDTLS_SSL_RENEGOTIATION */ @@ -5367,7 +5367,7 @@ int mbedtls_ssl_read( mbedtls_ssl_context *ssl, unsigned char *buf, size_t len ) MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= read" ) ); - return( (int) n ); + return (int) n ; } /* @@ -5391,7 +5391,7 @@ static int ssl_write_real( mbedtls_ssl_context *ssl, if( ret < 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_get_max_out_record_payload", ret ); - return( ret ); + return ret ; } if( len > max_len ) @@ -5403,7 +5403,7 @@ static int ssl_write_real( mbedtls_ssl_context *ssl, "maximum fragment length: %" MBEDTLS_PRINTF_SIZET " > %" MBEDTLS_PRINTF_SIZET, len, max_len ) ); - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; } else #endif @@ -5421,7 +5421,7 @@ static int ssl_write_real( mbedtls_ssl_context *ssl, if( ( ret = mbedtls_ssl_flush_output( ssl ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_flush_output", ret ); - return( ret ); + return ret ; } } else @@ -5438,11 +5438,11 @@ static int ssl_write_real( mbedtls_ssl_context *ssl, if( ( ret = mbedtls_ssl_write_record( ssl, SSL_FORCE_FLUSH ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_write_record", ret ); - return( ret ); + return ret ; } } - return( (int) len ); + return (int) len ; } /* @@ -5455,13 +5455,13 @@ int mbedtls_ssl_write( mbedtls_ssl_context *ssl, const unsigned char *buf, size_ MBEDTLS_SSL_DEBUG_MSG( 2, ( "=> write" ) ); if( ssl == NULL || ssl->conf == NULL ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; #if defined(MBEDTLS_SSL_RENEGOTIATION) if( ( ret = ssl_check_ctr_renegotiate( ssl ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "ssl_check_ctr_renegotiate", ret ); - return( ret ); + return ret ; } #endif @@ -5470,7 +5470,7 @@ int mbedtls_ssl_write( mbedtls_ssl_context *ssl, const unsigned char *buf, size_ if( ( ret = mbedtls_ssl_handshake( ssl ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_handshake", ret ); - return( ret ); + return ret ; } } @@ -5478,7 +5478,7 @@ int mbedtls_ssl_write( mbedtls_ssl_context *ssl, const unsigned char *buf, size_ MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= write" ) ); - return( ret ); + return ret ; } /* @@ -5489,12 +5489,12 @@ int mbedtls_ssl_close_notify( mbedtls_ssl_context *ssl ) int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; if( ssl == NULL || ssl->conf == NULL ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; MBEDTLS_SSL_DEBUG_MSG( 2, ( "=> write close notify" ) ); if( ssl->out_left != 0 ) - return( mbedtls_ssl_flush_output( ssl ) ); + return mbedtls_ssl_flush_output( ssl ) ; if( ssl->state == MBEDTLS_SSL_HANDSHAKE_OVER ) { @@ -5503,13 +5503,13 @@ int mbedtls_ssl_close_notify( mbedtls_ssl_context *ssl ) MBEDTLS_SSL_ALERT_MSG_CLOSE_NOTIFY ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_send_alert_message", ret ); - return( ret ); + return ret ; } } MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= write close notify" ) ); - return( 0 ); + return 0 ; } void mbedtls_ssl_transform_free( mbedtls_ssl_transform *transform ) diff --git a/library/ssl_srv.c b/library/ssl_srv.c index d82ec0471f..4cb360667a 100644 --- a/library/ssl_srv.c +++ b/library/ssl_srv.c @@ -51,17 +51,17 @@ int mbedtls_ssl_set_client_transport_id( mbedtls_ssl_context *ssl, size_t ilen ) { if( ssl->conf->endpoint != MBEDTLS_SSL_IS_SERVER ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; mbedtls_free( ssl->cli_id ); if( ( ssl->cli_id = mbedtls_calloc( 1, ilen ) ) == NULL ) - return( MBEDTLS_ERR_SSL_ALLOC_FAILED ); + return MBEDTLS_ERR_SSL_ALLOC_FAILED ; memcpy( ssl->cli_id, info, ilen ); ssl->cli_id_len = ilen; - return( 0 ); + return 0 ; } void mbedtls_ssl_conf_dtls_cookies( mbedtls_ssl_config *conf, @@ -91,7 +91,7 @@ static int ssl_parse_servername_ext( mbedtls_ssl_context *ssl, MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad client hello message" ) ); mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } servername_list_size = ( ( buf[0] << 8 ) | ( buf[1] ) ); if( servername_list_size + 2 != len ) @@ -99,7 +99,7 @@ static int ssl_parse_servername_ext( mbedtls_ssl_context *ssl, MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad client hello message" ) ); mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } p = buf + 2; @@ -111,7 +111,7 @@ static int ssl_parse_servername_ext( mbedtls_ssl_context *ssl, MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad client hello message" ) ); mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } if( p[0] == MBEDTLS_TLS_EXT_SERVERNAME_HOSTNAME ) @@ -123,9 +123,9 @@ static int ssl_parse_servername_ext( mbedtls_ssl_context *ssl, MBEDTLS_SSL_DEBUG_RET( 1, "ssl_sni_wrapper", ret ); mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_UNRECOGNIZED_NAME ); - return( MBEDTLS_ERR_SSL_UNRECOGNIZED_NAME ); + return MBEDTLS_ERR_SSL_UNRECOGNIZED_NAME ; } - return( 0 ); + return 0 ; } servername_list_size -= hostname_len + 3; @@ -137,10 +137,10 @@ static int ssl_parse_servername_ext( mbedtls_ssl_context *ssl, MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad client hello message" ) ); mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } - return( 0 ); + return 0 ; } #endif /* MBEDTLS_SSL_SERVER_NAME_INDICATION */ @@ -148,20 +148,20 @@ static int ssl_parse_servername_ext( mbedtls_ssl_context *ssl, static int ssl_conf_has_psk_or_cb( mbedtls_ssl_config const *conf ) { if( conf->f_psk != NULL ) - return( 1 ); + return 1 ; if( conf->psk_identity_len == 0 || conf->psk_identity == NULL ) - return( 0 ); + return 0 ; if( conf->psk != NULL && conf->psk_len != 0 ) - return( 1 ); + return 1 ; #if defined(MBEDTLS_USE_PSA_CRYPTO) if( ! mbedtls_svc_key_id_is_null( conf->psk_opaque ) ) - return( 1 ); + return 1 ; #endif /* MBEDTLS_USE_PSA_CRYPTO */ - return( 0 ); + return 0 ; } #if defined(MBEDTLS_USE_PSA_CRYPTO) @@ -173,15 +173,15 @@ static int ssl_use_opaque_psk( mbedtls_ssl_context const *ssl ) * the static configuration is irrelevant. */ if( ! mbedtls_svc_key_id_is_null( ssl->handshake->psk_opaque ) ) - return( 1 ); + return 1 ; - return( 0 ); + return 0 ; } if( ! mbedtls_svc_key_id_is_null( ssl->conf->psk_opaque ) ) - return( 1 ); + return 1 ; - return( 0 ); + return 0 ; } #endif /* MBEDTLS_USE_PSA_CRYPTO */ #endif /* MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED */ @@ -202,7 +202,7 @@ static int ssl_parse_renegotiation_info( mbedtls_ssl_context *ssl, MBEDTLS_SSL_DEBUG_MSG( 1, ( "non-matching renegotiation info" ) ); mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_HANDSHAKE_FAILURE ); - return( MBEDTLS_ERR_SSL_HANDSHAKE_FAILURE ); + return MBEDTLS_ERR_SSL_HANDSHAKE_FAILURE ; } } else @@ -213,13 +213,13 @@ static int ssl_parse_renegotiation_info( mbedtls_ssl_context *ssl, MBEDTLS_SSL_DEBUG_MSG( 1, ( "non-zero length renegotiation info" ) ); mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_HANDSHAKE_FAILURE ); - return( MBEDTLS_ERR_SSL_HANDSHAKE_FAILURE ); + return MBEDTLS_ERR_SSL_HANDSHAKE_FAILURE ; } ssl->secure_renegotiation = MBEDTLS_SSL_SECURE_RENEGOTIATION; } - return( 0 ); + return 0 ; } #if defined(MBEDTLS_SSL_PROTO_TLS1_2) && \ @@ -253,7 +253,7 @@ static int ssl_parse_signature_algorithms_ext( mbedtls_ssl_context *ssl, MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad client hello message" ) ); mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } sig_alg_list_size = ( ( buf[0] << 8 ) | ( buf[1] ) ); if( sig_alg_list_size + 2 != len || @@ -262,7 +262,7 @@ static int ssl_parse_signature_algorithms_ext( mbedtls_ssl_context *ssl, MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad client hello message" ) ); mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } /* Currently we only guarantee signing the ServerKeyExchange message according @@ -308,7 +308,7 @@ static int ssl_parse_signature_algorithms_ext( mbedtls_ssl_context *ssl, } } - return( 0 ); + return 0 ; } #endif /* MBEDTLS_SSL_PROTO_TLS1_2 && MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED */ @@ -327,7 +327,7 @@ static int ssl_parse_supported_elliptic_curves( mbedtls_ssl_context *ssl, MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad client hello message" ) ); mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } list_size = ( ( buf[0] << 8 ) | ( buf[1] ) ); if( list_size + 2 != len || @@ -336,7 +336,7 @@ static int ssl_parse_supported_elliptic_curves( mbedtls_ssl_context *ssl, MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad client hello message" ) ); mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } /* Should never happen unless client duplicates the extension */ @@ -345,7 +345,7 @@ static int ssl_parse_supported_elliptic_curves( mbedtls_ssl_context *ssl, MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad client hello message" ) ); mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_ILLEGAL_PARAMETER ); - return( MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER ); + return MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER ; } /* Don't allow our peer to make us allocate too much memory, @@ -358,7 +358,7 @@ static int ssl_parse_supported_elliptic_curves( mbedtls_ssl_context *ssl, { mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_INTERNAL_ERROR ); - return( MBEDTLS_ERR_SSL_ALLOC_FAILED ); + return MBEDTLS_ERR_SSL_ALLOC_FAILED ; } ssl->handshake->curves = curves; @@ -378,7 +378,7 @@ static int ssl_parse_supported_elliptic_curves( mbedtls_ssl_context *ssl, p += 2; } - return( 0 ); + return 0 ; } static int ssl_parse_supported_point_formats( mbedtls_ssl_context *ssl, @@ -393,7 +393,7 @@ static int ssl_parse_supported_point_formats( mbedtls_ssl_context *ssl, MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad client hello message" ) ); mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } list_size = buf[0]; @@ -411,14 +411,14 @@ static int ssl_parse_supported_point_formats( mbedtls_ssl_context *ssl, p[0] ); #endif MBEDTLS_SSL_DEBUG_MSG( 4, ( "point format selected: %d", p[0] ) ); - return( 0 ); + return 0 ; } list_size--; p++; } - return( 0 ); + return 0 ; } #endif /* MBEDTLS_ECDH_C || MBEDTLS_ECDSA_C || MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED */ @@ -433,7 +433,7 @@ static int ssl_parse_ecjpake_kkpp( mbedtls_ssl_context *ssl, if( mbedtls_ecjpake_check( &ssl->handshake->ecjpake_ctx ) != 0 ) { MBEDTLS_SSL_DEBUG_MSG( 3, ( "skip ecjpake kkpp extension" ) ); - return( 0 ); + return 0 ; } if( ( ret = mbedtls_ecjpake_read_round_one( &ssl->handshake->ecjpake_ctx, @@ -442,13 +442,13 @@ static int ssl_parse_ecjpake_kkpp( mbedtls_ssl_context *ssl, MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ecjpake_read_round_one", ret ); mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_ILLEGAL_PARAMETER ); - return( ret ); + return ret ; } /* Only mark the extension as OK when we're sure it is */ ssl->handshake->cli_exts |= MBEDTLS_TLS_EXT_ECJPAKE_KKPP_OK; - return( 0 ); + return 0 ; } #endif /* MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED */ @@ -462,12 +462,12 @@ static int ssl_parse_max_fragment_length_ext( mbedtls_ssl_context *ssl, MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad client hello message" ) ); mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_ILLEGAL_PARAMETER ); - return( MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER ); + return MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER ; } ssl->session_negotiate->mfl_code = buf[0]; - return( 0 ); + return 0 ; } #endif /* MBEDTLS_SSL_MAX_FRAGMENT_LENGTH */ @@ -484,7 +484,7 @@ static int ssl_parse_cid_ext( mbedtls_ssl_context *ssl, MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad client hello message" ) ); mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_ILLEGAL_PARAMETER ); - return( MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER ); + return MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER ; } /* @@ -501,7 +501,7 @@ static int ssl_parse_cid_ext( mbedtls_ssl_context *ssl, MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad client hello message" ) ); mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } peer_cid_len = *buf++; @@ -512,7 +512,7 @@ static int ssl_parse_cid_ext( mbedtls_ssl_context *ssl, MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad client hello message" ) ); mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } /* Ignore CID if the user has disabled its use. */ @@ -521,7 +521,7 @@ static int ssl_parse_cid_ext( mbedtls_ssl_context *ssl, /* Leave ssl->handshake->cid_in_use in its default * value of MBEDTLS_SSL_CID_DISABLED. */ MBEDTLS_SSL_DEBUG_MSG( 3, ( "Client sent CID extension, but CID disabled" ) ); - return( 0 ); + return 0 ; } if( peer_cid_len > MBEDTLS_SSL_CID_OUT_LEN_MAX ) @@ -529,7 +529,7 @@ static int ssl_parse_cid_ext( mbedtls_ssl_context *ssl, MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad client hello message" ) ); mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_ILLEGAL_PARAMETER ); - return( MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER ); + return MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER ; } ssl->handshake->cid_in_use = MBEDTLS_SSL_CID_ENABLED; @@ -539,7 +539,7 @@ static int ssl_parse_cid_ext( mbedtls_ssl_context *ssl, MBEDTLS_SSL_DEBUG_MSG( 3, ( "Use of CID extension negotiated" ) ); MBEDTLS_SSL_DEBUG_BUF( 3, "Client CID", buf, peer_cid_len ); - return( 0 ); + return 0 ; } #endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */ @@ -553,7 +553,7 @@ static int ssl_parse_encrypt_then_mac_ext( mbedtls_ssl_context *ssl, MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad client hello message" ) ); mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } ((void) buf); @@ -563,7 +563,7 @@ static int ssl_parse_encrypt_then_mac_ext( mbedtls_ssl_context *ssl, ssl->session_negotiate->encrypt_then_mac = MBEDTLS_SSL_ETM_ENABLED; } - return( 0 ); + return 0 ; } #endif /* MBEDTLS_SSL_ENCRYPT_THEN_MAC */ @@ -577,7 +577,7 @@ static int ssl_parse_extended_ms_ext( mbedtls_ssl_context *ssl, MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad client hello message" ) ); mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } ((void) buf); @@ -587,7 +587,7 @@ static int ssl_parse_extended_ms_ext( mbedtls_ssl_context *ssl, ssl->handshake->extended_ms = MBEDTLS_SSL_EXTENDED_MS_ENABLED; } - return( 0 ); + return 0 ; } #endif /* MBEDTLS_SSL_EXTENDED_MASTER_SECRET */ @@ -604,7 +604,7 @@ static int ssl_parse_session_ticket_ext( mbedtls_ssl_context *ssl, if( ssl->conf->f_ticket_parse == NULL || ssl->conf->f_ticket_write == NULL ) { - return( 0 ); + return 0 ; } /* Remember the client asked us to send a new ticket */ @@ -613,13 +613,13 @@ static int ssl_parse_session_ticket_ext( mbedtls_ssl_context *ssl, MBEDTLS_SSL_DEBUG_MSG( 3, ( "ticket length: %" MBEDTLS_PRINTF_SIZET, len ) ); if( len == 0 ) - return( 0 ); + return 0 ; #if defined(MBEDTLS_SSL_RENEGOTIATION) if( ssl->renego_status != MBEDTLS_SSL_INITIAL_HANDSHAKE ) { MBEDTLS_SSL_DEBUG_MSG( 3, ( "ticket rejected: renegotiating" ) ); - return( 0 ); + return 0 ; } #endif /* MBEDTLS_SSL_RENEGOTIATION */ @@ -638,7 +638,7 @@ static int ssl_parse_session_ticket_ext( mbedtls_ssl_context *ssl, else MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_ticket_parse", ret ); - return( 0 ); + return 0 ; } /* @@ -661,7 +661,7 @@ static int ssl_parse_session_ticket_ext( mbedtls_ssl_context *ssl, /* Don't send a new ticket after all, this one is OK */ ssl->handshake->new_session_ticket = 0; - return( 0 ); + return 0 ; } #endif /* MBEDTLS_SSL_SESSION_TICKETS */ @@ -675,7 +675,7 @@ static int ssl_parse_alpn_ext( mbedtls_ssl_context *ssl, /* If ALPN not configured, just ignore the extension */ if( ssl->conf->alpn_list == NULL ) - return( 0 ); + return 0 ; /* * opaque ProtocolName<1..2^8-1>; @@ -690,7 +690,7 @@ static int ssl_parse_alpn_ext( mbedtls_ssl_context *ssl, { mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } list_len = ( buf[0] << 8 ) | buf[1]; @@ -698,7 +698,7 @@ static int ssl_parse_alpn_ext( mbedtls_ssl_context *ssl, { mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } /* @@ -715,7 +715,7 @@ static int ssl_parse_alpn_ext( mbedtls_ssl_context *ssl, { mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } /* Empty strings MUST NOT be included */ @@ -723,7 +723,7 @@ static int ssl_parse_alpn_ext( mbedtls_ssl_context *ssl, { mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_ILLEGAL_PARAMETER ); - return( MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER ); + return MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER ; } } @@ -741,7 +741,7 @@ static int ssl_parse_alpn_ext( mbedtls_ssl_context *ssl, memcmp( theirs, *ours, cur_len ) == 0 ) { ssl->alpn_chosen = *ours; - return( 0 ); + return 0 ; } } } @@ -749,7 +749,7 @@ static int ssl_parse_alpn_ext( mbedtls_ssl_context *ssl, /* If we get there, no match was found */ mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_NO_APPLICATION_PROTOCOL ); - return( MBEDTLS_ERR_SSL_NO_APPLICATION_PROTOCOL ); + return MBEDTLS_ERR_SSL_NO_APPLICATION_PROTOCOL ; } #endif /* MBEDTLS_SSL_ALPN */ @@ -770,7 +770,7 @@ static int ssl_parse_use_srtp_ext( mbedtls_ssl_context *ssl, ( ssl->conf->dtls_srtp_profile_list == NULL ) || ( ssl->conf->dtls_srtp_profile_list_len == 0 ) ) { - return( 0 ); + return 0 ; } /* RFC5764 section 4.1.1 @@ -794,7 +794,7 @@ static int ssl_parse_use_srtp_ext( mbedtls_ssl_context *ssl, { mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } ssl->dtls_srtp_info.chosen_dtls_srtp_profile = MBEDTLS_TLS_SRTP_UNSET; @@ -809,7 +809,7 @@ static int ssl_parse_use_srtp_ext( mbedtls_ssl_context *ssl, { mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } /* * parse the extension list values are defined in @@ -854,7 +854,7 @@ static int ssl_parse_use_srtp_ext( mbedtls_ssl_context *ssl, { mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } /* Parse the mki only if present and mki is supported locally */ @@ -869,7 +869,7 @@ static int ssl_parse_use_srtp_ext( mbedtls_ssl_context *ssl, ssl->dtls_srtp_info.mki_len ); } - return( 0 ); + return 0 ; } #endif /* MBEDTLS_SSL_DTLS_SRTP */ @@ -891,11 +891,11 @@ static int ssl_check_key_curve( mbedtls_pk_context *pk, while( *crv != NULL ) { if( (*crv)->grp_id == grp_id ) - return( 0 ); + return 0 ; crv++; } - return( -1 ); + return -1 ; } #endif /* MBEDTLS_ECDSA_C */ @@ -919,14 +919,14 @@ static int ssl_pick_cert( mbedtls_ssl_context *ssl, list = ssl->conf->key_cert; if( pk_alg == MBEDTLS_PK_NONE ) - return( 0 ); + return 0 ; MBEDTLS_SSL_DEBUG_MSG( 3, ( "ciphersuite requires certificate" ) ); if( list == NULL ) { MBEDTLS_SSL_DEBUG_MSG( 3, ( "server has no certificate" ) ); - return( -1 ); + return -1 ; } for( cur = list; cur != NULL; cur = cur->next ) @@ -996,10 +996,10 @@ static int ssl_pick_cert( mbedtls_ssl_context *ssl, ssl->handshake->key_cert = cur; MBEDTLS_SSL_DEBUG_CRT( 3, "selected certificate chain, certificate", ssl->handshake->key_cert->cert ); - return( 0 ); + return 0 ; } - return( -1 ); + return -1 ; } #endif /* MBEDTLS_X509_CRT_PARSE_C */ @@ -1021,7 +1021,7 @@ static int ssl_ciphersuite_match( mbedtls_ssl_context *ssl, int suite_id, if( suite_info == NULL ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) ); - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; } MBEDTLS_SSL_DEBUG_MSG( 3, ( "trying ciphersuite: %#04x (%s)", @@ -1031,13 +1031,13 @@ static int ssl_ciphersuite_match( mbedtls_ssl_context *ssl, int suite_id, suite_info->max_minor_ver < ssl->minor_ver ) { MBEDTLS_SSL_DEBUG_MSG( 3, ( "ciphersuite mismatch: version" ) ); - return( 0 ); + return 0 ; } #if defined(MBEDTLS_SSL_PROTO_DTLS) if( ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM && ( suite_info->flags & MBEDTLS_CIPHERSUITE_NODTLS ) ) - return( 0 ); + return 0 ; #endif #if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED) @@ -1046,7 +1046,7 @@ static int ssl_ciphersuite_match( mbedtls_ssl_context *ssl, int suite_id, { MBEDTLS_SSL_DEBUG_MSG( 3, ( "ciphersuite mismatch: ecjpake " "not configured or ext missing" ) ); - return( 0 ); + return 0 ; } #endif @@ -1058,7 +1058,7 @@ static int ssl_ciphersuite_match( mbedtls_ssl_context *ssl, int suite_id, { MBEDTLS_SSL_DEBUG_MSG( 3, ( "ciphersuite mismatch: " "no common elliptic curve" ) ); - return( 0 ); + return 0 ; } #endif @@ -1069,7 +1069,7 @@ static int ssl_ciphersuite_match( mbedtls_ssl_context *ssl, int suite_id, ssl_conf_has_psk_or_cb( ssl->conf ) == 0 ) { MBEDTLS_SSL_DEBUG_MSG( 3, ( "ciphersuite mismatch: no pre-shared key" ) ); - return( 0 ); + return 0 ; } #endif @@ -1085,7 +1085,7 @@ static int ssl_ciphersuite_match( mbedtls_ssl_context *ssl, int suite_id, { MBEDTLS_SSL_DEBUG_MSG( 3, ( "ciphersuite mismatch: no suitable hash algorithm " "for signature algorithm %u", (unsigned) sig_type ) ); - return( 0 ); + return 0 ; } } @@ -1104,12 +1104,12 @@ static int ssl_ciphersuite_match( mbedtls_ssl_context *ssl, int suite_id, { MBEDTLS_SSL_DEBUG_MSG( 3, ( "ciphersuite mismatch: " "no suitable certificate" ) ); - return( 0 ); + return 0 ; } #endif *ciphersuite_info = suite_info; - return( 0 ); + return 0 ; } /* This function doesn't alert on errors that happen early during @@ -1160,7 +1160,7 @@ read_record_header: { /* No alert on a read error. */ MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_fetch_input", ret ); - return( ret ); + return ret ; } } @@ -1183,7 +1183,7 @@ read_record_header: if( buf[0] != MBEDTLS_SSL_MSG_HANDSHAKE ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad client hello message" ) ); - return( MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE ); + return MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE ; } MBEDTLS_SSL_DEBUG_MSG( 3, ( "client hello, message len.: %d", @@ -1201,7 +1201,7 @@ read_record_header: if( major < MBEDTLS_SSL_MAJOR_VERSION_3 ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad client hello message" ) ); - return( MBEDTLS_ERR_SSL_BAD_PROTOCOL_VERSION ); + return MBEDTLS_ERR_SSL_BAD_PROTOCOL_VERSION ; } /* For DTLS if this is the initial handshake, remember the client sequence @@ -1217,7 +1217,7 @@ read_record_header: if( ssl->in_ctr[0] != 0 || ssl->in_ctr[1] != 0 ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad client hello message" ) ); - return( MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER ); + return MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER ; } memcpy( ssl->cur_out_ctr + 2, ssl->in_ctr + 2, 6 ); @@ -1251,14 +1251,14 @@ read_record_header: if( msg_len > MBEDTLS_SSL_IN_CONTENT_LEN ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad client hello message" ) ); - return( MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER ); + return MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER ; } if( ( ret = mbedtls_ssl_fetch_input( ssl, mbedtls_ssl_in_hdr_len( ssl ) + msg_len ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_fetch_input", ret ); - return( ret ); + return ret ; } /* Done reading this record, get ready for the next one */ @@ -1287,7 +1287,7 @@ read_record_header: if( msg_len < mbedtls_ssl_hs_hdr_len( ssl ) ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad client hello message" ) ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } MBEDTLS_SSL_DEBUG_MSG( 3, ( "client hello v3, handshake type: %d", buf[0] ) ); @@ -1295,7 +1295,7 @@ read_record_header: if( buf[0] != MBEDTLS_SSL_HS_CLIENT_HELLO ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad client hello message" ) ); - return( MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE ); + return MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE ; } MBEDTLS_SSL_DEBUG_MSG( 3, ( "client hello v3, handshake len.: %d", @@ -1306,7 +1306,7 @@ read_record_header: msg_len != mbedtls_ssl_hs_hdr_len( ssl ) + ( ( buf[2] << 8 ) | buf[3] ) ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad client hello message" ) ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } #if defined(MBEDTLS_SSL_PROTO_DTLS) @@ -1328,7 +1328,7 @@ read_record_header: MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad client hello message_seq: " "%u (expected %u)", cli_msg_seq, ssl->handshake->in_msg_seq ) ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } ssl->handshake->in_msg_seq++; @@ -1350,7 +1350,7 @@ read_record_header: memcmp( ssl->in_msg + 1, ssl->in_msg + 9, 3 ) != 0 ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "ClientHello fragmentation not supported" ) ); - return( MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE ; } } #endif /* MBEDTLS_SSL_PROTO_DTLS */ @@ -1382,7 +1382,7 @@ read_record_header: if( msg_len < 38 ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad client hello message" ) ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } /* @@ -1406,7 +1406,7 @@ read_record_header: ssl->conf->min_major_ver, ssl->conf->min_minor_ver ) ); mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_PROTOCOL_VERSION ); - return( MBEDTLS_ERR_SSL_BAD_PROTOCOL_VERSION ); + return MBEDTLS_ERR_SSL_BAD_PROTOCOL_VERSION ; } if( ssl->major_ver > ssl->conf->max_major_ver ) @@ -1435,7 +1435,7 @@ read_record_header: MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad client hello message" ) ); mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } MBEDTLS_SSL_DEBUG_BUF( 3, "client hello, session id", buf + 35, sess_len ); @@ -1460,7 +1460,7 @@ read_record_header: MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad client hello message" ) ); mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } MBEDTLS_SSL_DEBUG_BUF( 3, "client hello, cookie", @@ -1494,7 +1494,7 @@ read_record_header: { /* This may be an attacker's probe, so don't send an alert */ MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad client hello message" ) ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } MBEDTLS_SSL_DEBUG_MSG( 2, ( "cookie verification skipped" ) ); @@ -1519,7 +1519,7 @@ read_record_header: MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad client hello message" ) ); mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } MBEDTLS_SSL_DEBUG_BUF( 3, "client hello, ciphersuitelist", @@ -1539,7 +1539,7 @@ read_record_header: MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad client hello message" ) ); mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } MBEDTLS_SSL_DEBUG_BUF( 3, "client hello, compression", @@ -1562,7 +1562,7 @@ read_record_header: MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad client hello message" ) ); mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } ext_len = ( buf[ext_offset + 0] << 8 ) @@ -1573,7 +1573,7 @@ read_record_header: MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad client hello message" ) ); mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } } else @@ -1590,7 +1590,7 @@ read_record_header: MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad client hello message" ) ); mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } ext_id = ( ( ext[0] << 8 ) | ( ext[1] ) ); ext_size = ( ( ext[2] << 8 ) | ( ext[3] ) ); @@ -1600,7 +1600,7 @@ read_record_header: MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad client hello message" ) ); mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } switch( ext_id ) { @@ -1612,7 +1612,7 @@ read_record_header: ret = ssl_parse_servername_ext( ssl, ext + 4, ext_size ); if( ret != 0 ) - return( ret ); + return ret ; break; #endif /* MBEDTLS_SSL_SERVER_NAME_INDICATION */ @@ -1624,7 +1624,7 @@ read_record_header: ret = ssl_parse_renegotiation_info( ssl, ext + 4, ext_size ); if( ret != 0 ) - return( ret ); + return ret ; break; #if defined(MBEDTLS_SSL_PROTO_TLS1_2) && \ @@ -1634,7 +1634,7 @@ read_record_header: ret = ssl_parse_signature_algorithms_ext( ssl, ext + 4, ext_size ); if( ret != 0 ) - return( ret ); + return ret ; sig_hash_alg_ext_present = 1; break; @@ -1648,7 +1648,7 @@ read_record_header: ret = ssl_parse_supported_elliptic_curves( ssl, ext + 4, ext_size ); if( ret != 0 ) - return( ret ); + return ret ; break; case MBEDTLS_TLS_EXT_SUPPORTED_POINT_FORMATS: @@ -1657,7 +1657,7 @@ read_record_header: ret = ssl_parse_supported_point_formats( ssl, ext + 4, ext_size ); if( ret != 0 ) - return( ret ); + return ret ; break; #endif /* MBEDTLS_ECDH_C || MBEDTLS_ECDSA_C || MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED */ @@ -1668,7 +1668,7 @@ read_record_header: ret = ssl_parse_ecjpake_kkpp( ssl, ext + 4, ext_size ); if( ret != 0 ) - return( ret ); + return ret ; break; #endif /* MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED */ @@ -1678,7 +1678,7 @@ read_record_header: ret = ssl_parse_max_fragment_length_ext( ssl, ext + 4, ext_size ); if( ret != 0 ) - return( ret ); + return ret ; break; #endif /* MBEDTLS_SSL_MAX_FRAGMENT_LENGTH */ @@ -1688,7 +1688,7 @@ read_record_header: ret = ssl_parse_cid_ext( ssl, ext + 4, ext_size ); if( ret != 0 ) - return( ret ); + return ret ; break; #endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */ @@ -1698,7 +1698,7 @@ read_record_header: ret = ssl_parse_encrypt_then_mac_ext( ssl, ext + 4, ext_size ); if( ret != 0 ) - return( ret ); + return ret ; break; #endif /* MBEDTLS_SSL_ENCRYPT_THEN_MAC */ @@ -1708,7 +1708,7 @@ read_record_header: ret = ssl_parse_extended_ms_ext( ssl, ext + 4, ext_size ); if( ret != 0 ) - return( ret ); + return ret ; break; #endif /* MBEDTLS_SSL_EXTENDED_MASTER_SECRET */ @@ -1718,7 +1718,7 @@ read_record_header: ret = ssl_parse_session_ticket_ext( ssl, ext + 4, ext_size ); if( ret != 0 ) - return( ret ); + return ret ; break; #endif /* MBEDTLS_SSL_SESSION_TICKETS */ @@ -1728,7 +1728,7 @@ read_record_header: ret = ssl_parse_alpn_ext( ssl, ext + 4, ext_size ); if( ret != 0 ) - return( ret ); + return ret ; break; #endif /* MBEDTLS_SSL_SESSION_TICKETS */ @@ -1738,7 +1738,7 @@ read_record_header: ret = ssl_parse_use_srtp_ext( ssl, ext + 4, ext_size ); if( ret != 0 ) - return( ret ); + return ret ; break; #endif /* MBEDTLS_SSL_DTLS_SRTP */ @@ -1786,7 +1786,7 @@ read_record_header: "during renegotiation" ) ); mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_HANDSHAKE_FAILURE ); - return( MBEDTLS_ERR_SSL_HANDSHAKE_FAILURE ); + return MBEDTLS_ERR_SSL_HANDSHAKE_FAILURE ; } #endif ssl->secure_renegotiation = MBEDTLS_SSL_SECURE_RENEGOTIATION; @@ -1831,7 +1831,7 @@ read_record_header: { mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_HANDSHAKE_FAILURE ); - return( MBEDTLS_ERR_SSL_HANDSHAKE_FAILURE ); + return MBEDTLS_ERR_SSL_HANDSHAKE_FAILURE ; } /* @@ -1856,7 +1856,7 @@ read_record_header: if( ( ret = ssl_ciphersuite_match( ssl, ciphersuites[i], &ciphersuite_info ) ) != 0 ) - return( ret ); + return ret ; if( ciphersuite_info != NULL ) goto have_ciphersuite; @@ -1873,7 +1873,7 @@ read_record_header: if( ( ret = ssl_ciphersuite_match( ssl, ciphersuites[i], &ciphersuite_info ) ) != 0 ) - return( ret ); + return ret ; if( ciphersuite_info != NULL ) goto have_ciphersuite; @@ -1886,14 +1886,14 @@ read_record_header: "but none of them usable" ) ); mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_HANDSHAKE_FAILURE ); - return( MBEDTLS_ERR_SSL_HANDSHAKE_FAILURE ); + return MBEDTLS_ERR_SSL_HANDSHAKE_FAILURE ; } else { MBEDTLS_SSL_DEBUG_MSG( 1, ( "got no ciphersuites in common" ) ); mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_HANDSHAKE_FAILURE ); - return( MBEDTLS_ERR_SSL_HANDSHAKE_FAILURE ); + return MBEDTLS_ERR_SSL_HANDSHAKE_FAILURE ; } have_ciphersuite: @@ -1933,7 +1933,7 @@ have_ciphersuite: MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= parse client hello" ) ); - return( 0 ); + return 0 ; } #if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID) @@ -2354,7 +2354,7 @@ static int ssl_write_hello_verify_request( mbedtls_ssl_context *ssl ) if( ssl->conf->f_cookie_write == NULL ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "inconsistent cookie callbacks" ) ); - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; } /* Skip length byte until we know the length */ @@ -2365,7 +2365,7 @@ static int ssl_write_hello_verify_request( mbedtls_ssl_context *ssl ) ssl->cli_id, ssl->cli_id_len ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "f_cookie_write", ret ); - return( ret ); + return ret ; } *cookie_len_byte = (unsigned char)( p - ( cookie_len_byte + 1 ) ); @@ -2381,7 +2381,7 @@ static int ssl_write_hello_verify_request( mbedtls_ssl_context *ssl ) if( ( ret = mbedtls_ssl_write_handshake_msg( ssl ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_write_handshake_msg", ret ); - return( ret ); + return ret ; } #if defined(MBEDTLS_SSL_PROTO_DTLS) @@ -2389,13 +2389,13 @@ static int ssl_write_hello_verify_request( mbedtls_ssl_context *ssl ) ( ret = mbedtls_ssl_flight_transmit( ssl ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_flight_transmit", ret ); - return( ret ); + return ret ; } #endif /* MBEDTLS_SSL_PROTO_DTLS */ MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= write hello verify request" ) ); - return( 0 ); + return 0 ; } #endif /* MBEDTLS_SSL_DTLS_HELLO_VERIFY */ @@ -2465,14 +2465,14 @@ static int ssl_write_server_hello( mbedtls_ssl_context *ssl ) MBEDTLS_SSL_DEBUG_MSG( 2, ( "client hello was not authenticated" ) ); MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= write server hello" ) ); - return( ssl_write_hello_verify_request( ssl ) ); + return ssl_write_hello_verify_request( ssl ) ; } #endif /* MBEDTLS_SSL_DTLS_HELLO_VERIFY */ if( ssl->conf->f_rng == NULL ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "no RNG provided") ); - return( MBEDTLS_ERR_SSL_NO_RNG ); + return MBEDTLS_ERR_SSL_NO_RNG ; } /* @@ -2503,13 +2503,13 @@ static int ssl_write_server_hello( mbedtls_ssl_context *ssl ) (long long) t ) ); #else if( ( ret = ssl->conf->f_rng( ssl->conf->p_rng, p, 4 ) ) != 0 ) - return( ret ); + return ret ; p += 4; #endif /* MBEDTLS_HAVE_TIME */ if( ( ret = ssl->conf->f_rng( ssl->conf->p_rng, p, 28 ) ) != 0 ) - return( ret ); + return ret ; p += 28; @@ -2543,7 +2543,7 @@ static int ssl_write_server_hello( mbedtls_ssl_context *ssl ) ssl->session_negotiate->id_len = n = 32; if( ( ret = ssl->conf->f_rng( ssl->conf->p_rng, ssl->session_negotiate->id, n ) ) != 0 ) - return( ret ); + return ret ; } } else @@ -2557,7 +2557,7 @@ static int ssl_write_server_hello( mbedtls_ssl_context *ssl ) if( ( ret = mbedtls_ssl_derive_keys( ssl ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_derive_keys", ret ); - return( ret ); + return ret ; } } @@ -2661,7 +2661,7 @@ static int ssl_write_server_hello( mbedtls_ssl_context *ssl ) MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= write server hello" ) ); - return( ret ); + return ret ; } #if !defined(MBEDTLS_KEY_EXCHANGE_CERT_REQ_ALLOWED_ENABLED) @@ -2676,11 +2676,11 @@ static int ssl_write_certificate_request( mbedtls_ssl_context *ssl ) { MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= skip write certificate request" ) ); ssl->state++; - return( 0 ); + return 0 ; } MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) ); - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; } #else /* !MBEDTLS_KEY_EXCHANGE_CERT_REQ_ALLOWED_ENABLED */ static int ssl_write_certificate_request( mbedtls_ssl_context *ssl ) @@ -2710,7 +2710,7 @@ static int ssl_write_certificate_request( mbedtls_ssl_context *ssl ) authmode == MBEDTLS_SSL_VERIFY_NONE ) { MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= skip write certificate request" ) ); - return( 0 ); + return 0 ; } /* @@ -2848,7 +2848,7 @@ static int ssl_write_certificate_request( mbedtls_ssl_context *ssl ) MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= write certificate request" ) ); - return( ret ); + return ret ; } #endif /* MBEDTLS_KEY_EXCHANGE_CERT_REQ_ALLOWED_ENABLED */ @@ -2861,7 +2861,7 @@ static int ssl_get_ecdh_params_from_cert( mbedtls_ssl_context *ssl ) if( ! mbedtls_pk_can_do( mbedtls_ssl_own_key( ssl ), MBEDTLS_PK_ECKEY ) ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "server key not ECDH capable" ) ); - return( MBEDTLS_ERR_SSL_PK_TYPE_MISMATCH ); + return MBEDTLS_ERR_SSL_PK_TYPE_MISMATCH ; } if( ( ret = mbedtls_ecdh_get_params( &ssl->handshake->ecdh_ctx, @@ -2869,10 +2869,10 @@ static int ssl_get_ecdh_params_from_cert( mbedtls_ssl_context *ssl ) MBEDTLS_ECDH_OURS ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, ( "mbedtls_ecdh_get_params" ), ret ); - return( ret ); + return ret ; } - return( 0 ); + return 0 ; } #endif /* MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) || MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED */ @@ -2898,7 +2898,7 @@ static int ssl_resume_server_key_exchange( mbedtls_ssl_context *ssl, mbedtls_ssl_set_async_operation_data( ssl, NULL ); } MBEDTLS_SSL_DEBUG_RET( 2, "ssl_resume_server_key_exchange", ret ); - return( ret ); + return ret ; } #endif /* defined(MBEDTLS_KEY_EXCHANGE_WITH_SERVER_SIGNATURE_ENABLED) && defined(MBEDTLS_SSL_ASYNC_PRIVATE) */ @@ -2956,7 +2956,7 @@ static int ssl_prepare_server_key_exchange( mbedtls_ssl_context *ssl, if( ret != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ecjpake_write_round_two", ret ); - return( ret ); + return ret ; } ssl->out_msglen += len; @@ -2991,7 +2991,7 @@ static int ssl_prepare_server_key_exchange( mbedtls_ssl_context *ssl, if( ssl->conf->dhm_P.p == NULL || ssl->conf->dhm_G.p == NULL ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "no DH parameters set" ) ); - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; } /* @@ -3008,7 +3008,7 @@ static int ssl_prepare_server_key_exchange( mbedtls_ssl_context *ssl, &ssl->conf->dhm_G ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_dhm_set_group", ret ); - return( ret ); + return ret ; } if( ( ret = mbedtls_dhm_make_params( @@ -3018,7 +3018,7 @@ static int ssl_prepare_server_key_exchange( mbedtls_ssl_context *ssl, ssl->conf->f_rng, ssl->conf->p_rng ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_dhm_make_params", ret ); - return( ret ); + return ret ; } #if defined(MBEDTLS_KEY_EXCHANGE_WITH_SERVER_SIGNATURE_ENABLED) @@ -3063,7 +3063,7 @@ curve_matching_done: if( curve == NULL || *curve == NULL ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "no matching curve for ECDHE" ) ); - return( MBEDTLS_ERR_SSL_HANDSHAKE_FAILURE ); + return MBEDTLS_ERR_SSL_HANDSHAKE_FAILURE ; } MBEDTLS_SSL_DEBUG_MSG( 2, ( "ECDHE curve: %s", (*curve)->name ) ); @@ -3072,7 +3072,7 @@ curve_matching_done: (*curve)->grp_id ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ecp_group_load", ret ); - return( ret ); + return ret ; } if( ( ret = mbedtls_ecdh_make_params( @@ -3082,7 +3082,7 @@ curve_matching_done: ssl->conf->f_rng, ssl->conf->p_rng ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ecdh_make_params", ret ); - return( ret ); + return ret ; } #if defined(MBEDTLS_KEY_EXCHANGE_WITH_SERVER_SIGNATURE_ENABLED) @@ -3132,13 +3132,13 @@ curve_matching_done: MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) ); /* (... because we choose a cipher suite * only if there is a matching hash.) */ - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; } } else { MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) ); - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; } #endif /* MBEDTLS_SSL_PROTO_TLS1_2 */ @@ -3155,13 +3155,13 @@ curve_matching_done: dig_signed_len, md_alg ); if( ret != 0 ) - return( ret ); + return ret ; } else #endif /* MBEDTLS_SSL_PROTO_TLS1_2 */ { MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) ); - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; } MBEDTLS_SSL_DEBUG_BUF( 3, "parameters hash", hash, hashlen ); @@ -3208,13 +3208,13 @@ curve_matching_done: break; case 0: ssl->handshake->async_in_progress = 1; - return( ssl_resume_server_key_exchange( ssl, signature_len ) ); + return ssl_resume_server_key_exchange( ssl, signature_len ) ; case MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS: ssl->handshake->async_in_progress = 1; - return( MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS ); + return MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS ; default: MBEDTLS_SSL_DEBUG_RET( 1, "f_async_sign_start", ret ); - return( ret ); + return ret ; } } #endif /* MBEDTLS_SSL_ASYNC_PRIVATE */ @@ -3222,7 +3222,7 @@ curve_matching_done: if( mbedtls_ssl_own_key( ssl ) == NULL ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "got no private key" ) ); - return( MBEDTLS_ERR_SSL_PRIVATE_KEY_REQUIRED ); + return MBEDTLS_ERR_SSL_PRIVATE_KEY_REQUIRED ; } /* Append the signature to ssl->out_msg, leaving 2 bytes for the @@ -3239,12 +3239,12 @@ curve_matching_done: ssl->conf->p_rng ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_pk_sign", ret ); - return( ret ); + return ret ; } } #endif /* MBEDTLS_KEY_EXCHANGE_WITH_SERVER_SIGNATURE_ENABLED */ - return( 0 ); + return 0 ; } /* Prepare the ServerKeyExchange message and send it. For ciphersuites @@ -3280,7 +3280,7 @@ static int ssl_write_server_key_exchange( mbedtls_ssl_context *ssl ) * ServerKeyExchange, so end here. */ MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= skip write server key exchange" ) ); ssl->state++; - return( 0 ); + return 0 ; } #endif /* MBEDTLS_KEY_EXCHANGE_SOME_NON_PFS_ENABLED */ @@ -3311,7 +3311,7 @@ static int ssl_write_server_key_exchange( mbedtls_ssl_context *ssl ) MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= write server key exchange (pending)" ) ); else ssl->out_msglen = 0; - return( ret ); + return ret ; } /* If there is a signature, write its length. @@ -3341,11 +3341,11 @@ static int ssl_write_server_key_exchange( mbedtls_ssl_context *ssl ) if( ( ret = mbedtls_ssl_write_handshake_msg( ssl ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_write_handshake_msg", ret ); - return( ret ); + return ret ; } MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= write server key exchange" ) ); - return( 0 ); + return 0 ; } static int ssl_write_server_hello_done( mbedtls_ssl_context *ssl ) @@ -3368,7 +3368,7 @@ static int ssl_write_server_hello_done( mbedtls_ssl_context *ssl ) if( ( ret = mbedtls_ssl_write_handshake_msg( ssl ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_write_handshake_msg", ret ); - return( ret ); + return ret ; } #if defined(MBEDTLS_SSL_PROTO_DTLS) @@ -3376,13 +3376,13 @@ static int ssl_write_server_hello_done( mbedtls_ssl_context *ssl ) ( ret = mbedtls_ssl_flight_transmit( ssl ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_flight_transmit", ret ); - return( ret ); + return ret ; } #endif /* MBEDTLS_SSL_PROTO_DTLS */ MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= write server hello done" ) ); - return( 0 ); + return 0 ; } #if defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED) || \ @@ -3399,7 +3399,7 @@ static int ssl_parse_client_dh_public( mbedtls_ssl_context *ssl, unsigned char * if( *p + 2 > end ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad client key exchange message" ) ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } n = ( (*p)[0] << 8 ) | (*p)[1]; @@ -3408,20 +3408,20 @@ static int ssl_parse_client_dh_public( mbedtls_ssl_context *ssl, unsigned char * if( *p + n > end ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad client key exchange message" ) ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } if( ( ret = mbedtls_dhm_read_public( &ssl->handshake->dhm_ctx, *p, n ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_dhm_read_public", ret ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } *p += n; MBEDTLS_SSL_DEBUG_MPI( 3, "DHM: GY", &ssl->handshake->dhm_ctx.GY ); - return( ret ); + return ret ; } #endif /* MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED || MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED */ @@ -3443,7 +3443,7 @@ static int ssl_resume_decrypt_pms( mbedtls_ssl_context *ssl, mbedtls_ssl_set_async_operation_data( ssl, NULL ); } MBEDTLS_SSL_DEBUG_RET( 2, "ssl_decrypt_encrypted_pms", ret ); - return( ret ); + return ret ; } #endif /* MBEDTLS_SSL_ASYNC_PRIVATE */ @@ -3476,20 +3476,20 @@ static int ssl_decrypt_encrypted_pms( mbedtls_ssl_context *ssl, #if defined(MBEDTLS_SSL_PROTO_TLS1_2) if ( p + 2 > end ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad client key exchange message" ) ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } if( *p++ != ( ( len >> 8 ) & 0xFF ) || *p++ != ( ( len ) & 0xFF ) ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad client key exchange message" ) ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } #endif if( p + len != end ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad client key exchange message" ) ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } /* @@ -3514,10 +3514,10 @@ static int ssl_decrypt_encrypted_pms( mbedtls_ssl_context *ssl, peer_pmssize ) ); case MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS: ssl->handshake->async_in_progress = 1; - return( MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS ); + return MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS ; default: MBEDTLS_SSL_DEBUG_RET( 1, "f_async_decrypt_start", ret ); - return( ret ); + return ret ; } } #endif /* MBEDTLS_SSL_ASYNC_PRIVATE */ @@ -3525,13 +3525,13 @@ static int ssl_decrypt_encrypted_pms( mbedtls_ssl_context *ssl, if( ! mbedtls_pk_can_do( private_key, MBEDTLS_PK_RSA ) ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "got no RSA private key" ) ); - return( MBEDTLS_ERR_SSL_PRIVATE_KEY_REQUIRED ); + return MBEDTLS_ERR_SSL_PRIVATE_KEY_REQUIRED ; } ret = mbedtls_pk_decrypt( private_key, p, len, peer_pms, peer_pmslen, peer_pmssize, ssl->conf->f_rng, ssl->conf->p_rng ); - return( ret ); + return ret ; } static int ssl_parse_encrypted_pms( mbedtls_ssl_context *ssl, @@ -3564,7 +3564,7 @@ static int ssl_parse_encrypted_pms( mbedtls_ssl_context *ssl, #if defined(MBEDTLS_SSL_ASYNC_PRIVATE) if ( ret == MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS ) - return( ret ); + return ret ; #endif /* MBEDTLS_SSL_ASYNC_PRIVATE */ mbedtls_ssl_write_version( ssl->handshake->max_major_ver, @@ -3605,7 +3605,7 @@ static int ssl_parse_encrypted_pms( mbedtls_ssl_context *ssl, { /* It's ok to abort on an RNG failure, since this does not reveal * anything about the RSA decryption. */ - return( ret ); + return ret ; } #if defined(MBEDTLS_SSL_DEBUG_ALL) @@ -3617,7 +3617,7 @@ static int ssl_parse_encrypted_pms( mbedtls_ssl_context *ssl, sizeof( ssl->handshake->premaster ) - pms_offset < 48 ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) ); - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; } ssl->handshake->pmslen = 48; @@ -3626,7 +3626,7 @@ static int ssl_parse_encrypted_pms( mbedtls_ssl_context *ssl, for( i = 0; i < ssl->handshake->pmslen; i++ ) pms[i] = ( mask & fake_pms[i] ) | ( (~mask) & peer_pms[i] ); - return( 0 ); + return 0 ; } #endif /* MBEDTLS_KEY_EXCHANGE_RSA_ENABLED || MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED */ @@ -3641,7 +3641,7 @@ static int ssl_parse_client_psk_identity( mbedtls_ssl_context *ssl, unsigned cha if( ssl_conf_has_psk_or_cb( ssl->conf ) == 0 ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "got no pre-shared key" ) ); - return( MBEDTLS_ERR_SSL_PRIVATE_KEY_REQUIRED ); + return MBEDTLS_ERR_SSL_PRIVATE_KEY_REQUIRED ; } /* @@ -3650,7 +3650,7 @@ static int ssl_parse_client_psk_identity( mbedtls_ssl_context *ssl, unsigned cha if( end - *p < 2 ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad client key exchange message" ) ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } n = ( (*p)[0] << 8 ) | (*p)[1]; @@ -3659,7 +3659,7 @@ static int ssl_parse_client_psk_identity( mbedtls_ssl_context *ssl, unsigned cha if( n == 0 || n > end - *p ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad client key exchange message" ) ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } if( ssl->conf->f_psk != NULL ) @@ -3683,12 +3683,12 @@ static int ssl_parse_client_psk_identity( mbedtls_ssl_context *ssl, unsigned cha MBEDTLS_SSL_DEBUG_BUF( 3, "Unknown PSK identity", *p, n ); mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_UNKNOWN_PSK_IDENTITY ); - return( MBEDTLS_ERR_SSL_UNKNOWN_IDENTITY ); + return MBEDTLS_ERR_SSL_UNKNOWN_IDENTITY ; } *p += n; - return( 0 ); + return 0 ; } #endif /* MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED */ @@ -3719,7 +3719,7 @@ static int ssl_parse_client_key_exchange( mbedtls_ssl_context *ssl ) if( ( ret = mbedtls_ssl_read_record( ssl, 1 ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_read_record", ret ); - return( ret ); + return ret ; } p = ssl->in_msg + mbedtls_ssl_hs_hdr_len( ssl ); @@ -3728,13 +3728,13 @@ static int ssl_parse_client_key_exchange( mbedtls_ssl_context *ssl ) if( ssl->in_msgtype != MBEDTLS_SSL_MSG_HANDSHAKE ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad client key exchange message" ) ); - return( MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE ); + return MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE ; } if( ssl->in_msg[0] != MBEDTLS_SSL_HS_CLIENT_KEY_EXCHANGE ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad client key exchange message" ) ); - return( MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE ); + return MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE ; } #if defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED) @@ -3743,13 +3743,13 @@ static int ssl_parse_client_key_exchange( mbedtls_ssl_context *ssl ) if( ( ret = ssl_parse_client_dh_public( ssl, &p, end ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, ( "ssl_parse_client_dh_public" ), ret ); - return( ret ); + return ret ; } if( p != end ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad client key exchange" ) ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } if( ( ret = mbedtls_dhm_calc_secret( &ssl->handshake->dhm_ctx, @@ -3759,7 +3759,7 @@ static int ssl_parse_client_key_exchange( mbedtls_ssl_context *ssl ) ssl->conf->f_rng, ssl->conf->p_rng ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_dhm_calc_secret", ret ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } MBEDTLS_SSL_DEBUG_MPI( 3, "DHM: K ", &ssl->handshake->dhm_ctx.K ); @@ -3779,7 +3779,7 @@ static int ssl_parse_client_key_exchange( mbedtls_ssl_context *ssl ) p, end - p) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ecdh_read_public", ret ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } MBEDTLS_SSL_DEBUG_ECDH( 3, &ssl->handshake->ecdh_ctx, @@ -3792,7 +3792,7 @@ static int ssl_parse_client_key_exchange( mbedtls_ssl_context *ssl ) ssl->conf->f_rng, ssl->conf->p_rng ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ecdh_calc_secret", ret ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } MBEDTLS_SSL_DEBUG_ECDH( 3, &ssl->handshake->ecdh_ctx, @@ -3809,13 +3809,13 @@ static int ssl_parse_client_key_exchange( mbedtls_ssl_context *ssl ) if( ( ret = ssl_parse_client_psk_identity( ssl, &p, end ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, ( "ssl_parse_client_psk_identity" ), ret ); - return( ret ); + return ret ; } if( p != end ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad client key exchange" ) ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } #if defined(MBEDTLS_USE_PSA_CRYPTO) @@ -3829,7 +3829,7 @@ static int ssl_parse_client_key_exchange( mbedtls_ssl_context *ssl ) ciphersuite_info->key_exchange ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_psk_derive_premaster", ret ); - return( ret ); + return ret ; } } else @@ -3853,26 +3853,26 @@ static int ssl_parse_client_key_exchange( mbedtls_ssl_context *ssl ) if( ( ret = ssl_parse_client_psk_identity( ssl, &p, end ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, ( "ssl_parse_client_psk_identity" ), ret ); - return( ret ); + return ret ; } #if defined(MBEDTLS_USE_PSA_CRYPTO) /* Opaque PSKs are currently only supported for PSK-only. */ if( ssl_use_opaque_psk( ssl ) == 1 ) - return( MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE ; #endif if( ( ret = ssl_parse_encrypted_pms( ssl, p, end, 2 ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, ( "ssl_parse_encrypted_pms" ), ret ); - return( ret ); + return ret ; } if( ( ret = mbedtls_ssl_psk_derive_premaster( ssl, ciphersuite_info->key_exchange ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_psk_derive_premaster", ret ); - return( ret ); + return ret ; } } else @@ -3883,31 +3883,31 @@ static int ssl_parse_client_key_exchange( mbedtls_ssl_context *ssl ) if( ( ret = ssl_parse_client_psk_identity( ssl, &p, end ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, ( "ssl_parse_client_psk_identity" ), ret ); - return( ret ); + return ret ; } if( ( ret = ssl_parse_client_dh_public( ssl, &p, end ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, ( "ssl_parse_client_dh_public" ), ret ); - return( ret ); + return ret ; } #if defined(MBEDTLS_USE_PSA_CRYPTO) /* Opaque PSKs are currently only supported for PSK-only. */ if( ssl_use_opaque_psk( ssl ) == 1 ) - return( MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE ; #endif if( p != end ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad client key exchange" ) ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } if( ( ret = mbedtls_ssl_psk_derive_premaster( ssl, ciphersuite_info->key_exchange ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_psk_derive_premaster", ret ); - return( ret ); + return ret ; } } else @@ -3918,20 +3918,20 @@ static int ssl_parse_client_key_exchange( mbedtls_ssl_context *ssl ) if( ( ret = ssl_parse_client_psk_identity( ssl, &p, end ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, ( "ssl_parse_client_psk_identity" ), ret ); - return( ret ); + return ret ; } if( ( ret = mbedtls_ecdh_read_public( &ssl->handshake->ecdh_ctx, p, end - p ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ecdh_read_public", ret ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } #if defined(MBEDTLS_USE_PSA_CRYPTO) /* Opaque PSKs are currently only supported for PSK-only. */ if( ssl_use_opaque_psk( ssl ) == 1 ) - return( MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE ; #endif MBEDTLS_SSL_DEBUG_ECDH( 3, &ssl->handshake->ecdh_ctx, @@ -3941,7 +3941,7 @@ static int ssl_parse_client_key_exchange( mbedtls_ssl_context *ssl ) ciphersuite_info->key_exchange ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_psk_derive_premaster", ret ); - return( ret ); + return ret ; } } else @@ -3952,7 +3952,7 @@ static int ssl_parse_client_key_exchange( mbedtls_ssl_context *ssl ) if( ( ret = ssl_parse_encrypted_pms( ssl, p, end, 0 ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, ( "ssl_parse_parse_encrypted_pms_secret" ), ret ); - return( ret ); + return ret ; } } else @@ -3965,7 +3965,7 @@ static int ssl_parse_client_key_exchange( mbedtls_ssl_context *ssl ) if( ret != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ecjpake_read_round_two", ret ); - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; } ret = mbedtls_ecjpake_derive_secret( &ssl->handshake->ecjpake_ctx, @@ -3974,27 +3974,27 @@ static int ssl_parse_client_key_exchange( mbedtls_ssl_context *ssl ) if( ret != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ecjpake_derive_secret", ret ); - return( ret ); + return ret ; } } else #endif /* MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED */ { MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) ); - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; } if( ( ret = mbedtls_ssl_derive_keys( ssl ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_derive_keys", ret ); - return( ret ); + return ret ; } ssl->state++; MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= parse client key exchange" ) ); - return( 0 ); + return 0 ; } #if !defined(MBEDTLS_KEY_EXCHANGE_CERT_REQ_ALLOWED_ENABLED) @@ -4009,11 +4009,11 @@ static int ssl_parse_certificate_verify( mbedtls_ssl_context *ssl ) { MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= skip parse certificate verify" ) ); ssl->state++; - return( 0 ); + return 0 ; } MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) ); - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; } #else /* !MBEDTLS_KEY_EXCHANGE_CERT_REQ_ALLOWED_ENABLED */ static int ssl_parse_certificate_verify( mbedtls_ssl_context *ssl ) @@ -4037,7 +4037,7 @@ static int ssl_parse_certificate_verify( mbedtls_ssl_context *ssl ) { MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= skip parse certificate verify" ) ); ssl->state++; - return( 0 ); + return 0 ; } #if defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE) @@ -4045,14 +4045,14 @@ static int ssl_parse_certificate_verify( mbedtls_ssl_context *ssl ) { MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= skip parse certificate verify" ) ); ssl->state++; - return( 0 ); + return 0 ; } #else /* MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */ if( ssl->session_negotiate->peer_cert_digest == NULL ) { MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= skip parse certificate verify" ) ); ssl->state++; - return( 0 ); + return 0 ; } #endif /* !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */ @@ -4061,7 +4061,7 @@ static int ssl_parse_certificate_verify( mbedtls_ssl_context *ssl ) if( 0 != ret ) { MBEDTLS_SSL_DEBUG_RET( 1, ( "mbedtls_ssl_read_record" ), ret ); - return( ret ); + return ret ; } ssl->state++; @@ -4071,7 +4071,7 @@ static int ssl_parse_certificate_verify( mbedtls_ssl_context *ssl ) ssl->in_msg[0] != MBEDTLS_SSL_HS_CERTIFICATE_VERIFY ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad certificate verify message" ) ); - return( MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE ); + return MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE ; } i = mbedtls_ssl_hs_hdr_len( ssl ); @@ -4082,7 +4082,7 @@ static int ssl_parse_certificate_verify( mbedtls_ssl_context *ssl ) if( ssl->session_negotiate->peer_cert == NULL ) { /* Should never happen */ - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; } peer_pk = &ssl->session_negotiate->peer_cert->pk; #endif /* MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */ @@ -4099,7 +4099,7 @@ static int ssl_parse_certificate_verify( mbedtls_ssl_context *ssl ) if( i + 2 > ssl->in_hslen ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad certificate verify message" ) ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } /* @@ -4111,7 +4111,7 @@ static int ssl_parse_certificate_verify( mbedtls_ssl_context *ssl ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "peer not adhering to requested sig_alg" " for verify message" ) ); - return( MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER ); + return MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER ; } #if !defined(MBEDTLS_MD_SHA1) @@ -4132,7 +4132,7 @@ static int ssl_parse_certificate_verify( mbedtls_ssl_context *ssl ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "peer not adhering to requested sig_alg" " for verify message" ) ); - return( MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER ); + return MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER ; } /* @@ -4141,7 +4141,7 @@ static int ssl_parse_certificate_verify( mbedtls_ssl_context *ssl ) if( !mbedtls_pk_can_do( peer_pk, pk_alg ) ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "sig_alg doesn't match cert key" ) ); - return( MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER ); + return MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER ; } i++; @@ -4150,13 +4150,13 @@ static int ssl_parse_certificate_verify( mbedtls_ssl_context *ssl ) #endif /* MBEDTLS_SSL_PROTO_TLS1_2 */ { MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) ); - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; } if( i + 2 > ssl->in_hslen ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad certificate verify message" ) ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } sig_len = ( ssl->in_msg[i] << 8 ) | ssl->in_msg[i+1]; @@ -4165,7 +4165,7 @@ static int ssl_parse_certificate_verify( mbedtls_ssl_context *ssl ) if( i + sig_len != ssl->in_hslen ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad certificate verify message" ) ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } /* Calculate hash and verify signature */ @@ -4179,14 +4179,14 @@ static int ssl_parse_certificate_verify( mbedtls_ssl_context *ssl ) ssl->in_msg + i, sig_len ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_pk_verify", ret ); - return( ret ); + return ret ; } mbedtls_ssl_update_handshake_status( ssl ); MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= parse certificate verify" ) ); - return( ret ); + return ret ; } #endif /* MBEDTLS_KEY_EXCHANGE_CERT_REQ_ALLOWED_ENABLED */ @@ -4242,12 +4242,12 @@ static int ssl_write_new_session_ticket( mbedtls_ssl_context *ssl ) if( ( ret = mbedtls_ssl_write_handshake_msg( ssl ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_write_handshake_msg", ret ); - return( ret ); + return ret ; } MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= write new session ticket" ) ); - return( 0 ); + return 0 ; } #endif /* MBEDTLS_SSL_SESSION_TICKETS */ @@ -4259,19 +4259,19 @@ int mbedtls_ssl_handshake_server_step( mbedtls_ssl_context *ssl ) int ret = 0; if( ssl->state == MBEDTLS_SSL_HANDSHAKE_OVER || ssl->handshake == NULL ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; MBEDTLS_SSL_DEBUG_MSG( 2, ( "server state: %d", ssl->state ) ); if( ( ret = mbedtls_ssl_flush_output( ssl ) ) != 0 ) - return( ret ); + return ret ; #if defined(MBEDTLS_SSL_PROTO_DTLS) if( ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM && ssl->handshake->retransmit_state == MBEDTLS_SSL_RETRANS_SENDING ) { if( ( ret = mbedtls_ssl_flight_transmit( ssl ) ) != 0 ) - return( ret ); + return ret ; } #endif /* MBEDTLS_SSL_PROTO_DTLS */ @@ -4290,7 +4290,7 @@ int mbedtls_ssl_handshake_server_step( mbedtls_ssl_context *ssl ) #if defined(MBEDTLS_SSL_PROTO_DTLS) case MBEDTLS_SSL_SERVER_HELLO_VERIFY_REQUEST_SENT: - return( MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED ); + return MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED ; #endif /* @@ -4376,10 +4376,10 @@ int mbedtls_ssl_handshake_server_step( mbedtls_ssl_context *ssl ) default: MBEDTLS_SSL_DEBUG_MSG( 1, ( "invalid state %d", ssl->state ) ); - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; } - return( ret ); + return ret ; } void mbedtls_ssl_conf_preference_order( mbedtls_ssl_config *conf, int order ) diff --git a/library/ssl_ticket.c b/library/ssl_ticket.c index 940e1a67a2..9226762804 100644 --- a/library/ssl_ticket.c +++ b/library/ssl_ticket.c @@ -78,10 +78,10 @@ static int ssl_ticket_gen_key( mbedtls_ssl_ticket_context *ctx, #endif if( ( ret = ctx->f_rng( ctx->p_rng, key->name, sizeof( key->name ) ) ) != 0 ) - return( ret ); + return ret ; if( ( ret = ctx->f_rng( ctx->p_rng, buf, sizeof( buf ) ) ) != 0 ) - return( ret ); + return ret ; /* With GCM and CCM, same context can encrypt & decrypt */ ret = mbedtls_cipher_setkey( &key->ctx, buf, @@ -90,7 +90,7 @@ static int ssl_ticket_gen_key( mbedtls_ssl_ticket_context *ctx, mbedtls_platform_zeroize( buf, sizeof( buf ) ); - return( ret ); + return ret ; } /* @@ -109,16 +109,16 @@ static int ssl_ticket_update_keys( mbedtls_ssl_ticket_context *ctx ) if( current_time >= key_time && current_time - key_time < ctx->ticket_lifetime ) { - return( 0 ); + return 0 ; } ctx->active = 1 - ctx->active; - return( ssl_ticket_gen_key( ctx, ctx->active ) ); + return ssl_ticket_gen_key( ctx, ctx->active ) ; } else #endif /* MBEDTLS_HAVE_TIME */ - return( 0 ); + return 0 ; } /* @@ -139,46 +139,46 @@ int mbedtls_ssl_ticket_setup( mbedtls_ssl_ticket_context *ctx, cipher_info = mbedtls_cipher_info_from_type( cipher); if( cipher_info == NULL ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; if( cipher_info->mode != MBEDTLS_MODE_GCM && cipher_info->mode != MBEDTLS_MODE_CCM ) { - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; } if( cipher_info->key_bitlen > 8 * MAX_KEY_BYTES ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; #if defined(MBEDTLS_USE_PSA_CRYPTO) ret = mbedtls_cipher_setup_psa( &ctx->keys[0].ctx, cipher_info, TICKET_AUTH_TAG_BYTES ); if( ret != 0 && ret != MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ) - return( ret ); + return ret ; /* We don't yet expect to support all ciphers through PSA, * so allow fallback to ordinary mbedtls_cipher_setup(). */ if( ret == MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ) #endif /* MBEDTLS_USE_PSA_CRYPTO */ if( ( ret = mbedtls_cipher_setup( &ctx->keys[0].ctx, cipher_info ) ) != 0 ) - return( ret ); + return ret ; #if defined(MBEDTLS_USE_PSA_CRYPTO) ret = mbedtls_cipher_setup_psa( &ctx->keys[1].ctx, cipher_info, TICKET_AUTH_TAG_BYTES ); if( ret != 0 && ret != MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ) - return( ret ); + return ret ; if( ret == MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ) #endif /* MBEDTLS_USE_PSA_CRYPTO */ if( ( ret = mbedtls_cipher_setup( &ctx->keys[1].ctx, cipher_info ) ) != 0 ) - return( ret ); + return ret ; if( ( ret = ssl_ticket_gen_key( ctx, 0 ) ) != 0 || ( ret = ssl_ticket_gen_key( ctx, 1 ) ) != 0 ) { - return( ret ); + return ret ; } - return( 0 ); + return 0 ; } /* @@ -214,7 +214,7 @@ int mbedtls_ssl_ticket_write( void *p_ticket, *tlen = 0; if( ctx == NULL || ctx->f_rng == NULL ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; /* We need at least 4 bytes for key_name, 12 for IV, 2 for len 16 for tag, * in addition to session itself, that will be checked when writing it. */ @@ -222,7 +222,7 @@ int mbedtls_ssl_ticket_write( void *p_ticket, #if defined(MBEDTLS_THREADING_C) if( ( ret = mbedtls_mutex_lock( &ctx->mutex ) ) != 0 ) - return( ret ); + return ret ; #endif if( ( ret = ssl_ticket_update_keys( ctx ) ) != 0 ) @@ -270,10 +270,10 @@ int mbedtls_ssl_ticket_write( void *p_ticket, cleanup: #if defined(MBEDTLS_THREADING_C) if( mbedtls_mutex_unlock( &ctx->mutex ) != 0 ) - return( MBEDTLS_ERR_THREADING_MUTEX_ERROR ); + return MBEDTLS_ERR_THREADING_MUTEX_ERROR ; #endif - return( ret ); + return ret ; } /* @@ -287,9 +287,9 @@ static mbedtls_ssl_ticket_key *ssl_ticket_select_key( for( i = 0; i < sizeof( ctx->keys ) / sizeof( *ctx->keys ); i++ ) if( memcmp( name, ctx->keys[i].name, 4 ) == 0 ) - return( &ctx->keys[i] ); + return &ctx->keys[i] ; - return( NULL ); + return NULL ; } /* @@ -310,14 +310,14 @@ int mbedtls_ssl_ticket_parse( void *p_ticket, size_t enc_len, clear_len; if( ctx == NULL || ctx->f_rng == NULL ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; if( len < TICKET_MIN_LEN ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; #if defined(MBEDTLS_THREADING_C) if( ( ret = mbedtls_mutex_lock( &ctx->mutex ) ) != 0 ) - return( ret ); + return ret ; #endif if( ( ret = ssl_ticket_update_keys( ctx ) ) != 0 ) @@ -381,10 +381,10 @@ int mbedtls_ssl_ticket_parse( void *p_ticket, cleanup: #if defined(MBEDTLS_THREADING_C) if( mbedtls_mutex_unlock( &ctx->mutex ) != 0 ) - return( MBEDTLS_ERR_THREADING_MUTEX_ERROR ); + return MBEDTLS_ERR_THREADING_MUTEX_ERROR ; #endif - return( ret ); + return ret ; } /* diff --git a/library/ssl_tls.c b/library/ssl_tls.c index bb5ddc470e..644a0e927e 100644 --- a/library/ssl_tls.c +++ b/library/ssl_tls.c @@ -61,17 +61,17 @@ int mbedtls_ssl_conf_cid( mbedtls_ssl_config *conf, int ignore_other_cid ) { if( len > MBEDTLS_SSL_CID_IN_LEN_MAX ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; if( ignore_other_cid != MBEDTLS_SSL_UNEXPECTED_CID_FAIL && ignore_other_cid != MBEDTLS_SSL_UNEXPECTED_CID_IGNORE ) { - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; } conf->ignore_unexpected_cid = ignore_other_cid; conf->cid_len = len; - return( 0 ); + return 0 ; } int mbedtls_ssl_set_cid( mbedtls_ssl_context *ssl, @@ -80,13 +80,13 @@ int mbedtls_ssl_set_cid( mbedtls_ssl_context *ssl, size_t own_cid_len ) { if( ssl->conf->transport != MBEDTLS_SSL_TRANSPORT_DATAGRAM ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; ssl->negotiate_cid = enable; if( enable == MBEDTLS_SSL_CID_DISABLED ) { MBEDTLS_SSL_DEBUG_MSG( 3, ( "Disable use of CID extension." ) ); - return( 0 ); + return 0 ; } MBEDTLS_SSL_DEBUG_MSG( 3, ( "Enable use of CID extension." ) ); MBEDTLS_SSL_DEBUG_BUF( 3, "Own CID", own_cid, own_cid_len ); @@ -96,7 +96,7 @@ int mbedtls_ssl_set_cid( mbedtls_ssl_context *ssl, MBEDTLS_SSL_DEBUG_MSG( 3, ( "CID length %u does not match CID length %u in config", (unsigned) own_cid_len, (unsigned) ssl->conf->cid_len ) ); - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; } memcpy( ssl->own_cid, own_cid, own_cid_len ); @@ -104,7 +104,7 @@ int mbedtls_ssl_set_cid( mbedtls_ssl_context *ssl, * MBEDTLS_SSL_CID_IN_LEN_MAX at most 255. */ ssl->own_cid_len = (uint8_t) own_cid_len; - return( 0 ); + return 0 ; } int mbedtls_ssl_get_peer_cid( mbedtls_ssl_context *ssl, @@ -117,7 +117,7 @@ int mbedtls_ssl_get_peer_cid( mbedtls_ssl_context *ssl, if( ssl->conf->transport != MBEDTLS_SSL_TRANSPORT_DATAGRAM || ssl->state != MBEDTLS_SSL_HANDSHAKE_OVER ) { - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; } /* We report MBEDTLS_SSL_CID_DISABLED in case the CID extensions @@ -127,7 +127,7 @@ int mbedtls_ssl_get_peer_cid( mbedtls_ssl_context *ssl, if( ssl->transform_in->in_cid_len == 0 && ssl->transform_in->out_cid_len == 0 ) { - return( 0 ); + return 0 ; } if( peer_cid_len != NULL ) @@ -142,7 +142,7 @@ int mbedtls_ssl_get_peer_cid( mbedtls_ssl_context *ssl, *enabled = MBEDTLS_SSL_CID_ENABLED; - return( 0 ); + return 0 ; } #endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */ @@ -162,7 +162,7 @@ static unsigned int ssl_mfl_code_to_length( int mfl ) switch( mfl ) { case MBEDTLS_SSL_MAX_FRAG_LEN_NONE: - return ( MBEDTLS_TLS_EXT_ADV_CONTENT_LEN ); + return MBEDTLS_TLS_EXT_ADV_CONTENT_LEN ; case MBEDTLS_SSL_MAX_FRAG_LEN_512: return 512; case MBEDTLS_SSL_MAX_FRAG_LEN_1024: @@ -172,7 +172,7 @@ static unsigned int ssl_mfl_code_to_length( int mfl ) case MBEDTLS_SSL_MAX_FRAG_LEN_4096: return 4096; default: - return ( MBEDTLS_TLS_EXT_ADV_CONTENT_LEN ); + return MBEDTLS_TLS_EXT_ADV_CONTENT_LEN ; } } #endif /* MBEDTLS_SSL_MAX_FRAGMENT_LENGTH */ @@ -192,7 +192,7 @@ int mbedtls_ssl_session_copy( mbedtls_ssl_session *dst, dst->peer_cert = mbedtls_calloc( 1, sizeof(mbedtls_x509_crt) ); if( dst->peer_cert == NULL ) - return( MBEDTLS_ERR_SSL_ALLOC_FAILED ); + return MBEDTLS_ERR_SSL_ALLOC_FAILED ; mbedtls_x509_crt_init( dst->peer_cert ); @@ -201,7 +201,7 @@ int mbedtls_ssl_session_copy( mbedtls_ssl_session *dst, { mbedtls_free( dst->peer_cert ); dst->peer_cert = NULL; - return( ret ); + return ret ; } } #else /* MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */ @@ -210,7 +210,7 @@ int mbedtls_ssl_session_copy( mbedtls_ssl_session *dst, dst->peer_cert_digest = mbedtls_calloc( 1, src->peer_cert_digest_len ); if( dst->peer_cert_digest == NULL ) - return( MBEDTLS_ERR_SSL_ALLOC_FAILED ); + return MBEDTLS_ERR_SSL_ALLOC_FAILED ; memcpy( dst->peer_cert_digest, src->peer_cert_digest, src->peer_cert_digest_len ); @@ -226,13 +226,13 @@ int mbedtls_ssl_session_copy( mbedtls_ssl_session *dst, { dst->ticket = mbedtls_calloc( 1, src->ticket_len ); if( dst->ticket == NULL ) - return( MBEDTLS_ERR_SSL_ALLOC_FAILED ); + return MBEDTLS_ERR_SSL_ALLOC_FAILED ; memcpy( dst->ticket, src->ticket, src->ticket_len ); } #endif /* MBEDTLS_SSL_SESSION_TICKETS && MBEDTLS_SSL_CLI_C */ - return( 0 ); + return 0 ; } #if defined(MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH) @@ -338,7 +338,7 @@ static psa_status_t setup_psa_key_derivation( psa_key_derivation_operation_t* de status = psa_key_derivation_setup( derivation, alg ); if( status != PSA_SUCCESS ) - return( status ); + return status ; if( PSA_ALG_IS_TLS12_PRF( alg ) || PSA_ALG_IS_TLS12_PSK_TO_MS( alg ) ) { @@ -346,7 +346,7 @@ static psa_status_t setup_psa_key_derivation( psa_key_derivation_operation_t* de PSA_KEY_DERIVATION_INPUT_SEED, seed, seed_length ); if( status != PSA_SUCCESS ) - return( status ); + return status ; if( mbedtls_svc_key_id_is_null( key ) ) { @@ -360,24 +360,24 @@ static psa_status_t setup_psa_key_derivation( psa_key_derivation_operation_t* de derivation, PSA_KEY_DERIVATION_INPUT_SECRET, key ); } if( status != PSA_SUCCESS ) - return( status ); + return status ; status = psa_key_derivation_input_bytes( derivation, PSA_KEY_DERIVATION_INPUT_LABEL, label, label_length ); if( status != PSA_SUCCESS ) - return( status ); + return status ; } else { - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; } status = psa_key_derivation_set_capacity( derivation, capacity ); if( status != PSA_SUCCESS ) - return( status ); + return status ; - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } static int tls_prf_generic( mbedtls_md_type_t md_type, @@ -413,7 +413,7 @@ static int tls_prf_generic( mbedtls_md_type_t md_type, status = psa_import_key( &key_attributes, secret, slen, &master_key ); if( status != PSA_SUCCESS ) - return( MBEDTLS_ERR_SSL_HW_ACCEL_FAILED ); + return MBEDTLS_ERR_SSL_HW_ACCEL_FAILED ; } status = setup_psa_key_derivation( &derivation, @@ -426,7 +426,7 @@ static int tls_prf_generic( mbedtls_md_type_t md_type, { psa_key_derivation_abort( &derivation ); psa_destroy_key( master_key ); - return( MBEDTLS_ERR_SSL_HW_ACCEL_FAILED ); + return MBEDTLS_ERR_SSL_HW_ACCEL_FAILED ; } status = psa_key_derivation_output_bytes( &derivation, dstbuf, dlen ); @@ -434,22 +434,22 @@ static int tls_prf_generic( mbedtls_md_type_t md_type, { psa_key_derivation_abort( &derivation ); psa_destroy_key( master_key ); - return( MBEDTLS_ERR_SSL_HW_ACCEL_FAILED ); + return MBEDTLS_ERR_SSL_HW_ACCEL_FAILED ; } status = psa_key_derivation_abort( &derivation ); if( status != PSA_SUCCESS ) { psa_destroy_key( master_key ); - return( MBEDTLS_ERR_SSL_HW_ACCEL_FAILED ); + return MBEDTLS_ERR_SSL_HW_ACCEL_FAILED ; } if( ! mbedtls_svc_key_id_is_null( master_key ) ) status = psa_destroy_key( master_key ); if( status != PSA_SUCCESS ) - return( MBEDTLS_ERR_SSL_HW_ACCEL_FAILED ); + return MBEDTLS_ERR_SSL_HW_ACCEL_FAILED ; - return( 0 ); + return 0 ; } #else /* MBEDTLS_USE_PSA_CRYPTO */ @@ -472,7 +472,7 @@ static int tls_prf_generic( mbedtls_md_type_t md_type, mbedtls_md_init( &md_ctx ); if( ( md_info = mbedtls_md_info_from_type( md_type ) ) == NULL ) - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; md_len = mbedtls_md_get_size( md_info ); @@ -523,7 +523,7 @@ exit: mbedtls_free( tmp ); - return( ret ); + return ret ; } #endif /* MBEDTLS_USE_PSA_CRYPTO */ #if defined(MBEDTLS_SHA256_C) @@ -574,15 +574,15 @@ static int ssl_use_opaque_psk( mbedtls_ssl_context const *ssl ) /* If we've used a callback to select the PSK, * the static configuration is irrelevant. */ if( ! mbedtls_svc_key_id_is_null( ssl->handshake->psk_opaque ) ) - return( 1 ); + return 1 ; - return( 0 ); + return 0 ; } if( ! mbedtls_svc_key_id_is_null( ssl->conf->psk_opaque ) ) - return( 1 ); + return 1 ; - return( 0 ); + return 0 ; } #endif /* MBEDTLS_USE_PSA_CRYPTO && MBEDTLS_KEY_EXCHANGE_PSK_ENABLED */ @@ -594,19 +594,19 @@ static mbedtls_tls_prf_types tls_prf_get_type( mbedtls_ssl_tls_prf_cb *tls_prf ) #if defined(MBEDTLS_SHA384_C) if( tls_prf == tls_prf_sha384 ) { - return( MBEDTLS_SSL_TLS_PRF_SHA384 ); + return MBEDTLS_SSL_TLS_PRF_SHA384 ; } else #endif #if defined(MBEDTLS_SHA256_C) if( tls_prf == tls_prf_sha256 ) { - return( MBEDTLS_SSL_TLS_PRF_SHA256 ); + return MBEDTLS_SSL_TLS_PRF_SHA256 ; } else #endif #endif /* MBEDTLS_SSL_PROTO_TLS1_2 */ - return( MBEDTLS_SSL_TLS_PRF_NONE ); + return MBEDTLS_SSL_TLS_PRF_NONE ; } #endif /* MBEDTLS_SSL_EXPORT_KEYS */ @@ -633,10 +633,10 @@ int mbedtls_ssl_tls_prf( const mbedtls_tls_prf_types prf, #endif /* MBEDTLS_SHA256_C */ #endif /* MBEDTLS_SSL_PROTO_TLS1_2 */ default: - return( MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE ; } - return( tls_prf( secret, slen, label, random, rlen, dstbuf, dlen ) ); + return tls_prf( secret, slen, label, random, rlen, dstbuf, dlen ) ; } /* Type for the TLS PRF */ @@ -721,7 +721,7 @@ static int ssl_populate_transform( mbedtls_ssl_transform *transform, { MBEDTLS_SSL_DEBUG_MSG( 1, ( "ciphersuite info for %d not found", ciphersuite ) ); - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; } cipher_info = mbedtls_cipher_info_from_type( ciphersuite_info->cipher ); @@ -729,7 +729,7 @@ static int ssl_populate_transform( mbedtls_ssl_transform *transform, { MBEDTLS_SSL_DEBUG_MSG( 1, ( "cipher info for %u not found", ciphersuite_info->cipher ) ); - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; } md_info = mbedtls_md_info_from_type( ciphersuite_info->mac ); @@ -737,7 +737,7 @@ static int ssl_populate_transform( mbedtls_ssl_transform *transform, { MBEDTLS_SSL_DEBUG_MSG( 1, ( "mbedtls_md info for %u not found", (unsigned) ciphersuite_info->mac ) ); - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; } #if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID) @@ -767,7 +767,7 @@ static int ssl_populate_transform( mbedtls_ssl_transform *transform, if( ret != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "prf", ret ); - return( ret ); + return ret ; } MBEDTLS_SSL_DEBUG_MSG( 3, ( "ciphersuite = %s", @@ -887,7 +887,7 @@ static int ssl_populate_transform( mbedtls_ssl_transform *transform, #endif /* MBEDTLS_SSL_SOME_SUITES_USE_MAC */ { MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) ); - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; } MBEDTLS_SSL_DEBUG_MSG( 3, ( "keylen: %u, minlen: %u, ivlen: %u, maclen: %u", @@ -1097,7 +1097,7 @@ static int ssl_populate_transform( mbedtls_ssl_transform *transform, end: mbedtls_platform_zeroize( keyblk, sizeof( keyblk ) ); - return( ret ); + return ret ; } /* @@ -1140,10 +1140,10 @@ static int ssl_set_handshake_prfs( mbedtls_ssl_handshake_params *handshake, #endif #endif /* MBEDTLS_SSL_PROTO_TLS1_2 */ { - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; } - return( 0 ); + return 0 ; } /* @@ -1201,7 +1201,7 @@ static int ssl_compute_master( mbedtls_ssl_handshake_params *handshake, if( handshake->resume != 0 ) { MBEDTLS_SSL_DEBUG_MSG( 3, ( "no premaster (session resumed)" ) ); - return( 0 ); + return 0 ; } #if defined(MBEDTLS_SSL_EXTENDED_MASTER_SECRET) @@ -1247,7 +1247,7 @@ static int ssl_compute_master( mbedtls_ssl_handshake_params *handshake, if( status != PSA_SUCCESS ) { psa_key_derivation_abort( &derivation ); - return( MBEDTLS_ERR_SSL_HW_ACCEL_FAILED ); + return MBEDTLS_ERR_SSL_HW_ACCEL_FAILED ; } status = psa_key_derivation_output_bytes( &derivation, @@ -1256,12 +1256,12 @@ static int ssl_compute_master( mbedtls_ssl_handshake_params *handshake, if( status != PSA_SUCCESS ) { psa_key_derivation_abort( &derivation ); - return( MBEDTLS_ERR_SSL_HW_ACCEL_FAILED ); + return MBEDTLS_ERR_SSL_HW_ACCEL_FAILED ; } status = psa_key_derivation_abort( &derivation ); if( status != PSA_SUCCESS ) - return( MBEDTLS_ERR_SSL_HW_ACCEL_FAILED ); + return MBEDTLS_ERR_SSL_HW_ACCEL_FAILED ; } else #endif @@ -1273,7 +1273,7 @@ static int ssl_compute_master( mbedtls_ssl_handshake_params *handshake, if( ret != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "prf", ret ); - return( ret ); + return ret ; } MBEDTLS_SSL_DEBUG_BUF( 3, "premaster secret", @@ -1284,7 +1284,7 @@ static int ssl_compute_master( mbedtls_ssl_handshake_params *handshake, sizeof(handshake->premaster) ); } - return( 0 ); + return 0 ; } int mbedtls_ssl_derive_keys( mbedtls_ssl_context *ssl ) @@ -1302,7 +1302,7 @@ int mbedtls_ssl_derive_keys( mbedtls_ssl_context *ssl ) if( ret != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "ssl_set_handshake_prfs", ret ); - return( ret ); + return ret ; } /* Compute master secret if needed */ @@ -1312,7 +1312,7 @@ int mbedtls_ssl_derive_keys( mbedtls_ssl_context *ssl ) if( ret != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "ssl_compute_master", ret ); - return( ret ); + return ret ; } /* Swap the client and server random values: @@ -1343,7 +1343,7 @@ int mbedtls_ssl_derive_keys( mbedtls_ssl_context *ssl ) if( ret != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "ssl_populate_transform", ret ); - return( ret ); + return ret ; } /* We no longer need Server/ClientHello.random values */ @@ -1352,7 +1352,7 @@ int mbedtls_ssl_derive_keys( mbedtls_ssl_context *ssl ) MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= derive keys" ) ); - return( 0 ); + return 0 ; } #if defined(MBEDTLS_SSL_PROTO_TLS1_2) @@ -1471,7 +1471,7 @@ int mbedtls_ssl_psk_derive_premaster( mbedtls_ssl_context *ssl, mbedtls_key_exch * checked before calling this function */ MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) ); - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; } /* @@ -1485,13 +1485,13 @@ int mbedtls_ssl_psk_derive_premaster( mbedtls_ssl_context *ssl, mbedtls_key_exch if( key_ex == MBEDTLS_KEY_EXCHANGE_PSK ) { if( end - p < 2 ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; *(p++) = (unsigned char)( psk_len >> 8 ); *(p++) = (unsigned char)( psk_len ); if( end < p || (size_t)( end - p ) < psk_len ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; memset( p, 0, psk_len ); p += psk_len; @@ -1506,7 +1506,7 @@ int mbedtls_ssl_psk_derive_premaster( mbedtls_ssl_context *ssl, mbedtls_key_exch * and is 48 bytes long */ if( end - p < 2 ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; *p++ = 0; *p++ = 48; @@ -1526,7 +1526,7 @@ int mbedtls_ssl_psk_derive_premaster( mbedtls_ssl_context *ssl, mbedtls_key_exch ssl->conf->f_rng, ssl->conf->p_rng ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_dhm_calc_secret", ret ); - return( ret ); + return ret ; } *(p++) = (unsigned char)( len >> 8 ); *(p++) = (unsigned char)( len ); @@ -1547,7 +1547,7 @@ int mbedtls_ssl_psk_derive_premaster( mbedtls_ssl_context *ssl, mbedtls_key_exch ssl->conf->f_rng, ssl->conf->p_rng ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ecdh_calc_secret", ret ); - return( ret ); + return ret ; } *(p++) = (unsigned char)( zlen >> 8 ); @@ -1561,25 +1561,25 @@ int mbedtls_ssl_psk_derive_premaster( mbedtls_ssl_context *ssl, mbedtls_key_exch #endif /* MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED */ { MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) ); - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; } /* opaque psk<0..2^16-1>; */ if( end - p < 2 ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; *(p++) = (unsigned char)( psk_len >> 8 ); *(p++) = (unsigned char)( psk_len ); if( end < p || (size_t)( end - p ) < psk_len ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; memcpy( p, psk, psk_len ); p += psk_len; ssl->handshake->pmslen = p - ssl->handshake->premaster; - return( 0 ); + return 0 ; } #endif /* MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED */ @@ -1605,11 +1605,11 @@ int mbedtls_ssl_resend_hello_request( mbedtls_ssl_context *ssl ) if( ++ssl->renego_records_seen > doublings ) { MBEDTLS_SSL_DEBUG_MSG( 2, ( "no longer retransmitting hello request" ) ); - return( 0 ); + return 0 ; } } - return( ssl_write_hello_request( ssl ) ); + return ssl_write_hello_request( ssl ) ; } #endif #endif /* MBEDTLS_SSL_SRV_C && MBEDTLS_SSL_RENEGOTIATION */ @@ -1653,11 +1653,11 @@ int mbedtls_ssl_write_certificate( mbedtls_ssl_context *ssl ) { MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= skip write certificate" ) ); ssl->state++; - return( 0 ); + return 0 ; } MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) ); - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; } int mbedtls_ssl_parse_certificate( mbedtls_ssl_context *ssl ) @@ -1671,11 +1671,11 @@ int mbedtls_ssl_parse_certificate( mbedtls_ssl_context *ssl ) { MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= skip parse certificate" ) ); ssl->state++; - return( 0 ); + return 0 ; } MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) ); - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; } #else /* MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED */ @@ -1695,7 +1695,7 @@ int mbedtls_ssl_write_certificate( mbedtls_ssl_context *ssl ) { MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= skip write certificate" ) ); ssl->state++; - return( 0 ); + return 0 ; } #if defined(MBEDTLS_SSL_CLI_C) @@ -1705,7 +1705,7 @@ int mbedtls_ssl_write_certificate( mbedtls_ssl_context *ssl ) { MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= skip write certificate" ) ); ssl->state++; - return( 0 ); + return 0 ; } } #endif /* MBEDTLS_SSL_CLI_C */ @@ -1716,7 +1716,7 @@ int mbedtls_ssl_write_certificate( mbedtls_ssl_context *ssl ) { /* Should never happen because we shouldn't have picked the * ciphersuite if we don't have a certificate. */ - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; } } #endif @@ -1743,7 +1743,7 @@ int mbedtls_ssl_write_certificate( mbedtls_ssl_context *ssl ) MBEDTLS_SSL_DEBUG_MSG( 1, ( "certificate too large, %" MBEDTLS_PRINTF_SIZET " > %" MBEDTLS_PRINTF_SIZET, i + 3 + n, (size_t) MBEDTLS_SSL_OUT_CONTENT_LEN ) ); - return( MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL ); + return MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL ; } ssl->out_msg[i ] = (unsigned char)( n >> 16 ); @@ -1767,12 +1767,12 @@ int mbedtls_ssl_write_certificate( mbedtls_ssl_context *ssl ) if( ( ret = mbedtls_ssl_write_handshake_msg( ssl ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_write_handshake_msg", ret ); - return( ret ); + return ret ; } MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= write certificate" ) ); - return( ret ); + return ret ; } #if defined(MBEDTLS_SSL_RENEGOTIATION) && defined(MBEDTLS_SSL_CLI_C) @@ -1785,12 +1785,12 @@ static int ssl_check_peer_crt_unchanged( mbedtls_ssl_context *ssl, mbedtls_x509_crt const * const peer_crt = ssl->session->peer_cert; if( peer_crt == NULL ) - return( -1 ); + return -1 ; if( peer_crt->raw.len != crt_buf_len ) - return( -1 ); + return -1 ; - return( memcmp( peer_crt->raw.p, crt_buf, peer_crt->raw.len ) ); + return memcmp( peer_crt->raw.p, crt_buf, peer_crt->raw.len ) ; } #else /* MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */ static int ssl_check_peer_crt_unchanged( mbedtls_ssl_context *ssl, @@ -1808,17 +1808,17 @@ static int ssl_check_peer_crt_unchanged( mbedtls_ssl_context *ssl, size_t digest_len; if( peer_cert_digest == NULL || digest_info == NULL ) - return( -1 ); + return -1 ; digest_len = mbedtls_md_get_size( digest_info ); if( digest_len > MBEDTLS_SSL_PEER_CERT_DIGEST_MAX_LEN ) - return( -1 ); + return -1 ; ret = mbedtls_md( digest_info, crt_buf, crt_buf_len, tmp_digest ); if( ret != 0 ) - return( -1 ); + return -1 ; - return( memcmp( tmp_digest, peer_cert_digest, digest_len ) ); + return memcmp( tmp_digest, peer_cert_digest, digest_len ) ; } #endif /* MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */ #endif /* MBEDTLS_SSL_RENEGOTIATION && MBEDTLS_SSL_CLI_C */ @@ -1842,14 +1842,14 @@ static int ssl_parse_certificate_chain( mbedtls_ssl_context *ssl, MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad certificate message" ) ); mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_UNEXPECTED_MESSAGE ); - return( MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE ); + return MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE ; } if( ssl->in_msg[0] != MBEDTLS_SSL_HS_CERTIFICATE ) { mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_UNEXPECTED_MESSAGE ); - return( MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE ); + return MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE ; } if( ssl->in_hslen < mbedtls_ssl_hs_hdr_len( ssl ) + 3 + 3 ) @@ -1857,7 +1857,7 @@ static int ssl_parse_certificate_chain( mbedtls_ssl_context *ssl, MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad certificate message" ) ); mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } i = mbedtls_ssl_hs_hdr_len( ssl ); @@ -1873,7 +1873,7 @@ static int ssl_parse_certificate_chain( mbedtls_ssl_context *ssl, MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad certificate message" ) ); mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } /* Make &ssl->in_msg[i] point to the beginning of the CRT chain. */ @@ -1888,7 +1888,7 @@ static int ssl_parse_certificate_chain( mbedtls_ssl_context *ssl, mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } /* In theory, the CRT can be up to 2**24 Bytes, but we don't support * anything beyond 2**16 ~ 64K. */ @@ -1898,7 +1898,7 @@ static int ssl_parse_certificate_chain( mbedtls_ssl_context *ssl, mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_UNSUPPORTED_CERT ); - return( MBEDTLS_ERR_SSL_BAD_CERTIFICATE ); + return MBEDTLS_ERR_SSL_BAD_CERTIFICATE ; } /* Read length of the next CRT in the chain. */ @@ -1912,7 +1912,7 @@ static int ssl_parse_certificate_chain( mbedtls_ssl_context *ssl, mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } /* Check if we're handling the first CRT in the chain. */ @@ -1934,7 +1934,7 @@ static int ssl_parse_certificate_chain( mbedtls_ssl_context *ssl, mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_ACCESS_DENIED ); - return( MBEDTLS_ERR_SSL_BAD_CERTIFICATE ); + return MBEDTLS_ERR_SSL_BAD_CERTIFICATE ; } /* Now we can safely free the original chain. */ @@ -1971,21 +1971,21 @@ static int ssl_parse_certificate_chain( mbedtls_ssl_context *ssl, crt_parse_der_failed: mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, alert ); MBEDTLS_SSL_DEBUG_RET( 1, " mbedtls_x509_crt_parse_der", ret ); - return( ret ); + return ret ; } i += n; } MBEDTLS_SSL_DEBUG_CRT( 3, "peer certificate", chain ); - return( 0 ); + return 0 ; } #if defined(MBEDTLS_SSL_SRV_C) static int ssl_srv_check_client_no_crt_notification( mbedtls_ssl_context *ssl ) { if( ssl->conf->endpoint == MBEDTLS_SSL_IS_CLIENT ) - return( -1 ); + return -1 ; #if defined(MBEDTLS_SSL_PROTO_TLS1_2) if( ssl->in_hslen == 3 + mbedtls_ssl_hs_hdr_len( ssl ) && @@ -1994,10 +1994,10 @@ static int ssl_srv_check_client_no_crt_notification( mbedtls_ssl_context *ssl ) memcmp( ssl->in_msg + mbedtls_ssl_hs_hdr_len( ssl ), "\0\0\0", 3 ) == 0 ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "TLSv1 client has no certificate" ) ); - return( 0 ); + return 0 ; } - return( -1 ); + return -1 ; #endif /* MBEDTLS_SSL_PROTO_TLS1_2 */ } #endif /* MBEDTLS_SSL_SRV_C */ @@ -2017,26 +2017,26 @@ static int ssl_parse_certificate_coordinate( mbedtls_ssl_context *ssl, ssl->handshake->ciphersuite_info; if( !mbedtls_ssl_ciphersuite_uses_srv_cert( ciphersuite_info ) ) - return( SSL_CERTIFICATE_SKIP ); + return SSL_CERTIFICATE_SKIP ; #if defined(MBEDTLS_SSL_SRV_C) if( ssl->conf->endpoint == MBEDTLS_SSL_IS_SERVER ) { if( ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_RSA_PSK ) - return( SSL_CERTIFICATE_SKIP ); + return SSL_CERTIFICATE_SKIP ; if( authmode == MBEDTLS_SSL_VERIFY_NONE ) { ssl->session_negotiate->verify_result = MBEDTLS_X509_BADCERT_SKIP_VERIFY; - return( SSL_CERTIFICATE_SKIP ); + return SSL_CERTIFICATE_SKIP ; } } #else ((void) authmode); #endif /* MBEDTLS_SSL_SRV_C */ - return( SSL_CERTIFICATE_EXPECTED ); + return SSL_CERTIFICATE_EXPECTED ; } static int ssl_parse_certificate_verify( mbedtls_ssl_context *ssl, @@ -2053,7 +2053,7 @@ static int ssl_parse_certificate_verify( mbedtls_ssl_context *ssl, void *p_vrfy; if( authmode == MBEDTLS_SSL_VERIFY_NONE ) - return( 0 ); + return 0 ; if( ssl->f_vrfy != NULL ) { @@ -2125,7 +2125,7 @@ static int ssl_parse_certificate_verify( mbedtls_ssl_context *ssl, #if defined(MBEDTLS_SSL_ECP_RESTARTABLE_ENABLED) if( ret == MBEDTLS_ERR_ECP_IN_PROGRESS ) - return( MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS ); + return MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS ; #endif /* @@ -2223,7 +2223,7 @@ static int ssl_parse_certificate_verify( mbedtls_ssl_context *ssl, } #endif /* MBEDTLS_DEBUG_C */ - return( ret ); + return ret ; } #if !defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE) @@ -2242,7 +2242,7 @@ static int ssl_remember_peer_crt_digest( mbedtls_ssl_context *ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_INTERNAL_ERROR ); - return( MBEDTLS_ERR_SSL_ALLOC_FAILED ); + return MBEDTLS_ERR_SSL_ALLOC_FAILED ; } ret = mbedtls_md( mbedtls_md_info_from_type( @@ -2255,7 +2255,7 @@ static int ssl_remember_peer_crt_digest( mbedtls_ssl_context *ssl, ssl->session_negotiate->peer_cert_digest_len = MBEDTLS_SSL_PEER_CERT_DIGEST_DFL_LEN; - return( ret ); + return ret ; } static int ssl_remember_peer_pubkey( mbedtls_ssl_context *ssl, @@ -2271,10 +2271,10 @@ static int ssl_remember_peer_pubkey( mbedtls_ssl_context *ssl, if( ret != 0 ) { /* We should have parsed the public key before. */ - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; } - return( 0 ); + return 0 ; } #endif /* !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */ @@ -2424,7 +2424,7 @@ exit: mbedtls_free( chain ); } - return( ret ); + return ret ; } #endif /* MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED */ @@ -2836,7 +2836,7 @@ int mbedtls_ssl_write_finished( mbedtls_ssl_context *ssl ) if( i == 0 ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "DTLS epoch would wrap" ) ); - return( MBEDTLS_ERR_SSL_COUNTER_WRAPPING ); + return MBEDTLS_ERR_SSL_COUNTER_WRAPPING ; } } else @@ -2854,7 +2854,7 @@ int mbedtls_ssl_write_finished( mbedtls_ssl_context *ssl ) if( ( ret = mbedtls_ssl_write_handshake_msg( ssl ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_write_handshake_msg", ret ); - return( ret ); + return ret ; } #if defined(MBEDTLS_SSL_PROTO_DTLS) @@ -2862,13 +2862,13 @@ int mbedtls_ssl_write_finished( mbedtls_ssl_context *ssl ) ( ret = mbedtls_ssl_flight_transmit( ssl ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_flight_transmit", ret ); - return( ret ); + return ret ; } #endif MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= write finished" ) ); - return( 0 ); + return 0 ; } #define SSL_MAX_HASH_LEN 12 @@ -2886,7 +2886,7 @@ int mbedtls_ssl_parse_finished( mbedtls_ssl_context *ssl ) if( ( ret = mbedtls_ssl_read_record( ssl, 1 ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_read_record", ret ); - return( ret ); + return ret ; } if( ssl->in_msgtype != MBEDTLS_SSL_MSG_HANDSHAKE ) @@ -2894,7 +2894,7 @@ int mbedtls_ssl_parse_finished( mbedtls_ssl_context *ssl ) MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad finished message" ) ); mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_UNEXPECTED_MESSAGE ); - return( MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE ); + return MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE ; } hash_len = 12; @@ -2903,7 +2903,7 @@ int mbedtls_ssl_parse_finished( mbedtls_ssl_context *ssl ) { mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_UNEXPECTED_MESSAGE ); - return( MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE ); + return MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE ; } if( ssl->in_hslen != mbedtls_ssl_hs_hdr_len( ssl ) + hash_len ) @@ -2911,7 +2911,7 @@ int mbedtls_ssl_parse_finished( mbedtls_ssl_context *ssl ) MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad finished message" ) ); mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR ); - return( MBEDTLS_ERR_SSL_DECODE_ERROR ); + return MBEDTLS_ERR_SSL_DECODE_ERROR ; } if( mbedtls_ssl_safer_memcmp( ssl->in_msg + mbedtls_ssl_hs_hdr_len( ssl ), @@ -2920,7 +2920,7 @@ int mbedtls_ssl_parse_finished( mbedtls_ssl_context *ssl ) MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad finished message" ) ); mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_DECRYPT_ERROR ); - return( MBEDTLS_ERR_SSL_HANDSHAKE_FAILURE ); + return MBEDTLS_ERR_SSL_HANDSHAKE_FAILURE ; } #if defined(MBEDTLS_SSL_RENEGOTIATION) @@ -2949,7 +2949,7 @@ int mbedtls_ssl_parse_finished( mbedtls_ssl_context *ssl ) MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= parse finished" ) ); - return( 0 ); + return 0 ; } static void ssl_handshake_params_init( mbedtls_ssl_handshake_params *handshake ) @@ -3080,7 +3080,7 @@ static int ssl_handshake_init( mbedtls_ssl_context *ssl ) ssl->transform_negotiate = NULL; ssl->session_negotiate = NULL; - return( MBEDTLS_ERR_SSL_ALLOC_FAILED ); + return MBEDTLS_ERR_SSL_ALLOC_FAILED ; } /* Initialize structures */ @@ -3102,7 +3102,7 @@ static int ssl_handshake_init( mbedtls_ssl_context *ssl ) } #endif - return( 0 ); + return 0 ; } #if defined(MBEDTLS_SSL_DTLS_HELLO_VERIFY) && defined(MBEDTLS_SSL_SRV_C) @@ -3117,7 +3117,7 @@ static int ssl_cookie_write_dummy( void *ctx, ((void) cli_id); ((void) cli_id_len); - return( MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE ; } static int ssl_cookie_check_dummy( void *ctx, @@ -3130,7 +3130,7 @@ static int ssl_cookie_check_dummy( void *ctx, ((void) cli_id); ((void) cli_id_len); - return( MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE ; } #endif /* MBEDTLS_SSL_DTLS_HELLO_VERIFY && MBEDTLS_SSL_SRV_C */ @@ -3193,7 +3193,7 @@ int mbedtls_ssl_setup( mbedtls_ssl_context *ssl, if( ( ret = ssl_handshake_init( ssl ) ) != 0 ) goto error; - return( 0 ); + return 0 ; error: mbedtls_free( ssl->in_buf ); @@ -3220,7 +3220,7 @@ error: ssl->out_iv = NULL; ssl->out_msg = NULL; - return( ret ); + return ret ; } /* @@ -3331,9 +3331,9 @@ int mbedtls_ssl_session_reset_int( mbedtls_ssl_context *ssl, int partial ) #endif if( ( ret = ssl_handshake_init( ssl ) ) != 0 ) - return( ret ); + return ret ; - return( 0 ); + return 0 ; } /* @@ -3342,7 +3342,7 @@ int mbedtls_ssl_session_reset_int( mbedtls_ssl_context *ssl, int partial ) */ int mbedtls_ssl_session_reset( mbedtls_ssl_context *ssl ) { - return( mbedtls_ssl_session_reset_int( ssl, 0 ) ); + return mbedtls_ssl_session_reset_int( ssl, 0 ) ; } /* @@ -3476,19 +3476,19 @@ int mbedtls_ssl_set_session( mbedtls_ssl_context *ssl, const mbedtls_ssl_session ssl->session_negotiate == NULL || ssl->conf->endpoint != MBEDTLS_SSL_IS_CLIENT ) { - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; } if( ssl->handshake->resume == 1 ) - return( MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE ; if( ( ret = mbedtls_ssl_session_copy( ssl->session_negotiate, session ) ) != 0 ) - return( ret ); + return ret ; ssl->handshake->resume = 1; - return( 0 ); + return 0 ; } #endif /* MBEDTLS_SSL_CLI_C */ @@ -3514,7 +3514,7 @@ static int ssl_append_key_cert( mbedtls_ssl_key_cert **head, new_cert = mbedtls_calloc( 1, sizeof( mbedtls_ssl_key_cert ) ); if( new_cert == NULL ) - return( MBEDTLS_ERR_SSL_ALLOC_FAILED ); + return MBEDTLS_ERR_SSL_ALLOC_FAILED ; new_cert->cert = cert; new_cert->key = key; @@ -3533,14 +3533,14 @@ static int ssl_append_key_cert( mbedtls_ssl_key_cert **head, cur->next = new_cert; } - return( 0 ); + return 0 ; } int mbedtls_ssl_conf_own_cert( mbedtls_ssl_config *conf, mbedtls_x509_crt *own_cert, mbedtls_pk_context *pk_key ) { - return( ssl_append_key_cert( &conf->key_cert, own_cert, pk_key ) ); + return ssl_append_key_cert( &conf->key_cert, own_cert, pk_key ) ; } void mbedtls_ssl_conf_ca_chain( mbedtls_ssl_config *conf, @@ -3619,7 +3619,7 @@ int mbedtls_ssl_set_hs_ecjpake_password( mbedtls_ssl_context *ssl, mbedtls_ecjpake_role role; if( ssl->handshake == NULL || ssl->conf == NULL ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; if( ssl->conf->endpoint == MBEDTLS_SSL_IS_SERVER ) role = MBEDTLS_ECJPAKE_SERVER; @@ -3640,13 +3640,13 @@ static int ssl_conf_psk_is_configured( mbedtls_ssl_config const *conf ) { #if defined(MBEDTLS_USE_PSA_CRYPTO) if( !mbedtls_svc_key_id_is_null( conf->psk_opaque ) ) - return( 1 ); + return 1 ; #endif /* MBEDTLS_USE_PSA_CRYPTO */ if( conf->psk != NULL ) - return( 1 ); + return 1 ; - return( 0 ); + return 0 ; } static void ssl_conf_remove_psk( mbedtls_ssl_config *conf ) @@ -3696,17 +3696,17 @@ static int ssl_conf_set_psk_identity( mbedtls_ssl_config *conf, ( psk_identity_len >> 16 ) != 0 || psk_identity_len > MBEDTLS_SSL_OUT_CONTENT_LEN ) { - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; } conf->psk_identity = mbedtls_calloc( 1, psk_identity_len ); if( conf->psk_identity == NULL ) - return( MBEDTLS_ERR_SSL_ALLOC_FAILED ); + return MBEDTLS_ERR_SSL_ALLOC_FAILED ; conf->psk_identity_len = psk_identity_len; memcpy( conf->psk_identity, psk_identity, conf->psk_identity_len ); - return( 0 ); + return 0 ; } int mbedtls_ssl_conf_psk( mbedtls_ssl_config *conf, @@ -3717,18 +3717,18 @@ int mbedtls_ssl_conf_psk( mbedtls_ssl_config *conf, /* We currently only support one PSK, raw or opaque. */ if( ssl_conf_psk_is_configured( conf ) ) - return( MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE ; /* Check and set raw PSK */ if( psk == NULL ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; if( psk_len == 0 ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; if( psk_len > MBEDTLS_PSK_MAX_LEN ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; if( ( conf->psk = mbedtls_calloc( 1, psk_len ) ) == NULL ) - return( MBEDTLS_ERR_SSL_ALLOC_FAILED ); + return MBEDTLS_ERR_SSL_ALLOC_FAILED ; conf->psk_len = psk_len; memcpy( conf->psk, psk, conf->psk_len ); @@ -3737,7 +3737,7 @@ int mbedtls_ssl_conf_psk( mbedtls_ssl_config *conf, if( ret != 0 ) ssl_conf_remove_psk( conf ); - return( ret ); + return ret ; } static void ssl_remove_psk( mbedtls_ssl_context *ssl ) @@ -3762,20 +3762,20 @@ int mbedtls_ssl_set_hs_psk( mbedtls_ssl_context *ssl, const unsigned char *psk, size_t psk_len ) { if( psk == NULL || ssl->handshake == NULL ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; if( psk_len > MBEDTLS_PSK_MAX_LEN ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; ssl_remove_psk( ssl ); if( ( ssl->handshake->psk = mbedtls_calloc( 1, psk_len ) ) == NULL ) - return( MBEDTLS_ERR_SSL_ALLOC_FAILED ); + return MBEDTLS_ERR_SSL_ALLOC_FAILED ; ssl->handshake->psk_len = psk_len; memcpy( ssl->handshake->psk, psk, ssl->handshake->psk_len ); - return( 0 ); + return 0 ; } #if defined(MBEDTLS_USE_PSA_CRYPTO) @@ -3788,11 +3788,11 @@ int mbedtls_ssl_conf_psk_opaque( mbedtls_ssl_config *conf, /* We currently only support one PSK, raw or opaque. */ if( ssl_conf_psk_is_configured( conf ) ) - return( MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE ; /* Check and set opaque PSK */ if( mbedtls_svc_key_id_is_null( psk ) ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; conf->psk_opaque = psk; /* Check and set PSK Identity */ @@ -3801,7 +3801,7 @@ int mbedtls_ssl_conf_psk_opaque( mbedtls_ssl_config *conf, if( ret != 0 ) ssl_conf_remove_psk( conf ); - return( ret ); + return ret ; } int mbedtls_ssl_set_hs_psk_opaque( mbedtls_ssl_context *ssl, @@ -3809,11 +3809,11 @@ int mbedtls_ssl_set_hs_psk_opaque( mbedtls_ssl_context *ssl, { if( ( mbedtls_svc_key_id_is_null( psk ) ) || ( ssl->handshake == NULL ) ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; ssl_remove_psk( ssl ); ssl->handshake->psk_opaque = psk; - return( 0 ); + return 0 ; } #endif /* MBEDTLS_USE_PSA_CRYPTO */ @@ -3839,10 +3839,10 @@ int mbedtls_ssl_conf_dh_param_bin( mbedtls_ssl_config *conf, { mbedtls_mpi_free( &conf->dhm_P ); mbedtls_mpi_free( &conf->dhm_G ); - return( ret ); + return ret ; } - return( 0 ); + return 0 ; } int mbedtls_ssl_conf_dh_param_ctx( mbedtls_ssl_config *conf, mbedtls_dhm_context *dhm_ctx ) @@ -3856,10 +3856,10 @@ int mbedtls_ssl_conf_dh_param_ctx( mbedtls_ssl_config *conf, mbedtls_dhm_context { mbedtls_mpi_free( &conf->dhm_P ); mbedtls_mpi_free( &conf->dhm_G ); - return( ret ); + return ret ; } - return( 0 ); + return 0 ; } #endif /* MBEDTLS_DHM_C && MBEDTLS_SSL_SRV_C */ @@ -3909,7 +3909,7 @@ int mbedtls_ssl_set_hostname( mbedtls_ssl_context *ssl, const char *hostname ) hostname_len = strlen( hostname ); if( hostname_len > MBEDTLS_SSL_MAX_HOST_NAME_LEN ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; } /* Now it's clear that we will overwrite the old hostname, @@ -3931,14 +3931,14 @@ int mbedtls_ssl_set_hostname( mbedtls_ssl_context *ssl, const char *hostname ) { ssl->hostname = mbedtls_calloc( 1, hostname_len + 1 ); if( ssl->hostname == NULL ) - return( MBEDTLS_ERR_SSL_ALLOC_FAILED ); + return MBEDTLS_ERR_SSL_ALLOC_FAILED ; memcpy( ssl->hostname, hostname, hostname_len ); ssl->hostname[hostname_len] = '\0'; } - return( 0 ); + return 0 ; } #endif /* MBEDTLS_X509_CRT_PARSE_C */ @@ -3973,17 +3973,17 @@ int mbedtls_ssl_conf_alpn_protocols( mbedtls_ssl_config *conf, const char **prot if( ( cur_len == 0 ) || ( cur_len > MBEDTLS_SSL_MAX_ALPN_NAME_LEN ) || ( tot_len > MBEDTLS_SSL_MAX_ALPN_LIST_LEN ) ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; } conf->alpn_list = protos; - return( 0 ); + return 0 ; } const char *mbedtls_ssl_get_alpn_protocol( const mbedtls_ssl_context *ssl ) { - return( ssl->alpn_chosen ); + return ssl->alpn_chosen ; } #endif /* MBEDTLS_SSL_ALPN */ @@ -4000,17 +4000,17 @@ int mbedtls_ssl_dtls_srtp_set_mki_value( mbedtls_ssl_context *ssl, { if( mki_len > MBEDTLS_TLS_SRTP_MAX_MKI_LENGTH ) { - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; } if( ssl->conf->dtls_srtp_mki_support == MBEDTLS_SSL_DTLS_SRTP_MKI_UNSUPPORTED ) { - return( MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE ; } memcpy( ssl->dtls_srtp_info.mki_value, mki_value, mki_len ); ssl->dtls_srtp_info.mki_len = mki_len; - return( 0 ); + return 0 ; } int mbedtls_ssl_conf_dtls_srtp_protection_profiles( mbedtls_ssl_config *conf, @@ -4040,13 +4040,13 @@ int mbedtls_ssl_conf_dtls_srtp_protection_profiles( mbedtls_ssl_config *conf, { conf->dtls_srtp_profile_list = NULL; conf->dtls_srtp_profile_list_len = 0; - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; } conf->dtls_srtp_profile_list = profiles; conf->dtls_srtp_profile_list_len = list_size; - return( 0 ); + return 0 ; } void mbedtls_ssl_get_dtls_srtp_negotiation_result( const mbedtls_ssl_context *ssl, @@ -4107,12 +4107,12 @@ int mbedtls_ssl_conf_max_frag_len( mbedtls_ssl_config *conf, unsigned char mfl_c if( mfl_code >= MBEDTLS_SSL_MAX_FRAG_LEN_INVALID || ssl_mfl_code_to_length( mfl_code ) > MBEDTLS_TLS_EXT_ADV_CONTENT_LEN ) { - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; } conf->mfl_code = mfl_code; - return( 0 ); + return 0 ; } #endif /* MBEDTLS_SSL_MAX_FRAGMENT_LENGTH */ @@ -4188,15 +4188,15 @@ void mbedtls_ssl_conf_async_private_cb( void *mbedtls_ssl_conf_get_async_config_data( const mbedtls_ssl_config *conf ) { - return( conf->p_async_config_data ); + return conf->p_async_config_data ; } void *mbedtls_ssl_get_async_operation_data( const mbedtls_ssl_context *ssl ) { if( ssl->handshake == NULL ) - return( NULL ); + return NULL ; else - return( ssl->handshake->user_async_ctx ); + return ssl->handshake->user_async_ctx ; } void mbedtls_ssl_set_async_operation_data( mbedtls_ssl_context *ssl, @@ -4213,18 +4213,18 @@ void mbedtls_ssl_set_async_operation_data( mbedtls_ssl_context *ssl, uint32_t mbedtls_ssl_get_verify_result( const mbedtls_ssl_context *ssl ) { if( ssl->session != NULL ) - return( ssl->session->verify_result ); + return ssl->session->verify_result ; if( ssl->session_negotiate != NULL ) - return( ssl->session_negotiate->verify_result ); + return ssl->session_negotiate->verify_result ; - return( 0xFFFFFFFF ); + return 0xFFFFFFFF ; } const char *mbedtls_ssl_get_ciphersuite( const mbedtls_ssl_context *ssl ) { if( ssl == NULL || ssl->session == NULL ) - return( NULL ); + return NULL ; return mbedtls_ssl_get_ciphersuite_name( ssl->session->ciphersuite ); } @@ -4237,10 +4237,10 @@ const char *mbedtls_ssl_get_version( const mbedtls_ssl_context *ssl ) switch( ssl->minor_ver ) { case MBEDTLS_SSL_MINOR_VERSION_3: - return( "DTLSv1.2" ); + return "DTLSv1.2" ; default: - return( "unknown (DTLS)" ); + return "unknown (DTLS)" ; } } #endif @@ -4248,10 +4248,10 @@ const char *mbedtls_ssl_get_version( const mbedtls_ssl_context *ssl ) switch( ssl->minor_ver ) { case MBEDTLS_SSL_MINOR_VERSION_3: - return( "TLSv1.2" ); + return "TLSv1.2" ; default: - return( "unknown" ); + return "unknown" ; } } @@ -4288,7 +4288,7 @@ size_t mbedtls_ssl_get_input_max_frag_len( const mbedtls_ssl_context *ssl ) } } - return( max_len ); + return max_len ; } size_t mbedtls_ssl_get_output_max_frag_len( const mbedtls_ssl_context *ssl ) @@ -4314,7 +4314,7 @@ size_t mbedtls_ssl_get_output_max_frag_len( const mbedtls_ssl_context *ssl ) max_len = ssl_mfl_code_to_length( ssl->session_negotiate->mfl_code ); } - return( max_len ); + return max_len ; } #endif /* MBEDTLS_SSL_MAX_FRAGMENT_LENGTH */ @@ -4325,13 +4325,13 @@ size_t mbedtls_ssl_get_current_mtu( const mbedtls_ssl_context *ssl ) if( ssl->conf->endpoint == MBEDTLS_SSL_IS_CLIENT && ( ssl->state == MBEDTLS_SSL_CLIENT_HELLO || ssl->state == MBEDTLS_SSL_SERVER_HELLO ) ) - return ( 0 ); + return 0 ; if( ssl->handshake == NULL || ssl->handshake->mtu == 0 ) - return( ssl->mtu ); + return ssl->mtu ; if( ssl->mtu == 0 ) - return( ssl->handshake->mtu ); + return ssl->handshake->mtu ; return( ssl->mtu < ssl->handshake->mtu ? ssl->mtu : ssl->handshake->mtu ); @@ -4362,12 +4362,12 @@ int mbedtls_ssl_get_max_out_record_payload( const mbedtls_ssl_context *ssl ) const size_t overhead = (size_t) ret; if( ret < 0 ) - return( ret ); + return ret ; if( mtu <= overhead ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "MTU too low for record expansion" ) ); - return( MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE ; } if( max_len > mtu - overhead ) @@ -4380,7 +4380,7 @@ int mbedtls_ssl_get_max_out_record_payload( const mbedtls_ssl_context *ssl ) ((void) ssl); #endif - return( (int) max_len ); + return (int) max_len ; } int mbedtls_ssl_get_max_in_record_payload( const mbedtls_ssl_context *ssl ) @@ -4398,19 +4398,19 @@ int mbedtls_ssl_get_max_in_record_payload( const mbedtls_ssl_context *ssl ) max_len = mfl; #endif - return( (int) max_len ); + return (int) max_len ; } #if defined(MBEDTLS_X509_CRT_PARSE_C) const mbedtls_x509_crt *mbedtls_ssl_get_peer_cert( const mbedtls_ssl_context *ssl ) { if( ssl == NULL || ssl->session == NULL ) - return( NULL ); + return NULL ; #if defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE) - return( ssl->session->peer_cert ); + return ssl->session->peer_cert ; #else - return( NULL ); + return NULL ; #endif /* MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */ } #endif /* MBEDTLS_X509_CRT_PARSE_C */ @@ -4426,7 +4426,7 @@ int mbedtls_ssl_get_session( const mbedtls_ssl_context *ssl, ssl->session == NULL || ssl->conf->endpoint != MBEDTLS_SSL_IS_CLIENT ) { - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; } /* Since Mbed TLS 3.0, mbedtls_ssl_get_session() is no longer @@ -4441,15 +4441,15 @@ int mbedtls_ssl_get_session( const mbedtls_ssl_context *ssl, * and fail if so. */ if( ssl->session->exported == 1 ) - return( MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE ; ret = mbedtls_ssl_session_copy( dst, ssl->session ); if( ret != 0 ) - return( ret ); + return ret ; /* Remember that we've exported the session. */ ssl->session->exported = 1; - return( 0 ); + return 0 ; } #endif /* MBEDTLS_SSL_CLI_C */ @@ -4733,7 +4733,7 @@ static size_t ssl_session_save_tls12( const mbedtls_ssl_session *session, *p++ = (unsigned char)( ( session->encrypt_then_mac ) & 0xFF ); #endif - return( used ); + return used ; } #endif /* MBEDTLS_SSL_PROTO_TLS1_2 */ @@ -4784,14 +4784,14 @@ static int ssl_session_save( const mbedtls_ssl_session *session, #endif /* MBEDTLS_SSL_PROTO_TLS1_2 */ default: - return( MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE ; } *olen = used; if( used > buf_len ) - return( MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL ); + return MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL ; - return( 0 ); + return 0 ; } /* @@ -4802,7 +4802,7 @@ int mbedtls_ssl_session_save( const mbedtls_ssl_session *session, size_t buf_len, size_t *olen ) { - return( ssl_session_save( session, 0, buf, buf_len, olen ) ); + return ssl_session_save( session, 0, buf, buf_len, olen ) ; } /* @@ -4832,7 +4832,7 @@ static int ssl_session_load_tls12( mbedtls_ssl_session *session, */ #if defined(MBEDTLS_HAVE_TIME) if( 8 > (size_t)( end - p ) ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; start = ( (uint64_t) p[0] << 56 ) | ( (uint64_t) p[1] << 48 ) | @@ -4851,7 +4851,7 @@ static int ssl_session_load_tls12( mbedtls_ssl_session *session, * Basic mandatory fields */ if( 2 + 1 + 1 + 32 + 48 + 4 > (size_t)( end - p ) ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; session->ciphersuite = ( p[0] << 8 ) | p[1]; p += 2; @@ -4891,7 +4891,7 @@ static int ssl_session_load_tls12( mbedtls_ssl_session *session, #if defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE) /* Deserialize CRT from the end of the ticket. */ if( 3 > (size_t)( end - p ) ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; cert_len = ( p[0] << 16 ) | ( p[1] << 8 ) | p[2]; p += 3; @@ -4901,12 +4901,12 @@ static int ssl_session_load_tls12( mbedtls_ssl_session *session, int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; if( cert_len > (size_t)( end - p ) ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; session->peer_cert = mbedtls_calloc( 1, sizeof( mbedtls_x509_crt ) ); if( session->peer_cert == NULL ) - return( MBEDTLS_ERR_SSL_ALLOC_FAILED ); + return MBEDTLS_ERR_SSL_ALLOC_FAILED ; mbedtls_x509_crt_init( session->peer_cert ); @@ -4916,7 +4916,7 @@ static int ssl_session_load_tls12( mbedtls_ssl_session *session, mbedtls_x509_crt_free( session->peer_cert ); mbedtls_free( session->peer_cert ); session->peer_cert = NULL; - return( ret ); + return ret ; } p += cert_len; @@ -4924,7 +4924,7 @@ static int ssl_session_load_tls12( mbedtls_ssl_session *session, #else /* MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */ /* Deserialize CRT digest from the end of the ticket. */ if( 2 > (size_t)( end - p ) ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; session->peer_cert_digest_type = (mbedtls_md_type_t) *p++; session->peer_cert_digest_len = (size_t) *p++; @@ -4934,17 +4934,17 @@ static int ssl_session_load_tls12( mbedtls_ssl_session *session, const mbedtls_md_info_t *md_info = mbedtls_md_info_from_type( session->peer_cert_digest_type ); if( md_info == NULL ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; if( session->peer_cert_digest_len != mbedtls_md_get_size( md_info ) ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; if( session->peer_cert_digest_len > (size_t)( end - p ) ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; session->peer_cert_digest = mbedtls_calloc( 1, session->peer_cert_digest_len ); if( session->peer_cert_digest == NULL ) - return( MBEDTLS_ERR_SSL_ALLOC_FAILED ); + return MBEDTLS_ERR_SSL_ALLOC_FAILED ; memcpy( session->peer_cert_digest, p, session->peer_cert_digest_len ); @@ -4958,7 +4958,7 @@ static int ssl_session_load_tls12( mbedtls_ssl_session *session, */ #if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_CLI_C) if( 3 > (size_t)( end - p ) ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; session->ticket_len = ( p[0] << 16 ) | ( p[1] << 8 ) | p[2]; p += 3; @@ -4966,18 +4966,18 @@ static int ssl_session_load_tls12( mbedtls_ssl_session *session, if( session->ticket_len != 0 ) { if( session->ticket_len > (size_t)( end - p ) ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; session->ticket = mbedtls_calloc( 1, session->ticket_len ); if( session->ticket == NULL ) - return( MBEDTLS_ERR_SSL_ALLOC_FAILED ); + return MBEDTLS_ERR_SSL_ALLOC_FAILED ; memcpy( session->ticket, p, session->ticket_len ); p += session->ticket_len; } if( 4 > (size_t)( end - p ) ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; session->ticket_lifetime = ( (uint32_t) p[0] << 24 ) | ( (uint32_t) p[1] << 16 ) | @@ -4991,23 +4991,23 @@ static int ssl_session_load_tls12( mbedtls_ssl_session *session, */ #if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH) if( 1 > (size_t)( end - p ) ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; session->mfl_code = *p++; #endif #if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC) if( 1 > (size_t)( end - p ) ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; session->encrypt_then_mac = *p++; #endif /* Done, should have consumed entire buffer */ if( p != end ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; - return( 0 ); + return 0 ; } static int ssl_session_load( mbedtls_ssl_session *session, @@ -5025,12 +5025,12 @@ static int ssl_session_load( mbedtls_ssl_session *session, */ if( (size_t)( end - p ) < sizeof( ssl_serialized_session_header ) ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; if( memcmp( p, ssl_serialized_session_header, sizeof( ssl_serialized_session_header ) ) != 0 ) { - return( MBEDTLS_ERR_SSL_VERSION_MISMATCH ); + return MBEDTLS_ERR_SSL_VERSION_MISMATCH ; } p += sizeof( ssl_serialized_session_header ); } @@ -5039,7 +5039,7 @@ static int ssl_session_load( mbedtls_ssl_session *session, * TLS version identifier */ if( 1 > (size_t)( end - p ) ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; session->minor_ver = *p++; /* Dispatch according to TLS version. */ @@ -5049,12 +5049,12 @@ static int ssl_session_load( mbedtls_ssl_session *session, case MBEDTLS_SSL_MINOR_VERSION_3: /* TLS 1.2 */ { size_t remaining_len = ( end - p ); - return( ssl_session_load_tls12( session, p, remaining_len ) ); + return ssl_session_load_tls12( session, p, remaining_len ) ; } #endif /* MBEDTLS_SSL_PROTO_TLS1_2 */ default: - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; } } @@ -5070,7 +5070,7 @@ int mbedtls_ssl_session_load( mbedtls_ssl_session *session, if( ret != 0 ) mbedtls_ssl_session_free( session ); - return( ret ); + return ret ; } /* @@ -5081,7 +5081,7 @@ int mbedtls_ssl_handshake_step( mbedtls_ssl_context *ssl ) int ret = MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE; if( ssl == NULL || ssl->conf == NULL ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; #if defined(MBEDTLS_SSL_CLI_C) if( ssl->conf->endpoint == MBEDTLS_SSL_IS_CLIENT ) @@ -5092,7 +5092,7 @@ int mbedtls_ssl_handshake_step( mbedtls_ssl_context *ssl ) ret = mbedtls_ssl_handshake_server_step( ssl ); #endif - return( ret ); + return ret ; } /* @@ -5105,7 +5105,7 @@ int mbedtls_ssl_handshake( mbedtls_ssl_context *ssl ) /* Sanity checks */ if( ssl == NULL || ssl->conf == NULL ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; #if defined(MBEDTLS_SSL_PROTO_DTLS) if( ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM && @@ -5113,7 +5113,7 @@ int mbedtls_ssl_handshake( mbedtls_ssl_context *ssl ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "You must use " "mbedtls_ssl_set_timer_cb() for DTLS" ) ); - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; } #endif /* MBEDTLS_SSL_PROTO_DTLS */ @@ -5130,7 +5130,7 @@ int mbedtls_ssl_handshake( mbedtls_ssl_context *ssl ) MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= handshake" ) ); - return( ret ); + return ret ; } #if defined(MBEDTLS_SSL_RENEGOTIATION) @@ -5151,12 +5151,12 @@ static int ssl_write_hello_request( mbedtls_ssl_context *ssl ) if( ( ret = mbedtls_ssl_write_handshake_msg( ssl ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_write_handshake_msg", ret ); - return( ret ); + return ret ; } MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= write hello request" ) ); - return( 0 ); + return 0 ; } #endif /* MBEDTLS_SSL_SRV_C */ @@ -5176,7 +5176,7 @@ int mbedtls_ssl_start_renegotiation( mbedtls_ssl_context *ssl ) MBEDTLS_SSL_DEBUG_MSG( 2, ( "=> renegotiate" ) ); if( ( ret = ssl_handshake_init( ssl ) ) != 0 ) - return( ret ); + return ret ; /* RFC 6347 4.2.2: "[...] the HelloRequest will have message_seq = 0 and * the ServerHello will have message_seq = 1" */ @@ -5197,12 +5197,12 @@ int mbedtls_ssl_start_renegotiation( mbedtls_ssl_context *ssl ) if( ( ret = mbedtls_ssl_handshake( ssl ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_handshake", ret ); - return( ret ); + return ret ; } MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= renegotiate" ) ); - return( 0 ); + return 0 ; } /* @@ -5214,22 +5214,22 @@ int mbedtls_ssl_renegotiate( mbedtls_ssl_context *ssl ) int ret = MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE; if( ssl == NULL || ssl->conf == NULL ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; #if defined(MBEDTLS_SSL_SRV_C) /* On server, just send the request */ if( ssl->conf->endpoint == MBEDTLS_SSL_IS_SERVER ) { if( ssl->state != MBEDTLS_SSL_HANDSHAKE_OVER ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; ssl->renego_status = MBEDTLS_SSL_RENEGOTIATION_PENDING; /* Did we already try/start sending HelloRequest? */ if( ssl->out_left != 0 ) - return( mbedtls_ssl_flush_output( ssl ) ); + return mbedtls_ssl_flush_output( ssl ) ; - return( ssl_write_hello_request( ssl ) ); + return ssl_write_hello_request( ssl ) ; } #endif /* MBEDTLS_SSL_SRV_C */ @@ -5241,12 +5241,12 @@ int mbedtls_ssl_renegotiate( mbedtls_ssl_context *ssl ) if( ssl->renego_status != MBEDTLS_SSL_RENEGOTIATION_IN_PROGRESS ) { if( ssl->state != MBEDTLS_SSL_HANDSHAKE_OVER ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; if( ( ret = mbedtls_ssl_start_renegotiation( ssl ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_start_renegotiation", ret ); - return( ret ); + return ret ; } } else @@ -5254,12 +5254,12 @@ int mbedtls_ssl_renegotiate( mbedtls_ssl_context *ssl ) if( ( ret = mbedtls_ssl_handshake( ssl ) ) != 0 ) { MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_handshake", ret ); - return( ret ); + return ret ; } } #endif /* MBEDTLS_SSL_CLI_C */ - return( ret ); + return ret ; } #endif /* MBEDTLS_SSL_RENEGOTIATION */ @@ -5517,59 +5517,59 @@ int mbedtls_ssl_context_save( mbedtls_ssl_context *ssl, if( ssl->state != MBEDTLS_SSL_HANDSHAKE_OVER ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "Initial handshake isn't over" ) ); - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; } if( ssl->handshake != NULL ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "Handshake isn't completed" ) ); - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; } /* Double-check that sub-structures are indeed ready */ if( ssl->transform == NULL || ssl->session == NULL ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "Serialised structures aren't ready" ) ); - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; } /* There must be no pending incoming or outgoing data */ if( mbedtls_ssl_check_pending( ssl ) != 0 ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "There is pending incoming data" ) ); - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; } if( ssl->out_left != 0 ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "There is pending outgoing data" ) ); - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; } /* Protocol must be DLTS, not TLS */ if( ssl->conf->transport != MBEDTLS_SSL_TRANSPORT_DATAGRAM ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "Only DTLS is supported" ) ); - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; } /* Version must be 1.2 */ if( ssl->major_ver != MBEDTLS_SSL_MAJOR_VERSION_3 ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "Only version 1.2 supported" ) ); - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; } if( ssl->minor_ver != MBEDTLS_SSL_MINOR_VERSION_3 ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "Only version 1.2 supported" ) ); - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; } /* We must be using an AEAD ciphersuite */ if( mbedtls_ssl_transform_uses_aead( ssl->transform ) != 1 ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "Only AEAD ciphersuites supported" ) ); - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; } /* Renegotiation must not be enabled */ #if defined(MBEDTLS_SSL_RENEGOTIATION) if( ssl->conf->disable_renegotiation != MBEDTLS_SSL_RENEGOTIATION_DISABLED ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "Renegotiation must not be enabled" ) ); - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; } #endif @@ -5590,7 +5590,7 @@ int mbedtls_ssl_context_save( mbedtls_ssl_context *ssl, */ ret = ssl_session_save( ssl->session, 1, NULL, 0, &session_len ); if( ret != MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL ) - return( ret ); + return ret ; used += 4 + session_len; if( used <= buf_len ) @@ -5603,7 +5603,7 @@ int mbedtls_ssl_context_save( mbedtls_ssl_context *ssl, ret = ssl_session_save( ssl->session, 1, p, session_len, &session_len ); if( ret != 0 ) - return( ret ); + return ret ; p += session_len; } @@ -5719,11 +5719,11 @@ int mbedtls_ssl_context_save( mbedtls_ssl_context *ssl, *olen = used; if( used > buf_len ) - return( MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL ); + return MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL ; MBEDTLS_SSL_DEBUG_BUF( 4, "saved context", buf, used ); - return( mbedtls_ssl_session_reset_int( ssl, 0 ) ); + return mbedtls_ssl_session_reset_int( ssl, 0 ) ; } /* @@ -5741,11 +5741,11 @@ static tls_prf_fn ssl_tls12prf_from_cs( int ciphersuite_id ) mbedtls_ssl_ciphersuite_from_id( ciphersuite_id ); if( ciphersuite_info->mac == MBEDTLS_MD_SHA384 ) - return( tls_prf_sha384 ); + return tls_prf_sha384 ; #else (void) ciphersuite_id; #endif - return( tls_prf_sha256 ); + return tls_prf_sha256 ; } /* @@ -5772,7 +5772,7 @@ static int ssl_context_load( mbedtls_ssl_context *ssl, if( ssl->state != MBEDTLS_SSL_HELLO_REQUEST || ssl->session != NULL ) { - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; } /* @@ -5789,7 +5789,7 @@ static int ssl_context_load( mbedtls_ssl_context *ssl, #endif 0 ) { - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; } MBEDTLS_SSL_DEBUG_BUF( 4, "context to load", buf, len ); @@ -5798,12 +5798,12 @@ static int ssl_context_load( mbedtls_ssl_context *ssl, * Check version identifier */ if( (size_t)( end - p ) < sizeof( ssl_serialized_context_header ) ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; if( memcmp( p, ssl_serialized_context_header, sizeof( ssl_serialized_context_header ) ) != 0 ) { - return( MBEDTLS_ERR_SSL_VERSION_MISMATCH ); + return MBEDTLS_ERR_SSL_VERSION_MISMATCH ; } p += sizeof( ssl_serialized_context_header ); @@ -5811,7 +5811,7 @@ static int ssl_context_load( mbedtls_ssl_context *ssl, * Session */ if( (size_t)( end - p ) < 4 ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; session_len = ( (size_t) p[0] << 24 ) | ( (size_t) p[1] << 16 ) | @@ -5827,13 +5827,13 @@ static int ssl_context_load( mbedtls_ssl_context *ssl, ssl->session_negotiate = NULL; if( (size_t)( end - p ) < session_len ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; ret = ssl_session_load( ssl->session, 1, p, session_len ); if( ret != 0 ) { mbedtls_ssl_session_free( ssl->session ); - return( ret ); + return ret ; } p += session_len; @@ -5851,7 +5851,7 @@ static int ssl_context_load( mbedtls_ssl_context *ssl, /* Read random bytes and populate structure */ if( (size_t)( end - p ) < sizeof( ssl->transform->randbytes ) ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; ret = ssl_populate_transform( ssl->transform, ssl->session->ciphersuite, @@ -5867,19 +5867,19 @@ static int ssl_context_load( mbedtls_ssl_context *ssl, ssl->conf->endpoint, ssl ); if( ret != 0 ) - return( ret ); + return ret ; p += sizeof( ssl->transform->randbytes ); #if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID) /* Read connection IDs and store them */ if( (size_t)( end - p ) < 1 ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; ssl->transform->in_cid_len = *p++; if( (size_t)( end - p ) < ssl->transform->in_cid_len + 1u ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; memcpy( ssl->transform->in_cid, p, ssl->transform->in_cid_len ); p += ssl->transform->in_cid_len; @@ -5887,7 +5887,7 @@ static int ssl_context_load( mbedtls_ssl_context *ssl, ssl->transform->out_cid_len = *p++; if( (size_t)( end - p ) < ssl->transform->out_cid_len ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; memcpy( ssl->transform->out_cid, p, ssl->transform->out_cid_len ); p += ssl->transform->out_cid_len; @@ -5897,7 +5897,7 @@ static int ssl_context_load( mbedtls_ssl_context *ssl, * Saved fields from top-level ssl_context structure */ if( (size_t)( end - p ) < 4 ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; ssl->badmac_seen = ( (uint32_t) p[0] << 24 ) | ( (uint32_t) p[1] << 16 ) | @@ -5907,7 +5907,7 @@ static int ssl_context_load( mbedtls_ssl_context *ssl, #if defined(MBEDTLS_SSL_DTLS_ANTI_REPLAY) if( (size_t)( end - p ) < 16 ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; ssl->in_window_top = ( (uint64_t) p[0] << 56 ) | ( (uint64_t) p[1] << 48 ) | @@ -5932,20 +5932,20 @@ static int ssl_context_load( mbedtls_ssl_context *ssl, #if defined(MBEDTLS_SSL_PROTO_DTLS) if( (size_t)( end - p ) < 1 ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; ssl->disable_datagram_packing = *p++; #endif /* MBEDTLS_SSL_PROTO_DTLS */ if( (size_t)( end - p ) < 8 ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; memcpy( ssl->cur_out_ctr, p, 8 ); p += 8; #if defined(MBEDTLS_SSL_PROTO_DTLS) if( (size_t)( end - p ) < 2 ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; ssl->mtu = ( p[0] << 8 ) | p[1]; p += 2; @@ -5957,7 +5957,7 @@ static int ssl_context_load( mbedtls_ssl_context *ssl, const char **cur; if( (size_t)( end - p ) < 1 ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; alpn_len = *p++; @@ -5977,7 +5977,7 @@ static int ssl_context_load( mbedtls_ssl_context *ssl, /* can only happen on conf mismatch */ if( alpn_len != 0 && ssl->alpn_chosen == NULL ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; p += alpn_len; } @@ -6017,9 +6017,9 @@ static int ssl_context_load( mbedtls_ssl_context *ssl, * Done - should have consumed entire buffer */ if( p != end ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; - return( 0 ); + return 0 ; } /* @@ -6034,7 +6034,7 @@ int mbedtls_ssl_context_load( mbedtls_ssl_context *context, if( ret != 0 ) mbedtls_ssl_free( context ); - return( ret ); + return ret ; } #endif /* MBEDTLS_SSL_CONTEXT_SERIALIZATION */ @@ -6278,7 +6278,7 @@ int mbedtls_ssl_config_defaults( mbedtls_ssl_config *conf, dhm_p, sizeof( dhm_p ), dhm_g, sizeof( dhm_g ) ) ) != 0 ) { - return( ret ); + return ret ; } } #endif @@ -6350,7 +6350,7 @@ int mbedtls_ssl_config_defaults( mbedtls_ssl_config *conf, #endif } - return( 0 ); + return 0 ; } /* @@ -6397,25 +6397,25 @@ unsigned char mbedtls_ssl_sig_from_pk( mbedtls_pk_context *pk ) { #if defined(MBEDTLS_RSA_C) if( mbedtls_pk_can_do( pk, MBEDTLS_PK_RSA ) ) - return( MBEDTLS_SSL_SIG_RSA ); + return MBEDTLS_SSL_SIG_RSA ; #endif #if defined(MBEDTLS_ECDSA_C) if( mbedtls_pk_can_do( pk, MBEDTLS_PK_ECDSA ) ) - return( MBEDTLS_SSL_SIG_ECDSA ); + return MBEDTLS_SSL_SIG_ECDSA ; #endif - return( MBEDTLS_SSL_SIG_ANON ); + return MBEDTLS_SSL_SIG_ANON ; } unsigned char mbedtls_ssl_sig_from_pk_alg( mbedtls_pk_type_t type ) { switch( type ) { case MBEDTLS_PK_RSA: - return( MBEDTLS_SSL_SIG_RSA ); + return MBEDTLS_SSL_SIG_RSA ; case MBEDTLS_PK_ECDSA: case MBEDTLS_PK_ECKEY: - return( MBEDTLS_SSL_SIG_ECDSA ); + return MBEDTLS_SSL_SIG_ECDSA ; default: - return( MBEDTLS_SSL_SIG_ANON ); + return MBEDTLS_SSL_SIG_ANON ; } } @@ -6425,14 +6425,14 @@ mbedtls_pk_type_t mbedtls_ssl_pk_alg_from_sig( unsigned char sig ) { #if defined(MBEDTLS_RSA_C) case MBEDTLS_SSL_SIG_RSA: - return( MBEDTLS_PK_RSA ); + return MBEDTLS_PK_RSA ; #endif #if defined(MBEDTLS_ECDSA_C) case MBEDTLS_SSL_SIG_ECDSA: - return( MBEDTLS_PK_ECDSA ); + return MBEDTLS_PK_ECDSA ; #endif default: - return( MBEDTLS_PK_NONE ); + return MBEDTLS_PK_NONE ; } } #endif /* MBEDTLS_PK_C && ( MBEDTLS_RSA_C || MBEDTLS_ECDSA_C ) */ @@ -6447,11 +6447,11 @@ mbedtls_md_type_t mbedtls_ssl_sig_hash_set_find( mbedtls_ssl_sig_hash_set_t *set switch( sig_alg ) { case MBEDTLS_PK_RSA: - return( set->rsa ); + return set->rsa ; case MBEDTLS_PK_ECDSA: - return( set->ecdsa ); + return set->ecdsa ; default: - return( MBEDTLS_MD_NONE ); + return MBEDTLS_MD_NONE ; } } @@ -6497,30 +6497,30 @@ mbedtls_md_type_t mbedtls_ssl_md_alg_from_hash( unsigned char hash ) { #if defined(MBEDTLS_MD5_C) case MBEDTLS_SSL_HASH_MD5: - return( MBEDTLS_MD_MD5 ); + return MBEDTLS_MD_MD5 ; #endif #if defined(MBEDTLS_SHA1_C) case MBEDTLS_SSL_HASH_SHA1: - return( MBEDTLS_MD_SHA1 ); + return MBEDTLS_MD_SHA1 ; #endif #if defined(MBEDTLS_SHA224_C) case MBEDTLS_SSL_HASH_SHA224: - return( MBEDTLS_MD_SHA224 ); + return MBEDTLS_MD_SHA224 ; #endif #if defined(MBEDTLS_SHA256_C) case MBEDTLS_SSL_HASH_SHA256: - return( MBEDTLS_MD_SHA256 ); + return MBEDTLS_MD_SHA256 ; #endif #if defined(MBEDTLS_SHA384_C) case MBEDTLS_SSL_HASH_SHA384: - return( MBEDTLS_MD_SHA384 ); + return MBEDTLS_MD_SHA384 ; #endif #if defined(MBEDTLS_SHA512_C) case MBEDTLS_SSL_HASH_SHA512: - return( MBEDTLS_MD_SHA512 ); + return MBEDTLS_MD_SHA512 ; #endif default: - return( MBEDTLS_MD_NONE ); + return MBEDTLS_MD_NONE ; } } @@ -6533,30 +6533,30 @@ unsigned char mbedtls_ssl_hash_from_md_alg( int md ) { #if defined(MBEDTLS_MD5_C) case MBEDTLS_MD_MD5: - return( MBEDTLS_SSL_HASH_MD5 ); + return MBEDTLS_SSL_HASH_MD5 ; #endif #if defined(MBEDTLS_SHA1_C) case MBEDTLS_MD_SHA1: - return( MBEDTLS_SSL_HASH_SHA1 ); + return MBEDTLS_SSL_HASH_SHA1 ; #endif #if defined(MBEDTLS_SHA224_C) case MBEDTLS_MD_SHA224: - return( MBEDTLS_SSL_HASH_SHA224 ); + return MBEDTLS_SSL_HASH_SHA224 ; #endif #if defined(MBEDTLS_SHA256_C) case MBEDTLS_MD_SHA256: - return( MBEDTLS_SSL_HASH_SHA256 ); + return MBEDTLS_SSL_HASH_SHA256 ; #endif #if defined(MBEDTLS_SHA384_C) case MBEDTLS_MD_SHA384: - return( MBEDTLS_SSL_HASH_SHA384 ); + return MBEDTLS_SSL_HASH_SHA384 ; #endif #if defined(MBEDTLS_SHA512_C) case MBEDTLS_MD_SHA512: - return( MBEDTLS_SSL_HASH_SHA512 ); + return MBEDTLS_SSL_HASH_SHA512 ; #endif default: - return( MBEDTLS_SSL_HASH_NONE ); + return MBEDTLS_SSL_HASH_NONE ; } } @@ -6570,13 +6570,13 @@ int mbedtls_ssl_check_curve( const mbedtls_ssl_context *ssl, mbedtls_ecp_group_i const mbedtls_ecp_group_id *gid; if( ssl->conf->curve_list == NULL ) - return( -1 ); + return -1 ; for( gid = ssl->conf->curve_list; *gid != MBEDTLS_ECP_DP_NONE; gid++ ) if( *gid == grp_id ) - return( 0 ); + return 0 ; - return( -1 ); + return -1 ; } #endif /* MBEDTLS_ECP_C */ @@ -6591,13 +6591,13 @@ int mbedtls_ssl_check_sig_hash( const mbedtls_ssl_context *ssl, const int *cur; if( ssl->conf->sig_hashes == NULL ) - return( -1 ); + return -1 ; for( cur = ssl->conf->sig_hashes; *cur != MBEDTLS_MD_NONE; cur++ ) if( *cur == (int) md ) - return( 0 ); + return 0 ; - return( -1 ); + return -1 ; } #endif /* MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED */ @@ -6671,7 +6671,7 @@ int mbedtls_ssl_check_cert_usage( const mbedtls_x509_crt *cert, ret = -1; } - return( ret ); + return ret ; } #endif /* MBEDTLS_X509_CRT_PARSE_C */ @@ -6679,7 +6679,7 @@ int mbedtls_ssl_set_calc_verify_md( mbedtls_ssl_context *ssl, int md ) { #if defined(MBEDTLS_SSL_PROTO_TLS1_2) if( ssl->minor_ver != MBEDTLS_SSL_MINOR_VERSION_3 ) - return( -1 ); + return -1 ; switch( md ) { @@ -6694,7 +6694,7 @@ int mbedtls_ssl_set_calc_verify_md( mbedtls_ssl_context *ssl, int md ) break; #endif default: - return( -1 ); + return -1 ; } return 0; @@ -6702,7 +6702,7 @@ int mbedtls_ssl_set_calc_verify_md( mbedtls_ssl_context *ssl, int md ) (void) ssl; (void) md; - return( -1 ); + return -1 ; #endif /* MBEDTLS_SSL_PROTO_TLS1_2 */ } @@ -6756,17 +6756,17 @@ exit: switch( status ) { case PSA_ERROR_NOT_SUPPORTED: - return( MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE ; case PSA_ERROR_BAD_STATE: /* Intentional fallthrough */ case PSA_ERROR_BUFFER_TOO_SMALL: - return( MBEDTLS_ERR_MD_BAD_INPUT_DATA ); + return MBEDTLS_ERR_MD_BAD_INPUT_DATA ; case PSA_ERROR_INSUFFICIENT_MEMORY: - return( MBEDTLS_ERR_MD_ALLOC_FAILED ); + return MBEDTLS_ERR_MD_ALLOC_FAILED ; default: - return( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED ); + return MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED ; } } - return( 0 ); + return 0 ; } #else @@ -6825,7 +6825,7 @@ exit: mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_INTERNAL_ERROR ); - return( ret ); + return ret ; } #endif /* MBEDTLS_USE_PSA_CRYPTO */ diff --git a/library/ssl_tls13_keys.c b/library/ssl_tls13_keys.c index f1c8a12d86..cd7c2c05e3 100644 --- a/library/ssl_tls13_keys.c +++ b/library/ssl_tls13_keys.c @@ -147,24 +147,24 @@ int mbedtls_ssl_tls1_3_hkdf_expand_label( /* Should never happen since this is an internal * function, and we know statically which labels * are allowed. */ - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; } if( clen > MBEDTLS_SSL_TLS1_3_KEY_SCHEDULE_MAX_CONTEXT_LEN ) { /* Should not happen, as above. */ - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; } if( blen > MBEDTLS_SSL_TLS1_3_KEY_SCHEDULE_MAX_EXPANSION_LEN ) { /* Should not happen, as above. */ - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; } md = mbedtls_md_info_from_type( hash_alg ); if( md == NULL ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; ssl_tls1_3_hkdf_encode_label( blen, label, llen, @@ -209,7 +209,7 @@ int mbedtls_ssl_tls1_3_make_traffic_keys( NULL, 0, keys->client_write_key, key_len ); if( ret != 0 ) - return( ret ); + return ret ; ret = mbedtls_ssl_tls1_3_hkdf_expand_label( hash_alg, server_secret, slen, @@ -217,7 +217,7 @@ int mbedtls_ssl_tls1_3_make_traffic_keys( NULL, 0, keys->server_write_key, key_len ); if( ret != 0 ) - return( ret ); + return ret ; ret = mbedtls_ssl_tls1_3_hkdf_expand_label( hash_alg, client_secret, slen, @@ -225,7 +225,7 @@ int mbedtls_ssl_tls1_3_make_traffic_keys( NULL, 0, keys->client_write_iv, iv_len ); if( ret != 0 ) - return( ret ); + return ret ; ret = mbedtls_ssl_tls1_3_hkdf_expand_label( hash_alg, server_secret, slen, @@ -233,12 +233,12 @@ int mbedtls_ssl_tls1_3_make_traffic_keys( NULL, 0, keys->server_write_iv, iv_len ); if( ret != 0 ) - return( ret ); + return ret ; keys->key_len = key_len; keys->iv_len = iv_len; - return( 0 ); + return 0 ; } int mbedtls_ssl_tls1_3_derive_secret( @@ -255,13 +255,13 @@ int mbedtls_ssl_tls1_3_derive_secret( const mbedtls_md_info_t *md; md = mbedtls_md_info_from_type( hash_alg ); if( md == NULL ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; if( ctx_hashed == MBEDTLS_SSL_TLS1_3_CONTEXT_UNHASHED ) { ret = mbedtls_md( md, ctx, clen, hashed_context ); if( ret != 0 ) - return( ret ); + return ret ; clen = mbedtls_md_get_size( md ); } else @@ -272,7 +272,7 @@ int mbedtls_ssl_tls1_3_derive_secret( * and the code sets `ctx_hashed` correctly. * Let's double-check nonetheless to not run at the risk * of getting a stack overflow. */ - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; } memcpy( hashed_context, ctx, clen ); @@ -299,7 +299,7 @@ int mbedtls_ssl_tls1_3_evolve_secret( const mbedtls_md_info_t *md; md = mbedtls_md_info_from_type( hash_alg ); if( md == NULL ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; hlen = mbedtls_md_get_size( md ); @@ -344,7 +344,7 @@ int mbedtls_ssl_tls1_3_evolve_secret( mbedtls_platform_zeroize( tmp_secret, sizeof(tmp_secret) ); mbedtls_platform_zeroize( tmp_input, sizeof(tmp_input) ); - return( ret ); + return ret ; } int mbedtls_ssl_tls1_3_derive_early_secrets( @@ -360,7 +360,7 @@ int mbedtls_ssl_tls1_3_derive_early_secrets( /* We should never call this function with an unknown hash, * but add an assertion anyway. */ if( md_info == 0 ) - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; /* * 0 @@ -385,7 +385,7 @@ int mbedtls_ssl_tls1_3_derive_early_secrets( derived->client_early_traffic_secret, md_size ); if( ret != 0 ) - return( ret ); + return ret ; /* Create early exporter */ ret = mbedtls_ssl_tls1_3_derive_secret( md_type, @@ -396,9 +396,9 @@ int mbedtls_ssl_tls1_3_derive_early_secrets( derived->early_exporter_master_secret, md_size ); if( ret != 0 ) - return( ret ); + return ret ; - return( 0 ); + return 0 ; } int mbedtls_ssl_tls1_3_derive_handshake_secrets( @@ -414,7 +414,7 @@ int mbedtls_ssl_tls1_3_derive_handshake_secrets( /* We should never call this function with an unknown hash, * but add an assertion anyway. */ if( md_info == 0 ) - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; /* * @@ -443,7 +443,7 @@ int mbedtls_ssl_tls1_3_derive_handshake_secrets( derived->client_handshake_traffic_secret, md_size ); if( ret != 0 ) - return( ret ); + return ret ; /* * Compute server_handshake_traffic_secret with @@ -458,9 +458,9 @@ int mbedtls_ssl_tls1_3_derive_handshake_secrets( derived->server_handshake_traffic_secret, md_size ); if( ret != 0 ) - return( ret ); + return ret ; - return( 0 ); + return 0 ; } int mbedtls_ssl_tls1_3_derive_application_secrets( @@ -476,7 +476,7 @@ int mbedtls_ssl_tls1_3_derive_application_secrets( /* We should never call this function with an unknown hash, * but add an assertion anyway. */ if( md_info == 0 ) - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; /* Generate {client,server}_application_traffic_secret_0 * @@ -504,7 +504,7 @@ int mbedtls_ssl_tls1_3_derive_application_secrets( derived->client_application_traffic_secret_N, md_size ); if( ret != 0 ) - return( ret ); + return ret ; ret = mbedtls_ssl_tls1_3_derive_secret( md_type, application_secret, md_size, @@ -514,7 +514,7 @@ int mbedtls_ssl_tls1_3_derive_application_secrets( derived->server_application_traffic_secret_N, md_size ); if( ret != 0 ) - return( ret ); + return ret ; ret = mbedtls_ssl_tls1_3_derive_secret( md_type, application_secret, md_size, @@ -524,9 +524,9 @@ int mbedtls_ssl_tls1_3_derive_application_secrets( derived->exporter_master_secret, md_size ); if( ret != 0 ) - return( ret ); + return ret ; - return( 0 ); + return 0 ; } /* Generate resumption_master_secret for use with the ticket exchange. @@ -546,7 +546,7 @@ int mbedtls_ssl_tls1_3_derive_resumption_master_secret( /* We should never call this function with an unknown hash, * but add an assertion anyway. */ if( md_info == 0 ) - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; ret = mbedtls_ssl_tls1_3_derive_secret( md_type, application_secret, md_size, @@ -557,9 +557,9 @@ int mbedtls_ssl_tls1_3_derive_resumption_master_secret( md_size ); if( ret != 0 ) - return( ret ); + return ret ; - return( 0 ); + return 0 ; } static int ssl_tls1_3_calc_finished_core( mbedtls_md_type_t md_type, @@ -575,7 +575,7 @@ static int ssl_tls1_3_calc_finished_core( mbedtls_md_type_t md_type, /* We should never call this function with an unknown hash, * but add an assertion anyway. */ if( md_info == 0 ) - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; /* TLS 1.3 Finished message * @@ -609,7 +609,7 @@ static int ssl_tls1_3_calc_finished_core( mbedtls_md_type_t md_type, exit: mbedtls_platform_zeroize( finished_key, sizeof( finished_key ) ); - return( ret ); + return ret ; } int mbedtls_ssl_tls1_3_create_psk_binder( mbedtls_ssl_context *ssl, @@ -633,7 +633,7 @@ int mbedtls_ssl_tls1_3_create_psk_binder( mbedtls_ssl_context *ssl, /* We should never call this function with an unknown hash, * but add an assertion anyway. */ if( md_info == 0 ) - return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR ; /* * 0 @@ -696,7 +696,7 @@ exit: mbedtls_platform_zeroize( early_secret, sizeof( early_secret ) ); mbedtls_platform_zeroize( binder_key, sizeof( binder_key ) ); - return( ret ); + return ret ; } #endif /* MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL */ diff --git a/library/threading.c b/library/threading.c index bae6644f68..cf01c0a964 100644 --- a/library/threading.c +++ b/library/threading.c @@ -88,23 +88,23 @@ static void threading_mutex_free_pthread( mbedtls_threading_mutex_t *mutex ) static int threading_mutex_lock_pthread( mbedtls_threading_mutex_t *mutex ) { if( mutex == NULL || ! mutex->is_valid ) - return( MBEDTLS_ERR_THREADING_BAD_INPUT_DATA ); + return MBEDTLS_ERR_THREADING_BAD_INPUT_DATA ; if( pthread_mutex_lock( &mutex->mutex ) != 0 ) - return( MBEDTLS_ERR_THREADING_MUTEX_ERROR ); + return MBEDTLS_ERR_THREADING_MUTEX_ERROR ; - return( 0 ); + return 0 ; } static int threading_mutex_unlock_pthread( mbedtls_threading_mutex_t *mutex ) { if( mutex == NULL || ! mutex->is_valid ) - return( MBEDTLS_ERR_THREADING_BAD_INPUT_DATA ); + return MBEDTLS_ERR_THREADING_BAD_INPUT_DATA ; if( pthread_mutex_unlock( &mutex->mutex ) != 0 ) - return( MBEDTLS_ERR_THREADING_MUTEX_ERROR ); + return MBEDTLS_ERR_THREADING_MUTEX_ERROR ; - return( 0 ); + return 0 ; } void (*mbedtls_mutex_init)( mbedtls_threading_mutex_t * ) = threading_mutex_init_pthread; @@ -123,7 +123,7 @@ int (*mbedtls_mutex_unlock)( mbedtls_threading_mutex_t * ) = threading_mutex_unl static int threading_mutex_fail( mbedtls_threading_mutex_t *mutex ) { ((void) mutex ); - return( MBEDTLS_ERR_THREADING_BAD_INPUT_DATA ); + return MBEDTLS_ERR_THREADING_BAD_INPUT_DATA ; } static void threading_mutex_dummy( mbedtls_threading_mutex_t *mutex ) { diff --git a/library/timing.c b/library/timing.c index 8a02c00de0..0acec5b036 100644 --- a/library/timing.c +++ b/library/timing.c @@ -84,7 +84,7 @@ unsigned long mbedtls_timing_get_timer( struct mbedtls_timing_hr_time *val, int if( reset ) { QueryPerformanceCounter( &t->start ); - return( 0 ); + return 0 ; } else { @@ -94,7 +94,7 @@ unsigned long mbedtls_timing_get_timer( struct mbedtls_timing_hr_time *val, int QueryPerformanceFrequency( &hfreq ); delta = (unsigned long)( ( now.QuadPart - t->start.QuadPart ) * 1000ul / hfreq.QuadPart ); - return( delta ); + return delta ; } } @@ -107,7 +107,7 @@ unsigned long mbedtls_timing_get_timer( struct mbedtls_timing_hr_time *val, int if( reset ) { gettimeofday( &t->start, NULL ); - return( 0 ); + return 0 ; } else { @@ -116,7 +116,7 @@ unsigned long mbedtls_timing_get_timer( struct mbedtls_timing_hr_time *val, int gettimeofday( &now, NULL ); delta = ( now.tv_sec - t->start.tv_sec ) * 1000ul + ( now.tv_usec - t->start.tv_usec ) / 1000; - return( delta ); + return delta ; } } @@ -145,17 +145,17 @@ int mbedtls_timing_get_delay( void *data ) unsigned long elapsed_ms; if( ctx->fin_ms == 0 ) - return( -1 ); + return -1 ; elapsed_ms = mbedtls_timing_get_timer( &ctx->timer, 0 ); if( elapsed_ms >= ctx->fin_ms ) - return( 2 ); + return 2 ; if( elapsed_ms >= ctx->int_ms ) - return( 1 ); + return 1 ; - return( 0 ); + return 0 ; } #endif /* !MBEDTLS_TIMING_ALT */ diff --git a/library/version.c b/library/version.c index 32a0d7d584..d80de43a5a 100644 --- a/library/version.c +++ b/library/version.c @@ -26,7 +26,7 @@ unsigned int mbedtls_version_get_number( void ) { - return( MBEDTLS_VERSION_NUMBER ); + return MBEDTLS_VERSION_NUMBER ; } void mbedtls_version_get_string( char *string ) diff --git a/library/x509.c b/library/x509.c index 2e11c7fcef..0f14aad07b 100644 --- a/library/x509.c +++ b/library/x509.c @@ -62,13 +62,13 @@ #include #endif -#define CHECK(code) if( ( ret = ( code ) ) != 0 ){ return( ret ); } +#define CHECK(code) if( ( ret = ( code ) ) != 0 ){ return ret ; } #define CHECK_RANGE(min, max, val) \ do \ { \ if( ( val ) < ( min ) || ( val ) > ( max ) ) \ { \ - return( ret ); \ + return ret ; \ } \ } while( 0 ) @@ -92,12 +92,12 @@ int mbedtls_x509_get_serial( unsigned char **p, const unsigned char *end, serial->tag = *(*p)++; if( ( ret = mbedtls_asn1_get_len( p, end, &serial->len ) ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_SERIAL, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_SERIAL, ret ) ; serial->p = *p; *p += serial->len; - return( 0 ); + return 0 ; } /* Get an algorithm identifier without parameters (eg for signatures) @@ -112,9 +112,9 @@ int mbedtls_x509_get_alg_null( unsigned char **p, const unsigned char *end, int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; if( ( ret = mbedtls_asn1_get_alg_null( p, end, alg ) ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_ALG, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_ALG, ret ) ; - return( 0 ); + return 0 ; } /* @@ -126,9 +126,9 @@ int mbedtls_x509_get_alg( unsigned char **p, const unsigned char *end, int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; if( ( ret = mbedtls_asn1_get_alg( p, end, alg, params ) ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_ALG, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_ALG, ret ) ; - return( 0 ); + return 0 ; } #if defined(MBEDTLS_X509_RSASSA_PSS_SUPPORT) @@ -165,27 +165,27 @@ static int x509_get_hash_alg( const mbedtls_x509_buf *alg, mbedtls_md_type_t *md md_oid.tag = *p; if( ( ret = mbedtls_asn1_get_tag( &p, end, &md_oid.len, MBEDTLS_ASN1_OID ) ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_ALG, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_ALG, ret ) ; md_oid.p = p; p += md_oid.len; /* Get md_alg from md_oid */ if( ( ret = mbedtls_oid_get_md_alg( &md_oid, md_alg ) ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_ALG, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_ALG, ret ) ; /* Make sure params is absent of NULL */ if( p == end ) - return( 0 ); + return 0 ; if( ( ret = mbedtls_asn1_get_tag( &p, end, &len, MBEDTLS_ASN1_NULL ) ) != 0 || len != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_ALG, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_ALG, ret ) ; if( p != end ) return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_ALG, MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) ); - return( 0 ); + return 0 ; } /* @@ -224,7 +224,7 @@ int mbedtls_x509_get_rsassa_pss_params( const mbedtls_x509_buf *params, end = p + params->len; if( p == end ) - return( 0 ); + return 0 ; /* * HashAlgorithm @@ -236,20 +236,20 @@ int mbedtls_x509_get_rsassa_pss_params( const mbedtls_x509_buf *params, /* HashAlgorithm ::= AlgorithmIdentifier (without parameters) */ if( ( ret = mbedtls_x509_get_alg_null( &p, end2, &alg_id ) ) != 0 ) - return( ret ); + return ret ; if( ( ret = mbedtls_oid_get_md_alg( &alg_id, md_alg ) ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_ALG, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_ALG, ret ) ; if( p != end2 ) return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_ALG, MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) ); } else if( ret != MBEDTLS_ERR_ASN1_UNEXPECTED_TAG ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_ALG, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_ALG, ret ) ; if( p == end ) - return( 0 ); + return 0 ; /* * MaskGenAlgorithm @@ -261,7 +261,7 @@ int mbedtls_x509_get_rsassa_pss_params( const mbedtls_x509_buf *params, /* MaskGenAlgorithm ::= AlgorithmIdentifier (params = HashAlgorithm) */ if( ( ret = mbedtls_x509_get_alg( &p, end2, &alg_id, &alg_params ) ) != 0 ) - return( ret ); + return ret ; /* Only MFG1 is recognised for now */ if( MBEDTLS_OID_CMP( MBEDTLS_OID_MGF1, &alg_id ) != 0 ) @@ -270,17 +270,17 @@ int mbedtls_x509_get_rsassa_pss_params( const mbedtls_x509_buf *params, /* Parse HashAlgorithm */ if( ( ret = x509_get_hash_alg( &alg_params, mgf_md ) ) != 0 ) - return( ret ); + return ret ; if( p != end2 ) return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_ALG, MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) ); } else if( ret != MBEDTLS_ERR_ASN1_UNEXPECTED_TAG ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_ALG, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_ALG, ret ) ; if( p == end ) - return( 0 ); + return 0 ; /* * salt_len @@ -291,17 +291,17 @@ int mbedtls_x509_get_rsassa_pss_params( const mbedtls_x509_buf *params, end2 = p + len; if( ( ret = mbedtls_asn1_get_int( &p, end2, salt_len ) ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_ALG, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_ALG, ret ) ; if( p != end2 ) return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_ALG, MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) ); } else if( ret != MBEDTLS_ERR_ASN1_UNEXPECTED_TAG ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_ALG, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_ALG, ret ) ; if( p == end ) - return( 0 ); + return 0 ; /* * trailer_field (if present, must be 1) @@ -314,23 +314,23 @@ int mbedtls_x509_get_rsassa_pss_params( const mbedtls_x509_buf *params, end2 = p + len; if( ( ret = mbedtls_asn1_get_int( &p, end2, &trailer_field ) ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_ALG, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_ALG, ret ) ; if( p != end2 ) return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_ALG, MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) ); if( trailer_field != 1 ) - return( MBEDTLS_ERR_X509_INVALID_ALG ); + return MBEDTLS_ERR_X509_INVALID_ALG ; } else if( ret != MBEDTLS_ERR_ASN1_UNEXPECTED_TAG ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_ALG, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_ALG, ret ) ; if( p != end ) return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_ALG, MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) ); - return( 0 ); + return 0 ; } #endif /* MBEDTLS_X509_RSASSA_PSS_SUPPORT */ @@ -354,7 +354,7 @@ static int x509_get_attr_type_value( unsigned char **p, if( ( ret = mbedtls_asn1_get_tag( p, end, &len, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_NAME, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_NAME, ret ) ; end = *p + len; @@ -366,7 +366,7 @@ static int x509_get_attr_type_value( unsigned char **p, oid->tag = **p; if( ( ret = mbedtls_asn1_get_tag( p, end, &oid->len, MBEDTLS_ASN1_OID ) ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_NAME, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_NAME, ret ) ; oid->p = *p; *p += oid->len; @@ -386,7 +386,7 @@ static int x509_get_attr_type_value( unsigned char **p, val->tag = *(*p)++; if( ( ret = mbedtls_asn1_get_len( p, end, &val->len ) ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_NAME, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_NAME, ret ) ; val->p = *p; *p += val->len; @@ -399,7 +399,7 @@ static int x509_get_attr_type_value( unsigned char **p, cur->next = NULL; - return( 0 ); + return 0 ; } /* @@ -440,14 +440,14 @@ int mbedtls_x509_get_name( unsigned char **p, const unsigned char *end, */ if( ( ret = mbedtls_asn1_get_tag( p, end, &set_len, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SET ) ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_NAME, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_NAME, ret ) ; end_set = *p + set_len; while( 1 ) { if( ( ret = x509_get_attr_type_value( p, end_set, cur ) ) != 0 ) - return( ret ); + return ret ; if( *p == end_set ) break; @@ -458,7 +458,7 @@ int mbedtls_x509_get_name( unsigned char **p, const unsigned char *end, cur->next = mbedtls_calloc( 1, sizeof( mbedtls_x509_name ) ); if( cur->next == NULL ) - return( MBEDTLS_ERR_X509_ALLOC_FAILED ); + return MBEDTLS_ERR_X509_ALLOC_FAILED ; cur = cur->next; } @@ -467,12 +467,12 @@ int mbedtls_x509_get_name( unsigned char **p, const unsigned char *end, * continue until end of SEQUENCE is reached */ if( *p == end ) - return( 0 ); + return 0 ; cur->next = mbedtls_calloc( 1, sizeof( mbedtls_x509_name ) ); if( cur->next == NULL ) - return( MBEDTLS_ERR_X509_ALLOC_FAILED ); + return MBEDTLS_ERR_X509_ALLOC_FAILED ; cur = cur->next; } @@ -485,13 +485,13 @@ static int x509_parse_int( unsigned char **p, size_t n, int *res ) for( ; n > 0; --n ) { if( ( **p < '0') || ( **p > '9' ) ) - return ( MBEDTLS_ERR_X509_INVALID_DATE ); + return MBEDTLS_ERR_X509_INVALID_DATE ; *res *= 10; *res += ( *(*p)++ - '0' ); } - return( 0 ); + return 0 ; } static int x509_date_is_valid(const mbedtls_x509_time *t ) @@ -520,11 +520,11 @@ static int x509_date_is_valid(const mbedtls_x509_time *t ) month_len = 28; break; default: - return( ret ); + return ret ; } CHECK_RANGE( 1, month_len, t->day ); - return( 0 ); + return 0 ; } /* @@ -540,7 +540,7 @@ static int x509_parse_time( unsigned char **p, size_t len, size_t yearlen, * Minimum length is 10 or 12 depending on yearlen */ if ( len < yearlen + 8 ) - return ( MBEDTLS_ERR_X509_INVALID_DATE ); + return MBEDTLS_ERR_X509_INVALID_DATE ; len -= yearlen + 8; /* @@ -569,7 +569,7 @@ static int x509_parse_time( unsigned char **p, size_t len, size_t yearlen, len -= 2; } else - return ( MBEDTLS_ERR_X509_INVALID_DATE ); + return MBEDTLS_ERR_X509_INVALID_DATE ; /* * Parse trailing 'Z' if present @@ -584,11 +584,11 @@ static int x509_parse_time( unsigned char **p, size_t len, size_t yearlen, * We should have parsed all characters at this point */ if ( 0 != len ) - return ( MBEDTLS_ERR_X509_INVALID_DATE ); + return MBEDTLS_ERR_X509_INVALID_DATE ; CHECK( x509_date_is_valid( tm ) ); - return ( 0 ); + return 0 ; } /* @@ -621,7 +621,7 @@ int mbedtls_x509_get_time( unsigned char **p, const unsigned char *end, ret = mbedtls_asn1_get_len( p, end, &len ); if( ret != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_DATE, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_DATE, ret ) ; return x509_parse_time( p, len, year_len, tm ); } @@ -639,7 +639,7 @@ int mbedtls_x509_get_sig( unsigned char **p, const unsigned char *end, mbedtls_x tag_type = **p; if( ( ret = mbedtls_asn1_get_bitstring_null( p, end, &len ) ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_SIGNATURE, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_SIGNATURE, ret ) ; sig->tag = tag_type; sig->len = len; @@ -647,7 +647,7 @@ int mbedtls_x509_get_sig( unsigned char **p, const unsigned char *end, mbedtls_x *p += len; - return( 0 ); + return 0 ; } /* @@ -660,10 +660,10 @@ int mbedtls_x509_get_sig_alg( const mbedtls_x509_buf *sig_oid, const mbedtls_x50 int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; if( *sig_opts != NULL ) - return( MBEDTLS_ERR_X509_BAD_INPUT_DATA ); + return MBEDTLS_ERR_X509_BAD_INPUT_DATA ; if( ( ret = mbedtls_oid_get_sig_alg( sig_oid, md_alg, pk_alg ) ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_UNKNOWN_SIG_ALG, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_UNKNOWN_SIG_ALG, ret ) ; #if defined(MBEDTLS_X509_RSASSA_PSS_SUPPORT) if( *pk_alg == MBEDTLS_PK_RSASSA_PSS ) @@ -672,7 +672,7 @@ int mbedtls_x509_get_sig_alg( const mbedtls_x509_buf *sig_oid, const mbedtls_x50 pss_opts = mbedtls_calloc( 1, sizeof( mbedtls_pk_rsassa_pss_options ) ); if( pss_opts == NULL ) - return( MBEDTLS_ERR_X509_ALLOC_FAILED ); + return MBEDTLS_ERR_X509_ALLOC_FAILED ; ret = mbedtls_x509_get_rsassa_pss_params( sig_params, md_alg, @@ -681,7 +681,7 @@ int mbedtls_x509_get_sig_alg( const mbedtls_x509_buf *sig_oid, const mbedtls_x50 if( ret != 0 ) { mbedtls_free( pss_opts ); - return( ret ); + return ret ; } *sig_opts = (void *) pss_opts; @@ -692,10 +692,10 @@ int mbedtls_x509_get_sig_alg( const mbedtls_x509_buf *sig_oid, const mbedtls_x50 /* Make sure parameters are absent or NULL */ if( ( sig_params->tag != MBEDTLS_ASN1_NULL && sig_params->tag != 0 ) || sig_params->len != 0 ) - return( MBEDTLS_ERR_X509_INVALID_ALG ); + return MBEDTLS_ERR_X509_INVALID_ALG ; } - return( 0 ); + return 0 ; } /* @@ -714,7 +714,7 @@ int mbedtls_x509_get_ext( unsigned char **p, const unsigned char *end, ret = mbedtls_asn1_get_tag( p, end, &ext->len, MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED | tag ); if( ret != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ; ext->tag = MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED | tag; ext->p = *p; @@ -725,13 +725,13 @@ int mbedtls_x509_get_ext( unsigned char **p, const unsigned char *end, */ if( ( ret = mbedtls_asn1_get_tag( p, end, &len, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ; if( end != *p + len ) return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) ); - return( 0 ); + return 0 ; } /* @@ -890,7 +890,7 @@ int mbedtls_x509_key_size_helper( char *buf, size_t buf_size, const char *name ) ret = mbedtls_snprintf( p, n, "%s key size", name ); MBEDTLS_X509_SAFE_SNPRINTF; - return( 0 ); + return 0 ; } #if defined(MBEDTLS_HAVE_TIME_DATE) @@ -919,7 +919,7 @@ static int x509_get_current_time( mbedtls_x509_time *now ) now->sec = lt->tm_sec; } - return( ret ); + return ret ; } /* @@ -928,29 +928,29 @@ static int x509_get_current_time( mbedtls_x509_time *now ) static int x509_check_time( const mbedtls_x509_time *before, const mbedtls_x509_time *after ) { if( before->year > after->year ) - return( 1 ); + return 1 ; if( before->year == after->year && before->mon > after->mon ) - return( 1 ); + return 1 ; if( before->year == after->year && before->mon == after->mon && before->day > after->day ) - return( 1 ); + return 1 ; if( before->year == after->year && before->mon == after->mon && before->day == after->day && before->hour > after->hour ) - return( 1 ); + return 1 ; if( before->year == after->year && before->mon == after->mon && before->day == after->day && before->hour == after->hour && before->min > after->min ) - return( 1 ); + return 1 ; if( before->year == after->year && before->mon == after->mon && @@ -958,9 +958,9 @@ static int x509_check_time( const mbedtls_x509_time *before, const mbedtls_x509_ before->hour == after->hour && before->min == after->min && before->sec > after->sec ) - return( 1 ); + return 1 ; - return( 0 ); + return 0 ; } int mbedtls_x509_time_is_past( const mbedtls_x509_time *to ) @@ -968,9 +968,9 @@ int mbedtls_x509_time_is_past( const mbedtls_x509_time *to ) mbedtls_x509_time now; if( x509_get_current_time( &now ) != 0 ) - return( 1 ); + return 1 ; - return( x509_check_time( &now, to ) ); + return x509_check_time( &now, to ) ; } int mbedtls_x509_time_is_future( const mbedtls_x509_time *from ) @@ -978,9 +978,9 @@ int mbedtls_x509_time_is_future( const mbedtls_x509_time *from ) mbedtls_x509_time now; if( x509_get_current_time( &now ) != 0 ) - return( 1 ); + return 1 ; - return( x509_check_time( from, &now ) ); + return x509_check_time( from, &now ) ; } #else /* MBEDTLS_HAVE_TIME_DATE */ @@ -988,13 +988,13 @@ int mbedtls_x509_time_is_future( const mbedtls_x509_time *from ) int mbedtls_x509_time_is_past( const mbedtls_x509_time *to ) { ((void) to); - return( 0 ); + return 0 ; } int mbedtls_x509_time_is_future( const mbedtls_x509_time *from ) { ((void) from); - return( 0 ); + return 0 ; } #endif /* MBEDTLS_HAVE_TIME_DATE */ #endif /* MBEDTLS_X509_USE_C */ diff --git a/library/x509_create.c b/library/x509_create.c index 056bbaa786..af157e8ebf 100644 --- a/library/x509_create.c +++ b/library/x509_create.c @@ -115,9 +115,9 @@ static const x509_attr_descriptor_t *x509_attr_descr_from_name( const char *name break; if ( cur->name == NULL ) - return( NULL ); + return NULL ; - return( cur ); + return cur ; } int mbedtls_x509_string_to_names( mbedtls_asn1_named_data **head, const char *name ) @@ -170,7 +170,7 @@ int mbedtls_x509_string_to_names( mbedtls_asn1_named_data **head, const char *na if(cur == NULL ) { - return( MBEDTLS_ERR_X509_ALLOC_FAILED ); + return MBEDTLS_ERR_X509_ALLOC_FAILED ; } // set tagType @@ -199,7 +199,7 @@ int mbedtls_x509_string_to_names( mbedtls_asn1_named_data **head, const char *na exit: - return( ret ); + return ret ; } /* The first byte of the value in the mbedtls_asn1_named_data structure is reserved @@ -213,13 +213,13 @@ int mbedtls_x509_set_extension( mbedtls_asn1_named_data **head, const char *oid, if( ( cur = mbedtls_asn1_store_named_data( head, oid, oid_len, NULL, val_len + 1 ) ) == NULL ) { - return( MBEDTLS_ERR_X509_ALLOC_FAILED ); + return MBEDTLS_ERR_X509_ALLOC_FAILED ; } cur->val.p[0] = critical; memcpy( cur->val.p + 1, val, val_len ); - return( 0 ); + return 0 ; } /* @@ -263,7 +263,7 @@ static int x509_write_name( unsigned char **p, unsigned char *start, mbedtls_asn MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SET ) ); - return( (int) len ); + return (int) len ; } int mbedtls_x509_write_names( unsigned char **p, unsigned char *start, @@ -283,7 +283,7 @@ int mbedtls_x509_write_names( unsigned char **p, unsigned char *start, MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( p, start, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ); - return( (int) len ); + return (int) len ; } int mbedtls_x509_write_sig( unsigned char **p, unsigned char *start, @@ -294,14 +294,14 @@ int mbedtls_x509_write_sig( unsigned char **p, unsigned char *start, size_t len = 0; if( *p < start || (size_t)( *p - start ) < size ) - return( MBEDTLS_ERR_ASN1_BUF_TOO_SMALL ); + return MBEDTLS_ERR_ASN1_BUF_TOO_SMALL ; len = size; (*p) -= len; memcpy( *p, sig, len ); if( *p - start < 1 ) - return( MBEDTLS_ERR_ASN1_BUF_TOO_SMALL ); + return MBEDTLS_ERR_ASN1_BUF_TOO_SMALL ; *--(*p) = 0; len += 1; @@ -314,7 +314,7 @@ int mbedtls_x509_write_sig( unsigned char **p, unsigned char *start, MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_algorithm_identifier( p, start, oid, oid_len, 0 ) ); - return( (int) len ); + return (int) len ; } static int x509_write_extension( unsigned char **p, unsigned char *start, @@ -342,7 +342,7 @@ static int x509_write_extension( unsigned char **p, unsigned char *start, MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( p, start, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ); - return( (int) len ); + return (int) len ; } /* @@ -368,7 +368,7 @@ int mbedtls_x509_write_extensions( unsigned char **p, unsigned char *start, cur_ext = cur_ext->next; } - return( (int) len ); + return (int) len ; } #endif /* MBEDTLS_X509_CREATE_C */ diff --git a/library/x509_crl.c b/library/x509_crl.c index e6efdca5cd..de8bcbc25f 100644 --- a/library/x509_crl.c +++ b/library/x509_crl.c @@ -76,13 +76,13 @@ static int x509_crl_get_version( unsigned char **p, if( ret == MBEDTLS_ERR_ASN1_UNEXPECTED_TAG ) { *ver = 0; - return( 0 ); + return 0 ; } - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_VERSION, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_VERSION, ret ) ; } - return( 0 ); + return 0 ; } /* @@ -99,14 +99,14 @@ static int x509_get_crl_ext( unsigned char **p, int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; if( *p == end ) - return( 0 ); + return 0 ; /* * crlExtensions [0] EXPLICIT Extensions OPTIONAL * -- if present, version MUST be v2 */ if( ( ret = mbedtls_x509_get_ext( p, end, ext, 0 ) ) != 0 ) - return( ret ); + return ret ; end = ext->p + ext->len; @@ -125,7 +125,7 @@ static int x509_get_crl_ext( unsigned char **p, /* Get enclosing sequence tag */ if( ( ret = mbedtls_asn1_get_tag( p, end, &len, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ; end_ext_data = *p + len; @@ -133,7 +133,7 @@ static int x509_get_crl_ext( unsigned char **p, if( ( ret = mbedtls_asn1_get_tag( p, end_ext_data, &len, MBEDTLS_ASN1_OID ) ) != 0 ) { - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ; } *p += len; @@ -142,13 +142,13 @@ static int x509_get_crl_ext( unsigned char **p, &is_critical ) ) != 0 && ( ret != MBEDTLS_ERR_ASN1_UNEXPECTED_TAG ) ) { - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ; } /* Data should be octet string type */ if( ( ret = mbedtls_asn1_get_tag( p, end_ext_data, &len, MBEDTLS_ASN1_OCTET_STRING ) ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ; /* Ignore data so far and just check its length */ *p += len; @@ -166,7 +166,7 @@ static int x509_get_crl_ext( unsigned char **p, return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) ); - return( 0 ); + return 0 ; } /* @@ -181,7 +181,7 @@ static int x509_get_crl_entry_ext( unsigned char **p, /* OPTIONAL */ if( end <= *p ) - return( 0 ); + return 0 ; ext->tag = **p; ext->p = *p; @@ -196,9 +196,9 @@ static int x509_get_crl_entry_ext( unsigned char **p, if( ret == MBEDTLS_ERR_ASN1_UNEXPECTED_TAG ) { ext->p = NULL; - return( 0 ); + return 0 ; } - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ; } end = *p + ext->len; @@ -211,7 +211,7 @@ static int x509_get_crl_entry_ext( unsigned char **p, { if( ( ret = mbedtls_asn1_get_tag( p, end, &len, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ; *p += len; } @@ -220,7 +220,7 @@ static int x509_get_crl_entry_ext( unsigned char **p, return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) ); - return( 0 ); + return 0 ; } /* @@ -235,15 +235,15 @@ static int x509_get_entries( unsigned char **p, mbedtls_x509_crl_entry *cur_entry = entry; if( *p == end ) - return( 0 ); + return 0 ; if( ( ret = mbedtls_asn1_get_tag( p, end, &entry_len, MBEDTLS_ASN1_SEQUENCE | MBEDTLS_ASN1_CONSTRUCTED ) ) != 0 ) { if( ret == MBEDTLS_ERR_ASN1_UNEXPECTED_TAG ) - return( 0 ); + return 0 ; - return( ret ); + return ret ; } end = *p + entry_len; @@ -257,7 +257,7 @@ static int x509_get_entries( unsigned char **p, if( ( ret = mbedtls_asn1_get_tag( p, end, &len2, MBEDTLS_ASN1_SEQUENCE | MBEDTLS_ASN1_CONSTRUCTED ) ) != 0 ) { - return( ret ); + return ret ; } cur_entry->raw.p = *p; @@ -265,28 +265,28 @@ static int x509_get_entries( unsigned char **p, end2 = *p + len2; if( ( ret = mbedtls_x509_get_serial( p, end2, &cur_entry->serial ) ) != 0 ) - return( ret ); + return ret ; if( ( ret = mbedtls_x509_get_time( p, end2, &cur_entry->revocation_date ) ) != 0 ) - return( ret ); + return ret ; if( ( ret = x509_get_crl_entry_ext( p, end2, &cur_entry->entry_ext ) ) != 0 ) - return( ret ); + return ret ; if( *p < end ) { cur_entry->next = mbedtls_calloc( 1, sizeof( mbedtls_x509_crl_entry ) ); if( cur_entry->next == NULL ) - return( MBEDTLS_ERR_X509_ALLOC_FAILED ); + return MBEDTLS_ERR_X509_ALLOC_FAILED ; cur_entry = cur_entry->next; } } - return( 0 ); + return 0 ; } /* @@ -305,7 +305,7 @@ int mbedtls_x509_crl_parse_der( mbedtls_x509_crl *chain, * Check for valid input */ if( crl == NULL || buf == NULL ) - return( MBEDTLS_ERR_X509_BAD_INPUT_DATA ); + return MBEDTLS_ERR_X509_BAD_INPUT_DATA ; memset( &sig_params1, 0, sizeof( mbedtls_x509_buf ) ); memset( &sig_params2, 0, sizeof( mbedtls_x509_buf ) ); @@ -324,7 +324,7 @@ int mbedtls_x509_crl_parse_der( mbedtls_x509_crl *chain, if( crl->next == NULL ) { mbedtls_x509_crl_free( crl ); - return( MBEDTLS_ERR_X509_ALLOC_FAILED ); + return MBEDTLS_ERR_X509_ALLOC_FAILED ; } mbedtls_x509_crl_init( crl->next ); @@ -335,11 +335,11 @@ int mbedtls_x509_crl_parse_der( mbedtls_x509_crl *chain, * Copy raw DER-encoded CRL */ if( buflen == 0 ) - return( MBEDTLS_ERR_X509_INVALID_FORMAT ); + return MBEDTLS_ERR_X509_INVALID_FORMAT ; p = mbedtls_calloc( 1, buflen ); if( p == NULL ) - return( MBEDTLS_ERR_X509_ALLOC_FAILED ); + return MBEDTLS_ERR_X509_ALLOC_FAILED ; memcpy( p, buf, buflen ); @@ -358,7 +358,7 @@ int mbedtls_x509_crl_parse_der( mbedtls_x509_crl *chain, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 ) { mbedtls_x509_crl_free( crl ); - return( MBEDTLS_ERR_X509_INVALID_FORMAT ); + return MBEDTLS_ERR_X509_INVALID_FORMAT ; } if( len != (size_t) ( end - p ) ) @@ -377,7 +377,7 @@ int mbedtls_x509_crl_parse_der( mbedtls_x509_crl *chain, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 ) { mbedtls_x509_crl_free( crl ); - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_FORMAT, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_FORMAT, ret ) ; } end = p + len; @@ -393,13 +393,13 @@ int mbedtls_x509_crl_parse_der( mbedtls_x509_crl *chain, ( ret = mbedtls_x509_get_alg( &p, end, &crl->sig_oid, &sig_params1 ) ) != 0 ) { mbedtls_x509_crl_free( crl ); - return( ret ); + return ret ; } if( crl->version < 0 || crl->version > 1 ) { mbedtls_x509_crl_free( crl ); - return( MBEDTLS_ERR_X509_UNKNOWN_VERSION ); + return MBEDTLS_ERR_X509_UNKNOWN_VERSION ; } crl->version++; @@ -409,7 +409,7 @@ int mbedtls_x509_crl_parse_der( mbedtls_x509_crl *chain, &crl->sig_opts ) ) != 0 ) { mbedtls_x509_crl_free( crl ); - return( MBEDTLS_ERR_X509_UNKNOWN_SIG_ALG ); + return MBEDTLS_ERR_X509_UNKNOWN_SIG_ALG ; } /* @@ -421,13 +421,13 @@ int mbedtls_x509_crl_parse_der( mbedtls_x509_crl *chain, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 ) { mbedtls_x509_crl_free( crl ); - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_FORMAT, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_FORMAT, ret ) ; } if( ( ret = mbedtls_x509_get_name( &p, p + len, &crl->issuer ) ) != 0 ) { mbedtls_x509_crl_free( crl ); - return( ret ); + return ret ; } crl->issuer_raw.len = p - crl->issuer_raw.p; @@ -439,7 +439,7 @@ int mbedtls_x509_crl_parse_der( mbedtls_x509_crl *chain, if( ( ret = mbedtls_x509_get_time( &p, end, &crl->this_update ) ) != 0 ) { mbedtls_x509_crl_free( crl ); - return( ret ); + return ret ; } if( ( ret = mbedtls_x509_get_time( &p, end, &crl->next_update ) ) != 0 ) @@ -450,7 +450,7 @@ int mbedtls_x509_crl_parse_der( mbedtls_x509_crl *chain, MBEDTLS_ERR_ASN1_OUT_OF_DATA ) ) ) { mbedtls_x509_crl_free( crl ); - return( ret ); + return ret ; } } @@ -465,7 +465,7 @@ int mbedtls_x509_crl_parse_der( mbedtls_x509_crl *chain, if( ( ret = x509_get_entries( &p, end, &crl->entry ) ) != 0 ) { mbedtls_x509_crl_free( crl ); - return( ret ); + return ret ; } /* @@ -479,7 +479,7 @@ int mbedtls_x509_crl_parse_der( mbedtls_x509_crl *chain, if( ret != 0 ) { mbedtls_x509_crl_free( crl ); - return( ret ); + return ret ; } } @@ -499,7 +499,7 @@ int mbedtls_x509_crl_parse_der( mbedtls_x509_crl *chain, if( ( ret = mbedtls_x509_get_alg( &p, end, &sig_oid2, &sig_params2 ) ) != 0 ) { mbedtls_x509_crl_free( crl ); - return( ret ); + return ret ; } if( crl->sig_oid.len != sig_oid2.len || @@ -509,13 +509,13 @@ int mbedtls_x509_crl_parse_der( mbedtls_x509_crl *chain, memcmp( sig_params1.p, sig_params2.p, sig_params1.len ) != 0 ) ) { mbedtls_x509_crl_free( crl ); - return( MBEDTLS_ERR_X509_SIG_MISMATCH ); + return MBEDTLS_ERR_X509_SIG_MISMATCH ; } if( ( ret = mbedtls_x509_get_sig( &p, end, &crl->sig ) ) != 0 ) { mbedtls_x509_crl_free( crl ); - return( ret ); + return ret ; } if( p != end ) @@ -525,7 +525,7 @@ int mbedtls_x509_crl_parse_der( mbedtls_x509_crl *chain, MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) ); } - return( 0 ); + return 0 ; } /* @@ -540,7 +540,7 @@ int mbedtls_x509_crl_parse( mbedtls_x509_crl *chain, const unsigned char *buf, s int is_pem = 0; if( chain == NULL || buf == NULL ) - return( MBEDTLS_ERR_X509_BAD_INPUT_DATA ); + return MBEDTLS_ERR_X509_BAD_INPUT_DATA ; do { @@ -570,13 +570,13 @@ int mbedtls_x509_crl_parse( mbedtls_x509_crl *chain, const unsigned char *buf, s pem.buf, pem.buflen ) ) != 0 ) { mbedtls_pem_free( &pem ); - return( ret ); + return ret ; } } else if( is_pem ) { mbedtls_pem_free( &pem ); - return( ret ); + return ret ; } mbedtls_pem_free( &pem ); @@ -586,10 +586,10 @@ int mbedtls_x509_crl_parse( mbedtls_x509_crl *chain, const unsigned char *buf, s while( is_pem && buflen > 1 ); if( is_pem ) - return( 0 ); + return 0 ; else #endif /* MBEDTLS_PEM_PARSE_C */ - return( mbedtls_x509_crl_parse_der( chain, buf, buflen ) ); + return mbedtls_x509_crl_parse_der( chain, buf, buflen ) ; } #if defined(MBEDTLS_FS_IO) @@ -603,14 +603,14 @@ int mbedtls_x509_crl_parse_file( mbedtls_x509_crl *chain, const char *path ) unsigned char *buf; if( ( ret = mbedtls_pk_load_file( path, &buf, &n ) ) != 0 ) - return( ret ); + return ret ; ret = mbedtls_x509_crl_parse( chain, buf, n ); mbedtls_platform_zeroize( buf, n ); mbedtls_free( buf ); - return( ret ); + return ret ; } #endif /* MBEDTLS_FS_IO */ diff --git a/library/x509_crt.c b/library/x509_crt.c index c8654445dd..cf3f91a894 100644 --- a/library/x509_crt.c +++ b/library/x509_crt.c @@ -185,12 +185,12 @@ static int x509_profile_check_md_alg( const mbedtls_x509_crt_profile *profile, mbedtls_md_type_t md_alg ) { if( md_alg == MBEDTLS_MD_NONE ) - return( -1 ); + return -1 ; if( ( profile->allowed_mds & MBEDTLS_X509_ID_FLAG( md_alg ) ) != 0 ) - return( 0 ); + return 0 ; - return( -1 ); + return -1 ; } /* @@ -201,12 +201,12 @@ static int x509_profile_check_pk_alg( const mbedtls_x509_crt_profile *profile, mbedtls_pk_type_t pk_alg ) { if( pk_alg == MBEDTLS_PK_NONE ) - return( -1 ); + return -1 ; if( ( profile->allowed_pks & MBEDTLS_X509_ID_FLAG( pk_alg ) ) != 0 ) - return( 0 ); + return 0 ; - return( -1 ); + return -1 ; } /* @@ -222,9 +222,9 @@ static int x509_profile_check_key( const mbedtls_x509_crt_profile *profile, if( pk_alg == MBEDTLS_PK_RSA || pk_alg == MBEDTLS_PK_RSASSA_PSS ) { if( mbedtls_pk_get_bitlen( pk ) >= profile->rsa_min_bitlen ) - return( 0 ); + return 0 ; - return( -1 ); + return -1 ; } #endif @@ -236,16 +236,16 @@ static int x509_profile_check_key( const mbedtls_x509_crt_profile *profile, const mbedtls_ecp_group_id gid = mbedtls_pk_ec( *pk )->grp.id; if( gid == MBEDTLS_ECP_DP_NONE ) - return( -1 ); + return -1 ; if( ( profile->allowed_curves & MBEDTLS_X509_ID_FLAG( gid ) ) != 0 ) - return( 0 ); + return 0 ; - return( -1 ); + return -1 ; } #endif - return( -1 ); + return -1 ; } /* @@ -271,10 +271,10 @@ static int x509_memcasecmp( const void *s1, const void *s2, size_t len ) continue; } - return( -1 ); + return -1 ; } - return( 0 ); + return 0 ; } /* @@ -287,7 +287,7 @@ static int x509_check_wildcard( const char *cn, const mbedtls_x509_buf *name ) /* We can't have a match if there is no wildcard to match */ if( name->len < 3 || name->p[0] != '*' || name->p[1] != '.' ) - return( -1 ); + return -1 ; for( i = 0; i < cn_len; ++i ) { @@ -299,15 +299,15 @@ static int x509_check_wildcard( const char *cn, const mbedtls_x509_buf *name ) } if( cn_idx == 0 ) - return( -1 ); + return -1 ; if( cn_len - cn_idx == name->len - 1 && x509_memcasecmp( name->p + 1, cn + cn_idx, name->len - 1 ) == 0 ) { - return( 0 ); + return 0 ; } - return( -1 ); + return -1 ; } /* @@ -322,7 +322,7 @@ static int x509_string_cmp( const mbedtls_x509_buf *a, const mbedtls_x509_buf *b a->len == b->len && memcmp( a->p, b->p, b->len ) == 0 ) { - return( 0 ); + return 0 ; } if( ( a->tag == MBEDTLS_ASN1_UTF8_STRING || a->tag == MBEDTLS_ASN1_PRINTABLE_STRING ) && @@ -330,10 +330,10 @@ static int x509_string_cmp( const mbedtls_x509_buf *a, const mbedtls_x509_buf *b a->len == b->len && x509_memcasecmp( a->p, b->p, b->len ) == 0 ) { - return( 0 ); + return 0 ; } - return( -1 ); + return -1 ; } /* @@ -352,30 +352,30 @@ static int x509_name_cmp( const mbedtls_x509_name *a, const mbedtls_x509_name *b while( a != NULL || b != NULL ) { if( a == NULL || b == NULL ) - return( -1 ); + return -1 ; /* type */ if( a->oid.tag != b->oid.tag || a->oid.len != b->oid.len || memcmp( a->oid.p, b->oid.p, b->oid.len ) != 0 ) { - return( -1 ); + return -1 ; } /* value */ if( x509_string_cmp( &a->val, &b->val ) != 0 ) - return( -1 ); + return -1 ; /* structure of the list of sets */ if( a->next_merged != b->next_merged ) - return( -1 ); + return -1 ; a = a->next; b = b->next; } /* a == NULL == b */ - return( 0 ); + return 0 ; } /* @@ -415,22 +415,22 @@ static int x509_get_version( unsigned char **p, if( ret == MBEDTLS_ERR_ASN1_UNEXPECTED_TAG ) { *ver = 0; - return( 0 ); + return 0 ; } - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_FORMAT, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_FORMAT, ret ) ; } end = *p + len; if( ( ret = mbedtls_asn1_get_int( p, end, ver ) ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_VERSION, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_VERSION, ret ) ; if( *p != end ) return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_VERSION, MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) ); - return( 0 ); + return 0 ; } /* @@ -448,21 +448,21 @@ static int x509_get_dates( unsigned char **p, if( ( ret = mbedtls_asn1_get_tag( p, end, &len, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_DATE, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_DATE, ret ) ; end = *p + len; if( ( ret = mbedtls_x509_get_time( p, end, from ) ) != 0 ) - return( ret ); + return ret ; if( ( ret = mbedtls_x509_get_time( p, end, to ) ) != 0 ) - return( ret ); + return ret ; if( *p != end ) return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_DATE, MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) ); - return( 0 ); + return 0 ; } /* @@ -475,7 +475,7 @@ static int x509_get_uid( unsigned char **p, int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; if( *p == end ) - return( 0 ); + return 0 ; uid->tag = **p; @@ -483,15 +483,15 @@ static int x509_get_uid( unsigned char **p, MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED | n ) ) != 0 ) { if( ret == MBEDTLS_ERR_ASN1_UNEXPECTED_TAG ) - return( 0 ); + return 0 ; - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_FORMAT, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_FORMAT, ret ) ; } uid->p = *p; *p += uid->len; - return( 0 ); + return 0 ; } static int x509_get_basic_constraints( unsigned char **p, @@ -512,10 +512,10 @@ static int x509_get_basic_constraints( unsigned char **p, if( ( ret = mbedtls_asn1_get_tag( p, end, &len, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ; if( *p == end ) - return( 0 ); + return 0 ; if( ( ret = mbedtls_asn1_get_bool( p, end, ca_istrue ) ) != 0 ) { @@ -523,17 +523,17 @@ static int x509_get_basic_constraints( unsigned char **p, ret = mbedtls_asn1_get_int( p, end, ca_istrue ); if( ret != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ; if( *ca_istrue != 0 ) *ca_istrue = 1; } if( *p == end ) - return( 0 ); + return 0 ; if( ( ret = mbedtls_asn1_get_int( p, end, max_pathlen ) ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ; if( *p != end ) return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, @@ -547,7 +547,7 @@ static int x509_get_basic_constraints( unsigned char **p, (*max_pathlen)++; - return( 0 ); + return 0 ; } static int x509_get_ns_cert_type( unsigned char **p, @@ -558,7 +558,7 @@ static int x509_get_ns_cert_type( unsigned char **p, mbedtls_x509_bitstring bs = { 0, 0, NULL }; if( ( ret = mbedtls_asn1_get_bitstring( p, end, &bs ) ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ; if( bs.len != 1 ) return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, @@ -566,7 +566,7 @@ static int x509_get_ns_cert_type( unsigned char **p, /* Get actual bitstring */ *ns_cert_type = *bs.p; - return( 0 ); + return 0 ; } static int x509_get_key_usage( unsigned char **p, @@ -578,7 +578,7 @@ static int x509_get_key_usage( unsigned char **p, mbedtls_x509_bitstring bs = { 0, 0, NULL }; if( ( ret = mbedtls_asn1_get_bitstring( p, end, &bs ) ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ; if( bs.len < 1 ) return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, @@ -591,7 +591,7 @@ static int x509_get_key_usage( unsigned char **p, *key_usage |= (unsigned int) bs.p[i] << (8*i); } - return( 0 ); + return 0 ; } /* @@ -606,14 +606,14 @@ static int x509_get_ext_key_usage( unsigned char **p, int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; if( ( ret = mbedtls_asn1_get_sequence_of( p, end, ext_key_usage, MBEDTLS_ASN1_OID ) ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ; /* Sequence length must be >= 1 */ if( ext_key_usage->buf.p == NULL ) return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, MBEDTLS_ERR_ASN1_INVALID_LENGTH ) ); - return( 0 ); + return 0 ; } /* @@ -656,7 +656,7 @@ static int x509_get_subject_alt_name( unsigned char **p, /* Get main sequence tag */ if( ( ret = mbedtls_asn1_get_tag( p, end, &len, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ; if( *p + len != end ) return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, @@ -670,7 +670,7 @@ static int x509_get_subject_alt_name( unsigned char **p, tag = **p; (*p)++; if( ( ret = mbedtls_asn1_get_len( p, end, &tag_len ) ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ; if( ( tag & MBEDTLS_ASN1_TAG_CLASS_MASK ) != MBEDTLS_ASN1_CONTEXT_SPECIFIC ) @@ -700,14 +700,14 @@ static int x509_get_subject_alt_name( unsigned char **p, mbedtls_free( seq_prv ); } subject_alt_name->next = NULL; - return( ret ); + return ret ; } /* Allocate and assign next pointer */ if( cur->buf.p != NULL ) { if( cur->next != NULL ) - return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS ); + return MBEDTLS_ERR_X509_INVALID_EXTENSIONS ; cur->next = mbedtls_calloc( 1, sizeof( mbedtls_asn1_sequence ) ); @@ -732,7 +732,7 @@ static int x509_get_subject_alt_name( unsigned char **p, return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) ); - return( 0 ); + return 0 ; } /* @@ -797,7 +797,7 @@ static int x509_get_certificate_policies( unsigned char **p, ret = mbedtls_asn1_get_tag( p, end, &len, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ); if( ret != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ; if( *p + len != end ) return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, @@ -820,13 +820,13 @@ static int x509_get_certificate_policies( unsigned char **p, */ if( ( ret = mbedtls_asn1_get_tag( p, end, &len, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ; policy_end = *p + len; if( ( ret = mbedtls_asn1_get_tag( p, policy_end, &len, MBEDTLS_ASN1_OID ) ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ; policy_oid.tag = MBEDTLS_ASN1_OID; policy_oid.len = len; @@ -848,7 +848,7 @@ static int x509_get_certificate_policies( unsigned char **p, if( cur->buf.p != NULL ) { if( cur->next != NULL ) - return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS ); + return MBEDTLS_ERR_X509_INVALID_EXTENSIONS ; cur->next = mbedtls_calloc( 1, sizeof( mbedtls_asn1_sequence ) ); @@ -874,7 +874,7 @@ static int x509_get_certificate_policies( unsigned char **p, { if( ( ret = mbedtls_asn1_get_tag( p, policy_end, &len, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ; /* * Skip the optional policy qualifiers. */ @@ -893,7 +893,7 @@ static int x509_get_certificate_policies( unsigned char **p, return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) ); - return( parse_ret ); + return parse_ret ; } /* @@ -911,10 +911,10 @@ static int x509_get_crt_ext( unsigned char **p, unsigned char *end_ext_data, *start_ext_octet, *end_ext_octet; if( *p == end ) - return( 0 ); + return 0 ; if( ( ret = mbedtls_x509_get_ext( p, end, &crt->v3_ext, 3 ) ) != 0 ) - return( ret ); + return ret ; end = crt->v3_ext.p + crt->v3_ext.len; while( *p < end ) @@ -931,14 +931,14 @@ static int x509_get_crt_ext( unsigned char **p, if( ( ret = mbedtls_asn1_get_tag( p, end, &len, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ; end_ext_data = *p + len; /* Get extension ID */ if( ( ret = mbedtls_asn1_get_tag( p, end_ext_data, &extn_oid.len, MBEDTLS_ASN1_OID ) ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ; extn_oid.tag = MBEDTLS_ASN1_OID; extn_oid.p = *p; @@ -947,12 +947,12 @@ static int x509_get_crt_ext( unsigned char **p, /* Get optional critical */ if( ( ret = mbedtls_asn1_get_bool( p, end_ext_data, &is_critical ) ) != 0 && ( ret != MBEDTLS_ERR_ASN1_UNEXPECTED_TAG ) ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ; /* Data should be octet string type */ if( ( ret = mbedtls_asn1_get_tag( p, end_ext_data, &len, MBEDTLS_ASN1_OCTET_STRING ) ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ; start_ext_octet = *p; end_ext_octet = *p + len; @@ -973,7 +973,7 @@ static int x509_get_crt_ext( unsigned char **p, { ret = cb( p_ctx, crt, &extn_oid, is_critical, *p, end_ext_octet ); if( ret != 0 && is_critical ) - return( ret ); + return ret ; *p = end_ext_octet; continue; } @@ -992,7 +992,7 @@ static int x509_get_crt_ext( unsigned char **p, /* Forbid repeated extensions */ if( ( crt->ext_types & ext_type ) != 0 ) - return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS ); + return MBEDTLS_ERR_X509_INVALID_EXTENSIONS ; crt->ext_types |= ext_type; @@ -1002,35 +1002,35 @@ static int x509_get_crt_ext( unsigned char **p, /* Parse basic constraints */ if( ( ret = x509_get_basic_constraints( p, end_ext_octet, &crt->ca_istrue, &crt->max_pathlen ) ) != 0 ) - return( ret ); + return ret ; break; case MBEDTLS_X509_EXT_KEY_USAGE: /* Parse key usage */ if( ( ret = x509_get_key_usage( p, end_ext_octet, &crt->key_usage ) ) != 0 ) - return( ret ); + return ret ; break; case MBEDTLS_X509_EXT_EXTENDED_KEY_USAGE: /* Parse extended key usage */ if( ( ret = x509_get_ext_key_usage( p, end_ext_octet, &crt->ext_key_usage ) ) != 0 ) - return( ret ); + return ret ; break; case MBEDTLS_X509_EXT_SUBJECT_ALT_NAME: /* Parse subject alt name */ if( ( ret = x509_get_subject_alt_name( p, end_ext_octet, &crt->subject_alt_names ) ) != 0 ) - return( ret ); + return ret ; break; case MBEDTLS_X509_EXT_NS_CERT_TYPE: /* Parse netscape certificate type */ if( ( ret = x509_get_ns_cert_type( p, end_ext_octet, &crt->ns_cert_type ) ) != 0 ) - return( ret ); + return ret ; break; case MBEDTLS_OID_X509_EXT_CERTIFICATE_POLICIES: @@ -1046,7 +1046,7 @@ static int x509_get_crt_ext( unsigned char **p, break; if( is_critical ) - return( ret ); + return ret ; else /* * If MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE is returned, then we @@ -1055,7 +1055,7 @@ static int x509_get_crt_ext( unsigned char **p, * unless the extension is critical. */ if( ret != MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE ) - return( ret ); + return ret ; } break; @@ -1066,7 +1066,7 @@ static int x509_get_crt_ext( unsigned char **p, * skip the extension. */ if( is_critical ) - return( MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE ; else *p = end_ext_octet; } @@ -1076,7 +1076,7 @@ static int x509_get_crt_ext( unsigned char **p, return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) ); - return( 0 ); + return 0 ; } /* @@ -1102,7 +1102,7 @@ static int x509_crt_parse_der_core( mbedtls_x509_crt *crt, * Check for valid input */ if( crt == NULL || buf == NULL ) - return( MBEDTLS_ERR_X509_BAD_INPUT_DATA ); + return MBEDTLS_ERR_X509_BAD_INPUT_DATA ; /* Use the original buffer until we figure out actual length. */ p = (unsigned char*) buf; @@ -1119,7 +1119,7 @@ static int x509_crt_parse_der_core( mbedtls_x509_crt *crt, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 ) { mbedtls_x509_crt_free( crt ); - return( MBEDTLS_ERR_X509_INVALID_FORMAT ); + return MBEDTLS_ERR_X509_INVALID_FORMAT ; } end = crt_end = p + len; @@ -1129,7 +1129,7 @@ static int x509_crt_parse_der_core( mbedtls_x509_crt *crt, /* Create and populate a new buffer for the raw field. */ crt->raw.p = p = mbedtls_calloc( 1, crt->raw.len ); if( crt->raw.p == NULL ) - return( MBEDTLS_ERR_X509_ALLOC_FAILED ); + return MBEDTLS_ERR_X509_ALLOC_FAILED ; memcpy( crt->raw.p, buf, crt->raw.len ); crt->own_buffer = 1; @@ -1152,7 +1152,7 @@ static int x509_crt_parse_der_core( mbedtls_x509_crt *crt, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 ) { mbedtls_x509_crt_free( crt ); - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_FORMAT, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_FORMAT, ret ) ; } end = p + len; @@ -1171,13 +1171,13 @@ static int x509_crt_parse_der_core( mbedtls_x509_crt *crt, &sig_params1 ) ) != 0 ) { mbedtls_x509_crt_free( crt ); - return( ret ); + return ret ; } if( crt->version < 0 || crt->version > 2 ) { mbedtls_x509_crt_free( crt ); - return( MBEDTLS_ERR_X509_UNKNOWN_VERSION ); + return MBEDTLS_ERR_X509_UNKNOWN_VERSION ; } crt->version++; @@ -1187,7 +1187,7 @@ static int x509_crt_parse_der_core( mbedtls_x509_crt *crt, &crt->sig_opts ) ) != 0 ) { mbedtls_x509_crt_free( crt ); - return( ret ); + return ret ; } /* @@ -1199,13 +1199,13 @@ static int x509_crt_parse_der_core( mbedtls_x509_crt *crt, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 ) { mbedtls_x509_crt_free( crt ); - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_FORMAT, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_FORMAT, ret ) ; } if( ( ret = mbedtls_x509_get_name( &p, p + len, &crt->issuer ) ) != 0 ) { mbedtls_x509_crt_free( crt ); - return( ret ); + return ret ; } crt->issuer_raw.len = p - crt->issuer_raw.p; @@ -1220,7 +1220,7 @@ static int x509_crt_parse_der_core( mbedtls_x509_crt *crt, &crt->valid_to ) ) != 0 ) { mbedtls_x509_crt_free( crt ); - return( ret ); + return ret ; } /* @@ -1232,13 +1232,13 @@ static int x509_crt_parse_der_core( mbedtls_x509_crt *crt, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 ) { mbedtls_x509_crt_free( crt ); - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_FORMAT, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_FORMAT, ret ) ; } if( len && ( ret = mbedtls_x509_get_name( &p, p + len, &crt->subject ) ) != 0 ) { mbedtls_x509_crt_free( crt ); - return( ret ); + return ret ; } crt->subject_raw.len = p - crt->subject_raw.p; @@ -1250,7 +1250,7 @@ static int x509_crt_parse_der_core( mbedtls_x509_crt *crt, if( ( ret = mbedtls_pk_parse_subpubkey( &p, end, &crt->pk ) ) != 0 ) { mbedtls_x509_crt_free( crt ); - return( ret ); + return ret ; } crt->pk_raw.len = p - crt->pk_raw.p; @@ -1268,7 +1268,7 @@ static int x509_crt_parse_der_core( mbedtls_x509_crt *crt, if( ret != 0 ) { mbedtls_x509_crt_free( crt ); - return( ret ); + return ret ; } } @@ -1278,7 +1278,7 @@ static int x509_crt_parse_der_core( mbedtls_x509_crt *crt, if( ret != 0 ) { mbedtls_x509_crt_free( crt ); - return( ret ); + return ret ; } } @@ -1288,7 +1288,7 @@ static int x509_crt_parse_der_core( mbedtls_x509_crt *crt, if( ret != 0 ) { mbedtls_x509_crt_free( crt ); - return( ret ); + return ret ; } } @@ -1311,7 +1311,7 @@ static int x509_crt_parse_der_core( mbedtls_x509_crt *crt, if( ( ret = mbedtls_x509_get_alg( &p, end, &sig_oid2, &sig_params2 ) ) != 0 ) { mbedtls_x509_crt_free( crt ); - return( ret ); + return ret ; } if( crt->sig_oid.len != sig_oid2.len || @@ -1322,13 +1322,13 @@ static int x509_crt_parse_der_core( mbedtls_x509_crt *crt, memcmp( sig_params1.p, sig_params2.p, sig_params1.len ) != 0 ) ) { mbedtls_x509_crt_free( crt ); - return( MBEDTLS_ERR_X509_SIG_MISMATCH ); + return MBEDTLS_ERR_X509_SIG_MISMATCH ; } if( ( ret = mbedtls_x509_get_sig( &p, end, &crt->sig ) ) != 0 ) { mbedtls_x509_crt_free( crt ); - return( ret ); + return ret ; } if( p != end ) @@ -1338,7 +1338,7 @@ static int x509_crt_parse_der_core( mbedtls_x509_crt *crt, MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) ); } - return( 0 ); + return 0 ; } /* @@ -1359,7 +1359,7 @@ static int mbedtls_x509_crt_parse_der_internal( mbedtls_x509_crt *chain, * Check for valid input */ if( crt == NULL || buf == NULL ) - return( MBEDTLS_ERR_X509_BAD_INPUT_DATA ); + return MBEDTLS_ERR_X509_BAD_INPUT_DATA ; while( crt->version != 0 && crt->next != NULL ) { @@ -1375,7 +1375,7 @@ static int mbedtls_x509_crt_parse_der_internal( mbedtls_x509_crt *chain, crt->next = mbedtls_calloc( 1, sizeof( mbedtls_x509_crt ) ); if( crt->next == NULL ) - return( MBEDTLS_ERR_X509_ALLOC_FAILED ); + return MBEDTLS_ERR_X509_ALLOC_FAILED ; prev = crt; mbedtls_x509_crt_init( crt->next ); @@ -1391,17 +1391,17 @@ static int mbedtls_x509_crt_parse_der_internal( mbedtls_x509_crt *chain, if( crt != chain ) mbedtls_free( crt ); - return( ret ); + return ret ; } - return( 0 ); + return 0 ; } int mbedtls_x509_crt_parse_der_nocopy( mbedtls_x509_crt *chain, const unsigned char *buf, size_t buflen ) { - return( mbedtls_x509_crt_parse_der_internal( chain, buf, buflen, 0, NULL, NULL ) ); + return mbedtls_x509_crt_parse_der_internal( chain, buf, buflen, 0, NULL, NULL ) ; } int mbedtls_x509_crt_parse_der_with_ext_cb( mbedtls_x509_crt *chain, @@ -1411,14 +1411,14 @@ int mbedtls_x509_crt_parse_der_with_ext_cb( mbedtls_x509_crt *chain, mbedtls_x509_crt_ext_cb_t cb, void *p_ctx ) { - return( mbedtls_x509_crt_parse_der_internal( chain, buf, buflen, make_copy, cb, p_ctx ) ); + return mbedtls_x509_crt_parse_der_internal( chain, buf, buflen, make_copy, cb, p_ctx ) ; } int mbedtls_x509_crt_parse_der( mbedtls_x509_crt *chain, const unsigned char *buf, size_t buflen ) { - return( mbedtls_x509_crt_parse_der_internal( chain, buf, buflen, 1, NULL, NULL ) ); + return mbedtls_x509_crt_parse_der_internal( chain, buf, buflen, 1, NULL, NULL ) ; } /* @@ -1438,7 +1438,7 @@ int mbedtls_x509_crt_parse( mbedtls_x509_crt *chain, * Check for valid input */ if( chain == NULL || buf == NULL ) - return( MBEDTLS_ERR_X509_BAD_INPUT_DATA ); + return MBEDTLS_ERR_X509_BAD_INPUT_DATA ; /* * Determine buffer content. Buffer contains either one DER certificate or @@ -1485,7 +1485,7 @@ int mbedtls_x509_crt_parse( mbedtls_x509_crt *chain, } else if( ret == MBEDTLS_ERR_PEM_BAD_INPUT_DATA ) { - return( ret ); + return ret ; } else if( ret != MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT ) { @@ -1516,7 +1516,7 @@ int mbedtls_x509_crt_parse( mbedtls_x509_crt *chain, * Quit parsing on a memory error */ if( ret == MBEDTLS_ERR_X509_ALLOC_FAILED ) - return( ret ); + return ret ; if( first_error == 0 ) first_error = ret; @@ -1530,11 +1530,11 @@ int mbedtls_x509_crt_parse( mbedtls_x509_crt *chain, } if( success ) - return( total_failed ); + return total_failed ; else if( first_error ) - return( first_error ); + return first_error ; else - return( MBEDTLS_ERR_X509_CERT_UNKNOWN_FORMAT ); + return MBEDTLS_ERR_X509_CERT_UNKNOWN_FORMAT ; #endif /* MBEDTLS_PEM_PARSE_C */ } @@ -1549,14 +1549,14 @@ int mbedtls_x509_crt_parse_file( mbedtls_x509_crt *chain, const char *path ) unsigned char *buf; if( ( ret = mbedtls_pk_load_file( path, &buf, &n ) ) != 0 ) - return( ret ); + return ret ; ret = mbedtls_x509_crt_parse( chain, buf, n ); mbedtls_platform_zeroize( buf, n ); mbedtls_free( buf ); - return( ret ); + return ret ; } int mbedtls_x509_crt_parse_path( mbedtls_x509_crt *chain, const char *path ) @@ -1573,7 +1573,7 @@ int mbedtls_x509_crt_parse_path( mbedtls_x509_crt *chain, const char *path ) HANDLE hFind; if( len > MAX_PATH - 3 ) - return( MBEDTLS_ERR_X509_BAD_INPUT_DATA ); + return MBEDTLS_ERR_X509_BAD_INPUT_DATA ; memset( szDir, 0, sizeof(szDir) ); memset( filename, 0, MAX_PATH ); @@ -1585,11 +1585,11 @@ int mbedtls_x509_crt_parse_path( mbedtls_x509_crt *chain, const char *path ) w_ret = MultiByteToWideChar( CP_ACP, 0, filename, (int)len, szDir, MAX_PATH - 3 ); if( w_ret == 0 ) - return( MBEDTLS_ERR_X509_BAD_INPUT_DATA ); + return MBEDTLS_ERR_X509_BAD_INPUT_DATA ; hFind = FindFirstFileW( szDir, &file_data ); if( hFind == INVALID_HANDLE_VALUE ) - return( MBEDTLS_ERR_X509_FILE_IO_ERROR ); + return MBEDTLS_ERR_X509_FILE_IO_ERROR ; len = MAX_PATH - len; do @@ -1631,13 +1631,13 @@ cleanup: DIR *dir = opendir( path ); if( dir == NULL ) - return( MBEDTLS_ERR_X509_FILE_IO_ERROR ); + return MBEDTLS_ERR_X509_FILE_IO_ERROR ; #if defined(MBEDTLS_THREADING_C) if( ( ret = mbedtls_mutex_lock( &mbedtls_threading_readdir_mutex ) ) != 0 ) { closedir( dir ); - return( ret ); + return ret ; } #endif /* MBEDTLS_THREADING_C */ @@ -1645,10 +1645,10 @@ cleanup: 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; @@ -1681,7 +1681,7 @@ cleanup: #endif /* _WIN32 */ - return( ret ); + return ret ; } #endif /* MBEDTLS_FS_IO */ @@ -1713,12 +1713,12 @@ static int x509_get_other_name( const mbedtls_x509_buf *subject_alt_name, /* * The given subject alternative name is not of type "othername". */ - return( MBEDTLS_ERR_X509_BAD_INPUT_DATA ); + return MBEDTLS_ERR_X509_BAD_INPUT_DATA ; } if( ( ret = mbedtls_asn1_get_tag( &p, end, &len, MBEDTLS_ASN1_OID ) ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ; cur_oid.tag = MBEDTLS_ASN1_OID; cur_oid.p = p; @@ -1729,7 +1729,7 @@ static int x509_get_other_name( const mbedtls_x509_buf *subject_alt_name, */ if( MBEDTLS_OID_CMP( MBEDTLS_OID_ON_HW_MODULE_NAME, &cur_oid ) != 0 ) { - return( MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE ; } if( p + len >= end ) @@ -1741,14 +1741,14 @@ static int x509_get_other_name( const mbedtls_x509_buf *subject_alt_name, p += len; if( ( ret = mbedtls_asn1_get_tag( &p, end, &len, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_CONTEXT_SPECIFIC ) ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ; if( ( ret = mbedtls_asn1_get_tag( &p, end, &len, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ; if( ( ret = mbedtls_asn1_get_tag( &p, end, &len, MBEDTLS_ASN1_OID ) ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ; other_name->value.hardware_module_name.oid.tag = MBEDTLS_ASN1_OID; other_name->value.hardware_module_name.oid.p = p; @@ -1763,7 +1763,7 @@ static int x509_get_other_name( const mbedtls_x509_buf *subject_alt_name, p += len; if( ( ret = mbedtls_asn1_get_tag( &p, end, &len, MBEDTLS_ASN1_OCTET_STRING ) ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ; other_name->value.hardware_module_name.val.tag = MBEDTLS_ASN1_OCTET_STRING; other_name->value.hardware_module_name.val.p = p; @@ -1776,7 +1776,7 @@ static int x509_get_other_name( const mbedtls_x509_buf *subject_alt_name, return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) ); } - return( 0 ); + return 0 ; } int mbedtls_x509_parse_subject_alt_name( const mbedtls_x509_buf *san_buf, @@ -1796,7 +1796,7 @@ int mbedtls_x509_parse_subject_alt_name( const mbedtls_x509_buf *san_buf, ret = x509_get_other_name( san_buf, &other_name ); if( ret != 0 ) - return( ret ); + return ret ; memset( san, 0, sizeof( mbedtls_x509_subject_alternative_name ) ); san->type = MBEDTLS_X509_SAN_OTHER_NAME; @@ -1824,9 +1824,9 @@ int mbedtls_x509_parse_subject_alt_name( const mbedtls_x509_buf *san_buf, * Type not supported */ default: - return( MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE ; } - return( 0 ); + return 0 ; } #if !defined(MBEDTLS_X509_REMOVE_INFO) @@ -1891,7 +1891,7 @@ static int x509_info_subject_alt_name( char **buf, size_t *size, if( other_name->value.hardware_module_name.val.len >= n ) { *p = '\0'; - return( MBEDTLS_ERR_X509_BUFFER_TOO_SMALL ); + return MBEDTLS_ERR_X509_BUFFER_TOO_SMALL ; } memcpy( p, other_name->value.hardware_module_name.val.p, @@ -1914,7 +1914,7 @@ static int x509_info_subject_alt_name( char **buf, size_t *size, if( san.san.unstructured_name.len >= n ) { *p = '\0'; - return( MBEDTLS_ERR_X509_BUFFER_TOO_SMALL ); + return MBEDTLS_ERR_X509_BUFFER_TOO_SMALL ; } memcpy( p, san.san.unstructured_name.p, san.san.unstructured_name.len ); @@ -1940,7 +1940,7 @@ static int x509_info_subject_alt_name( char **buf, size_t *size, *size = n; *buf = p; - return( 0 ); + return 0 ; } #define PRINT_ITEM(i) \ @@ -1974,7 +1974,7 @@ static int x509_info_cert_type( char **buf, size_t *size, *size = n; *buf = p; - return( 0 ); + return 0 ; } #define KEY_USAGE(code,name) \ @@ -2002,7 +2002,7 @@ static int x509_info_key_usage( char **buf, size_t *size, *size = n; *buf = p; - return( 0 ); + return 0 ; } static int x509_info_ext_key_usage( char **buf, size_t *size, @@ -2031,7 +2031,7 @@ static int x509_info_ext_key_usage( char **buf, size_t *size, *size = n; *buf = p; - return( 0 ); + return 0 ; } static int x509_info_cert_policies( char **buf, size_t *size, @@ -2060,7 +2060,7 @@ static int x509_info_cert_policies( char **buf, size_t *size, *size = n; *buf = p; - return( 0 ); + return 0 ; } /* @@ -2132,7 +2132,7 @@ int mbedtls_x509_crt_info( char *buf, size_t size, const char *prefix, if( ( ret = mbedtls_x509_key_size_helper( key_size_str, BEFORE_COLON, mbedtls_pk_get_name( &crt->pk ) ) ) != 0 ) { - return( ret ); + return ret ; } ret = mbedtls_snprintf( p, n, "\n%s%-" BC "s: %d bits", prefix, key_size_str, @@ -2164,7 +2164,7 @@ int mbedtls_x509_crt_info( char *buf, size_t size, const char *prefix, if( ( ret = x509_info_subject_alt_name( &p, &n, &crt->subject_alt_names, prefix ) ) != 0 ) - return( ret ); + return ret ; } if( crt->ext_types & MBEDTLS_X509_EXT_NS_CERT_TYPE ) @@ -2173,7 +2173,7 @@ int mbedtls_x509_crt_info( char *buf, size_t size, const char *prefix, MBEDTLS_X509_SAFE_SNPRINTF; if( ( ret = x509_info_cert_type( &p, &n, crt->ns_cert_type ) ) != 0 ) - return( ret ); + return ret ; } if( crt->ext_types & MBEDTLS_X509_EXT_KEY_USAGE ) @@ -2182,7 +2182,7 @@ int mbedtls_x509_crt_info( char *buf, size_t size, const char *prefix, MBEDTLS_X509_SAFE_SNPRINTF; if( ( ret = x509_info_key_usage( &p, &n, crt->key_usage ) ) != 0 ) - return( ret ); + return ret ; } if( crt->ext_types & MBEDTLS_X509_EXT_EXTENDED_KEY_USAGE ) @@ -2192,7 +2192,7 @@ int mbedtls_x509_crt_info( char *buf, size_t size, const char *prefix, if( ( ret = x509_info_ext_key_usage( &p, &n, &crt->ext_key_usage ) ) != 0 ) - return( ret ); + return ret ; } if( crt->ext_types & MBEDTLS_OID_X509_EXT_CERTIFICATE_POLICIES ) @@ -2202,7 +2202,7 @@ int mbedtls_x509_crt_info( char *buf, size_t size, const char *prefix, if( ( ret = x509_info_cert_policies( &p, &n, &crt->certificate_policies ) ) != 0 ) - return( ret ); + return ret ; } ret = mbedtls_snprintf( p, n, "\n" ); @@ -2260,19 +2260,19 @@ int mbedtls_x509_crt_check_key_usage( const mbedtls_x509_crt *crt, | MBEDTLS_X509_KU_DECIPHER_ONLY; if( ( crt->ext_types & MBEDTLS_X509_EXT_KEY_USAGE ) == 0 ) - return( 0 ); + return 0 ; usage_must = usage & ~may_mask; if( ( ( crt->key_usage & ~may_mask ) & usage_must ) != usage_must ) - return( MBEDTLS_ERR_X509_BAD_INPUT_DATA ); + return MBEDTLS_ERR_X509_BAD_INPUT_DATA ; usage_may = usage & may_mask; if( ( ( crt->key_usage & may_mask ) | usage_may ) != usage_may ) - return( MBEDTLS_ERR_X509_BAD_INPUT_DATA ); + return MBEDTLS_ERR_X509_BAD_INPUT_DATA ; - return( 0 ); + return 0 ; } int mbedtls_x509_crt_check_extended_key_usage( const mbedtls_x509_crt *crt, @@ -2283,7 +2283,7 @@ int mbedtls_x509_crt_check_extended_key_usage( const mbedtls_x509_crt *crt, /* Extension is not mandatory, absent means no restriction */ if( ( crt->ext_types & MBEDTLS_X509_EXT_EXTENDED_KEY_USAGE ) == 0 ) - return( 0 ); + return 0 ; /* * Look for the requested usage (or wildcard ANY) in our list @@ -2295,14 +2295,14 @@ int mbedtls_x509_crt_check_extended_key_usage( const mbedtls_x509_crt *crt, if( cur_oid->len == usage_len && memcmp( cur_oid->p, usage_oid, usage_len ) == 0 ) { - return( 0 ); + return 0 ; } if( MBEDTLS_OID_CMP( MBEDTLS_OID_ANY_EXTENDED_KEY_USAGE, cur_oid ) == 0 ) - return( 0 ); + return 0 ; } - return( MBEDTLS_ERR_X509_BAD_INPUT_DATA ); + return MBEDTLS_ERR_X509_BAD_INPUT_DATA ; } #if defined(MBEDTLS_X509_CRL_PARSE_C) @@ -2318,13 +2318,13 @@ int mbedtls_x509_crt_is_revoked( const mbedtls_x509_crt *crt, const mbedtls_x509 if( crt->serial.len == cur->serial.len && memcmp( crt->serial.p, cur->serial.p, crt->serial.len ) == 0 ) { - return( 1 ); + return 1 ; } cur = cur->next; } - return( 0 ); + return 0 ; } /* @@ -2340,7 +2340,7 @@ static int x509_crt_verifycrl( mbedtls_x509_crt *crt, mbedtls_x509_crt *ca, const mbedtls_md_info_t *md_info; if( ca == NULL ) - return( flags ); + return flags ; while( crl_list != NULL ) { @@ -2410,7 +2410,7 @@ static int x509_crt_verifycrl( mbedtls_x509_crt *crt, mbedtls_x509_crt *ca, crl_list = crl_list->next; } - return( flags ); + return flags ; } #endif /* MBEDTLS_X509_CRL_PARSE_C */ @@ -2430,29 +2430,29 @@ static int x509_crt_check_signature( const mbedtls_x509_crt *child, /* Note: hash errors can happen only after an internal error */ if( mbedtls_md( md_info, child->tbs.p, child->tbs.len, hash ) != 0 ) - return( -1 ); + return -1 ; #else psa_hash_operation_t hash_operation = PSA_HASH_OPERATION_INIT; psa_algorithm_t hash_alg = mbedtls_psa_translate_md( child->sig_md ); if( psa_hash_setup( &hash_operation, hash_alg ) != PSA_SUCCESS ) - return( -1 ); + return -1 ; if( psa_hash_update( &hash_operation, child->tbs.p, child->tbs.len ) != PSA_SUCCESS ) { - return( -1 ); + return -1 ; } if( psa_hash_finish( &hash_operation, hash, sizeof( hash ), &hash_len ) != PSA_SUCCESS ) { - return( -1 ); + return -1 ; } #endif /* MBEDTLS_USE_PSA_CRYPTO */ /* Skip expensive computation on obvious mismatch */ if( ! mbedtls_pk_can_do( &parent->pk, child->sig_pk ) ) - return( -1 ); + return -1 ; #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE) if( rs_ctx != NULL && child->sig_pk == MBEDTLS_PK_ECDSA ) @@ -2484,7 +2484,7 @@ static int x509_crt_check_parent( const mbedtls_x509_crt *child, /* Parent must be the issuer */ if( x509_name_cmp( &child->issuer, &parent->subject ) != 0 ) - return( -1 ); + return -1 ; /* Parent must have the basicConstraints CA bit set as a general rule */ need_ca_bit = 1; @@ -2494,15 +2494,15 @@ static int x509_crt_check_parent( const mbedtls_x509_crt *child, need_ca_bit = 0; if( need_ca_bit && ! parent->ca_istrue ) - return( -1 ); + return -1 ; if( need_ca_bit && mbedtls_x509_crt_check_key_usage( parent, MBEDTLS_X509_KU_KEY_CERT_SIGN ) != 0 ) { - return( -1 ); + return -1 ; } - return( 0 ); + return 0 ; } /* @@ -2611,7 +2611,7 @@ check_signature: rs_ctx->fallback_parent = fallback_parent; rs_ctx->fallback_signature_is_good = fallback_signature_is_good; - return( ret ); + return ret ; } #else (void) ret; @@ -2646,7 +2646,7 @@ check_signature: *r_signature_is_good = fallback_signature_is_good; } - return( 0 ); + return 0 ; } /* @@ -2708,7 +2708,7 @@ static int x509_crt_find_parent( { /* save state */ rs_ctx->parent_is_trusted = *parent_is_trusted; - return( ret ); + return ret ; } #else (void) ret; @@ -2729,7 +2729,7 @@ static int x509_crt_find_parent( *signature_is_good = 0; } - return( 0 ); + return 0 ; } /* @@ -2746,7 +2746,7 @@ static int x509_crt_check_ee_locally_trusted( /* must be self-issued */ if( x509_name_cmp( &crt->issuer, &crt->subject ) != 0 ) - return( -1 ); + return -1 ; /* look for an exact match with trusted cert */ for( cur = trust_ca; cur != NULL; cur = cur->next ) @@ -2754,12 +2754,12 @@ static int x509_crt_check_ee_locally_trusted( if( crt->raw.len == cur->raw.len && memcmp( crt->raw.p, cur->raw.p, crt->raw.len ) == 0 ) { - return( 0 ); + return 0 ; } } /* too bad */ - return( -1 ); + return -1 ; } /* @@ -2864,7 +2864,7 @@ static int x509_crt_verify_chain( /* Stop here for trusted roots (but not for trusted EE certs) */ if( child_is_trusted ) - return( 0 ); + return 0 ; /* Check signature algorithm: MD & PK algs */ if( x509_profile_check_md_alg( profile, child->sig_md ) != 0 ) @@ -2877,7 +2877,7 @@ static int x509_crt_verify_chain( if( ver_chain->len == 1 && x509_crt_check_ee_locally_trusted( child, trust_ca ) == 0 ) { - return( 0 ); + return 0 ; } #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE) @@ -2895,7 +2895,7 @@ find_parent: ret = f_ca_cb( p_ca_cb, child, &ver_chain->trust_ca_cb_result ); if( ret != 0 ) - return( MBEDTLS_ERR_X509_FATAL_ERROR ); + return MBEDTLS_ERR_X509_FATAL_ERROR ; cur_trust_ca = ver_chain->trust_ca_cb_result; } @@ -2920,7 +2920,7 @@ find_parent: rs_ctx->self_cnt = self_cnt; rs_ctx->ver_chain = *ver_chain; /* struct copy */ - return( ret ); + return ret ; } #else (void) ret; @@ -2930,7 +2930,7 @@ find_parent: if( parent == NULL ) { *flags |= MBEDTLS_X509_BADCERT_NOT_TRUSTED; - return( 0 ); + return 0 ; } /* Count intermediate self-issued (not necessarily self-signed) certs. @@ -2948,7 +2948,7 @@ find_parent: ver_chain->len > MBEDTLS_X509_MAX_INTERMEDIATE_CA ) { /* return immediately to avoid overflow the chain array */ - return( MBEDTLS_ERR_X509_FATAL_ERROR ); + return MBEDTLS_ERR_X509_FATAL_ERROR ; } /* signature was checked while searching parent */ @@ -2984,16 +2984,16 @@ static int x509_crt_check_cn( const mbedtls_x509_buf *name, if( name->len == cn_len && x509_memcasecmp( cn, name->p, cn_len ) == 0 ) { - return( 0 ); + return 0 ; } /* try wildcard match */ if( x509_check_wildcard( cn, name ) == 0 ) { - return( 0 ); + return 0 ; } - return( -1 ); + return -1 ; } /* @@ -3007,12 +3007,12 @@ static int x509_crt_check_san( const mbedtls_x509_buf *name, /* dNSName */ if( san_type == MBEDTLS_X509_SAN_DNS_NAME ) - return( x509_crt_check_cn( name, cn, cn_len ) ); + return x509_crt_check_cn( name, cn, cn_len ) ; /* (We may handle other types here later.) */ /* Unrecognized type */ - return( -1 ); + return -1 ; } /* @@ -3074,12 +3074,12 @@ static int x509_crt_merge_flags_with_cb( if( NULL != f_vrfy ) if( ( ret = f_vrfy( p_vrfy, cur->crt, (int) i-1, &cur_flags ) ) != 0 ) - return( ret ); + return ret ; *flags |= cur_flags; } - return( 0 ); + return 0 ; } /* @@ -3174,13 +3174,13 @@ exit: if( ret != 0 ) { *flags = (uint32_t) -1; - return( ret ); + return ret ; } if( *flags != 0 ) - return( MBEDTLS_ERR_X509_CERT_VERIFY_FAILED ); + return MBEDTLS_ERR_X509_CERT_VERIFY_FAILED ; - return( 0 ); + return 0 ; } diff --git a/library/x509_csr.c b/library/x509_csr.c index 25069b2a4c..bdcc2009d8 100644 --- a/library/x509_csr.c +++ b/library/x509_csr.c @@ -70,13 +70,13 @@ static int x509_csr_get_version( unsigned char **p, if( ret == MBEDTLS_ERR_ASN1_UNEXPECTED_TAG ) { *ver = 0; - return( 0 ); + return 0 ; } - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_VERSION, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_VERSION, ret ) ; } - return( 0 ); + return 0 ; } /* @@ -96,7 +96,7 @@ int mbedtls_x509_csr_parse_der( mbedtls_x509_csr *csr, * Check for valid input */ if( csr == NULL || buf == NULL || buflen == 0 ) - return( MBEDTLS_ERR_X509_BAD_INPUT_DATA ); + return MBEDTLS_ERR_X509_BAD_INPUT_DATA ; mbedtls_x509_csr_init( csr ); @@ -106,7 +106,7 @@ int mbedtls_x509_csr_parse_der( mbedtls_x509_csr *csr, p = mbedtls_calloc( 1, len = buflen ); if( p == NULL ) - return( MBEDTLS_ERR_X509_ALLOC_FAILED ); + return MBEDTLS_ERR_X509_ALLOC_FAILED ; memcpy( p, buf, buflen ); @@ -125,7 +125,7 @@ int mbedtls_x509_csr_parse_der( mbedtls_x509_csr *csr, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 ) { mbedtls_x509_csr_free( csr ); - return( MBEDTLS_ERR_X509_INVALID_FORMAT ); + return MBEDTLS_ERR_X509_INVALID_FORMAT ; } if( len != (size_t) ( end - p ) ) @@ -144,7 +144,7 @@ int mbedtls_x509_csr_parse_der( mbedtls_x509_csr *csr, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 ) { mbedtls_x509_csr_free( csr ); - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_FORMAT, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_FORMAT, ret ) ; } end = p + len; @@ -156,13 +156,13 @@ int mbedtls_x509_csr_parse_der( mbedtls_x509_csr *csr, if( ( ret = x509_csr_get_version( &p, end, &csr->version ) ) != 0 ) { mbedtls_x509_csr_free( csr ); - return( ret ); + return ret ; } if( csr->version != 0 ) { mbedtls_x509_csr_free( csr ); - return( MBEDTLS_ERR_X509_UNKNOWN_VERSION ); + return MBEDTLS_ERR_X509_UNKNOWN_VERSION ; } csr->version++; @@ -176,13 +176,13 @@ int mbedtls_x509_csr_parse_der( mbedtls_x509_csr *csr, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 ) { mbedtls_x509_csr_free( csr ); - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_FORMAT, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_FORMAT, ret ) ; } if( ( ret = mbedtls_x509_get_name( &p, p + len, &csr->subject ) ) != 0 ) { mbedtls_x509_csr_free( csr ); - return( ret ); + return ret ; } csr->subject_raw.len = p - csr->subject_raw.p; @@ -193,7 +193,7 @@ int mbedtls_x509_csr_parse_der( mbedtls_x509_csr *csr, if( ( ret = mbedtls_pk_parse_subpubkey( &p, end, &csr->pk ) ) != 0 ) { mbedtls_x509_csr_free( csr ); - return( ret ); + return ret ; } /* @@ -210,7 +210,7 @@ int mbedtls_x509_csr_parse_der( mbedtls_x509_csr *csr, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_CONTEXT_SPECIFIC ) ) != 0 ) { mbedtls_x509_csr_free( csr ); - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_FORMAT, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_FORMAT, ret ) ; } p += len; @@ -224,7 +224,7 @@ int mbedtls_x509_csr_parse_der( mbedtls_x509_csr *csr, if( ( ret = mbedtls_x509_get_alg( &p, end, &csr->sig_oid, &sig_params ) ) != 0 ) { mbedtls_x509_csr_free( csr ); - return( ret ); + return ret ; } if( ( ret = mbedtls_x509_get_sig_alg( &csr->sig_oid, &sig_params, @@ -232,13 +232,13 @@ int mbedtls_x509_csr_parse_der( mbedtls_x509_csr *csr, &csr->sig_opts ) ) != 0 ) { mbedtls_x509_csr_free( csr ); - return( MBEDTLS_ERR_X509_UNKNOWN_SIG_ALG ); + return MBEDTLS_ERR_X509_UNKNOWN_SIG_ALG ; } if( ( ret = mbedtls_x509_get_sig( &p, end, &csr->sig ) ) != 0 ) { mbedtls_x509_csr_free( csr ); - return( ret ); + return ret ; } if( p != end ) @@ -248,7 +248,7 @@ int mbedtls_x509_csr_parse_der( mbedtls_x509_csr *csr, MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) ); } - return( 0 ); + return 0 ; } /* @@ -266,7 +266,7 @@ int mbedtls_x509_csr_parse( mbedtls_x509_csr *csr, const unsigned char *buf, siz * Check for valid input */ if( csr == NULL || buf == NULL || buflen == 0 ) - return( MBEDTLS_ERR_X509_BAD_INPUT_DATA ); + return MBEDTLS_ERR_X509_BAD_INPUT_DATA ; #if defined(MBEDTLS_PEM_PARSE_C) /* Avoid calling mbedtls_pem_read_buffer() on non-null-terminated string */ @@ -295,10 +295,10 @@ int mbedtls_x509_csr_parse( mbedtls_x509_csr *csr, const unsigned char *buf, siz mbedtls_pem_free( &pem ); if( ret != MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT ) - return( ret ); + return ret ; } #endif /* MBEDTLS_PEM_PARSE_C */ - return( mbedtls_x509_csr_parse_der( csr, buf, buflen ) ); + return mbedtls_x509_csr_parse_der( csr, buf, buflen ) ; } #if defined(MBEDTLS_FS_IO) @@ -312,14 +312,14 @@ int mbedtls_x509_csr_parse_file( mbedtls_x509_csr *csr, const char *path ) unsigned char *buf; if( ( ret = mbedtls_pk_load_file( path, &buf, &n ) ) != 0 ) - return( ret ); + return ret ; ret = mbedtls_x509_csr_parse( csr, buf, n ); mbedtls_platform_zeroize( buf, n ); mbedtls_free( buf ); - return( ret ); + return ret ; } #endif /* MBEDTLS_FS_IO */ @@ -359,7 +359,7 @@ int mbedtls_x509_csr_info( char *buf, size_t size, const char *prefix, if( ( ret = mbedtls_x509_key_size_helper( key_size_str, BEFORE_COLON, mbedtls_pk_get_name( &csr->pk ) ) ) != 0 ) { - return( ret ); + return ret ; } ret = mbedtls_snprintf( p, n, "\n%s%-" BC "s: %d bits\n", prefix, key_size_str, diff --git a/library/x509write_crt.c b/library/x509write_crt.c index c8169f1feb..d0514a9605 100644 --- a/library/x509write_crt.c +++ b/library/x509write_crt.c @@ -101,9 +101,9 @@ int mbedtls_x509write_crt_set_serial( mbedtls_x509write_cert *ctx, int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; if( ( ret = mbedtls_mpi_copy( &ctx->serial, serial ) ) != 0 ) - return( ret ); + return ret ; - return( 0 ); + return 0 ; } int mbedtls_x509write_crt_set_validity( mbedtls_x509write_cert *ctx, @@ -113,14 +113,14 @@ int mbedtls_x509write_crt_set_validity( mbedtls_x509write_cert *ctx, if( strlen( not_before ) != MBEDTLS_X509_RFC5280_UTC_TIME_LEN - 1 || strlen( not_after ) != MBEDTLS_X509_RFC5280_UTC_TIME_LEN - 1 ) { - return( MBEDTLS_ERR_X509_BAD_INPUT_DATA ); + return MBEDTLS_ERR_X509_BAD_INPUT_DATA ; } strncpy( ctx->not_before, not_before, MBEDTLS_X509_RFC5280_UTC_TIME_LEN ); strncpy( ctx->not_after , not_after , MBEDTLS_X509_RFC5280_UTC_TIME_LEN ); ctx->not_before[MBEDTLS_X509_RFC5280_UTC_TIME_LEN - 1] = 'Z'; ctx->not_after[MBEDTLS_X509_RFC5280_UTC_TIME_LEN - 1] = 'Z'; - return( 0 ); + return 0 ; } int mbedtls_x509write_crt_set_extension( mbedtls_x509write_cert *ctx, @@ -143,7 +143,7 @@ int mbedtls_x509write_crt_set_basic_constraints( mbedtls_x509write_cert *ctx, memset( buf, 0, sizeof(buf) ); if( is_ca && max_pathlen > 127 ) - return( MBEDTLS_ERR_X509_BAD_INPUT_DATA ); + return MBEDTLS_ERR_X509_BAD_INPUT_DATA ; if( is_ca ) { @@ -181,7 +181,7 @@ int mbedtls_x509write_crt_set_subject_key_identifier( mbedtls_x509write_cert *ct ret = mbedtls_sha1( buf + sizeof( buf ) - len, len, buf + sizeof( buf ) - 20 ); if( ret != 0 ) - return( ret ); + return ret ; c = buf + sizeof( buf ) - 20; len = 20; @@ -209,7 +209,7 @@ int mbedtls_x509write_crt_set_authority_key_identifier( mbedtls_x509write_cert * ret = mbedtls_sha1( buf + sizeof( buf ) - len, len, buf + sizeof( buf ) - 20 ); if( ret != 0 ) - return( ret ); + return ret ; c = buf + sizeof( buf ) - 20; len = 20; @@ -248,7 +248,7 @@ int mbedtls_x509write_crt_set_key_usage( mbedtls_x509write_cert *ctx, /* Check that nothing other than the allowed flags is set */ if( ( key_usage & ~allowed_bits ) != 0 ) - return( MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE ; c = buf + 5; ku[0] = (unsigned char)( key_usage ); @@ -256,17 +256,17 @@ int mbedtls_x509write_crt_set_key_usage( mbedtls_x509write_cert *ctx, ret = mbedtls_asn1_write_named_bitstring( &c, buf, ku, 9 ); if( ret < 0 ) - return( ret ); + return ret ; else if( ret < 3 || ret > 5 ) - return( MBEDTLS_ERR_X509_INVALID_FORMAT ); + return MBEDTLS_ERR_X509_INVALID_FORMAT ; ret = mbedtls_x509write_crt_set_extension( ctx, MBEDTLS_OID_KEY_USAGE, MBEDTLS_OID_SIZE( MBEDTLS_OID_KEY_USAGE ), 1, c, (size_t)ret ); if( ret != 0 ) - return( ret ); + return ret ; - return( 0 ); + return 0 ; } int mbedtls_x509write_crt_set_ns_cert_type( mbedtls_x509write_cert *ctx, @@ -280,15 +280,15 @@ int mbedtls_x509write_crt_set_ns_cert_type( mbedtls_x509write_cert *ctx, ret = mbedtls_asn1_write_named_bitstring( &c, buf, &ns_cert_type, 8 ); if( ret < 3 || ret > 4 ) - return( ret ); + return ret ; ret = mbedtls_x509write_crt_set_extension( ctx, MBEDTLS_OID_NS_CERT_TYPE, MBEDTLS_OID_SIZE( MBEDTLS_OID_NS_CERT_TYPE ), 0, c, (size_t)ret ); if( ret != 0 ) - return( ret ); + return ret ; - return( 0 ); + return 0 ; } static int x509_write_time( unsigned char **p, unsigned char *start, @@ -319,7 +319,7 @@ static int x509_write_time( unsigned char **p, unsigned char *start, MBEDTLS_ASN1_GENERALIZED_TIME ) ); } - return( (int) len ); + return (int) len ; } int mbedtls_x509write_crt_der( mbedtls_x509write_cert *ctx, @@ -351,12 +351,12 @@ int mbedtls_x509write_crt_der( mbedtls_x509write_cert *ctx, else if( mbedtls_pk_can_do( ctx->issuer_key, MBEDTLS_PK_ECDSA ) ) pk_alg = MBEDTLS_PK_ECDSA; else - return( MBEDTLS_ERR_X509_INVALID_ALG ); + return MBEDTLS_ERR_X509_INVALID_ALG ; if( ( ret = mbedtls_oid_get_oid_by_sig_alg( pk_alg, ctx->md_alg, &sig_oid, &sig_oid_len ) ) != 0 ) { - return( ret ); + return ret ; } /* @@ -470,14 +470,14 @@ int mbedtls_x509write_crt_der( mbedtls_x509write_cert *ctx, if( ( ret = mbedtls_md( mbedtls_md_info_from_type( ctx->md_alg ), c, len, hash ) ) != 0 ) { - return( ret ); + return ret ; } if( ( ret = mbedtls_pk_sign( ctx->issuer_key, ctx->md_alg, hash, 0, sig, sizeof( sig ), &sig_len, f_rng, p_rng ) ) != 0 ) { - return( ret ); + return ret ; } /* Move CRT to the front of the buffer to have space @@ -509,7 +509,7 @@ int mbedtls_x509write_crt_der( mbedtls_x509write_cert *ctx, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ); - return( (int) len ); + return (int) len ; } #define PEM_BEGIN_CRT "-----BEGIN CERTIFICATE-----\n" @@ -527,17 +527,17 @@ int mbedtls_x509write_crt_pem( mbedtls_x509write_cert *crt, if( ( ret = mbedtls_x509write_crt_der( crt, buf, size, f_rng, p_rng ) ) < 0 ) { - return( ret ); + return ret ; } if( ( ret = mbedtls_pem_write_buffer( PEM_BEGIN_CRT, PEM_END_CRT, buf + size - ret, ret, buf, size, &olen ) ) != 0 ) { - return( ret ); + return ret ; } - return( 0 ); + return 0 ; } #endif /* MBEDTLS_PEM_WRITE_C */ diff --git a/library/x509write_csr.c b/library/x509write_csr.c index 555f296315..0e18dae090 100644 --- a/library/x509write_csr.c +++ b/library/x509write_csr.c @@ -100,15 +100,15 @@ int mbedtls_x509write_csr_set_key_usage( mbedtls_x509write_csr *ctx, unsigned ch ret = mbedtls_asn1_write_named_bitstring( &c, buf, &key_usage, 8 ); if( ret < 3 || ret > 4 ) - return( ret ); + return ret ; ret = mbedtls_x509write_csr_set_extension( ctx, MBEDTLS_OID_KEY_USAGE, MBEDTLS_OID_SIZE( MBEDTLS_OID_KEY_USAGE ), 0, c, (size_t)ret ); if( ret != 0 ) - return( ret ); + return ret ; - return( 0 ); + return 0 ; } int mbedtls_x509write_csr_set_ns_cert_type( mbedtls_x509write_csr *ctx, @@ -122,15 +122,15 @@ int mbedtls_x509write_csr_set_ns_cert_type( mbedtls_x509write_csr *ctx, ret = mbedtls_asn1_write_named_bitstring( &c, buf, &ns_cert_type, 8 ); if( ret < 3 || ret > 4 ) - return( ret ); + return ret ; ret = mbedtls_x509write_csr_set_extension( ctx, MBEDTLS_OID_NS_CERT_TYPE, MBEDTLS_OID_SIZE( MBEDTLS_OID_NS_CERT_TYPE ), 0, c, (size_t)ret ); if( ret != 0 ) - return( ret ); + return ret ; - return( 0 ); + return 0 ; } static int x509write_csr_der_internal( mbedtls_x509write_csr *ctx, @@ -220,26 +220,26 @@ static int x509write_csr_der_internal( mbedtls_x509write_csr *ctx, */ #if defined(MBEDTLS_USE_PSA_CRYPTO) if( psa_hash_setup( &hash_operation, hash_alg ) != PSA_SUCCESS ) - return( MBEDTLS_ERR_X509_FATAL_ERROR ); + return MBEDTLS_ERR_X509_FATAL_ERROR ; if( psa_hash_update( &hash_operation, c, len ) != PSA_SUCCESS ) - return( MBEDTLS_ERR_X509_FATAL_ERROR ); + return MBEDTLS_ERR_X509_FATAL_ERROR ; if( psa_hash_finish( &hash_operation, hash, sizeof( hash ), &hash_len ) != PSA_SUCCESS ) { - return( MBEDTLS_ERR_X509_FATAL_ERROR ); + return MBEDTLS_ERR_X509_FATAL_ERROR ; } #else /* MBEDTLS_USE_PSA_CRYPTO */ ret = mbedtls_md( mbedtls_md_info_from_type( ctx->md_alg ), c, len, hash ); if( ret != 0 ) - return( ret ); + return ret ; #endif if( ( ret = mbedtls_pk_sign( ctx->key, ctx->md_alg, hash, 0, sig, sig_size, &sig_len, f_rng, p_rng ) ) != 0 ) { - return( ret ); + return ret ; } if( mbedtls_pk_can_do( ctx->key, MBEDTLS_PK_RSA ) ) @@ -247,12 +247,12 @@ static int x509write_csr_der_internal( mbedtls_x509write_csr *ctx, else if( mbedtls_pk_can_do( ctx->key, MBEDTLS_PK_ECDSA ) ) pk_alg = MBEDTLS_PK_ECDSA; else - return( MBEDTLS_ERR_X509_INVALID_ALG ); + return MBEDTLS_ERR_X509_INVALID_ALG ; if( ( ret = mbedtls_oid_get_oid_by_sig_alg( pk_alg, ctx->md_alg, &sig_oid, &sig_oid_len ) ) != 0 ) { - return( ret ); + return ret ; } /* @@ -289,7 +289,7 @@ static int x509write_csr_der_internal( mbedtls_x509write_csr *ctx, /* Zero the unused bytes at the start of buf */ memset( buf, 0, c2 - buf); - return( (int) len ); + return (int) len ; } int mbedtls_x509write_csr_der( mbedtls_x509write_csr *ctx, unsigned char *buf, @@ -302,7 +302,7 @@ int mbedtls_x509write_csr_der( mbedtls_x509write_csr *ctx, unsigned char *buf, if( ( sig = mbedtls_calloc( 1, MBEDTLS_PK_SIGNATURE_MAX_SIZE ) ) == NULL ) { - return( MBEDTLS_ERR_X509_ALLOC_FAILED ); + return MBEDTLS_ERR_X509_ALLOC_FAILED ; } ret = x509write_csr_der_internal( ctx, buf, size, @@ -311,7 +311,7 @@ int mbedtls_x509write_csr_der( mbedtls_x509write_csr *ctx, unsigned char *buf, mbedtls_free( sig ); - return( ret ); + return ret ; } #define PEM_BEGIN_CSR "-----BEGIN CERTIFICATE REQUEST-----\n" @@ -328,17 +328,17 @@ int mbedtls_x509write_csr_pem( mbedtls_x509write_csr *ctx, unsigned char *buf, s if( ( ret = mbedtls_x509write_csr_der( ctx, buf, size, f_rng, p_rng ) ) < 0 ) { - return( ret ); + return ret ; } if( ( ret = mbedtls_pem_write_buffer( PEM_BEGIN_CSR, PEM_END_CSR, buf + size - ret, ret, buf, size, &olen ) ) != 0 ) { - return( ret ); + return ret ; } - return( 0 ); + return 0 ; } #endif /* MBEDTLS_PEM_WRITE_C */ diff --git a/programs/fuzz/common.c b/programs/fuzz/common.c index ac39ee22f3..70a5380758 100644 --- a/programs/fuzz/common.c +++ b/programs/fuzz/common.c @@ -27,9 +27,9 @@ int dummy_send( void *ctx, const unsigned char *buf, size_t len ) //pretends we wrote everything ok if( len > INT_MAX ) { - return( -1 ); + return -1 ; } - return( (int) len ); + return (int) len ; } int fuzz_recv( void *ctx, unsigned char *buf, size_t len ) @@ -39,10 +39,10 @@ int fuzz_recv( void *ctx, unsigned char *buf, size_t len ) if(biomemfuzz->Offset == biomemfuzz->Size) { //EOF - return( 0 ); + return 0 ; } if( len > INT_MAX ) { - return( -1 ); + return -1 ; } if( len + biomemfuzz->Offset > biomemfuzz->Size ) { //do not overflow @@ -50,7 +50,7 @@ int fuzz_recv( void *ctx, unsigned char *buf, size_t len ) } memcpy(buf, biomemfuzz->Data + biomemfuzz->Offset, len); biomemfuzz->Offset += len; - return( (int) len ); + return (int) len ; } int dummy_random( void *p_rng, unsigned char *output, size_t output_len ) @@ -69,7 +69,7 @@ int dummy_random( void *p_rng, unsigned char *output, size_t output_len ) //replace result with pseudo random output[i] = (unsigned char) rand(); } - return( ret ); + return ret ; } int dummy_entropy( void *data, unsigned char *output, size_t len ) @@ -84,7 +84,7 @@ int dummy_entropy( void *data, unsigned char *output, size_t len ) //replace result with pseudo random output[i] = (unsigned char) rand(); } - return( 0 ); + return 0 ; } int fuzz_recv_timeout( void *ctx, unsigned char *buf, size_t len, diff --git a/programs/hash/generic_sum.c b/programs/hash/generic_sum.c index 9243f0a4a4..23d78bd9ca 100644 --- a/programs/hash/generic_sum.c +++ b/programs/hash/generic_sum.c @@ -57,7 +57,7 @@ static int generic_wrapper( const mbedtls_md_info_t *md_info, char *filename, un if( ret == 2 ) mbedtls_fprintf( stderr, "failed to read: %s\n", filename ); - return( ret ); + return ret ; } static int generic_print( const mbedtls_md_info_t *md_info, char *filename ) @@ -66,13 +66,13 @@ static int generic_print( const mbedtls_md_info_t *md_info, char *filename ) unsigned char sum[MBEDTLS_MD_MAX_SIZE]; if( generic_wrapper( md_info, filename, sum ) != 0 ) - return( 1 ); + return 1 ; for( i = 0; i < mbedtls_md_get_size( md_info ); i++ ) mbedtls_printf( "%02x", sum[i] ); mbedtls_printf( " %s\n", filename ); - return( 0 ); + return 0 ; } static int generic_check( const mbedtls_md_info_t *md_info, char *filename ) @@ -94,7 +94,7 @@ static int generic_check( const mbedtls_md_info_t *md_info, char *filename ) if( ( f = fopen( filename, "rb" ) ) == NULL ) { mbedtls_printf( "failed to open: %s\n", filename ); - return( 1 ); + return 1 ; } nb_err1 = nb_err2 = 0; @@ -164,7 +164,7 @@ static int generic_check( const mbedtls_md_info_t *md_info, char *filename ) fclose( f ); - return( nb_err1 != 0 || nb_err2 != 0 ); + return nb_err1 != 0 || nb_err2 != 0 ; } int main( int argc, char *argv[] ) diff --git a/programs/pkey/ecdh_curve25519.c b/programs/pkey/ecdh_curve25519.c index ca046fd241..fcef380b38 100644 --- a/programs/pkey/ecdh_curve25519.c +++ b/programs/pkey/ecdh_curve25519.c @@ -73,7 +73,7 @@ int main( int argc, char *argv[] ) mbedtls_entropy_init( &entropy ); 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; diff --git a/programs/pkey/ecdsa.c b/programs/pkey/ecdsa.c index 6b6e9517d4..293bfbaf7b 100644 --- a/programs/pkey/ecdsa.c +++ b/programs/pkey/ecdsa.c @@ -81,7 +81,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; diff --git a/programs/pkey/gen_key.c b/programs/pkey/gen_key.c index 4043dfa6e0..8729be35c7 100644 --- a/programs/pkey/gen_key.c +++ b/programs/pkey/gen_key.c @@ -61,7 +61,7 @@ int dev_random_entropy_poll( void *data, unsigned char *output, file = fopen( "/dev/random", "rb" ); if( file == NULL ) - return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED ); + return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED ; while( left > 0 ) { @@ -70,7 +70,7 @@ int dev_random_entropy_poll( void *data, unsigned char *output, if( ret == 0 && ferror( file ) ) { fclose( file ); - return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED ); + return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED ; } p += ret; @@ -80,7 +80,7 @@ int dev_random_entropy_poll( void *data, unsigned char *output, fclose( file ); *olen = len; - return( 0 ); + return 0 ; } #endif /* !_WIN32 */ #endif @@ -157,31 +157,31 @@ static int write_private_key( mbedtls_pk_context *key, const char *output_file ) if( opt.format == FORMAT_PEM ) { if( ( ret = mbedtls_pk_write_key_pem( key, output_buf, 16000 ) ) != 0 ) - return( ret ); + return ret ; len = strlen( (char *) output_buf ); } else { if( ( ret = mbedtls_pk_write_key_der( key, output_buf, 16000 ) ) < 0 ) - return( ret ); + return ret ; len = ret; c = output_buf + sizeof(output_buf) - len; } if( ( f = fopen( output_file, "wb" ) ) == NULL ) - return( -1 ); + return -1 ; if( fwrite( c, 1, len, f ) != len ) { fclose( f ); - return( -1 ); + return -1 ; } fclose( f ); - return( 0 ); + return 0 ; } int main( int argc, char *argv[] ) diff --git a/programs/pkey/key_app_writer.c b/programs/pkey/key_app_writer.c index 8a09af5125..a61cda1479 100644 --- a/programs/pkey/key_app_writer.c +++ b/programs/pkey/key_app_writer.c @@ -128,7 +128,7 @@ static int write_public_key( mbedtls_pk_context *key, const char *output_file ) if( opt.output_format == OUTPUT_FORMAT_PEM ) { if( ( ret = mbedtls_pk_write_pubkey_pem( key, output_buf, 16000 ) ) != 0 ) - return( ret ); + return ret ; len = strlen( (char *) output_buf ); } @@ -136,24 +136,24 @@ static int write_public_key( mbedtls_pk_context *key, const char *output_file ) #endif { if( ( ret = mbedtls_pk_write_pubkey_der( key, output_buf, 16000 ) ) < 0 ) - return( ret ); + return ret ; len = ret; c = output_buf + sizeof(output_buf) - len; } if( ( f = fopen( output_file, "w" ) ) == NULL ) - return( -1 ); + return -1 ; if( fwrite( c, 1, len, f ) != len ) { fclose( f ); - return( -1 ); + return -1 ; } fclose( f ); - return( 0 ); + return 0 ; } static int write_private_key( mbedtls_pk_context *key, const char *output_file ) @@ -170,7 +170,7 @@ static int write_private_key( mbedtls_pk_context *key, const char *output_file ) if( opt.output_format == OUTPUT_FORMAT_PEM ) { if( ( ret = mbedtls_pk_write_key_pem( key, output_buf, 16000 ) ) != 0 ) - return( ret ); + return ret ; len = strlen( (char *) output_buf ); } @@ -178,24 +178,24 @@ static int write_private_key( mbedtls_pk_context *key, const char *output_file ) #endif { if( ( ret = mbedtls_pk_write_key_der( key, output_buf, 16000 ) ) < 0 ) - return( ret ); + return ret ; len = ret; c = output_buf + sizeof(output_buf) - len; } if( ( f = fopen( output_file, "w" ) ) == NULL ) - return( -1 ); + return -1 ; if( fwrite( c, 1, len, f ) != len ) { fclose( f ); - return( -1 ); + return -1 ; } fclose( f ); - return( 0 ); + return 0 ; } int main( int argc, char *argv[] ) diff --git a/programs/psa/crypto_examples.c b/programs/psa/crypto_examples.c index 935d657af5..80fe67efdd 100644 --- a/programs/psa/crypto_examples.c +++ b/programs/psa/crypto_examples.c @@ -54,7 +54,7 @@ int main( void ) "and/or MBEDTLS_CIPHER_MODE_WITH_PADDING " "not defined and/or MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER" " defined.\r\n" ); - return( 0 ); + return 0 ; } #else @@ -91,7 +91,7 @@ static psa_status_t cipher_operation( psa_cipher_operation_t *operation, *output_len += len; exit: - return( status ); + return status ; } static psa_status_t cipher_encrypt( psa_key_id_t key, @@ -122,7 +122,7 @@ static psa_status_t cipher_encrypt( psa_key_id_t key, exit: psa_cipher_abort( &operation ); - return( status ); + return status ; } static psa_status_t cipher_decrypt( psa_key_id_t key, @@ -152,7 +152,7 @@ static psa_status_t cipher_decrypt( psa_key_id_t key, exit: psa_cipher_abort( &operation ); - return( status ); + return status ; } static psa_status_t @@ -201,7 +201,7 @@ cipher_example_encrypt_decrypt_aes_cbc_nopad_1_block( void ) exit: psa_destroy_key( key ); - return( status ); + return status ; } static psa_status_t cipher_example_encrypt_decrypt_aes_cbc_pkcs7_multi( void ) @@ -249,7 +249,7 @@ static psa_status_t cipher_example_encrypt_decrypt_aes_cbc_pkcs7_multi( void ) exit: psa_destroy_key( key ); - return( status ); + return status ; } static psa_status_t cipher_example_encrypt_decrypt_aes_ctr_multi( void ) @@ -296,7 +296,7 @@ static psa_status_t cipher_example_encrypt_decrypt_aes_ctr_multi( void ) exit: psa_destroy_key( key ); - return( status ); + return status ; } static void cipher_examples( void ) @@ -325,7 +325,7 @@ int main( void ) cipher_examples( ); exit: mbedtls_psa_crypto_free( ); - return( 0 ); + return 0 ; } #endif /* MBEDTLS_PSA_CRYPTO_C && MBEDTLS_AES_C && MBEDTLS_CIPHER_MODE_CBC && MBEDTLS_CIPHER_MODE_CTR && MBEDTLS_CIPHER_MODE_WITH_PADDING */ diff --git a/programs/psa/key_ladder_demo.c b/programs/psa/key_ladder_demo.c index cad875e015..435c9ced41 100644 --- a/programs/psa/key_ladder_demo.c +++ b/programs/psa/key_ladder_demo.c @@ -72,7 +72,7 @@ int main( void ) "MBEDTLS_PSA_CRYPTO_C and/or MBEDTLS_FS_IO " "not defined and/or MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER " "defined.\n" ); - return( 0 ); + return 0 ; } #else @@ -184,7 +184,7 @@ static psa_status_t save_key( psa_key_id_t key, exit: if( key_file != NULL) fclose( key_file ); - return( status ); + return status ; } /* Generate a master key for use in this demo. @@ -210,7 +210,7 @@ static psa_status_t generate( const char *key_file_name ) exit: (void) psa_destroy_key( key ); - return( status ); + return status ; } /* Load the master key from a file. @@ -259,7 +259,7 @@ exit: (void) psa_destroy_key( *master_key ); *master_key = 0; } - return( status ); + return status ; } /* Derive the intermediate keys, using the list of labels provided on @@ -314,7 +314,7 @@ exit: psa_destroy_key( *key ); *key = 0; } - return( status ); + return status ; } /* Derive a wrapping key from the last intermediate key. */ @@ -351,7 +351,7 @@ static psa_status_t derive_wrapping_key( psa_key_usage_t usage, exit: psa_key_derivation_abort( &operation ); - return( status ); + return status ; } static psa_status_t wrap_data( const char *input_file_name, @@ -433,7 +433,7 @@ exit: if( buffer != NULL ) mbedtls_platform_zeroize( buffer, buffer_size ); free( buffer ); - return( status ); + return status ; } static psa_status_t unwrap_data( const char *input_file_name, @@ -522,7 +522,7 @@ exit: if( buffer != NULL ) mbedtls_platform_zeroize( buffer, ciphertext_size ); free( buffer ); - return( status ); + return status ; } static psa_status_t run( enum program_mode mode, @@ -540,7 +540,7 @@ static psa_status_t run( enum program_mode mode, /* Generate mode is unlike the others. Generate the master key and exit. */ if( mode == MODE_GENERATE ) - return( generate( key_file_name ) ); + return generate( key_file_name ) ; /* Read the master key. */ PSA_CHECK( import_key_from_file( PSA_KEY_USAGE_DERIVE | PSA_KEY_USAGE_EXPORT, @@ -584,7 +584,7 @@ exit: (void) psa_destroy_key( wrapping_key ); /* Deinitialize the PSA crypto library. */ mbedtls_psa_crypto_free( ); - return( status ); + return status ; } static void usage( void ) @@ -625,7 +625,7 @@ int main( int argc, char *argv[] ) strcmp( argv[1], "--help" ) == 0 ) { usage( ); - return( EXIT_SUCCESS ); + return EXIT_SUCCESS ; } for( i = 2; i < argc; i++ ) @@ -646,7 +646,7 @@ int main( int argc, char *argv[] ) { printf( "Maximum ladder depth %u exceeded.\n", (unsigned) MAX_LADDER_DEPTH ); - return( EXIT_FAILURE ); + return EXIT_FAILURE ; } ladder[ladder_depth] = q; ++ladder_depth; @@ -680,13 +680,13 @@ int main( int argc, char *argv[] ) ( mode == MODE_WRAP || mode == MODE_UNWRAP ) ) { printf( "Required argument missing: input\n" ); - return( DEMO_ERROR ); + return DEMO_ERROR ; } if( output_file_name == NULL && ( mode == MODE_SAVE || mode == MODE_WRAP || mode == MODE_UNWRAP ) ) { printf( "Required argument missing: output\n" ); - return( DEMO_ERROR ); + return DEMO_ERROR ; } status = run( mode, key_file_name, @@ -698,6 +698,6 @@ int main( int argc, char *argv[] ) usage_failure: usage( ); - return( EXIT_FAILURE ); + return EXIT_FAILURE ; } #endif /* MBEDTLS_SHA256_C && MBEDTLS_MD_C && MBEDTLS_AES_C && MBEDTLS_CCM_C && MBEDTLS_PSA_CRYPTO_C && MBEDTLS_FS_IO */ diff --git a/programs/psa/psa_constant_names.c b/programs/psa/psa_constant_names.c index b5fea04ddc..94edde5d78 100644 --- a/programs/psa/psa_constant_names.c +++ b/programs/psa/psa_constant_names.c @@ -33,7 +33,7 @@ int snprintf( char *s, size_t n, const char *fmt, ... ) /* Avoid calling the invalid parameter handler by checking ourselves */ if( s == NULL || n == 0 || fmt == NULL ) - return( -1 ); + return -1 ; va_start( argp, fmt ); #if defined(_TRUNCATE) && !defined(__MINGW32__) @@ -48,7 +48,7 @@ int snprintf( char *s, size_t n, const char *fmt, ... ) #endif va_end( argp ); - return( ret ); + return ret ; } #endif diff --git a/programs/ssl/ssl_client2.c b/programs/ssl/ssl_client2.c index 25fe21bd9d..54770960b3 100644 --- a/programs/ssl/ssl_client2.c +++ b/programs/ssl/ssl_client2.c @@ -518,7 +518,7 @@ static int my_verify( void *data, mbedtls_x509_crt *crt, memcpy( peer_crt_info, buf, sizeof( buf ) ); if( opt.debug_level == 0 ) - return( 0 ); + return 0 ; mbedtls_printf( "%s", buf ); #else @@ -534,7 +534,7 @@ static int my_verify( void *data, mbedtls_x509_crt *crt, mbedtls_printf( "%s\n", buf ); } - return( 0 ); + return 0 ; } #endif /* MBEDTLS_X509_CRT_PARSE_C */ @@ -548,7 +548,7 @@ int report_cid_usage( mbedtls_ssl_context *ssl, int cid_negotiated; if( opt.transport != MBEDTLS_SSL_TRANSPORT_DATAGRAM ) - return( 0 ); + return 0 ; /* Check if the use of a CID has been negotiated, * but don't ask for the CID value and length. @@ -566,7 +566,7 @@ int report_cid_usage( mbedtls_ssl_context *ssl, { mbedtls_printf( " failed\n ! mbedtls_ssl_get_peer_cid returned -0x%x\n\n", (unsigned int) -ret ); - return( ret ); + return ret ; } if( cid_negotiated == MBEDTLS_SSL_CID_DISABLED ) @@ -590,7 +590,7 @@ int report_cid_usage( mbedtls_ssl_context *ssl, { mbedtls_printf( " failed\n ! mbedtls_ssl_get_peer_cid returned -0x%x\n\n", (unsigned int) -ret ); - return( ret ); + return ret ; } /* Ask for just length + value of the peer's CID. */ @@ -600,7 +600,7 @@ int report_cid_usage( mbedtls_ssl_context *ssl, { mbedtls_printf( " failed\n ! mbedtls_ssl_get_peer_cid returned -0x%x\n\n", (unsigned int) -ret ); - return( ret ); + return ret ; } mbedtls_printf( "(%s) Peer CID (length %u Bytes): ", additional_description, @@ -613,7 +613,7 @@ int report_cid_usage( mbedtls_ssl_context *ssl, mbedtls_printf( "\n" ); } - return( 0 ); + return 0 ; } #endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */ diff --git a/programs/ssl/ssl_context_info.c b/programs/ssl/ssl_context_info.c index 5ad9120321..67e922c272 100644 --- a/programs/ssl/ssl_context_info.c +++ b/programs/ssl/ssl_context_info.c @@ -30,7 +30,7 @@ int main( void ) { printf("MBEDTLS_X509_CRT_PARSE_C and/or MBEDTLS_ERROR_C and/or " "MBEDTLS_SSL_TLS_C not defined.\n"); - return( 0 ); + return 0 ; } #else diff --git a/programs/ssl/ssl_mail_client.c b/programs/ssl/ssl_mail_client.c index 32960ad411..2477979af1 100644 --- a/programs/ssl/ssl_mail_client.c +++ b/programs/ssl/ssl_mail_client.c @@ -190,7 +190,7 @@ static int do_handshake( mbedtls_ssl_context *ssl ) mbedtls_strerror( ret, (char *) buf, 1024 ); #endif mbedtls_printf( " failed\n ! mbedtls_ssl_handshake returned %d: %s\n\n", ret, buf ); - return( -1 ); + return -1 ; } } @@ -227,7 +227,7 @@ static int do_handshake( mbedtls_ssl_context *ssl ) mbedtls_printf( "%s\n", buf ); #endif - return( 0 ); + return 0 ; } static int write_ssl_data( mbedtls_ssl_context *ssl, unsigned char *buf, size_t len ) @@ -244,7 +244,7 @@ static int write_ssl_data( mbedtls_ssl_context *ssl, unsigned char *buf, size_t } } - return( 0 ); + return 0 ; } static int write_ssl_and_get_response( mbedtls_ssl_context *ssl, unsigned char *buf, size_t len ) diff --git a/programs/ssl/ssl_pthread_server.c b/programs/ssl/ssl_pthread_server.c index a8db4d8b10..4517309775 100644 --- a/programs/ssl/ssl_pthread_server.c +++ b/programs/ssl/ssl_pthread_server.c @@ -267,7 +267,7 @@ thread_exit: thread_info->thread_complete = 1; - return( NULL ); + return NULL ; } static int thread_create( mbedtls_net_context *client_fd ) @@ -292,7 +292,7 @@ static int thread_create( mbedtls_net_context *client_fd ) } if( i == MAX_NUM_THREADS ) - return( -1 ); + return -1 ; /* * Fill thread-info for thread @@ -304,10 +304,10 @@ static int thread_create( mbedtls_net_context *client_fd ) if( ( ret = pthread_create( &threads[i].thread, NULL, handle_ssl_connection, &threads[i].data ) ) != 0 ) { - return( ret ); + return ret ; } - return( 0 ); + return 0 ; } int main( void ) diff --git a/programs/ssl/ssl_server2.c b/programs/ssl/ssl_server2.c index d2aa48a059..ea6706d056 100644 --- a/programs/ssl/ssl_server2.c +++ b/programs/ssl/ssl_server2.c @@ -616,13 +616,13 @@ struct options static int get_auth_mode( const char *s ) { if( strcmp( s, "none" ) == 0 ) - return( MBEDTLS_SSL_VERIFY_NONE ); + return MBEDTLS_SSL_VERIFY_NONE ; if( strcmp( s, "optional" ) == 0 ) - return( MBEDTLS_SSL_VERIFY_OPTIONAL ); + return MBEDTLS_SSL_VERIFY_OPTIONAL ; if( strcmp( s, "required" ) == 0 ) - return( MBEDTLS_SSL_VERIFY_REQUIRED ); + return MBEDTLS_SSL_VERIFY_REQUIRED ; - return( -1 ); + return -1 ; } /* @@ -701,7 +701,7 @@ sni_entry *sni_parse( char *sni_string ) if( ( new = mbedtls_calloc( 1, sizeof( sni_entry ) ) ) == NULL ) { sni_free( cur ); - return( NULL ); + return NULL ; } GET_ITEM( new->name ); @@ -760,12 +760,12 @@ sni_entry *sni_parse( char *sni_string ) cur = new; } - return( cur ); + return cur ; error: sni_free( new ); sni_free( cur ); - return( NULL ); + return NULL ; } /* @@ -787,13 +787,13 @@ int sni_callback( void *p_info, mbedtls_ssl_context *ssl, if( cur->authmode != DFL_AUTH_MODE ) mbedtls_ssl_set_hs_authmode( ssl, cur->authmode ); - return( mbedtls_ssl_set_hs_own_cert( ssl, cur->cert, cur->key ) ); + return mbedtls_ssl_set_hs_own_cert( ssl, cur->cert, cur->key ) ; } cur = cur->next; } - return( -1 ); + return -1 ; } #endif /* SNI_OPTION */ @@ -830,7 +830,7 @@ int psk_free( psk_entry *head ) { status = psa_destroy_key( slot ); if( status != PSA_SUCCESS ) - return( status ); + return status ; } #endif /* MBEDTLS_USE_PSA_CRYPTO */ @@ -839,7 +839,7 @@ int psk_free( psk_entry *head ) head = next; } - return( 0 ); + return 0 ; } /* @@ -877,12 +877,12 @@ psk_entry *psk_parse( char *psk_string ) cur = new; } - return( cur ); + return cur ; error: psk_free( new ); psk_free( cur ); - return( 0 ); + return 0 ; } /* @@ -900,16 +900,16 @@ int psk_callback( void *p_info, mbedtls_ssl_context *ssl, { #if defined(MBEDTLS_USE_PSA_CRYPTO) if( cur->slot != 0 ) - return( mbedtls_ssl_set_hs_psk_opaque( ssl, cur->slot ) ); + return mbedtls_ssl_set_hs_psk_opaque( ssl, cur->slot ) ; else #endif - return( mbedtls_ssl_set_hs_psk( ssl, cur->key, cur->key_len ) ); + return mbedtls_ssl_set_hs_psk( ssl, cur->key, cur->key_len ) ; } cur = cur->next; } - return( -1 ); + return -1 ; } #endif /* MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED */ @@ -977,13 +977,13 @@ int ssl_async_set_key( ssl_async_key_context_t *ctx, unsigned delay ) { if( ctx->slots_used >= sizeof( ctx->slots ) / sizeof( *ctx->slots ) ) - return( -1 ); + return -1 ; ctx->slots[ctx->slots_used].cert = cert; ctx->slots[ctx->slots_used].pk = pk; ctx->slots[ctx->slots_used].delay = delay; ctx->slots[ctx->slots_used].pk_owned = pk_take_ownership; ++ctx->slots_used; - return( 0 ); + return 0 ; } #define SSL_ASYNC_INPUT_MAX_SIZE 512 @@ -1047,7 +1047,7 @@ static int ssl_async_start( mbedtls_ssl_context *ssl, { mbedtls_printf( "Async %s callback: no key matches this certificate.\n", op_name ); - return( MBEDTLS_ERR_SSL_HW_ACCEL_FALLTHROUGH ); + return MBEDTLS_ERR_SSL_HW_ACCEL_FALLTHROUGH ; } mbedtls_printf( "Async %s callback: using key slot %u, delay=%u.\n", op_name, slot, config_data->slots[slot].delay ); @@ -1055,15 +1055,15 @@ static int ssl_async_start( mbedtls_ssl_context *ssl, if( config_data->inject_error == SSL_ASYNC_INJECT_ERROR_START ) { mbedtls_printf( "Async %s callback: injected error\n", op_name ); - return( MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE ; } if( input_len > SSL_ASYNC_INPUT_MAX_SIZE ) - return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ; ctx = mbedtls_calloc( 1, sizeof( *ctx ) ); if( ctx == NULL ) - return( MBEDTLS_ERR_SSL_ALLOC_FAILED ); + return MBEDTLS_ERR_SSL_ALLOC_FAILED ; ctx->slot = slot; ctx->operation_type = op_type; ctx->md_alg = md_alg; @@ -1073,9 +1073,9 @@ static int ssl_async_start( mbedtls_ssl_context *ssl, mbedtls_ssl_set_async_operation_data( ssl, ctx ); if( ctx->remaining_delay == 0 ) - return( 0 ); + return 0 ; else - return( MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS ); + return MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS ; } static int ssl_async_sign( mbedtls_ssl_context *ssl, @@ -1116,7 +1116,7 @@ static int ssl_async_resume( mbedtls_ssl_context *ssl, --ctx->remaining_delay; mbedtls_printf( "Async resume (slot %u): call %u more times.\n", ctx->slot, ctx->remaining_delay ); - return( MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS ); + return MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS ; } switch( ctx->operation_type ) @@ -1138,7 +1138,7 @@ static int ssl_async_resume( mbedtls_ssl_context *ssl, mbedtls_printf( "Async resume (slot %u): unknown operation type %ld. This shouldn't happen.\n", ctx->slot, (long) ctx->operation_type ); mbedtls_free( ctx ); - return( MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE ; break; } @@ -1149,13 +1149,13 @@ static int ssl_async_resume( mbedtls_ssl_context *ssl, mbedtls_printf( "Async resume callback: %s done but injected error\n", op_name ); mbedtls_free( ctx ); - return( MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE ); + return MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE ; } mbedtls_printf( "Async resume (slot %u): %s done, status=%d.\n", ctx->slot, op_name, ret ); mbedtls_free( ctx ); - return( ret ); + return ret ; } static void ssl_async_cancel( mbedtls_ssl_context *ssl ) @@ -1184,10 +1184,10 @@ static psa_status_t psa_setup_psk_key_slot( psa_key_id_t *slot, if( status != PSA_SUCCESS ) { fprintf( stderr, "IMPORT\n" ); - return( status ); + return status ; } - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } #endif /* MBEDTLS_USE_PSA_CRYPTO */ @@ -1201,7 +1201,7 @@ int report_cid_usage( mbedtls_ssl_context *ssl, int cid_negotiated; if( opt.transport != MBEDTLS_SSL_TRANSPORT_DATAGRAM ) - return( 0 ); + return 0 ; /* Check if the use of a CID has been negotiated */ ret = mbedtls_ssl_get_peer_cid( ssl, &cid_negotiated, @@ -1210,7 +1210,7 @@ int report_cid_usage( mbedtls_ssl_context *ssl, { mbedtls_printf( " failed\n ! mbedtls_ssl_get_peer_cid returned -0x%x\n\n", (unsigned int) -ret ); - return( ret ); + return ret ; } if( cid_negotiated == MBEDTLS_SSL_CID_DISABLED ) @@ -1237,7 +1237,7 @@ int report_cid_usage( mbedtls_ssl_context *ssl, mbedtls_printf( "\n" ); } - return( 0 ); + return 0 ; } #endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */ diff --git a/programs/ssl/ssl_test_common_source.c b/programs/ssl/ssl_test_common_source.c index 6ec4171a89..6ca7af325c 100644 --- a/programs/ssl/ssl_test_common_source.c +++ b/programs/ssl/ssl_test_common_source.c @@ -152,7 +152,7 @@ int ssl_check_record( mbedtls_ssl_context const *ssl, * so make a copy. */ tmp_buf = mbedtls_calloc( 1, len ); if( tmp_buf == NULL ) - return( MBEDTLS_ERR_SSL_ALLOC_FAILED ); + return MBEDTLS_ERR_SSL_ALLOC_FAILED ; memcpy( tmp_buf, buf, len ); ret_cr1 = mbedtls_ssl_check_record( ssl, tmp_buf, len ); @@ -201,7 +201,7 @@ int ssl_check_record( mbedtls_ssl_context const *ssl, cleanup: mbedtls_free( tmp_buf ); - return( my_ret ); + return my_ret ; } int recv_cb( void *ctx, unsigned char *buf, size_t len ) @@ -215,7 +215,7 @@ int recv_cb( void *ctx, unsigned char *buf, size_t len ) else ret = mbedtls_net_recv( io_ctx->net, buf, len ); if( ret < 0 ) - return( ret ); + return ret ; recv_len = (size_t) ret; if( opt.transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM ) @@ -224,10 +224,10 @@ int recv_cb( void *ctx, unsigned char *buf, size_t len ) * in between receiving the packet from the underlying * transport and passing it on to the TLS stack. */ if( ssl_check_record( io_ctx->ssl, buf, recv_len ) != 0 ) - return( -1 ); + return -1 ; } - return( (int) recv_len ); + return (int) recv_len ; } int recv_timeout_cb( void *ctx, unsigned char *buf, size_t len, @@ -239,7 +239,7 @@ int recv_timeout_cb( void *ctx, unsigned char *buf, size_t len, ret = mbedtls_net_recv_timeout( io_ctx->net, buf, len, timeout ); if( ret < 0 ) - return( ret ); + return ret ; recv_len = (size_t) ret; if( opt.transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM ) @@ -248,10 +248,10 @@ int recv_timeout_cb( void *ctx, unsigned char *buf, size_t len, * in between receiving the packet from the underlying * transport and passing it on to the TLS stack. */ if( ssl_check_record( io_ctx->ssl, buf, recv_len ) != 0 ) - return( -1 ); + return -1 ; } - return( (int) recv_len ); + return (int) recv_len ; } int send_cb( void *ctx, unsigned char const *buf, size_t len ) @@ -259,9 +259,9 @@ int send_cb( void *ctx, unsigned char const *buf, size_t len ) io_ctx_t *io_ctx = (io_ctx_t*) ctx; if( opt.nbio == 2 ) - return( delayed_send( io_ctx->net, buf, len ) ); + return delayed_send( io_ctx->net, buf, len ) ; - return( mbedtls_net_send( io_ctx->net, buf, len ) ); + return mbedtls_net_send( io_ctx->net, buf, len ) ; } #if defined(MBEDTLS_X509_CRT_PARSE_C) @@ -294,7 +294,7 @@ int x509_crt_verify_info( char *buf, size_t size, const char *prefix, uint32_t flags ) { #if !defined(MBEDTLS_X509_REMOVE_INFO) - return( mbedtls_x509_crt_verify_info( buf, size, prefix, flags ) ); + return mbedtls_x509_crt_verify_info( buf, size, prefix, flags ) ; #else /* !MBEDTLS_X509_REMOVE_INFO */ int ret; diff --git a/programs/ssl/ssl_test_lib.c b/programs/ssl/ssl_test_lib.c index 04e127a85e..382682f2b2 100644 --- a/programs/ssl/ssl_test_lib.c +++ b/programs/ssl/ssl_test_lib.c @@ -65,7 +65,7 @@ static int dummy_entropy( void *data, unsigned char *output, size_t len ) //replace result with pseudo random output[i] = (unsigned char) rand(); } - return( ret ); + return ret ; } #endif @@ -95,7 +95,7 @@ int rng_seed( rng_context_t *rng, int reproducible, const char *pers ) { mbedtls_fprintf( stderr, "MBEDTLS_USE_PSA_CRYPTO does not support reproducible mode.\n" ); - return( -1 ); + return -1 ; } #endif #if defined(MBEDTLS_TEST_USE_PSA_CRYPTO_RNG) @@ -106,9 +106,9 @@ int rng_seed( rng_context_t *rng, int reproducible, const char *pers ) { mbedtls_fprintf( stderr, "The PSA RNG does not support reproducible mode.\n" ); - return( -1 ); + return -1 ; } - return( 0 ); + return 0 ; #else /* !MBEDTLS_TEST_USE_PSA_CRYPTO_RNG */ int ( *f_entropy )( void *, unsigned char *, size_t ) = ( reproducible ? dummy_entropy : mbedtls_entropy_func ); @@ -142,11 +142,11 @@ int rng_seed( rng_context_t *rng, int reproducible, const char *pers ) { mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_seed returned -0x%x\n", (unsigned int) -ret ); - return( ret ); + return ret ; } #endif /* !MBEDTLS_TEST_USE_PSA_CRYPTO_RNG */ - return( 0 ); + return 0 ; } void rng_free( rng_context_t *rng ) @@ -181,9 +181,9 @@ int rng_get( void *p_rng, unsigned char *output, size_t output_len ) rng_context_t *rng = p_rng; #if defined(MBEDTLS_CTR_DRBG_C) - return( mbedtls_ctr_drbg_random( &rng->drbg, output, output_len ) ); + return mbedtls_ctr_drbg_random( &rng->drbg, output, output_len ) ; #elif defined(MBEDTLS_HMAC_DRBG_C) - return( mbedtls_hmac_drbg_random( &rng->drbg, output, output_len ) ); + return mbedtls_hmac_drbg_random( &rng->drbg, output, output_len ) ; #else #error "No DRBG available" #endif @@ -243,7 +243,7 @@ exit: } *candidates = first; - return( ret ); + return ret ; } #endif /* MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK */ @@ -255,13 +255,13 @@ int delayed_recv( void *ctx, unsigned char *buf, size_t len ) if( first_try ) { first_try = 0; - return( MBEDTLS_ERR_SSL_WANT_READ ); + return MBEDTLS_ERR_SSL_WANT_READ ; } ret = mbedtls_net_recv( ctx, buf, len ); if( ret != MBEDTLS_ERR_SSL_WANT_READ ) first_try = 1; /* Next call will be a new operation */ - return( ret ); + return ret ; } int delayed_send( void *ctx, const unsigned char *buf, size_t len ) @@ -272,13 +272,13 @@ int delayed_send( void *ctx, const unsigned char *buf, size_t len ) if( first_try ) { first_try = 0; - return( MBEDTLS_ERR_SSL_WANT_WRITE ); + return MBEDTLS_ERR_SSL_WANT_WRITE ; } ret = mbedtls_net_send( ctx, buf, len ); if( ret != MBEDTLS_ERR_SSL_WANT_WRITE ) first_try = 1; /* Next call will be a new operation */ - return( ret ); + return ret ; } #if !defined(MBEDTLS_TIMING_C) @@ -299,7 +299,7 @@ int idle( mbedtls_net_context *fd, poll_type = MBEDTLS_NET_POLL_READ; #if !defined(MBEDTLS_TIMING_C) else - return( 0 ); + return 0 ; #endif while( 1 ) @@ -318,13 +318,13 @@ int idle( mbedtls_net_context *fd, { ret = mbedtls_net_poll( fd, poll_type, 0 ); if( ret < 0 ) - return( ret ); + return ret ; if( ret == poll_type ) break; } } - return( 0 ); + return 0 ; } #if defined(MBEDTLS_TEST_HOOKS) @@ -346,8 +346,8 @@ int test_hooks_failure_detected( void ) #endif if( mbedtls_test_info.result != MBEDTLS_TEST_RESULT_SUCCESS ) - return( 1 ); - return( 0 ); + return 1 ; + return 0 ; } void test_hooks_free( void ) diff --git a/programs/test/benchmark.c b/programs/test/benchmark.c index 5985caf0bb..8e22748bfe 100644 --- a/programs/test/benchmark.c +++ b/programs/test/benchmark.c @@ -246,7 +246,7 @@ static unsigned long mbedtls_timing_hardclock( void ) unsigned long tsc; __asm rdtsc __asm mov [tsc], eax - return( tsc ); + return tsc ; } #endif /* !HAVE_HARDCLOCK && MBEDTLS_HAVE_ASM && ( _MSC_VER && _M_IX86 ) || __WATCOMC__ */ @@ -262,7 +262,7 @@ static unsigned long mbedtls_timing_hardclock( void ) { unsigned long lo, hi; asm volatile( "rdtsc" : "=a" (lo), "=d" (hi) ); - return( lo ); + return lo ; } #endif /* !HAVE_HARDCLOCK && MBEDTLS_HAVE_ASM && __GNUC__ && __i386__ */ @@ -276,7 +276,7 @@ static unsigned long mbedtls_timing_hardclock( void ) { unsigned long lo, hi; asm volatile( "rdtsc" : "=a" (lo), "=d" (hi) ); - return( lo | ( hi << 32 ) ); + return lo | ( hi << 32 ) ; } #endif /* !HAVE_HARDCLOCK && MBEDTLS_HAVE_ASM && __GNUC__ && ( __amd64__ || __x86_64__ ) */ @@ -298,7 +298,7 @@ static unsigned long mbedtls_timing_hardclock( void ) } while( tbu0 != tbu1 ); - return( tbl ); + return tbl ; } #endif /* !HAVE_HARDCLOCK && MBEDTLS_HAVE_ASM && __GNUC__ && ( __powerpc__ || __ppc__ ) */ @@ -315,7 +315,7 @@ static unsigned long mbedtls_timing_hardclock( void ) { unsigned long tick; asm volatile( "rdpr %%tick, %0;" : "=&r" (tick) ); - return( tick ); + return tick ; } #endif /* __OpenBSD__ */ #endif /* !HAVE_HARDCLOCK && MBEDTLS_HAVE_ASM && @@ -331,7 +331,7 @@ static unsigned long mbedtls_timing_hardclock( void ) unsigned long tick; asm volatile( ".byte 0x83, 0x41, 0x00, 0x00" ); asm volatile( "mov %%g1, %0" : "=r" (tick) ); - return( tick ); + return tick ; } #endif /* !HAVE_HARDCLOCK && MBEDTLS_HAVE_ASM && __GNUC__ && __sparc__ && !__sparc64__ */ @@ -345,7 +345,7 @@ static unsigned long mbedtls_timing_hardclock( void ) { unsigned long cc; asm volatile( "rpcc %0" : "=r" (cc) ); - return( cc & 0xFFFFFFFF ); + return cc & 0xFFFFFFFF ; } #endif /* !HAVE_HARDCLOCK && MBEDTLS_HAVE_ASM && __GNUC__ && __alpha__ */ @@ -359,7 +359,7 @@ static unsigned long mbedtls_timing_hardclock( void ) { unsigned long itc; asm volatile( "mov %0 = ar.itc" : "=r" (itc) ); - return( itc ); + return itc ; } #endif /* !HAVE_HARDCLOCK && MBEDTLS_HAVE_ASM && __GNUC__ && __ia64__ */ @@ -476,7 +476,7 @@ static int myrand( void *rng_state, unsigned char *output, size_t len ) len -= use_len; } - return( 0 ); + return 0 ; } #define CHECK_AND_CONTINUE( R ) \ @@ -523,10 +523,10 @@ static int set_ecp_curve( const char *string, mbedtls_ecp_curve_info *curve ) if( found != NULL ) { *curve = *found; - return( 1 ); + return 1 ; } else - return( 0 ); + return 0 ; } #endif diff --git a/programs/test/cmake_package/cmake_package.c b/programs/test/cmake_package/cmake_package.c index 1ae627d423..4263bd922a 100644 --- a/programs/test/cmake_package/cmake_package.c +++ b/programs/test/cmake_package/cmake_package.c @@ -45,5 +45,5 @@ int main() mbedtls_printf( "Built against %s\n", version ); - return( 0 ); + return 0 ; } diff --git a/programs/test/cmake_package_install/cmake_package_install.c b/programs/test/cmake_package_install/cmake_package_install.c index 9d5d3e4c73..e8517ba9da 100644 --- a/programs/test/cmake_package_install/cmake_package_install.c +++ b/programs/test/cmake_package_install/cmake_package_install.c @@ -46,5 +46,5 @@ int main() mbedtls_printf( "Built against %s\n", version ); - return( 0 ); + return 0 ; } diff --git a/programs/test/cmake_subproject/cmake_subproject.c b/programs/test/cmake_subproject/cmake_subproject.c index ff6ebf02e2..6f9d38343d 100644 --- a/programs/test/cmake_subproject/cmake_subproject.c +++ b/programs/test/cmake_subproject/cmake_subproject.c @@ -46,5 +46,5 @@ int main() mbedtls_printf( "Built against %s\n", version ); - return( 0 ); + return 0 ; } diff --git a/programs/test/query_compile_time_config.c b/programs/test/query_compile_time_config.c index a6eaf61590..e6403358eb 100644 --- a/programs/test/query_compile_time_config.c +++ b/programs/test/query_compile_time_config.c @@ -43,8 +43,8 @@ int main( int argc, char *argv[] ) if ( argc != 2 ) { mbedtls_printf( USAGE, argv[0] ); - return( MBEDTLS_EXIT_FAILURE ); + return MBEDTLS_EXIT_FAILURE ; } - return( query_config( argv[1] ) ); + return query_config( argv[1] ) ; } diff --git a/programs/test/selftest.c b/programs/test/selftest.c index c7bcc53ac9..72180bb8c2 100644 --- a/programs/test/selftest.c +++ b/programs/test/selftest.c @@ -147,7 +147,7 @@ static int calloc_self_test( int verbose ) mbedtls_free( empty2 ); mbedtls_free( buffer1 ); mbedtls_free( buffer2 ); - return( failures ); + return failures ; } #endif /* MBEDTLS_SELF_TEST */ @@ -165,10 +165,10 @@ static int test_snprintf( size_t n, const char *ref_buf, int ref_ret ) ref_ret != ret || memcmp( buf + n, ref + n, sizeof( buf ) - n ) != 0 ) { - return( 1 ); + return 1 ; } - return( 0 ); + return 0 ; } static int run_test_snprintf( void ) @@ -220,7 +220,7 @@ int mbedtls_entropy_self_test_wrapper( int verbose ) #if defined(MBEDTLS_ENTROPY_NV_SEED) && !defined(MBEDTLS_NO_PLATFORM_ENTROPY) create_entropy_seed_file( ); #endif - return( mbedtls_entropy_self_test( verbose ) ); + return mbedtls_entropy_self_test( verbose ) ; } #endif @@ -235,7 +235,7 @@ int mbedtls_memory_buffer_alloc_free_and_self_test( int verbose ) #endif } mbedtls_memory_buffer_alloc_free( ); - return( mbedtls_memory_buffer_alloc_self_test( verbose ) ); + return mbedtls_memory_buffer_alloc_self_test( verbose ) ; } #endif diff --git a/programs/test/udp_proxy.c b/programs/test/udp_proxy.c index 6546e8fd0a..aa01562d19 100644 --- a/programs/test/udp_proxy.c +++ b/programs/test/udp_proxy.c @@ -332,41 +332,41 @@ static void get_options( int argc, char *argv[] ) static const char *msg_type( unsigned char *msg, size_t len ) { - if( len < 1 ) return( "Invalid" ); + if( len < 1 ) return "Invalid" ; switch( msg[0] ) { - case MBEDTLS_SSL_MSG_CHANGE_CIPHER_SPEC: return( "ChangeCipherSpec" ); - case MBEDTLS_SSL_MSG_ALERT: return( "Alert" ); - case MBEDTLS_SSL_MSG_APPLICATION_DATA: return( "ApplicationData" ); - case MBEDTLS_SSL_MSG_CID: return( "CID" ); + case MBEDTLS_SSL_MSG_CHANGE_CIPHER_SPEC: return "ChangeCipherSpec" ; + case MBEDTLS_SSL_MSG_ALERT: return "Alert" ; + case MBEDTLS_SSL_MSG_APPLICATION_DATA: return "ApplicationData" ; + case MBEDTLS_SSL_MSG_CID: return "CID" ; case MBEDTLS_SSL_MSG_HANDSHAKE: break; /* See below */ - default: return( "Unknown" ); + default: return "Unknown" ; } - if( len < 13 + 12 ) return( "Invalid handshake" ); + if( len < 13 + 12 ) return "Invalid handshake" ; /* * Our handshake message are less than 2^16 bytes long, so they should * have 0 as the first byte of length, frag_offset and frag_length. * Otherwise, assume they are encrypted. */ - if( msg[14] || msg[19] || msg[22] ) return( "Encrypted handshake" ); + if( msg[14] || msg[19] || msg[22] ) return "Encrypted handshake" ; switch( msg[13] ) { - case MBEDTLS_SSL_HS_HELLO_REQUEST: return( "HelloRequest" ); - case MBEDTLS_SSL_HS_CLIENT_HELLO: return( "ClientHello" ); - case MBEDTLS_SSL_HS_SERVER_HELLO: return( "ServerHello" ); - case MBEDTLS_SSL_HS_HELLO_VERIFY_REQUEST: return( "HelloVerifyRequest" ); - case MBEDTLS_SSL_HS_NEW_SESSION_TICKET: return( "NewSessionTicket" ); - case MBEDTLS_SSL_HS_CERTIFICATE: return( "Certificate" ); - case MBEDTLS_SSL_HS_SERVER_KEY_EXCHANGE: return( "ServerKeyExchange" ); - case MBEDTLS_SSL_HS_CERTIFICATE_REQUEST: return( "CertificateRequest" ); - case MBEDTLS_SSL_HS_SERVER_HELLO_DONE: return( "ServerHelloDone" ); - case MBEDTLS_SSL_HS_CERTIFICATE_VERIFY: return( "CertificateVerify" ); - case MBEDTLS_SSL_HS_CLIENT_KEY_EXCHANGE: return( "ClientKeyExchange" ); - case MBEDTLS_SSL_HS_FINISHED: return( "Finished" ); - default: return( "Unknown handshake" ); + case MBEDTLS_SSL_HS_HELLO_REQUEST: return "HelloRequest" ; + case MBEDTLS_SSL_HS_CLIENT_HELLO: return "ClientHello" ; + case MBEDTLS_SSL_HS_SERVER_HELLO: return "ServerHello" ; + case MBEDTLS_SSL_HS_HELLO_VERIFY_REQUEST: return "HelloVerifyRequest" ; + case MBEDTLS_SSL_HS_NEW_SESSION_TICKET: return "NewSessionTicket" ; + case MBEDTLS_SSL_HS_CERTIFICATE: return "Certificate" ; + case MBEDTLS_SSL_HS_SERVER_KEY_EXCHANGE: return "ServerKeyExchange" ; + case MBEDTLS_SSL_HS_CERTIFICATE_REQUEST: return "CertificateRequest" ; + case MBEDTLS_SSL_HS_SERVER_HELLO_DONE: return "ServerHelloDone" ; + case MBEDTLS_SSL_HS_CERTIFICATE_VERIFY: return "CertificateVerify" ; + case MBEDTLS_SSL_HS_CLIENT_KEY_EXCHANGE: return "ClientKeyExchange" ; + case MBEDTLS_SSL_HS_FINISHED: return "Finished" ; + default: return "Unknown handshake" ; } } @@ -381,10 +381,10 @@ static unsigned ellapsed_time( void ) { (void) mbedtls_timing_get_timer( &hires, 1 ); initialized = 1; - return( 0 ); + return 0 ; } - return( mbedtls_timing_get_timer( &hires, 0 ) ); + return mbedtls_timing_get_timer( &hires, 0 ) ; } typedef struct @@ -417,7 +417,7 @@ static int ctx_buffer_flush( ctx_buffer *buf ) buf->len = 0; buf->num_datagrams = 0; - return( ret ); + return ret ; } static unsigned ctx_buffer_time_remaining( ctx_buffer *buf ) @@ -425,12 +425,12 @@ static unsigned ctx_buffer_time_remaining( ctx_buffer *buf ) unsigned const cur_time = ellapsed_time(); if( buf->num_datagrams == 0 ) - return( (unsigned) -1 ); + return (unsigned) -1 ; if( cur_time - buf->packet_lifetime >= opt.pack ) - return( 0 ); + return 0 ; - return( opt.pack - ( cur_time - buf->packet_lifetime ) ); + return opt.pack - ( cur_time - buf->packet_lifetime ) ; } static int ctx_buffer_append( ctx_buffer *buf, @@ -440,13 +440,13 @@ static int ctx_buffer_append( ctx_buffer *buf, int ret; if( len > (size_t) INT_MAX ) - return( -1 ); + return -1 ; if( len > sizeof( buf->data ) ) { mbedtls_printf( " ! buffer size %u too large (max %u)\n", (unsigned) len, (unsigned) sizeof( buf->data ) ); - return( -1 ); + return -1 ; } if( sizeof( buf->data ) - buf->len < len ) @@ -454,7 +454,7 @@ static int ctx_buffer_append( ctx_buffer *buf, if( ( ret = ctx_buffer_flush( buf ) ) <= 0 ) { mbedtls_printf( "ctx_buffer_flush failed with -%#04x", (unsigned int) -ret ); - return( ret ); + return ret ; } } @@ -464,7 +464,7 @@ static int ctx_buffer_append( ctx_buffer *buf, if( ++buf->num_datagrams == 1 ) buf->packet_lifetime = ellapsed_time(); - return( (int) len ); + return (int) len ; } #endif /* MBEDTLS_TIMING_C */ @@ -483,9 +483,9 @@ static int dispatch_data( mbedtls_net_context *ctx, buf = &outbuf[1]; if( buf == NULL ) - return( -1 ); + return -1 ; - return( ctx_buffer_append( buf, data, len ) ); + return ctx_buffer_append( buf, data, len ) ; } #endif /* MBEDTLS_TIMING_C */ @@ -494,7 +494,7 @@ static int dispatch_data( mbedtls_net_context *ctx, { mbedtls_printf( "net_send returned -%#04x\n", (unsigned int) -ret ); } - return( ret ); + return ret ; } typedef struct @@ -578,7 +578,7 @@ int send_packet( const packet *p, const char *why ) if( ( ret = dispatch_data( dst, buf, p->len ) ) <= 0 ) { mbedtls_printf( " ! dispatch returned %d\n", ret ); - return( ret ); + return ret ; } } @@ -602,7 +602,7 @@ int send_packet( const packet *p, const char *why ) if( ( ret = dispatch_data( dst, buf, p->len ) ) <= 0 ) { mbedtls_printf( " ! dispatch returned %d\n", ret ); - return( ret ); + return ret ; } } @@ -610,7 +610,7 @@ int send_packet( const packet *p, const char *why ) if( ( ret = dispatch_data( dst, p->buf, p->len ) ) <= 0 ) { mbedtls_printf( " ! dispatch returned %d\n", ret ); - return( ret ); + return ret ; } /* Don't duplicate Application Data, only handshake covered */ @@ -623,7 +623,7 @@ int send_packet( const packet *p, const char *why ) if( ( ret = dispatch_data( dst, p->buf, p->len ) ) <= 0 ) { mbedtls_printf( " ! dispatch returned %d\n", ret ); - return( ret ); + return ret ; } } @@ -638,13 +638,13 @@ int send_packet( const packet *p, const char *why ) initial_clihlo.len ) ) <= 0 ) { mbedtls_printf( " ! dispatch returned %d\n", ret ); - return( ret ); + return ret ; } inject_clihlo_state = ICH_INJECTED; } - return( 0 ); + return 0 ; } #define MAX_DELAYED_MSG 5 @@ -673,11 +673,11 @@ int send_delayed() { ret = send_packet( &prev[offset], "delayed" ); if( ret != 0 ) - return( ret ); + return ret ; } clear_pending(); - return( 0 ); + return 0 ; } /* @@ -713,7 +713,7 @@ int handle_message( const char *way, if( ( ret = mbedtls_net_recv( src, cur.buf, sizeof( cur.buf ) ) ) <= 0 ) { mbedtls_printf( " ! mbedtls_net_recv returned %d\n", ret ); - return( ret ); + return ret ; } cur.len = ret; @@ -751,7 +751,7 @@ int handle_message( const char *way, mbedtls_free( delay_list[delay_idx] ); delay_list[delay_idx] = NULL; - return( 0 ); + return 0 ; } } @@ -787,15 +787,15 @@ int handle_message( const char *way, { /* forward and possibly duplicate */ if( ( ret = send_packet( &cur, "forwarded" ) ) != 0 ) - return( ret ); + return ret ; /* send previously delayed messages if any */ ret = send_delayed(); if( ret != 0 ) - return( ret ); + return ret ; } - return( 0 ); + return 0 ; } int main( int argc, char *argv[] ) diff --git a/programs/util/pem2der.c b/programs/util/pem2der.c index e273200a9e..f70aaeea4a 100644 --- a/programs/util/pem2der.c +++ b/programs/util/pem2der.c @@ -78,11 +78,11 @@ int convert_pem_to_der( const unsigned char *input, size_t ilen, s1 = (unsigned char *) strstr( (const char *) input, "-----BEGIN" ); if( s1 == NULL ) - return( -1 ); + return -1 ; s2 = (unsigned char *) strstr( (const char *) input, "-----END" ); if( s2 == NULL ) - return( -1 ); + return -1 ; s1 += 10; while( s1 < end && *s1 != '-' ) @@ -93,24 +93,24 @@ int convert_pem_to_der( const unsigned char *input, size_t ilen, if( *s1 == '\n' ) s1++; if( s2 <= s1 || s2 > end ) - return( -1 ); + return -1 ; ret = mbedtls_base64_decode( NULL, 0, &len, (const unsigned char *) s1, s2 - s1 ); if( ret == MBEDTLS_ERR_BASE64_INVALID_CHARACTER ) - return( ret ); + return ret ; if( len > *olen ) - return( -1 ); + return -1 ; if( ( ret = mbedtls_base64_decode( output, len, &len, (const unsigned char *) s1, s2 - s1 ) ) != 0 ) { - return( ret ); + return ret ; } *olen = len; - return( 0 ); + return 0 ; } /* @@ -122,13 +122,13 @@ static int load_file( const char *path, unsigned char **buf, size_t *n ) long size; if( ( f = fopen( path, "rb" ) ) == NULL ) - return( -1 ); + return -1 ; fseek( f, 0, SEEK_END ); if( ( size = ftell( f ) ) == -1 ) { fclose( f ); - return( -1 ); + return -1 ; } fseek( f, 0, SEEK_SET ); @@ -138,7 +138,7 @@ static int load_file( const char *path, unsigned char **buf, size_t *n ) ( *buf = mbedtls_calloc( 1, *n + 1 ) ) == NULL ) { fclose( f ); - return( -1 ); + return -1 ; } if( fread( *buf, 1, *n, f ) != *n ) @@ -146,14 +146,14 @@ static int load_file( const char *path, unsigned char **buf, size_t *n ) fclose( f ); free( *buf ); *buf = NULL; - return( -1 ); + return -1 ; } fclose( f ); (*buf)[*n] = '\0'; - return( 0 ); + return 0 ; } /* @@ -164,16 +164,16 @@ static int write_file( const char *path, unsigned char *buf, size_t n ) FILE *f; if( ( f = fopen( path, "wb" ) ) == NULL ) - return( -1 ); + return -1 ; if( fwrite( buf, 1, n, f ) != n ) { fclose( f ); - return( -1 ); + return -1 ; } fclose( f ); - return( 0 ); + return 0 ; } int main( int argc, char *argv[] ) diff --git a/programs/util/strerror.c b/programs/util/strerror.c index 4b776d340e..dda6916977 100644 --- a/programs/util/strerror.c +++ b/programs/util/strerror.c @@ -65,7 +65,7 @@ int main( int argc, char *argv[] ) if( *end != '\0' ) { mbedtls_printf( USAGE ); - return( 0 ); + return 0 ; } } if( val > 0 ) diff --git a/programs/x509/cert_app.c b/programs/x509/cert_app.c index aab15db2b7..65276e7ce9 100644 --- a/programs/x509/cert_app.c +++ b/programs/x509/cert_app.c @@ -138,7 +138,7 @@ static int my_verify( void *data, mbedtls_x509_crt *crt, int depth, uint32_t *fl mbedtls_printf( "%s\n", buf ); } - return( 0 ); + return 0 ; } int main( int argc, char *argv[] ) diff --git a/programs/x509/cert_req.c b/programs/x509/cert_req.c index ed42079b49..03dbd209a2 100644 --- a/programs/x509/cert_req.c +++ b/programs/x509/cert_req.c @@ -129,22 +129,22 @@ int write_certificate_request( mbedtls_x509write_csr *req, const char *output_fi memset( output_buf, 0, 4096 ); if( ( ret = mbedtls_x509write_csr_pem( req, output_buf, 4096, f_rng, p_rng ) ) < 0 ) - return( ret ); + return ret ; len = strlen( (char *) output_buf ); if( ( f = fopen( output_file, "w" ) ) == NULL ) - return( -1 ); + return -1 ; if( fwrite( output_buf, 1, len, f ) != len ) { fclose( f ); - return( -1 ); + return -1 ; } fclose( f ); - return( 0 ); + return 0 ; } int main( int argc, char *argv[] ) diff --git a/programs/x509/cert_write.c b/programs/x509/cert_write.c index 9a20d63419..72e823fa7f 100644 --- a/programs/x509/cert_write.c +++ b/programs/x509/cert_write.c @@ -191,22 +191,22 @@ int write_certificate( mbedtls_x509write_cert *crt, const char *output_file, memset( output_buf, 0, 4096 ); if( ( ret = mbedtls_x509write_crt_pem( crt, output_buf, 4096, f_rng, p_rng ) ) < 0 ) - return( ret ); + return ret ; len = strlen( (char *) output_buf ); if( ( f = fopen( output_file, "w" ) ) == NULL ) - return( -1 ); + return -1 ; if( fwrite( output_buf, 1, len, f ) != len ) { fclose( f ); - return( -1 ); + return -1 ; } fclose( f ); - return( 0 ); + return 0 ; } int main( int argc, char *argv[] ) diff --git a/scripts/data_files/error.fmt b/scripts/data_files/error.fmt index 3be94bd2c4..6c2b487aed 100644 --- a/scripts/data_files/error.fmt +++ b/scripts/data_files/error.fmt @@ -56,7 +56,7 @@ HIGH_LEVEL_CODE_CHECKS break; } - return( NULL ); + return NULL ; } const char * mbedtls_low_level_strerr( int error_code ) @@ -79,7 +79,7 @@ LOW_LEVEL_CODE_CHECKS break; } - return( NULL ); + return NULL ; } void mbedtls_strerror( int ret, char *buf, size_t buflen ) diff --git a/scripts/data_files/query_config.fmt b/scripts/data_files/query_config.fmt index ffa816ecee..77f628fb84 100644 --- a/scripts/data_files/query_config.fmt +++ b/scripts/data_files/query_config.fmt @@ -115,7 +115,7 @@ int query_config( const char *config ) { CHECK_CONFIG /* If the symbol is not found, return an error */ - return( 1 ); + return 1 ; } #if defined(_MSC_VER) diff --git a/scripts/data_files/version_features.fmt b/scripts/data_files/version_features.fmt index d4bf774462..e572c5ef19 100644 --- a/scripts/data_files/version_features.fmt +++ b/scripts/data_files/version_features.fmt @@ -37,18 +37,18 @@ int mbedtls_version_check_feature( const char *feature ) const char * const *idx = features; if( *idx == NULL ) - return( -2 ); + return -2 ; if( feature == NULL ) - return( -1 ); + return -1 ; while( *idx != NULL ) { if( !strcmp( *idx, feature ) ) - return( 0 ); + return 0 ; idx++; } - return( -1 ); + return -1 ; } #endif /* MBEDTLS_VERSION_C */ diff --git a/tests/configs/config-wrapper-malloc-0-null.h b/tests/configs/config-wrapper-malloc-0-null.h index e7bdbeb9e4..2cb772277b 100644 --- a/tests/configs/config-wrapper-malloc-0-null.h +++ b/tests/configs/config-wrapper-malloc-0-null.h @@ -24,8 +24,8 @@ static inline void *custom_calloc( size_t nmemb, size_t size ) { if( nmemb == 0 || size == 0 ) - return( NULL ); - return( calloc( nmemb, size ) ); + return NULL ; + return calloc( nmemb, size ) ; } #define MBEDTLS_PLATFORM_MEMORY diff --git a/tests/include/test/drivers/aead.h b/tests/include/test/drivers/aead.h index 0830229e4e..92c2989a48 100644 --- a/tests/include/test/drivers/aead.h +++ b/tests/include/test/drivers/aead.h @@ -40,7 +40,7 @@ static inline mbedtls_test_driver_aead_hooks_t mbedtls_test_driver_aead_hooks_init( void ) { const mbedtls_test_driver_aead_hooks_t v = MBEDTLS_TEST_DRIVER_AEAD_INIT; - return( v ); + return v ; } extern mbedtls_test_driver_aead_hooks_t mbedtls_test_driver_aead_hooks; diff --git a/tests/include/test/drivers/cipher.h b/tests/include/test/drivers/cipher.h index 142f3b7655..8dbee9263f 100644 --- a/tests/include/test/drivers/cipher.h +++ b/tests/include/test/drivers/cipher.h @@ -44,7 +44,7 @@ static inline mbedtls_test_driver_cipher_hooks_t mbedtls_test_driver_cipher_hooks_init( void ) { const mbedtls_test_driver_cipher_hooks_t v = MBEDTLS_TEST_DRIVER_CIPHER_INIT; - return( v ); + return v ; } extern mbedtls_test_driver_cipher_hooks_t mbedtls_test_driver_cipher_hooks; diff --git a/tests/include/test/drivers/hash.h b/tests/include/test/drivers/hash.h index d202c8bf06..f72a1a5932 100644 --- a/tests/include/test/drivers/hash.h +++ b/tests/include/test/drivers/hash.h @@ -40,7 +40,7 @@ static inline mbedtls_test_driver_hash_hooks_t mbedtls_test_driver_hash_hooks_init( void ) { const mbedtls_test_driver_hash_hooks_t v = MBEDTLS_TEST_DRIVER_HASH_INIT; - return( v ); + return v ; } extern mbedtls_test_driver_hash_hooks_t mbedtls_test_driver_hash_hooks; diff --git a/tests/include/test/drivers/key_management.h b/tests/include/test/drivers/key_management.h index 16e1f755ca..8c9c628c81 100644 --- a/tests/include/test/drivers/key_management.h +++ b/tests/include/test/drivers/key_management.h @@ -46,7 +46,7 @@ static inline mbedtls_test_driver_key_management_hooks_t { const mbedtls_test_driver_key_management_hooks_t v = MBEDTLS_TEST_DRIVER_KEY_MANAGEMENT_INIT; - return( v ); + return v ; } extern mbedtls_test_driver_key_management_hooks_t diff --git a/tests/include/test/drivers/mac.h b/tests/include/test/drivers/mac.h index 5f6cd38a4d..6c0e96b42e 100644 --- a/tests/include/test/drivers/mac.h +++ b/tests/include/test/drivers/mac.h @@ -40,7 +40,7 @@ static inline mbedtls_test_driver_mac_hooks_t mbedtls_test_driver_mac_hooks_init( void ) { const mbedtls_test_driver_mac_hooks_t v = MBEDTLS_TEST_DRIVER_MAC_INIT; - return( v ); + return v ; } extern mbedtls_test_driver_mac_hooks_t mbedtls_test_driver_mac_hooks; diff --git a/tests/include/test/drivers/signature.h b/tests/include/test/drivers/signature.h index 67f2b29a35..c540d4cefe 100644 --- a/tests/include/test/drivers/signature.h +++ b/tests/include/test/drivers/signature.h @@ -42,7 +42,7 @@ static inline mbedtls_test_driver_signature_hooks_t { const mbedtls_test_driver_signature_hooks_t v = MBEDTLS_TEST_DRIVER_SIGNATURE_INIT; - return( v ); + return v ; } extern mbedtls_test_driver_signature_hooks_t diff --git a/tests/src/asn1_helpers.c b/tests/src/asn1_helpers.c index 79aa166ce6..8ece1e3dce 100644 --- a/tests/src/asn1_helpers.c +++ b/tests/src/asn1_helpers.c @@ -52,7 +52,7 @@ int mbedtls_test_asn1_skip_integer( unsigned char **p, const unsigned char *end, --len; } if( min_bits == 0 && len == 0 ) - return( 1 ); + return 1 ; msb = ( *p )[0]; TEST_ASSERT( msb != 0 ); actual_bits = 8 * ( len - 1 ); @@ -66,9 +66,9 @@ int mbedtls_test_asn1_skip_integer( unsigned char **p, const unsigned char *end, if( must_be_odd ) TEST_ASSERT( ( ( *p )[len-1] & 1 ) != 0 ); *p += len; - return( 1 ); + return 1 ; exit: - return( 0 ); + return 0 ; } #endif /* MBEDTLS_ASN1_PARSE_C */ diff --git a/tests/src/drivers/hash.c b/tests/src/drivers/hash.c index b1880f778e..d57ce6ca30 100644 --- a/tests/src/drivers/hash.c +++ b/tests/src/drivers/hash.c @@ -47,7 +47,7 @@ psa_status_t mbedtls_test_transparent_hash_compute( hash, hash_size, hash_length ); } - return( mbedtls_test_driver_hash_hooks.driver_status ); + return mbedtls_test_driver_hash_hooks.driver_status ; } psa_status_t mbedtls_test_transparent_hash_setup( @@ -67,7 +67,7 @@ psa_status_t mbedtls_test_transparent_hash_setup( mbedtls_transparent_test_driver_hash_setup( operation, alg ); } - return( mbedtls_test_driver_hash_hooks.driver_status ); + return mbedtls_test_driver_hash_hooks.driver_status ; } psa_status_t mbedtls_test_transparent_hash_clone( @@ -88,7 +88,7 @@ psa_status_t mbedtls_test_transparent_hash_clone( target_operation ); } - return( mbedtls_test_driver_hash_hooks.driver_status ); + return mbedtls_test_driver_hash_hooks.driver_status ; } psa_status_t mbedtls_test_transparent_hash_update( @@ -110,7 +110,7 @@ psa_status_t mbedtls_test_transparent_hash_update( operation, input, input_length ); } - return( mbedtls_test_driver_hash_hooks.driver_status ); + return mbedtls_test_driver_hash_hooks.driver_status ; } psa_status_t mbedtls_test_transparent_hash_finish( @@ -133,7 +133,7 @@ psa_status_t mbedtls_test_transparent_hash_finish( operation, hash, hash_size, hash_length ); } - return( mbedtls_test_driver_hash_hooks.driver_status ); + return mbedtls_test_driver_hash_hooks.driver_status ; } psa_status_t mbedtls_test_transparent_hash_abort( @@ -152,6 +152,6 @@ psa_status_t mbedtls_test_transparent_hash_abort( mbedtls_transparent_test_driver_hash_abort( operation ); } - return( mbedtls_test_driver_hash_hooks.driver_status ); + return mbedtls_test_driver_hash_hooks.driver_status ; } #endif /* MBEDTLS_PSA_CRYPTO_DRIVERS && PSA_CRYPTO_DRIVER_TEST */ diff --git a/tests/src/drivers/platform_builtin_keys.c b/tests/src/drivers/platform_builtin_keys.c index da5865d869..6d125a0ddf 100644 --- a/tests/src/drivers/platform_builtin_keys.c +++ b/tests/src/drivers/platform_builtin_keys.c @@ -85,9 +85,9 @@ psa_status_t mbedtls_psa_platform_get_builtin_key( { *lifetime = builtin_key->lifetime; *slot_number = builtin_key->slot_number; - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } } - return( PSA_ERROR_DOES_NOT_EXIST ); + return PSA_ERROR_DOES_NOT_EXIST ; } diff --git a/tests/src/drivers/test_driver_aead.c b/tests/src/drivers/test_driver_aead.c index ce9ce37795..76afcd75f0 100644 --- a/tests/src/drivers/test_driver_aead.c +++ b/tests/src/drivers/test_driver_aead.c @@ -55,7 +55,7 @@ psa_status_t mbedtls_test_transparent_aead_encrypt( ciphertext, ciphertext_size, ciphertext_length ); } - return( mbedtls_test_driver_aead_hooks.driver_status ); + return mbedtls_test_driver_aead_hooks.driver_status ; } psa_status_t mbedtls_test_transparent_aead_decrypt( @@ -86,7 +86,7 @@ psa_status_t mbedtls_test_transparent_aead_decrypt( plaintext, plaintext_size, plaintext_length ); } - return( mbedtls_test_driver_aead_hooks.driver_status ); + return mbedtls_test_driver_aead_hooks.driver_status ; } #endif /* MBEDTLS_PSA_CRYPTO_DRIVERS && PSA_CRYPTO_DRIVER_TEST */ diff --git a/tests/src/drivers/test_driver_cipher.c b/tests/src/drivers/test_driver_cipher.c index 89a7b59944..20d79d8d83 100644 --- a/tests/src/drivers/test_driver_cipher.c +++ b/tests/src/drivers/test_driver_cipher.c @@ -51,18 +51,18 @@ psa_status_t mbedtls_test_transparent_cipher_encrypt( if( mbedtls_test_driver_cipher_hooks.forced_output != NULL ) { if( output_size < mbedtls_test_driver_cipher_hooks.forced_output_length ) - return( PSA_ERROR_BUFFER_TOO_SMALL ); + return PSA_ERROR_BUFFER_TOO_SMALL ; memcpy( output, mbedtls_test_driver_cipher_hooks.forced_output, mbedtls_test_driver_cipher_hooks.forced_output_length ); *output_length = mbedtls_test_driver_cipher_hooks.forced_output_length; - return( mbedtls_test_driver_cipher_hooks.forced_status ); + return mbedtls_test_driver_cipher_hooks.forced_status ; } if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS ) - return( mbedtls_test_driver_cipher_hooks.forced_status ); + return mbedtls_test_driver_cipher_hooks.forced_status ; psa_generate_random( output, PSA_CIPHER_IV_LENGTH( attributes->core.type, alg ) ); @@ -88,18 +88,18 @@ psa_status_t mbedtls_test_transparent_cipher_decrypt( if( mbedtls_test_driver_cipher_hooks.forced_output != NULL ) { if( output_size < mbedtls_test_driver_cipher_hooks.forced_output_length ) - return( PSA_ERROR_BUFFER_TOO_SMALL ); + return PSA_ERROR_BUFFER_TOO_SMALL ; memcpy( output, mbedtls_test_driver_cipher_hooks.forced_output, mbedtls_test_driver_cipher_hooks.forced_output_length ); *output_length = mbedtls_test_driver_cipher_hooks.forced_output_length; - return( mbedtls_test_driver_cipher_hooks.forced_status ); + return mbedtls_test_driver_cipher_hooks.forced_status ; } if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS ) - return( mbedtls_test_driver_cipher_hooks.forced_status ); + return mbedtls_test_driver_cipher_hooks.forced_status ; return( mbedtls_transparent_test_driver_cipher_decrypt( attributes, key_buffer, key_buffer_size, @@ -122,7 +122,7 @@ psa_status_t mbedtls_test_transparent_cipher_encrypt_setup( memset( operation, 0, sizeof( *operation ) ); if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS ) - return( mbedtls_test_driver_cipher_hooks.forced_status ); + return mbedtls_test_driver_cipher_hooks.forced_status ; return ( mbedtls_transparent_test_driver_cipher_encrypt_setup( operation, attributes, key, key_length, alg ) ); @@ -137,7 +137,7 @@ psa_status_t mbedtls_test_transparent_cipher_decrypt_setup( mbedtls_test_driver_cipher_hooks.hits++; if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS ) - return( mbedtls_test_driver_cipher_hooks.forced_status ); + return mbedtls_test_driver_cipher_hooks.forced_status ; return ( mbedtls_transparent_test_driver_cipher_decrypt_setup( operation, attributes, key, key_length, alg ) ); @@ -149,7 +149,7 @@ psa_status_t mbedtls_test_transparent_cipher_abort( mbedtls_test_driver_cipher_hooks.hits++; if( operation->alg == 0 ) - return( PSA_SUCCESS ); + return PSA_SUCCESS ; mbedtls_transparent_test_driver_cipher_abort( operation ); @@ -159,7 +159,7 @@ psa_status_t mbedtls_test_transparent_cipher_abort( * our context struct. */ memset( operation, 0, sizeof( *operation ) ); - return( mbedtls_test_driver_cipher_hooks.forced_status ); + return mbedtls_test_driver_cipher_hooks.forced_status ; } psa_status_t mbedtls_test_transparent_cipher_set_iv( @@ -170,7 +170,7 @@ psa_status_t mbedtls_test_transparent_cipher_set_iv( mbedtls_test_driver_cipher_hooks.hits++; if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS ) - return( mbedtls_test_driver_cipher_hooks.forced_status ); + return mbedtls_test_driver_cipher_hooks.forced_status ; return( mbedtls_transparent_test_driver_cipher_set_iv( operation, iv, iv_length ) ); @@ -196,11 +196,11 @@ psa_status_t mbedtls_test_transparent_cipher_update( mbedtls_test_driver_cipher_hooks.forced_output_length ); *output_length = mbedtls_test_driver_cipher_hooks.forced_output_length; - return( mbedtls_test_driver_cipher_hooks.forced_status ); + return mbedtls_test_driver_cipher_hooks.forced_status ; } if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS ) - return( mbedtls_test_driver_cipher_hooks.forced_status ); + return mbedtls_test_driver_cipher_hooks.forced_status ; return( mbedtls_transparent_test_driver_cipher_update( operation, input, input_length, @@ -225,11 +225,11 @@ psa_status_t mbedtls_test_transparent_cipher_finish( mbedtls_test_driver_cipher_hooks.forced_output_length ); *output_length = mbedtls_test_driver_cipher_hooks.forced_output_length; - return( mbedtls_test_driver_cipher_hooks.forced_status ); + return mbedtls_test_driver_cipher_hooks.forced_status ; } if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS ) - return( mbedtls_test_driver_cipher_hooks.forced_status ); + return mbedtls_test_driver_cipher_hooks.forced_status ; return( mbedtls_transparent_test_driver_cipher_finish( operation, output, output_size, output_length ) ); @@ -254,7 +254,7 @@ psa_status_t mbedtls_test_opaque_cipher_encrypt( (void) output; (void) output_size; (void) output_length; - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; } psa_status_t mbedtls_test_opaque_cipher_decrypt( @@ -273,7 +273,7 @@ psa_status_t mbedtls_test_opaque_cipher_decrypt( (void) output; (void) output_size; (void) output_length; - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; } psa_status_t mbedtls_test_opaque_cipher_encrypt_setup( @@ -287,7 +287,7 @@ psa_status_t mbedtls_test_opaque_cipher_encrypt_setup( (void) key; (void) key_length; (void) alg; - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; } psa_status_t mbedtls_test_opaque_cipher_decrypt_setup( @@ -301,14 +301,14 @@ psa_status_t mbedtls_test_opaque_cipher_decrypt_setup( (void) key; (void) key_length; (void) alg; - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; } psa_status_t mbedtls_test_opaque_cipher_abort( mbedtls_opaque_test_driver_cipher_operation_t *operation ) { (void) operation; - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; } psa_status_t mbedtls_test_opaque_cipher_set_iv( @@ -319,7 +319,7 @@ psa_status_t mbedtls_test_opaque_cipher_set_iv( (void) operation; (void) iv; (void) iv_length; - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; } psa_status_t mbedtls_test_opaque_cipher_update( @@ -336,7 +336,7 @@ psa_status_t mbedtls_test_opaque_cipher_update( (void) output; (void) output_size; (void) output_length; - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; } psa_status_t mbedtls_test_opaque_cipher_finish( @@ -349,6 +349,6 @@ psa_status_t mbedtls_test_opaque_cipher_finish( (void) output; (void) output_size; (void) output_length; - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; } #endif /* MBEDTLS_PSA_CRYPTO_DRIVERS && PSA_CRYPTO_DRIVER_TEST */ diff --git a/tests/src/drivers/test_driver_key_management.c b/tests/src/drivers/test_driver_key_management.c index afa1fc261e..d2bc9b82dc 100644 --- a/tests/src/drivers/test_driver_key_management.c +++ b/tests/src/drivers/test_driver_key_management.c @@ -63,17 +63,17 @@ psa_status_t mbedtls_test_transparent_generate_key( ++mbedtls_test_driver_key_management_hooks.hits; if( mbedtls_test_driver_key_management_hooks.forced_status != PSA_SUCCESS ) - return( mbedtls_test_driver_key_management_hooks.forced_status ); + return mbedtls_test_driver_key_management_hooks.forced_status ; if( mbedtls_test_driver_key_management_hooks.forced_output != NULL ) { if( mbedtls_test_driver_key_management_hooks.forced_output_length > key_size ) - return( PSA_ERROR_BUFFER_TOO_SMALL ); + return PSA_ERROR_BUFFER_TOO_SMALL ; memcpy( key, mbedtls_test_driver_key_management_hooks.forced_output, mbedtls_test_driver_key_management_hooks.forced_output_length ); *key_length = mbedtls_test_driver_key_management_hooks.forced_output_length; - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } /* Copied from psa_crypto.c */ @@ -95,7 +95,7 @@ psa_status_t mbedtls_test_transparent_generate_key( #endif /* defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_KEY_PAIR) */ { (void)attributes; - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; } } @@ -107,7 +107,7 @@ psa_status_t mbedtls_test_opaque_generate_key( (void) key; (void) key_size; (void) key_length; - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; } psa_status_t mbedtls_test_transparent_import_key( @@ -122,7 +122,7 @@ psa_status_t mbedtls_test_transparent_import_key( ++mbedtls_test_driver_key_management_hooks.hits; if( mbedtls_test_driver_key_management_hooks.forced_status != PSA_SUCCESS ) - return( mbedtls_test_driver_key_management_hooks.forced_status ); + return mbedtls_test_driver_key_management_hooks.forced_status ; psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED; psa_key_type_t type = psa_get_key_type( attributes ); @@ -162,7 +162,7 @@ psa_status_t mbedtls_test_transparent_import_key( (void)type; } - return( status ); + return status ; } psa_status_t mbedtls_test_opaque_export_key( @@ -173,7 +173,7 @@ psa_status_t mbedtls_test_opaque_export_key( if( key_length != sizeof( psa_drv_slot_number_t ) ) { /* Test driver does not support generic opaque key handling yet. */ - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; } /* Assume this is a builtin key based on the key material length. */ @@ -186,47 +186,47 @@ psa_status_t mbedtls_test_opaque_export_key( * returning the private key. */ if( psa_get_key_type( attributes ) != PSA_KEY_TYPE_ECC_KEY_PAIR( PSA_ECC_FAMILY_SECP_R1 ) ) - return( PSA_ERROR_CORRUPTION_DETECTED ); + return PSA_ERROR_CORRUPTION_DETECTED ; if( psa_get_key_bits( attributes ) != 256 ) - return( PSA_ERROR_CORRUPTION_DETECTED ); + return PSA_ERROR_CORRUPTION_DETECTED ; if( psa_get_key_algorithm( attributes ) != PSA_ALG_ECDSA( PSA_ALG_ANY_HASH ) ) - return( PSA_ERROR_CORRUPTION_DETECTED ); + return PSA_ERROR_CORRUPTION_DETECTED ; if( ( psa_get_key_usage_flags( attributes ) & PSA_KEY_USAGE_EXPORT ) == 0 ) - return( PSA_ERROR_CORRUPTION_DETECTED ); + return PSA_ERROR_CORRUPTION_DETECTED ; if( data_size < sizeof( mbedtls_test_driver_ecdsa_key ) ) - return( PSA_ERROR_BUFFER_TOO_SMALL ); + return PSA_ERROR_BUFFER_TOO_SMALL ; memcpy( data, mbedtls_test_driver_ecdsa_key, sizeof( mbedtls_test_driver_ecdsa_key ) ); *data_length = sizeof( mbedtls_test_driver_ecdsa_key ); - return( PSA_SUCCESS ); + return PSA_SUCCESS ; case PSA_CRYPTO_TEST_DRIVER_BUILTIN_AES_KEY_SLOT: /* This is the AES slot. Verify the key's attributes before * returning the key. */ if( psa_get_key_type( attributes ) != PSA_KEY_TYPE_AES ) - return( PSA_ERROR_CORRUPTION_DETECTED ); + return PSA_ERROR_CORRUPTION_DETECTED ; if( psa_get_key_bits( attributes ) != 128 ) - return( PSA_ERROR_CORRUPTION_DETECTED ); + return PSA_ERROR_CORRUPTION_DETECTED ; if( psa_get_key_algorithm( attributes ) != PSA_ALG_CTR ) - return( PSA_ERROR_CORRUPTION_DETECTED ); + return PSA_ERROR_CORRUPTION_DETECTED ; if( ( psa_get_key_usage_flags( attributes ) & PSA_KEY_USAGE_EXPORT ) == 0 ) - return( PSA_ERROR_CORRUPTION_DETECTED ); + return PSA_ERROR_CORRUPTION_DETECTED ; if( data_size < sizeof( mbedtls_test_driver_aes_key ) ) - return( PSA_ERROR_BUFFER_TOO_SMALL ); + return PSA_ERROR_BUFFER_TOO_SMALL ; memcpy( data, mbedtls_test_driver_aes_key, sizeof( mbedtls_test_driver_aes_key ) ); *data_length = sizeof( mbedtls_test_driver_aes_key ); - return( PSA_SUCCESS ); + return PSA_SUCCESS ; default: - return( PSA_ERROR_DOES_NOT_EXIST ); + return PSA_ERROR_DOES_NOT_EXIST ; } } @@ -238,17 +238,17 @@ psa_status_t mbedtls_test_transparent_export_public_key( ++mbedtls_test_driver_key_management_hooks.hits; if( mbedtls_test_driver_key_management_hooks.forced_status != PSA_SUCCESS ) - return( mbedtls_test_driver_key_management_hooks.forced_status ); + return mbedtls_test_driver_key_management_hooks.forced_status ; if( mbedtls_test_driver_key_management_hooks.forced_output != NULL ) { if( mbedtls_test_driver_key_management_hooks.forced_output_length > data_size ) - return( PSA_ERROR_BUFFER_TOO_SMALL ); + return PSA_ERROR_BUFFER_TOO_SMALL ; memcpy( data, mbedtls_test_driver_key_management_hooks.forced_output, mbedtls_test_driver_key_management_hooks.forced_output_length ); *data_length = mbedtls_test_driver_key_management_hooks.forced_output_length; - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED; @@ -283,7 +283,7 @@ psa_status_t mbedtls_test_transparent_export_public_key( (void)key_type; } - return( status ); + return status ; } psa_status_t mbedtls_test_opaque_export_public_key( @@ -294,7 +294,7 @@ psa_status_t mbedtls_test_opaque_export_public_key( if( key_length != sizeof( psa_drv_slot_number_t ) ) { /* Test driver does not support generic opaque key handling yet. */ - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; } /* Assume this is a builtin key based on the key material length. */ @@ -306,23 +306,23 @@ psa_status_t mbedtls_test_opaque_export_public_key( * returning the public key. */ if( psa_get_key_type( attributes ) != PSA_KEY_TYPE_ECC_KEY_PAIR( PSA_ECC_FAMILY_SECP_R1 ) ) - return( PSA_ERROR_CORRUPTION_DETECTED ); + return PSA_ERROR_CORRUPTION_DETECTED ; if( psa_get_key_bits( attributes ) != 256 ) - return( PSA_ERROR_CORRUPTION_DETECTED ); + return PSA_ERROR_CORRUPTION_DETECTED ; if( psa_get_key_algorithm( attributes ) != PSA_ALG_ECDSA( PSA_ALG_ANY_HASH ) ) - return( PSA_ERROR_CORRUPTION_DETECTED ); + return PSA_ERROR_CORRUPTION_DETECTED ; if( data_size < sizeof( mbedtls_test_driver_ecdsa_pubkey ) ) - return( PSA_ERROR_BUFFER_TOO_SMALL ); + return PSA_ERROR_BUFFER_TOO_SMALL ; memcpy( data, mbedtls_test_driver_ecdsa_pubkey, sizeof( mbedtls_test_driver_ecdsa_pubkey ) ); *data_length = sizeof( mbedtls_test_driver_ecdsa_pubkey ); - return( PSA_SUCCESS ); + return PSA_SUCCESS ; default: - return( PSA_ERROR_DOES_NOT_EXIST ); + return PSA_ERROR_DOES_NOT_EXIST ; } } @@ -354,12 +354,12 @@ psa_status_t mbedtls_test_opaque_get_builtin_key( psa_set_key_algorithm( attributes, PSA_ALG_CTR ); if( key_buffer_size < sizeof( psa_drv_slot_number_t ) ) - return( PSA_ERROR_BUFFER_TOO_SMALL ); + return PSA_ERROR_BUFFER_TOO_SMALL ; *( (psa_drv_slot_number_t*) key_buffer ) = PSA_CRYPTO_TEST_DRIVER_BUILTIN_AES_KEY_SLOT; *key_buffer_length = sizeof( psa_drv_slot_number_t ); - return( PSA_SUCCESS ); + return PSA_SUCCESS ; case PSA_CRYPTO_TEST_DRIVER_BUILTIN_ECDSA_KEY_SLOT: psa_set_key_type( attributes, @@ -374,14 +374,14 @@ psa_status_t mbedtls_test_opaque_get_builtin_key( attributes, PSA_ALG_ECDSA( PSA_ALG_ANY_HASH ) ); if( key_buffer_size < sizeof( psa_drv_slot_number_t ) ) - return( PSA_ERROR_BUFFER_TOO_SMALL ); + return PSA_ERROR_BUFFER_TOO_SMALL ; *( (psa_drv_slot_number_t*) key_buffer ) = PSA_CRYPTO_TEST_DRIVER_BUILTIN_ECDSA_KEY_SLOT; *key_buffer_length = sizeof( psa_drv_slot_number_t ); - return( PSA_SUCCESS ); + return PSA_SUCCESS ; default: - return( PSA_ERROR_DOES_NOT_EXIST ); + return PSA_ERROR_DOES_NOT_EXIST ; } } diff --git a/tests/src/drivers/test_driver_mac.c b/tests/src/drivers/test_driver_mac.c index 3b766dcb53..cfcf162e90 100644 --- a/tests/src/drivers/test_driver_mac.c +++ b/tests/src/drivers/test_driver_mac.c @@ -54,7 +54,7 @@ psa_status_t mbedtls_test_transparent_mac_compute( mac, mac_size, mac_length ); } - return( mbedtls_test_driver_mac_hooks.driver_status ); + return mbedtls_test_driver_mac_hooks.driver_status ; } psa_status_t mbedtls_test_transparent_mac_sign_setup( @@ -78,7 +78,7 @@ psa_status_t mbedtls_test_transparent_mac_sign_setup( operation, attributes, key_buffer, key_buffer_size, alg ); } - return( mbedtls_test_driver_mac_hooks.driver_status ); + return mbedtls_test_driver_mac_hooks.driver_status ; } psa_status_t mbedtls_test_transparent_mac_verify_setup( @@ -102,7 +102,7 @@ psa_status_t mbedtls_test_transparent_mac_verify_setup( operation, attributes, key_buffer, key_buffer_size, alg ); } - return( mbedtls_test_driver_mac_hooks.driver_status ); + return mbedtls_test_driver_mac_hooks.driver_status ; } psa_status_t mbedtls_test_transparent_mac_update( @@ -124,7 +124,7 @@ psa_status_t mbedtls_test_transparent_mac_update( operation, input, input_length ); } - return( mbedtls_test_driver_mac_hooks.driver_status ); + return mbedtls_test_driver_mac_hooks.driver_status ; } psa_status_t mbedtls_test_transparent_mac_sign_finish( @@ -147,7 +147,7 @@ psa_status_t mbedtls_test_transparent_mac_sign_finish( operation, mac, mac_size, mac_length ); } - return( mbedtls_test_driver_mac_hooks.driver_status ); + return mbedtls_test_driver_mac_hooks.driver_status ; } psa_status_t mbedtls_test_transparent_mac_verify_finish( @@ -169,7 +169,7 @@ psa_status_t mbedtls_test_transparent_mac_verify_finish( operation, mac, mac_length ); } - return( mbedtls_test_driver_mac_hooks.driver_status ); + return mbedtls_test_driver_mac_hooks.driver_status ; } psa_status_t mbedtls_test_transparent_mac_abort( @@ -188,7 +188,7 @@ psa_status_t mbedtls_test_transparent_mac_abort( mbedtls_transparent_test_driver_mac_abort( operation ); } - return( mbedtls_test_driver_mac_hooks.driver_status ); + return mbedtls_test_driver_mac_hooks.driver_status ; } psa_status_t mbedtls_test_opaque_mac_compute( @@ -218,7 +218,7 @@ psa_status_t mbedtls_test_opaque_mac_compute( mac, mac_size, mac_length ); } - return( mbedtls_test_driver_mac_hooks.driver_status ); + return mbedtls_test_driver_mac_hooks.driver_status ; } psa_status_t mbedtls_test_opaque_mac_sign_setup( @@ -242,7 +242,7 @@ psa_status_t mbedtls_test_opaque_mac_sign_setup( operation, attributes, key_buffer, key_buffer_size, alg ); } - return( mbedtls_test_driver_mac_hooks.driver_status ); + return mbedtls_test_driver_mac_hooks.driver_status ; } psa_status_t mbedtls_test_opaque_mac_verify_setup( @@ -266,7 +266,7 @@ psa_status_t mbedtls_test_opaque_mac_verify_setup( operation, attributes, key_buffer, key_buffer_size, alg ); } - return( mbedtls_test_driver_mac_hooks.driver_status ); + return mbedtls_test_driver_mac_hooks.driver_status ; } psa_status_t mbedtls_test_opaque_mac_update( @@ -288,7 +288,7 @@ psa_status_t mbedtls_test_opaque_mac_update( operation, input, input_length ); } - return( mbedtls_test_driver_mac_hooks.driver_status ); + return mbedtls_test_driver_mac_hooks.driver_status ; } psa_status_t mbedtls_test_opaque_mac_sign_finish( @@ -311,7 +311,7 @@ psa_status_t mbedtls_test_opaque_mac_sign_finish( operation, mac, mac_size, mac_length ); } - return( mbedtls_test_driver_mac_hooks.driver_status ); + return mbedtls_test_driver_mac_hooks.driver_status ; } psa_status_t mbedtls_test_opaque_mac_verify_finish( @@ -333,7 +333,7 @@ psa_status_t mbedtls_test_opaque_mac_verify_finish( operation, mac, mac_length ); } - return( mbedtls_test_driver_mac_hooks.driver_status ); + return mbedtls_test_driver_mac_hooks.driver_status ; } psa_status_t mbedtls_test_opaque_mac_abort( @@ -352,7 +352,7 @@ psa_status_t mbedtls_test_opaque_mac_abort( mbedtls_opaque_test_driver_mac_abort( operation ); } - return( mbedtls_test_driver_mac_hooks.driver_status ); + return mbedtls_test_driver_mac_hooks.driver_status ; } #endif /* MBEDTLS_PSA_CRYPTO_DRIVERS && PSA_CRYPTO_DRIVER_TEST */ diff --git a/tests/src/drivers/test_driver_signature.c b/tests/src/drivers/test_driver_signature.c index 2d58756aa5..e573b723c9 100644 --- a/tests/src/drivers/test_driver_signature.c +++ b/tests/src/drivers/test_driver_signature.c @@ -88,7 +88,7 @@ psa_status_t sign_hash( } else { - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; } } else @@ -104,7 +104,7 @@ psa_status_t sign_hash( (void)signature; (void)signature_size; (void)signature_length; - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; } } @@ -146,7 +146,7 @@ psa_status_t verify_hash( } else { - return( PSA_ERROR_INVALID_ARGUMENT ); + return PSA_ERROR_INVALID_ARGUMENT ; } } else @@ -162,7 +162,7 @@ psa_status_t verify_hash( (void)signature; (void)signature_length; - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; } } @@ -184,18 +184,18 @@ psa_status_t mbedtls_test_transparent_signature_sign_message( ++mbedtls_test_driver_signature_sign_hooks.hits; if( mbedtls_test_driver_signature_sign_hooks.forced_status != PSA_SUCCESS ) - return( mbedtls_test_driver_signature_sign_hooks.forced_status ); + return mbedtls_test_driver_signature_sign_hooks.forced_status ; if( mbedtls_test_driver_signature_sign_hooks.forced_output != NULL ) { if( mbedtls_test_driver_signature_sign_hooks.forced_output_length > signature_size ) - return( PSA_ERROR_BUFFER_TOO_SMALL ); + return PSA_ERROR_BUFFER_TOO_SMALL ; memcpy( signature, mbedtls_test_driver_signature_sign_hooks.forced_output, mbedtls_test_driver_signature_sign_hooks.forced_output_length ); *signature_length = mbedtls_test_driver_signature_sign_hooks.forced_output_length; - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } status = mbedtls_transparent_test_driver_hash_compute( @@ -231,7 +231,7 @@ psa_status_t mbedtls_test_opaque_signature_sign_message( (void) signature_size; (void) signature_length; - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; } psa_status_t mbedtls_test_transparent_signature_verify_message( @@ -251,7 +251,7 @@ psa_status_t mbedtls_test_transparent_signature_verify_message( ++mbedtls_test_driver_signature_verify_hooks.hits; if( mbedtls_test_driver_signature_verify_hooks.forced_status != PSA_SUCCESS ) - return( mbedtls_test_driver_signature_verify_hooks.forced_status ); + return mbedtls_test_driver_signature_verify_hooks.forced_status ; status = mbedtls_transparent_test_driver_hash_compute( PSA_ALG_SIGN_GET_HASH( alg ), input, input_length, @@ -284,7 +284,7 @@ psa_status_t mbedtls_test_opaque_signature_verify_message( (void) signature; (void) signature_length; - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; } psa_status_t mbedtls_test_transparent_signature_sign_hash( @@ -297,16 +297,16 @@ psa_status_t mbedtls_test_transparent_signature_sign_hash( ++mbedtls_test_driver_signature_sign_hooks.hits; if( mbedtls_test_driver_signature_sign_hooks.forced_status != PSA_SUCCESS ) - return( mbedtls_test_driver_signature_sign_hooks.forced_status ); + return mbedtls_test_driver_signature_sign_hooks.forced_status ; if( mbedtls_test_driver_signature_sign_hooks.forced_output != NULL ) { if( mbedtls_test_driver_signature_sign_hooks.forced_output_length > signature_size ) - return( PSA_ERROR_BUFFER_TOO_SMALL ); + return PSA_ERROR_BUFFER_TOO_SMALL ; memcpy( signature, mbedtls_test_driver_signature_sign_hooks.forced_output, mbedtls_test_driver_signature_sign_hooks.forced_output_length ); *signature_length = mbedtls_test_driver_signature_sign_hooks.forced_output_length; - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } return sign_hash( attributes, key_buffer, key_buffer_size, @@ -331,7 +331,7 @@ psa_status_t mbedtls_test_opaque_signature_sign_hash( (void) signature_size; (void) signature_length; - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; } psa_status_t mbedtls_test_transparent_signature_verify_hash( @@ -344,7 +344,7 @@ psa_status_t mbedtls_test_transparent_signature_verify_hash( ++mbedtls_test_driver_signature_verify_hooks.hits; if( mbedtls_test_driver_signature_verify_hooks.forced_status != PSA_SUCCESS ) - return( mbedtls_test_driver_signature_verify_hooks.forced_status ); + return mbedtls_test_driver_signature_verify_hooks.forced_status ; return verify_hash( attributes, key_buffer, key_buffer_size, alg, hash, hash_length, @@ -366,7 +366,7 @@ psa_status_t mbedtls_test_opaque_signature_verify_hash( (void) hash_length; (void) signature; (void) signature_length; - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; } #endif /* MBEDTLS_PSA_CRYPTO_DRIVERS && PSA_CRYPTO_DRIVER_TEST */ diff --git a/tests/src/drivers/test_driver_size.c b/tests/src/drivers/test_driver_size.c index 033cf32de0..837d82a844 100644 --- a/tests/src/drivers/test_driver_size.c +++ b/tests/src/drivers/test_driver_size.c @@ -92,6 +92,6 @@ size_t mbedtls_test_size_function( ( ( key_bits + 7 ) / 8 ) ); } - return( key_buffer_size ); + return key_buffer_size ; } #endif /* MBEDTLS_PSA_CRYPTO_DRIVERS && PSA_CRYPTO_DRIVER_TEST */ diff --git a/tests/src/fake_external_rng_for_test.c b/tests/src/fake_external_rng_for_test.c index 9c2195bf0c..ec83541482 100644 --- a/tests/src/fake_external_rng_for_test.c +++ b/tests/src/fake_external_rng_for_test.c @@ -45,12 +45,12 @@ psa_status_t mbedtls_psa_external_get_random( (void) context; if( !test_insecure_external_rng_enabled ) - return( PSA_ERROR_INSUFFICIENT_ENTROPY ); + return PSA_ERROR_INSUFFICIENT_ENTROPY ; /* This implementation is for test purposes only! * Use the libc non-cryptographic random generator. */ mbedtls_test_rnd_std_rand( NULL, output, output_size ); *output_length = output_size; - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } #endif /* MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG */ diff --git a/tests/src/helpers.c b/tests/src/helpers.c index 4d3d53da50..7bbfa50d58 100644 --- a/tests/src/helpers.c +++ b/tests/src/helpers.c @@ -37,7 +37,7 @@ int mbedtls_test_platform_setup( void ) #if defined(MBEDTLS_PLATFORM_C) ret = mbedtls_platform_setup( &platform_ctx ); #endif /* MBEDTLS_PLATFORM_C */ - return( ret ); + return ret ; } void mbedtls_test_platform_teardown( void ) @@ -56,9 +56,9 @@ static int ascii2uc(const char c, unsigned char *uc) else if( ( c >= 'A' ) && ( c <= 'F' ) ) *uc = c - 'A' + 10; else - return( -1 ); + return -1 ; - return( 0 ); + return 0 ; } void mbedtls_test_fail( const char *test, int line_no, const char* filename ) @@ -108,24 +108,24 @@ int mbedtls_test_unhexify( unsigned char *obuf, /* Must be even number of bytes. */ if ( ( *len ) & 1 ) - return( -1 ); + return -1 ; *len /= 2; if ( (*len) > obufmax ) - return( -1 ); + return -1 ; while( *ibuf != 0 ) { if ( ascii2uc( *(ibuf++), &uc ) != 0 ) - return( -1 ); + return -1 ; if ( ascii2uc( *(ibuf++), &uc2 ) != 0 ) - return( -1 ); + return -1 ; *(obuf++) = ( uc << 4 ) | uc2; } - return( 0 ); + return 0 ; } void mbedtls_test_hexify( unsigned char *obuf, @@ -164,7 +164,7 @@ unsigned char *mbedtls_test_zero_alloc( size_t len ) memset( p, 0x00, actual_len ); - return( p ); + return p ; } unsigned char *mbedtls_test_unhexify_alloc( const char *ibuf, size_t *olen ) @@ -175,13 +175,13 @@ unsigned char *mbedtls_test_unhexify_alloc( const char *ibuf, size_t *olen ) *olen = strlen( ibuf ) / 2; if( *olen == 0 ) - return( mbedtls_test_zero_alloc( *olen ) ); + return mbedtls_test_zero_alloc( *olen ) ; obuf = mbedtls_calloc( 1, *olen ); TEST_HELPER_ASSERT( obuf != NULL ); TEST_HELPER_ASSERT( mbedtls_test_unhexify( obuf, *olen, ibuf, &len ) == 0 ); - return( obuf ); + return obuf ; } int mbedtls_test_hexcmp( uint8_t * a, uint8_t * b, @@ -191,7 +191,7 @@ int mbedtls_test_hexcmp( uint8_t * a, uint8_t * b, uint32_t i = 0; if( a_len != b_len ) - return( -1 ); + return -1 ; for( i = 0; i < a_len; i++ ) { @@ -268,9 +268,9 @@ int mbedtls_test_read_mpi( mbedtls_mpi *X, int radix, const char *s ) if( s[0] == 0 ) { mbedtls_mpi_free( X ); - return( 0 ); + return 0 ; } else - return( mbedtls_mpi_read_string( X, radix, s ) ); + return mbedtls_mpi_read_string( X, radix, s ) ; } #endif diff --git a/tests/src/psa_crypto_helpers.c b/tests/src/psa_crypto_helpers.c index d9d841abd5..cef4093a54 100644 --- a/tests/src/psa_crypto_helpers.c +++ b/tests/src/psa_crypto_helpers.c @@ -42,18 +42,18 @@ int mbedtls_test_uses_key_id( mbedtls_svc_key_id_t key_id ) PSA_MAX_PERSISTENT_KEY_IDENTIFIER ) { /* Don't touch key id values that designate non-key files. */ - return( 1 ); + return 1 ; } for( i = 0; i < num_key_ids_used ; i++ ) { if( mbedtls_svc_key_id_equal( key_id, key_ids_used_in_test[i] ) ) - return( 1 ); + return 1 ; } if( num_key_ids_used == ARRAY_LENGTH( key_ids_used_in_test ) ) - return( 0 ); + return 0 ; key_ids_used_in_test[num_key_ids_used] = key_id; ++num_key_ids_used; - return( 1 ); + return 1 ; } void mbedtls_test_psa_purge_key_storage( void ) @@ -80,17 +80,17 @@ const char *mbedtls_test_helper_is_psa_leaking( void ) mbedtls_psa_get_stats( &stats ); if( stats.volatile_slots != 0 ) - return( "A volatile slot has not been closed properly." ); + return "A volatile slot has not been closed properly." ; if( stats.persistent_slots != 0 ) - return( "A persistent slot has not been closed properly." ); + return "A persistent slot has not been closed properly." ; if( stats.external_slots != 0 ) - return( "An external slot has not been closed properly." ); + return "An external slot has not been closed properly." ; if( stats.half_filled_slots != 0 ) - return( "A half-filled slot has not been cleared properly." ); + return "A half-filled slot has not been cleared properly." ; if( stats.locked_slots != 0 ) - return( "Some slots are still marked as locked." ); + return "Some slots are still marked as locked." ; - return( NULL ); + return NULL ; } #if defined(RECORD_PSA_STATUS_COVERAGE_LOG) @@ -110,7 +110,7 @@ psa_status_t mbedtls_test_record_status( psa_status_t status, if( log == NULL ) log = fopen( STATUS_LOG_FILE_NAME, "a" ); fprintf( log, "%d:%s:%s:%d:%s\n", (int) status, func, file, line, expr ); - return( status ); + return status ; } #endif /* defined(RECORD_PSA_STATUS_COVERAGE_LOG) */ @@ -124,7 +124,7 @@ psa_key_usage_t mbedtls_test_update_key_usage_flags( psa_key_usage_t usage_flags if( usage_flags & PSA_KEY_USAGE_VERIFY_HASH ) updated_usage |= PSA_KEY_USAGE_VERIFY_MESSAGE; - return( updated_usage ); + return updated_usage ; } #endif /* MBEDTLS_PSA_CRYPTO_C */ diff --git a/tests/src/psa_exercise_key.c b/tests/src/psa_exercise_key.c index e4e55c9c2c..f47f15ae6c 100644 --- a/tests/src/psa_exercise_key.c +++ b/tests/src/psa_exercise_key.c @@ -110,7 +110,7 @@ exit: */ psa_reset_key_attributes( &attributes ); - return( ok ); + return ok ; } static int exercise_mac_key( mbedtls_svc_key_id_t key, @@ -151,11 +151,11 @@ static int exercise_mac_key( mbedtls_svc_key_id_t key, verify_status ); } - return( 1 ); + return 1 ; exit: psa_mac_abort( &operation ); - return( 0 ); + return 0 ; } static int exercise_cipher_key( mbedtls_svc_key_id_t key, @@ -224,11 +224,11 @@ static int exercise_cipher_key( mbedtls_svc_key_id_t key, PSA_ASSERT( status ); } - return( 1 ); + return 1 ; exit: psa_cipher_abort( &operation ); - return( 0 ); + return 0 ; } static int exercise_aead_key( mbedtls_svc_key_id_t key, @@ -287,10 +287,10 @@ static int exercise_aead_key( mbedtls_svc_key_id_t key, verify_status ); } - return( 1 ); + return 1 ; exit: - return( 0 ); + return 0 ; } static int exercise_signature_key( mbedtls_svc_key_id_t key, @@ -371,10 +371,10 @@ static int exercise_signature_key( mbedtls_svc_key_id_t key, } } - return( 1 ); + return 1 ; exit: - return( 0 ); + return 0 ; } static int exercise_asymmetric_encryption_key( mbedtls_svc_key_id_t key, @@ -409,10 +409,10 @@ static int exercise_asymmetric_encryption_key( mbedtls_svc_key_id_t key, status == PSA_ERROR_INVALID_PADDING ) ) ); } - return( 1 ); + return 1 ; exit: - return( 0 ); + return 0 ; } int mbedtls_test_psa_setup_key_derivation_wrap( @@ -458,10 +458,10 @@ int mbedtls_test_psa_setup_key_derivation_wrap( if( capacity != SIZE_MAX ) PSA_ASSERT( psa_key_derivation_set_capacity( operation, capacity ) ); - return( 1 ); + return 1 ; exit: - return( 0 ); + return 0 ; } @@ -491,10 +491,10 @@ static int exercise_key_derivation_key( mbedtls_svc_key_id_t key, PSA_ASSERT( psa_key_derivation_abort( &operation ) ); } - return( 1 ); + return 1 ; exit: - return( 0 ); + return 0 ; } /* We need two keys to exercise key agreement. Exercise the @@ -534,7 +534,7 @@ exit: psa_reset_key_attributes( &attributes ); mbedtls_free( public_key ); - return( status ); + return status ; } /* We need two keys to exercise key agreement. Exercise the @@ -586,7 +586,7 @@ exit: psa_reset_key_attributes( &attributes ); mbedtls_free( public_key ); - return( status ); + return status ; } static int exercise_raw_key_agreement_key( mbedtls_svc_key_id_t key, @@ -604,7 +604,7 @@ static int exercise_raw_key_agreement_key( mbedtls_svc_key_id_t key, ok = 1; exit: - return( ok ); + return ok ; } static int exercise_key_agreement_key( mbedtls_svc_key_id_t key, @@ -629,7 +629,7 @@ static int exercise_key_agreement_key( mbedtls_svc_key_id_t key, ok = 1; exit: - return( ok ); + return ok ; } int mbedtls_test_psa_exported_key_sanity_check( @@ -785,10 +785,10 @@ int mbedtls_test_psa_exported_key_sanity_check( } #endif - return( 1 ); + return 1 ; exit: - return( 0 ); + return 0 ; } static int exercise_export_key( mbedtls_svc_key_id_t key, @@ -832,7 +832,7 @@ exit: psa_reset_key_attributes( &attributes ); mbedtls_free( exported ); - return( ok ); + return ok ; } static int exercise_export_public_key( mbedtls_svc_key_id_t key ) @@ -880,7 +880,7 @@ exit: psa_reset_key_attributes( &attributes ); mbedtls_free( exported ); - return( ok ); + return ok ; } int mbedtls_test_psa_exercise_key( mbedtls_svc_key_id_t key, @@ -890,7 +890,7 @@ int mbedtls_test_psa_exercise_key( mbedtls_svc_key_id_t key, int ok = 0; if( ! check_key_attributes_sanity( key ) ) - return( 0 ); + return 0 ; if( alg == 0 ) ok = 1; /* If no algorihm, do nothing (used for raw data "keys"). */ @@ -917,7 +917,7 @@ int mbedtls_test_psa_exercise_key( mbedtls_svc_key_id_t key, ok = ok && exercise_export_public_key( key ); exit: - return( ok ); + return ok ; } psa_key_usage_t mbedtls_test_psa_usage_to_exercise( psa_key_type_t type, @@ -952,11 +952,11 @@ psa_key_usage_t mbedtls_test_psa_usage_to_exercise( psa_key_type_t type, else if( PSA_ALG_IS_KEY_DERIVATION( alg ) || PSA_ALG_IS_KEY_AGREEMENT( alg ) ) { - return( PSA_KEY_USAGE_DERIVE ); + return PSA_KEY_USAGE_DERIVE ; } else { - return( 0 ); + return 0 ; } } diff --git a/tests/src/random.c b/tests/src/random.c index 7f3f40166c..d578985a0e 100644 --- a/tests/src/random.c +++ b/tests/src/random.c @@ -56,7 +56,7 @@ int mbedtls_test_rnd_std_rand( void *rng_state, arc4random_buf( output, len ); #endif /* !OpenBSD && !NetBSD */ - return( 0 ); + return 0 ; } int mbedtls_test_rnd_zero_rand( void *rng_state, @@ -68,7 +68,7 @@ int mbedtls_test_rnd_zero_rand( void *rng_state, memset( output, 0, len ); - return( 0 ); + return 0 ; } int mbedtls_test_rnd_buffer_rand( void *rng_state, @@ -79,7 +79,7 @@ int mbedtls_test_rnd_buffer_rand( void *rng_state, size_t use_len; if( rng_state == NULL ) - return( mbedtls_test_rnd_std_rand( NULL, output, len ) ); + return mbedtls_test_rnd_std_rand( NULL, output, len ) ; use_len = len; if( len > info->length ) @@ -101,10 +101,10 @@ int mbedtls_test_rnd_buffer_rand( void *rng_state, len - use_len ) ); } else - return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED ); + return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED ; } - return( 0 ); + return 0 ; } int mbedtls_test_rnd_pseudo_rand( void *rng_state, @@ -117,7 +117,7 @@ int mbedtls_test_rnd_pseudo_rand( void *rng_state, unsigned char result[4], *out = output; if( rng_state == NULL ) - return( mbedtls_test_rnd_std_rand( NULL, output, len ) ); + return mbedtls_test_rnd_std_rand( NULL, output, len ) ; k = info->key; @@ -141,5 +141,5 @@ int mbedtls_test_rnd_pseudo_rand( void *rng_state, out += 4; } - return( 0 ); + return 0 ; } diff --git a/tests/src/threading_helpers.c b/tests/src/threading_helpers.c index ca91b7933a..f5a95641d5 100644 --- a/tests/src/threading_helpers.c +++ b/tests/src/threading_helpers.c @@ -160,7 +160,7 @@ static int mbedtls_test_wrap_mutex_lock( mbedtls_threading_mutex_t *mutex ) mbedtls_test_mutex_usage_error( mutex, "corrupted state" ); break; } - return( ret ); + return ret ; } static int mbedtls_test_wrap_mutex_unlock( mbedtls_threading_mutex_t *mutex ) @@ -182,7 +182,7 @@ static int mbedtls_test_wrap_mutex_unlock( mbedtls_threading_mutex_t *mutex ) mbedtls_test_mutex_usage_error( mutex, "corrupted state" ); break; } - return( ret ); + return ret ; } void mbedtls_test_mutex_usage_init( void ) diff --git a/tests/suites/helpers.function b/tests/suites/helpers.function index 7481c5b4ad..0071f6f5b4 100644 --- a/tests/suites/helpers.function +++ b/tests/suites/helpers.function @@ -123,14 +123,14 @@ static int redirect_output( FILE* out_stream, const char* path ) if( dup_fd == -1 ) { - return( -1 ); + return -1 ; } path_stream = fopen( path, "w" ); if( path_stream == NULL ) { close( dup_fd ); - return( -1 ); + return -1 ; } fflush( out_stream ); @@ -138,11 +138,11 @@ static int redirect_output( FILE* out_stream, const char* path ) { close( dup_fd ); fclose( path_stream ); - return( -1 ); + return -1 ; } fclose( path_stream ); - return( dup_fd ); + return dup_fd ; } static int restore_output( FILE* out_stream, int dup_fd ) @@ -154,10 +154,10 @@ static int restore_output( FILE* out_stream, int dup_fd ) { close( out_fd ); close( dup_fd ); - return( -1 ); + return -1 ; } close( dup_fd ); - return( 0 ); + return 0 ; } #endif /* __unix__ || __APPLE__ __MACH__ */ diff --git a/tests/suites/host_test.function b/tests/suites/host_test.function index a5fd7179b6..f414c38876 100644 --- a/tests/suites/host_test.function +++ b/tests/suites/host_test.function @@ -15,13 +15,13 @@ int verify_string( char **str ) { mbedtls_fprintf( stderr, "Expected string (with \"\") for parameter and got: %s\n", *str ); - return( -1 ); + return -1 ; } ( *str )++; ( *str )[strlen( *str ) - 1] = '\0'; - return( 0 ); + return 0 ; } /** @@ -71,12 +71,12 @@ int verify_int( char *str, int32_t *value ) else *value = strtol( str, NULL, 10 ); - return( 0 ); + return 0 ; } mbedtls_fprintf( stderr, "Expected integer for parameter and got: %s\n", str ); - return( KEY_VALUE_MAPPING_NOT_FOUND ); + return KEY_VALUE_MAPPING_NOT_FOUND ; } @@ -117,7 +117,7 @@ int get_line( FILE *f, char *buf, size_t len ) { ret = fgets( buf, len, f ); if( ret == NULL ) - return( -1 ); + return -1 ; str_len = strlen( buf ); @@ -144,7 +144,7 @@ int get_line( FILE *f, char *buf, size_t len ) if( ret-- > buf && *ret == '\r' ) *ret = '\0'; - return( 0 ); + return 0 ; } /** @@ -217,7 +217,7 @@ static int parse_arguments( char *buf, size_t len, char **params, *q = '\0'; } - return( cnt ); + return cnt ; } /** @@ -312,7 +312,7 @@ static int convert_params( size_t cnt , char ** params , int32_t * int_params_st break; } } - return( ret ); + return ret ; } /** @@ -342,7 +342,7 @@ static int test_snprintf( size_t n, const char *ref_buf, int ref_ret ) const char ref[10] = "xxxxxxxxx"; if( n >= sizeof( buf ) ) - return( -1 ); + return -1 ; ret = mbedtls_snprintf( buf, n, "%s", "123" ); if( ret < 0 || (size_t) ret >= n ) ret = -1; @@ -351,10 +351,10 @@ static int test_snprintf( size_t n, const char *ref_buf, int ref_ret ) ref_ret != ret || memcmp( buf + n, ref + n, sizeof( buf ) - n ) != 0 ) { - return( 1 ); + return 1 ; } - return( 0 ); + return 0 ; } /** @@ -547,7 +547,7 @@ int execute_tests( int argc , const char ** argv ) if( pointer != NULL ) { mbedtls_fprintf( stderr, "all-bits-zero is not a NULL pointer\n" ); - return( 1 ); + return 1 ; } /* @@ -556,7 +556,7 @@ int execute_tests( int argc , const char ** argv ) if( run_test_snprintf() != 0 ) { mbedtls_fprintf( stderr, "the snprintf implementation is broken\n" ); - return( 1 ); + return 1 ; } if( outcome_file_name != NULL && *outcome_file_name != '\0' ) @@ -623,7 +623,7 @@ int execute_tests( int argc , const char ** argv ) test_filename ); if( outcome_file != NULL ) fclose( outcome_file ); - return( 1 ); + return 1 ; } while( !feof( file ) ) @@ -819,5 +819,5 @@ int execute_tests( int argc , const char ** argv ) mbedtls_memory_buffer_alloc_free(); #endif - return( total_errors != 0 ); + return total_errors != 0 ; } diff --git a/tests/suites/main_test.function b/tests/suites/main_test.function index e016865348..cfad32e119 100644 --- a/tests/suites/main_test.function +++ b/tests/suites/main_test.function @@ -86,7 +86,7 @@ $expression_code } break; } - return( ret ); + return ret ; } @@ -114,7 +114,7 @@ $dep_check_code default: break; } - return( ret ); + return ret ; } @@ -185,7 +185,7 @@ int dispatch_test( size_t func_idx, void ** params ) ret = DISPATCH_TEST_FN_NOT_FOUND; } - return( ret ); + return ret ; } @@ -215,7 +215,7 @@ int check_test( size_t func_idx ) ret = DISPATCH_TEST_FN_NOT_FOUND; } - return( ret ); + return ret ; } @@ -251,10 +251,10 @@ int main( int argc, const char *argv[] ) mbedtls_fprintf( stderr, "FATAL: Failed to initialize platform - error %d\n", ret ); - return( -1 ); + return -1 ; } ret = execute_tests( argc, argv ); mbedtls_test_platform_teardown(); - return( ret ); + return ret ; } diff --git a/tests/suites/target_test.function b/tests/suites/target_test.function index 637a79d5ee..3d0bc801e6 100644 --- a/tests/suites/target_test.function +++ b/tests/suites/target_test.function @@ -54,9 +54,9 @@ int verify_dependencies( uint8_t count, uint8_t * dep_p ) for ( i = 0; i < count; i++ ) { if ( dep_check( (int)(dep_p[i]) ) != DEPENDENCY_SUPPORTED ) - return( DEPENDENCY_NOT_SUPPORTED ); + return DEPENDENCY_NOT_SUPPORTED ; } - return( DEPENDENCY_SUPPORTED ); + return DEPENDENCY_SUPPORTED ; } /** @@ -80,7 +80,7 @@ uint8_t receive_byte() c, &len ) == 0 ); TEST_HELPER_ASSERT( len != 2 ); - return( byte ); + return byte ; } /** @@ -111,7 +111,7 @@ uint32_t receive_uint32() c, &len ) == 0 ); TEST_HELPER_ASSERT( len != 8 ); - return( value ); + return value ; } /** @@ -129,7 +129,7 @@ uint32_t parse_uint32( uint8_t * p ) value |= *p++ << 16; value |= *p++ << 8; value |= *p; - return( value ); + return value ; } @@ -157,7 +157,7 @@ uint8_t * receive_data( uint32_t * data_len ) continue; i++; if ( c != '{' ) - return( NULL ); + return NULL ; } /* Read data length */ @@ -188,7 +188,7 @@ uint8_t * receive_data( uint32_t * data_len ) *data_len = 0; } - return( data ); + return data ; } /** @@ -230,7 +230,7 @@ uint32_t find_hex_count( uint8_t count, uint8_t * data, uint32_t data_len ) } } - return( hex_count ); + return hex_count ; } /** @@ -317,7 +317,7 @@ exit: params = NULL; } - return( params ); + return params ; } /** @@ -444,6 +444,6 @@ int execute_tests( int args, const char ** argv ) else send_status( mbedtls_test_info.result ); } - return( 0 ); + return 0 ; } diff --git a/tests/suites/test_suite_asn1parse.function b/tests/suites/test_suite_asn1parse.function index 535274b74e..78ccdb088f 100644 --- a/tests/suites/test_suite_asn1parse.function +++ b/tests/suites/test_suite_asn1parse.function @@ -31,7 +31,7 @@ static int nested_parse( unsigned char **const p, ret = mbedtls_asn1_get_len( &content_start, end, &len ); TEST_ASSERT( content_start <= end ); if( ret != 0 ) - return( ret ); + return ret ; /* Since we have a valid element start (tag and length), retrieve and * check the tag. */ @@ -111,14 +111,14 @@ static int nested_parse( unsigned char **const p, default: /* No further testing implemented for this tag. */ *p += len; - return( 0 ); + return 0 ; } TEST_ASSERT( *p <= end ); - return( ret ); + return ret ; exit: - return( ERR_PARSE_INCONSISTENCY ); + return ERR_PARSE_INCONSISTENCY ; } int get_len_step( const data_t *input, size_t buffer_size, @@ -168,11 +168,11 @@ int get_len_step( const data_t *input, size_t buffer_size, TEST_EQUAL( ret, MBEDTLS_ERR_ASN1_OUT_OF_DATA ); } mbedtls_free( buf ); - return( 1 ); + return 1 ; exit: mbedtls_free( buf ); - return( 0 ); + return 0 ; } typedef struct @@ -201,7 +201,7 @@ static int traverse_callback( void *ctx, int tag, mbedtls_test_set_step( offset ); if( *rest == 0 ) - return( RET_TRAVERSE_STOP ); + return RET_TRAVERSE_STOP ; n = strtoul( rest, (char **) &rest, 0 ); TEST_EQUAL( n, offset ); TEST_EQUAL( *rest, ',' ); @@ -216,10 +216,10 @@ static int traverse_callback( void *ctx, int tag, ++rest; state->description = rest; - return( 0 ); + return 0 ; exit: - return( RET_TRAVERSE_ERROR ); + return RET_TRAVERSE_ERROR ; } /* END_HEADER */ diff --git a/tests/suites/test_suite_asn1write.function b/tests/suites/test_suite_asn1write.function index 103a024f70..312145d6b9 100644 --- a/tests/suites/test_suite_asn1write.function +++ b/tests/suites/test_suite_asn1write.function @@ -20,9 +20,9 @@ int generic_write_start_step( generic_write_data_t *data ) data->end = data->output + data->size; data->p = data->end; data->start = data->end - data->size; - return( 1 ); + return 1 ; exit: - return( 0 ); + return 0 ; } int generic_write_finish_step( generic_write_data_t *data, @@ -47,7 +47,7 @@ int generic_write_finish_step( generic_write_data_t *data, exit: mbedtls_free( data->output ); data->output = NULL; - return( ok ); + return ok ; } /* END_HEADER */ diff --git a/tests/suites/test_suite_cipher.function b/tests/suites/test_suite_cipher.function index 674349f764..ff229e1d95 100644 --- a/tests/suites/test_suite_cipher.function +++ b/tests/suites/test_suite_cipher.function @@ -48,10 +48,10 @@ static int cipher_reset_key( mbedtls_cipher_context_t *ctx, int cipher_id, TEST_ASSERT( 0 == mbedtls_cipher_setkey( ctx, key->x, 8 * key->len, direction ) ); - return( 1 ); + return 1 ; exit: - return( 0 ); + return 0 ; } /* diff --git a/tests/suites/test_suite_ctr_drbg.function b/tests/suites/test_suite_ctr_drbg.function index a46f21c1f2..1447a04608 100644 --- a/tests/suites/test_suite_ctr_drbg.function +++ b/tests/suites/test_suite_ctr_drbg.function @@ -18,10 +18,10 @@ static int mbedtls_test_entropy_func( void *data, unsigned char *buf, size_t len { const unsigned char *p = (unsigned char *) data; if( test_offset_idx + len > test_max_idx ) - return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED ); + return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED ; memcpy( buf, p + test_offset_idx, len ); test_offset_idx += len; - return( 0 ); + return 0 ; } static void ctr_drbg_validate_internal( int reseed_mode, data_t * nonce, @@ -285,7 +285,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( diff --git a/tests/suites/test_suite_dhm.function b/tests/suites/test_suite_dhm.function index bc43016656..db88daafe2 100644 --- a/tests/suites/test_suite_dhm.function +++ b/tests/suites/test_suite_dhm.function @@ -15,7 +15,7 @@ int check_get_value( const mbedtls_dhm_context *ctx, exit: mbedtls_mpi_free( &actual ); - return( ok ); + return ok ; } /* Sanity checks on a Diffie-Hellman parameter: check the length-value @@ -47,7 +47,7 @@ static int check_dhm_param_output( const mbedtls_mpi *expected, ok = 1; exit: mbedtls_mpi_free( &actual ); - return( ok ); + return ok ; } /* Sanity checks on Diffie-Hellman parameters: syntax, range, and comparison @@ -75,9 +75,9 @@ static int check_dhm_params( const mbedtls_dhm_context *ctx, goto exit; TEST_EQUAL( offset, ske_len ); - return( 1 ); + return 1 ; exit: - return( 0 ); + return 0 ; } /* END_HEADER */ diff --git a/tests/suites/test_suite_ecdh.function b/tests/suites/test_suite_ecdh.function index 6893bcfa40..b0cd2e40f5 100644 --- a/tests/suites/test_suite_ecdh.function +++ b/tests/suites/test_suite_ecdh.function @@ -14,7 +14,7 @@ static int load_public_key( int grp_id, data_t *point, &ecp->Q ) == 0 ); ok = 1; exit: - return( ok ); + return ok ; } static int load_private_key( int grp_id, data_t *private_key, @@ -33,7 +33,7 @@ static int load_private_key( int grp_id, data_t *private_key, rnd_info ) == 0 ); ok = 1; exit: - return( ok ); + return ok ; } /* END_HEADER */ diff --git a/tests/suites/test_suite_ecjpake.function b/tests/suites/test_suite_ecjpake.function index 311733b0dd..0ef334f9ce 100644 --- a/tests/suites/test_suite_ecjpake.function +++ b/tests/suites/test_suite_ecjpake.function @@ -86,7 +86,7 @@ static int ecjpake_test_load( mbedtls_ecjpake_context *ctx, &ctx->Xp2, Xp2, len_Xp2 ) ); cleanup: - return( ret ); + return ret ; } #define ADD_SIZE( x ) x, sizeof( x ) diff --git a/tests/suites/test_suite_entropy.function b/tests/suites/test_suite_entropy.function index c26f4f8665..6f72add9d4 100644 --- a/tests/suites/test_suite_entropy.function +++ b/tests/suites/test_suite_entropy.function @@ -39,11 +39,11 @@ static int entropy_dummy_source( void *arg, unsigned char *output, *olen = len; break; case DUMMY_FAIL: - return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED ); + return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED ; } memset( output, 0x2a, *olen ); - return( 0 ); + return 0 ; } /* @@ -71,19 +71,19 @@ static unsigned char buffer_seed[MBEDTLS_ENTROPY_BLOCK_SIZE]; int buffer_nv_seed_read( unsigned char *buf, size_t buf_len ) { if( buf_len != MBEDTLS_ENTROPY_BLOCK_SIZE ) - return( -1 ); + return -1 ; memcpy( buf, buffer_seed, MBEDTLS_ENTROPY_BLOCK_SIZE ); - return( 0 ); + return 0 ; } int buffer_nv_seed_write( unsigned char *buf, size_t buf_len ) { if( buf_len != MBEDTLS_ENTROPY_BLOCK_SIZE ) - return( -1 ); + return -1 ; memcpy( buffer_seed, buf, MBEDTLS_ENTROPY_BLOCK_SIZE ); - return( 0 ); + return 0 ; } /* @@ -94,18 +94,18 @@ static int write_nv_seed( unsigned char *buf, size_t buf_len ) FILE *f; if( buf_len != MBEDTLS_ENTROPY_BLOCK_SIZE ) - return( -1 ); + return -1 ; if( ( f = fopen( MBEDTLS_PLATFORM_STD_NV_SEED_FILE, "w" ) ) == NULL ) - return( -1 ); + return -1 ; if( fwrite( buf, 1, MBEDTLS_ENTROPY_BLOCK_SIZE, f ) != MBEDTLS_ENTROPY_BLOCK_SIZE ) - return( -1 ); + return -1 ; fclose( f ); - return( 0 ); + return 0 ; } int read_nv_seed( unsigned char *buf, size_t buf_len ) @@ -113,18 +113,18 @@ int read_nv_seed( unsigned char *buf, size_t buf_len ) FILE *f; if( buf_len != MBEDTLS_ENTROPY_BLOCK_SIZE ) - return( -1 ); + return -1 ; if( ( f = fopen( MBEDTLS_PLATFORM_STD_NV_SEED_FILE, "rb" ) ) == NULL ) - return( -1 ); + return -1 ; if( fread( buf, 1, MBEDTLS_ENTROPY_BLOCK_SIZE, f ) != MBEDTLS_ENTROPY_BLOCK_SIZE ) - return( -1 ); + return -1 ; fclose( f ); - return( 0 ); + return 0 ; } #endif /* MBEDTLS_ENTROPY_NV_SEED */ /* END_HEADER */ diff --git a/tests/suites/test_suite_gcm.function b/tests/suites/test_suite_gcm.function index c530e6b429..2bcd1d7b47 100644 --- a/tests/suites/test_suite_gcm.function +++ b/tests/suites/test_suite_gcm.function @@ -59,7 +59,7 @@ static int check_multipart( mbedtls_gcm_context *ctx, ok = 1; exit: mbedtls_free( output ); - return( ok ); + return ok ; } static void check_cipher_with_empty_ad( mbedtls_gcm_context *ctx, diff --git a/tests/suites/test_suite_hmac_drbg.function b/tests/suites/test_suite_hmac_drbg.function index b83d760d22..e678979ba3 100644 --- a/tests/suites/test_suite_hmac_drbg.function +++ b/tests/suites/test_suite_hmac_drbg.function @@ -13,14 +13,14 @@ static int mbedtls_test_entropy_func( void *data, unsigned char *buf, size_t len entropy_ctx *ctx = (entropy_ctx *) data; if( len > ctx->len ) - return( -1 ); + return -1 ; memcpy( buf, ctx->p, len ); ctx->p += len; ctx->len -= len; - return( 0 ); + return 0 ; } /* END_HEADER */ diff --git a/tests/suites/test_suite_mdx.function b/tests/suites/test_suite_mdx.function index 73f91231cc..5cdb1a59a4 100644 --- a/tests/suites/test_suite_mdx.function +++ b/tests/suites/test_suite_mdx.function @@ -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 */ diff --git a/tests/suites/test_suite_memory_buffer_alloc.function b/tests/suites/test_suite_memory_buffer_alloc.function index cc884c28e5..f5e05e2bd9 100644 --- a/tests/suites/test_suite_memory_buffer_alloc.function +++ b/tests/suites/test_suite_memory_buffer_alloc.function @@ -13,12 +13,12 @@ static int check_pointer( void *p ) { if( p == NULL ) - return( -1 ); + return -1 ; if( (size_t) p % MBEDTLS_MEMORY_ALIGN_MULTIPLE != 0 ) - return( -1 ); + return -1 ; - return( 0 ); + return 0 ; } /* END_SUITE_HELPERS */ diff --git a/tests/suites/test_suite_mpi.function b/tests/suites/test_suite_mpi.function index 1372668b52..5c184cb6a9 100644 --- a/tests/suites/test_suite_mpi.function +++ b/tests/suites/test_suite_mpi.function @@ -12,10 +12,10 @@ static int sign_is_valid( const mbedtls_mpi *X ) { if( X->s != 1 && X->s != -1 ) - return( 0 ); // invalid sign bit, e.g. 0 + return 0 ; // invalid sign bit, e.g. 0 if( mbedtls_mpi_bitlen( X ) == 0 && X->s != 1 ) - return( 0 ); // negative zero - return( 1 ); + return 0 ; // negative zero + return 1 ; } typedef struct mbedtls_test_mpi_random @@ -38,12 +38,12 @@ int mbedtls_test_mpi_miller_rabin_determinizer( void* state, mbedtls_test_mpi_random *random = (mbedtls_test_mpi_random*) state; if( random == NULL || random->data->x == NULL || buf == NULL ) - return( -1 ); + return -1 ; if( random->pos + random->chunk_len > random->data->len || random->chunk_len > len ) { - return( -1 ); + return -1 ; } memset( buf, 0, len ); @@ -58,7 +58,7 @@ int mbedtls_test_mpi_miller_rabin_determinizer( void* state, random->pos += random->chunk_len; - return( 0 ); + return 0 ; } /* Random generator that is told how many bytes to return. */ @@ -69,11 +69,11 @@ static int f_rng_bytes_left( void *state, unsigned char *buf, size_t len ) for( i = 0; i < len; i++ ) { if( *bytes_left == 0 ) - return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED ); + return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED ; buf[i] = *bytes_left & 0xff; --( *bytes_left ); } - return( 0 ); + return 0 ; } /* Test whether bytes represents (in big-endian base 256) a number b that @@ -101,7 +101,7 @@ static int is_significantly_above_a_power_of_2( data_t *bytes ) } /* 0 is not significantly above a power of 2 */ if( len == 0 ) - return( 0 ); + return 0 ; /* Extract the (up to) 2 most significant bytes */ if( len == 1 ) x = p[0]; @@ -117,7 +117,7 @@ static int is_significantly_above_a_power_of_2( data_t *bytes ) * a power of 2 iff x is significantly above 0 compared to 2^8. * Testing x >= 2^4 amounts to picking A = 1/16 in the function * description above. */ - return( x >= 0x10 ); + return x >= 0x10 ; } /* END_HEADER */ diff --git a/tests/suites/test_suite_net.function b/tests/suites/test_suite_net.function index f429fc9221..fdf6b024bf 100644 --- a/tests/suites/test_suite_net.function +++ b/tests/suites/test_suite_net.function @@ -40,9 +40,9 @@ static int open_file_on_fd( mbedtls_net_context *ctx, int wanted_fd ) TEST_ASSERT( close( got_fd ) >= 0 ); } ctx->fd = wanted_fd; - return( 0 ); + return 0 ; exit: - return( -1 ); + return -1 ; } #endif /* MBEDTLS_PLATFORM_IS_UNIXLIKE */ diff --git a/tests/suites/test_suite_pk.function b/tests/suites/test_suite_pk.function index 56cc45b625..454bfac165 100644 --- a/tests/suites/test_suite_pk.function +++ b/tests/suites/test_suite_pk.function @@ -48,7 +48,7 @@ static int pk_genkey( mbedtls_pk_context *pk, int parameter ) int ret; if( ( ret = mbedtls_ecp_group_load( &mbedtls_pk_ec( *pk )->grp, parameter ) ) != 0 ) - return( ret ); + return ret ; return mbedtls_ecp_gen_keypair( &mbedtls_pk_ec( *pk )->grp, &mbedtls_pk_ec( *pk )->d, @@ -56,7 +56,7 @@ static int pk_genkey( mbedtls_pk_context *pk, int parameter ) mbedtls_test_rnd_std_rand, NULL ); } #endif - return( -1 ); + return -1 ; } #if defined(MBEDTLS_RSA_C) @@ -81,7 +81,7 @@ int mbedtls_rsa_sign_func( void *ctx, } size_t mbedtls_rsa_key_len_func( void *ctx ) { - return( ((const mbedtls_rsa_context *) ctx)->len ); + return ((const mbedtls_rsa_context *) ctx)->len ; } #endif /* MBEDTLS_RSA_C */ @@ -107,7 +107,7 @@ mbedtls_svc_key_id_t pk_psa_genkey( void ) PSA_ASSERT( psa_generate_key( &attributes, &key ) ); exit: - return( key ); + return key ; } #endif /* MBEDTLS_USE_PSA_CRYPTO */ /* END_HEADER */ @@ -604,7 +604,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, hlen, - sig, sizeof sig, &slen, + sig, sizeof(sig), &slen, mbedtls_test_rnd_std_rand, NULL, &rs_ctx ); TEST_ASSERT( ret == MBEDTLS_ERR_ECP_IN_PROGRESS ); @@ -640,15 +640,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 ) @@ -673,7 +673,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 ) @@ -688,12 +688,12 @@ void pk_sign_verify( int type, int parameter, int sign_ret, int verify_ret ) { 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]--; } @@ -835,8 +835,8 @@ void pk_rsa_overflow( ) if( SIZE_MAX <= UINT_MAX ) 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 ); @@ -853,7 +853,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 ); @@ -881,11 +881,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) ); /* Initiliaze PK RSA context with random key */ TEST_ASSERT( mbedtls_pk_setup( &rsa, @@ -909,34 +909,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: @@ -999,11 +999,11 @@ void pk_psa_sign( int grpid_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. */ @@ -1024,7 +1024,7 @@ void pk_psa_sign( int grpid_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: /* diff --git a/tests/suites/test_suite_psa_crypto.function b/tests/suites/test_suite_psa_crypto.function index 150a3f43e3..a73b9a1615 100644 --- a/tests/suites/test_suite_psa_crypto.function +++ b/tests/suites/test_suite_psa_crypto.function @@ -44,9 +44,9 @@ static int mem_is_char( void *buffer, unsigned char c, size_t size ) for( i = 0; i < size; i++ ) { if( ( (unsigned char *) buffer )[i] != c ) - return( 0 ); + return 0 ; } - return( 1 ); + return 1 ; } /* Write the ASN.1 INTEGER with the value 2^(bits-1)+x backwards from *p. */ @@ -58,11 +58,11 @@ static int asn1_write_10x( unsigned char **p, int ret; int len = bits / 8 + 1; if( bits == 0 ) - return( MBEDTLS_ERR_ASN1_INVALID_DATA ); + return MBEDTLS_ERR_ASN1_INVALID_DATA ; if( bits <= 8 && x >= 1 << ( bits - 1 ) ) - return( MBEDTLS_ERR_ASN1_INVALID_DATA ); + return MBEDTLS_ERR_ASN1_INVALID_DATA ; if( *p < start || *p - start < (ptrdiff_t) len ) - return( MBEDTLS_ERR_ASN1_BUF_TOO_SMALL ); + return MBEDTLS_ERR_ASN1_BUF_TOO_SMALL ; *p -= len; ( *p )[len-1] = x; if( bits % 8 == 0 ) @@ -72,7 +72,7 @@ static int asn1_write_10x( unsigned char **p, MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( p, start, len ) ); MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( p, start, MBEDTLS_ASN1_INTEGER ) ); - return( len ); + return len ; } static int construct_fake_rsa_key( unsigned char *buffer, @@ -130,7 +130,7 @@ static int construct_fake_rsa_key( unsigned char *buffer, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE; MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( p, buffer, tag ) ); } - return( len ); + return len ; } int exercise_mac_setup( psa_key_type_t key_type, @@ -159,11 +159,11 @@ int exercise_mac_setup( psa_key_type_t key_type, } psa_destroy_key( key ); - return( 1 ); + return 1 ; exit: psa_destroy_key( key ); - return( 0 ); + return 0 ; } int exercise_cipher_setup( psa_key_type_t key_type, @@ -193,11 +193,11 @@ int exercise_cipher_setup( psa_key_type_t key_type, } psa_destroy_key( key ); - return( 1 ); + return 1 ; exit: psa_destroy_key( key ); - return( 0 ); + return 0 ; } static int test_operations_on_invalid_key( mbedtls_svc_key_id_t key ) @@ -239,7 +239,7 @@ exit: */ psa_reset_key_attributes( &attributes ); - return( ok ); + return ok ; } /* Assert that a key isn't reported as having a slot number. */ diff --git a/tests/suites/test_suite_psa_crypto_entropy.function b/tests/suites/test_suite_psa_crypto_entropy.function index 0a2623f58d..d209c08d4e 100644 --- a/tests/suites/test_suite_psa_crypto_entropy.function +++ b/tests/suites/test_suite_psa_crypto_entropy.function @@ -26,11 +26,11 @@ psa_status_t remove_seed_file( void ) { #if defined(MBEDTLS_PSA_ITS_FILE_C) if( remove( "00000000ffffff52.psa_its" ) == 0 ) - return( PSA_SUCCESS ); + return PSA_SUCCESS ; else - return( PSA_ERROR_DOES_NOT_EXIST ); + return PSA_ERROR_DOES_NOT_EXIST ; #else - return( psa_its_remove( PSA_CRYPTO_ITS_RANDOM_SEED_UID ) ); + return psa_its_remove( PSA_CRYPTO_ITS_RANDOM_SEED_UID ) ; #endif } diff --git a/tests/suites/test_suite_psa_crypto_init.function b/tests/suites/test_suite_psa_crypto_init.function index 9f72b47a4b..2ee301579d 100644 --- a/tests/suites/test_suite_psa_crypto_init.function +++ b/tests/suites/test_suite_psa_crypto_init.function @@ -43,13 +43,13 @@ static int fake_entropy_source( void *state_arg, size_t i; if( state->step >= state->max_steps ) - return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED ); + return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED ; *olen = MIN( len, state->length_sequence[state->step] ); for( i = 0; i < *olen; i++ ) output[i] = i; ++state->step; - return( 0 ); + return 0 ; } #define ENTROPY_SOURCE_PLATFORM 0x00000001 diff --git a/tests/suites/test_suite_psa_crypto_metadata.function b/tests/suites/test_suite_psa_crypto_metadata.function index 9f4fc75495..52c96a6ffd 100644 --- a/tests/suites/test_suite_psa_crypto_metadata.function +++ b/tests/suites/test_suite_psa_crypto_metadata.function @@ -88,7 +88,7 @@ int has_even_parity( uint32_t value ) value ^= value >> 16; value ^= value >> 8; value ^= value >> 4; - return( 0x9669 & 1 << ( value & 0xf ) ); + return 0x9669 & 1 << ( value & 0xf ) ; } #define TEST_PARITY( value ) \ TEST_ASSERT( has_even_parity( value ) ) diff --git a/tests/suites/test_suite_psa_crypto_se_driver_hal.function b/tests/suites/test_suite_psa_crypto_se_driver_hal.function index 79d658fd0a..7212d1547b 100644 --- a/tests/suites/test_suite_psa_crypto_se_driver_hal.function +++ b/tests/suites/test_suite_psa_crypto_se_driver_hal.function @@ -46,7 +46,7 @@ if( ! (TEST) ) \ { \ mbedtls_test_fail( #TEST, __LINE__, __FILE__ ); \ - return( PSA_ERROR_DETECTED_BY_DRIVER ); \ + return PSA_ERROR_DETECTED_BY_DRIVER ; \ } \ } while( 0 ) @@ -103,14 +103,14 @@ static size_t ecc_curve_bits( psa_ecc_family_t curve, size_t data_length ) { case PSA_ECC_FAMILY_SECP_R1: if( data_length == PSA_BYTES_TO_BITS( 521 ) ) - return( 521 ); + return 521 ; break; case PSA_ECC_FAMILY_MONTGOMERY: if( data_length == PSA_BYTES_TO_BITS( 255 ) ) - return( 255 ); + return 255 ; } /* If not listed above, assume a multiple of 8 bits. */ - return( PSA_BYTES_TO_BITS( data_length ) ); + return PSA_BYTES_TO_BITS( data_length ) ; } @@ -141,7 +141,7 @@ static psa_status_t validate_slot_number_as_directed( validate_slot_number_directions.slot_number ); DRIVER_ASSERT_RETURN( method == validate_slot_number_directions.method ); - return( validate_slot_number_directions.status ); + return validate_slot_number_directions.status ; } /* Allocate slot numbers with a monotonic counter. */ @@ -160,13 +160,13 @@ static psa_status_t counter_allocate( psa_drv_se_context_t *context, (void) attributes; (void) method; if( context->persistent_data_size != sizeof( psa_key_slot_number_t ) ) - return( PSA_ERROR_DETECTED_BY_DRIVER ); + return PSA_ERROR_DETECTED_BY_DRIVER ; ++*p_counter; if( *p_counter == 0 ) - return( PSA_ERROR_INSUFFICIENT_STORAGE ); + return PSA_ERROR_INSUFFICIENT_STORAGE ; shadow_counter = *p_counter; *slot_number = *p_counter; - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } /* Null import: do nothing, but pretend it worked. */ @@ -184,7 +184,7 @@ static psa_status_t null_import( psa_drv_se_context_t *context, /* We're supposed to return a key size. Return one that's correct for * plain data keys. */ *bits = PSA_BYTES_TO_BITS( data_length ); - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } /* Null generate: do nothing, but pretend it worked. */ @@ -206,7 +206,7 @@ static psa_status_t null_generate( psa_drv_se_context_t *context, DRIVER_ASSERT_RETURN( pubkey_size == 0 ); } - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } /* Null destroy: do nothing, but pretend it worked. */ @@ -217,7 +217,7 @@ static psa_status_t null_destroy( psa_drv_se_context_t *context, (void) context; (void) persistent_data; (void) slot_number; - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } @@ -274,10 +274,10 @@ static psa_status_t ram_create_common( psa_drv_se_context_t *context, if( required_storage > sizeof( ram_slots[slot_number].content ) ) { memset( &ram_slots[slot_number], 0, sizeof( ram_slots[slot_number] ) ); - return( PSA_ERROR_INSUFFICIENT_STORAGE ); + return PSA_ERROR_INSUFFICIENT_STORAGE ; } - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } /* This function does everything except actually generating key material. @@ -304,7 +304,7 @@ static psa_status_t ram_fake_generate( psa_drv_se_context_t *context, status = ram_create_common( context, slot_number, attributes, required_storage ); - return( status ); + return status ; } static psa_status_t ram_import( psa_drv_se_context_t *context, @@ -318,7 +318,7 @@ static psa_status_t ram_import( psa_drv_se_context_t *context, psa_status_t status = ram_create_common( context, slot_number, attributes, data_length ); if( status != PSA_SUCCESS ) - return( status ); + return status ; /* The RAM driver only works for certain key types: raw keys, * and ECC key pairs. This is true in particular of the bit-size @@ -329,18 +329,18 @@ static psa_status_t ram_import( psa_drv_se_context_t *context, { *bits = ecc_curve_bits( PSA_KEY_TYPE_ECC_GET_FAMILY( type ), data_length ); if( *bits == 0 ) - return( PSA_ERROR_DETECTED_BY_DRIVER ); + return PSA_ERROR_DETECTED_BY_DRIVER ; } else { memset( &ram_slots[slot_number], 0, sizeof( ram_slots[slot_number] ) ); - return( PSA_ERROR_NOT_SUPPORTED ); + return PSA_ERROR_NOT_SUPPORTED ; } ram_slots[slot_number].bits = *bits; memcpy( ram_slots[slot_number].content, data, data_length ); - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } static psa_status_t ram_export( psa_drv_se_context_t *context, @@ -354,10 +354,10 @@ static psa_status_t ram_export( psa_drv_se_context_t *context, DRIVER_ASSERT_RETURN( slot_number < ARRAY_LENGTH( ram_slots ) ); actual_size = PSA_BITS_TO_BYTES( ram_slots[slot_number].bits ); if( actual_size > data_size ) - return( PSA_ERROR_BUFFER_TOO_SMALL ); + return PSA_ERROR_BUFFER_TOO_SMALL ; *data_length = actual_size; memcpy( data, ram_slots[slot_number].content, actual_size ); - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } static psa_status_t ram_export_public( psa_drv_se_context_t *context, @@ -381,10 +381,10 @@ static psa_status_t ram_export_public( psa_drv_se_context_t *context, PSA_BITS_TO_BYTES( ram_slots[slot_number].bits ), &key ); if( status != PSA_SUCCESS ) - return( status ); + return status ; status = psa_export_public_key( key, data, data_size, data_length ); psa_destroy_key( key ); - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } static psa_status_t ram_destroy( psa_drv_se_context_t *context, @@ -397,7 +397,7 @@ static psa_status_t ram_destroy( psa_drv_se_context_t *context, memset( &ram_slots[slot_number], 0, sizeof( ram_slots[slot_number] ) ); *slot_usage &= ~(ram_slot_usage_t)( 1 << slot_number ); ram_shadow_slot_usage = *slot_usage; - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } static psa_status_t ram_allocate( psa_drv_se_context_t *context, @@ -417,10 +417,10 @@ static psa_status_t ram_allocate( psa_drv_se_context_t *context, if( ! ( *slot_usage & 1 << *slot_number ) ) { ram_shadow_slot_usage = *slot_usage; - return( PSA_SUCCESS ); + return PSA_SUCCESS ; } } - return( PSA_ERROR_INSUFFICIENT_STORAGE ); + return PSA_ERROR_INSUFFICIENT_STORAGE ; } static psa_status_t ram_validate_slot_number( @@ -435,8 +435,8 @@ static psa_status_t ram_validate_slot_number( (void) attributes; (void) method; if( slot_number >= ARRAY_LENGTH( ram_slots ) ) - return( PSA_ERROR_INVALID_ARGUMENT ); - return( PSA_SUCCESS ); + return PSA_ERROR_INVALID_ARGUMENT ; + return PSA_SUCCESS ; } static psa_status_t ram_sign( psa_drv_se_context_t *context, @@ -470,7 +470,7 @@ static psa_status_t ram_sign( psa_drv_se_context_t *context, exit: psa_destroy_key( key ); - return( status ); + return status ; } static psa_status_t ram_verify( psa_drv_se_context_t *context, @@ -504,7 +504,7 @@ static psa_status_t ram_verify( psa_drv_se_context_t *context, exit: psa_destroy_key( key ); - return( status ); + return status ; } @@ -583,7 +583,7 @@ exit: */ psa_reset_key_attributes( &actual_attributes ); - return( ok ); + return ok ; } /* Get the file UID corresponding to the specified location. @@ -593,8 +593,8 @@ exit: psa_storage_uid_t file_uid_for_location( psa_key_location_t location ) { if( location > PSA_MAX_SE_LOCATION ) - return( 0 ); - return( 0xfffffe00 + location ); + return 0 ; + return 0xfffffe00 + location ; } /* Check that the persistent data of a driver has its expected content. */ @@ -615,7 +615,7 @@ static int check_persistent_data( psa_key_location_t location, exit: mbedtls_free( loaded ); - return( ok ); + return ok ; } /* Check that no persistent data exists for the given location. */ @@ -629,7 +629,7 @@ static int check_no_persistent_data( psa_key_location_t location ) ok = 1; exit: - return( ok ); + return ok ; } /* Check that a function's return status is "smoke-free", i.e. that @@ -646,9 +646,9 @@ static int is_status_smoke_free( psa_status_t status ) case PSA_ERROR_INVALID_ARGUMENT: case PSA_ERROR_INVALID_SIGNATURE: case PSA_ERROR_INVALID_PADDING: - return( 1 ); + return 1 ; default: - return( 0 ); + return 0 ; } } #define SMOKE_ASSERT( expr ) \ @@ -764,7 +764,7 @@ exit: */ psa_reset_key_attributes( &attributes ); - return( ok ); + return ok ; } static void psa_purge_storage( void ) diff --git a/tests/suites/test_suite_psa_crypto_se_driver_hal_mocks.function b/tests/suites/test_suite_psa_crypto_se_driver_hal_mocks.function index 12c58ebbba..5d3af02147 100644 --- a/tests/suites/test_suite_psa_crypto_se_driver_hal_mocks.function +++ b/tests/suites/test_suite_psa_crypto_se_driver_hal_mocks.function @@ -127,7 +127,7 @@ static psa_status_t mock_init( psa_drv_se_context_t *drv_context, mock_init_data.called++; mock_init_data.location = location; - return( mock_init_data.return_value ); + return mock_init_data.return_value ; } static psa_status_t mock_generate( psa_drv_se_context_t *drv_context, @@ -146,7 +146,7 @@ static psa_status_t mock_generate( psa_drv_se_context_t *drv_context, mock_generate_data.attributes = *attributes; mock_generate_data.pubkey_size = pubkey_size; - return( mock_generate_data.return_value ); + return mock_generate_data.return_value ; } static psa_status_t mock_import( psa_drv_se_context_t *drv_context, @@ -166,7 +166,7 @@ static psa_status_t mock_import( psa_drv_se_context_t *drv_context, mock_import_data.attributes = *attributes; mock_import_data.data_length = data_length; - return( mock_import_data.return_value ); + return mock_import_data.return_value ; } psa_status_t mock_export( psa_drv_se_context_t *context, @@ -183,7 +183,7 @@ psa_status_t mock_export( psa_drv_se_context_t *context, mock_export_data.slot_number = slot_number; mock_export_data.data_size = data_size; - return( mock_export_data.return_value ); + return mock_export_data.return_value ; } psa_status_t mock_export_public( psa_drv_se_context_t *context, @@ -200,7 +200,7 @@ psa_status_t mock_export_public( psa_drv_se_context_t *context, mock_export_public_data.slot_number = slot_number; mock_export_public_data.data_size = data_size; - return( mock_export_public_data.return_value ); + return mock_export_public_data.return_value ; } psa_status_t mock_sign( psa_drv_se_context_t *context, @@ -262,7 +262,7 @@ psa_status_t mock_allocate( psa_drv_se_context_t *drv_context, mock_allocate_data.called++; *key_slot = 0; - return( mock_allocate_data.return_value ); + return mock_allocate_data.return_value ; } psa_status_t mock_destroy( psa_drv_se_context_t *context, @@ -275,7 +275,7 @@ psa_status_t mock_destroy( psa_drv_se_context_t *context, mock_destroy_data.called++; mock_destroy_data.slot_number = slot_number; - return( mock_destroy_data.return_value ); + return mock_destroy_data.return_value ; } /* END_HEADER */ diff --git a/tests/suites/test_suite_psa_crypto_slot_management.function b/tests/suites/test_suite_psa_crypto_slot_management.function index aa3ce28f24..ca54966e7e 100644 --- a/tests/suites/test_suite_psa_crypto_slot_management.function +++ b/tests/suites/test_suite_psa_crypto_slot_management.function @@ -68,9 +68,9 @@ static int invalidate_key( invalidate_method_t invalidate_method, case INVALIDATE_BY_SHUTDOWN: break; } - return( 1 ); + return 1 ; exit: - return( 0 ); + return 0 ; } /** Restart the PSA subsystem if \p invalidate_method says so. */ @@ -81,7 +81,7 @@ static int invalidate_psa( invalidate_method_t invalidate_method ) case INVALIDATE_BY_CLOSING: case INVALIDATE_BY_DESTROYING: case INVALIDATE_BY_PURGING: - return( 1 ); + return 1 ; case INVALIDATE_BY_CLOSING_WITH_SHUTDOWN: case INVALIDATE_BY_DESTROYING_WITH_SHUTDOWN: case INVALIDATE_BY_PURGING_WITH_SHUTDOWN: @@ -97,10 +97,10 @@ static int invalidate_psa( invalidate_method_t invalidate_method ) PSA_ASSERT( psa_crypto_init( ) ); ASSERT_PSA_PRISTINE( ); - return( 1 ); + return 1 ; exit: - return( 0 ); + return 0 ; } /* END_HEADER */ diff --git a/tests/suites/test_suite_psa_crypto_storage_format.function b/tests/suites/test_suite_psa_crypto_storage_format.function index b90ef6efcb..76d8189740 100644 --- a/tests/suites/test_suite_psa_crypto_storage_format.function +++ b/tests/suites/test_suite_psa_crypto_storage_format.function @@ -46,18 +46,18 @@ static int test_written_key( const psa_key_attributes_t *attributes, exit: mbedtls_free( actual_representation ); - return( ok ); + return ok ; } /** Check if a key is exportable. */ static int can_export( const psa_key_attributes_t *attributes ) { if( psa_get_key_usage_flags( attributes ) & PSA_KEY_USAGE_EXPORT ) - return( 1 ); + return 1 ; else if( PSA_KEY_TYPE_IS_PUBLIC_KEY( psa_get_key_type( attributes ) ) ) - return( 1 ); + return 1 ; else - return( 0 ); + return 0 ; } /** Write a key with the given representation to storage, then check @@ -137,7 +137,7 @@ exit: psa_reset_key_attributes( &actual_attributes ); psa_its_remove( uid ); mbedtls_free( exported_material ); - return( ok ); + return ok ; } /* END_HEADER */ diff --git a/tests/suites/test_suite_psa_its.function b/tests/suites/test_suite_psa_its.function index fb9ce07036..79e5ccc538 100644 --- a/tests/suites/test_suite_psa_its.function +++ b/tests/suites/test_suite_psa_its.function @@ -68,7 +68,7 @@ static psa_status_t psa_its_set_wrap( psa_storage_uid_t uid, { if( uid_max != (psa_storage_uid_t)( -1 ) && uid_max < uid ) uid_max = uid; - return( psa_its_set( uid, data_length, p_data, create_flags ) ); + return psa_its_set( uid, data_length, p_data, create_flags ) ; } /* END_HEADER */ diff --git a/tests/suites/test_suite_ssl.function b/tests/suites/test_suite_ssl.function index 72b0cdb8ac..b24e131acf 100644 --- a/tests/suites/test_suite_ssl.function +++ b/tests/suites/test_suite_ssl.function @@ -1177,7 +1177,7 @@ int psk_dummy_callback( void *p_info, mbedtls_ssl_context *ssl, (void) name; (void) name_len; - return ( 0 ); + return 0 ; } #if MBEDTLS_SSL_CID_OUT_LEN_MAX > MBEDTLS_SSL_CID_IN_LEN_MAX @@ -1428,7 +1428,7 @@ cleanup: mbedtls_free( md0 ); mbedtls_free( md1 ); - return( ret ); + return ret ; } /* @@ -1458,13 +1458,13 @@ static int ssl_populate_session_tls12( mbedtls_ssl_session *session, mbedtls_x509_crt_init( &tmp_crt ); ret = mbedtls_x509_crt_parse_file( &tmp_crt, crt_file ); if( ret != 0 ) - return( ret ); + return ret ; #if defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE) /* Move temporary CRT. */ session->peer_cert = mbedtls_calloc( 1, sizeof( *session->peer_cert ) ); if( session->peer_cert == NULL ) - return( -1 ); + return -1 ; *session->peer_cert = tmp_crt; memset( &tmp_crt, 0, sizeof( tmp_crt ) ); #else /* MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */ @@ -1472,13 +1472,13 @@ static int ssl_populate_session_tls12( mbedtls_ssl_session *session, session->peer_cert_digest = mbedtls_calloc( 1, MBEDTLS_SSL_PEER_CERT_DIGEST_DFL_LEN ); if( session->peer_cert_digest == NULL ) - return( -1 ); + return -1 ; ret = mbedtls_md( mbedtls_md_info_from_type( MBEDTLS_SSL_PEER_CERT_DIGEST_DFL_TYPE ), tmp_crt.raw.p, tmp_crt.raw.len, session->peer_cert_digest ); if( ret != 0 ) - return( ret ); + return ret ; session->peer_cert_digest_type = MBEDTLS_SSL_PEER_CERT_DIGEST_DFL_TYPE; session->peer_cert_digest_len = @@ -1497,7 +1497,7 @@ static int ssl_populate_session_tls12( mbedtls_ssl_session *session, { session->ticket = mbedtls_calloc( 1, ticket_len ); if( session->ticket == NULL ) - return( -1 ); + return -1 ; memset( session->ticket, 33, ticket_len ); } session->ticket_len = ticket_len; @@ -1513,7 +1513,7 @@ static int ssl_populate_session_tls12( mbedtls_ssl_session *session, session->encrypt_then_mac = 1; #endif - return( 0 ); + return 0 ; } /* diff --git a/tests/suites/test_suite_x509parse.function b/tests/suites/test_suite_x509parse.function index fea02f362c..912364c103 100644 --- a/tests/suites/test_suite_x509parse.function +++ b/tests/suites/test_suite_x509parse.function @@ -139,7 +139,7 @@ exit: } *candidates = first; - return( ret ); + return ret ; } #endif /* MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK */ @@ -154,10 +154,10 @@ int verify_fatal( void *data, mbedtls_x509_crt *crt, int certificate_depth, uint if( *levels & ( 1 << certificate_depth ) ) { *flags |= ( 1 << certificate_depth ); - return( -1 - certificate_depth ); + return -1 - certificate_depth ; } - return( 0 ); + return 0 ; } /* strsep() not available on Windows */ @@ -167,7 +167,7 @@ char *mystrsep(char **stringp, const char *delim) char *ret = *stringp; if( *stringp == NULL ) - return( NULL ); + return NULL ; for( ; ; (*stringp)++ ) { @@ -187,7 +187,7 @@ char *mystrsep(char **stringp, const char *delim) } done: - return( ret ); + return ret ; } #if defined(MBEDTLS_X509_CRT_PARSE_C) @@ -227,7 +227,7 @@ int verify_print( void *data, mbedtls_x509_crt *crt, int certificate_depth, uint ctx->p = p; - return( 0 ); + return 0 ; } int verify_parse_san( mbedtls_x509_subject_alternative_name *san, @@ -265,7 +265,7 @@ int verify_parse_san( mbedtls_x509_subject_alternative_name *san, if( san->san.other_name.value.hardware_module_name.val.len >= n ) { *p = '\0'; - return( MBEDTLS_ERR_X509_BUFFER_TOO_SMALL ); + return MBEDTLS_ERR_X509_BUFFER_TOO_SMALL ; } for( i=0; i < san->san.other_name.value.hardware_module_name.val.len; i++ ) @@ -281,7 +281,7 @@ int verify_parse_san( mbedtls_x509_subject_alternative_name *san, if( san->san.unstructured_name.len >= n ) { *p = '\0'; - return( MBEDTLS_ERR_X509_BUFFER_TOO_SMALL ); + return MBEDTLS_ERR_X509_BUFFER_TOO_SMALL ; } n -= san->san.unstructured_name.len; for( i = 0; i < san->san.unstructured_name.len; i++ ) @@ -292,7 +292,7 @@ int verify_parse_san( mbedtls_x509_subject_alternative_name *san, /* * Should not happen. */ - return( -1 ); + return -1 ; } ret = mbedtls_snprintf( p, n, "\n" ); MBEDTLS_X509_SAFE_SNPRINTF; @@ -300,7 +300,7 @@ int verify_parse_san( mbedtls_x509_subject_alternative_name *san, *size = n; *buf = p; - return( 0 ); + return 0 ; } int parse_crt_ext_cb( void *p_ctx, mbedtls_x509_crt const *crt, mbedtls_x509_buf const *oid, @@ -321,7 +321,7 @@ int parse_crt_ext_cb( void *p_ctx, mbedtls_x509_crt const *crt, mbedtls_x509_buf ret = mbedtls_asn1_get_tag( p, end, &len, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ); if( ret != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ; if( *p + len != end ) return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, @@ -343,13 +343,13 @@ int parse_crt_ext_cb( void *p_ctx, mbedtls_x509_crt const *crt, mbedtls_x509_buf */ if( ( ret = mbedtls_asn1_get_tag( p, end, &len, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ; policy_end = *p + len; if( ( ret = mbedtls_asn1_get_tag( p, policy_end, &len, MBEDTLS_ASN1_OID ) ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ; /* * Recognize exclusively the policy with OID 1 @@ -367,7 +367,7 @@ int parse_crt_ext_cb( void *p_ctx, mbedtls_x509_crt const *crt, mbedtls_x509_buf { if( ( ret = mbedtls_asn1_get_tag( p, policy_end, &len, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 ) - return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ); + return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ; /* * Skip the optional policy qualifiers. */ @@ -383,11 +383,11 @@ int parse_crt_ext_cb( void *p_ctx, mbedtls_x509_crt const *crt, mbedtls_x509_buf return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) ); - return( parse_ret ); + return parse_ret ; } else if( new_oid != NULL && new_oid->tag == oid->tag && new_oid->len == oid->len && memcmp( new_oid->p, oid->p, oid->len ) == 0 ) - return( 0 ); + return 0 ; else return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, MBEDTLS_ERR_ASN1_UNEXPECTED_TAG ) ); @@ -1059,9 +1059,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 */ @@ -1155,13 +1155,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 ); diff --git a/tests/suites/test_suite_x509write.function b/tests/suites/test_suite_x509write.function index 261794c7f8..a5450936de 100644 --- a/tests/suites/test_suite_x509write.function +++ b/tests/suites/test_suite_x509write.function @@ -24,7 +24,7 @@ int mbedtls_rsa_sign_func( void *ctx, } size_t mbedtls_rsa_key_len_func( void *ctx ) { - return( ((const mbedtls_rsa_context *) ctx)->len ); + return ((const mbedtls_rsa_context *) ctx)->len ; } #endif /* MBEDTLS_RSA_C */ @@ -64,7 +64,7 @@ static int x509_crt_verifycsr( const unsigned char *buf, size_t buflen ) cleanup: mbedtls_x509_csr_free( &csr ); - return( ret ); + return ret ; } #endif /* MBEDTLS_USE_PSA_CRYPTO && MBEDTLS_PEM_WRITE_C && MBEDTLS_X509_CSR_WRITE_C */