Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 1 | /** |
| 2 | * \file md_wrap.c |
Manuel Pégourié-Gonnard | 1bab7d7 | 2015-07-13 09:06:18 +0100 | [diff] [blame] | 3 | * |
Manuel Pégourié-Gonnard | b4fe3cb | 2015-01-22 16:11:05 +0000 | [diff] [blame] | 4 | * \brief Generic message digest wrapper for mbed TLS |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 5 | * |
| 6 | * \author Adriaan de Jong <dejong@fox-it.com> |
| 7 | * |
Manuel Pégourié-Gonnard | 6fb8187 | 2015-07-27 11:11:48 +0200 | [diff] [blame] | 8 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved |
Manuel Pégourié-Gonnard | 37ff140 | 2015-09-04 14:21:07 +0200 | [diff] [blame] | 9 | * SPDX-License-Identifier: Apache-2.0 |
| 10 | * |
| 11 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 12 | * not use this file except in compliance with the License. |
| 13 | * You may obtain a copy of the License at |
| 14 | * |
| 15 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 16 | * |
| 17 | * Unless required by applicable law or agreed to in writing, software |
| 18 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 19 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 20 | * See the License for the specific language governing permissions and |
| 21 | * limitations under the License. |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 22 | * |
Manuel Pégourié-Gonnard | fe44643 | 2015-03-06 13:17:10 +0000 | [diff] [blame] | 23 | * This file is part of mbed TLS (https://tls.mbed.org) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 24 | */ |
| 25 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 26 | #if !defined(MBEDTLS_CONFIG_FILE) |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 27 | #include "mbedtls/config.h" |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 28 | #else |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 29 | #include MBEDTLS_CONFIG_FILE |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 30 | #endif |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 31 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 32 | #if defined(MBEDTLS_MD_C) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 33 | |
Manuel Pégourié-Gonnard | 50518f4 | 2015-05-26 11:04:15 +0200 | [diff] [blame] | 34 | #include "mbedtls/md_internal.h" |
Paul Bakker | f654371 | 2012-03-05 14:01:29 +0000 | [diff] [blame] | 35 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 36 | #if defined(MBEDTLS_MD2_C) |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 37 | #include "mbedtls/md2.h" |
Paul Bakker | f654371 | 2012-03-05 14:01:29 +0000 | [diff] [blame] | 38 | #endif |
| 39 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 40 | #if defined(MBEDTLS_MD4_C) |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 41 | #include "mbedtls/md4.h" |
Paul Bakker | f654371 | 2012-03-05 14:01:29 +0000 | [diff] [blame] | 42 | #endif |
| 43 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 44 | #if defined(MBEDTLS_MD5_C) |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 45 | #include "mbedtls/md5.h" |
Paul Bakker | f654371 | 2012-03-05 14:01:29 +0000 | [diff] [blame] | 46 | #endif |
| 47 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 48 | #if defined(MBEDTLS_RIPEMD160_C) |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 49 | #include "mbedtls/ripemd160.h" |
Manuel Pégourié-Gonnard | e4d47a6 | 2014-01-17 20:41:32 +0100 | [diff] [blame] | 50 | #endif |
| 51 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 52 | #if defined(MBEDTLS_SHA1_C) |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 53 | #include "mbedtls/sha1.h" |
Paul Bakker | f654371 | 2012-03-05 14:01:29 +0000 | [diff] [blame] | 54 | #endif |
| 55 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 56 | #if defined(MBEDTLS_SHA256_C) |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 57 | #include "mbedtls/sha256.h" |
Paul Bakker | f654371 | 2012-03-05 14:01:29 +0000 | [diff] [blame] | 58 | #endif |
| 59 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 60 | #if defined(MBEDTLS_SHA512_C) |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 61 | #include "mbedtls/sha512.h" |
Paul Bakker | f654371 | 2012-03-05 14:01:29 +0000 | [diff] [blame] | 62 | #endif |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 63 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 64 | #if defined(MBEDTLS_PLATFORM_C) |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 65 | #include "mbedtls/platform.h" |
Paul Bakker | 6e339b5 | 2013-07-03 13:37:05 +0200 | [diff] [blame] | 66 | #else |
Rich Evans | 00ab470 | 2015-02-06 13:43:58 +0000 | [diff] [blame] | 67 | #include <stdlib.h> |
Manuel Pégourié-Gonnard | 7551cb9 | 2015-05-26 16:04:06 +0200 | [diff] [blame] | 68 | #define mbedtls_calloc calloc |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 69 | #define mbedtls_free free |
Paul Bakker | 6e339b5 | 2013-07-03 13:37:05 +0200 | [diff] [blame] | 70 | #endif |
| 71 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 72 | #if defined(MBEDTLS_MD2_C) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 73 | |
Andres Amaya Garcia | 5f872df | 2017-06-28 14:12:44 +0100 | [diff] [blame] | 74 | static int md2_starts_wrap( void *ctx ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 75 | { |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 76 | return( mbedtls_md2_starts_ret( (mbedtls_md2_context *) ctx ) ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 77 | } |
| 78 | |
Andres Amaya Garcia | 5f872df | 2017-06-28 14:12:44 +0100 | [diff] [blame] | 79 | static int md2_update_wrap( void *ctx, const unsigned char *input, |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 80 | size_t ilen ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 81 | { |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 82 | return( mbedtls_md2_update_ret( (mbedtls_md2_context *) ctx, input, ilen ) ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 83 | } |
| 84 | |
Andres Amaya Garcia | 5f872df | 2017-06-28 14:12:44 +0100 | [diff] [blame] | 85 | static int md2_finish_wrap( void *ctx, unsigned char *output ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 86 | { |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 87 | return( mbedtls_md2_finish_ret( (mbedtls_md2_context *) ctx, output ) ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 88 | } |
| 89 | |
Manuel Pégourié-Gonnard | ab59321 | 2015-06-23 11:30:47 +0200 | [diff] [blame] | 90 | static void *md2_ctx_alloc( void ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 91 | { |
Manuel Pégourié-Gonnard | ab59321 | 2015-06-23 11:30:47 +0200 | [diff] [blame] | 92 | void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_md2_context ) ); |
| 93 | |
| 94 | if( ctx != NULL ) |
| 95 | mbedtls_md2_init( (mbedtls_md2_context *) ctx ); |
| 96 | |
| 97 | return( ctx ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | static void md2_ctx_free( void *ctx ) |
| 101 | { |
Manuel Pégourié-Gonnard | 71d296a | 2015-07-06 11:27:12 +0200 | [diff] [blame] | 102 | mbedtls_md2_free( (mbedtls_md2_context *) ctx ); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 103 | mbedtls_free( ctx ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 104 | } |
| 105 | |
Manuel Pégourié-Gonnard | 052a6c9 | 2015-07-06 16:06:02 +0200 | [diff] [blame] | 106 | static void md2_clone_wrap( void *dst, const void *src ) |
| 107 | { |
| 108 | mbedtls_md2_clone( (mbedtls_md2_context *) dst, |
| 109 | (const mbedtls_md2_context *) src ); |
| 110 | } |
| 111 | |
Andres Amaya Garcia | 5f872df | 2017-06-28 14:12:44 +0100 | [diff] [blame] | 112 | static int md2_process_wrap( void *ctx, const unsigned char *data ) |
Paul Bakker | 1bd3ae8 | 2013-03-13 10:26:44 +0100 | [diff] [blame] | 113 | { |
| 114 | ((void) data); |
| 115 | |
Andres Amaya Garcia | 5f872df | 2017-06-28 14:12:44 +0100 | [diff] [blame] | 116 | return( mbedtls_internal_md2_process( (mbedtls_md2_context *) ctx ) ); |
Paul Bakker | 1bd3ae8 | 2013-03-13 10:26:44 +0100 | [diff] [blame] | 117 | } |
| 118 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 119 | const mbedtls_md_info_t mbedtls_md2_info = { |
| 120 | MBEDTLS_MD_MD2, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 121 | "MD2", |
| 122 | 16, |
Manuel Pégourié-Gonnard | 8379a82 | 2015-03-24 16:48:22 +0100 | [diff] [blame] | 123 | 16, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 124 | md2_starts_wrap, |
| 125 | md2_update_wrap, |
| 126 | md2_finish_wrap, |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 127 | mbedtls_md2_ret, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 128 | md2_ctx_alloc, |
| 129 | md2_ctx_free, |
Manuel Pégourié-Gonnard | 052a6c9 | 2015-07-06 16:06:02 +0200 | [diff] [blame] | 130 | md2_clone_wrap, |
Paul Bakker | 1bd3ae8 | 2013-03-13 10:26:44 +0100 | [diff] [blame] | 131 | md2_process_wrap, |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 132 | }; |
| 133 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 134 | #endif /* MBEDTLS_MD2_C */ |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 135 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 136 | #if defined(MBEDTLS_MD4_C) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 137 | |
Andres Amaya Garcia | 5f872df | 2017-06-28 14:12:44 +0100 | [diff] [blame] | 138 | static int md4_starts_wrap( void *ctx ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 139 | { |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 140 | return( mbedtls_md4_starts_ret( (mbedtls_md4_context *) ctx ) ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 141 | } |
| 142 | |
Andres Amaya Garcia | 5f872df | 2017-06-28 14:12:44 +0100 | [diff] [blame] | 143 | static int md4_update_wrap( void *ctx, const unsigned char *input, |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 144 | size_t ilen ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 145 | { |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 146 | return( mbedtls_md4_update_ret( (mbedtls_md4_context *) ctx, input, ilen ) ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 147 | } |
| 148 | |
Andres Amaya Garcia | 5f872df | 2017-06-28 14:12:44 +0100 | [diff] [blame] | 149 | static int md4_finish_wrap( void *ctx, unsigned char *output ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 150 | { |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 151 | return( mbedtls_md4_finish_ret( (mbedtls_md4_context *) ctx, output ) ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 152 | } |
| 153 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 154 | static void *md4_ctx_alloc( void ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 155 | { |
Manuel Pégourié-Gonnard | ab59321 | 2015-06-23 11:30:47 +0200 | [diff] [blame] | 156 | void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_md4_context ) ); |
| 157 | |
| 158 | if( ctx != NULL ) |
| 159 | mbedtls_md4_init( (mbedtls_md4_context *) ctx ); |
| 160 | |
| 161 | return( ctx ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 162 | } |
| 163 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 164 | static void md4_ctx_free( void *ctx ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 165 | { |
Manuel Pégourié-Gonnard | 71d296a | 2015-07-06 11:27:12 +0200 | [diff] [blame] | 166 | mbedtls_md4_free( (mbedtls_md4_context *) ctx ); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 167 | mbedtls_free( ctx ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 168 | } |
| 169 | |
Manuel Pégourié-Gonnard | 052a6c9 | 2015-07-06 16:06:02 +0200 | [diff] [blame] | 170 | static void md4_clone_wrap( void *dst, const void *src ) |
| 171 | { |
| 172 | mbedtls_md4_clone( (mbedtls_md4_context *) dst, |
Andres Amaya Garcia | 5f872df | 2017-06-28 14:12:44 +0100 | [diff] [blame] | 173 | (const mbedtls_md4_context *) src ); |
Manuel Pégourié-Gonnard | 052a6c9 | 2015-07-06 16:06:02 +0200 | [diff] [blame] | 174 | } |
| 175 | |
Andres Amaya Garcia | 5f872df | 2017-06-28 14:12:44 +0100 | [diff] [blame] | 176 | static int md4_process_wrap( void *ctx, const unsigned char *data ) |
Paul Bakker | 1bd3ae8 | 2013-03-13 10:26:44 +0100 | [diff] [blame] | 177 | { |
Andres Amaya Garcia | 5f872df | 2017-06-28 14:12:44 +0100 | [diff] [blame] | 178 | return( mbedtls_internal_md4_process( (mbedtls_md4_context *) ctx, data ) ); |
Paul Bakker | 1bd3ae8 | 2013-03-13 10:26:44 +0100 | [diff] [blame] | 179 | } |
| 180 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 181 | const mbedtls_md_info_t mbedtls_md4_info = { |
| 182 | MBEDTLS_MD_MD4, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 183 | "MD4", |
| 184 | 16, |
Manuel Pégourié-Gonnard | 8379a82 | 2015-03-24 16:48:22 +0100 | [diff] [blame] | 185 | 64, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 186 | md4_starts_wrap, |
| 187 | md4_update_wrap, |
| 188 | md4_finish_wrap, |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 189 | mbedtls_md4_ret, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 190 | md4_ctx_alloc, |
| 191 | md4_ctx_free, |
Manuel Pégourié-Gonnard | 052a6c9 | 2015-07-06 16:06:02 +0200 | [diff] [blame] | 192 | md4_clone_wrap, |
Paul Bakker | 1bd3ae8 | 2013-03-13 10:26:44 +0100 | [diff] [blame] | 193 | md4_process_wrap, |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 194 | }; |
| 195 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 196 | #endif /* MBEDTLS_MD4_C */ |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 197 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 198 | #if defined(MBEDTLS_MD5_C) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 199 | |
Andres Amaya Garcia | 5f872df | 2017-06-28 14:12:44 +0100 | [diff] [blame] | 200 | static int md5_starts_wrap( void *ctx ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 201 | { |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 202 | return( mbedtls_md5_starts_ret( (mbedtls_md5_context *) ctx ) ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 203 | } |
| 204 | |
Andres Amaya Garcia | 5f872df | 2017-06-28 14:12:44 +0100 | [diff] [blame] | 205 | static int md5_update_wrap( void *ctx, const unsigned char *input, |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 206 | size_t ilen ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 207 | { |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 208 | return( mbedtls_md5_update_ret( (mbedtls_md5_context *) ctx, input, ilen ) ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 209 | } |
| 210 | |
Andres Amaya Garcia | 5f872df | 2017-06-28 14:12:44 +0100 | [diff] [blame] | 211 | static int md5_finish_wrap( void *ctx, unsigned char *output ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 212 | { |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 213 | return( mbedtls_md5_finish_ret( (mbedtls_md5_context *) ctx, output ) ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 214 | } |
| 215 | |
Manuel Pégourié-Gonnard | ab59321 | 2015-06-23 11:30:47 +0200 | [diff] [blame] | 216 | static void *md5_ctx_alloc( void ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 217 | { |
Manuel Pégourié-Gonnard | ab59321 | 2015-06-23 11:30:47 +0200 | [diff] [blame] | 218 | void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_md5_context ) ); |
| 219 | |
| 220 | if( ctx != NULL ) |
| 221 | mbedtls_md5_init( (mbedtls_md5_context *) ctx ); |
| 222 | |
| 223 | return( ctx ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | static void md5_ctx_free( void *ctx ) |
| 227 | { |
Manuel Pégourié-Gonnard | 71d296a | 2015-07-06 11:27:12 +0200 | [diff] [blame] | 228 | mbedtls_md5_free( (mbedtls_md5_context *) ctx ); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 229 | mbedtls_free( ctx ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 230 | } |
| 231 | |
Manuel Pégourié-Gonnard | 052a6c9 | 2015-07-06 16:06:02 +0200 | [diff] [blame] | 232 | static void md5_clone_wrap( void *dst, const void *src ) |
| 233 | { |
| 234 | mbedtls_md5_clone( (mbedtls_md5_context *) dst, |
Andres Amaya Garcia | 5f872df | 2017-06-28 14:12:44 +0100 | [diff] [blame] | 235 | (const mbedtls_md5_context *) src ); |
Manuel Pégourié-Gonnard | 052a6c9 | 2015-07-06 16:06:02 +0200 | [diff] [blame] | 236 | } |
| 237 | |
Andres Amaya Garcia | 5f872df | 2017-06-28 14:12:44 +0100 | [diff] [blame] | 238 | static int md5_process_wrap( void *ctx, const unsigned char *data ) |
Paul Bakker | 1bd3ae8 | 2013-03-13 10:26:44 +0100 | [diff] [blame] | 239 | { |
Andres Amaya Garcia | 5f872df | 2017-06-28 14:12:44 +0100 | [diff] [blame] | 240 | return( mbedtls_internal_md5_process( (mbedtls_md5_context *) ctx, data ) ); |
Paul Bakker | 1bd3ae8 | 2013-03-13 10:26:44 +0100 | [diff] [blame] | 241 | } |
| 242 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 243 | const mbedtls_md_info_t mbedtls_md5_info = { |
| 244 | MBEDTLS_MD_MD5, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 245 | "MD5", |
| 246 | 16, |
Manuel Pégourié-Gonnard | 8379a82 | 2015-03-24 16:48:22 +0100 | [diff] [blame] | 247 | 64, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 248 | md5_starts_wrap, |
| 249 | md5_update_wrap, |
| 250 | md5_finish_wrap, |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 251 | mbedtls_md5_ret, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 252 | md5_ctx_alloc, |
| 253 | md5_ctx_free, |
Manuel Pégourié-Gonnard | 052a6c9 | 2015-07-06 16:06:02 +0200 | [diff] [blame] | 254 | md5_clone_wrap, |
Paul Bakker | 1bd3ae8 | 2013-03-13 10:26:44 +0100 | [diff] [blame] | 255 | md5_process_wrap, |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 256 | }; |
| 257 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 258 | #endif /* MBEDTLS_MD5_C */ |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 259 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 260 | #if defined(MBEDTLS_RIPEMD160_C) |
Manuel Pégourié-Gonnard | e4d47a6 | 2014-01-17 20:41:32 +0100 | [diff] [blame] | 261 | |
Andres Amaya Garcia | 5f872df | 2017-06-28 14:12:44 +0100 | [diff] [blame] | 262 | static int ripemd160_starts_wrap( void *ctx ) |
Manuel Pégourié-Gonnard | e4d47a6 | 2014-01-17 20:41:32 +0100 | [diff] [blame] | 263 | { |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 264 | return( mbedtls_ripemd160_starts_ret( (mbedtls_ripemd160_context *) ctx ) ); |
Manuel Pégourié-Gonnard | e4d47a6 | 2014-01-17 20:41:32 +0100 | [diff] [blame] | 265 | } |
| 266 | |
Andres Amaya Garcia | 5f872df | 2017-06-28 14:12:44 +0100 | [diff] [blame] | 267 | static int ripemd160_update_wrap( void *ctx, const unsigned char *input, |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 268 | size_t ilen ) |
Manuel Pégourié-Gonnard | e4d47a6 | 2014-01-17 20:41:32 +0100 | [diff] [blame] | 269 | { |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 270 | return( mbedtls_ripemd160_update_ret( (mbedtls_ripemd160_context *) ctx, |
Andres Amaya Garcia | 5f872df | 2017-06-28 14:12:44 +0100 | [diff] [blame] | 271 | input, ilen ) ); |
Manuel Pégourié-Gonnard | e4d47a6 | 2014-01-17 20:41:32 +0100 | [diff] [blame] | 272 | } |
| 273 | |
Andres Amaya Garcia | 5f872df | 2017-06-28 14:12:44 +0100 | [diff] [blame] | 274 | static int ripemd160_finish_wrap( void *ctx, unsigned char *output ) |
Manuel Pégourié-Gonnard | e4d47a6 | 2014-01-17 20:41:32 +0100 | [diff] [blame] | 275 | { |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 276 | return( mbedtls_ripemd160_finish_ret( (mbedtls_ripemd160_context *) ctx, |
Andres Amaya Garcia | 5f872df | 2017-06-28 14:12:44 +0100 | [diff] [blame] | 277 | output ) ); |
Manuel Pégourié-Gonnard | e4d47a6 | 2014-01-17 20:41:32 +0100 | [diff] [blame] | 278 | } |
| 279 | |
Manuel Pégourié-Gonnard | ab59321 | 2015-06-23 11:30:47 +0200 | [diff] [blame] | 280 | static void *ripemd160_ctx_alloc( void ) |
Manuel Pégourié-Gonnard | e4d47a6 | 2014-01-17 20:41:32 +0100 | [diff] [blame] | 281 | { |
Manuel Pégourié-Gonnard | ab59321 | 2015-06-23 11:30:47 +0200 | [diff] [blame] | 282 | void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_ripemd160_context ) ); |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 283 | |
Manuel Pégourié-Gonnard | ab59321 | 2015-06-23 11:30:47 +0200 | [diff] [blame] | 284 | if( ctx != NULL ) |
| 285 | mbedtls_ripemd160_init( (mbedtls_ripemd160_context *) ctx ); |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 286 | |
| 287 | return( ctx ); |
Manuel Pégourié-Gonnard | e4d47a6 | 2014-01-17 20:41:32 +0100 | [diff] [blame] | 288 | } |
| 289 | |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 290 | static void ripemd160_ctx_free( void *ctx ) |
Manuel Pégourié-Gonnard | e4d47a6 | 2014-01-17 20:41:32 +0100 | [diff] [blame] | 291 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 292 | mbedtls_ripemd160_free( (mbedtls_ripemd160_context *) ctx ); |
| 293 | mbedtls_free( ctx ); |
Manuel Pégourié-Gonnard | e4d47a6 | 2014-01-17 20:41:32 +0100 | [diff] [blame] | 294 | } |
| 295 | |
Manuel Pégourié-Gonnard | 052a6c9 | 2015-07-06 16:06:02 +0200 | [diff] [blame] | 296 | static void ripemd160_clone_wrap( void *dst, const void *src ) |
| 297 | { |
| 298 | mbedtls_ripemd160_clone( (mbedtls_ripemd160_context *) dst, |
| 299 | (const mbedtls_ripemd160_context *) src ); |
| 300 | } |
| 301 | |
Andres Amaya Garcia | 5f872df | 2017-06-28 14:12:44 +0100 | [diff] [blame] | 302 | static int ripemd160_process_wrap( void *ctx, const unsigned char *data ) |
Manuel Pégourié-Gonnard | e4d47a6 | 2014-01-17 20:41:32 +0100 | [diff] [blame] | 303 | { |
Andres Amaya Garcia | 5f872df | 2017-06-28 14:12:44 +0100 | [diff] [blame] | 304 | return( mbedtls_internal_ripemd160_process( |
| 305 | (mbedtls_ripemd160_context *) ctx, data ) ); |
Manuel Pégourié-Gonnard | e4d47a6 | 2014-01-17 20:41:32 +0100 | [diff] [blame] | 306 | } |
| 307 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 308 | const mbedtls_md_info_t mbedtls_ripemd160_info = { |
| 309 | MBEDTLS_MD_RIPEMD160, |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 310 | "RIPEMD160", |
Manuel Pégourié-Gonnard | e4d47a6 | 2014-01-17 20:41:32 +0100 | [diff] [blame] | 311 | 20, |
Manuel Pégourié-Gonnard | 8379a82 | 2015-03-24 16:48:22 +0100 | [diff] [blame] | 312 | 64, |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 313 | ripemd160_starts_wrap, |
| 314 | ripemd160_update_wrap, |
| 315 | ripemd160_finish_wrap, |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 316 | mbedtls_ripemd160_ret, |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 317 | ripemd160_ctx_alloc, |
| 318 | ripemd160_ctx_free, |
Manuel Pégourié-Gonnard | 052a6c9 | 2015-07-06 16:06:02 +0200 | [diff] [blame] | 319 | ripemd160_clone_wrap, |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 320 | ripemd160_process_wrap, |
Manuel Pégourié-Gonnard | e4d47a6 | 2014-01-17 20:41:32 +0100 | [diff] [blame] | 321 | }; |
| 322 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 323 | #endif /* MBEDTLS_RIPEMD160_C */ |
Manuel Pégourié-Gonnard | e4d47a6 | 2014-01-17 20:41:32 +0100 | [diff] [blame] | 324 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 325 | #if defined(MBEDTLS_SHA1_C) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 326 | |
Andres Amaya Garcia | 5f872df | 2017-06-28 14:12:44 +0100 | [diff] [blame] | 327 | static int sha1_starts_wrap( void *ctx ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 328 | { |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 329 | return( mbedtls_sha1_starts_ret( (mbedtls_sha1_context *) ctx ) ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 330 | } |
| 331 | |
Andres Amaya Garcia | 5f872df | 2017-06-28 14:12:44 +0100 | [diff] [blame] | 332 | static int sha1_update_wrap( void *ctx, const unsigned char *input, |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 333 | size_t ilen ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 334 | { |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 335 | return( mbedtls_sha1_update_ret( (mbedtls_sha1_context *) ctx, |
Andres Amaya Garcia | 5f872df | 2017-06-28 14:12:44 +0100 | [diff] [blame] | 336 | input, ilen ) ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 337 | } |
| 338 | |
Andres Amaya Garcia | 5f872df | 2017-06-28 14:12:44 +0100 | [diff] [blame] | 339 | static int sha1_finish_wrap( void *ctx, unsigned char *output ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 340 | { |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 341 | return( mbedtls_sha1_finish_ret( (mbedtls_sha1_context *) ctx, output ) ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 342 | } |
| 343 | |
Manuel Pégourié-Gonnard | ab59321 | 2015-06-23 11:30:47 +0200 | [diff] [blame] | 344 | static void *sha1_ctx_alloc( void ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 345 | { |
Manuel Pégourié-Gonnard | ab59321 | 2015-06-23 11:30:47 +0200 | [diff] [blame] | 346 | void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_sha1_context ) ); |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 347 | |
Manuel Pégourié-Gonnard | ab59321 | 2015-06-23 11:30:47 +0200 | [diff] [blame] | 348 | if( ctx != NULL ) |
| 349 | mbedtls_sha1_init( (mbedtls_sha1_context *) ctx ); |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 350 | |
| 351 | return( ctx ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 352 | } |
| 353 | |
Manuel Pégourié-Gonnard | 052a6c9 | 2015-07-06 16:06:02 +0200 | [diff] [blame] | 354 | static void sha1_clone_wrap( void *dst, const void *src ) |
| 355 | { |
| 356 | mbedtls_sha1_clone( (mbedtls_sha1_context *) dst, |
| 357 | (const mbedtls_sha1_context *) src ); |
| 358 | } |
| 359 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 360 | static void sha1_ctx_free( void *ctx ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 361 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 362 | mbedtls_sha1_free( (mbedtls_sha1_context *) ctx ); |
| 363 | mbedtls_free( ctx ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 364 | } |
| 365 | |
Andres Amaya Garcia | 5f872df | 2017-06-28 14:12:44 +0100 | [diff] [blame] | 366 | static int sha1_process_wrap( void *ctx, const unsigned char *data ) |
Paul Bakker | 1bd3ae8 | 2013-03-13 10:26:44 +0100 | [diff] [blame] | 367 | { |
Andres Amaya Garcia | 5f872df | 2017-06-28 14:12:44 +0100 | [diff] [blame] | 368 | return( mbedtls_internal_sha1_process( (mbedtls_sha1_context *) ctx, |
| 369 | data ) ); |
Paul Bakker | 1bd3ae8 | 2013-03-13 10:26:44 +0100 | [diff] [blame] | 370 | } |
| 371 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 372 | const mbedtls_md_info_t mbedtls_sha1_info = { |
| 373 | MBEDTLS_MD_SHA1, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 374 | "SHA1", |
| 375 | 20, |
Manuel Pégourié-Gonnard | 8379a82 | 2015-03-24 16:48:22 +0100 | [diff] [blame] | 376 | 64, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 377 | sha1_starts_wrap, |
| 378 | sha1_update_wrap, |
| 379 | sha1_finish_wrap, |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 380 | mbedtls_sha1_ret, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 381 | sha1_ctx_alloc, |
| 382 | sha1_ctx_free, |
Manuel Pégourié-Gonnard | 052a6c9 | 2015-07-06 16:06:02 +0200 | [diff] [blame] | 383 | sha1_clone_wrap, |
Paul Bakker | 1bd3ae8 | 2013-03-13 10:26:44 +0100 | [diff] [blame] | 384 | sha1_process_wrap, |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 385 | }; |
| 386 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 387 | #endif /* MBEDTLS_SHA1_C */ |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 388 | |
| 389 | /* |
| 390 | * Wrappers for generic message digests |
| 391 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 392 | #if defined(MBEDTLS_SHA256_C) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 393 | |
Andres Amaya Garcia | 5f872df | 2017-06-28 14:12:44 +0100 | [diff] [blame] | 394 | static int sha224_starts_wrap( void *ctx ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 395 | { |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 396 | return( mbedtls_sha256_starts_ret( (mbedtls_sha256_context *) ctx, 1 ) ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 397 | } |
| 398 | |
Andres Amaya Garcia | 5f872df | 2017-06-28 14:12:44 +0100 | [diff] [blame] | 399 | static int sha224_update_wrap( void *ctx, const unsigned char *input, |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 400 | size_t ilen ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 401 | { |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 402 | return( mbedtls_sha256_update_ret( (mbedtls_sha256_context *) ctx, |
Andres Amaya Garcia | 5f872df | 2017-06-28 14:12:44 +0100 | [diff] [blame] | 403 | input, ilen ) ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 404 | } |
| 405 | |
Andres Amaya Garcia | 5f872df | 2017-06-28 14:12:44 +0100 | [diff] [blame] | 406 | static int sha224_finish_wrap( void *ctx, unsigned char *output ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 407 | { |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 408 | return( mbedtls_sha256_finish_ret( (mbedtls_sha256_context *) ctx, |
Andres Amaya Garcia | 5f872df | 2017-06-28 14:12:44 +0100 | [diff] [blame] | 409 | output ) ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 410 | } |
| 411 | |
Andres Amaya Garcia | 5f872df | 2017-06-28 14:12:44 +0100 | [diff] [blame] | 412 | static int sha224_wrap( const unsigned char *input, size_t ilen, |
| 413 | unsigned char *output ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 414 | { |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 415 | return( mbedtls_sha256_ret( input, ilen, output, 1 ) ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 416 | } |
| 417 | |
Manuel Pégourié-Gonnard | ab59321 | 2015-06-23 11:30:47 +0200 | [diff] [blame] | 418 | static void *sha224_ctx_alloc( void ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 419 | { |
Manuel Pégourié-Gonnard | ab59321 | 2015-06-23 11:30:47 +0200 | [diff] [blame] | 420 | void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_sha256_context ) ); |
| 421 | |
| 422 | if( ctx != NULL ) |
| 423 | mbedtls_sha256_init( (mbedtls_sha256_context *) ctx ); |
| 424 | |
| 425 | return( ctx ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 426 | } |
| 427 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 428 | static void sha224_ctx_free( void *ctx ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 429 | { |
Manuel Pégourié-Gonnard | 71d296a | 2015-07-06 11:27:12 +0200 | [diff] [blame] | 430 | mbedtls_sha256_free( (mbedtls_sha256_context *) ctx ); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 431 | mbedtls_free( ctx ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 432 | } |
| 433 | |
Manuel Pégourié-Gonnard | 052a6c9 | 2015-07-06 16:06:02 +0200 | [diff] [blame] | 434 | static void sha224_clone_wrap( void *dst, const void *src ) |
| 435 | { |
| 436 | mbedtls_sha256_clone( (mbedtls_sha256_context *) dst, |
| 437 | (const mbedtls_sha256_context *) src ); |
| 438 | } |
| 439 | |
Andres Amaya Garcia | 5f872df | 2017-06-28 14:12:44 +0100 | [diff] [blame] | 440 | static int sha224_process_wrap( void *ctx, const unsigned char *data ) |
Paul Bakker | 1bd3ae8 | 2013-03-13 10:26:44 +0100 | [diff] [blame] | 441 | { |
Andres Amaya Garcia | 5f872df | 2017-06-28 14:12:44 +0100 | [diff] [blame] | 442 | return( mbedtls_internal_sha256_process( (mbedtls_sha256_context *) ctx, |
| 443 | data ) ); |
Paul Bakker | 1bd3ae8 | 2013-03-13 10:26:44 +0100 | [diff] [blame] | 444 | } |
| 445 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 446 | const mbedtls_md_info_t mbedtls_sha224_info = { |
| 447 | MBEDTLS_MD_SHA224, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 448 | "SHA224", |
| 449 | 28, |
Manuel Pégourié-Gonnard | 8379a82 | 2015-03-24 16:48:22 +0100 | [diff] [blame] | 450 | 64, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 451 | sha224_starts_wrap, |
| 452 | sha224_update_wrap, |
| 453 | sha224_finish_wrap, |
| 454 | sha224_wrap, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 455 | sha224_ctx_alloc, |
| 456 | sha224_ctx_free, |
Manuel Pégourié-Gonnard | 052a6c9 | 2015-07-06 16:06:02 +0200 | [diff] [blame] | 457 | sha224_clone_wrap, |
Paul Bakker | 1bd3ae8 | 2013-03-13 10:26:44 +0100 | [diff] [blame] | 458 | sha224_process_wrap, |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 459 | }; |
| 460 | |
Andres Amaya Garcia | 5f872df | 2017-06-28 14:12:44 +0100 | [diff] [blame] | 461 | static int sha256_starts_wrap( void *ctx ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 462 | { |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 463 | return( mbedtls_sha256_starts_ret( (mbedtls_sha256_context *) ctx, 0 ) ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 464 | } |
| 465 | |
Andres Amaya Garcia | 5f872df | 2017-06-28 14:12:44 +0100 | [diff] [blame] | 466 | static int sha256_wrap( const unsigned char *input, size_t ilen, |
| 467 | unsigned char *output ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 468 | { |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 469 | return( mbedtls_sha256_ret( input, ilen, output, 0 ) ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 470 | } |
| 471 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 472 | const mbedtls_md_info_t mbedtls_sha256_info = { |
| 473 | MBEDTLS_MD_SHA256, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 474 | "SHA256", |
| 475 | 32, |
Manuel Pégourié-Gonnard | 8379a82 | 2015-03-24 16:48:22 +0100 | [diff] [blame] | 476 | 64, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 477 | sha256_starts_wrap, |
Manuel Pégourié-Gonnard | 496f24e | 2015-06-23 11:34:35 +0200 | [diff] [blame] | 478 | sha224_update_wrap, |
| 479 | sha224_finish_wrap, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 480 | sha256_wrap, |
Manuel Pégourié-Gonnard | 496f24e | 2015-06-23 11:34:35 +0200 | [diff] [blame] | 481 | sha224_ctx_alloc, |
| 482 | sha224_ctx_free, |
Manuel Pégourié-Gonnard | 052a6c9 | 2015-07-06 16:06:02 +0200 | [diff] [blame] | 483 | sha224_clone_wrap, |
Manuel Pégourié-Gonnard | 496f24e | 2015-06-23 11:34:35 +0200 | [diff] [blame] | 484 | sha224_process_wrap, |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 485 | }; |
| 486 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 487 | #endif /* MBEDTLS_SHA256_C */ |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 488 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 489 | #if defined(MBEDTLS_SHA512_C) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 490 | |
Andres Amaya Garcia | 5f872df | 2017-06-28 14:12:44 +0100 | [diff] [blame] | 491 | static int sha384_starts_wrap( void *ctx ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 492 | { |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 493 | return( mbedtls_sha512_starts_ret( (mbedtls_sha512_context *) ctx, 1 ) ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 494 | } |
| 495 | |
Andres Amaya Garcia | 5f872df | 2017-06-28 14:12:44 +0100 | [diff] [blame] | 496 | static int sha384_update_wrap( void *ctx, const unsigned char *input, |
| 497 | size_t ilen ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 498 | { |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 499 | return( mbedtls_sha512_update_ret( (mbedtls_sha512_context *) ctx, |
Andres Amaya Garcia | 5f872df | 2017-06-28 14:12:44 +0100 | [diff] [blame] | 500 | input, ilen ) ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 501 | } |
| 502 | |
Andres Amaya Garcia | 5f872df | 2017-06-28 14:12:44 +0100 | [diff] [blame] | 503 | static int sha384_finish_wrap( void *ctx, unsigned char *output ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 504 | { |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 505 | return( mbedtls_sha512_finish_ret( (mbedtls_sha512_context *) ctx, |
Andres Amaya Garcia | 5f872df | 2017-06-28 14:12:44 +0100 | [diff] [blame] | 506 | output ) ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 507 | } |
| 508 | |
Andres Amaya Garcia | 5f872df | 2017-06-28 14:12:44 +0100 | [diff] [blame] | 509 | static int sha384_wrap( const unsigned char *input, size_t ilen, |
| 510 | unsigned char *output ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 511 | { |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 512 | return( mbedtls_sha512_ret( input, ilen, output, 1 ) ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 513 | } |
| 514 | |
Manuel Pégourié-Gonnard | ab59321 | 2015-06-23 11:30:47 +0200 | [diff] [blame] | 515 | static void *sha384_ctx_alloc( void ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 516 | { |
Manuel Pégourié-Gonnard | ab59321 | 2015-06-23 11:30:47 +0200 | [diff] [blame] | 517 | void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_sha512_context ) ); |
| 518 | |
| 519 | if( ctx != NULL ) |
| 520 | mbedtls_sha512_init( (mbedtls_sha512_context *) ctx ); |
| 521 | |
| 522 | return( ctx ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 523 | } |
| 524 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 525 | static void sha384_ctx_free( void *ctx ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 526 | { |
Manuel Pégourié-Gonnard | 71d296a | 2015-07-06 11:27:12 +0200 | [diff] [blame] | 527 | mbedtls_sha512_free( (mbedtls_sha512_context *) ctx ); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 528 | mbedtls_free( ctx ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 529 | } |
| 530 | |
Manuel Pégourié-Gonnard | 052a6c9 | 2015-07-06 16:06:02 +0200 | [diff] [blame] | 531 | static void sha384_clone_wrap( void *dst, const void *src ) |
| 532 | { |
| 533 | mbedtls_sha512_clone( (mbedtls_sha512_context *) dst, |
| 534 | (const mbedtls_sha512_context *) src ); |
| 535 | } |
| 536 | |
Andres Amaya Garcia | 5f872df | 2017-06-28 14:12:44 +0100 | [diff] [blame] | 537 | static int sha384_process_wrap( void *ctx, const unsigned char *data ) |
Paul Bakker | 1bd3ae8 | 2013-03-13 10:26:44 +0100 | [diff] [blame] | 538 | { |
Andres Amaya Garcia | 5f872df | 2017-06-28 14:12:44 +0100 | [diff] [blame] | 539 | return( mbedtls_internal_sha512_process( (mbedtls_sha512_context *) ctx, |
| 540 | data ) ); |
Paul Bakker | 1bd3ae8 | 2013-03-13 10:26:44 +0100 | [diff] [blame] | 541 | } |
| 542 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 543 | const mbedtls_md_info_t mbedtls_sha384_info = { |
| 544 | MBEDTLS_MD_SHA384, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 545 | "SHA384", |
| 546 | 48, |
Manuel Pégourié-Gonnard | 8379a82 | 2015-03-24 16:48:22 +0100 | [diff] [blame] | 547 | 128, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 548 | sha384_starts_wrap, |
| 549 | sha384_update_wrap, |
| 550 | sha384_finish_wrap, |
| 551 | sha384_wrap, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 552 | sha384_ctx_alloc, |
| 553 | sha384_ctx_free, |
Manuel Pégourié-Gonnard | 052a6c9 | 2015-07-06 16:06:02 +0200 | [diff] [blame] | 554 | sha384_clone_wrap, |
Paul Bakker | 1bd3ae8 | 2013-03-13 10:26:44 +0100 | [diff] [blame] | 555 | sha384_process_wrap, |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 556 | }; |
| 557 | |
Andres Amaya Garcia | 5f872df | 2017-06-28 14:12:44 +0100 | [diff] [blame] | 558 | static int sha512_starts_wrap( void *ctx ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 559 | { |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 560 | return( mbedtls_sha512_starts_ret( (mbedtls_sha512_context *) ctx, 0 ) ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 561 | } |
| 562 | |
Andres Amaya Garcia | 5f872df | 2017-06-28 14:12:44 +0100 | [diff] [blame] | 563 | static int sha512_wrap( const unsigned char *input, size_t ilen, |
| 564 | unsigned char *output ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 565 | { |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 566 | return( mbedtls_sha512_ret( input, ilen, output, 0 ) ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 567 | } |
| 568 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 569 | const mbedtls_md_info_t mbedtls_sha512_info = { |
| 570 | MBEDTLS_MD_SHA512, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 571 | "SHA512", |
| 572 | 64, |
Manuel Pégourié-Gonnard | 8379a82 | 2015-03-24 16:48:22 +0100 | [diff] [blame] | 573 | 128, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 574 | sha512_starts_wrap, |
Manuel Pégourié-Gonnard | 496f24e | 2015-06-23 11:34:35 +0200 | [diff] [blame] | 575 | sha384_update_wrap, |
| 576 | sha384_finish_wrap, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 577 | sha512_wrap, |
Manuel Pégourié-Gonnard | 496f24e | 2015-06-23 11:34:35 +0200 | [diff] [blame] | 578 | sha384_ctx_alloc, |
| 579 | sha384_ctx_free, |
Manuel Pégourié-Gonnard | 052a6c9 | 2015-07-06 16:06:02 +0200 | [diff] [blame] | 580 | sha384_clone_wrap, |
Manuel Pégourié-Gonnard | 496f24e | 2015-06-23 11:34:35 +0200 | [diff] [blame] | 581 | sha384_process_wrap, |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 582 | }; |
| 583 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 584 | #endif /* MBEDTLS_SHA512_C */ |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 585 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 586 | #endif /* MBEDTLS_MD_C */ |