Skip to content

Commit 1b34927

Browse files
author
Ron Eldor
committed
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.
1 parent d487c80 commit 1b34927

File tree

2 files changed

+50
-139
lines changed

2 files changed

+50
-139
lines changed

features/cryptocell/FEATURE_CRYPTOCELL310/ccm_alt.c

Lines changed: 48 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,18 @@ int mbedtls_ccm_setkey( mbedtls_ccm_context *ctx,
4242
unsigned int keybits )
4343
{
4444
if( ctx == NULL )
45-
return ( MBEDTLS_ERR_CCM_BAD_INPUT );
45+
return( MBEDTLS_ERR_CCM_BAD_INPUT );
4646

4747
if( cipher != MBEDTLS_CIPHER_ID_AES ||
4848
keybits != 128 )
4949
{
50-
return ( MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED );
50+
return( MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED );
5151
}
5252

5353
memcpy( ctx->cipher_key , key, keybits / 8 );
54-
ctx->keySize_ID = CRYS_AES_Key128BitSize;
54+
ctx->key_size = CRYS_AES_Key128BitSize;
5555

56-
return ( 0 );
56+
return( 0 );
5757

5858
}
5959

@@ -62,52 +62,55 @@ int mbedtls_ccm_setkey( mbedtls_ccm_context *ctx,
6262
*/
6363

6464
int mbedtls_ccm_encrypt_and_tag( mbedtls_ccm_context *ctx, size_t length,
65-
const unsigned char *iv, size_t iv_len,
66-
const unsigned char *add, size_t add_len,
67-
const unsigned char *input, unsigned char *output,
68-
unsigned char *tag, size_t tag_len )
65+
const unsigned char *iv, size_t iv_len,
66+
const unsigned char *add, size_t add_len,
67+
const unsigned char *input,
68+
unsigned char *output,
69+
unsigned char *tag, size_t tag_len )
6970

7071
{
71-
CRYSError_t CrysRet = CRYS_OK;
72-
CRYS_AESCCM_Mac_Res_t CC_Mac_Res = { 0 };
72+
CRYSError_t crys_ret = CRYS_OK;
73+
CRYS_AESCCM_Mac_Res_t cc_mac_res = { 0 };
7374
int ret = 0;
7475
/*
7576
* Check length requirements: SP800-38C A.1
7677
* Additional requirement: a < 2^16 - 2^8 to simplify the code.
7778
* 'length' checked later (when writing it to the first block)
7879
*/
7980
if( tag_len < 4 || tag_len > 16 || tag_len % 2 != 0 )
80-
return ( MBEDTLS_ERR_CCM_BAD_INPUT );
81+
return( MBEDTLS_ERR_CCM_BAD_INPUT );
8182

82-
if( tag_len > sizeof( CC_Mac_Res ) )
83-
return ( MBEDTLS_ERR_CCM_BAD_INPUT );
83+
if( tag_len > sizeof( cc_mac_res ) )
84+
return( MBEDTLS_ERR_CCM_BAD_INPUT );
8485

8586
/* Also implies q is within bounds */
8687
if( iv_len < 7 || iv_len > 13 )
87-
return ( MBEDTLS_ERR_CCM_BAD_INPUT );
88+
return( MBEDTLS_ERR_CCM_BAD_INPUT );
8889

8990
#if SIZE_MAX > UINT_MAX
9091
if( length > 0xFFFFFFFF || add_len > 0xFFFFFFFF )
91-
return ( MBEDTLS_ERR_CCM_BAD_INPUT );
92+
return( MBEDTLS_ERR_CCM_BAD_INPUT );
9293
#endif
9394

94-
CrysRet = CRYS_AESCCM( SASI_AES_ENCRYPT, ctx->cipher_key, ctx->keySize_ID, (uint8_t*)iv, iv_len,
95-
(uint8_t*)add, add_len, (uint8_t*)input, length, output, tag_len, CC_Mac_Res );
96-
if( CrysRet == CRYS_AESCCM_ILLEGAL_PARAMETER_SIZE_ERROR )
95+
crys_ret = CRYS_AESCCM( SASI_AES_ENCRYPT, ctx->cipher_key, ctx->key_size,
96+
(uint8_t*)iv, iv_len, (uint8_t*)add, add_len,
97+
(uint8_t*)input, length, output, tag_len,
98+
cc_mac_res );
99+
if( crys_ret == CRYS_AESCCM_ILLEGAL_PARAMETER_SIZE_ERROR )
97100
{
98-
ret = MBEDTLS_ERR_CCM_BAD_INPUT;
99-
goto exit;
101+
ret = MBEDTLS_ERR_CCM_BAD_INPUT;
102+
goto exit;
100103
}
101-
else if ( CrysRet != CRYS_OK )
104+
else if( crys_ret != CRYS_OK )
102105
{
103106
ret = MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED;
104107
goto exit;
105108
}
106109

107-
memcpy( tag, CC_Mac_Res, tag_len );
110+
memcpy( tag, cc_mac_res, tag_len );
108111

109112
exit:
110-
return ( ret );
113+
return( ret );
111114

112115
}
113116

