public Permutation getP1() { return new Permutation(encP1); }
/** * Multiply this vector with a permutation. * * @param p the permutation * @return <tt>this*p = p*this</tt> */ public Vector multiply(Permutation p) { int[] pVec = p.getVector(); if (length != pVec.length) { throw new ArithmeticException( "permutation size and vector size mismatch"); } int[] result = new int[length]; for (int i = 0; i < pVec.length; i++) { result[i] = vector[pVec[i]]; } return new GF2mVector(field, result); }
public McEliecePrivateKey(int n, int k, GF2mField field, PolynomialGF2mSmallM goppaPoly, Permutation p1, Permutation p2, GF2Matrix sInv) { this.n = n; this.k = k; this.encField = field.getEncoded(); this.encGp = goppaPoly.getEncoded(); this.encSInv = sInv.getEncoded(); this.encP1 = p1.getEncoded(); this.encP2 = p2.getEncoded(); }
/** * Create an nxn random regular matrix. * * @param n number of rows (and columns) * @param sr source of randomness */ private void assignRandomRegularMatrix(int n, SecureRandom sr) { numRows = n; numColumns = n; length = (n + 31) >>> 5; matrix = new int[numRows][length]; GF2Matrix lm = new GF2Matrix(n, Matrix.MATRIX_TYPE_RANDOM_LT, sr); GF2Matrix um = new GF2Matrix(n, Matrix.MATRIX_TYPE_RANDOM_UT, sr); GF2Matrix rm = (GF2Matrix)lm.rightMultiply(um); Permutation perm = new Permutation(n, sr); int[] p = perm.getVector(); for (int i = 0; i < n; i++) { System.arraycopy(rm.matrix[i], 0, matrix[p[i]], 0, length); } }
Permutation p = p1.rightMultiply(p2); Permutation pInv = p.computeInverse();
/** * Create a permutation using the given permutation vector. * * @param perm the permutation vector */ public Permutation(int[] perm) { if (!isPermutation(perm)) { throw new IllegalArgumentException( "array is not a permutation vector"); } this.perm = IntUtils.clone(perm); }
public static GF2Vector[] decryptionPrimitive( McElieceCCA2PrivateKeyParameters privKey, GF2Vector 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(syndVec, field, gp, q); 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[]{m, errors}; }
/** * @return the hash code of this key */ public int hashCode() { int code = params.getK(); code = code * 37 + params.getN(); code = code * 37 + params.getField().hashCode(); code = code * 37 + params.getGoppaPoly().hashCode(); code = code * 37 + params.getP1().hashCode(); code = code * 37 + params.getP2().hashCode(); return code * 37 + params.getSInv().hashCode(); }
/** * Compare this key with another object. * * @param other the other object * @return the result of the comparison */ public boolean equals(Object other) { if (!(other instanceof BCMcEliecePrivateKey)) { return false; } BCMcEliecePrivateKey otherKey = (BCMcEliecePrivateKey)other; return (getN() == otherKey.getN()) && (getK() == otherKey.getK()) && getField().equals(otherKey.getField()) && getGoppaPoly().equals(otherKey.getGoppaPoly()) && getSInv().equals(otherKey.getSInv()) && getP1().equals(otherKey.getP1()) && getP2().equals(otherKey.getP2()); }
/** * Create an nxn random regular matrix. * * @param n number of rows (and columns) * @param sr source of randomness */ private void assignRandomRegularMatrix(int n, SecureRandom sr) { numRows = n; numColumns = n; length = (n + 31) >>> 5; matrix = new int[numRows][length]; GF2Matrix lm = new GF2Matrix(n, Matrix.MATRIX_TYPE_RANDOM_LT, sr); GF2Matrix um = new GF2Matrix(n, Matrix.MATRIX_TYPE_RANDOM_UT, sr); GF2Matrix rm = (GF2Matrix)lm.rightMultiply(um); Permutation perm = new Permutation(n, sr); int[] p = perm.getVector(); for (int i = 0; i < n; i++) { System.arraycopy(rm.matrix[i], 0, matrix[p[i]], 0, length); } }
Permutation p = p1.rightMultiply(p2); Permutation pInv = p.computeInverse();
/** * Create a permutation using the given permutation vector. * * @param perm the permutation vector */ public Permutation(int[] perm) { if (!isPermutation(perm)) { throw new IllegalArgumentException( "array is not a permutation vector"); } this.perm = IntUtils.clone(perm); }
Permutation pInv = p.computeInverse();
/** * @return the hash code of this key */ public int hashCode() { int code = params.getK(); code = code * 37 + params.getN(); code = code * 37 + params.getField().hashCode(); code = code * 37 + params.getGoppaPoly().hashCode(); code = code * 37 + params.getP().hashCode(); return code * 37 + params.getH().hashCode(); }
/** * Compare this key with another object. * * @param other the other object * @return the result of the comparison */ public boolean equals(Object other) { if (other == null || !(other instanceof BCMcElieceCCA2PrivateKey)) { return false; } BCMcElieceCCA2PrivateKey otherKey = (BCMcElieceCCA2PrivateKey)other; return (getN() == otherKey.getN()) && (getK() == otherKey.getK()) && getField().equals(otherKey.getField()) && getGoppaPoly().equals(otherKey.getGoppaPoly()) && getP().equals(otherKey.getP()) && getH().equals(otherKey.getH()); }
/** * Create an nxn random regular matrix. * * @param n number of rows (and columns) * @param sr source of randomness */ public void assignRandomRegularMatrix(int n, SecureRandom sr) { numRows = n; numColumns = n; length = (n + (INTSIZE-1)) >>> BLOCKEXP; matrix = new int[numRows][length]; GF2MatrixEx lm = new GF2MatrixEx(n, Matrix.MATRIX_TYPE_RANDOM_LT, sr); GF2MatrixEx um = new GF2MatrixEx(n, Matrix.MATRIX_TYPE_RANDOM_UT, sr); GF2MatrixEx rm = (GF2MatrixEx)lm.rightMultiply(um); Permutation perm = new Permutation(n, sr); int[] p = perm.getVector(); for (int i = 0; i < n; i++) { System.arraycopy(rm.getIntArray()[i], 0, matrix[p[i]], 0, length); } }
public Permutation getP2() { return new Permutation(encP2); }
/** * Multiply this vector with a permutation. * * @param p the permutation * @return <tt>this*p = p*this</tt> */ public Vector multiply(Permutation p) { int[] pVec = p.getVector(); if (length != pVec.length) { throw new ArithmeticException( "permutation size and vector size mismatch"); } int[] result = new int[length]; for (int i = 0; i < pVec.length; i++) { result[i] = vector[pVec[i]]; } return new GF2mVector(field, result); }
public McElieceCCA2PrivateKey(int n, int k, GF2mField field, PolynomialGF2mSmallM goppaPoly, Permutation p, AlgorithmIdentifier digest) { this.n = n; this.k = k; this.encField = field.getEncoded(); this.encGp = goppaPoly.getEncoded(); this.encP = p.getEncoded(); this.digest = digest; }
/** * Create a permutation from an encoded permutation. * * @param enc the encoded permutation */ public Permutation(byte[] enc) { if (enc.length <= 4) { throw new IllegalArgumentException("invalid encoding"); } int n = LittleEndianConversions.OS2IP(enc, 0); int size = IntegerFunctions.ceilLog256(n - 1); if (enc.length != 4 + n * size) { throw new IllegalArgumentException("invalid encoding"); } perm = new int[n]; for (int i = 0; i < n; i++) { perm[i] = LittleEndianConversions.OS2IP(enc, 4 + i * size, size); } if (!isPermutation(perm)) { throw new IllegalArgumentException("invalid encoding"); } }