Top Fields Constructors Methods
sun.security.provider

public Class CtrDrbg

extends AbstractDrbg
Class Inheritance
Imports
javax.crypto.Cipher, .NoSuchPaddingException, javax.crypto.spec.SecretKeySpec, java.security.*, java.util.Arrays, .HexFormat, .Locale

Field Summary

Modifier and TypeField and Description
private static final int
private int
private Cipher
private String
private int
private byte[]
k

private String
private int
private int
private byte[]
v

Inherited from sun.security.provider.AbstractDrbg:
algorithmdebugDEFAULT_STRENGTHhighestSupportedSecurityStrengthmaxAdditionalInputLengthmaxLengthmaxNumberOfBytesPerRequestmaxPersonalizationStringLengthmechNameminLengthnoncepersonalizationStringrequestedAlgorithmrequestedInstantiationSecurityStrengthreseedCounterreseedIntervalsecurityStrengthsupportPredictionResistancesupportReseedingusedf

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private static void
addOne(byte[] data, int len)

Add one to data, only touch the last len bytes.

private static int
alg2strength(String algorithm)

private byte[]

Returns:

the result
bcc
(byte[]
the key
k
,
byte[]...
after concatenated, the data to be operated upon. This is a series of byte[], each with an arbitrary length. Note that the full length is not necessarily a multiple of outlen. XOR with zero is no-op.
data
)

Block_Encrypt in 10.3.3

protected void
chooseAlgorithmAndStrength()

Implements abstract sun.security.provider.AbstractDrbg.chooseAlgorithmAndStrength.

Decides what algorithm and strength to use (SHA-256 or AES-256, 128 or 256).
private byte[]

Returns:

the output block (always of seedLen)
df
(byte[]
the input string
input
)

Block_cipher_df in 10.3.2

public synchronized void
generateAlgorithm(byte[]
fill result here, not null
result
,
byte[]
additional input, can be null. If not null, its length is smaller than maxAdditionalInputLength
additionalInput
)

Implements abstract sun.security.provider.AbstractDrbg.generateAlgorithm.

The generate function.
protected void
initEngine()

Implements abstract sun.security.provider.AbstractDrbg.initEngine.

This call, used by the constructors, instantiates the digest.
protected void
instantiateAlgorithm(byte[]
the entropy input, its length is already conditioned to be between minLength and maxLength.
ei
)

Implements abstract sun.security.provider.AbstractDrbg.instantiateAlgorithm.

Instantiates a DRBG.
protected synchronized void
reseedAlgorithm(byte[]
the entropy input, its length is already conditioned to be between minLength and maxLength.
ei
,
byte[]
additional input, can be null. If not null, its length is smaller than maxAdditionalInputLength
additionalInput
)

Overrides sun.security.provider.AbstractDrbg.reseedAlgorithm.

The reseed function.
private void
public String
toString()

Overrides sun.security.provider.AbstractDrbg.toString.

Returns a string representation of the object.
private void
update(byte[] input)

Inherited from sun.security.provider.AbstractDrbg:
configureengineGenerateSeedengineGetParametersengineNextBytesengineNextBytesengineReseedengineSetSeedgetStandardStrength

Field Detail

AES_LIMITback to summary
private static final int AES_LIMIT
blockLenback to summary
private int blockLen
cipherback to summary
private Cipher cipher
cipherAlgback to summary
private String cipherAlg
ctrLenback to summary
private int ctrLen
kback to summary
private byte[] k
keyAlgback to summary
private String keyAlg
keyLenback to summary
private int keyLen
seedLenback to summary
private int seedLen
vback to summary
private byte[] v

Constructor Detail

CtrDrbgback to summary
public CtrDrbg(SecureRandomParameters params)

Method Detail

addOneback to summary
private static void addOne(byte[] data, int len)

Add one to data, only touch the last len bytes.

alg2strengthback to summary
private static int alg2strength(String algorithm)
bccback to summary
private byte[] bcc(byte[] k, byte[]... data)

Block_Encrypt in 10.3.3

