From fec613384cbb4dbf03a0fef8959af403f6d21529 Mon Sep 17 00:00:00 2001 From: Igor Khanin Date: Wed, 20 Dec 2023 17:40:50 +0200 Subject: [PATCH 1/4] Use portable byteswap functions --- .../crypto/GFp_curve_algebra/GFp_curve_algebra.c | 4 ++-- src/common/crypto/ed25519_algebra/ed25519_algebra.c | 12 ++++++------ .../crypto/zero_knowledge_proof/diffie_hellman_log.c | 4 ++-- test/crypto/ed25519_algebra/main.cpp | 6 ++++-- test/crypto/secp256k1_algebra/main.cpp | 6 ++++-- 5 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/common/crypto/GFp_curve_algebra/GFp_curve_algebra.c b/src/common/crypto/GFp_curve_algebra/GFp_curve_algebra.c index e4a0f36..7c77a83 100644 --- a/src/common/crypto/GFp_curve_algebra/GFp_curve_algebra.c +++ b/src/common/crypto/GFp_curve_algebra/GFp_curve_algebra.c @@ -1019,8 +1019,8 @@ static uint8_t in_field(const elliptic_curve256_scalar_t val, const uint8_t *fie const uint32_t *ptr2 = (const uint32_t*)field; for (size_t i = sizeof(elliptic_curve256_scalar_t) / sizeof(uint32_t); i > 0; i --) { - uint64_t v1 = __bswap_32(ptr1[i - 1]); - uint64_t v2 = __bswap_32(ptr2[i - 1]); + uint64_t v1 = bswap_32(ptr1[i - 1]); + uint64_t v2 = bswap_32(ptr2[i - 1]); cc = ((v1 - v2 - cc) >> 32) & 1; } return cc; diff --git a/src/common/crypto/ed25519_algebra/ed25519_algebra.c b/src/common/crypto/ed25519_algebra/ed25519_algebra.c index 1dbe233..cb9b115 100644 --- a/src/common/crypto/ed25519_algebra/ed25519_algebra.c +++ b/src/common/crypto/ed25519_algebra/ed25519_algebra.c @@ -51,10 +51,10 @@ static inline void bswap_256(const ed25519_scalar_t in, ed25519_scalar_t out) { uint64_t *inptr = (uint64_t*)in; uint64_t *outptr = (uint64_t*)out; - outptr[0] = __bswap_64(inptr[3]); - outptr[1] = __bswap_64(inptr[2]); - outptr[2] = __bswap_64(inptr[1]); - outptr[3] = __bswap_64(inptr[0]); + outptr[0] = bswap_64(inptr[3]); + outptr[1] = bswap_64(inptr[2]); + outptr[2] = bswap_64(inptr[1]); + outptr[3] = bswap_64(inptr[0]); } static inline int ed25519_to_scalar(const ed25519_scalar_t in, ed25519_scalar_t out) @@ -852,8 +852,8 @@ static uint8_t in_field(const elliptic_curve256_scalar_t val) const uint32_t *ptr2 = (const uint32_t*)ED25519_FIELD; for (size_t i = sizeof(elliptic_curve256_scalar_t) / sizeof(uint32_t); i > 0; i --) { - uint64_t v1 = __bswap_32(ptr1[i - 1]); - uint64_t v2 = __bswap_32(ptr2[i - 1]); + uint64_t v1 = bswap_32(ptr1[i - 1]); + uint64_t v2 = bswap_32(ptr2[i - 1]); cc = ((v1 - v2 - cc) >> 32) & 1; } return cc; diff --git a/src/common/crypto/zero_knowledge_proof/diffie_hellman_log.c b/src/common/crypto/zero_knowledge_proof/diffie_hellman_log.c index 699d5cb..8eefd5d 100644 --- a/src/common/crypto/zero_knowledge_proof/diffie_hellman_log.c +++ b/src/common/crypto/zero_knowledge_proof/diffie_hellman_log.c @@ -13,8 +13,8 @@ static inline int cmp_uint256(const uint8_t *a, const uint8_t *b) for (size_t i = 0; i < sizeof(elliptic_curve256_scalar_t) / sizeof(uint64_t); i++) { - uint64_t n1 = __bswap_64(*aptr); // elliptic_curve256_scalar_t is represented as big endian number - uint64_t n2 = __bswap_64(*bptr); + uint64_t n1 = bswap_64(*aptr); // elliptic_curve256_scalar_t is represented as big endian number + uint64_t n2 = bswap_64(*bptr); if (n1 > n2) return 1; else if (n1 < n2) diff --git a/test/crypto/ed25519_algebra/main.cpp b/test/crypto/ed25519_algebra/main.cpp index 293b2f3..f988734 100644 --- a/test/crypto/ed25519_algebra/main.cpp +++ b/test/crypto/ed25519_algebra/main.cpp @@ -4,6 +4,8 @@ #include #include +#include + #define CATCH_CONFIG_MAIN #include @@ -264,7 +266,7 @@ TEST_CASE( "ed25519_algebra_add_points", "zkp") { status = ed25519_algebra_add_points(ctx, &res, &pa, &pb); REQUIRE(status == ELLIPTIC_CURVE_ALGEBRA_SUCCESS); - uint32_t val = __bswap_32(__bswap_32(a)+__bswap_32(b)); // sum in big endian + uint32_t val = bswap_32(bswap_32(a)+bswap_32(b)); // sum in big endian status = ed25519_algebra_generator_mul_data(ctx, (uint8_t*)&val, sizeof(val), &sum); REQUIRE(status == ELLIPTIC_CURVE_ALGEBRA_SUCCESS); @@ -284,7 +286,7 @@ TEST_CASE( "ed25519_algebra_add_points", "zkp") { REQUIRE(status == ELLIPTIC_CURVE_ALGEBRA_SUCCESS); REQUIRE(memcmp(pa, res, sizeof(ed25519_point_t)) == 0); - uint32_t val = __bswap_32(__bswap_32(a)+__bswap_32(b)); // sum in big endian + uint32_t val = bswap_32(bswap_32(a)+bswap_32(b)); // sum in big endian status = ed25519_algebra_generator_mul_data(ctx, (uint8_t*)&val, sizeof(val), &sum); REQUIRE(status == ELLIPTIC_CURVE_ALGEBRA_SUCCESS); diff --git a/test/crypto/secp256k1_algebra/main.cpp b/test/crypto/secp256k1_algebra/main.cpp index cfd166c..447b2ae 100644 --- a/test/crypto/secp256k1_algebra/main.cpp +++ b/test/crypto/secp256k1_algebra/main.cpp @@ -5,6 +5,8 @@ #include #include +#include + #define CATCH_CONFIG_MAIN #include @@ -358,7 +360,7 @@ TEST_CASE( "secp256k1_algebra_add_points", "zkp") { status = GFp_curve_algebra_add_points(ctx, &res, &pa, &pb); REQUIRE(status == ELLIPTIC_CURVE_ALGEBRA_SUCCESS); - uint32_t val = __bswap_32(__bswap_32(a)+__bswap_32(b)); // sum in big endian + uint32_t val = bswap_32(bswap_32(a)+bswap_32(b)); // sum in big endian status = GFp_curve_algebra_generator_mul_data(ctx, (uint8_t*)&val, sizeof(val), &sum); REQUIRE(status == ELLIPTIC_CURVE_ALGEBRA_SUCCESS); @@ -378,7 +380,7 @@ TEST_CASE( "secp256k1_algebra_add_points", "zkp") { REQUIRE(status == ELLIPTIC_CURVE_ALGEBRA_SUCCESS); REQUIRE(memcmp(pa, res, sizeof(elliptic_curve256_point_t)) == 0); - uint32_t val = __bswap_32(__bswap_32(a)+__bswap_32(b)); // sum in big endian + uint32_t val = bswap_32(bswap_32(a)+bswap_32(b)); // sum in big endian status = GFp_curve_algebra_generator_mul_data(ctx, (uint8_t*)&val, sizeof(val), &sum); REQUIRE(status == ELLIPTIC_CURVE_ALGEBRA_SUCCESS); From 0c5d6ea9cbde99f3e7eef9ba66c1aa18e7c56f59 Mon Sep 17 00:00:00 2001 From: Igor Khanin Date: Wed, 20 Dec 2023 17:30:23 +0200 Subject: [PATCH 2/4] Support runtime pluggable logging callback Allow setting up a callback function that receives logging messages, with the current behavior of printing to stdout and stderr as a default. --- include/logging/logging.h | 33 +++++++++++++ include/logging/logging_t.h | 16 ------- src/common/Makefile | 6 +-- .../cosigner/asymmetric_eddsa_cosigner.cpp | 2 +- .../asymmetric_eddsa_cosigner_client.cpp | 2 +- .../asymmetric_eddsa_cosigner_server.cpp | 2 +- .../cmp_ecdsa_offline_signing_service.cpp | 2 +- .../cmp_ecdsa_online_signing_service.cpp | 2 +- .../cosigner/cmp_ecdsa_signing_service.cpp | 2 +- .../cosigner/cmp_offline_refresh_service.cpp | 2 +- src/common/cosigner/cmp_setup_service.cpp | 2 +- src/common/cosigner/cosigner_exception.cpp | 2 +- .../cosigner/eddsa_online_signing_service.cpp | 2 +- src/common/cosigner/mta.cpp | 2 +- src/common/cosigner/utils.cpp | 2 +- src/common/lib.lds | 1 + src/common/logging/logging.c | 46 +++++++++++++++++++ 17 files changed, 95 insertions(+), 31 deletions(-) create mode 100644 include/logging/logging.h delete mode 100644 include/logging/logging_t.h create mode 100644 src/common/logging/logging.c diff --git a/include/logging/logging.h b/include/logging/logging.h new file mode 100644 index 0000000..939ae67 --- /dev/null +++ b/include/logging/logging.h @@ -0,0 +1,33 @@ +#pragma once + +typedef enum { + COSIGNER_LOG_LEVEL_FATAL = 50000, + COSIGNER_LOG_LEVEL_ERROR = 40000, + COSIGNER_LOG_LEVEL_WARN = 30000, + COSIGNER_LOG_LEVEL_INFO = 20000, + COSIGNER_LOG_LEVEL_DEBUG = 10000, + COSIGNER_LOG_LEVEL_TRACE = 5000, +} COSIGNER_LOG_LEVEL; + +typedef void (*cosigner_log_callback)(int level, const char* file, int line, const char* func, const char* message, void* userp); + +#ifdef __cplusplus +extern "C" { +#endif //__cplusplus + +void cosigner_log_init(cosigner_log_callback cb, void* userp); + +void cosigner_log_msg(int level, const char* file, int line, const char* func, const char* message, ...) + __attribute__ ((format (printf, 5, 6))); + +#ifdef __cplusplus +} +#endif //__cplusplus + +#define LOG(level, message, ...) cosigner_log_msg((level), __FILE__, __LINE__, __func__, (message), ##__VA_ARGS__) +#define LOG_TRACE(message, ...) LOG(COSIGNER_LOG_LEVEL_TRACE, message, ##__VA_ARGS__) +#define LOG_DEBUG(message, ...) LOG(COSIGNER_LOG_LEVEL_DEBUG, message, ##__VA_ARGS__) +#define LOG_INFO(message, ...) LOG(COSIGNER_LOG_LEVEL_INFO, message, ##__VA_ARGS__) +#define LOG_WARN(message, ...) LOG(COSIGNER_LOG_LEVEL_WARN, message, ##__VA_ARGS__) +#define LOG_ERROR(message, ...) LOG(COSIGNER_LOG_LEVEL_ERROR, message, ##__VA_ARGS__) +#define LOG_FATAL(message, ...) LOG(COSIGNER_LOG_LEVEL_FATAL, message, ##__VA_ARGS__) diff --git a/include/logging/logging_t.h b/include/logging/logging_t.h deleted file mode 100644 index 8c8c5de..0000000 --- a/include/logging/logging_t.h +++ /dev/null @@ -1,16 +0,0 @@ -// This file can be replaced with other logging system integration - -#ifndef LOGGING_T_H_ -#define LOGGING_T_H_ - -#include - -#define LOG(level, message, ...) do {printf((message), ##__VA_ARGS__);putchar('\n');} while(0) -#define LOG_DEBUG(message, ...) do {printf((message), ##__VA_ARGS__);putchar('\n');} while(0) -#define LOG_TRACE(message, ...) do {printf((message), ##__VA_ARGS__);putchar('\n');} while(0) -#define LOG_INFO(message, ...) do {printf((message), ##__VA_ARGS__);putchar('\n');} while(0) -#define LOG_WARN(message, ...) do {printf((message), ##__VA_ARGS__);putchar('\n');} while(0) -#define LOG_ERROR(message, ...) do {fprintf(stderr, (message), ##__VA_ARGS__);putchar('\n');} while(0) -#define LOG_FATAL(message, ...) do {fprintf(stderr, (message), ##__VA_ARGS__);putchar('\n');} while(0) - -#endif diff --git a/src/common/Makefile b/src/common/Makefile index cd68bb6..fddb99a 100644 --- a/src/common/Makefile +++ b/src/common/Makefile @@ -11,9 +11,9 @@ endif COMMON_CFLAGS := $(COMMON_CFLAGS) C_Files := crypto/shamir_secret_sharing/verifiable_secret_sharing.c crypto/paillier/paillier.c crypto/paillier/paillier_zkp.c crypto/GFp_curve_algebra/GFp_curve_algebra.c \ - crypto/commitments/commitments.c crypto/zero_knowledge_proof/schnorr.c crypto/zero_knowledge_proof/range_proofs.c crypto/zero_knowledge_proof/diffie_hellman_log.c \ - crypto/commitments/ring_pedersen.c crypto/ed25519_algebra/ed25519_algebra.c crypto/drng/drng.c crypto/keccak1600/keccak1600.c - + crypto/commitments/commitments.c crypto/zero_knowledge_proof/schnorr.c crypto/zero_knowledge_proof/range_proofs.c crypto/zero_knowledge_proof/diffie_hellman_log.c \ + crypto/commitments/ring_pedersen.c crypto/ed25519_algebra/ed25519_algebra.c crypto/drng/drng.c crypto/keccak1600/keccak1600.c logging/logging.c + C_Objects := $(C_Files:.c=.o) Cpp_Files := cosigner/cosigner_exception.cpp cosigner/cmp_setup_service.cpp cosigner/cmp_offline_refresh_service.cpp cosigner/utils.cpp \ diff --git a/src/common/cosigner/asymmetric_eddsa_cosigner.cpp b/src/common/cosigner/asymmetric_eddsa_cosigner.cpp index 1a72722..09f6203 100644 --- a/src/common/cosigner/asymmetric_eddsa_cosigner.cpp +++ b/src/common/cosigner/asymmetric_eddsa_cosigner.cpp @@ -2,7 +2,7 @@ #include "cosigner/cmp_key_persistency.h" #include "cosigner/cosigner_exception.h" #include "cosigner/platform_service.h" -#include "logging/logging_t.h" +#include "logging/logging.h" #include diff --git a/src/common/cosigner/asymmetric_eddsa_cosigner_client.cpp b/src/common/cosigner/asymmetric_eddsa_cosigner_client.cpp index ea01267..d824ad4 100644 --- a/src/common/cosigner/asymmetric_eddsa_cosigner_client.cpp +++ b/src/common/cosigner/asymmetric_eddsa_cosigner_client.cpp @@ -3,7 +3,7 @@ #include "cosigner/cosigner_exception.h" #include "cosigner/platform_service.h" #include "cosigner/mpc_globals.h" -#include "logging/logging_t.h" +#include "logging/logging.h" #include "utils.h" #include diff --git a/src/common/cosigner/asymmetric_eddsa_cosigner_server.cpp b/src/common/cosigner/asymmetric_eddsa_cosigner_server.cpp index 362cad9..dc30d6e 100644 --- a/src/common/cosigner/asymmetric_eddsa_cosigner_server.cpp +++ b/src/common/cosigner/asymmetric_eddsa_cosigner_server.cpp @@ -4,7 +4,7 @@ #include "cosigner/platform_service.h" #include "cosigner/mpc_globals.h" #include "utils.h" -#include "logging/logging_t.h" +#include "logging/logging.h" #include diff --git a/src/common/cosigner/cmp_ecdsa_offline_signing_service.cpp b/src/common/cosigner/cmp_ecdsa_offline_signing_service.cpp index 0109a86..0bedf6e 100644 --- a/src/common/cosigner/cmp_ecdsa_offline_signing_service.cpp +++ b/src/common/cosigner/cmp_ecdsa_offline_signing_service.cpp @@ -6,7 +6,7 @@ #include "utils.h" #include "crypto/GFp_curve_algebra/GFp_curve_algebra.h" #include "crypto/zero_knowledge_proof/range_proofs.h" -#include "logging/logging_t.h" +#include "logging/logging.h" namespace fireblocks { diff --git a/src/common/cosigner/cmp_ecdsa_online_signing_service.cpp b/src/common/cosigner/cmp_ecdsa_online_signing_service.cpp index 21bb43a..899ab52 100644 --- a/src/common/cosigner/cmp_ecdsa_online_signing_service.cpp +++ b/src/common/cosigner/cmp_ecdsa_online_signing_service.cpp @@ -6,7 +6,7 @@ #include "crypto/GFp_curve_algebra/GFp_curve_algebra.h" #include "crypto/zero_knowledge_proof/range_proofs.h" #include "utils.h" -#include "logging/logging_t.h" +#include "logging/logging.h" namespace fireblocks { diff --git a/src/common/cosigner/cmp_ecdsa_signing_service.cpp b/src/common/cosigner/cmp_ecdsa_signing_service.cpp index 7278a82..1a9d158 100644 --- a/src/common/cosigner/cmp_ecdsa_signing_service.cpp +++ b/src/common/cosigner/cmp_ecdsa_signing_service.cpp @@ -4,7 +4,7 @@ #include "crypto/GFp_curve_algebra/GFp_curve_algebra.h" #include "crypto/zero_knowledge_proof/diffie_hellman_log.h" #include "crypto/zero_knowledge_proof/range_proofs.h" -#include "logging/logging_t.h" +#include "logging/logging.h" #include diff --git a/src/common/cosigner/cmp_offline_refresh_service.cpp b/src/common/cosigner/cmp_offline_refresh_service.cpp index 7e5c5b9..b752e67 100644 --- a/src/common/cosigner/cmp_offline_refresh_service.cpp +++ b/src/common/cosigner/cmp_offline_refresh_service.cpp @@ -6,7 +6,7 @@ #include "cosigner/platform_service.h" #include "cosigner/prf.h" #include "crypto/elliptic_curve_algebra/elliptic_curve256_algebra.h" -#include "logging/logging_t.h" +#include "logging/logging.h" namespace fireblocks { diff --git a/src/common/cosigner/cmp_setup_service.cpp b/src/common/cosigner/cmp_setup_service.cpp index 8bf373d..0594b17 100644 --- a/src/common/cosigner/cmp_setup_service.cpp +++ b/src/common/cosigner/cmp_setup_service.cpp @@ -2,7 +2,7 @@ #include "cosigner/cosigner_exception.h" #include "utils.h" #include "crypto/zero_knowledge_proof/schnorr.h" -#include "logging/logging_t.h" +#include "logging/logging.h" #include diff --git a/src/common/cosigner/cosigner_exception.cpp b/src/common/cosigner/cosigner_exception.cpp index 32b9f15..6fc99f2 100644 --- a/src/common/cosigner/cosigner_exception.cpp +++ b/src/common/cosigner/cosigner_exception.cpp @@ -1,6 +1,6 @@ #include "cosigner/cosigner_exception.h" #include "crypto/paillier/paillier.h" -#include "logging/logging_t.h" +#include "logging/logging.h" namespace fireblocks { diff --git a/src/common/cosigner/eddsa_online_signing_service.cpp b/src/common/cosigner/eddsa_online_signing_service.cpp index 8bb4f91..4aaa8aa 100644 --- a/src/common/cosigner/eddsa_online_signing_service.cpp +++ b/src/common/cosigner/eddsa_online_signing_service.cpp @@ -4,7 +4,7 @@ #include "cosigner/mpc_globals.h" #include "cosigner/platform_service.h" #include "utils.h" -#include "logging/logging_t.h" +#include "logging/logging.h" extern "C" int gettimeofday(struct timeval *tv, struct timezone *tz); diff --git a/src/common/cosigner/mta.cpp b/src/common/cosigner/mta.cpp index 3d3a088..0b078c0 100644 --- a/src/common/cosigner/mta.cpp +++ b/src/common/cosigner/mta.cpp @@ -6,7 +6,7 @@ #include "../crypto/paillier/paillier_internal.h" #ifndef TEST_ONLY -#include "logging/logging_t.h" +#include "logging/logging.h" #else #define LOG_ERROR(message, ...) printf((message), ##__VA_ARGS__);putchar('\n') #endif diff --git a/src/common/cosigner/utils.cpp b/src/common/cosigner/utils.cpp index e9b220b..50d735b 100644 --- a/src/common/cosigner/utils.cpp +++ b/src/common/cosigner/utils.cpp @@ -2,7 +2,7 @@ #include "cosigner/cmp_key_persistency.h" #include "cosigner/cosigner_exception.h" #include "cosigner/platform_service.h" -#include "logging/logging_t.h" +#include "logging/logging.h" namespace fireblocks { diff --git a/src/common/lib.lds b/src/common/lib.lds index b4d420f..d52fbff 100644 --- a/src/common/lib.lds +++ b/src/common/lib.lds @@ -14,6 +14,7 @@ libcosigner.so range_proof_*; schnorr_zkp_*; derive_*; + cosigner_log_*; _ZN10fireblocks6common8cosigner17*; _ZN10fireblocks6common8cosigner2*; _ZN10fireblocks6common8cosigner32*; diff --git a/src/common/logging/logging.c b/src/common/logging/logging.c new file mode 100644 index 0000000..0c08ca0 --- /dev/null +++ b/src/common/logging/logging.c @@ -0,0 +1,46 @@ +#include "logging/logging.h" + +#include +#include + +#define MAX_LOG_SIZE 4096 + +static void default_log_callback(int level, const char* file, int line, const char* func, const char* message, void* userp) +{ + (void)file; + (void)line; + (void)func; + (void)userp; + + if (level >= COSIGNER_LOG_LEVEL_ERROR) + fprintf(stderr, "%s\n", message); + else + printf("%s\n", message); +} + +static cosigner_log_callback log_callback = default_log_callback; +static void* log_callback_user_data_pointer = NULL; + +void cosigner_log_init(cosigner_log_callback cb, void* userp) +{ + log_callback = cb; + log_callback_user_data_pointer = userp; +} + +void cosigner_log_msg(int level, const char* file, int line, const char* func, const char* message, ...) +{ + va_list args; + char buffer[MAX_LOG_SIZE] = { '\0' }; + + if (log_callback == NULL) + return; + + if (message != NULL) + { + va_start(args, message); + vsnprintf(buffer, MAX_LOG_SIZE, message, args); + va_end(args); + } + + log_callback(level, file, line, func, buffer, log_callback_user_data_pointer); +} From c96f6aaf1779619b6c767a7e15a15948f6b84e97 Mon Sep 17 00:00:00 2001 From: Igor Khanin Date: Wed, 20 Dec 2023 17:58:49 +0200 Subject: [PATCH 3/4] Build BIP-44 path in caller allocated array --- include/blockchain/mpc/hd_derive.h | 6 ++++-- src/common/blockchain/mpc/hd_derive.cpp | 23 ++++++++--------------- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/include/blockchain/mpc/hd_derive.h b/include/blockchain/mpc/hd_derive.h index 1add6ac..778aec8 100644 --- a/include/blockchain/mpc/hd_derive.h +++ b/include/blockchain/mpc/hd_derive.h @@ -16,9 +16,11 @@ const unsigned int EDDSA_PUBLIC_KEY_SIZE = 32; const unsigned int PRIVATE_KEY_SIZE = 32; const unsigned int CHAIN_CODE_SIZE_BYTES = 32; const unsigned int BIP44_PATH_LENGTH = 5; + typedef unsigned char HDChaincode[CHAIN_CODE_SIZE_BYTES]; typedef unsigned char PubKey[COMPRESSED_PUBLIC_KEY_SIZE]; typedef unsigned char PrivKey[PRIVATE_KEY_SIZE]; +typedef uint32_t Bip44Path[BIP44_PATH_LENGTH]; typedef enum { @@ -41,12 +43,12 @@ inline uint32_t bip32_hardened_index(uint32_t idx) return (1U<<31) + idx; } -// TODO: Refactor receive allocated int[BIP44_PATH_LENGTH] path -hd_derive_status build_bip44_path(uint32_t** path, uint32_t* path_len, uint32_t asset_num, uint32_t account, uint32_t change = 0, uint32_t addr_index = 0); hd_derive_status derive_public_key_generic(const elliptic_curve256_algebra_ctx_t *ctx, PubKey derived_key, const PubKey pubkey, const HDChaincode chaincode, const uint32_t* path, const uint32_t path_len); hd_derive_status derive_private_key_generic(const elliptic_curve256_algebra_ctx_t *ctx, PrivKey derived_privkey, const PubKey pubkey, const PrivKey privkey, const HDChaincode chaincode, const uint32_t* path, const uint32_t path_len); hd_derive_status derive_private_and_public_keys(const elliptic_curve256_algebra_ctx_t *ctx, PrivKey derived_privkey, PubKey derived_pubkey, const PubKey pubkey, const PrivKey privkey, const HDChaincode chaincode, const uint32_t* path, const uint32_t path_len); +hd_derive_status build_bip44_path(Bip44Path path, uint32_t asset_num, uint32_t account, uint32_t change = 0, uint32_t addr_index = 0); + #ifdef __cplusplus } #endif //__cplusplus diff --git a/src/common/blockchain/mpc/hd_derive.cpp b/src/common/blockchain/mpc/hd_derive.cpp index e8b3365..1430396 100644 --- a/src/common/blockchain/mpc/hd_derive.cpp +++ b/src/common/blockchain/mpc/hd_derive.cpp @@ -51,7 +51,7 @@ static hd_derive_status BIP32Hash(hmac_sha_result output, const HDChaincode chai if (1 != HMAC_Update(ctx, num, 4)) { goto end_bip32_hash; } - + if (1 != HMAC_Final(ctx, output, &output_len)) { goto end_bip32_hash; } @@ -142,7 +142,7 @@ hd_derive_status derive_private_key_generic(const elliptic_curve256_algebra_ctx_ hd_derive_status derive_private_and_public_keys(const elliptic_curve256_algebra_ctx_t *ctx, PrivKey derived_privkey, PubKey derived_pubkey, const PubKey pubkey, const PrivKey privkey, const HDChaincode chaincode, const uint32_t* path, const uint32_t path_len) { PubKey temp_pubkey; - + if (!path || !path_len) { memcpy(derived_privkey, privkey, PRIVATE_KEY_SIZE); @@ -170,18 +170,11 @@ hd_derive_status derive_private_and_public_keys(const elliptic_curve256_algebra_ return HD_DERIVE_SUCCESS; } -hd_derive_status build_bip44_path(uint32_t** path, uint32_t* path_len, uint32_t asset_num, uint32_t account, uint32_t change, uint32_t addr_index) { - *path_len = 5; - *path = (uint32_t*)malloc(BIP44_PATH_LENGTH * sizeof(uint32_t)); - if (NULL == *path){ - return HD_DERIVE_ERROR_OUT_OF_MEMORY; - } - - (*path)[0] = BIP44; //purpose - (*path)[1] = asset_num; - (*path)[2] = account; - (*path)[3] = change; - (*path)[4] = addr_index; - +hd_derive_status build_bip44_path(Bip44Path path, uint32_t asset_num, uint32_t account, uint32_t change, uint32_t addr_index) { + path[0] = BIP44; //purpose + path[1] = asset_num; + path[2] = account; + path[3] = change; + path[4] = addr_index; return HD_DERIVE_SUCCESS; } From 1dd05ccfe4bdea65ff845256ea192a738262f1cf Mon Sep 17 00:00:00 2001 From: Igor Khanin Date: Thu, 21 Dec 2023 10:05:19 +0200 Subject: [PATCH 4/4] Revert file name to logging_t --- include/logging/{logging.h => logging_t.h} | 0 src/common/Makefile | 2 +- src/common/cosigner/asymmetric_eddsa_cosigner.cpp | 2 +- src/common/cosigner/asymmetric_eddsa_cosigner_client.cpp | 2 +- src/common/cosigner/asymmetric_eddsa_cosigner_server.cpp | 2 +- src/common/cosigner/cmp_ecdsa_offline_signing_service.cpp | 2 +- src/common/cosigner/cmp_ecdsa_online_signing_service.cpp | 2 +- src/common/cosigner/cmp_ecdsa_signing_service.cpp | 2 +- src/common/cosigner/cmp_offline_refresh_service.cpp | 2 +- src/common/cosigner/cmp_setup_service.cpp | 2 +- src/common/cosigner/cosigner_exception.cpp | 2 +- src/common/cosigner/eddsa_online_signing_service.cpp | 2 +- src/common/cosigner/mta.cpp | 2 +- src/common/cosigner/utils.cpp | 2 +- src/common/logging/{logging.c => logging_t.c} | 2 +- 15 files changed, 14 insertions(+), 14 deletions(-) rename include/logging/{logging.h => logging_t.h} (100%) rename src/common/logging/{logging.c => logging_t.c} (97%) diff --git a/include/logging/logging.h b/include/logging/logging_t.h similarity index 100% rename from include/logging/logging.h rename to include/logging/logging_t.h diff --git a/src/common/Makefile b/src/common/Makefile index fddb99a..d1eb327 100644 --- a/src/common/Makefile +++ b/src/common/Makefile @@ -12,7 +12,7 @@ COMMON_CFLAGS := $(COMMON_CFLAGS) C_Files := crypto/shamir_secret_sharing/verifiable_secret_sharing.c crypto/paillier/paillier.c crypto/paillier/paillier_zkp.c crypto/GFp_curve_algebra/GFp_curve_algebra.c \ crypto/commitments/commitments.c crypto/zero_knowledge_proof/schnorr.c crypto/zero_knowledge_proof/range_proofs.c crypto/zero_knowledge_proof/diffie_hellman_log.c \ - crypto/commitments/ring_pedersen.c crypto/ed25519_algebra/ed25519_algebra.c crypto/drng/drng.c crypto/keccak1600/keccak1600.c logging/logging.c + crypto/commitments/ring_pedersen.c crypto/ed25519_algebra/ed25519_algebra.c crypto/drng/drng.c crypto/keccak1600/keccak1600.c logging/logging_t.c C_Objects := $(C_Files:.c=.o) diff --git a/src/common/cosigner/asymmetric_eddsa_cosigner.cpp b/src/common/cosigner/asymmetric_eddsa_cosigner.cpp index 09f6203..1a72722 100644 --- a/src/common/cosigner/asymmetric_eddsa_cosigner.cpp +++ b/src/common/cosigner/asymmetric_eddsa_cosigner.cpp @@ -2,7 +2,7 @@ #include "cosigner/cmp_key_persistency.h" #include "cosigner/cosigner_exception.h" #include "cosigner/platform_service.h" -#include "logging/logging.h" +#include "logging/logging_t.h" #include diff --git a/src/common/cosigner/asymmetric_eddsa_cosigner_client.cpp b/src/common/cosigner/asymmetric_eddsa_cosigner_client.cpp index d824ad4..ea01267 100644 --- a/src/common/cosigner/asymmetric_eddsa_cosigner_client.cpp +++ b/src/common/cosigner/asymmetric_eddsa_cosigner_client.cpp @@ -3,7 +3,7 @@ #include "cosigner/cosigner_exception.h" #include "cosigner/platform_service.h" #include "cosigner/mpc_globals.h" -#include "logging/logging.h" +#include "logging/logging_t.h" #include "utils.h" #include diff --git a/src/common/cosigner/asymmetric_eddsa_cosigner_server.cpp b/src/common/cosigner/asymmetric_eddsa_cosigner_server.cpp index dc30d6e..362cad9 100644 --- a/src/common/cosigner/asymmetric_eddsa_cosigner_server.cpp +++ b/src/common/cosigner/asymmetric_eddsa_cosigner_server.cpp @@ -4,7 +4,7 @@ #include "cosigner/platform_service.h" #include "cosigner/mpc_globals.h" #include "utils.h" -#include "logging/logging.h" +#include "logging/logging_t.h" #include diff --git a/src/common/cosigner/cmp_ecdsa_offline_signing_service.cpp b/src/common/cosigner/cmp_ecdsa_offline_signing_service.cpp index 0bedf6e..0109a86 100644 --- a/src/common/cosigner/cmp_ecdsa_offline_signing_service.cpp +++ b/src/common/cosigner/cmp_ecdsa_offline_signing_service.cpp @@ -6,7 +6,7 @@ #include "utils.h" #include "crypto/GFp_curve_algebra/GFp_curve_algebra.h" #include "crypto/zero_knowledge_proof/range_proofs.h" -#include "logging/logging.h" +#include "logging/logging_t.h" namespace fireblocks { diff --git a/src/common/cosigner/cmp_ecdsa_online_signing_service.cpp b/src/common/cosigner/cmp_ecdsa_online_signing_service.cpp index 899ab52..21bb43a 100644 --- a/src/common/cosigner/cmp_ecdsa_online_signing_service.cpp +++ b/src/common/cosigner/cmp_ecdsa_online_signing_service.cpp @@ -6,7 +6,7 @@ #include "crypto/GFp_curve_algebra/GFp_curve_algebra.h" #include "crypto/zero_knowledge_proof/range_proofs.h" #include "utils.h" -#include "logging/logging.h" +#include "logging/logging_t.h" namespace fireblocks { diff --git a/src/common/cosigner/cmp_ecdsa_signing_service.cpp b/src/common/cosigner/cmp_ecdsa_signing_service.cpp index 1a9d158..7278a82 100644 --- a/src/common/cosigner/cmp_ecdsa_signing_service.cpp +++ b/src/common/cosigner/cmp_ecdsa_signing_service.cpp @@ -4,7 +4,7 @@ #include "crypto/GFp_curve_algebra/GFp_curve_algebra.h" #include "crypto/zero_knowledge_proof/diffie_hellman_log.h" #include "crypto/zero_knowledge_proof/range_proofs.h" -#include "logging/logging.h" +#include "logging/logging_t.h" #include diff --git a/src/common/cosigner/cmp_offline_refresh_service.cpp b/src/common/cosigner/cmp_offline_refresh_service.cpp index b752e67..7e5c5b9 100644 --- a/src/common/cosigner/cmp_offline_refresh_service.cpp +++ b/src/common/cosigner/cmp_offline_refresh_service.cpp @@ -6,7 +6,7 @@ #include "cosigner/platform_service.h" #include "cosigner/prf.h" #include "crypto/elliptic_curve_algebra/elliptic_curve256_algebra.h" -#include "logging/logging.h" +#include "logging/logging_t.h" namespace fireblocks { diff --git a/src/common/cosigner/cmp_setup_service.cpp b/src/common/cosigner/cmp_setup_service.cpp index 0594b17..8bf373d 100644 --- a/src/common/cosigner/cmp_setup_service.cpp +++ b/src/common/cosigner/cmp_setup_service.cpp @@ -2,7 +2,7 @@ #include "cosigner/cosigner_exception.h" #include "utils.h" #include "crypto/zero_knowledge_proof/schnorr.h" -#include "logging/logging.h" +#include "logging/logging_t.h" #include diff --git a/src/common/cosigner/cosigner_exception.cpp b/src/common/cosigner/cosigner_exception.cpp index 6fc99f2..32b9f15 100644 --- a/src/common/cosigner/cosigner_exception.cpp +++ b/src/common/cosigner/cosigner_exception.cpp @@ -1,6 +1,6 @@ #include "cosigner/cosigner_exception.h" #include "crypto/paillier/paillier.h" -#include "logging/logging.h" +#include "logging/logging_t.h" namespace fireblocks { diff --git a/src/common/cosigner/eddsa_online_signing_service.cpp b/src/common/cosigner/eddsa_online_signing_service.cpp index 4aaa8aa..8bb4f91 100644 --- a/src/common/cosigner/eddsa_online_signing_service.cpp +++ b/src/common/cosigner/eddsa_online_signing_service.cpp @@ -4,7 +4,7 @@ #include "cosigner/mpc_globals.h" #include "cosigner/platform_service.h" #include "utils.h" -#include "logging/logging.h" +#include "logging/logging_t.h" extern "C" int gettimeofday(struct timeval *tv, struct timezone *tz); diff --git a/src/common/cosigner/mta.cpp b/src/common/cosigner/mta.cpp index 0b078c0..3d3a088 100644 --- a/src/common/cosigner/mta.cpp +++ b/src/common/cosigner/mta.cpp @@ -6,7 +6,7 @@ #include "../crypto/paillier/paillier_internal.h" #ifndef TEST_ONLY -#include "logging/logging.h" +#include "logging/logging_t.h" #else #define LOG_ERROR(message, ...) printf((message), ##__VA_ARGS__);putchar('\n') #endif diff --git a/src/common/cosigner/utils.cpp b/src/common/cosigner/utils.cpp index 50d735b..e9b220b 100644 --- a/src/common/cosigner/utils.cpp +++ b/src/common/cosigner/utils.cpp @@ -2,7 +2,7 @@ #include "cosigner/cmp_key_persistency.h" #include "cosigner/cosigner_exception.h" #include "cosigner/platform_service.h" -#include "logging/logging.h" +#include "logging/logging_t.h" namespace fireblocks { diff --git a/src/common/logging/logging.c b/src/common/logging/logging_t.c similarity index 97% rename from src/common/logging/logging.c rename to src/common/logging/logging_t.c index 0c08ca0..ec1da77 100644 --- a/src/common/logging/logging.c +++ b/src/common/logging/logging_t.c @@ -1,4 +1,4 @@ -#include "logging/logging.h" +#include "logging/logging_t.h" #include #include