Beispiel #1
0
        public GGHModel(int dim, int l, VectorND errorVector)
        {
            this.dim = dim;
            this.l   = l;
            k        = (int)Math.Round(l * Math.Sqrt(dim));

            do
            {
                GeneratePrivateKey();
                GeneratePublicKey();
            } while (privateKeyR.Det() == 0 || publicKeyB.Det() == 0);

            privateKeyR1 = privateKeyR.Invert();
            publicKeyB1  = publicKeyB.Invert();

            GenerateLattice();

            if (errorVector == null || errorVector.dim != dim)
            {
                GenerateErrorVector();
            }
            else
            {
                this.errorVector  = errorVector;
                errorVectorIntern = new MatrixND(dim, 1);
                for (int i = 0; i < dim; i++)
                {
                    errorVectorIntern[i, 0] = (double)errorVector.values[i];
                }
            }
        }
Beispiel #2
0
        public static MatrixND Power(MatrixND m, int pow)           // Power matrix to exponent
        {
            if (pow == 0)
            {
                return(IdentityMatrix(m.rows, m.cols));
            }
            if (pow == 1)
            {
                return(m.Duplicate());
            }
            if (pow == -1)
            {
                return(m.Invert());
            }

            MatrixND x;

            if (pow < 0)
            {
                x = m.Invert(); pow *= -1;
            }
            else
            {
                x = m.Duplicate();
            }

            MatrixND ret = IdentityMatrix(m.rows, m.cols);

            while (pow != 0)
            {
                if ((pow & 1) == 1)
                {
                    ret *= x;
                }
                x    *= x;
                pow >>= 1;
            }
            return(ret);
        }
Beispiel #3
0
        public void SetPrivateKeyManually(MatrixND newPrivateKeyR, bool generatePublicKey)
        {
            privateKeyR  = newPrivateKeyR;
            privateKeyR1 = privateKeyR.Invert();

            if (!generatePublicKey)
            {
                return;
            }

            do
            {
                GeneratePublicKey();
            } while (publicKeyB.Det() == 0);

            publicKeyB1 = publicKeyB.Invert();
        }
Beispiel #4
0
        public GGHModel(int dim, MatrixND privateKeyR, MatrixND publicKeyB, VectorND errorVector)
        {
            this.dim         = dim;
            this.privateKeyR = privateKeyR;
            this.publicKeyB  = publicKeyB;
            privateKeyR1     = privateKeyR.Invert();
            publicKeyB1      = publicKeyB.Invert();

            GenerateLattice();

            this.errorVector  = errorVector;
            errorVectorIntern = new MatrixND(dim, 1);
            for (int i = 0; i < dim; i++)
            {
                errorVectorIntern[i, 0] = (double)errorVector.values[i];
            }
        }
Beispiel #5
0
 public void SetPublicKeyManually(MatrixND newPublicKeyB)
 {
     publicKeyB  = newPublicKeyB;
     publicKeyB1 = publicKeyB.Invert();
 }