Skip to content

Commit d14a0dc

Browse files
committed
crypto/mbedtls: Fix gcm_mynewt coding style
This adjusts codings style for the latest clang-format requirements
1 parent a80a874 commit d14a0dc

File tree

3 files changed

+66
-68
lines changed

3 files changed

+66
-68
lines changed

crypto/mbedtls/include/mbedtls/gcm_mynewt.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,9 @@
2626
/**
2727
* Same as mbedtls_gcm_setkey, but with preallocated memory for cipher algorithm context
2828
*/
29-
int mbedtls_gcm_setkey_noalloc( mbedtls_gcm_context *ctx,
30-
const mbedtls_cipher_info_t *cipher_info,
31-
const unsigned char *key,
32-
unsigned int keybits,
33-
void *cipher_ctx);
34-
29+
int mbedtls_gcm_setkey_noalloc(mbedtls_gcm_context *ctx,
30+
const mbedtls_cipher_info_t *cipher_info,
31+
const unsigned char *key, unsigned int keybits,
32+
void *cipher_ctx);
3533

3634
#endif /* _GCM_MYNEWT_H_ */

crypto/mbedtls/selftest/src/testcases/gcm_mynewt_test.c

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,32 +24,33 @@ static const mbedtls_cipher_info_t *rsm_ucast_cipher;
2424

2525
/* This contains both ADD and plaintext for encryption */
2626
static const uint8_t initial_data[110] = {
27-
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A,
28-
0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A,
29-
0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A,
30-
0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A,
31-
0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A,
32-
0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A,
33-
0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A,
34-
0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A,
35-
0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A,
36-
0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A,
37-
0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA
27+
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x11,
28+
0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x21, 0x22,
29+
0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x31, 0x32, 0x33,
30+
0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x41, 0x42, 0x43, 0x44,
31+
0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x51, 0x52, 0x53, 0x54, 0x55,
32+
0x56, 0x57, 0x58, 0x59, 0x5A, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
33+
0x67, 0x68, 0x69, 0x6A, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
34+
0x78, 0x79, 0x7A, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88,
35+
0x89, 0x8A, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99,
36+
0x9A, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA
3837
};
39-
static const uint8_t key[32] = {
40-
0xC0, 0xCA, 0xC0, 0x1A, 0xC0, 0xCA, 0xC0, 0x1A,
41-
0xC0, 0xCA, 0xC0, 0x1A, 0xC0, 0xCA, 0xC0, 0x1A,
42-
0xC0, 0xCA, 0xC0, 0x1A, 0xC0, 0xCA, 0xC0, 0x1A,
43-
0xC0, 0xCA, 0xC0, 0x1A, 0xC0, 0xCA, 0xC0, 0x1A
44-
};
45-
static const uint8_t iv[12] = { 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xA, 0xB };
46-
static const uint8_t expected_tag[16] = { 0x05, 0x5D, 0x8E, 0xD4, 0xF9, 0x2A, 0x87, 0x87,
47-
0x6F, 0x23, 0xF2, 0xE6, 0xF0, 0x1D, 0x6D, 0x5C };
38+
static const uint8_t key[32] = { 0xC0, 0xCA, 0xC0, 0x1A, 0xC0, 0xCA, 0xC0,
39+
0x1A, 0xC0, 0xCA, 0xC0, 0x1A, 0xC0, 0xCA,
40+
0xC0, 0x1A, 0xC0, 0xCA, 0xC0, 0x1A, 0xC0,
41+
0xCA, 0xC0, 0x1A, 0xC0, 0xCA, 0xC0, 0x1A,
42+
0xC0, 0xCA, 0xC0, 0x1A };
43+
static const uint8_t iv[12] = { 0x0, 0x1, 0x2, 0x3, 0x4, 0x5,
44+
0x6, 0x7, 0x8, 0x9, 0xA, 0xB };
45+
static const uint8_t expected_tag[16] = { 0x05, 0x5D, 0x8E, 0xD4, 0xF9, 0x2A,
46+
0x87, 0x87, 0x6F, 0x23, 0xF2, 0xE6,
47+
0xF0, 0x1D, 0x6D, 0x5C };
4848

4949
static uint8_t test_tag[16];
5050
static uint8_t test_buf[110];
5151

