crypto.h 2.2 KB
Newer Older
1
/* Copyright (c) 2001, Matej Pfajfar.
Roger Dingledine's avatar
Roger Dingledine committed
2
 * Copyright (c) 2001-2004, Roger Dingledine.
3
 * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
Nick Mathewson's avatar
Nick Mathewson committed
4
 * Copyright (c) 2007-2018, The Tor Project, Inc. */
5
6
/* See LICENSE for licensing information */

Nick Mathewson's avatar
Nick Mathewson committed
7
/**
8
 * \file crypto.h
Nick Mathewson's avatar
Nick Mathewson committed
9
 *
10
 * \brief Headers for crypto.c
Nick Mathewson's avatar
Nick Mathewson committed
11
12
 **/

13
14
#ifndef TOR_CRYPTO_H
#define TOR_CRYPTO_H
15

16
17
#include "orconfig.h"

18
#include <stdio.h>
19
#include "lib/cc/torint.h"
20
#include "lib/crypt_ops/crypto_rsa.h"
21

22
/** Length of our symmetric cipher's keys of 128-bit. */
23
#define CIPHER_KEY_LEN 16
24
/** Length of our symmetric cipher's IV of 128-bit. */
25
#define CIPHER_IV_LEN 16
26
27
/** Length of our symmetric cipher's keys of 256-bit. */
#define CIPHER256_KEY_LEN 32
28

Nick Mathewson's avatar
Nick Mathewson committed
29
/** Length of encoded public key fingerprints, including space; but not
30
 * including terminating NUL. */
31
32
#define FINGERPRINT_LEN 49

33
typedef struct aes_cnt_cipher crypto_cipher_t;
34
35

/* environment setup */
36
crypto_cipher_t *crypto_cipher_new(const char *key);
37
crypto_cipher_t *crypto_cipher_new_with_bits(const char *key, int bits);
38
crypto_cipher_t *crypto_cipher_new_with_iv(const char *key, const char *iv);
39
40
41
crypto_cipher_t *crypto_cipher_new_with_iv_and_bits(const uint8_t *key,
                                                    const uint8_t *iv,
                                                    int bits);
42
void crypto_cipher_free_(crypto_cipher_t *env);
43
44
#define crypto_cipher_free(c) \
  FREE_AND_NULL(crypto_cipher_t, crypto_cipher_free_, (c))
45
46

/* symmetric crypto */
47
const char *crypto_cipher_get_key(crypto_cipher_t *env);
48

49
int crypto_cipher_encrypt(crypto_cipher_t *env, char *to,
50
                          const char *from, size_t fromlen);
51
int crypto_cipher_decrypt(crypto_cipher_t *env, char *to,
52
                          const char *from, size_t fromlen);
53
void crypto_cipher_crypt_inplace(crypto_cipher_t *env, char *d, size_t len);
54

55
int crypto_cipher_encrypt_with_iv(const char *key,
56
57
                                  char *to, size_t tolen,
                                  const char *from, size_t fromlen);
58
int crypto_cipher_decrypt_with_iv(const char *key,
59
60
61
                                  char *to, size_t tolen,
                                  const char *from, size_t fromlen);

62
#endif /* !defined(TOR_CRYPTO_H) */