Tor 0.4.9.0-alpha-dev
Macros | Typedefs | Functions
crypto_cipher.h File Reference

Headers for crypto_cipher.c. More...

#include "orconfig.h"
#include <stdio.h>
#include "lib/cc/torint.h"

Go to the source code of this file.

Macros

#define CIPHER_KEY_LEN   16
 
#define CIPHER_IV_LEN   16
 
#define CIPHER256_KEY_LEN   32
 
#define crypto_cipher_free(c)    FREE_AND_NULL(crypto_cipher_t, crypto_cipher_free_, (c))
 

Typedefs

typedef struct aes_cnt_cipher_t crypto_cipher_t
 

Functions

crypto_cipher_t * crypto_cipher_new (const char *key)
 
crypto_cipher_t * crypto_cipher_new_with_bits (const char *key, int bits)
 
crypto_cipher_t * crypto_cipher_new_with_iv (const char *key, const char *iv)
 
crypto_cipher_t * crypto_cipher_new_with_iv_and_bits (const uint8_t *key, const uint8_t *iv, int bits)
 
void crypto_cipher_free_ (crypto_cipher_t *env)
 
const char * crypto_cipher_get_key (crypto_cipher_t *env)
 
int crypto_cipher_encrypt (crypto_cipher_t *env, char *to, const char *from, size_t fromlen)
 
int crypto_cipher_decrypt (crypto_cipher_t *env, char *to, const char *from, size_t fromlen)
 
void crypto_cipher_crypt_inplace (crypto_cipher_t *env, char *d, size_t len)
 
int crypto_cipher_encrypt_with_iv (const char *key, char *to, size_t tolen, const char *from, size_t fromlen)
 
int crypto_cipher_decrypt_with_iv (const char *key, char *to, size_t tolen, const char *from, size_t fromlen)
 

Detailed Description

Headers for crypto_cipher.c.

Definition in file crypto_cipher.h.

Macro Definition Documentation

◆ CIPHER256_KEY_LEN

#define CIPHER256_KEY_LEN   32

Length of our symmetric cipher's keys of 256-bit.

Definition at line 26 of file crypto_cipher.h.

◆ CIPHER_IV_LEN

#define CIPHER_IV_LEN   16

Length of our symmetric cipher's IV of 128-bit.

Definition at line 24 of file crypto_cipher.h.

◆ CIPHER_KEY_LEN

#define CIPHER_KEY_LEN   16

Length of our symmetric cipher's keys of 128-bit.

Definition at line 22 of file crypto_cipher.h.

◆ crypto_cipher_free

#define crypto_cipher_free (   c)     FREE_AND_NULL(crypto_cipher_t, crypto_cipher_free_, (c))

Definition at line 38 of file crypto_cipher.h.

Typedef Documentation

◆ crypto_cipher_t

typedef struct aes_cnt_cipher_t crypto_cipher_t

Definition at line 28 of file crypto_cipher.h.

Function Documentation

◆ crypto_cipher_crypt_inplace()

void crypto_cipher_crypt_inplace ( crypto_cipher_t *  env,
char *  buf,
size_t  len 
)

Encrypt len bytes on from using the cipher in env; on success. Does not check for failure.

Definition at line 125 of file crypto_cipher.c.

Referenced by relay_crypt_one_payload().

◆ crypto_cipher_decrypt()

int crypto_cipher_decrypt ( crypto_cipher_t *  env,
char *  to,
const char *  from,
size_t  fromlen 
)

Decrypt fromlen bytes from from using the cipher env; on success, store the result to to and return 0. Does not check for failure.

Definition at line 108 of file crypto_cipher.c.

◆ crypto_cipher_decrypt_with_iv()

int crypto_cipher_decrypt_with_iv ( const char *  key,
char *  to,
size_t  tolen,
const char *  from,
size_t  fromlen 
)

Decrypt fromlen bytes (at least 1+CIPHER_IV_LEN) from from with the key in key to the buffer in to of length tolen. tolen must be at least fromlen minus CIPHER_IV_LEN bytes for the initialization vector. On success, return the number of bytes written, on failure, return -1.

Definition at line 170 of file crypto_cipher.c.

◆ crypto_cipher_encrypt()

int crypto_cipher_encrypt ( crypto_cipher_t *  env,
char *  to,
const char *  from,
size_t  fromlen 
)

Encrypt fromlen bytes from from using the cipher env; on success, store the result to to and return 0. Does not check for failure.

Definition at line 88 of file crypto_cipher.c.

Referenced by crypto_cipher_decrypt_with_iv(), and crypto_cipher_encrypt_with_iv().

◆ crypto_cipher_encrypt_with_iv()

int crypto_cipher_encrypt_with_iv ( const char *  key,
char *  to,
size_t  tolen,
const char *  from,
size_t  fromlen 
)

Encrypt fromlen bytes (at least 1) from from with the key in key to the buffer in to of length tolen. tolen must be at least fromlen plus CIPHER_IV_LEN bytes for the initialization vector. On success, return the number of bytes written, on failure, return -1.

Definition at line 138 of file crypto_cipher.c.

◆ crypto_cipher_free_()

void crypto_cipher_free_ ( crypto_cipher_t *  env)

Free a symmetric cipher.

Definition at line 73 of file crypto_cipher.c.

◆ crypto_cipher_new()

crypto_cipher_t * crypto_cipher_new ( const char *  key)

Return a new crypto_cipher_t with the provided key (of CIPHER_KEY_LEN bytes) and an IV of all zero bytes.

Definition at line 65 of file crypto_cipher.c.

Referenced by crypto_pk_obsolete_public_hybrid_encrypt().

◆ crypto_cipher_new_with_bits()

crypto_cipher_t * crypto_cipher_new_with_bits ( const char *  key,
int  bits 
)

Return a new crypto_cipher_t with the provided key and an IV of all zero bytes and key length bits. Key length must be 128, 192, or

Definition at line 54 of file crypto_cipher.c.

Referenced by crypto_cipher_new(), and decrypt_introduce2().

◆ crypto_cipher_new_with_iv()

crypto_cipher_t * crypto_cipher_new_with_iv ( const char *  key,
const char *  iv 
)

Allocate and return a new symmetric cipher using the provided key and iv. The key is CIPHER_KEY_LEN bytes; the IV is CIPHER_IV_LEN bytes. Both must be provided.

Definition at line 44 of file crypto_cipher.c.

Referenced by crypto_cipher_decrypt_with_iv(), and crypto_cipher_encrypt_with_iv().

◆ crypto_cipher_new_with_iv_and_bits()

crypto_cipher_t * crypto_cipher_new_with_iv_and_bits ( const uint8_t *  key,
const uint8_t *  iv,
int  bits 
)

Allocate and return a new symmetric cipher using the provided key and iv. The key is bits bits long; the IV is CIPHER_IV_LEN bytes. Both must be provided. Key length must be 128, 192, or 256

Definition at line 29 of file crypto_cipher.c.

Referenced by cipher_from_seed(), crypto_cipher_new_with_bits(), crypto_cipher_new_with_iv(), and ope_get_cipher().