Cryptography Reference
In-Depth Information
// wrong block type or incorrect format
return (UCHAR*)NULL;
}
else
{
return Mess; // return pointer to message
}
}
// RSA signing
LINT RSAkey::sign (const UCHAR* Mess, int LenMess)
{
int LenEncryptionBlock = key.bytelen_mod - 1;
UCHAR HashRes[RMDVER>>3];
UCHAR* EncryptionBlock = new UCHAR[LenEncryptionBlock];
ripemd160 (HashRes, (UCHAR*)Mess, (ULONG)LenMess);
if (NULL == format_pkcs1 (EncryptionBlock, LenEncryptionBLock,
BLOCKTYPE_SIGN, HashRes, RMDVER >> 3))
{
delete [] EncryptionBlock;
return LINT (0);// error in formatting: message too long
}
// change encryption block into LINT number (constructor 3)
LINT m = LINT (EncryptionBlock, LenEncryptionBlock);
delete [] EncryptionBlock;
return fastdecrypt (m);
}
////////////////////////////////////////////////////////////////////////
// private auxiliary functions of the class RSAkey
// ... among other things: RSA key generation according to IEEE P1363, Annex A
// If parameter PubExp == 1 or is absent, a public exponent
// of length half the modulus is determined randomly.
int RSAkey::makekey (int length, const LINT& PubExp)
{
// generate prime p such that 2 ˆ (m-r-1)<=p<2 ˆ (m - r), where
//m=
(length + 1)/2 and r random in interval 2 <=r<15
USHORT m = ((length + 1) >> 1)-2-usrandBBS_l () % 13;
key.p = findprime (m, PubExp);
// determine interval bounds qmin and qmax for prime q
// set qmin =
(2 ˆ (length - 1))/p + 1
LINT qmin = LINT(0).setbit (length - 1)/key.p + 1;
// set qmax =
(2 ˆ length - 1)/p)
LINT qmax = (((LINT(0).setbit (length - 1) - 1) << 1) + 1)/key.p;
Search WWH ::




Custom Search