Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.bouncycastle.pqc.jcajce.provider.mceliece;
  
Core operations for the CCA-secure variants of McEliece.
 
 public final class McElieceCCA2Primitives
 {

    
Default constructor (private).
 
     private McElieceCCA2Primitives()
     {
     }

    
The McEliece encryption primitive.

Parameters:
pubKey the public key
m the message vector
z the error vector
Returns:
m*G + z
 
     public static GF2Vector encryptionPrimitive(BCMcElieceCCA2PublicKey pubKey,
                                                 GF2Vector mGF2Vector z)
     {
 
         GF2Matrix matrixG = pubKey.getG();
         Vector mG = matrixG.leftMultiplyLeftCompactForm(m);
         return (GF2Vector)mG.add(z);
     }
 
                                                 GF2Vector mGF2Vector z)
     {
 
         GF2Matrix matrixG = pubKey.getMatrixG();
         Vector mG = matrixG.leftMultiplyLeftCompactForm(m);
         return (GF2Vector)mG.add(z);
     }

    
The McEliece decryption primitive.

Parameters:
privKey the private key
c the ciphertext vector c = m*G + z
Returns:
the message vector m and the error vector z
 
     public static GF2Vector[] decryptionPrimitive(
         BCMcElieceCCA2PrivateKey privKeyGF2Vector c)
     {
 
         // obtain values from private key
         int k = privKey.getK();
         Permutation p = privKey.getP();
         GF2mField field = privKey.getField();
         PolynomialGF2mSmallM gp = privKey.getGoppaPoly();
         GF2Matrix h = privKey.getH();
         PolynomialGF2mSmallM[] q = privKey.getQInv();
 
         // compute inverse permutation P^-1
         Permutation pInv = p.computeInverse();
 
         // multiply c with permutation P^-1
         GF2Vector cPInv = (GF2Vector)c.multiply(pInv);
 
         // compute syndrome of cP^-1
         GF2Vector syndVec = (GF2Vector)h.rightMultiply(cPInv);
 
         // decode syndrome
         GF2Vector errors = GoppaCode.syndromeDecode(syndVecfieldgpq);
         GF2Vector mG = (GF2Vector)cPInv.add(errors);
 
         // multiply codeword and error vector with P
         mG = (GF2Vector)mG.multiply(p);
         errors = (GF2Vector)errors.multiply(p);
 
         // extract plaintext vector (last k columns of mG)
         GF2Vector m = mG.extractRightVector(k);
 
         // return vectors
         return new GF2Vector[]{merrors};
     }
 
     public static GF2Vector[] decryptionPrimitive(
         McElieceCCA2PrivateKeyParameters privKeyGF2Vector c)
     {
 
         // obtain values from private key
        int k = privKey.getK();
        Permutation p = privKey.getP();
        GF2mField field = privKey.getField();
        PolynomialGF2mSmallM gp = privKey.getGoppaPoly();
        GF2Matrix h = privKey.getH();
        PolynomialGF2mSmallM[] q = privKey.getQInv();
        // compute inverse permutation P^-1
        Permutation pInv = p.computeInverse();
        // multiply c with permutation P^-1
        GF2Vector cPInv = (GF2Vector)c.multiply(pInv);
        // compute syndrome of cP^-1
        GF2Vector syndVec = (GF2Vector)h.rightMultiply(cPInv);
        // decode syndrome
        GF2Vector errors = GoppaCode.syndromeDecode(syndVecfieldgpq);
        GF2Vector mG = (GF2Vector)cPInv.add(errors);
        // multiply codeword and error vector with P
        mG = (GF2Vector)mG.multiply(p);
        errors = (GF2Vector)errors.multiply(p);
        // extract plaintext vector (last k columns of mG)
        GF2Vector m = mG.extractRightVector(k);
        // return vectors
        return new GF2Vector[]{merrors};
    }
New to GrepCode? Check out our FAQ X