Skip to content

Commit ac48a76

Browse files
Ron EldorRon Eldor
Ron Eldor
authored and
Ron Eldor
committed
Add MBEDTLS_SELF_TEST check in header files
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 Mbed-TLS#971
1 parent 45d2695 commit ac48a76

21 files changed

+79
-0
lines changed

ChangeLog

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ Bugfix
3030
when dealing with negative MPI. Found by Guido Vranken.
3131
* Fix potential stack underflow in mpi_read_file.
3232
Found by Guido Vranken.
33+
* Add `MBEDTLS_SELF_TEST` for the mbedtls_self_test functions
34+
in the header files, which missed the precompilation check. #971
3335

3436
Changes
3537
* Send fatal alerts in many more cases instead of dropping the connection.

include/mbedtls/aes.h

+3
Original file line numberDiff line numberDiff line change
@@ -339,13 +339,16 @@ MBEDTLS_DEPRECATED static inline void mbedtls_aes_decrypt(
339339
extern "C" {
340340
#endif
341341

342+
#if defined(MBEDTLS_SELF_TEST)
342343
/**
343344
* \brief Checkup routine
344345
*
345346
* \return 0 if successful, or 1 if the test failed
346347
*/
347348
int mbedtls_aes_self_test( int verbose );
348349

350+
#endif /*MBEDTLS_SELF_TEST*/
351+
349352
#ifdef __cplusplus
350353
}
351354
#endif

include/mbedtls/arc4.h

+4
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,17 @@ int mbedtls_arc4_crypt( mbedtls_arc4_context *ctx, size_t length, const unsigned
9999
extern "C" {
100100
#endif
101101

102+
#if defined(MBEDTLS_SELF_TEST)
103+
102104
/**
103105
* \brief Checkup routine
104106
*
105107
* \return 0 if successful, or 1 if the test failed
106108
*/
107109
int mbedtls_arc4_self_test( int verbose );
108110

111+
#endif /*MBEDTLS_SELF_TEST*/
112+
109113
#ifdef __cplusplus
110114
}
111115
#endif

include/mbedtls/base64.h

+3
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,16 @@ int mbedtls_base64_encode( unsigned char *dst, size_t dlen, size_t *olen,
7474
int mbedtls_base64_decode( unsigned char *dst, size_t dlen, size_t *olen,
7575
const unsigned char *src, size_t slen );
7676

77+
#if defined(MBEDTLS_SELF_TEST)
7778
/**
7879
* \brief Checkup routine
7980
*
8081
* \return 0 if successful, or 1 if the test failed
8182
*/
8283
int mbedtls_base64_self_test( int verbose );
8384

85+
#endif /*MBEDTLS_SELF_TEST*/
86+
8487
#ifdef __cplusplus
8588
}
8689
#endif

include/mbedtls/bignum.h

+4
Original file line numberDiff line numberDiff line change
@@ -712,13 +712,17 @@ int mbedtls_mpi_gen_prime( mbedtls_mpi *X, size_t nbits, int dh_flag,
712712
int (*f_rng)(void *, unsigned char *, size_t),
713713
void *p_rng );
714714

715+
#if defined(MBEDTLS_SELF_TEST)
716+
715717
/**
716718
* \brief Checkup routine
717719
*
718720
* \return 0 if successful, or 1 if the test failed
719721
*/
720722
int mbedtls_mpi_self_test( int verbose );
721723

724+
#endif /*MBEDTLS_SELF_TEST*/
725+
722726
#ifdef __cplusplus
723727
}
724728
#endif

include/mbedtls/camellia.h

+4
Original file line numberDiff line numberDiff line change
@@ -221,13 +221,17 @@ int mbedtls_camellia_crypt_ctr( mbedtls_camellia_context *ctx,
221221
extern "C" {
222222
#endif
223223

224+
#if defined(MBEDTLS_SELF_TEST)
225+
224226
/**
225227
* \brief Checkup routine
226228
*
227229
* \return 0 if successful, or 1 if the test failed
228230
*/
229231
int mbedtls_camellia_self_test( int verbose );
230232

233+
#endif /*MBEDTLS_SELF_TEST*/
234+
231235
#ifdef __cplusplus
232236
}
233237
#endif

include/mbedtls/ctr_drbg.h

+4
Original file line numberDiff line numberDiff line change
@@ -271,13 +271,17 @@ int mbedtls_ctr_drbg_write_seed_file( mbedtls_ctr_drbg_context *ctx, const char
271271
int mbedtls_ctr_drbg_update_seed_file( mbedtls_ctr_drbg_context *ctx, const char *path );
272272
#endif /* MBEDTLS_FS_IO */
273273

274+
#if defined(MBEDTLS_SELF_TEST)
275+
274276
/**
275277
* \brief Checkup routine
276278
*
277279
* \return 0 if successful, or 1 if the test failed
278280
*/
279281
int mbedtls_ctr_drbg_self_test( int verbose );
280282

283+
#endif
284+
281285
/* Internal functions (do not call directly) */
282286
int mbedtls_ctr_drbg_seed_entropy_len( mbedtls_ctr_drbg_context *,
283287
int (*)(void *, unsigned char *, size_t), void *,

include/mbedtls/des.h

+4
Original file line numberDiff line numberDiff line change
@@ -292,13 +292,17 @@ void mbedtls_des_setkey( uint32_t SK[32],
292292
extern "C" {
293293
#endif
294294

295+
#if defined(MBEDTLS_SELF_TEST)
296+
295297
/**
296298
* \brief Checkup routine
297299
*
298300
* \return 0 if successful, or 1 if the test failed
299301
*/
300302
int mbedtls_des_self_test( int verbose );
301303

304+
#endif /*MBEDTLS_SELF_TEST*/
305+
302306
#ifdef __cplusplus
303307
}
304308
#endif

include/mbedtls/dhm.h

+3
Original file line numberDiff line numberDiff line change
@@ -291,13 +291,16 @@ int mbedtls_dhm_parse_dhmfile( mbedtls_dhm_context *dhm, const char *path );
291291
#endif /* MBEDTLS_FS_IO */
292292
#endif /* MBEDTLS_ASN1_PARSE_C */
293293

294+
#if defined(MBEDTLS_SELF_TEST)
295+
294296
/**
295297
* \brief Checkup routine
296298
*
297299
* \return 0 if successful, or 1 if the test failed
298300
*/
299301
int mbedtls_dhm_self_test( int verbose );
300302

303+
#endif /*MBEDTLS_SELF_TEST*/
301304
#ifdef __cplusplus
302305
}
303306
#endif

include/mbedtls/gcm.h

+4
Original file line numberDiff line numberDiff line change
@@ -206,13 +206,17 @@ int mbedtls_gcm_finish( mbedtls_gcm_context *ctx,
206206
*/
207207
void mbedtls_gcm_free( mbedtls_gcm_context *ctx );
208208

209+
#if defined(MBEDTLS_SELF_TEST)
210+
209211
/**
210212
* \brief Checkup routine
211213
*
212214
* \return 0 if successful, or 1 if the test failed
213215
*/
214216
int mbedtls_gcm_self_test( int verbose );
215217

218+
#endif /*MBEDTLS_SELF_TEST*/
219+
216220
#ifdef __cplusplus
217221
}
218222
#endif

include/mbedtls/md2.h

+4
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,17 @@ extern "C" {
119119
*/
120120
void mbedtls_md2( const unsigned char *input, size_t ilen, unsigned char output[16] );
121121

122+
#if defined(MBEDTLS_SELF_TEST)
123+
122124
/**
123125
* \brief Checkup routine
124126
*
125127
* \return 0 if successful, or 1 if the test failed
126128
*/
127129
int mbedtls_md2_self_test( int verbose );
128130

131+
#endif /*MBEDTLS_SELF_TEST*/
132+
129133
/* Internal use */
130134
void mbedtls_md2_process( mbedtls_md2_context *ctx );
131135

include/mbedtls/md4.h

+4
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,17 @@ extern "C" {
119119
*/
120120
void mbedtls_md4( const unsigned char *input, size_t ilen, unsigned char output[16] );
121121

122+
#if defined(MBEDTLS_SELF_TEST)
123+
122124
/**
123125
* \brief Checkup routine
124126
*
125127
* \return 0 if successful, or 1 if the test failed
126128
*/
127129
int mbedtls_md4_self_test( int verbose );
128130

131+
#endif /*MBEDTLS_SELF_TEST*/
132+
129133
/* Internal use */
130134
void mbedtls_md4_process( mbedtls_md4_context *ctx, const unsigned char data[64] );
131135

include/mbedtls/md5.h

+4
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,17 @@ extern "C" {
122122
*/
123123
void mbedtls_md5( const unsigned char *input, size_t ilen, unsigned char output[16] );
124124

125+
#if defined(MBEDTLS_SELF_TEST)
126+
125127
/**
126128
* \brief Checkup routine
127129
*
128130
* \return 0 if successful, or 1 if the test failed
129131
*/
130132
int mbedtls_md5_self_test( int verbose );
131133

134+
#endif /*MBEDTLS_SELF_TEST*/
135+
132136
#ifdef __cplusplus
133137
}
134138
#endif

include/mbedtls/pkcs5.h

+4
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,17 @@ int mbedtls_pkcs5_pbkdf2_hmac( mbedtls_md_context_t *ctx, const unsigned char *p
8080
unsigned int iteration_count,
8181
uint32_t key_length, unsigned char *output );
8282

83+
#if defined(MBEDTLS_SELF_TEST)
84+
8385
/**
8486
* \brief Checkup routine
8587
*
8688
* \return 0 if successful, or 1 if the test failed
8789
*/
8890
int mbedtls_pkcs5_self_test( int verbose );
8991

92+
#endif /*MBEDTLS_SELF_TEST*/
93+
9094
#ifdef __cplusplus
9195
}
9296
#endif

include/mbedtls/ripemd160.h

+4
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,17 @@ extern "C" {
124124
void mbedtls_ripemd160( const unsigned char *input, size_t ilen,
125125
unsigned char output[20] );
126126

127+
#if defined(MBEDTLS_SELF_TEST)
128+
127129
/**
128130
* \brief Checkup routine
129131
*
130132
* \return 0 if successful, or 1 if the test failed
131133
*/
132134
int mbedtls_ripemd160_self_test( int verbose );
133135

136+
#endif /*MBEDTLS_SELF_TEST*/
137+
134138
#ifdef __cplusplus
135139
}
136140
#endif

include/mbedtls/rsa.h

+4
Original file line numberDiff line numberDiff line change
@@ -636,13 +636,17 @@ int mbedtls_rsa_copy( mbedtls_rsa_context *dst, const mbedtls_rsa_context *src )
636636
*/
637637
void mbedtls_rsa_free( mbedtls_rsa_context *ctx );
638638

639+
#if defined(MBEDTLS_SELF_TEST)
640+
639641
/**
640642
* \brief Checkup routine
641643
*
642644
* \return 0 if successful, or 1 if the test failed
643645
*/
644646
int mbedtls_rsa_self_test( int verbose );
645647

648+
#endif /*MBEDTLS_SELF_TEST*/
649+
646650
#ifdef __cplusplus
647651
}
648652
#endif

include/mbedtls/sha1.h

+4
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,17 @@ extern "C" {
122122
*/
123123
void mbedtls_sha1( const unsigned char *input, size_t ilen, unsigned char output[20] );
124124

125+
#if defined(MBEDTLS_SELF_TEST)
126+
125127
/**
126128
* \brief Checkup routine
127129
*
128130
* \return 0 if successful, or 1 if the test failed
129131
*/
130132
int mbedtls_sha1_self_test( int verbose );
131133

134+
#endif /*MBEDTLS_SELF_TEST*/
135+
132136
#ifdef __cplusplus
133137
}
134138
#endif

include/mbedtls/sha256.h

+4
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,17 @@ extern "C" {
127127
void mbedtls_sha256( const unsigned char *input, size_t ilen,
128128
unsigned char output[32], int is224 );
129129

130+
#if defined(MBEDTLS_SELF_TEST)
131+
130132
/**
131133
* \brief Checkup routine
132134
*
133135
* \return 0 if successful, or 1 if the test failed
134136
*/
135137
int mbedtls_sha256_self_test( int verbose );
136138

139+
#endif /*MBEDTLS_SELF_TEST*/
140+
137141
#ifdef __cplusplus
138142
}
139143
#endif

include/mbedtls/sha512.h

+4
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,17 @@ extern "C" {
124124
void mbedtls_sha512( const unsigned char *input, size_t ilen,
125125
unsigned char output[64], int is384 );
126126

127+
#if defined(MBEDTLS_SELF_TEST)
128+
127129
/**
128130
* \brief Checkup routine
129131
*
130132
* \return 0 if successful, or 1 if the test failed
131133
*/
132134
int mbedtls_sha512_self_test( int verbose );
133135

136+
#endif /*MBEDTLS_SELF_TEST*/
137+
134138
/* Internal use */
135139
void mbedtls_sha512_process( mbedtls_sha512_context *ctx, const unsigned char data[128] );
136140

include/mbedtls/x509.h

+4
Original file line numberDiff line numberDiff line change
@@ -267,13 +267,17 @@ int mbedtls_x509_time_is_past( const mbedtls_x509_time *time );
267267
*/
268268
int mbedtls_x509_time_is_future( const mbedtls_x509_time *time );
269269

270+
#if defined(MBEDTLS_SELF_TEST)
271+
270272
/**
271273
* \brief Checkup routine
272274
*
273275
* \return 0 if successful, or 1 if the test failed
274276
*/
275277
int mbedtls_x509_self_test( int verbose );
276278

279+
#endif /*MBEDTLS_SELF_TEST*/
280+
277281
/*
278282
* Internal module functions. You probably do not want to use these unless you
279283
* know you do.

include/mbedtls/xtea.h

+4
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,17 @@ int mbedtls_xtea_crypt_cbc( mbedtls_xtea_context *ctx,
125125
extern "C" {
126126
#endif
127127

128+
#if defined(MBEDTLS_SELF_TEST)
129+
128130
/**
129131
* \brief Checkup routine
130132
*
131133
* \return 0 if successful, or 1 if the test failed
132134
*/
133135
int mbedtls_xtea_self_test( int verbose );
134136

137+
#endif /*MBEDTLS_SELF_TEST*/
138+
135139
#ifdef __cplusplus
136140
}
137141
#endif

0 commit comments

Comments
 (0)