Skip to content

Commit

Permalink
Add MBEDTLS_SELF_TEST check in header files
Browse files Browse the repository at this point in the history
Add the `MBEDTLS_SELF_TEST` precompilation surrounding the self test functions,
which were missing this check in the header files. ( most of the header files were missing this check).
Addresses issue #971
  • Loading branch information
Ron Eldor authored and Ron Eldor committed May 21, 2018
1 parent c4bd8ec commit fa8f635
Show file tree
Hide file tree
Showing 21 changed files with 83 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ API Changes
Therefore, mbedtls_platform_zeroize() is moved to the platform module to
facilitate testing and maintenance.

Bugfix
* Add `MBEDTLS_SELF_TEST` for the mbedtls_self_test functions
in the header files, which missed the precompilation check. #971

= mbed TLS 2.9.0 branch released 2018-04-30

Security
Expand Down
4 changes: 4 additions & 0 deletions include/mbedtls/aes.h
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,8 @@ MBEDTLS_DEPRECATED void mbedtls_aes_decrypt( mbedtls_aes_context *ctx,
#undef MBEDTLS_DEPRECATED
#endif /* !MBEDTLS_DEPRECATED_REMOVED */


#if defined(MBEDTLS_SELF_TEST)
/**
* \brief Checkup routine.
*
Expand All @@ -408,6 +410,8 @@ MBEDTLS_DEPRECATED void mbedtls_aes_decrypt( mbedtls_aes_context *ctx,
*/
int mbedtls_aes_self_test( int verbose );

#endif /* MBEDTLS_SELF_TEST */

#ifdef __cplusplus
}
#endif
Expand Down
4 changes: 4 additions & 0 deletions include/mbedtls/arc4.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ void mbedtls_arc4_setup( mbedtls_arc4_context *ctx, const unsigned char *key,
int mbedtls_arc4_crypt( mbedtls_arc4_context *ctx, size_t length, const unsigned char *input,
unsigned char *output );

#if defined(MBEDTLS_SELF_TEST)

/**
* \brief Checkup routine
*
Expand All @@ -134,6 +136,8 @@ int mbedtls_arc4_crypt( mbedtls_arc4_context *ctx, size_t length, const unsigned
*/
int mbedtls_arc4_self_test( int verbose );

#endif /* MBEDTLS_SELF_TEST */

#ifdef __cplusplus
}
#endif
Expand Down
3 changes: 3 additions & 0 deletions include/mbedtls/base64.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,16 @@ int mbedtls_base64_encode( unsigned char *dst, size_t dlen, size_t *olen,
int mbedtls_base64_decode( unsigned char *dst, size_t dlen, size_t *olen,
const unsigned char *src, size_t slen );

#if defined(MBEDTLS_SELF_TEST)
/**
* \brief Checkup routine
*
* \return 0 if successful, or 1 if the test failed
*/
int mbedtls_base64_self_test( int verbose );

#endif /* MBEDTLS_SELF_TEST */

#ifdef __cplusplus
}
#endif
Expand Down
4 changes: 4 additions & 0 deletions include/mbedtls/bignum.h
Original file line number Diff line number Diff line change
Expand Up @@ -758,13 +758,17 @@ int mbedtls_mpi_gen_prime( mbedtls_mpi *X, size_t nbits, int dh_flag,
int (*f_rng)(void *, unsigned char *, size_t),
void *p_rng );

#if defined(MBEDTLS_SELF_TEST)

/**
* \brief Checkup routine
*
* \return 0 if successful, or 1 if the test failed
*/
int mbedtls_mpi_self_test( int verbose );

#endif /* MBEDTLS_SELF_TEST */

#ifdef __cplusplus
}
#endif
Expand Down
4 changes: 4 additions & 0 deletions include/mbedtls/camellia.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,17 @@ int mbedtls_camellia_crypt_ctr( mbedtls_camellia_context *ctx,
unsigned char *output );
#endif /* MBEDTLS_CIPHER_MODE_CTR */

#if defined(MBEDTLS_SELF_TEST)

/**
* \brief Checkup routine
*
* \return 0 if successful, or 1 if the test failed
*/
int mbedtls_camellia_self_test( int verbose );

#endif /* MBEDTLS_SELF_TEST */

