Add changes file for bug40642.
[tor.git] / src / lib / crypt_ops / crypto_curve25519.h
blob146945fa24d421a3000b4383bfb362a2846b3fe3
1 /* Copyright (c) 2012-2021, The Tor Project, Inc. */
2 /* See LICENSE for licensing information */
4 /**
5 * \file crypto_curve25519.h
6 * \brief Header for crypto_curve25519.c
7 **/
9 #ifndef TOR_CRYPTO_CURVE25519_H
10 #define TOR_CRYPTO_CURVE25519_H
12 #include <stdbool.h>
13 #include "lib/testsupport/testsupport.h"
14 #include "lib/cc/torint.h"
15 #include "lib/crypt_ops/crypto_digest.h"
16 #include "lib/crypt_ops/crypto_openssl_mgt.h"
17 #include "lib/defs/x25519_sizes.h"
19 /** Wrapper type for a curve25519 public key.
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];
26 } curve25519_public_key_t;
28 /** Wrapper type for a curve25519 secret key
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];
35 } curve25519_secret_key_t;
37 /** A paired public and private key for curve25519. **/
38 typedef struct curve25519_keypair_t {
39 curve25519_public_key_t pubkey;
40 curve25519_secret_key_t seckey;
41 } curve25519_keypair_t;
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.
48 int curve25519_public_key_is_ok(const curve25519_public_key_t *);
50 int curve25519_secret_key_generate(curve25519_secret_key_t *key_out,
51 int extra_strong);
52 void curve25519_public_key_generate(curve25519_public_key_t *key_out,
53 const curve25519_secret_key_t *seckey);
54 int curve25519_keypair_generate(curve25519_keypair_t *keypair_out,
55 int extra_strong);
57 void curve25519_handshake(uint8_t *output,
58 const curve25519_secret_key_t *,
59 const curve25519_public_key_t *);
61 int curve25519_keypair_write_to_file(const curve25519_keypair_t *keypair,
62 const char *fname,
63 const char *tag);
65 int curve25519_keypair_read_from_file(curve25519_keypair_t *keypair_out,
66 char **tag_out,
67 const char *fname);
69 int curve25519_rand_seckey_bytes(uint8_t *out, int extra_strong);
71 #ifdef CRYPTO_CURVE25519_PRIVATE
72 STATIC int curve25519_impl(uint8_t *output, const uint8_t *secret,
73 const uint8_t *basepoint);
75 STATIC int curve25519_basepoint_impl(uint8_t *output, const uint8_t *secret);
76 #endif /* defined(CRYPTO_CURVE25519_PRIVATE) */
78 int curve25519_public_from_base64(curve25519_public_key_t *pkey,
79 const char *input);
80 void curve25519_public_to_base64(char *output,
81 const curve25519_public_key_t *pkey,
82 bool pad);
84 void curve25519_set_impl_params(int use_ed);
85 void curve25519_init(void);
87 #endif /* !defined(TOR_CRYPTO_CURVE25519_H) */