Skip to content

Commit 071e17a

Browse files
committed
clang-format almost all first-party code
Added a .clang-format file and auto-formatted almost all first-party code (all except core/include/config.h). Required some additional #include directives in a few headers, due to changes in #include ordering. Also fixed up CMakeLists.txt: - aes_gcm_dev.h is only included in dev builds - aes_gcm_ncipher.h is only included in ncipher builds. Required some additional #include directives in a few headers, due to changes in #include ordering.
1 parent 9879eea commit 071e17a

61 files changed

Lines changed: 1012 additions & 792 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

core/.clang-format

Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
# see https://clang.llvm.org/docs/ClangFormatStyleOptions.html
2+
---
3+
# BasedOnStyle: Mozilla
4+
5+
Language: Cpp
6+
AccessModifierOffset: -2
7+
AlignAfterOpenBracket: AlwaysBreak
8+
AlignArrayOfStructures: None
9+
AlignConsecutiveAssignments:
10+
Enabled: false
11+
AcrossEmptyLines: false
12+
AcrossComments: false
13+
AlignCompound: false
14+
PadOperators: true
15+
AlignConsecutiveBitFields:
16+
Enabled: false
17+
AcrossEmptyLines: false
18+
AcrossComments: false
19+
AlignCompound: false
20+
PadOperators: false
21+
AlignConsecutiveDeclarations:
22+
Enabled: false
23+
AcrossEmptyLines: false
24+
AcrossComments: false
25+
AlignCompound: false
26+
PadOperators: false
27+
AlignConsecutiveMacros:
28+
Enabled: false
29+
AcrossEmptyLines: false
30+
AcrossComments: false
31+
AlignCompound: false
32+
PadOperators: false
33+
AlignEscapedNewlines: Left
34+
AlignOperands: Align
35+
AlignTrailingComments:
36+
Kind: Always
37+
OverEmptyLines: 0
38+
AllowAllArgumentsOnNextLine: true
39+
AllowAllParametersOfDeclarationOnNextLine: false
40+
AllowShortBlocksOnASingleLine: Never
41+
AllowShortCaseLabelsOnASingleLine: false
42+
AllowShortEnumsOnASingleLine: true
43+
AllowShortFunctionsOnASingleLine: Inline
44+
AllowShortIfStatementsOnASingleLine: Never
45+
AllowShortLambdasOnASingleLine: All
46+
AllowShortLoopsOnASingleLine: false
47+
AlwaysBreakAfterDefinitionReturnType: None
48+
AlwaysBreakAfterReturnType: None
49+
AlwaysBreakBeforeMultilineStrings: true
50+
AlwaysBreakTemplateDeclarations: Yes
51+
AttributeMacros:
52+
- __capability
53+
BinPackArguments: false
54+
BinPackParameters: false
55+
BitFieldColonSpacing: Both
56+
BraceWrapping:
57+
AfterCaseLabel: false
58+
AfterClass: false
59+
AfterControlStatement: Never
60+
AfterEnum: false
61+
AfterExternBlock: false
62+
AfterFunction: false
63+
AfterNamespace: false
64+
AfterObjCDeclaration: false
65+
AfterStruct: false
66+
AfterUnion: false
67+
BeforeCatch: false
68+
BeforeElse: false
69+
BeforeLambdaBody: false
70+
BeforeWhile: false
71+
IndentBraces: false
72+
SplitEmptyFunction: false
73+
SplitEmptyRecord: false
74+
SplitEmptyNamespace: false
75+
BreakAfterAttributes: Never
76+
BreakAfterJavaFieldAnnotations: false
77+
BreakArrays: false
78+
BreakBeforeBinaryOperators: None
79+
BreakBeforeConceptDeclarations: Always
80+
BreakBeforeBraces: Custom
81+
BreakBeforeInlineASMColon: OnlyMultiline
82+
BreakBeforeTernaryOperators: true
83+
BreakConstructorInitializers: AfterColon
84+
BreakInheritanceList: AfterColon
85+
BreakStringLiterals: true
86+
ColumnLimit: 120
87+
CommentPragmas: '^ IWYU pragma:'
88+
CompactNamespaces: false
89+
ConstructorInitializerIndentWidth: 4
90+
ContinuationIndentWidth: 4
91+
Cpp11BracedListStyle: false
92+
DerivePointerAlignment: false
93+
DisableFormat: false
94+
EmptyLineAfterAccessModifier: Never
95+
EmptyLineBeforeAccessModifier: LogicalBlock
96+
ExperimentalAutoDetectBinPacking: false
97+
FixNamespaceComments: true
98+
ForEachMacros:
99+
- foreach
100+
- Q_FOREACH
101+
- BOOST_FOREACH
102+
IfMacros:
103+
- KJ_IF_MAYBE
104+
IncludeBlocks: Regroup
105+
IncludeCategories:
106+
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
107+
Priority: 2
108+
SortPriority: 0
109+
CaseSensitive: false
110+
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
111+
Priority: 3
112+
SortPriority: 0
113+
CaseSensitive: false
114+
- Regex: '.*'
115+
Priority: 1
116+
SortPriority: 0
117+
CaseSensitive: false
118+
IncludeIsMainRegex: '(Test)?$'
119+
IncludeIsMainSourceRegex: ''
120+
IndentAccessModifiers: false
121+
IndentCaseBlocks: false
122+
IndentCaseLabels: false
123+
IndentExternBlock: AfterExternBlock
124+
IndentGotoLabels: true
125+
IndentPPDirectives: BeforeHash
126+
IndentRequiresClause: true
127+
IndentWidth: 2
128+
IndentWrappedFunctionNames: false
129+
InsertBraces: true
130+
InsertNewlineAtEOF: true
131+
InsertTrailingCommas: None
132+
IntegerLiteralSeparator:
133+
Binary: 0
134+
BinaryMinDigits: 0
135+
Decimal: 0
136+
DecimalMinDigits: 0
137+
Hex: 0
138+
HexMinDigits: 0
139+
JavaScriptQuotes: Leave
140+
JavaScriptWrapImports: true
141+
KeepEmptyLinesAtTheStartOfBlocks: false
142+
LambdaBodyIndentation: Signature
143+
LineEnding: DeriveLF
144+
MacroBlockBegin: ''
145+
MacroBlockEnd: ''
146+
MaxEmptyLinesToKeep: 1
147+
NamespaceIndentation: None
148+
ObjCBinPackProtocolList: Auto
149+
ObjCBlockIndentWidth: 2
150+
ObjCBreakBeforeNestedBlockParam: true
151+
ObjCSpaceAfterProperty: true
152+
ObjCSpaceBeforeProtocolList: false
153+
PackConstructorInitializers: CurrentLine
154+
PenaltyBreakAssignment: 2
155+
PenaltyBreakBeforeFirstCallParameter: 19
156+
PenaltyBreakComment: 300
157+
PenaltyBreakFirstLessLess: 120
158+
PenaltyBreakOpenParenthesis: 0
159+
PenaltyBreakString: 1000
160+
PenaltyBreakTemplateDeclaration: 10
161+
PenaltyExcessCharacter: 1000000
162+
PenaltyIndentedWhitespace: 0
163+
PenaltyReturnTypeOnItsOwnLine: 200
164+
PointerAlignment: Left
165+
PPIndentWidth: -1
166+
QualifierAlignment: Leave
167+
ReferenceAlignment: Pointer
168+
ReflowComments: true
169+
RemoveBracesLLVM: false
170+
RemoveSemicolon: true
171+
RequiresClausePosition: OwnLine
172+
RequiresExpressionIndentation: OuterScope
173+
SeparateDefinitionBlocks: Always
174+
ShortNamespaceLines: 1
175+
SortIncludes: CaseSensitive
176+
SortJavaStaticImport: Before
177+
SortUsingDeclarations: LexicographicNumeric
178+
SpaceAfterCStyleCast: true
179+
SpaceAfterLogicalNot: false
180+
SpaceAfterTemplateKeyword: false
181+
SpaceAroundPointerQualifiers: Default
182+
SpaceBeforeAssignmentOperators: true
183+
SpaceBeforeCaseColon: false
184+
SpaceBeforeCpp11BracedList: false
185+
SpaceBeforeCtorInitializerColon: true
186+
SpaceBeforeInheritanceColon: true
187+
SpaceBeforeParens: Custom
188+
SpaceBeforeParensOptions:
189+
AfterControlStatements: true
190+
AfterForeachMacros: true
191+
AfterFunctionDefinitionName: false
192+
AfterFunctionDeclarationName: false
193+
AfterIfMacros: true
194+
AfterOverloadedOperator: false
195+
AfterRequiresInClause: false
196+
AfterRequiresInExpression: false
197+
BeforeNonEmptyParentheses: false
198+
SpaceBeforeRangeBasedForLoopColon: true
199+
SpaceBeforeSquareBrackets: false
200+
SpaceInEmptyBlock: false
201+
SpaceInEmptyParentheses: false
202+
SpacesBeforeTrailingComments: 1
203+
SpacesInAngles: Never
204+
SpacesInConditionalStatement: false
205+
SpacesInContainerLiterals: false
206+
SpacesInCStyleCastParentheses: false
207+
SpacesInLineCommentPrefix:
208+
Minimum: 1
209+
Maximum: -1
210+
SpacesInParentheses: false
211+
SpacesInSquareBrackets: false
212+
Standard: Latest
213+
StatementAttributeLikeMacros:
214+
- Q_EMIT
215+
StatementMacros:
216+
- Q_UNUSED
217+
- QT_REQUIRE_VERSION
218+
TabWidth: 8
219+
UseTab: Never
220+
WhitespaceSensitiveMacros:
221+
- BOOST_PP_STRINGIZE
222+
- CF_SWIFT_NAME
223+
- NS_SWIFT_NAME
224+
- PP_STRINGIZE
225+
- STRINGIZE

