intel / cryptography-primitives

Apache License 2.0
318 stars 86 forks source link

Is there any example about how to generate RSA key pair by ippsRSA_GenerateKeys()? #40

Closed xhuan28 closed 2 years ago

xhuan28 commented 2 years ago

Is there any example about how to generate RSA key pair by ippsRSA_GenerateKeys(). Per my understanding, I have to allocate memory for pModulus, pPublicExp and pPrivateExp respectively before call ippsRSA_GenerateKeys(), right? If the bit size of n is 1024 and the bit size of e is 16, I can allocate memory for pModulus and pPublicExp easily. However, how can I allocate memory for pPrivateExp as I don't know the bit size of d. Is there any relationship between the bit size of n, e and d? Thanks.

amatyuko-intc commented 2 years ago

No, unfortunately we don't have a complete example in the source tree, but you can refer to the Developer Reference page for description of the function and steps that should be taken to use it.

The bit size of the private exponent is at most bit size of modulus, so you should allocate an IppsBigNumState object of this size:

int size;
const int len = 1024 / 32;
ippsBigNumGetSize(len, &size);
IppsBigNumState* pBN = (IppsBigNumState*) malloc(size);
ippsBigNumInit(len, pBN);
xhuan28 commented 2 years ago

Thanks for your answer.