Parameters
k:byte[]

the key

data:byte[][]

after concatenated, the data to be operated upon. This is a series of byte[], each with an arbitrary length. Note that the full length is not necessarily a multiple of outlen. XOR with zero is no-op.

Returns:byte[]

the result

chooseAlgorithmAndStrengthback to summary
protected void chooseAlgorithmAndStrength()

Implements abstract sun.security.provider.AbstractDrbg.chooseAlgorithmAndStrength.

Doc from sun.security.provider.AbstractDrbg.chooseAlgorithmAndStrength.

Decides what algorithm and strength to use (SHA-256 or AES-256, 128 or 256). Strength related fields must also be defined or redefined here. Called in configure. A mechanism uses requestedAlgorithm, requestedInstantiationSecurityStrength, and DEFAULT_STRENGTH to decide which algorithm and strength to use.

If requestedAlgorithm is provided, it will always be used. If requestedInstantiationSecurityStrength is also provided, the algorithm will use the strength (an exception will be thrown if the strength is not supported), otherwise, the smaller one of the highest supported strength of the algorithm and the default strength will be used.

If requestedAlgorithm is not provided, an algorithm will be chosen that supports requestedInstantiationSecurityStrength (or DEFAULT_STRENGTH if there is no request).

Since every call to configure will call this method, make sure to the calls do not contradict with each other.

Here are some examples of the algorithm and strength chosen (suppose DEFAULT_STRENGTH is 128) for HashDRBG:

requested             effective
(SHA-224, 256)        IAE
(SHA-256, -1)         (SHA-256,128)
(SHA-256, 112)        (SHA-256,112)
(SHA-256, 128)        (SHA-256,128)
(SHA-3, -1)           IAE
(null, -1)            (SHA-256,128)
(null, 112)           (SHA-256,112)
(null, 192)           (SHA-256,192)
(null, 256)           (SHA-256,256)
(null, 384)           IAE
Annotations
@Override
dfback to summary
private byte[] df(byte[] input)

Block_cipher_df in 10.3.2

Parameters
input:byte[]

the input string

Returns:byte[]

the output block (always of seedLen)

generateAlgorithmback to summary
public synchronized void generateAlgorithm(byte[] result, byte[] additionalInput)

Implements abstract sun.security.provider.AbstractDrbg.generateAlgorithm.

Doc from sun.security.provider.AbstractDrbg.generateAlgorithm.

The generate function.

Parameters
result:byte[]

fill result here, not null

additionalInput:byte[]

additional input, can be null. If not null, its length is smaller than maxAdditionalInputLength

Annotations
@Override
initEngineback to summary
protected void initEngine()

Implements abstract sun.security.provider.AbstractDrbg.initEngine.

This call, used by the constructors, instantiates the digest.

Annotations
@Override
instantiateAlgorithmback to summary
protected void instantiateAlgorithm(byte[] ei)

Implements abstract sun.security.provider.AbstractDrbg.instantiateAlgorithm.

Doc from sun.security.provider.AbstractDrbg.instantiateAlgorithm.

Instantiates a DRBG. Called automatically before the first nextBytes call.

Note that the other parameters (nonce, strength, ps) are already stored inside at configuration.

Parameters
ei:byte[]

the entropy input, its length is already conditioned to be between minLength and maxLength.

Annotations
@Override
reseedAlgorithmback to summary
protected synchronized void reseedAlgorithm(byte[] ei, byte[] additionalInput)

Overrides sun.security.provider.AbstractDrbg.reseedAlgorithm.

Doc from sun.security.provider.AbstractDrbg.reseedAlgorithm.

The reseed function.

Parameters
ei:byte[]

the entropy input, its length is already conditioned to be between minLength and maxLength.

additionalInput:byte[]

additional input, can be null. If not null, its length is smaller than maxAdditionalInputLength

Annotations
@Override
statusback to summary
private void status()
toStringback to summary
public String toString()

Overrides sun.security.provider.AbstractDrbg.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object

Annotations
@Override
updateback to summary
private void update(byte[] input)