Tor  0.4.7.0-alpha-dev
crypto_curve25519.h
Go to the documentation of this file.
1 /* Copyright (c) 2012-2021, The Tor Project, Inc. */
2 /* See LICENSE for licensing information */
3 
4 /**
5  * \file crypto_curve25519.h
6  * \brief Header for crypto_curve25519.c
7  **/
8 
9 #ifndef TOR_CRYPTO_CURVE25519_H
10 #define TOR_CRYPTO_CURVE25519_H
11 
12 #include <stdbool.h>
14 #include "lib/cc/torint.h"
17 #include "lib/defs/x25519_sizes.h"
18 
19 /** Wrapper type for a curve25519 public key.
20  *
21  * (We define a separate type for these to make it less likely that we'll
22  * mistake them for secret keys.)
23  * */
24 typedef struct curve25519_public_key_t {
25  uint8_t public_key[CURVE25519_PUBKEY_LEN];
27 
28 /** Wrapper type for a curve25519 secret key
29  *
30  * (We define a separate type for these to make it less likely that we'll
31  * mistake them for public keys.)
32  **/
33 typedef struct curve25519_secret_key_t {
34  uint8_t secret_key[CURVE25519_SECKEY_LEN];
36 
37 /** A paired public and private key for curve25519. **/
38 typedef struct curve25519_keypair_t {
42 
43 /* These functions require that we actually know how to use curve25519 keys.
44  * The other data structures and functions in this header let us parse them,
45  * store them, and move them around.
46  */
47 
49 
51  int extra_strong);
53  const curve25519_secret_key_t *seckey);
55  int extra_strong);
56 
57 void curve25519_handshake(uint8_t *output,
59  const curve25519_public_key_t *);
60 
62  const char *fname,
63  const char *tag);
64 
66  char **tag_out,
67  const char *fname);
68 
69 int curve25519_rand_seckey_bytes(uint8_t *out, int extra_strong);
70 
71 #ifdef CRYPTO_CURVE25519_PRIVATE
72 STATIC int curve25519_impl(uint8_t *output, const uint8_t *secret,
73  const uint8_t *basepoint);
74 
75 STATIC int curve25519_basepoint_impl(uint8_t *output, const uint8_t *secret);
76 #endif /* defined(CRYPTO_CURVE25519_PRIVATE) */
77 
79  const char *input);
80 void curve25519_public_to_base64(char *output,
81  const curve25519_public_key_t *pkey,
82  bool pad);
83 
84 void curve25519_set_impl_params(int use_ed);
85 void curve25519_init(void);
86 
87 #endif /* !defined(TOR_CRYPTO_CURVE25519_H) */
STATIC int curve25519_impl(uint8_t *output, const uint8_t *secret, const uint8_t *point)
STATIC int curve25519_basepoint_impl(uint8_t *output, const uint8_t *secret)
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)
int curve25519_public_from_base64(curve25519_public_key_t *pkey, const char *input)
int curve25519_rand_seckey_bytes(uint8_t *out, int extra_strong)
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)
void curve25519_public_to_base64(char *output, const curve25519_public_key_t *pkey, bool pad)
void curve25519_init(void)
void curve25519_handshake(uint8_t *output, const curve25519_secret_key_t *, const curve25519_public_key_t *)
void curve25519_set_impl_params(int use_ed)
Headers for crypto_digest.c.
Headers for crypto_openssl_mgt.c.
Macros to implement mocking and selective exposure for the test code.
#define STATIC
Definition: testsupport.h:32
Integer definitions used throughout Tor.
Definitions for sizes of x25519 keys and elements.
#define CURVE25519_PUBKEY_LEN
Definition: x25519_sizes.h:20
#define CURVE25519_SECKEY_LEN
Definition: x25519_sizes.h:22