52-
static int mbedtls_gcm_mynewt_test_crypt(uint8_t enc)
52+
static int
53+
mbedtls_gcm_mynewt_test_crypt(uint8_t enc)
5354
{
5455
int add_len = 40;
5556
mbedtls_gcm_context ctx;
@@ -63,9 +64,8 @@ static int mbedtls_gcm_mynewt_test_crypt(uint8_t enc)
6364
int rc;
6465

6566
if (rsm_ucast_cipher == NULL) {
66-
rsm_ucast_cipher =
67-
mbedtls_cipher_info_from_values(MBEDTLS_CIPHER_ID_AES, 256,
68-
MBEDTLS_MODE_ECB);
67+
rsm_ucast_cipher = mbedtls_cipher_info_from_values(MBEDTLS_CIPHER_ID_AES,
68+
256, MBEDTLS_MODE_ECB);
6969
}
7070

7171
memset(&ctx, 0, sizeof(ctx));
@@ -75,8 +75,7 @@ static int mbedtls_gcm_mynewt_test_crypt(uint8_t enc)
7575
goto out;
7676
}
7777

78-
rc = mbedtls_gcm_starts(&ctx,
79-
enc == 1 ? MBEDTLS_GCM_ENCRYPT : MBEDTLS_GCM_DECRYPT,
78+
rc = mbedtls_gcm_starts(&ctx, enc == 1 ? MBEDTLS_GCM_ENCRYPT : MBEDTLS_GCM_DECRYPT,
8079
iv, sizeof(iv));
8180
if (rc) {
8281
goto out;

crypto/mbedtls/src/gcm_mynewt.c

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,13 @@
6969
#if !defined(MBEDTLS_GCM_ALT)
7070

7171
/* Used to select the acceleration mechanism */
72-
#define MBEDTLS_GCM_ACC_SMALLTABLE 0
73-
#define MBEDTLS_GCM_ACC_LARGETABLE 1
74-
#define MBEDTLS_GCM_ACC_AESNI 2
75-
#define MBEDTLS_GCM_ACC_AESCE 3
72+
#define MBEDTLS_GCM_ACC_SMALLTABLE 0
73+
#define MBEDTLS_GCM_ACC_LARGETABLE 1
74+
#define MBEDTLS_GCM_ACC_AESNI 2
75+
#define MBEDTLS_GCM_ACC_AESCE 3
7676

77-
static inline void gcm_set_acceleration(mbedtls_gcm_context *ctx)
77+
static inline void
78+
gcm_set_acceleration(mbedtls_gcm_context *ctx)
7879
{
7980
#if defined(MBEDTLS_GCM_LARGE_TABLE)
8081
ctx->acceleration = MBEDTLS_GCM_ACC_LARGETABLE;
@@ -96,10 +97,11 @@ static inline void gcm_set_acceleration(mbedtls_gcm_context *ctx)
9697
#endif
9798
}
9899

99-
static inline void gcm_gen_table_rightshift(uint64_t dst[2], const uint64_t src[2])
100+
static inline void
101+
gcm_gen_table_rightshift(uint64_t dst[2], const uint64_t src[2])
100102
{
101-
uint8_t *u8Dst = (uint8_t *) dst;
102-
uint8_t *u8Src = (uint8_t *) src;
103+
uint8_t *u8Dst = (uint8_t *)dst;
104+
uint8_t *u8Src = (uint8_t *)src;
103105

104106
MBEDTLS_PUT_UINT64_BE(MBEDTLS_GET_UINT64_BE(&src[1], 0) >> 1, &dst[1], 0);
105107
u8Dst[8] |= (u8Src[7] & 0x01) << 7;
@@ -115,11 +117,12 @@ static inline void gcm_gen_table_rightshift(uint64_t dst[2], const uint64_t src[
115117
* is the high-order bit of HH corresponds to P^0 and the low-order bit of HL
116118
* corresponds to P^127.
117119
*/
118-
static int gcm_gen_table(mbedtls_gcm_context *ctx)
120+
static int
121+
gcm_gen_table(mbedtls_gcm_context *ctx)
119122
{
120123
int ret, i, j;
121124
uint64_t u64h[2] = { 0 };
122-
uint8_t *h = (uint8_t *) u64h;
125+
uint8_t *h = (uint8_t *)u64h;
123126

124127
#if defined(MBEDTLS_BLOCK_CIPHER_C)
125128
ret = mbedtls_block_cipher_encrypt(&ctx->block_cipher_ctx, h, h);
@@ -134,55 +137,54 @@ static int gcm_gen_table(mbedtls_gcm_context *ctx)
134137
gcm_set_acceleration(ctx);
135138

136139
/* MBEDTLS_GCM_HTABLE_SIZE/2 = 1000 corresponds to 1 in GF(2^128) */
137-
ctx->H[MBEDTLS_GCM_HTABLE_SIZE/2][0] = u64h[0];
138-
ctx->H[MBEDTLS_GCM_HTABLE_SIZE/2][1] = u64h[1];
140+
ctx->H[MBEDTLS_GCM_HTABLE_SIZE / 2][0] = u64h[0];
141+
ctx->H[MBEDTLS_GCM_HTABLE_SIZE / 2][1] = u64h[1];
139142

140143
switch (ctx->acceleration) {
141144
#if defined(MBEDTLS_AESNI_HAVE_CODE)
142-
case MBEDTLS_GCM_ACC_AESNI:
143-
return 0;
145+
case MBEDTLS_GCM_ACC_AESNI:
146+
return 0;
144147
#endif
145148

146149
#if defined(MBEDTLS_AESCE_HAVE_CODE)
147-
case MBEDTLS_GCM_ACC_AESCE:
148-
return 0;
150+
case MBEDTLS_GCM_ACC_AESCE:
151+
return 0;
149152
#endif
150153

151154
default:
152155
/* 0 corresponds to 0 in GF(2^128) */
153156
ctx->H[0][0] = 0;
154157
ctx->H[0][1] = 0;
155158

156-
for (i = MBEDTLS_GCM_HTABLE_SIZE/4; i > 0; i >>= 1) {
157-
gcm_gen_table_rightshift(ctx->H[i], ctx->H[i*2]);
159+
for (i = MBEDTLS_GCM_HTABLE_SIZE / 4; i > 0; i >>= 1) {
160+
gcm_gen_table_rightshift(ctx->H[i], ctx->H[i * 2]);
158161
}
159162

160163
#if !defined(MBEDTLS_GCM_LARGE_TABLE)
161164
/* pack elements of H as 64-bits ints, big-endian */
162-
for (i = MBEDTLS_GCM_HTABLE_SIZE/2; i > 0; i >>= 1) {
165+
for (i = MBEDTLS_GCM_HTABLE_SIZE / 2; i > 0; i >>= 1) {
163166
MBEDTLS_PUT_UINT64_BE(ctx->H[i][0], &ctx->H[i][0], 0);
164167
MBEDTLS_PUT_UINT64_BE(ctx->H[i][1], &ctx->H[i][1], 0);
165168
}
166169
#endif
167170

168171
for (i = 2; i < MBEDTLS_GCM_HTABLE_SIZE; i <<= 1) {
169172
for (j = 1; j < i; j++) {
170-
mbedtls_xor_no_simd((unsigned char *) ctx->H[i+j],
171-
(unsigned char *) ctx->H[i],
172-
(unsigned char *) ctx->H[j],
173-
16);
173+
mbedtls_xor_no_simd((unsigned char *)ctx->H[i + j],
174+
(unsigned char *)ctx->H[i],
175+
(unsigned char *)ctx->H[j], 16);
174176
}
175177
}
176178
}
177179

178180
return 0;
179181
}
180182

181-
int mbedtls_gcm_setkey_noalloc( mbedtls_gcm_context *ctx,
182-
const mbedtls_cipher_info_t *cipher_info,
183-
const unsigned char *key,
184-
unsigned int keybits,
185-
void *cipher_ctx)
183+
int
184+
mbedtls_gcm_setkey_noalloc(mbedtls_gcm_context *ctx,
185+
const mbedtls_cipher_info_t *cipher_info,
186+
const unsigned char *key, unsigned int keybits,
187+
void *cipher_ctx)
186188
{
187189
int ret;
188190

@@ -205,17 +207,16 @@ int mbedtls_gcm_setkey_noalloc( mbedtls_gcm_context *ctx,
205207
#endif
206208
#endif /* MBEDTLS_CIPHER_MODE_WITH_PADDING */
207209

208-
if( ( ret = mbedtls_cipher_setkey( &ctx->cipher_ctx, key,
209-
keybits,
210-
MBEDTLS_ENCRYPT ) ) != 0 )
211-
{
212-
return( ret );
210+
if ((ret = mbedtls_cipher_setkey(&ctx->cipher_ctx, key, keybits,
211+
MBEDTLS_ENCRYPT)) != 0) {
212+
return ret;
213213
}
214214

215-
if( ( ret = gcm_gen_table( ctx ) ) != 0 )
216-
return( ret );
215+
if ((ret = gcm_gen_table(ctx)) != 0) {
216+
return ret;
217+
}
217218

218-
return( 0 );
219+
return 0;
219220
}
220221
#endif /* !MBEDTLS_GCM_ALT */
221222

0 commit comments

Comments
 (0)