Tor 0.4.9.2-alpha-dev
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
Macros | Functions | Variables
aes_openssl.c File Reference

Use OpenSSL to implement AES_CTR. More...

#include "orconfig.h"
#include "lib/crypt_ops/aes.h"
#include "lib/crypt_ops/crypto_util.h"
#include "lib/log/util_bug.h"
#include "lib/arch/bytes.h"
#include "lib/crypt_ops/compat_openssl.h"
#include <openssl/opensslv.h>
#include "lib/crypt_ops/crypto_openssl_mgt.h"
#include <stdlib.h>
#include <string.h>
#include <openssl/aes.h>
#include <openssl/evp.h>
#include <openssl/engine.h>
#include <openssl/modes.h>
#include "lib/log/log.h"
#include "lib/ctime/di_ops.h"

Go to the source code of this file.

Macros

#define USE_AES_RAW
 
#define TOR_AES_PRIVATE
 
#define RESOLVE_CIPHER(c)    EVP_CIPHER_fetch(NULL, OBJ_nid2sn(EVP_CIPHER_get_nid(c)), "")
 
#define INIT_CIPHERS()
 
#define aes_raw_free(cipher)    FREE_AND_NULL(aes_raw_t, aes_raw_free_, (cipher))
 

Functions

static void init_ciphers (void)
 
aes_cnt_cipher_taes_new_cipher (const uint8_t *key, const uint8_t *iv, int key_bits)
 
void aes_cipher_free_ (aes_cnt_cipher_t *cipher_)
 
void aes_cipher_set_key (aes_cnt_cipher_t *cipher_, const uint8_t *key, int key_bits)
 
void aes_cipher_set_iv_aligned (aes_cnt_cipher_t *cipher_, const uint8_t *iv)
 
void aes_crypt_inplace (aes_cnt_cipher_t *cipher_, char *data, size_t len)
 
aes_raw_t * aes_raw_new (const uint8_t *key, int key_bits, bool encrypt)
 
void aes_raw_set_key (aes_raw_t **cipher_, const uint8_t *key, int key_bits, bool encrypt)
 
void aes_raw_free_ (aes_raw_t *cipher_)
 
void aes_raw_encrypt (const aes_raw_t *cipher, uint8_t *block)
 
void aes_raw_decrypt (const aes_raw_t *cipher, uint8_t *block)
 

Variables

static const EVP_CIPHER * aes128ctr = NULL
 
static const EVP_CIPHER * aes192ctr = NULL
 
static const EVP_CIPHER * aes256ctr = NULL
 
static const EVP_CIPHER * aes128ecb = NULL
 
static const EVP_CIPHER * aes192ecb = NULL
 
static const EVP_CIPHER * aes256ecb = NULL
 

Detailed Description

Use OpenSSL to implement AES_CTR.

Definition in file aes_openssl.c.

Macro Definition Documentation

◆ aes_raw_free

#define aes_raw_free (   cipher)     FREE_AND_NULL(aes_raw_t, aes_raw_free_, (cipher))

Definition at line 252 of file aes_openssl.c.

◆ INIT_CIPHERS

#define INIT_CIPHERS ( )
Value:
STMT_BEGIN { \
if (PREDICT_UNLIKELY(NULL == aes128ctr)) { \
init_ciphers(); \
} \
} STMT_END

Definition at line 76 of file aes_openssl.c.

◆ RESOLVE_CIPHER

#define RESOLVE_CIPHER (   c)     EVP_CIPHER_fetch(NULL, OBJ_nid2sn(EVP_CIPHER_get_nid(c)), "")

Definition at line 57 of file aes_openssl.c.

◆ TOR_AES_PRIVATE

#define TOR_AES_PRIVATE

Definition at line 13 of file aes_openssl.c.

◆ USE_AES_RAW

#define USE_AES_RAW

Definition at line 12 of file aes_openssl.c.

