Bouncy Castle Cryptography Library 1.86

org.bouncycastle.crypto.test
Class HPKETestVectors

java.lang.Object
  extended byjunit.framework.Assert
      extended byjunit.framework.TestCase
          extended byorg.bouncycastle.crypto.test.HPKETestVectors
All Implemented Interfaces:
junit.framework.Test

public class HPKETestVectors
extends junit.framework.TestCase


Constructor Summary
HPKETestVectors()
           
 
Method Summary
 void testAuthOneShotPairwise()
           
 void testAuthPairwise()
           
 void testBaseOneShotPairwise()
           
 void testBasePairwise()
           
 void testOpenFailureDoesNotAdvanceSequence()
          RFC 9180 sec. 5.2 advances the sequence number only after a successful Seal/Open.
 void testPQKemAuthModesUnsupported()
           
 void testPQKemBaseOneShotPairwise()
           
 void testPQKemDeriveKeyPair()
           
 void testPQKemPSKPairwise()
           
 void testPQKemSerialization()
           
 void testSealOnExportOnlyLeavesContextUsable()
          The sender side has the same contract: a failed seal must not consume a sequence number.
 void testSendReceiveExportOnlySuite()
          Export is the whole point of the export-only suite, which has no cipher to seal with, so the one-shot export pair has to work there.
 void testSendReceiveExportPairwise()
          The one-shot secret export pair (RFC 9180 sec. 5.3), which had no caller anywhere in the tree and so no coverage at all: HPKE.sendExport(org.bouncycastle.crypto.params.AsymmetricKeyParameter, byte[], byte[], int, byte[], byte[], org.bouncycastle.crypto.AsymmetricCipherKeyPair) sets up a sender context and returns the encapsulation alongside the exported secret, and HPKE.receiveExport(byte[], org.bouncycastle.crypto.AsymmetricCipherKeyPair, byte[], byte[], int, byte[], byte[], org.bouncycastle.crypto.params.AsymmetricKeyParameter) rebuilds the matching context from that encapsulation and must produce the same bytes.
 void testVectors()
           
 void testXWingHPKEVector()
           
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runBare, runTest, setName, setUp, tearDown, toString
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

HPKETestVectors

public HPKETestVectors()
Method Detail

testBaseOneShotPairwise

public void testBaseOneShotPairwise()
                             throws java.lang.Exception
Throws:
java.lang.Exception

testAuthOneShotPairwise

public void testAuthOneShotPairwise()
                             throws java.lang.Exception
Throws:
java.lang.Exception

testSendReceiveExportPairwise

public void testSendReceiveExportPairwise()
                                   throws java.lang.Exception
The one-shot secret export pair (RFC 9180 sec. 5.3), which had no caller anywhere in the tree and so no coverage at all: HPKE.sendExport(org.bouncycastle.crypto.params.AsymmetricKeyParameter, byte[], byte[], int, byte[], byte[], org.bouncycastle.crypto.AsymmetricCipherKeyPair) sets up a sender context and returns the encapsulation alongside the exported secret, and HPKE.receiveExport(byte[], org.bouncycastle.crypto.AsymmetricCipherKeyPair, byte[], byte[], int, byte[], byte[], org.bouncycastle.crypto.params.AsymmetricKeyParameter) rebuilds the matching context from that encapsulation and must produce the same bytes. Both dispatch on the mode the HPKE instance was built with, so all four are exercised here - the psk and auth arguments are only consulted by the modes that need them.

Throws:
java.lang.Exception

testSendReceiveExportOnlySuite

public void testSendReceiveExportOnlySuite()
                                    throws java.lang.Exception
Export is the whole point of the export-only suite, which has no cipher to seal with, so the one-shot export pair has to work there.

Throws:
java.lang.Exception

testOpenFailureDoesNotAdvanceSequence

public void testOpenFailureDoesNotAdvanceSequence()
                                           throws java.lang.Exception
RFC 9180 sec. 5.2 advances the sequence number only after a successful Seal/Open. The receiving context used to advance it while computing the nonce, so a ciphertext rejected by the tag check still moved the counter on and left the receiver permanently out of step with the sender: every subsequent genuine message then failed to open. This is a receiver-side denial of service on a multi-shot context, not a nonce reuse - the counter only ever moved forwards - and the one-shot HPKE.seal/HPKE.open pair is unaffected because each call gets a fresh context.

Throws:
java.lang.Exception

testSealOnExportOnlyLeavesContextUsable

public void testSealOnExportOnlyLeavesContextUsable()
                                             throws java.lang.Exception
The sender side has the same contract: a failed seal must not consume a sequence number. Export-only suites cannot seal at all, so the rejection happens before any counter movement and the context stays usable for its exports.

Throws:
java.lang.Exception

testBasePairwise

public void testBasePairwise()
                      throws java.lang.Exception
Throws:
java.lang.Exception

testAuthPairwise

public void testAuthPairwise()
                      throws java.lang.Exception
Throws:
java.lang.Exception

testPQKemBaseOneShotPairwise

public void testPQKemBaseOneShotPairwise()
                                  throws java.lang.Exception
Throws:
java.lang.Exception

testPQKemPSKPairwise

public void testPQKemPSKPairwise()
                          throws java.lang.Exception
Throws:
java.lang.Exception

testPQKemSerialization

public void testPQKemSerialization()
                            throws java.lang.Exception
Throws:
java.lang.Exception

testPQKemDeriveKeyPair

public void testPQKemDeriveKeyPair()
                            throws java.lang.Exception
Throws:
java.lang.Exception

testPQKemAuthModesUnsupported

public void testPQKemAuthModesUnsupported()
                                   throws java.lang.Exception
Throws:
java.lang.Exception

testXWingHPKEVector

public void testXWingHPKEVector()
                         throws java.lang.Exception
Throws:
java.lang.Exception

testVectors

public void testVectors()
                 throws java.lang.Exception
Throws:
java.lang.Exception

Bouncy Castle Cryptography Library 1.86