/// <summary> /// This function generates the private map F, which consists of u-1 layers. /// <para>Each layer consists of oi polynomials where oi = vi[i+1]-vi[i]. /// The methods for the generation of the coefficients of these polynomials are called here.</para> /// </summary> private void GenerateF() { _layers = new MapLayer[_numLayers]; for (int i = 0; i < _numLayers; i++) _layers[i] = new MapLayer(_VI[i], _VI[i + 1], _rngEngine); }
/// <summary> /// Reconstructs a public key from its <c>byte</c> array representation. /// </summary> /// /// <param name="KeyStream">An input stream containing an encoded key</param> /// /// <exception cref="CryptoAsymmetricSignException">Thrown if the key could not be loaded</exception> public RNBWPrivateKey(Stream KeyStream) { try { BinaryReader reader = new BinaryReader(KeyStream); int len; byte[] data; len = reader.ReadInt32(); data = reader.ReadBytes(len); _a1Inv = ArrayUtils.ToArray2x16(data); len = reader.ReadInt32(); data = reader.ReadBytes(len); _B1 = ArrayUtils.ToArray16(data); len = reader.ReadInt32(); data = reader.ReadBytes(len); _a2Inv = ArrayUtils.ToArray2x16(data); len = reader.ReadInt32(); data = reader.ReadBytes(len); _B2 = ArrayUtils.ToArray16(data); len = reader.ReadInt32(); data = reader.ReadBytes(len); _VI = ArrayUtils.ToArray32(data); len = reader.ReadInt32(); _layers = new MapLayer[len]; for (int i = 0; i < _layers.Length; i++) { len = reader.ReadInt32(); data = reader.ReadBytes(len); _layers[i] = new MapLayer(data); } } catch (Exception ex) { throw new CryptoAsymmetricException("RNBWPrivateKey:CTor", "The RNBWPrivateKey could not be loaded!", ex); } }
/// <summary> /// Initial operations before solving the Linear equation system /// </summary> /// /// <param name="Layer">The current layer for which a LES is to be solved</param> /// <param name="Message">The message that should be signed</param> /// /// <returns>The modified document needed for solving LES, (Y_ = A1^{-1}*(Y-b1)) linear map L1 = A1 x + b1</returns> private short[] InitSign(MapLayer[] Layer, short[] Message) { // preparation: Modifies the document with the inverse of L1, tmp = Y - b1: short[] tmpVec = new short[Message.Length]; tmpVec = _cptIf.AddVect(((RNBWPrivateKey)this._asmKey).B1, Message); // Y_ = A1^{-1} * (Y - b1) : short[] y = _cptIf.MultiplyMatrix(((RNBWPrivateKey)this._asmKey).InvA1, tmpVec); // generates the vinegar vars of the first layer at random for (int i = 0; i < Layer[0].VI; i++) { _X[i] = (short)_rndEngine.Next(); _X[i] = (short)(_X[i] & GF2Field.MASK); } return y; }
/// <summary> /// Initialize this class /// </summary> /// /// <param name="A1inv">The inverse of A1(the matrix part of the affine linear map L1) (n-v1 x n-v1 matrix)</param> /// <param name="B1">Translation vector, part of the linear affine map L1</param> /// <param name="A2inv">The inverse of A2(the matrix part of the affine linear map L2) (n x n matrix)</param> /// <param name="B2">Translation vector, part of the linear affine map L2</param> /// <param name="Vi">The number of Vinegar-variables per layer</param> /// <param name="Layers">The polynomials with their coefficients of private map F</param> internal RNBWPrivateKey(short[][] A1inv, short[] B1, short[][] A2inv, short[] B2, int[] Vi, MapLayer[] Layers) { _a1Inv = A1inv; _B1 = B1; _a2Inv = A2inv; _B2 = B2; _VI = Vi; _layers = Layers; }