~cpick/mongrel2/release

« back to all changes in this revision

Viewing changes to src/polarssl/md_wrap.c

  • Committer: Chris Pick
  • Date: 2013-06-30 16:39:57 UTC
  • mfrom: (1106.1.15)
  • Revision ID: git-v1:ec39967acb6bc9867ed9b9dc3774304ca6b9c294
Merge tag 'v1.8.1' into debian

Hotfix for github issue 148

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * \file md_wrap.c
 
3
 
 
4
 * \brief Generic message digest wrapper for PolarSSL
 
5
 *
 
6
 * \author Adriaan de Jong <dejong@fox-it.com>
 
7
 *
 
8
 *  Copyright (C) 2006-2010, Brainspark B.V.
 
9
 *
 
10
 *  This file is part of PolarSSL (http://www.polarssl.org)
 
11
 *  Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
 
12
 *
 
13
 *  All rights reserved.
 
14
 *
 
15
 *  This program is free software; you can redistribute it and/or modify
 
16
 *  it under the terms of the GNU General Public License as published by
 
17
 *  the Free Software Foundation; either version 2 of the License, or
 
18
 *  (at your option) any later version.
 
19
 *
 
20
 *  This program is distributed in the hope that it will be useful,
 
21
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
22
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
23
 *  GNU General Public License for more details.
 
24
 *
 
25
 *  You should have received a copy of the GNU General Public License along
 
26
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 
27
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
28
 */
 
29
 
 
30
#include "polarssl/config.h"
 
31
 
 
32
#if defined(POLARSSL_MD_C)
 
33
 
 
34
#include "polarssl/md_wrap.h"
 
35
#include "polarssl/md2.h"
 
36
#include "polarssl/md4.h"
 
37
#include "polarssl/md5.h"
 
38
#include "polarssl/sha1.h"
 
39
#include "polarssl/sha2.h"
 
40
#include "polarssl/sha4.h"
 
41
 
 
42
#include <stdlib.h>
 
43
 
 
44
#if defined(POLARSSL_MD2_C)
 
45
 
 
46
static void md2_starts_wrap( void *ctx )
 
47
{
 
48
    md2_starts( (md2_context *) ctx );
 
49
}
 
50
 
 
51
static void md2_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
 
52
{
 
53
    md2_update( (md2_context *) ctx, input, ilen );
 
54
}
 
55
 
 
56
static void md2_finish_wrap( void *ctx, unsigned char *output )
 
57
{
 
58
    md2_finish( (md2_context *) ctx, output );
 
59
}
 
60
 
 
61
int md2_file_wrap( const char *path, unsigned char *output )
 
62
{
 
63
#if defined(POLARSSL_FS_IO)
 
64
    return md2_file( path, output );
 
65
#else
 
66
    ((void) path);
 
67
    ((void) output);
 
68
    return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
 
69
#endif
 
70
}
 
71
 
 
72
static void md2_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen )
 
73
{
 
74
    md2_hmac_starts( (md2_context *) ctx, key, keylen );
 
75
}
 
76
 
 
77
static void md2_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
 
78
{
 
79
    md2_hmac_update( (md2_context *) ctx, input, ilen );
 
80
}
 
81
 
 
82
static void md2_hmac_finish_wrap( void *ctx, unsigned char *output )
 
83
{
 
84
    md2_hmac_finish( (md2_context *) ctx, output );
 
85
}
 
86
 
 
87
static void md2_hmac_reset_wrap( void *ctx )
 
88
{
 
89
    md2_hmac_reset( (md2_context *) ctx );
 
90
}
 
91
 
 
92
static void * md2_ctx_alloc( void )
 
93
{
 
94
    return malloc( sizeof( md2_context ) );
 
95
}
 
96
 
 
97
static void md2_ctx_free( void *ctx )
 
98
{
 
99
    free( ctx );
 
100
}
 
101
 
 
102
const md_info_t md2_info = {
 
103
    POLARSSL_MD_MD2,
 
104
    "MD2",
 
105
    16,
 
106
    md2_starts_wrap,
 
107
    md2_update_wrap,
 
108
    md2_finish_wrap,
 
109
    md2,
 
110
    md2_file_wrap,
 
111
    md2_hmac_starts_wrap,
 
112
    md2_hmac_update_wrap,
 
113
    md2_hmac_finish_wrap,
 
114
    md2_hmac_reset_wrap,
 
115
    md2_hmac,
 
116
    md2_ctx_alloc,
 
117
    md2_ctx_free,
 
118
};
 
