Skip to content

Commit fa8f635

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 c4bd8ec commit fa8f635

21 files changed

+83
-0
lines changed

ChangeLog

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ API Changes
1313
Therefore, mbedtls_platform_zeroize() is moved to the platform module to
1414
facilitate testing and maintenance.
1515

16+
Bugfix
17+
* Add `MBEDTLS_SELF_TEST` for the mbedtls_self_test functions
18+
in the header files, which missed the precompilation check. #971
19+
1620
= mbed TLS 2.9.0 branch released 2018-04-30
1721

1822
Security

include/mbedtls/aes.h

+4
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,8 @@ MBEDTLS_DEPRECATED void mbedtls_aes_decrypt( mbedtls_aes_context *ctx,
400400
#undef MBEDTLS_DEPRECATED
401401
#endif /* !MBEDTLS_DEPRECATED_REMOVED */
402402

403+
404+
#if defined(MBEDTLS_SELF_TEST)
403405
/**
404406
* \brief Checkup routine.
405407
*
@@ -408,6 +410,8 @@ MBEDTLS_DEPRECATED void mbedtls_aes_decrypt( mbedtls_aes_context *ctx,
408410
*/
409411
int mbedtls_aes_self_test( int verbose );
410412

413+
#endif /* MBEDTLS_SELF_TEST */
414+
411415
#ifdef __cplusplus
412416
}
413417
#endif

include/mbedtls/arc4.h

+4
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ void mbedtls_arc4_setup( mbedtls_arc4_context *ctx, const unsigned char *key,
122122
int mbedtls_arc4_crypt( mbedtls_arc4_context *ctx, size_t length, const unsigned char *input,
123123
unsigned char *output );
124124

125+
#if defined(MBEDTLS_SELF_TEST)
126+
125127
/**
126128
* \brief Checkup routine
127129
*
@@ -134,6 +136,8 @@ int mbedtls_arc4_crypt( mbedtls_arc4_context *ctx, size_t length, const unsigned
134136
*/
135137
int mbedtls_arc4_self_test( int verbose );
136138

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

include/mbedtls/base64.h

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

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

86+
#endif /* MBEDTLS_SELF_TEST */
87+
8588
#ifdef __cplusplus
8689
}
8790
#endif

include/mbedtls/bignum.h

+4
Original file line numberDiff line numberDiff line change
@@ -758,13 +758,17 @@ int mbedtls_mpi_gen_prime( mbedtls_mpi *X, size_t nbits, int dh_flag,
758758
int (*f_rng)(void *, unsigned char *, size_t),
759759
void *p_rng );
760760

761+
#if defined(MBEDTLS_SELF_TEST)
762+
761763
/**
762764
* \brief Checkup routine
763765
*
764766
* \return 0 if successful, or 1 if the test failed
765767
*/
766768
int mbedtls_mpi_self_test( int verbose );
767769

770+
#endif /* MBEDTLS_SELF_TEST */
771+
768772
#ifdef __cplusplus
769773
}
770774
#endif

include/mbedtls/camellia.h

+4
Original file line numberDiff line numberDiff line change
@@ -215,13 +215,17 @@ int mbedtls_camellia_crypt_ctr( mbedtls_camellia_context *ctx,
215215
unsigned char *output );
216216
#endif /* MBEDTLS_CIPHER_MODE_CTR */
217217

218+
#if defined(MBEDTLS_SELF_TEST)
219+
218220
/**
219221
* \brief Checkup routine
220222
*
221223
* \return 0 if successful, or 1 if the test failed
222224
*/
223225
int mbedtls_camellia_self_test( int verbose );
224226

227+
#endif /* MBEDTLS_SELF_TEST */
228+
225229
#ifdef __cplusplus
226230
}
227231
#endif

include/mbedtls/ctr_drbg.h

