Class RBGNonce

java.lang.Object
org.cryptacular.generator.sp80038a.RBGNonce
All Implemented Interfaces:
Nonce

public class RBGNonce extends Object implements Nonce
Nonce generation strategy that produces a random value according to NIST SP-800-38a, appendix C, method 2 (random number generator), suitable for use with any block cipher mode described in that standard except OFB.

Instances of this class are thread safe.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final int
    Length of generated nonces.
    private final org.bouncycastle.crypto.prng.drbg.SP80090DRBG
    Random bit generator.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new instance that produces 16-bytes (128-bits) of random data.
    RBGNonce(int length)
    Creates a new instance that produces length bytes of random data.
  • Method Summary

    Modifier and Type
    Method
    Description
    byte[]
    Generates a nonce value.
    int
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • length

      private final int length
      Length of generated nonces.
    • rbg

      private final org.bouncycastle.crypto.prng.drbg.SP80090DRBG rbg
      Random bit generator.
  • Constructor Details

    • RBGNonce

      public RBGNonce()
      Creates a new instance that produces 16-bytes (128-bits) of random data.
    • RBGNonce

      public RBGNonce(int length)
      Creates a new instance that produces length bytes of random data.
      Parameters:
      length - Number of bytes in generated nonce values.
  • Method Details

    • generate

      public byte[] generate() throws LimitException
      Description copied from interface: Nonce
      Generates a nonce value.
      Specified by:
      generate in interface Nonce
      Returns:
      Nonce bytes.
      Throws:
      LimitException - When a limit imposed by the nonce generation strategy, if any, is exceeded.
    • getLength

      public int getLength()
      Specified by:
      getLength in interface Nonce
      Returns:
      Length in bytes of generated nonce values.