119
 
 
120
#endif
 
121
 
 
122
#if defined(POLARSSL_MD4_C)
 
123
 
 
124
void md4_starts_wrap( void *ctx )
 
125
{
 
126
    md4_starts( (md4_context *) ctx );
 
127
}
 
128
 
 
129
void md4_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
 
130
{
 
131
    md4_update( (md4_context *) ctx, input, ilen );
 
132
}
 
133
 
 
134
void md4_finish_wrap( void *ctx, unsigned char *output )
 
135
{
 
136
    md4_finish( (md4_context *) ctx, output );
 
137
}
 
138
 
 
139
int md4_file_wrap( const char *path, unsigned char *output )
 
140
{
 
141
#if defined(POLARSSL_FS_IO)
 
142
    return md4_file( path, output );
 
143
#else
 
144
    ((void) path);
 
145
    ((void) output);
 
146
    return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
 
147
#endif
 
148
}
 
149
 
 
150
void md4_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen )
 
151
{
 
152
    md4_hmac_starts( (md4_context *) ctx, key, keylen );
 
153
}
 
154
 
 
155
void md4_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
 
156
{
 
157
    md4_hmac_update( (md4_context *) ctx, input, ilen );
 
158
}
 
159
 
 
160
void md4_hmac_finish_wrap( void *ctx, unsigned char *output )
 
161
{
 
162
    md4_hmac_finish( (md4_context *) ctx, output );
 
163
}
 
164
 
 
165
void md4_hmac_reset_wrap( void *ctx )
 
166
{
 
167
    md4_hmac_reset( (md4_context *) ctx );
 
168
}
 
169
 
 
170
void *md4_ctx_alloc( void )
 
171
{
 
172
    return malloc( sizeof( md4_context ) );
 
173
}
 
174
 
 
175
void md4_ctx_free( void *ctx )
 
176
{
 
177
    free( ctx );
 
178
}
 
179
 
 
180
const md_info_t md4_info = {
 
181
    POLARSSL_MD_MD4,
 
182
    "MD4",
 
183
    16,
 
184
    md4_starts_wrap,
 
185
    md4_update_wrap,
 
186
    md4_finish_wrap,
 
187
    md4,
 
188
    md4_file_wrap,
 
189
    md4_hmac_starts_wrap,
 
190
    md4_hmac_update_wrap,
 
191
    md4_hmac_finish_wrap,
 
192
    md4_hmac_reset_wrap,
 
193
    md4_hmac,
 
194
    md4_ctx_alloc,
 
195
    md4_ctx_free,
 
196
};
 
197
 
 
198
#endif
 
199
 
 
200
#if defined(POLARSSL_MD5_C)
 
201
 
 
202
static void md5_starts_wrap( void *ctx )
 
203
{
 
204
    md5_starts( (md5_context *) ctx );
 
205
}
 
206
 
 
207
static void md5_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
 
208
{
 
209
    md5_update( (md5_context *) ctx, input, ilen );
 
210
}
 
211
 
 
212
static void md5_finish_wrap( void *ctx, unsigned char *output )
 
213
{
 
214
    md5_finish( (md5_context *) ctx, output );
 
215
}
 
216
 
 
217
int md5_file_wrap( const char *path, unsigned char *output )
 
218
{
 
219
#if defined(POLARSSL_FS_IO)
 
220
    return md5_file( path, output );
 
221
#else
 
222
    ((void) path);
 
223
    ((void) output);
 
224
    return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
 
225
#endif
 
226
}
 
227
 
 
228
static void md5_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen )
 
229
{
 
230
    md5_hmac_starts( (md5_context *) ctx, key, keylen );
 
231
}
 
232
 
 
233
static void md5_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
 
234
{
 
235
    md5_hmac_update( (md5_context *) ctx, input, ilen );
 
236
}
 
237
 
 
238
static void md5_hmac_finish_wrap( void *ctx, unsigned char *output )
 
