如何为bigint生成RSA密钥?

时间:2018-06-27 09:18:50

标签: c rsa public-key-encryption

我正在使用以下程序生成4个字节长(无符号长)的RSA密钥。所以我的问题是如何修改程序以使用大整数?

void keygen(unsigned long int e, unsigned long int p, unsigned long int q)
{
    unsigned long int phi,d,n,s;

    n = p*q;
    phi=(p-1)*(q-1);

    d = phi / e ;

    do
    {
        d++;
    }
    while( ((d*e) % phi) != 1 );

    printf("\n public key: { e=%u n=%u }",e,n);
    printf("\n private key: { d=%u n=%u }",d,n);
    printf("\n verify modulo = %d\n",((d*e) % phi)); /* this need to be 1 */
}

void main()
{
    keygen(3, 17, 19);
    system("pause");
}

0 个答案:

没有答案