From f472b1656d4c06c35bdef2d231496e8af0ffe699 Mon Sep 17 00:00:00 2001 From: Nikos Mavrogiannopoulos Date: Sat, 11 Mar 2017 12:08:21 +0100 Subject: pkcs11: during scan, leave the provider loop asap This optimizes access when multiple provider modules are available, by avoiding scanning irrelevant ones. Signed-off-by: Nikos Mavrogiannopoulos --- lib/pkcs11.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/pkcs11.c b/lib/pkcs11.c index 4bd2f3f232..a7b2c2b2f6 100644 --- a/lib/pkcs11.c +++ b/lib/pkcs11.c @@ -1202,6 +1202,11 @@ pkcs11_find_slot(struct ck_function_list **module, ck_slot_id_t * slot, if (providers[x].active == 0) continue; + if (!p11_kit_uri_match_module_info(info, + &providers[x].info)) { + continue; + } + nslots = sizeof(slots) / sizeof(slots[0]); ret = scan_slots(&providers[x], slots, &nslots); if (ret < 0) { @@ -1219,17 +1224,12 @@ pkcs11_find_slot(struct ck_function_list **module, ck_slot_id_t * slot, continue; } - if (pkcs11_get_slot_info - (providers[x].module, slots[z], - &sinfo) != CKR_OK) { + if (!p11_kit_uri_match_token_info(info, &tinfo)) { continue; } - if (!p11_kit_uri_match_token_info - (info, &tinfo) - || !p11_kit_uri_match_module_info(info, - &providers - [x].info)) { + if (pkcs11_get_slot_info + (providers[x].module, slots[z], &sinfo) != CKR_OK) { continue; } @@ -1327,6 +1327,10 @@ _pkcs11_traverse_tokens(find_func_t find_func, void *input, if (flags & SESSION_TRUSTED && providers[x].trusted == 0) continue; + if (info && !p11_kit_uri_match_module_info(info, &providers[x].info)) { + continue; + } + nslots = sizeof(slots) / sizeof(slots[0]); ret = scan_slots(&providers[x], slots, &nslots); if (ret < 0) { @@ -1344,17 +1348,13 @@ _pkcs11_traverse_tokens(find_func_t find_func, void *input, continue; } - if (pkcs11_get_slot_info(module, slots[z], - &l_sinfo) != CKR_OK) { + if (info && !p11_kit_uri_match_token_info(info, &l_tinfo)) { continue; } - if (info != NULL) { - if (!p11_kit_uri_match_token_info(info, &l_tinfo) || - !p11_kit_uri_match_module_info(info, &providers - [x].info)) { + if (pkcs11_get_slot_info(module, slots[z], + &l_sinfo) != CKR_OK) { continue; - } } rv = (module)->C_OpenSession(slots[z], -- cgit v1.2.1