Browse Source

possibly the eBAT actually works now?

master
Mike Hamburg 10 years ago
parent
commit
c28723f699
5 changed files with 40 additions and 104 deletions
  1. +2
    -1
      Makefile
  2. +29
    -101
      src/include/api.h
  3. +3
    -1
      src/include/word.h
  4. +2
    -1
      src/scalarmul.c
  5. +4
    -0
      test/bench.c

+ 2
- 1
Makefile View File

@@ -68,7 +68,7 @@ TESTCOMPONENTS=build/test.o build/test_scalarmul.o build/test_sha512.o \

BENCHCOMPONENTS=build/bench.o

BATNAME=build/ed448-goldilocks
BATNAME=build/ed448goldilocks

all: lib build/test build/bench

@@ -128,6 +128,7 @@ $(BATNAME): include/* src/* src/*/*
mkdir -p $@/`basename $$arch`; \
cp include/* src/*.c src/include/* $$arch/* $@/`basename $$arch`; \
perl -p -i -e 's/.*endif.*GOLDILOCKS_CONFIG_H/#define SUPERCOP_WONT_LET_ME_OPEN_FILES 1\n\n$$&/' $@/`basename $$arch`/config.h; \
perl -p -i -e 's/SYSNAME/'`basename $(BATNAME)`_`basename $$arch`'/g' $@/`basename $$arch`/api.h; \
done
echo 'Mike Hamburg' > $@/designers
echo 'Ed448-Goldilocks sign and dh' > $@/description


+ 29
- 101
src/include/api.h View File

@@ -8,6 +8,7 @@
*/

#include <string.h>
#include <stdlib.h>
#include "goldilocks.h"

#define PUBLICKEY_BYTES GOLDI_PUBLIC_KEY_BYTES
@@ -15,18 +16,24 @@
#define SIGNATURE_BYTES GOLDI_SIGNATURE_BYTES
#define SHAREDSECRET_BYTES GOLDI_SHARED_SECRET_BYTES

#define crypto_dh_PUBLICKEYBYTES PUBLICKEY_BYTES
#define crypto_dh_SECRETKEYBYTES SECRETKEY_BYTES
#define crypto_dh_SYSNAME_PUBLICKEYBYTES PUBLICKEY_BYTES
#define crypto_dh_SYSNAME_SECRETKEYBYTES SECRETKEY_BYTES
#define PRIVATEKEY_BYTES SECRETKEY_BYTES
#define crypto_dh_BYTES SHAREDSECRET_BYTES
#define crypto_dh_IMPLEMENTATION "AMD64"
#define crypto_dh_VERSION "2014-07-11"

#define crypto_sign_PUBLICKEYBYTES PUBLICKEY_BYTES
#define crypto_sign_SECRETKEYBYTES SECRETKEY_BYTES
#define crypto_sign_IMPLEMENTATION "AMD64"
#define crypto_sign_VERSION "2014-07-11"
#define crypto_sign_BYTES SIGNATURE_BYTES
#define crypto_dh_SYSNAME_BYTES SHAREDSECRET_BYTES
#define crypto_dh_SYSNAME_IMPLEMENTATION "AMD64"
#define crypto_dh_SYSNAME_VERSION "2014-07-11"

#define crypto_sign_SYSNAME_PUBLICKEYBYTES PUBLICKEY_BYTES
#define crypto_sign_SYSNAME_SECRETKEYBYTES SECRETKEY_BYTES
#define crypto_sign_SYSNAME_IMPLEMENTATION "AMD64"
#define crypto_sign_SYSNAME_VERSION "2014-07-11"
#define crypto_sign_SYSNAME_BYTES SIGNATURE_BYTES

#define crypto_dh_SYSNAME_keypair crypto_dh_keypair
#define crypto_dh_SYSNAME crypto_dh
#define crypto_sign_SYSNAME_keypair crypto_dh_keypair
#define crypto_sign_SYSNAME crypto_sign
#define crypto_sign_SYSNAME_open crypto_sign_open

#define CRYPTO_DETERMINISTIC 1

@@ -44,7 +51,6 @@ static inline int patentclaims() {
return 20;
}

