Intel® Integrated Performance Primitives
Deliberate problems developing high-performance vision, signal, security, and storage applications.

RSA Encryption

Kryten67
Beginner
1,449 Views

I'm trying to find some easy-to-follow RSA key-generation, encryption/decryption examples.

What I've found are

http://software.intel.com/en-us/node/503498

and

http://software.intel.com/en-us/node/503457

Firstly, I'm not sure why (for example)

// Q prime factor
BigNumber    Q("0xC97FB1F027F453F6341233EAAAD1D9353F6C42D08866B1D05A0F2035028B9D86"
                 "9840B41666B42E92EA0DA3B43204B5CFCE3352524D0416A5A441E700AF461503");

This appear to be constants -- I'm assuming that these values are created by the RSA key generation procedure?

I can't get the samples to build as they are on the Intel site (I'm using IPP 8.1 on Windows FYI). I get the following errors:

error C2660: 'ippsPrimeGen' : function does not take 1 arguments

      IppsPrimeState* pPrimeG = ippsPrimeGen(P.BitSize());

and

1>rsa.cpp(83): error C3861: 'deletePrimeGen': identifier not found

      deletePrimeGen(pPrimeG);

 

Am I using the right samples for 8.1?

Are there better examples available -- I'm trying to find a good example that shows the end-to-end process or creating private/public key, using keys for encyption and decryption...

Any pointers greatly appreciated.

0 Kudos
1 Solution
Igor_A_Intel
Employee
1,449 Views

hi Paul,

  1. “This appear to be constants -- I'm assuming that these values are created by the RSA key generation procedure?”

Definitely RSA parameters were generated by some RSA key generation procedure.

  1. “I get the following errors: error C2660: 'ippsPrimeGen' : function does not take 1 arguments   IppsPrimeState* pPrimeG = ippsPrimeGen(P.BitSize()); “

I see the typo: ippsPrimeGen instead of newPrimeGen

  1. “rsa.cpp(83): error C3861: 'deletePrimeGen': identifier not found    deletePrimeGen(pPrimeG);”

Agree. No deletePrimeGen() propotype. I’ve send an update to the manual - will be available in the next release

  1. “Am I using the right samples for 8.1?”

Samples are working in general.

  1. “I'm trying to find a good example that shows the end-to-end process or creating private/public key, using keys for encyption and decryption...”

Use ippCP manual and try something like the following to generate RSA-1024 (it's just a scheme - haven't tried to compile)

   int factorP_bits = 512;

   int factorP_bits = 1024;

   int rsa_bits = factorP_bits + factorQ_bits;

 

   // random generator

   IppsPRNGState* pRand = newPRNG();

   // prime generator

   IppsPrimeState* pPrimeG = newPrimeGen(factorP_bits);

 

   // RSA modulus and public exponent

   BigNumber N(0, BITSIZE_WORD(rsa_bits));

   BigNumber E;

 

   // private type2 RSA

   int prvSize;

   ippsRSA_GetSizePrivateKeyType2(factorP_bits, factorQ_bits, &prvSize);

   IppsRSAPrivateKeyState* pPrvKey = (IppsRSAPrivateKeyState*)(new Ipp8u [prvSize]);

   ippsRSA_InitPrivateKeyType2(factorP_bits, factorQ_bits, pPrvKey, prvSize);

 

   // scratch buffer

   int bufSize;

   ippsRSA_GetBufferSizePrivateKey(&bufSize, pPrvKey);

   Ipp8u* pBuffer = new Ipp8u [bufSize];

 

   // init value of the public exponent

   BigNumber E0(3);

 

   // generate RSA system

   do {

      sts = ippsRSA_GenerateKeys(E0, N, E, NULL,

                                 pPrvKey,

                                 pBuffer,

                                 50,

                                 pPrimeGen,

                                 ippsPRNGen, pPRNG)

   } while(sts!=ippStsNoErr);

regards, Igor

 

 

View solution in original post

0 Kudos
4 Replies
Igor_A_Intel
Employee
1,450 Views

hi Paul,

  1. “This appear to be constants -- I'm assuming that these values are created by the RSA key generation procedure?”

Definitely RSA parameters were generated by some RSA key generation procedure.

  1. “I get the following errors: error C2660: 'ippsPrimeGen' : function does not take 1 arguments   IppsPrimeState* pPrimeG = ippsPrimeGen(P.BitSize()); “

I see the typo: ippsPrimeGen instead of newPrimeGen

  1. “rsa.cpp(83): error C3861: 'deletePrimeGen': identifier not found    deletePrimeGen(pPrimeG);”

Agree. No deletePrimeGen() propotype. I’ve send an update to the manual - will be available in the next release

  1. “Am I using the right samples for 8.1?”

Samples are working in general.

  1. “I'm trying to find a good example that shows the end-to-end process or creating private/public key, using keys for encyption and decryption...”

Use ippCP manual and try something like the following to generate RSA-1024 (it's just a scheme - haven't tried to compile)

   int factorP_bits = 512;

   int factorP_bits = 1024;

   int rsa_bits = factorP_bits + factorQ_bits;

 

   // random generator

   IppsPRNGState* pRand = newPRNG();

   // prime generator

   IppsPrimeState* pPrimeG = newPrimeGen(factorP_bits);

 

   // RSA modulus and public exponent

   BigNumber N(0, BITSIZE_WORD(rsa_bits));

   BigNumber E;

 

   // private type2 RSA

   int prvSize;

   ippsRSA_GetSizePrivateKeyType2(factorP_bits, factorQ_bits, &prvSize);

   IppsRSAPrivateKeyState* pPrvKey = (IppsRSAPrivateKeyState*)(new Ipp8u [prvSize]);

   ippsRSA_InitPrivateKeyType2(factorP_bits, factorQ_bits, pPrvKey, prvSize);

 

   // scratch buffer

   int bufSize;

   ippsRSA_GetBufferSizePrivateKey(&bufSize, pPrvKey);

   Ipp8u* pBuffer = new Ipp8u [bufSize];

 

   // init value of the public exponent

   BigNumber E0(3);

 

   // generate RSA system

   do {

      sts = ippsRSA_GenerateKeys(E0, N, E, NULL,

                                 pPrvKey,

                                 pBuffer,

                                 50,

                                 pPrimeGen,

                                 ippsPRNGen, pPRNG)

   } while(sts!=ippStsNoErr);

regards, Igor

 

 

0 Kudos
Kryten67
Beginner
1,449 Views

Thanks!

0 Kudos
bevin_b_
New Contributor I
1,374 Views

There are several problems in the above approximation.  It would be nice to have a working example posted here, or at least a link to one

0 Kudos
Abhinav_S_Intel
Moderator
1,346 Views

IPP Crypto samples are available here:

https://github.com/intel/ipp-crypto/tree/develop/examples

0 Kudos
Reply