ed25519/src/sha512_openssl.c

34 lines
787 B
C
Raw Normal View History

2018-04-24 12:33:55 -04:00
#include <openssl/sha.h>
2019-04-07 11:05:16 -04:00
#include <stdlib.h>
2018-04-24 12:33:55 -04:00
#include "../include/sha512.h"
2019-04-07 11:05:16 -04:00
int _ed_sha512_init(sha512_context* md) {
md->context = malloc(sizeof(SHA512_CTX));
return SHA512_Init(md->context) != 1; /* Returns 0 on success */
2018-04-24 12:33:55 -04:00
}
2019-04-07 11:05:16 -04:00
int _ed_sha512_final(sha512_context* md, unsigned char *out) {
assert(md->context);
int result = SHA512_Final(out, md->context) != 1; /* Returns 0 on success */
free(md->context);
md->context = 0;
return result;
2018-04-24 12:33:55 -04:00
}
2019-04-07 11:05:16 -04:00
int _ed_sha512_update(sha512_context* md, const unsigned char *in, size_t inlen) {
assert(md->context);
return SHA512_Update(md->context, in, inlen) != 1; /* Returns 0 on success */
2018-04-24 12:33:55 -04:00
}
#ifdef WIN32
__declspec(dllexport)
#endif
2019-04-07 10:59:49 -04:00
sha512_functions _ed_sha512_functions = {
_ed_sha512_init,
_ed_sha512_final,
_ed_sha512_update
};