34#define CURVE "Ed25519"
60 static const char *
const salt =
"key-derivation";
86 crypto_hash_sha512_state hs;
89 unsigned char hram[64];
92 unsigned char tmp[32];
93 unsigned char r_mod[64];
94 unsigned char hram_mod[64];
104 crypto_hash_sha512_init (&hs);
114 memcpy (sk, priv.
s, 64);
120 crypto_scalarmult_ed25519_base_noclamp (zk,
131 crypto_hash_sha512_update (&hs, sk + 32, 32);
132 crypto_hash_sha512_update (&hs, (uint8_t*) purpose, ntohl (purpose->
size));
133 crypto_hash_sha512_final (&hs, r);
138 memcpy (sig->
s, zk, 32);
143 crypto_core_ed25519_scalar_reduce (r_mod, r);
148 crypto_scalarmult_ed25519_base_noclamp (R, r_mod);
149 memcpy (sig->
r, R, sizeof (R));
155 crypto_hash_sha512_init (&hs);
156 crypto_hash_sha512_update (&hs, (uint8_t*) sig, 64);
157 crypto_hash_sha512_update (&hs, (uint8_t*) purpose,
158 ntohl (purpose->
size));
159 crypto_hash_sha512_final (&hs, hram);
164 crypto_core_ed25519_scalar_reduce (hram_mod, hram);
170 crypto_core_ed25519_scalar_mul (tmp, hram_mod, sk);
171 crypto_core_ed25519_scalar_add (sig->
s, tmp, r_mod);
173 sodium_memzero (sk,
sizeof (sk));
174 sodium_memzero (r,
sizeof (r));
175 sodium_memzero (r_mod,
sizeof (r_mod));
219 n = gcry_mpi_ec_get_mpi (
"n",
ctx, 1);
226 for (
size_t i = 0; i < 32; i++)
227 dc[i] = priv->
d[31 - i];
229 d = gcry_mpi_new (256);
230 gcry_mpi_mulm (
d,
h, x, n);
231 gcry_mpi_release (
h);
232 gcry_mpi_release (x);
233 gcry_mpi_release (n);
234 gcry_ctx_release (
ctx);
238 for (
size_t i = 0; i < 32; i++)
239 ret->d[i] =
dc[31 - i];
240 sodium_memzero (
dc,
sizeof(
dc));
241 gcry_mpi_release (
d);
267 q_y = gcry_mpi_set_opaque_copy (NULL,
pub->
q_y, 8 *
sizeof(
pub->
q_y));
270 gcry_mpi_release (q_y);
271 q = gcry_mpi_ec_get_point (
"q",
ctx, 0);
277 n = gcry_mpi_ec_get_mpi (
"n",
ctx, 1);
278 h_mod_n = gcry_mpi_new (256);
279 gcry_mpi_mod (h_mod_n,
h, n);
281 v = gcry_mpi_point_new (0);
282 gcry_mpi_ec_mul (v, h_mod_n,
q,
ctx);
283 gcry_mpi_release (h_mod_n);
284 gcry_mpi_release (
h);
285 gcry_mpi_release (n);
286 gcry_mpi_point_release (
q);
290 gcry_mpi_point_release (v);
291 q_y = gcry_mpi_ec_get_mpi (
"q@eddsa",
ctx, 0);
294 gcry_mpi_release (q_y);
295 gcry_ctx_release (
ctx);
309 unsigned char sk[64];
326 L = gcry_mpi_ec_get_mpi (
"n",
ctx, 1);
335 crypto_hash_sha512 (sk, priv->
d, 32);
345 h_mod_L = gcry_mpi_new (256);
346 gcry_mpi_mod (h_mod_L,
h, L);
348 for (
size_t i = 0; i < 32; i++)
357 d = gcry_mpi_new (256);
358 gcry_mpi_mulm (
d, h_mod_L, a, L);
359 gcry_mpi_release (
h);
360 gcry_mpi_release (a);
361 gcry_mpi_release (L);
362 gcry_mpi_release (h_mod_L);
363 gcry_ctx_release (
ctx);
372 crypto_hash_sha256_state hs;
373 crypto_hash_sha256_init (&hs);
374 crypto_hash_sha256_update (&hs, sk + 32, 32);
375 crypto_hash_sha256_update (&hs, (
unsigned char*) &hc,
sizeof (hc));
376 crypto_hash_sha256_final (&hs,
result->s + 32);
379 for (
size_t i = 0; i < 32; i++)
382 sodium_memzero (
dc,
sizeof(
dc));
383 gcry_mpi_release (
d);
408 q_y = gcry_mpi_set_opaque_copy (NULL,
pub->
q_y, 8 *
sizeof(
pub->
q_y));
411 gcry_mpi_release (q_y);
412 q = gcry_mpi_ec_get_point (
"q",
ctx, 0);
419 n = gcry_mpi_ec_get_mpi (
"n",
ctx, 1);
420 h_mod_n = gcry_mpi_new (256);
421 gcry_mpi_mod (h_mod_n,
h, n);
424 v = gcry_mpi_point_new (0);
425 gcry_mpi_ec_mul (v, h_mod_n,
q,
ctx);
426 gcry_mpi_release (h_mod_n);
427 gcry_mpi_release (
h);
428 gcry_mpi_release (n);
429 gcry_mpi_point_release (
q);
433 gcry_mpi_point_release (v);
434 q_y = gcry_mpi_ec_get_mpi (
"q@eddsa",
ctx, 0);
437 gcry_mpi_release (q_y);
438 gcry_ctx_release (
ctx);
448 unsigned char sk[32];
450 memcpy (sk, priv->
s, 32);
456 crypto_scalarmult_ed25519_base_noclamp (
pkey->q_y,
static void derive_h(const void *pub, size_t pubsize, const char *label, const char *context, struct GNUNET_HashCode *hc)
Derive the 'h' value for key derivation, where 'h = H(l,P)'.
static mp_limb_t d[(((256)+GMP_NUMB_BITS - 1)/GMP_NUMB_BITS)]
static struct GNUNET_ARM_Handle * h
Connection with ARM.
static int ret
Final status code.
struct GNUNET_HashCode key
The key used in the DHT.
static struct GNUNET_FS_Handle * ctx
static struct GNUNET_FS_DownloadContext * dc
static pa_context * context
Pulseaudio context.
static char * pkey
Public key of the zone to look in, in ASCII.
static char * res
Currently read line or NULL on EOF.
static int result
Global testing status.
static struct GNUNET_REVOCATION_Query * q
Handle for revocation query.
static struct GNUNET_CRYPTO_EddsaPublicKey pub
static struct GNUNET_CRYPTO_PowSalt salt
Salt for PoW calculations.
void GNUNET_CRYPTO_ecdsa_public_key_derive(const struct GNUNET_CRYPTO_EcdsaPublicKey *pub, const char *label, const char *context, struct GNUNET_CRYPTO_EcdsaPublicKey *result)
Derive a public key from a given public key and a label.
struct GNUNET_CRYPTO_EcdsaPrivateKey * GNUNET_CRYPTO_ecdsa_private_key_derive(const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, const char *label, const char *context)
Derive a private key from a given private key and a label.
void GNUNET_CRYPTO_eddsa_private_key_derive(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, const char *label, const char *context, struct GNUNET_CRYPTO_EddsaPrivateScalar *result)
Derive a private scalar from a given private key and a label.
void GNUNET_CRYPTO_eddsa_key_get_public(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Extract the public key for the given private key.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecdsa_sign_(const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, struct GNUNET_CRYPTO_EcdsaSignature *sig)
ECDSA Sign a given block.
void GNUNET_CRYPTO_eddsa_public_key_derive(const struct GNUNET_CRYPTO_EddsaPublicKey *pub, const char *label, const char *context, struct GNUNET_CRYPTO_EddsaPublicKey *result)
Derive a public key from a given public key and a label.
void GNUNET_CRYPTO_ecdsa_key_get_public(const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
Extract the public key for the given private key.
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_mpi_scan_unsigned(gcry_mpi_t *result, const void *data, size_t size)
Convert data buffer into MPI value.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_sign_derived(const struct GNUNET_CRYPTO_EddsaPrivateKey *pkey, const char *label, const char *context, const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, struct GNUNET_CRYPTO_EddsaSignature *sig)
This is a signature function for EdDSA which takes a private key and derives it using the label and c...
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecdsa_sign_derived(const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, const char *label, const char *context, const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, struct GNUNET_CRYPTO_EcdsaSignature *sig)
This is a signature function for ECDSA which takes a private key, derives/blinds it and signs the mes...
void GNUNET_CRYPTO_mpi_print_unsigned(void *buf, size_t size, gcry_mpi_t val)
Output the given MPI value to the given buffer in network byte order.
void GNUNET_CRYPTO_eddsa_key_get_public_from_scalar(const struct GNUNET_CRYPTO_EddsaPrivateScalar *priv, struct GNUNET_CRYPTO_EddsaPublicKey *pkey)
Extract the public key of the given private scalar.
GNUNET_GenericReturnValue
Named constants for return values.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
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 (!...
Private ECC key encoded for transmission.
unsigned char d[256/8]
d is a value mod n, where n has at most 256 bits.
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and ECDS...
an ECC signature using ECDSA
Private ECC key encoded for transmission.
unsigned char d[256/8]
d is a value mod n, where n has at most 256 bits.
Private ECC scalar encoded for transmission.
unsigned char s[512/8]
s is the expandedprivate 512-bit scalar of a private key.
Public ECC key (always for curve Ed25519) encoded in a format suitable for network transmission and E...
unsigned char q_y[256/8]
Point Q consists of a y-value mod p (256 bits); the x-value is always positive.
an ECC signature using EdDSA.
unsigned char s[256/8]
S value.
unsigned char r[256/8]
R value.