239
{
 
240
    md5_hmac_finish( (md5_context *) ctx, output );
 
241
}
 
242
 
 
243
static void md5_hmac_reset_wrap( void *ctx )
 
244
{
 
245
    md5_hmac_reset( (md5_context *) ctx );
 
246
}
 
247
 
 
248
static void * md5_ctx_alloc( void )
 
249
{
 
250
    return malloc( sizeof( md5_context ) );
 
251
}
 
252
 
 
253
static void md5_ctx_free( void *ctx )
 
254
{
 
255
    free( ctx );
 
256
}
 
257
 
 
258
const md_info_t md5_info = {
 
259
    POLARSSL_MD_MD5,
 
260
    "MD5",
 
261
    16,
 
262
    md5_starts_wrap,
 
263
    md5_update_wrap,
 
264
    md5_finish_wrap,
 
265
    md5,
 
266
    md5_file_wrap,
 
267
    md5_hmac_starts_wrap,
 
268
    md5_hmac_update_wrap,
 
269
    md5_hmac_finish_wrap,
 
270
    md5_hmac_reset_wrap,
 
271
    md5_hmac,
 
272
    md5_ctx_alloc,
 
273
    md5_ctx_free,
 
274
};
 
275
 
 
276
#endif
 
277
 
 
278
#if defined(POLARSSL_SHA1_C)
 
279
 
 
280
void sha1_starts_wrap( void *ctx )
 
281
{
 
282
    sha1_starts( (sha1_context *) ctx );
 
283
}
 
284
 
 
285
void sha1_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
 
286
{
 
287
    sha1_update( (sha1_context *) ctx, input, ilen );
 
288
}
 
289
 
 
290
void sha1_finish_wrap( void *ctx, unsigned char *output )
 
291
{
 
292
    sha1_finish( (sha1_context *) ctx, output );
 
293
}
 
294
 
 
295
int sha1_file_wrap( const char *path, unsigned char *output )
 
296
{
 
297
#if defined(POLARSSL_FS_IO)
 
298
    return sha1_file( path, output );
 
299
#else
 
300
    ((void) path);
 
301
    ((void) output);
 
302
    return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
 
303
#endif
 
304
}
 
305
 
 
306
void sha1_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen )
 
307
{
 
308
    sha1_hmac_starts( (sha1_context *) ctx, key, keylen );
 
309
}
 
310
 
 
311
void sha1_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
 
312
{
 
313
    sha1_hmac_update( (sha1_context *) ctx, input, ilen );
 
314
}
 
315
 
 
316
void sha1_hmac_finish_wrap( void *ctx, unsigned char *output )
 
317
{
 
318
    sha1_hmac_finish( (sha1_context *) ctx, output );
 
319
}
 
320
 
 
321
void sha1_hmac_reset_wrap( void *ctx )
 
322
{
 
323
    sha1_hmac_reset( (sha1_context *) ctx );
 
324
}
 
325
 
 
326
void * sha1_ctx_alloc( void )
 
327
{
 
328
    return malloc( sizeof( sha1_context ) );
 
329
}
 
330
 
 
331
void sha1_ctx_free( void *ctx )
 
332
{
 
333
    free( ctx );
 
334
}
 
335
 
 
336
const md_info_t sha1_info = {
 
337
    POLARSSL_MD_SHA1,
 
338
    "SHA1",
 
339
    20,
 
340
    sha1_starts_wrap,
 
341
    sha1_update_wrap,
 
342
    sha1_finish_wrap,
 
343
    sha1,
 
344
    sha1_file_wrap,
 
345
    sha1_hmac_starts_wrap,
 
346
    sha1_hmac_update_wrap,
 
347
    sha1_hmac_finish_wrap,
 
348
    sha1_hmac_reset_wrap,
 
349
    sha1_hmac,
 
350
    sha1_ctx_alloc,
 
351
    sha1_ctx_free,
 
352
};
 
353
 
 
354
#endif
 
355
 
 
356
/*
 
357
 * Wrappers for generic message digests
 
358
 */
 
359
#if defined(POLARSSL_SHA2_C)
 
360
 
 
361
void sha224_starts_wrap( void *ctx )
 
