Skip to content

Commit f4d8c81

Browse files
Use SDK TLV library
1 parent 98055ba commit f4d8c81

File tree

6 files changed

+143
-340
lines changed

6 files changed

+143
-340
lines changed

src/hash_bytes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* @param[in] hash_ctx pointer to the hashing context
99
*/
1010
void hash_nbytes(const uint8_t *bytes_ptr, size_t n, cx_hash_t *hash_ctx) {
11-
CX_ASSERT(cx_hash_no_throw(hash_ctx, 0, bytes_ptr, n, NULL, 0));
11+
CX_ASSERT(cx_hash_update(hash_ctx, bytes_ptr, n));
1212
}
1313

1414
/**

src/ledger_pki.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ int check_signature_with_pubkey(const char *tag,
2424
#ifdef HAVE_LEDGER_PKI
2525
const uint8_t keyUsageExp,
2626
#endif
27-
uint8_t *signature,
27+
const uint8_t *signature,
2828
const uint8_t sigLen) {
2929
UNUSED(tag);
3030
cx_ecfp_public_key_t verif_key = {0};
@@ -50,7 +50,7 @@ int check_signature_with_pubkey(const char *tag,
5050
KEY_USAGE_STR(key_usage));
5151

5252
// Checking the signature with PKI
53-
if (!os_pki_verify(buffer, bufLen, signature, sigLen)) {
53+
if (!os_pki_verify(buffer, bufLen, (uint8_t *)signature, sigLen)) {
5454
PRINTF("%s: Invalid signature\n", tag);
5555
#ifndef HAVE_BYPASS_SIGNATURES
5656
error = APDU_RESPONSE_INVALID_DATA;

src/public_keys.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,5 +117,5 @@ int check_signature_with_pubkey(const char *tag,
117117
#ifdef HAVE_LEDGER_PKI
118118
const uint8_t keyUsageExp,
119119
#endif
120-
uint8_t *signature,
120+
const uint8_t *signature,
121121
const uint8_t sigLen);

src_features/provide_trusted_name/cmd_trusted_name.c

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,6 @@
88
#include "tlv_apdu.h"
99
#include "apdu_constants.h"
1010

11-
static bool handle_tlv_payload(const uint8_t *payload, uint16_t size, bool to_free) {
12-
s_trusted_name_ctx ctx = {0};
13-
bool parsing_ret;
14-
15-
ctx.trusted_name.name = g_trusted_name;
16-
cx_sha256_init(&ctx.hash_ctx);
17-
parsing_ret = tlv_parse(payload, size, (f_tlv_data_handler) &handle_trusted_name_struct, &ctx);
18-
if (to_free) mem_dealloc(size);
19-
if (!parsing_ret || !verify_trusted_name_struct(&ctx)) {
20-
roll_challenge(); // prevent brute-force guesses
21-
return false;
22-
}
23-
roll_challenge(); // prevent replays
24-
return true;
25-
}
26-
2711
/**
2812
* Handle trusted name APDU
2913
*
@@ -32,7 +16,7 @@ static bool handle_tlv_payload(const uint8_t *payload, uint16_t size, bool to_fr
3216
* @param[in] length payload size
3317
*/
3418
uint16_t handle_trusted_name(uint8_t p1, const uint8_t *data, uint8_t length) {
35-
if (!tlv_from_apdu(p1 == P1_FIRST_CHUNK, length, data, &handle_tlv_payload)) {
19+
if (!tlv_from_apdu(p1 == P1_FIRST_CHUNK, length, data, &handle_tlv_trusted_name_payload)) {
3620
return APDU_RESPONSE_INVALID_DATA;
3721
}
3822
return APDU_RESPONSE_OK;

0 commit comments

Comments
 (0)