From aab39d41736c29cd0e40c0b6dd19a611957df55b Mon Sep 17 00:00:00 2001 From: Prashant Patil Date: Mon, 11 Dec 2023 19:42:07 +0000 Subject: Handle FLAG_MGF1_DIGEST_SETTER enable and disable The setMgf1Digests() API is flagged API, however initially this API is used without checking whether Flag is enabled or disabled. So these tests are updated to check whether FLAG_MGF1_DIGEST_SETTER flag is enabled or disabled. Bug: 308069562 Test: atest CtsKeystoreWycheproofTestCases:RsaOaepTest Change-Id: If077503ca981dfa8628c4981627daae591a0f75e --- .../google/security/wycheproof/testcases/RsaOaepTest.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/keystore-cts/java/com/google/security/wycheproof/testcases/RsaOaepTest.java b/keystore-cts/java/com/google/security/wycheproof/testcases/RsaOaepTest.java index dbcc5ab..c0ee341 100644 --- a/keystore-cts/java/com/google/security/wycheproof/testcases/RsaOaepTest.java +++ b/keystore-cts/java/com/google/security/wycheproof/testcases/RsaOaepTest.java @@ -38,6 +38,7 @@ import javax.crypto.spec.PSource; import org.junit.After; import org.junit.Test; import org.junit.Ignore; +import android.security.Flags; import android.security.keystore.KeyProtection; import android.security.keystore.KeyProperties; import android.keystore.cts.util.KeyStoreUtil; @@ -66,9 +67,17 @@ public class RsaOaepTest { KeyProperties.PURPOSE_DECRYPT) .setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_RSA_PKCS1, KeyProperties.ENCRYPTION_PADDING_RSA_OAEP) - .setDigests(digest) - .setMgf1Digests(mgfDigest) .setIsStrongBoxBacked(isStrongBox); + if (Flags.mgf1DigestSetter()) { + keyProtection.setDigests(digest); + keyProtection.setMgf1Digests(mgfDigest); + } else { + if (digest.equalsIgnoreCase(mgfDigest)) { + keyProtection.setDigests(digest); + } else { + keyProtection.setDigests(digest, mgfDigest); + } + } return (PrivateKey) KeyStoreUtil.saveKeysToKeystore(KEY_ALIAS_1, pubKey, privKey, keyProtection.build()).getKey(KEY_ALIAS_1, null); } -- cgit v1.2.3