All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bouncycastle.pqc.crypto.mceliece.McEliecePrivateKeyParameters Maven / Gradle / Ivy

Go to download

The Bouncy Castle Crypto package is a Java implementation of cryptographic algorithms. This jar contains JCE provider and lightweight API for the Bouncy Castle Cryptography APIs for JDK 1.5 to JDK 1.8 with debug enabled.

There is a newer version: 1.70
Show newest version
package org.bouncycastle.pqc.crypto.mceliece;

import org.bouncycastle.pqc.math.linearalgebra.GF2Matrix;
import org.bouncycastle.pqc.math.linearalgebra.GF2mField;
import org.bouncycastle.pqc.math.linearalgebra.GoppaCode;
import org.bouncycastle.pqc.math.linearalgebra.Permutation;
import org.bouncycastle.pqc.math.linearalgebra.PolynomialGF2mSmallM;
import org.bouncycastle.pqc.math.linearalgebra.PolynomialRingGF2m;


public class McEliecePrivateKeyParameters
    extends McElieceKeyParameters
{

    // the OID of the algorithm
    private String oid;

    // the length of the code
    private int n;

    // the dimension of the code, where k >= n - mt
    private int k;

    // the underlying finite field
    private GF2mField field;

    // the irreducible Goppa polynomial
    private PolynomialGF2mSmallM goppaPoly;

    // a k x k random binary non-singular matrix
    private GF2Matrix sInv;

    // the permutation used to generate the systematic check matrix
    private Permutation p1;

    // the permutation used to compute the public generator matrix
    private Permutation p2;

    // the canonical check matrix of the code
    private GF2Matrix h;

    // the matrix used to compute square roots in (GF(2^m))^t
    private PolynomialGF2mSmallM[] qInv;

    /**
     * Constructor.
     *
     * @param n         the length of the code
     * @param k         the dimension of the code
     * @param field     the field polynomial defining the finite field
*                  GF(2m)
     * @param gp the irreducible Goppa polynomial
     * @param p1        the permutation used to generate the systematic check
*                  matrix
     * @param p2        the permutation used to compute the public generator
*                  matrix
     * @param sInv      the matrix S-1
     */
    public McEliecePrivateKeyParameters(int n, int k, GF2mField field,
                                        PolynomialGF2mSmallM gp, Permutation p1, Permutation p2, GF2Matrix sInv)
    {
        super(true, null);
        this.k = k;
        this.n = n;
        this.field = field;
        this.goppaPoly = gp;
        this.sInv = sInv;
        this.p1 = p1;
        this.p2 = p2;
        this.h = GoppaCode.createCanonicalCheckMatrix(field, gp);

        PolynomialRingGF2m ring = new PolynomialRingGF2m(field, gp);

          // matrix used to compute square roots in (GF(2^m))^t
        this.qInv = ring.getSquareRootMatrix();
    }

    /**
     * Constructor.
     *
     * @param n            the length of the code
     * @param k            the dimension of the code
     * @param encField     the encoded field polynomial defining the finite field
     *                     GF(2m)
     * @param encGoppaPoly the encoded irreducible Goppa polynomial
     * @param encSInv      the encoded matrix S-1
     * @param encP1        the encoded permutation used to generate the systematic
     *                     check matrix
     * @param encP2        the encoded permutation used to compute the public
     *                     generator matrix
     * @param encH         the encoded canonical check matrix
     * @param encQInv      the encoded matrix used to compute square roots in
     *                     (GF(2m))t
     */
    public McEliecePrivateKeyParameters(int n, int k, byte[] encField,
                                        byte[] encGoppaPoly, byte[] encSInv, byte[] encP1, byte[] encP2,
                                        byte[] encH, byte[][] encQInv)
    {
        super(true, null);
        this.n = n;
        this.k = k;
        field = new GF2mField(encField);
        goppaPoly = new PolynomialGF2mSmallM(field, encGoppaPoly);
        sInv = new GF2Matrix(encSInv);
        p1 = new Permutation(encP1);
        p2 = new Permutation(encP2);
        h = new GF2Matrix(encH);
        qInv = new PolynomialGF2mSmallM[encQInv.length];
        for (int i = 0; i < encQInv.length; i++)
        {
            qInv[i] = new PolynomialGF2mSmallM(field, encQInv[i]);
        }
    }

    /**
     * @return the length of the code
     */
    public int getN()
    {
        return n;
    }

    /**
     * @return the dimension of the code
     */
    public int getK()
    {
        return k;
    }

    /**
     * @return the finite field GF(2m)
     */
    public GF2mField getField()
    {
        return field;
    }

    /**
     * @return the irreducible Goppa polynomial
     */
    public PolynomialGF2mSmallM getGoppaPoly()
    {
        return goppaPoly;
    }

    /**
     * @return the k x k random binary non-singular matrix S^-1
     */
    public GF2Matrix getSInv()
    {
        return sInv;
    }

    /**
     * @return the permutation used to generate the systematic check matrix
     */
    public Permutation getP1()
    {
        return p1;
    }

    /**
     * @return the permutation used to compute the public generator matrix
     */
    public Permutation getP2()
    {
        return p2;
    }

    /**
     * @return the canonical check matrix H
     */
    public GF2Matrix getH()
    {
        return h;
    }

    /**
     * @return the matrix used to compute square roots in
     *         (GF(2m))t
     */
    public PolynomialGF2mSmallM[] getQInv()
    {
        return qInv;
    }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy