35#define CURVE "Ed25519"
83 crypto_scalarmult_ed25519_base_noclamp (
pub->
q_y,
109 crypto_hash_sha512_state hs;
111 unsigned char hram[64];
113 unsigned char r_mod[64];
115 unsigned char tmp[32];
116 unsigned char hram_mod[64];
118 crypto_hash_sha512_init (&hs);
123 crypto_scalarmult_ed25519_base_noclamp (P,
131 crypto_hash_sha512_update (&hs,
134 crypto_hash_sha512_update (&hs,
136 ntohl (purpose->
size));
137 crypto_hash_sha512_final (&hs,
143 memcpy (sig->
s, P, 32);
148 crypto_core_ed25519_scalar_reduce (r_mod, r);
153 crypto_scalarmult_ed25519_base_noclamp (R, r_mod);
154 memcpy (sig->
r, R, sizeof (R));
160 crypto_hash_sha512_init (&hs);
161 crypto_hash_sha512_update (&hs, (uint8_t*) sig, 64);
162 crypto_hash_sha512_update (&hs, (uint8_t*) purpose,
163 ntohl (purpose->
size));
164 crypto_hash_sha512_final (&hs, hram);
169 crypto_core_ed25519_scalar_reduce (hram_mod, hram);
175 crypto_core_ed25519_scalar_mul (tmp, hram_mod, priv->
a);
176 crypto_core_ed25519_scalar_add (sig->
s, tmp, r_mod);
178 sodium_memzero (r,
sizeof (r));
179 sodium_memzero (r_mod,
sizeof (r_mod));
192 const unsigned char *
m = (
const void *) validate;
193 size_t mlen = ntohl (validate->
size);
194 const unsigned char *s = (
const void *) sig;
198 if (purpose != ntohl (validate->
purpose))
201 res = crypto_sign_verify_detached (s,
m, mlen,
pub->
q_y);
229 static const char *
const salt =
"edx25519-derivation";
254 uint8_t eight[32] = { 8 };
255 uint8_t eight_inv[32];
256 uint8_t
h[64] = { 0 };
267 crypto_core_ed25519_scalar_reduce (
h,
269#ifdef CHECK_RARE_CASES
278 char zero[32] = { 0 };
279 char one[32] = { 1 };
295 GNUNET_assert (0 == crypto_core_ed25519_scalar_invert (eight_inv,
298 crypto_core_ed25519_scalar_mul (a, priv->
a, eight_inv);
299 crypto_core_ed25519_scalar_mul (a, a,
h);
300 crypto_core_ed25519_scalar_mul (a, a, eight);
302#ifdef CHECK_RARE_CASES
305 char zero[32] = { 0 };
306 char one[32] = { 1 };
327 for (
size_t i = 0; i < 32; i++)
328 result->b[i] = ((
unsigned char *) &hcb)[i];
331 for (
size_t i = 0; i < 32; i++)
334 sodium_memzero (a,
sizeof(a));
346 uint8_t
h[64] = { 0 };
355 crypto_core_ed25519_scalar_reduce (
h,
static void derive_h(const struct GNUNET_CRYPTO_Edx25519PublicKey *pub, const void *seed, size_t seedsize, struct GNUNET_HashCode *phc)
Derive the 'h' value for key derivation, where 'h = H(P ∥ seed) mod n' and 'n' is the size of the cyc...
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
static struct GNUNET_ARM_Handle * h
Connection with ARM.
struct GNUNET_CRYPTO_PrivateKey pk
Private key from command line option, or NULL.
static char * res
Currently read line or NULL on EOF.
static int result
Global testing status.
static struct GNUNET_CRYPTO_EddsaPublicKey pub
static struct GNUNET_CRYPTO_PowSalt salt
Salt for PoW calculations.
static const struct GNUNET_CRYPTO_PrivateKey zero
Public key of all zeros.
void GNUNET_CRYPTO_edx25519_key_get_public(const struct GNUNET_CRYPTO_Edx25519PrivateKey *priv, struct GNUNET_CRYPTO_Edx25519PublicKey *pub)
Extract the public key for the given private key.
void GNUNET_CRYPTO_edx25519_key_clear(struct GNUNET_CRYPTO_Edx25519PrivateKey *pk)
Clear memory that was used to store a private key.
void GNUNET_CRYPTO_edx25519_private_key_derive(const struct GNUNET_CRYPTO_Edx25519PrivateKey *priv, const void *seed, size_t seedsize, struct GNUNET_CRYPTO_Edx25519PrivateKey *result)
Derive a private scalar from a given private key and a label.
void GNUNET_CRYPTO_edx25519_key_create_from_seed(const void *seed, size_t seedsize, struct GNUNET_CRYPTO_Edx25519PrivateKey *pk)
Create a new private key for Edx25519 from a given seed.
void GNUNET_CRYPTO_edx25519_public_key_derive(const struct GNUNET_CRYPTO_Edx25519PublicKey *pub, const void *seed, size_t seedsize, struct GNUNET_CRYPTO_Edx25519PublicKey *result)
Derive a public key from a given public key and a label.
void GNUNET_CRYPTO_random_block(enum GNUNET_CRYPTO_Quality mode, void *buffer, size_t length)
Fill block with a random values.
void GNUNET_CRYPTO_edx25519_key_create(struct GNUNET_CRYPTO_Edx25519PrivateKey *pk)
Create a new private key.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_edx25519_verify_(uint32_t purpose, const struct GNUNET_CRYPTO_EccSignaturePurpose *validate, const struct GNUNET_CRYPTO_Edx25519Signature *sig, const struct GNUNET_CRYPTO_Edx25519PublicKey *pub)
Verify Edx25519 signature.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_edx25519_sign_(const struct GNUNET_CRYPTO_Edx25519PrivateKey *priv, const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, struct GNUNET_CRYPTO_Edx25519Signature *sig)
This function operates the basically same way as the signature function for EdDSA.
@ GNUNET_CRYPTO_QUALITY_NONCE
Randomness for IVs etc.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_kdf(void *result, size_t out_len, const void *xts, size_t xts_len, const void *skm, size_t skm_len,...)
Derive key.
void GNUNET_CRYPTO_hash_context_read(struct GNUNET_HashContext *hc, const void *buf, size_t size)
Add data to be hashed.
void GNUNET_CRYPTO_hash_context_finish(struct GNUNET_HashContext *hc, struct GNUNET_HashCode *r_hash)
Finish the hash computation.
GNUNET_GenericReturnValue
Named constants for return values.
struct GNUNET_HashContext * GNUNET_CRYPTO_hash_context_start(void)
Start incremental hashing operation.
#define GNUNET_static_assert(cond)
Assertion to be checked (if supported by C compiler) at compile time, otherwise checked at runtime an...
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
header of what an ECC signature signs this must be followed by "size - 8" bytes of the actual signed ...
uint32_t size
How many bytes does this signature sign? (including this purpose header); in network byte order (!...
uint32_t purpose
What does this signature vouch for? This must contain a GNUNET_SIGNATURE_PURPOSE_XXX constant (from g...
unsigned char q_y[256/8]
Point Q consists of a y-value mod p (256 bits); the x-value is always positive.
Private ECC key material encoded for transmission.
unsigned char b[256/8]
b consists of 32 bytes which where originally the lower 32bytes of the key expansion.
unsigned char a[256/8]
a is a value mod n, where n has at most 256 bits.
Public ECC key (always for curve Ed25519) encoded in a format suitable for network transmission and E...
an ECC signature using Edx25519 (same as in EdDSA).
unsigned char s[256/8]
S value.
unsigned char r[256/8]
R value.