+4
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,8 @@ int mbedtls_ctr_drbg_write_seed_file( mbedtls_ctr_drbg_context *ctx, const char
310310
int mbedtls_ctr_drbg_update_seed_file( mbedtls_ctr_drbg_context *ctx, const char *path );
311311
#endif /* MBEDTLS_FS_IO */
312312

313+
#if defined(MBEDTLS_SELF_TEST)
314+
313315
/**
314316
* \brief The CTR_DRBG checkup routine.
315317
*
@@ -318,6 +320,8 @@ int mbedtls_ctr_drbg_update_seed_file( mbedtls_ctr_drbg_context *ctx, const char
318320
*/
319321
int mbedtls_ctr_drbg_self_test( int verbose );
320322

323+
#endif /* MBEDTLS_SELF_TEST */
324+
321325
/* Internal functions (do not call directly) */
322326
int mbedtls_ctr_drbg_seed_entropy_len( mbedtls_ctr_drbg_context *,
323327
int (*)(void *, unsigned char *, size_t), void *,

include/mbedtls/des.h

+4
Original file line numberDiff line numberDiff line change
@@ -336,13 +336,17 @@ int mbedtls_des3_crypt_cbc( mbedtls_des3_context *ctx,
336336
void mbedtls_des_setkey( uint32_t SK[32],
337337
const unsigned char key[MBEDTLS_DES_KEY_SIZE] );
338338

339+
#if defined(MBEDTLS_SELF_TEST)
340+
339341
/**
340342
* \brief Checkup routine
341343
*
342344
* \return 0 if successful, or 1 if the test failed
343345
*/
344346
int mbedtls_des_self_test( int verbose );
345347

348+
#endif /* MBEDTLS_SELF_TEST */
349+
346350
#ifdef __cplusplus
347351
}
348352
#endif

include/mbedtls/dhm.h

+3
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,8 @@ int mbedtls_dhm_parse_dhmfile( mbedtls_dhm_context *dhm, const char *path );
295295
#endif /* MBEDTLS_FS_IO */
296296
#endif /* MBEDTLS_ASN1_PARSE_C */
297297

298+
#if defined(MBEDTLS_SELF_TEST)
299+
298300
/**
299301
* \brief The DMH checkup routine.
300302
*
@@ -303,6 +305,7 @@ int mbedtls_dhm_parse_dhmfile( mbedtls_dhm_context *dhm, const char *path );
303305
*/
304306
int mbedtls_dhm_self_test( int verbose );
305307

308+
#endif /* MBEDTLS_SELF_TEST */
306309
#ifdef __cplusplus
307310
}
308311
#endif

include/mbedtls/gcm.h

+4
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,8 @@ int mbedtls_gcm_finish( mbedtls_gcm_context *ctx,
250250
*/
251251
void mbedtls_gcm_free( mbedtls_gcm_context *ctx );
252252

253+
#if defined(MBEDTLS_SELF_TEST)
254+
253255
/**
254256
* \brief The GCM checkup routine.
255257
*
@@ -258,6 +260,8 @@ void mbedtls_gcm_free( mbedtls_gcm_context *ctx );
258260
*/
259261
int mbedtls_gcm_self_test( int verbose );
260262

263+
#endif /* MBEDTLS_SELF_TEST */
264+
261265
#ifdef __cplusplus
262266
}
263267
#endif

include/mbedtls/md2.h

+4
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,8 @@ MBEDTLS_DEPRECATED void mbedtls_md2( const unsigned char *input,
282282
#undef MBEDTLS_DEPRECATED
283283
#endif /* !MBEDTLS_DEPRECATED_REMOVED */
284284

285+
#if defined(MBEDTLS_SELF_TEST)
286+
285287
/**
286288
* \brief Checkup routine
287289
*
@@ -294,6 +296,8 @@ MBEDTLS_DEPRECATED void mbedtls_md2( const unsigned char *input,
294296
*/
295297
int mbedtls_md2_self_test( int verbose );
296298

299+
#endif /* MBEDTLS_SELF_TEST */
300+
297301
#ifdef __cplusplus
298302
}
299303
#endif

include/mbedtls/md4.h

+4
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,8 @@ MBEDTLS_DEPRECATED void mbedtls_md4( const unsigned char *input,
287287
#undef MBEDTLS_DEPRECATED
288288
#endif /* !MBEDTLS_DEPRECATED_REMOVED */
289289

290+
#if defined(MBEDTLS_SELF_TEST)
291+
290292
/**
291293
* \brief Checkup routine
292294
*
@@ -299,6 +301,8 @@ MBEDTLS_DEPRECATED void mbedtls_md4( const unsigned char *input,
299301
*/
300302
int mbedtls_md4_self_test( int verbose );
301303

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

include/mbedtls/md5.h

+4
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,8 @@ MBEDTLS_DEPRECATED void mbedtls_md5( const unsigned char *input,
287287
#undef MBEDTLS_DEPRECATED
288288
#endif /* !MBEDTLS_DEPRECATED_REMOVED */
289289

290+
#if defined(MBEDTLS_SELF_TEST)
291+
290292
/**
291293
* \brief Checkup routine
292294
*
@@ -299,6 +301,8 @@ MBEDTLS_DEPRECATED void mbedtls_md5( const unsigned char *input,
299301
*/
300302
int mbedtls_md5_self_test( int verbose );
301303

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

include/mbedtls/pkcs5.h

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

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

93+
#endif /* MBEDTLS_SELF_TEST */
94+
9195
#ifdef __cplusplus
9296
}
9397
#endif

include/mbedtls/ripemd160.h

+4
Original file line numberDiff line numberDiff line change
@@ -217,13 +217,17 @@ MBEDTLS_DEPRECATED void mbedtls_ripemd160( const unsigned char *input,
217217
#undef MBEDTLS_DEPRECATED
218218
#endif /* !MBEDTLS_DEPRECATED_REMOVED */
219219

220+
#if defined(MBEDTLS_SELF_TEST)
221+
220222
/**
221223
* \brief Checkup routine
222224
*
223225
* \return 0 if successful, or 1 if the test failed
224226
*/
225227
int mbedtls_ripemd160_self_test( int verbose );
226228

229+
#endif /* MBEDTLS_SELF_TEST */
230+
227231
#ifdef __cplusplus
228232
}
229233
#endif

include/mbedtls/rsa.h

+4
Original file line numberDiff line numberDiff line change
@@ -1116,6 +1116,8 @@ int mbedtls_rsa_copy( mbedtls_rsa_context *dst, const mbedtls_rsa_context *src )
11161116
*/
11171117
void mbedtls_rsa_free( mbedtls_rsa_context *ctx );
11181118

1119+
#if defined(MBEDTLS_SELF_TEST)
1120+
11191121
/**
11201122
* \brief The RSA checkup routine.
11211123
*
@@ -1124,6 +1126,8 @@ void mbedtls_rsa_free( mbedtls_rsa_context *ctx );
11241126
*/
11251127
int mbedtls_rsa_self_test( int verbose );
11261128

1129+
#endif /* MBEDTLS_SELF_TEST */
1130+
11271131
#ifdef __cplusplus
11281132
}
11291133
#endif

include/mbedtls/sha1.h

+4
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,8 @@ MBEDTLS_DEPRECATED void mbedtls_sha1( const unsigned char *input,
304304
#undef MBEDTLS_DEPRECATED
305305
#endif /* !MBEDTLS_DEPRECATED_REMOVED */
306306

307+
#if defined(MBEDTLS_SELF_TEST)
308+
307309
/**
308310
* \brief The SHA-1 checkup routine.
309311
*
@@ -317,6 +319,8 @@ MBEDTLS_DEPRECATED void mbedtls_sha1( const unsigned char *input,
317319
*/
318320
int mbedtls_sha1_self_test( int verbose );
319321

322+
#endif /* MBEDTLS_SELF_TEST */
323+
320324
#ifdef __cplusplus
321325
}
322326
#endif

include/mbedtls/sha256.h

+4
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,8 @@ MBEDTLS_DEPRECATED void mbedtls_sha256( const unsigned char *input,
257257
#undef MBEDTLS_DEPRECATED
258258
#endif /* !MBEDTLS_DEPRECATED_REMOVED */
259259

260+
#if defined(MBEDTLS_SELF_TEST)
261+
260262
/**
261263
* \brief The SHA-224 and SHA-256 checkup routine.
262264
*
@@ -265,6 +267,8 @@ MBEDTLS_DEPRECATED void mbedtls_sha256( const unsigned char *input,
265267
*/
266268
int mbedtls_sha256_self_test( int verbose );
267269

270+
#endif /* MBEDTLS_SELF_TEST */
271+
268272
#ifdef __cplusplus
269273
}
270274
#endif

include/mbedtls/sha512.h

+5
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ int mbedtls_sha512_ret( const unsigned char *input,
230230
#else
231231
#define MBEDTLS_DEPRECATED
232232
#endif
233+
233234
/**
234235
* \brief This function calculates the SHA-512 or SHA-384
235236
* checksum of a buffer.
@@ -255,13 +256,17 @@ MBEDTLS_DEPRECATED void mbedtls_sha512( const unsigned char *input,
255256

256257
#undef MBEDTLS_DEPRECATED
257258
#endif /* !MBEDTLS_DEPRECATED_REMOVED */
259+
260+
#if defined(MBEDTLS_SELF_TEST)
261+
258262
/**
259263
* \brief The SHA-384 or SHA-512 checkup routine.
260264
*
261265
* \return \c 0 on success.
262266
* \return \c 1 on failure.
263267
*/
264268
int mbedtls_sha512_self_test( int verbose );
269+
#endif /* MBEDTLS_SELF_TEST */
265270

266271
#ifdef __cplusplus
267272
}

include/mbedtls/x509.h

+4
Original file line numberDiff line numberDiff line change
@@ -269,13 +269,17 @@ int mbedtls_x509_time_is_past( const mbedtls_x509_time *to );
269269
*/
270270
int mbedtls_x509_time_is_future( const mbedtls_x509_time *from );
271271

272+
#if defined(MBEDTLS_SELF_TEST)
273+
272274
/**
273275
* \brief Checkup routine
274276
*
275277
* \return 0 if successful, or 1 if the test failed
276278
*/
277279
int mbedtls_x509_self_test( int verbose );
278280

281+
#endif /* MBEDTLS_SELF_TEST */
282+
279283
/*
280284
* Internal module functions. You probably do not want to use these unless you
281285
* know you do.

include/mbedtls/xtea.h

+4
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,17 @@ int mbedtls_xtea_crypt_cbc( mbedtls_xtea_context *ctx,
119119
unsigned char *output);
120120
#endif /* MBEDTLS_CIPHER_MODE_CBC */
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_xtea_self_test( int verbose );
128130

131+
#endif /* MBEDTLS_SELF_TEST */
132+
129133
#ifdef __cplusplus
130134
}
131135
#endif

0 commit comments

Comments
 (0)