Function Documentation

◆ aes_cipher_free_()

void aes_cipher_free_ ( aes_cnt_cipher_t cipher_)

Definition at line 119 of file aes_openssl.c.

◆ aes_cipher_set_iv_aligned()

void aes_cipher_set_iv_aligned ( aes_cnt_cipher_t cipher_,
const uint8_t *  iv 
)

Change the IV of this stream cipher without changing the key.

Requires that the cipher stream position is at an even multiple of 16 bytes.

Definition at line 153 of file aes_openssl.c.

Referenced by cgo_prf_xor_t0().

◆ aes_cipher_set_key()

void aes_cipher_set_key ( aes_cnt_cipher_t cipher_,
const uint8_t *  key,
int  key_bits 
)

Changes the key of the cipher; sets the IV to 0.

Definition at line 132 of file aes_openssl.c.

Referenced by cgo_prf_set_key().

◆ aes_crypt_inplace()

void aes_crypt_inplace ( aes_cnt_cipher_t cipher_,
char *  data,
size_t  len 
)

Definition at line 166 of file aes_openssl.c.

◆ aes_new_cipher()

aes_cnt_cipher_t * aes_new_cipher ( const uint8_t *  key,
const uint8_t *  iv,
int  key_bits 
)

Definition at line 104 of file aes_openssl.c.

◆ aes_raw_decrypt()

void aes_raw_decrypt ( const aes_raw_t *  cipher,
uint8_t *  block 
)

Decrypt a single 16-byte block with 'cipher', which must have been initialized for decryption.

Definition at line 271 of file aes_openssl.c.

Referenced by cgo_et_decrypt().

◆ aes_raw_encrypt()

void aes_raw_encrypt ( const aes_raw_t *  cipher,
uint8_t *  block 
)

Encrypt a single 16-byte block with 'cipher', which must have been initialized for encryption.

Definition at line 259 of file aes_openssl.c.

Referenced by cgo_et_encrypt().

◆ aes_raw_free_()

void aes_raw_free_ ( aes_raw_t *  cipher_)

Release storage held by 'cipher'.

Definition at line 240 of file aes_openssl.c.

◆ aes_raw_new()

aes_raw_t * aes_raw_new ( const uint8_t *  key,
int  key_bits,
bool  encrypt 
)

Create a new instance of AES using a key of length 'key_bits' for raw block encryption.

This is even more low-level than counter-mode, and you should only use it with extreme caution.

Definition at line 193 of file aes_openssl.c.

Referenced by cgo_et_init().

◆ aes_raw_set_key()

void aes_raw_set_key ( aes_raw_t **  cipher_,
const uint8_t *  key,
int  key_bits,
bool  encrypt 
)

Replace the key on an existing aes_raw_t.

This may be faster than freeing and reallocating.

Definition at line 219 of file aes_openssl.c.

Referenced by cgo_et_set_key().

◆ init_ciphers()

static void init_ciphers ( void  )
static

Pre-fetch the versions of every AES cipher with its associated provider.

Definition at line 67 of file aes_openssl.c.

Variable Documentation

◆ aes128ctr

const EVP_CIPHER* aes128ctr = NULL
static

Definition at line 48 of file aes_openssl.c.

◆ aes128ecb

const EVP_CIPHER* aes128ecb = NULL
static

Definition at line 51 of file aes_openssl.c.

◆ aes192ctr

const EVP_CIPHER* aes192ctr = NULL
static

Definition at line 49 of file aes_openssl.c.

◆ aes192ecb

const EVP_CIPHER* aes192ecb = NULL
static

Definition at line 52 of file aes_openssl.c.

◆ aes256ctr

const EVP_CIPHER* aes256ctr = NULL
static

Definition at line 50 of file aes_openssl.c.

◆ aes256ecb

const EVP_CIPHER* aes256ecb = NULL
static

Definition at line 53 of file aes_openssl.c.