summaryrefslogtreecommitdiff
path: root/ed25519-sha512-sign.c
diff options
context:
space:
mode:
authorNiels Möller <nisse@lysator.liu.se>2014-10-20 21:46:05 +0200
committerNiels Möller <nisse@lysator.liu.se>2014-10-20 21:46:05 +0200
commit451ec8e0a63bcf02dacfb87d46d0965efbb3f327 (patch)
tree64934b29c5f9c75be77d70e996350f1a86963dd1 /ed25519-sha512-sign.c
parentb645d8924b2163f2a4c417948d599ef3ae5a3ae3 (diff)
downloadnettle-451ec8e0a63bcf02dacfb87d46d0965efbb3f327.tar.gz
Implemented high level functions for ed25519-sha512.
Diffstat (limited to 'ed25519-sha512-sign.c')
-rw-r--r--ed25519-sha512-sign.c70
1 files changed, 70 insertions, 0 deletions
diff --git a/ed25519-sha512-sign.c b/ed25519-sha512-sign.c
new file mode 100644
index 00000000..bbcd133b
--- /dev/null
+++ b/ed25519-sha512-sign.c
@@ -0,0 +1,70 @@
+/* ed25519-sha512-sign.c
+
+ Copyright (C) 2014 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.h"
+
+#include "ecc-internal.h"
+#include "sha2.h"
+
+void
+ed25519_sha512_set_private_key (struct ed25519_private_key *priv,
+ const uint8_t *key)
+{
+ mp_size_t itch = _eddsa_expand_key_itch (&nettle_curve25519);
+ mp_limb_t *scratch = gmp_alloc_limbs (itch);
+ struct sha512_ctx ctx;
+
+ _eddsa_expand_key (&nettle_curve25519, &nettle_sha512, &ctx,
+ key, priv->pub, priv->k1, priv->k2, scratch);
+ gmp_free_limbs (scratch, itch);
+}
+
+void
+ed25519_sha512_sign (const struct ed25519_private_key *priv,
+ size_t length, const uint8_t *msg,
+ uint8_t *signature)
+{
+ mp_size_t itch = _eddsa_sign_itch (&nettle_curve25519);
+ mp_limb_t *scratch = gmp_alloc_limbs (itch);
+ struct sha512_ctx ctx;
+
+ sha512_init (&ctx);
+ sha512_update (&ctx, ED25519_KEY_SIZE, priv->k1);
+ _eddsa_sign (&nettle_curve25519, &nettle_sha512, priv->pub,
+ &ctx,
+ priv->k2, length, msg, signature, scratch);
+
+ gmp_free_limbs (scratch, itch);
+}