From c110ec500100d1fe9a9295fd1fdbd118836e0341 Mon Sep 17 00:00:00 2001 From: NIIBE Yutaka Date: Tue, 28 Jun 2022 19:53:59 +0900 Subject: [PATCH] Remove DO definition for internal NR_DO_PRVKEY_*. Signed-off-by: NIIBE Yutaka --- src/flash.c | 2 +- src/gnuk.h | 4 +--- src/openpgp-do.c | 16 +++++++++------- src/openpgp.c | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/flash.c b/src/flash.c index ea14bf9..3638c93 100644 --- a/src/flash.c +++ b/src/flash.c @@ -105,7 +105,7 @@ struct pkc_key { uint16_t last_dek_offset; }; -struct pkc_key pkc_key[MAX_PKC_KEY]; +static struct pkc_key pkc_key[MAX_PKC_KEY]; #define CHIP_ID_REG ((uint32_t *)0xe0042000) diff --git a/src/gnuk.h b/src/gnuk.h index a979c56..7d67c04 100644 --- a/src/gnuk.h +++ b/src/gnuk.h @@ -320,9 +320,7 @@ extern uint8_t admin_authorized; #define NR_DO_URL 0x0b #define NR_DO_NAME 0x0c #define NR_DO_LANGUAGE 0x0d -#define NR_DO_PRVKEY_SIG 0x0e -#define NR_DO_PRVKEY_DEC 0x0f -#define NR_DO_PRVKEY_AUT 0x10 +/**/ #define NR_DO_KEYSTRING_PW1 0x11 #define NR_DO_KEYSTRING_RC 0x12 #define NR_DO_KEYSTRING_PW3 0x13 diff --git a/src/openpgp-do.c b/src/openpgp-do.c index 50d57fa..7f0c015 100644 --- a/src/openpgp-do.c +++ b/src/openpgp-do.c @@ -45,6 +45,8 @@ static void gpg_reset_digital_signature_counter (void); #define PASSWORD_ERRORS_MAX 3 /* >= errors, it will be locked */ static const uint8_t *pw_err_counter_p[3]; +static int8_t num_prv_keys; + static int gpg_pw_get_err_counter (uint8_t which) { @@ -925,8 +927,7 @@ rw_kdf (uint16_t tag, int with_tag, const uint8_t *data, int len, int is_write) const uint8_t **do_data_p = (const uint8_t **)&do_ptr[NR_DO_KDF]; /* KDF DO can be changed only when no keys are registered. */ - if (do_ptr[NR_DO_PRVKEY_SIG] || do_ptr[NR_DO_PRVKEY_DEC] - || do_ptr[NR_DO_PRVKEY_AUT]) + if (num_prv_keys) return 0; /* The valid data format is: @@ -1241,11 +1242,12 @@ gpg_do_load_prvkey (enum kind_of_key kk, int who, const uint8_t *keystring) } -static int8_t num_prv_keys; - static void gpg_do_delete_prvkey (enum kind_of_key kk) { + if (flash_key_addr (kk, NULL, NULL, NULL, NULL, NULL, NULL, NULL) == NULL) + return; + flash_key_release (kk); if (admin_authorized == BY_ADMIN && kk == GPG_KEY_FOR_SIGNING) @@ -1818,11 +1820,11 @@ gpg_data_scan (const uint8_t *do_start, const uint8_t *do_end) flash_set_data_pool_last (p); num_prv_keys = 0; - if (do_ptr[NR_DO_PRVKEY_SIG] != NULL) + if (flash_key_addr (0, NULL, NULL, NULL, NULL, NULL, NULL, NULL)) num_prv_keys++; - if (do_ptr[NR_DO_PRVKEY_DEC] != NULL) + if (flash_key_addr (1, NULL, NULL, NULL, NULL, NULL, NULL, NULL)) num_prv_keys++; - if (do_ptr[NR_DO_PRVKEY_AUT] != NULL) + if (flash_key_addr (2, NULL, NULL, NULL, NULL, NULL, NULL, NULL)) num_prv_keys++; data_objects_number_of_bytes = 0; diff --git a/src/openpgp.c b/src/openpgp.c index 6a89116..019b0c6 100644 --- a/src/openpgp.c +++ b/src/openpgp.c @@ -115,8 +115,8 @@ gpg_init (void) else file_selection = FILE_NONE; - gpg_data_scan (flash_do_start, flash_do_end); flash_key_storage_init (); + gpg_data_scan (flash_do_start, flash_do_end); } static void