Community
cancel
Showing results for 
Search instead for 
Did you mean: 
achrzesz2
New Contributor I
88 Views

cryptography: ippsECCPSignDSA example

Hello,
as a newcomer I'm trying to write a simple example to ippsECCPSignDSA.
What should I change to obtain valid signature with this code:

#include "ippcore.h"
#include "ippcp.h"
#include "bignum.h"
#include
#include "cpobjs.h"

int main(){
int pSize;
int feBitSize=256;

// Standart EC 256r1 Setting
ippsECCPGetSize(feBitSize,&pSize);
//cout << "pSize: " << pSize<< endl;
IppsECCPState* pECC=(IppsECCPState *)(new Ipp8u [pSize]);
ippsECCPInit(feBitSize,pECC);
ippsECCPSetStd(IppECCPStd256r1,pECC);

// ECValidation
IppsPRNGState* pRand=newPRNG();
int nTrials=20;
IppECResult pResult;
ippsECCPValidate(nTrials,&pResult,pECC,ippsPRNGen,pRand);//pRand pPrng
cout << "ECValidation: " << ippsECCGetResultString(pResult) << endl;
//ECValidation: Validation pass successfully

// Regular Keys
int pPointSize;
ippsECCPPointGetSize(feBitSize,&pPointSize);
IppsBigNumState* pPrivate = newBN(feBitSize/32); ////???
IppsECCPPointState* pPublic=(IppsECCPPointState *)(new Ipp8u [pPointSize]);
ippsECCPPointInit(feBitSize,pPublic);
ippsECCPGenKeyPair(pPrivate,pPublic,pECC,ippsPRNGen,pRand);
ippsECCPSetKeyPair(pPrivate,pPublic,ippTrue,pECC);
ippsECCPValidateKeyPair(pPrivate,pPublic,&pResult,pECC);
cout << "regKeyPairValidation: "<< ippsECCGetResultString(pResult) << endl;
//regKeyPairValidation: Validation pass successfully

// Digest
Ipp32u ddat[] = {
0xBEAD208B, 0x5E668076, 0x2ABF62E3, 0xDB7C000};
IppsBigNumState* digest=newBN(feBitSize/32,ddat);

// Ephemeral Keys
IppsBigNumState* pephPrivate = newBN(feBitSize/32);////???
IppsECCPPointState* pephPublic=(IppsECCPPointState *)(new Ipp8u [pPointSize]);
ippsECCPGenKeyPair(pephPrivate,pephPublic,pECC,ippsPRNGen,pRand);
ippsECCPSetKeyPair(pephPrivate,pephPublic,ippFalse,pECC);
ippsECCPPublicKey(pephPrivate,pephPublic,pECC);
ippsECCPValidateKeyPair(pephPrivate,pephPublic,&pResult,pECC);
cout << "ephKeyPairValidation: "<< ippsECCGetResultString(pResult) << endl;
//ephKeyPairValidation: Validation pass successfully

// Signature
IppsBigNumState* pSignX = newBN(feBitSize/32);////???
IppsBigNumState* pSignY = newBN(feBitSize/32);////???
IppStatus w;
w=ippsECCPSignDSA(digest,pPrivate,pSignX,pSignY,pECC);
cout << "Sign: "<//Sign: ippStsNoErr: No error, it's OK

//Verification
w=ippsECCPVerifyDSA(digest,pSignX,pSignY,&pResult,pECC);
cout << "Verify: "<< ippsECCGetResultString(pResult) << endl;
//Verify: Invalid Signature // !!!
cout <<"Verify: "<< ippGetStatusString(w) << endl;
//Verify: ippStsNoErr: No error, it's OK
return 0;
}

A. Chrzeszczyk
0 Kudos
2 Replies
achrzesz2
New Contributor I
88 Views

Quoting - achrzesz2
Hello,
as a newcomer I'm trying to write a simple example to ippsECCPSignDSA.
What should I change to obtain valid signature with this code:

#include "ippcore.h"
#include "ippcp.h"
#include "bignum.h"
#include
#include "cpobjs.h"

int main(){
int pSize;
int feBitSize=256;

// Standart EC 256r1 Setting
ippsECCPGetSize(feBitSize,&pSize);
//cout << "pSize: " << pSize<< endl;
IppsECCPState* pECC=(IppsECCPState *)(new Ipp8u [pSize]);
ippsECCPInit(feBitSize,pECC);
ippsECCPSetStd(IppECCPStd256r1,pECC);

// ECValidation
IppsPRNGState* pRand=newPRNG();
int nTrials=20;
IppECResult pResult;
ippsECCPValidate(nTrials,&pResult,pECC,ippsPRNGen,pRand);//pRand pPrng
cout << "ECValidation: " << ippsECCGetResultString(pResult) << endl;
//ECValidation: Validation pass successfully

// Regular Keys
int pPointSize;
ippsECCPPointGetSize(feBitSize,&pPointSize);
IppsBigNumState* pPrivate = newBN(feBitSize/32); ////???
IppsECCPPointState* pPublic=(IppsECCPPointState *)(new Ipp8u [pPointSize]);
ippsECCPPointInit(feBitSize,pPublic);
ippsECCPGenKeyPair(pPrivate,pPublic,pECC,ippsPRNGen,pRand);
ippsECCPSetKeyPair(pPrivate,pPublic,ippTrue,pECC);
ippsECCPValidateKeyPair(pPrivate,pPublic,&pResult,pECC);
cout << "regKeyPairValidation: "<< ippsECCGetResultString(pResult) << endl;
//regKeyPairValidation: Validation pass successfully

// Digest
Ipp32u ddat[] = {
0xBEAD208B, 0x5E668076, 0x2ABF62E3, 0xDB7C000};
IppsBigNumState* digest=newBN(feBitSize/32,ddat);

// Ephemeral Keys
IppsBigNumState* pephPrivate = newBN(feBitSize/32);////???
IppsECCPPointState* pephPublic=(IppsECCPPointState *)(new Ipp8u [pPointSize]);
ippsECCPGenKeyPair(pephPrivate,pephPublic,pECC,ippsPRNGen,pRand);
ippsECCPSetKeyPair(pephPrivate,pephPublic,ippFalse,pECC);
ippsECCPPublicKey(pephPrivate,pephPublic,pECC);
ippsECCPValidateKeyPair(pephPrivate,pephPublic,&pResult,pECC);
cout << "ephKeyPairValidation: "<< ippsECCGetResultString(pResult) << endl;
//ephKeyPairValidation: Validation pass successfully

// Signature
IppsBigNumState* pSignX = newBN(feBitSize/32);////???
IppsBigNumState* pSignY = newBN(feBitSize/32);////???
IppStatus w;
w=ippsECCPSignDSA(digest,pPrivate,pSignX,pSignY,pECC);
cout << "Sign: "<//Sign: ippStsNoErr: No error, it's OK

//Verification
w=ippsECCPVerifyDSA(digest,pSignX,pSignY,&pResult,pECC);
cout << "Verify: "<< ippsECCGetResultString(pResult) << endl;
//Verify: Invalid Signature // !!!
cout <<"Verify: "<< ippGetStatusString(w) << endl;
//Verify: ippStsNoErr: No error, it's OK
return 0;
}

A. Chrzeszczyk

Hi
The problem was caused by the uninitialized Ephemeral Key
After initialization it's OK.
achrzesz2
Vladimir_Dudnik
Employee
88 Views


Thanks for update on this and glad to hear it work for you.

Vladimir
Reply