31#include <openssl/ec.h>
32#include <openssl/ecdsa.h>
33#include <openssl/rsa.h>
34#include <openssl/x509.h>
44static const uint8_t oid_secp256r1[] = {
ASN1_OID, 0x08, 0x2a, 0x86, 0x48,
45 0xce, 0x3d, 0x03, 0x01, 0x07};
53 0x03, 0x03, 0x02, 0x08,
56 0x03, 0x03, 0x02, 0x08,
59 0x03, 0x03, 0x02, 0x08,
63 CK_MECHANISM_TYPE item) {
87 CK_MECHANISM_TYPE buffer[128];
221 if (items > *
count) {
235static void find_minmax_rsa_key_length_in_bits(
yh_algorithm *algorithms,
242 for (
size_t i = 0; i < n_algorithms; i++) {
245 switch (algorithms[i]) {
261 if (*min == 0 || *min > size) {
270static void find_minmax_ec_key_length_in_bits(
yh_algorithm *algorithms,
277 for (
size_t i = 0; i < n_algorithms; i++) {
279 switch (algorithms[i]) {
304 if (*min == 0 || *min > size) {
336 &
pInfo->ulMinKeySize,
337 &
pInfo->ulMaxKeySize);
347 &
pInfo->ulMinKeySize,
348 &
pInfo->ulMaxKeySize);
354 &
pInfo->ulMinKeySize,
355 &
pInfo->ulMaxKeySize);
361 &
pInfo->ulMinKeySize,
362 &
pInfo->ulMaxKeySize);
368 &
pInfo->ulMinKeySize,
369 &
pInfo->ulMaxKeySize);
375 pInfo->ulMaxKeySize = 64 * 8;
376 pInfo->ulMinKeySize = 1;
381 pInfo->ulMaxKeySize = 64 * 8;
382 pInfo->ulMinKeySize = 1;
387 pInfo->ulMaxKeySize = 128 * 8;
388 pInfo->ulMinKeySize = 1;
393 pInfo->ulMaxKeySize = 128 * 8;
394 pInfo->ulMinKeySize = 1;
406 &
pInfo->ulMinKeySize,
407 &
pInfo->ulMaxKeySize);
414 &
pInfo->ulMinKeySize,
415 &
pInfo->ulMaxKeySize);
421 pInfo->ulMaxKeySize = 0;
422 pInfo->ulMinKeySize = 0;
427 pInfo->ulMaxKeySize = 0;
428 pInfo->ulMinKeySize = 0;
433 pInfo->ulMaxKeySize = 0;
434 pInfo->ulMinKeySize = 0;
439 pInfo->ulMaxKeySize = 0;
440 pInfo->ulMinKeySize = 0;
445 pInfo->ulMaxKeySize = 256;
446 pInfo->ulMinKeySize = 128;
451 pInfo->ulMaxKeySize =
453 pInfo->ulMinKeySize = 1;
468 for (
CK_ULONG i = 0; i < hex_len; i += 2) {
469 if (isxdigit(hex[i]) == 0 || isxdigit(hex[i + 1]) == 0) {
473 if (isdigit(hex[i])) {
474 parsed[
j] = (hex[i] -
'0') << 4;
476 parsed[
j] = (tolower(hex[i]) -
'a' + 10) << 4;
479 if (isdigit(hex[i + 1])) {
480 parsed[
j] |= (hex[i + 1] -
'0');
482 parsed[
j] |= (tolower(hex[i + 1]) -
'a' + 10);
536 const char *capability,
bool val,
552static CK_RV get_attribute_opaque(CK_ATTRIBUTE_TYPE type,
568 *length =
sizeof(CK_OBJECT_CLASS);
587 get_label_attribute(
object,
value, length);
591 get_id_attribute(
object,
value, length);
597 char *
str =
"Opaque object";
598 strcpy((
char *)
value, str);
599 *length = strlen(str);
618 *length =
sizeof(CK_CERTIFICATE_TYPE);
633static CK_RV get_attribute_secret_key(CK_ATTRIBUTE_TYPE type,
640 *length =
sizeof(CK_OBJECT_CLASS);
659 get_label_attribute(
object,
value, length);
706 *length =
sizeof(CK_KEY_TYPE);
710 get_id_attribute(
object,
value, length);
743 get_capability_attribute(
object,
"sign-hmac",
true,
value, length,
749 get_capability_attribute(
object,
"verify-hmac",
true,
value, length,
755 get_capability_attribute(
object,
"unwrap-data",
true,
value, length,
761 get_capability_attribute(
object,
"wrap-data",
true,
value, length,
773 get_capability_attribute(
object,
"export-wrapped",
true,
value, length,
779 get_capability_attribute(
object,
"import-wrapped",
true,
value, length,
784 get_capability_attribute(
object,
"exportable-under-wrap",
true,
value,
789 get_capability_attribute(
object,
"exportable-under-wrap",
false,
value,
807static CK_RV get_attribute_private_key(CK_ATTRIBUTE_TYPE type,
814 *length =
sizeof(CK_OBJECT_CLASS);
833 get_label_attribute(
object,
value, length);
846 *length =
sizeof(CK_KEY_TYPE);
853 get_id_attribute(
object,
value, length);
899 get_capability_attribute(
object,
"decrypt-pkcs,decrypt-oaep",
true,
900 value, length, NULL);
910 get_capability_attribute(
object,
"sign-pkcs,sign-pss",
true,
value,
914 get_capability_attribute(
object,
"sign-ecdsa",
true,
value, length,
931 get_capability_attribute(
object,
"exportable-under-wrap",
true,
value,
936 get_capability_attribute(
object,
"exportable-under-wrap",
false,
value,
950 *length =
sizeof(oid_secp224r1);
954 *length =
sizeof(oid_secp256r1);
958 *length =
sizeof(oid_secp384r1);
962 *length =
sizeof(oid_secp521r1);
966 *length =
sizeof(oid_secp256k1);
969 oid = oid_brainpool256r1;
970 *length =
sizeof(oid_brainpool256r1);
973 oid = oid_brainpool384r1;
974 *length =
sizeof(oid_brainpool384r1);
977 oid = oid_brainpool512r1;
978 *length =
sizeof(oid_brainpool512r1);
992 size_t resp_len =
sizeof(resp);
1047 size_t data_len =
sizeof(data) - 1;
1052 EC_KEY *ec_key = NULL;
1053 EC_GROUP *ec_group = NULL;
1054 EC_POINT *ec_point = NULL;
1065 if (rsa == NULL || e == NULL) {
1069 if (BN_hex2bn(&e,
"10001") == 0) {
1073 n = BN_bin2bn(data + 1, data_len, NULL);
1082 if (EVP_PKEY_assign_RSA(key, rsa) == 0) {
1086 ec_key = EC_KEY_new();
1087 if (ec_key == NULL) {
1091 ec_group = EC_GROUP_new_by_curve_name(
algo2nid(algo));
1092 if (ec_group == NULL) {
1098 EC_GROUP_set_asn1_flag(ec_group,
algo2nid(algo));
1100 if (EC_KEY_set_group(ec_key, ec_group) == 0) {
1104 ec_point = EC_POINT_new(ec_group);
1105 if (ec_point == NULL) {
1111 if (EC_POINT_oct2point(ec_group, ec_point, data, data_len, NULL) == 0) {
1115 if (EC_KEY_set_public_key(ec_key, ec_point) == 0) {
1119 if (EVP_PKEY_assign_EC_KEY(key, ec_key) == 0) {
1123 EC_POINT_free(ec_point);
1124 EC_GROUP_free(ec_group);
1130 if (ec_point != NULL) {
1131 EC_POINT_free(ec_point);
1134 if (ec_group != NULL) {
1135 EC_GROUP_free(ec_group);
1138 if (ec_key != NULL) {
1139 EC_KEY_free(ec_key);
1153static CK_RV get_attribute_public_key(CK_ATTRIBUTE_TYPE type,
1160 *length =
sizeof(CK_OBJECT_CLASS);
1192 get_capability_attribute(
object,
"decrypt-pkcs,decrypt-oaep",
true,
1193 value, length, NULL);
1203 get_capability_attribute(
object,
"sign-pkcs,sign-pss",
true,
value,
1207 get_capability_attribute(
object,
"sign-ecdsa",
true,
value, length,
1216 get_label_attribute(
object,
value, length);
1245 *length =
sizeof(CK_KEY_TYPE);
1267 *length =
sizeof(CK_KEY_TYPE);
1274 get_id_attribute(
object,
value, length);
1325 oid = oid_secp224r1;
1326 *length =
sizeof(oid_secp224r1);
1329 oid = oid_secp256r1;
1330 *length =
sizeof(oid_secp256r1);
1333 oid = oid_secp384r1;
1334 *length =
sizeof(oid_secp384r1);
1337 oid = oid_secp521r1;
1338 *length =
sizeof(oid_secp521r1);
1341 oid = oid_secp256k1;
1342 *length =
sizeof(oid_secp256k1);
1345 oid = oid_brainpool256r1;
1346 *length =
sizeof(oid_brainpool256r1);
1349 oid = oid_brainpool384r1;
1350 *length =
sizeof(oid_brainpool384r1);
1353 oid = oid_brainpool512r1;
1354 *length =
sizeof(oid_brainpool512r1);
1365 size_t resplen =
sizeof(resp);
1371 if (resplen + 1 >= 0x80) {
1392 size_t resp_len =
sizeof(resp);
1431 EVP_PKEY *pkey = EVP_PKEY_new();
1438 EVP_PKEY_free(pkey);
1443 *length = i2d_PUBKEY(pkey, (
unsigned char **) &
value);
1444 EVP_PKEY_free(pkey);
1461 if (
value == NULL) {
1464 *length =
sizeof(tmp);
1472 return get_attribute_opaque(type,
object, ptr, length,
session);
1476 return get_attribute_secret_key(type,
object, ptr, length);
1479 return get_attribute_private_key(type,
object, ptr, length,
session);
1481 return get_attribute_public_key(type,
object, ptr, length,
session);
1498 if (
value == NULL) {
1500 *length =
sizeof(tmp);
1508 *length =
sizeof(CK_OBJECT_CLASS);
1513 *length =
sizeof(CK_KEY_TYPE);
1517 CK_OBJECT_HANDLE *
id = ptr;
1519 *length =
sizeof(CK_OBJECT_HANDLE);
1524 *length = strlen(key->label);
1525 memcpy(ptr, key->label, *length);
1559 memcpy(ptr, key->ecdh_key, key->len);
1572 CK_OBJECT_HANDLE objHandle) {
1574 uint8_t type = objHandle >> 16;
1575 uint8_t sequence = objHandle >> 24;
1578 if (objects[i].
object.
id ==
id &&
1579 (objects[i].
object.type & 0x7f) == (type & 0x7f) &&
1580 objects[i].
object.sequence == sequence) {
1589 CK_OBJECT_HANDLE objHandle) {
1593 uint8_t type = objHandle >> 16;
1594 uint8_t sequence = objHandle >> 24;
1597 if (objects[i].
object.
id ==
id &&
1598 (objects[i].
object.type & 0x7f) == (type & 0x7f) &&
1599 objects[i].
object.sequence == sequence) {
1600 object = &objects[i];
1607 struct timeval *low_time = NULL;
1610 if (objects[i].tv.tv_sec == 0) {
1612 low_time = &objects[i].
tv;
1615 if (!low_time || objects[i].tv.tv_sec < low_time->tv_sec ||
1616 (objects[i].
tv.tv_sec == low_time->tv_sec &&
1617 objects[i].
tv.tv_usec < low_time->tv_usec)) {
1619 low_time = &objects[i].
tv;
1624 object = &objects[low];
1636 object->filled =
true;
1641 gettimeofday(&
object->tv, NULL);
1649 CK_MECHANISM_TYPE mechanisms[128];
1681 CK_MECHANISM_TYPE mechanisms[128];
1705 CK_MECHANISM_TYPE mechanisms[128];
1743 CK_MECHANISM_TYPE mechanisms[128];
1765 const EVP_MD *md = NULL;
1812 if (EVP_DigestInit_ex(op_info->
op.
sign.
md_ctx, md, NULL) == 0) {
1823 const EVP_MD *md = NULL;
1904 const EVP_MD *md = NULL;
1934 if (EVP_DigestInit_ex(op_info->
op.
digest.
md_ctx, md, NULL) == 0) {
2151 __attribute((unused))) {
2157 __attribute((unused))) {
2159 op_info->op.decrypt.finalized =
true;
2179static bool apply_DER_encoding_to_ECSIG(
uint8_t *signature,
2181 ECDSA_SIG *sig = ECDSA_SIG_new();
2190 r = BN_bin2bn(signature, *signature_len / 2, NULL);
2191 s = BN_bin2bn(signature + *signature_len / 2, *signature_len / 2, NULL);
2192 if (
r == NULL ||
s == NULL) {
2203 *signature_len = i2d_ECDSA_SIG(sig, &pp);
2205 if (*signature_len == 0) {
2213 ECDSA_SIG_free(sig);
2230 bool verified =
false;
2233 signature_len, op_info->
buffer,
2240 if (verified ==
false) {
2247 EVP_PKEY *key = EVP_PKEY_new();
2248 uint8_t md_data[EVP_MAX_MD_SIZE];
2250 unsigned int md_len =
sizeof(md_data);
2251 EVP_PKEY_CTX *ctx = NULL;
2263 ctx = EVP_PKEY_CTX_new(key, NULL);
2268 if (EVP_PKEY_verify_init(ctx) <= 0) {
2274 unsigned char data[2048];
2276 if (EVP_DigestFinal_ex(op_info->
op.
verify.
md_ctx, md, &md_len) <= 0) {
2280 }
else if (EVP_PKEY_base_id(key) == EVP_PKEY_RSA) {
2281 const EVP_MD *md_type;
2289 if (md_type == EVP_md_null()) {
2295 md = op_info->
buffer + di_len;
2298 }
else if (EVP_PKEY_base_id(key) == EVP_PKEY_EC) {
2303 }
else if (md_len == 32) {
2305 }
else if (md_len == 48) {
2307 }
else if (md_len == 64) {
2317 if (EVP_PKEY_CTX_set_signature_md(ctx, op_info->
op.
verify.
md) <= 0) {
2322 if (EVP_PKEY_CTX_set_rsa_padding(ctx, op_info->
op.
verify.
padding) <= 0) {
2327 if (EVP_PKEY_CTX_set_rsa_pss_saltlen(ctx, op_info->
op.
verify.
saltLen) <=
2332 if (EVP_PKEY_CTX_set_rsa_mgf1_md(ctx, op_info->
op.
verify.
mgf1md) <= 0) {
2339 memcpy(data, signature, signature_len);
2341 if (apply_DER_encoding_to_ECSIG(signature, &signature_len) ==
false) {
2342 DBG_ERR(
"Failed to apply DER encoding to ECDSA signature");
2347 res = EVP_PKEY_verify(ctx, signature, signature_len, md, md_len);
2351 }
else if (res == 0) {
2359 EVP_PKEY_CTX_free(ctx);
2374static bool strip_DER_encoding_from_ECSIG(
uint8_t *signature,
2375 size_t *signature_len,
2379 const unsigned char *pp = (
const unsigned char *) signature;
2383 sig = ECDSA_SIG_new();
2388 if (d2i_ECDSA_SIG(&sig, &pp, *signature_len) == NULL) {
2389 ECDSA_SIG_free(sig);
2395 memset(signature, 0, *signature_len);
2399 r_len = BN_num_bytes(
r);
2400 s_len = BN_num_bytes(
s);
2401 BN_bn2bin(
r, signature + sig_len / 2 - r_len);
2402 BN_bn2bin(
s, signature + sig_len - s_len);
2404 *signature_len = sig_len;
2406 ECDSA_SIG_free(sig);
2414 size_t outlen =
sizeof(op_info->
buffer);
2427 op_info->
buffer, &outlen);
2448 if (strip_DER_encoding_from_ECSIG(op_info->
buffer, &outlen,
2454 if (outlen > *signature_len) {
2458 *signature_len = outlen;
2467 size_t outlen =
sizeof(op_info->
buffer);
2472 op_info->
buffer, &outlen);
2494 if (outlen > *data_len) {
2495 DBG_ERR(
"Data won't fit in buffer %zu > %d", outlen, *data_len);
2509 size_t outlen =
sizeof(op_info->
buffer);
2524 if (outlen > *data_len) {
2740static void free_pkcs11_slot(
void *data) {
2745 DBG_ERR(
"Failed destroying session");
2754static bool compare_slot(
void *data,
void *item) {
2760static bool compare_session(
void *data,
void *item) {
2804 DBG_ERR(
"Session %d doesn't exist", session_id);
2809 int state = (int) (*session)->session_state;
2810 if (session_state == 0 || ((session_state &
state) ==
state)) {
2818 DBG_ERR(
"Session user not logged in");
2824 DBG_ERR(
"Session user already logged in");
2856static CK_RV native_create_mutex(
void **mutex) {
2859 CRITICAL_SECTION *mtx = calloc(1,
sizeof(CRITICAL_SECTION));
2863 InitializeCriticalSection(mtx);
2865 pthread_mutex_t *mtx = calloc(1,
sizeof(pthread_mutex_t));
2870 pthread_mutex_init(mtx, NULL);
2877static CK_RV native_destroy_mutex(
void *mutex) {
2880 DeleteCriticalSection(mutex);
2882 pthread_mutex_destroy(mutex);
2890static CK_RV native_lock_mutex(
void *mutex) {
2893 EnterCriticalSection(mutex);
2895 if (pthread_mutex_lock(mutex) != 0) {
2903static CK_RV native_unlock_mutex(
void *mutex) {
2906 LeaveCriticalSection(mutex);
2908 if (pthread_mutex_unlock(mutex) != 0) {
2930 for (
int i = 0; i < n_connectors; i++) {
2966static CK_RV check_bool_attribute(
void *
value,
bool check) {
2968 if (check ==
true && b_val ==
CK_TRUE) {
2970 }
else if (check ==
false && b_val ==
CK_FALSE) {
2991 template->obj.rsa.p++;
2993 if (primelen == 0 || primelen ==
pTemplate[i].ulValueLen) {
3008 template->obj.rsa.q++;
3010 if (primelen == 0 || primelen ==
pTemplate[i].ulValueLen) {
3024 memcmp(e,
"\x01\x00\x01", 3) != 0) {
3072 template->objlen = primelen;
3095 EC_GROUP *group = EC_GROUP_new(EC_GFp_simple_method());
3096 const uint8_t *param_ptr = ecparams;
3098 if (group == NULL) {
3101 if (d2i_ECPKParameters(&group, ¶m_ptr, ecparams_len) != NULL) {
3102 curve = EC_GROUP_get_curve_name(group);
3104 EC_GROUP_free(group);
3110 case NID_X9_62_prime256v1:
3126#ifdef NID_brainpoolP256r1
3127 case NID_brainpoolP256r1:
3132#ifdef NID_brainpoolP384r1
3133 case NID_brainpoolP384r1:
3138#ifdef NID_brainpoolP512r1
3139 case NID_brainpoolP512r1:
3163 template->objlen =
pTemplate[i].ulValueLen;
3170 if (ecparams == NULL) {
3242 template->objlen =
pTemplate[i].ulValueLen;
3312 bool label_set =
FALSE;
3321 DBG_ERR(
"CKA_CLASS inconsistent in PublicKeyTemplate");
3328 DBG_ERR(
"CKA_KEY_TYPE inconsistent in PublicKeyTemplate");
3338 DBG_ERR(
"CKA_ID invalid in PublicKeyTemplate");
3343 DBG_ERR(
"CKA_ID inconsistent in PublicKeyTemplate");
3352 memcmp(e,
"\x01\x00\x01", 3) == 0) ||
3354 memcmp(e,
"\x00\x01\x00\x01", 4) == 0))) {
3355 DBG_ERR(
"CKA_PUBLIC_EXPONENT invalid in PublicKeyTemplate");
3359 DBG_ERR(
"CKA_PUBLIC_EXPONENT inconsistent in PublicKeyTemplate");
3379 DBG_ERR(
"CKA_MODULUS_BITS wrong length in PublicKeyTemplate (%lu)",
3387 DBG_ERR(
"CKA_LABEL invalid in PublicKeyTemplate");
3401 DBG_ERR(
"Boolean truth check failed for attribute 0x%lx",
3413 DBG_ERR(
"Boolean false check failed for attribute 0x%lx",
3429 DBG_ERR(
"invalid attribute type in PublicKeyTemplate: 0x%lx",
3440 DBG_ERR(
"CKA_CLASS inconsistent in PrivateKeyTemplate");
3447 DBG_ERR(
"CKA_KEY_TYPE inconsistent in PrivateKeyTemplate");
3456 DBG_ERR(
"CKA_ID invalid in PrivateKeyTemplate");
3460 DBG_ERR(
"CKA_ID inconsistent in PrivateKeyTemplate");
3471 DBG_ERR(
"CKA_DECRYPT inconsistent in PrivateKeyTemplate");
3480 DBG_ERR(
"CKA_SIGN inconsistent in PrivateKeyTemplate");
3489 DBG_ERR(
"CKA_EXTRACTABLE inconsistent in PrivateKeyTemplate");
3496 DBG_ERR(
"CKA_LABEL invalid in PrivateKeyTemplate");
3500 if (label_set ==
TRUE) {
3503 DBG_ERR(
"CKA_LABEL inconsistent in PrivateKeyTemplate");
3518 DBG_ERR(
"Boolean truth check failed for attribute 0x%lx",
3531 DBG_ERR(
"Boolean false check failed for attribute 0x%lx",
3542 DBG_ERR(
"invalid attribute type in PrivateKeyTemplate: 0x%lx",
3549 DBG_ERR(
"No RSA bitlength set");
3565 DBG_INFO(
"Supplied id is long, truncating it (was %lu bytes)",
len);
3578 bool label_set =
FALSE;
3587 DBG_ERR(
"CKA_CLASS inconsistent in PublicKeyTemplate");
3594 DBG_ERR(
"CKA_KEY_TYPE inconsistent in PublicKeyTemplate");
3604 DBG_ERR(
"CKA_ID invalid in PublicKeyTemplate");
3609 DBG_ERR(
"CKA_ID inconsistent in PublicKeyTemplate");
3615 if (ecparams == NULL) {
3619 DBG_ERR(
"CKA_PUBLIC_EXPONENT inconsistent in PublicKeyTemplate");
3626 DBG_ERR(
"CKA_LABEL invalid in PublicKeyTemplate");
3640 DBG_ERR(
"Boolean truth check failed for attribute 0x%lx",
3653 DBG_ERR(
"Boolean false check failed for attribute 0x%lx",
3668 DBG_ERR(
"invalid attribute type in PublicKeyTemplate: 0x%lx\n",
3679 DBG_ERR(
"CKA_CLASS inconsistent in PrivateKeyTemplate");
3686 DBG_ERR(
"CKA_KEY_TYPE inconsistent in PrivateKeyTemplate");
3695 DBG_ERR(
"CKA_ID invalid in PrivateKeyTemplate");
3699 DBG_ERR(
"CKA_ID inconsistent in PrivateKeyTemplate");
3710 DBG_ERR(
"CKA_SIGN inconsistent in PrivateKeyTemplate");
3719 DBG_ERR(
"CKA_EXTRACTABLE inconsistent in PrivateKeyTemplate");
3728 DBG_ERR(
"CKA_DERIVE inconsistent in PrivateKeyTemplate");
3735 DBG_ERR(
"CKA_LABEL invalid in PrivateKeyTemplate");
3739 if (label_set ==
TRUE) {
3742 DBG_ERR(
"CKA_LABEL inconsistent in PrivateKeyTemplate");
3757 DBG_ERR(
"Boolean truth check failed for attribute 0x%lx",
3771 DBG_ERR(
"Boolean false check failed for attribute 0x%lx",
3786 if (ecparams == NULL) {
3787 DBG_ERR(
"CKA_ECPARAMS not set");
3794 DBG_ERR(
"Failed to parse CKA_ECPARAMS");
3813 template->objlen =
pTemplate[i].ulValueLen;
3903 if (attribute_rc !=
CKR_OK) {
3906 DBG_ERR(
"Unable to get attribute");
3908 DBG_ERR(
"Skipping attribute because buffer is too small");
3913 DBG_INFO(
"Attribute/length successfully returned with length %lu",
3944 DBG_ERR(
"Derived key can only be a session object");
3951 DBG_ERR(
"Derived key class is unsupported");
3958 DBG_ERR(
"Derived key type is unsupported");
3965 DBG_ERR(
"The derived key will be extractable");
3971 DBG_WARN(
"ECDH key derive template contains the ignored attribute: %lx",
CK_SESSION_HANDLE session
const char * yh_strerror(yh_rc err)
bool list_append(List *list, void *item)
void list_delete(List *list, ListItem *item)
ListItem * list_get(List *list, void *data, CompareItemFn compare_item_fn)
void list_create(List *list, int item_size, FreeItemFn free_item_fn)
void list_destroy(List *list)
fc::array< char, 72 > signature
const T & min(const T &a, const T &b)
void ECDSA_SIG_get0(const ECDSA_SIG *sig, const BIGNUM **pr, const BIGNUM **ps)
int RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d)
int ECDSA_SIG_set0(ECDSA_SIG *sig, BIGNUM *r, BIGNUM *s)
#define CKA_NEVER_EXTRACTABLE
#define CKR_GENERAL_ERROR
#define CKR_MECHANISM_INVALID
#define CKR_ATTRIBUTE_TYPE_INVALID
#define CKF_EC_UNCOMPRESS
#define CKR_ATTRIBUTE_SENSITIVE
#define CKA_PRIVATE_EXPONENT
ck_session_handle_t * CK_SESSION_HANDLE_PTR
ck_mechanism_type_t * CK_MECHANISM_TYPE_PTR
unsigned long int CK_ULONG
#define CKA_PUBLIC_EXPONENT
#define CKM_RSA_PKCS_KEY_PAIR_GEN
#define CKR_SESSION_READ_ONLY
#define CKR_SIGNATURE_INVALID
#define CKR_SESSION_HANDLE_INVALID
#define CKA_PUBLIC_KEY_INFO
#define CKF_GENERATE_KEY_PAIR
#define CKM_SHA512_RSA_PKCS_PSS
#define CKM_RSA_PKCS_OAEP
#define CKM_SHA512_RSA_PKCS
#define CK_UNAVAILABLE_INFORMATION
#define CKF_EC_ECPARAMETERS
#define CKM_GENERIC_SECRET_KEY_GEN
#define CKR_FUNCTION_FAILED
#define CKM_EC_KEY_PAIR_GEN
#define CKR_TEMPLATE_INCONSISTENT
#define CKR_DATA_LEN_RANGE
#define CKM_SHA1_RSA_PKCS
#define CKA_WRAP_WITH_TRUSTED
#define CKR_BUFFER_TOO_SMALL
#define CKA_ALWAYS_AUTHENTICATE
#define CKR_USER_ALREADY_LOGGED_IN
#define CKK_GENERIC_SECRET
#define CKR_ATTRIBUTE_VALUE_INVALID
#define CKK_VENDOR_DEFINED
#define CKR_USER_NOT_LOGGED_IN
#define CKA_ALWAYS_SENSITIVE
#define CKA_CERTIFICATE_TYPE
#define CKR_TEMPLATE_INCOMPLETE
#define CKM_SHA256_RSA_PKCS_PSS
#define CKM_SHA1_RSA_PKCS_PSS
#define CKM_SHA384_RSA_PKCS
#define CKA_UNWRAP_TEMPLATE
#define CKR_CURVE_NOT_SUPPORTED
#define CKM_SHA256_RSA_PKCS
#define CKM_SHA384_RSA_PKCS_PSS
#define CKA_WRAP_TEMPLATE
CK_UTF8CHAR * CK_UTF8CHAR_PTR
#define CKK_YUBICO_AES192_CCM_WRAP
#define CKK_YUBICO_AES128_CCM_WRAP
#define CKM_YUBICO_AES_CCM_WRAP
#define CKK_YUBICO_AES256_CCM_WRAP
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
ck_mechanism_type_t mechanism
struct mechanism::@110::@112 oaep
struct mechanism::@110::@113 pss
CK_MECHANISM_TYPE mechanism
yh_algorithm algorithm
Object algorithm.
yh_capabilities capabilities
Object capabilities.
uint8_t origin
Object origin.
char label[YH_OBJ_LABEL_LEN+1]
Object label.
yh_object_type type
Object type.
CK_UNLOCKMUTEX unlock_mutex
CK_DESTROYMUTEX destroy_mutex
CK_CREATEMUTEX create_mutex
yh_object_descriptor object
yubihsm_pkcs11_attribute sign
yubihsm_pkcs11_attribute decrypt
yubihsm_pkcs11_attribute wrap
char label[YH_OBJ_LABEL_LEN+1]
yubihsm_pkcs11_attribute exportable
yubihsm_pkcs11_attribute derive
struct yubihsm_pkcs11_object_template::@114::@115 rsa
yubihsm_pkcs11_attribute verify
yubihsm_pkcs11_attribute encrypt
union yubihsm_pkcs11_object_template::@114 obj
yubihsm_pkcs11_attribute unwrap
unsigned int buffer_length
uint8_t buffer[YUBIHSM_PKCS11_OP_BUFSIZE]
yh_session * device_session
yh_algorithm algorithms[YH_MAX_ALGORITHM_COUNT]
int algo2nid(yh_algorithm algo)
void parse_NID(uint8_t *data, uint16_t data_len, const EVP_MD **md_type, int *digestinfo_len)
bool is_PKCS1v1_5_sign_mechanism(CK_MECHANISM_TYPE m)
bool is_ECDSA_sign_mechanism(CK_MECHANISM_TYPE m)
CK_RV set_template_attribute(yubihsm_pkcs11_attribute *attribute, void *value)
CK_RV get_mechanism_list(yubihsm_pkcs11_slot *slot, CK_MECHANISM_TYPE_PTR pMechanismList, CK_ULONG_PTR count)
bool add_connectors(yubihsm_pkcs11_context *ctx, int n_connectors, char **connector_names, yh_connector **connectors)
CK_RV apply_verify_mechanism_finalize(yubihsm_pkcs11_op_info *op_info __attribute((unused)))
bool decrypt_mechanism_cleanup(yubihsm_pkcs11_op_info *op_info)
bool verify_mechanism_cleanup(yubihsm_pkcs11_op_info *op_info)
CK_RV populate_template(int type, void *object, CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulCount, yh_session *session)
bool check_encrypt_mechanism(yubihsm_pkcs11_slot *slot, CK_MECHANISM_PTR pMechanism)
CK_RV parse_ec_generate_template(CK_ATTRIBUTE_PTR pPublicKeyTemplate, CK_ULONG ulPublicKeyAttributeCount, CK_ATTRIBUTE_PTR pPrivateKeyTemplate, CK_ULONG ulPrivateKeyAttributeCount, yubihsm_pkcs11_object_template *template)
CK_RV apply_verify_mechanism_init(yubihsm_pkcs11_op_info *op_info)
CK_RV perform_digest(yubihsm_pkcs11_op_info *op_info, uint8_t *digest, uint16_t *digest_len)
bool is_PSS_sign_mechanism(CK_MECHANISM_TYPE m)
void release_slot(yubihsm_pkcs11_context *ctx, yubihsm_pkcs11_slot *slot)
CK_RV apply_decrypt_mechanism_finalize(yubihsm_pkcs11_op_info *op_info __attribute((unused)))
CK_RV parse_rsa_generate_template(CK_ATTRIBUTE_PTR pPublicKeyTemplate, CK_ULONG ulPublicKeyAttributeCount, CK_ATTRIBUTE_PTR pPrivateKeyTemplate, CK_ULONG ulPrivateKeyAttributeCount, yubihsm_pkcs11_object_template *template)
bool is_HMAC_sign_mechanism(CK_MECHANISM_TYPE m)
bool is_hashed_mechanism(CK_MECHANISM_TYPE m)
CK_RV get_session(yubihsm_pkcs11_context *ctx, CK_SESSION_HANDLE hSession, yubihsm_pkcs11_session **session, int session_state)
bool parse_hex(CK_UTF8CHAR_PTR hex, CK_ULONG hex_len, uint8_t *parsed)
CK_RV apply_digest_mechanism_init(yubihsm_pkcs11_op_info *op_info)
CK_RV perform_signature(yh_session *session, yubihsm_pkcs11_op_info *op_info, uint8_t *signature, uint16_t *signature_len)
CK_RV validate_derive_key_attribute(CK_ATTRIBUTE_TYPE type, void *value)
CK_RV apply_encrypt_mechanism_update(yubihsm_pkcs11_op_info *op_info, CK_BYTE_PTR in, CK_ULONG in_len)
CK_RV get_attribute_ecsession_key(CK_ATTRIBUTE_TYPE type, ecdh_session_key *key, CK_VOID_PTR value, CK_ULONG_PTR length)
bool check_decrypt_mechanism(yubihsm_pkcs11_slot *slot, CK_MECHANISM_PTR pMechanism)
bool check_digest_mechanism(CK_MECHANISM_PTR pMechanism)
CK_RV parse_wrap_template(CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulCount, yubihsm_pkcs11_object_template *template, bool generate)
int parse_id_value(void *value, CK_ULONG len)
CK_RV parse_ec_template(CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulCount, yubihsm_pkcs11_object_template *template)
bool sign_mechanism_cleanup(yubihsm_pkcs11_op_info *op_info)
bool create_session(yubihsm_pkcs11_slot *slot, CK_FLAGS flags, CK_SESSION_HANDLE_PTR phSession)
CK_RV apply_sign_mechanism_finalize(yubihsm_pkcs11_op_info *op_info)
yubihsm_pkcs11_slot * get_slot(yubihsm_pkcs11_context *ctx, CK_ULONG id)
CK_RV parse_hmac_template(CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulCount, yubihsm_pkcs11_object_template *template, bool generate)
bool is_RSA_sign_mechanism(CK_MECHANISM_TYPE m)
CK_RV apply_sign_mechanism_update(yubihsm_pkcs11_op_info *op_info, CK_BYTE_PTR in, CK_ULONG in_len)
void set_native_locking(yubihsm_pkcs11_context *ctx)
CK_RV apply_decrypt_mechanism_update(yubihsm_pkcs11_op_info *op_info, CK_BYTE_PTR in, CK_ULONG in_len)
bool check_wrap_mechanism(yubihsm_pkcs11_slot *slot, CK_MECHANISM_PTR pMechanism)
yubihsm_pkcs11_object_desc * get_object_desc(yh_session *session, yubihsm_pkcs11_object_desc *objects, CK_OBJECT_HANDLE objHandle)
bool delete_session(yubihsm_pkcs11_context *ctx, CK_SESSION_HANDLE_PTR phSession)
CK_RV apply_digest_mechanism_update(yubihsm_pkcs11_op_info *op_info, CK_BYTE_PTR in, CK_ULONG in_len)
bool check_verify_mechanism(yubihsm_pkcs11_slot *slot, CK_MECHANISM_PTR pMechanism)
CK_RV perform_decrypt(yh_session *session, yubihsm_pkcs11_op_info *op_info, uint8_t *data, uint16_t *data_len)
bool is_RSA_decrypt_mechanism(CK_MECHANISM_TYPE m)
CK_RV apply_decrypt_mechanism_init(yubihsm_pkcs11_op_info *op_info)
CK_RV apply_digest_mechanism_finalize(yubihsm_pkcs11_op_info *op_info)
bool get_mechanism_info(yubihsm_pkcs11_slot *slot, CK_MECHANISM_TYPE type, CK_MECHANISM_INFO_PTR pInfo)
void release_session(yubihsm_pkcs11_context *ctx, yubihsm_pkcs11_session *session)
CK_RV perform_verify(yh_session *session, yubihsm_pkcs11_op_info *op_info, uint8_t *signature, uint16_t signature_len)
CK_RV parse_rsa_template(CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulCount, yubihsm_pkcs11_object_template *template)
void delete_object_from_cache(yubihsm_pkcs11_object_desc *objects, CK_OBJECT_HANDLE objHandle)
CK_ULONG get_digest_bytelength(CK_MECHANISM_TYPE m)
CK_RV get_attribute(CK_ATTRIBUTE_TYPE type, yh_object_descriptor *object, CK_VOID_PTR value, CK_ULONG_PTR length, yh_session *session)
CK_RV apply_sign_mechanism_init(yubihsm_pkcs11_op_info *op_info)
bool digest_mechanism_cleanup(yubihsm_pkcs11_op_info *op_info)
CK_RV apply_verify_mechanism_update(yubihsm_pkcs11_op_info *op_info, CK_BYTE_PTR in, CK_ULONG in_len)
bool check_sign_mechanism(yubihsm_pkcs11_slot *slot, CK_MECHANISM_PTR pMechanism)
CK_RV perform_encrypt(yh_session *session, yubihsm_pkcs11_op_info *op_info, uint8_t *data, uint16_t *data_len)
bool yh_is_rsa(yh_algorithm algorithm)
yh_rc yh_destroy_session(yh_session **session)
bool yh_is_ec(yh_algorithm algorithm)
yh_rc yh_util_sign_ecdsa(yh_session *session, uint16_t key_id, const uint8_t *in, size_t in_len, uint8_t *out, size_t *out_len)
yh_rc yh_util_unwrap_data(yh_session *session, uint16_t key_id, const uint8_t *in, size_t in_len, uint8_t *out, size_t *out_len)
yh_rc yh_util_get_opaque(yh_session *session, uint16_t object_id, uint8_t *out, size_t *out_len)
yh_rc yh_util_decrypt_pkcs1v1_5(yh_session *session, uint16_t key_id, const uint8_t *in, size_t in_len, uint8_t *out, size_t *out_len)
yh_rc yh_util_get_device_info(yh_connector *connector, uint8_t *major, uint8_t *minor, uint8_t *patch, uint32_t *serial, uint8_t *log_total, uint8_t *log_used, yh_algorithm *algorithms, size_t *n_algorithms)
yh_rc yh_util_get_object_info(yh_session *session, uint16_t id, yh_object_type type, yh_object_descriptor *object)
yh_rc yh_util_wrap_data(yh_session *session, uint16_t key_id, const uint8_t *in, size_t in_len, uint8_t *out, size_t *out_len)
yh_rc yh_util_sign_hmac(yh_session *session, uint16_t key_id, const uint8_t *in, size_t in_len, uint8_t *out, size_t *out_len)
yh_rc yh_util_sign_pss(yh_session *session, uint16_t key_id, const uint8_t *in, size_t in_len, uint8_t *out, size_t *out_len, size_t salt_len, yh_algorithm mgf1Algo)
yh_rc yh_util_sign_pkcs1v1_5(yh_session *session, uint16_t key_id, bool hashed, const uint8_t *in, size_t in_len, uint8_t *out, size_t *out_len)
yh_rc yh_util_get_public_key(yh_session *session, uint16_t id, uint8_t *data, size_t *data_len, yh_algorithm *algorithm)
yh_rc yh_util_decrypt_oaep(yh_session *session, uint16_t key_id, const uint8_t *in, size_t in_len, uint8_t *out, size_t *out_len, const uint8_t *label, size_t label_len, yh_algorithm mgf1Algo)
yh_rc yh_disconnect(yh_connector *connector)
yh_rc yh_util_verify_hmac(yh_session *session, uint16_t key_id, const uint8_t *signature, size_t signature_len, const uint8_t *data, size_t data_len, bool *verified)
bool yh_check_capability(const yh_capabilities *capabilities, const char *capability)
#define YH_ORIGIN_GENERATED
The object was generated on the device.
@ YH_OTP_AEAD_KEY
OTP AEAD Key is a secret key used to decrypt Yubico OTP values.
@ YH_HMAC_KEY
HMAC Key is a secret key used when computing and verifying HMAC signatures.
@ YH_ASYMMETRIC_KEY
Asymmetric Key is the private key of an asymmetric key-pair.
@ YH_AUTHENTICATION_KEY
Authentication Key is used to establish Sessions with a device.
#define YH_MAX_ITEMS_COUNT
Max items the device may hold.
#define YH_OBJ_LABEL_LEN
Max length of object labels.
@ YH_ALGO_RSA_PSS_SHA384
rsa-pss-sha384
@ YH_ALGO_RSA_PKCS1_SHA256
rsa-pkcs1-sha256
@ YH_ALGO_RSA_PKCS1_SHA1
rsa-pkcs1-sha1
@ YH_ALGO_RSA_PSS_SHA512
rsa-pss-sha512
@ YH_ALGO_EC_BP384
ecbp384
@ YH_ALGO_RSA_PSS_SHA1
rsa-pss-sha1
@ YH_ALGO_EC_ECDSA_SHA256
ecdsa-sha256
@ YH_ALGO_EC_ECDSA_SHA512
ecdsa-sha512
@ YH_ALGO_RSA_OAEP_SHA256
rsa-oaep-sha256
@ YH_ALGO_OPAQUE_X509_CERTIFICATE
opaque-x509-certificate
@ YH_ALGO_EC_ECDSA_SHA384
ecdsa-sha384
@ YH_ALGO_HMAC_SHA512
hmac-sha512
@ YH_ALGO_HMAC_SHA384
hmac-sha384
@ YH_ALGO_RSA_PKCS1_SHA512
rsa-pkcs1-sha512
@ YH_ALGO_AES256_CCM_WRAP
aes256-ccm-wrap
@ YH_ALGO_HMAC_SHA1
hmac-sha1
@ YH_ALGO_RSA_OAEP_SHA512
rsa-oaep-sha512
@ YH_ALGO_RSA_2048
rsa2048
@ YH_ALGO_HMAC_SHA256
hmac-sha256
@ YH_ALGO_RSA_OAEP_SHA384
rsa-oaep-sha384
@ YH_ALGO_AES192_CCM_WRAP
aes192-ccm-wrap
@ YH_ALGO_EC_BP512
ecbp512
@ YH_ALGO_EC_BP256
ecbp256
@ YH_ALGO_RSA_PSS_SHA256
rsa-pss-sha256
@ YH_ALGO_AES128_CCM_WRAP
aes128-ccm-wrap
@ YH_ALGO_RSA_4096
rsa4096
@ YH_ALGO_EC_ECDSA_SHA1
ecdsa-sha1
@ YH_ALGO_RSA_OAEP_SHA1
rsa-oaep-sha1
@ YH_ALGO_RSA_PKCS1_SHA384
rsa-pkcs1-sha384
@ YH_ALGO_RSA_3072
rsa3072
@ YHR_SUCCESS
Returned value when function was successful.
yubihsm_pkcs11_slot * slot
CK_SLOT_ID CK_SLOT_INFO_PTR pInfo
CK_SESSION_HANDLE CK_MECHANISM_PTR CK_ATTRIBUTE_PTR CK_ULONG CK_ATTRIBUTE_PTR CK_ULONG ulPrivateKeyAttributeCount
CK_SESSION_HANDLE hSession
CK_SESSION_HANDLE CK_ATTRIBUTE_PTR CK_ULONG ulCount
CK_SLOT_ID CK_FLAGS CK_VOID_PTR CK_NOTIFY CK_SESSION_HANDLE_PTR phSession
yubihsm_pkcs11_object_template template
CK_SLOT_ID CK_MECHANISM_TYPE_PTR pMechanismList
yh_object_descriptor object
session operation op sign key_len
CK_SESSION_HANDLE CK_MECHANISM_PTR CK_ATTRIBUTE_PTR CK_ULONG CK_ATTRIBUTE_PTR pPrivateKeyTemplate
CK_SESSION_HANDLE CK_ATTRIBUTE_PTR pTemplate
CK_SESSION_HANDLE CK_MECHANISM_PTR CK_ATTRIBUTE_PTR CK_ULONG ulPublicKeyAttributeCount
session operation op digest digest_len
CK_SESSION_HANDLE CK_MECHANISM_PTR pMechanism
memset(pInfo->slotDescription, ' ', 64)
CK_SESSION_HANDLE CK_MECHANISM_PTR CK_ATTRIBUTE_PTR pPublicKeyTemplate
memcpy((char *) pInfo->slotDescription, s, l)
@ SESSION_AUTHENTICATED_RW
@ SESSION_AUTHENTICATED_RO
#define SESSION_NOT_AUTHENTICATED
#define SESSION_AUTHENTICATED