Tor  0.4.3.0-alpha-dev
Data Structures | Macros | Functions
crypto_ed25519.h File Reference

Header for crypto_ed25519.c. More...

#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))
 

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)
 
int ed25519_checksig (const ed25519_signature_t *signature, const uint8_t *msg, size_t len, const ed25519_public_key_t *pubkey)
 
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)
 
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.

Function Documentation

◆ ed25519_checksig()

int ed25519_checksig ( const ed25519_signature_t signature,
const uint8_t *  msg,
size_t  len,
const ed25519_public_key_t pubkey 
)

Check whether if signature is a valid signature for the len-byte message in msg made with the key pubkey.

Return 0 if the signature is valid; -1 if it isn't.

Definition at line 327 of file crypto_ed25519.c.

Referenced by ed25519_checksig_batch().

◆ ed25519_checksig_batch()

int ed25519_checksig_batch ( int *  okay_out,
const ed25519_checkable_t checkable,
int  n_checkable 
)

Validate every signature among those in checkable, which contains exactly n_checkable elements. If okay_out is non-NULL, set the i'th element of okay_out to 1 if the i'th element of checkable is valid, and to 0 otherwise. Return 0 if every signature was valid. Otherwise return -N, where N is the number of invalid signatures.

Definition at line 376 of file crypto_ed25519.c.

◆ 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.

Referenced by hs_build_blinded_keypair().

◆ 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.

◆ 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.

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.

◆ 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.

Referenced by build_service_desc_plaintext(), create_intro_circuit_identifier(), and hs_ident_dir_conn_init().

◆ ed25519_pubkey_eq()

int ed25519_pubkey_eq ( const ed25519_public_key_t key1,
const ed25519_public_key_t key2 
)

◆ 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.

◆ 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.

Referenced by ed25519_keypair_blind(), and hs_build_blinded_pubkey().

◆ 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.

◆ 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.

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)

◆ 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.

◆ 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.

◆ 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.

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.

◆ 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.

◆ ed25519_sign_prefixed()

int ed25519_sign_prefixed ( ed25519_signature_t signature_out,
const uint8_t *  msg,
size_t  msg_len,
const char *  prefix_str,
const ed25519_keypair_t keypair 
)

Like ed25519_sign(), but also prefix msg with prefix_str before signing. prefix_str must be a NUL-terminated string.

Definition at line 292 of file crypto_ed25519.c.

◆ 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.