File tree 1 file changed +30
-1
lines changed
1 file changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -1268,6 +1268,28 @@ fn sha256_digest() -> TestResult {
1268
1268
Ok ( ( ) )
1269
1269
}
1270
1270
1271
+ #[ test]
1272
+ #[ serial]
1273
+ fn gcm_param_graceful_failure ( ) -> TestResult {
1274
+ // Try to generate GcmParams with max size IV (2^32-1)
1275
+ // Verify that the ulIvBits doesn't cause failover
1276
+ println ! ( "start" ) ;
1277
+ // setting this as a [u8] array causes stack overflow before operation has even begun
1278
+ let mut iv = vec ! [ 0 ; 4294967295 ] ;
1279
+ println ! ( "iv" ) ;
1280
+ let aad = [ 0 ; 16 ] ;
1281
+
1282
+ let _gcm_params = match GcmParams :: new ( & mut iv, & aad, 96 . into ( ) ) {
1283
+ Ok ( params) => params,
1284
+ Err ( e) => {
1285
+ println ! ( "{e}" ) ;
1286
+ return Err ( e. into ( ) ) ;
1287
+ } ,
1288
+ } ;
1289
+
1290
+ Ok ( ( ) )
1291
+ }
1292
+
1271
1293
#[ test]
1272
1294
#[ serial]
1273
1295
// Currently empty AAD crashes SoftHSM, see: https://github.com/opendnssec/SoftHSMv2/issues/605
@@ -1326,7 +1348,14 @@ fn aes_gcm_with_aad() -> TestResult {
1326
1348
Attribute :: Encrypt ( true ) ,
1327
1349
] ;
1328
1350
let key_handle = session. create_object ( & template) ?;
1329
- let mechanism = Mechanism :: AesGcm ( GcmParams :: new ( & mut iv, & aad, 96 . into ( ) ) . unwrap ( ) ) ;
1351
+ let gcm_params = match GcmParams :: new ( & mut iv, & aad, 96 . into ( ) ) {
1352
+ Ok ( params) => params,
1353
+ Err ( e) => {
1354
+ println ! ( "{e}" ) ;
1355
+ return Err ( e. into ( ) ) ;
1356
+ } ,
1357
+ } ;
1358
+ let mechanism = Mechanism :: AesGcm ( gcm_params) ;
1330
1359
let cipher_and_tag = session. encrypt ( & mechanism, key_handle, & plain) ?;
1331
1360
assert_eq ! ( expected_cipher_and_tag[ ..] , cipher_and_tag[ ..] ) ;
1332
1361
Ok ( ( ) )
You can’t perform that action at this time.
0 commit comments