sandbox: refactor string-based option-unchanged tests to use a macro
[tor.git] / src / common / crypto_curve25519.h
blob57018ac2f515a5013758e5fa4cc7b1424234daba
1 /* Copyright (c) 2012-2013, The Tor Project, Inc. */
2 /* See LICENSE for licensing information */
4 #ifndef TOR_CRYPTO_CURVE25519_H
5 #define TOR_CRYPTO_CURVE25519_H
7 #include "testsupport.h"
8 #include "torint.h"
10 /** Length of a curve25519 public key when encoded. */
11 #define CURVE25519_PUBKEY_LEN 32
12 /** Length of a curve25519 secret key when encoded. */
13 #define CURVE25519_SECKEY_LEN 32
14 /** Length of the result of a curve25519 handshake. */
15 #define CURVE25519_OUTPUT_LEN 32
17 /** Wrapper type for a curve25519 public key */
18 typedef struct curve25519_public_key_t {
19 uint8_t public_key[CURVE25519_PUBKEY_LEN];
20 } curve25519_public_key_t;
22 /** Wrapper type for a curve25519 secret key */
23 typedef struct curve25519_secret_key_t {
24 uint8_t secret_key[CURVE25519_SECKEY_LEN];
25 } curve25519_secret_key_t;
27 /** A paired public and private key for curve25519. **/
28 typedef struct curve25519_keypair_t {
29 curve25519_public_key_t pubkey;
30 curve25519_secret_key_t seckey;
31 } curve25519_keypair_t;
33 #ifdef CURVE25519_ENABLED
34 /* These functions require that we actually know how to use curve25519 keys.
35 * The other data structures and functions in this header let us parse them,
36 * store them, and move them around.
39 int curve25519_public_key_is_ok(const curve25519_public_key_t *);
41 int curve25519_secret_key_generate(curve25519_secret_key_t *key_out,
42 int extra_strong);
43 void curve25519_public_key_generate(curve25519_public_key_t *key_out,
44 const curve25519_secret_key_t *seckey);
45 int curve25519_keypair_generate(curve25519_keypair_t *keypair_out,
46 int extra_strong);
48 void curve25519_handshake(uint8_t *output,
49 const curve25519_secret_key_t *,
50 const curve25519_public_key_t *);
52 int curve25519_keypair_write_to_file(const curve25519_keypair_t *keypair,
53 const char *fname,
54 const char *tag);
56 int curve25519_keypair_read_from_file(curve25519_keypair_t *keypair_out,
57 char **tag_out,
58 const char *fname);
60 #ifdef CRYPTO_CURVE25519_PRIVATE
61 STATIC int curve25519_impl(uint8_t *output, const uint8_t *secret,
62 const uint8_t *basepoint);
63 #endif
64 #endif
66 #define CURVE25519_BASE64_PADDED_LEN 44
68 int curve25519_public_from_base64(curve25519_public_key_t *pkey,
69 const char *input);
70 int curve25519_public_to_base64(char *output,
71 const curve25519_public_key_t *pkey);
73 #endif