Skip to content

Commit 9c04b32

Browse files
authored
Clang Format (zmap#838)
* clang format options * Clang Format on ZMap 4.1.0-RC1
1 parent c214bcd commit 9c04b32

36 files changed

+326
-330
lines changed

.clang-format

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ PointerAlignment: Right
99
BreakStringLiterals: false
1010
SortIncludes: false
1111
ReflowComments: false
12+
ColumnLimit: 0

lib/aes128.c

Lines changed: 39 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@
1717
#include <string.h>
1818
#include <pthread.h>
1919

20-
2120
#define AES128_ROUNDS 10
2221
#define BITS_PER_BYTE 8
2322

24-
2523
#ifdef AES_HW
2624

2725
#if defined(__x86_64__)
@@ -40,10 +38,10 @@ aes128_hw_supported(void)
4038
}
4139

4240
#if defined(__clang__)
43-
# pragma clang attribute push (__attribute__((target("sse2,aes"))), apply_to=function)
41+
#pragma clang attribute push(__attribute__((target("sse2,aes"))), apply_to = function)
4442
#elif defined(__GNUC__)
45-
# pragma GCC push_options
46-
# pragma GCC target ("sse2,aes")
43+
#pragma GCC push_options
44+
#pragma GCC target("sse2,aes")
4745
#endif
4846

