2017-12-01 18:12:25 +00:00
|
|
|
/*
|
2018-01-18 13:12:46 +00:00
|
|
|
* Copyright 2017-2018 The OpenSSL Project Authors. All Rights Reserved.
|
2017-12-01 18:12:25 +00:00
|
|
|
* Copyright 2015-2016 Cryptography Research, Inc.
|
2017-11-15 15:27:21 +00:00
|
|
|
*
|
2017-12-01 18:12:25 +00:00
|
|
|
* Licensed under the OpenSSL license (the "License"). You may not use
|
|
|
|
* this file except in compliance with the License. You can obtain a copy
|
|
|
|
* in the file LICENSE in the source distribution or at
|
|
|
|
* https://www.openssl.org/source/license.html
|
2017-11-15 15:27:21 +00:00
|
|
|
*
|
2017-12-01 18:12:25 +00:00
|
|
|
* Originally written by Mike Hamburg
|
2017-11-15 15:27:21 +00:00
|
|
|
*/
|
2018-02-07 11:47:41 +00:00
|
|
|
#include <string.h>
|
2017-11-15 16:39:33 +00:00
|
|
|
#include <openssl/crypto.h>
|
2017-11-28 12:09:23 +00:00
|
|
|
#include <openssl/evp.h>
|
2017-11-27 11:32:03 +00:00
|
|
|
#include "curve448_lcl.h"
|
2017-11-15 15:27:21 +00:00
|
|
|
#include "word.h"
|
2017-11-15 16:15:18 +00:00
|
|
|
#include "ed448.h"
|
2017-11-28 12:09:23 +00:00
|
|
|
#include "internal/numbers.h"
|
2017-11-15 15:27:21 +00:00
|
|
|
|
|
|
|
#define COFACTOR 4
|
|
|
|
|
2017-12-05 16:37:57 +00:00
|
|
|
static c448_error_t oneshot_hash(uint8_t *out, size_t outlen,
|
|
|
|
const uint8_t *in, size_t inlen)
|
2017-11-28 12:09:23 +00:00
|
|
|
{
|
|
|
|
EVP_MD_CTX *hashctx = EVP_MD_CTX_new();
|
|
|
|
|
|
|
|
if (hashctx == NULL)
|
2017-12-05 16:37:57 +00:00
|
|
|
return C448_FAILURE;
|
2017-11-28 12:09:23 +00:00
|
|
|
|
|
|
|
if (!EVP_DigestInit_ex(hashctx, EVP_shake256(), NULL)
|
2018-02-12 14:03:36 +00:00
|
|
|
|| !EVP_DigestUpdate(hashctx, in, inlen)
|
|
|
|
|| !EVP_DigestFinalXOF(hashctx, out, outlen)) {
|
2017-11-28 12:09:23 +00:00
|
|
|
EVP_MD_CTX_free(hashctx);
|
2017-12-05 16:37:57 +00:00
|
|
|
return C448_FAILURE;
|
2017-11-28 12:09:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
EVP_MD_CTX_free(hashctx);
|
2017-12-05 16:37:57 +00:00
|
|
|
return C448_SUCCESS;
|
2017-11-28 12:09:23 +00:00
|
|
|
}
|
|
|
|
|
2017-12-06 13:06:13 +00:00
|
|
|
static void clamp(uint8_t secret_scalar_ser[EDDSA_448_PRIVATE_BYTES])
|
2017-12-04 11:38:58 +00:00
|
|
|
{
|
2017-11-15 15:27:21 +00:00
|
|
|
secret_scalar_ser[0] &= -COFACTOR;
|
2018-02-07 13:40:56 +00:00
|
|
|
secret_scalar_ser[EDDSA_448_PRIVATE_BYTES - 1] = 0;
|
|
|
|
secret_scalar_ser[EDDSA_448_PRIVATE_BYTES - 2] |= 0x80;
|
2017-11-15 15:27:21 +00:00
|
|
|
}
|
|
|
|
|
2017-12-05 16:37:57 +00:00
|
|
|
static c448_error_t hash_init_with_dom(EVP_MD_CTX *hashctx, uint8_t prehashed,
|
|
|
|
uint8_t for_prehash,
|
|
|
|
const uint8_t *context,
|
|
|
|
size_t context_len)
|
2017-12-04 11:38:58 +00:00
|
|
|
{
|
2017-11-28 12:09:23 +00:00
|
|
|
const char *dom_s = "SigEd448";
|
2018-01-18 12:55:23 +00:00
|
|
|
uint8_t dom[2];
|
|
|
|
|
2017-11-28 12:09:23 +00:00
|
|
|
if (context_len > UINT8_MAX)
|
2017-12-05 16:37:57 +00:00
|
|
|
return C448_FAILURE;
|
2017-11-15 15:27:21 +00:00
|
|
|
|
2018-02-07 12:14:25 +00:00
|
|
|
dom[0] = (uint8_t)(2 - (prehashed == 0 ? 1 : 0)
|
|
|
|
- (for_prehash == 0 ? 1 : 0));
|
2018-02-07 11:47:41 +00:00
|
|
|
dom[1] = (uint8_t)context_len;
|
|
|
|
|
2017-11-28 12:09:23 +00:00
|
|
|
if (!EVP_DigestInit_ex(hashctx, EVP_shake256(), NULL)
|
2018-02-12 14:03:36 +00:00
|
|
|
|| !EVP_DigestUpdate(hashctx, dom_s, strlen(dom_s))
|
|
|
|
|| !EVP_DigestUpdate(hashctx, dom, sizeof(dom))
|
2018-02-20 14:53:06 +00:00
|
|
|
|| (context_len > 0
|
|
|
|
&& !EVP_DigestUpdate(hashctx, context, context_len)))
|
2017-12-05 16:37:57 +00:00
|
|
|
return C448_FAILURE;
|
2017-11-28 12:09:23 +00:00
|
|
|
|
2017-12-05 16:37:57 +00:00
|
|
|
return C448_SUCCESS;
|
2017-11-15 15:27:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* In this file because it uses the hash */
|
2017-12-05 16:37:57 +00:00
|
|
|
c448_error_t c448_ed448_convert_private_key_to_x448(
|
2017-12-06 13:06:13 +00:00
|
|
|
uint8_t x[X448_PRIVATE_BYTES],
|
|
|
|
const uint8_t ed [EDDSA_448_PRIVATE_BYTES])
|
2017-12-04 11:38:58 +00:00
|
|
|
{
|
2017-11-28 12:09:23 +00:00
|
|
|
/* pass the private key through oneshot_hash function */
|
2017-12-06 13:06:13 +00:00
|
|
|
/* and keep the first X448_PRIVATE_BYTES bytes */
|
|
|
|
return oneshot_hash(x, X448_PRIVATE_BYTES, ed,
|
|
|
|
EDDSA_448_PRIVATE_BYTES);
|
2017-11-15 15:27:21 +00:00
|
|
|
}
|
2017-12-04 11:38:58 +00:00
|
|
|
|
2017-12-05 16:37:57 +00:00
|
|
|
c448_error_t c448_ed448_derive_public_key(
|
2017-12-06 13:06:13 +00:00
|
|
|
uint8_t pubkey[EDDSA_448_PUBLIC_BYTES],
|
|
|
|
const uint8_t privkey[EDDSA_448_PRIVATE_BYTES])
|
2017-12-04 11:38:58 +00:00
|
|
|
{
|
2017-11-15 15:27:21 +00:00
|
|
|
/* only this much used for keygen */
|
2017-12-06 13:06:13 +00:00
|
|
|
uint8_t secret_scalar_ser[EDDSA_448_PRIVATE_BYTES];
|
2018-01-18 12:55:23 +00:00
|
|
|
curve448_scalar_t secret_scalar;
|
|
|
|
unsigned int c;
|
|
|
|
curve448_point_t p;
|
|
|
|
|
2017-11-28 12:09:23 +00:00
|
|
|
if (!oneshot_hash(secret_scalar_ser, sizeof(secret_scalar_ser), privkey,
|
2017-12-06 13:06:13 +00:00
|
|
|
EDDSA_448_PRIVATE_BYTES))
|
2017-12-05 16:37:57 +00:00
|
|
|
return C448_FAILURE;
|
2017-12-04 13:30:53 +00:00
|
|
|
|
2017-11-15 15:27:21 +00:00
|
|
|
clamp(secret_scalar_ser);
|
2018-01-18 12:55:23 +00:00
|
|
|
|
2017-12-04 11:38:58 +00:00
|
|
|
curve448_scalar_decode_long(secret_scalar, secret_scalar_ser,
|
|
|
|
sizeof(secret_scalar_ser));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Since we are going to mul_by_cofactor during encoding, divide by it
|
|
|
|
* here. However, the EdDSA base point is not the same as the decaf base
|
|
|
|
* point if the sigma isogeny is in use: the EdDSA base point is on
|
|
|
|
* Etwist_d/(1-d) and the decaf base point is on Etwist_d, and when
|
|
|
|
* converted it effectively picks up a factor of 2 from the isogenies. So
|
|
|
|
* we might start at 2 instead of 1.
|
2017-11-15 15:27:21 +00:00
|
|
|
*/
|
2017-12-06 13:06:13 +00:00
|
|
|
for (c = 1; c < C448_EDDSA_ENCODE_RATIO; c <<= 1)
|
2017-12-04 11:38:58 +00:00
|
|
|
curve448_scalar_halve(secret_scalar, secret_scalar);
|
|
|
|
|
|
|
|
curve448_precomputed_scalarmul(p, curve448_precomputed_base, secret_scalar);
|
|
|
|
|
2017-11-16 16:27:48 +00:00
|
|
|
curve448_point_mul_by_ratio_and_encode_like_eddsa(pubkey, p);
|
2017-12-04 11:38:58 +00:00
|
|
|
|
2017-11-15 15:27:21 +00:00
|
|
|
/* Cleanup */
|
2017-11-16 16:27:48 +00:00
|
|
|
curve448_scalar_destroy(secret_scalar);
|
|
|
|
curve448_point_destroy(p);
|
2017-11-15 16:39:33 +00:00
|
|
|
OPENSSL_cleanse(secret_scalar_ser, sizeof(secret_scalar_ser));
|
2017-11-28 12:09:23 +00:00
|
|
|
|
2017-12-05 16:37:57 +00:00
|
|
|
return C448_SUCCESS;
|
2017-11-15 15:27:21 +00:00
|
|
|
}
|
|
|
|
|
2017-12-05 16:37:57 +00:00
|
|
|
c448_error_t c448_ed448_sign(
|
2017-12-06 13:06:13 +00:00
|
|
|
uint8_t signature[EDDSA_448_SIGNATURE_BYTES],
|
|
|
|
const uint8_t privkey[EDDSA_448_PRIVATE_BYTES],
|
|
|
|
const uint8_t pubkey[EDDSA_448_PUBLIC_BYTES],
|
2017-12-04 13:30:53 +00:00
|
|
|
const uint8_t *message, size_t message_len,
|
|
|
|
uint8_t prehashed, const uint8_t *context,
|
|
|
|
size_t context_len)
|
2017-12-04 11:38:58 +00:00
|
|
|
{
|
2017-11-16 16:27:48 +00:00
|
|
|
curve448_scalar_t secret_scalar;
|
2017-11-28 12:09:23 +00:00
|
|
|
EVP_MD_CTX *hashctx = EVP_MD_CTX_new();
|
2017-12-05 16:37:57 +00:00
|
|
|
c448_error_t ret = C448_FAILURE;
|
2018-01-18 12:55:23 +00:00
|
|
|
curve448_scalar_t nonce_scalar;
|
2017-12-06 13:06:13 +00:00
|
|
|
uint8_t nonce_point[EDDSA_448_PUBLIC_BYTES] = { 0 };
|
2018-01-18 12:55:23 +00:00
|
|
|
unsigned int c;
|
|
|
|
curve448_scalar_t challenge_scalar;
|
2017-11-28 12:09:23 +00:00
|
|
|
|
|
|
|
if (hashctx == NULL)
|
2017-12-05 16:37:57 +00:00
|
|
|
return C448_FAILURE;
|
2017-11-28 12:09:23 +00:00
|
|
|
|
2017-11-15 15:27:21 +00:00
|
|
|
{
|
2017-12-12 14:17:40 +00:00
|
|
|
/*
|
|
|
|
* Schedule the secret key, First EDDSA_448_PRIVATE_BYTES is serialised
|
|
|
|
* secret scalar,next EDDSA_448_PRIVATE_BYTES bytes is the seed.
|
|
|
|
*/
|
|
|
|
uint8_t expanded[EDDSA_448_PRIVATE_BYTES * 2];
|
2017-11-28 12:09:23 +00:00
|
|
|
|
2017-12-12 14:17:40 +00:00
|
|
|
if (!oneshot_hash(expanded, sizeof(expanded), privkey,
|
2017-12-06 13:06:13 +00:00
|
|
|
EDDSA_448_PRIVATE_BYTES))
|
2017-11-28 12:09:23 +00:00
|
|
|
goto err;
|
2017-12-12 14:17:40 +00:00
|
|
|
clamp(expanded);
|
|
|
|
curve448_scalar_decode_long(secret_scalar, expanded,
|
|
|
|
EDDSA_448_PRIVATE_BYTES);
|
2017-12-04 11:38:58 +00:00
|
|
|
|
2017-11-15 15:27:21 +00:00
|
|
|
/* Hash to create the nonce */
|
2017-11-28 12:09:23 +00:00
|
|
|
if (!hash_init_with_dom(hashctx, prehashed, 0, context, context_len)
|
2018-02-12 14:03:36 +00:00
|
|
|
|| !EVP_DigestUpdate(hashctx,
|
|
|
|
expanded + EDDSA_448_PRIVATE_BYTES,
|
|
|
|
EDDSA_448_PRIVATE_BYTES)
|
2018-02-20 14:53:06 +00:00
|
|
|
|| (message_len > 0
|
|
|
|
&& !EVP_DigestUpdate(hashctx, message, message_len))) {
|
2018-02-12 14:27:02 +00:00
|
|
|
OPENSSL_cleanse(expanded, sizeof(expanded));
|
2017-11-28 12:09:23 +00:00
|
|
|
goto err;
|
|
|
|
}
|
2017-12-12 14:17:40 +00:00
|
|
|
OPENSSL_cleanse(expanded, sizeof(expanded));
|
2017-11-15 15:27:21 +00:00
|
|
|
}
|
2017-12-04 11:38:58 +00:00
|
|
|
|
2017-11-15 15:27:21 +00:00
|
|
|
/* Decode the nonce */
|
|
|
|
{
|
2017-12-06 13:06:13 +00:00
|
|
|
uint8_t nonce[2 * EDDSA_448_PRIVATE_BYTES];
|
2017-11-28 12:09:23 +00:00
|
|
|
|
|
|
|
if (!EVP_DigestFinalXOF(hashctx, nonce, sizeof(nonce)))
|
|
|
|
goto err;
|
2017-11-16 16:27:48 +00:00
|
|
|
curve448_scalar_decode_long(nonce_scalar, nonce, sizeof(nonce));
|
2017-11-15 16:39:33 +00:00
|
|
|
OPENSSL_cleanse(nonce, sizeof(nonce));
|
2017-11-15 15:27:21 +00:00
|
|
|
}
|
2018-01-18 12:55:23 +00:00
|
|
|
|
2017-11-15 15:27:21 +00:00
|
|
|
{
|
|
|
|
/* Scalarmul to create the nonce-point */
|
2017-11-16 16:27:48 +00:00
|
|
|
curve448_scalar_t nonce_scalar_2;
|
2018-01-18 12:55:23 +00:00
|
|
|
curve448_point_t p;
|
|
|
|
|
2017-12-04 11:38:58 +00:00
|
|
|
curve448_scalar_halve(nonce_scalar_2, nonce_scalar);
|
2018-02-12 14:27:02 +00:00
|
|
|
for (c = 2; c < C448_EDDSA_ENCODE_RATIO; c <<= 1)
|
2017-12-04 11:38:58 +00:00
|
|
|
curve448_scalar_halve(nonce_scalar_2, nonce_scalar_2);
|
2018-01-18 12:55:23 +00:00
|
|
|
|
2017-12-04 11:38:58 +00:00
|
|
|
curve448_precomputed_scalarmul(p, curve448_precomputed_base,
|
|
|
|
nonce_scalar_2);
|
2017-11-16 16:27:48 +00:00
|
|
|
curve448_point_mul_by_ratio_and_encode_like_eddsa(nonce_point, p);
|
|
|
|
curve448_point_destroy(p);
|
|
|
|
curve448_scalar_destroy(nonce_scalar_2);
|
2017-11-15 15:27:21 +00:00
|
|
|
}
|
2018-01-18 12:55:23 +00:00
|
|
|
|
2017-11-15 15:27:21 +00:00
|
|
|
{
|
2017-12-06 13:06:13 +00:00
|
|
|
uint8_t challenge[2 * EDDSA_448_PRIVATE_BYTES];
|
2017-11-28 12:09:23 +00:00
|
|
|
|
|
|
|
/* Compute the challenge */
|
|
|
|
if (!hash_init_with_dom(hashctx, prehashed, 0, context, context_len)
|
2018-02-12 14:27:02 +00:00
|
|
|
|| !EVP_DigestUpdate(hashctx, nonce_point, sizeof(nonce_point))
|
|
|
|
|| !EVP_DigestUpdate(hashctx, pubkey, EDDSA_448_PUBLIC_BYTES)
|
2018-02-20 14:53:06 +00:00
|
|
|
|| (message_len > 0
|
|
|
|
&& !EVP_DigestUpdate(hashctx, message, message_len))
|
2018-02-12 14:27:02 +00:00
|
|
|
|| !EVP_DigestFinalXOF(hashctx, challenge, sizeof(challenge)))
|
2017-11-28 12:09:23 +00:00
|
|
|
goto err;
|
|
|
|
|
2017-12-04 11:38:58 +00:00
|
|
|
curve448_scalar_decode_long(challenge_scalar, challenge,
|
|
|
|
sizeof(challenge));
|
|
|
|
OPENSSL_cleanse(challenge, sizeof(challenge));
|
2017-11-15 15:27:21 +00:00
|
|
|
}
|
2017-12-04 11:38:58 +00:00
|
|
|
|
|
|
|
curve448_scalar_mul(challenge_scalar, challenge_scalar, secret_scalar);
|
|
|
|
curve448_scalar_add(challenge_scalar, challenge_scalar, nonce_scalar);
|
|
|
|
|
2017-12-06 13:06:13 +00:00
|
|
|
OPENSSL_cleanse(signature, EDDSA_448_SIGNATURE_BYTES);
|
2017-12-04 11:38:58 +00:00
|
|
|
memcpy(signature, nonce_point, sizeof(nonce_point));
|
2017-12-06 13:06:13 +00:00
|
|
|
curve448_scalar_encode(&signature[EDDSA_448_PUBLIC_BYTES],
|
2017-12-04 11:38:58 +00:00
|
|
|
challenge_scalar);
|
|
|
|
|
2017-11-16 16:27:48 +00:00
|
|
|
curve448_scalar_destroy(secret_scalar);
|
|
|
|
curve448_scalar_destroy(nonce_scalar);
|
|
|
|
curve448_scalar_destroy(challenge_scalar);
|
2017-11-28 12:09:23 +00:00
|
|
|
|
2017-12-05 16:37:57 +00:00
|
|
|
ret = C448_SUCCESS;
|
2017-11-28 12:09:23 +00:00
|
|
|
err:
|
|
|
|
EVP_MD_CTX_free(hashctx);
|
|
|
|
return ret;
|
2017-11-15 15:27:21 +00:00
|
|
|
}
|
|
|
|
|
2017-12-05 16:37:57 +00:00
|
|
|
c448_error_t c448_ed448_sign_prehash(
|
2017-12-06 13:06:13 +00:00
|
|
|
uint8_t signature[EDDSA_448_SIGNATURE_BYTES],
|
|
|
|
const uint8_t privkey[EDDSA_448_PRIVATE_BYTES],
|
|
|
|
const uint8_t pubkey[EDDSA_448_PUBLIC_BYTES],
|
2017-12-05 16:37:57 +00:00
|
|
|
const uint8_t hash[64], const uint8_t *context,
|
|
|
|
size_t context_len)
|
2017-12-04 11:38:58 +00:00
|
|
|
{
|
2017-12-05 16:37:57 +00:00
|
|
|
return c448_ed448_sign(signature, privkey, pubkey, hash, 64, 1, context,
|
|
|
|
context_len);
|
2017-11-15 15:27:21 +00:00
|
|
|
}
|
|
|
|
|
2017-12-05 16:37:57 +00:00
|
|
|
c448_error_t c448_ed448_verify(
|
2017-12-06 13:06:13 +00:00
|
|
|
const uint8_t signature[EDDSA_448_SIGNATURE_BYTES],
|
|
|
|
const uint8_t pubkey[EDDSA_448_PUBLIC_BYTES],
|
2017-12-05 16:37:57 +00:00
|
|
|
const uint8_t *message, size_t message_len,
|
|
|
|
uint8_t prehashed, const uint8_t *context,
|
|
|
|
uint8_t context_len)
|
2017-12-04 11:38:58 +00:00
|
|
|
{
|
2017-11-16 16:27:48 +00:00
|
|
|
curve448_point_t pk_point, r_point;
|
2017-12-05 16:37:57 +00:00
|
|
|
c448_error_t error =
|
2017-12-04 11:38:58 +00:00
|
|
|
curve448_point_decode_like_eddsa_and_mul_by_ratio(pk_point, pubkey);
|
2018-01-18 12:55:23 +00:00
|
|
|
curve448_scalar_t challenge_scalar;
|
|
|
|
curve448_scalar_t response_scalar;
|
|
|
|
unsigned int c;
|
|
|
|
|
2017-12-05 16:37:57 +00:00
|
|
|
if (C448_SUCCESS != error)
|
2017-12-04 11:38:58 +00:00
|
|
|
return error;
|
|
|
|
|
|
|
|
error =
|
|
|
|
curve448_point_decode_like_eddsa_and_mul_by_ratio(r_point, signature);
|
2017-12-05 16:37:57 +00:00
|
|
|
if (C448_SUCCESS != error)
|
2017-12-04 11:38:58 +00:00
|
|
|
return error;
|
|
|
|
|
2017-11-15 15:27:21 +00:00
|
|
|
{
|
|
|
|
/* Compute the challenge */
|
2017-11-28 12:09:23 +00:00
|
|
|
EVP_MD_CTX *hashctx = EVP_MD_CTX_new();
|
2017-12-06 13:06:13 +00:00
|
|
|
uint8_t challenge[2 * EDDSA_448_PRIVATE_BYTES];
|
2017-11-28 12:09:23 +00:00
|
|
|
|
|
|
|
if (hashctx == NULL
|
2018-02-01 14:29:01 +00:00
|
|
|
|| !hash_init_with_dom(hashctx, prehashed, 0, context,
|
|
|
|
context_len)
|
|
|
|
|| !EVP_DigestUpdate(hashctx, signature, EDDSA_448_PUBLIC_BYTES)
|
|
|
|
|| !EVP_DigestUpdate(hashctx, pubkey, EDDSA_448_PUBLIC_BYTES)
|
|
|
|
|| !EVP_DigestUpdate(hashctx, message, message_len)
|
|
|
|
|| !EVP_DigestFinalXOF(hashctx, challenge, sizeof(challenge))) {
|
2017-11-28 12:09:23 +00:00
|
|
|
EVP_MD_CTX_free(hashctx);
|
2017-12-05 16:37:57 +00:00
|
|
|
return C448_FAILURE;
|
2017-11-28 12:09:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
EVP_MD_CTX_free(hashctx);
|
2017-12-04 11:38:58 +00:00
|
|
|
curve448_scalar_decode_long(challenge_scalar, challenge,
|
|
|
|
sizeof(challenge));
|
|
|
|
OPENSSL_cleanse(challenge, sizeof(challenge));
|
2017-11-15 15:27:21 +00:00
|
|
|
}
|
2017-12-04 11:38:58 +00:00
|
|
|
curve448_scalar_sub(challenge_scalar, curve448_scalar_zero,
|
|
|
|
challenge_scalar);
|
|
|
|
|
|
|
|
curve448_scalar_decode_long(response_scalar,
|
2017-12-06 13:06:13 +00:00
|
|
|
&signature[EDDSA_448_PUBLIC_BYTES],
|
|
|
|
EDDSA_448_PRIVATE_BYTES);
|
2017-12-04 11:38:58 +00:00
|
|
|
|
2017-12-06 13:06:13 +00:00
|
|
|
for (c = 1; c < C448_EDDSA_DECODE_RATIO; c <<= 1)
|
2017-12-04 11:38:58 +00:00
|
|
|
curve448_scalar_add(response_scalar, response_scalar, response_scalar);
|
|
|
|
|
2017-11-15 15:27:21 +00:00
|
|
|
/* pk_point = -c(x(P)) + (cx + k)G = kG */
|
2017-12-04 11:38:58 +00:00
|
|
|
curve448_base_double_scalarmul_non_secret(pk_point,
|
|
|
|
response_scalar,
|
|
|
|
pk_point, challenge_scalar);
|
2017-12-05 16:37:57 +00:00
|
|
|
return c448_succeed_if(curve448_point_eq(pk_point, r_point));
|
2017-11-15 15:27:21 +00:00
|
|
|
}
|
|
|
|
|
2017-12-05 16:37:57 +00:00
|
|
|
c448_error_t c448_ed448_verify_prehash(
|
2017-12-06 13:06:13 +00:00
|
|
|
const uint8_t signature[EDDSA_448_SIGNATURE_BYTES],
|
|
|
|
const uint8_t pubkey[EDDSA_448_PUBLIC_BYTES],
|
2017-12-04 13:30:53 +00:00
|
|
|
const uint8_t hash[64], const uint8_t *context,
|
|
|
|
uint8_t context_len)
|
2017-12-04 11:38:58 +00:00
|
|
|
{
|
2018-02-12 14:27:02 +00:00
|
|
|
return c448_ed448_verify(signature, pubkey, hash, 64, 1, context,
|
|
|
|
context_len);
|
2017-11-15 15:27:21 +00:00
|
|
|
}
|
2017-11-27 11:32:03 +00:00
|
|
|
|
|
|
|
int ED448_sign(uint8_t *out_sig, const uint8_t *message, size_t message_len,
|
2017-11-28 18:23:51 +00:00
|
|
|
const uint8_t public_key[57], const uint8_t private_key[57],
|
2017-11-28 09:53:58 +00:00
|
|
|
const uint8_t *context, size_t context_len)
|
|
|
|
{
|
2017-12-05 16:37:57 +00:00
|
|
|
return c448_ed448_sign(out_sig, private_key, public_key, message,
|
|
|
|
message_len, 0, context, context_len)
|
|
|
|
== C448_SUCCESS;
|
2017-11-27 11:32:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int ED448_verify(const uint8_t *message, size_t message_len,
|
2017-11-28 18:23:51 +00:00
|
|
|
const uint8_t signature[114], const uint8_t public_key[57],
|
2017-11-28 09:53:58 +00:00
|
|
|
const uint8_t *context, size_t context_len)
|
|
|
|
{
|
2017-12-05 16:37:57 +00:00
|
|
|
return c448_ed448_verify(signature, public_key, message, message_len, 0,
|
2018-01-19 15:37:34 +00:00
|
|
|
context, (uint8_t)context_len) == C448_SUCCESS;
|
2017-11-27 11:32:03 +00:00
|
|
|
}
|
|
|
|
|
2017-11-28 09:53:58 +00:00
|
|
|
int ED448ph_sign(uint8_t *out_sig, const uint8_t hash[64],
|
2017-11-28 18:23:51 +00:00
|
|
|
const uint8_t public_key[57], const uint8_t private_key[57],
|
2017-11-28 09:53:58 +00:00
|
|
|
const uint8_t *context, size_t context_len)
|
|
|
|
{
|
2017-12-05 16:37:57 +00:00
|
|
|
return c448_ed448_sign_prehash(out_sig, private_key, public_key, hash,
|
|
|
|
context, context_len) == C448_SUCCESS;
|
2017-11-27 11:32:03 +00:00
|
|
|
|
2017-11-28 09:53:58 +00:00
|
|
|
}
|
2017-11-27 11:32:03 +00:00
|
|
|
|
2017-11-28 18:23:51 +00:00
|
|
|
int ED448ph_verify(const uint8_t hash[64], const uint8_t signature[114],
|
|
|
|
const uint8_t public_key[57], const uint8_t *context,
|
2017-11-28 09:53:58 +00:00
|
|
|
size_t context_len)
|
|
|
|
{
|
2017-12-05 16:37:57 +00:00
|
|
|
return c448_ed448_verify_prehash(signature, public_key, hash, context,
|
2018-01-19 15:37:34 +00:00
|
|
|
(uint8_t)context_len) == C448_SUCCESS;
|
2017-11-27 11:32:03 +00:00
|
|
|
}
|
|
|
|
|
2017-11-28 18:23:51 +00:00
|
|
|
int ED448_public_from_private(uint8_t out_public_key[57],
|
2017-12-04 11:38:58 +00:00
|
|
|
const uint8_t private_key[57])
|
2017-11-28 09:53:58 +00:00
|
|
|
{
|
2017-12-05 16:37:57 +00:00
|
|
|
return c448_ed448_derive_public_key(out_public_key, private_key)
|
|
|
|
== C448_SUCCESS;
|
2017-11-27 11:32:03 +00:00
|
|
|
}
|