mirror of https://github.com/ARMmbed/mbed-os.git
Style fixes
1. Change camelcase variables to Mbed OS style. 2. Remove functions declarations from the `_alt` header, since they are now added from the module header regardless whether an alternative implementation exists. 3. Remove the `extern "c"` declaration from the `_alt` headers. 4. Remove whitespaces before opening parenthesis. 5. Fix alignment of function parameters. 6. Fix indentations. 7. Limit lines to 80 characters.pull/8704/head
parent
d487c80d76
commit
1b34927e83
|
@ -51,7 +51,7 @@ int mbedtls_ccm_setkey( mbedtls_ccm_context *ctx,
|
|||
}
|
||||
|
||||
memcpy( ctx->cipher_key , key, keybits / 8 );
|
||||
ctx->keySize_ID = CRYS_AES_Key128BitSize;
|
||||
ctx->key_size = CRYS_AES_Key128BitSize;
|
||||
|
||||
return( 0 );
|
||||
|
||||
|
@ -64,12 +64,13 @@ int mbedtls_ccm_setkey( mbedtls_ccm_context *ctx,
|
|||
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,
|
||||
const unsigned char *input,
|
||||
unsigned char *output,
|
||||
unsigned char *tag, size_t tag_len )
|
||||
|
||||
{
|
||||
CRYSError_t CrysRet = CRYS_OK;
|
||||
CRYS_AESCCM_Mac_Res_t CC_Mac_Res = { 0 };
|
||||
CRYSError_t crys_ret = CRYS_OK;
|
||||
CRYS_AESCCM_Mac_Res_t cc_mac_res = { 0 };
|
||||
int ret = 0;
|
||||
/*
|
||||
* Check length requirements: SP800-38C A.1
|
||||
|
@ -79,7 +80,7 @@ int mbedtls_ccm_encrypt_and_tag( mbedtls_ccm_context *ctx, size_t length,
|
|||
if( tag_len < 4 || tag_len > 16 || tag_len % 2 != 0 )
|
||||
return( MBEDTLS_ERR_CCM_BAD_INPUT );
|
||||
|
||||
if( tag_len > sizeof( CC_Mac_Res ) )
|
||||
if( tag_len > sizeof( cc_mac_res ) )
|
||||
return( MBEDTLS_ERR_CCM_BAD_INPUT );
|
||||
|
||||
/* Also implies q is within bounds */
|
||||
|
@ -91,20 +92,22 @@ int mbedtls_ccm_encrypt_and_tag( mbedtls_ccm_context *ctx, size_t length,
|
|||
return( MBEDTLS_ERR_CCM_BAD_INPUT );
|
||||
#endif
|
||||
|
||||
CrysRet = CRYS_AESCCM( SASI_AES_ENCRYPT, ctx->cipher_key, ctx->keySize_ID, (uint8_t*)iv, iv_len,
|
||||
(uint8_t*)add, add_len, (uint8_t*)input, length, output, tag_len, CC_Mac_Res );
|
||||
if( CrysRet == CRYS_AESCCM_ILLEGAL_PARAMETER_SIZE_ERROR )
|
||||
crys_ret = CRYS_AESCCM( SASI_AES_ENCRYPT, ctx->cipher_key, ctx->key_size,
|
||||
(uint8_t*)iv, iv_len, (uint8_t*)add, add_len,
|
||||
(uint8_t*)input, length, output, tag_len,
|
||||
cc_mac_res );
|
||||
if( crys_ret == CRYS_AESCCM_ILLEGAL_PARAMETER_SIZE_ERROR )
|
||||
{
|
||||
ret = MBEDTLS_ERR_CCM_BAD_INPUT;
|
||||
goto exit;
|
||||
}
|
||||
else if ( CrysRet != CRYS_OK )
|
||||
else if( crys_ret != CRYS_OK )
|
||||
{
|
||||
ret = MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
memcpy( tag, CC_Mac_Res, tag_len );
|
||||
memcpy( tag, cc_mac_res, tag_len );
|
||||
|
||||
exit:
|
||||
return( ret );
|
||||
|
@ -121,7 +124,7 @@ int mbedtls_ccm_auth_decrypt( mbedtls_ccm_context *ctx, size_t length,
|
|||
const unsigned char *tag, size_t tag_len )
|
||||
|
||||
{
|
||||
CRYSError_t CrysRet = CRYS_OK;
|
||||
CRYSError_t crys_ret = CRYS_OK;
|
||||
int ret = 0;
|
||||
/*
|
||||
* Check length requirements: SP800-38C A.1
|
||||
|
@ -140,9 +143,11 @@ int mbedtls_ccm_auth_decrypt( mbedtls_ccm_context *ctx, size_t length,
|
|||
return( MBEDTLS_ERR_CCM_BAD_INPUT );
|
||||
#endif
|
||||
|
||||
CrysRet = CRYS_AESCCM( SASI_AES_DECRYPT, ctx->cipher_key, ctx->keySize_ID,(uint8_t*)iv, iv_len,
|
||||
(uint8_t*)add, add_len, (uint8_t*)input, length, output, tag_len, (uint8_t*)tag );
|
||||
if( CrysRet == CRYS_AESCCM_ILLEGAL_PARAMETER_SIZE_ERROR )
|
||||
crys_ret = CRYS_AESCCM( SASI_AES_DECRYPT, ctx->cipher_key, ctx->key_size,
|
||||
(uint8_t*)iv, iv_len, (uint8_t*)add, add_len,
|
||||
(uint8_t*)input, length, output, tag_len,
|
||||
(uint8_t*)tag );
|
||||
if( crys_ret == CRYS_AESCCM_ILLEGAL_PARAMETER_SIZE_ERROR )
|
||||
{
|
||||
/*
|
||||
* When CRYS_AESCCM_ILLEGAL_PARAMETER_SIZE_ERROR is returned,
|
||||
|
@ -153,7 +158,7 @@ int mbedtls_ccm_auth_decrypt( mbedtls_ccm_context *ctx, size_t length,
|
|||
*/
|
||||
return( MBEDTLS_ERR_CCM_BAD_INPUT );
|
||||
}
|
||||
else if( CrysRet == CRYS_FATAL_ERROR )
|
||||
else if( crys_ret == CRYS_FATAL_ERROR )
|
||||
{
|
||||
/*
|
||||
* Unfortunately, Crys AESCCM returns CRYS_FATAL_ERROR when
|
||||
|
@ -162,7 +167,7 @@ int mbedtls_ccm_auth_decrypt( mbedtls_ccm_context *ctx, size_t length,
|
|||
ret = MBEDTLS_ERR_CCM_AUTH_FAILED;
|
||||
goto exit;
|
||||
}
|
||||
else if ( CrysRet != CRYS_OK )
|
||||
else if( crys_ret != CRYS_OK )
|
||||
{
|
||||
ret = MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED;
|
||||
goto exit;
|
||||
|
@ -178,22 +183,21 @@ exit:
|
|||
int mbedtls_ccm_star_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,
|
||||
const unsigned char *input,
|
||||
unsigned char *output,
|
||||
unsigned char *tag, size_t tag_len )
|
||||
{
|
||||
|
||||
return( MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE );
|
||||
|
||||
}
|
||||
|
||||
int mbedtls_ccm_star_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 *input,
|
||||
unsigned char *output,
|
||||
const unsigned char *tag, size_t tag_len )
|
||||
{
|
||||
return( MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE );
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -24,104 +24,11 @@
|
|||
#if defined(MBEDTLS_CCM_ALT)
|
||||
#include "crys_aesccm.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
CRYS_AESCCM_Key_t cipher_key; /*!< cipher key used */
|
||||
CRYS_AESCCM_KeySize_t keySize_ID;
|
||||
CRYS_AESCCM_KeySize_t key_size;
|
||||
}
|
||||
mbedtls_ccm_context;
|
||||
|
||||
/**
|
||||
* \brief Initialize CCM context (just makes references valid)
|
||||
* Makes the context ready for mbedtls_ccm_setkey() or
|
||||
* mbedtls_ccm_free().
|
||||
*
|
||||
* \param ctx CCM context to initialize
|
||||
*/
|
||||
void mbedtls_ccm_init( mbedtls_ccm_context *ctx );
|
||||
|
||||
/**
|
||||
* \brief CCM initialization (encryption and decryption)
|
||||
*
|
||||
* \param ctx CCM context to be initialized
|
||||
* \param cipher cipher to use (a 128-bit block cipher)
|
||||
* \param key encryption key
|
||||
* \param keybits key size in bits (must be acceptable by the cipher)
|
||||
*
|
||||
* \return 0 if successful, or a cipher specific error code
|
||||
*/
|
||||
int mbedtls_ccm_setkey( mbedtls_ccm_context *ctx,
|
||||
mbedtls_cipher_id_t cipher,
|
||||
const unsigned char *key,
|
||||
unsigned int keybits );
|
||||
|
||||
/**
|
||||
* \brief Free a CCM context and underlying cipher sub-context
|
||||
*
|
||||
* \param ctx CCM context to free
|
||||
*/
|
||||
void mbedtls_ccm_free( mbedtls_ccm_context *ctx );
|
||||
|
||||
/**
|
||||
* \brief CCM buffer encryption
|
||||
*
|
||||
* \param ctx CCM context
|
||||
* \param length length of the input data in bytes
|
||||
* \param iv nonce (initialization vector)
|
||||
* \param iv_len length of IV in bytes
|
||||
* must be 2, 3, 4, 5, 6, 7 or 8
|
||||
* \param add additional data
|
||||
* \param add_len length of additional data in bytes
|
||||
* must be less than 2^16 - 2^8
|
||||
* \param input buffer holding the input data
|
||||
* \param output buffer for holding the output data
|
||||
* must be at least 'length' bytes wide
|
||||
* \param tag buffer for holding the tag
|
||||
* \param tag_len length 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.
|
||||
*
|
||||
* \return 0 if successful
|
||||
*/
|
||||
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 );
|
||||
|
||||
/**
|
||||
* \brief CCM buffer authenticated decryption
|
||||
*
|
||||
* \param ctx CCM context
|
||||
* \param length length of the input data
|
||||
* \param iv initialization vector
|
||||
* \param iv_len length of IV
|
||||
* \param add additional data
|
||||
* \param add_len length of additional data
|
||||
* \param input buffer holding the input data
|
||||
* \param output buffer for holding the output data
|
||||
* \param tag buffer holding the tag
|
||||
* \param tag_len length of the tag
|
||||
*
|
||||
* \return 0 if successful and authenticated,
|
||||
* MBEDTLS_ERR_CCM_AUTH_FAILED if tag does not match
|
||||
*/
|
||||
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 );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* MBEDTLS_CCM_ALT */
|
||||
#endif /* __CCM_ALT__ */
|
||||
|
|
Loading…
Reference in New Issue