Hi Julie,
Find below an example of what I have tried starting for a .pkcs8 file.
Hope it helps...
const BYTE IS[]={ 0x30,0x81,0xFF,
0x02,0x01,0x00,0x30,0x81,0xD4,0x06,0x07,0x2A,0x86,0x48,0xCE,0x3D,
0x02,0x01,0x30,0x81,0xC8,0x02,0x01,0x01,0x30,0x28,0x06,0x07,0x2A,
0x86,0x48,0xCE,
0x3D,0x01,0x01,0x02,0x1D,0x00,0xD7,0xC1,0x34,0xAA,
0x26,0x43,0x66,0x86,0x2A,0x18,
0x30,0x25,0x75,0xD1,0xD7,0x87,0xB0,0x9F,0x07,0x57,0x97,0xDA,
0x89,0xF5,0x7E,0xC8,
0xC0,0xFF,0x30,0x3C,0x04,0x1C,0x68,0xA5,0xE6,0x2C,0xA9,0xCE,0x6C,
0x1C,0x29,0x98,
0x03,0xA6,0xC1,0x53,0x0B,0x51,0x4E,0x18,0x2A,0xD8,0xB0,0x04,0x2A,
0x59,0xCA,0xD2,
0x9F,0x43,0x04,0x1C,0x25,0x80,0xF6,0x3C,0xCF,
0xE4,0x41,0x38,0x87,0x07,0x13,0xB1,
0xA9,0x23,0x69,0xE3,0x3E,0x21,0x35,0xD2,0x66,0xDB,
0xB3,0x72,0x38,0x6C,0x40,0x0B,
0x04,0x39,0x04,0x0D,0x90,0x29,0xAD,0x2C,0x7E,0x5C,
0xF4,0x34,0x08,0x23,0xB2,0xA8,
0x7D,0xC6,0x8C,0x9E,0x4C,0xE3,0x17,0x4C,0x1E,0x6E,0xFD,0xEE,
0x12,0xC0,0x7D,0x58,
0xAA,0x56,0xF7,0x72,0xC0,0x72,0x6F,0x24,0xC6,0xB8,0x9E,0x4E,0xCD,
0xAC,0x24,0x35,
0x4B,0x9E,0x99,0xCA,0xA3,0xF6,0xD3,0x76,0x14,0x02,0xCD,0x02,0x1D,
0x00,0xD7,0xC1,
0x34,0xAA,0x26,0x43,0x66,0x86,0x2A,0x18,0x30,0x25,0x75,0xD0,0xFB,
0x98,0xD1,0x16,
0xBC,0x4B,0x6D,0xDE,0xBC,0xA3,0xA5,0xA7,0x93,0x9F,
0x02,0x01,0x01,0x04,0x23,0x30,
0x21,0x02,0x01,0x01,0x04,0x1C,0x06,0x08,0x0E,0xED,0x1B,0x5B,0xDC,
0x1B,0xD9,0xDF,
0x8E,0xEA,0x40,0xCF,0x28,0x22,0x15,0x70,0x8E,0x7C,0x2D,0x96,0x5E,
0x21,0xC7,0x17,
0x38,0x66};
const BYTE message[] =
{0x35,0x38,0x52,0x46,0x30,0x32,0x32,0x34,0x38,0x37,
0xbb,0x2a,0xcf,0x6d,0xe3,0x2f,0x88,0xf8,
0x36,0xb8,0xc3,0x25,0x8a,0xda,0xfe,
0xf5,0xa1,0xc9,0x9e,0x88,0x3f,0x8d,0xb8,0xfa,0x1b,0x01,0x8d,0x30};
const BYTE signature[]={0x62,0xa4,0xca,0xa2,0xcb,0xa0,0x4b,0x4b,0x0c,
0xf4,0x4e,0x4c,0x58,0x79,0x1d,0xf6,
0x5c,0x17,0x35,0x10,0x9f,0x44,0x8d,0xcf,0xbf,0x01,0x43,0x33,0x1f,
0xe0,0x54,0x69,
0x54,0xd7,0x96,0x66,0x29,0x52,0x02,0x7a,
0x34,0x31,0xf1,0x20,0xa3,0x17,0xa1,0xfd,
0xf4,0x54,0x8b,0x90,0x8f,0x1d,0x6b,0xa4};
void TA_ECDSA(void)
{
AutoSeededRandomPool arng;
RandomNumberGenerator& rng = *dynamic_cast<RandomNumberGenerator
*>(&arng);
BOOL bVerify;
CryptoPP::ECDSA<CryptoPP::ECP,CryptoPP::SHA224>::PrivateKey
ecdsaPrivateKey;
CryptoPP::ECDSA<CryptoPP::ECP,CryptoPP::SHA224>::PublicKey
ecdsaPublicKey;
unsigned long ISLength = sizeof(IS);
std::string sIS(reinterpret_cast<const char *>(IS), ISLength);
ecdsaPrivateKey.BERDecode(StringStore(sIS).Ref());
ecdsaPublicKey.AssignFrom(ecdsaPrivateKey);
CryptoPP::ECDSA<CryptoPP::ECP,CryptoPP::SHA224>::Signer
ecdsasigner(ecdsaPrivateKey);
CryptoPP::ECDSA<CryptoPP::ECP,CryptoPP::SHA224>::Verifier
ecdsaverifier(ecdsaPublicKey);
BYTE *ECDSAsignature = (BYTE*)
calloc(ecdsasigner.SignatureLength(),sizeof(BYTE));
ecdsasigner.SignMessage(rng,message,sizeof(message),ECDSAsignature);
Log.Log("Signature 0x%x bytes long:", ecdsasigner.SignatureLength());
Log.LogHex(ECDSAsignature, ecdsasigner.SignatureLength(), 16);
Log.Log("ECDSA Sign %d
(0=OK)",memcmp(signature,ECDSAsignature,ecdsasigner.SignatureLength()));
bVerify=ecdsaverifier.VerifyMessage(message,sizeof(message),ECDSAsignature,ecdsasigner.SignatureLength());
Log.Log("Verify returned %d (1=OK 0=failed)", bVerify);
bVerify=ecdsaverifier.VerifyMessage(message,sizeof(message),signature,sizeof(signature));
Log.Log("Verify returned %d (1=OK 0=failed)", bVerify);
}
Regards,
Spirou
On 30 mar, 15:13, Julie VOLLAND <[email protected]> wrote:
> Hi all,
>
> We are trying to sign a message with the ECDSA algorithm, for that we
> want to use a key we have inside a file. We have already done the same
> thing for the RSA_PKCS1 and the RSA_PSS algorithms and with these
> both algorithms it works very well ! But with ECDSA it doesn’t work
> and we don’t understand why. Actually, we always have a data abort at
> run time…
>
> You can find below the code for RSA_PKCS1 and RSA_PSS and also the
> code we try to do to use ECDSA.
>
> /////////////////////////////////////////////
>
> // encryption: RSASSA_PKCS1_V1_5_SIGNATURE //
>
> /////////////////////////////////////////////
>
> if(hashIndex==SHA1_HASH &&
> encryptIndex==RSASSA_PKCS1_V1_5_SIGNATURE)
>
> {
>
> CryptoPP::RandomPool randomPool;
>
> CryptoPP::FileSource privFile(keyFileName.c_str(), true,
> new CryptoPP::HexDecoder);
>
> CryptoPP::RSASS<CryptoPP::PKCS1v15,
> CryptoPP::SHA1>::Signer priv(privFile);
>
> priv.SignMessage (randomPool, (const byte *)pMsgBuffer,
> msgLength,(byte *) pCertificateBuffer);
>
> }
>
> //////////////////////////////////////
>
> // encryption: RSASSA_PSS_SIGNATURE //
>
> //////////////////////////////////////
>
> if(hashIndex==SHA1_HASH && encryptIndex==RSASSA_PSS_SIGNATURE)
>
> {
>
> CryptoPP::RandomPool randomPool;
>
> CryptoPP::FileSource privFile(keyFileName.c_str(), true,
> new CryptoPP::HexDecoder);
>
> CryptoPP::RSASS<CryptoPP::PSS, CryptoPP::SHA1>::Signer
> priv(privFile);
>
> priv.SignMessage (randomPool, (const byte *)pMsgBuffer,
> msgLength,(byte *) pCertificateBuffer);
>
> }
>
> /////////////////////////////////
>
> // encryption: ECDSA_SIGNATURE //
>
> /////////////////////////////////
>
> if(hashIndex==SHA1_HASH && encryptIndex==ECDSA_SIGNATURE)
>
> {
>
> CryptoPP::RandomPool randomPool;
>
> CryptoPP::FileSource privFile(keyFileName.c_str(), true,
> new CryptoPP::HexDecoder);
>
> CryptoPP::ECDSA<ECP,SHA1>::Signer priv(privFile);
>
> priv.SignMessage (randomPool, (const byte *)pMsgBuffer,
> msgLength,(byte *) pCertificateBuffer);
>
> }
>
> We have also tried to find another way to use this algorithm: in using
> this kind of code for example:
>
> ECIES<ECP>::PrivateKey privateKey;
> ByteQueue bq;
> StringSource(base32encodedKey, true, new Base32Decoder(new
> Redirector(bq)));
> privateKey.Load(bq);
>
> But it doesn’t work better because we don’t know how to use our own
> key.
>
> Can you help us? Can't we use the same method as for PSS/PKCS ?
>
> We are working with the CryptoPP version 5.5.2 and Visual studio 2005.
>
> Regards,
>
> Julie
--
You received this message because you are subscribed to the "Crypto++ Users"
Google Group.
To unsubscribe, send an email to [email protected].
More information about Crypto++ and this group is available at
http://www.cryptopp.com.
Subscription settings:
http://groups.google.com/group/cryptopp-users/subscribe?hl=en