Fixed code for windows

This commit is contained in:
WolverinDEV 2019-04-10 20:17:38 +02:00
parent 438f6b3f77
commit 5ae5ff880a
4 changed files with 26 additions and 20 deletions

View File

@ -18,11 +18,12 @@ set(SOURCE
src/verify.c src/verify.c
) )
set(USE_OPENSSL OFF)
if(USE_OPENSSL) if(USE_OPENSSL)
add_definitions(-DUSE_OPENSSL) add_definitions(-DUSE_OPENSSL)
set(SOURCE ${SOURCE} src/sha512_openssl.c) set(SOURCE ${SOURCE} src/sha512_openssl.c)
else() else()
message(FATAL_ERROR "Not supported yet!") # message(FATAL_ERROR "Not supported yet!")
set(SOURCE ${SOURCE} src/sha512.c) set(SOURCE ${SOURCE} src/sha512.c)
endif() endif()

View File

@ -1,4 +1,3 @@
#include <memory.h>
#include "../include/ge.h" #include "../include/ge.h"
#include "../include/precomp_data.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) { 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_tobytes(buffer, p);
ge_frombytes_negate_vartime(r, buffer); ge_frombytes_negate_vartime(r, buffer);
} }

View File

@ -8,7 +8,7 @@
* *
* Tom St Denis, tomstdenis@gmail.com, http://libtom.org * Tom St Denis, tomstdenis@gmail.com, http://libtom.org
*/ */
#include <stdlib.h>
#include "../include/fixedint.h" #include "../include/fixedint.h"
#include "../include/sha512.h" #include "../include/sha512.h"
@ -17,7 +17,7 @@ typedef struct sha512_context_ {
uint64_t length, state[8]; uint64_t length, state[8];
size_t curlen; size_t curlen;
unsigned char buf[128]; unsigned char buf[128];
} sha512_context; } sha512_internal_context;
/* the K array */ /* the K array */
static const uint64_t K[80] = { static const uint64_t K[80] = {
@ -95,7 +95,7 @@ static const uint64_t K[80] = {
#endif #endif
/* compress 1024-bits */ /* 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; uint64_t S[8], W[80], t0, t1;
int i; 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 @param md The hash state you wish to initialize
@return 0 if successful @return 0 if successful
*/ */
int _ed_sha512_init(sha512_context *md) { int _ed_sha512_init(sha512_internal_context *md) {
if (md == NULL) return 1; if (md == NULL) return 1;
md->curlen = 0; md->curlen = 0;
@ -174,7 +174,7 @@ int _ed_sha512_init(sha512_context *md) {
@param inlen The length of the data (octets) @param inlen The length of the data (octets)
@return 0 if successful @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 n;
size_t i; size_t i;
int err; 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) @param out [out] The destination of the hash (64 bytes)
@return 0 if successful @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; int i;
if (md == NULL) return 1; if (md == NULL) return 1;
@ -268,17 +268,23 @@ int _ed_sha512_final(sha512_context *md, unsigned char *out) {
return 0; return 0;
} }
int _ed_sha512(const unsigned char *message, size_t message_len, unsigned char *out) { int __ed_sha512_final(sha512_context *md, unsigned char *out) {
sha512_context ctx; auto result = _ed_sha512_final(md->context, out);
int ret; free(md->context);
if ((ret = _ed_sha512_init(&ctx))) return ret; return result;
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_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 = { sha512_functions _ed_sha512_functions = {
_ed_sha512_init, __ed_sha512_init,
_ed_sha512_final, __ed_sha512_final,
_ed_sha512_update __ed_sha512_update
}; };

2
test.c
View File

@ -21,7 +21,7 @@ int main() {
int i; int i;
const unsigned char message[] = "Hello, world!"; 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 */ /* create a random seed, and a keypair out of that seed */
ed25519_create_seed(seed); ed25519_create_seed(seed);