core/CMakeLists.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,6 @@ set(checks_SRC
8989
list(APPEND main_SRC ${checks_SRC})
9090

9191
set(include_SRC
92-
"include/aes_gcm_dev.h"
93-
"include/aes_gcm_ncipher.h"
9492
"include/checks.h"
9593
"include/config.h"
9694
"include/conv.h"
@@ -111,6 +109,8 @@ set(include_SRC
111109
list(APPEND main_SRC ${include_SRC})
112110

113111
if ($ENV{TARGET} MATCHES "nCipher")
112+
list(APPEND include_SRC "include/aes_gcm_ncipher.h")
113+
114114
set(extra_SRC
115115
"src/ncipher/additional_checks.c"
116116
"src/ncipher/aes_gcm.c"
@@ -123,7 +123,9 @@ if ($ENV{TARGET} MATCHES "nCipher")
123123
"src/ncipher/transact.c"
124124
)
125125
list(APPEND main_SRC ${extra_SRC})
126-
else ()
126+
else () # "dev" target
127+
list(APPEND include_SRC "include/aes_gcm_dev.h")
128+
127129
set(extra_SRC
128130
"src/dev/additional_checks.c"
129131
"src/dev/no_rollback.c"

core/external-crypto/.clang-format

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DisableFormat: true

core/include/aes_gcm_dev.h

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#pragma once
22

3+
#include <squareup/subzero/internal.pb.h> // For error codes
4+
#include <stdint.h>
5+
36
/* This header is meant for the dev target, and should only be included in the
47
* dev implementation */
58

@@ -14,17 +17,24 @@
1417
// reserved for an invalid key object in the nCipher target. We would like to
1518
// simulate this behavior in the dev target, and therefore avoid value 0 for
1619
// M_KeyID enum below.
17-
typedef enum {master_seed_encryption_key = 1,
18-
pub_key_encryption_key = 2} M_KeyID;
20+
typedef enum { master_seed_encryption_key = 1, pub_key_encryption_key = 2 } M_KeyID;
1921

2022
// Key encryption key declaration, for AES-128-GCM
2123
// KEK[0], i.e., KEK[master_seed_encryption_key - 1], is master seed encryption key
2224
// KEK[1], i.e., KEK[pub_key_encryption_key], is public key encryption key
2325
extern uint8_t KEK[2][16];
2426

25-
Result aes_gcm_encrypt(M_KeyID keyId, uint8_t *plaintext, size_t plaintext_len,
26-
uint8_t *ciphertext, size_t ciphertext_len,
27-
size_t *bytes_written);
28-
Result aes_gcm_decrypt(M_KeyID keyId, const uint8_t *ciphertext,
29-
size_t ciphertext_len, uint8_t *plaintext,
30-
size_t plaintext_len, size_t *bytes_written);
27+
Result aes_gcm_encrypt(
28+
M_KeyID keyId,
29+
uint8_t* plaintext,
30+
size_t plaintext_len,
31+
uint8_t* ciphertext,
32+
size_t ciphertext_len,
33+
size_t* bytes_written);
34+
Result aes_gcm_decrypt(
35+
M_KeyID keyId,
36+
const uint8_t* ciphertext,
37+
size_t ciphertext_len,
38+
uint8_t* plaintext,
39+
size_t plaintext_len,
40+
size_t* bytes_written);

core/include/aes_gcm_ncipher.h

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,27 @@
11
#pragma once
22

3+
#include <nfastapp.h>
4+
#include <squareup/subzero/internal.pb.h> // For error codes
5+
#include <stdint.h>
6+
37
/* This header is meant for the nCipher target, and should only be included in the
48
* codesafe/ncipher implementation */
59

610
// magic string for binary static analysis
711
// aes_gcm_ncipher:$(echo -n "aes_gcm_ncipher" | sha256sum | cut -c1-16)
812
#define MAGIC "aes_gcm_ncipher:ffb944993c73a1d3"
913

10-
Result aes_gcm_encrypt(M_KeyID keyId, uint8_t *plaintext, size_t plaintext_len,
11-
uint8_t *ciphertext, size_t ciphertext_len,
12-
size_t *bytes_written);
13-
Result aes_gcm_decrypt(M_KeyID keyId, const uint8_t *ciphertext,
14-
size_t ciphertext_len, uint8_t *plaintext,
15-
size_t plaintext_len, size_t *bytes_written);
14+
Result aes_gcm_encrypt(
15+
M_KeyID keyId,
16+
uint8_t* plaintext,
17+
size_t plaintext_len,
18+
uint8_t* ciphertext,
19+
size_t ciphertext_len,
20+
size_t* bytes_written);
21+
Result aes_gcm_decrypt(
22+
M_KeyID keyId,
23+
const uint8_t* ciphertext,
24+
size_t ciphertext_len,
25+
uint8_t* plaintext,
26+
size_t plaintext_len,
27+
size_t* bytes_written);

core/include/checks.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ int verify_conv_btc_to_satoshi(void);
4141
ERROR("got: %s", value); \
4242
return -1; \
4343
} \
44-
} while(0)
44+
} while (0)

core/include/config.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#pragma once
22

3+
// clang-format off
4+
// (to avoid conflicting with production patch files)
5+
36
// maximum size for xpub. TODO: we can make this 112 bytes, based on:
47
// https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#serialization-format
58
#define XPUB_SIZE 128
@@ -118,3 +121,5 @@
118121
#define MASTER_SEED_SIZE 64
119122

120123
#define COMPRESSED_PUBKEY_SIZE 33
124+
125+
// clang-format on

core/include/hash.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
#include <hasher.h>
44

5-
void hash_uint8(Hasher *hasher, uint8_t value);
6-
void hash_uint16(Hasher *hasher, uint16_t value);
7-
void hash_uint32(Hasher *hasher, uint32_t value);
8-
void hash_uint64(Hasher *hasher, uint64_t value);
5+
void hash_uint8(Hasher* hasher, uint8_t value);
6+
void hash_uint16(Hasher* hasher, uint16_t value);
7+
void hash_uint32(Hasher* hasher, uint32_t value);
8+
void hash_uint64(Hasher* hasher, uint64_t value);
99
// hashes are serialized in "normal" order
10-
void hash_bytes(Hasher *hasher, const uint8_t *data, size_t len);
10+
void hash_bytes(Hasher* hasher, const uint8_t* data, size_t len);
1111
// addresses are serialized in reverse order
12-
void hash_rev_bytes(Hasher *hasher, const uint8_t *data, size_t len);
12+
void hash_rev_bytes(Hasher* hasher, const uint8_t* data, size_t len);
1313
// scripts are serialized with a length prefix
14-
void hash_var_bytes(Hasher *hasher, const uint8_t *data, size_t len);
14+
void hash_var_bytes(Hasher* hasher, const uint8_t* data, size_t len);

core/include/init_wallet.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
#pragma once
22

3+
#include "config.h"
4+
35
#include <squareup/subzero/common.pb.h>
46
#include <squareup/subzero/internal.pb.h>
57
#include <stdint.h>
68

7-
#include "config.h"
8-
9-
Result mix_entropy(uint8_t wallet_entropy[static MASTER_SEED_SIZE],
10-
const InternalCommandRequest* const in);
9+
Result mix_entropy(uint8_t wallet_entropy[static MASTER_SEED_SIZE], const InternalCommandRequest* const in);

0 commit comments

Comments
 (0)