blob: 72a8e46455bd95f90a14d6b84101ae97f6e39a6a [file] [log] [blame]
Paul Bakker17373852011-01-06 14:20:01 +00001/**
Manuel Pégourié-Gonnard50518f42015-05-26 11:04:15 +02002 * \file md_internal.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>
Darryl Greena40a1012018-01-05 15:33:17 +00009 */
10/*
Manuel Pégourié-Gonnardca878db2015-03-24 12:13:30 +010011 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +020012 * SPDX-License-Identifier: Apache-2.0
13 *
14 * Licensed under the Apache License, Version 2.0 (the "License"); you may
15 * not use this file except in compliance with the License.
16 * You may obtain a copy of the License at
17 *
18 * http://www.apache.org/licenses/LICENSE-2.0
19 *
20 * Unless required by applicable law or agreed to in writing, software
21 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
22 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23 * See the License for the specific language governing permissions and
24 * limitations under the License.
Paul Bakker17373852011-01-06 14:20:01 +000025 *
Manuel Pégourié-Gonnardfe446432015-03-06 13:17:10 +000026 * This file is part of mbed TLS (https://tls.mbed.org)
Paul Bakker17373852011-01-06 14:20:01 +000027 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020028#ifndef MBEDTLS_MD_WRAP_H
29#define MBEDTLS_MD_WRAP_H
Paul Bakker17373852011-01-06 14:20:01 +000030
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020031#if !defined(MBEDTLS_CONFIG_FILE)
Paul Bakker314052f2011-08-15 09:07:52 +000032#include "config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020033#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020034#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020035#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 */
Hanno Becker530387e2019-07-17 14:10:26 +010047
48typedef int mbedtls_md_starts_func_t( void *ctx );
49typedef int mbedtls_md_update_func_t( void *ctx,
50 const unsigned char *input,
51 size_t ilen );
52typedef int mbedtls_md_finish_func_t( void *ctx, unsigned char *output );
53typedef int mbedtls_md_digest_func_t( const unsigned char *input,
54 size_t ilen,
55 unsigned char *output );
56typedef void* mbedtls_md_ctx_alloc_func_t( void );
57typedef void mbedtls_md_ctx_free_func_t( void *ctx );
58typedef void mbedtls_md_clone_func_t( void *st, const void *src );
59typedef int mbedtls_md_process_func_t( void *ctx,
60 const unsigned char *input );
61
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020062struct mbedtls_md_info_t
Manuel Pégourié-Gonnardf5fc6492015-04-02 14:43:57 +010063{
Manuel Pégourié-Gonnardca878db2015-03-24 12:13:30 +010064 /** Digest identifier */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020065 mbedtls_md_type_t type;
Manuel Pégourié-Gonnardca878db2015-03-24 12:13:30 +010066
67 /** Name of the message digest */
68 const char * name;
69
Manuel Pégourié-Gonnardb8186a52015-06-18 14:58:58 +020070 /** Output length of the digest function in bytes */
Manuel Pégourié-Gonnardca878db2015-03-24 12:13:30 +010071 int size;
72
Manuel Pégourié-Gonnardb8186a52015-06-18 14:58:58 +020073 /** Block length of the digest function in bytes */
Manuel Pégourié-Gonnard8379a822015-03-24 16:48:22 +010074 int block_size;
75
Manuel Pégourié-Gonnardca878db2015-03-24 12:13:30 +010076 /** Digest initialisation function */
Hanno Becker530387e2019-07-17 14:10:26 +010077 mbedtls_md_starts_func_t *starts_func;
Manuel Pégourié-Gonnardca878db2015-03-24 12:13:30 +010078
79 /** Digest update function */
Hanno Becker530387e2019-07-17 14:10:26 +010080 mbedtls_md_update_func_t *update_func;
Manuel Pégourié-Gonnardca878db2015-03-24 12:13:30 +010081
82 /** Digest finalisation function */
Hanno Becker530387e2019-07-17 14:10:26 +010083 mbedtls_md_finish_func_t *finish_func;
Manuel Pégourié-Gonnardca878db2015-03-24 12:13:30 +010084
85 /** Generic digest function */
Hanno Becker530387e2019-07-17 14:10:26 +010086 mbedtls_md_digest_func_t *digest_func;
Manuel Pégourié-Gonnardca878db2015-03-24 12:13:30 +010087
Manuel Pégourié-Gonnardca878db2015-03-24 12:13:30 +010088 /** Allocate a new context */
Hanno Becker530387e2019-07-17 14:10:26 +010089 mbedtls_md_ctx_alloc_func_t *ctx_alloc_func;
Manuel Pégourié-Gonnardca878db2015-03-24 12:13:30 +010090
91 /** Free the given context */
Hanno Becker530387e2019-07-17 14:10:26 +010092 mbedtls_md_ctx_free_func_t *ctx_free_func;
Manuel Pégourié-Gonnardca878db2015-03-24 12:13:30 +010093
Manuel Pégourié-Gonnard052a6c92015-07-06 16:06:02 +020094 /** Clone state from a context */
Hanno Becker530387e2019-07-17 14:10:26 +010095 mbedtls_md_clone_func_t *clone_func;
Manuel Pégourié-Gonnard052a6c92015-07-06 16:06:02 +020096
Manuel Pégourié-Gonnardca878db2015-03-24 12:13:30 +010097 /** Internal use only */
Hanno Becker530387e2019-07-17 14:10:26 +010098 mbedtls_md_process_func_t *process_func;
Manuel Pégourié-Gonnardca878db2015-03-24 12:13:30 +010099};
100
Hanno Becker530387e2019-07-17 14:10:26 +0100101/*
102 * Getter functions for MD info structure.
103 */
104
105static inline mbedtls_md_type_t mbedtls_md_info_type(
106 mbedtls_md_handle_t info )
107{
108 return( info->type );
109}
110
111static inline const char * mbedtls_md_info_name(
112 mbedtls_md_handle_t info )
113{
114 return( info->name );
115}
116
117static inline int mbedtls_md_info_size(
118 mbedtls_md_handle_t info )
119{
120 return( info->size );
121}
122
123static inline int mbedtls_md_info_block_size(
124 mbedtls_md_handle_t info )
125{
126 return( info->block_size );
127}
128
129static inline mbedtls_md_starts_func_t *mbedtls_md_info_starts_func(
130 mbedtls_md_handle_t info )
131{
132 return( info->starts_func );
133}
134
135static inline mbedtls_md_update_func_t *mbedtls_md_info_update_func(
136 mbedtls_md_handle_t info )
137{
138 return( info->update_func );
139}
140
141static inline mbedtls_md_finish_func_t *mbedtls_md_info_finish_func(
142 mbedtls_md_handle_t info )
143{
144 return( info->finish_func );
145}
146
147static inline mbedtls_md_digest_func_t *mbedtls_md_info_digest_func(
148 mbedtls_md_handle_t info )
149{
150 return( info->digest_func );
151}
152
153static inline mbedtls_md_ctx_alloc_func_t *mbedtls_md_info_ctx_alloc_func(
154 mbedtls_md_handle_t info )
155{
156 return( info->ctx_alloc_func );
157}
158
159static inline mbedtls_md_ctx_free_func_t *mbedtls_md_info_ctx_free_func(
160 mbedtls_md_handle_t info )
161{
162 return( info->ctx_free_func );
163}
164
165static inline mbedtls_md_clone_func_t *mbedtls_md_info_clone_func(
166 mbedtls_md_handle_t info )
167{
168 return( info->clone_func );
169}
170
171static inline mbedtls_md_process_func_t *mbedtls_md_info_process_func(
172 mbedtls_md_handle_t info )
173{
174 return( info->process_func );
175}
176
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200177#if defined(MBEDTLS_MD2_C)
178extern const mbedtls_md_info_t mbedtls_md2_info;
Paul Bakker17373852011-01-06 14:20:01 +0000179#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200180#if defined(MBEDTLS_MD4_C)
181extern const mbedtls_md_info_t mbedtls_md4_info;
Paul Bakker17373852011-01-06 14:20:01 +0000182#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200183#if defined(MBEDTLS_MD5_C)
184extern const mbedtls_md_info_t mbedtls_md5_info;
Paul Bakker17373852011-01-06 14:20:01 +0000185#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200186#if defined(MBEDTLS_RIPEMD160_C)
187extern const mbedtls_md_info_t mbedtls_ripemd160_info;
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100188#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200189#if defined(MBEDTLS_SHA1_C)
190extern const mbedtls_md_info_t mbedtls_sha1_info;
Paul Bakker17373852011-01-06 14:20:01 +0000191#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200192#if defined(MBEDTLS_SHA256_C)
Manuel Pégourié-Gonnard394c5fb2019-07-16 15:57:36 +0200193#if !defined(MBEDTLS_SHA256_NO_SHA224)
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200194extern const mbedtls_md_info_t mbedtls_sha224_info;
Manuel Pégourié-Gonnard394c5fb2019-07-16 15:57:36 +0200195#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200196extern const mbedtls_md_info_t mbedtls_sha256_info;
Paul Bakker17373852011-01-06 14:20:01 +0000197#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200198#if defined(MBEDTLS_SHA512_C)
199extern const mbedtls_md_info_t mbedtls_sha384_info;
200extern const mbedtls_md_info_t mbedtls_sha512_info;
Paul Bakker17373852011-01-06 14:20:01 +0000201#endif
202
203#ifdef __cplusplus
204}
205#endif
206
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200207#endif /* MBEDTLS_MD_WRAP_H */