@@ -1416,6 +1416,74 @@ int test_aes_gcm_bad_tag(void *data)
14161416 return err ;
14171417}
14181418
1419+ static int test_aes_gcm_tls_iv_fixed_oversized_helper (OSSL_LIB_CTX * libCtx ,
1420+ const char * cipherName , int keyLen )
1421+ {
1422+ int err ;
1423+ EVP_CIPHER * cipher = NULL ;
1424+ EVP_CIPHER_CTX * ctx = NULL ;
1425+ unsigned char key [32 ];
1426+ /* ivLen (12, the GCM default) + EVP_GCM_TLS_EXPLICIT_IV_LEN (8) = 20: */
1427+ unsigned char iv [20 ];
1428+
1429+ memset (key , 0xCC , keyLen );
1430+ memset (iv , 0xDD , sizeof (iv ));
1431+
1432+ cipher = EVP_CIPHER_fetch (libCtx , cipherName , "" );
1433+ err = cipher == NULL ;
1434+
1435+ /* A fixed len that leaves exactly the 8-byte
1436+ * explicit/invocation field must still be accepted. */
1437+ if (err == 0 ) {
1438+ ctx = EVP_CIPHER_CTX_new ();
1439+ err = ctx == NULL ;
1440+ }
1441+ if (err == 0 ) {
1442+ err = EVP_DecryptInit_ex (ctx , cipher , NULL , key , NULL ) != 1 ;
1443+ }
1444+ if (err == 0 ) {
1445+ err = EVP_CIPHER_CTX_ctrl (ctx , EVP_CTRL_GCM_SET_IV_FIXED ,
1446+ EVP_GCM_TLS_FIXED_IV_LEN , iv ) != 1 ;
1447+ }
1448+ EVP_CIPHER_CTX_free (ctx );
1449+ ctx = NULL ;
1450+
1451+ /* Oversized fixed len (> ctx->ivLen, default 12) must be rejected. */
1452+ if (err == 0 ) {
1453+ ctx = EVP_CIPHER_CTX_new ();
1454+ err = ctx == NULL ;
1455+ }
1456+ if (err == 0 ) {
1457+ err = EVP_DecryptInit_ex (ctx , cipher , NULL , key , NULL ) != 1 ;
1458+ }
1459+ if (err == 0 ) {
1460+ if (EVP_CIPHER_CTX_ctrl (ctx , EVP_CTRL_GCM_SET_IV_FIXED ,
1461+ (int )sizeof (iv ), iv ) == 1 ) {
1462+ PRINT_ERR_MSG ("%s: EVP_CTRL_GCM_SET_IV_FIXED incorrectly "
1463+ "accepted a fixed IV length (%d) larger than "
1464+ "the IV length" , cipherName , (int )sizeof (iv ));
1465+ err = 1 ;
1466+ }
1467+ }
1468+
1469+ EVP_CIPHER_CTX_free (ctx );
1470+ EVP_CIPHER_free (cipher );
1471+ return err ;
1472+ }
1473+
1474+ int test_aes_gcm_tls_iv_fixed_oversized (void * data )
1475+ {
1476+ int err ;
1477+
1478+ (void )data ;
1479+
1480+ PRINT_MSG ("AES-128-GCM TLS1 fixed-IV oversized length rejection" );
1481+ err = test_aes_gcm_tls_iv_fixed_oversized_helper (wpLibCtx ,
1482+ "AES-128-GCM" , 16 );
1483+
1484+ return err ;
1485+ }
1486+
14191487#endif /* WP_HAVE_AESGCM */
14201488
14211489/******************************************************************************/
0 commit comments