forked from contrun/libecc
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsha512.c
84 lines (69 loc) · 2 KB
/
sha512.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
* Copyright (C) 2017 - This file is part of libecc project
*
* Authors:
* Ryad BENADJILA <[email protected]>
* Arnaud EBALARD <[email protected]>
* Jean-Pierre FLORI <[email protected]>
*
* Contributors:
* Nicolas VIVET <[email protected]>
* Karim KHALFALLAH <[email protected]>
*
* This software is licensed under a dual BSD and GPL v2 license.
* See LICENSE file at the root folder of the project.
*/
#include "../lib_ecc_config.h"
#ifdef WITH_HASH_SHA512
#include "sha512.h"
/* Init hash function */
void sha512_init(sha512_context *ctx)
{
MUST_HAVE(ctx != NULL);
ctx->sha512_total[0] = ctx->sha512_total[1] = 0;
ctx->sha512_state[0] = (u64)(0x6A09E667F3BCC908);
ctx->sha512_state[1] = (u64)(0xBB67AE8584CAA73B);
ctx->sha512_state[2] = (u64)(0x3C6EF372FE94F82B);
ctx->sha512_state[3] = (u64)(0xA54FF53A5F1D36F1);
ctx->sha512_state[4] = (u64)(0x510E527FADE682D1);
ctx->sha512_state[5] = (u64)(0x9B05688C2B3E6C1F);
ctx->sha512_state[6] = (u64)(0x1F83D9ABFB41BD6B);
ctx->sha512_state[7] = (u64)(0x5BE0CD19137E2179);
}
/* Update hash function */
void sha512_update(sha512_context *ctx, const u8 *input, u32 ilen)
{
sha512_core_update(ctx, input, ilen);
return;
}
/* Finalize */
void sha512_final(sha512_context *ctx, u8 output[SHA512_DIGEST_SIZE])
{
sha512_core_final(ctx, output, SHA512_DIGEST_SIZE);
return;
}
void sha512_scattered(const u8 **inputs, const u32 *ilens,
u8 output[SHA512_DIGEST_SIZE])
{
sha512_context ctx;
int pos = 0;
sha512_init(&ctx);
while (inputs[pos] != NULL) {
sha512_update(&ctx, inputs[pos], ilens[pos]);
pos += 1;
}
sha512_final(&ctx, output);
}
void sha512(const u8 *input, u32 ilen, u8 output[SHA512_DIGEST_SIZE])
{
sha512_context ctx;
sha512_init(&ctx);
sha512_update(&ctx, input, ilen);
sha512_final(&ctx, output);
}
#else /* WITH_HASH_SHA512 */
/*
* Dummy definition to avoid the empty translation unit ISO C warning
*/
typedef int dummy;
#endif /* WITH_HASH_SHA512 */