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