de.flexiprovider.pqc.ecc.mceliece
Class McElieceFujisakiCipher
java.lang.Object
|
+--javax.crypto.CipherSpi
|
+--de.flexiprovider.api.Cipher
|
+--de.flexiprovider.api.AsymmetricHybridCipher
|
+--de.flexiprovider.pqc.ecc.mceliece.McElieceFujisakiCipher
- public class McElieceFujisakiCipher
- extends AsymmetricHybridCipher
This class implements the Fujisaki/Okamoto conversion of the McEliecePKCS.
Fujisaki and Okamoto propose hybrid encryption that merges a symmetric
encryption scheme which is secure in the find-guess model with an asymmetric
one-way encryption scheme which is sufficiently probabilistic to obtain a
public key cryptosystem which is CCA2-secure. For details, see D. Engelbert,
R. Overbeck, A. Schmidt, "A summary of the development of the McEliece
Cryptosystem", technical report.
This class extends the CipherSpi class.
The Fujisaki/Okamoto conversion can be used as follows:
To encrypt a message, the following steps have to be performed:
// setup
KeyPairGenerator kpg = KeyPairGenerator.getInstance("McEliece", "FlexiPQC");
KeyPair keys = kpg.generateKeyPair();
McElieceCCA2PublicKey pubK = (McElieceCCA2PublicKey) keys.getPublic();
McElieceCCA2PrivateKey privK = (McElieceCCA2PrivateKey) keys.getPrivate();
SecureRandom sr = Registry.getSecureRandom();
Cipher cipher = Cipher.getInstance("McElieceFujisakiConversion");
// the string to encrypt and decrypt
String m = "This is a test for the Fujisaki conversion of the McEliecePKCS.";
byte[] mBytes = m.getBytes();
// initialize cipher in encrypt mode
cipher.init(Cipher.ENCRYPT_MODE, pubK, sr);
// encrypt
byte[] cBytes = cipher.doFinal(mBytes);
To decrypt, the following steps have to be performed (using setup from
above):
// initialize cipher in decrypt mode
cipher.init(Cipher.DECRYPT_MODE, privK);
// decrypt
byte[] decBytes = cipher.doFinal(cBytes);
String newM = new String(decBytes);
|
Field Summary |
static java.lang.String |
OID
The OID of the algorithm. |
|
Method Summary |
protected int |
decryptOutputSize(int inLen)
Compute the output size of an update() or doFinal() operation of a hybrid
asymmetric cipher in decryption mode when given input of the specified
length. |
byte[] |
doFinal(byte[] input,
int inOff,
int inLen)
Encrypts or decrypts data in a single-part operation, or finishes a
multiple-part operation. |
protected int |
encryptOutputSize(int inLen)
Compute the output size of an update() or doFinal() operation of a hybrid
asymmetric cipher in encryption mode when given input of the specified
length. |
int |
getKeySize(Key key)
Return the key size of the given key object. |
java.lang.String |
getName()
|
protected void |
initCipherDecrypt(Key key,
AlgorithmParameterSpec params)
Initialize the AsymmetricHybridCipher with a certain key for data
encryption. |
protected void |
initCipherEncrypt(Key key,
AlgorithmParameterSpec params,
SecureRandom secureRand)
Initialize the AsymmetricHybridCipher with a certain key for data
encryption. |
protected byte[] |
messageDecrypt(byte[] input)
|
protected byte[] |
messageEncrypt(byte[] input)
|
byte[] |
update(byte[] input,
int inOff,
int inLen)
Continue a multiple-part encryption or decryption operation. |
| Methods inherited from class de.flexiprovider.api.AsymmetricHybridCipher |
doFinal, getBlockSize, getIV, getOutputSize, getParameters, initDecrypt, initDecrypt, initEncrypt, initEncrypt, initEncrypt, initEncrypt, setMode, setPadding, update |
| Methods inherited from class de.flexiprovider.api.Cipher |
doFinal, doFinal, engineDoFinal, engineDoFinal, engineGetBlockSize, engineGetIV, engineGetKeySize, engineGetOutputSize, engineGetParameters, engineInit, engineInit, engineInit, engineSetMode, engineSetPadding, engineUpdate, engineUpdate, update |
| Methods inherited from class java.lang.Object |
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
OID
public static final java.lang.String OID
- The OID of the algorithm.
McElieceFujisakiCipher
public McElieceFujisakiCipher()
getName
public java.lang.String getName()
- Overrides:
getName in class Cipher
- Returns:
- the name of this cipher
getKeySize
public int getKeySize(Key key)
throws InvalidKeyException
- Return the key size of the given key object. Checks whether the key
object is an instance of McElieceCCA2PublicKey or
McElieceCCA2PrivateKey.
- Overrides:
getKeySize in class Cipher
- Parameters:
key - the key object- Returns:
- the keysize of the given key object
- Throws:
InvalidKeyException - if the key is invalid
encryptOutputSize
protected int encryptOutputSize(int inLen)
- Description copied from class:
AsymmetricHybridCipher
- Compute the output size of an update() or doFinal() operation of a hybrid
asymmetric cipher in encryption mode when given input of the specified
length.
- Overrides:
encryptOutputSize in class AsymmetricHybridCipher
- Following copied from class:
de.flexiprovider.api.AsymmetricHybridCipher
- Parameters:
inLen - the length of the input- Returns:
- the output size
decryptOutputSize
protected int decryptOutputSize(int inLen)
- Description copied from class:
AsymmetricHybridCipher
- Compute the output size of an update() or doFinal() operation of a hybrid
asymmetric cipher in decryption mode when given input of the specified
length.
- Overrides:
decryptOutputSize in class AsymmetricHybridCipher
- Following copied from class:
de.flexiprovider.api.AsymmetricHybridCipher
- Parameters:
inLen - the length of the input- Returns:
- the output size
update
public byte[] update(byte[] input,
int inOff,
int inLen)
- Continue a multiple-part encryption or decryption operation.
- Overrides:
update in class AsymmetricHybridCipher
- Parameters:
input - byte array containing the next part of the inputinOff - index in the array where the input startsinLen - length of the input- Returns:
- the processed byte array.
doFinal
public byte[] doFinal(byte[] input,
int inOff,
int inLen)
throws BadPaddingException
- Encrypts or decrypts data in a single-part operation, or finishes a
multiple-part operation. The data is encrypted or decrypted, depending on
how this cipher was initialized.
- Overrides:
doFinal in class AsymmetricHybridCipher
- Parameters:
input - the input bufferinOff - the offset in input where the input startsinLen - the input length- Returns:
- the new buffer with the result
- Throws:
BadPaddingException - on decryption errors.
initCipherEncrypt
protected void initCipherEncrypt(Key key,
AlgorithmParameterSpec params,
SecureRandom secureRand)
throws InvalidKeyException,
InvalidAlgorithmParameterException
- Description copied from class:
AsymmetricHybridCipher
- Initialize the AsymmetricHybridCipher with a certain key for data
encryption.
- Overrides:
initCipherEncrypt in class AsymmetricHybridCipher
- Following copied from class:
de.flexiprovider.api.AsymmetricHybridCipher
- Parameters:
key - the key which has to be used to encrypt dataparams - the algorithm parameterssr - the source of randomness- Throws:
InvalidKeyException - if the given key is inappropriate for initializing this
cipher.InvalidAlgorithmParameterException - if the given parameters are inappropriate for
initializing this cipher.
initCipherDecrypt
protected void initCipherDecrypt(Key key,
AlgorithmParameterSpec params)
throws InvalidKeyException,
InvalidAlgorithmParameterException
- Description copied from class:
AsymmetricHybridCipher
- Initialize the AsymmetricHybridCipher with a certain key for data
encryption.
- Overrides:
initCipherDecrypt in class AsymmetricHybridCipher
- Following copied from class:
de.flexiprovider.api.AsymmetricHybridCipher
- Parameters:
key - the key which has to be used to decrypt dataparams - the algorithm parameters- Throws:
InvalidKeyException - if the given key is inappropriate for initializing this
cipherInvalidAlgorithmParameterException - if the given parameters are inappropriate for
initializing this cipher.
messageEncrypt
protected byte[] messageEncrypt(byte[] input)
messageDecrypt
protected byte[] messageDecrypt(byte[] input)
throws BadPaddingException