Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.bouncycastle.pqc.crypto.rainbow;
  
  
This class represents a layer of the Rainbow Oil- and Vinegar Map. Each Layer consists of oi polynomials with their coefficients, generated at random.

To sign a document, we solve a LES (linear equation system) for each layer in order to find the oil variables of that layer and to be able to use the variables to compute the signature. This functionality is implemented in the RainbowSignature-class, by the aid of the private key.

Each layer is a part of the private key.

More information about the layer can be found in the paper of Jintai Ding, Dieter Schmidt: Rainbow, a New Multivariable Polynomial Signature Scheme. ACNS 2005: 164-175 (http://dx.doi.org/10.1007/11496137_12)

 
 public class Layer
 {
     private int vi// number of vinegars in this layer
     private int viNext// number of vinegars in next layer
     private int oi// number of oils in this layer
 
     /*
       * k : index of polynomial
       *
       * i,j : indices of oil and vinegar variables
       */
     private short[/* k */][/* i */][/* j */coeff_alpha;
     private short[/* k */][/* i */][/* j */coeff_beta;
     private short[/* k */][/* i */coeff_gamma;
     private short[/* k */coeff_eta;

    
Constructor

Parameters:
vi number of vinegar variables of this layer
viNext number of vinegar variables of next layer. It's the same as (num of oils) + (num of vinegars) of this layer.
coeffAlpha alpha-coefficients in the polynomials of this layer
coeffBeta beta-coefficients in the polynomials of this layer
coeffGamma gamma-coefficients in the polynomials of this layer
coeffEta eta-coefficients in the polynomials of this layer
 
     public Layer(byte vibyte viNextshort[][][] coeffAlpha,
                  short[][][] coeffBetashort[][] coeffGammashort[] coeffEta)
     {
         this. = vi & 0xff;
         this. = viNext & 0xff;
         this. = this. - this.;
 
         // the secret coefficients of all polynomials in this layer
         this. = coeffAlpha;
         this. = coeffBeta;
         this. = coeffGamma;
         this. = coeffEta;
     }

    
This function generates the coefficients of all polynomials in this layer at random using random generator.

Parameters:
sr the random generator which is to be used
 
     public Layer(int viint viNextSecureRandom sr)
     {
         this. = vi;
         this. = viNext;
         this. = viNext - vi;
 
         // the coefficients of all polynomials in this layer
         this. = new short[this.][this.][this.];
         this. = new short[this.][this.][this.];
         this. = new short[this.][this.];
         this. = new short[this.];
 
         int numOfPoly = this.// number of polynomials per layer
 
         // Alpha coeffs
         for (int k = 0; k < numOfPolyk++)
         {
             for (int i = 0; i < this.i++)
             {
                 for (int j = 0; j < this.j++)
                 {
                     [k][i][j] = (short)(sr.nextInt() & .);
                 }
             }
         }
         // Beta coeffs
         for (int k = 0; k < numOfPolyk++)
         {
            for (int i = 0; i < this.i++)
            {
                for (int j = 0; j < this.j++)
                {
                    [k][i][j] = (short)(sr.nextInt() & .);
                }
            }
        }
        // Gamma coeffs
        for (int k = 0; k < numOfPolyk++)
        {
            for (int i = 0; i < this.i++)
            {
                [k][i] = (short)(sr.nextInt() & .);
            }
        }
        // Eta
        for (int k = 0; k < numOfPolyk++)
        {
            [k] = (short)(sr.nextInt() & .);
        }
    }

    
This method plugs in the vinegar variables into the polynomials of this layer and computes the coefficients of the Oil-variables as well as the free coefficient in each polynomial.

It is needed for computing the Oil variables while signing.

Parameters:
x vinegar variables of this layer that should be plugged into the polynomials.
Returns:
coeff the coefficients of Oil variables and the free coeff in the polynomials of this layer.
    public short[][] plugInVinegars(short[] x)
    {
        // temporary variable needed for the multiplication
        short tmpMult = 0;
        // coeff: 1st index = which polynomial, 2nd index=which variable
        short[][] coeff = new short[][ + 1]; // gets returned
        // free coefficient per polynomial
        short[] sum = new short[];
        /*
           * evaluate the beta-part of the polynomials (it contains no oil
           * variables)
           */
        for (int k = 0; k < k++)
        {
            for (int i = 0; i < i++)
            {
                for (int j = 0; j < j++)
                {
                    // tmp = beta * xi (plug in)
                    tmpMult = GF2Field.multElem([k][i][j], x[i]);
                    // tmp = tmp * xj
                    tmpMult = GF2Field.multElem(tmpMultx[j]);
                    // accumulate into the array for the free coefficients.
                    sum[k] = GF2Field.addElem(sum[k], tmpMult);
                }
            }
        }
        /* evaluate the alpha-part (it contains oils) */
        for (int k = 0; k < k++)
        {
            for (int i = 0; i < i++)
            {
                for (int j = 0; j < j++)
                {
                    // alpha * xj (plug in)
                    tmpMult = GF2Field.multElem([k][i][j], x[j]);
                    // accumulate
                    coeff[k][i] = GF2Field.addElem(coeff[k][i], tmpMult);
                }
            }
        }
        /* evaluate the gama-part of the polynomial (containing no oils) */
        for (int k = 0; k < k++)
        {
            for (int i = 0; i < i++)
            {
                // gamma * xi (plug in)
                tmpMult = GF2Field.multElem([k][i], x[i]);
                // accumulate in the array for the free coefficients (per
                // polynomial).
                sum[k] = GF2Field.addElem(sum[k], tmpMult);
            }
        }
        /* evaluate the gama-part of the polynomial (but containing oils) */
        for (int k = 0; k < k++)
        {
            for (int i = i < i++)
            { // oils
                // accumulate the coefficients of the oil variables (per
                // polynomial).
                coeff[k][i - ] = GF2Field.addElem([k][i],
                    coeff[k][i - ]);
            }
        }
        /* evaluate the eta-part of the polynomial */
        for (int k = 0; k < k++)
        {
            // accumulate in the array for the free coefficients per polynomial.
            sum[k] = GF2Field.addElem(sum[k], [k]);
        }
        /* put the free coefficients (sum) into the coeff-array as last column */
        for (int k = 0; k < k++)
        {
            coeff[k][] = sum[k];
        }
        return coeff;
    }

    
Getter for the number of vinegar variables of this layer.

Returns:
the number of vinegar variables of this layer.
    public int getVi()
    {
        return ;
    }

    
Getter for the number of vinegar variables of the next layer.

Returns:
the number of vinegar variables of the next layer.
    public int getViNext()
    {
        return ;
    }

    
Getter for the number of Oil variables of this layer.

Returns:
the number of oil variables of this layer.
    public int getOi()
    {
        return ;
    }

    
Getter for the alpha-coefficients of the polynomials in this layer.

Returns:
the coefficients of alpha-terms of this layer.
    public short[][][] getCoeffAlpha()
    {
        return ;
    }

    
Getter for the beta-coefficients of the polynomials in this layer.

Returns:
the coefficients of beta-terms of this layer.
    public short[][][] getCoeffBeta()
    {
        return ;
    }

    
Getter for the gamma-coefficients of the polynomials in this layer.

Returns:
the coefficients of gamma-terms of this layer
    public short[][] getCoeffGamma()
    {
        return ;
    }

    
Getter for the eta-coefficients of the polynomials in this layer.

Returns:
the coefficients eta of this layer
    public short[] getCoeffEta()
    {
        return ;
    }

    
This function compares this Layer with another object.

Parameters:
other the other object
Returns:
the result of the comparison
    public boolean equals(Object other)
    {
        if (other == null || !(other instanceof Layer))
        {
            return false;
        }
        Layer otherLayer = (Layer)other;
        return   == otherLayer.getVi()
                &&  == otherLayer.getViNext()
                &&  == otherLayer.getOi()
                && RainbowUtil.equals(otherLayer.getCoeffAlpha())
                && RainbowUtil.equals(otherLayer.getCoeffBeta())
                && RainbowUtil.equals(otherLayer.getCoeffGamma())
                && RainbowUtil.equals(otherLayer.getCoeffEta());
    }
    public int hashCode()
    {
        int hash = ;
        hash = hash * 37 + ;
        hash = hash * 37 + ;
        hash = hash * 37 + Arrays.hashCode();
        hash = hash * 37 + Arrays.hashCode();
        hash = hash * 37 + Arrays.hashCode();
        hash = hash * 37 + Arrays.hashCode();
        return hash;
    }
New to GrepCode? Check out our FAQ X