From f8eda7cd538ac7ea5a0caa4e5ef626dc13626dc6 Mon Sep 17 00:00:00 2001 From: Christian Hohnstaedt Date: Fri, 31 Oct 2014 21:57:54 +0100 Subject: [PATCH] Minor improvements for EC keys --- lib/builtin_curves.cpp | 25 ++++++++++++++++++++++--- lib/builtin_curves.h | 7 ++----- widgets/NewKey.cpp | 21 ++++++++++++--------- 3 files changed, 36 insertions(+), 17 deletions(-) diff --git a/lib/builtin_curves.cpp b/lib/builtin_curves.cpp index e0ffcfa6..5ebf0d93 100644 --- a/lib/builtin_curves.cpp +++ b/lib/builtin_curves.cpp @@ -7,9 +7,12 @@ #include "builtin_curves.h" #include "exception.h" +#include "func.h" #ifndef OPENSSL_NO_EC #include +#include "opensc-pkcs11.h" + static const int x962_curve_nids[] = { NID_X9_62_prime192v1, NID_X9_62_prime192v2, @@ -117,6 +120,7 @@ builtin_curves::builtin_curves() for (i=0; i< num_curves; i++) { size_t j; int flag = 0, nid = curves[i].nid; + unsigned long type = 0; for (j=0; jtokenInfo(slot); tl = typeList; //idx of EVP_PKEY_RSA #ifndef OPENSSL_NO_EC @@ -63,7 +66,13 @@ class keyListItem tl = typeList +2; CK_MECHANISM_INFO info; p11->mechanismInfo(slot, m, &info); - ec_flags = info.flags & (CKF_EC_F_2M | CKF_EC_F_P); + ec_flags = info.flags & (CKF_EC_F_P | CKF_EC_F_2M); + if (!ec_flags) { + /* Fallback: Assume to support both for + * libraries leaving this flag empty + */ + ec_flags = CKF_EC_F_P | CKF_EC_F_2M; + } } #endif printname = QString("%1 #%2 (%3 Key of %4 - %5 bits)"). @@ -168,18 +177,12 @@ void NewKey::updateCurves(unsigned min, unsigned max, unsigned long ec_flags) QStringList curve_x962, curve_other; foreach(builtin_curve curve, pki_key::builtinCurves) { const char *sn = OBJ_nid2sn(curve.nid); - unsigned long group_type; QString comment = curve.comment; if (!sn || curve.order_size < min || curve.order_size > max) continue; if (ec_flags) { - if (curve.type == NID_X9_62_prime_field) - group_type = CKF_EC_F_P; - else // ft = NID_X9_62_characteristic_two_field - group_type = CKF_EC_F_2M; - - if ((group_type & ec_flags) == 0) + if ((curve.type & ec_flags) == 0) continue; } if (comment.isEmpty())