blob: e0c6354d0ef391e530a5e8199bc0f2bd1eb7de4f [file] [log] [blame]
Paul Bakker17373852011-01-06 14:20:01 +00001/**
2 * \file md_wrap.h
Paul Bakker9af723c2014-05-01 13:03:14 +02003 *
Paul Bakker17373852011-01-06 14:20:01 +00004 * \brief Message digest wrappers.
5 *
Manuel Pégourié-Gonnardca878db2015-03-24 12:13:30 +01006 * \warning This in an internal header. Do not include directly.
7 *
Paul Bakker17373852011-01-06 14:20:01 +00008 * \author Adriaan de Jong <dejong@fox-it.com>
9 *
Manuel Pégourié-Gonnardca878db2015-03-24 12:13:30 +010010 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
Paul Bakker17373852011-01-06 14:20:01 +000011 *
Manuel Pégourié-Gonnardfe446432015-03-06 13:17:10 +000012 * This file is part of mbed TLS (https://tls.mbed.org)
Paul Bakker17373852011-01-06 14:20:01 +000013 *
Paul Bakker17373852011-01-06 14:20:01 +000014 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License along
25 * with this program; if not, write to the Free Software Foundation, Inc.,
26 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 */
Paul Bakkercce9d772011-11-18 14:26:47 +000028#ifndef POLARSSL_MD_WRAP_H
29#define POLARSSL_MD_WRAP_H
Paul Bakker17373852011-01-06 14:20:01 +000030
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020031#if !defined(POLARSSL_CONFIG_FILE)
Paul Bakker314052f2011-08-15 09:07:52 +000032#include "config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020033#else
34#include POLARSSL_CONFIG_FILE
35#endif
Manuel Pégourié-Gonnard6c5abfa2015-02-13 14:12:07 +000036
Paul Bakker314052f2011-08-15 09:07:52 +000037#include "md.h"
Paul Bakker17373852011-01-06 14:20:01 +000038
Paul Bakker17373852011-01-06 14:20:01 +000039#ifdef __cplusplus
40extern "C" {
41#endif
42
Manuel Pégourié-Gonnardca878db2015-03-24 12:13:30 +010043/**
44 * Message digest information.
45 * Allows message digest functions to be called in a generic way.
46 */
47struct _md_info_t {
48 /** Digest identifier */
49 md_type_t type;
50
51 /** Name of the message digest */
52 const char * name;
53
54 /** Output length of the digest function */
55 int size;
56
Manuel Pégourié-Gonnard8379a822015-03-24 16:48:22 +010057 /** Block length of the digest function */
58 int block_size;
59
Manuel Pégourié-Gonnardca878db2015-03-24 12:13:30 +010060 /** Digest initialisation function */
61 void (*starts_func)( void *ctx );
62
63 /** Digest update function */
64 void (*update_func)( void *ctx, const unsigned char *input, size_t ilen );
65
66 /** Digest finalisation function */
67 void (*finish_func)( void *ctx, unsigned char *output );
68
69 /** Generic digest function */
70 void (*digest_func)( const unsigned char *input, size_t ilen,
71 unsigned char *output );
72
73 /** Generic file digest function */
74 int (*file_func)( const char *path, unsigned char *output );
75
76 /** HMAC Initialisation function */
77 void (*hmac_starts_func)( void *ctx, const unsigned char *key,
78 size_t keylen );
79
80 /** HMAC update function */
81 void (*hmac_update_func)( void *ctx, const unsigned char *input,
82 size_t ilen );
83
84 /** HMAC finalisation function */
85 void (*hmac_finish_func)( void *ctx, unsigned char *output);
86
87 /** HMAC context reset function */
88 void (*hmac_reset_func)( void *ctx );
89
90 /** Generic HMAC function */
91 void (*hmac_func)( const unsigned char *key, size_t keylen,
92 const unsigned char *input, size_t ilen,
93 unsigned char *output );
94
95 /** Allocate a new context */
96 void * (*ctx_alloc_func)( void );
97
98 /** Free the given context */
99 void (*ctx_free_func)( void *ctx );
100
101 /** Internal use only */
102 void (*process_func)( void *ctx, const unsigned char *input );
103};
104
Paul Bakker17373852011-01-06 14:20:01 +0000105#if defined(POLARSSL_MD2_C)
106extern const md_info_t md2_info;
107#endif
108#if defined(POLARSSL_MD4_C)
109extern const md_info_t md4_info;
110#endif
111#if defined(POLARSSL_MD5_C)
112extern const md_info_t md5_info;
113#endif
Paul Bakker61b699e2014-01-22 13:35:29 +0100114#if defined(POLARSSL_RIPEMD160_C)
115extern const md_info_t ripemd160_info;
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100116#endif
Paul Bakker17373852011-01-06 14:20:01 +0000117#if defined(POLARSSL_SHA1_C)
118extern const md_info_t sha1_info;
119#endif
Paul Bakker9e36f042013-06-30 14:34:05 +0200120#if defined(POLARSSL_SHA256_C)
Paul Bakker17373852011-01-06 14:20:01 +0000121extern const md_info_t sha224_info;
122extern const md_info_t sha256_info;
123#endif
Paul Bakker9e36f042013-06-30 14:34:05 +0200124#if defined(POLARSSL_SHA512_C)
Paul Bakker17373852011-01-06 14:20:01 +0000125extern const md_info_t sha384_info;
126extern const md_info_t sha512_info;
127#endif
128
129#ifdef __cplusplus
130}
131#endif
132
133#endif /* POLARSSL_MD_WRAP_H */