Post
Topic
Board Development & Technical Discussion
Re: How to construct hardened ECDSA from ECDSA?
by
garlonicon
on 18/11/2023, 11:19:21 UTC
Quote
I would like to know the relation between p and n, because it seems that G is irrelevant in the curve calculations.
I can even give you some code to get n-value, based on p-value, and the curve equation. Of course, it is the simplest brute-force, and it will stop working if you use it on bigger numbers, but it is simple enough to understand it, and implement in any programming language you want.
Code:
#include <iostream>

int get_n_from_p(int p)
{
    int n=1; //we start from n=1, and not n=0, because of the point at infinity
    for(int y=0;y<p;++y)
    {
        for(int x=0;x<p;++x)
        {
            int y_square=(y*y)%p;
            int x_cube=(x*x*x)%p;
            int x_cube_plus_seven=(x_cube+7)%p;
            if(y_square==x_cube_plus_seven)
            {
                ++n;
            }
        }
    }
    return n;
}

int main()
{
    for(int p=1;p<=1000;++p)
    {
        std::cout<<"p="<<p<<", n="<<get_n_from_p(p)<<'\n';
    }
}
See? No generator is used there. Every single point is checked, and you can just create an image, and put a black pixel, if there is no point on a given curve, or put a white pixel, when you can find a match. This is basically what vjudeu did in his repository. As you can see, in this brute-force algorithm, there is no need to even pick any specific point, because all of them are checked.