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

public Class SparkleEngine

extends Object
implements AEADCipher
Class Inheritance
All Implemented Interfaces
org.bouncycastle.crypto.modes.AEADCipher
Imports
org.bouncycastle.crypto.CipherParameters, .CryptoServicesRegistrar, .DataLengthException, .InvalidCipherTextException, .OutputLengthException, org.bouncycastle.crypto.constraints.DefaultServiceProperties, org.bouncycastle.crypto.digests.SparkleDigest, org.bouncycastle.crypto.modes.AEADCipher, org.bouncycastle.crypto.params.AEADParameters, .KeyParameter, .ParametersWithIV, org.bouncycastle.util.Arrays, .Integers, .Pack

Sparkle v1.2, based on the current round 3 submission, https://sparkle-lwc.github.io/ Reference C implementation: https://github.com/cryptolu/sparkle Specification: https://csrc.nist.gov/CSRC/media/Projects/lightweight-cryptography/documents/finalist-round/updated-spec-doc/sparkle-spec-final.pdf

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
private static enum

Field Summary

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

private final int
private final int
private final byte[]
private final int
private int
private SparkleEngine.State
private final int[]
private final int
private final int
private static final int[]
private final int
private final int
private final int
private final int
private final int[]
private final int
private byte[]
private final int
private final int

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private void
private boolean
public int
doFinal(byte[]
space for any resulting output data.
out
,
int
offset into out to start copying the data at.
outOff
)

Implements org.bouncycastle.crypto.modes.AEADCipher.doFinal.

Finish the operation either appending or verifying the MAC at the end of the data.
private static int
ELL(int x)

private void
public String
getAlgorithmName()

Implements org.bouncycastle.crypto.modes.AEADCipher.getAlgorithmName.

Return the name of the algorithm.
public int
public int
public byte[]
getMac()

Implements org.bouncycastle.crypto.modes.AEADCipher.getMac.

Return the value of the MAC associated with the last stream processed.
public int
getOutputSize(int
the length of the input.
len
)

Implements org.bouncycastle.crypto.modes.AEADCipher.getOutputSize.

return the size of the output buffer required for a processBytes plus a doFinal with an input of len bytes.
public int
getUpdateOutputSize(int
the length of the input.
len
)

Implements org.bouncycastle.crypto.modes.AEADCipher.getUpdateOutputSize.

return the size of the output buffer required for a processBytes an input of len bytes.
public void
init(boolean
true if we are setting up for encryption, false otherwise.
forEncryption
,
CipherParameters
the necessary parameters for the underlying cipher to be initialised.
params
)

Implements org.bouncycastle.crypto.modes.AEADCipher.init.

initialise the underlying cipher.
public void
processAADByte(byte
the byte to be processed.
in
)

Implements org.bouncycastle.crypto.modes.AEADCipher.processAADByte.

Add a single byte to the associated data check.
public void
processAADBytes(byte[]
the input byte array.
in
,
int
the offset into the in array where the data to be processed starts.
inOff
,
int
the number of bytes to be processed.
len
)

Implements org.bouncycastle.crypto.modes.AEADCipher.processAADBytes.

Add a sequence of bytes to the associated data check.
private void
processBufferAAD(byte[] buffer, int bufOff)

private void
processBufferDecrypt(byte[] buffer, int bufOff, byte[] output, int outOff)

private void
processBufferEncrypt(byte[] buffer, int bufOff, byte[] output, int outOff)

public int
processByte(byte
the byte to be processed.
in
,
byte[]
the output buffer the processed byte goes into.
out
,
int
the offset into the output byte array the processed data starts at.
outOff
)

Implements org.bouncycastle.crypto.modes.AEADCipher.processByte.

encrypt/decrypt a single byte.
public int
processBytes(byte[]
the input byte array.
in
,
int
the offset into the in array where the data to be processed starts.
inOff
,
int
the number of bytes to be processed.
len
,
byte[]
the output buffer the processed bytes go into.
out
,
int
the offset into the output byte array the processed data starts at.
outOff
)

