Skip to content

Commit

Permalink
tt/P124525118: Add alias for RSA/ECB/OAEPWithSHA-1AndMGF1Padding
Browse files Browse the repository at this point in the history
We add this alias to better support [open-source projects using
non-JCA-standard algorithm names][1].

[1]: https://github.com/search?q=RSA%2FECB%2FOAEPWithSHA1AndMGF1Padding&type=code
  • Loading branch information
WillChilds-Klein committed Apr 4, 2024
1 parent 4ec7ff6 commit 735df54
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ private void buildServiceMap() {
addService("Cipher", "RSA/ECB/Pkcs1Padding", "RsaCipher$Pkcs1");
addService("Cipher", "RSA/ECB/OAEPPadding", "RsaCipher$OAEP");
addService("Cipher", "RSA/ECB/OAEPWithSHA-1AndMGF1Padding", "RsaCipher$OAEPSha1");
addService("Cipher", "RSA/ECB/OAEPWithSHA1AndMGF1Padding", "RsaCipher$OAEPSha1");

for (String hash : new String[] {"MD5", "SHA1", "SHA256", "SHA384", "SHA512"}) {
addService("Mac", "Hmac" + hash, "EvpHmac$" + hash);
Expand Down
12 changes: 9 additions & 3 deletions tst/com/amazon/corretto/crypto/provider/test/RsaCipherTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
@ResourceLock(value = TestUtil.RESOURCE_GLOBAL, mode = ResourceAccessMode.READ)
public class RsaCipherTest {
private static final String OAEP_SHA1_PADDING = "RSA/ECB/OAEPWithSHA-1AndMGF1Padding";
// Some non-JCA-standard aliases are allowed for compatibility
private static final String OAEP_SHA1_PADDING_ALT1 = "RSA/ECB/OAEPWithSHA1AndMGF1Padding";
private static final String OAEP_PADDING = "RSA/ECB/OAEPPadding";
private static final String PKCS1_PADDING = "RSA/ECB/Pkcs1Padding";
private static final String NO_PADDING = "RSA/ECB/NoPadding";
Expand Down Expand Up @@ -94,7 +96,8 @@ public class RsaCipherTest {
}

public static List<String> paddingParams() {
return Arrays.asList(OAEP_PADDING, OAEP_SHA1_PADDING, PKCS1_PADDING, NO_PADDING);
return Arrays.asList(
OAEP_PADDING, OAEP_SHA1_PADDING, OAEP_SHA1_PADDING_ALT1, PKCS1_PADDING, NO_PADDING);
}

public static List<String> messageDigestParams() {
Expand All @@ -106,7 +109,8 @@ public static List<String> messageDigestParams() {
Object o = f.get(null); // static field, so null "instance"
Method m = MGF1ParameterSpec.class.getDeclaredMethod("getDigestAlgorithm");
String digest = (String) m.invoke(o);
// NOTE: AWS-LC doesn't support SHA-512/224 or SHA3
// NOTE: AWS-LC doesn't support SHA-512/224 or SHA3 in a recent FIPS
// version, but does support them as of non-FIPS v1.17.0
if ("SHA-512/224".equals(digest) || !digest.startsWith("SHA-")) {
continue;
}
Expand Down Expand Up @@ -734,7 +738,8 @@ public void testSetOaepParamsOnNonOaepPadding(final String padding)
// Inspect each field, as for some reason the OAEPParameterSpec.equals method seems
// to compare object hash code instead of individual members.
private static void assertOAEPParamSpecsEqual(OAEPParameterSpec a, OAEPParameterSpec b) {
assertEquals(a.getDigestAlgorithm(), b.getDigestAlgorithm());
assertEquals(
a.getDigestAlgorithm().replaceAll("-", ""), b.getDigestAlgorithm().replaceAll("-", ""));
assertEquals(a.getMGFAlgorithm(), b.getMGFAlgorithm());
assertEquals(a.getMGFParameters(), b.getMGFParameters());
assertEquals(a.getPSource().getAlgorithm(), b.getPSource().getAlgorithm());
Expand Down Expand Up @@ -1084,6 +1089,7 @@ private static int getPaddingSize(final String padding, final OAEPParameterSpec
return 11;
case OAEP_PADDING:
case OAEP_SHA1_PADDING:
case OAEP_SHA1_PADDING_ALT1:
return 42;
default:
throw new IllegalArgumentException("Bad padding: " + padding);
Expand Down

0 comments on commit 735df54

Please sign in to comment.