Mbed OS Reference
Loading...
Searching...
No Matches
cipher.h File Reference

This file contains an abstraction interface for use with the cipher primitives provided by the library. More...

#include "mbedtls/config.h"
#include <stddef.h>
#include "mbedtls/platform_util.h"

Go to the source code of this file.

Data Structures

struct  mbedtls_cipher_info_t
 Cipher information. More...
 
struct  mbedtls_cipher_context_t
 Generic cipher context. More...
 

Macros

#define MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE   -0x6080
 The selected feature is not available. More...
 
#define MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA   -0x6100
 Bad input parameters. More...
 
#define MBEDTLS_ERR_CIPHER_ALLOC_FAILED   -0x6180
 Failed to allocate memory. More...
 
#define MBEDTLS_ERR_CIPHER_INVALID_PADDING   -0x6200
 Input data contains invalid padding and is rejected. More...
 
#define MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED   -0x6280
 Decryption of block requires a full block. More...
 
#define MBEDTLS_ERR_CIPHER_AUTH_FAILED   -0x6300
 Authentication failed (for AEAD modes). More...
 
#define MBEDTLS_ERR_CIPHER_INVALID_CONTEXT   -0x6380
 The context is invalid. More...
 
#define MBEDTLS_ERR_CIPHER_HW_ACCEL_FAILED   -0x6400
 Cipher hardware accelerator failed. More...
 
#define MBEDTLS_CIPHER_VARIABLE_IV_LEN   0x01
 Cipher accepts IVs of variable length. More...
 
#define MBEDTLS_CIPHER_VARIABLE_KEY_LEN   0x02
 Cipher accepts keys of variable length. More...
 
#define MBEDTLS_MAX_IV_LENGTH   16
 Maximum length of any IV, in Bytes. More...
 
#define MBEDTLS_MAX_BLOCK_LENGTH   16
 Maximum block size of any cipher, in Bytes. More...
 
#define MBEDTLS_MAX_KEY_LENGTH   32
 Maximum key length, in Bytes. More...
 

Typedefs

typedef struct mbedtls_cipher_base_t mbedtls_cipher_base_t
 Base cipher information (opaque struct). More...
 
typedef struct mbedtls_cmac_context_t mbedtls_cmac_context_t
 CMAC context (opaque struct). More...
 
typedef struct mbedtls_cipher_info_t mbedtls_cipher_info_t
 Cipher information. More...
 
typedef struct mbedtls_cipher_context_t mbedtls_cipher_context_t
 Generic cipher context. More...
 

Enumerations

enum  mbedtls_cipher_id_t {
  MBEDTLS_CIPHER_ID_NONE = 0 , MBEDTLS_CIPHER_ID_NULL , MBEDTLS_CIPHER_ID_AES , MBEDTLS_CIPHER_ID_DES ,
  MBEDTLS_CIPHER_ID_3DES , MBEDTLS_CIPHER_ID_CAMELLIA , MBEDTLS_CIPHER_ID_BLOWFISH , MBEDTLS_CIPHER_ID_ARC4 ,
  MBEDTLS_CIPHER_ID_ARIA , MBEDTLS_CIPHER_ID_CHACHA20
}
 Supported cipher types. More...
 
