RetroArch
Macros | Functions | Variables
ccm.c File Reference
#include "mbedtls/config.h"
#include "mbedtls/ccm.h"
#include <string.h>
#include "mbedtls/platform.h"
#include "arc4_alt.h"
Include dependency graph for ccm.c:

Macros

#define CCM_ENCRYPT   0
 
#define CCM_DECRYPT   1
 
#define UPDATE_CBC_MAC
 
#define CTR_CRYPT(dst, src, len)
 
#define NB_TESTS   3
 

Functions

void mbedtls_ccm_init (mbedtls_ccm_context *ctx)
 Initialize CCM context (just makes references valid) Makes the context ready for mbedtls_ccm_setkey() or mbedtls_ccm_free(). More...
 
int mbedtls_ccm_setkey (mbedtls_ccm_context *ctx, mbedtls_cipher_id_t cipher, const unsigned char *key, unsigned int keybits)
 CCM initialization (encryption and decryption) More...
 
void mbedtls_ccm_free (mbedtls_ccm_context *ctx)
 Free a CCM context and underlying cipher sub-context. More...
 
static int ccm_auth_crypt (mbedtls_ccm_context *ctx, int mode, size_t length, const unsigned char *iv, size_t iv_len, const unsigned char *add, size_t add_len, const unsigned char *input, unsigned char *output, unsigned char *tag, size_t tag_len)
 
int mbedtls_ccm_encrypt_and_tag (mbedtls_ccm_context *ctx, size_t length, const unsigned char *iv, size_t iv_len, const unsigned char *add, size_t add_len, const unsigned char *input, unsigned char *output, unsigned char *tag, size_t tag_len)
 CCM buffer encryption. More...
 
int mbedtls_ccm_auth_decrypt (mbedtls_ccm_context *ctx, size_t length, const unsigned char *iv, size_t iv_len, const unsigned char *add, size_t add_len, const unsigned char *input, unsigned char *output, const unsigned char *tag, size_t tag_len)
 CCM buffer authenticated decryption. More...
 
int mbedtls_ccm_self_test (int verbose)
 Checkup routine. More...
 

Variables

static const unsigned char ccm_key []
 
static const unsigned char iv []
 
static const unsigned char ad []
 
static const unsigned char msg []
 
static const size_t iv_len [NB_TESTS] = { 7, 8, 12 }
 
static const size_t add_len [NB_TESTS] = { 8, 16, 20 }
 
static const size_t msg_len [NB_TESTS] = { 4, 16, 24 }
 
static const size_t tag_len [NB_TESTS] = { 4, 6, 8 }
 
static const unsigned char res [NB_TESTS][32]
 

Macro Definition Documentation

◆ CCM_DECRYPT

#define CCM_DECRYPT   1

◆ CCM_ENCRYPT

#define CCM_ENCRYPT   0

◆ CTR_CRYPT

#define CTR_CRYPT (   dst,
  src,
  len 
)
Value:
if( ( ret = mbedtls_cipher_update( &ctx->cipher_ctx, ctr, 16, b, &olen ) ) != 0 ) \
return( ret ); \
\
for( i = 0; i < len; i++ ) \
dst[i] = src[i] ^ b[i];
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
GLenum GLsizei len
Definition: glext.h:7389
GLboolean GLboolean GLboolean b
Definition: glext.h:6844
AVFormatContext * ctx
Definition: record_ffmpeg.c:247
GLenum src
Definition: glext.h:6980
GLenum GLenum dst
Definition: glext.h:6980

◆ NB_TESTS

#define NB_TESTS   3

◆ UPDATE_CBC_MAC

