Hannes Tschofenig
/
aes-gcm-test-program
Example program to test AES-GCM functionality. Used for a workshop
SSL/library/md_wrap.c@0:796d0f61a05b, 2018-09-27 (annotated)
- Committer:
- HannesTschofenig
- Date:
- Thu Sep 27 06:34:22 2018 +0000
- Revision:
- 0:796d0f61a05b
Example AES-GCM test program
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
HannesTschofenig | 0:796d0f61a05b | 1 | /** |
HannesTschofenig | 0:796d0f61a05b | 2 | * \file md_wrap.c |
HannesTschofenig | 0:796d0f61a05b | 3 | |
HannesTschofenig | 0:796d0f61a05b | 4 | * \brief Generic message digest wrapper for PolarSSL |
HannesTschofenig | 0:796d0f61a05b | 5 | * |
HannesTschofenig | 0:796d0f61a05b | 6 | * \author Adriaan de Jong <dejong@fox-it.com> |
HannesTschofenig | 0:796d0f61a05b | 7 | * |
HannesTschofenig | 0:796d0f61a05b | 8 | * Copyright (C) 2006-2014, Brainspark B.V. |
HannesTschofenig | 0:796d0f61a05b | 9 | * |
HannesTschofenig | 0:796d0f61a05b | 10 | * This file is part of PolarSSL (http://www.polarssl.org) |
HannesTschofenig | 0:796d0f61a05b | 11 | * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org> |
HannesTschofenig | 0:796d0f61a05b | 12 | * |
HannesTschofenig | 0:796d0f61a05b | 13 | * All rights reserved. |
HannesTschofenig | 0:796d0f61a05b | 14 | * |
HannesTschofenig | 0:796d0f61a05b | 15 | * This program is free software; you can redistribute it and/or modify |
HannesTschofenig | 0:796d0f61a05b | 16 | * it under the terms of the GNU General Public License as published by |
HannesTschofenig | 0:796d0f61a05b | 17 | * the Free Software Foundation; either version 2 of the License, or |
HannesTschofenig | 0:796d0f61a05b | 18 | * (at your option) any later version. |
HannesTschofenig | 0:796d0f61a05b | 19 | * |
HannesTschofenig | 0:796d0f61a05b | 20 | * This program is distributed in the hope that it will be useful, |
HannesTschofenig | 0:796d0f61a05b | 21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
HannesTschofenig | 0:796d0f61a05b | 22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
HannesTschofenig | 0:796d0f61a05b | 23 | * GNU General Public License for more details. |
HannesTschofenig | 0:796d0f61a05b | 24 | * |
HannesTschofenig | 0:796d0f61a05b | 25 | * You should have received a copy of the GNU General Public License along |
HannesTschofenig | 0:796d0f61a05b | 26 | * with this program; if not, write to the Free Software Foundation, Inc., |
HannesTschofenig | 0:796d0f61a05b | 27 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
HannesTschofenig | 0:796d0f61a05b | 28 | */ |
HannesTschofenig | 0:796d0f61a05b | 29 | |
HannesTschofenig | 0:796d0f61a05b | 30 | #if !defined(POLARSSL_CONFIG_FILE) |
HannesTschofenig | 0:796d0f61a05b | 31 | #include "polarssl/config.h" |
HannesTschofenig | 0:796d0f61a05b | 32 | #else |
HannesTschofenig | 0:796d0f61a05b | 33 | #include POLARSSL_CONFIG_FILE |
HannesTschofenig | 0:796d0f61a05b | 34 | #endif |
HannesTschofenig | 0:796d0f61a05b | 35 | |
HannesTschofenig | 0:796d0f61a05b | 36 | #if defined(POLARSSL_MD_C) |
HannesTschofenig | 0:796d0f61a05b | 37 | |
HannesTschofenig | 0:796d0f61a05b | 38 | #include "polarssl/md_wrap.h" |
HannesTschofenig | 0:796d0f61a05b | 39 | |
HannesTschofenig | 0:796d0f61a05b | 40 | #if defined(POLARSSL_MD2_C) |
HannesTschofenig | 0:796d0f61a05b | 41 | #include "polarssl/md2.h" |
HannesTschofenig | 0:796d0f61a05b | 42 | #endif |
HannesTschofenig | 0:796d0f61a05b | 43 | |
HannesTschofenig | 0:796d0f61a05b | 44 | #if defined(POLARSSL_MD4_C) |
HannesTschofenig | 0:796d0f61a05b | 45 | #include "polarssl/md4.h" |
HannesTschofenig | 0:796d0f61a05b | 46 | #endif |
HannesTschofenig | 0:796d0f61a05b | 47 | |
HannesTschofenig | 0:796d0f61a05b | 48 | #if defined(POLARSSL_MD5_C) |
HannesTschofenig | 0:796d0f61a05b | 49 | #include "polarssl/md5.h" |
HannesTschofenig | 0:796d0f61a05b | 50 | #endif |
HannesTschofenig | 0:796d0f61a05b | 51 | |
HannesTschofenig | 0:796d0f61a05b | 52 | #if defined(POLARSSL_RIPEMD160_C) |
HannesTschofenig | 0:796d0f61a05b | 53 | #include "polarssl/ripemd160.h" |
HannesTschofenig | 0:796d0f61a05b | 54 | #endif |
HannesTschofenig | 0:796d0f61a05b | 55 | |
HannesTschofenig | 0:796d0f61a05b | 56 | #if defined(POLARSSL_SHA1_C) |
HannesTschofenig | 0:796d0f61a05b | 57 | #include "polarssl/sha1.h" |
HannesTschofenig | 0:796d0f61a05b | 58 | #endif |
HannesTschofenig | 0:796d0f61a05b | 59 | |
HannesTschofenig | 0:796d0f61a05b | 60 | #if defined(POLARSSL_SHA256_C) |
HannesTschofenig | 0:796d0f61a05b | 61 | #include "polarssl/sha256.h" |
HannesTschofenig | 0:796d0f61a05b | 62 | #endif |
HannesTschofenig | 0:796d0f61a05b | 63 | |
HannesTschofenig | 0:796d0f61a05b | 64 | #if defined(POLARSSL_SHA512_C) |
HannesTschofenig | 0:796d0f61a05b | 65 | #include "polarssl/sha512.h" |
HannesTschofenig | 0:796d0f61a05b | 66 | #endif |
HannesTschofenig | 0:796d0f61a05b | 67 | |
HannesTschofenig | 0:796d0f61a05b | 68 | #if defined(POLARSSL_PLATFORM_C) |
HannesTschofenig | 0:796d0f61a05b | 69 | #include "polarssl/platform.h" |
HannesTschofenig | 0:796d0f61a05b | 70 | #else |
HannesTschofenig | 0:796d0f61a05b | 71 | #define polarssl_malloc malloc |
HannesTschofenig | 0:796d0f61a05b | 72 | #define polarssl_free free |
HannesTschofenig | 0:796d0f61a05b | 73 | #endif |
HannesTschofenig | 0:796d0f61a05b | 74 | |
HannesTschofenig | 0:796d0f61a05b | 75 | #include <stdlib.h> |
HannesTschofenig | 0:796d0f61a05b | 76 | |
HannesTschofenig | 0:796d0f61a05b | 77 | #if defined(POLARSSL_MD2_C) |
HannesTschofenig | 0:796d0f61a05b | 78 | |
HannesTschofenig | 0:796d0f61a05b | 79 | static void md2_starts_wrap( void *ctx ) |
HannesTschofenig | 0:796d0f61a05b | 80 | { |
HannesTschofenig | 0:796d0f61a05b | 81 | md2_starts( (md2_context *) ctx ); |
HannesTschofenig | 0:796d0f61a05b | 82 | } |
HannesTschofenig | 0:796d0f61a05b | 83 | |
HannesTschofenig | 0:796d0f61a05b | 84 | static void md2_update_wrap( void *ctx, const unsigned char *input, |
HannesTschofenig | 0:796d0f61a05b | 85 | size_t ilen ) |
HannesTschofenig | 0:796d0f61a05b | 86 | { |
HannesTschofenig | 0:796d0f61a05b | 87 | md2_update( (md2_context *) ctx, input, ilen ); |
HannesTschofenig | 0:796d0f61a05b | 88 | } |
HannesTschofenig | 0:796d0f61a05b | 89 | |
HannesTschofenig | 0:796d0f61a05b | 90 | static void md2_finish_wrap( void *ctx, unsigned char *output ) |
HannesTschofenig | 0:796d0f61a05b | 91 | { |
HannesTschofenig | 0:796d0f61a05b | 92 | md2_finish( (md2_context *) ctx, output ); |
HannesTschofenig | 0:796d0f61a05b | 93 | } |
HannesTschofenig | 0:796d0f61a05b | 94 | |
HannesTschofenig | 0:796d0f61a05b | 95 | static int md2_file_wrap( const char *path, unsigned char *output ) |
HannesTschofenig | 0:796d0f61a05b | 96 | { |
HannesTschofenig | 0:796d0f61a05b | 97 | #if defined(POLARSSL_FS_IO) |
HannesTschofenig | 0:796d0f61a05b | 98 | return md2_file( path, output ); |
HannesTschofenig | 0:796d0f61a05b | 99 | #else |
HannesTschofenig | 0:796d0f61a05b | 100 | ((void) path); |
HannesTschofenig | 0:796d0f61a05b | 101 | ((void) output); |
HannesTschofenig | 0:796d0f61a05b | 102 | return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE; |
HannesTschofenig | 0:796d0f61a05b | 103 | #endif |
HannesTschofenig | 0:796d0f61a05b | 104 | } |
HannesTschofenig | 0:796d0f61a05b | 105 | |
HannesTschofenig | 0:796d0f61a05b | 106 | static void md2_hmac_starts_wrap( void *ctx, const unsigned char *key, |
HannesTschofenig | 0:796d0f61a05b | 107 | size_t keylen ) |
HannesTschofenig | 0:796d0f61a05b | 108 | { |
HannesTschofenig | 0:796d0f61a05b | 109 | md2_hmac_starts( (md2_context *) ctx, key, keylen ); |
HannesTschofenig | 0:796d0f61a05b | 110 | } |
HannesTschofenig | 0:796d0f61a05b | 111 | |
HannesTschofenig | 0:796d0f61a05b | 112 | static void md2_hmac_update_wrap( void *ctx, const unsigned char *input, |
HannesTschofenig | 0:796d0f61a05b | 113 | size_t ilen ) |
HannesTschofenig | 0:796d0f61a05b | 114 | { |
HannesTschofenig | 0:796d0f61a05b | 115 | md2_hmac_update( (md2_context *) ctx, input, ilen ); |
HannesTschofenig | 0:796d0f61a05b | 116 | } |
HannesTschofenig | 0:796d0f61a05b | 117 | |
HannesTschofenig | 0:796d0f61a05b | 118 | static void md2_hmac_finish_wrap( void *ctx, unsigned char *output ) |
HannesTschofenig | 0:796d0f61a05b | 119 | { |
HannesTschofenig | 0:796d0f61a05b | 120 | md2_hmac_finish( (md2_context *) ctx, output ); |
HannesTschofenig | 0:796d0f61a05b | 121 | } |
HannesTschofenig | 0:796d0f61a05b | 122 | |
HannesTschofenig | 0:796d0f61a05b | 123 | static void md2_hmac_reset_wrap( void *ctx ) |
HannesTschofenig | 0:796d0f61a05b | 124 | { |
HannesTschofenig | 0:796d0f61a05b | 125 | md2_hmac_reset( (md2_context *) ctx ); |
HannesTschofenig | 0:796d0f61a05b | 126 | } |
HannesTschofenig | 0:796d0f61a05b | 127 | |
HannesTschofenig | 0:796d0f61a05b | 128 | static void * md2_ctx_alloc( void ) |
HannesTschofenig | 0:796d0f61a05b | 129 | { |
HannesTschofenig | 0:796d0f61a05b | 130 | return polarssl_malloc( sizeof( md2_context ) ); |
HannesTschofenig | 0:796d0f61a05b | 131 | } |
HannesTschofenig | 0:796d0f61a05b | 132 | |
HannesTschofenig | 0:796d0f61a05b | 133 | static void md2_ctx_free( void *ctx ) |
HannesTschofenig | 0:796d0f61a05b | 134 | { |
HannesTschofenig | 0:796d0f61a05b | 135 | polarssl_free( ctx ); |
HannesTschofenig | 0:796d0f61a05b | 136 | } |
HannesTschofenig | 0:796d0f61a05b | 137 | |
HannesTschofenig | 0:796d0f61a05b | 138 | static void md2_process_wrap( void *ctx, const unsigned char *data ) |
HannesTschofenig | 0:796d0f61a05b | 139 | { |
HannesTschofenig | 0:796d0f61a05b | 140 | ((void) data); |
HannesTschofenig | 0:796d0f61a05b | 141 | |
HannesTschofenig | 0:796d0f61a05b | 142 | md2_process( (md2_context *) ctx ); |
HannesTschofenig | 0:796d0f61a05b | 143 | } |
HannesTschofenig | 0:796d0f61a05b | 144 | |
HannesTschofenig | 0:796d0f61a05b | 145 | const md_info_t md2_info = { |
HannesTschofenig | 0:796d0f61a05b | 146 | POLARSSL_MD_MD2, |
HannesTschofenig | 0:796d0f61a05b | 147 | "MD2", |
HannesTschofenig | 0:796d0f61a05b | 148 | 16, |
HannesTschofenig | 0:796d0f61a05b | 149 | md2_starts_wrap, |
HannesTschofenig | 0:796d0f61a05b | 150 | md2_update_wrap, |
HannesTschofenig | 0:796d0f61a05b | 151 | md2_finish_wrap, |
HannesTschofenig | 0:796d0f61a05b | 152 | md2, |
HannesTschofenig | 0:796d0f61a05b | 153 | md2_file_wrap, |
HannesTschofenig | 0:796d0f61a05b | 154 | md2_hmac_starts_wrap, |
HannesTschofenig | 0:796d0f61a05b | 155 | md2_hmac_update_wrap, |
HannesTschofenig | 0:796d0f61a05b | 156 | md2_hmac_finish_wrap, |
HannesTschofenig | 0:796d0f61a05b | 157 | md2_hmac_reset_wrap, |
HannesTschofenig | 0:796d0f61a05b | 158 | md2_hmac, |
HannesTschofenig | 0:796d0f61a05b | 159 | md2_ctx_alloc, |
HannesTschofenig | 0:796d0f61a05b | 160 | md2_ctx_free, |
HannesTschofenig | 0:796d0f61a05b | 161 | md2_process_wrap, |
HannesTschofenig | 0:796d0f61a05b | 162 | }; |
HannesTschofenig | 0:796d0f61a05b | 163 | |
HannesTschofenig | 0:796d0f61a05b | 164 | #endif /* POLARSSL_MD2_C */ |
HannesTschofenig | 0:796d0f61a05b | 165 | |
HannesTschofenig | 0:796d0f61a05b | 166 | #if defined(POLARSSL_MD4_C) |
HannesTschofenig | 0:796d0f61a05b | 167 | |
HannesTschofenig | 0:796d0f61a05b | 168 | static void md4_starts_wrap( void *ctx ) |
HannesTschofenig | 0:796d0f61a05b | 169 | { |
HannesTschofenig | 0:796d0f61a05b | 170 | md4_starts( (md4_context *) ctx ); |
HannesTschofenig | 0:796d0f61a05b | 171 | } |
HannesTschofenig | 0:796d0f61a05b | 172 | |
HannesTschofenig | 0:796d0f61a05b | 173 | static void md4_update_wrap( void *ctx, const unsigned char *input, |
HannesTschofenig | 0:796d0f61a05b | 174 | size_t ilen ) |
HannesTschofenig | 0:796d0f61a05b | 175 | { |
HannesTschofenig | 0:796d0f61a05b | 176 | md4_update( (md4_context *) ctx, input, ilen ); |
HannesTschofenig | 0:796d0f61a05b | 177 | } |
HannesTschofenig | 0:796d0f61a05b | 178 | |
HannesTschofenig | 0:796d0f61a05b | 179 | static void md4_finish_wrap( void *ctx, unsigned char *output ) |
HannesTschofenig | 0:796d0f61a05b | 180 | { |
HannesTschofenig | 0:796d0f61a05b | 181 | md4_finish( (md4_context *) ctx, output ); |
HannesTschofenig | 0:796d0f61a05b | 182 | } |
HannesTschofenig | 0:796d0f61a05b | 183 | |
HannesTschofenig | 0:796d0f61a05b | 184 | static int md4_file_wrap( const char *path, unsigned char *output ) |
HannesTschofenig | 0:796d0f61a05b | 185 | { |
HannesTschofenig | 0:796d0f61a05b | 186 | #if defined(POLARSSL_FS_IO) |
HannesTschofenig | 0:796d0f61a05b | 187 | return md4_file( path, output ); |
HannesTschofenig | 0:796d0f61a05b | 188 | #else |
HannesTschofenig | 0:796d0f61a05b | 189 | ((void) path); |
HannesTschofenig | 0:796d0f61a05b | 190 | ((void) output); |
HannesTschofenig | 0:796d0f61a05b | 191 | return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE; |
HannesTschofenig | 0:796d0f61a05b | 192 | #endif |
HannesTschofenig | 0:796d0f61a05b | 193 | } |
HannesTschofenig | 0:796d0f61a05b | 194 | |
HannesTschofenig | 0:796d0f61a05b | 195 | static void md4_hmac_starts_wrap( void *ctx, const unsigned char *key, |
HannesTschofenig | 0:796d0f61a05b | 196 | size_t keylen ) |
HannesTschofenig | 0:796d0f61a05b | 197 | { |
HannesTschofenig | 0:796d0f61a05b | 198 | md4_hmac_starts( (md4_context *) ctx, key, keylen ); |
HannesTschofenig | 0:796d0f61a05b | 199 | } |
HannesTschofenig | 0:796d0f61a05b | 200 | |
HannesTschofenig | 0:796d0f61a05b | 201 | static void md4_hmac_update_wrap( void *ctx, const unsigned char *input, |
HannesTschofenig | 0:796d0f61a05b | 202 | size_t ilen ) |
HannesTschofenig | 0:796d0f61a05b | 203 | { |
HannesTschofenig | 0:796d0f61a05b | 204 | md4_hmac_update( (md4_context *) ctx, input, ilen ); |
HannesTschofenig | 0:796d0f61a05b | 205 | } |
HannesTschofenig | 0:796d0f61a05b | 206 | |
HannesTschofenig | 0:796d0f61a05b | 207 | static void md4_hmac_finish_wrap( void *ctx, unsigned char *output ) |
HannesTschofenig | 0:796d0f61a05b | 208 | { |
HannesTschofenig | 0:796d0f61a05b | 209 | md4_hmac_finish( (md4_context *) ctx, output ); |
HannesTschofenig | 0:796d0f61a05b | 210 | } |
HannesTschofenig | 0:796d0f61a05b | 211 | |
HannesTschofenig | 0:796d0f61a05b | 212 | static void md4_hmac_reset_wrap( void *ctx ) |
HannesTschofenig | 0:796d0f61a05b | 213 | { |
HannesTschofenig | 0:796d0f61a05b | 214 | md4_hmac_reset( (md4_context *) ctx ); |
HannesTschofenig | 0:796d0f61a05b | 215 | } |
HannesTschofenig | 0:796d0f61a05b | 216 | |
HannesTschofenig | 0:796d0f61a05b | 217 | static void *md4_ctx_alloc( void ) |
HannesTschofenig | 0:796d0f61a05b | 218 | { |
HannesTschofenig | 0:796d0f61a05b | 219 | return polarssl_malloc( sizeof( md4_context ) ); |
HannesTschofenig | 0:796d0f61a05b | 220 | } |
HannesTschofenig | 0:796d0f61a05b | 221 | |
HannesTschofenig | 0:796d0f61a05b | 222 | static void md4_ctx_free( void *ctx ) |
HannesTschofenig | 0:796d0f61a05b | 223 | { |
HannesTschofenig | 0:796d0f61a05b | 224 | polarssl_free( ctx ); |
HannesTschofenig | 0:796d0f61a05b | 225 | } |
HannesTschofenig | 0:796d0f61a05b | 226 | |
HannesTschofenig | 0:796d0f61a05b | 227 | static void md4_process_wrap( void *ctx, const unsigned char *data ) |
HannesTschofenig | 0:796d0f61a05b | 228 | { |
HannesTschofenig | 0:796d0f61a05b | 229 | md4_process( (md4_context *) ctx, data ); |
HannesTschofenig | 0:796d0f61a05b | 230 | } |
HannesTschofenig | 0:796d0f61a05b | 231 | |
HannesTschofenig | 0:796d0f61a05b | 232 | const md_info_t md4_info = { |
HannesTschofenig | 0:796d0f61a05b | 233 | POLARSSL_MD_MD4, |
HannesTschofenig | 0:796d0f61a05b | 234 | "MD4", |
HannesTschofenig | 0:796d0f61a05b | 235 | 16, |
HannesTschofenig | 0:796d0f61a05b | 236 | md4_starts_wrap, |
HannesTschofenig | 0:796d0f61a05b | 237 | md4_update_wrap, |
HannesTschofenig | 0:796d0f61a05b | 238 | md4_finish_wrap, |
HannesTschofenig | 0:796d0f61a05b | 239 | md4, |
HannesTschofenig | 0:796d0f61a05b | 240 | md4_file_wrap, |
HannesTschofenig | 0:796d0f61a05b | 241 | md4_hmac_starts_wrap, |
HannesTschofenig | 0:796d0f61a05b | 242 | md4_hmac_update_wrap, |
HannesTschofenig | 0:796d0f61a05b | 243 | md4_hmac_finish_wrap, |
HannesTschofenig | 0:796d0f61a05b | 244 | md4_hmac_reset_wrap, |
HannesTschofenig | 0:796d0f61a05b | 245 | md4_hmac, |
HannesTschofenig | 0:796d0f61a05b | 246 | md4_ctx_alloc, |
HannesTschofenig | 0:796d0f61a05b | 247 | md4_ctx_free, |
HannesTschofenig | 0:796d0f61a05b | 248 | md4_process_wrap, |
HannesTschofenig | 0:796d0f61a05b | 249 | }; |
HannesTschofenig | 0:796d0f61a05b | 250 | |
HannesTschofenig | 0:796d0f61a05b | 251 | #endif /* POLARSSL_MD4_C */ |
HannesTschofenig | 0:796d0f61a05b | 252 | |
HannesTschofenig | 0:796d0f61a05b | 253 | #if defined(POLARSSL_MD5_C) |
HannesTschofenig | 0:796d0f61a05b | 254 | |
HannesTschofenig | 0:796d0f61a05b | 255 | static void md5_starts_wrap( void *ctx ) |
HannesTschofenig | 0:796d0f61a05b | 256 | { |
HannesTschofenig | 0:796d0f61a05b | 257 | md5_starts( (md5_context *) ctx ); |
HannesTschofenig | 0:796d0f61a05b | 258 | } |
HannesTschofenig | 0:796d0f61a05b | 259 | |
HannesTschofenig | 0:796d0f61a05b | 260 | static void md5_update_wrap( void *ctx, const unsigned char *input, |
HannesTschofenig | 0:796d0f61a05b | 261 | size_t ilen ) |
HannesTschofenig | 0:796d0f61a05b | 262 | { |
HannesTschofenig | 0:796d0f61a05b | 263 | md5_update( (md5_context *) ctx, input, ilen ); |
HannesTschofenig | 0:796d0f61a05b | 264 | } |
HannesTschofenig | 0:796d0f61a05b | 265 | |
HannesTschofenig | 0:796d0f61a05b | 266 | static void md5_finish_wrap( void *ctx, unsigned char *output ) |
HannesTschofenig | 0:796d0f61a05b | 267 | { |
HannesTschofenig | 0:796d0f61a05b | 268 | md5_finish( (md5_context *) ctx, output ); |
HannesTschofenig | 0:796d0f61a05b | 269 | } |
HannesTschofenig | 0:796d0f61a05b | 270 | |
HannesTschofenig | 0:796d0f61a05b | 271 | static int md5_file_wrap( const char *path, unsigned char *output ) |
HannesTschofenig | 0:796d0f61a05b | 272 | { |
HannesTschofenig | 0:796d0f61a05b | 273 | #if defined(POLARSSL_FS_IO) |
HannesTschofenig | 0:796d0f61a05b | 274 | return md5_file( path, output ); |
HannesTschofenig | 0:796d0f61a05b | 275 | #else |
HannesTschofenig | 0:796d0f61a05b | 276 | ((void) path); |
HannesTschofenig | 0:796d0f61a05b | 277 | ((void) output); |
HannesTschofenig | 0:796d0f61a05b | 278 | return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE; |
HannesTschofenig | 0:796d0f61a05b | 279 | #endif |
HannesTschofenig | 0:796d0f61a05b | 280 | } |
HannesTschofenig | 0:796d0f61a05b | 281 | |
HannesTschofenig | 0:796d0f61a05b | 282 | static void md5_hmac_starts_wrap( void *ctx, const unsigned char *key, |
HannesTschofenig | 0:796d0f61a05b | 283 | size_t keylen ) |
HannesTschofenig | 0:796d0f61a05b | 284 | { |
HannesTschofenig | 0:796d0f61a05b | 285 | md5_hmac_starts( (md5_context *) ctx, key, keylen ); |
HannesTschofenig | 0:796d0f61a05b | 286 | } |
HannesTschofenig | 0:796d0f61a05b | 287 | |
HannesTschofenig | 0:796d0f61a05b | 288 | static void md5_hmac_update_wrap( void *ctx, const unsigned char *input, |
HannesTschofenig | 0:796d0f61a05b | 289 | size_t ilen ) |
HannesTschofenig | 0:796d0f61a05b | 290 | { |
HannesTschofenig | 0:796d0f61a05b | 291 | md5_hmac_update( (md5_context *) ctx, input, ilen ); |
HannesTschofenig | 0:796d0f61a05b | 292 | } |
HannesTschofenig | 0:796d0f61a05b | 293 | |
HannesTschofenig | 0:796d0f61a05b | 294 | static void md5_hmac_finish_wrap( void *ctx, unsigned char *output ) |
HannesTschofenig | 0:796d0f61a05b | 295 | { |
HannesTschofenig | 0:796d0f61a05b | 296 | md5_hmac_finish( (md5_context *) ctx, output ); |
HannesTschofenig | 0:796d0f61a05b | 297 | } |
HannesTschofenig | 0:796d0f61a05b | 298 | |
HannesTschofenig | 0:796d0f61a05b | 299 | static void md5_hmac_reset_wrap( void *ctx ) |
HannesTschofenig | 0:796d0f61a05b | 300 | { |
HannesTschofenig | 0:796d0f61a05b | 301 | md5_hmac_reset( (md5_context *) ctx ); |
HannesTschofenig | 0:796d0f61a05b | 302 | } |
HannesTschofenig | 0:796d0f61a05b | 303 | |
HannesTschofenig | 0:796d0f61a05b | 304 | static void * md5_ctx_alloc( void ) |
HannesTschofenig | 0:796d0f61a05b | 305 | { |
HannesTschofenig | 0:796d0f61a05b | 306 | return polarssl_malloc( sizeof( md5_context ) ); |
HannesTschofenig | 0:796d0f61a05b | 307 | } |
HannesTschofenig | 0:796d0f61a05b | 308 | |
HannesTschofenig | 0:796d0f61a05b | 309 | static void md5_ctx_free( void *ctx ) |
HannesTschofenig | 0:796d0f61a05b | 310 | { |
HannesTschofenig | 0:796d0f61a05b | 311 | polarssl_free( ctx ); |
HannesTschofenig | 0:796d0f61a05b | 312 | } |
HannesTschofenig | 0:796d0f61a05b | 313 | |
HannesTschofenig | 0:796d0f61a05b | 314 | static void md5_process_wrap( void *ctx, const unsigned char *data ) |
HannesTschofenig | 0:796d0f61a05b | 315 | { |
HannesTschofenig | 0:796d0f61a05b | 316 | md5_process( (md5_context *) ctx, data ); |
HannesTschofenig | 0:796d0f61a05b | 317 | } |
HannesTschofenig | 0:796d0f61a05b | 318 | |
HannesTschofenig | 0:796d0f61a05b | 319 | const md_info_t md5_info = { |
HannesTschofenig | 0:796d0f61a05b | 320 | POLARSSL_MD_MD5, |
HannesTschofenig | 0:796d0f61a05b | 321 | "MD5", |
HannesTschofenig | 0:796d0f61a05b | 322 | 16, |
HannesTschofenig | 0:796d0f61a05b | 323 | md5_starts_wrap, |
HannesTschofenig | 0:796d0f61a05b | 324 | md5_update_wrap, |
HannesTschofenig | 0:796d0f61a05b | 325 | md5_finish_wrap, |
HannesTschofenig | 0:796d0f61a05b | 326 | md5, |
HannesTschofenig | 0:796d0f61a05b | 327 | md5_file_wrap, |
HannesTschofenig | 0:796d0f61a05b | 328 | md5_hmac_starts_wrap, |
HannesTschofenig | 0:796d0f61a05b | 329 | md5_hmac_update_wrap, |
HannesTschofenig | 0:796d0f61a05b | 330 | md5_hmac_finish_wrap, |
HannesTschofenig | 0:796d0f61a05b | 331 | md5_hmac_reset_wrap, |
HannesTschofenig | 0:796d0f61a05b | 332 | md5_hmac, |
HannesTschofenig | 0:796d0f61a05b | 333 | md5_ctx_alloc, |
HannesTschofenig | 0:796d0f61a05b | 334 | md5_ctx_free, |
HannesTschofenig | 0:796d0f61a05b | 335 | md5_process_wrap, |
HannesTschofenig | 0:796d0f61a05b | 336 | }; |
HannesTschofenig | 0:796d0f61a05b | 337 | |
HannesTschofenig | 0:796d0f61a05b | 338 | #endif /* POLARSSL_MD5_C */ |
HannesTschofenig | 0:796d0f61a05b | 339 | |
HannesTschofenig | 0:796d0f61a05b | 340 | #if defined(POLARSSL_RIPEMD160_C) |
HannesTschofenig | 0:796d0f61a05b | 341 | |
HannesTschofenig | 0:796d0f61a05b | 342 | static void ripemd160_starts_wrap( void *ctx ) |
HannesTschofenig | 0:796d0f61a05b | 343 | { |
HannesTschofenig | 0:796d0f61a05b | 344 | ripemd160_starts( (ripemd160_context *) ctx ); |
HannesTschofenig | 0:796d0f61a05b | 345 | } |
HannesTschofenig | 0:796d0f61a05b | 346 | |
HannesTschofenig | 0:796d0f61a05b | 347 | static void ripemd160_update_wrap( void *ctx, const unsigned char *input, |
HannesTschofenig | 0:796d0f61a05b | 348 | size_t ilen ) |
HannesTschofenig | 0:796d0f61a05b | 349 | { |
HannesTschofenig | 0:796d0f61a05b | 350 | ripemd160_update( (ripemd160_context *) ctx, input, ilen ); |
HannesTschofenig | 0:796d0f61a05b | 351 | } |
HannesTschofenig | 0:796d0f61a05b | 352 | |
HannesTschofenig | 0:796d0f61a05b | 353 | static void ripemd160_finish_wrap( void *ctx, unsigned char *output ) |
HannesTschofenig | 0:796d0f61a05b | 354 | { |
HannesTschofenig | 0:796d0f61a05b | 355 | ripemd160_finish( (ripemd160_context *) ctx, output ); |
HannesTschofenig | 0:796d0f61a05b | 356 | } |
HannesTschofenig | 0:796d0f61a05b | 357 | |
HannesTschofenig | 0:796d0f61a05b | 358 | static int ripemd160_file_wrap( const char *path, unsigned char *output ) |
HannesTschofenig | 0:796d0f61a05b | 359 | { |
HannesTschofenig | 0:796d0f61a05b | 360 | #if defined(POLARSSL_FS_IO) |
HannesTschofenig | 0:796d0f61a05b | 361 | return ripemd160_file( path, output ); |
HannesTschofenig | 0:796d0f61a05b | 362 | #else |
HannesTschofenig | 0:796d0f61a05b | 363 | ((void) path); |
HannesTschofenig | 0:796d0f61a05b | 364 | ((void) output); |
HannesTschofenig | 0:796d0f61a05b | 365 | return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE; |
HannesTschofenig | 0:796d0f61a05b | 366 | #endif |
HannesTschofenig | 0:796d0f61a05b | 367 | } |
HannesTschofenig | 0:796d0f61a05b | 368 | |
HannesTschofenig | 0:796d0f61a05b | 369 | static void ripemd160_hmac_starts_wrap( void *ctx, const unsigned char *key, |
HannesTschofenig | 0:796d0f61a05b | 370 | size_t keylen ) |
HannesTschofenig | 0:796d0f61a05b | 371 | { |
HannesTschofenig | 0:796d0f61a05b | 372 | ripemd160_hmac_starts( (ripemd160_context *) ctx, key, keylen ); |
HannesTschofenig | 0:796d0f61a05b | 373 | } |
HannesTschofenig | 0:796d0f61a05b | 374 | |
HannesTschofenig | 0:796d0f61a05b | 375 | static void ripemd160_hmac_update_wrap( void *ctx, const unsigned char *input, |
HannesTschofenig | 0:796d0f61a05b | 376 | size_t ilen ) |
HannesTschofenig | 0:796d0f61a05b | 377 | { |
HannesTschofenig | 0:796d0f61a05b | 378 | ripemd160_hmac_update( (ripemd160_context *) ctx, input, ilen ); |
HannesTschofenig | 0:796d0f61a05b | 379 | } |
HannesTschofenig | 0:796d0f61a05b | 380 | |
HannesTschofenig | 0:796d0f61a05b | 381 | static void ripemd160_hmac_finish_wrap( void *ctx, unsigned char *output ) |
HannesTschofenig | 0:796d0f61a05b | 382 | { |
HannesTschofenig | 0:796d0f61a05b | 383 | ripemd160_hmac_finish( (ripemd160_context *) ctx, output ); |
HannesTschofenig | 0:796d0f61a05b | 384 | } |
HannesTschofenig | 0:796d0f61a05b | 385 | |
HannesTschofenig | 0:796d0f61a05b | 386 | static void ripemd160_hmac_reset_wrap( void *ctx ) |
HannesTschofenig | 0:796d0f61a05b | 387 | { |
HannesTschofenig | 0:796d0f61a05b | 388 | ripemd160_hmac_reset( (ripemd160_context *) ctx ); |
HannesTschofenig | 0:796d0f61a05b | 389 | } |
HannesTschofenig | 0:796d0f61a05b | 390 | |
HannesTschofenig | 0:796d0f61a05b | 391 | static void * ripemd160_ctx_alloc( void ) |
HannesTschofenig | 0:796d0f61a05b | 392 | { |
HannesTschofenig | 0:796d0f61a05b | 393 | return polarssl_malloc( sizeof( ripemd160_context ) ); |
HannesTschofenig | 0:796d0f61a05b | 394 | } |
HannesTschofenig | 0:796d0f61a05b | 395 | |
HannesTschofenig | 0:796d0f61a05b | 396 | static void ripemd160_ctx_free( void *ctx ) |
HannesTschofenig | 0:796d0f61a05b | 397 | { |
HannesTschofenig | 0:796d0f61a05b | 398 | polarssl_free( ctx ); |
HannesTschofenig | 0:796d0f61a05b | 399 | } |
HannesTschofenig | 0:796d0f61a05b | 400 | |
HannesTschofenig | 0:796d0f61a05b | 401 | static void ripemd160_process_wrap( void *ctx, const unsigned char *data ) |
HannesTschofenig | 0:796d0f61a05b | 402 | { |
HannesTschofenig | 0:796d0f61a05b | 403 | ripemd160_process( (ripemd160_context *) ctx, data ); |
HannesTschofenig | 0:796d0f61a05b | 404 | } |
HannesTschofenig | 0:796d0f61a05b | 405 | |
HannesTschofenig | 0:796d0f61a05b | 406 | const md_info_t ripemd160_info = { |
HannesTschofenig | 0:796d0f61a05b | 407 | POLARSSL_MD_RIPEMD160, |
HannesTschofenig | 0:796d0f61a05b | 408 | "RIPEMD160", |
HannesTschofenig | 0:796d0f61a05b | 409 | 20, |
HannesTschofenig | 0:796d0f61a05b | 410 | ripemd160_starts_wrap, |
HannesTschofenig | 0:796d0f61a05b | 411 | ripemd160_update_wrap, |
HannesTschofenig | 0:796d0f61a05b | 412 | ripemd160_finish_wrap, |
HannesTschofenig | 0:796d0f61a05b | 413 | ripemd160, |
HannesTschofenig | 0:796d0f61a05b | 414 | ripemd160_file_wrap, |
HannesTschofenig | 0:796d0f61a05b | 415 | ripemd160_hmac_starts_wrap, |
HannesTschofenig | 0:796d0f61a05b | 416 | ripemd160_hmac_update_wrap, |
HannesTschofenig | 0:796d0f61a05b | 417 | ripemd160_hmac_finish_wrap, |
HannesTschofenig | 0:796d0f61a05b | 418 | ripemd160_hmac_reset_wrap, |
HannesTschofenig | 0:796d0f61a05b | 419 | ripemd160_hmac, |
HannesTschofenig | 0:796d0f61a05b | 420 | ripemd160_ctx_alloc, |
HannesTschofenig | 0:796d0f61a05b | 421 | ripemd160_ctx_free, |
HannesTschofenig | 0:796d0f61a05b | 422 | ripemd160_process_wrap, |
HannesTschofenig | 0:796d0f61a05b | 423 | }; |
HannesTschofenig | 0:796d0f61a05b | 424 | |
HannesTschofenig | 0:796d0f61a05b | 425 | #endif /* POLARSSL_RIPEMD160_C */ |
HannesTschofenig | 0:796d0f61a05b | 426 | |
HannesTschofenig | 0:796d0f61a05b | 427 | #if defined(POLARSSL_SHA1_C) |
HannesTschofenig | 0:796d0f61a05b | 428 | |
HannesTschofenig | 0:796d0f61a05b | 429 | static void sha1_starts_wrap( void *ctx ) |
HannesTschofenig | 0:796d0f61a05b | 430 | { |
HannesTschofenig | 0:796d0f61a05b | 431 | sha1_starts( (sha1_context *) ctx ); |
HannesTschofenig | 0:796d0f61a05b | 432 | } |
HannesTschofenig | 0:796d0f61a05b | 433 | |
HannesTschofenig | 0:796d0f61a05b | 434 | static void sha1_update_wrap( void *ctx, const unsigned char *input, |
HannesTschofenig | 0:796d0f61a05b | 435 | size_t ilen ) |
HannesTschofenig | 0:796d0f61a05b | 436 | { |
HannesTschofenig | 0:796d0f61a05b | 437 | sha1_update( (sha1_context *) ctx, input, ilen ); |
HannesTschofenig | 0:796d0f61a05b | 438 | } |
HannesTschofenig | 0:796d0f61a05b | 439 | |
HannesTschofenig | 0:796d0f61a05b | 440 | static void sha1_finish_wrap( void *ctx, unsigned char *output ) |
HannesTschofenig | 0:796d0f61a05b | 441 | { |
HannesTschofenig | 0:796d0f61a05b | 442 | sha1_finish( (sha1_context *) ctx, output ); |
HannesTschofenig | 0:796d0f61a05b | 443 | } |
HannesTschofenig | 0:796d0f61a05b | 444 | |
HannesTschofenig | 0:796d0f61a05b | 445 | static int sha1_file_wrap( const char *path, unsigned char *output ) |
HannesTschofenig | 0:796d0f61a05b | 446 | { |
HannesTschofenig | 0:796d0f61a05b | 447 | #if defined(POLARSSL_FS_IO) |
HannesTschofenig | 0:796d0f61a05b | 448 | return sha1_file( path, output ); |
HannesTschofenig | 0:796d0f61a05b | 449 | #else |
HannesTschofenig | 0:796d0f61a05b | 450 | ((void) path); |
HannesTschofenig | 0:796d0f61a05b | 451 | ((void) output); |
HannesTschofenig | 0:796d0f61a05b | 452 | return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE; |
HannesTschofenig | 0:796d0f61a05b | 453 | #endif |
HannesTschofenig | 0:796d0f61a05b | 454 | } |
HannesTschofenig | 0:796d0f61a05b | 455 | |
HannesTschofenig | 0:796d0f61a05b | 456 | static void sha1_hmac_starts_wrap( void *ctx, const unsigned char *key, |
HannesTschofenig | 0:796d0f61a05b | 457 | size_t keylen ) |
HannesTschofenig | 0:796d0f61a05b | 458 | { |
HannesTschofenig | 0:796d0f61a05b | 459 | sha1_hmac_starts( (sha1_context *) ctx, key, keylen ); |
HannesTschofenig | 0:796d0f61a05b | 460 | } |
HannesTschofenig | 0:796d0f61a05b | 461 | |
HannesTschofenig | 0:796d0f61a05b | 462 | static void sha1_hmac_update_wrap( void *ctx, const unsigned char *input, |
HannesTschofenig | 0:796d0f61a05b | 463 | size_t ilen ) |
HannesTschofenig | 0:796d0f61a05b | 464 | { |
HannesTschofenig | 0:796d0f61a05b | 465 | sha1_hmac_update( (sha1_context *) ctx, input, ilen ); |
HannesTschofenig | 0:796d0f61a05b | 466 | } |
HannesTschofenig | 0:796d0f61a05b | 467 | |
HannesTschofenig | 0:796d0f61a05b | 468 | static void sha1_hmac_finish_wrap( void *ctx, unsigned char *output ) |
HannesTschofenig | 0:796d0f61a05b | 469 | { |
HannesTschofenig | 0:796d0f61a05b | 470 | sha1_hmac_finish( (sha1_context *) ctx, output ); |
HannesTschofenig | 0:796d0f61a05b | 471 | } |
HannesTschofenig | 0:796d0f61a05b | 472 | |
HannesTschofenig | 0:796d0f61a05b | 473 | static void sha1_hmac_reset_wrap( void *ctx ) |
HannesTschofenig | 0:796d0f61a05b | 474 | { |
HannesTschofenig | 0:796d0f61a05b | 475 | sha1_hmac_reset( (sha1_context *) ctx ); |
HannesTschofenig | 0:796d0f61a05b | 476 | } |
HannesTschofenig | 0:796d0f61a05b | 477 | |
HannesTschofenig | 0:796d0f61a05b | 478 | static void * sha1_ctx_alloc( void ) |
HannesTschofenig | 0:796d0f61a05b | 479 | { |
HannesTschofenig | 0:796d0f61a05b | 480 | return polarssl_malloc( sizeof( sha1_context ) ); |
HannesTschofenig | 0:796d0f61a05b | 481 | } |
HannesTschofenig | 0:796d0f61a05b | 482 | |
HannesTschofenig | 0:796d0f61a05b | 483 | static void sha1_ctx_free( void *ctx ) |
HannesTschofenig | 0:796d0f61a05b | 484 | { |
HannesTschofenig | 0:796d0f61a05b | 485 | polarssl_free( ctx ); |
HannesTschofenig | 0:796d0f61a05b | 486 | } |
HannesTschofenig | 0:796d0f61a05b | 487 | |
HannesTschofenig | 0:796d0f61a05b | 488 | static void sha1_process_wrap( void *ctx, const unsigned char *data ) |
HannesTschofenig | 0:796d0f61a05b | 489 | { |
HannesTschofenig | 0:796d0f61a05b | 490 | sha1_process( (sha1_context *) ctx, data ); |
HannesTschofenig | 0:796d0f61a05b | 491 | } |
HannesTschofenig | 0:796d0f61a05b | 492 | |
HannesTschofenig | 0:796d0f61a05b | 493 | const md_info_t sha1_info = { |
HannesTschofenig | 0:796d0f61a05b | 494 | POLARSSL_MD_SHA1, |
HannesTschofenig | 0:796d0f61a05b | 495 | "SHA1", |
HannesTschofenig | 0:796d0f61a05b | 496 | 20, |
HannesTschofenig | 0:796d0f61a05b | 497 | sha1_starts_wrap, |
HannesTschofenig | 0:796d0f61a05b | 498 | sha1_update_wrap, |
HannesTschofenig | 0:796d0f61a05b | 499 | sha1_finish_wrap, |
HannesTschofenig | 0:796d0f61a05b | 500 | sha1, |
HannesTschofenig | 0:796d0f61a05b | 501 | sha1_file_wrap, |
HannesTschofenig | 0:796d0f61a05b | 502 | sha1_hmac_starts_wrap, |
HannesTschofenig | 0:796d0f61a05b | 503 | sha1_hmac_update_wrap, |
HannesTschofenig | 0:796d0f61a05b | 504 | sha1_hmac_finish_wrap, |
HannesTschofenig | 0:796d0f61a05b | 505 | sha1_hmac_reset_wrap, |
HannesTschofenig | 0:796d0f61a05b | 506 | sha1_hmac, |
HannesTschofenig | 0:796d0f61a05b | 507 | sha1_ctx_alloc, |
HannesTschofenig | 0:796d0f61a05b | 508 | sha1_ctx_free, |
HannesTschofenig | 0:796d0f61a05b | 509 | sha1_process_wrap, |
HannesTschofenig | 0:796d0f61a05b | 510 | }; |
HannesTschofenig | 0:796d0f61a05b | 511 | |
HannesTschofenig | 0:796d0f61a05b | 512 | #endif /* POLARSSL_SHA1_C */ |
HannesTschofenig | 0:796d0f61a05b | 513 | |
HannesTschofenig | 0:796d0f61a05b | 514 | /* |
HannesTschofenig | 0:796d0f61a05b | 515 | * Wrappers for generic message digests |
HannesTschofenig | 0:796d0f61a05b | 516 | */ |
HannesTschofenig | 0:796d0f61a05b | 517 | #if defined(POLARSSL_SHA256_C) |
HannesTschofenig | 0:796d0f61a05b | 518 | |
HannesTschofenig | 0:796d0f61a05b | 519 | static void sha224_starts_wrap( void *ctx ) |
HannesTschofenig | 0:796d0f61a05b | 520 | { |
HannesTschofenig | 0:796d0f61a05b | 521 | sha256_starts( (sha256_context *) ctx, 1 ); |
HannesTschofenig | 0:796d0f61a05b | 522 | } |
HannesTschofenig | 0:796d0f61a05b | 523 | |
HannesTschofenig | 0:796d0f61a05b | 524 | static void sha224_update_wrap( void *ctx, const unsigned char *input, |
HannesTschofenig | 0:796d0f61a05b | 525 | size_t ilen ) |
HannesTschofenig | 0:796d0f61a05b | 526 | { |
HannesTschofenig | 0:796d0f61a05b | 527 | sha256_update( (sha256_context *) ctx, input, ilen ); |
HannesTschofenig | 0:796d0f61a05b | 528 | } |
HannesTschofenig | 0:796d0f61a05b | 529 | |
HannesTschofenig | 0:796d0f61a05b | 530 | static void sha224_finish_wrap( void *ctx, unsigned char *output ) |
HannesTschofenig | 0:796d0f61a05b | 531 | { |
HannesTschofenig | 0:796d0f61a05b | 532 | sha256_finish( (sha256_context *) ctx, output ); |
HannesTschofenig | 0:796d0f61a05b | 533 | } |
HannesTschofenig | 0:796d0f61a05b | 534 | |
HannesTschofenig | 0:796d0f61a05b | 535 | static void sha224_wrap( const unsigned char *input, size_t ilen, |
HannesTschofenig | 0:796d0f61a05b | 536 | unsigned char *output ) |
HannesTschofenig | 0:796d0f61a05b | 537 | { |
HannesTschofenig | 0:796d0f61a05b | 538 | sha256( input, ilen, output, 1 ); |
HannesTschofenig | 0:796d0f61a05b | 539 | } |
HannesTschofenig | 0:796d0f61a05b | 540 | |
HannesTschofenig | 0:796d0f61a05b | 541 | static int sha224_file_wrap( const char *path, unsigned char *output ) |
HannesTschofenig | 0:796d0f61a05b | 542 | { |
HannesTschofenig | 0:796d0f61a05b | 543 | #if defined(POLARSSL_FS_IO) |
HannesTschofenig | 0:796d0f61a05b | 544 | return sha256_file( path, output, 1 ); |
HannesTschofenig | 0:796d0f61a05b | 545 | #else |
HannesTschofenig | 0:796d0f61a05b | 546 | ((void) path); |
HannesTschofenig | 0:796d0f61a05b | 547 | ((void) output); |
HannesTschofenig | 0:796d0f61a05b | 548 | return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE; |
HannesTschofenig | 0:796d0f61a05b | 549 | #endif |
HannesTschofenig | 0:796d0f61a05b | 550 | } |
HannesTschofenig | 0:796d0f61a05b | 551 | |
HannesTschofenig | 0:796d0f61a05b | 552 | static void sha224_hmac_starts_wrap( void *ctx, const unsigned char *key, |
HannesTschofenig | 0:796d0f61a05b | 553 | size_t keylen ) |
HannesTschofenig | 0:796d0f61a05b | 554 | { |
HannesTschofenig | 0:796d0f61a05b | 555 | sha256_hmac_starts( (sha256_context *) ctx, key, keylen, 1 ); |
HannesTschofenig | 0:796d0f61a05b | 556 | } |
HannesTschofenig | 0:796d0f61a05b | 557 | |
HannesTschofenig | 0:796d0f61a05b | 558 | static void sha224_hmac_update_wrap( void *ctx, const unsigned char *input, |
HannesTschofenig | 0:796d0f61a05b | 559 | size_t ilen ) |
HannesTschofenig | 0:796d0f61a05b | 560 | { |
HannesTschofenig | 0:796d0f61a05b | 561 | sha256_hmac_update( (sha256_context *) ctx, input, ilen ); |
HannesTschofenig | 0:796d0f61a05b | 562 | } |
HannesTschofenig | 0:796d0f61a05b | 563 | |
HannesTschofenig | 0:796d0f61a05b | 564 | static void sha224_hmac_finish_wrap( void *ctx, unsigned char *output ) |
HannesTschofenig | 0:796d0f61a05b | 565 | { |
HannesTschofenig | 0:796d0f61a05b | 566 | sha256_hmac_finish( (sha256_context *) ctx, output ); |
HannesTschofenig | 0:796d0f61a05b | 567 | } |
HannesTschofenig | 0:796d0f61a05b | 568 | |
HannesTschofenig | 0:796d0f61a05b | 569 | static void sha224_hmac_reset_wrap( void *ctx ) |
HannesTschofenig | 0:796d0f61a05b | 570 | { |
HannesTschofenig | 0:796d0f61a05b | 571 | sha256_hmac_reset( (sha256_context *) ctx ); |
HannesTschofenig | 0:796d0f61a05b | 572 | } |
HannesTschofenig | 0:796d0f61a05b | 573 | |
HannesTschofenig | 0:796d0f61a05b | 574 | static void sha224_hmac_wrap( const unsigned char *key, size_t keylen, |
HannesTschofenig | 0:796d0f61a05b | 575 | const unsigned char *input, size_t ilen, |
HannesTschofenig | 0:796d0f61a05b | 576 | unsigned char *output ) |
HannesTschofenig | 0:796d0f61a05b | 577 | { |
HannesTschofenig | 0:796d0f61a05b | 578 | sha256_hmac( key, keylen, input, ilen, output, 1 ); |
HannesTschofenig | 0:796d0f61a05b | 579 | } |
HannesTschofenig | 0:796d0f61a05b | 580 | |
HannesTschofenig | 0:796d0f61a05b | 581 | static void * sha224_ctx_alloc( void ) |
HannesTschofenig | 0:796d0f61a05b | 582 | { |
HannesTschofenig | 0:796d0f61a05b | 583 | return polarssl_malloc( sizeof( sha256_context ) ); |
HannesTschofenig | 0:796d0f61a05b | 584 | } |
HannesTschofenig | 0:796d0f61a05b | 585 | |
HannesTschofenig | 0:796d0f61a05b | 586 | static void sha224_ctx_free( void *ctx ) |
HannesTschofenig | 0:796d0f61a05b | 587 | { |
HannesTschofenig | 0:796d0f61a05b | 588 | polarssl_free( ctx ); |
HannesTschofenig | 0:796d0f61a05b | 589 | } |
HannesTschofenig | 0:796d0f61a05b | 590 | |
HannesTschofenig | 0:796d0f61a05b | 591 | static void sha224_process_wrap( void *ctx, const unsigned char *data ) |
HannesTschofenig | 0:796d0f61a05b | 592 | { |
HannesTschofenig | 0:796d0f61a05b | 593 | sha256_process( (sha256_context *) ctx, data ); |
HannesTschofenig | 0:796d0f61a05b | 594 | } |
HannesTschofenig | 0:796d0f61a05b | 595 | |
HannesTschofenig | 0:796d0f61a05b | 596 | const md_info_t sha224_info = { |
HannesTschofenig | 0:796d0f61a05b | 597 | POLARSSL_MD_SHA224, |
HannesTschofenig | 0:796d0f61a05b | 598 | "SHA224", |
HannesTschofenig | 0:796d0f61a05b | 599 | 28, |
HannesTschofenig | 0:796d0f61a05b | 600 | sha224_starts_wrap, |
HannesTschofenig | 0:796d0f61a05b | 601 | sha224_update_wrap, |
HannesTschofenig | 0:796d0f61a05b | 602 | sha224_finish_wrap, |
HannesTschofenig | 0:796d0f61a05b | 603 | sha224_wrap, |
HannesTschofenig | 0:796d0f61a05b | 604 | sha224_file_wrap, |
HannesTschofenig | 0:796d0f61a05b | 605 | sha224_hmac_starts_wrap, |
HannesTschofenig | 0:796d0f61a05b | 606 | sha224_hmac_update_wrap, |
HannesTschofenig | 0:796d0f61a05b | 607 | sha224_hmac_finish_wrap, |
HannesTschofenig | 0:796d0f61a05b | 608 | sha224_hmac_reset_wrap, |
HannesTschofenig | 0:796d0f61a05b | 609 | sha224_hmac_wrap, |
HannesTschofenig | 0:796d0f61a05b | 610 | sha224_ctx_alloc, |
HannesTschofenig | 0:796d0f61a05b | 611 | sha224_ctx_free, |
HannesTschofenig | 0:796d0f61a05b | 612 | sha224_process_wrap, |
HannesTschofenig | 0:796d0f61a05b | 613 | }; |
HannesTschofenig | 0:796d0f61a05b | 614 | |
HannesTschofenig | 0:796d0f61a05b | 615 | static void sha256_starts_wrap( void *ctx ) |
HannesTschofenig | 0:796d0f61a05b | 616 | { |
HannesTschofenig | 0:796d0f61a05b | 617 | sha256_starts( (sha256_context *) ctx, 0 ); |
HannesTschofenig | 0:796d0f61a05b | 618 | } |
HannesTschofenig | 0:796d0f61a05b | 619 | |
HannesTschofenig | 0:796d0f61a05b | 620 | static void sha256_update_wrap( void *ctx, const unsigned char *input, |
HannesTschofenig | 0:796d0f61a05b | 621 | size_t ilen ) |
HannesTschofenig | 0:796d0f61a05b | 622 | { |
HannesTschofenig | 0:796d0f61a05b | 623 | sha256_update( (sha256_context *) ctx, input, ilen ); |
HannesTschofenig | 0:796d0f61a05b | 624 | } |
HannesTschofenig | 0:796d0f61a05b | 625 | |
HannesTschofenig | 0:796d0f61a05b | 626 | static void sha256_finish_wrap( void *ctx, unsigned char *output ) |
HannesTschofenig | 0:796d0f61a05b | 627 | { |
HannesTschofenig | 0:796d0f61a05b | 628 | sha256_finish( (sha256_context *) ctx, output ); |
HannesTschofenig | 0:796d0f61a05b | 629 | } |
HannesTschofenig | 0:796d0f61a05b | 630 | |
HannesTschofenig | 0:796d0f61a05b | 631 | static void sha256_wrap( const unsigned char *input, size_t ilen, |
HannesTschofenig | 0:796d0f61a05b | 632 | unsigned char *output ) |
HannesTschofenig | 0:796d0f61a05b | 633 | { |
HannesTschofenig | 0:796d0f61a05b | 634 | sha256( input, ilen, output, 0 ); |
HannesTschofenig | 0:796d0f61a05b | 635 | } |
HannesTschofenig | 0:796d0f61a05b | 636 | |
HannesTschofenig | 0:796d0f61a05b | 637 | static int sha256_file_wrap( const char *path, unsigned char *output ) |
HannesTschofenig | 0:796d0f61a05b | 638 | { |
HannesTschofenig | 0:796d0f61a05b | 639 | #if defined(POLARSSL_FS_IO) |
HannesTschofenig | 0:796d0f61a05b | 640 | return sha256_file( path, output, 0 ); |
HannesTschofenig | 0:796d0f61a05b | 641 | #else |
HannesTschofenig | 0:796d0f61a05b | 642 | ((void) path); |
HannesTschofenig | 0:796d0f61a05b | 643 | ((void) output); |
HannesTschofenig | 0:796d0f61a05b | 644 | return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE; |
HannesTschofenig | 0:796d0f61a05b | 645 | #endif |
HannesTschofenig | 0:796d0f61a05b | 646 | } |
HannesTschofenig | 0:796d0f61a05b | 647 | |
HannesTschofenig | 0:796d0f61a05b | 648 | static void sha256_hmac_starts_wrap( void *ctx, const unsigned char *key, |
HannesTschofenig | 0:796d0f61a05b | 649 | size_t keylen ) |
HannesTschofenig | 0:796d0f61a05b | 650 | { |
HannesTschofenig | 0:796d0f61a05b | 651 | sha256_hmac_starts( (sha256_context *) ctx, key, keylen, 0 ); |
HannesTschofenig | 0:796d0f61a05b | 652 | } |
HannesTschofenig | 0:796d0f61a05b | 653 | |
HannesTschofenig | 0:796d0f61a05b | 654 | static void sha256_hmac_update_wrap( void *ctx, const unsigned char *input, |
HannesTschofenig | 0:796d0f61a05b | 655 | size_t ilen ) |
HannesTschofenig | 0:796d0f61a05b | 656 | { |
HannesTschofenig | 0:796d0f61a05b | 657 | sha256_hmac_update( (sha256_context *) ctx, input, ilen ); |
HannesTschofenig | 0:796d0f61a05b | 658 | } |
HannesTschofenig | 0:796d0f61a05b | 659 | |
HannesTschofenig | 0:796d0f61a05b | 660 | static void sha256_hmac_finish_wrap( void *ctx, unsigned char *output ) |
HannesTschofenig | 0:796d0f61a05b | 661 | { |
HannesTschofenig | 0:796d0f61a05b | 662 | sha256_hmac_finish( (sha256_context *) ctx, output ); |
HannesTschofenig | 0:796d0f61a05b | 663 | } |
HannesTschofenig | 0:796d0f61a05b | 664 | |
HannesTschofenig | 0:796d0f61a05b | 665 | static void sha256_hmac_reset_wrap( void *ctx ) |
HannesTschofenig | 0:796d0f61a05b | 666 | { |
HannesTschofenig | 0:796d0f61a05b | 667 | sha256_hmac_reset( (sha256_context *) ctx ); |
HannesTschofenig | 0:796d0f61a05b | 668 | } |
HannesTschofenig | 0:796d0f61a05b | 669 | |
HannesTschofenig | 0:796d0f61a05b | 670 | static void sha256_hmac_wrap( const unsigned char *key, size_t keylen, |
HannesTschofenig | 0:796d0f61a05b | 671 | const unsigned char *input, size_t ilen, |
HannesTschofenig | 0:796d0f61a05b | 672 | unsigned char *output ) |
HannesTschofenig | 0:796d0f61a05b | 673 | { |
HannesTschofenig | 0:796d0f61a05b | 674 | sha256_hmac( key, keylen, input, ilen, output, 0 ); |
HannesTschofenig | 0:796d0f61a05b | 675 | } |
HannesTschofenig | 0:796d0f61a05b | 676 | |
HannesTschofenig | 0:796d0f61a05b | 677 | static void * sha256_ctx_alloc( void ) |
HannesTschofenig | 0:796d0f61a05b | 678 | { |
HannesTschofenig | 0:796d0f61a05b | 679 | return polarssl_malloc( sizeof( sha256_context ) ); |
HannesTschofenig | 0:796d0f61a05b | 680 | } |
HannesTschofenig | 0:796d0f61a05b | 681 | |
HannesTschofenig | 0:796d0f61a05b | 682 | static void sha256_ctx_free( void *ctx ) |
HannesTschofenig | 0:796d0f61a05b | 683 | { |
HannesTschofenig | 0:796d0f61a05b | 684 | polarssl_free( ctx ); |
HannesTschofenig | 0:796d0f61a05b | 685 | } |
HannesTschofenig | 0:796d0f61a05b | 686 | |
HannesTschofenig | 0:796d0f61a05b | 687 | static void sha256_process_wrap( void *ctx, const unsigned char *data ) |
HannesTschofenig | 0:796d0f61a05b | 688 | { |
HannesTschofenig | 0:796d0f61a05b | 689 | sha256_process( (sha256_context *) ctx, data ); |
HannesTschofenig | 0:796d0f61a05b | 690 | } |
HannesTschofenig | 0:796d0f61a05b | 691 | |
HannesTschofenig | 0:796d0f61a05b | 692 | const md_info_t sha256_info = { |
HannesTschofenig | 0:796d0f61a05b | 693 | POLARSSL_MD_SHA256, |
HannesTschofenig | 0:796d0f61a05b | 694 | "SHA256", |
HannesTschofenig | 0:796d0f61a05b | 695 | 32, |
HannesTschofenig | 0:796d0f61a05b | 696 | sha256_starts_wrap, |
HannesTschofenig | 0:796d0f61a05b | 697 | sha256_update_wrap, |
HannesTschofenig | 0:796d0f61a05b | 698 | sha256_finish_wrap, |
HannesTschofenig | 0:796d0f61a05b | 699 | sha256_wrap, |
HannesTschofenig | 0:796d0f61a05b | 700 | sha256_file_wrap, |
HannesTschofenig | 0:796d0f61a05b | 701 | sha256_hmac_starts_wrap, |
HannesTschofenig | 0:796d0f61a05b | 702 | sha256_hmac_update_wrap, |
HannesTschofenig | 0:796d0f61a05b | 703 | sha256_hmac_finish_wrap, |
HannesTschofenig | 0:796d0f61a05b | 704 | sha256_hmac_reset_wrap, |
HannesTschofenig | 0:796d0f61a05b | 705 | sha256_hmac_wrap, |
HannesTschofenig | 0:796d0f61a05b | 706 | sha256_ctx_alloc, |
HannesTschofenig | 0:796d0f61a05b | 707 | sha256_ctx_free, |
HannesTschofenig | 0:796d0f61a05b | 708 | sha256_process_wrap, |
HannesTschofenig | 0:796d0f61a05b | 709 | }; |
HannesTschofenig | 0:796d0f61a05b | 710 | |
HannesTschofenig | 0:796d0f61a05b | 711 | #endif /* POLARSSL_SHA256_C */ |
HannesTschofenig | 0:796d0f61a05b | 712 | |
HannesTschofenig | 0:796d0f61a05b | 713 | #if defined(POLARSSL_SHA512_C) |
HannesTschofenig | 0:796d0f61a05b | 714 | |
HannesTschofenig | 0:796d0f61a05b | 715 | static void sha384_starts_wrap( void *ctx ) |
HannesTschofenig | 0:796d0f61a05b | 716 | { |
HannesTschofenig | 0:796d0f61a05b | 717 | sha512_starts( (sha512_context *) ctx, 1 ); |
HannesTschofenig | 0:796d0f61a05b | 718 | } |
HannesTschofenig | 0:796d0f61a05b | 719 | |
HannesTschofenig | 0:796d0f61a05b | 720 | static void sha384_update_wrap( void *ctx, const unsigned char *input, |
HannesTschofenig | 0:796d0f61a05b | 721 | size_t ilen ) |
HannesTschofenig | 0:796d0f61a05b | 722 | { |
HannesTschofenig | 0:796d0f61a05b | 723 | sha512_update( (sha512_context *) ctx, input, ilen ); |
HannesTschofenig | 0:796d0f61a05b | 724 | } |
HannesTschofenig | 0:796d0f61a05b | 725 | |
HannesTschofenig | 0:796d0f61a05b | 726 | static void sha384_finish_wrap( void *ctx, unsigned char *output ) |
HannesTschofenig | 0:796d0f61a05b | 727 | { |
HannesTschofenig | 0:796d0f61a05b | 728 | sha512_finish( (sha512_context *) ctx, output ); |
HannesTschofenig | 0:796d0f61a05b | 729 | } |
HannesTschofenig | 0:796d0f61a05b | 730 | |
HannesTschofenig | 0:796d0f61a05b | 731 | static void sha384_wrap( const unsigned char *input, size_t ilen, |
HannesTschofenig | 0:796d0f61a05b | 732 | unsigned char *output ) |
HannesTschofenig | 0:796d0f61a05b | 733 | { |
HannesTschofenig | 0:796d0f61a05b | 734 | sha512( input, ilen, output, 1 ); |
HannesTschofenig | 0:796d0f61a05b | 735 | } |
HannesTschofenig | 0:796d0f61a05b | 736 | |
HannesTschofenig | 0:796d0f61a05b | 737 | static int sha384_file_wrap( const char *path, unsigned char *output ) |
HannesTschofenig | 0:796d0f61a05b | 738 | { |
HannesTschofenig | 0:796d0f61a05b | 739 | #if defined(POLARSSL_FS_IO) |
HannesTschofenig | 0:796d0f61a05b | 740 | return sha512_file( path, output, 1 ); |
HannesTschofenig | 0:796d0f61a05b | 741 | #else |
HannesTschofenig | 0:796d0f61a05b | 742 | ((void) path); |
HannesTschofenig | 0:796d0f61a05b | 743 | ((void) output); |
HannesTschofenig | 0:796d0f61a05b | 744 | return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE; |
HannesTschofenig | 0:796d0f61a05b | 745 | #endif |
HannesTschofenig | 0:796d0f61a05b | 746 | } |
HannesTschofenig | 0:796d0f61a05b | 747 | |
HannesTschofenig | 0:796d0f61a05b | 748 | static void sha384_hmac_starts_wrap( void *ctx, const unsigned char *key, |
HannesTschofenig | 0:796d0f61a05b | 749 | size_t keylen ) |
HannesTschofenig | 0:796d0f61a05b | 750 | { |
HannesTschofenig | 0:796d0f61a05b | 751 | sha512_hmac_starts( (sha512_context *) ctx, key, keylen, 1 ); |
HannesTschofenig | 0:796d0f61a05b | 752 | } |
HannesTschofenig | 0:796d0f61a05b | 753 | |
HannesTschofenig | 0:796d0f61a05b | 754 | static void sha384_hmac_update_wrap( void *ctx, const unsigned char *input, |
HannesTschofenig | 0:796d0f61a05b | 755 | size_t ilen ) |
HannesTschofenig | 0:796d0f61a05b | 756 | { |
HannesTschofenig | 0:796d0f61a05b | 757 | sha512_hmac_update( (sha512_context *) ctx, input, ilen ); |
HannesTschofenig | 0:796d0f61a05b | 758 | } |
HannesTschofenig | 0:796d0f61a05b | 759 | |
HannesTschofenig | 0:796d0f61a05b | 760 | static void sha384_hmac_finish_wrap( void *ctx, unsigned char *output ) |
HannesTschofenig | 0:796d0f61a05b | 761 | { |
HannesTschofenig | 0:796d0f61a05b | 762 | sha512_hmac_finish( (sha512_context *) ctx, output ); |
HannesTschofenig | 0:796d0f61a05b | 763 | } |
HannesTschofenig | 0:796d0f61a05b | 764 | |
HannesTschofenig | 0:796d0f61a05b | 765 | static void sha384_hmac_reset_wrap( void *ctx ) |
HannesTschofenig | 0:796d0f61a05b | 766 | { |
HannesTschofenig | 0:796d0f61a05b | 767 | sha512_hmac_reset( (sha512_context *) ctx ); |
HannesTschofenig | 0:796d0f61a05b | 768 | } |
HannesTschofenig | 0:796d0f61a05b | 769 | |
HannesTschofenig | 0:796d0f61a05b | 770 | static void sha384_hmac_wrap( const unsigned char *key, size_t keylen, |
HannesTschofenig | 0:796d0f61a05b | 771 | const unsigned char *input, size_t ilen, |
HannesTschofenig | 0:796d0f61a05b | 772 | unsigned char *output ) |
HannesTschofenig | 0:796d0f61a05b | 773 | { |
HannesTschofenig | 0:796d0f61a05b | 774 | sha512_hmac( key, keylen, input, ilen, output, 1 ); |
HannesTschofenig | 0:796d0f61a05b | 775 | } |
HannesTschofenig | 0:796d0f61a05b | 776 | |
HannesTschofenig | 0:796d0f61a05b | 777 | static void * sha384_ctx_alloc( void ) |
HannesTschofenig | 0:796d0f61a05b | 778 | { |
HannesTschofenig | 0:796d0f61a05b | 779 | return polarssl_malloc( sizeof( sha512_context ) ); |
HannesTschofenig | 0:796d0f61a05b | 780 | } |
HannesTschofenig | 0:796d0f61a05b | 781 | |
HannesTschofenig | 0:796d0f61a05b | 782 | static void sha384_ctx_free( void *ctx ) |
HannesTschofenig | 0:796d0f61a05b | 783 | { |
HannesTschofenig | 0:796d0f61a05b | 784 | polarssl_free( ctx ); |
HannesTschofenig | 0:796d0f61a05b | 785 | } |
HannesTschofenig | 0:796d0f61a05b | 786 | |
HannesTschofenig | 0:796d0f61a05b | 787 | static void sha384_process_wrap( void *ctx, const unsigned char *data ) |
HannesTschofenig | 0:796d0f61a05b | 788 | { |
HannesTschofenig | 0:796d0f61a05b | 789 | sha512_process( (sha512_context *) ctx, data ); |
HannesTschofenig | 0:796d0f61a05b | 790 | } |
HannesTschofenig | 0:796d0f61a05b | 791 | |
HannesTschofenig | 0:796d0f61a05b | 792 | const md_info_t sha384_info = { |
HannesTschofenig | 0:796d0f61a05b | 793 | POLARSSL_MD_SHA384, |
HannesTschofenig | 0:796d0f61a05b | 794 | "SHA384", |
HannesTschofenig | 0:796d0f61a05b | 795 | 48, |
HannesTschofenig | 0:796d0f61a05b | 796 | sha384_starts_wrap, |
HannesTschofenig | 0:796d0f61a05b | 797 | sha384_update_wrap, |
HannesTschofenig | 0:796d0f61a05b | 798 | sha384_finish_wrap, |
HannesTschofenig | 0:796d0f61a05b | 799 | sha384_wrap, |
HannesTschofenig | 0:796d0f61a05b | 800 | sha384_file_wrap, |
HannesTschofenig | 0:796d0f61a05b | 801 | sha384_hmac_starts_wrap, |
HannesTschofenig | 0:796d0f61a05b | 802 | sha384_hmac_update_wrap, |
HannesTschofenig | 0:796d0f61a05b | 803 | sha384_hmac_finish_wrap, |
HannesTschofenig | 0:796d0f61a05b | 804 | sha384_hmac_reset_wrap, |
HannesTschofenig | 0:796d0f61a05b | 805 | sha384_hmac_wrap, |
HannesTschofenig | 0:796d0f61a05b | 806 | sha384_ctx_alloc, |
HannesTschofenig | 0:796d0f61a05b | 807 | sha384_ctx_free, |
HannesTschofenig | 0:796d0f61a05b | 808 | sha384_process_wrap, |
HannesTschofenig | 0:796d0f61a05b | 809 | }; |
HannesTschofenig | 0:796d0f61a05b | 810 | |
HannesTschofenig | 0:796d0f61a05b | 811 | static void sha512_starts_wrap( void *ctx ) |
HannesTschofenig | 0:796d0f61a05b | 812 | { |
HannesTschofenig | 0:796d0f61a05b | 813 | sha512_starts( (sha512_context *) ctx, 0 ); |
HannesTschofenig | 0:796d0f61a05b | 814 | } |
HannesTschofenig | 0:796d0f61a05b | 815 | |
HannesTschofenig | 0:796d0f61a05b | 816 | static void sha512_update_wrap( void *ctx, const unsigned char *input, |
HannesTschofenig | 0:796d0f61a05b | 817 | size_t ilen ) |
HannesTschofenig | 0:796d0f61a05b | 818 | { |
HannesTschofenig | 0:796d0f61a05b | 819 | sha512_update( (sha512_context *) ctx, input, ilen ); |
HannesTschofenig | 0:796d0f61a05b | 820 | } |
HannesTschofenig | 0:796d0f61a05b | 821 | |
HannesTschofenig | 0:796d0f61a05b | 822 | static void sha512_finish_wrap( void *ctx, unsigned char *output ) |
HannesTschofenig | 0:796d0f61a05b | 823 | { |
HannesTschofenig | 0:796d0f61a05b | 824 | sha512_finish( (sha512_context *) ctx, output ); |
HannesTschofenig | 0:796d0f61a05b | 825 | } |
HannesTschofenig | 0:796d0f61a05b | 826 | |
HannesTschofenig | 0:796d0f61a05b | 827 | static void sha512_wrap( const unsigned char *input, size_t ilen, |
HannesTschofenig | 0:796d0f61a05b | 828 | unsigned char *output ) |
HannesTschofenig | 0:796d0f61a05b | 829 | { |
HannesTschofenig | 0:796d0f61a05b | 830 | sha512( input, ilen, output, 0 ); |
HannesTschofenig | 0:796d0f61a05b | 831 | } |
HannesTschofenig | 0:796d0f61a05b | 832 | |
HannesTschofenig | 0:796d0f61a05b | 833 | static int sha512_file_wrap( const char *path, unsigned char *output ) |
HannesTschofenig | 0:796d0f61a05b | 834 | { |
HannesTschofenig | 0:796d0f61a05b | 835 | #if defined(POLARSSL_FS_IO) |
HannesTschofenig | 0:796d0f61a05b | 836 | return sha512_file( path, output, 0 ); |
HannesTschofenig | 0:796d0f61a05b | 837 | #else |
HannesTschofenig | 0:796d0f61a05b | 838 | ((void) path); |
HannesTschofenig | 0:796d0f61a05b | 839 | ((void) output); |
HannesTschofenig | 0:796d0f61a05b | 840 | return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE; |
HannesTschofenig | 0:796d0f61a05b | 841 | #endif |
HannesTschofenig | 0:796d0f61a05b | 842 | } |
HannesTschofenig | 0:796d0f61a05b | 843 | |
HannesTschofenig | 0:796d0f61a05b | 844 | static void sha512_hmac_starts_wrap( void *ctx, const unsigned char *key, |
HannesTschofenig | 0:796d0f61a05b | 845 | size_t keylen ) |
HannesTschofenig | 0:796d0f61a05b | 846 | { |
HannesTschofenig | 0:796d0f61a05b | 847 | sha512_hmac_starts( (sha512_context *) ctx, key, keylen, 0 ); |
HannesTschofenig | 0:796d0f61a05b | 848 | } |
HannesTschofenig | 0:796d0f61a05b | 849 | |
HannesTschofenig | 0:796d0f61a05b | 850 | static void sha512_hmac_update_wrap( void *ctx, const unsigned char *input, |
HannesTschofenig | 0:796d0f61a05b | 851 | size_t ilen ) |
HannesTschofenig | 0:796d0f61a05b | 852 | { |
HannesTschofenig | 0:796d0f61a05b | 853 | sha512_hmac_update( (sha512_context *) ctx, input, ilen ); |
HannesTschofenig | 0:796d0f61a05b | 854 | } |
HannesTschofenig | 0:796d0f61a05b | 855 | |
HannesTschofenig | 0:796d0f61a05b | 856 | static void sha512_hmac_finish_wrap( void *ctx, unsigned char *output ) |
HannesTschofenig | 0:796d0f61a05b | 857 | { |
HannesTschofenig | 0:796d0f61a05b | 858 | sha512_hmac_finish( (sha512_context *) ctx, output ); |
HannesTschofenig | 0:796d0f61a05b | 859 | } |
HannesTschofenig | 0:796d0f61a05b | 860 | |
HannesTschofenig | 0:796d0f61a05b | 861 | static void sha512_hmac_reset_wrap( void *ctx ) |
HannesTschofenig | 0:796d0f61a05b | 862 | { |
HannesTschofenig | 0:796d0f61a05b | 863 | sha512_hmac_reset( (sha512_context *) ctx ); |
HannesTschofenig | 0:796d0f61a05b | 864 | } |
HannesTschofenig | 0:796d0f61a05b | 865 | |
HannesTschofenig | 0:796d0f61a05b | 866 | static void sha512_hmac_wrap( const unsigned char *key, size_t keylen, |
HannesTschofenig | 0:796d0f61a05b | 867 | const unsigned char *input, size_t ilen, |
HannesTschofenig | 0:796d0f61a05b | 868 | unsigned char *output ) |
HannesTschofenig | 0:796d0f61a05b | 869 | { |
HannesTschofenig | 0:796d0f61a05b | 870 | sha512_hmac( key, keylen, input, ilen, output, 0 ); |
HannesTschofenig | 0:796d0f61a05b | 871 | } |
HannesTschofenig | 0:796d0f61a05b | 872 | |
HannesTschofenig | 0:796d0f61a05b | 873 | static void * sha512_ctx_alloc( void ) |
HannesTschofenig | 0:796d0f61a05b | 874 | { |
HannesTschofenig | 0:796d0f61a05b | 875 | return polarssl_malloc( sizeof( sha512_context ) ); |
HannesTschofenig | 0:796d0f61a05b | 876 | } |
HannesTschofenig | 0:796d0f61a05b | 877 | |
HannesTschofenig | 0:796d0f61a05b | 878 | static void sha512_ctx_free( void *ctx ) |
HannesTschofenig | 0:796d0f61a05b | 879 | { |
HannesTschofenig | 0:796d0f61a05b | 880 | polarssl_free( ctx ); |
HannesTschofenig | 0:796d0f61a05b | 881 | } |
HannesTschofenig | 0:796d0f61a05b | 882 | |
HannesTschofenig | 0:796d0f61a05b | 883 | static void sha512_process_wrap( void *ctx, const unsigned char *data ) |
HannesTschofenig | 0:796d0f61a05b | 884 | { |
HannesTschofenig | 0:796d0f61a05b | 885 | sha512_process( (sha512_context *) ctx, data ); |
HannesTschofenig | 0:796d0f61a05b | 886 | } |
HannesTschofenig | 0:796d0f61a05b | 887 | |
HannesTschofenig | 0:796d0f61a05b | 888 | const md_info_t sha512_info = { |
HannesTschofenig | 0:796d0f61a05b | 889 | POLARSSL_MD_SHA512, |
HannesTschofenig | 0:796d0f61a05b | 890 | "SHA512", |
HannesTschofenig | 0:796d0f61a05b | 891 | 64, |
HannesTschofenig | 0:796d0f61a05b | 892 | sha512_starts_wrap, |
HannesTschofenig | 0:796d0f61a05b | 893 | sha512_update_wrap, |
HannesTschofenig | 0:796d0f61a05b | 894 | sha512_finish_wrap, |
HannesTschofenig | 0:796d0f61a05b | 895 | sha512_wrap, |
HannesTschofenig | 0:796d0f61a05b | 896 | sha512_file_wrap, |
HannesTschofenig | 0:796d0f61a05b | 897 | sha512_hmac_starts_wrap, |
HannesTschofenig | 0:796d0f61a05b | 898 | sha512_hmac_update_wrap, |
HannesTschofenig | 0:796d0f61a05b | 899 | sha512_hmac_finish_wrap, |
HannesTschofenig | 0:796d0f61a05b | 900 | sha512_hmac_reset_wrap, |
HannesTschofenig | 0:796d0f61a05b | 901 | sha512_hmac_wrap, |
HannesTschofenig | 0:796d0f61a05b | 902 | sha512_ctx_alloc, |
HannesTschofenig | 0:796d0f61a05b | 903 | sha512_ctx_free, |
HannesTschofenig | 0:796d0f61a05b | 904 | sha512_process_wrap, |
HannesTschofenig | 0:796d0f61a05b | 905 | }; |
HannesTschofenig | 0:796d0f61a05b | 906 | |
HannesTschofenig | 0:796d0f61a05b | 907 | #endif /* POLARSSL_SHA512_C */ |
HannesTschofenig | 0:796d0f61a05b | 908 | |
HannesTschofenig | 0:796d0f61a05b | 909 | #endif /* POLARSSL_MD_C */ |
HannesTschofenig | 0:796d0f61a05b | 910 | |
HannesTschofenig | 0:796d0f61a05b | 911 |