4947
struct aes128_hw_ctx {
@@ -53,7 +51,7 @@ struct aes128_hw_ctx {
5351
static __m128i
5452
aes128_hw_round_key(__m128i rk, __m128i rc)
5553
{
56-
rc = _mm_shuffle_epi32(rc, _MM_SHUFFLE(3,3,3,3));
54+
rc = _mm_shuffle_epi32(rc, _MM_SHUFFLE(3, 3, 3, 3));
5755
rk = _mm_xor_si128(rk, _mm_slli_si128(rk, 4));
5856
rk = _mm_xor_si128(rk, _mm_slli_si128(rk, 4));
5957
rk = _mm_xor_si128(rk, _mm_slli_si128(rk, 4));
@@ -97,42 +95,42 @@ aes128_hw_enc_block(struct aes128_hw_ctx const *ctx, uint8_t const *pt, uint8_t
9795
}
9896

9997
#if defined(__clang__)
100-
# pragma clang attribute pop
98+
#pragma clang attribute pop
10199
#elif defined(__GNUC__)
102-
# pragma GCC pop_options
100+
#pragma GCC pop_options
103101
#endif
104102

105103
#elif defined(__aarch64__)
106104
#define AES_HW_NAME "ARMv8 CE"
107105

108106
#ifdef __ARM_ACLE
109-
# include <arm_acle.h>
107+
#include <arm_acle.h>
110108
#endif
111109
#ifdef __ARM_NEON
112-
# include <arm_neon.h>
110+
#include <arm_neon.h>
113111
#endif
114112

115113
#if defined(__APPLE__)
116-
# include <sys/types.h>
117-
# include <sys/sysctl.h>
114+
#include <sys/types.h>
115+
#include <sys/sysctl.h>
118116
#elif defined(__FreeBSD__)
119-
# include <sys/auxv.h>
120-
# ifndef HWCAP_NEON
121-
# define HWCAP_NEON 0x00001000
122-
# endif
123-
# ifndef HWCAP2_AES
124-
# define HWCAP2_AES 0x00000001
125-
# endif
117+
#include <sys/auxv.h>
118+
#ifndef HWCAP_NEON
119+
#define HWCAP_NEON 0x00001000
120+
#endif
121+
#ifndef HWCAP2_AES
122+
#define HWCAP2_AES 0x00000001
123+
#endif
126124
#elif defined(__linux__)
127-
# include <sys/auxv.h>
128-
# ifndef HWCAP_NEON
129-
# define HWCAP_NEON 0x00000010
130-
# endif
131-
# ifndef HWCAP_AES
132-
# define HWCAP_AES 0x00001000
133-
# endif
125+
#include <sys/auxv.h>
126+
#ifndef HWCAP_NEON
127+
#define HWCAP_NEON 0x00000010
128+
#endif
129+
#ifndef HWCAP_AES
130+
#define HWCAP_AES 0x00001000
131+
#endif
134132
#else
135-
# warning "Runtime detection of AES hardware acceleration not implemented for platform"
133+
#warning "Runtime detection of AES hardware acceleration not implemented for platform"
136134
#endif
137135

138136
static bool
@@ -160,16 +158,17 @@ aes128_hw_supported(void)
160158
}
161159

162160
#if defined(__clang__)
163-
# pragma clang attribute push (__attribute__((target("aes"))), apply_to=function)
161+
#pragma clang attribute push(__attribute__((target("aes"))), apply_to = function)
164162
#elif defined(__GNUC__)
165-
# pragma GCC push_options
166-
# pragma GCC target ("+aes")
163+
#pragma GCC push_options
164+
#pragma GCC target("+aes")
167165
#endif
168166

169167
struct aes128_hw_ctx {
170168
uint8_t rk[AES128_ROUNDS + 1][AES128_KEY_BYTES];
171169
};
172170

171+
// clang-format off
173172
static uint8_t const sbox[256] = {
174173
0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76,
175174
0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0,
@@ -188,8 +187,9 @@ static uint8_t const sbox[256] = {
188187
0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
189188
0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16,
190189
};
190+
// clang-format on
191191

192-
static uint8_t const rcon[AES128_ROUNDS + 1] = { 0, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36 };
192+
static uint8_t const rcon[AES128_ROUNDS + 1] = {0, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36};
193193

194194
static void
195195
aes128_hw_key_sched(uint8_t const *key, struct aes128_hw_ctx *ctx)
@@ -234,9 +234,9 @@ aes128_hw_enc_block(struct aes128_hw_ctx const *ctx, uint8_t const *pt, uint8_t
234234
}
235235

236236
#if defined(__clang__)
237-
# pragma clang attribute pop
237+
#pragma clang attribute pop
238238
#elif defined(__GNUC__)
239-
# pragma GCC pop_options
239+
#pragma GCC pop_options
240240
#endif
241241

242242
#else
@@ -245,7 +245,6 @@ aes128_hw_enc_block(struct aes128_hw_ctx const *ctx, uint8_t const *pt, uint8_t
245245

246246
#endif // AES_HW
247247

248-
249248
struct aes128_ctx {
250249
union {
251250
struct {
@@ -298,8 +297,7 @@ aes128_init(uint8_t const *key)
298297
return ctx;
299298
}
300299

301-
void
302-
aes128_encrypt_block(aes128_ctx_t *ctx, uint8_t const *pt, uint8_t *ct)
300+
void aes128_encrypt_block(aes128_ctx_t *ctx, uint8_t const *pt, uint8_t *ct)
303301
{
304302
#ifdef AES_HW
305303
if (use_hw) {
@@ -311,19 +309,17 @@ aes128_encrypt_block(aes128_ctx_t *ctx, uint8_t const *pt, uint8_t *ct)
311309
rijndaelEncrypt(ctx->u.sw.rk, AES128_ROUNDS, pt, ct);
312310
}
313311

314-
void
315-
aes128_fini(aes128_ctx_t *ctx)
312+
void aes128_fini(aes128_ctx_t *ctx)
316313
{
317314
free(ctx);
318315
}
319316

320-
void
321-
aes128_selftest(void)
317+
void aes128_selftest(void)
322318
{
323319
// Test vector from appendix C of NIST FIPS-197.
324-
uint8_t const pt[AES128_BLOCK_BYTES] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff };
325-
uint8_t const key[AES128_KEY_BYTES] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
326-
uint8_t const expected_ct[AES128_BLOCK_BYTES] = { 0x69, 0xc4, 0xe0, 0xd8, 0x6a, 0x7b, 0x04, 0x30, 0xd8, 0xcd, 0xb7, 0x80, 0x70, 0xb4, 0xc5, 0x5a };
320+
uint8_t const pt[AES128_BLOCK_BYTES] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff};
321+
uint8_t const key[AES128_KEY_BYTES] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f};
322+
uint8_t const expected_ct[AES128_BLOCK_BYTES] = {0x69, 0xc4, 0xe0, 0xd8, 0x6a, 0x7b, 0x04, 0x30, 0xd8, 0xcd, 0xb7, 0x80, 0x70, 0xb4, 0xc5, 0x5a};
327323

328324
uint8_t actual_ct[AES128_BLOCK_BYTES];
329325
memset(actual_ct, 0, sizeof(actual_ct));

lib/aes128.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
typedef struct aes128_ctx aes128_ctx_t;
1818

19-
aes128_ctx_t * aes128_init(uint8_t const *key);
19+
aes128_ctx_t *aes128_init(uint8_t const *key);
2020
void aes128_encrypt_block(aes128_ctx_t *ctx, uint8_t const *pt, uint8_t *ct);
2121
void aes128_fini(aes128_ctx_t *ctx);
2222

lib/blocklist.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ void allowlist_prefix(char *ip, int prefix_len)
102102
_add_constraint(addr, prefix_len, ADDR_ALLOWED);
103103
}
104104

105-
static int is_ip_ipv6(char *ip) {
105+
static int is_ip_ipv6(char *ip)
106+
{
106107
// don't modify the input string
107108
char *new_str = strdup(ip);
108109
// check if there's a subnet mask_char

lib/constraint.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ typedef struct node {
7575
#define RADIX_LENGTH 20
7676

7777
struct _constraint {
78-
node_t *root; // root node of the tree
79-
uint32_t *radix; // array of prefixes (/RADIX_LENGTH) that are painted
80-
// paint_value
81-
size_t radix_len; // number of prefixes in radix array
82-
int painted; // have we precomputed counts for each node?
78+
node_t *root; // root node of the tree
79+
uint32_t *radix; // array of prefixes (/RADIX_LENGTH) that are painted
80+
// paint_value
81+
size_t radix_len; // number of prefixes in radix array
82+
int painted; // have we precomputed counts for each node?
8383
value_t paint_value; // value for which we precomputed counts
8484
};
8585

lib/logger.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ static int color = 0;
3030
static int log_to_syslog = 0;
3131

3232
static const char *log_level_name[] = {"FATAL", "ERROR", "WARN",
33-
"INFO", "DEBUG", "TRACE"};
33+
"INFO", "DEBUG", "TRACE"};
3434

3535
#define RED "\x1b[31m"
3636
#define GREEN "\x1b[32m"
@@ -40,10 +40,10 @@ static const char *log_level_name[] = {"FATAL", "ERROR", "WARN",
4040
#define CYAN "\x1b[36m"
4141
#define RESET "\033[0m"
4242

43-
#define COLOR(x) \
44-
do { \
45-
if (color) \
46-
fprintf(log_output_stream, "%s", x); \
43+
#define COLOR(x) \
44+
do { \
45+
if (color) \
46+
fprintf(log_output_stream, "%s", x); \
4747
} while (0)
4848

4949
static const char *color_for_level(enum LogLevel level)

0 commit comments

Comments
 (0)