Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 1 | /** |
| 2 | * \file md_wrap.c |
| 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 | a658a40 | 2015-01-23 09:45:19 +0000 | [diff] [blame] | 8 | * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 9 | * |
Manuel Pégourié-Gonnard | fe44643 | 2015-03-06 13:17:10 +0000 | [diff] [blame] | 10 | * This file is part of mbed TLS (https://tls.mbed.org) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 11 | * |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 12 | * This program is free software; you can redistribute it and/or modify |
| 13 | * it under the terms of the GNU General Public License as published by |
| 14 | * the Free Software Foundation; either version 2 of the License, or |
| 15 | * (at your option) any later version. |
| 16 | * |
| 17 | * This program is distributed in the hope that it will be useful, |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | * GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along |
| 23 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 24 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 25 | */ |
| 26 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 27 | #if !defined(MBEDTLS_CONFIG_FILE) |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 28 | #include "mbedtls/config.h" |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 29 | #else |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 30 | #include MBEDTLS_CONFIG_FILE |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 31 | #endif |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 32 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 33 | #if defined(MBEDTLS_MD_C) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 34 | |
Manuel Pégourié-Gonnard | 50518f4 | 2015-05-26 11:04:15 +0200 | [diff] [blame] | 35 | #include "mbedtls/md_internal.h" |
Paul Bakker | f654371 | 2012-03-05 14:01:29 +0000 | [diff] [blame] | 36 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 37 | #if defined(MBEDTLS_MD2_C) |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 38 | #include "mbedtls/md2.h" |
Paul Bakker | f654371 | 2012-03-05 14:01:29 +0000 | [diff] [blame] | 39 | #endif |
| 40 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 41 | #if defined(MBEDTLS_MD4_C) |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 42 | #include "mbedtls/md4.h" |
Paul Bakker | f654371 | 2012-03-05 14:01:29 +0000 | [diff] [blame] | 43 | #endif |
| 44 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 45 | #if defined(MBEDTLS_MD5_C) |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 46 | #include "mbedtls/md5.h" |
Paul Bakker | f654371 | 2012-03-05 14:01:29 +0000 | [diff] [blame] | 47 | #endif |
| 48 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 49 | #if defined(MBEDTLS_RIPEMD160_C) |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 50 | #include "mbedtls/ripemd160.h" |
Manuel Pégourié-Gonnard | e4d47a6 | 2014-01-17 20:41:32 +0100 | [diff] [blame] | 51 | #endif |
| 52 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 53 | #if defined(MBEDTLS_SHA1_C) |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 54 | #include "mbedtls/sha1.h" |
Paul Bakker | f654371 | 2012-03-05 14:01:29 +0000 | [diff] [blame] | 55 | #endif |
| 56 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 57 | #if defined(MBEDTLS_SHA256_C) |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 58 | #include "mbedtls/sha256.h" |
Paul Bakker | f654371 | 2012-03-05 14:01:29 +0000 | [diff] [blame] | 59 | #endif |
| 60 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 61 | #if defined(MBEDTLS_SHA512_C) |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 62 | #include "mbedtls/sha512.h" |
Paul Bakker | f654371 | 2012-03-05 14:01:29 +0000 | [diff] [blame] | 63 | #endif |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 64 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 65 | #if defined(MBEDTLS_PLATFORM_C) |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 66 | #include "mbedtls/platform.h" |
Paul Bakker | 6e339b5 | 2013-07-03 13:37:05 +0200 | [diff] [blame] | 67 | #else |
Rich Evans | 00ab470 | 2015-02-06 13:43:58 +0000 | [diff] [blame] | 68 | #include <stdlib.h> |
Manuel Pégourié-Gonnard | 7551cb9 | 2015-05-26 16:04:06 +0200 | [diff] [blame] | 69 | #define mbedtls_calloc calloc |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 70 | #define mbedtls_free free |
Paul Bakker | 6e339b5 | 2013-07-03 13:37:05 +0200 | [diff] [blame] | 71 | #endif |
| 72 | |
Paul Bakker | 3461772 | 2014-06-13 17:20:13 +0200 | [diff] [blame] | 73 | /* Implementation that should never be optimized out by the compiler */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 74 | static void mbedtls_zeroize( void *v, size_t n ) { |
Paul Bakker | 3461772 | 2014-06-13 17:20:13 +0200 | [diff] [blame] | 75 | volatile unsigned char *p = v; while( n-- ) *p++ = 0; |
| 76 | } |
| 77 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 78 | #if defined(MBEDTLS_MD2_C) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 79 | |
| 80 | static void md2_starts_wrap( void *ctx ) |
| 81 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 82 | mbedtls_md2_starts( (mbedtls_md2_context *) ctx ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 83 | } |
| 84 | |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 85 | static void md2_update_wrap( void *ctx, const unsigned char *input, |
| 86 | size_t ilen ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 87 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 88 | mbedtls_md2_update( (mbedtls_md2_context *) ctx, input, ilen ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | static void md2_finish_wrap( void *ctx, unsigned char *output ) |
| 92 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 93 | mbedtls_md2_finish( (mbedtls_md2_context *) ctx, output ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 94 | } |
| 95 | |
Manuel Pégourié-Gonnard | ab59321 | 2015-06-23 11:30:47 +0200 | [diff] [blame] | 96 | static void *md2_ctx_alloc( void ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 97 | { |
Manuel Pégourié-Gonnard | ab59321 | 2015-06-23 11:30:47 +0200 | [diff] [blame] | 98 | void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_md2_context ) ); |
| 99 | |
| 100 | if( ctx != NULL ) |
| 101 | mbedtls_md2_init( (mbedtls_md2_context *) ctx ); |
| 102 | |
| 103 | return( ctx ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | static void md2_ctx_free( void *ctx ) |
| 107 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 108 | mbedtls_zeroize( ctx, sizeof( mbedtls_md2_context ) ); |
| 109 | mbedtls_free( ctx ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 110 | } |
| 111 | |
Paul Bakker | 1bd3ae8 | 2013-03-13 10:26:44 +0100 | [diff] [blame] | 112 | static void md2_process_wrap( void *ctx, const unsigned char *data ) |
| 113 | { |
| 114 | ((void) data); |
| 115 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 116 | mbedtls_md2_process( (mbedtls_md2_context *) ctx ); |
Paul Bakker | 1bd3ae8 | 2013-03-13 10:26:44 +0100 | [diff] [blame] | 117 | } |
| 118 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 119 | const mbedtls_md_info_t mbedtls_md2_info = { |
| 120 | MBEDTLS_MD_MD2, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 121 | "MD2", |
| 122 | 16, |
Manuel Pégourié-Gonnard | 8379a82 | 2015-03-24 16:48:22 +0100 | [diff] [blame] | 123 | 16, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 124 | md2_starts_wrap, |
| 125 | md2_update_wrap, |
| 126 | md2_finish_wrap, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 127 | mbedtls_md2, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 128 | md2_ctx_alloc, |
| 129 | md2_ctx_free, |
Paul Bakker | 1bd3ae8 | 2013-03-13 10:26:44 +0100 | [diff] [blame] | 130 | md2_process_wrap, |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 131 | }; |
| 132 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 133 | #endif /* MBEDTLS_MD2_C */ |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 134 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 135 | #if defined(MBEDTLS_MD4_C) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 136 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 137 | static void md4_starts_wrap( void *ctx ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 138 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 139 | mbedtls_md4_starts( (mbedtls_md4_context *) ctx ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 140 | } |
| 141 | |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 142 | static void md4_update_wrap( void *ctx, const unsigned char *input, |
| 143 | size_t ilen ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 144 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 145 | mbedtls_md4_update( (mbedtls_md4_context *) ctx, input, ilen ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 146 | } |
| 147 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 148 | static void md4_finish_wrap( void *ctx, unsigned char *output ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 149 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 150 | mbedtls_md4_finish( (mbedtls_md4_context *) ctx, output ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 151 | } |
| 152 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 153 | static void *md4_ctx_alloc( void ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 154 | { |
Manuel Pégourié-Gonnard | ab59321 | 2015-06-23 11:30:47 +0200 | [diff] [blame] | 155 | void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_md4_context ) ); |
| 156 | |
| 157 | if( ctx != NULL ) |
| 158 | mbedtls_md4_init( (mbedtls_md4_context *) ctx ); |
| 159 | |
| 160 | return( ctx ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 161 | } |
| 162 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 163 | static void md4_ctx_free( void *ctx ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 164 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 165 | mbedtls_zeroize( ctx, sizeof( mbedtls_md4_context ) ); |
| 166 | mbedtls_free( ctx ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 167 | } |
| 168 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 169 | static void md4_process_wrap( void *ctx, const unsigned char *data ) |
Paul Bakker | 1bd3ae8 | 2013-03-13 10:26:44 +0100 | [diff] [blame] | 170 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 171 | mbedtls_md4_process( (mbedtls_md4_context *) ctx, data ); |
Paul Bakker | 1bd3ae8 | 2013-03-13 10:26:44 +0100 | [diff] [blame] | 172 | } |
| 173 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 174 | const mbedtls_md_info_t mbedtls_md4_info = { |
| 175 | MBEDTLS_MD_MD4, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 176 | "MD4", |
| 177 | 16, |
Manuel Pégourié-Gonnard | 8379a82 | 2015-03-24 16:48:22 +0100 | [diff] [blame] | 178 | 64, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 179 | md4_starts_wrap, |
| 180 | md4_update_wrap, |
| 181 | md4_finish_wrap, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 182 | mbedtls_md4, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 183 | md4_ctx_alloc, |
| 184 | md4_ctx_free, |
Paul Bakker | 1bd3ae8 | 2013-03-13 10:26:44 +0100 | [diff] [blame] | 185 | md4_process_wrap, |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 186 | }; |
| 187 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 188 | #endif /* MBEDTLS_MD4_C */ |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 189 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 190 | #if defined(MBEDTLS_MD5_C) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 191 | |
| 192 | static void md5_starts_wrap( void *ctx ) |
| 193 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 194 | mbedtls_md5_starts( (mbedtls_md5_context *) ctx ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 195 | } |
| 196 | |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 197 | static void md5_update_wrap( void *ctx, const unsigned char *input, |
| 198 | size_t ilen ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 199 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 200 | mbedtls_md5_update( (mbedtls_md5_context *) ctx, input, ilen ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | static void md5_finish_wrap( void *ctx, unsigned char *output ) |
| 204 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 205 | mbedtls_md5_finish( (mbedtls_md5_context *) ctx, output ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 206 | } |
| 207 | |
Manuel Pégourié-Gonnard | ab59321 | 2015-06-23 11:30:47 +0200 | [diff] [blame] | 208 | static void *md5_ctx_alloc( void ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 209 | { |
Manuel Pégourié-Gonnard | ab59321 | 2015-06-23 11:30:47 +0200 | [diff] [blame] | 210 | void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_md5_context ) ); |
| 211 | |
| 212 | if( ctx != NULL ) |
| 213 | mbedtls_md5_init( (mbedtls_md5_context *) ctx ); |
| 214 | |
| 215 | return( ctx ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | static void md5_ctx_free( void *ctx ) |
| 219 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 220 | mbedtls_zeroize( ctx, sizeof( mbedtls_md5_context ) ); |
| 221 | mbedtls_free( ctx ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 222 | } |
| 223 | |
Paul Bakker | 1bd3ae8 | 2013-03-13 10:26:44 +0100 | [diff] [blame] | 224 | static void md5_process_wrap( void *ctx, const unsigned char *data ) |
| 225 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 226 | mbedtls_md5_process( (mbedtls_md5_context *) ctx, data ); |
Paul Bakker | 1bd3ae8 | 2013-03-13 10:26:44 +0100 | [diff] [blame] | 227 | } |
| 228 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 229 | const mbedtls_md_info_t mbedtls_md5_info = { |
| 230 | MBEDTLS_MD_MD5, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 231 | "MD5", |
| 232 | 16, |
Manuel Pégourié-Gonnard | 8379a82 | 2015-03-24 16:48:22 +0100 | [diff] [blame] | 233 | 64, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 234 | md5_starts_wrap, |
| 235 | md5_update_wrap, |
| 236 | md5_finish_wrap, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 237 | mbedtls_md5, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 238 | md5_ctx_alloc, |
| 239 | md5_ctx_free, |
Paul Bakker | 1bd3ae8 | 2013-03-13 10:26:44 +0100 | [diff] [blame] | 240 | md5_process_wrap, |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 241 | }; |
| 242 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 243 | #endif /* MBEDTLS_MD5_C */ |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 244 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 245 | #if defined(MBEDTLS_RIPEMD160_C) |
Manuel Pégourié-Gonnard | e4d47a6 | 2014-01-17 20:41:32 +0100 | [diff] [blame] | 246 | |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 247 | static void ripemd160_starts_wrap( void *ctx ) |
Manuel Pégourié-Gonnard | e4d47a6 | 2014-01-17 20:41:32 +0100 | [diff] [blame] | 248 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 249 | mbedtls_ripemd160_starts( (mbedtls_ripemd160_context *) ctx ); |
Manuel Pégourié-Gonnard | e4d47a6 | 2014-01-17 20:41:32 +0100 | [diff] [blame] | 250 | } |
| 251 | |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 252 | static void ripemd160_update_wrap( void *ctx, const unsigned char *input, |
| 253 | size_t ilen ) |
Manuel Pégourié-Gonnard | e4d47a6 | 2014-01-17 20:41:32 +0100 | [diff] [blame] | 254 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 255 | mbedtls_ripemd160_update( (mbedtls_ripemd160_context *) ctx, input, ilen ); |
Manuel Pégourié-Gonnard | e4d47a6 | 2014-01-17 20:41:32 +0100 | [diff] [blame] | 256 | } |
| 257 | |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 258 | static void ripemd160_finish_wrap( void *ctx, unsigned char *output ) |
Manuel Pégourié-Gonnard | e4d47a6 | 2014-01-17 20:41:32 +0100 | [diff] [blame] | 259 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 260 | mbedtls_ripemd160_finish( (mbedtls_ripemd160_context *) ctx, output ); |
Manuel Pégourié-Gonnard | e4d47a6 | 2014-01-17 20:41:32 +0100 | [diff] [blame] | 261 | } |
| 262 | |
Manuel Pégourié-Gonnard | ab59321 | 2015-06-23 11:30:47 +0200 | [diff] [blame] | 263 | static void *ripemd160_ctx_alloc( void ) |
Manuel Pégourié-Gonnard | e4d47a6 | 2014-01-17 20:41:32 +0100 | [diff] [blame] | 264 | { |
Manuel Pégourié-Gonnard | ab59321 | 2015-06-23 11:30:47 +0200 | [diff] [blame] | 265 | void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_ripemd160_context ) ); |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 266 | |
Manuel Pégourié-Gonnard | ab59321 | 2015-06-23 11:30:47 +0200 | [diff] [blame] | 267 | if( ctx != NULL ) |
| 268 | mbedtls_ripemd160_init( (mbedtls_ripemd160_context *) ctx ); |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 269 | |
| 270 | return( ctx ); |
Manuel Pégourié-Gonnard | e4d47a6 | 2014-01-17 20:41:32 +0100 | [diff] [blame] | 271 | } |
| 272 | |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 273 | static void ripemd160_ctx_free( void *ctx ) |
Manuel Pégourié-Gonnard | e4d47a6 | 2014-01-17 20:41:32 +0100 | [diff] [blame] | 274 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 275 | mbedtls_ripemd160_free( (mbedtls_ripemd160_context *) ctx ); |
| 276 | mbedtls_free( ctx ); |
Manuel Pégourié-Gonnard | e4d47a6 | 2014-01-17 20:41:32 +0100 | [diff] [blame] | 277 | } |
| 278 | |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 279 | static void ripemd160_process_wrap( void *ctx, const unsigned char *data ) |
Manuel Pégourié-Gonnard | e4d47a6 | 2014-01-17 20:41:32 +0100 | [diff] [blame] | 280 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 281 | mbedtls_ripemd160_process( (mbedtls_ripemd160_context *) ctx, data ); |
Manuel Pégourié-Gonnard | e4d47a6 | 2014-01-17 20:41:32 +0100 | [diff] [blame] | 282 | } |
| 283 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 284 | const mbedtls_md_info_t mbedtls_ripemd160_info = { |
| 285 | MBEDTLS_MD_RIPEMD160, |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 286 | "RIPEMD160", |
Manuel Pégourié-Gonnard | e4d47a6 | 2014-01-17 20:41:32 +0100 | [diff] [blame] | 287 | 20, |
Manuel Pégourié-Gonnard | 8379a82 | 2015-03-24 16:48:22 +0100 | [diff] [blame] | 288 | 64, |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 289 | ripemd160_starts_wrap, |
| 290 | ripemd160_update_wrap, |
| 291 | ripemd160_finish_wrap, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 292 | mbedtls_ripemd160, |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 293 | ripemd160_ctx_alloc, |
| 294 | ripemd160_ctx_free, |
| 295 | ripemd160_process_wrap, |
Manuel Pégourié-Gonnard | e4d47a6 | 2014-01-17 20:41:32 +0100 | [diff] [blame] | 296 | }; |
| 297 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 298 | #endif /* MBEDTLS_RIPEMD160_C */ |
Manuel Pégourié-Gonnard | e4d47a6 | 2014-01-17 20:41:32 +0100 | [diff] [blame] | 299 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 300 | #if defined(MBEDTLS_SHA1_C) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 301 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 302 | static void sha1_starts_wrap( void *ctx ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 303 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 304 | mbedtls_sha1_starts( (mbedtls_sha1_context *) ctx ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 305 | } |
| 306 | |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 307 | static void sha1_update_wrap( void *ctx, const unsigned char *input, |
| 308 | size_t ilen ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 309 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 310 | mbedtls_sha1_update( (mbedtls_sha1_context *) ctx, input, ilen ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 311 | } |
| 312 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 313 | static void sha1_finish_wrap( void *ctx, unsigned char *output ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 314 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 315 | mbedtls_sha1_finish( (mbedtls_sha1_context *) ctx, output ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 316 | } |
| 317 | |
Manuel Pégourié-Gonnard | ab59321 | 2015-06-23 11:30:47 +0200 | [diff] [blame] | 318 | static void *sha1_ctx_alloc( void ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 319 | { |
Manuel Pégourié-Gonnard | ab59321 | 2015-06-23 11:30:47 +0200 | [diff] [blame] | 320 | void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_sha1_context ) ); |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 321 | |
Manuel Pégourié-Gonnard | ab59321 | 2015-06-23 11:30:47 +0200 | [diff] [blame] | 322 | if( ctx != NULL ) |
| 323 | mbedtls_sha1_init( (mbedtls_sha1_context *) ctx ); |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 324 | |
| 325 | return( ctx ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 326 | } |
| 327 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 328 | static void sha1_ctx_free( void *ctx ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 329 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 330 | mbedtls_sha1_free( (mbedtls_sha1_context *) ctx ); |
| 331 | mbedtls_free( ctx ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 332 | } |
| 333 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 334 | static void sha1_process_wrap( void *ctx, const unsigned char *data ) |
Paul Bakker | 1bd3ae8 | 2013-03-13 10:26:44 +0100 | [diff] [blame] | 335 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 336 | mbedtls_sha1_process( (mbedtls_sha1_context *) ctx, data ); |
Paul Bakker | 1bd3ae8 | 2013-03-13 10:26:44 +0100 | [diff] [blame] | 337 | } |
| 338 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 339 | const mbedtls_md_info_t mbedtls_sha1_info = { |
| 340 | MBEDTLS_MD_SHA1, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 341 | "SHA1", |
| 342 | 20, |
Manuel Pégourié-Gonnard | 8379a82 | 2015-03-24 16:48:22 +0100 | [diff] [blame] | 343 | 64, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 344 | sha1_starts_wrap, |
| 345 | sha1_update_wrap, |
| 346 | sha1_finish_wrap, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 347 | mbedtls_sha1, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 348 | sha1_ctx_alloc, |
| 349 | sha1_ctx_free, |
Paul Bakker | 1bd3ae8 | 2013-03-13 10:26:44 +0100 | [diff] [blame] | 350 | sha1_process_wrap, |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 351 | }; |
| 352 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 353 | #endif /* MBEDTLS_SHA1_C */ |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 354 | |
| 355 | /* |
| 356 | * Wrappers for generic message digests |
| 357 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 358 | #if defined(MBEDTLS_SHA256_C) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 359 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 360 | static void sha224_starts_wrap( void *ctx ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 361 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 362 | mbedtls_sha256_starts( (mbedtls_sha256_context *) ctx, 1 ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 363 | } |
| 364 | |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 365 | static void sha224_update_wrap( void *ctx, const unsigned char *input, |
| 366 | size_t ilen ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 367 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 368 | mbedtls_sha256_update( (mbedtls_sha256_context *) ctx, input, ilen ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 369 | } |
| 370 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 371 | static void sha224_finish_wrap( void *ctx, unsigned char *output ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 372 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 373 | mbedtls_sha256_finish( (mbedtls_sha256_context *) ctx, output ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 374 | } |
| 375 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 376 | static void sha224_wrap( const unsigned char *input, size_t ilen, |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 377 | unsigned char *output ) |
| 378 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 379 | mbedtls_sha256( input, ilen, output, 1 ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 380 | } |
| 381 | |
Manuel Pégourié-Gonnard | ab59321 | 2015-06-23 11:30:47 +0200 | [diff] [blame] | 382 | static void *sha224_ctx_alloc( void ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 383 | { |
Manuel Pégourié-Gonnard | ab59321 | 2015-06-23 11:30:47 +0200 | [diff] [blame] | 384 | void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_sha256_context ) ); |
| 385 | |
| 386 | if( ctx != NULL ) |
| 387 | mbedtls_sha256_init( (mbedtls_sha256_context *) ctx ); |
| 388 | |
| 389 | return( ctx ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 390 | } |
| 391 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 392 | static void sha224_ctx_free( void *ctx ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 393 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 394 | mbedtls_zeroize( ctx, sizeof( mbedtls_sha256_context ) ); |
| 395 | mbedtls_free( ctx ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 396 | } |
| 397 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 398 | static void sha224_process_wrap( void *ctx, const unsigned char *data ) |
Paul Bakker | 1bd3ae8 | 2013-03-13 10:26:44 +0100 | [diff] [blame] | 399 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 400 | mbedtls_sha256_process( (mbedtls_sha256_context *) ctx, data ); |
Paul Bakker | 1bd3ae8 | 2013-03-13 10:26:44 +0100 | [diff] [blame] | 401 | } |
| 402 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 403 | const mbedtls_md_info_t mbedtls_sha224_info = { |
| 404 | MBEDTLS_MD_SHA224, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 405 | "SHA224", |
| 406 | 28, |
Manuel Pégourié-Gonnard | 8379a82 | 2015-03-24 16:48:22 +0100 | [diff] [blame] | 407 | 64, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 408 | sha224_starts_wrap, |
| 409 | sha224_update_wrap, |
| 410 | sha224_finish_wrap, |
| 411 | sha224_wrap, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 412 | sha224_ctx_alloc, |
| 413 | sha224_ctx_free, |
Paul Bakker | 1bd3ae8 | 2013-03-13 10:26:44 +0100 | [diff] [blame] | 414 | sha224_process_wrap, |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 415 | }; |
| 416 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 417 | static void sha256_starts_wrap( void *ctx ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 418 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 419 | mbedtls_sha256_starts( (mbedtls_sha256_context *) ctx, 0 ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 420 | } |
| 421 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 422 | static void sha256_wrap( const unsigned char *input, size_t ilen, |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 423 | unsigned char *output ) |
| 424 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 425 | mbedtls_sha256( input, ilen, output, 0 ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 426 | } |
| 427 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 428 | const mbedtls_md_info_t mbedtls_sha256_info = { |
| 429 | MBEDTLS_MD_SHA256, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 430 | "SHA256", |
| 431 | 32, |
Manuel Pégourié-Gonnard | 8379a82 | 2015-03-24 16:48:22 +0100 | [diff] [blame] | 432 | 64, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 433 | sha256_starts_wrap, |
Manuel Pégourié-Gonnard | 496f24e | 2015-06-23 11:34:35 +0200 | [diff] [blame^] | 434 | sha224_update_wrap, |
| 435 | sha224_finish_wrap, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 436 | sha256_wrap, |
Manuel Pégourié-Gonnard | 496f24e | 2015-06-23 11:34:35 +0200 | [diff] [blame^] | 437 | sha224_ctx_alloc, |
| 438 | sha224_ctx_free, |
| 439 | sha224_process_wrap, |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 440 | }; |
| 441 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 442 | #endif /* MBEDTLS_SHA256_C */ |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 443 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 444 | #if defined(MBEDTLS_SHA512_C) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 445 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 446 | static void sha384_starts_wrap( void *ctx ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 447 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 448 | mbedtls_sha512_starts( (mbedtls_sha512_context *) ctx, 1 ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 449 | } |
| 450 | |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 451 | static void sha384_update_wrap( void *ctx, const unsigned char *input, |
| 452 | size_t ilen ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 453 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 454 | mbedtls_sha512_update( (mbedtls_sha512_context *) ctx, input, ilen ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 455 | } |
| 456 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 457 | static void sha384_finish_wrap( void *ctx, unsigned char *output ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 458 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 459 | mbedtls_sha512_finish( (mbedtls_sha512_context *) ctx, output ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 460 | } |
| 461 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 462 | static void sha384_wrap( const unsigned char *input, size_t ilen, |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 463 | unsigned char *output ) |
| 464 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 465 | mbedtls_sha512( input, ilen, output, 1 ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 466 | } |
| 467 | |
Manuel Pégourié-Gonnard | ab59321 | 2015-06-23 11:30:47 +0200 | [diff] [blame] | 468 | static void *sha384_ctx_alloc( void ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 469 | { |
Manuel Pégourié-Gonnard | ab59321 | 2015-06-23 11:30:47 +0200 | [diff] [blame] | 470 | void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_sha512_context ) ); |
| 471 | |
| 472 | if( ctx != NULL ) |
| 473 | mbedtls_sha512_init( (mbedtls_sha512_context *) ctx ); |
| 474 | |
| 475 | return( ctx ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 476 | } |
| 477 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 478 | static void sha384_ctx_free( void *ctx ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 479 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 480 | mbedtls_zeroize( ctx, sizeof( mbedtls_sha512_context ) ); |
| 481 | mbedtls_free( ctx ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 482 | } |
| 483 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 484 | static void sha384_process_wrap( void *ctx, const unsigned char *data ) |
Paul Bakker | 1bd3ae8 | 2013-03-13 10:26:44 +0100 | [diff] [blame] | 485 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 486 | mbedtls_sha512_process( (mbedtls_sha512_context *) ctx, data ); |
Paul Bakker | 1bd3ae8 | 2013-03-13 10:26:44 +0100 | [diff] [blame] | 487 | } |
| 488 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 489 | const mbedtls_md_info_t mbedtls_sha384_info = { |
| 490 | MBEDTLS_MD_SHA384, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 491 | "SHA384", |
| 492 | 48, |
Manuel Pégourié-Gonnard | 8379a82 | 2015-03-24 16:48:22 +0100 | [diff] [blame] | 493 | 128, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 494 | sha384_starts_wrap, |
| 495 | sha384_update_wrap, |
| 496 | sha384_finish_wrap, |
| 497 | sha384_wrap, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 498 | sha384_ctx_alloc, |
| 499 | sha384_ctx_free, |
Paul Bakker | 1bd3ae8 | 2013-03-13 10:26:44 +0100 | [diff] [blame] | 500 | sha384_process_wrap, |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 501 | }; |
| 502 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 503 | static void sha512_starts_wrap( void *ctx ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 504 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 505 | mbedtls_sha512_starts( (mbedtls_sha512_context *) ctx, 0 ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 506 | } |
| 507 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 508 | static void sha512_wrap( const unsigned char *input, size_t ilen, |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 509 | unsigned char *output ) |
| 510 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 511 | mbedtls_sha512( input, ilen, output, 0 ); |
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 | const mbedtls_md_info_t mbedtls_sha512_info = { |
| 515 | MBEDTLS_MD_SHA512, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 516 | "SHA512", |
| 517 | 64, |
Manuel Pégourié-Gonnard | 8379a82 | 2015-03-24 16:48:22 +0100 | [diff] [blame] | 518 | 128, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 519 | sha512_starts_wrap, |
Manuel Pégourié-Gonnard | 496f24e | 2015-06-23 11:34:35 +0200 | [diff] [blame^] | 520 | sha384_update_wrap, |
| 521 | sha384_finish_wrap, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 522 | sha512_wrap, |
Manuel Pégourié-Gonnard | 496f24e | 2015-06-23 11:34:35 +0200 | [diff] [blame^] | 523 | sha384_ctx_alloc, |
| 524 | sha384_ctx_free, |
| 525 | sha384_process_wrap, |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 526 | }; |
| 527 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 528 | #endif /* MBEDTLS_SHA512_C */ |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 529 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 530 | #endif /* MBEDTLS_MD_C */ |