blob: 568c9714b92176d7e7f28d861addb4f24b89e333 [file] [log] [blame]
Hanno Beckerc4e42102019-09-04 12:43:22 +01001 /**
2 * \file md.h
3 *
4 * \brief This file contains the generic message-digest wrapper.
5 *
6 * \author Adriaan de Jong <dejong@fox-it.com>
7 */
8/*
9 * Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved
10 * SPDX-License-Identifier: Apache-2.0
11 *
12 * Licensed under the Apache License, Version 2.0 (the "License"); you may
13 * not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
15 *
16 * http://www.apache.org/licenses/LICENSE-2.0
17 *
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
20 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
23 *
24 * This file is part of Mbed TLS (https://tls.mbed.org)
25 */
26
27#ifndef MBEDTLS_MD_INTERNAL_H
28#define MBEDTLS_MD_INTERNAL_H
29
30#if defined(MBEDTLS_MD2_C)
31#include "mbedtls/md2.h"
32#endif
33
34#if defined(MBEDTLS_MD4_C)
35#include "mbedtls/md4.h"
36#endif
37
38#if defined(MBEDTLS_MD5_C)
39#include "mbedtls/md5.h"
40#endif
41
42#if defined(MBEDTLS_RIPEMD160_C)
43#include "mbedtls/ripemd160.h"
44#endif
45
46#if defined(MBEDTLS_SHA1_C)
47#include "mbedtls/sha1.h"
48#endif
49
50#if defined(MBEDTLS_SHA256_C)
51#include "mbedtls/sha256.h"
52#endif
53
54#if defined(MBEDTLS_SHA512_C)
55#include "mbedtls/sha512.h"
56#endif
57
58#include "mbedtls/platform_util.h"
59
60#if defined(MBEDTLS_PLATFORM_C)
61#include "mbedtls/platform.h"
62#else
63#include <stdlib.h>
64#define mbedtls_calloc calloc
65#define mbedtls_free free
66#endif
67
68#ifdef __cplusplus
69extern "C" {
70#endif
71
72/*
73 * Message-digest information macro definition
74 */
75
76/* SHA-256 */
77#define MBEDTLS_MD_INFO_SHA256_TYPE MBEDTLS_MD_SHA256
78#define MBEDTLS_MD_INFO_SHA256_NAME "SHA256"
79#define MBEDTLS_MD_INFO_SHA256_SIZE 32
80#define MBEDTLS_MD_INFO_SHA256_BLOCKSIZE 64
81#define MBEDTLS_MD_INFO_SHA256_STARTS_FUNC mbedtls_sha256_starts_wrap
82#define MBEDTLS_MD_INFO_SHA256_UPDATE_FUNC mbedtls_sha224_update_wrap
83#define MBEDTLS_MD_INFO_SHA256_FINISH_FUNC mbedtls_sha224_finish_wrap
84#define MBEDTLS_MD_INFO_SHA256_DIGEST_FUNC mbedtls_sha256_wrap
85#define MBEDTLS_MD_INFO_SHA256_ALLOC_FUNC mbedtls_sha224_ctx_alloc
86#define MBEDTLS_MD_INFO_SHA256_FREE_FUNC mbedtls_sha224_ctx_free
87#define MBEDTLS_MD_INFO_SHA256_CLONE_FUNC mbedtls_sha224_clone_wrap
88#define MBEDTLS_MD_INFO_SHA256_PROCESS_FUNC mbedtls_sha224_process_wrap
89
90/*
91 * Helper macros to extract fields from ciphersuites.
92 */
93
94#define MBEDTLS_MD_INFO_TYPE_T( MD ) MD ## _TYPE
95#define MBEDTLS_MD_INFO_NAME_T( MD ) MD ## _NAME
96#define MBEDTLS_MD_INFO_SIZE_T( MD ) MD ## _SIZE
97#define MBEDTLS_MD_INFO_BLOCKSIZE_T( MD ) MD ## _BLOCKSIZE
98#define MBEDTLS_MD_INFO_STARTS_FUNC_T( MD ) MD ## _STARTS_FUNC
99#define MBEDTLS_MD_INFO_UPDATE_FUNC_T( MD ) MD ## _UPDATE_FUNC
100#define MBEDTLS_MD_INFO_FINISH_FUNC_T( MD ) MD ## _FINISH_FUNC
101#define MBEDTLS_MD_INFO_DIGEST_FUNC_T( MD ) MD ## _DIGEST_FUNC
102#define MBEDTLS_MD_INFO_ALLOC_FUNC_T( MD ) MD ## _ALLOC_FUNC
103#define MBEDTLS_MD_INFO_FREE_FUNC_T( MD ) MD ## _FREE_FUNC
104#define MBEDTLS_MD_INFO_CLONE_FUNC_T( MD ) MD ## _CLONE_FUNC
105#define MBEDTLS_MD_INFO_PROCESS_FUNC_T( MD ) MD ## _PROCESS_FUNC
106
107/* Wrapper around MBEDTLS_MD_INFO_XXX_T() which makes sure that
108 * the argument is macro-expanded before concatenated with the
109 * field name. This allows to call these macros as
110 * MBEDTLS_MD_INFO_XXX( MBEDTLS_MD_SINGLE_HASH ).
111 * where MBEDTLS_MD_SINGLE_HASH expands to MBEDTLS_MD_INFO_XXX. */
112#define MBEDTLS_MD_INFO_TYPE( MD ) MBEDTLS_MD_INFO_TYPE_T( MD )
113#define MBEDTLS_MD_INFO_NAME( MD ) MBEDTLS_MD_INFO_NAME_T( MD )
114#define MBEDTLS_MD_INFO_SIZE( MD ) MBEDTLS_MD_INFO_SIZE_T( MD )
115#define MBEDTLS_MD_INFO_BLOCKSIZE( MD ) MBEDTLS_MD_INFO_BLOCKSIZE_T( MD )
116#define MBEDTLS_MD_INFO_STARTS_FUNC( MD ) MBEDTLS_MD_INFO_STARTS_FUNC_T( MD )
117#define MBEDTLS_MD_INFO_UPDATE_FUNC( MD ) MBEDTLS_MD_INFO_UPDATE_FUNC_T( MD )
118#define MBEDTLS_MD_INFO_FINISH_FUNC( MD ) MBEDTLS_MD_INFO_FINISH_FUNC_T( MD )
119#define MBEDTLS_MD_INFO_DIGEST_FUNC( MD ) MBEDTLS_MD_INFO_DIGEST_FUNC_T( MD )
120#define MBEDTLS_MD_INFO_ALLOC_FUNC( MD ) MBEDTLS_MD_INFO_ALLOC_FUNC_T( MD )
121#define MBEDTLS_MD_INFO_FREE_FUNC( MD ) MBEDTLS_MD_INFO_FREE_FUNC_T( MD )
122#define MBEDTLS_MD_INFO_CLONE_FUNC( MD ) MBEDTLS_MD_INFO_CLONE_FUNC_T( MD )
123#define MBEDTLS_MD_INFO_PROCESS_FUNC( MD ) MBEDTLS_MD_INFO_PROCESS_FUNC_T( MD )
124
125/**
126 * Message digest information.
127 * Allows message digest functions to be called in a generic way.
128 */
129
130typedef int mbedtls_md_starts_func_t( void *ctx );
131typedef int mbedtls_md_update_func_t( void *ctx,
132 const unsigned char *input,
133 size_t ilen );
134typedef int mbedtls_md_finish_func_t( void *ctx, unsigned char *output );
135typedef int mbedtls_md_digest_func_t( const unsigned char *input,
136 size_t ilen,
137 unsigned char *output );
138typedef void* mbedtls_md_ctx_alloc_func_t( void );
139typedef void mbedtls_md_ctx_free_func_t( void *ctx );
140typedef void mbedtls_md_clone_func_t( void *st, const void *src );
141typedef int mbedtls_md_process_func_t( void *ctx,
142 const unsigned char *input );
143
144#if !defined(MBEDTLS_MD_SINGLE_HASH)
145struct mbedtls_md_info_t
146{
147 /** Digest identifier */
148 mbedtls_md_type_t type;
149
150 /** Name of the message digest */
151 const char * name;
152
153 /** Output length of the digest function in bytes */
154 int size;
155
156 /** Block length of the digest function in bytes */
157 int block_size;
158
159 /** Digest initialisation function */
160 mbedtls_md_starts_func_t *starts_func;
161
162 /** Digest update function */
163 mbedtls_md_update_func_t *update_func;
164
165 /** Digest finalisation function */
166 mbedtls_md_finish_func_t *finish_func;
167
168 /** Generic digest function */
169 mbedtls_md_digest_func_t *digest_func;
170
171 /** Allocate a new context */
172 mbedtls_md_ctx_alloc_func_t *ctx_alloc_func;
173
174 /** Free the given context */
175 mbedtls_md_ctx_free_func_t *ctx_free_func;
176
177 /** Clone state from a context */
178 mbedtls_md_clone_func_t *clone_func;
179
180 /** Internal use only */
181 mbedtls_md_process_func_t *process_func;
182};
183
184/**
185 * \brief This macro builds an instance of ::mbedtls_md_info_t
186 * from an \c MBEDTLS_MD_INFO_XXX identifier.
187 */
188#define MBEDTLS_MD_INFO( MD ) \
189 { MBEDTLS_MD_INFO_TYPE( MD ), \
190 MBEDTLS_MD_INFO_NAME( MD ), \
191 MBEDTLS_MD_INFO_SIZE( MD ), \
192 MBEDTLS_MD_INFO_BLOCKSIZE( MD ), \
193 MBEDTLS_MD_INFO_STARTS_FUNC( MD ), \
194 MBEDTLS_MD_INFO_UPDATE_FUNC( MD ), \
195 MBEDTLS_MD_INFO_FINISH_FUNC( MD ), \
196 MBEDTLS_MD_INFO_DIGEST_FUNC( MD ), \
197 MBEDTLS_MD_INFO_ALLOC_FUNC( MD ), \
198 MBEDTLS_MD_INFO_FREE_FUNC( MD ), \
199 MBEDTLS_MD_INFO_CLONE_FUNC( MD ), \
200 MBEDTLS_MD_INFO_PROCESS_FUNC( MD ) }
201
202#endif /* !MBEDTLS_MD_SINGLE_HASH */
203
204/*
205 *
206 * Definitions of MD information structures for various digests.
207 *
208 */
209
210/*
211 * MD-2
212 */
213
214#if defined(MBEDTLS_MD2_C)
215
216static int mbedtls_md2_starts_wrap( void *ctx )
217{
218 return( mbedtls_md2_starts_ret( (mbedtls_md2_context *) ctx ) );
219}
220
221static int mbedtls_md2_update_wrap( void *ctx, const unsigned char *input,
222 size_t ilen )
223{
224 return( mbedtls_md2_update_ret( (mbedtls_md2_context *) ctx, input, ilen ) );
225}
226
227static int mbedtls_md2_finish_wrap( void *ctx, unsigned char *output )
228{
229 return( mbedtls_md2_finish_ret( (mbedtls_md2_context *) ctx, output ) );
230}
231
232static void* mbedtls_md2_ctx_alloc( void )
233{
234 void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_md2_context ) );
235
236 if( ctx != NULL )
237 mbedtls_md2_init( (mbedtls_md2_context *) ctx );
238
239 return( ctx );
240}
241
242static void mbedtls_md2_ctx_free( void *ctx )
243{
244 mbedtls_md2_free( (mbedtls_md2_context *) ctx );
245 mbedtls_free( ctx );
246}
247
248static void mbedtls_md2_clone_wrap( void *dst, const void *src )
249{
250 mbedtls_md2_clone( (mbedtls_md2_context *) dst,
251 (const mbedtls_md2_context *) src );
252}
253
254static int mbedtls_md2_process_wrap( void *ctx, const unsigned char *data )
255{
256 ((void) data);
257
258 return( mbedtls_internal_md2_process( (mbedtls_md2_context *) ctx ) );
259}
260
261#endif /* MBEDTLS_MD2_C */
262
263/*
264 * MD-4
265 */
266
267#if defined(MBEDTLS_MD4_C)
268
269static int mbedtls_md4_starts_wrap( void *ctx )
270{
271 return( mbedtls_md4_starts_ret( (mbedtls_md4_context *) ctx ) );
272}
273
274static int mbedtls_md4_update_wrap( void *ctx, const unsigned char *input,
275 size_t ilen )
276{
277 return( mbedtls_md4_update_ret( (mbedtls_md4_context *) ctx, input, ilen ) );
278}
279
280static int mbedtls_md4_finish_wrap( void *ctx, unsigned char *output )
281{
282 return( mbedtls_md4_finish_ret( (mbedtls_md4_context *) ctx, output ) );
283}
284
285static void* mbedtls_md4_ctx_alloc( void )
286{
287 void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_md4_context ) );
288
289 if( ctx != NULL )
290 mbedtls_md4_init( (mbedtls_md4_context *) ctx );
291
292 return( ctx );
293}
294
295static void mbedtls_md4_ctx_free( void *ctx )
296{
297 mbedtls_md4_free( (mbedtls_md4_context *) ctx );
298 mbedtls_free( ctx );
299}
300
301static void mbedtls_md4_clone_wrap( void *dst, const void *src )
302{
303 mbedtls_md4_clone( (mbedtls_md4_context *) dst,
304 (const mbedtls_md4_context *) src );
305}
306
307static int mbedtls_md4_process_wrap( void *ctx, const unsigned char *data )
308{
309 return( mbedtls_internal_md4_process( (mbedtls_md4_context *) ctx, data ) );
310}
311
312#endif /* MBEDTLS_MD4_C */
313
314/*
315 * MD-5
316 */
317
318#if defined(MBEDTLS_MD5_C)
319
320static int mbedtls_md5_starts_wrap( void *ctx )
321{
322 return( mbedtls_md5_starts_ret( (mbedtls_md5_context *) ctx ) );
323}
324
325static int mbedtls_md5_update_wrap( void *ctx, const unsigned char *input,
326 size_t ilen )
327{
328 return( mbedtls_md5_update_ret( (mbedtls_md5_context *) ctx, input, ilen ) );
329}
330
331static int mbedtls_md5_finish_wrap( void *ctx, unsigned char *output )
332{
333 return( mbedtls_md5_finish_ret( (mbedtls_md5_context *) ctx, output ) );
334}
335
336static void* mbedtls_md5_ctx_alloc( void )
337{
338 void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_md5_context ) );
339
340 if( ctx != NULL )
341 mbedtls_md5_init( (mbedtls_md5_context *) ctx );
342
343 return( ctx );
344}
345
346static void mbedtls_md5_ctx_free( void *ctx )
347{
348 mbedtls_md5_free( (mbedtls_md5_context *) ctx );
349 mbedtls_free( ctx );
350}
351
352static void mbedtls_md5_clone_wrap( void *dst, const void *src )
353{
354 mbedtls_md5_clone( (mbedtls_md5_context *) dst,
355 (const mbedtls_md5_context *) src );
356}
357
358static int mbedtls_md5_process_wrap( void *ctx, const unsigned char *data )
359{
360 return( mbedtls_internal_md5_process( (mbedtls_md5_context *) ctx, data ) );
361}
362
363#endif /* MBEDTLS_MD5_C */
364
365/*
366 * RIPEMD-160
367 */
368
369#if defined(MBEDTLS_RIPEMD160_C)
370
371static int mbedtls_ripemd160_starts_wrap( void *ctx )
372{
373 return( mbedtls_ripemd160_starts_ret( (mbedtls_ripemd160_context *) ctx ) );
374}
375
376static int mbedtls_ripemd160_update_wrap( void *ctx, const unsigned char *input,
377 size_t ilen )
378{
379 return( mbedtls_ripemd160_update_ret( (mbedtls_ripemd160_context *) ctx,
380 input, ilen ) );
381}
382
383static int mbedtls_ripemd160_finish_wrap( void *ctx, unsigned char *output )
384{
385 return( mbedtls_ripemd160_finish_ret( (mbedtls_ripemd160_context *) ctx,
386 output ) );
387}
388
389static void* mbedtls_ripemd160_ctx_alloc( void )
390{
391 void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_ripemd160_context ) );
392
393 if( ctx != NULL )
394 mbedtls_ripemd160_init( (mbedtls_ripemd160_context *) ctx );
395
396 return( ctx );
397}
398
399static void mbedtls_ripemd160_ctx_free( void *ctx )
400{
401 mbedtls_ripemd160_free( (mbedtls_ripemd160_context *) ctx );
402 mbedtls_free( ctx );
403}
404
405static void mbedtls_ripemd160_clone_wrap( void *dst, const void *src )
406{
407 mbedtls_ripemd160_clone( (mbedtls_ripemd160_context *) dst,
408 (const mbedtls_ripemd160_context *) src );
409}
410
411static int mbedtls_ripemd160_process_wrap( void *ctx, const unsigned char *data )
412{
413 return( mbedtls_internal_ripemd160_process(
414 (mbedtls_ripemd160_context *) ctx, data ) );
415}
416
417#endif /* MBEDTLS_RIPEMD160_C */
418
419/*
420 * SHA-1
421 */
422
423#if defined(MBEDTLS_SHA1_C)
424
425static int mbedtls_sha1_starts_wrap( void *ctx )
426{
427 return( mbedtls_sha1_starts_ret( (mbedtls_sha1_context *) ctx ) );
428}
429
430static int mbedtls_sha1_update_wrap( void *ctx, const unsigned char *input,
431 size_t ilen )
432{
433 return( mbedtls_sha1_update_ret( (mbedtls_sha1_context *) ctx,
434 input, ilen ) );
435}
436
437static int mbedtls_sha1_finish_wrap( void *ctx, unsigned char *output )
438{
439 return( mbedtls_sha1_finish_ret( (mbedtls_sha1_context *) ctx, output ) );
440}
441
442static void* mbedtls_sha1_ctx_alloc( void )
443{
444 void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_sha1_context ) );
445
446 if( ctx != NULL )
447 mbedtls_sha1_init( (mbedtls_sha1_context *) ctx );
448
449 return( ctx );
450}
451
452static void mbedtls_sha1_clone_wrap( void *dst, const void *src )
453{
454 mbedtls_sha1_clone( (mbedtls_sha1_context *) dst,
455 (const mbedtls_sha1_context *) src );
456}
457
458static void mbedtls_sha1_ctx_free( void *ctx )
459{
460 mbedtls_sha1_free( (mbedtls_sha1_context *) ctx );
461 mbedtls_free( ctx );
462}
463
464static int mbedtls_sha1_process_wrap( void *ctx, const unsigned char *data )
465{
466 return( mbedtls_internal_sha1_process( (mbedtls_sha1_context *) ctx,
467 data ) );
468}
469
470#endif /* MBEDTLS_SHA1_C */
471
472/*
473 * SHA-224 and SHA-256
474 */
475
476#if defined(MBEDTLS_SHA256_C)
477
478#if !defined(MBEDTLS_SHA256_NO_SHA224)
479static int mbedtls_sha224_starts_wrap( void *ctx )
480{
481 return( mbedtls_sha256_starts_ret( (mbedtls_sha256_context *) ctx, 1 ) );
482}
483#endif /* !MBEDTLS_SHA256_NO_SHA224 */
484
485static int mbedtls_sha224_update_wrap( void *ctx, const unsigned char *input,
486 size_t ilen )
487{
488 return( mbedtls_sha256_update_ret( (mbedtls_sha256_context *) ctx,
489 input, ilen ) );
490}
491
492static int mbedtls_sha224_finish_wrap( void *ctx, unsigned char *output )
493{
494 return( mbedtls_sha256_finish_ret( (mbedtls_sha256_context *) ctx,
495 output ) );
496}
497
498#if !defined(MBEDTLS_SHA256_NO_SHA224)
499static int mbedtls_sha224_wrap( const unsigned char *input, size_t ilen,
500 unsigned char *output )
501{
502 return( mbedtls_sha256_ret( input, ilen, output, 1 ) );
503}
504#endif /* !MBEDTLS_SHA256_NO_SHA224 */
505
506static void* mbedtls_sha224_ctx_alloc( void )
507{
508 void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_sha256_context ) );
509
510 if( ctx != NULL )
511 mbedtls_sha256_init( (mbedtls_sha256_context *) ctx );
512
513 return( ctx );
514}
515
516static void mbedtls_sha224_ctx_free( void *ctx )
517{
518 mbedtls_sha256_free( (mbedtls_sha256_context *) ctx );
519 mbedtls_free( ctx );
520}
521
522static void mbedtls_sha224_clone_wrap( void *dst, const void *src )
523{
524 mbedtls_sha256_clone( (mbedtls_sha256_context *) dst,
525 (const mbedtls_sha256_context *) src );
526}
527
528static int mbedtls_sha224_process_wrap( void *ctx, const unsigned char *data )
529{
530 return( mbedtls_internal_sha256_process( (mbedtls_sha256_context *) ctx,
531 data ) );
532}
533
534static int mbedtls_sha256_starts_wrap( void *ctx )
535{
536 return( mbedtls_sha256_starts_ret( (mbedtls_sha256_context *) ctx, 0 ) );
537}
538
539static int mbedtls_sha256_wrap( const unsigned char *input, size_t ilen,
540 unsigned char *output )
541{
542 return( mbedtls_sha256_ret( input, ilen, output, 0 ) );
543}
544
545#endif /* MBEDTLS_SHA256_C */
546
547/*
548 * SHA-384 and SHA-512
549 */
550
551#if defined(MBEDTLS_SHA512_C)
552
553static int mbedtls_sha384_starts_wrap( void *ctx )
554{
555 return( mbedtls_sha512_starts_ret( (mbedtls_sha512_context *) ctx, 1 ) );
556}
557
558static int mbedtls_sha384_update_wrap( void *ctx, const unsigned char *input,
559 size_t ilen )
560{
561 return( mbedtls_sha512_update_ret( (mbedtls_sha512_context *) ctx,
562 input, ilen ) );
563}
564
565static int mbedtls_sha384_finish_wrap( void *ctx, unsigned char *output )
566{
567 return( mbedtls_sha512_finish_ret( (mbedtls_sha512_context *) ctx,
568 output ) );
569}
570
571static int mbedtls_sha384_wrap( const unsigned char *input, size_t ilen,
572 unsigned char *output )
573{
574 return( mbedtls_sha512_ret( input, ilen, output, 1 ) );
575}
576
577static void* mbedtls_sha384_ctx_alloc( void )
578{
579 void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_sha512_context ) );
580
581 if( ctx != NULL )
582 mbedtls_sha512_init( (mbedtls_sha512_context *) ctx );
583
584 return( ctx );
585}
586
587static void mbedtls_sha384_ctx_free( void *ctx )
588{
589 mbedtls_sha512_free( (mbedtls_sha512_context *) ctx );
590 mbedtls_free( ctx );
591}
592
593static void mbedtls_sha384_clone_wrap( void *dst, const void *src )
594{
595 mbedtls_sha512_clone( (mbedtls_sha512_context *) dst,
596 (const mbedtls_sha512_context *) src );
597}
598
599static int mbedtls_sha384_process_wrap( void *ctx, const unsigned char *data )
600{
601 return( mbedtls_internal_sha512_process( (mbedtls_sha512_context *) ctx,
602 data ) );
603}
604
605static int mbedtls_sha512_starts_wrap( void *ctx )
606{
607 return( mbedtls_sha512_starts_ret( (mbedtls_sha512_context *) ctx, 0 ) );
608}
609
610static int mbedtls_sha512_wrap( const unsigned char *input, size_t ilen,
611 unsigned char *output )
612{
613 return( mbedtls_sha512_ret( input, ilen, output, 0 ) );
614}
615
616#endif /* MBEDTLS_SHA512_C */
617
618/*
619 * Getter functions for MD info structure.
620 */
621
622#if !defined(MBEDTLS_MD_SINGLE_HASH)
623
624MBEDTLS_ALWAYS_INLINE static inline mbedtls_md_type_t mbedtls_md_info_type(
625 mbedtls_md_handle_t info )
626{
627 return( info->type );
628}
629
630MBEDTLS_ALWAYS_INLINE static inline const char * mbedtls_md_info_name(
631 mbedtls_md_handle_t info )
632{
633 return( info->name );
634}
635
636MBEDTLS_ALWAYS_INLINE static inline int mbedtls_md_info_size(
637 mbedtls_md_handle_t info )
638{
639 return( info->size );
640}
641
642MBEDTLS_ALWAYS_INLINE static inline int mbedtls_md_info_block_size(
643 mbedtls_md_handle_t info )
644{
645 return( info->block_size );
646}
647
648MBEDTLS_ALWAYS_INLINE static inline int mbedtls_md_info_starts(
649 mbedtls_md_handle_t info,
650 void *ctx )
651{
652 return( info->starts_func( ctx ) );
653}
654
655MBEDTLS_ALWAYS_INLINE static inline int mbedtls_md_info_update(
656 mbedtls_md_handle_t info,
657 void *ctx,
658 const unsigned char *input,
659 size_t ilen )
660{
661 return( info->update_func( ctx, input, ilen ) );
662}
663
664MBEDTLS_ALWAYS_INLINE static inline int mbedtls_md_info_finish(
665 mbedtls_md_handle_t info,
666 void *ctx,
667 unsigned char *output )
668{
669 return( info->finish_func( ctx, output ) );
670}
671
672MBEDTLS_ALWAYS_INLINE static inline int mbedtls_md_info_digest(
673 mbedtls_md_handle_t info,
674 const unsigned char *input,
675 size_t ilen,
676 unsigned char *output )
677{
678 return( info->digest_func( input, ilen, output ) );
679}
680
681MBEDTLS_ALWAYS_INLINE static inline void* mbedtls_md_info_ctx_alloc(
682 mbedtls_md_handle_t info )
683{
684 return( info->ctx_alloc_func() );
685}
686
687MBEDTLS_ALWAYS_INLINE static inline void mbedtls_md_info_ctx_free(
688 mbedtls_md_handle_t info,
689 void *ctx )
690{
691 info->ctx_free_func( ctx );
692}
693
694MBEDTLS_ALWAYS_INLINE static inline void mbedtls_md_info_clone(
695 mbedtls_md_handle_t info,
696 void *dst,
697 const void *src )
698{
699 info->clone_func( dst, src );
700}
701
702MBEDTLS_ALWAYS_INLINE static inline int mbedtls_md_info_process(
703 mbedtls_md_handle_t info,
704 void *ctx,
705 const unsigned char *input )
706{
707 return( info->process_func( ctx, input ) );
708}
709
710#else /* !MBEDTLS_MD_SINGLE_HASH */
711
712MBEDTLS_ALWAYS_INLINE static inline mbedtls_md_type_t mbedtls_md_info_type(
713 mbedtls_md_handle_t info )
714{
715 ((void) info);
716 return( MBEDTLS_MD_INFO_TYPE( MBEDTLS_MD_SINGLE_HASH ) );
717}
718
719MBEDTLS_ALWAYS_INLINE static inline const char * mbedtls_md_info_name(
720 mbedtls_md_handle_t info )
721{
722 ((void) info);
723 return( MBEDTLS_MD_INFO_NAME( MBEDTLS_MD_SINGLE_HASH ) );
724}
725
726MBEDTLS_ALWAYS_INLINE static inline int mbedtls_md_info_size(
727 mbedtls_md_handle_t info )
728{
729 ((void) info);
730 return( MBEDTLS_MD_INFO_SIZE( MBEDTLS_MD_SINGLE_HASH ) );
731}
732
733MBEDTLS_ALWAYS_INLINE static inline int mbedtls_md_info_block_size(
734 mbedtls_md_handle_t info )
735{
736 ((void) info);
737 return( MBEDTLS_MD_INFO_BLOCKSIZE( MBEDTLS_MD_SINGLE_HASH ) );
738}
739
740MBEDTLS_ALWAYS_INLINE static inline int mbedtls_md_info_starts(
741 mbedtls_md_handle_t info,
742 void *ctx )
743{
744 ((void) info);
745 return( MBEDTLS_MD_INFO_STARTS_FUNC( MBEDTLS_MD_SINGLE_HASH )( ctx ) );
746}
747
748MBEDTLS_ALWAYS_INLINE static inline int mbedtls_md_info_update(
749 mbedtls_md_handle_t info,
750 void *ctx,
751 const unsigned char *input,
752 size_t ilen )
753{
754 ((void) info);
755 return( MBEDTLS_MD_INFO_UPDATE_FUNC( MBEDTLS_MD_SINGLE_HASH )
756 ( ctx, input, ilen ) );
757}
758
759MBEDTLS_ALWAYS_INLINE static inline int mbedtls_md_info_finish(
760 mbedtls_md_handle_t info,
761 void *ctx,
762 unsigned char *output )
763{
764 ((void) info);
765 return( MBEDTLS_MD_INFO_FINISH_FUNC( MBEDTLS_MD_SINGLE_HASH )
766 ( ctx, output ) );
767}
768
769MBEDTLS_ALWAYS_INLINE static inline int mbedtls_md_info_digest(
770 mbedtls_md_handle_t info,
771 const unsigned char *input,
772 size_t ilen,
773 unsigned char *output )
774{
775 ((void) info);
776 return( MBEDTLS_MD_INFO_DIGEST_FUNC( MBEDTLS_MD_SINGLE_HASH )
777 ( input, ilen, output ) );
778}
779
780MBEDTLS_ALWAYS_INLINE static inline void* mbedtls_md_info_ctx_alloc(
781 mbedtls_md_handle_t info )
782{
783 ((void) info);
784 return( MBEDTLS_MD_INFO_ALLOC_FUNC( MBEDTLS_MD_SINGLE_HASH )() );
785}
786
787MBEDTLS_ALWAYS_INLINE static inline void mbedtls_md_info_ctx_free(
788 mbedtls_md_handle_t info,
789 void *ctx )
790{
791 ((void) info);
792 MBEDTLS_MD_INFO_FREE_FUNC( MBEDTLS_MD_SINGLE_HASH )( ctx );
793}
794
795MBEDTLS_ALWAYS_INLINE static inline void mbedtls_md_info_clone(
796 mbedtls_md_handle_t info,
797 void *dst,
798 const void *src )
799{
800 ((void) info);
801 MBEDTLS_MD_INFO_CLONE_FUNC( MBEDTLS_MD_SINGLE_HASH )( dst, src );
802}
803
804MBEDTLS_ALWAYS_INLINE static inline int mbedtls_md_info_process(
805 mbedtls_md_handle_t info,
806 void *ctx,
807 const unsigned char *input )
808{
809 ((void) info);
810 return( MBEDTLS_MD_INFO_PROCESS_FUNC( MBEDTLS_MD_SINGLE_HASH )
811 ( ctx, input ) );
812}
813
814#endif /* MBEDTLS_MD_SINGLE_HASH */
815
816#ifdef __cplusplus
817}
818#endif
819
820#endif /* MBEDTLS_MD_INTERNAL_H */