tor  0.4.2.0-alpha-dev
Data Structures | Macros | Typedefs | Functions
crypto_ed25519.h File Reference
#include "lib/testsupport/testsupport.h"
#include "lib/cc/torint.h"
#include "lib/crypt_ops/crypto_curve25519.h"
#include "lib/defs/x25519_sizes.h"

Go to the source code of this file.

Data Structures

struct  ed25519_signature_t
 
struct  ed25519_public_key_t
 
struct  ed25519_secret_key_t
 
struct  ed25519_keypair_t
 
struct  ed25519_checkable_t
 

Macros

#define ed25519_keypair_free(kp)   FREE_AND_NULL(ed25519_keypair_t, ed25519_keypair_free_, (kp))
 

Typedefs

typedef struct ed25519_signature_t ed25519_signature_t
 
typedef struct ed25519_public_key_t ed25519_public_key_t
 
typedef struct ed25519_secret_key_t ed25519_secret_key_t
 
typedef struct ed25519_keypair_t ed25519_keypair_t
 

Functions

int ed25519_secret_key_generate (ed25519_secret_key_t *seckey_out, int extra_strong)
 
int ed25519_secret_key_from_seed (ed25519_secret_key_t *seckey_out, const uint8_t *seed)
 
int ed25519_public_key_generate (ed25519_public_key_t *pubkey_out, const ed25519_secret_key_t *seckey)
 
int ed25519_keypair_generate (ed25519_keypair_t *keypair_out, int extra_strong)
 
int ed25519_sign (ed25519_signature_t *signature_out, const uint8_t *msg, size_t len, const ed25519_keypair_t *key)
 
 MOCK_DECL (int, ed25519_checksig,(const ed25519_signature_t *signature, const uint8_t *msg, size_t len, const ed25519_public_key_t *pubkey))
 
 MOCK_DECL (int, ed25519_sign_prefixed,(ed25519_signature_t *signature_out, const uint8_t *msg, size_t len, const char *prefix_str, const ed25519_keypair_t *keypair))
 
int ed25519_checksig_prefixed (const ed25519_signature_t *signature, const uint8_t *msg, size_t len, const char *prefix_str, const ed25519_public_key_t *pubkey)
 
int ed25519_public_key_is_zero (const ed25519_public_key_t *pubkey)
 
 MOCK_DECL (int, ed25519_checksig_batch,(int *okay_out, const ed25519_checkable_t *checkable, int n_checkable))
 
int ed25519_keypair_from_curve25519_keypair (ed25519_keypair_t *out, int *signbit_out, const curve25519_keypair_t *inp)
 
int ed25519_public_key_from_curve25519_public_key (ed25519_public_key_t *pubkey, const curve25519_public_key_t *pubkey_in, int signbit)
 
int ed25519_keypair_blind (ed25519_keypair_t *out, const ed25519_keypair_t *inp, const uint8_t *param)
 
int ed25519_public_blind (ed25519_public_key_t *out, const ed25519_public_key_t *inp, const uint8_t *param)
 
int ed25519_seckey_write_to_file (const ed25519_secret_key_t *seckey, const char *filename, const char *tag)
 
int ed25519_seckey_read_from_file (ed25519_secret_key_t *seckey_out, char **tag_out, const char *filename)
 
int ed25519_pubkey_write_to_file (const ed25519_public_key_t *pubkey, const char *filename, const char *tag)
 
int ed25519_pubkey_read_from_file (ed25519_public_key_t *pubkey_out, char **tag_out, const char *filename)
 
void ed25519_keypair_free_ (ed25519_keypair_t *kp)
 
int ed25519_pubkey_eq (const ed25519_public_key_t *key1, const ed25519_public_key_t *key2)
 
void ed25519_pubkey_copy (ed25519_public_key_t *dest, const ed25519_public_key_t *src)
 
void ed25519_set_impl_params (int use_donna)
 
void ed25519_init (void)
 
int ed25519_validate_pubkey (const ed25519_public_key_t *pubkey)
 

Detailed Description

Header for crypto_ed25519.c.

Definition in file crypto_ed25519.h.

Typedef Documentation

◆ ed25519_keypair_t

An Ed25519 keypair.

◆ ed25519_public_key_t

An Ed25519 public key

◆ ed25519_secret_key_t

An Ed25519 secret key

◆ ed25519_signature_t

An Ed25519 signature.

Function Documentation

