26 #ifndef MBEDTLS_CIPHER_H 27 #define MBEDTLS_CIPHER_H 29 #if !defined(MBEDTLS_CONFIG_FILE) 32 #include MBEDTLS_CONFIG_FILE 39 #if defined(MBEDTLS_GCM_C) || defined(MBEDTLS_CCM_C) 40 #define MBEDTLS_CIPHER_MODE_AEAD 43 #if defined(MBEDTLS_CIPHER_MODE_CBC) 44 #define MBEDTLS_CIPHER_MODE_WITH_PADDING 47 #if defined(MBEDTLS_ARC4_C) 48 #define MBEDTLS_CIPHER_MODE_STREAM 51 #define MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE -0x6080 52 #define MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA -0x6100 53 #define MBEDTLS_ERR_CIPHER_ALLOC_FAILED -0x6180 54 #define MBEDTLS_ERR_CIPHER_INVALID_PADDING -0x6200 55 #define MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED -0x6280 56 #define MBEDTLS_ERR_CIPHER_AUTH_FAILED -0x6300 57 #define MBEDTLS_ERR_CIPHER_INVALID_CONTEXT -0x6380 59 #define MBEDTLS_CIPHER_VARIABLE_IV_LEN 0x01 60 #define MBEDTLS_CIPHER_VARIABLE_KEY_LEN 0x02 167 #define MBEDTLS_MAX_IV_LENGTH 16 169 #define MBEDTLS_MAX_BLOCK_LENGTH 16 226 #if defined(MBEDTLS_CIPHER_MODE_WITH_PADDING) 228 void (*add_padding)(
unsigned char *
output,
size_t olen,
size_t data_len );
229 int (*get_padding)(
unsigned char *
input,
size_t ilen,
size_t *data_len );
247 #if defined(MBEDTLS_CMAC_C) 342 return ctx->cipher_info->block_size;
359 return ctx->cipher_info->mode;
376 if(
ctx->iv_size != 0 )
377 return (
int)
ctx->iv_size;
379 return (
int)
ctx->cipher_info->iv_size;
395 return ctx->cipher_info->type;
410 return ctx->cipher_info->name;
427 return (
int)
ctx->cipher_info->key_bitlen;
444 return ctx->operation;
465 #if defined(MBEDTLS_CIPHER_MODE_WITH_PADDING) 495 const unsigned char *
iv,
size_t iv_len );
507 #if defined(MBEDTLS_GCM_C) 520 const unsigned char *
ad,
size_t ad_len );
553 size_t ilen,
unsigned char *
output,
size_t *olen );
573 unsigned char *
output,
size_t *olen );
575 #if defined(MBEDTLS_GCM_C) 633 const unsigned char *
iv,
size_t iv_len,
634 const unsigned char *
input,
size_t ilen,
635 unsigned char *
output,
size_t *olen );
637 #if defined(MBEDTLS_CIPHER_MODE_AEAD) 661 const unsigned char *
iv,
size_t iv_len,
662 const unsigned char *
ad,
size_t ad_len,
663 const unsigned char *
input,
size_t ilen,
664 unsigned char *
output,
size_t *olen,
695 const unsigned char *
iv,
size_t iv_len,
696 const unsigned char *
ad,
size_t ad_len,
697 const unsigned char *
input,
size_t ilen,
698 unsigned char *
output,
size_t *olen,
#define MBEDTLS_MAX_BLOCK_LENGTH
Definition: cipher.h:169
static INLINE int mbedtls_cipher_get_iv_size(const mbedtls_cipher_context_t *ctx)
Returns the size of the cipher's IV/NONCE in bytes.
Definition: cipher.h:371
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).
Definition: cipher.c:870
static INLINE unsigned int mbedtls_cipher_get_block_size(const mbedtls_cipher_context_t *ctx)
Returns the block size of the given cipher.
Definition: cipher.h:337
mbedtls_cipher_type_t type
Definition: cipher.h:186
unsigned int iv_size
Definition: cipher.h:200
mbedtls_cipher_mode_t mode
Definition: cipher.h:189
GLenum mode
Definition: glext.h:6857
#define INLINE
Definition: retro_inline.h:35
static const unsigned char tag[MAX_TESTS *3][16]
Definition: gcm.c:696
Configuration options (set of defines)
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.
Definition: cipher.c:88
#define MBEDTLS_MAX_IV_LENGTH
Definition: cipher.h:167
mbedtls_cipher_padding_t
Definition: cipher.h:141
static INLINE int mbedtls_cipher_get_key_bitlen(const mbedtls_cipher_context_t *ctx)
Returns the key length of the cipher.
Definition: cipher.h:422
mbedtls_operation_t
Definition: cipher.h:149
static INLINE mbedtls_cipher_mode_t mbedtls_cipher_get_cipher_mode(const mbedtls_cipher_context_t *ctx)
Returns the mode of operation for the cipher. (e.g. MBEDTLS_MODE_CBC)
Definition: cipher.h:354
typedef void(__stdcall *PFN_DESTRUCTION_CALLBACK)(void *pData)
int key_bitlen
Definition: cipher.h:221
int flags
Definition: cipher.h:203
GLenum GLenum GLenum input
Definition: glext.h:9938
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. (Default: PKCS7 padding.)
Definition: cipher.c:703
mbedtls_operation_t operation
Definition: cipher.h:224
void * cipher_ctx
Definition: cipher.h:245
#define NULL
Pointer to 0.
Definition: gctypes.h:65
unsigned int block_size
Definition: cipher.h:206
AVFormatContext * ctx
Definition: record_ffmpeg.c:247
int mbedtls_cipher_finish(mbedtls_cipher_context_t *ctx, unsigned char *output, size_t *olen)
Generic cipher finalisation function. If data still needs to be flushed from an incomplete block,...
Definition: cipher.c:623
int mbedtls_cipher_check_tag(mbedtls_cipher_context_t *ctx, const unsigned char *tag, size_t tag_len)
Check tag for AEAD ciphers. Currently only supported with GCM. Must be called after mbedtls_cipher_fi...
Definition: cipher.c:766
mbedtls_cipher_mode_t
Definition: cipher.h:129
Definition: cipher_internal.h:43
static const unsigned char iv[]
Definition: ccm.c:364
const char * name
Definition: cipher.h:196
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).
Definition: cipher.c:838
static INLINE const char * mbedtls_cipher_get_name(const mbedtls_cipher_context_t *ctx)
Returns the name of the given cipher, as a string.
Definition: cipher.h:405
int mbedtls_cipher_reset(mbedtls_cipher_context_t *ctx)
Finish preparation of the given context.
Definition: cipher.c:240
const mbedtls_cipher_info_t * cipher_info
Definition: cipher.h:218
size_t iv_size
Definition: cipher.h:242
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.
Definition: cipher.c:211
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.
Definition: cipher.c:113
std::string output
Definition: Config.FromFile.cpp:44
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.
Definition: cipher.c:99
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.
Definition: cipher.c:178
const int * mbedtls_cipher_list(void)
Returns the list of ciphers supported by the generic cipher module.
Definition: cipher.c:67
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. Encrypts/decrypts using the given cipher context. Writes as many bloc...
Definition: cipher.c:267
void mbedtls_cipher_init(mbedtls_cipher_context_t *ctx)
Initialize a cipher_context (as NONE)
Definition: cipher.c:128
static const size_t iv_len[NB_TESTS]
Definition: ccm.c:381
int mbedtls_cipher_update_ad(mbedtls_cipher_context_t *ctx, const unsigned char *ad, size_t ad_len)
Add additional data (for AEAD ciphers). Currently only supported with GCM. Must be called exactly onc...
Definition: cipher.c:251
int mbedtls_cipher_write_tag(mbedtls_cipher_context_t *ctx, unsigned char *tag, size_t tag_len)
Write tag for AEAD ciphers. Currently only supported with GCM. Must be called after mbedtls_cipher_fi...
Definition: cipher.c:751
static INLINE mbedtls_cipher_type_t mbedtls_cipher_get_type(const mbedtls_cipher_context_t *ctx)
Returns the type of the given cipher.
Definition: cipher.h:390
const mbedtls_cipher_base_t * base
Definition: cipher.h:209
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.
Definition: cipher.c:152
static const size_t tag_len[NB_TESTS]
Definition: ccm.c:384
static INLINE mbedtls_operation_t mbedtls_cipher_get_operation(const mbedtls_cipher_context_t *ctx)
Returns the operation of the given cipher.
Definition: cipher.h:439
static const unsigned char ad[]
Definition: ccm.c:369
void mbedtls_cipher_free(mbedtls_cipher_context_t *ctx)
Free and clear the cipher-specific context of ctx. Freeing ctx itself remains the responsibility of t...
Definition: cipher.c:133
unsigned int key_bitlen
Definition: cipher.h:193
mbedtls_cipher_id_t
Definition: cipher.h:66
size_t unprocessed_len
Definition: cipher.h:236
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).
Definition: cipher.c:809
mbedtls_cipher_type_t
Definition: cipher.h:77