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