| Thread Tools | Search this thread |
|---|
bqduong
| March 31, 2009 3:10 PM PDT RSA Encryption using C | ||||
Hi, I am trying to create a function for a dll that takes in a char* to a string and encrypts the string. I am not sure why I get a ippStscontextMatchErr when I send in my context to the ippsRSASetkey function. I am following the steps stated in the user manual for cryptography: "The application code for conducting a typical RSA encryption must perform the following sequence of operations, starting with building of a crypto system: 1. Call the function RSAGetSize to get the size required to configure IppsRSAState context. 2. Ensure that the required memory space is properly allocated. With the allocated memory, call the RSAInit function to initialize the context for the RSA encryption. 3. Keep calling the RSASetKey to set up RSA public key (n, e). 4. Invoke the RSAEncrypt function with the established RSA public key to encode the plaintext into the respective ciphertext. 5. Free the memory allocated for the IppsRSAState context by calling the operating system memory free service function." This is what I did prior to the error: void __declspec(dllexport) RSAEncyrption(char* myString, unsigned char* encrypted) { int pSize, bitsN, bitsP; IppsRSAState *pCtx; IppsBigNumState *pY, *pBN, *pE; bitsN = 128; bitsP = 64; //allocate space for cyphertext (not sure if its //the same way as the AES IPP pY = (IppsBigNumState *)malloc(strlen(myString)) //get the size required to configure IppsRSAState context ippsRSAGetSize(bitsN, bitsP, IppRSApublic, &pSize); //allocate memory pCtx = (IppsRSAState *)malloc(sizeof(Ipp8u)*pSize); //init key ippsRSAInit(bitsN, bitsP, IppRSApublic, pCtx); pBN = (IppsBigNumState *)malloc(sizeof(Ipp8u)*pSize); pE = (IppsBigNumState *)malloc(sizeof(Ipp8u)*pSize); ippsRSASetKey(pBN, IppRSAkeyN, pCtx); ippsRSASetKey(pE, IppRSAkeyE, pCtx); //not sure if I can just pass in a char* like the AES IPP ippsRSAEncrypt((IppsBigNumState*)myString, pY, pCtx); memcpy(encrypted, pY, strlen(myString)); } So all in all, the call to ippsRSASetkey throws a return value of -17 which says that the context parameter does not match the operation. I am confused as I thought the ippsRSAinit function takes care of the context (pCtx). Any help would be greatly appreciated. Thanks. | |||||
|
|||||||||||||
| 8473 users have contributed to 31604 threads and 100653 posts to date. |
|---|
| In the past 24 hours, we have 31 new thread(s) 110 new posts(s), and 163 new user(s). In the past 3 days, the most popular thread for everyone has been gemm(A,A,A) like possible? The most posts were made to gemm(A,A,A) like possible? The post with the most views is Dear Steve, excuse me for a d Please welcome our newest member Kevin Johnson |