#ifdef __cplusplus
}
#endif
Expand Down
4 changes: 4 additions & 0 deletions include/mbedtls/ctr_drbg.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,8 @@ int mbedtls_ctr_drbg_write_seed_file( mbedtls_ctr_drbg_context *ctx, const char
int mbedtls_ctr_drbg_update_seed_file( mbedtls_ctr_drbg_context *ctx, const char *path );
#endif /* MBEDTLS_FS_IO */

#if defined(MBEDTLS_SELF_TEST)

/**
* \brief The CTR_DRBG checkup routine.
*
Expand All @@ -318,6 +320,8 @@ int mbedtls_ctr_drbg_update_seed_file( mbedtls_ctr_drbg_context *ctx, const char
*/
int mbedtls_ctr_drbg_self_test( int verbose );

#endif /* MBEDTLS_SELF_TEST */

/* Internal functions (do not call directly) */
int mbedtls_ctr_drbg_seed_entropy_len( mbedtls_ctr_drbg_context *,
int (*)(void *, unsigned char *, size_t), void *,
Expand Down
4 changes: 4 additions & 0 deletions include/mbedtls/des.h
Original file line number Diff line number Diff line change
Expand Up @@ -336,13 +336,17 @@ int mbedtls_des3_crypt_cbc( mbedtls_des3_context *ctx,
void mbedtls_des_setkey( uint32_t SK[32],
const unsigned char key[MBEDTLS_DES_KEY_SIZE] );

#if defined(MBEDTLS_SELF_TEST)

/**
* \brief Checkup routine
*
* \return 0 if successful, or 1 if the test failed
*/
int mbedtls_des_self_test( int verbose );

#endif /* MBEDTLS_SELF_TEST */

#ifdef __cplusplus
}
#endif
Expand Down
3 changes: 3 additions & 0 deletions include/mbedtls/dhm.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,8 @@ int mbedtls_dhm_parse_dhmfile( mbedtls_dhm_context *dhm, const char *path );
#endif /* MBEDTLS_FS_IO */
#endif /* MBEDTLS_ASN1_PARSE_C */

#if defined(MBEDTLS_SELF_TEST)

/**
* \brief The DMH checkup routine.
*
Expand All @@ -303,6 +305,7 @@ int mbedtls_dhm_parse_dhmfile( mbedtls_dhm_context *dhm, const char *path );
*/
int mbedtls_dhm_self_test( int verbose );

#endif /* MBEDTLS_SELF_TEST */
#ifdef __cplusplus
}
#endif
Expand Down
4 changes: 4 additions & 0 deletions include/mbedtls/gcm.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ int mbedtls_gcm_finish( mbedtls_gcm_context *ctx,
*/
void mbedtls_gcm_free( mbedtls_gcm_context *ctx );

#if defined(MBEDTLS_SELF_TEST)

/**
* \brief The GCM checkup routine.
*
Expand All @@ -258,6 +260,8 @@ void mbedtls_gcm_free( mbedtls_gcm_context *ctx );
*/
int mbedtls_gcm_self_test( int verbose );

#endif /* MBEDTLS_SELF_TEST */

#ifdef __cplusplus
}
#endif
Expand Down
4 changes: 4 additions & 0 deletions include/mbedtls/md2.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,8 @@ MBEDTLS_DEPRECATED void mbedtls_md2( const unsigned char *input,
#undef MBEDTLS_DEPRECATED
#endif /* !MBEDTLS_DEPRECATED_REMOVED */

#if defined(MBEDTLS_SELF_TEST)

/**
* \brief Checkup routine
*
Expand All @@ -294,6 +296,8 @@ MBEDTLS_DEPRECATED void mbedtls_md2( const unsigned char *input,
*/
int mbedtls_md2_self_test( int verbose );

#endif /* MBEDTLS_SELF_TEST */

#ifdef __cplusplus
}
#endif
Expand Down
4 changes: 4 additions & 0 deletions include/mbedtls/md4.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ MBEDTLS_DEPRECATED void mbedtls_md4( const unsigned char *input,
#undef MBEDTLS_DEPRECATED
#endif /* !MBEDTLS_DEPRECATED_REMOVED */

#if defined(MBEDTLS_SELF_TEST)

/**
* \brief Checkup routine
*
Expand All @@ -299,6 +301,8 @@ MBEDTLS_DEPRECATED void mbedtls_md4( const unsigned char *input,
*/
int mbedtls_md4_self_test( int verbose );

#endif /* MBEDTLS_SELF_TEST */

#ifdef __cplusplus
}
#endif
Expand Down
4 changes: 4 additions & 0 deletions include/mbedtls/md5.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ MBEDTLS_DEPRECATED void mbedtls_md5( const unsigned char *input,
#undef MBEDTLS_DEPRECATED
#endif /* !MBEDTLS_DEPRECATED_REMOVED */

#if defined(MBEDTLS_SELF_TEST)

/**
* \brief Checkup routine
*
Expand All @@ -299,6 +301,8 @@ MBEDTLS_DEPRECATED void mbedtls_md5( const unsigned char *input,
*/
int mbedtls_md5_self_test( int verbose );

#endif /* MBEDTLS_SELF_TEST */

#ifdef __cplusplus
}
#endif
Expand Down
4 changes: 4 additions & 0 deletions include/mbedtls/pkcs5.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,17 @@ int mbedtls_pkcs5_pbkdf2_hmac( mbedtls_md_context_t *ctx, const unsigned char *p
unsigned int iteration_count,
uint32_t key_length, unsigned char *output );

#if defined(MBEDTLS_SELF_TEST)

/**
* \brief Checkup routine
*
* \return 0 if successful, or 1 if the test failed
*/
int mbedtls_pkcs5_self_test( int verbose );

#endif /* MBEDTLS_SELF_TEST */

#ifdef __cplusplus
}
#endif
Expand Down
4 changes: 4 additions & 0 deletions include/mbedtls/ripemd160.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,17 @@ MBEDTLS_DEPRECATED void mbedtls_ripemd160( const unsigned char *input,
#undef MBEDTLS_DEPRECATED
#endif /* !MBEDTLS_DEPRECATED_REMOVED */

#if defined(MBEDTLS_SELF_TEST)

/**
* \brief Checkup routine
*
* \return 0 if successful, or 1 if the test failed
*/
int mbedtls_ripemd160_self_test( int verbose );

#endif /* MBEDTLS_SELF_TEST */

#ifdef __cplusplus
}
#endif
Expand Down
4 changes: 4 additions & 0 deletions include/mbedtls/rsa.h
Original file line number Diff line number Diff line change
Expand Up @@ -1116,6 +1116,8 @@ int mbedtls_rsa_copy( mbedtls_rsa_context *dst, const mbedtls_rsa_context *src )
*/
void mbedtls_rsa_free( mbedtls_rsa_context *ctx );

