Top Description Fields Constructors Methods
org.bouncycastle.crypto.general

pack-priv Class Poly1305KeyGenerator

extends CipherKeyGenerator
Class Inheritance
Imports
org.bouncycastle.crypto.internal.KeyGenerationParameters

Generates keys for the Poly1305 MAC.

Poly1305 keys are 256 bit keys consisting of a 128 bit secret key used for the underlying block cipher followed by a 128 bit r value used for the polynomial portion of the Mac.
The r value has a specific format with some bits required to be cleared, resulting in an effective 106 bit key.
A separately generated 256 bit key can be modified to fit the Poly1305 key format by using the clamp(byte[]) method to clear the required bits.

See Also
Poly1305Impl

Field Summary

Modifier and TypeField and Description
private static final byte
private static final byte
Inherited from org.bouncycastle.crypto.general.CipherKeyGenerator:
randomstrength

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv static byte[]
clamp(byte[]
a 32 byte key value k[0] ... k[15], r[0] ... r[15]
key
)

Modifies an existing 32 byte key value to comply with the requirements of the Poly1305 key by clearing required bits in the r (second 16 bytes) portion of the key.

public byte[]
generateKey()

Overrides org.bouncycastle.crypto.general.CipherKeyGenerator.generateKey.

Generates a 256 bit key in the format required for Poly1305 - e.g. k[0] ...
public void
init(KeyGenerationParameters
the parameters to be used for key generation
param
)

Overrides org.bouncycastle.crypto.general.CipherKeyGenerator.init.

Initialises the key generator.

Field Detail

R_MASK_HIGH_4back to summary
private static final byte R_MASK_HIGH_4
R_MASK_LOW_2back to summary
private static final byte R_MASK_LOW_2

Constructor Detail

Poly1305KeyGeneratorback to summary
pack-priv Poly1305KeyGenerator()

Method Detail

clampback to summary
pack-priv static byte[] clamp(byte[] key)

Modifies an existing 32 byte key value to comply with the requirements of the Poly1305 key by clearing required bits in the r (second 16 bytes) portion of the key.
Specifically:

  • r[3], r[7], r[11], r[15] have top four bits clear (i.e., are {0, 1, . . . , 15})
  • r[4], r[8], r[12] have bottom two bits clear (i.e., are in {0, 4, 8, . . . , 252})
Parameters
key:byte[]

a 32 byte key value k[0] ... k[15], r[0] ... r[15]

generateKeyback to summary
public byte[] generateKey()

Overrides org.bouncycastle.crypto.general.CipherKeyGenerator.generateKey.

Generates a 256 bit key in the format required for Poly1305 - e.g. k[0] ... k[15], r[0] ... r[15] with the required bits in r cleared as per clamp(byte[]).

Returns:byte[]

Doc from org.bouncycastle.crypto.general.CipherKeyGenerator.generateKey.

a byte array containing the key value.

initback to summary
public void init(KeyGenerationParameters param)

Overrides org.bouncycastle.crypto.general.CipherKeyGenerator.init.

Initialises the key generator.
Poly1305 keys are always 256 bits, so the key length in the provided parameters is ignored.

Parameters
param:KeyGenerationParameters

Doc from org.bouncycastle.crypto.general.CipherKeyGenerator.init.

the parameters to be used for key generation