Commit 6225bfd2 authored by Michael Hamburg's avatar Michael Hamburg

EdDSA is go!

parent 1f716044
......@@ -294,6 +294,12 @@ static void cfrg() {
FixedArrayBuffer<Group::DhLadder::PRIVATE_BYTES> s1(rng);
for (Benchmark b("RFC 7748 keygen"); b.iter(); ) { Group::DhLadder::generate_key(s1); }
for (Benchmark b("RFC 7748 shared secret"); b.iter(); ) { Group::DhLadder::shared_secret(base,s1); }
FixedArrayBuffer<Group::EdDSA::PRIVATE_BYTES> e1(rng);
SecureBuffer pk, sig;
for (Benchmark b("EdDSA keygen"); b.iter(); ) { pk = Group::EdDSA::generate_key(e1); }
for (Benchmark b("EdDSA sign"); b.iter(); ) { sig = Group::EdDSA::sign(e1,pk,Block(NULL,0)); }
for (Benchmark b("EdDSA verify"); b.iter(); ) { Group::EdDSA::verify(sig,pk,Block(NULL,0)); }
}
static void macro() {
......
......@@ -466,7 +466,7 @@ static void test_cfrg_crypto() {
}
}
static const Block eddsa_sk, eddsa_pk, eddsa_sig0;
static const Block eddsa_sk[], eddsa_pk[], eddsa_message[], eddsa_context[], eddsa_sig[];
static void test_cfrg_vectors() {
Test test("CFRG test vectors");
......@@ -476,25 +476,30 @@ static void test_cfrg_vectors() {
int the_ntests = (NTESTS < 1000000) ? 1000 : 1000000;
/* EdDSA */
if (eddsa_sk.size()) {
SecureBuffer eddsa_pk2 = EdDSA::generate_key(eddsa_sk);
if (!memeq(SecureBuffer(eddsa_pk), eddsa_pk2)) {
for (unsigned int t=0; eddsa_sk[t].size(); t++) {
SecureBuffer eddsa_pk2 = EdDSA::generate_key(eddsa_sk[t]);
if (!memeq(SecureBuffer(eddsa_pk[t]), eddsa_pk2)) {
test.fail();
printf(" EdDSA PK vectors disagree.");
printf("\n Correct: ");
for (unsigned i=0; i<eddsa_pk.size(); i++) printf("%02x", eddsa_pk[i]);
for (unsigned i=0; i<eddsa_pk[t].size(); i++) printf("%02x", eddsa_pk[t][i]);
printf("\n Incorrect: ");
for (unsigned i=0; i<eddsa_pk2.size(); i++) printf("%02x", eddsa_pk2[i]);
printf("\n");
}
SecureBuffer sig = EdDSA::sign(eddsa_sk,eddsa_pk,Block(NULL,0));
SecureBuffer sig;
if (EdDSA::SUPPORTS_CONTEXTS) {
sig = EdDSA::sign(eddsa_sk[t],eddsa_pk[t],eddsa_message[t],false,eddsa_context[t]);
} else {
sig = EdDSA::sign(eddsa_sk[t],eddsa_pk[t],eddsa_message[t]);
}
if (!memeq(SecureBuffer(eddsa_sig0),sig)) {
if (!memeq(SecureBuffer(eddsa_sig[t]),sig)) {
test.fail();
printf(" EdDSA sig vectors disagree.");
printf("\n Correct: ");
for (unsigned i=0; i<eddsa_sig0.size(); i++) printf("%02x", eddsa_sig0[i]);
for (unsigned i=0; i<eddsa_sig[t].size(); i++) printf("%02x", eddsa_sig[t][i]);
printf("\n Incorrect: ");
for (unsigned i=0; i<sig.size(); i++) printf("%02x", sig[i]);
......@@ -566,155 +571,10 @@ static void run() {
}; /* template<GroupId GROUP> struct Tests */
/* X25519, X448 test vectors */
template<> const uint8_t Tests<IsoEd25519>::rfc7748_1[32] = {
0x42,0x2c,0x8e,0x7a,0x62,0x27,0xd7,0xbc,
0xa1,0x35,0x0b,0x3e,0x2b,0xb7,0x27,0x9f,
0x78,0x97,0xb8,0x7b,0xb6,0x85,0x4b,0x78,
0x3c,0x60,0xe8,0x03,0x11,0xae,0x30,0x79
};
template<> const uint8_t Tests<IsoEd25519>::rfc7748_1000[32] = {
0x68,0x4c,0xf5,0x9b,0xa8,0x33,0x09,0x55,
0x28,0x00,0xef,0x56,0x6f,0x2f,0x4d,0x3c,
0x1c,0x38,0x87,0xc4,0x93,0x60,0xe3,0x87,
0x5f,0x2e,0xb9,0x4d,0x99,0x53,0x2c,0x51
};
template<> const uint8_t Tests<IsoEd25519>::rfc7748_1000000[32] = {
0x7c,0x39,0x11,0xe0,0xab,0x25,0x86,0xfd,
0x86,0x44,0x97,0x29,0x7e,0x57,0x5e,0x6f,
0x3b,0xc6,0x01,0xc0,0x88,0x3c,0x30,0xdf,
0x5f,0x4d,0xd2,0xd2,0x4f,0x66,0x54,0x24
};
template<> const uint8_t Tests<Ed448Goldilocks>::rfc7748_1[56] = {
0x3f,0x48,0x2c,0x8a,0x9f,0x19,0xb0,0x1e,
0x6c,0x46,0xee,0x97,0x11,0xd9,0xdc,0x14,
0xfd,0x4b,0xf6,0x7a,0xf3,0x07,0x65,0xc2,
0xae,0x2b,0x84,0x6a,0x4d,0x23,0xa8,0xcd,
0x0d,0xb8,0x97,0x08,0x62,0x39,0x49,0x2c,
0xaf,0x35,0x0b,0x51,0xf8,0x33,0x86,0x8b,
0x9b,0xc2,0xb3,0xbc,0xa9,0xcf,0x41,0x13
};
template<> const uint8_t Tests<Ed448Goldilocks>::rfc7748_1000[56] = {
0xaa,0x3b,0x47,0x49,0xd5,0x5b,0x9d,0xaf,
0x1e,0x5b,0x00,0x28,0x88,0x26,0xc4,0x67,
0x27,0x4c,0xe3,0xeb,0xbd,0xd5,0xc1,0x7b,
0x97,0x5e,0x09,0xd4,0xaf,0x6c,0x67,0xcf,
0x10,0xd0,0x87,0x20,0x2d,0xb8,0x82,0x86,
0xe2,0xb7,0x9f,0xce,0xea,0x3e,0xc3,0x53,
0xef,0x54,0xfa,0xa2,0x6e,0x21,0x9f,0x38
};
template<> const uint8_t Tests<Ed448Goldilocks>::rfc7748_1000000[56] = {
0x07,0x7f,0x45,0x36,0x81,0xca,0xca,0x36,
0x93,0x19,0x84,0x20,0xbb,0xe5,0x15,0xca,
0xe0,0x00,0x24,0x72,0x51,0x9b,0x3e,0x67,
0x66,0x1a,0x7e,0x89,0xca,0xb9,0x46,0x95,
0xc8,0xf4,0xbc,0xd6,0x6e,0x61,0xb9,0xb9,
0xc9,0x46,0xda,0x8d,0x52,0x4d,0xe3,0xd6,
0x9b,0xd9,0xd9,0xd6,0x6b,0x99,0x7e,0x37
};
template<> const Block Tests<Ed448Goldilocks>::sqrt_minus_one(NULL,0);
const uint8_t sm1_25519[32] = {
0xb0,0xa0,0x0e,0x4a,0x27,0x1b,0xee,0xc4,
0x78,0xe4,0x2f,0xad,0x06,0x18,0x43,0x2f,
0xa7,0xd7,0xfb,0x3d,0x99,0x00,0x4d,0x2b,
0x0b,0xdf,0xc1,0x4f,0x80,0x24,0x83,0x2b
};
template<> const Block Tests<IsoEd25519>::sqrt_minus_one(sm1_25519,32);
template<> const Block Tests<Ed448Goldilocks>::minus_sqrt_minus_one(NULL,0);
const uint8_t msm1_25519[32] = {
0x3d,0x5f,0xf1,0xb5,0xd8,0xe4,0x11,0x3b,
0x87,0x1b,0xd0,0x52,0xf9,0xe7,0xbc,0xd0,
0x58,0x28,0x04,0xc2,0x66,0xff,0xb2,0xd4,
0xf4,0x20,0x3e,0xb0,0x7f,0xdb,0x7c,0x54
};
template<> const Block Tests<IsoEd25519>::minus_sqrt_minus_one(msm1_25519,32);
const uint8_t elli_patho_448[56] = {
0x14,0xf0,0x70,0x58,0x41,0xc7,0xf9,0xa5,
0xfa,0x2c,0x7d,0x87,0x07,0x89,0xe8,0x61,
0x63,0xe8,0xc8,0xdc,0x06,0x2d,0x39,0x8f,
0x18,0x83,0x1e,0xc6,0x8c,0x6d,0x73,0x24,
0xd4,0xb3,0xd3,0xe1,0xf3,0x51,0x8c,0xee,
0x65,0x79,0x88,0xc1,0x0b,0xcf,0x8e,0xa5,
0x86,0xa9,0x2e,0xc9,0x17,0x68,0x9b,0x20
};
template<> const Block Tests<Ed448Goldilocks>::elli_patho(elli_patho_448,56);
template<> const Block Tests<IsoEd25519>::elli_patho(NULL,0);
/* EdDSA test vectors */
const uint8_t ed448_eddsa_sk[57] = {
0x6c,0x82,0xa5,0x62,0xcb,0x80,0x8d,0x10,
0xd6,0x32,0xbe,0x89,0xc8,0x51,0x3e,0xbf,
0x6c,0x92,0x9f,0x34,0xdd,0xfa,0x8c,0x9f,
0x63,0xc9,0x96,0x0e,0xf6,0xe3,0x48,0xa3,
0x52,0x8c,0x8a,0x3f,0xcc,0x2f,0x04,0x4e,
0x39,0xa3,0xfc,0x5b,0x94,0x49,0x2f,0x8f,
0x03,0x2e,0x75,0x49,0xa2,0x00,0x98,0xf9,
0x5b
};
const uint8_t ed448_eddsa_pk[57] = {
0x5f,0xd7,0x44,0x9b,0x59,0xb4,0x61,0xfd,
0x2c,0xe7,0x87,0xec,0x61,0x6a,0xd4,0x6a,
0x1d,0xa1,0x34,0x24,0x85,0xa7,0x0e,0x1f,
0x8a,0x0e,0xa7,0x5d,0x80,0xe9,0x67,0x78,
0xed,0xf1,0x24,0x76,0x9b,0x46,0xc7,0x06,
0x1b,0xd6,0x78,0x3d,0xf1,0xe5,0x0f,0x6c,
0xd1,0xfa,0x1a,0xbe,0xaf,0xe8,0x25,0x61,
0x80
};
const uint8_t ed448_eddsa_sig0[114] = {
0x53,0x3a,0x37,0xf6,0xbb,0xe4,0x57,0x25,
0x1f,0x02,0x3c,0x0d,0x88,0xf9,0x76,0xae,
0x2d,0xfb,0x50,0x4a,0x84,0x3e,0x34,0xd2,
0x07,0x4f,0xd8,0x23,0xd4,0x1a,0x59,0x1f,
0x2b,0x23,0x3f,0x03,0x4f,0x62,0x82,0x81,
0xf2,0xfd,0x7a,0x22,0xdd,0xd4,0x7d,0x78,
0x28,0xc5,0x9b,0xd0,0xa2,0x1b,0xfd,0x39,
0x80,0xff,0x0d,0x20,0x28,0xd4,0xb1,0x8a,
0x9d,0xf6,0x3e,0x00,0x6c,0x5d,0x1c,0x2d,
0x34,0x5b,0x92,0x5d,0x8d,0xc0,0x0b,0x41,
0x04,0x85,0x2d,0xb9,0x9a,0xc5,0xc7,0xcd,
0xda,0x85,0x30,0xa1,0x13,0xa0,0xf4,0xdb,
0xb6,0x11,0x49,0xf0,0x5a,0x73,0x63,0x26,
0x8c,0x71,0xd9,0x58,0x08,0xff,0x2e,0x65,
0x26,0x00
};
template<> const Block Tests<Ed448Goldilocks>::eddsa_sk(ed448_eddsa_sk,57);
template<> const Block Tests<Ed448Goldilocks>::eddsa_pk(ed448_eddsa_pk,57);
template<> const Block Tests<Ed448Goldilocks>::eddsa_sig0(ed448_eddsa_sig0,114);
const uint8_t ed25519_eddsa_sk[32] = {
0x9d,0x61,0xb1,0x9d,0xef,0xfd,0x5a,0x60,
0xba,0x84,0x4a,0xf4,0x92,0xec,0x2c,0xc4,
0x44,0x49,0xc5,0x69,0x7b,0x32,0x69,0x19,
0x70,0x3b,0xac,0x03,0x1c,0xae,0x7f,0x60
};
const uint8_t ed25519_eddsa_pk[32] = {
0xd7,0x5a,0x98,0x01,0x82,0xb1,0x0a,0xb7,
0xd5,0x4b,0xfe,0xd3,0xc9,0x64,0x07,0x3a,
0x0e,0xe1,0x72,0xf3,0xda,0xa6,0x23,0x25,
0xaf,0x02,0x1a,0x68,0xf7,0x07,0x51,0x1a
};
const uint8_t ed25518_eddsa_sig0[64] = {
0xe5,0x56,0x43,0x00,0xc3,0x60,0xac,0x72,
0x90,0x86,0xe2,0xcc,0x80,0x6e,0x82,0x8a,
0x84,0x87,0x7f,0x1e,0xb8,0xe5,0xd9,0x74,
0xd8,0x73,0xe0,0x65,0x22,0x49,0x01,0x55,
0x5f,0xb8,0x82,0x15,0x90,0xa3,0x3b,0xac,
0xc6,0x1e,0x39,0x70,0x1c,0xf9,0xb4,0x6b,
0xd2,0x5b,0xf5,0xf0,0x59,0x5b,0xbe,0x24,
0x65,0x51,0x41,0x43,0x8e,0x7a,0x10,0x0b
};
template<> const Block Tests<IsoEd25519>::eddsa_sk(ed25519_eddsa_sk,32);
template<> const Block Tests<IsoEd25519>::eddsa_pk(ed25519_eddsa_pk,32);
template<> const Block Tests<IsoEd25519>::eddsa_sig0(ed25518_eddsa_sig0,64);
#include "vectors.inc.c"
int main(int argc, char **argv) {
(void) argc; (void) argv;
Tests<IsoEd25519>::test_cfrg_vectors();
run_for_all_curves<Tests>();
if (passing) printf("Passed all tests.\n");
return passing ? 0 : 1;
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment