Search in sources :

Example 1 with PolynomialRingGF2m

use of com.github.zhenwei.core.pqc.math.linearalgebra.PolynomialRingGF2m in project LinLong-Java by zhenwei1108.

the class McElieceKeyPairGenerator method genKeyPair.

private AsymmetricCipherKeyPair genKeyPair() {
    if (!initialized) {
        initializeDefault();
    }
    // finite field GF(2^m)
    GF2mField field = new GF2mField(m, fieldPoly);
    // irreducible Goppa polynomial
    PolynomialGF2mSmallM gp = new PolynomialGF2mSmallM(field, t, PolynomialGF2mSmallM.RANDOM_IRREDUCIBLE_POLYNOMIAL, random);
    PolynomialRingGF2m ring = new PolynomialRingGF2m(field, gp);
    // matrix used to compute square roots in (GF(2^m))^t
    PolynomialGF2mSmallM[] sqRootMatrix = ring.getSquareRootMatrix();
    // generate canonical check matrix
    GF2Matrix h = GoppaCode.createCanonicalCheckMatrix(field, gp);
    // compute short systematic form of check matrix
    MaMaPe mmp = GoppaCode.computeSystematicForm(h, random);
    GF2Matrix shortH = mmp.getSecondMatrix();
    Permutation p1 = mmp.getPermutation();
    // compute short systematic form of generator matrix
    GF2Matrix shortG = (GF2Matrix) shortH.computeTranspose();
    // extend to full systematic form
    GF2Matrix gPrime = shortG.extendLeftCompactForm();
    // obtain number of rows of G (= dimension of the code)
    int k = shortG.getNumRows();
    // generate random invertible (k x k)-matrix S and its inverse S^-1
    GF2Matrix[] matrixSandInverse = GF2Matrix.createRandomRegularMatrixAndItsInverse(k, random);
    // generate random permutation P2
    Permutation p2 = new Permutation(n, random);
    // compute public matrix G=S*G'*P2
    GF2Matrix g = (GF2Matrix) matrixSandInverse[0].rightMultiply(gPrime);
    g = (GF2Matrix) g.rightMultiply(p2);
    // generate keys
    McEliecePublicKeyParameters pubKey = new McEliecePublicKeyParameters(n, t, g);
    McEliecePrivateKeyParameters privKey = new McEliecePrivateKeyParameters(n, k, field, gp, p1, p2, matrixSandInverse[1]);
    // return key pair
    return new AsymmetricCipherKeyPair(pubKey, privKey);
}
Also used : GF2mField(com.github.zhenwei.core.pqc.math.linearalgebra.GF2mField) PolynomialGF2mSmallM(com.github.zhenwei.core.pqc.math.linearalgebra.PolynomialGF2mSmallM) PolynomialRingGF2m(com.github.zhenwei.core.pqc.math.linearalgebra.PolynomialRingGF2m) GF2Matrix(com.github.zhenwei.core.pqc.math.linearalgebra.GF2Matrix) Permutation(com.github.zhenwei.core.pqc.math.linearalgebra.Permutation) MaMaPe(com.github.zhenwei.core.pqc.math.linearalgebra.GoppaCode.MaMaPe) AsymmetricCipherKeyPair(com.github.zhenwei.core.crypto.AsymmetricCipherKeyPair)

Aggregations

AsymmetricCipherKeyPair (com.github.zhenwei.core.crypto.AsymmetricCipherKeyPair)1 GF2Matrix (com.github.zhenwei.core.pqc.math.linearalgebra.GF2Matrix)1 GF2mField (com.github.zhenwei.core.pqc.math.linearalgebra.GF2mField)1 MaMaPe (com.github.zhenwei.core.pqc.math.linearalgebra.GoppaCode.MaMaPe)1 Permutation (com.github.zhenwei.core.pqc.math.linearalgebra.Permutation)1 PolynomialGF2mSmallM (com.github.zhenwei.core.pqc.math.linearalgebra.PolynomialGF2mSmallM)1 PolynomialRingGF2m (com.github.zhenwei.core.pqc.math.linearalgebra.PolynomialRingGF2m)1