362
{
 
363
    sha2_starts( (sha2_context *) ctx, 1 );
 
364
}
 
365
 
 
366
void sha224_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
 
367
{
 
368
    sha2_update( (sha2_context *) ctx, input, ilen );
 
369
}
 
370
 
 
371
void sha224_finish_wrap( void *ctx, unsigned char *output )
 
372
{
 
373
    sha2_finish( (sha2_context *) ctx, output );
 
374
}
 
375
 
 
376
void sha224_wrap( const unsigned char *input, size_t ilen,
 
377
                    unsigned char *output )
 
378
{
 
379
    sha2( input, ilen, output, 1 );
 
380
}
 
381
 
 
382
int sha224_file_wrap( const char *path, unsigned char *output )
 
383
{
 
384
#if defined(POLARSSL_FS_IO)
 
385
    return sha2_file( path, output, 1 );
 
386
#else
 
387
    ((void) path);
 
388
    ((void) output);
 
389
    return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
 
390
#endif
 
391
}
 
392
 
 
393
void sha224_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen )
 
394
{
 
395
    sha2_hmac_starts( (sha2_context *) ctx, key, keylen, 1 );
 
396
}
 
397
 
 
398
void sha224_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
 
399
{
 
400
    sha2_hmac_update( (sha2_context *) ctx, input, ilen );
 
401
}
 
402
 
 
403
void sha224_hmac_finish_wrap( void *ctx, unsigned char *output )
 
404
{
 
405
    sha2_hmac_finish( (sha2_context *) ctx, output );
 
406
}
 
407
 
 
408
void sha224_hmac_reset_wrap( void *ctx )
 
409
{
 
410
    sha2_hmac_reset( (sha2_context *) ctx );
 
411
}
 
412
 
 
413
void sha224_hmac_wrap( const unsigned char *key, size_t keylen,
 
414
        const unsigned char *input, size_t ilen,
 
415
        unsigned char *output )
 
416
{
 
417
    sha2_hmac( key, keylen, input, ilen, output, 1 );
 
418
}
 
419
 
 
420
void * sha224_ctx_alloc( void )
 
421
{
 
422
    return malloc( sizeof( sha2_context ) );
 
423
}
 
424
 
 
425
void sha224_ctx_free( void *ctx )
 
426
{
 
427
    free( ctx );
 
428
}
 
429
 
 
430
const md_info_t sha224_info = {
 
431
    POLARSSL_MD_SHA224,
 
432
    "SHA224",
 
433
    28,
 
434
    sha224_starts_wrap,
 
435
    sha224_update_wrap,
 
436
    sha224_finish_wrap,
 
437
    sha224_wrap,
 
438
    sha224_file_wrap,
 
439
    sha224_hmac_starts_wrap,
 
440
    sha224_hmac_update_wrap,
 
441
    sha224_hmac_finish_wrap,
 
442
    sha224_hmac_reset_wrap,
 
443
    sha224_hmac_wrap,
 
444
    sha224_ctx_alloc,
 
445
    sha224_ctx_free,
 
446
};
 
447
 
 
448
void sha256_starts_wrap( void *ctx )
 
449
{
 
450
    sha2_starts( (sha2_context *) ctx, 0 );
 
451
}
 
452
 
 
453
void sha256_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
 
454
{
 
455
    sha2_update( (sha2_context *) ctx, input, ilen );
 
456
}
 
457
 
 
458
void sha256_finish_wrap( void *ctx, unsigned char *output )
 
459
{
 
460
    sha2_finish( (sha2_context *) ctx, output );
 
461
}
 
462
 
 
463
void sha256_wrap( const unsigned char *input, size_t ilen,
 
464
                    unsigned char *output )
 
465
{
 
466
    sha2( input, ilen, output, 0 );
 
467
}
 
468
 
 
469
int sha256_file_wrap( const char *path, unsigned char *output )
 
470
{
 
471
#if defined(POLARSSL_FS_IO)
 
472
    return sha2_file( path, output, 0 );
 
473
#else
 
474
    ((void) path);
 
475
    ((void) output);
 
476
    return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
 
477
#endif
 
478
}
 
479
 
 
480
void sha256_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen )
 
