/** * This function generates the private map F, which consists of u-1 layers. * Each layer consists of oi polynomials where oi = vi[i+1]-vi[i]. * <p> * The methods for the generation of the coefficients of these polynomials * are called here. * </p> */ private void generateF() { this.layers = new Layer[this.numOfLayers]; for (int i = 0; i < this.numOfLayers; i++) { layers[i] = new Layer(this.vi[i], this.vi[i + 1], sr); } }
/** * This function compares this Layer with another object. * * @param other the other object * @return the result of the comparison */ public boolean equals(Object other) { if (other == null || !(other instanceof Layer)) { return false; } Layer otherLayer = (Layer)other; return vi == otherLayer.getVi() && viNext == otherLayer.getViNext() && oi == otherLayer.getOi() && RainbowUtil.equals(coeff_alpha, otherLayer.getCoeffAlpha()) && RainbowUtil.equals(coeff_beta, otherLayer.getCoeffBeta()) && RainbowUtil.equals(coeff_gamma, otherLayer.getCoeffGamma()) && RainbowUtil.equals(coeff_eta, otherLayer.getCoeffEta()); }
coeff_alpha = this.layers[l].getCoeffAlpha(); coeff_beta = this.layers[l].getCoeffBeta(); coeff_gamma = this.layers[l].getCoeffGamma(); coeff_eta = this.layers[l].getCoeffEta(); oils = coeff_alpha[0].length;// this.layers[l].getOi(); vins = coeff_beta[0].length;// this.layers[l].getVi();
/** * initial operations before solving the Linear equation system. * * @param layer the current layer for which a LES is to be solved. * @param msg the message that should be signed. * @return Y_ the modified document needed for solving LES, (Y_ = * A1^{-1}*(Y-b1)) linear map L1 = A1 x + b1. */ private short[] initSign(Layer[] layer, short[] msg) { /* preparation: Modifies the document with the inverse of L1 */ // tmp = Y - b1: short[] tmpVec = new short[msg.length]; tmpVec = cf.addVect(((RainbowPrivateKeyParameters)this.key).getB1(), msg); // Y_ = A1^{-1} * (Y - b1) : short[] Y_ = cf.multiplyMatrix(((RainbowPrivateKeyParameters)this.key).getInvA1(), tmpVec); /* generates the vinegar vars of the first layer at random */ for (int i = 0; i < layer[0].getVi(); i++) { x[i] = (short)random.nextInt(); x[i] = (short)(x[i] & GF2Field.MASK); } return Y_; }
/** * Compare this Rainbow private 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 BCRainbowPrivateKey)) { return false; } BCRainbowPrivateKey otherKey = (BCRainbowPrivateKey)other; boolean eq = true; // compare using shortcut rule ( && instead of &) eq = eq && RainbowUtil.equals(A1inv, otherKey.getInvA1()); eq = eq && RainbowUtil.equals(A2inv, otherKey.getInvA2()); eq = eq && RainbowUtil.equals(b1, otherKey.getB1()); eq = eq && RainbowUtil.equals(b2, otherKey.getB2()); eq = eq && Arrays.equals(vi, otherKey.getVi()); if (layers.length != otherKey.getLayers().length) { return false; } for (int i = layers.length - 1; i >= 0; i--) { eq &= layers[i].equals(otherKey.getLayers()[i]); } return eq; }
coeff_alpha = this.layers[l].getCoeffAlpha(); coeff_beta = this.layers[l].getCoeffBeta(); coeff_gamma = this.layers[l].getCoeffGamma(); coeff_eta = this.layers[l].getCoeffEta(); oils = coeff_alpha[0].length;// this.layers[l].getOi(); vins = coeff_beta[0].length;// this.layers[l].getVi();
/** * initial operations before solving the Linear equation system. * * @param layer the current layer for which a LES is to be solved. * @param msg the message that should be signed. * @return Y_ the modified document needed for solving LES, (Y_ = * A1^{-1}*(Y-b1)) linear map L1 = A1 x + b1. */ private short[] initSign(Layer[] layer, short[] msg) { /* preparation: Modifies the document with the inverse of L1 */ // tmp = Y - b1: short[] tmpVec = new short[msg.length]; tmpVec = cf.addVect(((RainbowPrivateKeyParameters)this.key).getB1(), msg); // Y_ = A1^{-1} * (Y - b1) : short[] Y_ = cf.multiplyMatrix(((RainbowPrivateKeyParameters)this.key).getInvA1(), tmpVec); /* generates the vinegar vars of the first layer at random */ for (int i = 0; i < layer[0].getVi(); i++) { x[i] = (short)random.nextInt(); x[i] = (short)(x[i] & GF2Field.MASK); } return Y_; }
/** * This function compares this Layer with another object. * * @param other the other object * @return the result of the comparison */ public boolean equals(Object other) { if (other == null || !(other instanceof Layer)) { return false; } Layer otherLayer = (Layer)other; return vi == otherLayer.getVi() && viNext == otherLayer.getViNext() && oi == otherLayer.getOi() && RainbowUtil.equals(coeff_alpha, otherLayer.getCoeffAlpha()) && RainbowUtil.equals(coeff_beta, otherLayer.getCoeffBeta()) && RainbowUtil.equals(coeff_gamma, otherLayer.getCoeffGamma()) && RainbowUtil.equals(coeff_eta, otherLayer.getCoeffEta()); }
byte[][][] alphas = RainbowUtil.convertArray(layers[l].getCoeffAlpha()); ASN1EncodableVector alphas3d = new ASN1EncodableVector(); for (int i = 0; i < alphas.length; i++) byte[][][] betas = RainbowUtil.convertArray(layers[l].getCoeffBeta()); ASN1EncodableVector betas3d = new ASN1EncodableVector(); for (int i = 0; i < betas.length; i++) byte[][] gammas = RainbowUtil.convertArray(layers[l].getCoeffGamma()); ASN1EncodableVector asnG = new ASN1EncodableVector(); for (int i = 0; i < gammas.length; i++) aLayer.add(new DEROctetString(RainbowUtil.convertArray(layers[l].getCoeffEta())));
/** * This function generates the private map F, which consists of u-1 layers. * Each layer consists of oi polynomials where oi = vi[i+1]-vi[i]. * <p> * The methods for the generation of the coefficients of these polynomials * are called here. * </p> */ private void generateF() { this.layers = new Layer[this.numOfLayers]; for (int i = 0; i < this.numOfLayers; i++) { layers[i] = new Layer(this.vi[i], this.vi[i + 1], sr); } }
byte[][][] alphas = RainbowUtil.convertArray(layers[l].getCoeffAlpha()); ASN1EncodableVector alphas3d = new ASN1EncodableVector(); for (int i = 0; i < alphas.length; i++) byte[][][] betas = RainbowUtil.convertArray(layers[l].getCoeffBeta()); ASN1EncodableVector betas3d = new ASN1EncodableVector(); for (int i = 0; i < betas.length; i++) byte[][] gammas = RainbowUtil.convertArray(layers[l].getCoeffGamma()); ASN1EncodableVector asnG = new ASN1EncodableVector(); for (int i = 0; i < gammas.length; i++) aLayer.add(new DEROctetString(RainbowUtil.convertArray(layers[l].getCoeffEta())));
for (int i = 0; i < numOfLayers; i++) Layer l = new Layer(vi[i], vi[i + 1], RainbowUtil.convertArray(alphas[i]), RainbowUtil.convertArray(betas[i]), RainbowUtil.convertArray(gammas[i]), RainbowUtil.convertArray(etas[i])); this.layers[i] = l;
for (int i = 0; i < numOfLayers; i++) Layer l = new Layer(vi[i], vi[i + 1], RainbowUtil.convertArray(alphas[i]), RainbowUtil.convertArray(betas[i]), RainbowUtil.convertArray(gammas[i]), RainbowUtil.convertArray(etas[i])); this.layers[i] = l;