de.flexiprovider.pqc.ecc.mceliece
Class McElieceKobaraImaiCipher

java.lang.Object
  |
  +--javax.crypto.CipherSpi
        |
        +--de.flexiprovider.api.Cipher
              |
              +--de.flexiprovider.api.AsymmetricHybridCipher
                    |
                    +--de.flexiprovider.pqc.ecc.mceliece.McElieceKobaraImaiCipher

public class McElieceKobaraImaiCipher
extends AsymmetricHybridCipher

This class implements the Kobara/Imai conversion of the McEliecePKCS. This is a conversion of the McEliecePKCS 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 Kobara/Imai 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("McElieceKobaraImaiConversion");
 
 // 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.
static byte[] PUBLIC_CONSTANT
          A predetermined public constant.
 
Fields inherited from class de.flexiprovider.api.AsymmetricHybridCipher
paramSpec
 
Fields inherited from class de.flexiprovider.api.Cipher
DECRYPT_MODE, ENCRYPT_MODE, opMode
 
Constructor Summary
McElieceKobaraImaiCipher()
           
 
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 sr)
          Initialize the AsymmetricHybridCipher with a certain key for data encryption.
protected  byte[] messageDecrypt()
           
protected  byte[] messageEncrypt()
           
 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
 

Field Detail

OID

public static final java.lang.String OID
The OID of the algorithm.

PUBLIC_CONSTANT

public static final byte[] PUBLIC_CONSTANT
A predetermined public constant.
Constructor Detail

McElieceKobaraImaiCipher

public McElieceKobaraImaiCipher()
Method Detail

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

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

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

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 input
inOff - index in the array where the input starts
inLen - 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 buffer
inOff - the offset in input where the input starts
inLen - the input length
Returns:
the new buffer with the result
Throws:
BadPaddingException - if this cipher is in decryption mode, and (un)padding has been requested, but the decrypted data is not bounded by the appropriate padding bytes

initCipherEncrypt

protected void initCipherEncrypt(Key key,
                                 AlgorithmParameterSpec params,
                                 SecureRandom sr)
                          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 data
params - the algorithm parameters
sr - 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 data
params - the algorithm parameters
Throws:
InvalidKeyException - if the given key is inappropriate for initializing this cipher
InvalidAlgorithmParameterException - if the given parameters are inappropriate for initializing this cipher.

messageEncrypt

protected byte[] messageEncrypt()

messageDecrypt

protected byte[] messageDecrypt()
                         throws BadPaddingException