enum  mbedtls_cipher_type_t {
  MBEDTLS_CIPHER_NONE = 0 , MBEDTLS_CIPHER_NULL , MBEDTLS_CIPHER_AES_128_ECB , MBEDTLS_CIPHER_AES_192_ECB ,
  MBEDTLS_CIPHER_AES_256_ECB , MBEDTLS_CIPHER_AES_128_CBC , MBEDTLS_CIPHER_AES_192_CBC , MBEDTLS_CIPHER_AES_256_CBC ,
  MBEDTLS_CIPHER_AES_128_CFB128 , MBEDTLS_CIPHER_AES_192_CFB128 , MBEDTLS_CIPHER_AES_256_CFB128 , MBEDTLS_CIPHER_AES_128_CTR ,
  MBEDTLS_CIPHER_AES_192_CTR , MBEDTLS_CIPHER_AES_256_CTR , MBEDTLS_CIPHER_AES_128_GCM , MBEDTLS_CIPHER_AES_192_GCM ,
  MBEDTLS_CIPHER_AES_256_GCM , MBEDTLS_CIPHER_CAMELLIA_128_ECB , MBEDTLS_CIPHER_CAMELLIA_192_ECB , MBEDTLS_CIPHER_CAMELLIA_256_ECB ,
  MBEDTLS_CIPHER_CAMELLIA_128_CBC , MBEDTLS_CIPHER_CAMELLIA_192_CBC , MBEDTLS_CIPHER_CAMELLIA_256_CBC , MBEDTLS_CIPHER_CAMELLIA_128_CFB128 ,
  MBEDTLS_CIPHER_CAMELLIA_192_CFB128 , MBEDTLS_CIPHER_CAMELLIA_256_CFB128 , MBEDTLS_CIPHER_CAMELLIA_128_CTR , MBEDTLS_CIPHER_CAMELLIA_192_CTR ,
  MBEDTLS_CIPHER_CAMELLIA_256_CTR , MBEDTLS_CIPHER_CAMELLIA_128_GCM , MBEDTLS_CIPHER_CAMELLIA_192_GCM , MBEDTLS_CIPHER_CAMELLIA_256_GCM ,
  MBEDTLS_CIPHER_DES_ECB , MBEDTLS_CIPHER_DES_CBC , MBEDTLS_CIPHER_DES_EDE_ECB , MBEDTLS_CIPHER_DES_EDE_CBC ,
  MBEDTLS_CIPHER_DES_EDE3_ECB , MBEDTLS_CIPHER_DES_EDE3_CBC , MBEDTLS_CIPHER_BLOWFISH_ECB , MBEDTLS_CIPHER_BLOWFISH_CBC ,
  MBEDTLS_CIPHER_BLOWFISH_CFB64 , MBEDTLS_CIPHER_BLOWFISH_CTR , MBEDTLS_CIPHER_ARC4_128 , MBEDTLS_CIPHER_AES_128_CCM ,
  MBEDTLS_CIPHER_AES_192_CCM , MBEDTLS_CIPHER_AES_256_CCM , MBEDTLS_CIPHER_CAMELLIA_128_CCM , MBEDTLS_CIPHER_CAMELLIA_192_CCM ,
  MBEDTLS_CIPHER_CAMELLIA_256_CCM , MBEDTLS_CIPHER_ARIA_128_ECB , MBEDTLS_CIPHER_ARIA_192_ECB , MBEDTLS_CIPHER_ARIA_256_ECB ,
  MBEDTLS_CIPHER_ARIA_128_CBC , MBEDTLS_CIPHER_ARIA_192_CBC , MBEDTLS_CIPHER_ARIA_256_CBC , MBEDTLS_CIPHER_ARIA_128_CFB128 ,
  MBEDTLS_CIPHER_ARIA_192_CFB128 , MBEDTLS_CIPHER_ARIA_256_CFB128 , MBEDTLS_CIPHER_ARIA_128_CTR , MBEDTLS_CIPHER_ARIA_192_CTR ,
  MBEDTLS_CIPHER_ARIA_256_CTR , MBEDTLS_CIPHER_ARIA_128_GCM , MBEDTLS_CIPHER_ARIA_192_GCM , MBEDTLS_CIPHER_ARIA_256_GCM ,
  MBEDTLS_CIPHER_ARIA_128_CCM , MBEDTLS_CIPHER_ARIA_192_CCM , MBEDTLS_CIPHER_ARIA_256_CCM , MBEDTLS_CIPHER_AES_128_OFB ,
  MBEDTLS_CIPHER_AES_192_OFB , MBEDTLS_CIPHER_AES_256_OFB , MBEDTLS_CIPHER_AES_128_XTS , MBEDTLS_CIPHER_AES_256_XTS ,
  MBEDTLS_CIPHER_CHACHA20 , MBEDTLS_CIPHER_CHACHA20_POLY1305 , MBEDTLS_CIPHER_AES_128_KW , MBEDTLS_CIPHER_AES_192_KW ,
  MBEDTLS_CIPHER_AES_256_KW , MBEDTLS_CIPHER_AES_128_KWP , MBEDTLS_CIPHER_AES_192_KWP , MBEDTLS_CIPHER_AES_256_KWP
}
 Supported {cipher type, cipher mode} pairs. More...
 
enum  mbedtls_cipher_mode_t {
  MBEDTLS_MODE_NONE = 0 , MBEDTLS_MODE_ECB , MBEDTLS_MODE_CBC , MBEDTLS_MODE_CFB ,
  MBEDTLS_MODE_OFB , MBEDTLS_MODE_CTR , MBEDTLS_MODE_GCM , MBEDTLS_MODE_STREAM ,
  MBEDTLS_MODE_CCM , MBEDTLS_MODE_XTS , MBEDTLS_MODE_CHACHAPOLY , MBEDTLS_MODE_KW ,
  MBEDTLS_MODE_KWP
}
 Supported cipher modes. More...
 
enum  mbedtls_cipher_padding_t {
  MBEDTLS_PADDING_PKCS7 = 0 , MBEDTLS_PADDING_ONE_AND_ZEROS , MBEDTLS_PADDING_ZEROS_AND_LEN , MBEDTLS_PADDING_ZEROS ,
  MBEDTLS_PADDING_NONE
}
 Supported cipher padding types. More...
 
enum  mbedtls_operation_t { }
 Type of operation. More...
 
enum  { MBEDTLS_KEY_LENGTH_NONE = 0 , MBEDTLS_KEY_LENGTH_DES = 64 , MBEDTLS_KEY_LENGTH_DES_EDE = 128 , MBEDTLS_KEY_LENGTH_DES_EDE3 = 192 }
 

Functions

const int * mbedtls_cipher_list (void)
 This function retrieves the list of ciphers supported by the generic cipher module. More...
 
const mbedtls_cipher_info_tmbedtls_cipher_info_from_string (const char *cipher_name)
 This function retrieves the cipher-information structure associated with the given cipher name. More...
 
const mbedtls_cipher_info_tmbedtls_cipher_info_from_type (const mbedtls_cipher_type_t cipher_type)
 This function retrieves the cipher-information structure associated with the given cipher type. More...
 
const mbedtls_cipher_info_tmbedtls_cipher_info_from_values (const mbedtls_cipher_id_t cipher_id, int key_bitlen, const mbedtls_cipher_mode_t mode)
 This function retrieves the cipher-information structure associated with the given cipher ID, key size and mode. More...
 
void mbedtls_cipher_init (mbedtls_cipher_context_t *ctx)
 This function initializes a cipher_context as NONE. More...
 
void mbedtls_cipher_free (mbedtls_cipher_context_t *ctx)
 This function frees and clears the cipher-specific context of ctx. More...
 
int mbedtls_cipher_setup (mbedtls_cipher_context_t *ctx, const mbedtls_cipher_info_t *cipher_info)
 This function initializes a cipher context for use with the given cipher primitive. More...
 
int mbedtls_cipher_setkey (mbedtls_cipher_context_t *ctx, const unsigned char *key, int key_bitlen, const mbedtls_operation_t operation)
 This function sets the key to use with the given context. More...
 
int mbedtls_cipher_set_iv (mbedtls_cipher_context_t *ctx, const unsigned char *iv, size_t iv_len)
 This function sets the initialization vector (IV) or nonce. More...
 
int mbedtls_cipher_reset (mbedtls_cipher_context_t *ctx)
 This function resets the cipher state. More...
 
int mbedtls_cipher_update (mbedtls_cipher_context_t *ctx, const unsigned char *input, size_t ilen, unsigned char *output, size_t *olen)
 The generic cipher update function. More...
 
int mbedtls_cipher_finish (mbedtls_cipher_context_t *ctx, unsigned char *output, size_t *olen)
 The generic cipher finalization function. More...
 
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)
 The generic all-in-one encryption/decryption function, for all ciphers except AEAD constructs. More...
 

Detailed Description

This file contains an abstraction interface for use with the cipher primitives provided by the library.

It provides a common interface to all of the available cipher operations.

Author
Adriaan de Jong dejon.nosp@m.g@fo.nosp@m.x-it..nosp@m.com

Definition in file cipher.h.

Macro Definition Documentation

◆ MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE

#define MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE   -0x6080

The selected feature is not available.

Definition at line 57 of file cipher.h.

◆ MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA

#define MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA   -0x6100

Bad input parameters.

Definition at line 58 of file cipher.h.

◆ MBEDTLS_ERR_CIPHER_ALLOC_FAILED

#define MBEDTLS_ERR_CIPHER_ALLOC_FAILED   -0x6180

Failed to allocate memory.

Definition at line 59 of file cipher.h.

◆ MBEDTLS_ERR_CIPHER_INVALID_PADDING

#define MBEDTLS_ERR_CIPHER_INVALID_PADDING   -0x6200

Input data contains invalid padding and is rejected.

Definition at line 60 of file cipher.h.

◆ MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED

#define MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED   -0x6280

Decryption of block requires a full block.

Definition at line 61 of file cipher.h.

◆ MBEDTLS_ERR_CIPHER_AUTH_FAILED

#define MBEDTLS_ERR_CIPHER_AUTH_FAILED   -0x6300

Authentication failed (for AEAD modes).

Definition at line 62 of file cipher.h.

◆ MBEDTLS_ERR_CIPHER_INVALID_CONTEXT

#define MBEDTLS_ERR_CIPHER_INVALID_CONTEXT   -0x6380

The context is invalid.

For example, because it was freed.

Definition at line 63 of file cipher.h.

◆ MBEDTLS_ERR_CIPHER_HW_ACCEL_FAILED

#define MBEDTLS_ERR_CIPHER_HW_ACCEL_FAILED   -0x6400

Cipher hardware accelerator failed.

Definition at line 66 of file cipher.h.

◆ MBEDTLS_CIPHER_VARIABLE_IV_LEN

#define MBEDTLS_CIPHER_VARIABLE_IV_LEN   0x01

Cipher accepts IVs of variable length.

Definition at line 68 of file cipher.h.

◆ MBEDTLS_CIPHER_VARIABLE_KEY_LEN

#define MBEDTLS_CIPHER_VARIABLE_KEY_LEN   0x02

Cipher accepts keys of variable length.

Definition at line 69 of file cipher.h.