@@ -1187,3 +1187,71 @@ fn ekdf_aes_cbc_encrypt_data() -> TestResult {
1187
1187
1188
1188
Ok ( ( ) )
1189
1189
}
1190
+
1191
+ #[ test]
1192
+ #[ serial]
1193
+ fn aes_cmac_sign ( ) -> TestResult {
1194
+ let ( pkcs11, slot) = init_pins ( ) ;
1195
+ let session = pkcs11. open_rw_session ( slot) ?;
1196
+ session. login ( UserType :: User , Some ( & AuthPin :: new ( USER_PIN . into ( ) ) ) ) ?;
1197
+ let key: [ u8 ; 16 ] = [
1198
+ 0x2b , 0x7e , 0x15 , 0x16 , 0x28 , 0xae , 0xd2 , 0xa6 , 0xab , 0xf7 , 0x15 , 0x88 , 0x09 , 0xcf , 0x4f ,
1199
+ 0x3c ,
1200
+ ] ;
1201
+ let message: [ u8 ; 16 ] = [
1202
+ 0x6b , 0xc1 , 0xbe , 0xe2 , 0x2e , 0x40 , 0x9f , 0x96 , 0xe9 , 0x3d , 0x7e , 0x11 , 0x73 , 0x93 , 0x17 ,
1203
+ 0x2a ,
1204
+ ] ;
1205
+ let expected_mac: [ u8 ; 16 ] = [
1206
+ 0x07 , 0x0a , 0x16 , 0xb4 , 0x6b , 0x4d , 0x41 , 0x44 , 0xf7 , 0x9b , 0xdd , 0x9d , 0xd0 , 0x4a , 0x28 ,
1207
+ 0x7c ,
1208
+ ] ;
1209
+
1210
+ let key_template = vec ! [
1211
+ Attribute :: Class ( ObjectClass :: SECRET_KEY ) ,
1212
+ Attribute :: KeyType ( KeyType :: AES ) ,
1213
+ Attribute :: Token ( true ) ,
1214
+ Attribute :: Sensitive ( true ) ,
1215
+ Attribute :: Private ( true ) ,
1216
+ Attribute :: Value ( key. into( ) ) ,
1217
+ Attribute :: Sign ( true ) ,
1218
+ ] ;
1219
+ let key = session. create_object ( & key_template) ?;
1220
+ let signature = session. sign ( & Mechanism :: AesCMac , key, & message) ?;
1221
+
1222
+ assert_eq ! ( expected_mac. as_slice( ) , signature. as_slice( ) ) ;
1223
+ Ok ( ( ) )
1224
+ }
1225
+
1226
+ #[ test]
1227
+ #[ serial]
1228
+ fn aes_cmac_verify ( ) -> TestResult {
1229
+ let ( pkcs11, slot) = init_pins ( ) ;
1230
+ let session = pkcs11. open_rw_session ( slot) ?;
1231
+ session. login ( UserType :: User , Some ( & AuthPin :: new ( USER_PIN . into ( ) ) ) ) ?;
1232
+ let key: [ u8 ; 16 ] = [
1233
+ 0x2b , 0x7e , 0x15 , 0x16 , 0x28 , 0xae , 0xd2 , 0xa6 , 0xab , 0xf7 , 0x15 , 0x88 , 0x09 , 0xcf , 0x4f ,
1234
+ 0x3c ,
1235
+ ] ;
1236
+ let message: [ u8 ; 16 ] = [
1237
+ 0x6b , 0xc1 , 0xbe , 0xe2 , 0x2e , 0x40 , 0x9f , 0x96 , 0xe9 , 0x3d , 0x7e , 0x11 , 0x73 , 0x93 , 0x17 ,
1238
+ 0x2a ,
1239
+ ] ;
1240
+ let expected_mac: [ u8 ; 16 ] = [
1241
+ 0x07 , 0x0a , 0x16 , 0xb4 , 0x6b , 0x4d , 0x41 , 0x44 , 0xf7 , 0x9b , 0xdd , 0x9d , 0xd0 , 0x4a , 0x28 ,
1242
+ 0x7c ,
1243
+ ] ;
1244
+
1245
+ let key_template = vec ! [
1246
+ Attribute :: Class ( ObjectClass :: SECRET_KEY ) ,
1247
+ Attribute :: KeyType ( KeyType :: AES ) ,
1248
+ Attribute :: Token ( true ) ,
1249
+ Attribute :: Sensitive ( true ) ,
1250
+ Attribute :: Private ( true ) ,
1251
+ Attribute :: Value ( key. into( ) ) ,
1252
+ Attribute :: Verify ( true ) ,
1253
+ ] ;
1254
+ let key = session. create_object ( & key_template) ?;
1255
+ session. verify ( & Mechanism :: AesCMac , key, & message, & expected_mac) ?;
1256
+ Ok ( ( ) )
1257
+ }
0 commit comments