26 #ifndef MBEDTLS_CIPHER_H 27 #define MBEDTLS_CIPHER_H 29 #if !defined(MBEDTLS_CONFIG_FILE) 32 #include MBEDTLS_CONFIG_FILE 37 #if defined(MBEDTLS_GCM_C) || defined(MBEDTLS_CCM_C) 38 #define MBEDTLS_CIPHER_MODE_AEAD 41 #if defined(MBEDTLS_CIPHER_MODE_CBC) 42 #define MBEDTLS_CIPHER_MODE_WITH_PADDING 45 #if defined(MBEDTLS_ARC4_C) 46 #define MBEDTLS_CIPHER_MODE_STREAM 49 #if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \ 50 !defined(inline) && !defined(__cplusplus) 51 #define inline __inline 54 #define MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE -0x6080 55 #define MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA -0x6100 56 #define MBEDTLS_ERR_CIPHER_ALLOC_FAILED -0x6180 57 #define MBEDTLS_ERR_CIPHER_INVALID_PADDING -0x6200 58 #define MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED -0x6280 59 #define MBEDTLS_ERR_CIPHER_AUTH_FAILED -0x6300 60 #define MBEDTLS_ERR_CIPHER_INVALID_CONTEXT -0x6380 62 #define MBEDTLS_CIPHER_VARIABLE_IV_LEN 0x01 63 #define MBEDTLS_CIPHER_VARIABLE_KEY_LEN 0x02 170 #define MBEDTLS_MAX_IV_LENGTH 16 172 #define MBEDTLS_MAX_BLOCK_LENGTH 16 224 #if defined(MBEDTLS_CIPHER_MODE_WITH_PADDING) 226 void (*add_padding)(
unsigned char *output,
size_t olen,
size_t data_len );
227 int (*get_padding)(
unsigned char *input,
size_t ilen,
size_t *data_len );
290 const mbedtls_cipher_mode_t mode );
456 int key_bitlen,
const mbedtls_operation_t operation );
458 #if defined(MBEDTLS_CIPHER_MODE_WITH_PADDING) 488 const unsigned char *iv,
size_t iv_len );
500 #if defined(MBEDTLS_GCM_C) 513 const unsigned char *ad,
size_t ad_len );
546 size_t ilen,
unsigned char *output,
size_t *olen );
566 unsigned char *output,
size_t *olen );
568 #if defined(MBEDTLS_GCM_C) 581 unsigned char *tag,
size_t tag_len );
595 const unsigned char *tag,
size_t tag_len );
626 const unsigned char *iv,
size_t iv_len,
627 const unsigned char *input,
size_t ilen,
628 unsigned char *output,
size_t *olen );
630 #if defined(MBEDTLS_CIPHER_MODE_AEAD) 654 const unsigned char *iv,
size_t iv_len,
655 const unsigned char *ad,
size_t ad_len,
656 const unsigned char *input,
size_t ilen,
657 unsigned char *output,
size_t *olen,
658 unsigned char *tag,
size_t tag_len );
688 const unsigned char *iv,
size_t iv_len,
689 const unsigned char *ad,
size_t ad_len,
690 const unsigned char *input,
size_t ilen,
691 unsigned char *output,
size_t *olen,
692 const unsigned char *tag,
size_t tag_len );
unsigned int iv_size
IV/NONCE size, in bytes.
Key length, in bits (including parity), for DES in two key EDE.
never pad (full blocks only)
static mbedtls_cipher_mode_t mbedtls_cipher_get_cipher_mode(const mbedtls_cipher_context_t *ctx)
Returns the mode of operation for the cipher.
int flags
Flags for variable IV size, variable key size, etc.
static unsigned int mbedtls_cipher_get_block_size(const mbedtls_cipher_context_t *ctx)
Returns the block size of the given cipher.
const mbedtls_cipher_info_t * mbedtls_cipher_info_from_string(const char *cipher_name)
Returns the cipher information structure associated with the given cipher name.
int mbedtls_cipher_finish(mbedtls_cipher_context_t *ctx, unsigned char *output, size_t *olen)
Generic cipher finalisation function.
int mbedtls_cipher_reset(mbedtls_cipher_context_t *ctx)
Finish preparation of the given context.
static const char * mbedtls_cipher_get_name(const mbedtls_cipher_context_t *ctx)
Returns the name of the given cipher, as a string.
Configuration options (set of defines)
int mbedtls_cipher_set_iv(mbedtls_cipher_context_t *ctx, const unsigned char *iv, size_t iv_len)
Set the initialization vector (IV) or nonce.
int mbedtls_cipher_set_padding_mode(mbedtls_cipher_context_t *ctx, mbedtls_cipher_padding_t mode)
Set padding mode, for cipher modes that use padding.
mbedtls_cipher_mode_t mode
Cipher mode (e.g.
int mbedtls_cipher_update(mbedtls_cipher_context_t *ctx, const unsigned char *input, size_t ilen, unsigned char *output, size_t *olen)
Generic cipher update function.
unsigned int block_size
block size, in bytes
void mbedtls_cipher_free(mbedtls_cipher_context_t *ctx)
Free and clear the cipher-specific context of ctx.
static mbedtls_operation_t mbedtls_cipher_get_operation(const mbedtls_cipher_context_t *ctx)
Returns the operation of the given cipher.
const int * mbedtls_cipher_list(void)
Returns the list of ciphers supported by the generic cipher module.
static int mbedtls_cipher_get_key_bitlen(const mbedtls_cipher_context_t *ctx)
Returns the key length of the cipher.
const mbedtls_cipher_info_t * cipher_info
Information about the associated cipher.
zero padding (not reversible!)
struct mbedtls_cipher_base_t mbedtls_cipher_base_t
Base cipher information (opaque struct).
const mbedtls_cipher_info_t * mbedtls_cipher_info_from_values(const mbedtls_cipher_id_t cipher_id, int key_bitlen, const mbedtls_cipher_mode_t mode)
Returns the cipher information structure associated with the given cipher id, key size and mode...
Key length, in bits (including parity), for DES in three-key EDE.
static mbedtls_cipher_type_t mbedtls_cipher_get_type(const mbedtls_cipher_context_t *ctx)
Returns the type of the given cipher.
void * cipher_ctx
Cipher-specific context.
mbedtls_operation_t operation
Operation that the context's key has been initialised for.
int mbedtls_cipher_setkey(mbedtls_cipher_context_t *ctx, const unsigned char *key, int key_bitlen, const mbedtls_operation_t operation)
Set the key to use with the given context.
#define MBEDTLS_MAX_IV_LENGTH
Maximum length of any IV, in bytes.
size_t unprocessed_len
Number of bytes that still need processing.
int mbedtls_cipher_auth_decrypt(mbedtls_cipher_context_t *ctx, const unsigned char *iv, size_t iv_len, const unsigned char *ad, size_t ad_len, const unsigned char *input, size_t ilen, unsigned char *output, size_t *olen, const unsigned char *tag, size_t tag_len)
Generic autenticated decryption (AEAD ciphers).
const char * name
Name of the cipher.
int mbedtls_cipher_auth_encrypt(mbedtls_cipher_context_t *ctx, const unsigned char *iv, size_t iv_len, const unsigned char *ad, size_t ad_len, const unsigned char *input, size_t ilen, unsigned char *output, size_t *olen, unsigned char *tag, size_t tag_len)
Generic autenticated encryption (AEAD ciphers).
int mbedtls_cipher_crypt(mbedtls_cipher_context_t *ctx, const unsigned char *iv, size_t iv_len, const unsigned char *input, size_t ilen, unsigned char *output, size_t *olen)
Generic all-in-one encryption/decryption (for all ciphers except AEAD constructs).
int key_bitlen
Key length to use.
void mbedtls_cipher_init(mbedtls_cipher_context_t *ctx)
Initialize a cipher_context (as NONE)
int mbedtls_cipher_update_ad(mbedtls_cipher_context_t *ctx, const unsigned char *ad, size_t ad_len)
Add additional data (for AEAD ciphers).
int mbedtls_cipher_setup(mbedtls_cipher_context_t *ctx, const mbedtls_cipher_info_t *cipher_info)
Initialises and fills the cipher context structure with the appropriate values.
int mbedtls_cipher_check_tag(mbedtls_cipher_context_t *ctx, const unsigned char *tag, size_t tag_len)
Check tag for AEAD ciphers.
static int mbedtls_cipher_get_iv_size(const mbedtls_cipher_context_t *ctx)
Returns the size of the cipher's IV/NONCE in bytes.
Key length, in bits (including parity), for DES keys.
int mbedtls_cipher_write_tag(mbedtls_cipher_context_t *ctx, unsigned char *tag, size_t tag_len)
Write tag for AEAD ciphers.
size_t iv_size
IV size in bytes (for ciphers with variable-length IVs)
#define MBEDTLS_MAX_BLOCK_LENGTH
Maximum block size of any cipher, in bytes.
unsigned int key_bitlen
Cipher key length, in bits (default length for variable sized ciphers) (Includes parity bits for ciph...
mbedtls_cipher_type_t type
Full cipher identifier (e.g.
const mbedtls_cipher_info_t * mbedtls_cipher_info_from_type(const mbedtls_cipher_type_t cipher_type)
Returns the cipher information structure associated with the given cipher type.
const mbedtls_cipher_base_t * base
Base cipher information and functions.