481
{
 
482
    sha2_hmac_starts( (sha2_context *) ctx, key, keylen, 0 );
 
483
}
 
484
 
 
485
void sha256_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
 
486
{
 
487
    sha2_hmac_update( (sha2_context *) ctx, input, ilen );
 
488
}
 
489
 
 
490
void sha256_hmac_finish_wrap( void *ctx, unsigned char *output )
 
491
{
 
492
    sha2_hmac_finish( (sha2_context *) ctx, output );
 
493
}
 
494
 
 
495
void sha256_hmac_reset_wrap( void *ctx )
 
496
{
 
497
    sha2_hmac_reset( (sha2_context *) ctx );
 
498
}
 
499
 
 
500
void sha256_hmac_wrap( const unsigned char *key, size_t keylen,
 
501
        const unsigned char *input, size_t ilen,
 
502
        unsigned char *output )
 
503
{
 
504
    sha2_hmac( key, keylen, input, ilen, output, 0 );
 
505
}
 
506
 
 
507
void * sha256_ctx_alloc( void )
 
508
{
 
509
    return malloc( sizeof( sha2_context ) );
 
510
}
 
511
 
 
512
void sha256_ctx_free( void *ctx )
 
513
{
 
514
    free( ctx );
 
515
}
 
516
 
 
517
const md_info_t sha256_info = {
 
518
    POLARSSL_MD_SHA256,
 
519
    "SHA256",
 
520
    32,
 
521
    sha256_starts_wrap,
 
522
    sha256_update_wrap,
 
523
    sha256_finish_wrap,
 
524
    sha256_wrap,
 
525
    sha256_file_wrap,
 
526
    sha256_hmac_starts_wrap,
 
527
    sha256_hmac_update_wrap,
 
528
    sha256_hmac_finish_wrap,
 
529
    sha256_hmac_reset_wrap,
 
530
    sha256_hmac_wrap,
 
531
    sha256_ctx_alloc,
 
532
    sha256_ctx_free,
 
533
};
 
534
 
 
535
#endif
 
536
 
 
537
#if defined(POLARSSL_SHA4_C)
 
538
 
 
539
void sha384_starts_wrap( void *ctx )
 
540
{
 
541
    sha4_starts( (sha4_context *) ctx, 1 );
 
542
}
 
543
 
 
544
void sha384_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
 
545
{
 
546
    sha4_update( (sha4_context *) ctx, input, ilen );
 
547
}
 
548
 
 
549
void sha384_finish_wrap( void *ctx, unsigned char *output )
 
550
{
 
551
    sha4_finish( (sha4_context *) ctx, output );
 
552
}
 
553
 
 
554
void sha384_wrap( const unsigned char *input, size_t ilen,
 
555
                    unsigned char *output )
 
556
{
 
557
    sha4( input, ilen, output, 1 );
 
558
}
 
559
 
 
560
int sha384_file_wrap( const char *path, unsigned char *output )
 
561
{
 
562
#if defined(POLARSSL_FS_IO)
 
563
    return sha4_file( path, output, 1 );
 
564
#else
 
565
    ((void) path);
 
566
    ((void) output);
 
567
    return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
 
568
#endif
 
569
}
 
570
 
 
571
void sha384_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen )
 
572
{
 
573
    sha4_hmac_starts( (sha4_context *) ctx, key, keylen, 1 );
 
574
}
 
575
 
 
576
void sha384_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
 
577
{
 
578
    sha4_hmac_update( (sha4_context *) ctx, input, ilen );
 
579
}
 
580
 
 
581
void sha384_hmac_finish_wrap( void *ctx, unsigned char *output )
 
582
{
 
583
    sha4_hmac_finish( (sha4_context *) ctx, output );
 
584
}
 
585
 
 
586
void sha384_hmac_reset_wrap( void *ctx )
 
587
{
 
588
    sha4_hmac_reset( (sha4_context *) ctx );
 
589
}
 
590
 
 
591
void sha384_hmac_wrap( const unsigned char *key, size_t keylen,
 
592
        const unsigned char *input, size_t ilen,
 
593
        unsigned char *output )
 
594
{
 
595
    sha4_hmac( key, keylen, input, ilen, output, 1 );
 
596
}
 
