From 5ae5ff880a1c24176f7445cabec8f45f86263fd6 Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Wed, 10 Apr 2019 20:17:38 +0200 Subject: [PATCH] Fixed code for windows --- CMakeLists.txt | 3 ++- src/ge.c | 3 +-- src/sha512.c | 38 ++++++++++++++++++++++---------------- test.c | 2 +- 4 files changed, 26 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 71c48d5..f9e3b3a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,11 +18,12 @@ set(SOURCE src/verify.c ) +set(USE_OPENSSL OFF) if(USE_OPENSSL) add_definitions(-DUSE_OPENSSL) set(SOURCE ${SOURCE} src/sha512_openssl.c) else() - message(FATAL_ERROR "Not supported yet!") +# message(FATAL_ERROR "Not supported yet!") set(SOURCE ${SOURCE} src/sha512.c) endif() diff --git a/src/ge.c b/src/ge.c index be6c27a..7d5e749 100644 --- a/src/ge.c +++ b/src/ge.c @@ -1,4 +1,3 @@ -#include #include "../include/ge.h" #include "../include/precomp_data.h" @@ -328,7 +327,7 @@ void ge_p3_to_p2(ge_p2 *r, const ge_p3 *p) { } void ge_p2_to_p3(ge_p3 *r, const ge_p2 *p) { - uint8_t buffer[32]; + unsigned char buffer[32]; ge_tobytes(buffer, p); ge_frombytes_negate_vartime(r, buffer); } diff --git a/src/sha512.c b/src/sha512.c index 7440e78..0d33ce8 100644 --- a/src/sha512.c +++ b/src/sha512.c @@ -8,7 +8,7 @@ * * Tom St Denis, tomstdenis@gmail.com, http://libtom.org */ - +#include #include "../include/fixedint.h" #include "../include/sha512.h" @@ -17,7 +17,7 @@ typedef struct sha512_context_ { uint64_t length, state[8]; size_t curlen; unsigned char buf[128]; -} sha512_context; +} sha512_internal_context; /* the K array */ static const uint64_t K[80] = { @@ -95,7 +95,7 @@ static const uint64_t K[80] = { #endif /* compress 1024-bits */ -static int _ed_sha512_compress(sha512_context *md, unsigned char *buf) { +static int _ed_sha512_compress(sha512_internal_context *md, unsigned char *buf) { uint64_t S[8], W[80], t0, t1; int i; @@ -150,7 +150,7 @@ static int _ed_sha512_compress(sha512_context *md, unsigned char *buf) { @param md The hash state you wish to initialize @return 0 if successful */ -int _ed_sha512_init(sha512_context *md) { +int _ed_sha512_init(sha512_internal_context *md) { if (md == NULL) return 1; md->curlen = 0; @@ -174,7 +174,7 @@ int _ed_sha512_init(sha512_context *md) { @param inlen The length of the data (octets) @return 0 if successful */ -int _ed_sha512_update(sha512_context *md, const unsigned char *in, size_t inlen) { +int _ed_sha512_update(sha512_internal_context *md, const unsigned char *in, size_t inlen) { size_t n; size_t i; int err; @@ -220,7 +220,7 @@ int _ed_sha512_update(sha512_context *md, const unsigned char *in, size_t inlen) @param out [out] The destination of the hash (64 bytes) @return 0 if successful */ -int _ed_sha512_final(sha512_context *md, unsigned char *out) { +int _ed_sha512_final(sha512_internal_context *md, unsigned char *out) { int i; if (md == NULL) return 1; @@ -268,17 +268,23 @@ int _ed_sha512_final(sha512_context *md, unsigned char *out) { return 0; } -int _ed_sha512(const unsigned char *message, size_t message_len, unsigned char *out) { - sha512_context ctx; - int ret; - if ((ret = _ed_sha512_init(&ctx))) return ret; - if ((ret = _ed_sha512_update(&ctx, message, message_len))) return ret; - if ((ret = _ed_sha512_final(&ctx, out))) return ret; - return 0; +int __ed_sha512_final(sha512_context *md, unsigned char *out) { + auto result = _ed_sha512_final(md->context, out); + free(md->context); + return result; +} + +int __ed_sha512_init(sha512_context *md) { + md->context = malloc(sizeof(sha512_internal_context)); + return _ed_sha512_init(md->context); +} + +int __ed_sha512_update(sha512_context *md, const unsigned char *in, size_t inlen) { + return _ed_sha512_update(md->context, in, inlen); } sha512_functions _ed_sha512_functions = { - _ed_sha512_init, - _ed_sha512_final, - _ed_sha512_update + __ed_sha512_init, + __ed_sha512_final, + __ed_sha512_update }; \ No newline at end of file diff --git a/test.c b/test.c index dd7195f..a601d58 100644 --- a/test.c +++ b/test.c @@ -21,7 +21,7 @@ int main() { int i; const unsigned char message[] = "Hello, world!"; - const int message_len = strlen((char*) message); + const size_t message_len = strlen((char*) message); /* create a random seed, and a keypair out of that seed */ ed25519_create_seed(seed);