#define UPDATE_CBC_MAC
Value:
for( i = 0; i < 16; i++ ) \
y[i] ^= b[i]; \
if( ( ret = mbedtls_cipher_update( &ctx->cipher_ctx, y, 16, y, &olen ) ) != 0 ) \
return( ret );
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
GLboolean GLboolean GLboolean b
Definition: glext.h:6844
set set set set set set set macro pixldst1 abits if abits op else op endif endm macro pixldst2 abits if abits op else op endif endm macro pixldst4 abits if abits op else op endif endm macro pixldst0 abits op endm macro pixldst3 mem_operand op endm macro pixldst30 mem_operand op endm macro pixldst abits if abits elseif abits elseif abits elseif abits elseif abits pixldst0 abits else pixldst0 abits pixldst0 abits pixldst0 abits pixldst0 abits endif elseif abits else pixldst0 abits pixldst0 abits endif elseif abits else error unsupported bpp *numpix else pixst endif endm macro pixld1_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl else error unsupported endif endm macro pixld2_s mem_operand if mov asr add asl add asl mov asr sub UNIT_X add asl mov asr add asl add asl mov asr add UNIT_X add asl else pixld1_s mem_operand pixld1_s mem_operand endif endm macro pixld0_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl endif endm macro pixld_s_internal mem_operand if mem_operand pixld2_s mem_operand pixdeinterleave basereg elseif mem_operand elseif mem_operand elseif mem_operand elseif mem_operand pixld0_s mem_operand else pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else error unsupported mem_operand if bpp mem_operand endif endm macro vuzp8 reg2 vuzp d d &reg2 endm macro vzip8 reg2 vzip d d &reg2 endm macro pixdeinterleave basereg basereg basereg basereg basereg endif endm macro pixinterleave basereg basereg basereg basereg basereg endif endm macro PF boost_increment endif if endif PF tst PF addne PF subne PF cmp ORIG_W if endif if endif if endif PF subge ORIG_W PF subges if endif if endif if endif endif endm macro cache_preload_simple endif if dst_r_bpp pld [DST_R, #(PREFETCH_DISTANCE_SIMPLE *dst_r_bpp/8)] endif if mask_bpp pld if[MASK, #(PREFETCH_DISTANCE_SIMPLE *mask_bpp/8)] endif endif endm macro fetch_mask_pixblock pixld mask_basereg pixblock_size MASK endm macro ensure_destination_ptr_alignment process_pixblock_tail_head if beq irp local skip1(dst_w_bpp<=(lowbit *8)) &&((lowbit *8)<(pixblock_size *dst_w_bpp)) .if lowbit< 16 tst DST_R
Definition: pixman-arm-neon-asm.h:469
AVFormatContext * ctx
Definition: record_ffmpeg.c:247
GLint GLint GLint GLint GLint GLint y
Definition: glext.h:6295

Function Documentation

◆ ccm_auth_crypt()

static int ccm_auth_crypt ( mbedtls_ccm_context ctx,
int  mode,
size_t  length,
const unsigned char *  iv,
size_t  iv_len,
const unsigned char *  add,
size_t  add_len,
const unsigned char *  input,
unsigned char *  output,
unsigned char *  tag,
size_t  tag_len 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mbedtls_ccm_auth_decrypt()

int mbedtls_ccm_auth_decrypt ( mbedtls_ccm_context ctx,
size_t  length,
const unsigned char *  iv,
size_t  iv_len,
const unsigned char *  add,
size_t  add_len,
const unsigned char *  input,
unsigned char *  output,
const unsigned char *  tag,
size_t  tag_len 
)

CCM buffer authenticated decryption.

Parameters
ctxCCM context
lengthlength of the input data
ivinitialization vector
iv_lenlength of IV
addadditional data
add_lenlength of additional data
inputbuffer holding the input data
outputbuffer for holding the output data
tagbuffer holding the tag
tag_lenlength of the tag
Returns
0 if successful and authenticated, MBEDTLS_ERR_CCM_AUTH_FAILED if tag does not match
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mbedtls_ccm_encrypt_and_tag()

int mbedtls_ccm_encrypt_and_tag ( mbedtls_ccm_context ctx,
size_t  length,
const unsigned char *  iv,
size_t  iv_len,
const unsigned char *  add,
size_t  add_len,
const unsigned char *  input,
unsigned char *  output,
unsigned char *  tag,
size_t  tag_len 
)

CCM buffer encryption.

Parameters
ctxCCM context
lengthlength of the input data in bytes
ivnonce (initialization vector)
iv_lenlength of IV in bytes must be 2, 3, 4, 5, 6, 7 or 8
addadditional data
add_lenlength of additional data in bytes must be less than 2^16 - 2^8
inputbuffer holding the input data
outputbuffer for holding the output data must be at least 'length' bytes wide
tagbuffer for holding the tag
tag_lenlength of the tag to generate in bytes must be 4, 6, 8, 10, 14 or 16
Note
The tag is written to a separate buffer. To get the tag concatenated with the output as in the CCM spec, use tag = output + length and make sure the output buffer is at least length + tag_len wide.
Returns
0 if successful
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mbedtls_ccm_free()

void mbedtls_ccm_free ( mbedtls_ccm_context ctx)

Free a CCM context and underlying cipher sub-context.

Parameters
ctxCCM context to free
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mbedtls_ccm_init()

void mbedtls_ccm_init ( mbedtls_ccm_context ctx)

Initialize CCM context (just makes references valid) Makes the context ready for mbedtls_ccm_setkey() or mbedtls_ccm_free().

Parameters
ctxCCM context to initialize
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mbedtls_ccm_self_test()

int mbedtls_ccm_self_test ( int  verbose)

Checkup routine.

Returns
0 if successful, or 1 if the test failed
Here is the call graph for this function:

◆ mbedtls_ccm_setkey()

int mbedtls_ccm_setkey ( mbedtls_ccm_context ctx,
mbedtls_cipher_id_t  cipher,
const unsigned char *  key,
unsigned int  keybits 
)

CCM initialization (encryption and decryption)

Parameters
ctxCCM context to be initialized
ciphercipher to use (a 128-bit block cipher)
keyencryption key
keybitskey size in bits (must be acceptable by the cipher)
Returns
0 if successful, or a cipher specific error code
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ ad

const unsigned char ad[]
static
Initial value:
= {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
0x10, 0x11, 0x12, 0x13
}

◆ add_len

const size_t add_len[NB_TESTS] = { 8, 16, 20 }
static

◆ ccm_key

const unsigned char ccm_key[]
static
Initial value:
= {
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f
}

◆ iv

const unsigned char iv[]
static
Initial value:
= {
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1a, 0x1b
}

◆ iv_len

const size_t iv_len[NB_TESTS] = { 7, 8, 12 }
static

◆ msg

const unsigned char msg[]
static
Initial value:
= {
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
}

◆ msg_len

const size_t msg_len[NB_TESTS] = { 4, 16, 24 }
static

◆ res

const unsigned char res[NB_TESTS][32]
static
Initial value:
= {
{ 0x71, 0x62, 0x01, 0x5b, 0x4d, 0xac, 0x25, 0x5d },
{ 0xd2, 0xa1, 0xf0, 0xe0, 0x51, 0xea, 0x5f, 0x62,
0x08, 0x1a, 0x77, 0x92, 0x07, 0x3d, 0x59, 0x3d,
0x1f, 0xc6, 0x4f, 0xbf, 0xac, 0xcd },
{ 0xe3, 0xb2, 0x01, 0xa9, 0xf5, 0xb7, 0x1a, 0x7a,
0x9b, 0x1c, 0xea, 0xec, 0xcd, 0x97, 0xe7, 0x0b,
0x61, 0x76, 0xaa, 0xd9, 0xa4, 0x42, 0x8a, 0xa5,
0x48, 0x43, 0x92, 0xfb, 0xc1, 0xb0, 0x99, 0x51 }
}

◆ tag_len

const size_t tag_len[NB_TESTS] = { 4, 6, 8 }
static