@@ -148,10 +148,6 @@ pub enum AttributeType {
148
148
Seed ,
149
149
/// Algorithm-specific parameter set
150
150
ParameterSet ,
151
- /// ML-KEM parameter set
152
- MlKemParameterSet ,
153
- /// ML-DSA parameter set
154
- MlDsaParameterSet ,
155
151
}
156
152
157
153
impl AttributeType {
@@ -323,8 +319,6 @@ impl From<AttributeType> for CK_ATTRIBUTE_TYPE {
323
319
AttributeType :: KeyType => CKA_KEY_TYPE ,
324
320
AttributeType :: Label => CKA_LABEL ,
325
321
AttributeType :: Local => CKA_LOCAL ,
326
- AttributeType :: MlDsaParameterSet => CKA_PARAMETER_SET ,
327
- AttributeType :: MlKemParameterSet => CKA_PARAMETER_SET ,
328
322
AttributeType :: Modifiable => CKA_MODIFIABLE ,
329
323
AttributeType :: Modulus => CKA_MODULUS ,
330
324
AttributeType :: ModulusBits => CKA_MODULUS_BITS ,
@@ -508,10 +502,6 @@ pub enum Attribute {
508
502
Label ( Vec < u8 > ) ,
509
503
/// Indicates if the key was generated locally or copied from a locally created object
510
504
Local ( bool ) ,
511
- /// ML-DSA parameter set
512
- MlDsaParameterSet ( MlDsaParameterSetType ) ,
513
- /// ML-KEM parameter set
514
- MlKemParameterSet ( MlKemParameterSetType ) ,
515
505
/// Determines if the object can be modified
516
506
Modifiable ( bool ) ,
517
507
/// Modulus value of a key
@@ -524,8 +514,8 @@ pub enum Attribute {
524
514
ObjectId ( Vec < u8 > ) ,
525
515
/// DER encoding of the attribute certificate's subject field
526
516
Owner ( Vec < u8 > ) ,
527
- /// Algorithm specific parameter set
528
- ParameterSet ( Vec < u8 > ) ,
517
+ /// Algorithm specific parameter set, now used for ML-DSA and ML-KEM algorithms
518
+ ParameterSet ( ParameterSetType ) ,
529
519
/// Prime number value of a key
530
520
Prime ( Vec < u8 > ) ,
531
521
/// The prime `p` of an RSA private key
@@ -616,8 +606,6 @@ impl Attribute {
616
606
Attribute :: KeyType ( _) => AttributeType :: KeyType ,
617
607
Attribute :: Label ( _) => AttributeType :: Label ,
618
608
Attribute :: Local ( _) => AttributeType :: Local ,
619
- Attribute :: MlDsaParameterSet ( _) => AttributeType :: MlDsaParameterSet ,
620
- Attribute :: MlKemParameterSet ( _) => AttributeType :: MlKemParameterSet ,
621
609
Attribute :: Modifiable ( _) => AttributeType :: Modifiable ,
622
610
Attribute :: Modulus ( _) => AttributeType :: Modulus ,
623
611
Attribute :: ModulusBits ( _) => AttributeType :: ModulusBits ,
@@ -705,7 +693,7 @@ impl Attribute {
705
693
Attribute :: ModulusBits ( _) => size_of :: < CK_ULONG > ( ) ,
706
694
Attribute :: ObjectId ( bytes) => bytes. len ( ) ,
707
695
Attribute :: Owner ( bytes) => bytes. len ( ) ,
708
- Attribute :: ParameterSet ( bytes ) => bytes . len ( ) ,
696
+ Attribute :: ParameterSet ( _ ) => size_of :: < CK_ULONG > ( ) ,
709
697
Attribute :: Prime ( bytes) => bytes. len ( ) ,
710
698
Attribute :: Prime1 ( bytes) => bytes. len ( ) ,
711
699
Attribute :: Prime2 ( bytes) => bytes. len ( ) ,
@@ -719,8 +707,6 @@ impl Attribute {
719
707
Attribute :: Value ( bytes) => bytes. len ( ) ,
720
708
Attribute :: ValueLen ( _) => size_of :: < CK_ULONG > ( ) ,
721
709
Attribute :: EndDate ( _) | Attribute :: StartDate ( _) => size_of :: < CK_DATE > ( ) ,
722
- Attribute :: MlKemParameterSet ( _) => size_of :: < CK_ML_KEM_PARAMETER_SET_TYPE > ( ) ,
723
- Attribute :: MlDsaParameterSet ( _) => size_of :: < CK_ML_DSA_PARAMETER_SET_TYPE > ( ) ,
724
710
725
711
Attribute :: AllowedMechanisms ( mechanisms) => {
726
712
size_of :: < CK_MECHANISM_TYPE > ( ) * mechanisms. len ( )
@@ -788,7 +774,6 @@ impl Attribute {
788
774
| Attribute :: Issuer ( bytes)
789
775
| Attribute :: Label ( bytes)
790
776
| Attribute :: ObjectId ( bytes)
791
- | Attribute :: ParameterSet ( bytes)
792
777
| Attribute :: Prime ( bytes)
793
778
| Attribute :: Prime1 ( bytes)
794
779
| Attribute :: Prime2 ( bytes)
@@ -806,14 +791,13 @@ impl Attribute {
806
791
| Attribute :: VendorDefined ( ( _, bytes) )
807
792
| Attribute :: Id ( bytes) => bytes. as_ptr ( ) as * mut c_void ,
808
793
// Unique types
794
+ Attribute :: ParameterSet ( val) => val as * const _ as * mut c_void ,
809
795
Attribute :: CertificateType ( certificate_type) => {
810
796
certificate_type as * const _ as * mut c_void
811
797
}
812
798
Attribute :: Class ( object_class) => object_class as * const _ as * mut c_void ,
813
799
Attribute :: KeyGenMechanism ( mech) => mech as * const _ as * mut c_void ,
814
800
Attribute :: KeyType ( key_type) => key_type as * const _ as * mut c_void ,
815
- Attribute :: MlKemParameterSet ( p) => p as * const _ as * mut c_void ,
816
- Attribute :: MlDsaParameterSet ( p) => p as * const _ as * mut c_void ,
817
801
Attribute :: AllowedMechanisms ( mechanisms) => mechanisms. as_ptr ( ) as * mut c_void ,
818
802
Attribute :: EndDate ( date) | Attribute :: StartDate ( date) => {
819
803
date as * const _ as * mut c_void
@@ -921,7 +905,6 @@ impl TryFrom<CK_ATTRIBUTE> for Attribute {
921
905
}
922
906
AttributeType :: Issuer => Ok ( Attribute :: Issuer ( val. to_vec ( ) ) ) ,
923
907
AttributeType :: Label => Ok ( Attribute :: Label ( val. to_vec ( ) ) ) ,
924
- AttributeType :: ParameterSet => Ok ( Attribute :: ParameterSet ( val. to_vec ( ) ) ) ,
925
908
AttributeType :: Prime => Ok ( Attribute :: Prime ( val. to_vec ( ) ) ) ,
926
909
AttributeType :: Prime1 => Ok ( Attribute :: Prime1 ( val. to_vec ( ) ) ) ,
927
910
AttributeType :: Prime2 => Ok ( Attribute :: Prime2 ( val. to_vec ( ) ) ) ,
@@ -939,6 +922,9 @@ impl TryFrom<CK_ATTRIBUTE> for Attribute {
939
922
AttributeType :: Value => Ok ( Attribute :: Value ( val. to_vec ( ) ) ) ,
940
923
AttributeType :: Id => Ok ( Attribute :: Id ( val. to_vec ( ) ) ) ,
941
924
// Unique types
925
+ AttributeType :: ParameterSet => Ok ( Attribute :: ParameterSet ( ParameterSetType {
926
+ val : CK_ULONG :: from_ne_bytes ( val. try_into ( ) ?) . into ( ) ,
927
+ } ) ) ,
942
928
AttributeType :: CertificateType => Ok ( Attribute :: CertificateType (
943
929
CK_CERTIFICATE_TYPE :: from_ne_bytes ( val. try_into ( ) ?) . try_into ( ) ?,
944
930
) ) ,
@@ -951,12 +937,6 @@ impl TryFrom<CK_ATTRIBUTE> for Attribute {
951
937
AttributeType :: KeyType => Ok ( Attribute :: KeyType (
952
938
CK_KEY_TYPE :: from_ne_bytes ( val. try_into ( ) ?) . try_into ( ) ?,
953
939
) ) ,
954
- AttributeType :: MlKemParameterSet => Ok ( Attribute :: MlKemParameterSet (
955
- CK_ML_KEM_PARAMETER_SET_TYPE :: from_ne_bytes ( val. try_into ( ) ?) . try_into ( ) ?,
956
- ) ) ,
957
- AttributeType :: MlDsaParameterSet => Ok ( Attribute :: MlDsaParameterSet (
958
- CK_ML_DSA_PARAMETER_SET_TYPE :: from_ne_bytes ( val. try_into ( ) ?) . try_into ( ) ?,
959
- ) ) ,
960
940
AttributeType :: AllowedMechanisms => {
961
941
let val = unsafe {
962
942
std:: slice:: from_raw_parts (
@@ -1059,6 +1039,63 @@ impl std::fmt::UpperHex for ObjectHandle {
1059
1039
}
1060
1040
}
1061
1041
1042
+ #[ derive( Copy , Debug , Clone , PartialEq , Eq ) ]
1043
+ #[ repr( transparent) ]
1044
+ /// Generic parameter set
1045
+ pub struct ParameterSetType {
1046
+ val : Ulong ,
1047
+ }
1048
+
1049
+ impl ParameterSetType {
1050
+ pub ( crate ) fn stringify ( val : Ulong ) -> String {
1051
+ format ! ( "unknown ({:08x})" , * val)
1052
+ }
1053
+ }
1054
+
1055
+ impl std:: fmt:: Display for ParameterSetType {
1056
+ fn fmt ( & self , f : & mut Formatter < ' _ > ) -> std:: fmt:: Result {
1057
+ write ! ( f, "{}" , ParameterSetType :: stringify( self . val) )
1058
+ }
1059
+ }
1060
+
1061
+ impl Deref for ParameterSetType {
1062
+ type Target = Ulong ;
1063
+
1064
+ fn deref ( & self ) -> & Self :: Target {
1065
+ & self . val
1066
+ }
1067
+ }
1068
+
1069
+ impl From < ParameterSetType > for Ulong {
1070
+ fn from ( val : ParameterSetType ) -> Self {
1071
+ * val
1072
+ }
1073
+ }
1074
+
1075
+ impl TryFrom < Ulong > for ParameterSetType {
1076
+ type Error = Error ;
1077
+
1078
+ fn try_from ( val : Ulong ) -> Result < Self > {
1079
+ Ok ( ParameterSetType { val } )
1080
+ }
1081
+ }
1082
+
1083
+ impl From < MlKemParameterSetType > for ParameterSetType {
1084
+ fn from ( val : MlKemParameterSetType ) -> Self {
1085
+ ParameterSetType {
1086
+ val : Ulong :: new ( * val) ,
1087
+ }
1088
+ }
1089
+ }
1090
+
1091
+ impl From < MlDsaParameterSetType > for ParameterSetType {
1092
+ fn from ( val : MlDsaParameterSetType ) -> Self {
1093
+ ParameterSetType {
1094
+ val : Ulong :: new ( * val) ,
1095
+ }
1096
+ }
1097
+ }
1098
+
1062
1099
#[ derive( Copy , Debug , Clone , PartialEq , Eq ) ]
1063
1100
#[ repr( transparent) ]
1064
1101
/// Identifier of the ML-KEM parameter set
@@ -1126,6 +1163,14 @@ impl TryFrom<CK_ML_KEM_PARAMETER_SET_TYPE> for MlKemParameterSetType {
1126
1163
}
1127
1164
}
1128
1165
1166
+ impl From < ParameterSetType > for MlKemParameterSetType {
1167
+ fn from ( val : ParameterSetType ) -> Self {
1168
+ MlKemParameterSetType {
1169
+ val : CK_ULONG :: from ( * val) ,
1170
+ }
1171
+ }
1172
+ }
1173
+
1129
1174
#[ derive( Copy , Debug , Clone , PartialEq , Eq ) ]
1130
1175
#[ repr( transparent) ]
1131
1176
/// Identifier of the ML-DSA parameter set
@@ -1187,6 +1232,14 @@ impl TryFrom<CK_ML_DSA_PARAMETER_SET_TYPE> for MlDsaParameterSetType {
1187
1232
}
1188
1233
}
1189
1234
1235
+ impl From < ParameterSetType > for MlDsaParameterSetType {
1236
+ fn from ( val : ParameterSetType ) -> Self {
1237
+ MlDsaParameterSetType {
1238
+ val : CK_ULONG :: from ( * val) ,
1239
+ }
1240
+ }
1241
+ }
1242
+
1190
1243
#[ derive( Copy , Debug , Clone , PartialEq , Eq ) ]
1191
1244
#[ repr( transparent) ]
1192
1245
/// Identifier of the class of an object
0 commit comments