1
#pragma clang diagnostic ignored "-Wunknown-warning-option"
2
#pragma clang diagnostic ignored "-Wimplicit-int-conversion"
3
#pragma clang diagnostic ignored "-Wsign-conversion"
5
#pragma GCC diagnostic ignored "-Wconversion"
7
#pragma clang diagnostic ignored "-Wimplicit-int-conversion"
8
#pragma clang diagnostic ignored "-Wsign-conversion"
10
#pragma GCC diagnostic ignored "-Wconversion"
12
#pragma clang diagnostic ignored "-Wimplicit-int-conversion"
13
#pragma clang diagnostic ignored "-Wsign-conversion"
17
* \brief Generic message digest wrapper for mbed TLS
19
* \author Adriaan de Jong <dejong@fox-it.com>
21
* Copyright The Mbed TLS Contributors
22
* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
24
* This file is provided under the Apache License 2.0, or the
25
* GNU General Public License v2.0 or later.
30
* Licensed under the Apache License, Version 2.0 (the "License"); you may
31
* not use this file except in compliance with the License.
32
* You may obtain a copy of the License at
34
* http://www.apache.org/licenses/LICENSE-2.0
36
* Unless required by applicable law or agreed to in writing, software
37
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
38
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
39
* See the License for the specific language governing permissions and
40
* limitations under the License.
45
* GNU General Public License v2.0 or later:
47
* This program is free software; you can redistribute it and/or modify
48
* it under the terms of the GNU General Public License as published by
49
* the Free Software Foundation; either version 2 of the License, or
50
* (at your option) any later version.
52
* This program is distributed in the hope that it will be useful,
53
* but WITHOUT ANY WARRANTY; without even the implied warranty of
54
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
55
* GNU General Public License for more details.
57
* You should have received a copy of the GNU General Public License along
58
* with this program; if not, write to the Free Software Foundation, Inc.,
59
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
64
#if !defined(MBEDTLS_CONFIG_FILE)
65
#include "mbedtls/config.h"
67
#include MBEDTLS_CONFIG_FILE
70
#if defined(MBEDTLS_MD_C)
72
#include "mbedtls/md_internal.h"
74
#if defined(MBEDTLS_MD2_C)
75
#include "mbedtls/md2.h"
78
#if defined(MBEDTLS_MD4_C)
79
#include "mbedtls/md4.h"
82
#if defined(MBEDTLS_MD5_C)
83
#include "mbedtls/md5.h"
86
#if defined(MBEDTLS_RIPEMD160_C)
87
#include "mbedtls/ripemd160.h"
90
#if defined(MBEDTLS_SHA1_C)
91
#include "mbedtls/sha1.h"
94
#if defined(MBEDTLS_SHA256_C)
95
#include "mbedtls/sha256.h"
98
#if defined(MBEDTLS_SHA512_C)
99
#include "mbedtls/sha512.h"
102
#if defined(MBEDTLS_PLATFORM_C)
103
#include "mbedtls/platform.h"
106
#define mbedtls_calloc calloc
107
#define mbedtls_free free
110
#if defined(MBEDTLS_MD2_C)
112
static int md2_starts_wrap( void *ctx )
114
return( mbedtls_md2_starts_ret( (mbedtls_md2_context *) ctx ) );
117
static int md2_update_wrap( void *ctx, const unsigned char *input,
120
return( mbedtls_md2_update_ret( (mbedtls_md2_context *) ctx, input, ilen ) );
123
static int md2_finish_wrap( void *ctx, unsigned char *output )
125
return( mbedtls_md2_finish_ret( (mbedtls_md2_context *) ctx, output ) );
128
static void *md2_ctx_alloc( void )
130
void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_md2_context ) );
133
mbedtls_md2_init( (mbedtls_md2_context *) ctx );
138
static void md2_ctx_free( void *ctx )
140
mbedtls_md2_free( (mbedtls_md2_context *) ctx );
144
static void md2_clone_wrap( void *dst, const void *src )
146
mbedtls_md2_clone( (mbedtls_md2_context *) dst,
147
(const mbedtls_md2_context *) src );
150
static int md2_process_wrap( void *ctx, const unsigned char *data )
154
return( mbedtls_internal_md2_process( (mbedtls_md2_context *) ctx ) );
157
const mbedtls_md_info_t mbedtls_md2_info = {
172
#endif /* MBEDTLS_MD2_C */
174
#if defined(MBEDTLS_MD4_C)
176
static int md4_starts_wrap( void *ctx )
178
return( mbedtls_md4_starts_ret( (mbedtls_md4_context *) ctx ) );
181
static int md4_update_wrap( void *ctx, const unsigned char *input,
184
return( mbedtls_md4_update_ret( (mbedtls_md4_context *) ctx, input, ilen ) );
187
static int md4_finish_wrap( void *ctx, unsigned char *output )
189
return( mbedtls_md4_finish_ret( (mbedtls_md4_context *) ctx, output ) );
192
static void *md4_ctx_alloc( void )
194
void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_md4_context ) );
197
mbedtls_md4_init( (mbedtls_md4_context *) ctx );
202
static void md4_ctx_free( void *ctx )
204
mbedtls_md4_free( (mbedtls_md4_context *) ctx );
208
static void md4_clone_wrap( void *dst, const void *src )
210
mbedtls_md4_clone( (mbedtls_md4_context *) dst,
211
(const mbedtls_md4_context *) src );
214
static int md4_process_wrap( void *ctx, const unsigned char *data )
216
return( mbedtls_internal_md4_process( (mbedtls_md4_context *) ctx, data ) );
219
const mbedtls_md_info_t mbedtls_md4_info = {
234
#endif /* MBEDTLS_MD4_C */
236
#if defined(MBEDTLS_MD5_C)
238
static int md5_starts_wrap( void *ctx )
240
return( mbedtls_md5_starts_ret( (mbedtls_md5_context *) ctx ) );
243
static int md5_update_wrap( void *ctx, const unsigned char *input,
246
return( mbedtls_md5_update_ret( (mbedtls_md5_context *) ctx, input, ilen ) );
249
static int md5_finish_wrap( void *ctx, unsigned char *output )
251
return( mbedtls_md5_finish_ret( (mbedtls_md5_context *) ctx, output ) );
254
static void *md5_ctx_alloc( void )
256
void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_md5_context ) );
259
mbedtls_md5_init( (mbedtls_md5_context *) ctx );
264
static void md5_ctx_free( void *ctx )
266
mbedtls_md5_free( (mbedtls_md5_context *) ctx );
270
static void md5_clone_wrap( void *dst, const void *src )
272
mbedtls_md5_clone( (mbedtls_md5_context *) dst,
273
(const mbedtls_md5_context *) src );
276
static int md5_process_wrap( void *ctx, const unsigned char *data )
278
return( mbedtls_internal_md5_process( (mbedtls_md5_context *) ctx, data ) );
281
const mbedtls_md_info_t mbedtls_md5_info = {
296
#endif /* MBEDTLS_MD5_C */
298
#if defined(MBEDTLS_RIPEMD160_C)
300
static int ripemd160_starts_wrap( void *ctx )
302
return( mbedtls_ripemd160_starts_ret( (mbedtls_ripemd160_context *) ctx ) );
305
static int ripemd160_update_wrap( void *ctx, const unsigned char *input,
308
return( mbedtls_ripemd160_update_ret( (mbedtls_ripemd160_context *) ctx,
312
static int ripemd160_finish_wrap( void *ctx, unsigned char *output )
314
return( mbedtls_ripemd160_finish_ret( (mbedtls_ripemd160_context *) ctx,
318
static void *ripemd160_ctx_alloc( void )
320
void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_ripemd160_context ) );
323
mbedtls_ripemd160_init( (mbedtls_ripemd160_context *) ctx );
328
static void ripemd160_ctx_free( void *ctx )
330
mbedtls_ripemd160_free( (mbedtls_ripemd160_context *) ctx );
334
static void ripemd160_clone_wrap( void *dst, const void *src )
336
mbedtls_ripemd160_clone( (mbedtls_ripemd160_context *) dst,
337
(const mbedtls_ripemd160_context *) src );
340
static int ripemd160_process_wrap( void *ctx, const unsigned char *data )
342
return( mbedtls_internal_ripemd160_process(
343
(mbedtls_ripemd160_context *) ctx, data ) );
346
const mbedtls_md_info_t mbedtls_ripemd160_info = {
347
MBEDTLS_MD_RIPEMD160,
351
ripemd160_starts_wrap,
352
ripemd160_update_wrap,
353
ripemd160_finish_wrap,
354
mbedtls_ripemd160_ret,
357
ripemd160_clone_wrap,
358
ripemd160_process_wrap,
361
#endif /* MBEDTLS_RIPEMD160_C */
363
#if defined(MBEDTLS_SHA1_C)
365
static int sha1_starts_wrap( void *ctx )
367
return( mbedtls_sha1_starts_ret( (mbedtls_sha1_context *) ctx ) );
370
static int sha1_update_wrap( void *ctx, const unsigned char *input,
373
return( mbedtls_sha1_update_ret( (mbedtls_sha1_context *) ctx,
377
static int sha1_finish_wrap( void *ctx, unsigned char *output )
379
return( mbedtls_sha1_finish_ret( (mbedtls_sha1_context *) ctx, output ) );
382
static void *sha1_ctx_alloc( void )
384
void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_sha1_context ) );
387
mbedtls_sha1_init( (mbedtls_sha1_context *) ctx );
392
static void sha1_clone_wrap( void *dst, const void *src )
394
mbedtls_sha1_clone( (mbedtls_sha1_context *) dst,
395
(const mbedtls_sha1_context *) src );
398
static void sha1_ctx_free( void *ctx )
400
mbedtls_sha1_free( (mbedtls_sha1_context *) ctx );
404
static int sha1_process_wrap( void *ctx, const unsigned char *data )
406
return( mbedtls_internal_sha1_process( (mbedtls_sha1_context *) ctx,
410
const mbedtls_md_info_t mbedtls_sha1_info = {
425
#endif /* MBEDTLS_SHA1_C */
428
* Wrappers for generic message digests
430
#if defined(MBEDTLS_SHA256_C)
432
static int sha224_starts_wrap( void *ctx )
434
return( mbedtls_sha256_starts_ret( (mbedtls_sha256_context *) ctx, 1 ) );
437
static int sha224_update_wrap( void *ctx, const unsigned char *input,
440
return( mbedtls_sha256_update_ret( (mbedtls_sha256_context *) ctx,
444
static int sha224_finish_wrap( void *ctx, unsigned char *output )
446
return( mbedtls_sha256_finish_ret( (mbedtls_sha256_context *) ctx,
450
static int sha224_wrap( const unsigned char *input, size_t ilen,
451
unsigned char *output )
453
return( mbedtls_sha256_ret( input, ilen, output, 1 ) );
456
static void *sha224_ctx_alloc( void )
458
void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_sha256_context ) );
461
mbedtls_sha256_init( (mbedtls_sha256_context *) ctx );
466
static void sha224_ctx_free( void *ctx )
468
mbedtls_sha256_free( (mbedtls_sha256_context *) ctx );
472
static void sha224_clone_wrap( void *dst, const void *src )
474
mbedtls_sha256_clone( (mbedtls_sha256_context *) dst,
475
(const mbedtls_sha256_context *) src );
478
static int sha224_process_wrap( void *ctx, const unsigned char *data )
480
return( mbedtls_internal_sha256_process( (mbedtls_sha256_context *) ctx,
484
const mbedtls_md_info_t mbedtls_sha224_info = {
499
static int sha256_starts_wrap( void *ctx )
501
return( mbedtls_sha256_starts_ret( (mbedtls_sha256_context *) ctx, 0 ) );
504
static int sha256_wrap( const unsigned char *input, size_t ilen,
505
unsigned char *output )
507
return( mbedtls_sha256_ret( input, ilen, output, 0 ) );
510
const mbedtls_md_info_t mbedtls_sha256_info = {
525
#endif /* MBEDTLS_SHA256_C */
527
#if defined(MBEDTLS_SHA512_C)
529
static int sha384_starts_wrap( void *ctx )
531
return( mbedtls_sha512_starts_ret( (mbedtls_sha512_context *) ctx, 1 ) );
534
static int sha384_update_wrap( void *ctx, const unsigned char *input,
537
return( mbedtls_sha512_update_ret( (mbedtls_sha512_context *) ctx,
541
static int sha384_finish_wrap( void *ctx, unsigned char *output )
543
return( mbedtls_sha512_finish_ret( (mbedtls_sha512_context *) ctx,
547
static int sha384_wrap( const unsigned char *input, size_t ilen,
548
unsigned char *output )
550
return( mbedtls_sha512_ret( input, ilen, output, 1 ) );
553
static void *sha384_ctx_alloc( void )
555
void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_sha512_context ) );
558
mbedtls_sha512_init( (mbedtls_sha512_context *) ctx );
563
static void sha384_ctx_free( void *ctx )
565
mbedtls_sha512_free( (mbedtls_sha512_context *) ctx );
569
static void sha384_clone_wrap( void *dst, const void *src )
571
mbedtls_sha512_clone( (mbedtls_sha512_context *) dst,
572
(const mbedtls_sha512_context *) src );
575
static int sha384_process_wrap( void *ctx, const unsigned char *data )
577
return( mbedtls_internal_sha512_process( (mbedtls_sha512_context *) ctx,
581
const mbedtls_md_info_t mbedtls_sha384_info = {
596
static int sha512_starts_wrap( void *ctx )
598
return( mbedtls_sha512_starts_ret( (mbedtls_sha512_context *) ctx, 0 ) );
601
static int sha512_wrap( const unsigned char *input, size_t ilen,
602
unsigned char *output )
604
return( mbedtls_sha512_ret( input, ilen, output, 0 ) );
607
const mbedtls_md_info_t mbedtls_sha512_info = {
622
#endif /* MBEDTLS_SHA512_C */
624
#endif /* MBEDTLS_MD_C */