4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 * Copyright 2012 Milan Jurik. All rights reserved.
29 #include <security/cryptoki.h>
30 #include <sys/crypto/common.h>
33 #include <blowfish_impl.h>
37 #include "softGlobal.h"
38 #include "softObject.h"
39 #include "softSession.h"
40 #include "softKeystore.h"
41 #include "softKeystoreUtil.h"
42 #include "softCrypt.h"
46 * This attribute table is used by the soft_lookup_attr()
47 * to validate the attributes.
49 CK_ATTRIBUTE_TYPE attr_map
[] = {
79 CKA_NEVER_EXTRACTABLE
,
93 * attributes that exists only in public key objects
94 * Note: some attributes may also exist in one or two
95 * other object classes, but they are also listed
96 * because not all object have them.
98 CK_ATTRIBUTE_TYPE PUB_KEY_ATTRS
[] =
118 * attributes that exists only in private key objects
119 * Note: some attributes may also exist in one or two
120 * other object classes, but they are also listed
121 * because not all object have them.
123 CK_ATTRIBUTE_TYPE PRIV_KEY_ATTRS
[] =
131 CKA_PRIVATE_EXPONENT
,
144 CKA_NEVER_EXTRACTABLE
,
145 CKA_ALWAYS_SENSITIVE
,
150 * attributes that exists only in secret key objects
151 * Note: some attributes may also exist in one or two
152 * other object classes, but they are also listed
153 * because not all object have them.
155 CK_ATTRIBUTE_TYPE SECRET_KEY_ATTRS
[] =
166 CKA_NEVER_EXTRACTABLE
,
171 * attributes that exists only in domain parameter objects
172 * Note: some attributes may also exist in one or two
173 * other object classes, but they are also listed
174 * because not all object have them.
176 CK_ATTRIBUTE_TYPE DOMAIN_ATTRS
[] =
187 * attributes that exists only in hardware feature objects
190 CK_ATTRIBUTE_TYPE HARDWARE_ATTRS
[] =
198 * attributes that exists only in certificate objects
200 CK_ATTRIBUTE_TYPE CERT_ATTRS
[] =
202 CKA_CERTIFICATE_TYPE
,
215 * Validate the attribute by using binary search algorithm.
218 soft_lookup_attr(CK_ATTRIBUTE_TYPE type
)
221 size_t lower
, middle
, upper
;
224 upper
= (sizeof (attr_map
) / sizeof (CK_ATTRIBUTE_TYPE
)) - 1;
226 while (lower
<= upper
) {
227 /* Always starts from middle. */
228 middle
= (lower
+ upper
) / 2;
230 if (type
> attr_map
[middle
]) {
231 /* Adjust the lower bound to upper half. */
236 if (type
== attr_map
[middle
]) {
241 if (type
< attr_map
[middle
]) {
242 /* Adjust the upper bound to lower half. */
248 /* Failed to find the matching attribute from the attribute table. */
249 return (CKR_ATTRIBUTE_TYPE_INVALID
);
254 * Validate the attribute by using the following search algorithm:
256 * 1) Search for the most frequently used attributes first.
257 * 2) If not found, search for the usage-purpose attributes - these
258 * attributes have dense set of values, therefore compiler will
259 * optimize it with a branch table and branch to the appropriate
261 * 3) If still not found, use binary search for the rest of the
262 * attributes in the attr_map[] table.
265 soft_validate_attr(CK_ATTRIBUTE_PTR
template, CK_ULONG ulAttrNum
,
266 CK_OBJECT_CLASS
*class)
272 for (i
= 0; i
< ulAttrNum
; i
++) {
273 /* First tier search */
274 switch (template[i
].type
) {
276 *class = *((CK_OBJECT_CLASS
*)template[i
].pValue
);
289 /* Second tier search */
290 switch (template[i
].type
) {
301 case CKA_SIGN_RECOVER
:
305 case CKA_VERIFY_RECOVER
:
310 /* Third tier search */
311 rv
= soft_lookup_attr(template[i
].type
);
323 cleanup_cert_attr(cert_attr_t
*attr
)
327 (void) memset(attr
->value
, 0, attr
->length
);
336 copy_cert_attr(cert_attr_t
*src_attr
, cert_attr_t
**dest_attr
)
340 if (src_attr
== NULL
|| dest_attr
== NULL
)
341 return (CKR_HOST_MEMORY
);
343 if (src_attr
->value
== NULL
)
344 return (CKR_HOST_MEMORY
);
346 /* free memory if its already allocated */
347 if (*dest_attr
!= NULL
) {
348 if ((*dest_attr
)->value
!= (CK_BYTE
*)NULL
)
349 free((*dest_attr
)->value
);
351 *dest_attr
= malloc(sizeof (cert_attr_t
));
352 if (*dest_attr
== NULL
)
353 return (CKR_HOST_MEMORY
);
356 (*dest_attr
)->value
= NULL
;
357 (*dest_attr
)->length
= 0;
359 if (src_attr
->length
) {
360 (*dest_attr
)->value
= malloc(src_attr
->length
);
361 if ((*dest_attr
)->value
== NULL
) {
363 return (CKR_HOST_MEMORY
);
366 (void) memcpy((*dest_attr
)->value
, src_attr
->value
,
368 (*dest_attr
)->length
= src_attr
->length
;
375 soft_cleanup_cert_object(soft_object_t
*object_p
)
377 CK_CERTIFICATE_TYPE certtype
= object_p
->cert_type
;
379 if (object_p
->class != CKO_CERTIFICATE
||
380 OBJ_CERT(object_p
) == NULL
)
383 if (certtype
== CKC_X_509
) {
384 if (X509_CERT_SUBJECT(object_p
) != NULL
) {
385 cleanup_cert_attr(X509_CERT_SUBJECT(object_p
));
386 free(X509_CERT_SUBJECT(object_p
));
387 X509_CERT_SUBJECT(object_p
) = NULL
;
389 if (X509_CERT_VALUE(object_p
) != NULL
) {
390 cleanup_cert_attr(X509_CERT_VALUE(object_p
));
391 free(X509_CERT_VALUE(object_p
));
392 X509_CERT_VALUE(object_p
) = NULL
;
394 free(OBJ_CERT(object_p
));
395 } else if (certtype
== CKC_X_509_ATTR_CERT
) {
396 if (X509_ATTR_CERT_VALUE(object_p
) != NULL
) {
397 cleanup_cert_attr(X509_ATTR_CERT_VALUE(object_p
));
398 free(X509_ATTR_CERT_VALUE(object_p
));
399 X509_ATTR_CERT_VALUE(object_p
) = NULL
;
401 if (X509_ATTR_CERT_OWNER(object_p
) != NULL
) {
402 cleanup_cert_attr(X509_ATTR_CERT_OWNER(object_p
));
403 free(X509_ATTR_CERT_OWNER(object_p
));
404 X509_ATTR_CERT_OWNER(object_p
) = NULL
;
406 free(OBJ_CERT(object_p
));
411 * Clean up and release all the storage in the extra attribute list
415 soft_cleanup_extra_attr(soft_object_t
*object_p
)
418 CK_ATTRIBUTE_INFO_PTR extra_attr
;
419 CK_ATTRIBUTE_INFO_PTR tmp
;
421 extra_attr
= object_p
->extra_attrlistp
;
423 tmp
= extra_attr
->next
;
424 free(extra_attr
->attr
.pValue
);
426 /* Free the storage for the attribute_info struct. */
431 object_p
->extra_attrlistp
= NULL
;
436 * Create the attribute_info struct to hold the object's attribute,
437 * and add it to the extra attribute list of an object.
440 soft_add_extra_attr(CK_ATTRIBUTE_PTR
template, soft_object_t
*object_p
)
443 CK_ATTRIBUTE_INFO_PTR attrp
;
445 /* Allocate the storage for the attribute_info struct. */
446 attrp
= calloc(1, sizeof (attribute_info_t
));
448 return (CKR_HOST_MEMORY
);
451 /* Set up attribute_info struct. */
452 attrp
->attr
.type
= template->type
;
453 attrp
->attr
.ulValueLen
= template->ulValueLen
;
455 if ((template->pValue
!= NULL
) &&
456 (template->ulValueLen
> 0)) {
457 /* Allocate storage for the value of the attribute. */
458 attrp
->attr
.pValue
= malloc(template->ulValueLen
);
459 if (attrp
->attr
.pValue
== NULL
) {
461 return (CKR_HOST_MEMORY
);
464 (void) memcpy(attrp
->attr
.pValue
, template->pValue
,
465 template->ulValueLen
);
467 attrp
->attr
.pValue
= NULL
;
470 /* Insert the new attribute in front of extra attribute list. */
471 if (object_p
->extra_attrlistp
== NULL
) {
472 object_p
->extra_attrlistp
= attrp
;
475 attrp
->next
= object_p
->extra_attrlistp
;
476 object_p
->extra_attrlistp
= attrp
;
483 soft_copy_certificate(certificate_obj_t
*oldcert
, certificate_obj_t
**newcert
,
484 CK_CERTIFICATE_TYPE type
)
487 certificate_obj_t
*cert
;
489 x509_attr_cert_t x509_attr
;
491 cert
= calloc(1, sizeof (certificate_obj_t
));
493 return (CKR_HOST_MEMORY
);
496 if (type
== CKC_X_509
) {
497 x509
= oldcert
->cert_type_u
.x509
;
499 if ((rv
= copy_cert_attr(x509
.subject
,
500 &cert
->cert_type_u
.x509
.subject
)))
503 if ((rv
= copy_cert_attr(x509
.value
,
504 &cert
->cert_type_u
.x509
.value
)))
506 } else if (type
== CKC_X_509_ATTR_CERT
) {
507 x509_attr
= oldcert
->cert_type_u
.x509_attr
;
509 if ((rv
= copy_cert_attr(x509_attr
.owner
,
510 &cert
->cert_type_u
.x509_attr
.owner
)))
513 if ((rv
= copy_cert_attr(x509_attr
.value
,
514 &cert
->cert_type_u
.x509_attr
.value
)))
517 /* wrong certificate type */
518 rv
= CKR_ATTRIBUTE_TYPE_INVALID
;
526 * Copy the attribute_info struct from the old object to a new attribute_info
527 * struct, and add that new struct to the extra attribute list of the new
531 soft_copy_extra_attr(CK_ATTRIBUTE_INFO_PTR old_attrp
, soft_object_t
*object_p
)
533 CK_ATTRIBUTE_INFO_PTR attrp
;
535 /* Allocate attribute_info struct. */
536 attrp
= calloc(1, sizeof (attribute_info_t
));
538 return (CKR_HOST_MEMORY
);
541 attrp
->attr
.type
= old_attrp
->attr
.type
;
542 attrp
->attr
.ulValueLen
= old_attrp
->attr
.ulValueLen
;
544 if ((old_attrp
->attr
.pValue
!= NULL
) &&
545 (old_attrp
->attr
.ulValueLen
> 0)) {
546 attrp
->attr
.pValue
= malloc(old_attrp
->attr
.ulValueLen
);
547 if (attrp
->attr
.pValue
== NULL
) {
549 return (CKR_HOST_MEMORY
);
552 (void) memcpy(attrp
->attr
.pValue
, old_attrp
->attr
.pValue
,
553 old_attrp
->attr
.ulValueLen
);
555 attrp
->attr
.pValue
= NULL
;
558 /* Insert the new attribute in front of extra attribute list */
559 if (object_p
->extra_attrlistp
== NULL
) {
560 object_p
->extra_attrlistp
= attrp
;
563 attrp
->next
= object_p
->extra_attrlistp
;
564 object_p
->extra_attrlistp
= attrp
;
572 * Get the attribute triple from the extra attribute list in the object
573 * (if the specified attribute type is found), and copy it to a template.
574 * Note the type of the attribute to be copied is specified by the template,
575 * and the storage is pre-allocated for the atrribute value in the template
576 * for doing the copy.
579 get_extra_attr_from_object(soft_object_t
*object_p
, CK_ATTRIBUTE_PTR
template)
582 CK_ATTRIBUTE_INFO_PTR extra_attr
;
583 CK_ATTRIBUTE_TYPE type
= template->type
;
585 extra_attr
= object_p
->extra_attrlistp
;
588 if (type
== extra_attr
->attr
.type
) {
592 /* Does not match, try next one. */
593 extra_attr
= extra_attr
->next
;
597 if (extra_attr
== NULL
) {
598 /* A valid but un-initialized attribute. */
599 template->ulValueLen
= 0;
604 * We found the attribute in the extra attribute list.
606 if (template->pValue
== NULL
) {
607 template->ulValueLen
= extra_attr
->attr
.ulValueLen
;
611 if (template->ulValueLen
>= extra_attr
->attr
.ulValueLen
) {
613 * The buffer provided by the application is large
614 * enough to hold the value of the attribute.
616 (void) memcpy(template->pValue
, extra_attr
->attr
.pValue
,
617 extra_attr
->attr
.ulValueLen
);
618 template->ulValueLen
= extra_attr
->attr
.ulValueLen
;
622 * The buffer provided by the application does
623 * not have enough space to hold the value.
625 template->ulValueLen
= (CK_ULONG
)-1;
626 return (CKR_BUFFER_TOO_SMALL
);
632 * Modify the attribute triple in the extra attribute list of the object
633 * if the specified attribute type is found. Otherwise, just add it to
637 set_extra_attr_to_object(soft_object_t
*object_p
, CK_ATTRIBUTE_TYPE type
,
638 CK_ATTRIBUTE_PTR
template)
641 CK_ATTRIBUTE_INFO_PTR extra_attr
;
643 extra_attr
= object_p
->extra_attrlistp
;
646 if (type
== extra_attr
->attr
.type
) {
650 /* Does not match, try next one. */
651 extra_attr
= extra_attr
->next
;
655 if (extra_attr
== NULL
) {
657 * This attribute is a new one, go ahead adding it to
658 * the extra attribute list.
660 return (soft_add_extra_attr(template, object_p
));
663 /* We found the attribute in the extra attribute list. */
664 if ((template->pValue
!= NULL
) &&
665 (template->ulValueLen
> 0)) {
666 if (template->ulValueLen
> extra_attr
->attr
.ulValueLen
) {
667 /* The old buffer is too small to hold the new value. */
668 free(extra_attr
->attr
.pValue
);
670 /* Allocate storage for the new attribute value. */
671 extra_attr
->attr
.pValue
= malloc(template->ulValueLen
);
672 if (extra_attr
->attr
.pValue
== NULL
) {
673 return (CKR_HOST_MEMORY
);
677 /* Replace the attribute with new value. */
678 extra_attr
->attr
.ulValueLen
= template->ulValueLen
;
679 (void) memcpy(extra_attr
->attr
.pValue
, template->pValue
,
680 template->ulValueLen
);
682 extra_attr
->attr
.pValue
= NULL
;
690 * Copy the big integer attribute value from template to a biginteger_t struct.
693 get_bigint_attr_from_template(biginteger_t
*big
, CK_ATTRIBUTE_PTR
template)
696 if ((template->pValue
!= NULL
) &&
697 (template->ulValueLen
> 0)) {
698 /* Allocate storage for the value of the attribute. */
699 big
->big_value
= malloc(template->ulValueLen
);
700 if (big
->big_value
== NULL
) {
701 return (CKR_HOST_MEMORY
);
704 (void) memcpy(big
->big_value
, template->pValue
,
705 template->ulValueLen
);
706 big
->big_value_len
= template->ulValueLen
;
708 big
->big_value
= NULL
;
709 big
->big_value_len
= 0;
717 * Copy the big integer attribute value from a biginteger_t struct in the
718 * object to a template.
721 get_bigint_attr_from_object(biginteger_t
*big
, CK_ATTRIBUTE_PTR
template)
724 if (template->pValue
== NULL
) {
725 template->ulValueLen
= big
->big_value_len
;
729 if (big
->big_value
== NULL
) {
730 template->ulValueLen
= 0;
734 if (template->ulValueLen
>= big
->big_value_len
) {
736 * The buffer provided by the application is large
737 * enough to hold the value of the attribute.
739 (void) memcpy(template->pValue
, big
->big_value
,
741 template->ulValueLen
= big
->big_value_len
;
745 * The buffer provided by the application does
746 * not have enough space to hold the value.
748 template->ulValueLen
= (CK_ULONG
)-1;
749 return (CKR_BUFFER_TOO_SMALL
);
755 * Copy the boolean data type attribute value from an object for the
756 * specified attribute to the template.
759 get_bool_attr_from_object(soft_object_t
*object_p
, CK_ULONG bool_flag
,
760 CK_ATTRIBUTE_PTR
template)
763 if (template->pValue
== NULL
) {
764 template->ulValueLen
= sizeof (CK_BBOOL
);
768 if (template->ulValueLen
>= sizeof (CK_BBOOL
)) {
770 * The buffer provided by the application is large
771 * enough to hold the value of the attribute.
773 if (object_p
->bool_attr_mask
& bool_flag
) {
774 *((CK_BBOOL
*)template->pValue
) = B_TRUE
;
776 *((CK_BBOOL
*)template->pValue
) = B_FALSE
;
779 template->ulValueLen
= sizeof (CK_BBOOL
);
783 * The buffer provided by the application does
784 * not have enough space to hold the value.
786 template->ulValueLen
= (CK_ULONG
)-1;
787 return (CKR_BUFFER_TOO_SMALL
);
792 * Set the boolean data type attribute value in the object.
795 set_bool_attr_to_object(soft_object_t
*object_p
, CK_ULONG bool_flag
,
796 CK_ATTRIBUTE_PTR
template)
799 if (*(CK_BBOOL
*)template->pValue
)
800 object_p
->bool_attr_mask
|= bool_flag
;
802 object_p
->bool_attr_mask
&= ~bool_flag
;
809 * Copy the CK_ULONG data type attribute value from an object to the
813 get_ulong_attr_from_object(CK_ULONG value
, CK_ATTRIBUTE_PTR
template)
816 if (template->pValue
== NULL
) {
817 template->ulValueLen
= sizeof (CK_ULONG
);
821 if (template->ulValueLen
>= sizeof (CK_ULONG
)) {
823 * The buffer provided by the application is large
824 * enough to hold the value of the attribute.
825 * It is also assumed to be correctly aligned.
827 *(CK_ULONG_PTR
)template->pValue
= value
;
828 template->ulValueLen
= sizeof (CK_ULONG
);
832 * The buffer provided by the application does
833 * not have enough space to hold the value.
835 template->ulValueLen
= (CK_ULONG
)-1;
836 return (CKR_BUFFER_TOO_SMALL
);
842 * Copy the CK_ULONG data type attribute value from a template to the
846 get_ulong_attr_from_template(CK_ULONG
*value
, CK_ATTRIBUTE_PTR
template)
849 if (template->ulValueLen
< sizeof (CK_ULONG
))
850 return (CKR_ATTRIBUTE_VALUE_INVALID
);
852 if (template->pValue
!= NULL
) {
853 *value
= *(CK_ULONG_PTR
)template->pValue
;
862 * Copy the big integer attribute value from source's biginteger_t to
863 * destination's biginteger_t.
866 copy_bigint_attr(biginteger_t
*src
, biginteger_t
*dst
)
869 if ((src
->big_value
!= NULL
) &&
870 (src
->big_value_len
> 0)) {
872 * To do the copy, just have dst's big_value points
875 dst
->big_value
= src
->big_value
;
876 dst
->big_value_len
= src
->big_value_len
;
879 * After the copy, nullify the src's big_value pointer.
880 * It prevents any double freeing the value.
882 src
->big_value
= NULL
;
883 src
->big_value_len
= 0;
885 dst
->big_value
= NULL
;
886 dst
->big_value_len
= 0;
891 get_string_from_template(CK_ATTRIBUTE_PTR dest
, CK_ATTRIBUTE_PTR src
)
893 if ((src
->pValue
!= NULL
) &&
894 (src
->ulValueLen
> 0)) {
895 /* Allocate storage for the value of the attribute. */
896 dest
->pValue
= malloc(src
->ulValueLen
);
897 if (dest
->pValue
== NULL
) {
898 return (CKR_HOST_MEMORY
);
901 (void) memcpy(dest
->pValue
, src
->pValue
,
903 dest
->ulValueLen
= src
->ulValueLen
;
904 dest
->type
= src
->type
;
907 dest
->ulValueLen
= 0;
908 dest
->type
= src
->type
;
916 get_cert_attr_from_template(cert_attr_t
**dest
, CK_ATTRIBUTE_PTR src
)
918 if (src
->pValue
!= NULL
&& src
->ulValueLen
> 0) {
920 * If the attribute was already set, clear out the
921 * existing value and release the memory.
924 if ((*dest
)->value
!= NULL
) {
925 (void) memset((*dest
)->value
, 0,
927 free((*dest
)->value
);
930 *dest
= malloc(sizeof (cert_attr_t
));
932 return (CKR_HOST_MEMORY
);
934 (void) memset(*dest
, 0, sizeof (cert_attr_t
));
936 (*dest
)->value
= malloc(src
->ulValueLen
);
937 if ((*dest
)->value
== NULL
) {
940 return (CKR_HOST_MEMORY
);
942 (void) memcpy((*dest
)->value
, src
->pValue
, src
->ulValueLen
);
943 (*dest
)->length
= src
->ulValueLen
;
950 * Copy the certificate attribute information to the template.
951 * If the template attribute is not big enough, set the ulValueLen=-1
952 * and return CKR_BUFFER_TOO_SMALL.
955 get_cert_attr_from_object(cert_attr_t
*src
, CK_ATTRIBUTE_PTR
template)
957 if (template->pValue
== NULL
) {
958 template->ulValueLen
= src
->length
;
960 } else if (template->ulValueLen
>= src
->length
) {
962 * The buffer provided by the application is large
963 * enough to hold the value of the attribute.
965 (void) memcpy(template->pValue
, src
->value
, src
->length
);
966 template->ulValueLen
= src
->length
;
970 * The buffer provided by the application does
971 * not have enough space to hold the value.
973 template->ulValueLen
= (CK_ULONG
)-1;
974 return (CKR_BUFFER_TOO_SMALL
);
979 string_attr_cleanup(CK_ATTRIBUTE_PTR
template)
982 if (template->pValue
) {
983 free(template->pValue
);
984 template->pValue
= NULL
;
985 template->ulValueLen
= 0;
990 * Release the storage allocated for object attribute with big integer
994 bigint_attr_cleanup(biginteger_t
*big
)
1000 if (big
->big_value
) {
1001 (void) memset(big
->big_value
, 0, big
->big_value_len
);
1002 free(big
->big_value
);
1003 big
->big_value
= NULL
;
1004 big
->big_value_len
= 0;
1010 * Clean up and release all the storage allocated to hold the big integer
1011 * attributes associated with the type (i.e. class) of the object. Also,
1012 * release the storage allocated to the type of the object.
1015 soft_cleanup_object_bigint_attrs(soft_object_t
*object_p
)
1018 CK_OBJECT_CLASS
class = object_p
->class;
1019 CK_KEY_TYPE keytype
= object_p
->key_type
;
1023 case CKO_PUBLIC_KEY
:
1024 if (OBJ_PUB(object_p
)) {
1027 bigint_attr_cleanup(OBJ_PUB_RSA_MOD(
1029 bigint_attr_cleanup(OBJ_PUB_RSA_PUBEXPO(
1034 bigint_attr_cleanup(OBJ_PUB_DSA_PRIME(
1036 bigint_attr_cleanup(OBJ_PUB_DSA_SUBPRIME(
1038 bigint_attr_cleanup(OBJ_PUB_DSA_BASE(
1040 bigint_attr_cleanup(OBJ_PUB_DSA_VALUE(
1045 bigint_attr_cleanup(OBJ_PUB_DH_PRIME(
1047 bigint_attr_cleanup(OBJ_PUB_DH_BASE(
1049 bigint_attr_cleanup(OBJ_PUB_DH_VALUE(
1054 bigint_attr_cleanup(OBJ_PUB_DH942_PRIME(
1056 bigint_attr_cleanup(OBJ_PUB_DH942_BASE(
1058 bigint_attr_cleanup(OBJ_PUB_DH942_SUBPRIME(
1060 bigint_attr_cleanup(OBJ_PUB_DH942_VALUE(
1064 bigint_attr_cleanup(OBJ_PUB_EC_POINT(
1069 /* Release Public Key Object struct */
1070 free(OBJ_PUB(object_p
));
1071 OBJ_PUB(object_p
) = NULL
;
1075 case CKO_PRIVATE_KEY
:
1076 if (OBJ_PRI(object_p
)) {
1079 bigint_attr_cleanup(OBJ_PRI_RSA_MOD(
1081 bigint_attr_cleanup(OBJ_PRI_RSA_PUBEXPO(
1083 bigint_attr_cleanup(OBJ_PRI_RSA_PRIEXPO(
1085 bigint_attr_cleanup(OBJ_PRI_RSA_PRIME1(
1087 bigint_attr_cleanup(OBJ_PRI_RSA_PRIME2(
1089 bigint_attr_cleanup(OBJ_PRI_RSA_EXPO1(
1091 bigint_attr_cleanup(OBJ_PRI_RSA_EXPO2(
1093 bigint_attr_cleanup(OBJ_PRI_RSA_COEF(
1098 bigint_attr_cleanup(OBJ_PRI_DSA_PRIME(
1100 bigint_attr_cleanup(OBJ_PRI_DSA_SUBPRIME(
1102 bigint_attr_cleanup(OBJ_PRI_DSA_BASE(
1104 bigint_attr_cleanup(OBJ_PRI_DSA_VALUE(
1109 bigint_attr_cleanup(OBJ_PRI_DH_PRIME(
1111 bigint_attr_cleanup(OBJ_PRI_DH_BASE(
1113 bigint_attr_cleanup(OBJ_PRI_DH_VALUE(
1118 bigint_attr_cleanup(OBJ_PRI_DH942_PRIME(
1120 bigint_attr_cleanup(OBJ_PRI_DH942_BASE(
1122 bigint_attr_cleanup(OBJ_PRI_DH942_SUBPRIME(
1124 bigint_attr_cleanup(OBJ_PRI_DH942_VALUE(
1129 bigint_attr_cleanup(OBJ_PRI_EC_VALUE(
1134 /* Release Private Key Object struct. */
1135 free(OBJ_PRI(object_p
));
1136 OBJ_PRI(object_p
) = NULL
;
1140 case CKO_SECRET_KEY
:
1141 if (OBJ_SEC(object_p
)) {
1142 /* cleanup key data area */
1143 if (OBJ_SEC_VALUE(object_p
) != NULL
&&
1144 OBJ_SEC_VALUE_LEN(object_p
) > 0) {
1145 (void) memset(OBJ_SEC_VALUE(object_p
), 0,
1146 OBJ_SEC_VALUE_LEN(object_p
));
1147 free(OBJ_SEC_VALUE(object_p
));
1149 /* cleanup key schedule data area */
1150 if (OBJ_KEY_SCHED(object_p
) != NULL
&&
1151 OBJ_KEY_SCHED_LEN(object_p
) > 0) {
1152 (void) memset(OBJ_KEY_SCHED(object_p
), 0,
1153 OBJ_KEY_SCHED_LEN(object_p
));
1154 free(OBJ_KEY_SCHED(object_p
));
1157 /* Release Secret Key Object struct. */
1158 free(OBJ_SEC(object_p
));
1159 OBJ_SEC(object_p
) = NULL
;
1163 case CKO_DOMAIN_PARAMETERS
:
1164 if (OBJ_DOM(object_p
)) {
1167 bigint_attr_cleanup(OBJ_DOM_DSA_PRIME(
1169 bigint_attr_cleanup(OBJ_DOM_DSA_SUBPRIME(
1171 bigint_attr_cleanup(OBJ_DOM_DSA_BASE(
1176 bigint_attr_cleanup(OBJ_DOM_DH_PRIME(
1178 bigint_attr_cleanup(OBJ_DOM_DH_BASE(
1183 bigint_attr_cleanup(OBJ_DOM_DH942_PRIME(
1185 bigint_attr_cleanup(OBJ_DOM_DH942_BASE(
1187 bigint_attr_cleanup(OBJ_DOM_DH942_SUBPRIME(
1192 /* Release Domain Parameters Object struct. */
1193 free(OBJ_DOM(object_p
));
1194 OBJ_DOM(object_p
) = NULL
;
1202 * Parse the common attributes. Return to caller with appropriate return
1203 * value to indicate if the supplied template specifies a valid attribute
1204 * with a valid value.
1207 soft_parse_common_attrs(CK_ATTRIBUTE_PTR
template, uchar_t
*object_type
)
1212 switch (template->type
) {
1216 /* default boolean attributes */
1218 if ((*(CK_BBOOL
*)template->pValue
) == B_TRUE
) {
1219 if (!soft_keystore_status(KEYSTORE_INITIALIZED
))
1220 return (CKR_DEVICE_REMOVED
);
1221 *object_type
|= TOKEN_OBJECT
;
1226 if ((*(CK_BBOOL
*)template->pValue
) == B_TRUE
) {
1227 (void) pthread_mutex_lock(&soft_giant_mutex
);
1228 if (!soft_slot
.authenticated
) {
1230 * Check if this is the special case when
1231 * the PIN is never initialized in the keystore.
1232 * If true, we will let it pass here and let
1233 * it fail with CKR_PIN_EXPIRED later on.
1235 if (!soft_slot
.userpin_change_needed
) {
1236 (void) pthread_mutex_unlock(
1238 return (CKR_USER_NOT_LOGGED_IN
);
1241 (void) pthread_mutex_unlock(&soft_giant_mutex
);
1242 *object_type
|= PRIVATE_OBJECT
;
1250 rv
= CKR_TEMPLATE_INCONSISTENT
;
1258 * Build a Public Key Object.
1260 * - Parse the object's template, and when an error is detected such as
1261 * invalid attribute type, invalid attribute value, etc., return
1262 * with appropriate return value.
1263 * - Set up attribute mask field in the object for the supplied common
1264 * attributes that have boolean type.
1265 * - Build the attribute_info struct to hold the value of each supplied
1266 * attribute that has byte array type. Link attribute_info structs
1267 * together to form the extra attribute list of the object.
1268 * - Allocate storage for the Public Key object.
1269 * - Build the Public Key object according to the key type. Allocate
1270 * storage to hold the big integer value for the supplied attributes
1271 * that are required for a certain key type.
1275 soft_build_public_key_object(CK_ATTRIBUTE_PTR
template, CK_ULONG ulAttrNum
,
1276 soft_object_t
*new_object
, CK_ULONG mode
, CK_KEY_TYPE key_type
)
1280 CK_KEY_TYPE keytype
= (CK_KEY_TYPE
)~0UL;
1281 uint64_t attr_mask
= PUBLIC_KEY_DEFAULT
;
1284 /* Must set flags */
1293 /* Must not set flags */
1294 int isModulusBits
= 0;
1295 CK_ULONG modulus_bits
= 0;
1297 biginteger_t modulus
;
1298 biginteger_t pubexpo
;
1300 biginteger_t subprime
;
1304 CK_ATTRIBUTE string_tmp
;
1305 CK_ATTRIBUTE param_tmp
;
1307 public_key_obj_t
*pbk
;
1308 uchar_t object_type
= 0;
1310 CK_ATTRIBUTE defpubexpo
= { CKA_PUBLIC_EXPONENT
,
1311 (CK_BYTE_PTR
)DEFAULT_PUB_EXPO
, DEFAULT_PUB_EXPO_Len
};
1315 /* prevent bigint_attr_cleanup from freeing invalid attr value */
1316 (void) memset(&modulus
, 0x0, sizeof (biginteger_t
));
1317 (void) memset(&pubexpo
, 0x0, sizeof (biginteger_t
));
1318 (void) memset(&prime
, 0x0, sizeof (biginteger_t
));
1319 (void) memset(&subprime
, 0x0, sizeof (biginteger_t
));
1320 (void) memset(&base
, 0x0, sizeof (biginteger_t
));
1321 (void) memset(&value
, 0x0, sizeof (biginteger_t
));
1322 (void) memset(&point
, 0x0, sizeof (biginteger_t
));
1323 string_tmp
.pValue
= NULL
;
1324 param_tmp
.pValue
= NULL
;
1326 for (i
= 0; i
< ulAttrNum
; i
++) {
1328 /* Public Key Object Attributes */
1329 switch (template[i
].type
) {
1331 /* common key attributes */
1333 keytype
= *((CK_KEY_TYPE
*)template[i
].pValue
);
1337 case CKA_START_DATE
:
1340 /* common public key attribute */
1343 * Allocate storage to hold the attribute
1344 * value with byte array type, and add it to
1345 * the extra attribute list of the object.
1347 rv
= soft_add_extra_attr(&template[i
],
1355 * The following key related attribute types must
1356 * not be specified by C_CreateObject, C_GenerateKey(Pair).
1359 case CKA_KEY_GEN_MECHANISM
:
1360 rv
= CKR_TEMPLATE_INCONSISTENT
;
1363 /* Key related boolean attributes */
1365 if (*(CK_BBOOL
*)template[i
].pValue
)
1366 attr_mask
|= DERIVE_BOOL_ON
;
1370 if (*(CK_BBOOL
*)template[i
].pValue
)
1371 attr_mask
|= ENCRYPT_BOOL_ON
;
1373 attr_mask
&= ~ENCRYPT_BOOL_ON
;
1377 if (*(CK_BBOOL
*)template[i
].pValue
)
1378 attr_mask
|= VERIFY_BOOL_ON
;
1380 attr_mask
&= ~VERIFY_BOOL_ON
;
1383 case CKA_VERIFY_RECOVER
:
1384 if (*(CK_BBOOL
*)template[i
].pValue
)
1385 attr_mask
|= VERIFY_RECOVER_BOOL_ON
;
1387 attr_mask
&= ~VERIFY_RECOVER_BOOL_ON
;
1391 if (*(CK_BBOOL
*)template[i
].pValue
)
1392 attr_mask
|= WRAP_BOOL_ON
;
1394 attr_mask
&= ~WRAP_BOOL_ON
;
1398 if (*(CK_BBOOL
*)template[i
].pValue
)
1399 attr_mask
|= TRUSTED_BOOL_ON
;
1402 case CKA_MODIFIABLE
:
1403 if ((*(CK_BBOOL
*)template[i
].pValue
) == B_FALSE
)
1404 attr_mask
|= NOT_MODIFIABLE_BOOL_ON
;
1408 * The following key related attribute types must
1409 * be specified according to the key type by
1416 * Copyin big integer attribute from template
1417 * to a local variable.
1419 rv
= get_bigint_attr_from_template(&modulus
,
1425 * Modulus length needs to be between min key length and
1428 if ((modulus
.big_value_len
<
1429 MIN_RSA_KEYLENGTH_IN_BYTES
) ||
1430 (modulus
.big_value_len
>
1431 MAX_RSA_KEYLENGTH_IN_BYTES
)) {
1432 rv
= CKR_ATTRIBUTE_VALUE_INVALID
;
1437 case CKA_PUBLIC_EXPONENT
:
1439 rv
= get_bigint_attr_from_template(&pubexpo
,
1447 rv
= get_bigint_attr_from_template(&prime
,
1455 rv
= get_bigint_attr_from_template(&subprime
,
1463 rv
= get_bigint_attr_from_template(&base
,
1471 if (mode
== SOFT_CREATE_OBJ
) {
1472 if ((template[i
].ulValueLen
== 0) ||
1473 (template[i
].pValue
== NULL
)) {
1474 rv
= CKR_ATTRIBUTE_VALUE_INVALID
;
1479 rv
= get_bigint_attr_from_template(&value
,
1485 case CKA_MODULUS_BITS
:
1487 rv
= get_ulong_attr_from_template(&modulus_bits
,
1495 rv
= get_string_from_template(&string_tmp
,
1503 rv
= get_string_from_template(¶m_tmp
, &template[i
]);
1510 rv
= get_bigint_attr_from_template(&point
,
1517 rv
= soft_parse_common_attrs(&template[i
],
1525 /* Allocate storage for Public Key Object. */
1526 pbk
= calloc(1, sizeof (public_key_obj_t
));
1528 rv
= CKR_HOST_MEMORY
;
1532 new_object
->object_class_u
.public_key
= pbk
;
1533 new_object
->class = CKO_PUBLIC_KEY
;
1535 if ((mode
== SOFT_CREATE_OBJ
) && (keytype
== (CK_KEY_TYPE
)~0UL)) {
1536 rv
= CKR_TEMPLATE_INCOMPLETE
;
1540 if ((mode
== SOFT_GEN_KEY
) && (keytype
== (CK_KEY_TYPE
)~0UL)) {
1544 if ((mode
== SOFT_GEN_KEY
) && (keytype
!= key_type
)) {
1546 * The key type specified in the template does not
1547 * match the implied key type based on the mechanism.
1549 rv
= CKR_TEMPLATE_INCONSISTENT
;
1553 new_object
->key_type
= keytype
;
1555 /* Supported key types of the Public Key Object */
1559 if (mode
== SOFT_CREATE_OBJ
) {
1560 if (isModulusBits
|| isPrime
|| isSubprime
||
1561 isBase
|| isValue
) {
1562 rv
= CKR_TEMPLATE_INCONSISTENT
;
1566 if (isModulus
&& isPubExpo
) {
1568 * Derive modulus_bits attribute from modulus.
1569 * Save modulus_bits integer value to the
1570 * designated place in the public key object.
1574 if (big_init(&n
, (int)CHARLEN2BIGNUMLEN(
1575 modulus
.big_value_len
)) != BIG_OK
) {
1576 #else /* !__sparcv9 */
1577 if (big_init(&n
, CHARLEN2BIGNUMLEN(
1578 modulus
.big_value_len
)) != BIG_OK
) {
1579 #endif /* __sparcv9 */
1580 rv
= CKR_HOST_MEMORY
;
1584 bytestring2bignum(&n
, modulus
.big_value
,
1585 modulus
.big_value_len
);
1587 modulus_bits
= big_bitlength(&n
);
1588 KEY_PUB_RSA_MOD_BITS(pbk
) = modulus_bits
;
1592 * After modulus_bits has been computed,
1593 * it is safe to move modulus and pubexpo
1594 * big integer attribute value to the
1595 * designated place in the public key object.
1597 copy_bigint_attr(&modulus
,
1598 KEY_PUB_RSA_MOD(pbk
));
1600 copy_bigint_attr(&pubexpo
,
1601 KEY_PUB_RSA_PUBEXPO(pbk
));
1603 rv
= CKR_TEMPLATE_INCOMPLETE
;
1607 /* mode is SOFT_GEN_KEY */
1609 if (isModulus
|| isPrime
|| isSubprime
||
1610 isBase
|| isValue
) {
1611 rv
= CKR_TEMPLATE_INCONSISTENT
;
1616 if (isModulusBits
) {
1618 * Copy big integer attribute value to the
1619 * designated place in the public key object.
1621 KEY_PUB_RSA_MOD_BITS(pbk
) = modulus_bits
;
1623 rv
= CKR_TEMPLATE_INCOMPLETE
;
1628 * Use PKCS#11 default 0x010001 for public exponent
1629 * if not not specified in attribute template.
1633 rv
= get_bigint_attr_from_template(&pubexpo
,
1639 * Copy big integer attribute value to the
1640 * designated place in the public key object.
1642 copy_bigint_attr(&pubexpo
, KEY_PUB_RSA_PUBEXPO(pbk
));
1648 if (mode
== SOFT_CREATE_OBJ
) {
1649 if (isModulusBits
|| isModulus
|| isPubExpo
) {
1650 rv
= CKR_TEMPLATE_INCONSISTENT
;
1654 if (isPrime
&& isSubprime
&& isBase
&& isValue
) {
1655 copy_bigint_attr(&value
,
1656 KEY_PUB_DSA_VALUE(pbk
));
1658 rv
= CKR_TEMPLATE_INCOMPLETE
;
1662 if (isModulusBits
|| isModulus
|| isPubExpo
||
1664 rv
= CKR_TEMPLATE_INCONSISTENT
;
1668 if (!(isPrime
&& isSubprime
&& isBase
)) {
1669 rv
= CKR_TEMPLATE_INCOMPLETE
;
1674 copy_bigint_attr(&prime
, KEY_PUB_DSA_PRIME(pbk
));
1676 copy_bigint_attr(&subprime
, KEY_PUB_DSA_SUBPRIME(pbk
));
1678 copy_bigint_attr(&base
, KEY_PUB_DSA_BASE(pbk
));
1683 if (mode
== SOFT_CREATE_OBJ
) {
1684 if (isModulusBits
|| isModulus
|| isPubExpo
||
1686 rv
= CKR_TEMPLATE_INCONSISTENT
;
1690 if (isPrime
&& isBase
&& isValue
) {
1691 copy_bigint_attr(&value
,
1692 KEY_PUB_DH_VALUE(pbk
));
1694 rv
= CKR_TEMPLATE_INCOMPLETE
;
1698 if (isModulusBits
|| isModulus
|| isPubExpo
||
1699 isSubprime
|| isValue
) {
1700 rv
= CKR_TEMPLATE_INCONSISTENT
;
1704 if (!(isPrime
&& isBase
)) {
1705 rv
= CKR_TEMPLATE_INCOMPLETE
;
1710 copy_bigint_attr(&prime
, KEY_PUB_DH_PRIME(pbk
));
1712 copy_bigint_attr(&base
, KEY_PUB_DH_BASE(pbk
));
1717 if (mode
== SOFT_CREATE_OBJ
) {
1718 if (isModulusBits
|| isModulus
|| isPubExpo
) {
1719 rv
= CKR_TEMPLATE_INCONSISTENT
;
1723 if (isPrime
&& isSubprime
&& isBase
&& isValue
) {
1724 copy_bigint_attr(&value
,
1725 KEY_PUB_DH942_VALUE(pbk
));
1727 rv
= CKR_TEMPLATE_INCOMPLETE
;
1731 if (isModulusBits
|| isModulus
|| isPubExpo
||
1733 rv
= CKR_TEMPLATE_INCONSISTENT
;
1737 if (!(isPrime
&& isSubprime
&& isBase
)) {
1738 rv
= CKR_TEMPLATE_INCOMPLETE
;
1743 copy_bigint_attr(&prime
, KEY_PUB_DH942_PRIME(pbk
));
1745 copy_bigint_attr(&base
, KEY_PUB_DH942_BASE(pbk
));
1747 copy_bigint_attr(&subprime
, KEY_PUB_DH942_SUBPRIME(pbk
));
1752 if (mode
== SOFT_CREATE_OBJ
) {
1753 if (isModulusBits
|| isModulus
|| isPubExpo
||
1754 isPrime
|| isSubprime
|| isBase
|| isValue
) {
1755 rv
= CKR_TEMPLATE_INCONSISTENT
;
1758 } else if (!isECParam
|| !isECPoint
) {
1759 rv
= CKR_TEMPLATE_INCOMPLETE
;
1763 if (isModulusBits
|| isModulus
|| isPubExpo
||
1764 isPrime
|| isSubprime
|| isBase
|| isValue
) {
1765 rv
= CKR_TEMPLATE_INCONSISTENT
;
1768 } else if (!isECParam
) {
1769 rv
= CKR_TEMPLATE_INCOMPLETE
;
1775 copy_bigint_attr(&point
, KEY_PUB_EC_POINT(pbk
));
1777 rv
= soft_add_extra_attr(¶m_tmp
, new_object
);
1780 string_attr_cleanup(¶m_tmp
);
1784 rv
= CKR_TEMPLATE_INCONSISTENT
;
1788 /* Set up object. */
1789 new_object
->object_type
= object_type
;
1790 new_object
->bool_attr_mask
= attr_mask
;
1792 rv
= soft_add_extra_attr(&string_tmp
, new_object
);
1795 string_attr_cleanup(&string_tmp
);
1802 * cleanup the storage allocated to the local variables.
1804 bigint_attr_cleanup(&modulus
);
1805 bigint_attr_cleanup(&pubexpo
);
1806 bigint_attr_cleanup(&prime
);
1807 bigint_attr_cleanup(&subprime
);
1808 bigint_attr_cleanup(&base
);
1809 bigint_attr_cleanup(&value
);
1810 bigint_attr_cleanup(&point
);
1811 string_attr_cleanup(&string_tmp
);
1812 string_attr_cleanup(¶m_tmp
);
1815 * cleanup the storage allocated inside the object itself.
1817 soft_cleanup_object(new_object
);
1824 * Build a Private Key Object.
1826 * - Parse the object's template, and when an error is detected such as
1827 * invalid attribute type, invalid attribute value, etc., return
1828 * with appropriate return value.
1829 * - Set up attribute mask field in the object for the supplied common
1830 * attributes that have boolean type.
1831 * - Build the attribute_info struct to hold the value of each supplied
1832 * attribute that has byte array type. Link attribute_info structs
1833 * together to form the extra attribute list of the object.
1834 * - Allocate storage for the Private Key object.
1835 * - Build the Private Key object according to the key type. Allocate
1836 * storage to hold the big integer value for the supplied attributes
1837 * that are required for a certain key type.
1841 soft_build_private_key_object(CK_ATTRIBUTE_PTR
template, CK_ULONG ulAttrNum
,
1842 soft_object_t
*new_object
, CK_ULONG mode
, CK_KEY_TYPE key_type
)
1845 CK_KEY_TYPE keytype
= (CK_KEY_TYPE
)~0UL;
1846 uint64_t attr_mask
= PRIVATE_KEY_DEFAULT
;
1850 /* Must set flags unless mode == SOFT_UNWRAP_KEY */
1856 /* Must set flags if mode == SOFT_GEN_KEY */
1858 /* Must not set flags */
1859 int isValueBits
= 0;
1860 CK_ULONG value_bits
= 0;
1862 /* Private Key RSA optional */
1870 biginteger_t modulus
;
1871 biginteger_t priexpo
;
1873 biginteger_t subprime
;
1877 biginteger_t pubexpo
;
1878 biginteger_t prime1
;
1879 biginteger_t prime2
;
1883 CK_ATTRIBUTE string_tmp
;
1884 CK_ATTRIBUTE param_tmp
;
1887 private_key_obj_t
*pvk
;
1888 uchar_t object_type
= 0;
1890 /* prevent bigint_attr_cleanup from freeing invalid attr value */
1891 (void) memset(&modulus
, 0x0, sizeof (biginteger_t
));
1892 (void) memset(&priexpo
, 0x0, sizeof (biginteger_t
));
1893 (void) memset(&prime
, 0x0, sizeof (biginteger_t
));
1894 (void) memset(&subprime
, 0x0, sizeof (biginteger_t
));
1895 (void) memset(&base
, 0x0, sizeof (biginteger_t
));
1896 (void) memset(&value
, 0x0, sizeof (biginteger_t
));
1897 (void) memset(&pubexpo
, 0x0, sizeof (biginteger_t
));
1898 (void) memset(&prime1
, 0x0, sizeof (biginteger_t
));
1899 (void) memset(&prime2
, 0x0, sizeof (biginteger_t
));
1900 (void) memset(&expo1
, 0x0, sizeof (biginteger_t
));
1901 (void) memset(&expo2
, 0x0, sizeof (biginteger_t
));
1902 (void) memset(&coef
, 0x0, sizeof (biginteger_t
));
1903 string_tmp
.pValue
= NULL
;
1904 param_tmp
.pValue
= NULL
;
1908 for (i
= 0; i
< ulAttrNum
; i
++) {
1910 /* Private Key Object Attributes */
1911 switch (template[i
].type
) {
1912 /* common key attributes */
1914 keytype
= *((CK_KEY_TYPE
*)template[i
].pValue
);
1918 case CKA_START_DATE
:
1921 /* common private key attribute */
1924 * Allocate storage to hold the attribute
1925 * value with byte array type, and add it to
1926 * the extra attribute list of the object.
1928 rv
= soft_add_extra_attr(&template[i
],
1936 * The following key related attribute types must
1937 * not be specified by C_CreateObject or C_GenerateKey(Pair).
1940 case CKA_KEY_GEN_MECHANISM
:
1941 case CKA_AUTH_PIN_FLAGS
:
1942 case CKA_ALWAYS_SENSITIVE
:
1943 case CKA_NEVER_EXTRACTABLE
:
1944 rv
= CKR_TEMPLATE_INCONSISTENT
;
1947 /* Key related boolean attributes */
1949 if (*(CK_BBOOL
*)template[i
].pValue
)
1950 attr_mask
|= DERIVE_BOOL_ON
;
1954 if (*(CK_BBOOL
*)template[i
].pValue
)
1955 attr_mask
|= SENSITIVE_BOOL_ON
;
1958 case CKA_SECONDARY_AUTH
:
1959 if (*(CK_BBOOL
*)template[i
].pValue
) {
1960 rv
= CKR_ATTRIBUTE_VALUE_INVALID
;
1966 if (*(CK_BBOOL
*)template[i
].pValue
)
1967 attr_mask
|= DECRYPT_BOOL_ON
;
1969 attr_mask
&= ~DECRYPT_BOOL_ON
;
1973 if (*(CK_BBOOL
*)template[i
].pValue
)
1974 attr_mask
|= SIGN_BOOL_ON
;
1976 attr_mask
&= ~SIGN_BOOL_ON
;
1979 case CKA_SIGN_RECOVER
:
1980 if (*(CK_BBOOL
*)template[i
].pValue
)
1981 attr_mask
|= SIGN_RECOVER_BOOL_ON
;
1983 attr_mask
&= ~SIGN_RECOVER_BOOL_ON
;
1987 if (*(CK_BBOOL
*)template[i
].pValue
)
1988 attr_mask
|= UNWRAP_BOOL_ON
;
1990 attr_mask
&= ~UNWRAP_BOOL_ON
;
1993 case CKA_EXTRACTABLE
:
1994 if (*(CK_BBOOL
*)template[i
].pValue
)
1995 attr_mask
|= EXTRACTABLE_BOOL_ON
;
1997 attr_mask
&= ~EXTRACTABLE_BOOL_ON
;
2000 case CKA_MODIFIABLE
:
2001 if ((*(CK_BBOOL
*)template[i
].pValue
) == B_FALSE
)
2002 attr_mask
|= NOT_MODIFIABLE_BOOL_ON
;
2006 * The following key related attribute types must
2007 * be specified according to the key type by
2014 * Copyin big integer attribute from template
2015 * to a local variable.
2017 rv
= get_bigint_attr_from_template(&modulus
,
2023 * Modulus length needs to be between min key length and
2026 if ((modulus
.big_value_len
<
2027 MIN_RSA_KEYLENGTH_IN_BYTES
) ||
2028 (modulus
.big_value_len
>
2029 MAX_RSA_KEYLENGTH_IN_BYTES
)) {
2030 rv
= CKR_ATTRIBUTE_VALUE_INVALID
;
2035 case CKA_PUBLIC_EXPONENT
:
2038 rv
= get_bigint_attr_from_template(&pubexpo
,
2044 case CKA_PRIVATE_EXPONENT
:
2047 rv
= get_bigint_attr_from_template(&priexpo
,
2055 rv
= get_bigint_attr_from_template(&prime1
,
2063 rv
= get_bigint_attr_from_template(&prime2
,
2069 case CKA_EXPONENT_1
:
2071 rv
= get_bigint_attr_from_template(&expo1
,
2077 case CKA_EXPONENT_2
:
2079 rv
= get_bigint_attr_from_template(&expo2
,
2085 case CKA_COEFFICIENT
:
2087 rv
= get_bigint_attr_from_template(&coef
,
2095 rv
= get_bigint_attr_from_template(&prime
,
2103 rv
= get_bigint_attr_from_template(&subprime
,
2111 rv
= get_bigint_attr_from_template(&base
,
2119 if (mode
== SOFT_CREATE_OBJ
) {
2120 if ((template[i
].ulValueLen
== 0) ||
2121 (template[i
].pValue
== NULL
)) {
2122 rv
= CKR_ATTRIBUTE_VALUE_INVALID
;
2127 rv
= get_bigint_attr_from_template(&value
,
2133 case CKA_VALUE_BITS
:
2135 rv
= get_ulong_attr_from_template(&value_bits
,
2143 rv
= get_string_from_template(&string_tmp
,
2151 rv
= get_string_from_template(¶m_tmp
,
2158 rv
= soft_parse_common_attrs(&template[i
],
2167 /* Allocate storage for Private Key Object. */
2168 pvk
= calloc(1, sizeof (private_key_obj_t
));
2170 rv
= CKR_HOST_MEMORY
;
2174 new_object
->object_class_u
.private_key
= pvk
;
2175 new_object
->class = CKO_PRIVATE_KEY
;
2177 if ((mode
== SOFT_CREATE_OBJ
) && (keytype
== (CK_KEY_TYPE
)~0UL)) {
2178 rv
= CKR_TEMPLATE_INCOMPLETE
;
2182 if (mode
== SOFT_GEN_KEY
) {
2184 * The key type is not specified in the application's
2185 * template, so we use the implied key type based on
2188 if (keytype
== (CK_KEY_TYPE
)~0UL) {
2192 /* If still unspecified, template is incomplete */
2193 if (keytype
== (CK_KEY_TYPE
)~0UL) {
2194 rv
= CKR_TEMPLATE_INCOMPLETE
;
2199 * The key type specified in the template does not
2200 * match the implied key type based on the mechanism.
2202 if (keytype
!= key_type
) {
2203 rv
= CKR_TEMPLATE_INCONSISTENT
;
2208 if (mode
== SOFT_UNWRAP_KEY
) {
2210 * Note that, for mode SOFT_UNWRAP_KEY, key type is not
2211 * implied by the mechanism (key_type), so if it is not
2212 * specified from the attribute template (keytype), it is
2215 if (keytype
== (CK_KEY_TYPE
)~0UL) {
2216 rv
= CKR_TEMPLATE_INCOMPLETE
;
2221 new_object
->key_type
= keytype
;
2223 /* Supported key types of the Private Key Object */
2226 if (isPrime
|| isSubprime
|| isBase
|| isValue
||
2228 rv
= CKR_TEMPLATE_INCONSISTENT
;
2232 if (mode
== SOFT_GEN_KEY
|| mode
== SOFT_UNWRAP_KEY
) {
2233 if (isModulus
|| isPubExpo
|| isPriExpo
|| isPrime1
||
2234 isPrime2
|| isExpo1
|| isExpo2
|| isCoef
) {
2235 rv
= CKR_TEMPLATE_INCONSISTENT
;
2241 if (isModulus
&& isPriExpo
) {
2243 * Copy big integer attribute value to the
2244 * designated place in the Private Key object.
2246 copy_bigint_attr(&modulus
, KEY_PRI_RSA_MOD(pvk
));
2248 copy_bigint_attr(&priexpo
, KEY_PRI_RSA_PRIEXPO(pvk
));
2250 rv
= CKR_TEMPLATE_INCOMPLETE
;
2254 /* The following attributes are optional. */
2256 copy_bigint_attr(&pubexpo
, KEY_PRI_RSA_PUBEXPO(pvk
));
2260 copy_bigint_attr(&prime1
, KEY_PRI_RSA_PRIME1(pvk
));
2264 copy_bigint_attr(&prime2
, KEY_PRI_RSA_PRIME2(pvk
));
2268 copy_bigint_attr(&expo1
, KEY_PRI_RSA_EXPO1(pvk
));
2272 copy_bigint_attr(&expo2
, KEY_PRI_RSA_EXPO2(pvk
));
2276 copy_bigint_attr(&coef
, KEY_PRI_RSA_COEF(pvk
));
2281 if (isModulus
|| isPubExpo
|| isPriExpo
|| isPrime1
||
2282 isPrime2
|| isExpo1
|| isExpo2
|| isCoef
||
2284 rv
= CKR_TEMPLATE_INCONSISTENT
;
2288 if (mode
== SOFT_GEN_KEY
|| mode
== SOFT_UNWRAP_KEY
) {
2289 if (isPrime
|| isSubprime
|| isBase
|| isValue
) {
2290 rv
= CKR_TEMPLATE_INCONSISTENT
;
2296 if (isPrime
&& isSubprime
&& isBase
&& isValue
) {
2298 * The private value x must be less than subprime q.
2299 * Size for big_init is in BIG_CHUNK_TYPE words.
2303 (int)CHARLEN2BIGNUMLEN(value
.big_value_len
))
2305 #else /* !__sparcv9 */
2307 CHARLEN2BIGNUMLEN(value
.big_value_len
))
2309 #endif /* __sparcv9 */
2310 rv
= CKR_HOST_MEMORY
;
2315 (int)CHARLEN2BIGNUMLEN(subprime
.big_value_len
))
2317 #else /* !__sparcv9 */
2319 CHARLEN2BIGNUMLEN(subprime
.big_value_len
))
2321 #endif /* __sparcv9 */
2322 rv
= CKR_HOST_MEMORY
;
2325 bytestring2bignum(&x
, value
.big_value
,
2326 value
.big_value_len
);
2327 bytestring2bignum(&q
, subprime
.big_value
,
2328 subprime
.big_value_len
);
2330 if (big_cmp_abs(&x
, &q
) > 0) {
2331 rv
= CKR_ATTRIBUTE_VALUE_INVALID
;
2335 copy_bigint_attr(&prime
, KEY_PRI_DSA_PRIME(pvk
));
2337 copy_bigint_attr(&subprime
, KEY_PRI_DSA_SUBPRIME(pvk
));
2339 copy_bigint_attr(&base
, KEY_PRI_DSA_BASE(pvk
));
2341 copy_bigint_attr(&value
, KEY_PRI_DSA_VALUE(pvk
));
2343 rv
= CKR_TEMPLATE_INCOMPLETE
;
2349 if (isModulus
|| isPubExpo
|| isPriExpo
|| isPrime1
||
2350 isPrime2
|| isExpo1
|| isExpo2
|| isCoef
||
2352 rv
= CKR_TEMPLATE_INCONSISTENT
;
2356 /* CKA_VALUE_BITS is for key gen but not unwrap */
2357 if (mode
== SOFT_GEN_KEY
)
2358 KEY_PRI_DH_VAL_BITS(pvk
) = (isValueBits
) ?
2360 else if (mode
== SOFT_UNWRAP_KEY
) {
2362 rv
= CKR_TEMPLATE_INCONSISTENT
;
2367 if (mode
== SOFT_GEN_KEY
|| mode
== SOFT_UNWRAP_KEY
) {
2368 if (isPrime
|| isBase
|| isValue
) {
2369 rv
= CKR_TEMPLATE_INCONSISTENT
;
2376 rv
= CKR_TEMPLATE_INCONSISTENT
;
2380 if (isPrime
&& isBase
&& isValue
) {
2381 copy_bigint_attr(&prime
, KEY_PRI_DH_PRIME(pvk
));
2383 copy_bigint_attr(&base
, KEY_PRI_DH_BASE(pvk
));
2385 copy_bigint_attr(&value
, KEY_PRI_DH_VALUE(pvk
));
2387 rv
= CKR_TEMPLATE_INCOMPLETE
;
2393 if (isModulus
|| isPubExpo
|| isPriExpo
|| isPrime1
||
2394 isPrime2
|| isExpo1
|| isExpo2
|| isCoef
||
2396 rv
= CKR_TEMPLATE_INCONSISTENT
;
2400 if (mode
== SOFT_GEN_KEY
|| mode
== SOFT_UNWRAP_KEY
) {
2401 if (isPrime
|| isSubprime
|| isBase
|| isValue
) {
2402 rv
= CKR_TEMPLATE_INCONSISTENT
;
2408 if (isPrime
&& isSubprime
&& isBase
&& isValue
) {
2409 copy_bigint_attr(&prime
, KEY_PRI_DH942_PRIME(pvk
));
2411 copy_bigint_attr(&base
, KEY_PRI_DH942_BASE(pvk
));
2413 copy_bigint_attr(&subprime
,
2414 KEY_PRI_DH942_SUBPRIME(pvk
));
2416 copy_bigint_attr(&value
, KEY_PRI_DH942_VALUE(pvk
));
2418 rv
= CKR_TEMPLATE_INCOMPLETE
;
2424 if (isModulus
|| isPubExpo
|| isPrime
||
2425 isPrime1
|| isPrime2
|| isExpo1
|| isExpo2
|| isCoef
||
2426 isValueBits
|| isBase
) {
2427 rv
= CKR_TEMPLATE_INCONSISTENT
;
2430 } else if (isECParam
) {
2431 rv
= soft_add_extra_attr(¶m_tmp
, new_object
);
2434 string_attr_cleanup(¶m_tmp
);
2437 copy_bigint_attr(&value
, KEY_PRI_EC_VALUE(pvk
));
2442 rv
= CKR_TEMPLATE_INCONSISTENT
;
2446 /* Set up object. */
2447 new_object
->object_type
= object_type
;
2448 new_object
->bool_attr_mask
= attr_mask
;
2450 rv
= soft_add_extra_attr(&string_tmp
, new_object
);
2453 string_attr_cleanup(&string_tmp
);
2462 * cleanup the storage allocated to the local variables.
2464 bigint_attr_cleanup(&modulus
);
2465 bigint_attr_cleanup(&priexpo
);
2466 bigint_attr_cleanup(&prime
);
2467 bigint_attr_cleanup(&subprime
);
2468 bigint_attr_cleanup(&base
);
2469 bigint_attr_cleanup(&value
);
2470 bigint_attr_cleanup(&pubexpo
);
2471 bigint_attr_cleanup(&prime1
);
2472 bigint_attr_cleanup(&prime2
);
2473 bigint_attr_cleanup(&expo1
);
2474 bigint_attr_cleanup(&expo2
);
2475 bigint_attr_cleanup(&coef
);
2476 string_attr_cleanup(&string_tmp
);
2477 string_attr_cleanup(¶m_tmp
);
2482 * cleanup the storage allocated inside the object itself.
2484 soft_cleanup_object(new_object
);
2491 * Build a Secret Key Object.
2493 * - Parse the object's template, and when an error is detected such as
2494 * invalid attribute type, invalid attribute value, etc., return
2495 * with appropriate return value.
2496 * - Set up attribute mask field in the object for the supplied common
2497 * attributes that have boolean type.
2498 * - Build the attribute_info struct to hold the value of each supplied
2499 * attribute that has byte array type. Link attribute_info structs
2500 * together to form the extra attribute list of the object.
2501 * - Allocate storage for the Secret Key object.
2502 * - Build the Secret Key object. Allocate storage to hold the big integer
2503 * value for the attribute CKA_VALUE that is required for all the key
2504 * types supported by secret key object.
2505 * This function is called internally with mode = SOFT_CREATE_OBJ_INT.
2509 soft_build_secret_key_object(CK_ATTRIBUTE_PTR
template, CK_ULONG ulAttrNum
,
2510 soft_object_t
*new_object
, CK_ULONG mode
, CK_ULONG key_len
,
2511 CK_KEY_TYPE key_type
)
2515 CK_KEY_TYPE keytype
= (CK_KEY_TYPE
)~0UL;
2516 uint64_t attr_mask
= SECRET_KEY_DEFAULT
;
2519 /* Must set flags if mode != SOFT_UNWRAP_KEY, else must not set */
2521 /* Must not set flags if mode != SOFT_UNWRAP_KEY, else optional */
2524 CK_ATTRIBUTE string_tmp
;
2526 secret_key_obj_t
*sck
;
2527 uchar_t object_type
= 0;
2529 string_tmp
.pValue
= NULL
;
2531 /* Allocate storage for Secret Key Object. */
2532 sck
= calloc(1, sizeof (secret_key_obj_t
));
2534 rv
= CKR_HOST_MEMORY
;
2538 new_object
->object_class_u
.secret_key
= sck
;
2539 new_object
->class = CKO_SECRET_KEY
;
2541 for (i
= 0; i
< ulAttrNum
; i
++) {
2543 /* Secret Key Object Attributes */
2544 switch (template[i
].type
) {
2546 /* common key attributes */
2548 keytype
= *((CK_KEY_TYPE
*)template[i
].pValue
);
2552 case CKA_START_DATE
:
2555 * Allocate storage to hold the attribute
2556 * value with byte array type, and add it to
2557 * the extra attribute list of the object.
2559 rv
= soft_add_extra_attr(&template[i
],
2567 * The following key related attribute types must
2568 * not be specified by C_CreateObject and C_GenerateKey.
2571 case CKA_KEY_GEN_MECHANISM
:
2572 case CKA_ALWAYS_SENSITIVE
:
2573 case CKA_NEVER_EXTRACTABLE
:
2574 rv
= CKR_TEMPLATE_INCONSISTENT
;
2577 /* Key related boolean attributes */
2579 if (*(CK_BBOOL
*)template[i
].pValue
)
2580 attr_mask
|= DERIVE_BOOL_ON
;
2584 if (*(CK_BBOOL
*)template[i
].pValue
)
2585 attr_mask
|= SENSITIVE_BOOL_ON
;
2589 if (*(CK_BBOOL
*)template[i
].pValue
)
2590 attr_mask
|= ENCRYPT_BOOL_ON
;
2592 attr_mask
&= ~ENCRYPT_BOOL_ON
;
2596 if (*(CK_BBOOL
*)template[i
].pValue
)
2597 attr_mask
|= DECRYPT_BOOL_ON
;
2599 attr_mask
&= ~DECRYPT_BOOL_ON
;
2603 if (*(CK_BBOOL
*)template[i
].pValue
)
2604 attr_mask
|= SIGN_BOOL_ON
;
2606 attr_mask
&= ~SIGN_BOOL_ON
;
2610 if (*(CK_BBOOL
*)template[i
].pValue
)
2611 attr_mask
|= VERIFY_BOOL_ON
;
2613 attr_mask
&= ~VERIFY_BOOL_ON
;
2617 if (*(CK_BBOOL
*)template[i
].pValue
)
2618 attr_mask
|= WRAP_BOOL_ON
;
2620 attr_mask
&= ~WRAP_BOOL_ON
;
2624 if (*(CK_BBOOL
*)template[i
].pValue
)
2625 attr_mask
|= UNWRAP_BOOL_ON
;
2627 attr_mask
&= ~UNWRAP_BOOL_ON
;
2630 case CKA_EXTRACTABLE
:
2631 if (*(CK_BBOOL
*)template[i
].pValue
)
2632 attr_mask
|= EXTRACTABLE_BOOL_ON
;
2634 attr_mask
&= ~EXTRACTABLE_BOOL_ON
;
2637 case CKA_MODIFIABLE
:
2638 if ((*(CK_BBOOL
*)template[i
].pValue
) == B_FALSE
)
2639 attr_mask
|= NOT_MODIFIABLE_BOOL_ON
;
2644 if (mode
== SOFT_CREATE_OBJ
) {
2645 if ((template[i
].ulValueLen
== 0) ||
2646 (template[i
].pValue
== NULL
)) {
2647 rv
= CKR_ATTRIBUTE_VALUE_INVALID
;
2653 * Copyin attribute from template
2654 * to a local variable.
2656 rv
= get_bigint_attr_from_template((biginteger_t
*)sck
,
2664 rv
= get_ulong_attr_from_template(&sck
->sk_value_len
,
2672 rv
= get_string_from_template(&string_tmp
,
2679 rv
= soft_parse_common_attrs(&template[i
],
2689 case SOFT_CREATE_OBJ
:
2690 case SOFT_CREATE_OBJ_INT
:
2691 case SOFT_DERIVE_KEY_DH
:
2693 * The key type must be specified in the application's
2694 * template. Otherwise, returns error.
2696 if (keytype
== (CK_KEY_TYPE
)~0UL) {
2697 rv
= CKR_TEMPLATE_INCOMPLETE
;
2703 if (keytype
== (CK_KEY_TYPE
)~0UL) {
2705 * The key type is not specified in the application's
2706 * template, so we use the implied key type based on
2711 if (keytype
!= key_type
) {
2713 * The key type specified in the template
2714 * does not match the implied key type based
2717 rv
= CKR_TEMPLATE_INCONSISTENT
;
2723 * If a key_len is passed as a parameter, it has to
2724 * match the one found in the template.
2727 if (isValueLen
&& sck
->sk_value_len
!= key_len
) {
2728 rv
= CKR_TEMPLATE_INCONSISTENT
;
2732 sck
->sk_value_len
= key_len
;
2736 case SOFT_UNWRAP_KEY
:
2738 * Note that, for mode SOFT_UNWRAP_KEY, key type is not
2739 * implied by the mechanism (key_type), so if it is not
2740 * specified from the attribute template (keytype), it is
2743 if (keytype
== (CK_KEY_TYPE
)~0UL) {
2744 rv
= CKR_TEMPLATE_INCOMPLETE
;
2749 case SOFT_DERIVE_KEY_OTHER
:
2751 * For CKM_MD5_KEY_DERIVATION & CKM_SHA1_KEY_DERIVATION, the
2752 * key type is optional.
2754 if (keytype
== (CK_KEY_TYPE
)~0UL) {
2761 case SOFT_CREATE_OBJ
:
2762 case SOFT_CREATE_OBJ_INT
:
2766 rv
= CKR_TEMPLATE_INCOMPLETE
;
2769 if ((sck
->sk_value_len
< ARCFOUR_MIN_KEY_BYTES
) ||
2770 (sck
->sk_value_len
> ARCFOUR_MAX_KEY_BYTES
)) {
2771 rv
= CKR_ATTRIBUTE_VALUE_INVALID
;
2776 case CKK_GENERIC_SECRET
:
2778 rv
= CKR_TEMPLATE_INCOMPLETE
;
2785 rv
= CKR_TEMPLATE_INCOMPLETE
;
2788 if ((sck
->sk_value_len
!= AES_MIN_KEY_BYTES
) &&
2789 (sck
->sk_value_len
!= AES_192_KEY_BYTES
) &&
2790 (sck
->sk_value_len
!= AES_MAX_KEY_BYTES
)) {
2791 rv
= CKR_ATTRIBUTE_VALUE_INVALID
;
2798 rv
= CKR_TEMPLATE_INCOMPLETE
;
2801 if ((sck
->sk_value_len
< BLOWFISH_MINBYTES
) ||
2802 (sck
->sk_value_len
> BLOWFISH_MAXBYTES
)) {
2803 rv
= CKR_ATTRIBUTE_VALUE_INVALID
;
2811 rv
= CKR_TEMPLATE_INCOMPLETE
;
2814 if (sck
->sk_value_len
!= DES_KEYSIZE
) {
2815 rv
= CKR_ATTRIBUTE_VALUE_INVALID
;
2822 rv
= CKR_TEMPLATE_INCOMPLETE
;
2825 if (sck
->sk_value_len
!= DES2_KEYSIZE
) {
2826 rv
= CKR_ATTRIBUTE_VALUE_INVALID
;
2833 rv
= CKR_TEMPLATE_INCOMPLETE
;
2836 if (sck
->sk_value_len
!= DES3_KEYSIZE
) {
2837 rv
= CKR_ATTRIBUTE_VALUE_INVALID
;
2843 rv
= CKR_TEMPLATE_INCONSISTENT
;
2849 * Templates for internal object creation come from
2850 * applications calls to C_DeriveKey(), for which it
2851 * is OKey to pass a CKA_VALUE_LEN attribute, as
2852 * long as it does not conflict with the length of the
2853 * CKA_VALUE attribute.
2855 if ((mode
!= SOFT_CREATE_OBJ_INT
) ||
2856 ((key_len
> 0) && sck
->sk_value_len
!= key_len
)) {
2857 rv
= CKR_TEMPLATE_INCONSISTENT
;
2864 /* CKA_VALUE must not be specified */
2866 rv
= CKR_TEMPLATE_INCONSISTENT
;
2872 * CKA_VALUE_LEN must be specified by C_GenerateKey
2873 * if mech is CKK_RC4, CKK_AES, CKK_GENERIC_SECRET.
2877 rv
= CKR_TEMPLATE_INCOMPLETE
;
2881 if ((sck
->sk_value_len
< ARCFOUR_MIN_KEY_BYTES
) ||
2882 (sck
->sk_value_len
> ARCFOUR_MAX_KEY_BYTES
)) {
2883 rv
= CKR_ATTRIBUTE_VALUE_INVALID
;
2888 case CKK_GENERIC_SECRET
:
2889 /* arbitrary key length - no length checking */
2891 rv
= CKR_TEMPLATE_INCOMPLETE
;
2898 rv
= CKR_TEMPLATE_INCOMPLETE
;
2902 if ((sck
->sk_value_len
!= AES_MIN_KEY_BYTES
) &&
2903 (sck
->sk_value_len
!= AES_192_KEY_BYTES
) &&
2904 (sck
->sk_value_len
!= AES_MAX_KEY_BYTES
)) {
2905 rv
= CKR_ATTRIBUTE_VALUE_INVALID
;
2913 rv
= CKR_TEMPLATE_INCOMPLETE
;
2916 if ((sck
->sk_value_len
< BLOWFISH_MINBYTES
) ||
2917 (sck
->sk_value_len
> BLOWFISH_MAXBYTES
)) {
2918 rv
= CKR_ATTRIBUTE_VALUE_INVALID
;
2927 /* CKA_VALUE_LEN attribute does not apply to DES<n> */
2929 rv
= CKR_TEMPLATE_INCONSISTENT
;
2935 rv
= CKR_TEMPLATE_INCONSISTENT
;
2940 case SOFT_UNWRAP_KEY
:
2942 * According to v2.11 of PKCS#11 spec, neither CKA_VALUE nor
2943 * CKA_VALUE_LEN can be be specified; however v2.20 has this
2944 * restriction removed, perhaps because it makes it hard to
2945 * determine variable-length key sizes. This case statement
2946 * complied with v2.20.
2949 rv
= CKR_TEMPLATE_INCONSISTENT
;
2955 * CKA_VALUE_LEN is optional
2956 * if key is CKK_RC4, CKK_AES, CKK_GENERIC_SECRET
2957 * and the unwrapping mech is *_CBC_PAD.
2959 * CKA_VALUE_LEN is required
2960 * if key is CKK_RC4, CKK_AES, CKK_GENERIC_SECRET
2961 * and the unwrapping mech is *_ECB or *_CBC.
2963 * since mech is not known at this point, CKA_VALUE_LEN is
2964 * treated as optional and the caller needs to enforce it.
2968 if ((sck
->sk_value_len
<
2969 ARCFOUR_MIN_KEY_BYTES
) ||
2970 (sck
->sk_value_len
>
2971 ARCFOUR_MAX_KEY_BYTES
)) {
2972 rv
= CKR_ATTRIBUTE_VALUE_INVALID
;
2978 case CKK_GENERIC_SECRET
:
2979 /* arbitrary key length - no length checking */
2984 if ((sck
->sk_value_len
!= AES_MIN_KEY_BYTES
) &&
2985 (sck
->sk_value_len
!= AES_192_KEY_BYTES
) &&
2986 (sck
->sk_value_len
!= AES_MAX_KEY_BYTES
)) {
2987 rv
= CKR_ATTRIBUTE_VALUE_INVALID
;
2995 ((sck
->sk_value_len
< BLOWFISH_MINBYTES
) ||
2996 (sck
->sk_value_len
> BLOWFISH_MAXBYTES
))) {
2997 rv
= CKR_ATTRIBUTE_VALUE_INVALID
;
3005 /* CKA_VALUE_LEN attribute does not apply to DES<n> */
3007 rv
= CKR_TEMPLATE_INCONSISTENT
;
3013 rv
= CKR_TEMPLATE_INCONSISTENT
;
3018 case SOFT_DERIVE_KEY_DH
:
3019 /* CKA_VALUE must not be specified */
3021 rv
= CKR_TEMPLATE_INCONSISTENT
;
3027 * CKA_VALUE_LEN is optional
3028 * if mech is CKK_RC4, CKK_AES, CKK_GENERIC_SECRET.
3032 if ((sck
->sk_value_len
<
3033 ARCFOUR_MIN_KEY_BYTES
) ||
3034 (sck
->sk_value_len
>
3035 ARCFOUR_MAX_KEY_BYTES
)) {
3036 rv
= CKR_ATTRIBUTE_VALUE_INVALID
;
3042 case CKK_GENERIC_SECRET
:
3043 /* arbitrary key length - no length checking */
3048 if ((sck
->sk_value_len
!= AES_MIN_KEY_BYTES
) &&
3049 (sck
->sk_value_len
!= AES_192_KEY_BYTES
) &&
3050 (sck
->sk_value_len
!= AES_MAX_KEY_BYTES
)) {
3051 rv
= CKR_ATTRIBUTE_VALUE_INVALID
;
3060 ((sck
->sk_value_len
< BLOWFISH_MINBYTES
) ||
3061 (sck
->sk_value_len
> BLOWFISH_MAXBYTES
))) {
3062 rv
= CKR_ATTRIBUTE_VALUE_INVALID
;
3070 /* CKA_VALUE_LEN attribute does not apply to DES<n> */
3072 rv
= CKR_TEMPLATE_INCONSISTENT
;
3078 rv
= CKR_TEMPLATE_INCONSISTENT
;
3083 case SOFT_DERIVE_KEY_OTHER
:
3084 /* CKA_VALUE must not be specified */
3086 rv
= CKR_TEMPLATE_INCONSISTENT
;
3092 * CKA_VALUE_LEN is an optional attribute for
3093 * CKM_SHA1_KEY_DERIVATION and CKM_MD5_KEY_DERIVATION
3094 * if mech is CKK_RC4, CKK_AES, CKK_GENERIC_SECRET.
3097 case CKK_GENERIC_SECRET
:
3101 * No need to check key length value here, it will be
3102 * validated later in soft_key_derive_check_length().
3109 /* CKA_VALUE_LEN attribute does not apply to DES<n> */
3111 rv
= CKR_TEMPLATE_INCONSISTENT
;
3117 rv
= CKR_TEMPLATE_INCONSISTENT
;
3123 /* Set up object. */
3124 new_object
->key_type
= keytype
;
3125 new_object
->object_type
= object_type
;
3126 new_object
->bool_attr_mask
= attr_mask
;
3128 rv
= soft_add_extra_attr(&string_tmp
, new_object
);
3131 string_attr_cleanup(&string_tmp
);
3137 * cleanup the storage allocated to the local variables.
3139 bigint_attr_cleanup((biginteger_t
*)sck
);
3140 string_attr_cleanup(&string_tmp
);
3143 * cleanup the storage allocated inside the object itself.
3145 soft_cleanup_object(new_object
);
3152 * Build a Domain Parameter Object.
3154 * - Parse the object's template, and when an error is detected such as
3155 * invalid attribute type, invalid attribute value, etc., return
3156 * with appropriate return value.
3157 * - Allocate storage for the Domain Parameter object.
3158 * - Build the Domain Parameter object according to the key type. Allocate
3159 * storage to hold the big integer value for the supplied attributes
3160 * that are required for a certain key type.
3164 soft_build_domain_parameters_object(CK_ATTRIBUTE_PTR
template,
3165 CK_ULONG ulAttrNum
, soft_object_t
*new_object
)
3169 CK_KEY_TYPE keytype
= (CK_KEY_TYPE
)~0UL;
3172 /* Must set flags */
3176 /* Must not set flags */
3177 int isPrimeBits
= 0;
3178 int isSubPrimeBits
= 0;
3181 biginteger_t subprime
;
3183 CK_ATTRIBUTE string_tmp
;
3186 uchar_t object_type
= 0;
3188 /* prevent bigint_attr_cleanup from freeing invalid attr value */
3189 (void) memset(&prime
, 0x0, sizeof (biginteger_t
));
3190 (void) memset(&subprime
, 0x0, sizeof (biginteger_t
));
3191 (void) memset(&base
, 0x0, sizeof (biginteger_t
));
3192 string_tmp
.pValue
= NULL
;
3194 for (i
= 0; i
< ulAttrNum
; i
++) {
3196 /* Domain Parameters Object Attributes */
3197 switch (template[i
].type
) {
3199 /* common domain parameter attribute */
3201 keytype
= *((CK_KEY_TYPE
*)template[i
].pValue
);
3205 * The following common domain parameter attribute
3206 * must not be specified by C_CreateObject.
3209 rv
= CKR_TEMPLATE_INCONSISTENT
;
3213 * The following domain parameter attributes must be
3214 * specified according to the key type by
3220 * Copyin big integer attribute from template
3221 * to a local variable.
3223 rv
= get_bigint_attr_from_template(&prime
,
3231 rv
= get_bigint_attr_from_template(&subprime
,
3239 rv
= get_bigint_attr_from_template(&base
,
3245 case CKA_PRIME_BITS
:
3249 case CKA_SUB_PRIME_BITS
:
3255 rv
= get_string_from_template(&string_tmp
,
3262 rv
= soft_parse_common_attrs(&template[i
],
3271 /* Allocate storage for Domain Parameters Object. */
3272 dom
= calloc(1, sizeof (domain_obj_t
));
3274 rv
= CKR_HOST_MEMORY
;
3278 new_object
->object_class_u
.domain
= dom
;
3279 new_object
->class = CKO_DOMAIN_PARAMETERS
;
3281 if (keytype
== (CK_KEY_TYPE
)~0UL) {
3282 rv
= CKR_TEMPLATE_INCOMPLETE
;
3286 new_object
->key_type
= keytype
;
3288 /* Supported key types of the Domain Parameters Object */
3291 if (isPrimeBits
|| isSubPrimeBits
) {
3292 rv
= CKR_TEMPLATE_INCONSISTENT
;
3296 if (isPrime
&& isSubprime
&& isBase
) {
3298 * Copy big integer attribute value to the
3299 * designated place in the domain parameter
3302 copy_bigint_attr(&prime
, KEY_DOM_DSA_PRIME(dom
));
3304 copy_bigint_attr(&subprime
, KEY_DOM_DSA_SUBPRIME(dom
));
3306 copy_bigint_attr(&base
, KEY_DOM_DSA_BASE(dom
));
3308 rv
= CKR_TEMPLATE_INCOMPLETE
;
3314 if (isPrimeBits
|| isSubprime
|| isSubPrimeBits
) {
3315 rv
= CKR_TEMPLATE_INCONSISTENT
;
3319 if (isPrime
&& isBase
) {
3320 copy_bigint_attr(&prime
, KEY_DOM_DH_PRIME(dom
));
3322 copy_bigint_attr(&base
, KEY_DOM_DH_BASE(dom
));
3324 rv
= CKR_TEMPLATE_INCOMPLETE
;
3330 if (isPrimeBits
|| isSubPrimeBits
) {
3331 rv
= CKR_TEMPLATE_INCONSISTENT
;
3335 if (isPrime
&& isSubprime
&& isBase
) {
3336 copy_bigint_attr(&prime
, KEY_DOM_DH942_PRIME(dom
));
3338 copy_bigint_attr(&base
, KEY_DOM_DH942_BASE(dom
));
3340 copy_bigint_attr(&subprime
,
3341 KEY_DOM_DH942_SUBPRIME(dom
));
3343 rv
= CKR_TEMPLATE_INCOMPLETE
;
3349 rv
= CKR_TEMPLATE_INCONSISTENT
;
3353 new_object
->object_type
= object_type
;
3356 rv
= soft_add_extra_attr(&string_tmp
, new_object
);
3359 string_attr_cleanup(&string_tmp
);
3366 * cleanup the storage allocated to the local variables.
3368 bigint_attr_cleanup(&prime
);
3369 bigint_attr_cleanup(&subprime
);
3370 bigint_attr_cleanup(&base
);
3371 string_attr_cleanup(&string_tmp
);
3374 * cleanup the storage allocated inside the object itself.
3376 soft_cleanup_object(new_object
);
3382 * Build a Certificate Object
3384 * - Parse the object's template, and when an error is detected such as
3385 * invalid attribute type, invalid attribute value, etc., return
3386 * with appropriate return value.
3387 * - Allocate storage for the Certificate object
3390 soft_build_certificate_object(CK_ATTRIBUTE_PTR
template,
3391 CK_ULONG ulAttrNum
, soft_object_t
*new_object
,
3392 CK_CERTIFICATE_TYPE cert_type
)
3394 uint64_t attr_mask
= 0;
3399 int subject_set
= 0;
3400 certificate_obj_t
*cert
;
3401 /* certificate type defaults to the value given as a parameter */
3402 CK_CERTIFICATE_TYPE certtype
= cert_type
;
3403 CK_ATTRIBUTE string_tmp
;
3405 uchar_t object_type
= 0;
3408 * Look for the certificate type attribute and do some
3409 * sanity checking before creating the structures.
3411 for (i
= 0; i
< ulAttrNum
; i
++) {
3412 /* Certificate Object Attributes */
3413 switch (template[i
].type
) {
3414 case CKA_CERTIFICATE_TYPE
:
3416 *((CK_CERTIFICATE_TYPE
*)template[i
].pValue
);
3430 /* The certificate type MUST be specified */
3431 if (certtype
!= CKC_X_509
&& certtype
!= CKC_X_509_ATTR_CERT
)
3432 return (CKR_TEMPLATE_INCOMPLETE
);
3435 * For X.509 certs, the CKA_SUBJECT and CKA_VALUE
3436 * must be present at creation time.
3438 if (certtype
== CKC_X_509
&&
3439 (!subject_set
|| !value_set
))
3440 return (CKR_TEMPLATE_INCOMPLETE
);
3443 * For X.509 Attribute certs, the CKA_OWNER and CKA_VALUE
3444 * must be present at creation time.
3446 if (certtype
== CKC_X_509_ATTR_CERT
&&
3447 (!owner_set
|| !value_set
))
3448 return (CKR_TEMPLATE_INCOMPLETE
);
3450 string_tmp
.pValue
= NULL
;
3451 cert
= calloc(1, sizeof (certificate_obj_t
));
3453 return (CKR_HOST_MEMORY
);
3455 cert
->certificate_type
= certtype
;
3457 for (i
= 0; i
< ulAttrNum
; i
++) {
3458 /* Certificate Object Attributes */
3461 switch (template[i
].type
) {
3463 rv
= get_cert_attr_from_template(
3464 &cert
->cert_type_u
.x509
.subject
,
3468 rv
= get_cert_attr_from_template(
3469 &cert
->cert_type_u
.x509
.value
,
3474 rv
= get_string_from_template(
3482 case CKA_SERIAL_NUMBER
:
3483 rv
= soft_add_extra_attr(&template[i
],
3486 case CKA_MODIFIABLE
:
3487 if ((*(CK_BBOOL
*)template[i
].pValue
) ==
3490 NOT_MODIFIABLE_BOOL_ON
;
3492 case CKA_CERTIFICATE_TYPE
:
3495 rv
= soft_parse_common_attrs(
3496 &template[i
], &object_type
);
3501 case CKC_X_509_ATTR_CERT
:
3502 switch (template[i
].type
) {
3504 rv
= get_cert_attr_from_template(
3505 &cert
->cert_type_u
.x509_attr
.owner
,
3509 rv
= get_cert_attr_from_template(
3510 &cert
->cert_type_u
.x509_attr
.value
,
3515 rv
= get_string_from_template(
3516 &string_tmp
, &template[i
]);
3520 case CKA_SERIAL_NUMBER
:
3522 case CKA_ATTR_TYPES
:
3523 rv
= soft_add_extra_attr(&template[i
],
3527 case CKA_MODIFIABLE
:
3528 if ((*(CK_BBOOL
*)template[i
].pValue
) ==
3531 NOT_MODIFIABLE_BOOL_ON
;
3533 case CKA_CERTIFICATE_TYPE
:
3536 rv
= soft_parse_common_attrs(
3537 &template[i
], &object_type
);
3544 rv
= CKR_TEMPLATE_INCOMPLETE
;
3550 new_object
->object_class_u
.certificate
= cert
;
3551 new_object
->class = CKO_CERTIFICATE
;
3552 new_object
->object_type
= object_type
;
3553 new_object
->cert_type
= certtype
;
3554 new_object
->bool_attr_mask
= attr_mask
;
3556 rv
= soft_add_extra_attr(&string_tmp
, new_object
);
3559 string_attr_cleanup(&string_tmp
);
3565 soft_cleanup_cert_object(new_object
);
3572 * Validate the attribute types in the object's template. Then,
3573 * call the appropriate build function according to the class of
3574 * the object specified in the template.
3576 * Note: The following classes of objects are supported:
3580 * - CKO_DOMAIN_PARAMETERS
3585 soft_build_object(CK_ATTRIBUTE_PTR
template, CK_ULONG ulAttrNum
,
3586 soft_object_t
*new_object
)
3589 CK_OBJECT_CLASS
class = (CK_OBJECT_CLASS
)~0UL;
3592 if (template == NULL
) {
3593 return (CKR_ARGUMENTS_BAD
);
3596 /* Validate the attribute type in the template. */
3597 rv
= soft_validate_attr(template, ulAttrNum
, &class);
3601 * CKA_CLASS is a mandatory attribute for C_CreateObject
3603 if (class == (CK_OBJECT_CLASS
)~0UL)
3604 return (CKR_TEMPLATE_INCOMPLETE
);
3607 * Call the appropriate function based on the supported class
3611 case CKO_PUBLIC_KEY
:
3612 rv
= soft_build_public_key_object(template, ulAttrNum
,
3613 new_object
, SOFT_CREATE_OBJ
, (CK_KEY_TYPE
)~0UL);
3616 case CKO_PRIVATE_KEY
:
3617 rv
= soft_build_private_key_object(template, ulAttrNum
,
3618 new_object
, SOFT_CREATE_OBJ
, (CK_KEY_TYPE
)~0UL);
3621 case CKO_SECRET_KEY
:
3622 rv
= soft_build_secret_key_object(template, ulAttrNum
,
3623 new_object
, SOFT_CREATE_OBJ
, 0, (CK_KEY_TYPE
)~0UL);
3626 case CKO_DOMAIN_PARAMETERS
:
3627 rv
= soft_build_domain_parameters_object(template, ulAttrNum
,
3631 case CKO_CERTIFICATE
:
3632 rv
= soft_build_certificate_object(template, ulAttrNum
,
3633 new_object
, (CK_CERTIFICATE_TYPE
)~0UL);
3637 case CKO_HW_FEATURE
:
3638 case CKO_VENDOR_DEFINED
:
3640 return (CKR_ATTRIBUTE_VALUE_INVALID
);
3647 * Validate the attribute types in the object's template. Then,
3648 * call the appropriate build function according to the class of
3649 * the object specified in the template.
3653 soft_build_key(CK_ATTRIBUTE_PTR
template, CK_ULONG ulAttrNum
,
3654 soft_object_t
*new_object
, CK_OBJECT_CLASS
class, CK_KEY_TYPE key_type
,
3655 CK_ULONG key_len
, CK_ULONG mode
)
3659 CK_OBJECT_CLASS temp_class
= (CK_OBJECT_CLASS
)~0UL;
3661 /* Validate the attribute type in the template. */
3662 if ((template != NULL
) && (ulAttrNum
!= 0)) {
3663 rv
= soft_validate_attr(template, ulAttrNum
, &temp_class
);
3669 * If either the class from the parameter list ("class") or
3670 * the class from the template ("temp_class") is not specified,
3671 * try to use the other one.
3673 if (temp_class
== (CK_OBJECT_CLASS
)~0UL) {
3675 } else if (class == (CK_OBJECT_CLASS
)~0UL) {
3679 /* If object class is still not specified, template is incomplete. */
3680 if (class == (CK_OBJECT_CLASS
)~0UL)
3681 return (CKR_TEMPLATE_INCOMPLETE
);
3683 /* Class should match if specified in both parameters and template. */
3684 if (class != temp_class
)
3685 return (CKR_TEMPLATE_INCONSISTENT
);
3688 * Call the appropriate function based on the supported class
3692 case CKO_PUBLIC_KEY
:
3694 /* Unwrapping public keys is not supported. */
3695 if (mode
== SOFT_UNWRAP_KEY
) {
3696 rv
= CKR_ATTRIBUTE_VALUE_INVALID
;
3700 rv
= soft_build_public_key_object(template, ulAttrNum
,
3701 new_object
, mode
, key_type
);
3704 case CKO_PRIVATE_KEY
:
3706 rv
= soft_build_private_key_object(template, ulAttrNum
,
3707 new_object
, mode
, key_type
);
3710 case CKO_SECRET_KEY
:
3712 rv
= soft_build_secret_key_object(template, ulAttrNum
,
3713 new_object
, mode
, key_len
, key_type
);
3716 case CKO_DOMAIN_PARAMETERS
:
3718 /* Unwrapping domain parameters is not supported. */
3719 if (mode
== SOFT_UNWRAP_KEY
) {
3720 rv
= CKR_ATTRIBUTE_VALUE_INVALID
;
3724 rv
= soft_build_domain_parameters_object(template, ulAttrNum
,
3729 case CKO_CERTIFICATE
:
3730 case CKO_HW_FEATURE
:
3731 case CKO_VENDOR_DEFINED
:
3733 return (CKR_ATTRIBUTE_VALUE_INVALID
);
3741 * Get the value of a requested attribute that is common to all supported
3742 * classes (i.e. public key, private key, secret key, domain parameters,
3743 * and certificate classes).
3746 soft_get_common_attrs(soft_object_t
*object_p
, CK_ATTRIBUTE_PTR
template,
3747 uchar_t object_type
)
3752 switch (template->type
) {
3755 return (get_ulong_attr_from_object(object_p
->class,
3758 /* default boolean attributes */
3760 template->ulValueLen
= sizeof (CK_BBOOL
);
3761 if (template->pValue
== NULL
) {
3764 if (object_type
& TOKEN_OBJECT
)
3765 *((CK_BBOOL
*)template->pValue
) = B_TRUE
;
3767 *((CK_BBOOL
*)template->pValue
) = B_FALSE
;
3772 template->ulValueLen
= sizeof (CK_BBOOL
);
3773 if (template->pValue
== NULL
) {
3776 if (object_type
& PRIVATE_OBJECT
)
3777 *((CK_BBOOL
*)template->pValue
) = B_TRUE
;
3779 *((CK_BBOOL
*)template->pValue
) = B_FALSE
;
3782 case CKA_MODIFIABLE
:
3783 template->ulValueLen
= sizeof (CK_BBOOL
);
3784 if (template->pValue
== NULL
) {
3787 if ((object_p
->bool_attr_mask
) & NOT_MODIFIABLE_BOOL_ON
)
3788 *((CK_BBOOL
*)template->pValue
) = B_FALSE
;
3790 *((CK_BBOOL
*)template->pValue
) = B_TRUE
;
3794 return (get_extra_attr_from_object(object_p
,
3799 * The specified attribute for the object is invalid.
3800 * (the object does not possess such an attribute.)
3802 template->ulValueLen
= (CK_ULONG
)-1;
3803 return (CKR_ATTRIBUTE_TYPE_INVALID
);
3810 * Get the value of a requested attribute that is common to all key objects
3811 * (i.e. public key, private key and secret key).
3814 soft_get_common_key_attrs(soft_object_t
*object_p
, CK_ATTRIBUTE_PTR
template)
3817 switch (template->type
) {
3820 return (get_ulong_attr_from_object(object_p
->key_type
,
3824 case CKA_START_DATE
:
3827 * The above extra attributes have byte array type.
3829 return (get_extra_attr_from_object(object_p
,
3832 /* Key related boolean attributes */
3834 return (get_bool_attr_from_object(object_p
,
3835 LOCAL_BOOL_ON
, template));
3838 return (get_bool_attr_from_object(object_p
,
3839 DERIVE_BOOL_ON
, template));
3841 case CKA_KEY_GEN_MECHANISM
:
3842 return (get_ulong_attr_from_object(object_p
->mechanism
,
3846 return (CKR_ATTRIBUTE_TYPE_INVALID
);
3851 * Get the value of a requested attribute of a Public Key Object.
3853 * Rule: All the attributes in the public key object can be revealed.
3856 soft_get_public_key_attribute(soft_object_t
*object_p
,
3857 CK_ATTRIBUTE_PTR
template)
3861 CK_KEY_TYPE keytype
= object_p
->key_type
;
3863 switch (template->type
) {
3868 * The above extra attributes have byte array type.
3870 return (get_extra_attr_from_object(object_p
,
3873 /* Key related boolean attributes */
3875 return (get_bool_attr_from_object(object_p
,
3876 ENCRYPT_BOOL_ON
, template));
3879 return (get_bool_attr_from_object(object_p
,
3880 VERIFY_BOOL_ON
, template));
3882 case CKA_VERIFY_RECOVER
:
3883 return (get_bool_attr_from_object(object_p
,
3884 VERIFY_RECOVER_BOOL_ON
, template));
3887 return (get_bool_attr_from_object(object_p
,
3888 WRAP_BOOL_ON
, template));
3891 return (get_bool_attr_from_object(object_p
,
3892 TRUSTED_BOOL_ON
, template));
3896 * This attribute is valid only for RSA public key
3899 if (keytype
== CKK_RSA
) {
3900 return (get_bigint_attr_from_object(
3901 OBJ_PUB_RSA_MOD(object_p
), template));
3903 template->ulValueLen
= (CK_ULONG
)-1;
3904 return (CKR_ATTRIBUTE_TYPE_INVALID
);
3907 case CKA_PUBLIC_EXPONENT
:
3908 if (keytype
== CKK_RSA
) {
3909 return (get_bigint_attr_from_object(
3910 OBJ_PUB_RSA_PUBEXPO(object_p
), template));
3912 template->ulValueLen
= (CK_ULONG
)-1;
3913 return (CKR_ATTRIBUTE_TYPE_INVALID
);
3916 case CKA_MODULUS_BITS
:
3917 if (keytype
== CKK_RSA
) {
3918 return (get_ulong_attr_from_object(
3919 OBJ_PUB_RSA_MOD_BITS(object_p
), template));
3921 template->ulValueLen
= (CK_ULONG
)-1;
3922 return (CKR_ATTRIBUTE_TYPE_INVALID
);
3928 return (get_bigint_attr_from_object(
3929 OBJ_PUB_DSA_PRIME(object_p
), template));
3932 return (get_bigint_attr_from_object(
3933 OBJ_PUB_DH_PRIME(object_p
), template));
3936 return (get_bigint_attr_from_object(
3937 OBJ_PUB_DH942_PRIME(object_p
), template));
3940 template->ulValueLen
= (CK_ULONG
)-1;
3941 return (CKR_ATTRIBUTE_TYPE_INVALID
);
3947 return (get_bigint_attr_from_object(
3948 OBJ_PUB_DSA_SUBPRIME(object_p
), template));
3951 return (get_bigint_attr_from_object(
3952 OBJ_PUB_DH942_SUBPRIME(object_p
), template));
3955 template->ulValueLen
= (CK_ULONG
)-1;
3956 return (CKR_ATTRIBUTE_TYPE_INVALID
);
3962 return (get_bigint_attr_from_object(
3963 OBJ_PUB_DSA_BASE(object_p
), template));
3966 return (get_bigint_attr_from_object(
3967 OBJ_PUB_DH_BASE(object_p
), template));
3970 return (get_bigint_attr_from_object(
3971 OBJ_PUB_DH942_BASE(object_p
), template));
3974 template->ulValueLen
= (CK_ULONG
)-1;
3975 return (CKR_ATTRIBUTE_TYPE_INVALID
);
3979 return (get_bigint_attr_from_object(
3980 OBJ_PUB_EC_POINT(object_p
), template));
3985 return (get_bigint_attr_from_object(
3986 OBJ_PUB_DSA_VALUE(object_p
), template));
3989 return (get_bigint_attr_from_object(
3990 OBJ_PUB_DH_VALUE(object_p
), template));
3993 return (get_bigint_attr_from_object(
3994 OBJ_PUB_DH942_VALUE(object_p
), template));
3997 template->ulValueLen
= (CK_ULONG
)-1;
3998 return (CKR_ATTRIBUTE_TYPE_INVALID
);
4003 * First, get the value of the request attribute defined
4004 * in the list of common key attributes. If the request
4005 * attribute is not found in that list, then get the
4006 * attribute from the list of common attributes.
4008 rv
= soft_get_common_key_attrs(object_p
, template);
4009 if (rv
== CKR_ATTRIBUTE_TYPE_INVALID
) {
4010 rv
= soft_get_common_attrs(object_p
, template,
4011 object_p
->object_type
);
4021 * Get the value of a requested attribute of a Private Key Object.
4023 * Rule: All the attributes in the private key object can be revealed
4024 * except those marked with footnote number "7" when the object
4025 * has its CKA_SENSITIVE attribute set to TRUE or its
4026 * CKA_EXTRACTABLE attribute set to FALSE (p.88 in PKCS11 spec.).
4029 soft_get_private_key_attribute(soft_object_t
*object_p
,
4030 CK_ATTRIBUTE_PTR
template)
4034 CK_KEY_TYPE keytype
= object_p
->key_type
;
4038 * If the following specified attributes for the private key
4039 * object cannot be revealed because the object is sensitive
4040 * or unextractable, then the ulValueLen is set to -1.
4042 if ((object_p
->bool_attr_mask
& SENSITIVE_BOOL_ON
) ||
4043 !(object_p
->bool_attr_mask
& EXTRACTABLE_BOOL_ON
)) {
4045 switch (template->type
) {
4046 case CKA_PRIVATE_EXPONENT
:
4049 case CKA_EXPONENT_1
:
4050 case CKA_EXPONENT_2
:
4051 case CKA_COEFFICIENT
:
4053 template->ulValueLen
= (CK_ULONG
)-1;
4054 return (CKR_ATTRIBUTE_SENSITIVE
);
4058 switch (template->type
) {
4063 * The above extra attributes have byte array type.
4065 return (get_extra_attr_from_object(object_p
,
4068 /* Key related boolean attributes */
4070 return (get_bool_attr_from_object(object_p
,
4071 SENSITIVE_BOOL_ON
, template));
4073 case CKA_SECONDARY_AUTH
:
4074 return (get_bool_attr_from_object(object_p
,
4075 SECONDARY_AUTH_BOOL_ON
, template));
4078 return (get_bool_attr_from_object(object_p
,
4079 DECRYPT_BOOL_ON
, template));
4082 return (get_bool_attr_from_object(object_p
,
4083 SIGN_BOOL_ON
, template));
4085 case CKA_SIGN_RECOVER
:
4086 return (get_bool_attr_from_object(object_p
,
4087 SIGN_RECOVER_BOOL_ON
, template));
4090 return (get_bool_attr_from_object(object_p
,
4091 UNWRAP_BOOL_ON
, template));
4093 case CKA_EXTRACTABLE
:
4094 return (get_bool_attr_from_object(object_p
,
4095 EXTRACTABLE_BOOL_ON
, template));
4097 case CKA_ALWAYS_SENSITIVE
:
4098 return (get_bool_attr_from_object(object_p
,
4099 ALWAYS_SENSITIVE_BOOL_ON
, template));
4101 case CKA_NEVER_EXTRACTABLE
:
4102 return (get_bool_attr_from_object(object_p
,
4103 NEVER_EXTRACTABLE_BOOL_ON
, template));
4106 if (keytype
== CKK_RSA
) {
4107 return (get_bigint_attr_from_object(
4108 OBJ_PRI_RSA_MOD(object_p
), template));
4110 template->ulValueLen
= (CK_ULONG
)-1;
4111 rv
= CKR_ATTRIBUTE_TYPE_INVALID
;
4115 case CKA_PUBLIC_EXPONENT
:
4116 if (keytype
== CKK_RSA
) {
4117 return (get_bigint_attr_from_object(
4118 OBJ_PRI_RSA_PUBEXPO(object_p
), template));
4120 template->ulValueLen
= (CK_ULONG
)-1;
4121 rv
= CKR_ATTRIBUTE_TYPE_INVALID
;
4125 case CKA_PRIVATE_EXPONENT
:
4126 if (keytype
== CKK_RSA
) {
4127 return (get_bigint_attr_from_object(
4128 OBJ_PRI_RSA_PRIEXPO(object_p
), template));
4130 template->ulValueLen
= (CK_ULONG
)-1;
4131 rv
= CKR_ATTRIBUTE_TYPE_INVALID
;
4136 if (keytype
== CKK_RSA
) {
4137 return (get_bigint_attr_from_object(
4138 OBJ_PRI_RSA_PRIME1(object_p
), template));
4140 template->ulValueLen
= (CK_ULONG
)-1;
4141 rv
= CKR_ATTRIBUTE_TYPE_INVALID
;
4146 if (keytype
== CKK_RSA
) {
4147 return (get_bigint_attr_from_object(
4148 OBJ_PRI_RSA_PRIME2(object_p
), template));
4150 template->ulValueLen
= (CK_ULONG
)-1;
4151 rv
= CKR_ATTRIBUTE_TYPE_INVALID
;
4155 case CKA_EXPONENT_1
:
4156 if (keytype
== CKK_RSA
) {
4157 return (get_bigint_attr_from_object(
4158 OBJ_PRI_RSA_EXPO1(object_p
), template));
4160 template->ulValueLen
= (CK_ULONG
)-1;
4161 rv
= CKR_ATTRIBUTE_TYPE_INVALID
;
4165 case CKA_EXPONENT_2
:
4166 if (keytype
== CKK_RSA
) {
4167 return (get_bigint_attr_from_object(
4168 OBJ_PRI_RSA_EXPO2(object_p
), template));
4170 template->ulValueLen
= (CK_ULONG
)-1;
4171 rv
= CKR_ATTRIBUTE_TYPE_INVALID
;
4175 case CKA_COEFFICIENT
:
4176 if (keytype
== CKK_RSA
) {
4177 return (get_bigint_attr_from_object(
4178 OBJ_PRI_RSA_COEF(object_p
), template));
4180 template->ulValueLen
= (CK_ULONG
)-1;
4181 rv
= CKR_ATTRIBUTE_TYPE_INVALID
;
4185 case CKA_VALUE_BITS
:
4186 if (keytype
== CKK_DH
) {
4187 return (get_ulong_attr_from_object(
4188 OBJ_PRI_DH_VAL_BITS(object_p
), template));
4190 template->ulValueLen
= (CK_ULONG
)-1;
4191 rv
= CKR_ATTRIBUTE_TYPE_INVALID
;
4198 return (get_bigint_attr_from_object(
4199 OBJ_PRI_DSA_PRIME(object_p
), template));
4202 return (get_bigint_attr_from_object(
4203 OBJ_PRI_DH_PRIME(object_p
), template));
4206 return (get_bigint_attr_from_object(
4207 OBJ_PRI_DH942_PRIME(object_p
), template));
4210 template->ulValueLen
= (CK_ULONG
)-1;
4211 return (CKR_ATTRIBUTE_TYPE_INVALID
);
4217 return (get_bigint_attr_from_object(
4218 OBJ_PRI_DSA_SUBPRIME(object_p
), template));
4221 return (get_bigint_attr_from_object(
4222 OBJ_PRI_DH942_SUBPRIME(object_p
), template));
4225 template->ulValueLen
= (CK_ULONG
)-1;
4226 return (CKR_ATTRIBUTE_TYPE_INVALID
);
4232 return (get_bigint_attr_from_object(
4233 OBJ_PRI_DSA_BASE(object_p
), template));
4236 return (get_bigint_attr_from_object(
4237 OBJ_PRI_DH_BASE(object_p
), template));
4240 return (get_bigint_attr_from_object(
4241 OBJ_PRI_DH942_BASE(object_p
), template));
4244 template->ulValueLen
= (CK_ULONG
)-1;
4245 return (CKR_ATTRIBUTE_TYPE_INVALID
);
4251 return (get_bigint_attr_from_object(
4252 OBJ_PRI_DSA_VALUE(object_p
), template));
4255 return (get_bigint_attr_from_object(
4256 OBJ_PRI_DH_VALUE(object_p
), template));
4259 return (get_bigint_attr_from_object(
4260 OBJ_PRI_DH942_VALUE(object_p
), template));
4263 return (get_bigint_attr_from_object(
4264 OBJ_PRI_EC_VALUE(object_p
), template));
4267 template->ulValueLen
= (CK_ULONG
)-1;
4268 return (CKR_ATTRIBUTE_TYPE_INVALID
);
4273 * First, get the value of the request attribute defined
4274 * in the list of common key attributes. If the request
4275 * attribute is not found in that list, then get the
4276 * attribute from the list of common attributes.
4278 rv
= soft_get_common_key_attrs(object_p
, template);
4279 if (rv
== CKR_ATTRIBUTE_TYPE_INVALID
) {
4280 rv
= soft_get_common_attrs(object_p
, template,
4281 object_p
->object_type
);
4291 * Get the value of a requested attribute of a Secret Key Object.
4293 * Rule: All the attributes in the secret key object can be revealed
4294 * except those marked with footnote number "7" when the object
4295 * has its CKA_SENSITIVE attribute set to TRUE or its
4296 * CKA_EXTRACTABLE attribute set to FALSE (p.88 in PKCS11 spec.).
4299 soft_get_secret_key_attribute(soft_object_t
*object_p
,
4300 CK_ATTRIBUTE_PTR
template)
4304 CK_KEY_TYPE keytype
= object_p
->key_type
;
4306 switch (template->type
) {
4308 /* Key related boolean attributes */
4310 return (get_bool_attr_from_object(object_p
,
4311 SENSITIVE_BOOL_ON
, template));
4314 return (get_bool_attr_from_object(object_p
,
4315 ENCRYPT_BOOL_ON
, template));
4318 return (get_bool_attr_from_object(object_p
,
4319 DECRYPT_BOOL_ON
, template));
4322 return (get_bool_attr_from_object(object_p
,
4323 SIGN_BOOL_ON
, template));
4326 return (get_bool_attr_from_object(object_p
,
4327 VERIFY_BOOL_ON
, template));
4330 return (get_bool_attr_from_object(object_p
,
4331 WRAP_BOOL_ON
, template));
4334 return (get_bool_attr_from_object(object_p
,
4335 UNWRAP_BOOL_ON
, template));
4337 case CKA_EXTRACTABLE
:
4338 return (get_bool_attr_from_object(object_p
,
4339 EXTRACTABLE_BOOL_ON
, template));
4341 case CKA_ALWAYS_SENSITIVE
:
4342 return (get_bool_attr_from_object(object_p
,
4343 ALWAYS_SENSITIVE_BOOL_ON
, template));
4345 case CKA_NEVER_EXTRACTABLE
:
4346 return (get_bool_attr_from_object(object_p
,
4347 NEVER_EXTRACTABLE_BOOL_ON
, template));
4352 * If the specified attribute for the secret key object
4353 * cannot be revealed because the object is sensitive
4354 * or unextractable, then the ulValueLen is set to -1.
4356 if ((object_p
->bool_attr_mask
& SENSITIVE_BOOL_ON
) ||
4357 !(object_p
->bool_attr_mask
& EXTRACTABLE_BOOL_ON
)) {
4358 template->ulValueLen
= (CK_ULONG
)-1;
4359 return (CKR_ATTRIBUTE_SENSITIVE
);
4364 case CKK_GENERIC_SECRET
:
4372 if (template->type
== CKA_VALUE_LEN
) {
4373 return (get_ulong_attr_from_object(
4374 OBJ_SEC_VALUE_LEN(object_p
),
4377 return (get_bigint_attr_from_object(
4378 (biginteger_t
*)OBJ_SEC(object_p
),
4382 template->ulValueLen
= (CK_ULONG
)-1;
4383 rv
= CKR_ATTRIBUTE_TYPE_INVALID
;
4390 * First, get the value of the request attribute defined
4391 * in the list of common key attributes. If the request
4392 * attribute is not found in that list, then get the
4393 * attribute from the list of common attributes.
4395 rv
= soft_get_common_key_attrs(object_p
, template);
4396 if (rv
== CKR_ATTRIBUTE_TYPE_INVALID
) {
4397 rv
= soft_get_common_attrs(object_p
, template,
4398 object_p
->object_type
);
4408 * Get the value of a requested attribute of a Domain Parameters Object.
4410 * Rule: All the attributes in the domain parameters object can be revealed.
4413 soft_get_domain_parameters_attribute(soft_object_t
*object_p
,
4414 CK_ATTRIBUTE_PTR
template)
4418 CK_KEY_TYPE keytype
= object_p
->key_type
;
4420 switch (template->type
) {
4423 return (get_ulong_attr_from_object(keytype
,
4427 return (get_bool_attr_from_object(object_p
,
4428 LOCAL_BOOL_ON
, template));
4433 return (get_bigint_attr_from_object(
4434 OBJ_DOM_DSA_PRIME(object_p
), template));
4437 return (get_bigint_attr_from_object(
4438 OBJ_DOM_DH_PRIME(object_p
), template));
4441 return (get_bigint_attr_from_object(
4442 OBJ_DOM_DH942_PRIME(object_p
), template));
4445 template->ulValueLen
= (CK_ULONG
)-1;
4446 return (CKR_ATTRIBUTE_TYPE_INVALID
);
4452 return (get_bigint_attr_from_object(
4453 OBJ_DOM_DSA_SUBPRIME(object_p
), template));
4456 return (get_bigint_attr_from_object(
4457 OBJ_DOM_DH942_SUBPRIME(object_p
), template));
4460 template->ulValueLen
= (CK_ULONG
)-1;
4461 return (CKR_ATTRIBUTE_TYPE_INVALID
);
4467 return (get_bigint_attr_from_object(
4468 OBJ_DOM_DSA_BASE(object_p
), template));
4471 return (get_bigint_attr_from_object(
4472 OBJ_DOM_DH_BASE(object_p
), template));
4475 return (get_bigint_attr_from_object(
4476 OBJ_DOM_DH942_BASE(object_p
), template));
4479 template->ulValueLen
= (CK_ULONG
)-1;
4480 return (CKR_ATTRIBUTE_TYPE_INVALID
);
4483 case CKA_PRIME_BITS
:
4486 return (get_ulong_attr_from_object(
4487 OBJ_DOM_DSA_PRIME_BITS(object_p
), template));
4490 return (get_ulong_attr_from_object(
4491 OBJ_DOM_DH_PRIME_BITS(object_p
), template));
4494 return (get_ulong_attr_from_object(
4495 OBJ_DOM_DH942_PRIME_BITS(object_p
), template));
4498 template->ulValueLen
= (CK_ULONG
)-1;
4499 return (CKR_ATTRIBUTE_TYPE_INVALID
);
4502 case CKA_SUB_PRIME_BITS
:
4505 return (get_ulong_attr_from_object(
4506 OBJ_DOM_DH942_SUBPRIME_BITS(object_p
), template));
4509 template->ulValueLen
= (CK_ULONG
)-1;
4510 return (CKR_ATTRIBUTE_TYPE_INVALID
);
4515 * Get the value of a common attribute.
4517 rv
= soft_get_common_attrs(object_p
, template,
4518 object_p
->object_type
);
4526 * Get certificate attributes from an object.
4527 * return CKR_ATTRIBUTE_TYPE_INVALID if the requested type
4528 * does not exist in the certificate.
4531 soft_get_certificate_attribute(soft_object_t
*object_p
,
4532 CK_ATTRIBUTE_PTR
template)
4534 CK_CERTIFICATE_TYPE certtype
= object_p
->cert_type
;
4537 switch (template->type
) {
4539 if (certtype
== CKC_X_509
) {
4540 return (get_cert_attr_from_object(
4541 X509_CERT_SUBJECT(object_p
), template));
4545 if (certtype
== CKC_X_509
) {
4546 return (get_cert_attr_from_object(
4547 X509_CERT_VALUE(object_p
), template));
4548 } else if (certtype
== CKC_X_509_ATTR_CERT
) {
4549 return (get_cert_attr_from_object(
4550 X509_ATTR_CERT_VALUE(object_p
), template));
4554 if (certtype
== CKC_X_509_ATTR_CERT
) {
4555 return (get_cert_attr_from_object(
4556 X509_ATTR_CERT_OWNER(object_p
), template));
4559 case CKA_CERTIFICATE_TYPE
:
4560 src
.value
= (CK_BYTE
*)&certtype
;
4561 src
.length
= sizeof (certtype
);
4562 return (get_cert_attr_from_object(&src
, template));
4564 return (get_bool_attr_from_object(object_p
,
4565 TRUSTED_BOOL_ON
, template));
4568 case CKA_SERIAL_NUMBER
:
4570 case CKA_ATTR_TYPES
:
4571 return (get_extra_attr_from_object(object_p
,
4574 return (soft_get_common_attrs(object_p
, template,
4575 object_p
->object_type
));
4579 * If we got this far, then the combination of certificate type
4580 * and requested attribute is invalid.
4582 return (CKR_ATTRIBUTE_TYPE_INVALID
);
4586 soft_set_certificate_attribute(soft_object_t
*object_p
,
4587 CK_ATTRIBUTE_PTR
template, boolean_t copy
)
4589 CK_CERTIFICATE_TYPE certtype
= object_p
->cert_type
;
4591 switch (template->type
) {
4593 if (certtype
== CKC_X_509
) {
4594 /* SUBJECT attr cannot be modified. */
4595 return (CKR_ATTRIBUTE_READ_ONLY
);
4599 if (certtype
== CKC_X_509_ATTR_CERT
) {
4600 /* OWNER attr cannot be modified. */
4601 return (CKR_ATTRIBUTE_READ_ONLY
);
4605 /* VALUE attr cannot be modified. */
4606 return (CKR_ATTRIBUTE_READ_ONLY
);
4609 if (certtype
== CKC_X_509
) {
4610 return (set_extra_attr_to_object(object_p
,
4611 template->type
, template));
4615 case CKA_ATTR_TYPES
:
4616 if (certtype
== CKC_X_509_ATTR_CERT
) {
4617 return (set_extra_attr_to_object(object_p
,
4618 template->type
, template));
4621 case CKA_SERIAL_NUMBER
:
4623 return (set_extra_attr_to_object(object_p
,
4624 template->type
, template));
4626 return (soft_set_common_storage_attribute(
4627 object_p
, template, copy
));
4631 * If we got this far, then the combination of certificate type
4632 * and requested attribute is invalid.
4634 return (CKR_ATTRIBUTE_TYPE_INVALID
);
4638 * Call the appropriate get attribute function according to the class
4641 * The caller of this function holds the lock on the object.
4644 soft_get_attribute(soft_object_t
*object_p
, CK_ATTRIBUTE_PTR
template)
4648 CK_OBJECT_CLASS
class = object_p
->class;
4651 case CKO_PUBLIC_KEY
:
4652 rv
= soft_get_public_key_attribute(object_p
, template);
4655 case CKO_PRIVATE_KEY
:
4656 rv
= soft_get_private_key_attribute(object_p
, template);
4659 case CKO_SECRET_KEY
:
4660 rv
= soft_get_secret_key_attribute(object_p
, template);
4663 case CKO_DOMAIN_PARAMETERS
:
4664 rv
= soft_get_domain_parameters_attribute(object_p
, template);
4667 case CKO_CERTIFICATE
:
4668 rv
= soft_get_certificate_attribute(object_p
, template);
4673 * If the specified attribute for the object is invalid
4674 * (the object does not possess such as attribute), then
4675 * the ulValueLen is modified to hold the value -1.
4677 template->ulValueLen
= (CK_ULONG
)-1;
4678 return (CKR_ATTRIBUTE_TYPE_INVALID
);
4686 soft_set_common_storage_attribute(soft_object_t
*object_p
,
4687 CK_ATTRIBUTE_PTR
template, boolean_t copy
)
4692 switch (template->type
) {
4696 if ((*(CK_BBOOL
*)template->pValue
) == B_TRUE
) {
4697 if (!soft_keystore_status(KEYSTORE_INITIALIZED
))
4698 return (CKR_DEVICE_REMOVED
);
4699 object_p
->object_type
|= TOKEN_OBJECT
;
4702 rv
= CKR_ATTRIBUTE_READ_ONLY
;
4709 if ((*(CK_BBOOL
*)template->pValue
) == B_TRUE
) {
4710 (void) pthread_mutex_lock(&soft_giant_mutex
);
4711 if (!soft_slot
.authenticated
) {
4713 * Check if this is the special case
4714 * when the PIN is never initialized
4715 * in the keystore. If true, we will
4716 * let it pass here and let it fail
4717 * with CKR_PIN_EXPIRED later on.
4719 if (!soft_slot
.userpin_change_needed
) {
4720 (void) pthread_mutex_unlock(
4722 return (CKR_USER_NOT_LOGGED_IN
);
4725 (void) pthread_mutex_unlock(&soft_giant_mutex
);
4726 object_p
->object_type
|= PRIVATE_OBJECT
;
4729 rv
= CKR_ATTRIBUTE_READ_ONLY
;
4733 case CKA_MODIFIABLE
:
4735 if ((*(CK_BBOOL
*)template->pValue
) == TRUE
)
4736 object_p
->bool_attr_mask
&=
4737 ~NOT_MODIFIABLE_BOOL_ON
;
4739 object_p
->bool_attr_mask
|=
4740 NOT_MODIFIABLE_BOOL_ON
;
4742 rv
= CKR_ATTRIBUTE_READ_ONLY
;
4747 rv
= CKR_ATTRIBUTE_READ_ONLY
;
4751 rv
= CKR_TEMPLATE_INCONSISTENT
;
4758 * Set the value of an attribute that is common to all key objects
4759 * (i.e. public key, private key and secret key).
4762 soft_set_common_key_attribute(soft_object_t
*object_p
,
4763 CK_ATTRIBUTE_PTR
template, boolean_t copy
)
4766 switch (template->type
) {
4770 * Only the LABEL can be modified in the common storage
4771 * object attributes after the object is created.
4773 return (set_extra_attr_to_object(object_p
,
4774 CKA_LABEL
, template));
4777 return (set_extra_attr_to_object(object_p
,
4780 case CKA_START_DATE
:
4781 return (set_extra_attr_to_object(object_p
,
4782 CKA_START_DATE
, template));
4785 return (set_extra_attr_to_object(object_p
,
4786 CKA_END_DATE
, template));
4789 return (set_bool_attr_to_object(object_p
,
4790 DERIVE_BOOL_ON
, template));
4794 case CKA_KEY_GEN_MECHANISM
:
4795 return (CKR_ATTRIBUTE_READ_ONLY
);
4798 return (soft_set_common_storage_attribute(object_p
,
4807 * Set the value of an attribute of a Public Key Object.
4809 * Rule: The attributes marked with footnote number "8" in the PKCS11
4810 * spec may be modified (p.88 in PKCS11 spec.).
4813 soft_set_public_key_attribute(soft_object_t
*object_p
,
4814 CK_ATTRIBUTE_PTR
template, boolean_t copy
)
4816 CK_KEY_TYPE keytype
= object_p
->key_type
;
4818 switch (template->type
) {
4821 return (set_extra_attr_to_object(object_p
,
4822 CKA_SUBJECT
, template));
4825 return (set_bool_attr_to_object(object_p
,
4826 ENCRYPT_BOOL_ON
, template));
4829 return (set_bool_attr_to_object(object_p
,
4830 VERIFY_BOOL_ON
, template));
4832 case CKA_VERIFY_RECOVER
:
4833 return (set_bool_attr_to_object(object_p
,
4834 VERIFY_RECOVER_BOOL_ON
, template));
4837 return (set_bool_attr_to_object(object_p
,
4838 WRAP_BOOL_ON
, template));
4841 case CKA_MODULUS_BITS
:
4842 case CKA_PUBLIC_EXPONENT
:
4843 if (keytype
== CKK_RSA
)
4844 return (CKR_ATTRIBUTE_READ_ONLY
);
4848 if ((keytype
== CKK_DSA
) ||
4849 (keytype
== CKK_X9_42_DH
))
4850 return (CKR_ATTRIBUTE_READ_ONLY
);
4856 if ((keytype
== CKK_DSA
) ||
4857 (keytype
== CKK_DH
) ||
4858 (keytype
== CKK_X9_42_DH
))
4859 return (CKR_ATTRIBUTE_READ_ONLY
);
4864 * Set the value of a common key attribute.
4866 return (soft_set_common_key_attribute(object_p
,
4871 * If we got this far, then the combination of key type
4872 * and requested attribute is invalid.
4874 return (CKR_ATTRIBUTE_TYPE_INVALID
);
4879 * Set the value of an attribute of a Private Key Object.
4881 * Rule: The attributes marked with footnote number "8" in the PKCS11
4882 * spec may be modified (p.88 in PKCS11 spec.).
4885 soft_set_private_key_attribute(soft_object_t
*object_p
,
4886 CK_ATTRIBUTE_PTR
template, boolean_t copy
)
4888 CK_KEY_TYPE keytype
= object_p
->key_type
;
4890 switch (template->type
) {
4893 return (set_extra_attr_to_object(object_p
,
4894 CKA_SUBJECT
, template));
4898 * Cannot set SENSITIVE to FALSE if it is already ON.
4900 if (((*(CK_BBOOL
*)template->pValue
) == B_FALSE
) &&
4901 (object_p
->bool_attr_mask
& SENSITIVE_BOOL_ON
)) {
4902 return (CKR_ATTRIBUTE_READ_ONLY
);
4905 if (*(CK_BBOOL
*)template->pValue
)
4906 object_p
->bool_attr_mask
|= SENSITIVE_BOOL_ON
;
4910 return (set_bool_attr_to_object(object_p
,
4911 DECRYPT_BOOL_ON
, template));
4914 return (set_bool_attr_to_object(object_p
,
4915 SIGN_BOOL_ON
, template));
4917 case CKA_SIGN_RECOVER
:
4918 return (set_bool_attr_to_object(object_p
,
4919 SIGN_RECOVER_BOOL_ON
, template));
4922 return (set_bool_attr_to_object(object_p
,
4923 UNWRAP_BOOL_ON
, template));
4925 case CKA_EXTRACTABLE
:
4927 * Cannot set EXTRACTABLE to TRUE if it is already OFF.
4929 if ((*(CK_BBOOL
*)template->pValue
) &&
4930 !(object_p
->bool_attr_mask
& EXTRACTABLE_BOOL_ON
)) {
4931 return (CKR_ATTRIBUTE_READ_ONLY
);
4934 if ((*(CK_BBOOL
*)template->pValue
) == B_FALSE
)
4935 object_p
->bool_attr_mask
&= ~EXTRACTABLE_BOOL_ON
;
4939 case CKA_PUBLIC_EXPONENT
:
4940 case CKA_PRIVATE_EXPONENT
:
4943 case CKA_EXPONENT_1
:
4944 case CKA_EXPONENT_2
:
4945 case CKA_COEFFICIENT
:
4946 if (keytype
== CKK_RSA
) {
4947 return (CKR_ATTRIBUTE_READ_ONLY
);
4952 if ((keytype
== CKK_DSA
) ||
4953 (keytype
== CKK_X9_42_DH
))
4954 return (CKR_ATTRIBUTE_READ_ONLY
);
4960 if ((keytype
== CKK_DSA
) ||
4961 (keytype
== CKK_DH
) ||
4962 (keytype
== CKK_X9_42_DH
))
4963 return (CKR_ATTRIBUTE_READ_ONLY
);
4966 case CKA_VALUE_BITS
:
4967 if (keytype
== CKK_DH
)
4968 return (CKR_ATTRIBUTE_READ_ONLY
);
4973 * Set the value of a common key attribute.
4975 return (soft_set_common_key_attribute(object_p
,
4980 * If we got this far, then the combination of key type
4981 * and requested attribute is invalid.
4983 return (CKR_ATTRIBUTE_TYPE_INVALID
);
4987 * Set the value of an attribute of a Secret Key Object.
4989 * Rule: The attributes marked with footnote number "8" in the PKCS11
4990 * spec may be modified (p.88 in PKCS11 spec.).
4993 soft_set_secret_key_attribute(soft_object_t
*object_p
,
4994 CK_ATTRIBUTE_PTR
template, boolean_t copy
)
4996 CK_KEY_TYPE keytype
= object_p
->key_type
;
4998 switch (template->type
) {
5002 * Cannot set SENSITIVE to FALSE if it is already ON.
5004 if (((*(CK_BBOOL
*)template->pValue
) == B_FALSE
) &&
5005 (object_p
->bool_attr_mask
& SENSITIVE_BOOL_ON
)) {
5006 return (CKR_ATTRIBUTE_READ_ONLY
);
5009 if (*(CK_BBOOL
*)template->pValue
)
5010 object_p
->bool_attr_mask
|= SENSITIVE_BOOL_ON
;
5014 return (set_bool_attr_to_object(object_p
,
5015 ENCRYPT_BOOL_ON
, template));
5018 return (set_bool_attr_to_object(object_p
,
5019 DECRYPT_BOOL_ON
, template));
5022 return (set_bool_attr_to_object(object_p
,
5023 SIGN_BOOL_ON
, template));
5026 return (set_bool_attr_to_object(object_p
,
5027 VERIFY_BOOL_ON
, template));
5030 return (set_bool_attr_to_object(object_p
,
5031 WRAP_BOOL_ON
, template));
5034 return (set_bool_attr_to_object(object_p
,
5035 UNWRAP_BOOL_ON
, template));
5037 case CKA_EXTRACTABLE
:
5039 * Cannot set EXTRACTABLE to TRUE if it is already OFF.
5041 if ((*(CK_BBOOL
*)template->pValue
) &&
5042 !(object_p
->bool_attr_mask
& EXTRACTABLE_BOOL_ON
)) {
5043 return (CKR_ATTRIBUTE_READ_ONLY
);
5046 if ((*(CK_BBOOL
*)template->pValue
) == B_FALSE
)
5047 object_p
->bool_attr_mask
&= ~EXTRACTABLE_BOOL_ON
;
5051 return (CKR_ATTRIBUTE_READ_ONLY
);
5054 if ((keytype
== CKK_RC4
) ||
5055 (keytype
== CKK_GENERIC_SECRET
) ||
5056 (keytype
== CKK_AES
) ||
5057 (keytype
== CKK_BLOWFISH
))
5058 return (CKR_ATTRIBUTE_READ_ONLY
);
5063 * Set the value of a common key attribute.
5065 return (soft_set_common_key_attribute(object_p
,
5070 * If we got this far, then the combination of key type
5071 * and requested attribute is invalid.
5073 return (CKR_ATTRIBUTE_TYPE_INVALID
);
5078 * Call the appropriate set attribute function according to the class
5081 * The caller of this function does not hold the lock on the original
5082 * object, since this function is setting the attribute on the new object
5083 * that is being modified.
5085 * Argument copy: TRUE when called by C_CopyObject,
5086 * FALSE when called by C_SetAttributeValue.
5089 soft_set_attribute(soft_object_t
*object_p
, CK_ATTRIBUTE_PTR
template,
5094 CK_OBJECT_CLASS
class = object_p
->class;
5098 case CKO_PUBLIC_KEY
:
5099 rv
= soft_set_public_key_attribute(object_p
, template, copy
);
5102 case CKO_PRIVATE_KEY
:
5103 rv
= soft_set_private_key_attribute(object_p
, template, copy
);
5106 case CKO_SECRET_KEY
:
5107 rv
= soft_set_secret_key_attribute(object_p
, template, copy
);
5110 case CKO_DOMAIN_PARAMETERS
:
5111 switch (template->type
) {
5114 * Only the LABEL can be modified in the common
5115 * storage object attributes after the object is
5118 return (set_extra_attr_to_object(object_p
,
5119 CKA_LABEL
, template));
5121 return (CKR_TEMPLATE_INCONSISTENT
);
5123 case CKO_CERTIFICATE
:
5124 rv
= soft_set_certificate_attribute(object_p
, template, copy
);
5129 * If the template specifies a value of an attribute
5130 * which is incompatible with other existing attributes
5131 * of the object, then fails with return code
5132 * CKR_TEMPLATE_INCONSISTENT.
5134 rv
= CKR_TEMPLATE_INCONSISTENT
;
5142 soft_get_public_value(soft_object_t
*key
, CK_ATTRIBUTE_TYPE type
,
5143 uchar_t
*value
, uint32_t *value_len
)
5148 /* The following attributes belong to RSA */
5154 ((biginteger_t
*)OBJ_PUB_RSA_MOD(key
))->big_value_len
;
5155 #else /* !__sparcv9 */
5157 ((biginteger_t
*)OBJ_PUB_RSA_MOD(key
))->big_value_len
;
5158 #endif /* __sparcv9 */
5160 /* This attribute MUST BE set */
5161 if (len
== 0 || len
> *value_len
) {
5162 return (CKR_ATTRIBUTE_VALUE_INVALID
);
5166 (void) memcpy(value
,
5167 ((biginteger_t
*)OBJ_PUB_RSA_MOD(key
))->big_value
,
5172 case CKA_PUBLIC_EXPONENT
:
5177 ((biginteger_t
*)OBJ_PUB_RSA_PUBEXPO(key
))->big_value_len
;
5178 #else /* !__sparcv9 */
5180 ((biginteger_t
*)OBJ_PUB_RSA_PUBEXPO(key
))->big_value_len
;
5181 #endif /* __sparcv9 */
5183 /* This attribute MUST BE set */
5184 if (len
== 0 || len
> *value_len
) {
5185 return (CKR_ATTRIBUTE_VALUE_INVALID
);
5189 (void) memcpy(value
,
5190 ((biginteger_t
*)OBJ_PUB_RSA_PUBEXPO(key
))->big_value
,
5195 /* The following attributes belong to DSA and DH */
5198 if (key
->key_type
== CKK_DSA
)
5203 ((biginteger_t
*)OBJ_PUB_DSA_PRIME(key
))->
5205 #else /* !__sparcv9 */
5207 ((biginteger_t
*)OBJ_PUB_DSA_PRIME(key
))->
5209 #endif /* __sparcv9 */
5215 ((biginteger_t
*)OBJ_PUB_DH_PRIME(key
))->
5217 #else /* !__sparcv9 */
5219 ((biginteger_t
*)OBJ_PUB_DH_PRIME(key
))->
5221 #endif /* __sparcv9 */
5223 /* This attribute MUST BE set */
5224 if (len
== 0 || len
> *value_len
) {
5225 return (CKR_ATTRIBUTE_VALUE_INVALID
);
5229 if (key
->key_type
== CKK_DSA
)
5230 (void) memcpy(value
,
5231 ((biginteger_t
*)OBJ_PUB_DSA_PRIME(key
))->big_value
,
5234 (void) memcpy(value
,
5235 ((biginteger_t
*)OBJ_PUB_DH_PRIME(key
))->big_value
,
5245 ((biginteger_t
*)OBJ_PUB_DSA_SUBPRIME(key
))->big_value_len
;
5246 #else /* !__sparcv9 */
5248 ((biginteger_t
*)OBJ_PUB_DSA_SUBPRIME(key
))->big_value_len
;
5249 #endif /* __sparcv9 */
5251 /* This attribute MUST BE set */
5252 if (len
== 0 || len
> *value_len
) {
5253 return (CKR_ATTRIBUTE_VALUE_INVALID
);
5257 (void) memcpy(value
,
5258 ((biginteger_t
*)OBJ_PUB_DSA_SUBPRIME(key
))->big_value
,
5265 if (key
->key_type
== CKK_DSA
)
5270 ((biginteger_t
*)OBJ_PUB_DSA_BASE(key
))->
5272 #else /* !__sparcv9 */
5274 ((biginteger_t
*)OBJ_PUB_DSA_BASE(key
))->
5276 #endif /* __sparcv9 */
5282 ((biginteger_t
*)OBJ_PUB_DH_BASE(key
))->
5284 #else /* !__sparcv9 */
5286 ((biginteger_t
*)OBJ_PUB_DH_BASE(key
))->
5288 #endif /* __sparcv9 */
5290 /* This attribute MUST BE set */
5291 if (len
== 0 || len
> *value_len
) {
5292 return (CKR_ATTRIBUTE_VALUE_INVALID
);
5296 if (key
->key_type
== CKK_DSA
)
5297 (void) memcpy(value
,
5298 ((biginteger_t
*)OBJ_PUB_DSA_BASE(key
))->big_value
,
5301 (void) memcpy(value
,
5302 ((biginteger_t
*)OBJ_PUB_DH_BASE(key
))->big_value
,
5308 if (key
->key_type
== CKK_DSA
)
5313 ((biginteger_t
*)OBJ_PUB_DSA_VALUE(key
))->
5315 #else /* !__sparcv9 */
5317 ((biginteger_t
*)OBJ_PUB_DSA_VALUE(key
))->
5319 #endif /* __sparcv9 */
5325 ((biginteger_t
*)OBJ_PUB_DH_VALUE(key
))->
5327 #else /* !__sparcv9 */
5329 ((biginteger_t
*)OBJ_PUB_DH_VALUE(key
))->
5331 #endif /* __sparcv9 */
5333 /* This attribute MUST BE set */
5334 if (len
== 0 || len
> *value_len
) {
5335 return (CKR_ATTRIBUTE_VALUE_INVALID
);
5339 if (key
->key_type
== CKK_DSA
)
5340 (void) memcpy(value
,
5341 ((biginteger_t
*)OBJ_PUB_DSA_VALUE(key
))->big_value
,
5344 (void) memcpy(value
,
5345 ((biginteger_t
*)OBJ_PUB_DH_VALUE(key
))->big_value
,
5356 soft_get_private_value(soft_object_t
*key
, CK_ATTRIBUTE_TYPE type
,
5357 uchar_t
*value
, uint32_t *value_len
)
5364 /* The following attributes belong to RSA */
5370 ((biginteger_t
*)OBJ_PRI_RSA_MOD(key
))->big_value_len
;
5371 #else /* !__sparcv9 */
5373 ((biginteger_t
*)OBJ_PRI_RSA_MOD(key
))->big_value_len
;
5374 #endif /* __sparcv9 */
5376 /* This attribute MUST BE set */
5377 if (len
== 0 || len
> *value_len
) {
5378 return (CKR_ATTRIBUTE_VALUE_INVALID
);
5382 (void) memcpy(value
,
5383 ((biginteger_t
*)OBJ_PRI_RSA_MOD(key
))->big_value
,
5388 case CKA_PRIVATE_EXPONENT
:
5393 ((biginteger_t
*)OBJ_PRI_RSA_PRIEXPO(key
))->big_value_len
;
5394 #else /* !__sparcv9 */
5396 ((biginteger_t
*)OBJ_PRI_RSA_PRIEXPO(key
))->big_value_len
;
5397 #endif /* __sparcv9 */
5399 /* This attribute MUST BE set */
5400 if (len
== 0 || len
> *value_len
) {
5401 return (CKR_ATTRIBUTE_VALUE_INVALID
);
5405 (void) memcpy(value
,
5406 ((biginteger_t
*)OBJ_PRI_RSA_PRIEXPO(key
))->big_value
,
5416 ((biginteger_t
*)OBJ_PRI_RSA_PRIME1(key
))->big_value_len
;
5417 #else /* !__sparcv9 */
5419 ((biginteger_t
*)OBJ_PRI_RSA_PRIME1(key
))->big_value_len
;
5420 #endif /* __sparcv9 */
5422 if (len
> *value_len
) {
5423 return (CKR_ATTRIBUTE_VALUE_INVALID
);
5427 if (*value_len
== 0) {
5431 (void) memcpy(value
,
5432 ((biginteger_t
*)OBJ_PRI_RSA_PRIME1(key
))->big_value
,
5442 ((biginteger_t
*)OBJ_PRI_RSA_PRIME2(key
))->big_value_len
;
5443 #else /* !__sparcv9 */
5445 ((biginteger_t
*)OBJ_PRI_RSA_PRIME2(key
))->big_value_len
;
5446 #endif /* __sparcv9 */
5448 if (len
> *value_len
) {
5449 return (CKR_ATTRIBUTE_VALUE_INVALID
);
5453 if (*value_len
== 0) {
5457 (void) memcpy(value
,
5458 ((biginteger_t
*)OBJ_PRI_RSA_PRIME2(key
))->big_value
,
5463 case CKA_EXPONENT_1
:
5468 ((biginteger_t
*)OBJ_PRI_RSA_EXPO1(key
))->big_value_len
;
5469 #else /* !__sparcv9 */
5471 ((biginteger_t
*)OBJ_PRI_RSA_EXPO1(key
))->big_value_len
;
5472 #endif /* __sparcv9 */
5474 if (len
> *value_len
) {
5475 return (CKR_ATTRIBUTE_VALUE_INVALID
);
5479 if (*value_len
== 0) {
5483 (void) memcpy(value
,
5484 ((biginteger_t
*)OBJ_PRI_RSA_EXPO1(key
))->big_value
,
5489 case CKA_EXPONENT_2
:
5494 ((biginteger_t
*)OBJ_PRI_RSA_EXPO2(key
))->big_value_len
;
5495 #else /* !__sparcv9 */
5497 ((biginteger_t
*)OBJ_PRI_RSA_EXPO2(key
))->big_value_len
;
5498 #endif /* __sparcv9 */
5500 if (len
> *value_len
) {
5501 return (CKR_ATTRIBUTE_VALUE_INVALID
);
5505 if (*value_len
== 0) {
5509 (void) memcpy(value
,
5510 ((biginteger_t
*)OBJ_PRI_RSA_EXPO2(key
))->big_value
,
5515 case CKA_COEFFICIENT
:
5520 ((biginteger_t
*)OBJ_PRI_RSA_COEF(key
))->big_value_len
;
5521 #else /* !__sparcv9 */
5523 ((biginteger_t
*)OBJ_PRI_RSA_COEF(key
))->big_value_len
;
5524 #endif /* __sparcv9 */
5526 if (len
> *value_len
) {
5527 return (CKR_ATTRIBUTE_VALUE_INVALID
);
5531 if (*value_len
== 0) {
5535 (void) memcpy(value
,
5536 ((biginteger_t
*)OBJ_PRI_RSA_COEF(key
))->big_value
,
5541 /* The following attributes belong to DSA and DH */
5544 if (key
->key_type
== CKK_DSA
)
5549 ((biginteger_t
*)OBJ_PRI_DSA_PRIME(key
))->
5551 #else /* !__sparcv9 */
5553 ((biginteger_t
*)OBJ_PRI_DSA_PRIME(key
))->
5555 #endif /* __sparcv9 */
5561 ((biginteger_t
*)OBJ_PRI_DH_PRIME(key
))->
5563 #else /* !__sparcv9 */
5565 ((biginteger_t
*)OBJ_PRI_DH_PRIME(key
))->
5567 #endif /* __sparcv9 */
5569 /* This attribute MUST BE set */
5570 if (len
== 0 || len
> *value_len
) {
5571 return (CKR_ATTRIBUTE_VALUE_INVALID
);
5575 if (key
->key_type
== CKK_DSA
)
5576 (void) memcpy(value
,
5577 ((biginteger_t
*)OBJ_PRI_DSA_PRIME(key
))->big_value
,
5580 (void) memcpy(value
,
5581 ((biginteger_t
*)OBJ_PRI_DH_PRIME(key
))->big_value
,
5591 ((biginteger_t
*)OBJ_PRI_DSA_SUBPRIME(key
))->big_value_len
;
5592 #else /* !__sparcv9 */
5594 ((biginteger_t
*)OBJ_PRI_DSA_SUBPRIME(key
))->big_value_len
;
5595 #endif /* __sparcv9 */
5597 /* This attribute MUST BE set */
5598 if (len
== 0 || len
> *value_len
) {
5599 return (CKR_ATTRIBUTE_VALUE_INVALID
);
5603 (void) memcpy(value
,
5604 ((biginteger_t
*)OBJ_PRI_DSA_SUBPRIME(key
))->big_value
,
5611 if (key
->key_type
== CKK_DSA
)
5616 ((biginteger_t
*)OBJ_PRI_DSA_BASE(key
))->
5618 #else /* !__sparcv9 */
5620 ((biginteger_t
*)OBJ_PRI_DSA_BASE(key
))->
5622 #endif /* __sparcv9 */
5628 ((biginteger_t
*)OBJ_PRI_DH_BASE(key
))->
5630 #else /* !__sparcv9 */
5632 ((biginteger_t
*)OBJ_PRI_DH_BASE(key
))->
5634 #endif /* __sparcv9 */
5636 /* This attribute MUST BE set */
5637 if (len
== 0 || len
> *value_len
) {
5638 return (CKR_ATTRIBUTE_VALUE_INVALID
);
5642 if (key
->key_type
== CKK_DSA
)
5643 (void) memcpy(value
,
5644 ((biginteger_t
*)OBJ_PRI_DSA_BASE(key
))->big_value
,
5647 (void) memcpy(value
,
5648 ((biginteger_t
*)OBJ_PRI_DH_BASE(key
))->big_value
,
5654 if (key
->key_type
== CKK_DSA
) {
5659 ((biginteger_t
*)OBJ_PRI_DSA_VALUE(key
))->
5661 #else /* !__sparcv9 */
5663 ((biginteger_t
*)OBJ_PRI_DSA_VALUE(key
))->
5665 #endif /* __sparcv9 */
5666 } else if (key
->key_type
== CKK_DH
) {
5671 ((biginteger_t
*)OBJ_PRI_DH_VALUE(key
))->
5673 #else /* !__sparcv9 */
5675 ((biginteger_t
*)OBJ_PRI_DH_VALUE(key
))->
5677 #endif /* __sparcv9 */
5683 ((biginteger_t
*)OBJ_PRI_EC_VALUE(key
))->
5685 #else /* !__sparcv9 */
5687 ((biginteger_t
*)OBJ_PRI_EC_VALUE(key
))->
5689 #endif /* __sparcv9 */
5692 /* This attribute MUST BE set */
5693 if (len
== 0 || len
> *value_len
) {
5694 return (CKR_ATTRIBUTE_VALUE_INVALID
);
5698 if (key
->key_type
== CKK_DSA
) {
5699 (void) memcpy(value
,
5700 ((biginteger_t
*)OBJ_PRI_DSA_VALUE(key
))->big_value
,
5702 } else if (key
->key_type
== CKK_DH
) {
5703 (void) memcpy(value
,
5704 ((biginteger_t
*)OBJ_PRI_DH_VALUE(key
))->big_value
,
5707 (void) memcpy(value
,
5708 ((biginteger_t
*)OBJ_PRI_EC_VALUE(key
))->big_value
,
5720 copy_bigint(biginteger_t
*new_bigint
, biginteger_t
*old_bigint
)
5722 new_bigint
->big_value
=
5723 malloc((sizeof (CK_BYTE
) * new_bigint
->big_value_len
));
5725 if (new_bigint
->big_value
== NULL
) {
5726 return (CKR_HOST_MEMORY
);
5729 (void) memcpy(new_bigint
->big_value
, old_bigint
->big_value
,
5730 (sizeof (CK_BYTE
) * new_bigint
->big_value_len
));
5736 free_public_key_attr(public_key_obj_t
*pbk
, CK_KEY_TYPE key_type
)
5744 bigint_attr_cleanup(KEY_PUB_RSA_MOD(pbk
));
5745 bigint_attr_cleanup(KEY_PUB_RSA_PUBEXPO(pbk
));
5748 bigint_attr_cleanup(KEY_PUB_DSA_PRIME(pbk
));
5749 bigint_attr_cleanup(KEY_PUB_DSA_SUBPRIME(pbk
));
5750 bigint_attr_cleanup(KEY_PUB_DSA_BASE(pbk
));
5751 bigint_attr_cleanup(KEY_PUB_DSA_VALUE(pbk
));
5754 bigint_attr_cleanup(KEY_PUB_DH_PRIME(pbk
));
5755 bigint_attr_cleanup(KEY_PUB_DH_BASE(pbk
));
5756 bigint_attr_cleanup(KEY_PUB_DH_VALUE(pbk
));
5759 bigint_attr_cleanup(KEY_PUB_EC_POINT(pbk
));
5762 bigint_attr_cleanup(KEY_PUB_DH942_PRIME(pbk
));
5763 bigint_attr_cleanup(KEY_PUB_DH942_SUBPRIME(pbk
));
5764 bigint_attr_cleanup(KEY_PUB_DH942_BASE(pbk
));
5765 bigint_attr_cleanup(KEY_PUB_DH942_VALUE(pbk
));
5774 soft_copy_public_key_attr(public_key_obj_t
*old_pub_key_obj_p
,
5775 public_key_obj_t
**new_pub_key_obj_p
, CK_KEY_TYPE key_type
)
5778 public_key_obj_t
*pbk
;
5781 pbk
= calloc(1, sizeof (public_key_obj_t
));
5783 return (CKR_HOST_MEMORY
);
5788 (void) memcpy(KEY_PUB_RSA(pbk
),
5789 KEY_PUB_RSA(old_pub_key_obj_p
),
5790 sizeof (rsa_pub_key_t
));
5792 rv
= copy_bigint(KEY_PUB_RSA_MOD(pbk
),
5793 KEY_PUB_RSA_MOD(old_pub_key_obj_p
));
5795 free_public_key_attr(pbk
, key_type
);
5798 /* copy public exponent */
5799 rv
= copy_bigint(KEY_PUB_RSA_PUBEXPO(pbk
),
5800 KEY_PUB_RSA_PUBEXPO(old_pub_key_obj_p
));
5802 free_public_key_attr(pbk
, key_type
);
5807 (void) memcpy(KEY_PUB_DSA(pbk
),
5808 KEY_PUB_DSA(old_pub_key_obj_p
),
5809 sizeof (dsa_pub_key_t
));
5812 rv
= copy_bigint(KEY_PUB_DSA_PRIME(pbk
),
5813 KEY_PUB_DSA_PRIME(old_pub_key_obj_p
));
5815 free_public_key_attr(pbk
, key_type
);
5820 rv
= copy_bigint(KEY_PUB_DSA_SUBPRIME(pbk
),
5821 KEY_PUB_DSA_SUBPRIME(old_pub_key_obj_p
));
5823 free_public_key_attr(pbk
, key_type
);
5828 rv
= copy_bigint(KEY_PUB_DSA_BASE(pbk
),
5829 KEY_PUB_DSA_BASE(old_pub_key_obj_p
));
5831 free_public_key_attr(pbk
, key_type
);
5836 rv
= copy_bigint(KEY_PUB_DSA_VALUE(pbk
),
5837 KEY_PUB_DSA_VALUE(old_pub_key_obj_p
));
5839 free_public_key_attr(pbk
, key_type
);
5844 (void) memcpy(KEY_PUB_DH(pbk
),
5845 KEY_PUB_DH(old_pub_key_obj_p
),
5846 sizeof (dh_pub_key_t
));
5849 rv
= copy_bigint(KEY_PUB_DH_PRIME(pbk
),
5850 KEY_PUB_DH_PRIME(old_pub_key_obj_p
));
5852 free_public_key_attr(pbk
, key_type
);
5857 rv
= copy_bigint(KEY_PUB_DH_BASE(pbk
),
5858 KEY_PUB_DH_BASE(old_pub_key_obj_p
));
5860 free_public_key_attr(pbk
, key_type
);
5865 rv
= copy_bigint(KEY_PUB_DH_VALUE(pbk
),
5866 KEY_PUB_DH_VALUE(old_pub_key_obj_p
));
5868 free_public_key_attr(pbk
, key_type
);
5873 (void) memcpy(KEY_PUB_EC(pbk
),
5874 KEY_PUB_EC(old_pub_key_obj_p
),
5875 sizeof (ec_pub_key_t
));
5878 rv
= copy_bigint(KEY_PUB_EC_POINT(pbk
),
5879 KEY_PUB_EC_POINT(old_pub_key_obj_p
));
5881 free_public_key_attr(pbk
, key_type
);
5886 (void) memcpy(KEY_PUB_DH942(pbk
),
5887 KEY_PUB_DH942(old_pub_key_obj_p
),
5888 sizeof (dh942_pub_key_t
));
5891 rv
= copy_bigint(KEY_PUB_DH942_PRIME(pbk
),
5892 KEY_PUB_DH942_PRIME(old_pub_key_obj_p
));
5894 free_public_key_attr(pbk
, key_type
);
5899 rv
= copy_bigint(KEY_PUB_DH942_SUBPRIME(pbk
),
5900 KEY_PUB_DH942_SUBPRIME(old_pub_key_obj_p
));
5902 free_public_key_attr(pbk
, key_type
);
5907 rv
= copy_bigint(KEY_PUB_DH942_BASE(pbk
),
5908 KEY_PUB_DH942_BASE(old_pub_key_obj_p
));
5910 free_public_key_attr(pbk
, key_type
);
5915 rv
= copy_bigint(KEY_PUB_DH942_VALUE(pbk
),
5916 KEY_PUB_DH942_VALUE(old_pub_key_obj_p
));
5918 free_public_key_attr(pbk
, key_type
);
5925 *new_pub_key_obj_p
= pbk
;
5930 free_private_key_attr(private_key_obj_t
*pbk
, CK_KEY_TYPE key_type
)
5938 bigint_attr_cleanup(KEY_PRI_RSA_MOD(pbk
));
5939 bigint_attr_cleanup(KEY_PRI_RSA_PUBEXPO(pbk
));
5940 bigint_attr_cleanup(KEY_PRI_RSA_PRIEXPO(pbk
));
5941 bigint_attr_cleanup(KEY_PRI_RSA_PRIME1(pbk
));
5942 bigint_attr_cleanup(KEY_PRI_RSA_PRIME2(pbk
));
5943 bigint_attr_cleanup(KEY_PRI_RSA_EXPO1(pbk
));
5944 bigint_attr_cleanup(KEY_PRI_RSA_EXPO2(pbk
));
5945 bigint_attr_cleanup(KEY_PRI_RSA_COEF(pbk
));
5948 bigint_attr_cleanup(KEY_PRI_DSA_PRIME(pbk
));
5949 bigint_attr_cleanup(KEY_PRI_DSA_SUBPRIME(pbk
));
5950 bigint_attr_cleanup(KEY_PRI_DSA_BASE(pbk
));
5951 bigint_attr_cleanup(KEY_PRI_DSA_VALUE(pbk
));
5954 bigint_attr_cleanup(KEY_PRI_DH_PRIME(pbk
));
5955 bigint_attr_cleanup(KEY_PRI_DH_BASE(pbk
));
5956 bigint_attr_cleanup(KEY_PRI_DH_VALUE(pbk
));
5959 bigint_attr_cleanup(KEY_PRI_EC_VALUE(pbk
));
5962 bigint_attr_cleanup(KEY_PRI_DH942_PRIME(pbk
));
5963 bigint_attr_cleanup(KEY_PRI_DH942_SUBPRIME(pbk
));
5964 bigint_attr_cleanup(KEY_PRI_DH942_BASE(pbk
));
5965 bigint_attr_cleanup(KEY_PRI_DH942_VALUE(pbk
));
5974 soft_copy_private_key_attr(private_key_obj_t
*old_pri_key_obj_p
,
5975 private_key_obj_t
**new_pri_key_obj_p
, CK_KEY_TYPE key_type
)
5978 private_key_obj_t
*pbk
;
5980 pbk
= calloc(1, sizeof (private_key_obj_t
));
5982 return (CKR_HOST_MEMORY
);
5987 (void) memcpy(KEY_PRI_RSA(pbk
),
5988 KEY_PRI_RSA(old_pri_key_obj_p
),
5989 sizeof (rsa_pri_key_t
));
5991 rv
= copy_bigint(KEY_PRI_RSA_MOD(pbk
),
5992 KEY_PRI_RSA_MOD(old_pri_key_obj_p
));
5994 free_private_key_attr(pbk
, key_type
);
5997 /* copy public exponent */
5998 rv
= copy_bigint(KEY_PRI_RSA_PUBEXPO(pbk
),
5999 KEY_PRI_RSA_PUBEXPO(old_pri_key_obj_p
));
6001 free_private_key_attr(pbk
, key_type
);
6004 /* copy private exponent */
6005 rv
= copy_bigint(KEY_PRI_RSA_PRIEXPO(pbk
),
6006 KEY_PRI_RSA_PRIEXPO(old_pri_key_obj_p
));
6008 free_private_key_attr(pbk
, key_type
);
6012 rv
= copy_bigint(KEY_PRI_RSA_PRIME1(pbk
),
6013 KEY_PRI_RSA_PRIME1(old_pri_key_obj_p
));
6015 free_private_key_attr(pbk
, key_type
);
6019 rv
= copy_bigint(KEY_PRI_RSA_PRIME2(pbk
),
6020 KEY_PRI_RSA_PRIME2(old_pri_key_obj_p
));
6022 free_private_key_attr(pbk
, key_type
);
6025 /* copy exponent_1 */
6026 rv
= copy_bigint(KEY_PRI_RSA_EXPO1(pbk
),
6027 KEY_PRI_RSA_EXPO1(old_pri_key_obj_p
));
6029 free_private_key_attr(pbk
, key_type
);
6032 /* copy exponent_2 */
6033 rv
= copy_bigint(KEY_PRI_RSA_EXPO2(pbk
),
6034 KEY_PRI_RSA_EXPO2(old_pri_key_obj_p
));
6036 free_private_key_attr(pbk
, key_type
);
6039 /* copy coefficient */
6040 rv
= copy_bigint(KEY_PRI_RSA_COEF(pbk
),
6041 KEY_PRI_RSA_COEF(old_pri_key_obj_p
));
6043 free_private_key_attr(pbk
, key_type
);
6048 (void) memcpy(KEY_PRI_DSA(pbk
),
6049 KEY_PRI_DSA(old_pri_key_obj_p
),
6050 sizeof (dsa_pri_key_t
));
6053 rv
= copy_bigint(KEY_PRI_DSA_PRIME(pbk
),
6054 KEY_PRI_DSA_PRIME(old_pri_key_obj_p
));
6056 free_private_key_attr(pbk
, key_type
);
6061 rv
= copy_bigint(KEY_PRI_DSA_SUBPRIME(pbk
),
6062 KEY_PRI_DSA_SUBPRIME(old_pri_key_obj_p
));
6064 free_private_key_attr(pbk
, key_type
);
6069 rv
= copy_bigint(KEY_PRI_DSA_BASE(pbk
),
6070 KEY_PRI_DSA_BASE(old_pri_key_obj_p
));
6072 free_private_key_attr(pbk
, key_type
);
6077 rv
= copy_bigint(KEY_PRI_DSA_VALUE(pbk
),
6078 KEY_PRI_DSA_VALUE(old_pri_key_obj_p
));
6080 free_private_key_attr(pbk
, key_type
);
6085 (void) memcpy(KEY_PRI_DH(pbk
),
6086 KEY_PRI_DH(old_pri_key_obj_p
),
6087 sizeof (dh_pri_key_t
));
6090 rv
= copy_bigint(KEY_PRI_DH_PRIME(pbk
),
6091 KEY_PRI_DH_PRIME(old_pri_key_obj_p
));
6093 free_private_key_attr(pbk
, key_type
);
6098 rv
= copy_bigint(KEY_PRI_DH_BASE(pbk
),
6099 KEY_PRI_DH_BASE(old_pri_key_obj_p
));
6101 free_private_key_attr(pbk
, key_type
);
6106 rv
= copy_bigint(KEY_PRI_DH_VALUE(pbk
),
6107 KEY_PRI_DH_VALUE(old_pri_key_obj_p
));
6109 free_private_key_attr(pbk
, key_type
);
6114 (void) memcpy(KEY_PRI_EC(pbk
),
6115 KEY_PRI_EC(old_pri_key_obj_p
),
6116 sizeof (ec_pri_key_t
));
6119 rv
= copy_bigint(KEY_PRI_EC_VALUE(pbk
),
6120 KEY_PRI_EC_VALUE(old_pri_key_obj_p
));
6122 free_private_key_attr(pbk
, key_type
);
6127 (void) memcpy(KEY_PRI_DH942(pbk
),
6128 KEY_PRI_DH942(old_pri_key_obj_p
),
6129 sizeof (dh942_pri_key_t
));
6132 rv
= copy_bigint(KEY_PRI_DH942_PRIME(pbk
),
6133 KEY_PRI_DH942_PRIME(old_pri_key_obj_p
));
6135 free_private_key_attr(pbk
, key_type
);
6140 rv
= copy_bigint(KEY_PRI_DH942_SUBPRIME(pbk
),
6141 KEY_PRI_DH942_SUBPRIME(old_pri_key_obj_p
));
6143 free_private_key_attr(pbk
, key_type
);
6148 rv
= copy_bigint(KEY_PRI_DH942_BASE(pbk
),
6149 KEY_PRI_DH942_BASE(old_pri_key_obj_p
));
6151 free_private_key_attr(pbk
, key_type
);
6156 rv
= copy_bigint(KEY_PRI_DH942_VALUE(pbk
),
6157 KEY_PRI_DH942_VALUE(old_pri_key_obj_p
));
6159 free_private_key_attr(pbk
, key_type
);
6166 *new_pri_key_obj_p
= pbk
;
6171 free_domain_attr(domain_obj_t
*domain
, CK_KEY_TYPE key_type
)
6173 if (domain
== NULL
) {
6179 bigint_attr_cleanup(KEY_DOM_DSA_PRIME(domain
));
6180 bigint_attr_cleanup(KEY_DOM_DSA_SUBPRIME(domain
));
6181 bigint_attr_cleanup(KEY_DOM_DSA_BASE(domain
));
6184 bigint_attr_cleanup(KEY_DOM_DH_PRIME(domain
));
6185 bigint_attr_cleanup(KEY_DOM_DH_BASE(domain
));
6188 bigint_attr_cleanup(KEY_DOM_DH942_PRIME(domain
));
6189 bigint_attr_cleanup(KEY_DOM_DH942_SUBPRIME(domain
));
6190 bigint_attr_cleanup(KEY_DOM_DH942_BASE(domain
));
6199 soft_copy_domain_attr(domain_obj_t
*old_domain_obj_p
,
6200 domain_obj_t
**new_domain_obj_p
, CK_KEY_TYPE key_type
)
6203 domain_obj_t
*domain
;
6205 domain
= calloc(1, sizeof (domain_obj_t
));
6206 if (domain
== NULL
) {
6207 return (CKR_HOST_MEMORY
);
6212 (void) memcpy(KEY_DOM_DSA(domain
),
6213 KEY_DOM_DSA(old_domain_obj_p
),
6214 sizeof (dsa_dom_key_t
));
6217 rv
= copy_bigint(KEY_DOM_DSA_PRIME(domain
),
6218 KEY_DOM_DSA_PRIME(old_domain_obj_p
));
6220 free_domain_attr(domain
, key_type
);
6225 rv
= copy_bigint(KEY_DOM_DSA_SUBPRIME(domain
),
6226 KEY_DOM_DSA_SUBPRIME(old_domain_obj_p
));
6228 free_domain_attr(domain
, key_type
);
6233 rv
= copy_bigint(KEY_DOM_DSA_BASE(domain
),
6234 KEY_DOM_DSA_BASE(old_domain_obj_p
));
6236 free_domain_attr(domain
, key_type
);
6242 (void) memcpy(KEY_DOM_DH(domain
),
6243 KEY_DOM_DH(old_domain_obj_p
),
6244 sizeof (dh_dom_key_t
));
6247 rv
= copy_bigint(KEY_DOM_DH_PRIME(domain
),
6248 KEY_DOM_DH_PRIME(old_domain_obj_p
));
6250 free_domain_attr(domain
, key_type
);
6255 rv
= copy_bigint(KEY_DOM_DH_BASE(domain
),
6256 KEY_DOM_DH_BASE(old_domain_obj_p
));
6258 free_domain_attr(domain
, key_type
);
6264 (void) memcpy(KEY_DOM_DH942(domain
),
6265 KEY_DOM_DH942(old_domain_obj_p
),
6266 sizeof (dh942_dom_key_t
));
6269 rv
= copy_bigint(KEY_DOM_DH942_PRIME(domain
),
6270 KEY_DOM_DH942_PRIME(old_domain_obj_p
));
6272 free_domain_attr(domain
, key_type
);
6277 rv
= copy_bigint(KEY_DOM_DH942_SUBPRIME(domain
),
6278 KEY_DOM_DH942_SUBPRIME(old_domain_obj_p
));
6280 free_domain_attr(domain
, key_type
);
6285 rv
= copy_bigint(KEY_DOM_DH942_BASE(domain
),
6286 KEY_DOM_DH942_BASE(old_domain_obj_p
));
6288 free_domain_attr(domain
, key_type
);
6296 *new_domain_obj_p
= domain
;
6301 soft_copy_secret_key_attr(secret_key_obj_t
*old_secret_key_obj_p
,
6302 secret_key_obj_t
**new_secret_key_obj_p
)
6304 secret_key_obj_t
*sk
;
6306 sk
= malloc(sizeof (secret_key_obj_t
));
6308 return (CKR_HOST_MEMORY
);
6310 (void) memcpy(sk
, old_secret_key_obj_p
, sizeof (secret_key_obj_t
));
6312 /* copy the secret key value */
6313 sk
->sk_value
= malloc((sizeof (CK_BYTE
) * sk
->sk_value_len
));
6314 if (sk
->sk_value
== NULL
) {
6316 return (CKR_HOST_MEMORY
);
6318 (void) memcpy(sk
->sk_value
, old_secret_key_obj_p
->sk_value
,
6319 (sizeof (CK_BYTE
) * sk
->sk_value_len
));
6322 * Copy the pre-expanded key schedule.
6324 if (old_secret_key_obj_p
->key_sched
!= NULL
&&
6325 old_secret_key_obj_p
->keysched_len
> 0) {
6326 sk
->key_sched
= malloc(old_secret_key_obj_p
->keysched_len
);
6327 if (sk
->key_sched
== NULL
) {
6329 return (CKR_HOST_MEMORY
);
6331 sk
->keysched_len
= old_secret_key_obj_p
->keysched_len
;
6332 (void) memcpy(sk
->key_sched
, old_secret_key_obj_p
->key_sched
,
6336 *new_secret_key_obj_p
= sk
;
6342 * If CKA_CLASS not given, guess CKA_CLASS using
6343 * attributes on template .
6345 * Some attributes are specific to an object class. If one or more
6346 * of these attributes are in the template, make a list of classes
6347 * that can have these attributes. This would speed up the search later,
6348 * because we can immediately skip an object if the class of that
6349 * object can not possibly contain one of the attributes.
6353 soft_process_find_attr(CK_OBJECT_CLASS
*pclasses
,
6354 CK_ULONG
*num_result_pclasses
, CK_ATTRIBUTE_PTR pTemplate
,
6359 boolean_t pub_found
= B_FALSE
,
6360 priv_found
= B_FALSE
,
6361 secret_found
= B_FALSE
,
6362 domain_found
= B_FALSE
,
6363 hardware_found
= B_FALSE
,
6364 cert_found
= B_FALSE
;
6365 int num_pub_key_attrs
, num_priv_key_attrs
,
6366 num_secret_key_attrs
, num_domain_attrs
,
6367 num_hardware_attrs
, num_cert_attrs
;
6368 int num_pclasses
= 0;
6370 for (i
= 0; i
< ulCount
; i
++) {
6371 if (pTemplate
[i
].type
== CKA_CLASS
) {
6373 * don't need to guess the class, it is specified.
6374 * Just record the class, and return.
6377 (*((CK_OBJECT_CLASS
*)pTemplate
[i
].pValue
));
6378 *num_result_pclasses
= 1;
6384 sizeof (PUB_KEY_ATTRS
) / sizeof (CK_ATTRIBUTE_TYPE
);
6385 num_priv_key_attrs
=
6386 sizeof (PRIV_KEY_ATTRS
) / sizeof (CK_ATTRIBUTE_TYPE
);
6387 num_secret_key_attrs
=
6388 sizeof (SECRET_KEY_ATTRS
) / sizeof (CK_ATTRIBUTE_TYPE
);
6390 sizeof (DOMAIN_ATTRS
) / sizeof (CK_ATTRIBUTE_TYPE
);
6391 num_hardware_attrs
=
6392 sizeof (HARDWARE_ATTRS
) / sizeof (CK_ATTRIBUTE_TYPE
);
6394 sizeof (CERT_ATTRS
) / sizeof (CK_ATTRIBUTE_TYPE
);
6397 * Get the list of objects class that might contain
6400 for (i
= 0; i
< ulCount
; i
++) {
6402 * only check if this attribute can belong to public key object
6403 * class if public key object isn't already in the list
6406 for (j
= 0; j
< num_pub_key_attrs
; j
++) {
6407 if (pTemplate
[i
].type
== PUB_KEY_ATTRS
[j
]) {
6409 pclasses
[num_pclasses
++] =
6417 for (j
= 0; j
< num_priv_key_attrs
; j
++) {
6418 if (pTemplate
[i
].type
== PRIV_KEY_ATTRS
[j
]) {
6419 priv_found
= B_TRUE
;
6420 pclasses
[num_pclasses
++] =
6427 if (!secret_found
) {
6428 for (j
= 0; j
< num_secret_key_attrs
; j
++) {
6429 if (pTemplate
[i
].type
== SECRET_KEY_ATTRS
[j
]) {
6430 secret_found
= B_TRUE
;
6431 pclasses
[num_pclasses
++] =
6438 if (!domain_found
) {
6439 for (j
= 0; j
< num_domain_attrs
; j
++) {
6440 if (pTemplate
[i
].type
== DOMAIN_ATTRS
[j
]) {
6441 domain_found
= B_TRUE
;
6442 pclasses
[num_pclasses
++] =
6443 CKO_DOMAIN_PARAMETERS
;
6449 if (!hardware_found
) {
6450 for (j
= 0; j
< num_hardware_attrs
; j
++) {
6451 if (pTemplate
[i
].type
== HARDWARE_ATTRS
[j
]) {
6452 hardware_found
= B_TRUE
;
6453 pclasses
[num_pclasses
++] =
6461 for (j
= 0; j
< num_cert_attrs
; j
++) {
6462 if (pTemplate
[i
].type
== CERT_ATTRS
[j
]) {
6463 cert_found
= B_TRUE
;
6464 pclasses
[num_pclasses
++] =
6471 *num_result_pclasses
= num_pclasses
;
6475 soft_find_match_attrs(soft_object_t
*obj
, CK_OBJECT_CLASS
*pclasses
,
6476 CK_ULONG num_pclasses
, CK_ATTRIBUTE
*template, CK_ULONG num_attr
)
6479 CK_ATTRIBUTE
*tmpl_attr
, *obj_attr
;
6480 cert_attr_t
*cert_attr
;
6482 biginteger_t
*bigint
;
6483 boolean_t compare_attr
, compare_bigint
, compare_boolean
;
6484 boolean_t compare_cert_val
, compare_cert_type
;
6487 * Check if the class of this object match with any
6488 * of object classes that can possibly contain the
6489 * requested attributes.
6491 if (num_pclasses
> 0) {
6492 for (i
= 0; i
< num_pclasses
; i
++) {
6493 if (obj
->class == pclasses
[i
]) {
6497 if (i
== num_pclasses
) {
6499 * this object can't possibly contain one or
6500 * more attributes, don't need to check this object
6506 /* need to examine everything */
6507 for (i
= 0; i
< num_attr
; i
++) {
6508 tmpl_attr
= &(template[i
]);
6509 compare_attr
= B_FALSE
;
6510 compare_bigint
= B_FALSE
;
6511 compare_boolean
= B_FALSE
;
6512 compare_cert_val
= B_FALSE
;
6513 compare_cert_type
= B_FALSE
;
6514 switch (tmpl_attr
->type
) {
6515 /* First, check the most common attributes */
6517 if (*((CK_OBJECT_CLASS
*)tmpl_attr
->pValue
) !=
6523 if (*((CK_KEY_TYPE
*)tmpl_attr
->pValue
) !=
6529 attr_mask
= (obj
->bool_attr_mask
) & ENCRYPT_BOOL_ON
;
6530 compare_boolean
= B_TRUE
;
6533 attr_mask
= (obj
->bool_attr_mask
) & DECRYPT_BOOL_ON
;
6534 compare_boolean
= B_TRUE
;
6537 attr_mask
= (obj
->bool_attr_mask
) & WRAP_BOOL_ON
;
6538 compare_boolean
= B_TRUE
;
6541 attr_mask
= (obj
->bool_attr_mask
) & UNWRAP_BOOL_ON
;
6542 compare_boolean
= B_TRUE
;
6545 attr_mask
= (obj
->bool_attr_mask
) & SIGN_BOOL_ON
;
6546 compare_boolean
= B_TRUE
;
6548 case CKA_SIGN_RECOVER
:
6549 attr_mask
= (obj
->bool_attr_mask
) &
6550 SIGN_RECOVER_BOOL_ON
;
6551 compare_boolean
= B_TRUE
;
6554 attr_mask
= (obj
->bool_attr_mask
) & VERIFY_BOOL_ON
;
6555 compare_boolean
= B_TRUE
;
6557 case CKA_VERIFY_RECOVER
:
6558 attr_mask
= (obj
->bool_attr_mask
) &
6559 VERIFY_RECOVER_BOOL_ON
;
6560 compare_boolean
= B_TRUE
;
6563 attr_mask
= (obj
->bool_attr_mask
) & DERIVE_BOOL_ON
;
6564 compare_boolean
= B_TRUE
;
6567 attr_mask
= (obj
->bool_attr_mask
) & LOCAL_BOOL_ON
;
6568 compare_boolean
= B_TRUE
;
6571 attr_mask
= (obj
->bool_attr_mask
) & SENSITIVE_BOOL_ON
;
6572 compare_boolean
= B_TRUE
;
6574 case CKA_SECONDARY_AUTH
:
6575 attr_mask
= (obj
->bool_attr_mask
) &
6576 SECONDARY_AUTH_BOOL_ON
;
6577 compare_boolean
= B_TRUE
;
6580 attr_mask
= (obj
->bool_attr_mask
) & TRUSTED_BOOL_ON
;
6581 compare_boolean
= B_TRUE
;
6583 case CKA_EXTRACTABLE
:
6584 attr_mask
= (obj
->bool_attr_mask
) &
6585 EXTRACTABLE_BOOL_ON
;
6586 compare_boolean
= B_TRUE
;
6588 case CKA_ALWAYS_SENSITIVE
:
6589 attr_mask
= (obj
->bool_attr_mask
) &
6590 ALWAYS_SENSITIVE_BOOL_ON
;
6591 compare_boolean
= B_TRUE
;
6593 case CKA_NEVER_EXTRACTABLE
:
6594 attr_mask
= (obj
->bool_attr_mask
) &
6595 NEVER_EXTRACTABLE_BOOL_ON
;
6596 compare_boolean
= B_TRUE
;
6599 attr_mask
= (obj
->object_type
) & TOKEN_OBJECT
;
6600 compare_boolean
= B_TRUE
;
6603 attr_mask
= (obj
->object_type
) & PRIVATE_OBJECT
;
6604 compare_boolean
= B_TRUE
;
6606 case CKA_MODIFIABLE
:
6609 attr_mask
= (obj
->bool_attr_mask
) &
6610 NOT_MODIFIABLE_BOOL_ON
;
6617 if (bval
!= *((CK_BBOOL
*)tmpl_attr
->pValue
)) {
6624 * For X.509 attribute certificate object, get its
6625 * CKA_OWNER attribute from the x509_attr_cert_t struct.
6627 if ((obj
->class == CKO_CERTIFICATE
) &&
6628 (obj
->cert_type
== CKC_X_509_ATTR_CERT
)) {
6629 cert_attr
= X509_ATTR_CERT_OWNER(obj
);
6630 compare_cert_val
= B_TRUE
;
6635 * For X.509 certificate object, get its CKA_SUBJECT
6636 * attribute from the x509_cert_t struct (not from
6637 * the extra_attrlistp).
6639 if ((obj
->class == CKO_CERTIFICATE
) &&
6640 (obj
->cert_type
== CKC_X_509
)) {
6641 cert_attr
= X509_CERT_SUBJECT(obj
);
6642 compare_cert_val
= B_TRUE
;
6647 case CKA_START_DATE
:
6649 case CKA_KEY_GEN_MECHANISM
:
6652 case CKA_SERIAL_NUMBER
:
6654 case CKA_ATTR_TYPES
:
6655 /* find these attributes from extra_attrlistp */
6656 obj_attr
= get_extra_attr(tmpl_attr
->type
, obj
);
6657 compare_attr
= B_TRUE
;
6659 case CKA_CERTIFICATE_TYPE
:
6660 compare_cert_type
= B_TRUE
;
6663 /* only secret key has this attribute */
6664 if (obj
->class == CKO_SECRET_KEY
) {
6665 if (*((CK_ULONG
*)tmpl_attr
->pValue
) !=
6666 OBJ_SEC_VALUE_LEN(obj
)) {
6674 switch (obj
->class) {
6675 case CKO_SECRET_KEY
:
6677 * secret_key_obj_t is the same as
6680 bigint
= (biginteger_t
*)OBJ_SEC(obj
);
6681 compare_bigint
= B_TRUE
;
6683 case CKO_PRIVATE_KEY
:
6684 if (obj
->key_type
== CKK_DSA
) {
6685 bigint
= OBJ_PRI_DSA_VALUE(obj
);
6686 } else if (obj
->key_type
== CKK_DH
) {
6687 bigint
= OBJ_PRI_DH_VALUE(obj
);
6688 } else if (obj
->key_type
== CKK_X9_42_DH
) {
6689 bigint
= OBJ_PRI_DH942_VALUE(obj
);
6693 compare_bigint
= B_TRUE
;
6695 case CKO_PUBLIC_KEY
:
6696 if (obj
->key_type
== CKK_DSA
) {
6697 bigint
= OBJ_PUB_DSA_VALUE(obj
);
6698 } else if (obj
->key_type
== CKK_DH
) {
6699 bigint
= OBJ_PUB_DH_VALUE(obj
);
6700 } else if (obj
->key_type
== CKK_X9_42_DH
) {
6701 bigint
= OBJ_PUB_DH942_VALUE(obj
);
6705 compare_bigint
= B_TRUE
;
6707 case CKO_CERTIFICATE
:
6708 if (obj
->cert_type
== CKC_X_509
) {
6709 cert_attr
= X509_CERT_VALUE(obj
);
6710 } else if (obj
->cert_type
==
6711 CKC_X_509_ATTR_CERT
) {
6712 cert_attr
= X509_ATTR_CERT_VALUE(obj
);
6714 compare_cert_val
= B_TRUE
;
6721 /* only RSA public and private key have this attr */
6722 if (obj
->key_type
== CKK_RSA
) {
6723 if (obj
->class == CKO_PUBLIC_KEY
) {
6724 bigint
= OBJ_PUB_RSA_MOD(obj
);
6725 } else if (obj
->class == CKO_PRIVATE_KEY
) {
6726 bigint
= OBJ_PRI_RSA_MOD(obj
);
6730 compare_bigint
= B_TRUE
;
6735 case CKA_MODULUS_BITS
:
6736 /* only RSA public key has this attribute */
6737 if ((obj
->key_type
== CKK_RSA
) &&
6738 (obj
->class == CKO_PUBLIC_KEY
)) {
6739 CK_ULONG mod_bits
= OBJ_PUB_RSA_MOD_BITS(obj
);
6741 *((CK_ULONG
*)tmpl_attr
->pValue
)) {
6748 case CKA_PUBLIC_EXPONENT
:
6749 /* only RSA public and private key have this attr */
6750 if (obj
->key_type
== CKK_RSA
) {
6751 if (obj
->class == CKO_PUBLIC_KEY
) {
6752 bigint
= OBJ_PUB_RSA_PUBEXPO(obj
);
6753 } else if (obj
->class == CKO_PRIVATE_KEY
) {
6754 bigint
= OBJ_PRI_RSA_PUBEXPO(obj
);
6758 compare_bigint
= B_TRUE
;
6763 case CKA_PRIVATE_EXPONENT
:
6764 /* only RSA private key has this attribute */
6765 if ((obj
->key_type
== CKK_RSA
) &&
6766 (obj
->class == CKO_PRIVATE_KEY
)) {
6767 bigint
= OBJ_PRI_RSA_PRIEXPO(obj
);
6768 compare_bigint
= B_TRUE
;
6774 /* only RSA private key has this attribute */
6775 if ((obj
->key_type
== CKK_RSA
) &&
6776 (obj
->class == CKO_PRIVATE_KEY
)) {
6777 bigint
= OBJ_PRI_RSA_PRIME1(obj
);
6778 compare_bigint
= B_TRUE
;
6784 /* only RSA private key has this attribute */
6785 if ((obj
->key_type
== CKK_RSA
) &&
6786 (obj
->class == CKO_PRIVATE_KEY
)) {
6787 bigint
= OBJ_PRI_RSA_PRIME2(obj
);
6788 compare_bigint
= B_TRUE
;
6793 case CKA_EXPONENT_1
:
6794 /* only RSA private key has this attribute */
6795 if ((obj
->key_type
== CKK_RSA
) &&
6796 (obj
->class == CKO_PRIVATE_KEY
)) {
6797 bigint
= OBJ_PRI_RSA_EXPO1(obj
);
6798 compare_bigint
= B_TRUE
;
6803 case CKA_EXPONENT_2
:
6804 /* only RSA private key has this attribute */
6805 if ((obj
->key_type
== CKK_RSA
) &&
6806 (obj
->class == CKO_PRIVATE_KEY
)) {
6807 bigint
= OBJ_PRI_RSA_EXPO2(obj
);
6808 compare_bigint
= B_TRUE
;
6813 case CKA_COEFFICIENT
:
6814 /* only RSA private key has this attribute */
6815 if ((obj
->key_type
== CKK_RSA
) &&
6816 (obj
->class == CKO_PRIVATE_KEY
)) {
6817 bigint
= OBJ_PRI_RSA_COEF(obj
);
6818 compare_bigint
= B_TRUE
;
6823 case CKA_VALUE_BITS
:
6824 /* only Diffie-Hellman private key has this attr */
6825 if ((obj
->key_type
== CKK_DH
) &&
6826 (obj
->class == CKO_PRIVATE_KEY
)) {
6827 CK_ULONG val_bits
= OBJ_PRI_DH_VAL_BITS(obj
);
6829 *((CK_ULONG
*)tmpl_attr
->pValue
)) {
6837 if (obj
->class == CKO_PUBLIC_KEY
) {
6838 switch (obj
->key_type
) {
6840 bigint
= OBJ_PUB_DSA_PRIME(obj
);
6843 bigint
= OBJ_PUB_DH_PRIME(obj
);
6846 bigint
= OBJ_PUB_DH942_PRIME(obj
);
6851 } else if (obj
->class == CKO_PRIVATE_KEY
) {
6852 switch (obj
->key_type
) {
6854 bigint
= OBJ_PRI_DSA_PRIME(obj
);
6857 bigint
= OBJ_PRI_DH_PRIME(obj
);
6860 bigint
= OBJ_PRI_DH942_PRIME(obj
);
6865 } else if (obj
->class == CKO_DOMAIN_PARAMETERS
) {
6866 switch (obj
->key_type
) {
6868 bigint
= OBJ_DOM_DSA_PRIME(obj
);
6871 bigint
= OBJ_DOM_DH_PRIME(obj
);
6874 bigint
= OBJ_DOM_DH942_PRIME(obj
);
6882 compare_bigint
= B_TRUE
;
6885 if (obj
->class == CKO_PUBLIC_KEY
) {
6886 switch (obj
->key_type
) {
6888 bigint
= OBJ_PUB_DSA_SUBPRIME(obj
);
6891 bigint
= OBJ_PUB_DH942_SUBPRIME(obj
);
6896 } else if (obj
->class == CKO_PRIVATE_KEY
) {
6897 switch (obj
->key_type
) {
6899 bigint
= OBJ_PRI_DSA_SUBPRIME(obj
);
6902 bigint
= OBJ_PRI_DH942_SUBPRIME(obj
);
6907 } else if (obj
->class == CKO_DOMAIN_PARAMETERS
) {
6908 switch (obj
->key_type
) {
6910 bigint
= OBJ_DOM_DSA_SUBPRIME(obj
);
6913 bigint
= OBJ_DOM_DH942_SUBPRIME(obj
);
6921 compare_bigint
= B_TRUE
;
6924 if (obj
->class == CKO_PUBLIC_KEY
) {
6925 switch (obj
->key_type
) {
6927 bigint
= OBJ_PUB_DSA_BASE(obj
);
6930 bigint
= OBJ_PUB_DH_BASE(obj
);
6933 bigint
= OBJ_PUB_DH942_BASE(obj
);
6938 } else if (obj
->class == CKO_PRIVATE_KEY
) {
6939 switch (obj
->key_type
) {
6941 bigint
= OBJ_PRI_DSA_BASE(obj
);
6944 bigint
= OBJ_PRI_DH_BASE(obj
);
6947 bigint
= OBJ_PRI_DH942_BASE(obj
);
6952 } else if (obj
->class == CKO_DOMAIN_PARAMETERS
) {
6953 switch (obj
->key_type
) {
6955 bigint
= OBJ_DOM_DSA_BASE(obj
);
6958 bigint
= OBJ_DOM_DH_BASE(obj
);
6961 bigint
= OBJ_DOM_DH942_BASE(obj
);
6969 compare_bigint
= B_TRUE
;
6971 case CKA_PRIME_BITS
:
6972 if (obj
->class == CKO_DOMAIN_PARAMETERS
) {
6973 CK_ULONG prime_bits
;
6974 if (obj
->key_type
== CKK_DSA
) {
6976 OBJ_DOM_DSA_PRIME_BITS(obj
);
6977 } else if (obj
->key_type
== CKK_DH
) {
6979 OBJ_DOM_DH_PRIME_BITS(obj
);
6980 } else if (obj
->key_type
== CKK_X9_42_DH
) {
6982 OBJ_DOM_DH942_PRIME_BITS(obj
);
6987 *((CK_ULONG
*)tmpl_attr
->pValue
)) {
6994 case CKA_SUBPRIME_BITS
:
6995 if ((obj
->class == CKO_DOMAIN_PARAMETERS
) &&
6996 (obj
->key_type
== CKK_X9_42_DH
)) {
6997 CK_ULONG subprime_bits
=
6998 OBJ_DOM_DH942_SUBPRIME_BITS(obj
);
6999 if (subprime_bits
!=
7000 *((CK_ULONG
*)tmpl_attr
->pValue
)) {
7009 * any other attributes are currently not supported.
7010 * so, it's not possible for them to be in the
7015 if (compare_boolean
) {
7023 if (bval
!= *((CK_BBOOL
*)tmpl_attr
->pValue
)) {
7026 } else if (compare_bigint
) {
7027 if (bigint
== NULL
) {
7030 if (tmpl_attr
->ulValueLen
!= bigint
->big_value_len
) {
7033 if (memcmp(tmpl_attr
->pValue
, bigint
->big_value
,
7034 tmpl_attr
->ulValueLen
) != 0) {
7037 } else if (compare_attr
) {
7038 if (obj_attr
== NULL
) {
7040 * The attribute type is valid, and its value
7041 * has not been initialized in the object. In
7042 * this case, it only matches the template's
7043 * attribute if the template's value length
7046 if (tmpl_attr
->ulValueLen
!= 0)
7049 if (tmpl_attr
->ulValueLen
!=
7050 obj_attr
->ulValueLen
) {
7053 if (memcmp(tmpl_attr
->pValue
, obj_attr
->pValue
,
7054 tmpl_attr
->ulValueLen
) != 0) {
7058 } else if (compare_cert_val
) {
7059 if (cert_attr
== NULL
) {
7060 /* specific attribute not found */
7063 if (tmpl_attr
->ulValueLen
!= cert_attr
->length
) {
7066 if (memcmp(tmpl_attr
->pValue
, cert_attr
->value
,
7067 tmpl_attr
->ulValueLen
) != 0) {
7070 } else if (compare_cert_type
) {
7071 if (memcmp(tmpl_attr
->pValue
, &(obj
->cert_type
),
7072 tmpl_attr
->ulValueLen
) != 0) {
7081 get_extra_attr(CK_ATTRIBUTE_TYPE type
, soft_object_t
*obj
)
7083 CK_ATTRIBUTE_INFO_PTR tmp
;
7085 tmp
= obj
->extra_attrlistp
;
7086 while (tmp
!= NULL
) {
7087 if (tmp
->attr
.type
== type
) {
7088 return (&(tmp
->attr
));
7092 /* if get there, the specified attribute is not found */