Top Description Inners Fields Constructors Methods
org.bouncycastle.crypto.engines

public Class EthereumIESEngine

extends Object
Class Inheritance
Imports
java.io.ByteArrayInputStream, .IOException, java.math.BigInteger, org.bouncycastle.crypto.BasicAgreement, .BufferedBlockCipher, .CipherParameters, .DataLengthException, .DerivationFunction, .DerivationParameters, .Digest, .DigestDerivationFunction, .EphemeralKeyPair, .InvalidCipherTextException, .KeyParser, .Mac, .OutputLengthException, org.bouncycastle.crypto.digests.SHA256Digest, org.bouncycastle.crypto.generators.EphemeralKeyPairGenerator, org.bouncycastle.crypto.params.AsymmetricKeyParameter, .IESParameters, .IESWithCipherParameters, .ISO18033KDFParameters, .KDFParameters, .KeyParameter, .ParametersWithIV, org.bouncycastle.util.Arrays, .BigIntegers, .Pack

Support class for constructing integrated encryption ciphers for doing basic message exchanges on top of key agreement ciphers. Follows the description given in IEEE Std 1363a.

Some tweaks added to IESEngine to conform to the Ethereum encryption approach.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
EthereumIESEngine.HandshakeKDFFunction

Basic KDF generator for derived keys and ivs as defined by IEEE P1363a/ISO 18033 This implementation is based on ISO 18033/P1363a.

Field Summary

Modifier and TypeField and Description
pack-priv BasicAgreement
pack-priv BufferedBlockCipher
pack-priv byte[]
pack-priv boolean
private byte[]
pack-priv DerivationFunction
private EphemeralKeyPairGenerator
private KeyParser
pack-priv Mac
pack-priv byte[]
pack-priv IESParameters
pack-priv CipherParameters
pack-priv CipherParameters
pack-priv byte[]
V

Constructor Summary

AccessConstructor and Description
public
EthereumIESEngine(BasicAgreement
the key agreement used as the basis for the encryption
agree
,
DerivationFunction
the key derivation function used for byte generation
kdf
,
Mac
the message authentication code generator for the message
mac
,
byte[]
the common MAC bytes to append to the mac
commonMac
)

Set up for use with stream mode, where the key derivation function is used to provide a stream of bytes to xor with the message.

public
EthereumIESEngine(BasicAgreement
the key agreement used as the basis for the encryption
agree
,
DerivationFunction
the key derivation function used for byte generation
kdf
,
Mac
the message authentication code generator for the message
mac
,
byte[]
the common MAC bytes to append to the mac
commonMac
,
BufferedBlockCipher
the cipher to used for encrypting the message
cipher
)

Set up for use in conjunction with a block cipher to handle the message.

Method Summary

Modifier and TypeMethod and Description
private byte[]
decryptBlock(byte[] in_enc, int inOff, int inLen)

private byte[]
encryptBlock(byte[] in, int inOff, int inLen)

private void
public BufferedBlockCipher
protected byte[]
getLengthTag(byte[] p2)

public Mac
public void
init(boolean
whether or not this is encryption/decryption.
forEncryption
,
CipherParameters
our private key parameters
privParam
,
CipherParameters
the recipient's/sender's public key parameters
pubParam
,
CipherParameters
encoding and derivation parameters, may be wrapped to include an IV for an underlying block cipher.
params
)

Initialise the encryptor.

public void
init(AsymmetricKeyParameter
the recipient's/sender's public key parameters
publicKey
,
CipherParameters
encoding and derivation parameters, may be wrapped to include an IV for an underlying block cipher.
params
,
EphemeralKeyPairGenerator
the ephemeral key pair generator to use.
ephemeralKeyPairGenerator
)

Initialise the decryptor.

public void
init(AsymmetricKeyParameter
the recipient's private key.
privateKey
,
CipherParameters
encoding and derivation parameters, may be wrapped to include an IV for an underlying block cipher.
params
,
KeyParser
the parser for reading the ephemeral public key.
publicKeyParser
)

Initialise the encryptor.

public byte[]
processBlock(byte[] in, int inOff, int inLen)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

agreeback to summary
pack-priv BasicAgreement agree
cipherback to summary
pack-priv BufferedBlockCipher cipher
commonMacback to summary
pack-priv byte[] commonMac
forEncryptionback to summary
pack-priv boolean forEncryption
IVback to summary
private byte[] IV
kdfback to summary
pack-priv DerivationFunction kdf
keyPairGeneratorback to summary
private EphemeralKeyPairGenerator keyPairGenerator
keyParserback to summary
private KeyParser keyParser
macback to summary
pack-priv Mac mac
macBufback to summary
pack-priv byte[] macBuf
paramback to summary
pack-priv IESParameters param
privParamback to summary
pack-priv CipherParameters privParam
pubParamback to summary
pack-priv CipherParameters pubParam
Vback to summary
pack-priv byte[] V

Constructor Detail

EthereumIESEngineback to summary
public EthereumIESEngine(BasicAgreement agree, DerivationFunction kdf, Mac mac, byte[] commonMac)

Set up for use with stream mode, where the key derivation function is used to provide a stream of bytes to xor with the message.

Parameters
agree:BasicAgreement

the key agreement used as the basis for the encryption

kdf:DerivationFunction

the key derivation function used for byte generation