Implements org.bouncycastle.crypto.modes.AEADCipher.processBytes.

process a block of bytes from in putting the result into out.
private void
public void
private void
reset(boolean clearMac)

private static void
sparkle_opt(int[] state, int steps)

pack-priv static void
sparkle_opt12(int[] state, int steps)

public static void
sparkle_opt12(SparkleDigest.Friend friend, int[] state, int steps)

pack-priv static void
sparkle_opt16(int[] state, int steps)

public static void
sparkle_opt16(SparkleDigest.Friend friend, int[] state, int steps)

pack-priv static void
sparkle_opt8(int[] state, int steps)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

_A0back to summary
private final int _A0
_A1back to summary
private final int _A1
_M2back to summary
private final int _M2
_M3back to summary
private final int _M3
algorithmNameback to summary
private String algorithmName
CAP_MASKback to summary
private final int CAP_MASK
encryptedback to summary
private boolean encrypted
initialAssociatedTextback to summary
private byte[] initialAssociatedText
kback to summary
private final int[] k
KEY_BYTESback to summary
private final int KEY_BYTES
KEY_WORDSback to summary
private final int KEY_WORDS
m_bufback to summary
private final byte[] m_buf
m_bufferSizeDecryptback to summary
private final int m_bufferSizeDecrypt
m_bufPosback to summary
private int m_bufPos
m_stateback to summary
private SparkleEngine.State m_state
npubback to summary
private final int[] npub
RATE_BYTESback to summary
private final int RATE_BYTES
RATE_WORDSback to summary
private final int RATE_WORDS
RCONback to summary
private static final int[] RCON
SCHWAEMM_KEY_LENback to summary
private final int SCHWAEMM_KEY_LEN
SCHWAEMM_NONCE_LENback to summary
private final int SCHWAEMM_NONCE_LEN
SPARKLE_STEPS_BIGback to summary
private final int SPARKLE_STEPS_BIG
SPARKLE_STEPS_SLIMback to summary
private final int SPARKLE_STEPS_SLIM
stateback to summary
private final int[] state
STATE_WORDSback to summary
private final int STATE_WORDS
tagback to summary
private byte[] tag
TAG_BYTESback to summary
private final int TAG_BYTES
TAG_WORDSback to summary
private final int TAG_WORDS

Constructor Detail

SparkleEngineback to summary
public SparkleEngine(SparkleEngine.SparkleParameters sparkleParameters)

Method Detail

checkAADback to summary
private void checkAAD()
checkDataback to summary
private boolean checkData()
doFinalback to summary
public int doFinal(byte[] out, int outOff) throws IllegalStateException, InvalidCipherTextException

Implements org.bouncycastle.crypto.modes.AEADCipher.doFinal.

Doc from org.bouncycastle.crypto.modes.AEADCipher.doFinal.

Finish the operation either appending or verifying the MAC at the end of the data.

Parameters
out:byte[]

space for any resulting output data.

outOff:int

offset into out to start copying the data at.

Returns:int

number of bytes written into out.

Exceptions
IllegalStateException:
if the cipher is in an inappropriate state.
InvalidCipherTextException:
if the MAC fails to match.
ELLback to summary
private static int ELL(int x)
finishAADback to summary
private void finishAAD(SparkleEngine.State nextState)
getAlgorithmNameback to summary
public String getAlgorithmName()

Implements org.bouncycastle.crypto.modes.AEADCipher.getAlgorithmName.

Doc from org.bouncycastle.crypto.modes.AEADCipher.getAlgorithmName.

Return the name of the algorithm.

Returns:String

the algorithm name.

getIVBytesSizeback to summary
public int getIVBytesSize()
getKeyBytesSizeback to summary
public int getKeyBytesSize()
getMacback to summary
public byte[] getMac()

Implements org.bouncycastle.crypto.modes.AEADCipher.getMac.

Doc from org.bouncycastle.crypto.modes.AEADCipher.getMac.