#if defined(MBEDTLS_SELF_TEST)

/**
* \brief The RSA checkup routine.
*
Expand All @@ -1124,6 +1126,8 @@ void mbedtls_rsa_free( mbedtls_rsa_context *ctx );
*/
int mbedtls_rsa_self_test( int verbose );

#endif /* MBEDTLS_SELF_TEST */

#ifdef __cplusplus
}
#endif
Expand Down
4 changes: 4 additions & 0 deletions include/mbedtls/sha1.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,8 @@ MBEDTLS_DEPRECATED void mbedtls_sha1( const unsigned char *input,
#undef MBEDTLS_DEPRECATED
#endif /* !MBEDTLS_DEPRECATED_REMOVED */

#if defined(MBEDTLS_SELF_TEST)

/**
* \brief The SHA-1 checkup routine.
*
Expand All @@ -317,6 +319,8 @@ MBEDTLS_DEPRECATED void mbedtls_sha1( const unsigned char *input,
*/
int mbedtls_sha1_self_test( int verbose );

#endif /* MBEDTLS_SELF_TEST */

#ifdef __cplusplus
}
#endif
Expand Down
4 changes: 4 additions & 0 deletions include/mbedtls/sha256.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ MBEDTLS_DEPRECATED void mbedtls_sha256( const unsigned char *input,
#undef MBEDTLS_DEPRECATED
#endif /* !MBEDTLS_DEPRECATED_REMOVED */

#if defined(MBEDTLS_SELF_TEST)

/**
* \brief The SHA-224 and SHA-256 checkup routine.
*
Expand All @@ -265,6 +267,8 @@ MBEDTLS_DEPRECATED void mbedtls_sha256( const unsigned char *input,
*/
int mbedtls_sha256_self_test( int verbose );

#endif /* MBEDTLS_SELF_TEST */

#ifdef __cplusplus
}
#endif
Expand Down
5 changes: 5 additions & 0 deletions include/mbedtls/sha512.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ int mbedtls_sha512_ret( const unsigned char *input,
#else
#define MBEDTLS_DEPRECATED
#endif

/**
* \brief This function calculates the SHA-512 or SHA-384
* checksum of a buffer.
Expand All @@ -255,13 +256,17 @@ MBEDTLS_DEPRECATED void mbedtls_sha512( const unsigned char *input,

#undef MBEDTLS_DEPRECATED
#endif /* !MBEDTLS_DEPRECATED_REMOVED */

#if defined(MBEDTLS_SELF_TEST)

/**
* \brief The SHA-384 or SHA-512 checkup routine.
*
* \return \c 0 on success.
* \return \c 1 on failure.
*/
int mbedtls_sha512_self_test( int verbose );
#endif /* MBEDTLS_SELF_TEST */

#ifdef __cplusplus
}
Expand Down
4 changes: 4 additions & 0 deletions include/mbedtls/x509.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,13 +269,17 @@ int mbedtls_x509_time_is_past( const mbedtls_x509_time *to );
*/
int mbedtls_x509_time_is_future( const mbedtls_x509_time *from );

#if defined(MBEDTLS_SELF_TEST)

/**
* \brief Checkup routine
*
* \return 0 if successful, or 1 if the test failed
*/
int mbedtls_x509_self_test( int verbose );

#endif /* MBEDTLS_SELF_TEST */

/*
* Internal module functions. You probably do not want to use these unless you
* know you do.
Expand Down
4 changes: 4 additions & 0 deletions include/mbedtls/xtea.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,17 @@ int mbedtls_xtea_crypt_cbc( mbedtls_xtea_context *ctx,
unsigned char *output);
#endif /* MBEDTLS_CIPHER_MODE_CBC */

#if defined(MBEDTLS_SELF_TEST)

/**
* \brief Checkup routine
*
* \return 0 if successful, or 1 if the test failed
*/
int mbedtls_xtea_self_test( int verbose );

#endif /* MBEDTLS_SELF_TEST */

#ifdef __cplusplus
}
#endif
Expand Down

0 comments on commit fa8f635

Please sign in to comment.