#define crypto_sign_keypair crypto_dh_keypair
static inline int crypto_dh_keypair (
unsigned char pk[SECRETKEY_BYTES],
unsigned char sk[PUBLICKEY_BYTES]
@@ -60,25 +66,6 @@ static inline int crypto_dh_keypair (
return ret;
}

static inline void keypair (
unsigned char sk[SECRETKEY_BYTES],
unsigned long long *sklen,
unsigned char pk[PUBLICKEY_BYTES],
unsigned long long *pklen
) {
int ret = goldilocks_init();
if (ret) abort();

ret = goldilocks_keygen(
(struct goldilocks_private_key_t *)sk,
(struct goldilocks_public_key_t *)pk
);
if (ret) abort();

*sklen = SECRETKEY_BYTES;
*pklen = PUBLICKEY_BYTES;
}

static inline int crypto_sign (
unsigned char *sm,
unsigned long long *smlen,
@@ -86,37 +73,17 @@ static inline int crypto_sign (
unsigned long long mlen,
const unsigned char sk[SECRETKEY_BYTES]
) {
unsigned char sig[SIGNATURE_BYTES];
int ret = goldilocks_sign(
sm, m, mlen,
(const struct goldilocks_private_key_t *)sk
);
if (ret) abort();

memcpy(sm + SIGNATURE_BYTES, m, mlen);
*smlen = mlen + SIGNATURE_BYTES;
return 0;
}

static inline void signmessage (
unsigned char *sm,
unsigned long long *smlen,
const unsigned char *m,
unsigned long long mlen,
const unsigned char sk[SECRETKEY_BYTES],
unsigned long long sklen
) {
if (sklen != PRIVATEKEY_BYTES) abort();
int ret = goldilocks_sign(
sm, m, mlen,
sig, m, mlen,
(const struct goldilocks_private_key_t *)sk
);
if (ret) abort();

memcpy(sm + SIGNATURE_BYTES, m, mlen);
*smlen = mlen + SIGNATURE_BYTES;
if (!ret) {
memmove(sm + SIGNATURE_BYTES, m, mlen);
memcpy(sm, sig, SIGNATURE_BYTES);
*smlen = mlen + SIGNATURE_BYTES;
}
return ret ? -1 : 0;
}

static inline int crypto_sign_open (
@@ -132,33 +99,15 @@ static inline int crypto_sign_open (
);
if (!ret) {
*mlen = smlen - SIGNATURE_BYTES;
memcpy(m, sm + SIGNATURE_BYTES, *mlen);
memmove(m, sm + SIGNATURE_BYTES, *mlen);
}
return ret ? -1 : 0;
}

static inline int verification (
const unsigned char *m,
unsigned long long mlen,
const unsigned char *sm,
unsigned long long smlen,
const unsigned char pk[PUBLICKEY_BYTES],
unsigned long long pklen
) {
if (pklen != PUBLICKEY_BYTES) abort();
int ret = goldilocks_verify(
sm, m, mlen,
(const struct goldilocks_public_key_t *)pk
);
return ret ? -1 : 0;
}


static inline int crypto_dh (
unsigned char s[SHAREDSECRET_BYTES],
const unsigned char sk[SECRETKEY_BYTES],
const unsigned char pk[PUBLICKEY_BYTES]
const unsigned char pk[PUBLICKEY_BYTES],
const unsigned char sk[SECRETKEY_BYTES]
) {
return goldilocks_shared_secret (
s,
@@ -167,24 +116,3 @@ static inline int crypto_dh (
);
}

static inline int sharedsecret (
unsigned char s[SHAREDSECRET_BYTES],
unsigned long long *slen,
const unsigned char sk[SECRETKEY_BYTES],
unsigned long long sklen,
const unsigned char pk[PUBLICKEY_BYTES],
unsigned long long pklen
) {
if (pklen != PUBLICKEY_BYTES) abort();
if (sklen != SECRETKEY_BYTES) abort();
int ret = goldilocks_shared_secret (
s,
(const struct goldilocks_private_key_t *)sk,
(const struct goldilocks_public_key_t *)pk
);
if (ret) return -1;
*slen = SHAREDSECRET_BYTES;
return 0;
}


+ 3
- 1
src/include/word.h View File

@@ -9,7 +9,9 @@
#define _XOPEN_SOURCE 600

#ifndef __APPLE__
#define _BSD_SOURCE
#ifndef _BSD_SOURCE
#define _BSD_SOURCE 1
#endif
#include <endian.h>
#endif



+ 2
- 1
src/scalarmul.c View File

@@ -752,6 +752,7 @@ prepare_wnaf_table(
struct tw_extensible_t *working,
unsigned int tbits
) {
int i;
convert_tw_extensible_to_tw_pniels(&output[0], working);

if (tbits == 0) return;
@@ -763,7 +764,7 @@ prepare_wnaf_table(
add_tw_pniels_to_tw_extensible(working, &output[0]);
convert_tw_extensible_to_tw_pniels(&output[1], working);

for (int i=2; i < 1<<tbits; i++) {
for (i=2; i < 1<<tbits; i++) {
add_tw_pniels_to_tw_extensible(working, &twop);
convert_tw_extensible_to_tw_pniels(&output[i], working);
}


+ 4
- 0
test/bench.c View File

@@ -552,6 +552,7 @@ int main(int argc, char **argv) {
when = now();
for (i=0; i<nbase; i++) {
res = goldilocks_sign(sout,(const unsigned char *)message,message_len,&gsk);
(void)res;
assert(!res);
}
when = now() - when;
@@ -560,6 +561,7 @@ int main(int argc, char **argv) {
when = now();
for (i=0; i<nbase; i++) {
int ver = goldilocks_verify(sout,(const unsigned char *)message,message_len,&gpk);
(void)ver;
assert(!ver);
}
when = now() - when;
@@ -577,6 +579,7 @@ int main(int argc, char **argv) {
when = now();
for (i=0; i<nbase; i++) {
int ver = goldilocks_verify_precomputed(sout,(const unsigned char *)message,message_len,pre);
(void)ver;
assert(!ver);
}
when = now() - when;
@@ -585,6 +588,7 @@ int main(int argc, char **argv) {
when = now();
for (i=0; i<nbase; i++) {
int ret = goldilocks_shared_secret_precomputed(ss1,&gsk,pre);
(void)ret;
assert(!ret);
}
when = now() - when;


Loading…
Cancel
Save