Class NTRUPlusKEMExtractor

java.lang.Object
org.bouncycastle.pqc.crypto.ntruplus.NTRUPlusKEMExtractor
All Implemented Interfaces:
EncapsulatedSecretExtractor

public class NTRUPlusKEMExtractor extends Object implements EncapsulatedSecretExtractor
NTRU+ decapsulation.

Not thread safe. The NTRUPlusEngine built here keeps one SHAKE instance in a field, so two threads sharing an extractor interleave its absorb and squeeze phases: the secrets they recover do not match the sender's, and an IllegalStateException from the digest is also possible. Give each thread its own extractor - construction is cheap, roughly a thousandth of a decapsulation. The KEM.Decapsulator that javax.crypto.KEM builds does exactly that, since that API requires decapsulate to be safe for concurrent use.

  • Constructor Details

  • Method Details

    • extractSecret

      public byte[] extractSecret(byte[] encapsulation)
      Extract the shared secret from an NTRU+ encapsulation.

      NTRU+ rejects an invalid encapsulation explicitly rather than implicitly: there is no pseudorandom rejection secret, so an encapsulation that fails the re-encryption check, or is not a canonical encoding, is refused with an exception instead of yielding a secret.

      Specified by:
      extractSecret in interface EncapsulatedSecretExtractor
      Parameters:
      encapsulation - the encapsulated secret.
      Returns:
      the shared secret.
      Throws:
      IllegalArgumentException - if the encapsulation is the wrong length or is rejected.
    • getEncapsulationLength

      public int getEncapsulationLength()
      Description copied from interface: EncapsulatedSecretExtractor
      Return the length in bytes of the encapsulation.
      Specified by:
      getEncapsulationLength in interface EncapsulatedSecretExtractor
      Returns:
      length in bytes of an encapsulation for this parameter set.