Tor  0.4.7.0-alpha-dev
crypto_cipher.h
Go to the documentation of this file.
1 /* Copyright (c) 2001, Matej Pfajfar.
2  * Copyright (c) 2001-2004, Roger Dingledine.
3  * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
4  * Copyright (c) 2007-2021, The Tor Project, Inc. */
5 /* See LICENSE for licensing information */
6 
7 /**
8  * \file crypto_cipher.h
9  *
10  * \brief Headers for crypto_cipher.c
11  **/
12 
13 #ifndef TOR_CRYPTO_CIPHER_H
14 #define TOR_CRYPTO_CIPHER_H
15 
16 #include "orconfig.h"
17 
18 #include <stdio.h>
19 #include "lib/cc/torint.h"
20 
21 /** Length of our symmetric cipher's keys of 128-bit. */
22 #define CIPHER_KEY_LEN 16
23 /** Length of our symmetric cipher's IV of 128-bit. */
24 #define CIPHER_IV_LEN 16
25 /** Length of our symmetric cipher's keys of 256-bit. */
26 #define CIPHER256_KEY_LEN 32
27 
28 typedef struct aes_cnt_cipher_t crypto_cipher_t;
29 
30 /* environment setup */
31 crypto_cipher_t *crypto_cipher_new(const char *key);
32 crypto_cipher_t *crypto_cipher_new_with_bits(const char *key, int bits);
33 crypto_cipher_t *crypto_cipher_new_with_iv(const char *key, const char *iv);
34 crypto_cipher_t *crypto_cipher_new_with_iv_and_bits(const uint8_t *key,
35  const uint8_t *iv,
36  int bits);
37 void crypto_cipher_free_(crypto_cipher_t *env);
38 #define crypto_cipher_free(c) \
39  FREE_AND_NULL(crypto_cipher_t, crypto_cipher_free_, (c))
40 
41 /* symmetric crypto */
42 const char *crypto_cipher_get_key(crypto_cipher_t *env);
43 
44 int crypto_cipher_encrypt(crypto_cipher_t *env, char *to,
45  const char *from, size_t fromlen);
46 int crypto_cipher_decrypt(crypto_cipher_t *env, char *to,
47  const char *from, size_t fromlen);
48 void crypto_cipher_crypt_inplace(crypto_cipher_t *env, char *d, size_t len);
49 
50 int crypto_cipher_encrypt_with_iv(const char *key,
51  char *to, size_t tolen,
52  const char *from, size_t fromlen);
53 int crypto_cipher_decrypt_with_iv(const char *key,
54  char *to, size_t tolen,
55  const char *from, size_t fromlen);
56 
57 #endif /* !defined(TOR_CRYPTO_CIPHER_H) */
int crypto_cipher_decrypt_with_iv(const char *key, char *to, size_t tolen, const char *from, size_t fromlen)
crypto_cipher_t * crypto_cipher_new(const char *key)
Definition: crypto_cipher.c:65
crypto_cipher_t * crypto_cipher_new_with_bits(const char *key, int bits)
Definition: crypto_cipher.c:54
int crypto_cipher_decrypt(crypto_cipher_t *env, char *to, const char *from, size_t fromlen)
int crypto_cipher_encrypt_with_iv(const char *key, char *to, size_t tolen, const char *from, size_t fromlen)
void crypto_cipher_crypt_inplace(crypto_cipher_t *env, char *d, size_t len)
crypto_cipher_t * crypto_cipher_new_with_iv_and_bits(const uint8_t *key, const uint8_t *iv, int bits)
Definition: crypto_cipher.c:29
int crypto_cipher_encrypt(crypto_cipher_t *env, char *to, const char *from, size_t fromlen)
Definition: crypto_cipher.c:88
void crypto_cipher_free_(crypto_cipher_t *env)
Definition: crypto_cipher.c:73
crypto_cipher_t * crypto_cipher_new_with_iv(const char *key, const char *iv)
Definition: crypto_cipher.c:44
Integer definitions used throughout Tor.