From 7ccbb0103f6f717c45d27eeda4061d8772d53ee7 Mon Sep 17 00:00:00 2001 From: Pol Henarejos Date: Sat, 4 Feb 2023 21:06:33 +0100 Subject: [PATCH] Fix computing length of algorithm attributes. Signed-off-by: Pol Henarejos --- src/openpgp/openpgp.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/openpgp/openpgp.c b/src/openpgp/openpgp.c index e09f268..1745232 100644 --- a/src/openpgp/openpgp.c +++ b/src/openpgp/openpgp.c @@ -674,11 +674,12 @@ int parse_algo(const uint8_t *algo, uint16_t tag) { } int parse_algoinfo(const file_t *f, int mode) { - uint8_t datalen = 0; + int datalen = 0; if (f->fid == EF_ALGO_INFO) { res_APDU[res_APDU_size++] = EF_ALGO_INFO & 0xff; - uint8_t *lp = res_APDU+res_APDU_size; - res_APDU_size++; + res_APDU[res_APDU_size++] = 0x82; + uint8_t *lp = res_APDU + res_APDU_size; + res_APDU_size += 2; datalen += parse_algo(algorithm_attr_rsa1k, EF_ALGO_SIG); datalen += parse_algo(algorithm_attr_rsa2k, EF_ALGO_SIG); datalen += parse_algo(algorithm_attr_rsa3k, EF_ALGO_SIG); @@ -716,8 +717,10 @@ int parse_algoinfo(const file_t *f, int mode) { datalen += parse_algo(algorithm_attr_bp256r1, EF_ALGO_SIG); datalen += parse_algo(algorithm_attr_bp384r1, EF_ALGO_SIG); datalen += parse_algo(algorithm_attr_bp512r1, EF_ALGO_SIG); - *lp = res_APDU+res_APDU_size-lp-1; - datalen = *lp; + uint16_t lpdif = res_APDU+res_APDU_size-lp-2; + *lp++ = lpdif >> 8; + *lp++ = lpdif & 0xff; + datalen = lpdif+4; } else if (f->fid == EF_ALGO_SIG || f->fid == EF_ALGO_DEC || f->fid == EF_ALGO_AUT) { uint16_t fid = 0x1000 | f->fid;