removed last stdlib dependency

This commit is contained in:
Orson Peters 2013-01-21 22:50:09 +01:00
parent ad89d029ed
commit 841d4981bc
10 changed files with 27 additions and 15 deletions

View File

@ -1,8 +1,10 @@
#ifndef ED25519_H #ifndef ED25519_H
#define ED25519_H #define ED25519_H
int ed25519_sign(unsigned char *signature, const unsigned char *message, unsigned int message_len, const unsigned char *sign_key); #include <stddef.h>
int ed25519_verify(const unsigned char *signature, const unsigned char *message, unsigned int message_len, const unsigned char *verify_key);
int ed25519_sign(unsigned char *signature, const unsigned char *message, size_t message_len, const unsigned char *sign_key);
int ed25519_verify(const unsigned char *signature, const unsigned char *message, size_t message_len, const unsigned char *verify_key);
int ed25519_create_keypair(unsigned char *verify_key, unsigned char *sign_key, unsigned char *seed); int ed25519_create_keypair(unsigned char *verify_key, unsigned char *sign_key, unsigned char *seed);
#ifndef ED25519_NO_SEED #ifndef ED25519_NO_SEED

View File

@ -1,5 +1,4 @@
#include "fixedint.h" #include "fixedint.h"
#include "fe.h" #include "fe.h"

View File

@ -1,6 +1,5 @@
#include "ge.h" #include "ge.h"
#include "precomp_data.h"
#include "base_precomp_data.h"
/* /*

View File

@ -1,6 +1,9 @@
#ifndef GE_H #ifndef GE_H
#define GE_H #define GE_H
#include "fe.h"
/* /*
ge means group element. ge means group element.
@ -15,8 +18,6 @@ Representations:
ge_precomp (Duif): (y+x,y-x,2dxy) ge_precomp (Duif): (y+x,y-x,2dxy)
*/ */
#include "fe.h"
typedef struct { typedef struct {
fe X; fe X;
fe Y; fe Y;

View File

@ -1,5 +1,5 @@
#include "sc.h"
#include "fixedint.h" #include "fixedint.h"
#include "sc.h"
static uint64_t load_3(const unsigned char *in) { static uint64_t load_3(const unsigned char *in) {
uint64_t result; uint64_t result;

Binary file not shown.

View File

@ -9,8 +9,6 @@
* Tom St Denis, tomstdenis@gmail.com, http://libtom.org * Tom St Denis, tomstdenis@gmail.com, http://libtom.org
*/ */
#include <string.h>
#include "fixedint.h" #include "fixedint.h"
#include "sha512.h" #include "sha512.h"
@ -171,6 +169,7 @@ return 0;
int sha512_update (sha512_context * md, const unsigned char *in, size_t inlen) int sha512_update (sha512_context * md, const unsigned char *in, size_t inlen)
{ {
size_t n; size_t n;
size_t i;
int err; int err;
if (md == NULL) return 1; if (md == NULL) return 1;
if (in == NULL) return 1; if (in == NULL) return 1;
@ -187,7 +186,12 @@ int sha512_update (sha512_context * md, const unsigned char *in, size_t inlen)
inlen -= 128; inlen -= 128;
} else { } else {
n = MIN(inlen, (128 - md->curlen)); n = MIN(inlen, (128 - md->curlen));
memcpy(md->buf + md->curlen, in, (size_t)n);
for (i = 0; i < n; i++) {
md->buf[i + md->curlen] = in[i];
}
md->curlen += n; md->curlen += n;
in += n; in += n;
inlen -= n; inlen -= n;

View File

@ -4,29 +4,35 @@
#include "sc.h" #include "sc.h"
int ed25519_sign(unsigned char *signature, const unsigned char *message, unsigned int message_len, const unsigned char *sign_key) { int ed25519_sign(unsigned char *signature, const unsigned char *message, size_t message_len, const unsigned char *sign_key) {
unsigned char az[64]; unsigned char az[64];
unsigned char r[64]; unsigned char r[64];
unsigned char hram[64]; unsigned char hram[64];
ge_p3 R; ge_p3 R;
sha512_context hash; sha512_context hash;
sha512(sign_key, 32, az); sha512(sign_key, 32, az);
az[0] &= 248; az[0] &= 248;
az[31] &= 63; az[31] &= 63;
az[31] |= 64; az[31] |= 64;
sha512_init(&hash); sha512_init(&hash);
sha512_update(&hash, az + 32, 32); sha512_update(&hash, az + 32, 32);
sha512_update(&hash, message, message_len); sha512_update(&hash, message, message_len);
sha512_final(&hash, r); sha512_final(&hash, r);
sc_reduce(r); sc_reduce(r);
ge_scalarmult_base(&R, r); ge_scalarmult_base(&R, r);
ge_p3_tobytes(signature, &R); ge_p3_tobytes(signature, &R);
sha512_init(&hash); sha512_init(&hash);
sha512_update(&hash, signature, 32); sha512_update(&hash, signature, 32);
sha512_update(&hash, sign_key + 32, 32); sha512_update(&hash, sign_key + 32, 32);
sha512_update(&hash, message, message_len); sha512_update(&hash, message, message_len);
sha512_final(&hash, hram); sha512_final(&hash, hram);
sc_reduce(hram); sc_reduce(hram);
sc_muladd(signature + 32, hram, az, r); sc_muladd(signature + 32, hram, az, r);
return 0; return 0;
} }

View File

@ -44,7 +44,7 @@ static int consttime_equal(const unsigned char *x, const unsigned char *y) {
return !r; return !r;
} }
int ed25519_verify(const unsigned char *signature, const unsigned char *message, unsigned int message_len, const unsigned char *verify_key) { int ed25519_verify(const unsigned char *signature, const unsigned char *message, size_t message_len, const unsigned char *verify_key) {
unsigned char h[64]; unsigned char h[64];
unsigned char checker[32]; unsigned char checker[32];
sha512_context hash; sha512_context hash;
@ -64,6 +64,7 @@ int ed25519_verify(const unsigned char *signature, const unsigned char *message,
sha512_update(&hash, verify_key, 32); sha512_update(&hash, verify_key, 32);
sha512_update(&hash, message, message_len); sha512_update(&hash, message, message_len);
sha512_final(&hash, h); sha512_final(&hash, h);
sc_reduce(h); sc_reduce(h);
ge_double_scalarmult_vartime(&R, h, &A, signature + 32); ge_double_scalarmult_vartime(&R, h, &A, signature + 32);
ge_tobytes(checker, &R); ge_tobytes(checker, &R);