ReactOS 0.4.15-dev-8408-g466a198
md_wrap.c
Go to the documentation of this file.
1
51#if !defined(MBEDTLS_CONFIG_FILE)
52#include "mbedtls/config.h"
53#else
54#include MBEDTLS_CONFIG_FILE
55#endif
56
57#if defined(MBEDTLS_MD_C)
58
59#include "mbedtls/md_internal.h"
60
61#if defined(MBEDTLS_MD2_C)
62#include "mbedtls/md2.h"
63#endif
64
65#if defined(MBEDTLS_MD4_C)
66#include "mbedtls/md4.h"
67#endif
68
69#if defined(MBEDTLS_MD5_C)
70#include "mbedtls/md5.h"
71#endif
72
73#if defined(MBEDTLS_RIPEMD160_C)
74#include "mbedtls/ripemd160.h"
75#endif
76
77#if defined(MBEDTLS_SHA1_C)
78#include "mbedtls/sha1.h"
79#endif
80
81#if defined(MBEDTLS_SHA256_C)
82#include "mbedtls/sha256.h"
83#endif
84
85#if defined(MBEDTLS_SHA512_C)
86#include "mbedtls/sha512.h"
87#endif
88
89#if defined(MBEDTLS_PLATFORM_C)
90#include "mbedtls/platform.h"
91#else
92#include <stdlib.h>
93#define mbedtls_calloc calloc
94#define mbedtls_free free
95#endif
96
97#if defined(MBEDTLS_MD2_C)
98
99static int md2_starts_wrap( void *ctx )
100{
102}
103
104static int md2_update_wrap( void *ctx, const unsigned char *input,
105 size_t ilen )
106{
107 return( mbedtls_md2_update_ret( (mbedtls_md2_context *) ctx, input, ilen ) );
108}
109
110static int md2_finish_wrap( void *ctx, unsigned char *output )
111{
112 return( mbedtls_md2_finish_ret( (mbedtls_md2_context *) ctx, output ) );
113}
114
115static void *md2_ctx_alloc( void )
116{
117 void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_md2_context ) );
118
119 if( ctx != NULL )
121
122 return( ctx );
123}
124
125static void md2_ctx_free( void *ctx )
126{
128 mbedtls_free( ctx );
129}
130
131static void md2_clone_wrap( void *dst, const void *src )
132{
134 (const mbedtls_md2_context *) src );
135}
136
137static int md2_process_wrap( void *ctx, const unsigned char *data )
138{
139 ((void) data);
140
142}
143
144const mbedtls_md_info_t mbedtls_md2_info = {
146 "MD2",
147 16,
148 16,
149 md2_starts_wrap,
150 md2_update_wrap,
151 md2_finish_wrap,
153 md2_ctx_alloc,
154 md2_ctx_free,
155 md2_clone_wrap,
156 md2_process_wrap,
157};
158
159#endif /* MBEDTLS_MD2_C */
160
161#if defined(MBEDTLS_MD4_C)
162
163static int md4_starts_wrap( void *ctx )
164{
166}
167
168static int md4_update_wrap( void *ctx, const unsigned char *input,
169 size_t ilen )
170{
171 return( mbedtls_md4_update_ret( (mbedtls_md4_context *) ctx, input, ilen ) );
172}
173
174static int md4_finish_wrap( void *ctx, unsigned char *output )
175{
176 return( mbedtls_md4_finish_ret( (mbedtls_md4_context *) ctx, output ) );
177}
178
179static void *md4_ctx_alloc( void )
180{
181 void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_md4_context ) );
182
183 if( ctx != NULL )
185
186 return( ctx );
187}
188
189static void md4_ctx_free( void *ctx )
190{
192 mbedtls_free( ctx );
193}
194
195static void md4_clone_wrap( void *dst, const void *src )
196{
198 (const mbedtls_md4_context *) src );
199}
200
201static int md4_process_wrap( void *ctx, const unsigned char *data )
202{
204}
205
206const mbedtls_md_info_t mbedtls_md4_info = {
208 "MD4",
209 16,
210 64,
211 md4_starts_wrap,
212 md4_update_wrap,
213 md4_finish_wrap,
215 md4_ctx_alloc,
216 md4_ctx_free,
217 md4_clone_wrap,
218 md4_process_wrap,
219};
220
221#endif /* MBEDTLS_MD4_C */
222
223#if defined(MBEDTLS_MD5_C)
224
225static int md5_starts_wrap( void *ctx )
226{
228}
229
230static int md5_update_wrap( void *ctx, const unsigned char *input,
231 size_t ilen )
232{
233 return( mbedtls_md5_update_ret( (mbedtls_md5_context *) ctx, input, ilen ) );
234}
235
236static int md5_finish_wrap( void *ctx, unsigned char *output )
237{
238 return( mbedtls_md5_finish_ret( (mbedtls_md5_context *) ctx, output ) );
239}
240
241static void *md5_ctx_alloc( void )
242{
243 void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_md5_context ) );
244
245 if( ctx != NULL )
247
248 return( ctx );
249}
250
251static void md5_ctx_free( void *ctx )
252{
254 mbedtls_free( ctx );
255}
256
257static void md5_clone_wrap( void *dst, const void *src )
258{
260 (const mbedtls_md5_context *) src );
261}
262
263static int md5_process_wrap( void *ctx, const unsigned char *data )
264{
266}
267
270 "MD5",
271 16,
272 64,
273 md5_starts_wrap,
274 md5_update_wrap,
275 md5_finish_wrap,
277 md5_ctx_alloc,
278 md5_ctx_free,
279 md5_clone_wrap,
280 md5_process_wrap,
281};
282
283#endif /* MBEDTLS_MD5_C */
284
285#if defined(MBEDTLS_RIPEMD160_C)
286
287static int ripemd160_starts_wrap( void *ctx )
288{
290}
291
292static int ripemd160_update_wrap( void *ctx, const unsigned char *input,
293 size_t ilen )
294{
296 input, ilen ) );
297}
298
299static int ripemd160_finish_wrap( void *ctx, unsigned char *output )
300{
302 output ) );
303}
304
305static void *ripemd160_ctx_alloc( void )
306{
307 void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_ripemd160_context ) );
308
309 if( ctx != NULL )
311
312 return( ctx );
313}
314
315static void ripemd160_ctx_free( void *ctx )
316{
318 mbedtls_free( ctx );
319}
320
321static void ripemd160_clone_wrap( void *dst, const void *src )
322{
324 (const mbedtls_ripemd160_context *) src );
325}
326
327static int ripemd160_process_wrap( void *ctx, const unsigned char *data )
328{
331}
332
335 "RIPEMD160",
336 20,
337 64,
338 ripemd160_starts_wrap,
339 ripemd160_update_wrap,
340 ripemd160_finish_wrap,
342 ripemd160_ctx_alloc,
343 ripemd160_ctx_free,
344 ripemd160_clone_wrap,
345 ripemd160_process_wrap,
346};
347
348#endif /* MBEDTLS_RIPEMD160_C */
349
350#if defined(MBEDTLS_SHA1_C)
351
352static int sha1_starts_wrap( void *ctx )
353{
355}
356
357static int sha1_update_wrap( void *ctx, const unsigned char *input,
358 size_t ilen )
359{
361 input, ilen ) );
362}
363
364static int sha1_finish_wrap( void *ctx, unsigned char *output )
365{
366 return( mbedtls_sha1_finish_ret( (mbedtls_sha1_context *) ctx, output ) );
367}
368
369static void *sha1_ctx_alloc( void )
370{
371 void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_sha1_context ) );
372
373 if( ctx != NULL )
375
376 return( ctx );
377}
378
379static void sha1_clone_wrap( void *dst, const void *src )
380{
382 (const mbedtls_sha1_context *) src );
383}
384
385static void sha1_ctx_free( void *ctx )
386{
388 mbedtls_free( ctx );
389}
390
391static int sha1_process_wrap( void *ctx, const unsigned char *data )
392{
394 data ) );
395}
396
399 "SHA1",
400 20,
401 64,
402 sha1_starts_wrap,
403 sha1_update_wrap,
404 sha1_finish_wrap,
406 sha1_ctx_alloc,
407 sha1_ctx_free,
408 sha1_clone_wrap,
409 sha1_process_wrap,
410};
411
412#endif /* MBEDTLS_SHA1_C */
413
414/*
415 * Wrappers for generic message digests
416 */
417#if defined(MBEDTLS_SHA256_C)
418
419static int sha224_starts_wrap( void *ctx )
420{
422}
423
424static int sha224_update_wrap( void *ctx, const unsigned char *input,
425 size_t ilen )
426{
428 input, ilen ) );
429}
430
431static int sha224_finish_wrap( void *ctx, unsigned char *output )
432{
434 output ) );
435}
436
437static int sha224_wrap( const unsigned char *input, size_t ilen,
438 unsigned char *output )
439{
440 return( mbedtls_sha256_ret( input, ilen, output, 1 ) );
441}
442
443static void *sha224_ctx_alloc( void )
444{
445 void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_sha256_context ) );
446
447 if( ctx != NULL )
449
450 return( ctx );
451}
452
453static void sha224_ctx_free( void *ctx )
454{
456 mbedtls_free( ctx );
457}
458
459static void sha224_clone_wrap( void *dst, const void *src )
460{
462 (const mbedtls_sha256_context *) src );
463}
464
465static int sha224_process_wrap( void *ctx, const unsigned char *data )
466{
468 data ) );
469}
470
473 "SHA224",
474 28,
475 64,
476 sha224_starts_wrap,
477 sha224_update_wrap,
478 sha224_finish_wrap,
479 sha224_wrap,
480 sha224_ctx_alloc,
481 sha224_ctx_free,
482 sha224_clone_wrap,
483 sha224_process_wrap,
484};
485
486static int sha256_starts_wrap( void *ctx )
487{
489}
490
491static int sha256_wrap( const unsigned char *input, size_t ilen,
492 unsigned char *output )
493{
494 return( mbedtls_sha256_ret( input, ilen, output, 0 ) );
495}
496
499 "SHA256",
500 32,
501 64,
502 sha256_starts_wrap,
503 sha224_update_wrap,
504 sha224_finish_wrap,
505 sha256_wrap,
506 sha224_ctx_alloc,
507 sha224_ctx_free,
508 sha224_clone_wrap,
509 sha224_process_wrap,
510};
511
512#endif /* MBEDTLS_SHA256_C */
513
514#if defined(MBEDTLS_SHA512_C)
515
516static int sha384_starts_wrap( void *ctx )
517{
519}
520
521static int sha384_update_wrap( void *ctx, const unsigned char *input,
522 size_t ilen )
523{
525 input, ilen ) );
526}
527
528static int sha384_finish_wrap( void *ctx, unsigned char *output )
529{
531 output ) );
532}
533
534static int sha384_wrap( const unsigned char *input, size_t ilen,
535 unsigned char *output )
536{
537 return( mbedtls_sha512_ret( input, ilen, output, 1 ) );
538}
539
540static void *sha384_ctx_alloc( void )
541{
542 void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_sha512_context ) );
543
544 if( ctx != NULL )
546
547 return( ctx );
548}
549
550static void sha384_ctx_free( void *ctx )
551{
553 mbedtls_free( ctx );
554}
555
556static void sha384_clone_wrap( void *dst, const void *src )
557{
559 (const mbedtls_sha512_context *) src );
560}
561
562static int sha384_process_wrap( void *ctx, const unsigned char *data )
563{
565 data ) );
566}
567
570 "SHA384",
571 48,
572 128,
573 sha384_starts_wrap,
574 sha384_update_wrap,
575 sha384_finish_wrap,
576 sha384_wrap,
577 sha384_ctx_alloc,
578 sha384_ctx_free,
579 sha384_clone_wrap,
580 sha384_process_wrap,
581};
582
583static int sha512_starts_wrap( void *ctx )
584{
586}
587
588static int sha512_wrap( const unsigned char *input, size_t ilen,
589 unsigned char *output )
590{
591 return( mbedtls_sha512_ret( input, ilen, output, 0 ) );
592}
593
596 "SHA512",
597 64,
598 128,
599 sha512_starts_wrap,
600 sha384_update_wrap,
601 sha384_finish_wrap,
602 sha512_wrap,
603 sha384_ctx_alloc,
604 sha384_ctx_free,
605 sha384_clone_wrap,
606 sha384_process_wrap,
607};
608
609#endif /* MBEDTLS_SHA512_C */
610
611#endif /* MBEDTLS_MD_C */
#define NULL
Definition: types.h:112
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLenum src
Definition: glext.h:6340
GLenum GLenum dst
Definition: glext.h:6340
GLenum GLenum GLenum input
Definition: glext.h:9031
MD4 message digest algorithm (hash function)
int mbedtls_md4_ret(const unsigned char *input, size_t ilen, unsigned char output[16])
Output = MD4( input buffer )
int mbedtls_md4_starts_ret(mbedtls_md4_context *ctx)
MD4 context setup.
void mbedtls_md4_free(mbedtls_md4_context *ctx)
Clear MD4 context.
int mbedtls_md4_update_ret(mbedtls_md4_context *ctx, const unsigned char *input, size_t ilen)
MD4 process buffer.
int mbedtls_md4_finish_ret(mbedtls_md4_context *ctx, unsigned char output[16])
MD4 final digest.
void mbedtls_md4_init(mbedtls_md4_context *ctx)
Initialize MD4 context.
void mbedtls_md4_clone(mbedtls_md4_context *dst, const mbedtls_md4_context *src)
Clone (the state of) an MD4 context.
int mbedtls_internal_md4_process(mbedtls_md4_context *ctx, const unsigned char data[64])
MD4 process data block (internal use only)
This file contains SHA-1 definitions and functions.
void mbedtls_sha1_free(mbedtls_sha1_context *ctx)
This function clears a SHA-1 context.
void mbedtls_sha1_clone(mbedtls_sha1_context *dst, const mbedtls_sha1_context *src)
This function clones the state of a SHA-1 context.
int mbedtls_sha1_ret(const unsigned char *input, size_t ilen, unsigned char output[20])
This function calculates the SHA-1 checksum of a buffer.
int mbedtls_sha1_update_ret(mbedtls_sha1_context *ctx, const unsigned char *input, size_t ilen)
This function feeds an input buffer into an ongoing SHA-1 checksum calculation.
int mbedtls_internal_sha1_process(mbedtls_sha1_context *ctx, const unsigned char data[64])
SHA-1 process data block (internal use only).
int mbedtls_sha1_starts_ret(mbedtls_sha1_context *ctx)
This function starts a SHA-1 checksum calculation.
int mbedtls_sha1_finish_ret(mbedtls_sha1_context *ctx, unsigned char output[20])
This function finishes the SHA-1 operation, and writes the result to the output buffer.
void mbedtls_sha1_init(mbedtls_sha1_context *ctx)
This function initializes a SHA-1 context.
MD2 message digest algorithm (hash function)
void mbedtls_md2_init(mbedtls_md2_context *ctx)
Initialize MD2 context.
void mbedtls_md2_clone(mbedtls_md2_context *dst, const mbedtls_md2_context *src)
Clone (the state of) an MD2 context.
int mbedtls_internal_md2_process(mbedtls_md2_context *ctx)
MD2 process data block (internal use only)
int mbedtls_md2_finish_ret(mbedtls_md2_context *ctx, unsigned char output[16])
MD2 final digest.
void mbedtls_md2_free(mbedtls_md2_context *ctx)
Clear MD2 context.
int mbedtls_md2_ret(const unsigned char *input, size_t ilen, unsigned char output[16])
Output = MD2( input buffer )
int mbedtls_md2_starts_ret(mbedtls_md2_context *ctx)
MD2 context setup.
int mbedtls_md2_update_ret(mbedtls_md2_context *ctx, const unsigned char *input, size_t ilen)
MD2 process buffer.
@ MBEDTLS_MD_SHA512
Definition: md.h:92
@ MBEDTLS_MD_MD5
Definition: md.h:87
@ MBEDTLS_MD_RIPEMD160
Definition: md.h:93
@ MBEDTLS_MD_SHA384
Definition: md.h:91
@ MBEDTLS_MD_SHA256
Definition: md.h:90
@ MBEDTLS_MD_SHA224
Definition: md.h:89
@ MBEDTLS_MD_SHA1
Definition: md.h:88
@ MBEDTLS_MD_MD4
Definition: md.h:86
@ MBEDTLS_MD_MD2
Definition: md.h:85
Message digest wrappers.
const mbedtls_md_info_t mbedtls_sha384_info
const mbedtls_md_info_t mbedtls_sha1_info
const mbedtls_md_info_t mbedtls_ripemd160_info
const mbedtls_md_info_t mbedtls_sha256_info
const mbedtls_md_info_t mbedtls_sha224_info
const mbedtls_md_info_t mbedtls_md5_info
const mbedtls_md_info_t mbedtls_sha512_info
RIPE MD-160 message digest.
void mbedtls_ripemd160_clone(mbedtls_ripemd160_context *dst, const mbedtls_ripemd160_context *src)
Clone (the state of) an RIPEMD-160 context.
void mbedtls_ripemd160_init(mbedtls_ripemd160_context *ctx)
Initialize RIPEMD-160 context.
int mbedtls_internal_ripemd160_process(mbedtls_ripemd160_context *ctx, const unsigned char data[64])
RIPEMD-160 process data block (internal use only)
void mbedtls_ripemd160_free(mbedtls_ripemd160_context *ctx)
Clear RIPEMD-160 context.
int mbedtls_ripemd160_update_ret(mbedtls_ripemd160_context *ctx, const unsigned char *input, size_t ilen)
RIPEMD-160 process buffer.
int mbedtls_ripemd160_ret(const unsigned char *input, size_t ilen, unsigned char output[20])
Output = RIPEMD-160( input buffer )
int mbedtls_ripemd160_finish_ret(mbedtls_ripemd160_context *ctx, unsigned char output[20])
RIPEMD-160 final digest.
int mbedtls_ripemd160_starts_ret(mbedtls_ripemd160_context *ctx)
RIPEMD-160 context setup.
Configuration options (set of defines)
MD5 message digest algorithm (hash function)
void mbedtls_md5_clone(mbedtls_md5_context *dst, const mbedtls_md5_context *src)
Clone (the state of) an MD5 context.
int mbedtls_internal_md5_process(mbedtls_md5_context *ctx, const unsigned char data[64])
MD5 process data block (internal use only)
void mbedtls_md5_free(mbedtls_md5_context *ctx)
Clear MD5 context.
int mbedtls_md5_ret(const unsigned char *input, size_t ilen, unsigned char output[16])
Output = MD5( input buffer )
int mbedtls_md5_starts_ret(mbedtls_md5_context *ctx)
MD5 context setup.
void mbedtls_md5_init(mbedtls_md5_context *ctx)
Initialize MD5 context.
int mbedtls_md5_update_ret(mbedtls_md5_context *ctx, const unsigned char *input, size_t ilen)
MD5 process buffer.
int mbedtls_md5_finish_ret(mbedtls_md5_context *ctx, unsigned char output[16])
MD5 final digest.
This file contains the definitions and functions of the Mbed TLS platform abstraction layer.
#define mbedtls_free
Definition: platform.h:168
#define mbedtls_calloc
Definition: platform.h:169
This file contains SHA-224 and SHA-256 definitions and functions.
void mbedtls_sha256_free(mbedtls_sha256_context *ctx)
This function clears a SHA-256 context.
void mbedtls_sha256_init(mbedtls_sha256_context *ctx)
This function initializes a SHA-256 context.
int mbedtls_internal_sha256_process(mbedtls_sha256_context *ctx, const unsigned char data[64])
This function processes a single data block within the ongoing SHA-256 computation....
void mbedtls_sha256_clone(mbedtls_sha256_context *dst, const mbedtls_sha256_context *src)
This function clones the state of a SHA-256 context.
int mbedtls_sha256_ret(const unsigned char *input, size_t ilen, unsigned char output[32], int is224)
This function calculates the SHA-224 or SHA-256 checksum of a buffer.
int mbedtls_sha256_finish_ret(mbedtls_sha256_context *ctx, unsigned char output[32])
This function finishes the SHA-256 operation, and writes the result to the output buffer.
int mbedtls_sha256_starts_ret(mbedtls_sha256_context *ctx, int is224)
This function starts a SHA-224 or SHA-256 checksum calculation.
int mbedtls_sha256_update_ret(mbedtls_sha256_context *ctx, const unsigned char *input, size_t ilen)
This function feeds an input buffer into an ongoing SHA-256 checksum calculation.
This file contains SHA-384 and SHA-512 definitions and functions.
int mbedtls_sha512_ret(const unsigned char *input, size_t ilen, unsigned char output[64], int is384)
This function calculates the SHA-512 or SHA-384 checksum of a buffer.
int mbedtls_internal_sha512_process(mbedtls_sha512_context *ctx, const unsigned char data[128])
This function processes a single data block within the ongoing SHA-512 computation....
void mbedtls_sha512_clone(mbedtls_sha512_context *dst, const mbedtls_sha512_context *src)
This function clones the state of a SHA-512 context.
void mbedtls_sha512_free(mbedtls_sha512_context *ctx)
This function clears a SHA-512 context.
int mbedtls_sha512_starts_ret(mbedtls_sha512_context *ctx, int is384)
This function starts a SHA-384 or SHA-512 checksum calculation.
int mbedtls_sha512_update_ret(mbedtls_sha512_context *ctx, const unsigned char *input, size_t ilen)
This function feeds an input buffer into an ongoing SHA-512 checksum calculation.
int mbedtls_sha512_finish_ret(mbedtls_sha512_context *ctx, unsigned char output[64])
This function finishes the SHA-512 operation, and writes the result to the output buffer.
void mbedtls_sha512_init(mbedtls_sha512_context *ctx)
This function initializes a SHA-512 context.
MD2 context structure.
Definition: md2.h:85
MD4 context structure.
Definition: md4.h:86
MD5 context structure.
Definition: md5.h:85
RIPEMD-160 context structure.
Definition: ripemd160.h:77
The SHA-1 context structure.
Definition: sha1.h:89
The SHA-256 context structure.
Definition: sha256.h:84
The SHA-512 context structure.
Definition: sha512.h:83