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