示例#1
0
        static void scalarMultiply(byte[] resFirst, byte[] resSecond, byte[] genx, byte[] geny, byte[] k)
        {
            bool flag = false;

            byte[] two       = { 2 };
            byte[] tempFirst = null, tempSecond = null, accFirst, accSecond;

            accFirst  = genx;
            accSecond = geny;
            k         = byteArithmetic.divm_byte_arr(k, CurveData.getp()); byte[] temp = { 2 };
            while (checkzero(k))
            {
                byte[] t = byteArithmetic.divm_byte_arr(k, temp);
                if (checkzero(t))
                {
                    if (flag == false)
                    {
                        tempFirst  = byteArithmetic.Add(CurveData.getp(), accFirst);
                        tempFirst  = byteArithmetic.divm_byte_arr(tempFirst, CurveData.getp());
                        tempSecond = byteArithmetic.Add(CurveData.getp(), accSecond);
                        tempSecond = byteArithmetic.divm_byte_arr(tempSecond, CurveData.getp());
                        flag       = true;
                    }
                }
                else
                {
                    add(tempFirst, tempSecond, resFirst, resSecond, accFirst, accSecond);
                }
                resFirst = tempFirst; resSecond = tempSecond;
            }
            doubling(tempFirst, tempSecond, accFirst, accSecond);
            accFirst = tempFirst; accSecond = tempSecond;
            k        = byteArithmetic.divq_byte_arr(k, two);
        }
示例#2
0
 static void add(byte[] PFirst, byte[] PSecond, byte[] RFirst, byte[] RSecond, byte[] QFirst, byte[] QSecond)
 {
     //	cout<<"add "<<Q.first<<" "<<P.first<<endl;
     byte[] slope;
     slope   = byteArithmetic.divq_byte_arr(byteArithmetic.Subtract(QSecond, PSecond), byteArithmetic.Subtract(QFirst, PFirst));
     RFirst  = byteArithmetic.Subtract(byteArithmetic.Subtract(byteArithmetic.Add(CurveData.getp(), byteArithmetic.Multiply(slope, slope)), PFirst), QFirst);
     RFirst  = byteArithmetic.divm_byte_arr(RFirst, CurveData.getp());
     RSecond = byteArithmetic.Subtract(byteArithmetic.Add(CurveData.getp(), byteArithmetic.Multiply(slope, byteArithmetic.Subtract(PFirst, RFirst))), PSecond);
     RSecond = byteArithmetic.divm_byte_arr(RSecond, CurveData.getp());
 }
示例#3
0
 static void doubling(byte[] PFirst, byte[] PSecond, byte[] RFirst, byte[] RSecond)
 {
     //	cout<<"DOUBLING "<<P.second<<"\n";
     byte[] x, y;
     byte[] slope, div;
     byte[] temp = { 3 }, temp1 = { 2 };
     slope  = byteArithmetic.Add(CurveData.geta(), byteArithmetic.Multiply(PFirst, byteArithmetic.Multiply(temp, PSecond)));
     div    = byteArithmetic.Multiply(temp1, PSecond);
     slope  = byteArithmetic.divq_byte_arr(slope, div);
     x      = byteArithmetic.Subtract(byteArithmetic.Add(CurveData.getp(), byteArithmetic.Multiply(slope, slope)), byteArithmetic.Multiply(temp1, PFirst));
     x      = byteArithmetic.divm_byte_arr(x, CurveData.getp());
     y      = byteArithmetic.Subtract(byteArithmetic.Add(CurveData.getp(), byteArithmetic.Multiply(slope, byteArithmetic.Subtract(PSecond, PSecond))), PSecond);
     y      = byteArithmetic.divm_byte_arr(y, CurveData.getp());
     RFirst = x; RSecond = y;
 }