Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add clang-format configuration and format sources #420

Merged
merged 5 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
Language: Cpp
BasedOnStyle: Chromium
IndentWidth: 4
ColumnLimit: 100
UseTab: Never
IndentCaseLabels: true
# do not allow ifs or loops without braces
InsertBraces: true
PointerAlignment: Right

BreakBeforeBraces: Stroustrup
BreakBeforeBinaryOperators: true

BinPackArguments: false
BinPackParameters: false

AlignConsecutiveMacros:
Enabled: true
AcrossComments: true
AcrossEmptyLines: false

AlignConsecutiveDeclarations:
Enabled: true
AcrossComments: false
AcrossEmptyLines: false

AlignConsecutiveAssignments:
Enabled: true
AcrossComments: false
AcrossEmptyLines: false

AlignArrayOfStructures: Left
SortIncludes: Never
SpaceAfterCStyleCast: True
AllowShortEnumsOnASingleLine: false
...
5 changes: 5 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Run this command to always ignore formatting commits in `git blame`
# git config blame.ignoreRevsFile .git-blame-ignore-revs

# Formatting commit
985bb5283ffac5991a21911b9ea8bc31ecd758d0
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,9 @@ repos:
rev: v2.2.5
hooks:
- id: codespell

- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v16.0.6
hooks:
- id: clang-format
types_or: [c]
76 changes: 40 additions & 36 deletions include/appflags.h
Original file line number Diff line number Diff line change
@@ -1,75 +1,79 @@
#pragma once

/**
* Base flag added to loaded application, to allow them to call all syscalls by default (the one requiring no extra permission)
* Base flag added to loaded application, to allow them to call all syscalls by default (the one
* requiring no extra permission)
*/
#define APPLICATION_FLAG_MAIN 0x1
#define APPLICATION_FLAG_MAIN 0x1

/**
* Flag which combined with ::APPLICATION_FLAG_ISSUER.
* The application is given full nvram access after the global seed has been destroyed.
*/
#define APPLICATION_FLAG_BOLOS_UPGRADE 0x2
#define APPLICATION_FLAG_BOLOS_UPGRADE 0x2

// this flag is set when a valid signature of the loaded application is presented at the end of the bolos application load.
#define APPLICATION_FLAG_SIGNED 0x4
// this flag is set when a valid signature of the loaded application is presented at the end of the
// bolos application load.
#define APPLICATION_FLAG_SIGNED 0x4

// must be set on one application in the registry which is used
#define APPLICATION_FLAG_BOLOS_UX 0x8
#define APPLICATION_FLAG_BOLOS_UX 0x8

// application is allowed to use the raw master seed, if not set, at least a level of derivation is
// required.
#define APPLICATION_FLAG_DERIVE_MASTER 0x10

// application is allowed to use the raw master seed, if not set, at least a level of derivation is required.
#define APPLICATION_FLAG_DERIVE_MASTER 0x10
#define APPLICATION_FLAG_SHARED_NVRAM 0x20
#define APPLICATION_FLAG_GLOBAL_PIN 0x40

#define APPLICATION_FLAG_SHARED_NVRAM 0x20
#define APPLICATION_FLAG_GLOBAL_PIN 0x40

// This flag means the application is meant to be debugged and allows for dump or core ARM register in
// case of a fault detection
#define APPLICATION_FLAG_DEBUG 0x80
// This flag means the application is meant to be debugged and allows for dump or core ARM register
// in case of a fault detection
#define APPLICATION_FLAG_DEBUG 0x80

/**
* Mark this application as defaultly booting along with the bootloader (no application menu displayed)
* Only one application can have this at a time. It is managed by the bootloader interface.
* Mark this application as defaultly booting along with the bootloader (no application menu
* displayed) Only one application can have this at a time. It is managed by the bootloader
* interface.
*/
#define APPLICATION_FLAG_AUTOBOOT 0x100
#define APPLICATION_FLAG_AUTOBOOT 0x100

/**
* Application is allowed to change the settings
*/
#define APPLICATION_FLAG_BOLOS_SETTINGS 0x200
#define APPLICATION_FLAG_BOLOS_SETTINGS 0x200

#define APPLICATION_FLAG_CUSTOM_CA 0x400
#define APPLICATION_FLAG_CUSTOM_CA 0x400

/**
* The application main can be called in two ways:
* - with first arg (stored in r0) set to 0: The application is called from the dashboard
* - with first arg (stored in r0) set to != 0 (ram address likely): The application is used as a library from another app.
* - with first arg (stored in r0) set to != 0 (ram address likely): The application is used as a
* library from another app.
*/
#define APPLICATION_FLAG_LIBRARY 0x800
#define APPLICATION_FLAG_LIBRARY 0x800

/**
* The application won't be shown on the dashboard (somewhat reasonable for pure library)
*/
#define APPLICATION_FLAG_NO_RUN 0x1000
#define APPLICATION_FLAG_NO_RUN 0x1000

#if defined(HAVE_LANGUAGE_PACK)
/**
* This application is in fact a Language pack!
*/
#define APPLICATION_FLAG_LANGUAGE_PACK 0x2000
#endif //defined(HAVE_LANGUAGE_PACK)
#define APPLICATION_FLAG_LANGUAGE_PACK 0x2000
#endif // defined(HAVE_LANGUAGE_PACK)

