sha1.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  1. /*
  2. * FIPS-180-1 compliant SHA-1 implementation
  3. *
  4. * Copyright The Mbed TLS Contributors
  5. * SPDX-License-Identifier: Apache-2.0
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  8. * not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. */
  19. /*
  20. * The SHA-1 standard was published by NIST in 1993.
  21. *
  22. * http://www.itl.nist.gov/fipspubs/fip180-1.htm
  23. */
  24. #include "common.h"
  25. #if defined(MBEDTLS_SHA1_C)
  26. #include "mbedtls/sha1.h"
  27. #include "mbedtls/platform_util.h"
  28. #include "mbedtls/error.h"
  29. #include <string.h>
  30. #if defined(MBEDTLS_SELF_TEST)
  31. #if defined(MBEDTLS_PLATFORM_C)
  32. #include "mbedtls/platform.h"
  33. #else
  34. #include <stdio.h>
  35. #define mbedtls_printf printf
  36. #endif /* MBEDTLS_PLATFORM_C */
  37. #endif /* MBEDTLS_SELF_TEST */
  38. #define SHA1_VALIDATE_RET(cond) \
  39. MBEDTLS_INTERNAL_VALIDATE_RET( cond, MBEDTLS_ERR_SHA1_BAD_INPUT_DATA )
  40. #define SHA1_VALIDATE(cond) MBEDTLS_INTERNAL_VALIDATE( cond )
  41. #if !defined(MBEDTLS_SHA1_ALT)
  42. /*
  43. * 32-bit integer manipulation macros (big endian)
  44. */
  45. #ifndef GET_UINT32_BE
  46. #define GET_UINT32_BE(n,b,i) \
  47. { \
  48. (n) = ( (uint32_t) (b)[(i) ] << 24 ) \
  49. | ( (uint32_t) (b)[(i) + 1] << 16 ) \
  50. | ( (uint32_t) (b)[(i) + 2] << 8 ) \
  51. | ( (uint32_t) (b)[(i) + 3] ); \
  52. }
  53. #endif
  54. #ifndef PUT_UINT32_BE
  55. #define PUT_UINT32_BE(n,b,i) \
  56. { \
  57. (b)[(i) ] = (unsigned char) ( (n) >> 24 ); \
  58. (b)[(i) + 1] = (unsigned char) ( (n) >> 16 ); \
  59. (b)[(i) + 2] = (unsigned char) ( (n) >> 8 ); \
  60. (b)[(i) + 3] = (unsigned char) ( (n) ); \
  61. }
  62. #endif
  63. void mbedtls_sha1_init( mbedtls_sha1_context *ctx )
  64. {
  65. SHA1_VALIDATE( ctx != NULL );
  66. memset( ctx, 0, sizeof( mbedtls_sha1_context ) );
  67. }
  68. void mbedtls_sha1_free( mbedtls_sha1_context *ctx )
  69. {
  70. if( ctx == NULL )
  71. return;
  72. mbedtls_platform_zeroize( ctx, sizeof( mbedtls_sha1_context ) );
  73. }
  74. void mbedtls_sha1_clone( mbedtls_sha1_context *dst,
  75. const mbedtls_sha1_context *src )
  76. {
  77. SHA1_VALIDATE( dst != NULL );
  78. SHA1_VALIDATE( src != NULL );
  79. *dst = *src;
  80. }
  81. /*
  82. * SHA-1 context setup
  83. */
  84. int mbedtls_sha1_starts_ret( mbedtls_sha1_context *ctx )
  85. {
  86. SHA1_VALIDATE_RET( ctx != NULL );
  87. ctx->total[0] = 0;
  88. ctx->total[1] = 0;
  89. ctx->state[0] = 0x67452301;
  90. ctx->state[1] = 0xEFCDAB89;
  91. ctx->state[2] = 0x98BADCFE;
  92. ctx->state[3] = 0x10325476;
  93. ctx->state[4] = 0xC3D2E1F0;
  94. return( 0 );
  95. }
  96. #if !defined(MBEDTLS_DEPRECATED_REMOVED)
  97. void mbedtls_sha1_starts( mbedtls_sha1_context *ctx )
  98. {
  99. mbedtls_sha1_starts_ret( ctx );
  100. }
  101. #endif
  102. #if !defined(MBEDTLS_SHA1_PROCESS_ALT)
  103. int mbedtls_internal_sha1_process( mbedtls_sha1_context *ctx,
  104. const unsigned char data[64] )
  105. {
  106. struct
  107. {
  108. uint32_t temp, W[16], A, B, C, D, E;
  109. } local;
  110. SHA1_VALIDATE_RET( ctx != NULL );
  111. SHA1_VALIDATE_RET( (const unsigned char *)data != NULL );
  112. GET_UINT32_BE( local.W[ 0], data, 0 );
  113. GET_UINT32_BE( local.W[ 1], data, 4 );
  114. GET_UINT32_BE( local.W[ 2], data, 8 );
  115. GET_UINT32_BE( local.W[ 3], data, 12 );
  116. GET_UINT32_BE( local.W[ 4], data, 16 );
  117. GET_UINT32_BE( local.W[ 5], data, 20 );
  118. GET_UINT32_BE( local.W[ 6], data, 24 );
  119. GET_UINT32_BE( local.W[ 7], data, 28 );
  120. GET_UINT32_BE( local.W[ 8], data, 32 );
  121. GET_UINT32_BE( local.W[ 9], data, 36 );
  122. GET_UINT32_BE( local.W[10], data, 40 );
  123. GET_UINT32_BE( local.W[11], data, 44 );
  124. GET_UINT32_BE( local.W[12], data, 48 );
  125. GET_UINT32_BE( local.W[13], data, 52 );
  126. GET_UINT32_BE( local.W[14], data, 56 );
  127. GET_UINT32_BE( local.W[15], data, 60 );
  128. #define S(x,n) (((x) << (n)) | (((x) & 0xFFFFFFFF) >> (32 - (n))))
  129. #define R(t) \
  130. ( \
  131. local.temp = local.W[( (t) - 3 ) & 0x0F] ^ \
  132. local.W[( (t) - 8 ) & 0x0F] ^ \
  133. local.W[( (t) - 14 ) & 0x0F] ^ \
  134. local.W[ (t) & 0x0F], \
  135. ( local.W[(t) & 0x0F] = S(local.temp,1) ) \
  136. )
  137. #define P(a,b,c,d,e,x) \
  138. do \
  139. { \
  140. (e) += S((a),5) + F((b),(c),(d)) + K + (x); \
  141. (b) = S((b),30); \
  142. } while( 0 )
  143. local.A = ctx->state[0];
  144. local.B = ctx->state[1];
  145. local.C = ctx->state[2];
  146. local.D = ctx->state[3];
  147. local.E = ctx->state[4];
  148. #define F(x,y,z) ((z) ^ ((x) & ((y) ^ (z))))
  149. #define K 0x5A827999
  150. P( local.A, local.B, local.C, local.D, local.E, local.W[0] );
  151. P( local.E, local.A, local.B, local.C, local.D, local.W[1] );
  152. P( local.D, local.E, local.A, local.B, local.C, local.W[2] );
  153. P( local.C, local.D, local.E, local.A, local.B, local.W[3] );
  154. P( local.B, local.C, local.D, local.E, local.A, local.W[4] );
  155. P( local.A, local.B, local.C, local.D, local.E, local.W[5] );
  156. P( local.E, local.A, local.B, local.C, local.D, local.W[6] );
  157. P( local.D, local.E, local.A, local.B, local.C, local.W[7] );
  158. P( local.C, local.D, local.E, local.A, local.B, local.W[8] );
  159. P( local.B, local.C, local.D, local.E, local.A, local.W[9] );
  160. P( local.A, local.B, local.C, local.D, local.E, local.W[10] );
  161. P( local.E, local.A, local.B, local.C, local.D, local.W[11] );
  162. P( local.D, local.E, local.A, local.B, local.C, local.W[12] );
  163. P( local.C, local.D, local.E, local.A, local.B, local.W[13] );
  164. P( local.B, local.C, local.D, local.E, local.A, local.W[14] );
  165. P( local.A, local.B, local.C, local.D, local.E, local.W[15] );
  166. P( local.E, local.A, local.B, local.C, local.D, R(16) );
  167. P( local.D, local.E, local.A, local.B, local.C, R(17) );
  168. P( local.C, local.D, local.E, local.A, local.B, R(18) );
  169. P( local.B, local.C, local.D, local.E, local.A, R(19) );
  170. #undef K
  171. #undef F
  172. #define F(x,y,z) ((x) ^ (y) ^ (z))
  173. #define K 0x6ED9EBA1
  174. P( local.A, local.B, local.C, local.D, local.E, R(20) );
  175. P( local.E, local.A, local.B, local.C, local.D, R(21) );
  176. P( local.D, local.E, local.A, local.B, local.C, R(22) );
  177. P( local.C, local.D, local.E, local.A, local.B, R(23) );
  178. P( local.B, local.C, local.D, local.E, local.A, R(24) );
  179. P( local.A, local.B, local.C, local.D, local.E, R(25) );
  180. P( local.E, local.A, local.B, local.C, local.D, R(26) );
  181. P( local.D, local.E, local.A, local.B, local.C, R(27) );
  182. P( local.C, local.D, local.E, local.A, local.B, R(28) );
  183. P( local.B, local.C, local.D, local.E, local.A, R(29) );
  184. P( local.A, local.B, local.C, local.D, local.E, R(30) );
  185. P( local.E, local.A, local.B, local.C, local.D, R(31) );
  186. P( local.D, local.E, local.A, local.B, local.C, R(32) );
  187. P( local.C, local.D, local.E, local.A, local.B, R(33) );
  188. P( local.B, local.C, local.D, local.E, local.A, R(34) );
  189. P( local.A, local.B, local.C, local.D, local.E, R(35) );
  190. P( local.E, local.A, local.B, local.C, local.D, R(36) );
  191. P( local.D, local.E, local.A, local.B, local.C, R(37) );
  192. P( local.C, local.D, local.E, local.A, local.B, R(38) );
  193. P( local.B, local.C, local.D, local.E, local.A, R(39) );
  194. #undef K
  195. #undef F
  196. #define F(x,y,z) (((x) & (y)) | ((z) & ((x) | (y))))
  197. #define K 0x8F1BBCDC
  198. P( local.A, local.B, local.C, local.D, local.E, R(40) );
  199. P( local.E, local.A, local.B, local.C, local.D, R(41) );
  200. P( local.D, local.E, local.A, local.B, local.C, R(42) );
  201. P( local.C, local.D, local.E, local.A, local.B, R(43) );
  202. P( local.B, local.C, local.D, local.E, local.A, R(44) );
  203. P( local.A, local.B, local.C, local.D, local.E, R(45) );
  204. P( local.E, local.A, local.B, local.C, local.D, R(46) );
  205. P( local.D, local.E, local.A, local.B, local.C, R(47) );
  206. P( local.C, local.D, local.E, local.A, local.B, R(48) );
  207. P( local.B, local.C, local.D, local.E, local.A, R(49) );
  208. P( local.A, local.B, local.C, local.D, local.E, R(50) );
  209. P( local.E, local.A, local.B, local.C, local.D, R(51) );
  210. P( local.D, local.E, local.A, local.B, local.C, R(52) );
  211. P( local.C, local.D, local.E, local.A, local.B, R(53) );
  212. P( local.B, local.C, local.D, local.E, local.A, R(54) );
  213. P( local.A, local.B, local.C, local.D, local.E, R(55) );
  214. P( local.E, local.A, local.B, local.C, local.D, R(56) );
  215. P( local.D, local.E, local.A, local.B, local.C, R(57) );
  216. P( local.C, local.D, local.E, local.A, local.B, R(58) );
  217. P( local.B, local.C, local.D, local.E, local.A, R(59) );
  218. #undef K
  219. #undef F
  220. #define F(x,y,z) ((x) ^ (y) ^ (z))
  221. #define K 0xCA62C1D6
  222. P( local.A, local.B, local.C, local.D, local.E, R(60) );
  223. P( local.E, local.A, local.B, local.C, local.D, R(61) );
  224. P( local.D, local.E, local.A, local.B, local.C, R(62) );
  225. P( local.C, local.D, local.E, local.A, local.B, R(63) );
  226. P( local.B, local.C, local.D, local.E, local.A, R(64) );
  227. P( local.A, local.B, local.C, local.D, local.E, R(65) );
  228. P( local.E, local.A, local.B, local.C, local.D, R(66) );
  229. P( local.D, local.E, local.A, local.B, local.C, R(67) );
  230. P( local.C, local.D, local.E, local.A, local.B, R(68) );
  231. P( local.B, local.C, local.D, local.E, local.A, R(69) );
  232. P( local.A, local.B, local.C, local.D, local.E, R(70) );
  233. P( local.E, local.A, local.B, local.C, local.D, R(71) );
  234. P( local.D, local.E, local.A, local.B, local.C, R(72) );
  235. P( local.C, local.D, local.E, local.A, local.B, R(73) );
  236. P( local.B, local.C, local.D, local.E, local.A, R(74) );
  237. P( local.A, local.B, local.C, local.D, local.E, R(75) );
  238. P( local.E, local.A, local.B, local.C, local.D, R(76) );
  239. P( local.D, local.E, local.A, local.B, local.C, R(77) );
  240. P( local.C, local.D, local.E, local.A, local.B, R(78) );
  241. P( local.B, local.C, local.D, local.E, local.A, R(79) );
  242. #undef K
  243. #undef F
  244. ctx->state[0] += local.A;
  245. ctx->state[1] += local.B;
  246. ctx->state[2] += local.C;
  247. ctx->state[3] += local.D;
  248. ctx->state[4] += local.E;
  249. /* Zeroise buffers and variables to clear sensitive data from memory. */
  250. mbedtls_platform_zeroize( &local, sizeof( local ) );
  251. return( 0 );
  252. }
  253. #if !defined(MBEDTLS_DEPRECATED_REMOVED)
  254. void mbedtls_sha1_process( mbedtls_sha1_context *ctx,
  255. const unsigned char data[64] )
  256. {
  257. mbedtls_internal_sha1_process( ctx, data );
  258. }
  259. #endif
  260. #endif /* !MBEDTLS_SHA1_PROCESS_ALT */
  261. /*
  262. * SHA-1 process buffer
  263. */
  264. int mbedtls_sha1_update_ret( mbedtls_sha1_context *ctx,
  265. const unsigned char *input,
  266. size_t ilen )
  267. {
  268. int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  269. size_t fill;
  270. uint32_t left;
  271. SHA1_VALIDATE_RET( ctx != NULL );
  272. SHA1_VALIDATE_RET( ilen == 0 || input != NULL );
  273. if( ilen == 0 )
  274. return( 0 );
  275. left = ctx->total[0] & 0x3F;
  276. fill = 64 - left;
  277. ctx->total[0] += (uint32_t) ilen;
  278. ctx->total[0] &= 0xFFFFFFFF;
  279. if( ctx->total[0] < (uint32_t) ilen )
  280. ctx->total[1]++;
  281. if( left && ilen >= fill )
  282. {
  283. memcpy( (void *) (ctx->buffer + left), input, fill );
  284. if( ( ret = mbedtls_internal_sha1_process( ctx, ctx->buffer ) ) != 0 )
  285. return( ret );
  286. input += fill;
  287. ilen -= fill;
  288. left = 0;
  289. }
  290. while( ilen >= 64 )
  291. {
  292. if( ( ret = mbedtls_internal_sha1_process( ctx, input ) ) != 0 )
  293. return( ret );
  294. input += 64;
  295. ilen -= 64;
  296. }
  297. if( ilen > 0 )
  298. memcpy( (void *) (ctx->buffer + left), input, ilen );
  299. return( 0 );
  300. }
  301. #if !defined(MBEDTLS_DEPRECATED_REMOVED)
  302. void mbedtls_sha1_update( mbedtls_sha1_context *ctx,
  303. const unsigned char *input,
  304. size_t ilen )
  305. {
  306. mbedtls_sha1_update_ret( ctx, input, ilen );
  307. }
  308. #endif
  309. /*
  310. * SHA-1 final digest
  311. */
  312. int mbedtls_sha1_finish_ret( mbedtls_sha1_context *ctx,
  313. unsigned char output[20] )
  314. {
  315. int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  316. uint32_t used;
  317. uint32_t high, low;
  318. SHA1_VALIDATE_RET( ctx != NULL );
  319. SHA1_VALIDATE_RET( (unsigned char *)output != NULL );
  320. /*
  321. * Add padding: 0x80 then 0x00 until 8 bytes remain for the length
  322. */
  323. used = ctx->total[0] & 0x3F;
  324. ctx->buffer[used++] = 0x80;
  325. if( used <= 56 )
  326. {
  327. /* Enough room for padding + length in current block */
  328. memset( ctx->buffer + used, 0, 56 - used );
  329. }
  330. else
  331. {
  332. /* We'll need an extra block */
  333. memset( ctx->buffer + used, 0, 64 - used );
  334. if( ( ret = mbedtls_internal_sha1_process( ctx, ctx->buffer ) ) != 0 )
  335. return( ret );
  336. memset( ctx->buffer, 0, 56 );
  337. }
  338. /*
  339. * Add message length
  340. */
  341. high = ( ctx->total[0] >> 29 )
  342. | ( ctx->total[1] << 3 );
  343. low = ( ctx->total[0] << 3 );
  344. PUT_UINT32_BE( high, ctx->buffer, 56 );
  345. PUT_UINT32_BE( low, ctx->buffer, 60 );
  346. if( ( ret = mbedtls_internal_sha1_process( ctx, ctx->buffer ) ) != 0 )
  347. return( ret );
  348. /*
  349. * Output final state
  350. */
  351. PUT_UINT32_BE( ctx->state[0], output, 0 );
  352. PUT_UINT32_BE( ctx->state[1], output, 4 );
  353. PUT_UINT32_BE( ctx->state[2], output, 8 );
  354. PUT_UINT32_BE( ctx->state[3], output, 12 );
  355. PUT_UINT32_BE( ctx->state[4], output, 16 );
  356. return( 0 );
  357. }
  358. #if !defined(MBEDTLS_DEPRECATED_REMOVED)
  359. void mbedtls_sha1_finish( mbedtls_sha1_context *ctx,
  360. unsigned char output[20] )
  361. {
  362. mbedtls_sha1_finish_ret( ctx, output );
  363. }
  364. #endif
  365. #endif /* !MBEDTLS_SHA1_ALT */
  366. /*
  367. * output = SHA-1( input buffer )
  368. */
  369. int mbedtls_sha1_ret( const unsigned char *input,
  370. size_t ilen,
  371. unsigned char output[20] )
  372. {
  373. int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  374. mbedtls_sha1_context ctx;
  375. SHA1_VALIDATE_RET( ilen == 0 || input != NULL );
  376. SHA1_VALIDATE_RET( (unsigned char *)output != NULL );
  377. mbedtls_sha1_init( &ctx );
  378. if( ( ret = mbedtls_sha1_starts_ret( &ctx ) ) != 0 )
  379. goto exit;
  380. if( ( ret = mbedtls_sha1_update_ret( &ctx, input, ilen ) ) != 0 )
  381. goto exit;
  382. if( ( ret = mbedtls_sha1_finish_ret( &ctx, output ) ) != 0 )
  383. goto exit;
  384. exit:
  385. mbedtls_sha1_free( &ctx );
  386. return( ret );
  387. }
  388. #if !defined(MBEDTLS_DEPRECATED_REMOVED)
  389. void mbedtls_sha1( const unsigned char *input,
  390. size_t ilen,
  391. unsigned char output[20] )
  392. {
  393. mbedtls_sha1_ret( input, ilen, output );
  394. }
  395. #endif
  396. #if defined(MBEDTLS_SELF_TEST)
  397. /*
  398. * FIPS-180-1 test vectors
  399. */
  400. static const unsigned char sha1_test_buf[3][57] =
  401. {
  402. { "abc" },
  403. { "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" },
  404. { "" }
  405. };
  406. static const size_t sha1_test_buflen[3] =
  407. {
  408. 3, 56, 1000
  409. };
  410. static const unsigned char sha1_test_sum[3][20] =
  411. {
  412. { 0xA9, 0x99, 0x3E, 0x36, 0x47, 0x06, 0x81, 0x6A, 0xBA, 0x3E,
  413. 0x25, 0x71, 0x78, 0x50, 0xC2, 0x6C, 0x9C, 0xD0, 0xD8, 0x9D },
  414. { 0x84, 0x98, 0x3E, 0x44, 0x1C, 0x3B, 0xD2, 0x6E, 0xBA, 0xAE,
  415. 0x4A, 0xA1, 0xF9, 0x51, 0x29, 0xE5, 0xE5, 0x46, 0x70, 0xF1 },
  416. { 0x34, 0xAA, 0x97, 0x3C, 0xD4, 0xC4, 0xDA, 0xA4, 0xF6, 0x1E,
  417. 0xEB, 0x2B, 0xDB, 0xAD, 0x27, 0x31, 0x65, 0x34, 0x01, 0x6F }
  418. };
  419. /*
  420. * Checkup routine
  421. */
  422. int mbedtls_sha1_self_test( int verbose )
  423. {
  424. int i, j, buflen, ret = 0;
  425. unsigned char buf[1024];
  426. unsigned char sha1sum[20];
  427. mbedtls_sha1_context ctx;
  428. mbedtls_sha1_init( &ctx );
  429. /*
  430. * SHA-1
  431. */
  432. for( i = 0; i < 3; i++ )
  433. {
  434. if( verbose != 0 )
  435. mbedtls_printf( " SHA-1 test #%d: ", i + 1 );
  436. if( ( ret = mbedtls_sha1_starts_ret( &ctx ) ) != 0 )
  437. goto fail;
  438. if( i == 2 )
  439. {
  440. memset( buf, 'a', buflen = 1000 );
  441. for( j = 0; j < 1000; j++ )
  442. {
  443. ret = mbedtls_sha1_update_ret( &ctx, buf, buflen );
  444. if( ret != 0 )
  445. goto fail;
  446. }
  447. }
  448. else
  449. {
  450. ret = mbedtls_sha1_update_ret( &ctx, sha1_test_buf[i],
  451. sha1_test_buflen[i] );
  452. if( ret != 0 )
  453. goto fail;
  454. }
  455. if( ( ret = mbedtls_sha1_finish_ret( &ctx, sha1sum ) ) != 0 )
  456. goto fail;
  457. if( memcmp( sha1sum, sha1_test_sum[i], 20 ) != 0 )
  458. {
  459. ret = 1;
  460. goto fail;
  461. }
  462. if( verbose != 0 )
  463. mbedtls_printf( "passed\n" );
  464. }
  465. if( verbose != 0 )
  466. mbedtls_printf( "\n" );
  467. goto exit;
  468. fail:
  469. if( verbose != 0 )
  470. mbedtls_printf( "failed\n" );
  471. exit:
  472. mbedtls_sha1_free( &ctx );
  473. return( ret );
  474. }
  475. #endif /* MBEDTLS_SELF_TEST */
  476. #endif /* MBEDTLS_SHA1_C */