Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 1 | /* |
| 2 | * FIPS-180-1 compliant SHA-1 implementation |
| 3 | * |
Bence Szépkúti | 1e14827 | 2020-08-07 13:07:28 +0200 | [diff] [blame] | 4 | * Copyright The Mbed TLS Contributors |
Manuel Pégourié-Gonnard | 37ff140 | 2015-09-04 14:21:07 +0200 | [diff] [blame] | 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. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 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 | |
Gilles Peskine | db09ef6 | 2020-06-03 01:43:33 +0200 | [diff] [blame] | 25 | #include "common.h" |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 26 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 27 | #if defined(MBEDTLS_SHA1_C) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 28 | |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 29 | #include "mbedtls/sha1.h" |
Andres Amaya Garcia | 1f6301b | 2018-04-17 09:51:09 -0500 | [diff] [blame] | 30 | #include "mbedtls/platform_util.h" |
Janos Follath | 24eed8d | 2019-11-22 13:21:35 +0000 | [diff] [blame] | 31 | #include "mbedtls/error.h" |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 32 | |
Rich Evans | 00ab470 | 2015-02-06 13:43:58 +0000 | [diff] [blame] | 33 | #include <string.h> |
| 34 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 35 | #if defined(MBEDTLS_SELF_TEST) |
| 36 | #if defined(MBEDTLS_PLATFORM_C) |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 37 | #include "mbedtls/platform.h" |
Paul Bakker | 7dc4c44 | 2014-02-01 22:50:26 +0100 | [diff] [blame] | 38 | #else |
Rich Evans | 00ab470 | 2015-02-06 13:43:58 +0000 | [diff] [blame] | 39 | #include <stdio.h> |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 40 | #define mbedtls_printf printf |
| 41 | #endif /* MBEDTLS_PLATFORM_C */ |
| 42 | #endif /* MBEDTLS_SELF_TEST */ |
Paul Bakker | 7dc4c44 | 2014-02-01 22:50:26 +0100 | [diff] [blame] | 43 | |
Hanno Becker | b3c7023 | 2018-12-20 10:18:05 +0000 | [diff] [blame] | 44 | #define SHA1_VALIDATE_RET(cond) \ |
| 45 | MBEDTLS_INTERNAL_VALIDATE_RET( cond, MBEDTLS_ERR_SHA1_BAD_INPUT_DATA ) |
| 46 | |
| 47 | #define SHA1_VALIDATE(cond) MBEDTLS_INTERNAL_VALIDATE( cond ) |
| 48 | |
Manuel Pégourié-Gonnard | 8b2641d | 2015-08-27 20:03:46 +0200 | [diff] [blame] | 49 | #if !defined(MBEDTLS_SHA1_ALT) |
| 50 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 51 | /* |
| 52 | * 32-bit integer manipulation macros (big endian) |
| 53 | */ |
Paul Bakker | 5c2364c | 2012-10-01 14:41:15 +0000 | [diff] [blame] | 54 | #ifndef GET_UINT32_BE |
| 55 | #define GET_UINT32_BE(n,b,i) \ |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 56 | { \ |
Paul Bakker | 5c2364c | 2012-10-01 14:41:15 +0000 | [diff] [blame] | 57 | (n) = ( (uint32_t) (b)[(i) ] << 24 ) \ |
| 58 | | ( (uint32_t) (b)[(i) + 1] << 16 ) \ |
| 59 | | ( (uint32_t) (b)[(i) + 2] << 8 ) \ |
| 60 | | ( (uint32_t) (b)[(i) + 3] ); \ |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 61 | } |
| 62 | #endif |
| 63 | |
Paul Bakker | 5c2364c | 2012-10-01 14:41:15 +0000 | [diff] [blame] | 64 | #ifndef PUT_UINT32_BE |
| 65 | #define PUT_UINT32_BE(n,b,i) \ |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 66 | { \ |
| 67 | (b)[(i) ] = (unsigned char) ( (n) >> 24 ); \ |
| 68 | (b)[(i) + 1] = (unsigned char) ( (n) >> 16 ); \ |
| 69 | (b)[(i) + 2] = (unsigned char) ( (n) >> 8 ); \ |
| 70 | (b)[(i) + 3] = (unsigned char) ( (n) ); \ |
| 71 | } |
| 72 | #endif |
| 73 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 74 | void mbedtls_sha1_init( mbedtls_sha1_context *ctx ) |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 75 | { |
Hanno Becker | 039ccab | 2018-12-18 17:52:14 +0000 | [diff] [blame] | 76 | SHA1_VALIDATE( ctx != NULL ); |
Andres Amaya Garcia | f7c43b3 | 2018-12-09 19:12:19 +0000 | [diff] [blame] | 77 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 78 | memset( ctx, 0, sizeof( mbedtls_sha1_context ) ); |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 79 | } |
| 80 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 81 | void mbedtls_sha1_free( mbedtls_sha1_context *ctx ) |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 82 | { |
| 83 | if( ctx == NULL ) |
| 84 | return; |
| 85 | |
Andres Amaya Garcia | 1f6301b | 2018-04-17 09:51:09 -0500 | [diff] [blame] | 86 | mbedtls_platform_zeroize( ctx, sizeof( mbedtls_sha1_context ) ); |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 87 | } |
| 88 | |
Manuel Pégourié-Gonnard | 16d412f | 2015-07-06 15:26:26 +0200 | [diff] [blame] | 89 | void mbedtls_sha1_clone( mbedtls_sha1_context *dst, |
| 90 | const mbedtls_sha1_context *src ) |
| 91 | { |
Hanno Becker | 039ccab | 2018-12-18 17:52:14 +0000 | [diff] [blame] | 92 | SHA1_VALIDATE( dst != NULL ); |
| 93 | SHA1_VALIDATE( src != NULL ); |
Andres Amaya Garcia | f7c43b3 | 2018-12-09 19:12:19 +0000 | [diff] [blame] | 94 | |
Manuel Pégourié-Gonnard | 16d412f | 2015-07-06 15:26:26 +0200 | [diff] [blame] | 95 | *dst = *src; |
| 96 | } |
| 97 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 98 | /* |
| 99 | * SHA-1 context setup |
| 100 | */ |
TRodziewicz | 26371e4 | 2021-06-08 16:45:41 +0200 | [diff] [blame] | 101 | int mbedtls_sha1_starts( mbedtls_sha1_context *ctx ) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 102 | { |
Hanno Becker | 039ccab | 2018-12-18 17:52:14 +0000 | [diff] [blame] | 103 | SHA1_VALIDATE_RET( ctx != NULL ); |
Andres Amaya Garcia | f7c43b3 | 2018-12-09 19:12:19 +0000 | [diff] [blame] | 104 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 105 | ctx->total[0] = 0; |
| 106 | ctx->total[1] = 0; |
| 107 | |
| 108 | ctx->state[0] = 0x67452301; |
| 109 | ctx->state[1] = 0xEFCDAB89; |
| 110 | ctx->state[2] = 0x98BADCFE; |
| 111 | ctx->state[3] = 0x10325476; |
| 112 | ctx->state[4] = 0xC3D2E1F0; |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 113 | |
| 114 | return( 0 ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 115 | } |
| 116 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 117 | #if !defined(MBEDTLS_SHA1_PROCESS_ALT) |
Andres Amaya Garcia | cccfe08 | 2017-06-28 10:36:39 +0100 | [diff] [blame] | 118 | int mbedtls_internal_sha1_process( mbedtls_sha1_context *ctx, |
| 119 | const unsigned char data[64] ) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 120 | { |
gabor-mezei-arm | 4cb56f8 | 2020-08-25 19:12:01 +0200 | [diff] [blame] | 121 | struct |
| 122 | { |
| 123 | uint32_t temp, W[16], A, B, C, D, E; |
| 124 | } local; |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 125 | |
Hanno Becker | 039ccab | 2018-12-18 17:52:14 +0000 | [diff] [blame] | 126 | SHA1_VALIDATE_RET( ctx != NULL ); |
| 127 | SHA1_VALIDATE_RET( (const unsigned char *)data != NULL ); |
Andres Amaya Garcia | f7c43b3 | 2018-12-09 19:12:19 +0000 | [diff] [blame] | 128 | |
gabor-mezei-arm | 4cb56f8 | 2020-08-25 19:12:01 +0200 | [diff] [blame] | 129 | GET_UINT32_BE( local.W[ 0], data, 0 ); |
| 130 | GET_UINT32_BE( local.W[ 1], data, 4 ); |
| 131 | GET_UINT32_BE( local.W[ 2], data, 8 ); |
| 132 | GET_UINT32_BE( local.W[ 3], data, 12 ); |
| 133 | GET_UINT32_BE( local.W[ 4], data, 16 ); |
| 134 | GET_UINT32_BE( local.W[ 5], data, 20 ); |
| 135 | GET_UINT32_BE( local.W[ 6], data, 24 ); |
| 136 | GET_UINT32_BE( local.W[ 7], data, 28 ); |
| 137 | GET_UINT32_BE( local.W[ 8], data, 32 ); |
| 138 | GET_UINT32_BE( local.W[ 9], data, 36 ); |
| 139 | GET_UINT32_BE( local.W[10], data, 40 ); |
| 140 | GET_UINT32_BE( local.W[11], data, 44 ); |
| 141 | GET_UINT32_BE( local.W[12], data, 48 ); |
| 142 | GET_UINT32_BE( local.W[13], data, 52 ); |
| 143 | GET_UINT32_BE( local.W[14], data, 56 ); |
| 144 | GET_UINT32_BE( local.W[15], data, 60 ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 145 | |
Hanno Becker | 1eeca41 | 2018-10-15 12:01:35 +0100 | [diff] [blame] | 146 | #define S(x,n) (((x) << (n)) | (((x) & 0xFFFFFFFF) >> (32 - (n)))) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 147 | |
Hanno Becker | 1eeca41 | 2018-10-15 12:01:35 +0100 | [diff] [blame] | 148 | #define R(t) \ |
| 149 | ( \ |
gabor-mezei-arm | 4cb56f8 | 2020-08-25 19:12:01 +0200 | [diff] [blame] | 150 | local.temp = local.W[( (t) - 3 ) & 0x0F] ^ \ |
| 151 | local.W[( (t) - 8 ) & 0x0F] ^ \ |
| 152 | local.W[( (t) - 14 ) & 0x0F] ^ \ |
| 153 | local.W[ (t) & 0x0F], \ |
| 154 | ( local.W[(t) & 0x0F] = S(local.temp,1) ) \ |
Hanno Becker | 1eeca41 | 2018-10-15 12:01:35 +0100 | [diff] [blame] | 155 | ) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 156 | |
Hanno Becker | 1eeca41 | 2018-10-15 12:01:35 +0100 | [diff] [blame] | 157 | #define P(a,b,c,d,e,x) \ |
| 158 | do \ |
| 159 | { \ |
Hanno Becker | 818bac5 | 2018-10-26 09:13:26 +0100 | [diff] [blame] | 160 | (e) += S((a),5) + F((b),(c),(d)) + K + (x); \ |
| 161 | (b) = S((b),30); \ |
Hanno Becker | 1eeca41 | 2018-10-15 12:01:35 +0100 | [diff] [blame] | 162 | } while( 0 ) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 163 | |
gabor-mezei-arm | 4cb56f8 | 2020-08-25 19:12:01 +0200 | [diff] [blame] | 164 | local.A = ctx->state[0]; |
| 165 | local.B = ctx->state[1]; |
| 166 | local.C = ctx->state[2]; |
| 167 | local.D = ctx->state[3]; |
| 168 | local.E = ctx->state[4]; |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 169 | |
Hanno Becker | 1eeca41 | 2018-10-15 12:01:35 +0100 | [diff] [blame] | 170 | #define F(x,y,z) ((z) ^ ((x) & ((y) ^ (z)))) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 171 | #define K 0x5A827999 |
| 172 | |
gabor-mezei-arm | 4cb56f8 | 2020-08-25 19:12:01 +0200 | [diff] [blame] | 173 | P( local.A, local.B, local.C, local.D, local.E, local.W[0] ); |
| 174 | P( local.E, local.A, local.B, local.C, local.D, local.W[1] ); |
| 175 | P( local.D, local.E, local.A, local.B, local.C, local.W[2] ); |
| 176 | P( local.C, local.D, local.E, local.A, local.B, local.W[3] ); |
| 177 | P( local.B, local.C, local.D, local.E, local.A, local.W[4] ); |
| 178 | P( local.A, local.B, local.C, local.D, local.E, local.W[5] ); |
| 179 | P( local.E, local.A, local.B, local.C, local.D, local.W[6] ); |
| 180 | P( local.D, local.E, local.A, local.B, local.C, local.W[7] ); |
| 181 | P( local.C, local.D, local.E, local.A, local.B, local.W[8] ); |
| 182 | P( local.B, local.C, local.D, local.E, local.A, local.W[9] ); |
| 183 | P( local.A, local.B, local.C, local.D, local.E, local.W[10] ); |
| 184 | P( local.E, local.A, local.B, local.C, local.D, local.W[11] ); |
| 185 | P( local.D, local.E, local.A, local.B, local.C, local.W[12] ); |
| 186 | P( local.C, local.D, local.E, local.A, local.B, local.W[13] ); |
| 187 | P( local.B, local.C, local.D, local.E, local.A, local.W[14] ); |
| 188 | P( local.A, local.B, local.C, local.D, local.E, local.W[15] ); |
| 189 | P( local.E, local.A, local.B, local.C, local.D, R(16) ); |
| 190 | P( local.D, local.E, local.A, local.B, local.C, R(17) ); |
| 191 | P( local.C, local.D, local.E, local.A, local.B, R(18) ); |
| 192 | P( local.B, local.C, local.D, local.E, local.A, R(19) ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 193 | |
| 194 | #undef K |
| 195 | #undef F |
| 196 | |
Hanno Becker | 1eeca41 | 2018-10-15 12:01:35 +0100 | [diff] [blame] | 197 | #define F(x,y,z) ((x) ^ (y) ^ (z)) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 198 | #define K 0x6ED9EBA1 |
| 199 | |
gabor-mezei-arm | 4cb56f8 | 2020-08-25 19:12:01 +0200 | [diff] [blame] | 200 | P( local.A, local.B, local.C, local.D, local.E, R(20) ); |
| 201 | P( local.E, local.A, local.B, local.C, local.D, R(21) ); |
| 202 | P( local.D, local.E, local.A, local.B, local.C, R(22) ); |
| 203 | P( local.C, local.D, local.E, local.A, local.B, R(23) ); |
| 204 | P( local.B, local.C, local.D, local.E, local.A, R(24) ); |
| 205 | P( local.A, local.B, local.C, local.D, local.E, R(25) ); |
| 206 | P( local.E, local.A, local.B, local.C, local.D, R(26) ); |
| 207 | P( local.D, local.E, local.A, local.B, local.C, R(27) ); |
| 208 | P( local.C, local.D, local.E, local.A, local.B, R(28) ); |
| 209 | P( local.B, local.C, local.D, local.E, local.A, R(29) ); |
| 210 | P( local.A, local.B, local.C, local.D, local.E, R(30) ); |
| 211 | P( local.E, local.A, local.B, local.C, local.D, R(31) ); |
| 212 | P( local.D, local.E, local.A, local.B, local.C, R(32) ); |
| 213 | P( local.C, local.D, local.E, local.A, local.B, R(33) ); |
| 214 | P( local.B, local.C, local.D, local.E, local.A, R(34) ); |
| 215 | P( local.A, local.B, local.C, local.D, local.E, R(35) ); |
| 216 | P( local.E, local.A, local.B, local.C, local.D, R(36) ); |
| 217 | P( local.D, local.E, local.A, local.B, local.C, R(37) ); |
| 218 | P( local.C, local.D, local.E, local.A, local.B, R(38) ); |
| 219 | P( local.B, local.C, local.D, local.E, local.A, R(39) ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 220 | |
| 221 | #undef K |
| 222 | #undef F |
| 223 | |
Hanno Becker | 1eeca41 | 2018-10-15 12:01:35 +0100 | [diff] [blame] | 224 | #define F(x,y,z) (((x) & (y)) | ((z) & ((x) | (y)))) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 225 | #define K 0x8F1BBCDC |
| 226 | |
gabor-mezei-arm | 4cb56f8 | 2020-08-25 19:12:01 +0200 | [diff] [blame] | 227 | P( local.A, local.B, local.C, local.D, local.E, R(40) ); |
| 228 | P( local.E, local.A, local.B, local.C, local.D, R(41) ); |
| 229 | P( local.D, local.E, local.A, local.B, local.C, R(42) ); |
| 230 | P( local.C, local.D, local.E, local.A, local.B, R(43) ); |
| 231 | P( local.B, local.C, local.D, local.E, local.A, R(44) ); |
| 232 | P( local.A, local.B, local.C, local.D, local.E, R(45) ); |
| 233 | P( local.E, local.A, local.B, local.C, local.D, R(46) ); |
| 234 | P( local.D, local.E, local.A, local.B, local.C, R(47) ); |
| 235 | P( local.C, local.D, local.E, local.A, local.B, R(48) ); |
| 236 | P( local.B, local.C, local.D, local.E, local.A, R(49) ); |
| 237 | P( local.A, local.B, local.C, local.D, local.E, R(50) ); |
| 238 | P( local.E, local.A, local.B, local.C, local.D, R(51) ); |
| 239 | P( local.D, local.E, local.A, local.B, local.C, R(52) ); |
| 240 | P( local.C, local.D, local.E, local.A, local.B, R(53) ); |
| 241 | P( local.B, local.C, local.D, local.E, local.A, R(54) ); |
| 242 | P( local.A, local.B, local.C, local.D, local.E, R(55) ); |
| 243 | P( local.E, local.A, local.B, local.C, local.D, R(56) ); |
| 244 | P( local.D, local.E, local.A, local.B, local.C, R(57) ); |
| 245 | P( local.C, local.D, local.E, local.A, local.B, R(58) ); |
| 246 | P( local.B, local.C, local.D, local.E, local.A, R(59) ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 247 | |
| 248 | #undef K |
| 249 | #undef F |
| 250 | |
Hanno Becker | 1eeca41 | 2018-10-15 12:01:35 +0100 | [diff] [blame] | 251 | #define F(x,y,z) ((x) ^ (y) ^ (z)) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 252 | #define K 0xCA62C1D6 |
| 253 | |
gabor-mezei-arm | 4cb56f8 | 2020-08-25 19:12:01 +0200 | [diff] [blame] | 254 | P( local.A, local.B, local.C, local.D, local.E, R(60) ); |
| 255 | P( local.E, local.A, local.B, local.C, local.D, R(61) ); |
| 256 | P( local.D, local.E, local.A, local.B, local.C, R(62) ); |
| 257 | P( local.C, local.D, local.E, local.A, local.B, R(63) ); |
| 258 | P( local.B, local.C, local.D, local.E, local.A, R(64) ); |
| 259 | P( local.A, local.B, local.C, local.D, local.E, R(65) ); |
| 260 | P( local.E, local.A, local.B, local.C, local.D, R(66) ); |
| 261 | P( local.D, local.E, local.A, local.B, local.C, R(67) ); |
| 262 | P( local.C, local.D, local.E, local.A, local.B, R(68) ); |
| 263 | P( local.B, local.C, local.D, local.E, local.A, R(69) ); |
| 264 | P( local.A, local.B, local.C, local.D, local.E, R(70) ); |
| 265 | P( local.E, local.A, local.B, local.C, local.D, R(71) ); |
| 266 | P( local.D, local.E, local.A, local.B, local.C, R(72) ); |
| 267 | P( local.C, local.D, local.E, local.A, local.B, R(73) ); |
| 268 | P( local.B, local.C, local.D, local.E, local.A, R(74) ); |
| 269 | P( local.A, local.B, local.C, local.D, local.E, R(75) ); |
| 270 | P( local.E, local.A, local.B, local.C, local.D, R(76) ); |
| 271 | P( local.D, local.E, local.A, local.B, local.C, R(77) ); |
| 272 | P( local.C, local.D, local.E, local.A, local.B, R(78) ); |
| 273 | P( local.B, local.C, local.D, local.E, local.A, R(79) ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 274 | |
| 275 | #undef K |
| 276 | #undef F |
| 277 | |
gabor-mezei-arm | 4cb56f8 | 2020-08-25 19:12:01 +0200 | [diff] [blame] | 278 | ctx->state[0] += local.A; |
| 279 | ctx->state[1] += local.B; |
| 280 | ctx->state[2] += local.C; |
| 281 | ctx->state[3] += local.D; |
| 282 | ctx->state[4] += local.E; |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 283 | |
gabor-mezei-arm | 76749ae | 2020-07-30 16:41:25 +0200 | [diff] [blame] | 284 | /* Zeroise buffers and variables to clear sensitive data from memory. */ |
gabor-mezei-arm | 4cb56f8 | 2020-08-25 19:12:01 +0200 | [diff] [blame] | 285 | mbedtls_platform_zeroize( &local, sizeof( local ) ); |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 286 | |
| 287 | return( 0 ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 288 | } |
Jaeden Amero | 041039f | 2018-02-19 15:28:08 +0000 | [diff] [blame] | 289 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 290 | #endif /* !MBEDTLS_SHA1_PROCESS_ALT */ |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 291 | |
| 292 | /* |
| 293 | * SHA-1 process buffer |
| 294 | */ |
TRodziewicz | 26371e4 | 2021-06-08 16:45:41 +0200 | [diff] [blame] | 295 | int mbedtls_sha1_update( mbedtls_sha1_context *ctx, |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 296 | const unsigned char *input, |
| 297 | size_t ilen ) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 298 | { |
Janos Follath | 24eed8d | 2019-11-22 13:21:35 +0000 | [diff] [blame] | 299 | int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 300 | size_t fill; |
Paul Bakker | 5c2364c | 2012-10-01 14:41:15 +0000 | [diff] [blame] | 301 | uint32_t left; |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 302 | |
Hanno Becker | 039ccab | 2018-12-18 17:52:14 +0000 | [diff] [blame] | 303 | SHA1_VALIDATE_RET( ctx != NULL ); |
| 304 | SHA1_VALIDATE_RET( ilen == 0 || input != NULL ); |
Hanno Becker | b3906d8 | 2018-12-18 11:35:00 +0000 | [diff] [blame] | 305 | |
Brian White | 12895d1 | 2014-04-11 11:29:42 -0400 | [diff] [blame] | 306 | if( ilen == 0 ) |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 307 | return( 0 ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 308 | |
| 309 | left = ctx->total[0] & 0x3F; |
| 310 | fill = 64 - left; |
| 311 | |
Paul Bakker | 5c2364c | 2012-10-01 14:41:15 +0000 | [diff] [blame] | 312 | ctx->total[0] += (uint32_t) ilen; |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 313 | ctx->total[0] &= 0xFFFFFFFF; |
| 314 | |
Paul Bakker | 5c2364c | 2012-10-01 14:41:15 +0000 | [diff] [blame] | 315 | if( ctx->total[0] < (uint32_t) ilen ) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 316 | ctx->total[1]++; |
| 317 | |
| 318 | if( left && ilen >= fill ) |
| 319 | { |
Paul Bakker | 3c2122f | 2013-06-24 19:03:14 +0200 | [diff] [blame] | 320 | memcpy( (void *) (ctx->buffer + left), input, fill ); |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 321 | |
Andres Amaya Garcia | cccfe08 | 2017-06-28 10:36:39 +0100 | [diff] [blame] | 322 | if( ( ret = mbedtls_internal_sha1_process( ctx, ctx->buffer ) ) != 0 ) |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 323 | return( ret ); |
| 324 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 325 | input += fill; |
| 326 | ilen -= fill; |
| 327 | left = 0; |
| 328 | } |
| 329 | |
| 330 | while( ilen >= 64 ) |
| 331 | { |
Andres Amaya Garcia | cccfe08 | 2017-06-28 10:36:39 +0100 | [diff] [blame] | 332 | if( ( ret = mbedtls_internal_sha1_process( ctx, input ) ) != 0 ) |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 333 | return( ret ); |
| 334 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 335 | input += 64; |
| 336 | ilen -= 64; |
| 337 | } |
| 338 | |
| 339 | if( ilen > 0 ) |
Paul Bakker | 3c2122f | 2013-06-24 19:03:14 +0200 | [diff] [blame] | 340 | memcpy( (void *) (ctx->buffer + left), input, ilen ); |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 341 | |
| 342 | return( 0 ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 343 | } |
| 344 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 345 | /* |
| 346 | * SHA-1 final digest |
| 347 | */ |
TRodziewicz | 26371e4 | 2021-06-08 16:45:41 +0200 | [diff] [blame] | 348 | int mbedtls_sha1_finish( mbedtls_sha1_context *ctx, |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 349 | unsigned char output[20] ) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 350 | { |
Janos Follath | 24eed8d | 2019-11-22 13:21:35 +0000 | [diff] [blame] | 351 | int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; |
Manuel Pégourié-Gonnard | 1cc1fb0 | 2018-06-28 12:10:27 +0200 | [diff] [blame] | 352 | uint32_t used; |
Paul Bakker | 5c2364c | 2012-10-01 14:41:15 +0000 | [diff] [blame] | 353 | uint32_t high, low; |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 354 | |
Hanno Becker | 039ccab | 2018-12-18 17:52:14 +0000 | [diff] [blame] | 355 | SHA1_VALIDATE_RET( ctx != NULL ); |
| 356 | SHA1_VALIDATE_RET( (unsigned char *)output != NULL ); |
Andres Amaya Garcia | f7c43b3 | 2018-12-09 19:12:19 +0000 | [diff] [blame] | 357 | |
Manuel Pégourié-Gonnard | 1cc1fb0 | 2018-06-28 12:10:27 +0200 | [diff] [blame] | 358 | /* |
| 359 | * Add padding: 0x80 then 0x00 until 8 bytes remain for the length |
| 360 | */ |
| 361 | used = ctx->total[0] & 0x3F; |
| 362 | |
| 363 | ctx->buffer[used++] = 0x80; |
| 364 | |
| 365 | if( used <= 56 ) |
| 366 | { |
| 367 | /* Enough room for padding + length in current block */ |
| 368 | memset( ctx->buffer + used, 0, 56 - used ); |
| 369 | } |
| 370 | else |
| 371 | { |
| 372 | /* We'll need an extra block */ |
| 373 | memset( ctx->buffer + used, 0, 64 - used ); |
| 374 | |
| 375 | if( ( ret = mbedtls_internal_sha1_process( ctx, ctx->buffer ) ) != 0 ) |
| 376 | return( ret ); |
| 377 | |
| 378 | memset( ctx->buffer, 0, 56 ); |
| 379 | } |
| 380 | |
| 381 | /* |
| 382 | * Add message length |
| 383 | */ |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 384 | high = ( ctx->total[0] >> 29 ) |
| 385 | | ( ctx->total[1] << 3 ); |
| 386 | low = ( ctx->total[0] << 3 ); |
| 387 | |
Manuel Pégourié-Gonnard | 1cc1fb0 | 2018-06-28 12:10:27 +0200 | [diff] [blame] | 388 | PUT_UINT32_BE( high, ctx->buffer, 56 ); |
| 389 | PUT_UINT32_BE( low, ctx->buffer, 60 ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 390 | |
Manuel Pégourié-Gonnard | 1cc1fb0 | 2018-06-28 12:10:27 +0200 | [diff] [blame] | 391 | if( ( ret = mbedtls_internal_sha1_process( ctx, ctx->buffer ) ) != 0 ) |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 392 | return( ret ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 393 | |
Manuel Pégourié-Gonnard | 1cc1fb0 | 2018-06-28 12:10:27 +0200 | [diff] [blame] | 394 | /* |
| 395 | * Output final state |
| 396 | */ |
Paul Bakker | 5c2364c | 2012-10-01 14:41:15 +0000 | [diff] [blame] | 397 | PUT_UINT32_BE( ctx->state[0], output, 0 ); |
| 398 | PUT_UINT32_BE( ctx->state[1], output, 4 ); |
| 399 | PUT_UINT32_BE( ctx->state[2], output, 8 ); |
| 400 | PUT_UINT32_BE( ctx->state[3], output, 12 ); |
| 401 | PUT_UINT32_BE( ctx->state[4], output, 16 ); |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 402 | |
| 403 | return( 0 ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 404 | } |
| 405 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 406 | #endif /* !MBEDTLS_SHA1_ALT */ |
Paul Bakker | 90995b5 | 2013-06-24 19:20:35 +0200 | [diff] [blame] | 407 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 408 | /* |
| 409 | * output = SHA-1( input buffer ) |
| 410 | */ |
TRodziewicz | 26371e4 | 2021-06-08 16:45:41 +0200 | [diff] [blame] | 411 | int mbedtls_sha1( const unsigned char *input, |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 412 | size_t ilen, |
| 413 | unsigned char output[20] ) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 414 | { |
Janos Follath | 24eed8d | 2019-11-22 13:21:35 +0000 | [diff] [blame] | 415 | int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 416 | mbedtls_sha1_context ctx; |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 417 | |
Hanno Becker | 039ccab | 2018-12-18 17:52:14 +0000 | [diff] [blame] | 418 | SHA1_VALIDATE_RET( ilen == 0 || input != NULL ); |
| 419 | SHA1_VALIDATE_RET( (unsigned char *)output != NULL ); |
Andres Amaya Garcia | f7c43b3 | 2018-12-09 19:12:19 +0000 | [diff] [blame] | 420 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 421 | mbedtls_sha1_init( &ctx ); |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 422 | |
TRodziewicz | 26371e4 | 2021-06-08 16:45:41 +0200 | [diff] [blame] | 423 | if( ( ret = mbedtls_sha1_starts( &ctx ) ) != 0 ) |
Andres Amaya Garcia | 0963e6c | 2017-07-20 14:34:08 +0100 | [diff] [blame] | 424 | goto exit; |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 425 | |
TRodziewicz | 26371e4 | 2021-06-08 16:45:41 +0200 | [diff] [blame] | 426 | if( ( ret = mbedtls_sha1_update( &ctx, input, ilen ) ) != 0 ) |
Andres Amaya Garcia | 0963e6c | 2017-07-20 14:34:08 +0100 | [diff] [blame] | 427 | goto exit; |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 428 | |
TRodziewicz | 26371e4 | 2021-06-08 16:45:41 +0200 | [diff] [blame] | 429 | if( ( ret = mbedtls_sha1_finish( &ctx, output ) ) != 0 ) |
Andres Amaya Garcia | 0963e6c | 2017-07-20 14:34:08 +0100 | [diff] [blame] | 430 | goto exit; |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 431 | |
Andres Amaya Garcia | 0963e6c | 2017-07-20 14:34:08 +0100 | [diff] [blame] | 432 | exit: |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 433 | mbedtls_sha1_free( &ctx ); |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 434 | |
Andres Amaya Garcia | 0963e6c | 2017-07-20 14:34:08 +0100 | [diff] [blame] | 435 | return( ret ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 436 | } |
| 437 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 438 | #if defined(MBEDTLS_SELF_TEST) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 439 | /* |
| 440 | * FIPS-180-1 test vectors |
| 441 | */ |
Manuel Pégourié-Gonnard | 28122e4 | 2015-03-11 09:13:42 +0000 | [diff] [blame] | 442 | static const unsigned char sha1_test_buf[3][57] = |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 443 | { |
| 444 | { "abc" }, |
| 445 | { "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" }, |
| 446 | { "" } |
| 447 | }; |
| 448 | |
Andres Amaya Garcia | 2d0aa8b | 2017-07-21 14:57:26 +0100 | [diff] [blame] | 449 | static const size_t sha1_test_buflen[3] = |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 450 | { |
| 451 | 3, 56, 1000 |
| 452 | }; |
| 453 | |
| 454 | static const unsigned char sha1_test_sum[3][20] = |
| 455 | { |
| 456 | { 0xA9, 0x99, 0x3E, 0x36, 0x47, 0x06, 0x81, 0x6A, 0xBA, 0x3E, |
| 457 | 0x25, 0x71, 0x78, 0x50, 0xC2, 0x6C, 0x9C, 0xD0, 0xD8, 0x9D }, |
| 458 | { 0x84, 0x98, 0x3E, 0x44, 0x1C, 0x3B, 0xD2, 0x6E, 0xBA, 0xAE, |
| 459 | 0x4A, 0xA1, 0xF9, 0x51, 0x29, 0xE5, 0xE5, 0x46, 0x70, 0xF1 }, |
| 460 | { 0x34, 0xAA, 0x97, 0x3C, 0xD4, 0xC4, 0xDA, 0xA4, 0xF6, 0x1E, |
| 461 | 0xEB, 0x2B, 0xDB, 0xAD, 0x27, 0x31, 0x65, 0x34, 0x01, 0x6F } |
| 462 | }; |
| 463 | |
| 464 | /* |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 465 | * Checkup routine |
| 466 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 467 | int mbedtls_sha1_self_test( int verbose ) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 468 | { |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 469 | int i, j, buflen, ret = 0; |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 470 | unsigned char buf[1024]; |
| 471 | unsigned char sha1sum[20]; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 472 | mbedtls_sha1_context ctx; |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 473 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 474 | mbedtls_sha1_init( &ctx ); |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 475 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 476 | /* |
| 477 | * SHA-1 |
| 478 | */ |
| 479 | for( i = 0; i < 3; i++ ) |
| 480 | { |
| 481 | if( verbose != 0 ) |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 482 | mbedtls_printf( " SHA-1 test #%d: ", i + 1 ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 483 | |
TRodziewicz | 26371e4 | 2021-06-08 16:45:41 +0200 | [diff] [blame] | 484 | if( ( ret = mbedtls_sha1_starts( &ctx ) ) != 0 ) |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 485 | goto fail; |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 486 | |
| 487 | if( i == 2 ) |
| 488 | { |
| 489 | memset( buf, 'a', buflen = 1000 ); |
| 490 | |
| 491 | for( j = 0; j < 1000; j++ ) |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 492 | { |
TRodziewicz | 26371e4 | 2021-06-08 16:45:41 +0200 | [diff] [blame] | 493 | ret = mbedtls_sha1_update( &ctx, buf, buflen ); |
Andres Amaya Garcia | 6a3f305 | 2017-07-20 14:18:54 +0100 | [diff] [blame] | 494 | if( ret != 0 ) |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 495 | goto fail; |
| 496 | } |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 497 | } |
| 498 | else |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 499 | { |
TRodziewicz | 26371e4 | 2021-06-08 16:45:41 +0200 | [diff] [blame] | 500 | ret = mbedtls_sha1_update( &ctx, sha1_test_buf[i], |
Andres Amaya Garcia | 6a3f305 | 2017-07-20 14:18:54 +0100 | [diff] [blame] | 501 | sha1_test_buflen[i] ); |
| 502 | if( ret != 0 ) |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 503 | goto fail; |
| 504 | } |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 505 | |
TRodziewicz | 26371e4 | 2021-06-08 16:45:41 +0200 | [diff] [blame] | 506 | if( ( ret = mbedtls_sha1_finish( &ctx, sha1sum ) ) != 0 ) |
Andres Amaya Garcia | 6a3f305 | 2017-07-20 14:18:54 +0100 | [diff] [blame] | 507 | goto fail; |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 508 | |
| 509 | if( memcmp( sha1sum, sha1_test_sum[i], 20 ) != 0 ) |
Andres Amaya Garcia | 6a3f305 | 2017-07-20 14:18:54 +0100 | [diff] [blame] | 510 | { |
| 511 | ret = 1; |
| 512 | goto fail; |
| 513 | } |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 514 | |
| 515 | if( verbose != 0 ) |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 516 | mbedtls_printf( "passed\n" ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 517 | } |
| 518 | |
| 519 | if( verbose != 0 ) |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 520 | mbedtls_printf( "\n" ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 521 | |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 522 | goto exit; |
| 523 | |
| 524 | fail: |
| 525 | if( verbose != 0 ) |
| 526 | mbedtls_printf( "failed\n" ); |
| 527 | |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 528 | exit: |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 529 | mbedtls_sha1_free( &ctx ); |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 530 | |
| 531 | return( ret ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 532 | } |
| 533 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 534 | #endif /* MBEDTLS_SELF_TEST */ |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 535 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 536 | #endif /* MBEDTLS_SHA1_C */ |