Skip to content

Commit

Permalink
Formatting: Format sources
Browse files Browse the repository at this point in the history
  • Loading branch information
abonnaudet-ledger committed Sep 13, 2023
1 parent ee20265 commit 985bb52
Show file tree
Hide file tree
Showing 273 changed files with 38,838 additions and 35,046 deletions.
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
60 changes: 31 additions & 29 deletions include/cx_errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,93 +11,95 @@
* Checks the error code of a function.
* @hideinitializer
*/
#define CX_CHECK(call) do { \
error = call; \
if (error) { \
goto end; \
} \
} while (0)
#define CX_CHECK(call) \
do { \
error = call; \
if (error) { \
goto end; \
} \
} while (0)

/**
* Checks the error code of a function and ignore
* it if CX_CARRY.
* @hideinitializer
*/
#define CX_CHECK_IGNORE_CARRY(call) do { \
error = call; \
if (error && error != CX_CARRY) { \
goto end; \
} \
} while (0)
#define CX_CHECK_IGNORE_CARRY(call) \
do { \
error = call; \
if (error && error != CX_CARRY) { \
goto end; \
} \
} while (0)

/** Success. */
#define CX_OK 0x00000000
#define CX_OK 0x00000000

/** There exists a carry at the end of the operation. */
#define CX_CARRY 0xFFFFFF21
#define CX_CARRY 0xFFFFFF21

/**
* Multi Precision Integer processor is locked:
* operations can be done.
*/
#define CX_LOCKED 0xFFFFFF81
#define CX_LOCKED 0xFFFFFF81

/**
* Multi Precision Integer processor is unlocked:
* operations can't be done.
*/
#define CX_UNLOCKED 0xFFFFFF82
#define CX_UNLOCKED 0xFFFFFF82

/**
* Multi Precision Integer processor is not locked:
* it cannot be unlocked.
*/
#define CX_NOT_LOCKED 0xFFFFFF83
#define CX_NOT_LOCKED 0xFFFFFF83

/**
* Multi Precision Integer processor is already locked:
* it cannot be locked.
*/
#define CX_NOT_UNLOCKED 0xFFFFFF84
#define CX_NOT_UNLOCKED 0xFFFFFF84

/** Internal error */
#define CX_INTERNAL_ERROR 0xFFFFFF85
#define CX_INTERNAL_ERROR 0xFFFFFF85

/**
* A parameter has an invalid size.
*/
#define CX_INVALID_PARAMETER_SIZE 0xFFFFFF86
#define CX_INVALID_PARAMETER_SIZE 0xFFFFFF86

/**
* A parameter has an invalid value.
*/
#define CX_INVALID_PARAMETER_VALUE 0xFFFFFF87
#define CX_INVALID_PARAMETER_VALUE 0xFFFFFF87

/** A parameter is invalid. */
#define CX_INVALID_PARAMETER 0xFFFFFF88
#define CX_INVALID_PARAMETER 0xFFFFFF88

/**
* A value is not invertible.
*/
#define CX_NOT_INVERTIBLE 0xFFFFFF89
#define CX_NOT_INVERTIBLE 0xFFFFFF89

/** A value overflow occurred. */
#define CX_OVERFLOW 0xFFFFFF8A
#define CX_OVERFLOW 0xFFFFFF8A

/** Memory is full: allocation is not possible anymore. */
#define CX_MEMORY_FULL 0xFFFFFF8B
#define CX_MEMORY_FULL 0xFFFFFF8B

/** A quadratic residue cannot be computed. */
#define CX_NO_RESIDUE 0xFFFFFF8C
#define CX_NO_RESIDUE 0xFFFFFF8C

/** Point at infinity is hit. */
#define CX_EC_INFINITE_POINT 0xFFFFFF41
#define CX_EC_INFINITE_POINT 0xFFFFFF41

/** Point is invalid: it does not belong to the curve. */
#define CX_EC_INVALID_POINT 0xFFFFFFA2
#define CX_EC_INVALID_POINT 0xFFFFFFA2

/** Curve is invalid. */
#define CX_EC_INVALID_CURVE 0xFFFFFFA3
#define CX_EC_INVALID_CURVE 0xFFFFFFA3

/** Type of error code */
typedef uint32_t cx_err_t;
Loading

0 comments on commit 985bb52

Please sign in to comment.