Skip to content

Commit

Permalink
[core] clang-format almost all first-party code
Browse files Browse the repository at this point in the history
Added a .clang-format file and auto-formatted almost all first-party code
(all except `core/include/config.h` and the auto-generated file
`core/src/checks/wycheproof/ecdsa_secp256k1_sha256_bitcoin_test.h`).
  • Loading branch information
ivmaykov committed Aug 1, 2023
1 parent f4f4d86 commit d8d5591
Show file tree
Hide file tree
Showing 61 changed files with 881 additions and 653 deletions.
225 changes: 225 additions & 0 deletions core/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
# see https://clang.llvm.org/docs/ClangFormatStyleOptions.html
---
# BasedOnStyle: Mozilla

Language: Cpp
AccessModifierOffset: -2
AlignAfterOpenBracket: AlwaysBreak
AlignArrayOfStructures: None
AlignConsecutiveAssignments:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
PadOperators: true
AlignConsecutiveBitFields:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
PadOperators: false
AlignConsecutiveDeclarations:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
PadOperators: false
AlignConsecutiveMacros:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
PadOperators: false
AlignEscapedNewlines: Left
AlignOperands: Align
AlignTrailingComments:
Kind: Always
OverEmptyLines: 0
AllowAllArgumentsOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortEnumsOnASingleLine: true
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: Yes
AttributeMacros:
- __capability
BinPackArguments: false
BinPackParameters: false
BitFieldColonSpacing: Both
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: Never
AfterEnum: false
AfterExternBlock: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
BeforeCatch: false
BeforeElse: false
BeforeLambdaBody: false
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: false
SplitEmptyRecord: false
SplitEmptyNamespace: false
BreakAfterAttributes: Never
BreakAfterJavaFieldAnnotations: false
BreakArrays: false
BreakBeforeBinaryOperators: None
BreakBeforeConceptDeclarations: Always
BreakBeforeBraces: Custom
BreakBeforeInlineASMColon: OnlyMultiline
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: AfterColon
BreakInheritanceList: AfterColon
BreakStringLiterals: true
ColumnLimit: 120
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: false
DerivePointerAlignment: false
DisableFormat: false
EmptyLineAfterAccessModifier: Never
EmptyLineBeforeAccessModifier: LogicalBlock
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IfMacros:
- KJ_IF_MAYBE
IncludeBlocks: Regroup
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
SortPriority: 0
CaseSensitive: false
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
SortPriority: 0
CaseSensitive: false
- Regex: '.*'
Priority: 1
SortPriority: 0
CaseSensitive: false
IncludeIsMainRegex: '(Test)?$'
IncludeIsMainSourceRegex: ''
IndentAccessModifiers: false
IndentCaseBlocks: false
IndentCaseLabels: false
IndentExternBlock: AfterExternBlock
IndentGotoLabels: true
IndentPPDirectives: BeforeHash
IndentRequiresClause: true
IndentWidth: 2
IndentWrappedFunctionNames: false
InsertBraces: true
InsertNewlineAtEOF: true
InsertTrailingCommas: None
IntegerLiteralSeparator:
Binary: 0
BinaryMinDigits: 0
Decimal: 0
DecimalMinDigits: 0
Hex: 0
HexMinDigits: 0
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false
LambdaBodyIndentation: Signature
LineEnding: DeriveLF
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 2
ObjCBreakBeforeNestedBlockParam: true
ObjCSpaceAfterProperty: true
ObjCSpaceBeforeProtocolList: false
PackConstructorInitializers: CurrentLine
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakOpenParenthesis: 0
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyIndentedWhitespace: 0
PenaltyReturnTypeOnItsOwnLine: 200
PointerAlignment: Left
PPIndentWidth: -1
QualifierAlignment: Leave
ReferenceAlignment: Pointer
ReflowComments: true
RemoveBracesLLVM: false
RemoveSemicolon: true
RequiresClausePosition: OwnLine
RequiresExpressionIndentation: OuterScope
SeparateDefinitionBlocks: Always
ShortNamespaceLines: 1
SortIncludes: CaseSensitive
SortJavaStaticImport: Before
SortUsingDeclarations: LexicographicNumeric
SpaceAfterCStyleCast: true
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: false
SpaceAroundPointerQualifiers: Default
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: Custom
SpaceBeforeParensOptions:
AfterControlStatements: true
AfterForeachMacros: true
AfterFunctionDefinitionName: false
AfterFunctionDeclarationName: false
AfterIfMacros: true
AfterOverloadedOperator: false
AfterRequiresInClause: false
AfterRequiresInExpression: false
BeforeNonEmptyParentheses: false
SpaceBeforeRangeBasedForLoopColon: true
SpaceBeforeSquareBrackets: false
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: Never
SpacesInConditionalStatement: false
SpacesInContainerLiterals: false
SpacesInCStyleCastParentheses: false
SpacesInLineCommentPrefix:
Minimum: 1
Maximum: -1
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Latest
StatementAttributeLikeMacros:
- Q_EMIT
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 8
UseTab: Never
WhitespaceSensitiveMacros:
- BOOST_PP_STRINGIZE
- CF_SWIFT_NAME
- NS_SWIFT_NAME
- PP_STRINGIZE
- STRINGIZE
1 change: 1 addition & 0 deletions core/external-crypto/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DisableFormat: true
23 changes: 15 additions & 8 deletions core/include/aes_gcm_dev.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,24 @@
// reserved for an invalid key object in the nCipher target. We would like to
// simulate this behavior in the dev target, and therefore avoid value 0 for
// M_KeyID enum below.
typedef enum {master_seed_encryption_key = 1,
pub_key_encryption_key = 2} M_KeyID;
typedef enum { master_seed_encryption_key = 1, pub_key_encryption_key = 2 } M_KeyID;

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

