18 #define CRYPTO_CURVE25519_PRIVATE
20 #ifdef HAVE_SYS_STAT_H
32 #include "ed25519/donna/ed25519_donna_tor.h"
40 #ifdef USE_CURVE25519_DONNA
41 int curve25519_donna(uint8_t *mypublic,
42 const uint8_t *secret,
const uint8_t *basepoint);
44 #ifdef USE_CURVE25519_NACL
45 #ifdef HAVE_CRYPTO_SCALARMULT_CURVE25519_H
46 #include <crypto_scalarmult_curve25519.h>
47 #elif defined(HAVE_NACL_CRYPTO_SCALARMULT_CURVE25519_H)
48 #include <nacl/crypto_scalarmult_curve25519.h>
73 #ifdef USE_CURVE25519_DONNA
74 r = curve25519_donna(output, secret, bp);
75 #elif defined(USE_CURVE25519_NACL)
76 r = crypto_scalarmult_curve25519(output, secret, bp);
78 #error "No implementation of curve25519 is available."
104 curved25519_scalarmult_basepoint_donna(output, secret);
107 static const uint8_t basepoint[32] = {9};
167 key_out->secret_key[0] &= 248;
168 key_out->secret_key[31] &= 127;
169 key_out->secret_key[31] |= 64;
224 memwipe(contents, 0,
sizeof(contents));
242 content,
sizeof(content));
243 if (len !=
sizeof(content))
249 if (
tor_memneq(keypair_out->pubkey.public_key,
257 memwipe(content, 0,
sizeof(content));
259 memset(keypair_out, 0,
sizeof(*keypair_out));
280 static const uint8_t alicesk[32] = {
281 0x77,0x07,0x6d,0x0a,0x73,0x18,0xa5,0x7d,
282 0x3c,0x16,0xc1,0x72,0x51,0xb2,0x66,0x45,
283 0xdf,0x4c,0x2f,0x87,0xeb,0xc0,0x99,0x2a,
284 0xb1,0x77,0xfb,0xa5,0x1d,0xb9,0x2c,0x2a
286 static const uint8_t alicepk[32] = {
287 0x85,0x20,0xf0,0x09,0x89,0x30,0xa7,0x54,
288 0x74,0x8b,0x7d,0xdc,0xb4,0x3e,0xf7,0x5a,
289 0x0d,0xbf,0x3a,0x0d,0x26,0x38,0x1a,0xf4,
290 0xeb,0xa4,0xa9,0x8e,0xaa,0x9b,0x4e,0x6a
292 const int loop_max=8;
294 unsigned char e1[32], e2[32];
295 unsigned char x[32],y[32];
299 memset(x, 0,
sizeof(x));
300 memset(y, 0,
sizeof(y));
301 memset(e1, 0,
sizeof(e1));
302 memset(e2, 0,
sizeof(e2));
319 for (i = 0; i < loop_max; ++i) {
354 "multiplication seems broken; using the curve25519 "
void curve25519_handshake(uint8_t *output, const curve25519_secret_key_t *skey, const curve25519_public_key_t *pkey)
static void pick_curve25519_basepoint_impl(void)
int curve25519_secret_key_generate(curve25519_secret_key_t *key_out, int extra_strong)
int curve25519_rand_seckey_bytes(uint8_t *out, int extra_strong)
static int curve25519_basepoint_spot_check(void)
STATIC int curve25519_impl(uint8_t *output, const uint8_t *secret, const uint8_t *point)
void curve25519_public_key_generate(curve25519_public_key_t *key_out, const curve25519_secret_key_t *seckey)
int curve25519_keypair_write_to_file(const curve25519_keypair_t *keypair, const char *fname, const char *tag)
int curve25519_keypair_read_from_file(curve25519_keypair_t *keypair_out, char **tag_out, const char *fname)
int curve25519_keypair_generate(curve25519_keypair_t *keypair_out, int extra_strong)
int curve25519_public_key_is_ok(const curve25519_public_key_t *key)
void curve25519_init(void)
static int curve25519_use_ed
void curve25519_set_impl_params(int use_ed)
STATIC int curve25519_basepoint_impl(uint8_t *output, const uint8_t *secret)
Header for crypto_curve25519.c.
Headers for crypto_digest.c.
void crypto_rand(char *to, size_t n)
void crypto_strongest_rand(uint8_t *out, size_t out_len)
Common functions for using (pseudo-)random number generators.
void memwipe(void *mem, uint8_t byte, size_t sz)
Common functions for cryptographic routines.
int safe_mem_is_zero(const void *mem, size_t sz)
#define tor_memneq(a, b, sz)
#define fast_memneq(a, b, c)
Macros to manage assertions, fatal and non-fatal.
#define CURVE25519_PUBKEY_LEN
#define CURVE25519_SECKEY_LEN