RFR: 8308711: Develop additional Tests for KEM implementation [v3]

Weijun Wang weijun at openjdk.org
Wed May 31 13:15:04 UTC 2023


On Wed, 31 May 2023 06:27:09 GMT, Sibabrata Sahoo <ssahoo at openjdk.org> wrote:

>> Additional Tests for KEM API.
>
> Sibabrata Sahoo has updated the pull request incrementally with one additional commit since the last revision:
> 
>   8308711: Comment addressed

test/jdk/javax/crypto/KEM/GenLargeNumberOfKeys.java line 45:

> 43:      * X448 produce keysize of 64 bytes which is larger in it's class
> 44:      * secp521r1 produce keysize of 64 bytes which is larger in it's class
> 45:      */

I don't quite understand what the comment mean.

test/jdk/javax/crypto/KEM/GenLargeNumberOfKeys.java line 64:

> 62:     private static KeyPair genKeyPair(String algo, String curveId) throws Exception {
> 63:         KeyPairGenerator kpg = KeyPairGenerator.getInstance(algo);
> 64:         kpg.initialize(new ECGenParameterSpec(curveId));

Although `ECGenParameterSpec` is a `NamedParameterSpec`, we usually don't create XDH keys using it. How about following the same style in `KemTest` and only call `initialize` when it's EC. For XDH, just use `X448` as the `algo` and there is no need to initialize it.

test/jdk/javax/crypto/KEM/KemTest.java line 129:

> 127:                 Asserts.assertEQ(encT.encapsulationSize(), decT.encapsulationSize());
> 128:                 Asserts.assertEQ(encT.secretSize(), enc.key().getEncoded().length);
> 129:                 Asserts.assertEQ(encT.secretSize(), decT.secretSize());

Since the decapsulator also has `secretSize` and `encapsulationSize` methods, you can add some more lines testing the output of them as well.

test/jdk/javax/crypto/KEM/KemTest.java line 195:

> 193:                 Callable<KEM.Encapsulator> task = () -> {
> 194:                     return kem.newEncapsulator(kp.getPublic());
> 195:                 };

Just use `() -> kem.newEncapsulator(kp.getPublic())`. Same on lines 229, 262, 300.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/14113#discussion_r1211680963
PR Review Comment: https://git.openjdk.org/jdk/pull/14113#discussion_r1211685868
PR Review Comment: https://git.openjdk.org/jdk/pull/14113#discussion_r1211691568
PR Review Comment: https://git.openjdk.org/jdk/pull/14113#discussion_r1211695732


More information about the security-dev mailing list