summaryrefslogtreecommitdiff
path: root/pkcspad.cpp
diff options
context:
space:
mode:
authorweidai <weidai11@users.noreply.github.com>2003-03-20 01:24:12 +0000
committerweidai <weidai11@users.noreply.github.com>2003-03-20 01:24:12 +0000
commit538de80a91da74598ba2449fbbec6de37376a4ce (patch)
treef85b3bed971083e90e5f3dbb84539ea4ba0359e9 /pkcspad.cpp
parent21955e23ec9697d1cd47ff91f91b08af382b8a6d (diff)
downloadcryptopp-git-538de80a91da74598ba2449fbbec6de37376a4ce.tar.gz
various changes for 5.1
Diffstat (limited to 'pkcspad.cpp')
-rw-r--r--pkcspad.cpp75
1 files changed, 25 insertions, 50 deletions
diff --git a/pkcspad.cpp b/pkcspad.cpp
index e94a1fdf..e04ac9dd 100644
--- a/pkcspad.cpp
+++ b/pkcspad.cpp
@@ -18,6 +18,9 @@ template<> const unsigned int PKCS_DigestDecoration<MD5>::length = sizeof(PKCS_D
template<> const byte PKCS_DigestDecoration<RIPEMD160>::decoration[] = {0x30,0x21,0x30,0x09,0x06,0x05,0x2b,0x24,0x03,0x02,0x01,0x05,0x00,0x04,0x14};
template<> const unsigned int PKCS_DigestDecoration<RIPEMD160>::length = sizeof(PKCS_DigestDecoration<RIPEMD160>::decoration);
+template<> const byte PKCS_DigestDecoration<Tiger>::decoration[] = {0x30,0x29,0x30,0x0D,0x06,0x09,0x2B,0x06,0x01,0x04,0x01,0xDA,0x47,0x0C,0x02,0x05,0x00,0x04,0x18};
+template<> const unsigned int PKCS_DigestDecoration<Tiger>::length = sizeof(PKCS_DigestDecoration<Tiger>::decoration);
+
template<> const byte PKCS_DigestDecoration<SHA256>::decoration[] = {0x30,0x31,0x30,0x0d,0x06,0x09,0x60,0x86,0x48,0x01,0x65,0x03,0x04,0x02,0x01,0x05,0x00,0x04,0x20};
template<> const unsigned int PKCS_DigestDecoration<SHA256>::length = sizeof(PKCS_DigestDecoration<SHA256>::decoration);
@@ -27,11 +30,9 @@ template<> const unsigned int PKCS_DigestDecoration<SHA384>::length = sizeof(PKC
template<> const byte PKCS_DigestDecoration<SHA512>::decoration[] = {0x30,0x51,0x30,0x0d,0x06,0x09,0x60,0x86,0x48,0x01,0x65,0x03,0x04,0x02,0x03,0x05,0x00,0x04,0x40};
template<> const unsigned int PKCS_DigestDecoration<SHA512>::length = sizeof(PKCS_DigestDecoration<SHA512>::decoration);
-
-
unsigned int PKCS_EncryptionPaddingScheme::MaxUnpaddedLength(unsigned int paddedLength) const
{
- return paddedLength/8 > 10 ? paddedLength/8-10 : 0;
+ return SaturatingSubtract(paddedLength/8, 10U);
}
void PKCS_EncryptionPaddingScheme::Pad(RandomNumberGenerator &rng, const byte *input, unsigned int inputLen, byte *pkcsBlock, unsigned int pkcsBlockLen) const
@@ -72,7 +73,7 @@ DecodingResult PKCS_EncryptionPaddingScheme::Unpad(const byte *pkcsBlock, unsign
// Require block type 2.
invalid = (pkcsBlock[0] != 2) || invalid;
- // skip past the padding until we find the seperator
+ // skip past the padding until we find the separator
unsigned i=1;
while (i<pkcsBlockLen && pkcsBlock[i++]) { // null body
}
@@ -90,62 +91,36 @@ DecodingResult PKCS_EncryptionPaddingScheme::Unpad(const byte *pkcsBlock, unsign
// ********************************************************
-unsigned int PKCS_SignaturePaddingScheme::MaxUnpaddedLength(unsigned int paddedLength) const
-{
- return paddedLength/8 > 10 ? paddedLength/8-10 : 0;
-}
-
-void PKCS_SignaturePaddingScheme::Pad(RandomNumberGenerator &, const byte *input, unsigned int inputLen, byte *pkcsBlock, unsigned int pkcsBlockLen) const
-{
- assert (inputLen <= MaxUnpaddedLength(pkcsBlockLen)); // this should be checked by caller
-
- // convert from bit length to byte length
- if (pkcsBlockLen % 8 != 0)
- {
- pkcsBlock[0] = 0;
- pkcsBlock++;
- }
- pkcsBlockLen /= 8;
-
- pkcsBlock[0] = 1; // block type 1
-
- // padd with 0xff
- memset(pkcsBlock+1, 0xff, pkcsBlockLen-inputLen-2);
-
- pkcsBlock[pkcsBlockLen-inputLen-1] = 0; // separator
- memcpy(pkcsBlock+pkcsBlockLen-inputLen, input, inputLen);
-}
-
-DecodingResult PKCS_SignaturePaddingScheme::Unpad(const byte *pkcsBlock, unsigned int pkcsBlockLen, byte *output) const
+void PKCS1v15_SignatureMessageEncodingMethod::ComputeMessageRepresentative(RandomNumberGenerator &rng,
+ const byte *recoverableMessage, unsigned int recoverableMessageLength,
+ HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty,
+ byte *representative, unsigned int representativeBitLength) const
{
- unsigned int maxOutputLen = MaxUnpaddedLength(pkcsBlockLen);
+ unsigned int digestSize = hash.DigestSize();
+ if (digestSize + hashIdentifier.second + 10 > representativeBitLength/8)
+ throw PK_Signer::KeyTooShort();
+ unsigned int pkcsBlockLen = representativeBitLength;
// convert from bit length to byte length
if (pkcsBlockLen % 8 != 0)
{
- if (pkcsBlock[0] != 0)
- return DecodingResult();
- pkcsBlock++;
+ representative[0] = 0;
+ representative++;
}
pkcsBlockLen /= 8;
- // Require block type 1.
- if (pkcsBlock[0] != 1)
- return DecodingResult();
-
- // skip past the padding until we find the seperator
- unsigned i=1;
- while (i<pkcsBlockLen && pkcsBlock[i++])
- if (pkcsBlock[i-1] != 0xff) // not valid padding
- return DecodingResult();
- assert(i==pkcsBlockLen || pkcsBlock[i-1]==0);
+ representative[0] = 1; // block type 1
- unsigned int outputLen = pkcsBlockLen - i;
- if (outputLen > maxOutputLen)
- return DecodingResult();
+ byte *pPadding = representative + 1;
+ byte *pDigest = representative + pkcsBlockLen - digestSize;
+ byte *pHashId = pDigest - hashIdentifier.second;
+ byte *pSeparator = pHashId - 1;
- memcpy (output, pkcsBlock+i, outputLen);
- return DecodingResult(outputLen);
+ // pad with 0xff
+ memset(pPadding, 0xff, pSeparator-pPadding);
+ *pSeparator = 0;
+ memcpy(pHashId, hashIdentifier.first, hashIdentifier.second);
+ hash.Final(pDigest);
}
NAMESPACE_END