Changed the SHA512 context system
This commit is contained in:
parent
fc8ade72c5
commit
f810597c6c
@ -22,6 +22,7 @@ if(USE_OPENSSL)
|
||||
add_definitions(-DUSE_OPENSSL)
|
||||
set(SOURCE ${SOURCE} src/sha512_openssl.c)
|
||||
else()
|
||||
message(FATAL_ERROR "Not supported yet!")
|
||||
set(SOURCE ${SOURCE} src/sha512.c)
|
||||
endif()
|
||||
|
||||
|
@ -3,22 +3,9 @@
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#ifdef USE_OPENSSL
|
||||
#include <openssl/sha.h>
|
||||
|
||||
typedef SHA512_CTX sha512_context;
|
||||
#else
|
||||
#include <stddef.h>
|
||||
|
||||
#include "fixedint.h"
|
||||
|
||||
/* state */
|
||||
typedef struct sha512_context_ {
|
||||
uint64_t length, state[8];
|
||||
size_t curlen;
|
||||
unsigned char buf[128];
|
||||
} sha512_context;
|
||||
#endif
|
||||
typedef struct {
|
||||
void* context;
|
||||
} sha512_context;
|
||||
|
||||
typedef struct sha512_functions_ {
|
||||
int(*_ed_sha512_init)(sha512_context*);
|
||||
|
@ -12,6 +12,13 @@
|
||||
#include "../include/fixedint.h"
|
||||
#include "../include/sha512.h"
|
||||
|
||||
/* state */
|
||||
typedef struct sha512_context_ {
|
||||
uint64_t length, state[8];
|
||||
size_t curlen;
|
||||
unsigned char buf[128];
|
||||
} sha512_context;
|
||||
|
||||
/* the K array */
|
||||
static const uint64_t K[80] = {
|
||||
UINT64_C(0x428a2f98d728ae22), UINT64_C(0x7137449123ef65cd),
|
||||
|
@ -1,17 +1,28 @@
|
||||
#include <openssl/sha.h>
|
||||
#include <stdlib.h>
|
||||
#include "../include/sha512.h"
|
||||
|
||||
|
||||
int _ed_sha512_init(sha512_context * md) {
|
||||
return SHA512_Init(md) != 1; /* Returns 0 on success */
|
||||
int _ed_sha512_init(sha512_context* md) {
|
||||
assert(!md->context);
|
||||
|
||||
md->context = malloc(sizeof(SHA512_CTX));
|
||||
return SHA512_Init(md->context) != 1; /* Returns 0 on success */
|
||||
}
|
||||
|
||||
int _ed_sha512_final(sha512_context * md, unsigned char *out) {
|
||||
return SHA512_Final(out, md) != 1; /* Returns 0 on success */
|
||||
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;
|
||||
}
|
||||
|
||||
int _ed_sha512_update(sha512_context * md, const unsigned char *in, size_t inlen) {
|
||||
return SHA512_Update(md, in, inlen) != 1; /* Returns 0 on success */
|
||||
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 */
|
||||
}
|
||||
|
||||
sha512_functions _ed_sha512_functions = {
|
||||
|
Loading…
Reference in New Issue
Block a user