Share via


DrbgParameters Class

Definition

This class specifies the parameters used by a DRBG (Deterministic Random Bit Generator).

[Android.Runtime.Register("java/security/DrbgParameters", ApiSince=35, DoNotGenerateAcw=true)]
public class DrbgParameters : Java.Lang.Object
[<Android.Runtime.Register("java/security/DrbgParameters", ApiSince=35, DoNotGenerateAcw=true)>]
type DrbgParameters = class
    inherit Object
Inheritance
DrbgParameters
Attributes

Remarks

This class specifies the parameters used by a DRBG (Deterministic Random Bit Generator).

According to NIST Special Publication 800-90A Revision 1, Recommendation for Random Number Generation Using Deterministic Random Bit Generators (800-90Ar1), <blockquote> A DRBG is based on a DRBG mechanism as specified in this Recommendation and includes a source of randomness. A DRBG mechanism uses an algorithm (i.e., a DRBG algorithm) that produces a sequence of bits from an initial value that is determined by a seed that is determined from the output of the randomness source." </blockquote>

The 800-90Ar1 specification allows for a variety of DRBG implementation choices, such as: <ul> <li> an entropy source, <li> a DRBG mechanism (for example, Hash_DRBG), <li> a DRBG algorithm (for example, SHA-256 for Hash_DRBG and AES-256 for CTR_DRBG. Please note that it is not the algorithm used in SecureRandom#getInstance, which we will call a <em>SecureRandom algorithm</em> below), <li> optional features, including prediction resistance and reseeding supports, <li> highest security strength. </ul>

These choices are set in each implementation and are not directly managed by the SecureRandom API. Check your DRBG provider's documentation to find an appropriate implementation for the situation.

On the other hand, the 800-90Ar1 specification does have some configurable options, such as: <ul> <li> required security strength, <li> if prediction resistance is required, <li> personalization string and additional input. </ul>

A DRBG instance can be instantiated with parameters from an DrbgParameters.Instantiation object and other information (for example, the nonce, which is not managed by this API). This maps to the Instantiate_function defined in NIST SP 800-90Ar1.

A DRBG instance can be reseeded with parameters from a DrbgParameters.Reseed object. This maps to the Reseed_function defined in NIST SP 800-90Ar1. Calling SecureRandom#reseed() is equivalent to calling SecureRandom#reseed(SecureRandomParameters) with the effective instantiated prediction resistance flag (as returned by SecureRandom#getParameters()) with no additional input.

A DRBG instance generates data with additional parameters from a DrbgParameters.NextBytes object. This maps to the Generate_function defined in NIST SP 800-90Ar1. Calling SecureRandom#nextBytes(byte[]) is equivalent to calling SecureRandom#nextBytes(byte[], SecureRandomParameters) with the effective instantiated strength and prediction resistance flag (as returned by SecureRandom#getParameters()) with no additional input.

A DRBG should be implemented as a subclass of SecureRandomSpi. It is recommended that the implementation contain the 1-arg SecureRandomSpi#SecureRandomSpi(SecureRandomParameters) constructor that takes a DrbgParameters.Instantiation argument. If implemented this way, this implementation can be chosen by any SecureRandom.getInstance() method. If it is chosen by a SecureRandom.getInstance() with a SecureRandomParameters parameter, the parameter is passed into this constructor. If it is chosen by a SecureRandom.getInstance() without a SecureRandomParameters parameter, the constructor is called with a null argument and the implementation should choose its own parameters. Its SecureRandom#getParameters() must always return a non-null effective DrbgParameters.Instantiation object that reflects how the DRBG is actually instantiated. A caller can use this information to determine whether a SecureRandom object is a DRBG and what features it supports. Please note that the returned value does not necessarily equal to the DrbgParameters.Instantiation object passed into the SecureRandom.getInstance() call. For example, the requested capability can be DrbgParameters.Capability#NONE but the effective value can be DrbgParameters.Capability#RESEED_ONLY if the implementation supports reseeding. The implementation must implement the SecureRandomSpi#engineNextBytes(byte[], SecureRandomParameters) method which takes a DrbgParameters.NextBytes parameter. Unless the result of SecureRandom#getParameters() has its DrbgParameters.Instantiation#getCapability() capability being Capability#NONE NONE, it must implement SecureRandomSpi#engineReseed(SecureRandomParameters) which takes a DrbgParameters.Reseed parameter.

On the other hand, if a DRBG implementation does not contain a constructor that has an DrbgParameters.Instantiation argument (not recommended), it can only be chosen by a SecureRandom.getInstance() without a SecureRandomParameters parameter, but will not be chosen if a getInstance method with a SecureRandomParameters parameter is called. If implemented this way, its SecureRandom#getParameters() must return null, and it does not need to implement either SecureRandomSpi#engineNextBytes(byte[], SecureRandomParameters) or SecureRandomSpi#engineReseed(SecureRandomParameters).

A DRBG might reseed itself automatically if the seed period is bigger than the maximum seed life defined by the DRBG mechanism.

A DRBG implementation should support serialization and deserialization by retaining the configuration and effective parameters, but the internal state must not be serialized and the deserialized object must be reinstantiated.

Examples: <blockquote>

SecureRandom drbg;
            byte[] buffer = new byte[32];

            // Any DRBG is OK
            drbg = SecureRandom.getInstance("DRBG");
            drbg.nextBytes(buffer);

            SecureRandomParameters params = drbg.getParameters();
            if (params instanceof DrbgParameters.Instantiation) {
                DrbgParameters.Instantiation ins = (DrbgParameters.Instantiation) params;
                if (ins.getCapability().supportsReseeding()) {
                    drbg.reseed();
                }
            }

            // The following call requests a weak DRBG instance. It is only
            // guaranteed to support 112 bits of security strength.
            drbg = SecureRandom.getInstance("DRBG",
                    DrbgParameters.instantiation(112, NONE, null));

            // Both the next two calls will likely fail, because drbg could be
            // instantiated with a smaller strength with no prediction resistance
            // support.
            drbg.nextBytes(buffer,
                    DrbgParameters.nextBytes(256, false, "more".getBytes()));
            drbg.nextBytes(buffer,
                    DrbgParameters.nextBytes(112, true, "more".getBytes()));

            // The following call requests a strong DRBG instance, with a
            // personalization string. If it successfully returns an instance,
            // that instance is guaranteed to support 256 bits of security strength
            // with prediction resistance available.
            drbg = SecureRandom.getInstance("DRBG", DrbgParameters.instantiation(
                    256, PR_AND_RESEED, "hello".getBytes()));

            // Prediction resistance is not requested in this single call,
            // but an additional input is used.
            drbg.nextBytes(buffer,
                    DrbgParameters.nextBytes(-1, false, "more".getBytes()));

            // Same for this call.
            drbg.reseed(DrbgParameters.reseed(false, "extra".getBytes()));

</blockquote>

Added in 9.

Java documentation for java.security.DrbgParameters.

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Constructors

DrbgParameters(IntPtr, JniHandleOwnership)

Properties

Class

Returns the runtime class of this Object.

(Inherited from Object)
Handle

The handle to the underlying Android instance.

(Inherited from Object)
JniIdentityHashCode (Inherited from Object)
JniPeerMembers
PeerReference (Inherited from Object)
ThresholdClass
ThresholdType

Methods

Clone()

Creates and returns a copy of this object.

(Inherited from Object)
Dispose() (Inherited from Object)
Dispose(Boolean) (Inherited from Object)
Equals(Object)

Indicates whether some other object is "equal to" this one.

(Inherited from Object)
GetHashCode()

Returns a hash code value for the object.

(Inherited from Object)
InvokeInstantiation(Int32, DrbgParameters+Capability, Byte[])
InvokeNextBytes(Int32, Boolean, Byte[])
InvokeReseed(Boolean, Byte[])
JavaFinalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

(Inherited from Object)
Notify()

Wakes up a single thread that is waiting on this object's monitor.

(Inherited from Object)
NotifyAll()

Wakes up all threads that are waiting on this object's monitor.

(Inherited from Object)
SetHandle(IntPtr, JniHandleOwnership)

Sets the Handle property.

(Inherited from Object)
ToArray<T>() (Inherited from Object)
ToString()

Returns a string representation of the object.

(Inherited from Object)
UnregisterFromRuntime() (Inherited from Object)
Wait()

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>.

(Inherited from Object)
Wait(Int64, Int32)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)
Wait(Int64)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)

Explicit Interface Implementations

IJavaPeerable.Disposed() (Inherited from Object)
IJavaPeerable.DisposeUnlessReferenced() (Inherited from Object)
IJavaPeerable.Finalized() (Inherited from Object)
IJavaPeerable.JniManagedPeerState (Inherited from Object)
IJavaPeerable.SetJniIdentityHashCode(Int32) (Inherited from Object)
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) (Inherited from Object)
IJavaPeerable.SetPeerReference(JniObjectReference) (Inherited from Object)

Extension Methods

JavaCast<TResult>(IJavaObject)

Performs an Android runtime-checked type conversion.

JavaCast<TResult>(IJavaObject)
GetJniTypeName(IJavaPeerable)

Gets the JNI name of the type of the instance self.

JavaAs<TResult>(IJavaPeerable)

Try to coerce self to type TResult, checking that the coercion is valid on the Java side.

TryJavaCast<TResult>(IJavaPeerable, TResult)

Try to coerce self to type TResult, checking that the coercion is valid on the Java side.

Applies to