-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathimpl_cifra.c
71 lines (61 loc) · 1.38 KB
/
impl_cifra.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
/*
* Copyright (c) 2022 Tino Reichardt <[email protected]>
*/
#include "sha2_impl.h"
#include "cifra/sha2.h"
static int cifra_SHA256_Init(void **ctx)
{
cf_sha256_context *c = malloc(sizeof(cf_sha256_context));
if (!c) exit(111);
*ctx = c;
cf_sha256_init(c);
return 0;
}
static int cifra_SHA256_Update(void *ctx, const void *data, size_t len)
{
cf_sha256_context *c = ctx;
cf_sha256_update(c, data, len);
return 0;
}
static int cifra_SHA256_Final(void *ctx, unsigned char *md)
{
cf_sha256_context *c = ctx;
cf_sha256_digest_final(c, md);
free(ctx);
return 0;
}
const sha2_impl_ops_t sha256_cifra_impl = {
.init = cifra_SHA256_Init,
.update = cifra_SHA256_Update,
.final = cifra_SHA256_Final,
.digest_len = 32,
.name = "sha256-cifra"
};
static int cifra_SHA512_Init(void **ctx)
{
cf_sha512_context *c = malloc(sizeof(cf_sha512_context));
if (!c) exit(111);
*ctx = c;
cf_sha512_init(c);
return 0;
}
static int cifra_SHA512_Update(void *ctx, const void *data, size_t len)
{
cf_sha512_context *c = ctx;
cf_sha512_update(c, data, len);
return 0;
}
static int cifra_SHA512_Final(void *ctx, unsigned char *md)
{
cf_sha512_context *c = ctx;
cf_sha512_digest_final(c, md);
free(ctx);
return 0;
}
const sha2_impl_ops_t sha512_cifra_impl = {
.init = cifra_SHA512_Init,
.update = cifra_SHA512_Update,
.final = cifra_SHA512_Final,
.digest_len = 64,
.name = "sha512-cifra"
};