mirror of
https://github.com/chris2511/xca.git
synced 2026-09-13 18:46:25 +05:00
Minor improvements for EC keys
This commit is contained in:
parent
ba303346f1
commit
f8eda7cd53
@ -7,9 +7,12 @@
|
||||
|
||||
#include "builtin_curves.h"
|
||||
#include "exception.h"
|
||||
#include "func.h"
|
||||
|
||||
#ifndef OPENSSL_NO_EC
|
||||
#include <openssl/ec.h>
|
||||
#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; j<ARRAY_SIZE(x962_curve_nids); j++) {
|
||||
if (x962_curve_nids[j] == nid) {
|
||||
@ -138,10 +142,25 @@ builtin_curves::builtin_curves()
|
||||
EC_GROUP *group = EC_GROUP_new_by_curve_name(nid);
|
||||
EC_GROUP_get_order(group, order, NULL);
|
||||
|
||||
switch (EC_METHOD_get_field_type(EC_GROUP_method_of(group))) {
|
||||
case NID_X9_62_prime_field:
|
||||
type = CKF_EC_F_P;
|
||||
break;
|
||||
case NID_X9_62_characteristic_two_field:
|
||||
type = CKF_EC_F_2M;
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
#undef PRINT_KNOWN_CURVES
|
||||
#ifdef PRINT_KNOWN_CURVES
|
||||
fprintf(stderr, "%50s %27s %20s %s\n",
|
||||
curves[i].comment, OBJ_nid2sn(nid),
|
||||
CCHAR(OBJ_obj2QString(OBJ_nid2obj(nid), 1)),
|
||||
type == CKF_EC_F_P ? "Fp" : "F2m");
|
||||
#endif
|
||||
append(builtin_curve(nid, QString(curves[i].comment),
|
||||
BN_num_bits(order), flag,
|
||||
EC_METHOD_get_field_type(EC_GROUP_method_of(group)))
|
||||
);
|
||||
BN_num_bits(order), flag, type));
|
||||
EC_GROUP_free(group);
|
||||
}
|
||||
BN_free(order);
|
||||
|
||||
@ -22,11 +22,8 @@ class builtin_curve
|
||||
QString comment;
|
||||
unsigned order_size;
|
||||
int flags;
|
||||
/* type:
|
||||
* NID_X9_62_prime_field
|
||||
* NID_X9_62_characteristic_two_field
|
||||
*/
|
||||
int type;
|
||||
/* type: CKF_EC_F_P || CKF_EC_F_2M */
|
||||
unsigned long type;
|
||||
builtin_curve(int n, QString c, int s, int f, int t) {
|
||||
nid = n;
|
||||
comment = c;
|
||||
|
||||
@ -55,7 +55,10 @@ class keyListItem
|
||||
|
||||
minKeySize = mechinfo.ulMinKeySize;
|
||||
maxKeySize = mechinfo.ulMaxKeySize;
|
||||
|
||||
if (maxKeySize == 0) {
|
||||
/* Fallback for libraries not filling in the maxKeySize */
|
||||
maxKeySize = INT_MAX;
|
||||
}
|
||||
tkInfo ti = p11->tokenInfo(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())
|
||||
|
||||
Loading…
Reference in New Issue
Block a user