@@ -121,28 +124,30 @@ int mbedtls_ccm_auth_decrypt( mbedtls_ccm_context *ctx, size_t length,
121124
const unsigned char *tag, size_t tag_len )
122125

123126
{
124-
CRYSError_t CrysRet = CRYS_OK;
127+
CRYSError_t crys_ret = CRYS_OK;
125128
int ret = 0;
126129
/*
127130
* Check length requirements: SP800-38C A.1
128131
* Additional requirement: a < 2^16 - 2^8 to simplify the code.
129132
* 'length' checked later (when writing it to the first block)
130133
*/
131134
if( tag_len < 4 || tag_len > 16 || tag_len % 2 != 0 )
132-
return ( MBEDTLS_ERR_CCM_BAD_INPUT );
135+
return( MBEDTLS_ERR_CCM_BAD_INPUT );
133136

134137
/* Also implies q is within bounds */
135138
if( iv_len < 7 || iv_len > 13 )
136-
return ( MBEDTLS_ERR_CCM_BAD_INPUT );
139+
return( MBEDTLS_ERR_CCM_BAD_INPUT );
137140

138141
#if SIZE_MAX > UINT_MAX
139142
if( length > 0xFFFFFFFF || add_len > 0xFFFFFFFF )
140-
return ( MBEDTLS_ERR_CCM_BAD_INPUT );
143+
return( MBEDTLS_ERR_CCM_BAD_INPUT );
141144
#endif
142145

143-
CrysRet = CRYS_AESCCM( SASI_AES_DECRYPT, ctx->cipher_key, ctx->keySize_ID,(uint8_t*)iv, iv_len,
144-
(uint8_t*)add, add_len, (uint8_t*)input, length, output, tag_len, (uint8_t*)tag );
145-
if( CrysRet == CRYS_AESCCM_ILLEGAL_PARAMETER_SIZE_ERROR )
146+
crys_ret = CRYS_AESCCM( SASI_AES_DECRYPT, ctx->cipher_key, ctx->key_size,
147+
(uint8_t*)iv, iv_len, (uint8_t*)add, add_len,
148+
(uint8_t*)input, length, output, tag_len,
149+
(uint8_t*)tag );
150+
if( crys_ret == CRYS_AESCCM_ILLEGAL_PARAMETER_SIZE_ERROR )
146151
{
147152
/*
148153
* When CRYS_AESCCM_ILLEGAL_PARAMETER_SIZE_ERROR is returned,
@@ -151,9 +156,9 @@ int mbedtls_ccm_auth_decrypt( mbedtls_ccm_context *ctx, size_t length,
151156
* returning this error code, and we don't want to overflow
152157
* the output buffer.
153158
*/
154-
return( MBEDTLS_ERR_CCM_BAD_INPUT );
159+
return( MBEDTLS_ERR_CCM_BAD_INPUT );
155160
}
156-
else if( CrysRet == CRYS_FATAL_ERROR )
161+
else if( crys_ret == CRYS_FATAL_ERROR )
157162
{
158163
/*
159164
* Unfortunately, Crys AESCCM returns CRYS_FATAL_ERROR when
@@ -162,7 +167,7 @@ int mbedtls_ccm_auth_decrypt( mbedtls_ccm_context *ctx, size_t length,
162167
ret = MBEDTLS_ERR_CCM_AUTH_FAILED;
163168
goto exit;
164169
}
165-
else if ( CrysRet != CRYS_OK )
170+
else if( crys_ret != CRYS_OK )
166171
{
167172
ret = MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED;
168173
goto exit;
@@ -176,24 +181,23 @@ int mbedtls_ccm_auth_decrypt( mbedtls_ccm_context *ctx, size_t length,
176181
}
177182

178183
int mbedtls_ccm_star_encrypt_and_tag( mbedtls_ccm_context *ctx, size_t length,
179-
const unsigned char *iv, size_t iv_len,
180-
const unsigned char *add, size_t add_len,
181-
const unsigned char *input, unsigned char *output,
182-
unsigned char *tag, size_t tag_len )
184+
const unsigned char *iv, size_t iv_len,
185+
const unsigned char *add, size_t add_len,
186+
const unsigned char *input,
187+
unsigned char *output,
188+
unsigned char *tag, size_t tag_len )
183189
{
184-
185190
return( MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE );
186-
187191
}
188192

189193
int mbedtls_ccm_star_auth_decrypt( mbedtls_ccm_context *ctx, size_t length,
190-
const unsigned char *iv, size_t iv_len,
191-
const unsigned char *add, size_t add_len,
192-
const unsigned char *input, unsigned char *output,
193-
const unsigned char *tag, size_t tag_len )
194+
const unsigned char *iv, size_t iv_len,
195+
const unsigned char *add, size_t add_len,
196+
const unsigned char *input,
197+
unsigned char *output,
198+
const unsigned char *tag, size_t tag_len )
194199
{
195200
return( MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE );
196-
197201
}
198202

199203
#endif

features/cryptocell/FEATURE_CRYPTOCELL310/ccm_alt.h

Lines changed: 2 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -24,104 +24,11 @@
2424
#if defined(MBEDTLS_CCM_ALT)
2525
#include "crys_aesccm.h"
2626

27-
#ifdef __cplusplus
28-
extern "C" {
29-
#endif
30-
3127
typedef struct {
32-
CRYS_AESCCM_Key_t cipher_key; /*!< cipher key used */
33-
CRYS_AESCCM_KeySize_t keySize_ID;
28+
CRYS_AESCCM_Key_t cipher_key; /*!< cipher key used */
29+
CRYS_AESCCM_KeySize_t key_size;
3430
}
3531
mbedtls_ccm_context;
3632

37-
/**
38-
* \brief Initialize CCM context (just makes references valid)
39-
* Makes the context ready for mbedtls_ccm_setkey() or
40-
* mbedtls_ccm_free().
41-
*
42-
* \param ctx CCM context to initialize
43-
*/
44-
void mbedtls_ccm_init( mbedtls_ccm_context *ctx );
45-
46-
/**
47-
* \brief CCM initialization (encryption and decryption)
48-
*
49-
* \param ctx CCM context to be initialized
50-
* \param cipher cipher to use (a 128-bit block cipher)
51-
* \param key encryption key
52-
* \param keybits key size in bits (must be acceptable by the cipher)
53-
*
54-
* \return 0 if successful, or a cipher specific error code
55-
*/
56-
int mbedtls_ccm_setkey( mbedtls_ccm_context *ctx,
57-
mbedtls_cipher_id_t cipher,
58-
const unsigned char *key,
59-
unsigned int keybits );
60-
61-
/**
62-
* \brief Free a CCM context and underlying cipher sub-context
63-
*
64-
* \param ctx CCM context to free
65-
*/
66-
void mbedtls_ccm_free( mbedtls_ccm_context *ctx );
67-
68-
/**
69-
* \brief CCM buffer encryption
70-
*
71-
* \param ctx CCM context
72-
* \param length length of the input data in bytes
73-
* \param iv nonce (initialization vector)
74-
* \param iv_len length of IV in bytes
75-
* must be 2, 3, 4, 5, 6, 7 or 8
76-
* \param add additional data
77-
* \param add_len length of additional data in bytes
78-
* must be less than 2^16 - 2^8
79-
* \param input buffer holding the input data
80-
* \param output buffer for holding the output data
81-
* must be at least 'length' bytes wide
82-
* \param tag buffer for holding the tag
83-
* \param tag_len length of the tag to generate in bytes
84-
* must be 4, 6, 8, 10, 14 or 16
85-
*
86-
* \note The tag is written to a separate buffer. To get the tag
87-
* concatenated with the output as in the CCM spec, use
88-
* tag = output + length and make sure the output buffer is
89-
* at least length + tag_len wide.
90-
*
91-
* \return 0 if successful
92-
*/
93-
int mbedtls_ccm_encrypt_and_tag( mbedtls_ccm_context *ctx, size_t length,
94-
const unsigned char *iv, size_t iv_len,
95-
const unsigned char *add, size_t add_len,
96-
const unsigned char *input, unsigned char *output,
97-
unsigned char *tag, size_t tag_len );
98-
99-
/**
100-
* \brief CCM buffer authenticated decryption
101-
*
102-
* \param ctx CCM context
103-
* \param length length of the input data
104-
* \param iv initialization vector
105-
* \param iv_len length of IV
106-
* \param add additional data
107-
* \param add_len length of additional data
108-
* \param input buffer holding the input data
109-
* \param output buffer for holding the output data
110-
* \param tag buffer holding the tag
111-
* \param tag_len length of the tag
112-
*
113-
* \return 0 if successful and authenticated,
114-
* MBEDTLS_ERR_CCM_AUTH_FAILED if tag does not match
115-
*/
116-
int mbedtls_ccm_auth_decrypt( mbedtls_ccm_context *ctx, size_t length,
117-
const unsigned char *iv, size_t iv_len,
118-
const unsigned char *add, size_t add_len,
119-
const unsigned char *input, unsigned char *output,
120-
const unsigned char *tag, size_t tag_len );
121-
122-
#ifdef __cplusplus
123-
}
124-
#endif
125-
12633
#endif /* MBEDTLS_CCM_ALT */
12734
#endif /* __CCM_ALT__ */

0 commit comments

Comments
 (0)