Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 1 | /* |
| 2 | * FIPS-180-2 compliant SHA-256 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-256 Secure Hash Standard was published by NIST in 2002. |
| 21 | * |
| 22 | * http://csrc.nist.gov/publications/fips/fips180-2/fips180-2.pdf |
| 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_SHA256_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/sha256.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> |
Russ Butler | bb83b42 | 2016-10-12 17:36:50 -0500 | [diff] [blame] | 40 | #include <stdlib.h> |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 41 | #define mbedtls_printf printf |
Russ Butler | bb83b42 | 2016-10-12 17:36:50 -0500 | [diff] [blame] | 42 | #define mbedtls_calloc calloc |
| 43 | #define mbedtls_free free |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 44 | #endif /* MBEDTLS_PLATFORM_C */ |
| 45 | #endif /* MBEDTLS_SELF_TEST */ |
Paul Bakker | 7dc4c44 | 2014-02-01 22:50:26 +0100 | [diff] [blame] | 46 | |
Tom Cosgrove | f3ebd90 | 2022-02-20 22:25:31 +0000 | [diff] [blame] | 47 | #if defined(__aarch64__) |
| 48 | # if defined(MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT) || \ |
| 49 | defined(MBEDTLS_SHA256_USE_A64_CRYPTO_ONLY) |
| 50 | # include <arm_neon.h> |
| 51 | # endif |
Tom Cosgrove | b7f5b97 | 2022-03-15 11:26:55 +0000 | [diff] [blame] | 52 | # if defined(MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT) |
| 53 | # if defined(__unix__) |
| 54 | # if defined(__linux__) |
| 55 | /* Our preferred method of detection is getauxval() */ |
| 56 | # include <sys/auxv.h> |
| 57 | # endif |
| 58 | /* Use SIGILL on Unix, and fall back to it on Linux */ |
| 59 | # include <signal.h> |
| 60 | # endif |
Tom Cosgrove | f3ebd90 | 2022-02-20 22:25:31 +0000 | [diff] [blame] | 61 | # endif |
Tom Cosgrove | b9987fc | 2022-02-21 12:26:11 +0000 | [diff] [blame] | 62 | #elif defined(_M_ARM64) |
| 63 | # if defined(MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT) || \ |
| 64 | defined(MBEDTLS_SHA256_USE_A64_CRYPTO_ONLY) |
| 65 | # include <arm64_neon.h> |
| 66 | # endif |
Tom Cosgrove | f3ebd90 | 2022-02-20 22:25:31 +0000 | [diff] [blame] | 67 | #else |
| 68 | # undef MBEDTLS_SHA256_USE_A64_CRYPTO_ONLY |
| 69 | # undef MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT |
| 70 | #endif |
| 71 | |
| 72 | #if defined(MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT) |
| 73 | /* |
| 74 | * Capability detection code comes early, so we can disable |
| 75 | * MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT if no detection mechanism found |
| 76 | */ |
| 77 | #if defined(HWCAP_SHA2) |
Tom Cosgrove | 7e7aba8 | 2022-02-24 08:33:11 +0000 | [diff] [blame] | 78 | static int mbedtls_a64_crypto_sha256_determine_support( void ) |
Tom Cosgrove | f3ebd90 | 2022-02-20 22:25:31 +0000 | [diff] [blame] | 79 | { |
| 80 | return( ( getauxval( AT_HWCAP ) & HWCAP_SHA2 ) ? 1 : 0 ); |
| 81 | } |
| 82 | #elif defined(__APPLE__) |
Tom Cosgrove | 7e7aba8 | 2022-02-24 08:33:11 +0000 | [diff] [blame] | 83 | static int mbedtls_a64_crypto_sha256_determine_support( void ) |
Tom Cosgrove | f3ebd90 | 2022-02-20 22:25:31 +0000 | [diff] [blame] | 84 | { |
| 85 | return( 1 ); |
| 86 | } |
Tom Cosgrove | b9987fc | 2022-02-21 12:26:11 +0000 | [diff] [blame] | 87 | #elif defined(_M_ARM64) |
| 88 | #define WIN32_LEAN_AND_MEAN |
| 89 | #include <Windows.h> |
| 90 | #include <processthreadsapi.h> |
| 91 | |
Tom Cosgrove | 7e7aba8 | 2022-02-24 08:33:11 +0000 | [diff] [blame] | 92 | static int mbedtls_a64_crypto_sha256_determine_support( void ) |
Tom Cosgrove | b9987fc | 2022-02-21 12:26:11 +0000 | [diff] [blame] | 93 | { |
| 94 | return( IsProcessorFeaturePresent( PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE ) ? |
| 95 | 1 : 0 ); |
| 96 | } |
Tom Cosgrove | f3ebd90 | 2022-02-20 22:25:31 +0000 | [diff] [blame] | 97 | #elif defined(__unix__) && defined(SIG_SETMASK) |
| 98 | /* Detection with SIGILL, setjmp() and longjmp() */ |
| 99 | #include <signal.h> |
| 100 | #include <setjmp.h> |
| 101 | |
| 102 | #ifndef asm |
| 103 | #define asm __asm__ |
| 104 | #endif |
| 105 | |
| 106 | static jmp_buf return_from_sigill; |
| 107 | |
| 108 | /* |
| 109 | * A64 SHA256 support detection via SIGILL |
| 110 | */ |
| 111 | static void sigill_handler( int signal ) |
| 112 | { |
| 113 | (void) signal; |
| 114 | longjmp( return_from_sigill, 1 ); |
| 115 | } |
| 116 | |
Tom Cosgrove | 7e7aba8 | 2022-02-24 08:33:11 +0000 | [diff] [blame] | 117 | static int mbedtls_a64_crypto_sha256_determine_support( void ) |
Tom Cosgrove | f3ebd90 | 2022-02-20 22:25:31 +0000 | [diff] [blame] | 118 | { |
| 119 | struct sigaction old_action, new_action; |
| 120 | |
| 121 | sigset_t old_mask; |
| 122 | if( sigprocmask( 0, NULL, &old_mask ) ) |
| 123 | return( 0 ); |
| 124 | |
| 125 | sigemptyset( &new_action.sa_mask ); |
| 126 | new_action.sa_flags = 0; |
| 127 | new_action.sa_handler = sigill_handler; |
| 128 | |
| 129 | sigaction( SIGILL, &new_action, &old_action ); |
| 130 | |
| 131 | static int ret = 0; |
| 132 | |
| 133 | if( setjmp( return_from_sigill ) == 0 ) /* First return only */ |
| 134 | { |
| 135 | /* If this traps, we will return a second time from setjmp() with 1 */ |
| 136 | asm( "sha256h q0, q0, v0.4s" : : : "v0" ); |
| 137 | ret = 1; |
| 138 | } |
| 139 | |
| 140 | sigaction( SIGILL, &old_action, NULL ); |
| 141 | sigprocmask( SIG_SETMASK, &old_mask, NULL ); |
| 142 | |
| 143 | return( ret ); |
| 144 | } |
| 145 | #else |
| 146 | #warning "No mechanism to detect A64_CRYPTO found, using C code only" |
| 147 | #undef MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT |
| 148 | #endif /* HWCAP_SHA2, __APPLE__, __unix__ && SIG_SETMASK */ |
| 149 | |
| 150 | #endif /* MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT */ |
| 151 | |
Manuel Pégourié-Gonnard | 8b2641d | 2015-08-27 20:03:46 +0200 | [diff] [blame] | 152 | #if !defined(MBEDTLS_SHA256_ALT) |
| 153 | |
Tom Cosgrove | f3ebd90 | 2022-02-20 22:25:31 +0000 | [diff] [blame] | 154 | #define SHA256_BLOCK_SIZE 64 |
| 155 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 156 | void mbedtls_sha256_init( mbedtls_sha256_context *ctx ) |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 157 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 158 | memset( ctx, 0, sizeof( mbedtls_sha256_context ) ); |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 159 | } |
| 160 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 161 | void mbedtls_sha256_free( mbedtls_sha256_context *ctx ) |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 162 | { |
| 163 | if( ctx == NULL ) |
| 164 | return; |
| 165 | |
Andres Amaya Garcia | 1f6301b | 2018-04-17 09:51:09 -0500 | [diff] [blame] | 166 | mbedtls_platform_zeroize( ctx, sizeof( mbedtls_sha256_context ) ); |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 167 | } |
| 168 | |
Manuel Pégourié-Gonnard | 16d412f | 2015-07-06 15:26:26 +0200 | [diff] [blame] | 169 | void mbedtls_sha256_clone( mbedtls_sha256_context *dst, |
| 170 | const mbedtls_sha256_context *src ) |
| 171 | { |
| 172 | *dst = *src; |
| 173 | } |
| 174 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 175 | /* |
| 176 | * SHA-256 context setup |
| 177 | */ |
TRodziewicz | 26371e4 | 2021-06-08 16:45:41 +0200 | [diff] [blame] | 178 | int mbedtls_sha256_starts( mbedtls_sha256_context *ctx, int is224 ) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 179 | { |
Mateusz Starzyk | e3c48b4 | 2021-04-19 16:46:28 +0200 | [diff] [blame] | 180 | #if defined(MBEDTLS_SHA224_C) |
Tuvshinzaya Erdenekhuu | 696dfb6 | 2022-08-05 15:59:19 +0100 | [diff] [blame] | 181 | if( is224 != 0 && is224 != 1 ) |
| 182 | return MBEDTLS_ERR_SHA256_BAD_INPUT_DATA; |
Mateusz Starzyk | e3c48b4 | 2021-04-19 16:46:28 +0200 | [diff] [blame] | 183 | #else |
Tuvshinzaya Erdenekhuu | 696dfb6 | 2022-08-05 15:59:19 +0100 | [diff] [blame] | 184 | if( is224 != 0 ) |
| 185 | return MBEDTLS_ERR_SHA256_BAD_INPUT_DATA; |
Mateusz Starzyk | e3c48b4 | 2021-04-19 16:46:28 +0200 | [diff] [blame] | 186 | #endif |
| 187 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 188 | ctx->total[0] = 0; |
| 189 | ctx->total[1] = 0; |
| 190 | |
| 191 | if( is224 == 0 ) |
| 192 | { |
| 193 | /* SHA-256 */ |
| 194 | ctx->state[0] = 0x6A09E667; |
| 195 | ctx->state[1] = 0xBB67AE85; |
| 196 | ctx->state[2] = 0x3C6EF372; |
| 197 | ctx->state[3] = 0xA54FF53A; |
| 198 | ctx->state[4] = 0x510E527F; |
| 199 | ctx->state[5] = 0x9B05688C; |
| 200 | ctx->state[6] = 0x1F83D9AB; |
| 201 | ctx->state[7] = 0x5BE0CD19; |
| 202 | } |
| 203 | else |
| 204 | { |
Mateusz Starzyk | e3c48b4 | 2021-04-19 16:46:28 +0200 | [diff] [blame] | 205 | #if defined(MBEDTLS_SHA224_C) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 206 | /* SHA-224 */ |
| 207 | ctx->state[0] = 0xC1059ED8; |
| 208 | ctx->state[1] = 0x367CD507; |
| 209 | ctx->state[2] = 0x3070DD17; |
| 210 | ctx->state[3] = 0xF70E5939; |
| 211 | ctx->state[4] = 0xFFC00B31; |
| 212 | ctx->state[5] = 0x68581511; |
| 213 | ctx->state[6] = 0x64F98FA7; |
| 214 | ctx->state[7] = 0xBEFA4FA4; |
Mateusz Starzyk | e3c48b4 | 2021-04-19 16:46:28 +0200 | [diff] [blame] | 215 | #endif |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | ctx->is224 = is224; |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 219 | |
| 220 | return( 0 ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 221 | } |
| 222 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 223 | #if !defined(MBEDTLS_SHA256_PROCESS_ALT) |
Manuel Pégourié-Gonnard | a7a3a5f | 2015-05-28 12:14:49 +0200 | [diff] [blame] | 224 | static const uint32_t K[] = |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 225 | { |
Manuel Pégourié-Gonnard | a7a3a5f | 2015-05-28 12:14:49 +0200 | [diff] [blame] | 226 | 0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5, |
| 227 | 0x3956C25B, 0x59F111F1, 0x923F82A4, 0xAB1C5ED5, |
| 228 | 0xD807AA98, 0x12835B01, 0x243185BE, 0x550C7DC3, |
| 229 | 0x72BE5D74, 0x80DEB1FE, 0x9BDC06A7, 0xC19BF174, |
| 230 | 0xE49B69C1, 0xEFBE4786, 0x0FC19DC6, 0x240CA1CC, |
| 231 | 0x2DE92C6F, 0x4A7484AA, 0x5CB0A9DC, 0x76F988DA, |
| 232 | 0x983E5152, 0xA831C66D, 0xB00327C8, 0xBF597FC7, |
| 233 | 0xC6E00BF3, 0xD5A79147, 0x06CA6351, 0x14292967, |
| 234 | 0x27B70A85, 0x2E1B2138, 0x4D2C6DFC, 0x53380D13, |
| 235 | 0x650A7354, 0x766A0ABB, 0x81C2C92E, 0x92722C85, |
| 236 | 0xA2BFE8A1, 0xA81A664B, 0xC24B8B70, 0xC76C51A3, |
| 237 | 0xD192E819, 0xD6990624, 0xF40E3585, 0x106AA070, |
| 238 | 0x19A4C116, 0x1E376C08, 0x2748774C, 0x34B0BCB5, |
| 239 | 0x391C0CB3, 0x4ED8AA4A, 0x5B9CCA4F, 0x682E6FF3, |
| 240 | 0x748F82EE, 0x78A5636F, 0x84C87814, 0x8CC70208, |
| 241 | 0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2, |
| 242 | }; |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 243 | |
Tom Cosgrove | f3ebd90 | 2022-02-20 22:25:31 +0000 | [diff] [blame] | 244 | #endif |
| 245 | |
| 246 | #if defined(MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT) || \ |
| 247 | defined(MBEDTLS_SHA256_USE_A64_CRYPTO_ONLY) |
| 248 | |
| 249 | #if defined(MBEDTLS_SHA256_USE_A64_CRYPTO_ONLY) |
| 250 | # define mbedtls_internal_sha256_process_many_a64_crypto mbedtls_internal_sha256_process_many |
| 251 | # define mbedtls_internal_sha256_process_a64_crypto mbedtls_internal_sha256_process |
| 252 | #endif |
| 253 | |
| 254 | static size_t mbedtls_internal_sha256_process_many_a64_crypto( |
| 255 | mbedtls_sha256_context *ctx, const uint8_t *msg, size_t len ) |
| 256 | { |
| 257 | uint32x4_t abcd = vld1q_u32( &ctx->state[0] ); |
| 258 | uint32x4_t efgh = vld1q_u32( &ctx->state[4] ); |
| 259 | |
| 260 | size_t processed = 0; |
| 261 | |
| 262 | for( ; |
| 263 | len >= SHA256_BLOCK_SIZE; |
| 264 | processed += SHA256_BLOCK_SIZE, |
| 265 | msg += SHA256_BLOCK_SIZE, |
| 266 | len -= SHA256_BLOCK_SIZE ) |
| 267 | { |
| 268 | uint32x4_t tmp, abcd_prev; |
| 269 | |
| 270 | uint32x4_t abcd_orig = abcd; |
| 271 | uint32x4_t efgh_orig = efgh; |
| 272 | |
Tom Cosgrove | b7f5b97 | 2022-03-15 11:26:55 +0000 | [diff] [blame] | 273 | uint32x4_t sched0 = (uint32x4_t) vld1q_u8( msg + 16 * 0 ); |
| 274 | uint32x4_t sched1 = (uint32x4_t) vld1q_u8( msg + 16 * 1 ); |
| 275 | uint32x4_t sched2 = (uint32x4_t) vld1q_u8( msg + 16 * 2 ); |
| 276 | uint32x4_t sched3 = (uint32x4_t) vld1q_u8( msg + 16 * 3 ); |
Tom Cosgrove | f3ebd90 | 2022-02-20 22:25:31 +0000 | [diff] [blame] | 277 | |
| 278 | #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ /* Will be true if not defined */ |
| 279 | /* Untested on BE */ |
| 280 | sched0 = vreinterpretq_u32_u8( vrev32q_u8( vreinterpretq_u8_u32( sched0 ) ) ); |
| 281 | sched1 = vreinterpretq_u32_u8( vrev32q_u8( vreinterpretq_u8_u32( sched1 ) ) ); |
| 282 | sched2 = vreinterpretq_u32_u8( vrev32q_u8( vreinterpretq_u8_u32( sched2 ) ) ); |
| 283 | sched3 = vreinterpretq_u32_u8( vrev32q_u8( vreinterpretq_u8_u32( sched3 ) ) ); |
| 284 | #endif |
| 285 | |
| 286 | /* Rounds 0 to 3 */ |
| 287 | tmp = vaddq_u32( sched0, vld1q_u32( &K[0] ) ); |
| 288 | abcd_prev = abcd; |
| 289 | abcd = vsha256hq_u32( abcd_prev, efgh, tmp ); |
| 290 | efgh = vsha256h2q_u32( efgh, abcd_prev, tmp ); |
| 291 | |
| 292 | /* Rounds 4 to 7 */ |
| 293 | tmp = vaddq_u32( sched1, vld1q_u32( &K[4] ) ); |
| 294 | abcd_prev = abcd; |
| 295 | abcd = vsha256hq_u32( abcd_prev, efgh, tmp ); |
| 296 | efgh = vsha256h2q_u32( efgh, abcd_prev, tmp ); |
| 297 | |
| 298 | /* Rounds 8 to 11 */ |
| 299 | tmp = vaddq_u32( sched2, vld1q_u32( &K[8] ) ); |
| 300 | abcd_prev = abcd; |
| 301 | abcd = vsha256hq_u32( abcd_prev, efgh, tmp ); |
| 302 | efgh = vsha256h2q_u32( efgh, abcd_prev, tmp ); |
| 303 | |
| 304 | /* Rounds 12 to 15 */ |
| 305 | tmp = vaddq_u32( sched3, vld1q_u32( &K[12] ) ); |
| 306 | abcd_prev = abcd; |
| 307 | abcd = vsha256hq_u32( abcd_prev, efgh, tmp ); |
| 308 | efgh = vsha256h2q_u32( efgh, abcd_prev, tmp ); |
| 309 | |
| 310 | for( int t = 16; t < 64; t += 16 ) |
| 311 | { |
| 312 | /* Rounds t to t + 3 */ |
| 313 | sched0 = vsha256su1q_u32( vsha256su0q_u32( sched0, sched1 ), sched2, sched3 ); |
| 314 | tmp = vaddq_u32( sched0, vld1q_u32( &K[t] ) ); |
| 315 | abcd_prev = abcd; |
| 316 | abcd = vsha256hq_u32( abcd_prev, efgh, tmp ); |
| 317 | efgh = vsha256h2q_u32( efgh, abcd_prev, tmp ); |
| 318 | |
| 319 | /* Rounds t + 4 to t + 7 */ |
| 320 | sched1 = vsha256su1q_u32( vsha256su0q_u32( sched1, sched2 ), sched3, sched0 ); |
| 321 | tmp = vaddq_u32( sched1, vld1q_u32( &K[t + 4] ) ); |
| 322 | abcd_prev = abcd; |
| 323 | abcd = vsha256hq_u32( abcd_prev, efgh, tmp ); |
| 324 | efgh = vsha256h2q_u32( efgh, abcd_prev, tmp ); |
| 325 | |
| 326 | /* Rounds t + 8 to t + 11 */ |
| 327 | sched2 = vsha256su1q_u32( vsha256su0q_u32( sched2, sched3 ), sched0, sched1 ); |
| 328 | tmp = vaddq_u32( sched2, vld1q_u32( &K[t + 8] ) ); |
| 329 | abcd_prev = abcd; |
| 330 | abcd = vsha256hq_u32( abcd_prev, efgh, tmp ); |
| 331 | efgh = vsha256h2q_u32( efgh, abcd_prev, tmp ); |
| 332 | |
| 333 | /* Rounds t + 12 to t + 15 */ |
| 334 | sched3 = vsha256su1q_u32( vsha256su0q_u32( sched3, sched0 ), sched1, sched2 ); |
| 335 | tmp = vaddq_u32( sched3, vld1q_u32( &K[t + 12] ) ); |
| 336 | abcd_prev = abcd; |
| 337 | abcd = vsha256hq_u32( abcd_prev, efgh, tmp ); |
| 338 | efgh = vsha256h2q_u32( efgh, abcd_prev, tmp ); |
| 339 | } |
| 340 | |
| 341 | abcd = vaddq_u32( abcd, abcd_orig ); |
| 342 | efgh = vaddq_u32( efgh, efgh_orig ); |
| 343 | } |
| 344 | |
| 345 | vst1q_u32( &ctx->state[0], abcd ); |
| 346 | vst1q_u32( &ctx->state[4], efgh ); |
| 347 | |
| 348 | return( processed ); |
| 349 | } |
| 350 | |
Tom Cosgrove | c144ca6 | 2022-04-19 13:52:24 +0100 | [diff] [blame] | 351 | #if defined(MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT) |
| 352 | /* |
| 353 | * This function is for internal use only if we are building both C and A64 |
| 354 | * versions, otherwise it is renamed to be the public mbedtls_internal_sha256_process() |
| 355 | */ |
| 356 | static |
| 357 | #endif |
Tom Cosgrove | f3ebd90 | 2022-02-20 22:25:31 +0000 | [diff] [blame] | 358 | int mbedtls_internal_sha256_process_a64_crypto( mbedtls_sha256_context *ctx, |
| 359 | const unsigned char data[SHA256_BLOCK_SIZE] ) |
| 360 | { |
| 361 | return( ( mbedtls_internal_sha256_process_many_a64_crypto( ctx, data, |
| 362 | SHA256_BLOCK_SIZE ) == SHA256_BLOCK_SIZE ) ? 0 : -1 ); |
| 363 | } |
| 364 | |
| 365 | #endif /* MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT || MBEDTLS_SHA256_USE_A64_CRYPTO_ONLY */ |
| 366 | |
| 367 | |
| 368 | #if !defined(MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT) |
| 369 | #define mbedtls_internal_sha256_process_many_c mbedtls_internal_sha256_process_many |
| 370 | #define mbedtls_internal_sha256_process_c mbedtls_internal_sha256_process |
| 371 | #endif |
| 372 | |
| 373 | |
| 374 | #if !defined(MBEDTLS_SHA256_PROCESS_ALT) && \ |
| 375 | !defined(MBEDTLS_SHA256_USE_A64_CRYPTO_ONLY) |
| 376 | |
Hanno Becker | 1eeca41 | 2018-10-15 12:01:35 +0100 | [diff] [blame] | 377 | #define SHR(x,n) (((x) & 0xFFFFFFFF) >> (n)) |
| 378 | #define ROTR(x,n) (SHR(x,n) | ((x) << (32 - (n)))) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 379 | |
| 380 | #define S0(x) (ROTR(x, 7) ^ ROTR(x,18) ^ SHR(x, 3)) |
| 381 | #define S1(x) (ROTR(x,17) ^ ROTR(x,19) ^ SHR(x,10)) |
| 382 | |
| 383 | #define S2(x) (ROTR(x, 2) ^ ROTR(x,13) ^ ROTR(x,22)) |
| 384 | #define S3(x) (ROTR(x, 6) ^ ROTR(x,11) ^ ROTR(x,25)) |
| 385 | |
Hanno Becker | 1eeca41 | 2018-10-15 12:01:35 +0100 | [diff] [blame] | 386 | #define F0(x,y,z) (((x) & (y)) | ((z) & ((x) | (y)))) |
| 387 | #define F1(x,y,z) ((z) ^ ((x) & ((y) ^ (z)))) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 388 | |
gabor-mezei-arm | 4cb56f8 | 2020-08-25 19:12:01 +0200 | [diff] [blame] | 389 | #define R(t) \ |
| 390 | ( \ |
| 391 | local.W[t] = S1(local.W[(t) - 2]) + local.W[(t) - 7] + \ |
| 392 | S0(local.W[(t) - 15]) + local.W[(t) - 16] \ |
Hanno Becker | 1eeca41 | 2018-10-15 12:01:35 +0100 | [diff] [blame] | 393 | ) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 394 | |
gabor-mezei-arm | 4cb56f8 | 2020-08-25 19:12:01 +0200 | [diff] [blame] | 395 | #define P(a,b,c,d,e,f,g,h,x,K) \ |
| 396 | do \ |
| 397 | { \ |
| 398 | local.temp1 = (h) + S3(e) + F1((e),(f),(g)) + (K) + (x); \ |
| 399 | local.temp2 = S2(a) + F0((a),(b),(c)); \ |
| 400 | (d) += local.temp1; (h) = local.temp1 + local.temp2; \ |
Hanno Becker | 1eeca41 | 2018-10-15 12:01:35 +0100 | [diff] [blame] | 401 | } while( 0 ) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 402 | |
Tom Cosgrove | c144ca6 | 2022-04-19 13:52:24 +0100 | [diff] [blame] | 403 | #if defined(MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT) |
| 404 | /* |
| 405 | * This function is for internal use only if we are building both C and A64 |
| 406 | * versions, otherwise it is renamed to be the public mbedtls_internal_sha256_process() |
| 407 | */ |
| 408 | static |
| 409 | #endif |
Tom Cosgrove | f3ebd90 | 2022-02-20 22:25:31 +0000 | [diff] [blame] | 410 | int mbedtls_internal_sha256_process_c( mbedtls_sha256_context *ctx, |
| 411 | const unsigned char data[SHA256_BLOCK_SIZE] ) |
Manuel Pégourié-Gonnard | a7a3a5f | 2015-05-28 12:14:49 +0200 | [diff] [blame] | 412 | { |
gabor-mezei-arm | 4cb56f8 | 2020-08-25 19:12:01 +0200 | [diff] [blame] | 413 | struct |
| 414 | { |
| 415 | uint32_t temp1, temp2, W[64]; |
| 416 | uint32_t A[8]; |
| 417 | } local; |
| 418 | |
Manuel Pégourié-Gonnard | a7a3a5f | 2015-05-28 12:14:49 +0200 | [diff] [blame] | 419 | unsigned int i; |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 420 | |
Manuel Pégourié-Gonnard | a7a3a5f | 2015-05-28 12:14:49 +0200 | [diff] [blame] | 421 | for( i = 0; i < 8; i++ ) |
gabor-mezei-arm | 4cb56f8 | 2020-08-25 19:12:01 +0200 | [diff] [blame] | 422 | local.A[i] = ctx->state[i]; |
Manuel Pégourié-Gonnard | a7a3a5f | 2015-05-28 12:14:49 +0200 | [diff] [blame] | 423 | |
Manuel Pégourié-Gonnard | eb0d870 | 2015-05-28 12:54:04 +0200 | [diff] [blame] | 424 | #if defined(MBEDTLS_SHA256_SMALLER) |
| 425 | for( i = 0; i < 64; i++ ) |
| 426 | { |
| 427 | if( i < 16 ) |
Joe Subbiani | 6a50631 | 2021-07-07 16:56:29 +0100 | [diff] [blame] | 428 | local.W[i] = MBEDTLS_GET_UINT32_BE( data, 4 * i ); |
Manuel Pégourié-Gonnard | eb0d870 | 2015-05-28 12:54:04 +0200 | [diff] [blame] | 429 | else |
| 430 | R( i ); |
| 431 | |
gabor-mezei-arm | 4cb56f8 | 2020-08-25 19:12:01 +0200 | [diff] [blame] | 432 | P( local.A[0], local.A[1], local.A[2], local.A[3], local.A[4], |
| 433 | local.A[5], local.A[6], local.A[7], local.W[i], K[i] ); |
Manuel Pégourié-Gonnard | eb0d870 | 2015-05-28 12:54:04 +0200 | [diff] [blame] | 434 | |
gabor-mezei-arm | 4cb56f8 | 2020-08-25 19:12:01 +0200 | [diff] [blame] | 435 | local.temp1 = local.A[7]; local.A[7] = local.A[6]; |
| 436 | local.A[6] = local.A[5]; local.A[5] = local.A[4]; |
| 437 | local.A[4] = local.A[3]; local.A[3] = local.A[2]; |
| 438 | local.A[2] = local.A[1]; local.A[1] = local.A[0]; |
| 439 | local.A[0] = local.temp1; |
Manuel Pégourié-Gonnard | eb0d870 | 2015-05-28 12:54:04 +0200 | [diff] [blame] | 440 | } |
| 441 | #else /* MBEDTLS_SHA256_SMALLER */ |
| 442 | for( i = 0; i < 16; i++ ) |
Joe Subbiani | 6a50631 | 2021-07-07 16:56:29 +0100 | [diff] [blame] | 443 | local.W[i] = MBEDTLS_GET_UINT32_BE( data, 4 * i ); |
Manuel Pégourié-Gonnard | eb0d870 | 2015-05-28 12:54:04 +0200 | [diff] [blame] | 444 | |
Manuel Pégourié-Gonnard | a7a3a5f | 2015-05-28 12:14:49 +0200 | [diff] [blame] | 445 | for( i = 0; i < 16; i += 8 ) |
| 446 | { |
gabor-mezei-arm | 4cb56f8 | 2020-08-25 19:12:01 +0200 | [diff] [blame] | 447 | P( local.A[0], local.A[1], local.A[2], local.A[3], local.A[4], |
| 448 | local.A[5], local.A[6], local.A[7], local.W[i+0], K[i+0] ); |
| 449 | P( local.A[7], local.A[0], local.A[1], local.A[2], local.A[3], |
| 450 | local.A[4], local.A[5], local.A[6], local.W[i+1], K[i+1] ); |
| 451 | P( local.A[6], local.A[7], local.A[0], local.A[1], local.A[2], |
| 452 | local.A[3], local.A[4], local.A[5], local.W[i+2], K[i+2] ); |
| 453 | P( local.A[5], local.A[6], local.A[7], local.A[0], local.A[1], |
| 454 | local.A[2], local.A[3], local.A[4], local.W[i+3], K[i+3] ); |
| 455 | P( local.A[4], local.A[5], local.A[6], local.A[7], local.A[0], |
| 456 | local.A[1], local.A[2], local.A[3], local.W[i+4], K[i+4] ); |
| 457 | P( local.A[3], local.A[4], local.A[5], local.A[6], local.A[7], |
| 458 | local.A[0], local.A[1], local.A[2], local.W[i+5], K[i+5] ); |
| 459 | P( local.A[2], local.A[3], local.A[4], local.A[5], local.A[6], |
| 460 | local.A[7], local.A[0], local.A[1], local.W[i+6], K[i+6] ); |
| 461 | P( local.A[1], local.A[2], local.A[3], local.A[4], local.A[5], |
| 462 | local.A[6], local.A[7], local.A[0], local.W[i+7], K[i+7] ); |
Manuel Pégourié-Gonnard | a7a3a5f | 2015-05-28 12:14:49 +0200 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | for( i = 16; i < 64; i += 8 ) |
| 466 | { |
gabor-mezei-arm | 4cb56f8 | 2020-08-25 19:12:01 +0200 | [diff] [blame] | 467 | P( local.A[0], local.A[1], local.A[2], local.A[3], local.A[4], |
| 468 | local.A[5], local.A[6], local.A[7], R(i+0), K[i+0] ); |
| 469 | P( local.A[7], local.A[0], local.A[1], local.A[2], local.A[3], |
| 470 | local.A[4], local.A[5], local.A[6], R(i+1), K[i+1] ); |
| 471 | P( local.A[6], local.A[7], local.A[0], local.A[1], local.A[2], |
| 472 | local.A[3], local.A[4], local.A[5], R(i+2), K[i+2] ); |
| 473 | P( local.A[5], local.A[6], local.A[7], local.A[0], local.A[1], |
| 474 | local.A[2], local.A[3], local.A[4], R(i+3), K[i+3] ); |
| 475 | P( local.A[4], local.A[5], local.A[6], local.A[7], local.A[0], |
| 476 | local.A[1], local.A[2], local.A[3], R(i+4), K[i+4] ); |
| 477 | P( local.A[3], local.A[4], local.A[5], local.A[6], local.A[7], |
| 478 | local.A[0], local.A[1], local.A[2], R(i+5), K[i+5] ); |
| 479 | P( local.A[2], local.A[3], local.A[4], local.A[5], local.A[6], |
| 480 | local.A[7], local.A[0], local.A[1], R(i+6), K[i+6] ); |
| 481 | P( local.A[1], local.A[2], local.A[3], local.A[4], local.A[5], |
| 482 | local.A[6], local.A[7], local.A[0], R(i+7), K[i+7] ); |
Manuel Pégourié-Gonnard | a7a3a5f | 2015-05-28 12:14:49 +0200 | [diff] [blame] | 483 | } |
Manuel Pégourié-Gonnard | eb0d870 | 2015-05-28 12:54:04 +0200 | [diff] [blame] | 484 | #endif /* MBEDTLS_SHA256_SMALLER */ |
Manuel Pégourié-Gonnard | a7a3a5f | 2015-05-28 12:14:49 +0200 | [diff] [blame] | 485 | |
| 486 | for( i = 0; i < 8; i++ ) |
gabor-mezei-arm | 4cb56f8 | 2020-08-25 19:12:01 +0200 | [diff] [blame] | 487 | ctx->state[i] += local.A[i]; |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 488 | |
gabor-mezei-arm | 76749ae | 2020-07-30 16:41:25 +0200 | [diff] [blame] | 489 | /* Zeroise buffers and variables to clear sensitive data from memory. */ |
gabor-mezei-arm | 4cb56f8 | 2020-08-25 19:12:01 +0200 | [diff] [blame] | 490 | mbedtls_platform_zeroize( &local, sizeof( local ) ); |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 491 | |
| 492 | return( 0 ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 493 | } |
Jaeden Amero | 041039f | 2018-02-19 15:28:08 +0000 | [diff] [blame] | 494 | |
Tom Cosgrove | f3ebd90 | 2022-02-20 22:25:31 +0000 | [diff] [blame] | 495 | #endif /* !MBEDTLS_SHA256_PROCESS_ALT && !MBEDTLS_SHA256_USE_A64_CRYPTO_ONLY */ |
| 496 | |
| 497 | |
| 498 | #if !defined(MBEDTLS_SHA256_USE_A64_CRYPTO_ONLY) |
| 499 | |
| 500 | static size_t mbedtls_internal_sha256_process_many_c( |
| 501 | mbedtls_sha256_context *ctx, const uint8_t *data, size_t len ) |
| 502 | { |
| 503 | size_t processed = 0; |
| 504 | |
| 505 | while( len >= SHA256_BLOCK_SIZE ) |
| 506 | { |
| 507 | if( mbedtls_internal_sha256_process_c( ctx, data ) != 0 ) |
| 508 | return( 0 ); |
| 509 | |
| 510 | data += SHA256_BLOCK_SIZE; |
| 511 | len -= SHA256_BLOCK_SIZE; |
| 512 | |
| 513 | processed += SHA256_BLOCK_SIZE; |
| 514 | } |
| 515 | |
| 516 | return( processed ); |
| 517 | } |
| 518 | |
| 519 | #endif /* !MBEDTLS_SHA256_USE_A64_CRYPTO_ONLY */ |
| 520 | |
| 521 | |
| 522 | #if defined(MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT) |
| 523 | |
| 524 | static int mbedtls_a64_crypto_sha256_has_support( void ) |
| 525 | { |
| 526 | static int done = 0; |
| 527 | static int supported = 0; |
| 528 | |
| 529 | if( !done ) |
| 530 | { |
Tom Cosgrove | 7e7aba8 | 2022-02-24 08:33:11 +0000 | [diff] [blame] | 531 | supported = mbedtls_a64_crypto_sha256_determine_support(); |
Tom Cosgrove | f3ebd90 | 2022-02-20 22:25:31 +0000 | [diff] [blame] | 532 | done = 1; |
| 533 | } |
| 534 | |
| 535 | return( supported ); |
| 536 | } |
| 537 | |
| 538 | static size_t mbedtls_internal_sha256_process_many( mbedtls_sha256_context *ctx, |
| 539 | const uint8_t *msg, size_t len ) |
| 540 | { |
| 541 | if( mbedtls_a64_crypto_sha256_has_support() ) |
| 542 | return( mbedtls_internal_sha256_process_many_a64_crypto( ctx, msg, len ) ); |
| 543 | else |
| 544 | return( mbedtls_internal_sha256_process_many_c( ctx, msg, len ) ); |
| 545 | } |
| 546 | |
| 547 | int mbedtls_internal_sha256_process( mbedtls_sha256_context *ctx, |
| 548 | const unsigned char data[SHA256_BLOCK_SIZE] ) |
| 549 | { |
| 550 | if( mbedtls_a64_crypto_sha256_has_support() ) |
| 551 | return( mbedtls_internal_sha256_process_a64_crypto( ctx, data ) ); |
| 552 | else |
| 553 | return( mbedtls_internal_sha256_process_c( ctx, data ) ); |
| 554 | } |
| 555 | |
| 556 | #endif /* MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT */ |
| 557 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 558 | |
| 559 | /* |
| 560 | * SHA-256 process buffer |
| 561 | */ |
TRodziewicz | 26371e4 | 2021-06-08 16:45:41 +0200 | [diff] [blame] | 562 | int mbedtls_sha256_update( mbedtls_sha256_context *ctx, |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 563 | const unsigned char *input, |
| 564 | size_t ilen ) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 565 | { |
Janos Follath | 24eed8d | 2019-11-22 13:21:35 +0000 | [diff] [blame] | 566 | int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 567 | size_t fill; |
Paul Bakker | 5c2364c | 2012-10-01 14:41:15 +0000 | [diff] [blame] | 568 | uint32_t left; |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 569 | |
Brian White | 12895d1 | 2014-04-11 11:29:42 -0400 | [diff] [blame] | 570 | if( ilen == 0 ) |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 571 | return( 0 ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 572 | |
| 573 | left = ctx->total[0] & 0x3F; |
Tom Cosgrove | f3ebd90 | 2022-02-20 22:25:31 +0000 | [diff] [blame] | 574 | fill = SHA256_BLOCK_SIZE - left; |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 575 | |
Paul Bakker | 5c2364c | 2012-10-01 14:41:15 +0000 | [diff] [blame] | 576 | ctx->total[0] += (uint32_t) ilen; |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 577 | ctx->total[0] &= 0xFFFFFFFF; |
| 578 | |
Paul Bakker | 5c2364c | 2012-10-01 14:41:15 +0000 | [diff] [blame] | 579 | if( ctx->total[0] < (uint32_t) ilen ) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 580 | ctx->total[1]++; |
| 581 | |
| 582 | if( left && ilen >= fill ) |
| 583 | { |
Paul Bakker | 3c2122f | 2013-06-24 19:03:14 +0200 | [diff] [blame] | 584 | memcpy( (void *) (ctx->buffer + left), input, fill ); |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 585 | |
Andres Amaya Garcia | cccfe08 | 2017-06-28 10:36:39 +0100 | [diff] [blame] | 586 | if( ( ret = mbedtls_internal_sha256_process( ctx, ctx->buffer ) ) != 0 ) |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 587 | return( ret ); |
| 588 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 589 | input += fill; |
| 590 | ilen -= fill; |
| 591 | left = 0; |
| 592 | } |
| 593 | |
Tom Cosgrove | f3ebd90 | 2022-02-20 22:25:31 +0000 | [diff] [blame] | 594 | while( ilen >= SHA256_BLOCK_SIZE ) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 595 | { |
Tom Cosgrove | f3ebd90 | 2022-02-20 22:25:31 +0000 | [diff] [blame] | 596 | size_t processed = |
| 597 | mbedtls_internal_sha256_process_many( ctx, input, ilen ); |
| 598 | if( processed < SHA256_BLOCK_SIZE ) |
| 599 | return( MBEDTLS_ERR_ERROR_GENERIC_ERROR ); |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 600 | |
Tom Cosgrove | f3ebd90 | 2022-02-20 22:25:31 +0000 | [diff] [blame] | 601 | input += processed; |
| 602 | ilen -= processed; |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 603 | } |
| 604 | |
| 605 | if( ilen > 0 ) |
Paul Bakker | 3c2122f | 2013-06-24 19:03:14 +0200 | [diff] [blame] | 606 | memcpy( (void *) (ctx->buffer + left), input, ilen ); |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 607 | |
| 608 | return( 0 ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 609 | } |
| 610 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 611 | /* |
| 612 | * SHA-256 final digest |
| 613 | */ |
TRodziewicz | 26371e4 | 2021-06-08 16:45:41 +0200 | [diff] [blame] | 614 | int mbedtls_sha256_finish( mbedtls_sha256_context *ctx, |
Gilles Peskine | d7b3d92 | 2021-05-13 00:45:25 +0200 | [diff] [blame] | 615 | unsigned char *output ) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 616 | { |
Janos Follath | 24eed8d | 2019-11-22 13:21:35 +0000 | [diff] [blame] | 617 | int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; |
Manuel Pégourié-Gonnard | 1cc1fb0 | 2018-06-28 12:10:27 +0200 | [diff] [blame] | 618 | uint32_t used; |
Paul Bakker | 5c2364c | 2012-10-01 14:41:15 +0000 | [diff] [blame] | 619 | uint32_t high, low; |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 620 | |
Manuel Pégourié-Gonnard | 1cc1fb0 | 2018-06-28 12:10:27 +0200 | [diff] [blame] | 621 | /* |
| 622 | * Add padding: 0x80 then 0x00 until 8 bytes remain for the length |
| 623 | */ |
| 624 | used = ctx->total[0] & 0x3F; |
| 625 | |
| 626 | ctx->buffer[used++] = 0x80; |
| 627 | |
| 628 | if( used <= 56 ) |
| 629 | { |
| 630 | /* Enough room for padding + length in current block */ |
| 631 | memset( ctx->buffer + used, 0, 56 - used ); |
| 632 | } |
| 633 | else |
| 634 | { |
| 635 | /* We'll need an extra block */ |
Tom Cosgrove | f3ebd90 | 2022-02-20 22:25:31 +0000 | [diff] [blame] | 636 | memset( ctx->buffer + used, 0, SHA256_BLOCK_SIZE - used ); |
Manuel Pégourié-Gonnard | 1cc1fb0 | 2018-06-28 12:10:27 +0200 | [diff] [blame] | 637 | |
| 638 | if( ( ret = mbedtls_internal_sha256_process( ctx, ctx->buffer ) ) != 0 ) |
| 639 | return( ret ); |
| 640 | |
| 641 | memset( ctx->buffer, 0, 56 ); |
| 642 | } |
| 643 | |
| 644 | /* |
| 645 | * Add message length |
| 646 | */ |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 647 | high = ( ctx->total[0] >> 29 ) |
| 648 | | ( ctx->total[1] << 3 ); |
| 649 | low = ( ctx->total[0] << 3 ); |
| 650 | |
Joe Subbiani | 5ecac21 | 2021-06-24 13:00:03 +0100 | [diff] [blame] | 651 | MBEDTLS_PUT_UINT32_BE( high, ctx->buffer, 56 ); |
| 652 | MBEDTLS_PUT_UINT32_BE( low, ctx->buffer, 60 ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 653 | |
Manuel Pégourié-Gonnard | 1cc1fb0 | 2018-06-28 12:10:27 +0200 | [diff] [blame] | 654 | if( ( ret = mbedtls_internal_sha256_process( ctx, ctx->buffer ) ) != 0 ) |
Andres Amaya Garcia | aa464ef | 2017-07-21 14:21:53 +0100 | [diff] [blame] | 655 | return( ret ); |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 656 | |
Manuel Pégourié-Gonnard | 1cc1fb0 | 2018-06-28 12:10:27 +0200 | [diff] [blame] | 657 | /* |
| 658 | * Output final state |
| 659 | */ |
Joe Subbiani | 5ecac21 | 2021-06-24 13:00:03 +0100 | [diff] [blame] | 660 | MBEDTLS_PUT_UINT32_BE( ctx->state[0], output, 0 ); |
| 661 | MBEDTLS_PUT_UINT32_BE( ctx->state[1], output, 4 ); |
| 662 | MBEDTLS_PUT_UINT32_BE( ctx->state[2], output, 8 ); |
| 663 | MBEDTLS_PUT_UINT32_BE( ctx->state[3], output, 12 ); |
| 664 | MBEDTLS_PUT_UINT32_BE( ctx->state[4], output, 16 ); |
| 665 | MBEDTLS_PUT_UINT32_BE( ctx->state[5], output, 20 ); |
| 666 | MBEDTLS_PUT_UINT32_BE( ctx->state[6], output, 24 ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 667 | |
Mateusz Starzyk | e3c48b4 | 2021-04-19 16:46:28 +0200 | [diff] [blame] | 668 | #if defined(MBEDTLS_SHA224_C) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 669 | if( ctx->is224 == 0 ) |
Mateusz Starzyk | e3c48b4 | 2021-04-19 16:46:28 +0200 | [diff] [blame] | 670 | #endif |
Joe Subbiani | 5ecac21 | 2021-06-24 13:00:03 +0100 | [diff] [blame] | 671 | MBEDTLS_PUT_UINT32_BE( ctx->state[7], output, 28 ); |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 672 | |
| 673 | return( 0 ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 674 | } |
| 675 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 676 | #endif /* !MBEDTLS_SHA256_ALT */ |
Paul Bakker | 90995b5 | 2013-06-24 19:20:35 +0200 | [diff] [blame] | 677 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 678 | /* |
| 679 | * output = SHA-256( input buffer ) |
| 680 | */ |
TRodziewicz | 26371e4 | 2021-06-08 16:45:41 +0200 | [diff] [blame] | 681 | int mbedtls_sha256( const unsigned char *input, |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 682 | size_t ilen, |
Gilles Peskine | d7b3d92 | 2021-05-13 00:45:25 +0200 | [diff] [blame] | 683 | unsigned char *output, |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 684 | int is224 ) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 685 | { |
Janos Follath | 24eed8d | 2019-11-22 13:21:35 +0000 | [diff] [blame] | 686 | int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 687 | mbedtls_sha256_context ctx; |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 688 | |
Mateusz Starzyk | e3c48b4 | 2021-04-19 16:46:28 +0200 | [diff] [blame] | 689 | #if defined(MBEDTLS_SHA224_C) |
Tuvshinzaya Erdenekhuu | 696dfb6 | 2022-08-05 15:59:19 +0100 | [diff] [blame] | 690 | if( is224 != 0 && is224 != 1 ) |
| 691 | return MBEDTLS_ERR_SHA256_BAD_INPUT_DATA; |
Mateusz Starzyk | e3c48b4 | 2021-04-19 16:46:28 +0200 | [diff] [blame] | 692 | #else |
Tuvshinzaya Erdenekhuu | 696dfb6 | 2022-08-05 15:59:19 +0100 | [diff] [blame] | 693 | if( is224 != 0 ) |
| 694 | return MBEDTLS_ERR_SHA256_BAD_INPUT_DATA; |
Mateusz Starzyk | e3c48b4 | 2021-04-19 16:46:28 +0200 | [diff] [blame] | 695 | #endif |
| 696 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 697 | mbedtls_sha256_init( &ctx ); |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 698 | |
TRodziewicz | 26371e4 | 2021-06-08 16:45:41 +0200 | [diff] [blame] | 699 | if( ( ret = mbedtls_sha256_starts( &ctx, is224 ) ) != 0 ) |
Andres Amaya Garcia | 0963e6c | 2017-07-20 14:34:08 +0100 | [diff] [blame] | 700 | goto exit; |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 701 | |
TRodziewicz | 26371e4 | 2021-06-08 16:45:41 +0200 | [diff] [blame] | 702 | if( ( ret = mbedtls_sha256_update( &ctx, input, ilen ) ) != 0 ) |
Andres Amaya Garcia | 0963e6c | 2017-07-20 14:34:08 +0100 | [diff] [blame] | 703 | goto exit; |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 704 | |
TRodziewicz | 26371e4 | 2021-06-08 16:45:41 +0200 | [diff] [blame] | 705 | if( ( ret = mbedtls_sha256_finish( &ctx, output ) ) != 0 ) |
Andres Amaya Garcia | 0963e6c | 2017-07-20 14:34:08 +0100 | [diff] [blame] | 706 | goto exit; |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 707 | |
Andres Amaya Garcia | 0963e6c | 2017-07-20 14:34:08 +0100 | [diff] [blame] | 708 | exit: |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 709 | mbedtls_sha256_free( &ctx ); |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 710 | |
Andres Amaya Garcia | 0963e6c | 2017-07-20 14:34:08 +0100 | [diff] [blame] | 711 | return( ret ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 712 | } |
| 713 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 714 | #if defined(MBEDTLS_SELF_TEST) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 715 | /* |
| 716 | * FIPS-180-2 test vectors |
| 717 | */ |
Manuel Pégourié-Gonnard | 28122e4 | 2015-03-11 09:13:42 +0000 | [diff] [blame] | 718 | static const unsigned char sha256_test_buf[3][57] = |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 719 | { |
| 720 | { "abc" }, |
| 721 | { "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" }, |
| 722 | { "" } |
| 723 | }; |
| 724 | |
Andres Amaya Garcia | 2d0aa8b | 2017-07-21 14:57:26 +0100 | [diff] [blame] | 725 | static const size_t sha256_test_buflen[3] = |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 726 | { |
| 727 | 3, 56, 1000 |
| 728 | }; |
| 729 | |
Paul Bakker | 9e36f04 | 2013-06-30 14:34:05 +0200 | [diff] [blame] | 730 | static const unsigned char sha256_test_sum[6][32] = |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 731 | { |
| 732 | /* |
| 733 | * SHA-224 test vectors |
| 734 | */ |
| 735 | { 0x23, 0x09, 0x7D, 0x22, 0x34, 0x05, 0xD8, 0x22, |
| 736 | 0x86, 0x42, 0xA4, 0x77, 0xBD, 0xA2, 0x55, 0xB3, |
| 737 | 0x2A, 0xAD, 0xBC, 0xE4, 0xBD, 0xA0, 0xB3, 0xF7, |
| 738 | 0xE3, 0x6C, 0x9D, 0xA7 }, |
| 739 | { 0x75, 0x38, 0x8B, 0x16, 0x51, 0x27, 0x76, 0xCC, |
| 740 | 0x5D, 0xBA, 0x5D, 0xA1, 0xFD, 0x89, 0x01, 0x50, |
| 741 | 0xB0, 0xC6, 0x45, 0x5C, 0xB4, 0xF5, 0x8B, 0x19, |
| 742 | 0x52, 0x52, 0x25, 0x25 }, |
| 743 | { 0x20, 0x79, 0x46, 0x55, 0x98, 0x0C, 0x91, 0xD8, |
| 744 | 0xBB, 0xB4, 0xC1, 0xEA, 0x97, 0x61, 0x8A, 0x4B, |
| 745 | 0xF0, 0x3F, 0x42, 0x58, 0x19, 0x48, 0xB2, 0xEE, |
| 746 | 0x4E, 0xE7, 0xAD, 0x67 }, |
| 747 | |
| 748 | /* |
| 749 | * SHA-256 test vectors |
| 750 | */ |
| 751 | { 0xBA, 0x78, 0x16, 0xBF, 0x8F, 0x01, 0xCF, 0xEA, |
| 752 | 0x41, 0x41, 0x40, 0xDE, 0x5D, 0xAE, 0x22, 0x23, |
| 753 | 0xB0, 0x03, 0x61, 0xA3, 0x96, 0x17, 0x7A, 0x9C, |
| 754 | 0xB4, 0x10, 0xFF, 0x61, 0xF2, 0x00, 0x15, 0xAD }, |
| 755 | { 0x24, 0x8D, 0x6A, 0x61, 0xD2, 0x06, 0x38, 0xB8, |
| 756 | 0xE5, 0xC0, 0x26, 0x93, 0x0C, 0x3E, 0x60, 0x39, |
| 757 | 0xA3, 0x3C, 0xE4, 0x59, 0x64, 0xFF, 0x21, 0x67, |
| 758 | 0xF6, 0xEC, 0xED, 0xD4, 0x19, 0xDB, 0x06, 0xC1 }, |
| 759 | { 0xCD, 0xC7, 0x6E, 0x5C, 0x99, 0x14, 0xFB, 0x92, |
| 760 | 0x81, 0xA1, 0xC7, 0xE2, 0x84, 0xD7, 0x3E, 0x67, |
| 761 | 0xF1, 0x80, 0x9A, 0x48, 0xA4, 0x97, 0x20, 0x0E, |
| 762 | 0x04, 0x6D, 0x39, 0xCC, 0xC7, 0x11, 0x2C, 0xD0 } |
| 763 | }; |
| 764 | |
| 765 | /* |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 766 | * Checkup routine |
| 767 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 768 | int mbedtls_sha256_self_test( int verbose ) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 769 | { |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 770 | int i, j, k, buflen, ret = 0; |
Russ Butler | bb83b42 | 2016-10-12 17:36:50 -0500 | [diff] [blame] | 771 | unsigned char *buf; |
Paul Bakker | 9e36f04 | 2013-06-30 14:34:05 +0200 | [diff] [blame] | 772 | unsigned char sha256sum[32]; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 773 | mbedtls_sha256_context ctx; |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 774 | |
Russ Butler | bb83b42 | 2016-10-12 17:36:50 -0500 | [diff] [blame] | 775 | buf = mbedtls_calloc( 1024, sizeof(unsigned char) ); |
| 776 | if( NULL == buf ) |
| 777 | { |
| 778 | if( verbose != 0 ) |
| 779 | mbedtls_printf( "Buffer allocation failed\n" ); |
| 780 | |
| 781 | return( 1 ); |
| 782 | } |
| 783 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 784 | mbedtls_sha256_init( &ctx ); |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 785 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 786 | for( i = 0; i < 6; i++ ) |
| 787 | { |
| 788 | j = i % 3; |
| 789 | k = i < 3; |
| 790 | |
| 791 | if( verbose != 0 ) |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 792 | mbedtls_printf( " SHA-%d test #%d: ", 256 - k * 32, j + 1 ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 793 | |
TRodziewicz | 26371e4 | 2021-06-08 16:45:41 +0200 | [diff] [blame] | 794 | if( ( ret = mbedtls_sha256_starts( &ctx, k ) ) != 0 ) |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 795 | goto fail; |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 796 | |
| 797 | if( j == 2 ) |
| 798 | { |
| 799 | memset( buf, 'a', buflen = 1000 ); |
| 800 | |
| 801 | for( j = 0; j < 1000; j++ ) |
Andres Amaya Garcia | 6a3f305 | 2017-07-20 14:18:54 +0100 | [diff] [blame] | 802 | { |
TRodziewicz | 26371e4 | 2021-06-08 16:45:41 +0200 | [diff] [blame] | 803 | ret = mbedtls_sha256_update( &ctx, buf, buflen ); |
Andres Amaya Garcia | 6a3f305 | 2017-07-20 14:18:54 +0100 | [diff] [blame] | 804 | if( ret != 0 ) |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 805 | goto fail; |
Andres Amaya Garcia | 6a3f305 | 2017-07-20 14:18:54 +0100 | [diff] [blame] | 806 | } |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 807 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 808 | } |
| 809 | else |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 810 | { |
TRodziewicz | 26371e4 | 2021-06-08 16:45:41 +0200 | [diff] [blame] | 811 | ret = mbedtls_sha256_update( &ctx, sha256_test_buf[j], |
Andres Amaya Garcia | 6a3f305 | 2017-07-20 14:18:54 +0100 | [diff] [blame] | 812 | sha256_test_buflen[j] ); |
| 813 | if( ret != 0 ) |
| 814 | goto fail; |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 815 | } |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 816 | |
TRodziewicz | 26371e4 | 2021-06-08 16:45:41 +0200 | [diff] [blame] | 817 | if( ( ret = mbedtls_sha256_finish( &ctx, sha256sum ) ) != 0 ) |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 818 | goto fail; |
| 819 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 820 | |
Paul Bakker | 9e36f04 | 2013-06-30 14:34:05 +0200 | [diff] [blame] | 821 | if( memcmp( sha256sum, sha256_test_sum[i], 32 - k * 4 ) != 0 ) |
Andres Amaya Garcia | 6a3f305 | 2017-07-20 14:18:54 +0100 | [diff] [blame] | 822 | { |
| 823 | ret = 1; |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 824 | goto fail; |
Andres Amaya Garcia | 6a3f305 | 2017-07-20 14:18:54 +0100 | [diff] [blame] | 825 | } |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 826 | |
| 827 | if( verbose != 0 ) |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 828 | mbedtls_printf( "passed\n" ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 829 | } |
| 830 | |
| 831 | if( verbose != 0 ) |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 832 | mbedtls_printf( "\n" ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 833 | |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 834 | goto exit; |
| 835 | |
| 836 | fail: |
| 837 | if( verbose != 0 ) |
| 838 | mbedtls_printf( "failed\n" ); |
| 839 | |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 840 | exit: |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 841 | mbedtls_sha256_free( &ctx ); |
Russ Butler | bb83b42 | 2016-10-12 17:36:50 -0500 | [diff] [blame] | 842 | mbedtls_free( buf ); |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 843 | |
| 844 | return( ret ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 845 | } |
| 846 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 847 | #endif /* MBEDTLS_SELF_TEST */ |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 848 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 849 | #endif /* MBEDTLS_SHA256_C */ |