Return the value of the MAC associated with the last stream processed.

Returns:byte[]

MAC for plaintext data.

getOutputSizeback to summary
public int getOutputSize(int len)

Implements org.bouncycastle.crypto.modes.AEADCipher.getOutputSize.

Doc from org.bouncycastle.crypto.modes.AEADCipher.getOutputSize.

return the size of the output buffer required for a processBytes plus a doFinal with an input of len bytes.

The returned size may be dependent on the initialisation of this cipher and may not be accurate once subsequent input data is processed - this method should be invoked immediately prior to a call to final processing of input data and a call to doFinal(byte[], int).

Parameters
len:int

the length of the input.

Returns:int

the space required to accommodate a call to processBytes and doFinal with len bytes of input.

getUpdateOutputSizeback to summary
public int getUpdateOutputSize(int len)

Implements org.bouncycastle.crypto.modes.AEADCipher.getUpdateOutputSize.

Doc from org.bouncycastle.crypto.modes.AEADCipher.getUpdateOutputSize.

return the size of the output buffer required for a processBytes an input of len bytes.

The returned size may be dependent on the initialisation of this cipher and may not be accurate once subsequent input data is processed - this method should be invoked immediately prior to input data being processed.

Parameters
len:int

the length of the input.

Returns:int

the space required to accommodate a call to processBytes with len bytes of input.

initback to summary
public void init(boolean forEncryption, CipherParameters params) throws IllegalArgumentException

Implements org.bouncycastle.crypto.modes.AEADCipher.init.

Doc from org.bouncycastle.crypto.modes.AEADCipher.init.

initialise the underlying cipher. Parameter can either be an AEADParameters or a ParametersWithIV object.

Parameters
forEncryption:boolean

true if we are setting up for encryption, false otherwise.

params:CipherParameters

the necessary parameters for the underlying cipher to be initialised.

Exceptions
IllegalArgumentException:
if the params argument is inappropriate.
processAADByteback to summary
public void processAADByte(byte in)

Implements org.bouncycastle.crypto.modes.AEADCipher.processAADByte.

Doc from org.bouncycastle.crypto.modes.AEADCipher.processAADByte.

Add a single byte to the associated data check.
If the implementation supports it, this will be an online operation and will not retain the associated data.

Parameters
in:byte

the byte to be processed.

processAADBytesback to summary
public void processAADBytes(byte[] in, int inOff, int len)

Implements org.bouncycastle.crypto.modes.AEADCipher.processAADBytes.

Doc from org.bouncycastle.crypto.modes.AEADCipher.processAADBytes.

Add a sequence of bytes to the associated data check.
If the implementation supports it, this will be an online operation and will not retain the associated data.

Parameters
in:byte[]

the input byte array.

inOff:int

the offset into the in array where the data to be processed starts.

len:int

the number of bytes to be processed.

processBufferAADback to summary
private void processBufferAAD(byte[] buffer, int bufOff)
processBufferDecryptback to summary
private void processBufferDecrypt(byte[] buffer, int bufOff, byte[] output, int outOff)
processBufferEncryptback to summary
private void processBufferEncrypt(byte[] buffer, int bufOff, byte[] output, int outOff)
processByteback to summary
public int processByte(byte in, byte[] out, int outOff) throws DataLengthException

Implements org.bouncycastle.crypto.modes.AEADCipher.processByte.

Doc from org.bouncycastle.crypto.modes.AEADCipher.processByte.

encrypt/decrypt a single byte.

Parameters
in:byte

the byte to be processed.

out:byte[]

the output buffer the processed byte goes into.

outOff:int

the offset into the output byte array the processed data starts at.

Returns:int

the number of bytes written to out.

Exceptions
DataLengthException:
if the output buffer is too small.
processBytesback to summary
public int processBytes(byte[] in, int inOff, int len, byte[] out, int outOff) throws DataLengthException

Implements org.bouncycastle.crypto.modes.AEADCipher.processBytes.

