mirror of
https://github.com/polhenarejos/pico-hsm.git
synced 2026-01-17 09:28:05 +00:00
Using file_has_data() to check contents.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
parent
723011078c
commit
5419ff74ee
7 changed files with 9 additions and 9 deletions
|
|
@ -43,7 +43,7 @@ int cmd_derive_asym() {
|
|||
file_t *fkey;
|
||||
if (!isUserAuthenticated)
|
||||
return SW_SECURITY_STATUS_NOT_SATISFIED();
|
||||
if (!(fkey = search_dynamic_file((KEY_PREFIX << 8) | key_id)) || !fkey->data || file_get_size(fkey) == 0)
|
||||
if (!(fkey = search_dynamic_file((KEY_PREFIX << 8) | key_id)) || !file_has_data(fkey))
|
||||
return SW_FILE_NOT_FOUND();
|
||||
if (key_has_purpose(fkey, ALGO_EC_DERIVE) == false)
|
||||
return SW_CONDITIONS_NOT_SATISFIED();
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ int cmd_external_authenticate() {
|
|||
if (apdu.nc == 0)
|
||||
return SW_WRONG_LENGTH();
|
||||
file_t *ef_puk = search_by_fid(EF_PUKAUT, NULL, SPECIFY_EF);
|
||||
if (!ef_puk || !ef_puk->data || file_get_size(ef_puk) == 0)
|
||||
if (!file_has_data(ef_puk))
|
||||
return SW_FILE_NOT_FOUND();
|
||||
uint8_t *puk_data = file_get_data(ef_puk);
|
||||
uint8_t *input = (uint8_t *)calloc(dev_name_len+challenge_len, sizeof(uint8_t)), hash[32];
|
||||
|
|
|
|||
|
|
@ -169,7 +169,7 @@ int cmd_initialize() {
|
|||
if (!fdkey)
|
||||
return SW_EXEC_ERROR();
|
||||
int ret = 0;
|
||||
if (ret_mkek != CCID_OK || file_get_size(fdkey) == 0 || file_get_data(fdkey) == NULL) {
|
||||
if (ret_mkek != CCID_OK || !file_has_data(fdkey)) {
|
||||
mbedtls_ecdsa_context ecdsa;
|
||||
mbedtls_ecdsa_init(&ecdsa);
|
||||
mbedtls_ecp_group_id ec_id = MBEDTLS_ECP_DP_SECP256R1;
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ int cmd_mse() {
|
|||
file_t *ef = search_dynamic_file(EF_PUK+i);
|
||||
if (!ef)
|
||||
break;
|
||||
if (ef->data == NULL || file_get_size(ef) == 0)
|
||||
if (!file_has_data(ef))
|
||||
break;
|
||||
size_t chr_len = 0;
|
||||
const uint8_t *chr = cvc_get_chr(file_get_data(ef), file_get_size(ef), &chr_len);
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@
|
|||
int cmd_puk_auth() {
|
||||
uint8_t p1 = P1(apdu), p2 = P2(apdu);
|
||||
file_t *ef_puk = search_by_fid(EF_PUKAUT, NULL, SPECIFY_EF);
|
||||
if (!ef_puk || !ef_puk->data || file_get_size(ef_puk) == 0)
|
||||
if (!file_has_data(ef_puk))
|
||||
return SW_FILE_NOT_FOUND();
|
||||
uint8_t *puk_data = file_get_data(ef_puk);
|
||||
if (apdu.nc > 0) {
|
||||
|
|
@ -35,7 +35,7 @@ int cmd_puk_auth() {
|
|||
ef = search_dynamic_file(EF_PUK+i);
|
||||
if (!ef) /* Never should not happen */
|
||||
return SW_MEMORY_FAILURE();
|
||||
if (ef->data == NULL || file_get_size(ef) == 0) /* found first empty slot */
|
||||
if (!file_has_data(ef)) /* found first empty slot */
|
||||
break;
|
||||
}
|
||||
uint8_t *tmp = (uint8_t *)calloc(file_get_size(ef_puk), sizeof(uint8_t));
|
||||
|
|
@ -64,7 +64,7 @@ int cmd_puk_auth() {
|
|||
file_t *ef = search_dynamic_file(EF_PUK+p2);
|
||||
if (!ef)
|
||||
return SW_INCORRECT_P1P2();
|
||||
if (ef->data == NULL || file_get_size(ef) == 0)
|
||||
if (!file_has_data(ef))
|
||||
return SW_REFERENCE_NOT_FOUND();
|
||||
size_t chr_len = 0;
|
||||
const uint8_t *chr = cvc_get_chr(file_get_data(ef), file_get_size(ef), &chr_len);
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ int cmd_reset_retry() {
|
|||
if (!file_sopin || !file_pin1) {
|
||||
return SW_FILE_NOT_FOUND();
|
||||
}
|
||||
if (!file_sopin->data) {
|
||||
if (!file_has_data(file_sopin)) {
|
||||
return SW_REFERENCE_NOT_FOUND();
|
||||
}
|
||||
uint16_t opts = get_device_options();
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ int cmd_signature() {
|
|||
file_t *fkey;
|
||||
if (!isUserAuthenticated)
|
||||
return SW_SECURITY_STATUS_NOT_SATISFIED();
|
||||
if (!(fkey = search_dynamic_file((KEY_PREFIX << 8) | key_id)) || !fkey->data || file_get_size(fkey) == 0)
|
||||
if (!(fkey = search_dynamic_file((KEY_PREFIX << 8) | key_id)) || !file_has_data(fkey))
|
||||
return SW_FILE_NOT_FOUND();
|
||||
if (get_key_counter(fkey) == 0)
|
||||
return SW_FILE_FULL();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue