tor

The Tor anonymity network
git clone https://git.dasho.dev/tor.git
Log | Files | Refs | README | LICENSE

crypto_curve25519.h (3133B)


      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>
     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"
     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];
     26 } curve25519_public_key_t;
     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];
     35 } curve25519_secret_key_t;
     36 
     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;
     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 
     48 int curve25519_public_key_is_ok(const curve25519_public_key_t *);
     49 
     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);
     56 
     57 void curve25519_handshake(uint8_t *output,
     58                          const curve25519_secret_key_t *,
     59                          const curve25519_public_key_t *);
     60 
     61 int curve25519_keypair_write_to_file(const curve25519_keypair_t *keypair,
     62                                     const char *fname,
     63                                     const char *tag);
     64 
     65 int curve25519_keypair_read_from_file(curve25519_keypair_t *keypair_out,
     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 
     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);
     83 
     84 void curve25519_set_impl_params(int use_ed);
     85 void curve25519_init(void);
     86 
     87 #endif /* !defined(TOR_CRYPTO_CURVE25519_H) */