/**
* Application has been loaded using a secure channel opened using the bootloader's issuer
* public key. This application is ledger legit.
*/
#define APPLICATION_FLAG_ISSUER 0x4000
#define APPLICATION_FLAG_ISSUER 0x4000

/**
* Application is enabled (when not being updated or removed)
*/
#define APPLICATION_FLAG_ENABLED 0x8000
#define APPLICATION_FLAG_ENABLED 0x8000

/**
* Application is actually a Stax background image
Expand All @@ -80,10 +84,10 @@
* Custom AEM flag to test AEM capabilities without standard UX permissions
*/
#if defined(BOLOS_DEBUG_UX_PERMISSION_FLAG)
#define APPLICATION_FLAG_AEM_PIN APPLICATION_FLAG_GLOBAL_PIN
#define APPLICATION_FLAG_AEM_PIN APPLICATION_FLAG_GLOBAL_PIN
#else
#define APPLICATION_FLAG_AEM_PIN APPLICATION_FLAG_BOLOS_UX
#endif // BOLOS_DEBUG_UX_PERMISSION_FLAG
#define APPLICATION_FLAG_AEM_PIN APPLICATION_FLAG_BOLOS_UX
#endif // BOLOS_DEBUG_UX_PERMISSION_FLAG

#ifdef HAVE_BACKGROUND_IMG
#define APPLICATION_FLAGS_MASK (0x00000000FFFFFFFFULL)
Expand All @@ -93,12 +97,12 @@
#define APPLICATION_FLAGS_MASK (0x0000FFFF)
#define APPLICATION_FLAG_NEG_MASK (0xFFFF0000)
#define APPLICATION_FLAGS_SHIFT (16)
#endif //HAVE_BACKGROUND_IMG
#endif // HAVE_BACKGROUND_IMG

#define GET_COMPLEMENTED_APPLICATION_FLAGS(flags) \
(((~((flags)&APPLICATION_FLAGS_MASK) << APPLICATION_FLAGS_SHIFT)) | \
((flags)&APPLICATION_FLAGS_MASK))
#define GET_COMPLEMENTED_APPLICATION_FLAGS(flags) \
(((~((flags) &APPLICATION_FLAGS_MASK) << APPLICATION_FLAGS_SHIFT)) \
| ((flags) &APPLICATION_FLAGS_MASK))

#define IS_APPLICATION_FLAGS_SECURE(complemented_flags) \
(((~(complemented_flags) << APPLICATION_FLAGS_SHIFT) & APPLICATION_FLAG_NEG_MASK) == \
((complemented_flags) & APPLICATION_FLAG_NEG_MASK))
#define IS_APPLICATION_FLAGS_SECURE(complemented_flags) \
(((~(complemented_flags) << APPLICATION_FLAGS_SHIFT) & APPLICATION_FLAG_NEG_MASK) \
== ((complemented_flags) &APPLICATION_FLAG_NEG_MASK))
14 changes: 7 additions & 7 deletions include/arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@
#include "os_hal.h"

#if defined(ST31)
#include <core_sc000.h>
#include <core_sc000.h>
#endif

#if defined(ST33J2M0)
#include <core_sc300.h>
#include <core_sc300.h>
#endif

#if defined(ST33K1M5)
#include <core_cm35p.h>
#include <core_cm35p.h>
#endif

#if defined(X86)
#define NATIVE_PRINT
#include <setjmp.h>
#include <stdio.h>
#define NATIVE_PRINT
#include <setjmp.h>
#include <stdio.h>
#endif

#endif // HAVE_BOLOS
#endif // HAVE_BOLOS

#define WIDE
38 changes: 19 additions & 19 deletions include/checks.h
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@

/*******************************************************************************
* Ledger Nano S - Secure firmware
* (c) 2022 Ledger
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
********************************************************************************/
* Ledger Nano S - Secure firmware
* (c) 2022 Ledger
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
********************************************************************************/

#if !defined(CHECKS_H)
#define CHECKS_H

#if !defined(HAVE_BOLOS) && defined(HAVE_PENDING_REVIEW_SCREEN)

#define CHECK_NOT_AUDITED_TLV_TAG 0x9F
#define CHECK_NOT_AUDITED_TLV_VAL 0x01
#define CHECK_NOT_AUDITED_MAX_LEN 0x40
#define CHECK_NOT_AUDITED_TLV_TAG 0x9F
#define CHECK_NOT_AUDITED_TLV_VAL 0x01
#define CHECK_NOT_AUDITED_MAX_LEN 0x40

void check_audited_app(void);
#endif // !defined(HAVE_BOLOS) && defined(HAVE_PENDING_REVIEW_SCREEN)
#endif // !defined(HAVE_BOLOS) && defined(HAVE_PENDING_REVIEW_SCREEN)

#endif
30 changes: 15 additions & 15 deletions include/cx.h
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@

/*******************************************************************************
* Ledger Nano S - Secure firmware
* (c) 2022 Ledger
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
********************************************************************************/
* Ledger Nano S - Secure firmware
* (c) 2022 Ledger
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
********************************************************************************/

#pragma once

Expand Down
Loading
Loading