From bf4a3aaf945b62e2fa1298aec0f5c815a1630c54 Mon Sep 17 00:00:00 2001 From: Yaroslav Isakov Date: Sun, 4 Apr 2021 15:14:49 +0200 Subject: [PATCH] Fix find for EC algos returning wrong algo If we're finding EC algo, and curve is not matched, another algo with the same key length shoud not be returned. --- src/libopensc/card.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/libopensc/card.c b/src/libopensc/card.c index f2c6ca5ae4..7b1d6f18de 100644 --- a/src/libopensc/card.c +++ b/src/libopensc/card.c @@ -1154,16 +1154,13 @@ sc_algorithm_info_t * sc_card_find_alg(sc_card_t *card, if (info->algorithm != algorithm) continue; - if (param) { - if (info->algorithm == SC_ALGORITHM_EC || - info->algorithm == SC_ALGORITHM_EDDSA || - info->algorithm == SC_ALGORITHM_XEDDSA) - if (sc_compare_oid((struct sc_object_id *)param, &info->u._ec.params.id)) - return info; - } - if (info->key_length != key_length) - continue; - return info; + if (param && (info->algorithm == SC_ALGORITHM_EC || + info->algorithm == SC_ALGORITHM_EDDSA || + info->algorithm == SC_ALGORITHM_XEDDSA)) { + if (sc_compare_oid((struct sc_object_id *)param, &info->u._ec.params.id)) + return info; + } else if (info->key_length == key_length) + return info; } return NULL; }