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