Data Structures | Typedefs | Functions
crypto_curve25519.h File Reference
#include "lib/testsupport/testsupport.h"
#include "lib/cc/torint.h"
#include "lib/crypt_ops/crypto_digest.h"
#include "lib/crypt_ops/crypto_openssl_mgt.h"
#include "lib/defs/x25519_sizes.h"

Go to the source code of this file.

Data Structures

struct  curve25519_public_key_t
struct  curve25519_secret_key_t
struct  curve25519_keypair_t


typedef struct curve25519_public_key_t curve25519_public_key_t
typedef struct curve25519_secret_key_t curve25519_secret_key_t
typedef struct curve25519_keypair_t curve25519_keypair_t


int curve25519_public_key_is_ok (const curve25519_public_key_t *)
int curve25519_secret_key_generate (curve25519_secret_key_t *key_out, int extra_strong)
void curve25519_public_key_generate (curve25519_public_key_t *key_out, const curve25519_secret_key_t *seckey)
int curve25519_keypair_generate (curve25519_keypair_t *keypair_out, int extra_strong)
void curve25519_handshake (uint8_t *output, const curve25519_secret_key_t *, const curve25519_public_key_t *)
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_rand_seckey_bytes (uint8_t *out, int extra_strong)
int curve25519_public_from_base64 (curve25519_public_key_t *pkey, const char *input)
void curve25519_public_to_base64 (char *output, const curve25519_public_key_t *pkey)
void curve25519_set_impl_params (int use_ed)
void curve25519_init (void)

Detailed Description

Header for crypto_curve25519.c.

Definition in file crypto_curve25519.h.

Typedef Documentation

◆ curve25519_keypair_t

A paired public and private key for curve25519.

◆ curve25519_public_key_t

Wrapper type for a curve25519 public key.

(We define a separate type for these to make it less likely that we'll mistake them for secret keys.)

◆ curve25519_secret_key_t

Wrapper type for a curve25519 secret key

(We define a separate type for these to make it less likely that we'll mistake them for public keys.)

Function Documentation

◆ curve25519_handshake()

void curve25519_handshake ( uint8_t *  output,
const curve25519_secret_key_t skey,
const curve25519_public_key_t pkey 

Perform the curve25519 ECDH handshake with skey and pkey, writing CURVE25519_OUTPUT_LEN bytes of output into output.

Definition at line 268 of file crypto_curve25519.c.

References curve25519_impl().

◆ curve25519_init()

void curve25519_init ( void  )

Initialize the curve25519 implementations. This is necessary if you're going to use them in a multithreaded setting, and not otherwise.

Definition at line 363 of file crypto_curve25519.c.

References pick_curve25519_basepoint_impl().

◆ curve25519_keypair_generate()

int curve25519_keypair_generate ( curve25519_keypair_t keypair_out,
int  extra_strong 

Construct a new keypair in *keypair_out. If extra_strong is true, this key is possibly going to get used more than once, so use a better-than-usual RNG. Return 0 on success, -1 on failure.

Definition at line 190 of file crypto_curve25519.c.

References curve25519_public_key_generate(), and curve25519_secret_key_generate().

◆ curve25519_keypair_read_from_file()

int curve25519_keypair_read_from_file ( curve25519_keypair_t keypair_out,
char **  tag_out,
const char *  fname 

Read a curve25519 keypair from a file named fname created by curve25519_keypair_write_to_file(). Store the keypair in keypair_out, and the associated tag string in tag_out. Return 0 on success, and -1 on failure.

Definition at line 233 of file crypto_curve25519.c.

References crypto_read_tagged_contents_from_file(), CURVE25519_PUBKEY_LEN, curve25519_public_key_generate(), and CURVE25519_SECKEY_LEN.

◆ curve25519_keypair_write_to_file()

int curve25519_keypair_write_to_file ( const curve25519_keypair_t keypair,
const char *  fname,
const char *  tag 

Store the keypair keypair, including its secret and public parts, to the file fname. Use the string tag tag to distinguish this from other Curve25519 keypairs. Return 0 on success, -1 on failure.

See crypto_write_tagged_contents_to_file() for more information on the metaformat used for these keys.

Definition at line 207 of file crypto_curve25519.c.

◆ curve25519_public_from_base64()

int curve25519_public_from_base64 ( curve25519_public_key_t pkey,
const char *  input 

Try to decode a base64-encoded curve25519 public key from input into the object at pkey. Return 0 on success, -1 on failure. Accepts keys with or without a trailing "=".

Definition at line 161 of file crypto_format.c.

◆ curve25519_public_key_generate()

void curve25519_public_key_generate ( curve25519_public_key_t key_out,
const curve25519_secret_key_t seckey 

Given a secret key in seckey, create the corresponding public key in key_out.

Definition at line 179 of file crypto_curve25519.c.

References curve25519_basepoint_impl().

Referenced by curve25519_keypair_generate(), and curve25519_keypair_read_from_file().

◆ curve25519_public_key_is_ok()

int curve25519_public_key_is_ok ( const curve25519_public_key_t key)

Return true iff a curve25519_public_key_t seems valid. (It's not necessary to see if the point is on the curve, since the twist is also secure, but we do need to make sure that it isn't the point at infinity.)

Definition at line 132 of file crypto_curve25519.c.

References CURVE25519_PUBKEY_LEN, and safe_mem_is_zero().

◆ curve25519_public_to_base64()

void curve25519_public_to_base64 ( char *  output,
const curve25519_public_key_t pkey 

Encode pkey as a base64-encoded string, including trailing "=" characters, in the buffer output, which must have at least CURVE25519_BASE64_PADDED_LEN+1 bytes available. Can not fail.

Careful! CURVE25519_BASE64_PADDED_LEN is one byte longer than ED25519_BASE64_LEN.

Definition at line 143 of file crypto_format.c.

References base64_encode(), CURVE25519_PUBKEY_LEN, and tor_assert().

◆ curve25519_rand_seckey_bytes()

int curve25519_rand_seckey_bytes ( uint8_t *  out,
int  extra_strong 

Generate CURVE25519_SECKEY_LEN random bytes in out. If extra_strong is true, this key is possibly going to get used more than once, so use a better-than-usual RNG. Return 0 on success, -1 on failure.

This function does not adjust the output of the RNG at all; the will caller will need to clear or set the appropriate bits to make curve25519 work.

Definition at line 147 of file crypto_curve25519.c.

References crypto_strongest_rand(), and CURVE25519_SECKEY_LEN.

Referenced by curve25519_secret_key_generate().

◆ curve25519_secret_key_generate()

int curve25519_secret_key_generate ( curve25519_secret_key_t key_out,
int  extra_strong 

Generate a new keypair and return the secret key. If extra_strong is true, this key is possibly going to get used more than once, so use a better-than-usual RNG. Return 0 on success, -1 on failure.

Definition at line 161 of file crypto_curve25519.c.

References curve25519_rand_seckey_bytes().

Referenced by curve25519_keypair_generate().

◆ curve25519_set_impl_params()

void curve25519_set_impl_params ( int  use_ed)

Override the decision of whether to use the Ed25519-based basepoint multiply function. Used for testing.

Definition at line 118 of file crypto_curve25519.c.

References curve25519_use_ed.