File tree Expand file tree Collapse file tree 1 file changed +30
-1
lines changed Expand file tree Collapse file tree 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 {
12681268 Ok ( ( ) )
12691269}
12701270
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+
12711293#[ test]
12721294#[ serial]
12731295// Currently empty AAD crashes SoftHSM, see: https://github.com/opendnssec/SoftHSMv2/issues/605
@@ -1326,7 +1348,14 @@ fn aes_gcm_with_aad() -> TestResult {
13261348 Attribute :: Encrypt ( true ) ,
13271349 ] ;
13281350 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) ;
13301359 let cipher_and_tag = session. encrypt ( & mechanism, key_handle, & plain) ?;
13311360 assert_eq ! ( expected_cipher_and_tag[ ..] , cipher_and_tag[ ..] ) ;
13321361 Ok ( ( ) )
You can’t perform that action at this time.
0 commit comments