blob: 847f50aa0a83616e1f65e4ab11975f3a6ae5a995 [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/*
Bence Szépkútia2947ac2020-08-19 16:37:36 +020011 * Copyright The Mbed TLS Contributors
Bence Szépkútif744bd72020-06-05 13:02:18 +020012 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
13 *
14 * This file is provided under the Apache License 2.0, or the
15 * GNU General Public License v2.0 or later.
16 *
17 * **********
18 * Apache License 2.0:
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +020019 *
20 * Licensed under the Apache License, Version 2.0 (the "License"); you may
21 * not use this file except in compliance with the License.
22 * You may obtain a copy of the License at
23 *
24 * http://www.apache.org/licenses/LICENSE-2.0
25 *
26 * Unless required by applicable law or agreed to in writing, software
27 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
28 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 * See the License for the specific language governing permissions and
30 * limitations under the License.
Paul Bakker17373852011-01-06 14:20:01 +000031 *
Bence Szépkútif744bd72020-06-05 13:02:18 +020032 * **********
33 *
34 * **********
35 * GNU General Public License v2.0 or later:
36 *
37 * This program is free software; you can redistribute it and/or modify
38 * it under the terms of the GNU General Public License as published by
39 * the Free Software Foundation; either version 2 of the License, or
40 * (at your option) any later version.
41 *
42 * This program is distributed in the hope that it will be useful,
43 * but WITHOUT ANY WARRANTY; without even the implied warranty of
44 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45 * GNU General Public License for more details.
46 *
47 * You should have received a copy of the GNU General Public License along
48 * with this program; if not, write to the Free Software Foundation, Inc.,
49 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
50 *
51 * **********
Paul Bakker17373852011-01-06 14:20:01 +000052 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020053#ifndef MBEDTLS_MD_WRAP_H
54#define MBEDTLS_MD_WRAP_H
Paul Bakker17373852011-01-06 14:20:01 +000055
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020056#if !defined(MBEDTLS_CONFIG_FILE)
Paul Bakker314052f2011-08-15 09:07:52 +000057#include "config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020058#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020059#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020060#endif
Manuel Pégourié-Gonnard6c5abfa2015-02-13 14:12:07 +000061
Paul Bakker314052f2011-08-15 09:07:52 +000062#include "md.h"
Paul Bakker17373852011-01-06 14:20:01 +000063
Paul Bakker17373852011-01-06 14:20:01 +000064#ifdef __cplusplus
65extern "C" {
66#endif
67
Manuel Pégourié-Gonnardca878db2015-03-24 12:13:30 +010068/**
69 * Message digest information.
70 * Allows message digest functions to be called in a generic way.
71 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020072struct mbedtls_md_info_t
Manuel Pégourié-Gonnardf5fc6492015-04-02 14:43:57 +010073{
Manuel Pégourié-Gonnardca878db2015-03-24 12:13:30 +010074 /** Digest identifier */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020075 mbedtls_md_type_t type;
Manuel Pégourié-Gonnardca878db2015-03-24 12:13:30 +010076
77 /** Name of the message digest */
78 const char * name;
79
Manuel Pégourié-Gonnardb8186a52015-06-18 14:58:58 +020080 /** Output length of the digest function in bytes */
Manuel Pégourié-Gonnardca878db2015-03-24 12:13:30 +010081 int size;
82
Manuel Pégourié-Gonnardb8186a52015-06-18 14:58:58 +020083 /** Block length of the digest function in bytes */
Manuel Pégourié-Gonnard8379a822015-03-24 16:48:22 +010084 int block_size;
85
Manuel Pégourié-Gonnardca878db2015-03-24 12:13:30 +010086 /** Digest initialisation function */
Andres Amaya Garcia5f872df2017-06-28 14:12:44 +010087 int (*starts_func)( void *ctx );
Manuel Pégourié-Gonnardca878db2015-03-24 12:13:30 +010088
89 /** Digest update function */
Andres Amaya Garcia5f872df2017-06-28 14:12:44 +010090 int (*update_func)( void *ctx, const unsigned char *input, size_t ilen );
Manuel Pégourié-Gonnardca878db2015-03-24 12:13:30 +010091
92 /** Digest finalisation function */
Andres Amaya Garcia5f872df2017-06-28 14:12:44 +010093 int (*finish_func)( void *ctx, unsigned char *output );
Manuel Pégourié-Gonnardca878db2015-03-24 12:13:30 +010094
95 /** Generic digest function */
Andres Amaya Garcia5f872df2017-06-28 14:12:44 +010096 int (*digest_func)( const unsigned char *input, size_t ilen,
97 unsigned char *output );
Manuel Pégourié-Gonnardca878db2015-03-24 12:13:30 +010098
Manuel Pégourié-Gonnardca878db2015-03-24 12:13:30 +010099 /** Allocate a new context */
100 void * (*ctx_alloc_func)( void );
101
102 /** Free the given context */
103 void (*ctx_free_func)( void *ctx );
104
Manuel Pégourié-Gonnard052a6c92015-07-06 16:06:02 +0200105 /** Clone state from a context */
106 void (*clone_func)( void *dst, const void *src );
107
Manuel Pégourié-Gonnardca878db2015-03-24 12:13:30 +0100108 /** Internal use only */
Andres Amaya Garcia5f872df2017-06-28 14:12:44 +0100109 int (*process_func)( void *ctx, const unsigned char *input );
Manuel Pégourié-Gonnardca878db2015-03-24 12:13:30 +0100110};
111
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200112#if defined(MBEDTLS_MD2_C)
113extern const mbedtls_md_info_t mbedtls_md2_info;
Paul Bakker17373852011-01-06 14:20:01 +0000114#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200115#if defined(MBEDTLS_MD4_C)
116extern const mbedtls_md_info_t mbedtls_md4_info;
Paul Bakker17373852011-01-06 14:20:01 +0000117#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200118#if defined(MBEDTLS_MD5_C)
119extern const mbedtls_md_info_t mbedtls_md5_info;
Paul Bakker17373852011-01-06 14:20:01 +0000120#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200121#if defined(MBEDTLS_RIPEMD160_C)
122extern const mbedtls_md_info_t mbedtls_ripemd160_info;
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100123#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200124#if defined(MBEDTLS_SHA1_C)
125extern const mbedtls_md_info_t mbedtls_sha1_info;
Paul Bakker17373852011-01-06 14:20:01 +0000126#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200127#if defined(MBEDTLS_SHA256_C)
128extern const mbedtls_md_info_t mbedtls_sha224_info;
129extern const mbedtls_md_info_t mbedtls_sha256_info;
Paul Bakker17373852011-01-06 14:20:01 +0000130#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200131#if defined(MBEDTLS_SHA512_C)
132extern const mbedtls_md_info_t mbedtls_sha384_info;
133extern const mbedtls_md_info_t mbedtls_sha512_info;
Paul Bakker17373852011-01-06 14:20:01 +0000134#endif
135
136#ifdef __cplusplus
137}
138#endif
139
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200140#endif /* MBEDTLS_MD_WRAP_H */