forked from mirkokiefer/LivelyC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LCSHA.c
46 lines (36 loc) · 1.22 KB
/
LCSHA.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
#include "LCSHA.h"
void computeSHA1(unsigned char data[], size_t length, LCByte buffer[]);
struct serializationCookie {
SHA_CTX context;
};
typedef struct serializationCookie* serializationCookieRef;
void createSHAString(LCByte data[], size_t length, char buffer[HASH_LENGTH]) {
LCByte sha[LC_HASH_BYTE_LENGTH];
computeSHA1(data, length, sha);
createHexString(sha, LC_HASH_BYTE_LENGTH, buffer);
}
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
void* createHashContext() {
SHA_CTX *context = malloc(sizeof(SHA_CTX));
if (context) {
SHA1_Init(context);
}
return context;
}
void updateHashContext(void* cookie, LCByte data[], size_t length) {
SHA_CTX *context = (SHA_CTX*)cookie;
SHA1_Update(context, data, length);
}
void finalizeHashContext(void* cookie, char buffer[HASH_LENGTH]) {
SHA_CTX *context = (SHA_CTX*)cookie;
LCByte byteBuffer[LC_HASH_BYTE_LENGTH];
SHA1_Final(byteBuffer, context);
createHexString(byteBuffer, LC_HASH_BYTE_LENGTH, buffer);
}
void computeSHA1(unsigned char data[], size_t length, LCByte buffer[]) {
SHA_CTX context;
SHA1_Init(&context);
SHA1_Update(&context, data, length);
SHA1_Final(buffer, &context);
}
#pragma GCC diagnostic warning "-Wdeprecated-declarations"