Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions test/jdk/sun/security/pkcs11/Cipher/ReinitCipher.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -32,6 +32,8 @@
* @run main/othervm ReinitCipher
*/

import jtreg.SkippedException;

import java.security.Provider;
import java.util.Random;
import javax.crypto.Cipher;
Expand All @@ -46,8 +48,7 @@ public static void main(String[] args) throws Exception {
@Override
public void main(Provider p) throws Exception {
if (p.getService("Cipher", "ARCFOUR") == null) {
System.out.println("Not supported by provider, skipping");
return;
throw new SkippedException("Algorithm ARCFOUR is not supported by provider, skipping");
}
Random random = new Random();
byte[] data1 = new byte[10 * 1024];
Expand Down
21 changes: 11 additions & 10 deletions test/jdk/sun/security/pkcs11/Cipher/Test4512704.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -29,14 +29,16 @@
* @run main Test4512704
* @summary Verify that AES cipher can generate default IV in encrypt mode
*/
import java.io.PrintStream;
import java.security.*;
import java.security.spec.*;
import java.util.Random;
import jtreg.SkippedException;

import javax.crypto.*;
import javax.crypto.spec.*;
import java.security.GeneralSecurityException;
import java.security.InvalidAlgorithmParameterException;

import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import java.security.Provider;
import java.security.spec.AlgorithmParameterSpec;

public class Test4512704 extends PKCS11Test {

Expand All @@ -48,9 +50,8 @@ public void test(String mode, Provider p) throws Exception {
transformation = "AES/" + mode + "/NoPadding";
c = Cipher.getInstance(transformation, p);
} catch (GeneralSecurityException e) {
System.out.println("Skip testing " + p.getName() +
", no support for " + mode);
return;
throw new SkippedException("Skip testing " + p.getName() +
", no support for " + mode);
}
SecretKey key = new SecretKeySpec(new byte[16], "AES");

Expand Down
27 changes: 17 additions & 10 deletions test/jdk/sun/security/pkcs11/Cipher/TestCICOWithGCM.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -31,13 +31,21 @@
* @key randomness
*/

import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.*;
import java.math.*;
import java.io.*;
import jtreg.SkippedException;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import javax.crypto.Cipher;
import javax.crypto.CipherInputStream;
import javax.crypto.CipherOutputStream;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;

import java.security.GeneralSecurityException;
import java.security.Provider;
import java.util.Arrays;
import java.util.Random;

import java.util.*;

public class TestCICOWithGCM extends PKCS11Test {
public static void main(String[] args) throws Exception {
Expand All @@ -55,9 +63,8 @@ public void test(String mode, Provider p) throws Exception {
String transformation = "AES/" + mode + "/NoPadding";
c = Cipher.getInstance(transformation, p);
} catch (GeneralSecurityException e) {
System.out.println("Skip testing " + p.getName() +
", no support for " + mode);
return;
throw new SkippedException("Skip testing " + p.getName() +
", no support for " + mode);
}

SecretKey key = new SecretKeySpec(new byte[16], "AES");
Expand Down
10 changes: 5 additions & 5 deletions test/jdk/sun/security/pkcs11/Cipher/TestCICOWithGCMAndAAD.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -30,6 +30,8 @@
* @summary Test CipherInputStream/OutputStream with AES GCM mode with AAD.
* @key randomness
*/
import jtreg.SkippedException;

import java.io.*;
import java.security.*;
import java.util.*;
Expand All @@ -44,7 +46,6 @@ public static void main(String[] args) throws Exception {
@Override
public void main(Provider p) throws Exception {
test("GCM", p);
// test("CCM", p);
}

public void test(String mode, Provider p) throws Exception {
Expand All @@ -53,9 +54,8 @@ public void test(String mode, Provider p) throws Exception {
String transformation = "AES/" + mode + "/NoPadding";
c = Cipher.getInstance(transformation, p);
} catch (GeneralSecurityException e) {
System.out.println("Skip testing " + p.getName() +
", no support for " + mode);
return;
throw new SkippedException("Skip testing " + p.getName() +
", no support for " + mode);
}
SecretKey key = new SecretKeySpec(new byte[16], "AES");

Expand Down
7 changes: 3 additions & 4 deletions test/jdk/sun/security/pkcs11/Cipher/TestChaChaPoly.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -47,7 +47,7 @@
import javax.crypto.spec.SecretKeySpec;
import javax.crypto.NoSuchPaddingException;

import jdk.test.lib.Utils;
import jtreg.SkippedException;

public class TestChaChaPoly extends PKCS11Test {

Expand All @@ -70,8 +70,7 @@ public void main(Provider p) throws Exception {
try {
Cipher.getInstance(ALGO, p);
} catch (NoSuchAlgorithmException nsae) {
System.out.println("Skip; no support for " + ALGO);
return;
throw new SkippedException("Skip; no support for " + ALGO);
}
this.p = p;
testTransformations();
Expand Down
16 changes: 9 additions & 7 deletions test/jdk/sun/security/pkcs11/Cipher/TestChaChaPolyKAT.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -26,22 +26,25 @@
* @bug 8255410
* @library /test/lib ..
* @modules jdk.crypto.cryptoki
* @build jdk.test.lib.Convert
* @run main/othervm TestChaChaPolyKAT
* @summary ChaCha20-Poly1305 Cipher Implementation (KAT)
*/

import java.util.*;
import jtreg.SkippedException;

import java.security.GeneralSecurityException;
import java.security.Provider;
import java.security.NoSuchAlgorithmException;
import javax.crypto.Cipher;
import javax.crypto.spec.ChaCha20ParameterSpec;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import javax.crypto.AEADBadTagException;
import java.nio.ByteBuffer;
import jdk.test.lib.Convert;
import java.util.Arrays;
import java.util.HexFormat;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;

public class TestChaChaPolyKAT extends PKCS11Test {
public static class TestData {
Expand Down Expand Up @@ -126,8 +129,7 @@ public void main(Provider p) throws Exception {
try {
Cipher.getInstance(ALGO, p);
} catch (NoSuchAlgorithmException nsae) {
System.out.println("Skip; no support for " + ALGO);
return;
throw new SkippedException("Skip; no support for " + ALGO);
}

int testsPassed = 0;
Expand Down
15 changes: 9 additions & 6 deletions test/jdk/sun/security/pkcs11/Cipher/TestChaChaPolyNoReuse.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -30,18 +30,22 @@
* (key/nonce reuse check)
*/

import java.util.*;
import jtreg.SkippedException;

import javax.crypto.Cipher;
import java.security.spec.AlgorithmParameterSpec;
import java.security.Provider;
import java.security.NoSuchAlgorithmException;
import javax.crypto.spec.ChaCha20ParameterSpec;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import javax.crypto.AEADBadTagException;
import javax.crypto.SecretKey;
import java.security.InvalidKeyException;
import java.security.InvalidAlgorithmParameterException;
import java.util.Arrays;
import java.util.HexFormat;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;

public class TestChaChaPolyNoReuse extends PKCS11Test {

Expand Down Expand Up @@ -238,8 +242,7 @@ public void main(Provider p) throws Exception {
try {
Cipher.getInstance(CIPHER_ALGO, p);
} catch (NoSuchAlgorithmException nsae) {
System.out.println("Skip; no support for " + CIPHER_ALGO);
return;
throw new SkippedException("Skip; no support for " + CIPHER_ALGO);
}

int testsPassed = 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -30,14 +30,14 @@
* @run main TestChaChaPolyOutputSize
*/

import jtreg.SkippedException;

import java.nio.ByteBuffer;
import java.security.GeneralSecurityException;
import java.security.Key;
import java.security.SecureRandom;
import java.security.Provider;
import java.security.NoSuchAlgorithmException;
import javax.crypto.Cipher;
import javax.crypto.spec.ChaCha20ParameterSpec;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;

Expand All @@ -60,8 +60,7 @@ public void main(Provider p) throws GeneralSecurityException {
try {
Cipher.getInstance(ALGO, p);
} catch (NoSuchAlgorithmException nsae) {
System.out.println("Skip; no support for " + ALGO);
return;
throw new SkippedException("Skip; no support for " + ALGO);
}
testGetOutSize(p);
testMultiPartAEADDec(p);
Expand Down
37 changes: 26 additions & 11 deletions test/jdk/sun/security/pkcs11/Cipher/TestCipherMode.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -30,6 +30,8 @@
* @run main/othervm TestCipherMode
*/

import jtreg.SkippedException;

import java.security.Provider;
import java.security.Key;
import java.security.KeyPair;
Expand All @@ -38,20 +40,22 @@
import java.security.PublicKey;
import java.security.InvalidParameterException;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;

public class TestCipherMode extends PKCS11Test {

private static String[] TRANSFORMATIONS = {
"AES/ECB/PKCS5Padding", "AES/GCM/NoPadding",
"RSA/ECB/PKCS1Padding"
private static final String[] TRANSFORMATIONS = {
"AES/ECB/PKCS5Padding", "AES/GCM/NoPadding",
"RSA/ECB/PKCS1Padding"
};

private static byte[] BYTES16 =
Arrays.copyOf(TRANSFORMATIONS[0].getBytes(), 16);
private static final byte[] BYTES16 =
Arrays.copyOf("AES/ECB/PKCS5Padding".getBytes(), 16);
private static SecretKey AES_KEY = new SecretKeySpec(BYTES16, "AES");
private static PublicKey RSA_PUBKEY = null;
private static PrivateKey RSA_PRIVKEY = null;
Expand Down Expand Up @@ -97,18 +101,29 @@ public void main(Provider p) throws Exception {

// test all cipher impls, e.g. P11Cipher, P11AEADCipher, and
// P11RSACipher
for (String t : TRANSFORMATIONS) {
checkModes(t, p);
List<String> skipped = new ArrayList<>();
for (final String t : TRANSFORMATIONS) {
try {
checkModes(t, p);
} catch (SkippedException skippedException) {
// printing to System.out, so it's easier to see which test it relates to
skippedException.printStackTrace(System.out);
skipped.add(t);
}
}

if (!skipped.isEmpty()) {
throw new SkippedException("Some tests skipped: " + skipped);
} else {
System.out.println("All tests passed");
}
System.out.println("All tests passed");
}

private static void checkModes(String t, Provider p) throws Exception {
try {
Cipher.getInstance(t, p);
} catch (Exception e) {
System.out.println("Skip " + t + " due to " + e.getMessage());
return;
throw new SkippedException("Skip " + t + " due to " + e.getMessage());
}

for (CipherMode m : CipherMode.values()) {
Expand Down
Loading