Result aes_gcm_encrypt(M_KeyID keyId, uint8_t *plaintext, size_t plaintext_len,
uint8_t *ciphertext, size_t ciphertext_len,
size_t *bytes_written);
Result aes_gcm_decrypt(M_KeyID keyId, const uint8_t *ciphertext,
size_t ciphertext_len, uint8_t *plaintext,
size_t plaintext_len, size_t *bytes_written);
Result aes_gcm_encrypt(
M_KeyID keyId,
uint8_t* plaintext,
size_t plaintext_len,
uint8_t* ciphertext,
size_t ciphertext_len,
size_t* bytes_written);
Result aes_gcm_decrypt(
M_KeyID keyId,
const uint8_t* ciphertext,
size_t ciphertext_len,
uint8_t* plaintext,
size_t plaintext_len,
size_t* bytes_written);
20 changes: 14 additions & 6 deletions core/include/aes_gcm_ncipher.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,17 @@
// aes_gcm_ncipher:$(echo -n "aes_gcm_ncipher" | sha256sum | cut -c1-16)
#define MAGIC "aes_gcm_ncipher:ffb944993c73a1d3"

Result aes_gcm_encrypt(M_KeyID keyId, uint8_t *plaintext, size_t plaintext_len,
uint8_t *ciphertext, size_t ciphertext_len,
size_t *bytes_written);
Result aes_gcm_decrypt(M_KeyID keyId, const uint8_t *ciphertext,
size_t ciphertext_len, uint8_t *plaintext,
size_t plaintext_len, size_t *bytes_written);
Result aes_gcm_encrypt(
M_KeyID keyId,
uint8_t* plaintext,
size_t plaintext_len,
uint8_t* ciphertext,
size_t ciphertext_len,
size_t* bytes_written);
Result aes_gcm_decrypt(
M_KeyID keyId,
const uint8_t* ciphertext,
size_t ciphertext_len,
uint8_t* plaintext,
size_t plaintext_len,
size_t* bytes_written);
2 changes: 1 addition & 1 deletion core/include/checks.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ int verify_rpc_oversized_message_rejected(void);
ERROR("got: %s", value); \
return -1; \
} \
} while(0)
} while (0)
5 changes: 5 additions & 0 deletions core/include/config.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// clang-format off
// (to avoid conflicting with production patch files)

#pragma once

// maximum size for xpub. TODO: we can make this 112 bytes, based on:
Expand Down Expand Up @@ -119,3 +122,5 @@
#define MASTER_SEED_SIZE 64

#define COMPRESSED_PUBKEY_SIZE 33

// clang-format on
14 changes: 7 additions & 7 deletions core/include/hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
#include <stddef.h>
#include <stdint.h>

void hash_uint8(Hasher *hasher, uint8_t value);
void hash_uint16(Hasher *hasher, uint16_t value);
void hash_uint32(Hasher *hasher, uint32_t value);
void hash_uint64(Hasher *hasher, uint64_t value);
void hash_uint8(Hasher* hasher, uint8_t value);
void hash_uint16(Hasher* hasher, uint16_t value);
void hash_uint32(Hasher* hasher, uint32_t value);
void hash_uint64(Hasher* hasher, uint64_t value);
// hashes are serialized in "normal" order
void hash_bytes(Hasher *hasher, const uint8_t *data, size_t len);
void hash_bytes(Hasher* hasher, const uint8_t* data, size_t len);
// addresses are serialized in reverse order
void hash_rev_bytes(Hasher *hasher, const uint8_t *data, size_t len);
void hash_rev_bytes(Hasher* hasher, const uint8_t* data, size_t len);
// scripts are serialized with a length prefix
void hash_var_bytes(Hasher *hasher, const uint8_t *data, size_t len);
void hash_var_bytes(Hasher* hasher, const uint8_t* data, size_t len);
3 changes: 1 addition & 2 deletions core/include/init_wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@

#include <stdint.h>

Result mix_entropy(uint8_t wallet_entropy[static MASTER_SEED_SIZE],
const InternalCommandRequest* const in);
Result mix_entropy(uint8_t wallet_entropy[static MASTER_SEED_SIZE], const InternalCommandRequest* const in);
Loading

0 comments on commit d8d5591

Please sign in to comment.