/** * 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); } }
/** * 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); } }
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 p = new Permutation(n, sr); int[] pVec = p.getVector(); result[1] = (GF2Matrix)invUm.rightMultiply(invLm.rightMultiply(p));
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 p = new Permutation(n, sr); int[] pVec = p.getVector(); result[1] = (GF2Matrix)invUm.rightMultiply(invLm.rightMultiply(p));
hp = (GF2Matrix)h.rightMultiply(p); sInv = hp.getLeftSubMatrix(); try GF2Matrix shp = (GF2Matrix)s.rightMultiply(hp); GF2Matrix m = shp.getRightSubMatrix();
hp = (GF2Matrix)h.rightMultiply(p); sInv = hp.getLeftSubMatrix(); try GF2Matrix shp = (GF2Matrix)s.rightMultiply(hp); GF2Matrix m = shp.getRightSubMatrix();
GF2Matrix g = (GF2Matrix)matrixSandInverse[0].rightMultiply(gPrime); g = (GF2Matrix)g.rightMultiply(p2);
GF2Matrix g = (GF2Matrix)matrixSandInverse[0].rightMultiply(gPrime); g = (GF2Matrix)g.rightMultiply(p2);
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}; }
GF2Vector syndVec = (GF2Vector)h.rightMultiply(cPInv);
GF2Vector syndVec = (GF2Vector)h.rightMultiply(cPInv);
GF2Vector syndVec = (GF2Vector)h.rightMultiply(cPInv);
GF2Vector syndrome = (GF2Vector)h.rightMultiply(cPInv);
GF2Vector syndrome = (GF2Vector)h.rightMultiply(cPInv);