mac:Mac

the message authentication code generator for the message

commonMac:byte[]

the common MAC bytes to append to the mac

EthereumIESEngineback to summary
public EthereumIESEngine(BasicAgreement agree, DerivationFunction kdf, Mac mac, byte[] commonMac, BufferedBlockCipher cipher)

Set up for use in conjunction with a block cipher to handle the message. It is strongly recommended that the cipher is not in ECB mode.

Parameters
agree:BasicAgreement

the key agreement used as the basis for the encryption

kdf:DerivationFunction

the key derivation function used for byte generation

mac:Mac

the message authentication code generator for the message

commonMac:byte[]

the common MAC bytes to append to the mac

cipher:BufferedBlockCipher

the cipher to used for encrypting the message

Method Detail

decryptBlockback to summary
private byte[] decryptBlock(byte[] in_enc, int inOff, int inLen) throws InvalidCipherTextException
encryptBlockback to summary
private byte[] encryptBlock(byte[] in, int inOff, int inLen) throws InvalidCipherTextException
extractParamsback to summary
private void extractParams(CipherParameters params)
getCipherback to summary
public BufferedBlockCipher getCipher()
getLengthTagback to summary
protected byte[] getLengthTag(byte[] p2)
getMacback to summary
public Mac getMac()
initback to summary
public void init(boolean forEncryption, CipherParameters privParam, CipherParameters pubParam, CipherParameters params)

Initialise the encryptor.

Parameters
forEncryption:boolean

whether or not this is encryption/decryption.

privParam:CipherParameters

our private key parameters

pubParam:CipherParameters

the recipient's/sender's public key parameters

params:CipherParameters

encoding and derivation parameters, may be wrapped to include an IV for an underlying block cipher.

initback to summary
public void init(AsymmetricKeyParameter publicKey, CipherParameters params, EphemeralKeyPairGenerator ephemeralKeyPairGenerator)

Initialise the decryptor.

Parameters
publicKey:AsymmetricKeyParameter

the recipient's/sender's public key parameters

params:CipherParameters

encoding and derivation parameters, may be wrapped to include an IV for an underlying block cipher.

ephemeralKeyPairGenerator:EphemeralKeyPairGenerator

the ephemeral key pair generator to use.

initback to summary
public void init(AsymmetricKeyParameter privateKey, CipherParameters params, KeyParser publicKeyParser)

Initialise the encryptor.

Parameters
privateKey:AsymmetricKeyParameter

the recipient's private key.

params:CipherParameters

encoding and derivation parameters, may be wrapped to include an IV for an underlying block cipher.

publicKeyParser:KeyParser

the parser for reading the ephemeral public key.

processBlockback to summary
public byte[] processBlock(byte[] in, int inOff, int inLen) throws InvalidCipherTextException
org.bouncycastle.crypto.engines back to summary

public Class EthereumIESEngine.HandshakeKDFFunction

extends Object
implements DigestDerivationFunction
Class Inheritance
  • java.lang.Object
  • org.bouncycastle.crypto.engines.EthereumIESEngine.HandshakeKDFFunction
All Implemented Interfaces
org.bouncycastle.crypto.DigestDerivationFunction, org.bouncycastle.crypto.DerivationFunction

Basic KDF generator for derived keys and ivs as defined by IEEE P1363a/ISO 18033
This implementation is based on ISO 18033/P1363a.

This class has been adapted from the BaseKDFBytesGenerator implementation of Bouncy Castle. Only one change is present specifically for Ethereum.

Field Summary

Modifier and TypeField and Description
private int
private Digest
private byte[]
private byte[]

Constructor Summary

AccessConstructor and Description
public
HandshakeKDFFunction(int
value of counter.
counterStart
,
Digest
the digest to be used as the source of derived keys.
digest
)

Construct a KDF Parameters generator.

Method Summary

Modifier and TypeMethod and Description
public int
generateBytes(byte[] out, int outOff, int len)

Implements org.bouncycastle.crypto.DerivationFunction.generateBytes.

fill len bytes of the output buffer with bytes generated from the derivation function.
public Digest
getDigest()

Implements org.bouncycastle.crypto.DigestDerivationFunction.getDigest.

return the underlying digest.
public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

counterStartback to summary
private int counterStart
digestback to summary
private Digest digest
ivback to summary
private byte[] iv
sharedback to summary
private byte[] shared

Constructor Detail

HandshakeKDFFunctionback to summary
public HandshakeKDFFunction(int counterStart, Digest digest)

Construct a KDF Parameters generator.

Parameters
counterStart:int

value of counter.

digest:Digest

the digest to be used as the source of derived keys.

Method Detail

generateBytesback to summary
public int generateBytes(byte[] out, int outOff, int len) throws DataLengthException, IllegalArgumentException

Implements org.bouncycastle.crypto.DerivationFunction.generateBytes.

fill len bytes of the output buffer with bytes generated from the derivation function.

Exceptions
DataLengthException:
if the out buffer is too small.
IllegalArgumentException:
if the size of the request will cause an overflow.
getDigestback to summary
public Digest getDigest()

Implements org.bouncycastle.crypto.DigestDerivationFunction.getDigest.

return the underlying digest.

initback to summary
public void init(DerivationParameters param)

Implements org.bouncycastle.crypto.DerivationFunction.init.