Skip to content

Commit

Permalink
deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
cedelavergne-ledger committed Jun 17, 2024
1 parent 5a270cc commit 339804e
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 93 deletions.
20 changes: 8 additions & 12 deletions src/eos_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,12 @@ static void processEosioUnlinkAuth(txProcessingContext_t *context) {
}

static void processUnknownAction(txProcessingContext_t *context) {
LEDGER_ASSERT(cx_hash_no_throw(&context->dataSha256->header,
CX_LAST,
context->dataChecksum,
0,
context->dataChecksum,
sizeof(context->dataChecksum)) == CX_OK,
"cx_hash_no_throw Error");
CX_ASSERT(cx_hash_no_throw(&context->dataSha256->header,
CX_LAST,
context->dataChecksum,
0,
context->dataChecksum,
sizeof(context->dataChecksum)));
context->content->argumentCount = 3;
}

Expand Down Expand Up @@ -387,14 +386,11 @@ static bool isKnownAction(txProcessingContext_t *context) {
* dependencies on specific hash implementation.
*/
static void hashTxData(txProcessingContext_t *context, uint8_t *buffer, uint32_t length) {
LEDGER_ASSERT(cx_hash_no_throw(&context->sha256->header, 0, buffer, length, NULL, 0) == CX_OK,
"cx_hash_no_throw Error");
CX_ASSERT(cx_hash_no_throw(&context->sha256->header, 0, buffer, length, NULL, 0));
}

static void hashActionData(txProcessingContext_t *context, uint8_t *buffer, uint32_t length) {
LEDGER_ASSERT(
cx_hash_no_throw(&context->dataSha256->header, 0, buffer, length, NULL, 0) == CX_OK,
"cx_hash_no_throw Error");
CX_ASSERT(cx_hash_no_throw(&context->dataSha256->header, 0, buffer, length, NULL, 0));
}

/**
Expand Down
4 changes: 1 addition & 3 deletions src/eos_types.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,7 @@ uint32_t compressed_public_key_to_wif(uint8_t *publicKey,
uint8_t check[20];
cx_ripemd160_t riprip;
cx_ripemd160_init(&riprip);
LEDGER_ASSERT(
cx_hash_no_throw(&riprip.header, CX_LAST, temp, 33, check, sizeof(check)) == CX_OK,
"cx_hash_no_throw Error");
CX_ASSERT(cx_hash_no_throw(&riprip.header, CX_LAST, temp, 33, check, sizeof(check)));
memmove(temp + 33, check, 4);

memset(out, 0, outLength);
Expand Down
55 changes: 18 additions & 37 deletions src/eos_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,49 +257,32 @@ void rng_rfc6979(unsigned char *rnd,
memset(K, 0x00, h_len);
// d. Set: K = HMAC_K(V || 0x00 || int2octets(x) || bits2octets(h1))
V[h_len] = 0;
LEDGER_ASSERT(cx_hmac_sha256_init_no_throw(&hmac, K, 32) == CX_OK,
"cx_hmac_sha256_init_no_throw Error");
LEDGER_ASSERT(cx_hmac_no_throw((cx_hmac_t *) &hmac, 0, V, h_len + 1, K, 32) == CX_OK,
"cx_hmac_no_throw Error");
LEDGER_ASSERT(cx_hmac_no_throw((cx_hmac_t *) &hmac, 0, x, x_len, K, 32) == CX_OK,
"cx_hmac_no_throw Error");
LEDGER_ASSERT(cx_hmac_no_throw((cx_hmac_t *) &hmac, CX_LAST, h1, h_len, K, 32) == CX_OK,
"cx_hmac_no_throw Error");
CX_ASSERT(cx_hmac_sha256_init_no_throw(&hmac, K, 32));
CX_ASSERT(cx_hmac_no_throw((cx_hmac_t *) &hmac, 0, V, h_len + 1, K, 32));
CX_ASSERT(cx_hmac_no_throw((cx_hmac_t *) &hmac, 0, x, x_len, K, 32));
CX_ASSERT(cx_hmac_no_throw((cx_hmac_t *) &hmac, CX_LAST, h1, h_len, K, 32));
// e. Set: V = HMAC_K(V)
LEDGER_ASSERT(cx_hmac_sha256_init_no_throw(&hmac, K, 32) == CX_OK,
"cx_hmac_sha256_init_no_throw Error");
LEDGER_ASSERT(cx_hmac_no_throw((cx_hmac_t *) &hmac, CX_LAST, V, h_len, V, 32) == CX_OK,
"cx_hmac_no_throw Error");
CX_ASSERT(cx_hmac_sha256_init_no_throw(&hmac, K, 32));
CX_ASSERT(cx_hmac_no_throw((cx_hmac_t *) &hmac, CX_LAST, V, h_len, V, 32));
// f. Set: K = HMAC_K(V || 0x01 || int2octets(x) || bits2octets(h1))
V[h_len] = 1;
LEDGER_ASSERT(cx_hmac_sha256_init_no_throw(&hmac, K, 32) == CX_OK,
"cx_hmac_sha256_init_no_throw Error");
LEDGER_ASSERT(cx_hmac_no_throw((cx_hmac_t *) &hmac, 0, V, h_len + 1, K, 32) == CX_OK,
"cx_hmac_no_throw Error");
LEDGER_ASSERT(cx_hmac_no_throw((cx_hmac_t *) &hmac, 0, x, x_len, K, 32) == CX_OK,
"cx_hmac_no_throw Error");
LEDGER_ASSERT(cx_hmac_no_throw((cx_hmac_t *) &hmac, CX_LAST, h1, h_len, K, 32) == CX_OK,
"cx_hmac_no_throw Error");
CX_ASSERT(cx_hmac_sha256_init_no_throw(&hmac, K, 32));
CX_ASSERT(cx_hmac_no_throw((cx_hmac_t *) &hmac, 0, V, h_len + 1, K, 32));
CX_ASSERT(cx_hmac_no_throw((cx_hmac_t *) &hmac, 0, x, x_len, K, 32));
CX_ASSERT(cx_hmac_no_throw((cx_hmac_t *) &hmac, CX_LAST, h1, h_len, K, 32));
// g. Set: V = HMAC_K(V) --
LEDGER_ASSERT(cx_hmac_sha256_init_no_throw(&hmac, K, 32) == CX_OK,
"cx_hmac_sha256_init_no_throw Error");
LEDGER_ASSERT(cx_hmac_no_throw((cx_hmac_t *) &hmac, CX_LAST, V, h_len, V, 32) == CX_OK,
"cx_hmac_no_throw Error");
CX_ASSERT(cx_hmac_sha256_init_no_throw(&hmac, K, 32));
CX_ASSERT(cx_hmac_no_throw((cx_hmac_t *) &hmac, CX_LAST, V, h_len, V, 32));
// initial setup only once
x = NULL;
} else {
// h.3 K = HMAC_K(V || 0x00)
V[h_len] = 0;
LEDGER_ASSERT(cx_hmac_sha256_init_no_throw(&hmac, K, 32) == CX_OK,
"cx_hmac_sha256_init_no_throw Error");
LEDGER_ASSERT(
cx_hmac_no_throw((cx_hmac_t *) &hmac, CX_LAST, V, h_len + 1, K, 32) == CX_OK,
"cx_hmac_no_throw Error");
CX_ASSERT(cx_hmac_sha256_init_no_throw(&hmac, K, 32));
CX_ASSERT(cx_hmac_no_throw((cx_hmac_t *) &hmac, CX_LAST, V, h_len + 1, K, 32));
// h.3 V = HMAC_K(V)
LEDGER_ASSERT(cx_hmac_sha256_init_no_throw(&hmac, K, 32) == CX_OK,
"cx_hmac_sha256_init_no_throw Error");
LEDGER_ASSERT(cx_hmac_no_throw((cx_hmac_t *) &hmac, CX_LAST, V, h_len, V, 32) == CX_OK,
"cx_hmac_no_throw Error");
CX_ASSERT(cx_hmac_sha256_init_no_throw(&hmac, K, 32));
CX_ASSERT(cx_hmac_no_throw((cx_hmac_t *) &hmac, CX_LAST, V, h_len, V, 32));
}

// generate candidate
Expand All @@ -316,10 +299,8 @@ void rng_rfc6979(unsigned char *rnd,
if (x_len < h_len) {
h_len = x_len;
}
LEDGER_ASSERT(cx_hmac_sha256_init_no_throw(&hmac, K, 32) == CX_OK,
"cx_hmac_sha256_init_no_throw Error");
LEDGER_ASSERT(cx_hmac_no_throw((cx_hmac_t *) &hmac, CX_LAST, V, h_len, V, 32) == CX_OK,
"cx_hmac_no_throw Error");
CX_ASSERT(cx_hmac_sha256_init_no_throw(&hmac, K, 32));
CX_ASSERT(cx_hmac_no_throw((cx_hmac_t *) &hmac, CX_LAST, V, h_len, V, 32));
memmove(rnd + offset, V, h_len);
x_len -= h_len;
}
Expand Down
72 changes: 31 additions & 41 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,22 +155,17 @@ uint32_t handleGetPublicKey(uint8_t p1,
dataBuffer += 4;
}
tmpCtx.publicKeyContext.getChaincode = (p2 == P2_CHAINCODE);
LEDGER_ASSERT(os_derive_bip32_no_throw(
CX_CURVE_256K1,
bip32Path,
bip32PathLength,
privateKeyData,
(tmpCtx.publicKeyContext.getChaincode ? tmpCtx.publicKeyContext.chainCode
: NULL)) == CX_OK,
"os_derive_bip32_no_throw Error");
LEDGER_ASSERT(
cx_ecfp_init_private_key_no_throw(CX_CURVE_256K1, privateKeyData, 32, &privateKey) == CX_OK,
"cx_ecfp_init_private_key_no_throw Error");
LEDGER_ASSERT(cx_ecfp_generate_pair_no_throw(CX_CURVE_256K1,
&tmpCtx.publicKeyContext.publicKey,
&privateKey,
1) == CX_OK,
"cx_ecfp_generate_pair_no_throw Error");
CX_ASSERT(os_derive_bip32_no_throw(
CX_CURVE_256K1,
bip32Path,
bip32PathLength,
privateKeyData,
(tmpCtx.publicKeyContext.getChaincode ? tmpCtx.publicKeyContext.chainCode : NULL)));
CX_ASSERT(cx_ecfp_init_private_key_no_throw(CX_CURVE_256K1, privateKeyData, 32, &privateKey));
CX_ASSERT(cx_ecfp_generate_pair_no_throw(CX_CURVE_256K1,
&tmpCtx.publicKeyContext.publicKey,
&privateKey,
1));
memset(&privateKey, 0, sizeof(privateKey));
memset(privateKeyData, 0, sizeof(privateKeyData));
public_key_to_wif(tmpCtx.publicKeyContext.publicKey.W,
Expand Down Expand Up @@ -208,13 +203,12 @@ uint32_t handleGetAppConfiguration(uint8_t p1,

uint32_t sign_hash_and_set_result(void) {
// store hash
LEDGER_ASSERT(cx_hash_no_throw(&sha256.header,
CX_LAST,
tmpCtx.transactionContext.hash,
0,
tmpCtx.transactionContext.hash,
sizeof(tmpCtx.transactionContext.hash)) == CX_OK,
"cx_hash_no_throw Error");
CX_ASSERT(cx_hash_no_throw(&sha256.header,
CX_LAST,
tmpCtx.transactionContext.hash,
0,
tmpCtx.transactionContext.hash,
sizeof(tmpCtx.transactionContext.hash)));

uint8_t privateKeyData[64];
cx_ecfp_private_key_t privateKey;
Expand All @@ -223,15 +217,12 @@ uint32_t sign_hash_and_set_result(void) {
uint8_t K[32];
int tries = 0;

LEDGER_ASSERT(os_derive_bip32_no_throw(CX_CURVE_256K1,
tmpCtx.transactionContext.bip32Path,
tmpCtx.transactionContext.pathLength,
privateKeyData,
NULL) == CX_OK,
"os_derive_bip32_no_throw Error");
LEDGER_ASSERT(
cx_ecfp_init_private_key_no_throw(CX_CURVE_256K1, privateKeyData, 32, &privateKey) == CX_OK,
"cx_ecfp_init_private_key_no_throw Error");
CX_ASSERT(os_derive_bip32_no_throw(CX_CURVE_256K1,
tmpCtx.transactionContext.bip32Path,
tmpCtx.transactionContext.pathLength,
privateKeyData,
NULL));
CX_ASSERT(cx_ecfp_init_private_key_no_throw(CX_CURVE_256K1, privateKeyData, 32, &privateKey));
memset(privateKeyData, 0, sizeof(privateKeyData));

// Loop until a candidate matching the canonical signature is found
Expand All @@ -258,15 +249,14 @@ uint32_t sign_hash_and_set_result(void) {
}
uint32_t infos;
uint32_t sig_len = 100;
LEDGER_ASSERT(cx_ecdsa_sign_no_throw(&privateKey,
CX_NO_CANONICAL | CX_RND_PROVIDED | CX_LAST,
CX_SHA256,
tmpCtx.transactionContext.hash,
32,
G_io_apdu_buffer + 100,
&sig_len,
&infos) == CX_OK,
"cx_ecdsa_sign_no_throw Error");
CX_ASSERT(cx_ecdsa_sign_no_throw(&privateKey,
CX_NO_CANONICAL | CX_RND_PROVIDED | CX_LAST,
CX_SHA256,
tmpCtx.transactionContext.hash,
32,
G_io_apdu_buffer + 100,
&sig_len,
&infos));
if ((infos & CX_ECCINFO_PARITY_ODD) != 0) {
G_io_apdu_buffer[100] |= 0x01;
}
Expand Down

0 comments on commit 339804e

Please sign in to comment.