◆ ed25519_checksig_prefixed()

int ed25519_checksig_prefixed ( const ed25519_signature_t signature,
const uint8_t *  msg,
size_t  msg_len,
const char *  prefix_str,
const ed25519_public_key_t pubkey 
)

Like ed2519_checksig(), but also prefix msg with prefix_str before verifying signature. prefix_str must be a NUL-terminated string.

Definition at line 339 of file crypto_ed25519.c.

◆ ed25519_keypair_blind()

int ed25519_keypair_blind ( ed25519_keypair_t out,
const ed25519_keypair_t inp,
const uint8_t *  param 
)

Given an ed25519 keypair in inp, generate a corresponding ed25519 keypair in out, blinded by the corresponding 32-byte input in 'param'.

Tor uses key blinding for the "next-generation" hidden services design: service descriptors are encrypted with a key derived from the service's long-term public key, and then signed with (and stored at a position indexed by) a short-term key derived by blinding the long-term keys.

Return 0 if blinding was successful, else return -1.

Definition at line 514 of file crypto_ed25519.c.

References ed25519_public_blind(), ed25519_public_key_generate(), get_ed_impl(), ed25519_secret_key_t::seckey, and tor_assert().

◆ ed25519_keypair_free_()

void ed25519_keypair_free_ ( ed25519_keypair_t kp)

Release all storage held for kp.

Definition at line 631 of file crypto_ed25519.c.

References memwipe(), and tor_free.

◆ ed25519_keypair_from_curve25519_keypair()

int ed25519_keypair_from_curve25519_keypair ( ed25519_keypair_t out,
int *  signbit_out,
const curve25519_keypair_t inp 
)

Given a curve25519 keypair in inp, generate a corresponding ed25519 keypair in out, and set signbit_out to the sign bit of the X coordinate of the ed25519 key.

NOTE THAT IT IS PROBABLY NOT SAFE TO USE THE GENERATED KEY FOR ANYTHING OUTSIDE OF WHAT'S PRESENTED IN PROPOSAL 228. In particular, it's probably not a great idea to use it to sign attacker-supplied anything.

Definition at line 455 of file crypto_ed25519.c.

References crypto_digest512_new(), DIGEST512_LEN, and ed25519_secret_key_t::seckey.

Referenced by make_ntor_onion_key_crosscert().

◆ ed25519_keypair_generate()

int ed25519_keypair_generate ( ed25519_keypair_t keypair_out,
int  extra_strong 
)

Generate a new ed25519 keypair in keypair_out. If extra_strong is set, try to mix some system entropy into the key generation process. Return 0 on success, -1 on failure.

Definition at line 214 of file crypto_ed25519.c.

References ed25519_public_key_generate(), and ed25519_secret_key_generate().

◆ ed25519_pubkey_copy()

void ed25519_pubkey_copy ( ed25519_public_key_t dest,
const ed25519_public_key_t src 
)

Set dest to contain the same key as src.

Definition at line 654 of file crypto_ed25519.c.

References tor_assert().

◆ ed25519_pubkey_eq()

int ed25519_pubkey_eq ( const ed25519_public_key_t key1,
const ed25519_public_key_t key2 
)

Return true iff key1 and key2 are the same public key.

Definition at line 642 of file crypto_ed25519.c.

References tor_assert(), and tor_memeq().

Referenced by dirserv_orconn_tls_done(), and node_ed25519_id_matches().

◆ ed25519_pubkey_read_from_file()

int ed25519_pubkey_read_from_file ( ed25519_public_key_t pubkey_out,
char **  tag_out,
const char *  filename 
)

Store pubkey unencrypted to filename, marking it with tag. Return 0 on success, -1 on failure.

Definition at line 610 of file crypto_ed25519.c.

References crypto_read_tagged_contents_from_file(), and tor_free.

◆ ed25519_pubkey_write_to_file()

int ed25519_pubkey_write_to_file ( const ed25519_public_key_t pubkey,
const char *  filename,
const char *  tag 
)

Store pubkey unencrypted to filename, marking it with tag. Return 0 on success, -1 on failure.

Definition at line 594 of file crypto_ed25519.c.

◆ ed25519_public_blind()

int ed25519_public_blind ( ed25519_public_key_t out,
const ed25519_public_key_t inp,
const uint8_t *  param 
)

Given an ed25519 public key in inp, generate a corresponding blinded public key in out, blinded with the 32-byte parameter in param. Return 0 on success, -1 on railure.

