-
Notifications
You must be signed in to change notification settings - Fork 1
/
impl_openssl.c
68 lines (57 loc) · 1.32 KB
/
impl_openssl.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
/*
* Copyright (c) 2022 Tino Reichardt <[email protected]>
*/
#include "sha2_impl.h"
#include <openssl/sha.h>
static int openssl_SHA256_Init(void **ctx)
{
SHA256_CTX *c = malloc(sizeof(SHA256_CTX));
if (!c) exit(111);
*ctx = c;
return SHA256_Init(c);
}
static int openssl_SHA256_Update(void *ctx, const void *data, size_t len)
{
SHA256_CTX *c = ctx;
return SHA256_Update(c, data, len);
}
static int openssl_SHA256_Final(void *ctx, unsigned char *md)
{
SHA256_CTX *c = ctx;
int r = SHA256_Final(md, c);
free(ctx);
return r;
}
const sha2_impl_ops_t sha256_openssl_impl = {
.init = openssl_SHA256_Init,
.update = openssl_SHA256_Update,
.final = openssl_SHA256_Final,
.digest_len = 32,
.name = "sha256-openssl"
};
static int openssl_SHA512_Init(void **ctx)
{
SHA512_CTX *c = malloc(sizeof(SHA512_CTX));
if (!c) exit(111);
*ctx = c;
return SHA512_Init(c);
}
static int openssl_SHA512_Update(void *ctx, const void *data, size_t len)
{
SHA512_CTX *c = ctx;
return SHA512_Update(c, data, len);
}
static int openssl_SHA512_Final(void *ctx, unsigned char *md)
{
SHA512_CTX *c = ctx;
int r = SHA512_Final(md, c);
free(ctx);
return r;
}
const sha2_impl_ops_t sha512_openssl_impl = {
.init = openssl_SHA512_Init,
.update = openssl_SHA512_Update,
.final = openssl_SHA512_Final,
.digest_len = 64,
.name = "sha512-openssl"
};