597
 
 
598
void * sha384_ctx_alloc( void )
 
599
{
 
600
    return malloc( sizeof( sha4_context ) );
 
601
}
 
602
 
 
603
void sha384_ctx_free( void *ctx )
 
604
{
 
605
    free( ctx );
 
606
}
 
607
 
 
608
const md_info_t sha384_info = {
 
609
    POLARSSL_MD_SHA384,
 
610
    "SHA384",
 
611
    48,
 
612
    sha384_starts_wrap,
 
613
    sha384_update_wrap,
 
614
    sha384_finish_wrap,
 
615
    sha384_wrap,
 
616
    sha384_file_wrap,
 
617
    sha384_hmac_starts_wrap,
 
618
    sha384_hmac_update_wrap,
 
619
    sha384_hmac_finish_wrap,
 
620
    sha384_hmac_reset_wrap,
 
621
    sha384_hmac_wrap,
 
622
    sha384_ctx_alloc,
 
623
    sha384_ctx_free,
 
624
};
 
625
 
 
626
void sha512_starts_wrap( void *ctx )
 
627
{
 
628
    sha4_starts( (sha4_context *) ctx, 0 );
 
629
}
 
630
 
 
631
void sha512_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
 
632
{
 
633
    sha4_update( (sha4_context *) ctx, input, ilen );
 
634
}
 
635
 
 
636
void sha512_finish_wrap( void *ctx, unsigned char *output )
 
637
{
 
638
    sha4_finish( (sha4_context *) ctx, output );
 
639
}
 
640
 
 
641
void sha512_wrap( const unsigned char *input, size_t ilen,
 
642
                    unsigned char *output )
 
643
{
 
644
    sha4( input, ilen, output, 0 );
 
645
}
 
646
 
 
647
int sha512_file_wrap( const char *path, unsigned char *output )
 
648
{
 
649
#if defined(POLARSSL_FS_IO)
 
650
    return sha4_file( path, output, 0 );
 
651
#else
 
652
    ((void) path);
 
653
    ((void) output);
 
654
    return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
 
655
#endif
 
656
}
 
657
 
 
658
void sha512_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen )
 
659
{
 
660
    sha4_hmac_starts( (sha4_context *) ctx, key, keylen, 0 );
 
661
}
 
662
 
 
663
void sha512_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
 
664
{
 
665
    sha4_hmac_update( (sha4_context *) ctx, input, ilen );
 
666
}
 
667
 
 
668
void sha512_hmac_finish_wrap( void *ctx, unsigned char *output )
 
669
{
 
670
    sha4_hmac_finish( (sha4_context *) ctx, output );
 
671
}
 
672
 
 
673
void sha512_hmac_reset_wrap( void *ctx )
 
674
{
 
675
    sha4_hmac_reset( (sha4_context *) ctx );
 
676
}
 
677
 
 
678
void sha512_hmac_wrap( const unsigned char *key, size_t keylen,
 
679
        const unsigned char *input, size_t ilen,
 
680
        unsigned char *output )
 
681
{
 
682
    sha4_hmac( key, keylen, input, ilen, output, 0 );
 
683
}
 
684
 
 
685
void * sha512_ctx_alloc( void )
 
686
{
 
687
    return malloc( sizeof( sha4_context ) );
 
688
}
 
689
 
 
690
void sha512_ctx_free( void *ctx )
 
691
{
 
692
    free( ctx );
 
693
}
 
694
 
 
695
const md_info_t sha512_info = {
 
696
    POLARSSL_MD_SHA512,
 
697
    "SHA512",
 
698
    64,
 
699
    sha512_starts_wrap,
 
700
    sha512_update_wrap,
 
701
    sha512_finish_wrap,
 
702
    sha512_wrap,
 
703
    sha512_file_wrap,
 
704
    sha512_hmac_starts_wrap,
 
705
    sha512_hmac_update_wrap,
 
706
    sha512_hmac_finish_wrap,
 
707
    sha512_hmac_reset_wrap,
 
708
    sha512_hmac_wrap,
 
709
    sha512_ctx_alloc,
 
710
    sha512_ctx_free,
 
711
};
 
712
 
 
713
#endif
 
714
 
 
715
#endif