Doc from org.bouncycastle.crypto.modes.AEADCipher.processBytes.

process a block of bytes from in putting the result into out.

Parameters
in:byte[]

the input byte array.

inOff:int

the offset into the in array where the data to be processed starts.

len:int

the number of bytes to be processed.

out:byte[]

the output buffer the processed bytes go into.

outOff:int

the offset into the output byte array the processed data starts at.

Returns:int

the number of bytes written to out.

Exceptions
DataLengthException:
if the output buffer is too small.
processFinalAADback to summary
private void processFinalAAD()
resetback to summary
public void reset()

Implements org.bouncycastle.crypto.modes.AEADCipher.reset.

Doc from org.bouncycastle.crypto.modes.AEADCipher.reset.

Reset the cipher. After resetting the cipher is in the same state as it was after the last init (if there was one).

resetback to summary
private void reset(boolean clearMac)
sparkle_optback to summary
private static void sparkle_opt(int[] state, int steps)
sparkle_opt12back to summary
pack-priv static void sparkle_opt12(int[] state, int steps)
sparkle_opt12back to summary
public static void sparkle_opt12(SparkleDigest.Friend friend, int[] state, int steps)
sparkle_opt16back to summary
pack-priv static void sparkle_opt16(int[] state, int steps)
sparkle_opt16back to summary
public static void sparkle_opt16(SparkleDigest.Friend friend, int[] state, int steps)
sparkle_opt8back to summary
pack-priv static void sparkle_opt8(int[] state, int steps)
org.bouncycastle.crypto.engines back to summary

public final Enum SparkleEngine.SparkleParameters

extends Enum<SparkleEngine.SparkleParameters>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final SparkleEngine.SparkleParameters
public static final SparkleEngine.SparkleParameters
public static final SparkleEngine.SparkleParameters
public static final SparkleEngine.SparkleParameters

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static SparkleEngine.SparkleParameters
public static SparkleEngine.SparkleParameters[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

SCHWAEMM128_128back to summary
public static final SparkleEngine.SparkleParameters SCHWAEMM128_128
SCHWAEMM192_192back to summary
public static final SparkleEngine.SparkleParameters SCHWAEMM192_192
SCHWAEMM256_128back to summary
public static final SparkleEngine.SparkleParameters SCHWAEMM256_128
SCHWAEMM256_256back to summary
public static final SparkleEngine.SparkleParameters SCHWAEMM256_256

Constructor Detail

SparkleParametersback to summary
private SparkleParameters()

Method Detail

valueOfback to summary
public static SparkleEngine.SparkleParameters valueOf(String name)
valuesback to summary
public static SparkleEngine.SparkleParameters[] values()
org.bouncycastle.crypto.engines back to summary

private final Enum SparkleEngine.State

extends Enum<SparkleEngine.State>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final SparkleEngine.State
public static final SparkleEngine.State
public static final SparkleEngine.State
public static final SparkleEngine.State
public static final SparkleEngine.State
public static final SparkleEngine.State
public static final SparkleEngine.State
public static final SparkleEngine.State
public static final SparkleEngine.State

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static SparkleEngine.State
public static SparkleEngine.State[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

DecAadback to summary
public static final SparkleEngine.State DecAad
DecDataback to summary
public static final SparkleEngine.State DecData
DecFinalback to summary
public static final SparkleEngine.State DecFinal
DecInitback to summary
public static final SparkleEngine.State DecInit
EncAadback to summary
public static final SparkleEngine.State EncAad
EncDataback to summary
public static final SparkleEngine.State EncData
EncFinalback to summary
public static final SparkleEngine.State EncFinal
EncInitback to summary
public static final SparkleEngine.State EncInit
Uninitializedback to summary
public static final SparkleEngine.State Uninitialized

Constructor Detail

Stateback to summary
private State()

Method Detail

valueOfback to summary
public static SparkleEngine.State valueOf(String name)
valuesback to summary
public static SparkleEngine.State[] values()