Definition at line 541 of file crypto_ed25519.c.

References get_ed_impl().

Referenced by ed25519_keypair_blind().

◆ ed25519_public_key_from_curve25519_public_key()

int ed25519_public_key_from_curve25519_public_key ( ed25519_public_key_t pubkey,
const curve25519_public_key_t pubkey_in,
int  signbit 
)

Given a curve25519 public key and sign bit of X coordinate of the ed25519 public key, generate the corresponding ed25519 public key.

Definition at line 493 of file crypto_ed25519.c.

References get_ed_impl().

◆ ed25519_public_key_generate()

int ed25519_public_key_generate ( ed25519_public_key_t pubkey_out,
const ed25519_secret_key_t seckey 
)

Given a secret key in seckey, expand it into an ed25519 public key. Return 0 on success, -1 on failure.

Definition at line 202 of file crypto_ed25519.c.

References get_ed_impl(), and ed25519_secret_key_t::seckey.

Referenced by ed25519_keypair_blind(), and ed25519_keypair_generate().

◆ ed25519_public_key_is_zero()

int ed25519_public_key_is_zero ( const ed25519_public_key_t pubkey)

Return true iff 'pubkey' is set to zero (eg to indicate that it is not set).

Definition at line 227 of file crypto_ed25519.c.

References safe_mem_is_zero().

Referenced by connection_or_client_learned_peer_id(), dirserv_orconn_tls_done(), learned_router_identity(), node_add_to_ed25519_map(), node_ed25519_id_matches(), and node_remove_from_ed25519_map().

◆ ed25519_seckey_read_from_file()

int ed25519_seckey_read_from_file ( ed25519_secret_key_t seckey_out,
char **  tag_out,
const char *  filename 
)

Read seckey unencrypted from filename, storing it into seckey_out. Set *tag_out to the tag it was marked with. Return 0 on success, -1 on failure.

Definition at line 570 of file crypto_ed25519.c.

References crypto_read_tagged_contents_from_file(), ed25519_secret_key_t::seckey, and tor_free.

◆ ed25519_seckey_write_to_file()

int ed25519_seckey_write_to_file ( const ed25519_secret_key_t seckey,
const char *  filename,
const char *  tag 
)

Store seckey unencrypted to filename, marking it with tag. Return 0 on success, -1 on failure.

Definition at line 553 of file crypto_ed25519.c.

◆ ed25519_secret_key_from_seed()

int ed25519_secret_key_from_seed ( ed25519_secret_key_t seckey_out,
const uint8_t *  seed 
)

Given a 32-byte random seed in seed, expand it into an ed25519 secret key in seckey_out. Return 0 on success, -1 on failure.

Definition at line 189 of file crypto_ed25519.c.

References get_ed_impl(), and ed25519_secret_key_t::seckey.

◆ ed25519_secret_key_generate()

int ed25519_secret_key_generate ( ed25519_secret_key_t seckey_out,
int  extra_strong 
)

Initialize a new ed25519 secret key in seckey_out. If extra_strong, take the RNG inputs directly from the operating system. Return 0 on success, -1 on failure.

Definition at line 168 of file crypto_ed25519.c.

References crypto_strongest_rand(), get_ed_impl(), memwipe(), and ed25519_secret_key_t::seckey.

Referenced by ed25519_keypair_generate().

◆ ed25519_set_impl_params()

void ed25519_set_impl_params ( int  use_donna)

Force the Ed25519 implementation to a given one, without sanity checking the output. Used for testing.

Definition at line 746 of file crypto_ed25519.c.

References ed25519_impl, impl_donna, and impl_ref10.

◆ ed25519_sign()

int ed25519_sign ( ed25519_signature_t signature_out,
const uint8_t *  msg,
size_t  len,
const ed25519_keypair_t keypair 
)

Set signature_out to a signature of the len-byte message msg, using the secret and public key in keypair.

Return 0 if we successfully signed the message, otherwise return -1.

Definition at line 271 of file crypto_ed25519.c.

References get_ed_impl(), and ed25519_secret_key_t::seckey.

◆ ed25519_validate_pubkey()

int ed25519_validate_pubkey ( const ed25519_public_key_t pubkey)

Validate pubkey to ensure that it has no torsion component. Return 0 if pubkey is valid, else return -1.

Definition at line 796 of file crypto_ed25519.c.