Commit a148ed32 authored by Niels Möller's avatar Niels Möller

Implement ed448-shake256

parent 42e410bf
......@@ -18,6 +18,23 @@
* eddsa-pubkey.c (_eddsa_public_key_itch): Assert that
_eddsa_compress_itch isn't too large.
Implementation of ed448-shake256, based on patch by Daiki Ueno.
* ed448-shake256-pubkey.c (ed448_shake256_public_key): New file
and function.
* ed448-shake256-sign.c (ed448_shake256_sign): New file and function.
* ed448-shake256-verify.c (ed448_shake256_verify): New file and function.
* Makefile.in (hogweed_SOURCES): Add new ed448 files.
* testsuite/eddsa-verify-test.c (test_ed448): New function.
(test_main): New ed448 tests.
* testsuite/eddsa-sign-test.c (test_ed448_sign): New function.
(test_main): New ed448 tests.
* testsuite/ed448-test.c: New tests.
* testsuite/Makefile.in (TS_HOGWEED_SOURCES): Add ed448-test.c.
* nettle.texinfo (Curve 25519 and Curve 448): Document ed448.
2020-01-01 Niels Möller <nisse@lysator.liu.se>
* ecc-448.c (ecc_mod_pow_2kp1): New function.
......
......@@ -192,7 +192,9 @@ hogweed_SOURCES = sexp.c sexp-format.c \
eddsa-compress.c eddsa-decompress.c eddsa-expand.c \
eddsa-hash.c eddsa-pubkey.c eddsa-sign.c eddsa-verify.c \
ed25519-sha512.c ed25519-sha512-pubkey.c \
ed25519-sha512-sign.c ed25519-sha512-verify.c
ed25519-sha512-sign.c ed25519-sha512-verify.c \
ed448-shake256.c ed448-shake256-pubkey.c \
ed448-shake256-sign.c ed448-shake256-verify.c
OPT_SOURCES = fat-x86_64.c fat-arm.c mini-gmp.c
......
/* ed448-shake256-pubkey.c
Copyright (C) 2017 Daiki Ueno
Copyright (C) 2017 Red Hat, Inc.
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#if HAVE_CONFIG_H
# include "config.h"
#endif
#include "eddsa.h"
#include "ecc-internal.h"
#include "eddsa-internal.h"
#include "sha3.h"
void
ed448_shake256_public_key (uint8_t *pub, const uint8_t *priv)
{
const struct ecc_curve *ecc = &_nettle_curve448;
struct sha3_256_ctx ctx;
uint8_t digest[ED448_SIGNATURE_SIZE];
mp_size_t itch = ecc->q.size + _eddsa_public_key_itch (ecc);
mp_limb_t *scratch = gmp_alloc_limbs (itch);
#define k scratch
#define scratch_out (scratch + ecc->q.size)
sha3_256_init (&ctx);
_eddsa_expand_key (ecc, &_nettle_ed448_shake256, &ctx, priv, digest, k);
_eddsa_public_key (ecc, k, pub, scratch_out);
gmp_free_limbs (scratch, itch);
#undef k
#undef scratch_out
}
/* ed448-shake256-sign.c
Copyright (C) 2017 Daiki Ueno
Copyright (C) 2017 Red Hat, Inc.
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#if HAVE_CONFIG_H
# include "config.h"
#endif
#include "eddsa.h"
#include "ecc-internal.h"
#include "eddsa-internal.h"
#include "sha3.h"
void
ed448_shake256_sign (const uint8_t *pub,
const uint8_t *priv,
size_t length, const uint8_t *msg,
uint8_t *signature)
{
const struct ecc_curve *ecc = &_nettle_curve448;
const struct ecc_eddsa *eddsa = &_nettle_ed448_shake256;
mp_size_t itch = ecc->q.size + _eddsa_sign_itch (ecc);
mp_limb_t *scratch = gmp_alloc_limbs (itch);
#define k2 scratch
#define scratch_out (scratch + ecc->q.size)
struct sha3_256_ctx ctx;
uint8_t digest[ED448_SIGNATURE_SIZE];
sha3_256_init (&ctx);
_eddsa_expand_key (ecc, eddsa, &ctx, priv, digest, k2);
_eddsa_sign (ecc, eddsa, &ctx,
pub, digest + ED448_KEY_SIZE, k2,
length, msg, signature, scratch_out);
gmp_free_limbs (scratch, itch);
#undef k1
#undef k2
#undef scratch_out
}
/* ed448-shake256-verify.c
Copyright (C) 2017 Daiki Ueno
Copyright (C) 2017 Red Hat, Inc.
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#if HAVE_CONFIG_H
# include "config.h"
#endif
#include <string.h>
#include "eddsa.h"
#include "ecc-internal.h"
#include "eddsa-internal.h"
#include "sha3.h"
int
ed448_shake256_verify (const uint8_t *pub,
size_t length, const uint8_t *msg,
const uint8_t *signature)
{
const struct ecc_curve *ecc = &_nettle_curve448;
mp_size_t itch = 3*ecc->p.size + _eddsa_verify_itch (ecc);
mp_limb_t *scratch = gmp_alloc_limbs (itch);
struct sha3_256_ctx ctx;
int res;
#define A scratch
#define scratch_out (scratch + 3*ecc->p.size)
sha3_256_init (&ctx);
res = (_eddsa_decompress (ecc,
A, pub, scratch_out)
&& _eddsa_verify (ecc, &_nettle_ed448_shake256, pub, A,
&ctx,
length, msg, signature,
scratch_out));
gmp_free_limbs (scratch, itch);
return res;
#undef A
#undef scratch_out
}
/* ed448-shake256.c
Copyright (C) 2019 Niels Möller
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#if HAVE_CONFIG_H
# include "config.h"
#endif
#include "eddsa-internal.h"
#include "nettle-types.h"
#include "sha3.h"
#define DOM_SIZE 10
static const uint8_t ed448_dom[DOM_SIZE] =
{ 'S', 'i', 'g', 'E', 'd', '4', '4', '8', 0, 0};
const struct ecc_eddsa _nettle_ed448_shake256 =
{
(nettle_hash_update_func *) sha3_256_update,
(nettle_hash_digest_func *) sha3_256_shake,
ed448_dom, DOM_SIZE,
~(mp_limb_t) 3,
(mp_limb_t) 1 << (447 % GMP_NUMB_BITS),
};
......@@ -66,6 +66,7 @@ struct ecc_eddsa
};
extern const struct ecc_eddsa _nettle_ed25519_sha512;
extern const struct ecc_eddsa _nettle_ed448_shake256;
mp_size_t
_eddsa_compress_itch (const struct ecc_curve *ecc);
......
......@@ -45,6 +45,9 @@ extern "C" {
#define ed25519_sha512_public_key nettle_ed25519_sha512_public_key
#define ed25519_sha512_sign nettle_ed25519_sha512_sign
#define ed25519_sha512_verify nettle_ed25519_sha512_verify
#define ed448_shake256_public_key nettle_ed448_shake256_public_key
#define ed448_shake256_sign nettle_ed448_shake256_sign
#define ed448_shake256_verify nettle_ed448_shake256_verify
#define ED25519_KEY_SIZE 32
#define ED25519_SIGNATURE_SIZE 64
......@@ -63,6 +66,22 @@ ed25519_sha512_verify (const uint8_t *pub,
size_t length, const uint8_t *msg,
const uint8_t *signature);
#define ED448_KEY_SIZE 57
#define ED448_SIGNATURE_SIZE 114
void
ed448_shake256_public_key (uint8_t *pub, const uint8_t *priv);
void
ed448_shake256_sign (const uint8_t *pub,
const uint8_t *priv,
size_t length, const uint8_t *msg,
uint8_t *signature);
int
ed448_shake256_verify (const uint8_t *pub,
size_t length, const uint8_t *msg,
const uint8_t *signature);
#ifdef __cplusplus
}
......
......@@ -5213,6 +5213,31 @@ Verifies a message using the provided public key. Returns 1 if the
signature is valid, otherwise 0.
@end deftypefun
Nettle also provides Ed448, an EdDSA signature scheme based on an
Edwards curve equivalent to curve448.
@defvr Constant ED448_KEY_SIZE
The size of a private or public Ed448 key, 57 octets.
@end defvr
@defvr Constant ED448_SIGNATURE_SIZE
The size of an Ed448 signature, 114 octets.
@end defvr
@deftypefun void ed448_shake256_public_key (uint8_t *@var{pub}, const uint8_t *@var{priv})
Computes the public key corresponding to the given private key. Both
input and output are of size @code{ED448_KEY_SIZE}.
@end deftypefun
@deftypefun void ed448_shake256_sign (const uint8_t *@var{pub}, const uint8_t *@var{priv}, size_t @var{length}, const uint8_t *@var{msg}, uint8_t *@var{signature})
Signs a message using the provided key pair.
@end deftypefun
@deftypefun int ed448_shake256_verify (const uint8_t *@var{pub}, size_t @var{length}, const uint8_t *@var{msg}, const uint8_t *@var{signature})
Verifies a message using the provided public key. Returns 1 if the
signature is valid, otherwise 0.
@end deftypefun
@node Randomness, ASCII encoding, Public-key algorithms, Reference
@comment node-name, next, previous, up
@section Randomness
......
......@@ -286,6 +286,9 @@ eddsa-verify-test$(EXEEXT): eddsa-verify-test.$(OBJEXT)
ed25519-test$(EXEEXT): ed25519-test.$(OBJEXT)
$(LINK) ed25519-test.$(OBJEXT) $(TEST_OBJS) -o ed25519-test$(EXEEXT)
ed448-test$(EXEEXT): ed448-test.$(OBJEXT)
$(LINK) ed448-test.$(OBJEXT) $(TEST_OBJS) -o ed448-test$(EXEEXT)
sha1-huge-test$(EXEEXT): sha1-huge-test.$(OBJEXT)
$(LINK) sha1-huge-test.$(OBJEXT) $(TEST_OBJS) -o sha1-huge-test$(EXEEXT)
......
......@@ -53,7 +53,7 @@ TS_HOGWEED_SOURCES = sexp-test.c sexp-format-test.c \
ecdsa-sign-test.c ecdsa-verify-test.c \
ecdsa-keygen-test.c ecdh-test.c \
eddsa-compress-test.c eddsa-sign-test.c \
eddsa-verify-test.c ed25519-test.c
eddsa-verify-test.c ed25519-test.c ed448-test.c
TS_SOURCES = $(TS_NETTLE_SOURCES) $(TS_HOGWEED_SOURCES)
CXX_SOURCES = cxx-test.cxx
......
This diff is collapsed.
......@@ -33,6 +33,7 @@
#include "eddsa.h"
#include "eddsa-internal.h"
#include "sha3.h"
static void
test_eddsa_sign (const struct ecc_curve *ecc,
......@@ -112,6 +113,19 @@ test_ed25519_sign (const struct tstring *public,
public, private, msg, ref);
}
static void
test_ed448_sign (const struct tstring *public,
const struct tstring *private,
const struct tstring *msg,
const struct tstring *ref)
{
struct sha3_256_ctx ctx;
sha3_256_init (&ctx);
test_eddsa_sign (&_nettle_curve448, &_nettle_ed448_shake256, &ctx,
public, private, msg, ref);
}
void
test_main (void)
{
......@@ -150,4 +164,59 @@ test_main (void)
"99df1340cce54626 183144ef46887163"
"4b0a5c0033534108 e1c67c0dc99d3014"
"f01084e98c95e101 4b309b1dbb2e6704"));
/* Based on a few of the test vectors from RFC 8032 */
test_ed448_sign (SHEX("5fd7449b59b461fd 2ce787ec616ad46a"
"1da1342485a70e1f 8a0ea75d80e96778"
"edf124769b46c706 1bd6783df1e50f6c"
"d1fa1abeafe82561 80"),
SHEX("6c82a562cb808d10 d632be89c8513ebf"
"6c929f34ddfa8c9f 63c9960ef6e348a3"
"528c8a3fcc2f044e 39a3fc5b94492f8f"
"032e7549a20098f9 5b"),
SHEX(""),
SHEX("533a37f6bbe45725 1f023c0d88f976ae"
"2dfb504a843e34d2 074fd823d41a591f"
"2b233f034f628281 f2fd7a22ddd47d78"
"28c59bd0a21bfd39 80ff0d2028d4b18a"
"9df63e006c5d1c2d 345b925d8dc00b41"
"04852db99ac5c7cd da8530a113a0f4db"
"b61149f05a736326 8c71d95808ff2e65"
"2600"));
test_ed448_sign (SHEX("43ba28f430cdff45 6ae531545f7ecd0a"
"c834a55d9358c037 2bfa0c6c6798c086"
"6aea01eb00742802 b8438ea4cb82169c"
"235160627b4c3a94 80"),
SHEX("c4eab05d357007c6 32f3dbb48489924d"
"552b08fe0c353a0d 4a1f00acda2c463a"
"fbea67c5e8d2877c 5e3bc397a659949e"
"f8021e954e0a1227 4e"),
SHEX("03"),
SHEX("26b8f91727bd6289 7af15e41eb43c377"
"efb9c610d48f2335 cb0bd0087810f435"
"2541b143c4b981b7 e18f62de8ccdf633"
"fc1bf037ab7cd779 805e0dbcc0aae1cb"
"cee1afb2e027df36 bc04dcecbf154336"
"c19f0af7e0a64729 05e799f1953d2a0f"
"f3348ab21aa4adaf d1d234441cf807c0"
"3a00"));
test_ed448_sign (SHEX("df9705f58edbab80 2c7f8363cfe5560a"
"b1c6132c20a9f1dd 163483a26f8ac53a"
"39d6808bf4a1dfbd 261b099bb03b3fb5"
"0906cb28bd8a081f 00"),
SHEX("d65df341ad13e008 567688baedda8e9d"
"cdc17dc024974ea5 b4227b6530e339bf"
"f21f99e68ca6968f 3cca6dfe0fb9f4fa"
"b4fa135d5542ea3f 01"),
SHEX("bd0f6a3747cd561b dddf4640a332461a"
"4a30a12a434cd0bf 40d766d9c6d458e5"
"512204a30c17d1f5 0b5079631f64eb31"
"12182da300583546 1113718d1a5ef944"),
SHEX("554bc2480860b49e ab8532d2a533b7d5"
"78ef473eeb58c98b b2d0e1ce488a98b1"
"8dfde9b9b90775e6 7f47d4a1c3482058"
"efc9f40d2ca033a0 801b63d45b3b722e"
"f552bad3b4ccb667 da350192b61c508c"
"f7b6b5adadc2c8d9 a446ef003fb05cba"
"5f30e88e36ec2703 b349ca229c267083"
"3900"));
}
......@@ -33,6 +33,7 @@
#include "eddsa.h"
#include "eddsa-internal.h"
#include "sha3.h"
static void
test_eddsa (const struct ecc_curve *ecc,
......@@ -136,6 +137,17 @@ test_ed25519 (const uint8_t *pub,
pub, msg, signature);
}
static void
test_ed448 (const uint8_t *pub,
const struct tstring *msg,
const uint8_t *signature)
{
struct sha3_256_ctx ctx;
sha3_256_init (&ctx);
test_eddsa (&_nettle_curve448, &_nettle_ed448_shake256, &ctx,
pub, msg, signature);
}
void
test_main (void)
......@@ -167,4 +179,47 @@ test_main (void)
"99df1340cce54626 183144ef46887163"
"4b0a5c0033534108 e1c67c0dc99d3014"
"f01084e98c95e101 4b309b1dbb2e6704"));
/* Based on a few of the test vectors from RFC 8032 */
test_ed448 (H("5fd7449b59b461fd 2ce787ec616ad46a"
"1da1342485a70e1f 8a0ea75d80e96778"
"edf124769b46c706 1bd6783df1e50f6c"
"d1fa1abeafe82561 80"),
SHEX(""),
H("533a37f6bbe45725 1f023c0d88f976ae"
"2dfb504a843e34d2 074fd823d41a591f"
"2b233f034f628281 f2fd7a22ddd47d78"
"28c59bd0a21bfd39 80ff0d2028d4b18a"
"9df63e006c5d1c2d 345b925d8dc00b41"
"04852db99ac5c7cd da8530a113a0f4db"
"b61149f05a736326 8c71d95808ff2e65"
"2600"));
test_ed448 (H("43ba28f430cdff45 6ae531545f7ecd0a"
"c834a55d9358c037 2bfa0c6c6798c086"
"6aea01eb00742802 b8438ea4cb82169c"
"235160627b4c3a94 80"),
SHEX("03"),
H("26b8f91727bd6289 7af15e41eb43c377"
"efb9c610d48f2335 cb0bd0087810f435"
"2541b143c4b981b7 e18f62de8ccdf633"
"fc1bf037ab7cd779 805e0dbcc0aae1cb"
"cee1afb2e027df36 bc04dcecbf154336"
"c19f0af7e0a64729 05e799f1953d2a0f"
"f3348ab21aa4adaf d1d234441cf807c0"
"3a00"));
test_ed448 (H("df9705f58edbab80 2c7f8363cfe5560a"
"b1c6132c20a9f1dd 163483a26f8ac53a"
"39d6808bf4a1dfbd 261b099bb03b3fb5"
"0906cb28bd8a081f 00"),
SHEX("bd0f6a3747cd561b dddf4640a332461a"
"4a30a12a434cd0bf 40d766d9c6d458e5"
"512204a30c17d1f5 0b5079631f64eb31"
"12182da300583546 1113718d1a5ef944"),
H("554bc2480860b49e ab8532d2a533b7d5"
"78ef473eeb58c98b b2d0e1ce488a98b1"
"8dfde9b9b90775e6 7f47d4a1c3482058"
"efc9f40d2ca033a0 801b63d45b3b722e"
"f552bad3b4ccb667 da350192b61c508c"
"f7b6b5adadc2c8d9 a446ef003fb05cba"
"5f30e88e36ec2703 b349ca229c267083"
"3900"));
}
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