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

public Class NaccacheSternEngine

extends Object
implements AsymmetricBlockCipher
Class Inheritance
All Implemented Interfaces
org.bouncycastle.crypto.AsymmetricBlockCipher
Imports
java.math.BigInteger, java.util.Vector, org.bouncycastle.crypto.AsymmetricBlockCipher, .CipherParameters, .CryptoServicesRegistrar, .DataLengthException, .InvalidCipherTextException, org.bouncycastle.crypto.constraints.ConstraintUtils, .DefaultServiceProperties, org.bouncycastle.crypto.params.NaccacheSternKeyParameters, .NaccacheSternPrivateKeyParameters, .ParametersWithRandom, org.bouncycastle.util.Arrays

NaccacheStern Engine. For details on this cipher, please see https://www.gemplus.com/smart/rd/publications/pdf/NS98pkcs.pdf

Field Summary

Modifier and TypeField and Description
private boolean
private boolean
private NaccacheSternKeyParameters
private Vector<E>[]
private static BigInteger
private static BigInteger

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public byte[]

Returns:

encrypt((block1 + block2) mod sigma)
addCryptedBlocks
(byte[]
the first encrypted block
block1
,
byte[]
the second encrypted block
block2
)

Adds the contents of two encrypted blocks mod sigma

private static BigInteger

Returns:

an integer x for that x % p_i == c_i
chineseRemainder
(Vector<E>
the congruences c_i
congruences
,
Vector<E>
the primes p_i
primes
)

Computes the integer x that is expressed through the given primes and the congruences with the chinese remainder theorem (CRT).

public byte[]

Returns:

The byte[] representation of the encrypted BigInteger (i.e. crypted.toByteArray())
encrypt
(BigInteger
The BigInteger to encrypt
plain
)

Encrypts a BigInteger aka Plaintext with the public key.

public int
getInputBlockSize()

Implements org.bouncycastle.crypto.AsymmetricBlockCipher.getInputBlockSize.

Returns the input block size of this algorithm.
public int
getOutputBlockSize()

Implements org.bouncycastle.crypto.AsymmetricBlockCipher.getOutputBlockSize.

Returns the output block size of this algorithm.
public void
init(boolean
if true the cipher is initialised for encryption, if false for decryption.
forEncryption
,
CipherParameters
the key and other data required by the cipher.
param
)

Implements org.bouncycastle.crypto.AsymmetricBlockCipher.init.

Initializes this algorithm.
public byte[]
processBlock(byte[]
the input data
in
,
int
offset into the in array where the data starts
inOff
,
int
the length of the block to be processed.
len
)

Implements org.bouncycastle.crypto.AsymmetricBlockCipher.processBlock.

Process a single Block using the Naccache-Stern algorithm.
public byte[]

Returns:

the data after it went through the NaccacheSternEngine.
processData
(byte[]
the data to be processed
data
)

Convenience Method for data exchange with the cipher.

public void
setDebug(boolean debug)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

debugback to summary
private boolean debug
forEncryptionback to summary
private boolean forEncryption
keyback to summary
private NaccacheSternKeyParameters key
lookupback to summary
private Vector<E>[] lookup
ONEback to summary
private static BigInteger ONE
ZEROback to summary
private static BigInteger ZERO

Constructor Detail

NaccacheSternEngineback to summary
public NaccacheSternEngine()

Method Detail

addCryptedBlocksback to summary
public byte[] addCryptedBlocks(byte[] block1, byte[] block2) throws InvalidCipherTextException

Adds the contents of two encrypted blocks mod sigma

Parameters
block1:byte[]

the first encrypted block

block2:byte[]

the second encrypted block

Returns:byte[]

encrypt((block1 + block2) mod sigma)

chineseRemainderback to summary
private static BigInteger chineseRemainder(Vector<E> congruences, Vector<E> primes)

Computes the integer x that is expressed through the given primes and the congruences with the chinese remainder theorem (CRT).

Parameters
congruences:Vector<E>

the congruences c_i

primes:Vector<E>

the primes p_i

Returns:BigInteger

an integer x for that x % p_i == c_i

encryptback to summary
public byte[] encrypt(BigInteger plain)

Encrypts a BigInteger aka Plaintext with the public key.

Parameters
plain:BigInteger

The BigInteger to encrypt

Returns:byte[]

The byte[] representation of the encrypted BigInteger (i.e. crypted.toByteArray())

getInputBlockSizeback to summary
public int getInputBlockSize()

Implements org.bouncycastle.crypto.AsymmetricBlockCipher.getInputBlockSize.

Returns the input block size of this algorithm.

Returns:int

Doc from org.bouncycastle.crypto.AsymmetricBlockCipher.getInputBlockSize.

maximum size for an input block.

See Also
org.bouncycastle.crypto.AsymmetricBlockCipher#getInputBlockSize()
getOutputBlockSizeback to summary
public int getOutputBlockSize()

Implements org.bouncycastle.crypto.AsymmetricBlockCipher.getOutputBlockSize.

Returns the output block size of this algorithm.

Returns:int

Doc from org.bouncycastle.crypto.AsymmetricBlockCipher.getOutputBlockSize.

maximum size of the output block produced by the cipher.

See Also
org.bouncycastle.crypto.AsymmetricBlockCipher#getOutputBlockSize()
initback to summary
public void init(boolean forEncryption, CipherParameters param)

Implements org.bouncycastle.crypto.AsymmetricBlockCipher.init.

Initializes this algorithm. Must be called before all other Functions.

Parameters
forEncryption:boolean

Doc from org.bouncycastle.crypto.AsymmetricBlockCipher.init.

if true the cipher is initialised for encryption, if false for decryption.

param:CipherParameters

Doc from org.bouncycastle.crypto.AsymmetricBlockCipher.init.

the key and other data required by the cipher.

See Also
org.bouncycastle.crypto.AsymmetricBlockCipher#init(boolean, org.bouncycastle.crypto.CipherParameters)
processBlockback to summary
public byte[] processBlock(byte[] in, int inOff, int len) throws InvalidCipherTextException

Implements org.bouncycastle.crypto.AsymmetricBlockCipher.processBlock.

Process a single Block using the Naccache-Stern algorithm.

Parameters
in:byte[]

Doc from org.bouncycastle.crypto.AsymmetricBlockCipher.processBlock.

the input data

inOff:int

Doc from org.bouncycastle.crypto.AsymmetricBlockCipher.processBlock.

offset into the in array where the data starts

len:int

Doc from org.bouncycastle.crypto.AsymmetricBlockCipher.processBlock.

the length of the block to be processed.

Returns:byte[]

Doc from org.bouncycastle.crypto.AsymmetricBlockCipher.processBlock.

the resulting byte array of the encryption/decryption process.

Exceptions
InvalidCipherTextException:

Doc from org.bouncycastle.crypto.AsymmetricBlockCipher.processBlock.

data decrypts improperly.

See Also
org.bouncycastle.crypto.AsymmetricBlockCipher#processBlock(byte[], int, int)
processDataback to summary
public byte[] processData(byte[] data) throws InvalidCipherTextException

Convenience Method for data exchange with the cipher. Determines blocksize and splits data to blocksize.

Parameters
data:byte[]

the data to be processed

Returns:byte[]

the data after it went through the NaccacheSternEngine.

setDebugback to summary
public void setDebug(boolean debug)