summaryrefslogtreecommitdiff
path: root/gfpcrypt.cpp
diff options
context:
space:
mode:
authorweidai <weidai@57ff6487-cd31-0410-9ec3-f628ee90f5f0>2003-03-20 01:24:12 +0000
committerweidai <weidai@57ff6487-cd31-0410-9ec3-f628ee90f5f0>2003-03-20 01:24:12 +0000
commitd23a489940499bd6c634a1cb0a9875f094f8a850 (patch)
treef85b3bed971083e90e5f3dbb84539ea4ba0359e9 /gfpcrypt.cpp
parentb3517523a738277cfe22428bd757833e69abb66e (diff)
downloadcryptopp-d23a489940499bd6c634a1cb0a9875f094f8a850.tar.gz
various changes for 5.1
git-svn-id: svn://svn.code.sf.net/p/cryptopp/code/trunk/c5@38 57ff6487-cd31-0410-9ec3-f628ee90f5f0
Diffstat (limited to 'gfpcrypt.cpp')
-rw-r--r--gfpcrypt.cpp50
1 files changed, 34 insertions, 16 deletions
diff --git a/gfpcrypt.cpp b/gfpcrypt.cpp
index 8d8b0bf..c27a967 100644
--- a/gfpcrypt.cpp
+++ b/gfpcrypt.cpp
@@ -63,30 +63,48 @@ bool DL_GroupParameters_DSA::ValidateGroup(RandomNumberGenerator &rng, unsigned
return pass;
}
-Integer NR_EncodeDigest(unsigned int modulusBits, const byte *digest, unsigned int digestLen)
+void DL_SignatureMessageEncodingMethod_DSA::ComputeMessageRepresentative(RandomNumberGenerator &rng,
+ const byte *recoverableMessage, unsigned int recoverableMessageLength,
+ HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty,
+ byte *representative, unsigned int representativeBitLength) const
{
- Integer h;
- if (digestLen*8 < modulusBits)
- h.Decode(digest, digestLen);
- else
+ assert(recoverableMessageLength == 0);
+ assert(hashIdentifier.second == 0);
+ const unsigned int representativeByteLength = BitsToBytes(representativeBitLength);
+ const unsigned int digestSize = hash.DigestSize();
+ const unsigned int paddingLength = SaturatingSubtract(representativeByteLength, digestSize);
+
+ memset(representative, 0, paddingLength);
+ hash.TruncatedFinal(representative+paddingLength, STDMIN(representativeByteLength, digestSize));
+
+ if (digestSize*8 > representativeBitLength)
{
- h.Decode(digest, BitsToBytes(modulusBits));
- h >>= BitsToBytes(modulusBits)*8 - modulusBits + 1;
+ Integer h(representative, representativeByteLength);
+ h >>= representativeByteLength*8 - representativeBitLength;
+ h.Encode(representative, representativeByteLength);
}
- return h;
}
-Integer DSA_EncodeDigest(unsigned int modulusBits, const byte *digest, unsigned int digestLen)
+void DL_SignatureMessageEncodingMethod_NR::ComputeMessageRepresentative(RandomNumberGenerator &rng,
+ const byte *recoverableMessage, unsigned int recoverableMessageLength,
+ HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty,
+ byte *representative, unsigned int representativeBitLength) const
{
- Integer h;
- if (digestLen*8 <= modulusBits)
- h.Decode(digest, digestLen);
- else
+ assert(recoverableMessageLength == 0);
+ assert(hashIdentifier.second == 0);
+ const unsigned int representativeByteLength = BitsToBytes(representativeBitLength);
+ const unsigned int digestSize = hash.DigestSize();
+ const unsigned int paddingLength = SaturatingSubtract(representativeByteLength, digestSize);
+
+ memset(representative, 0, paddingLength);
+ hash.TruncatedFinal(representative+paddingLength, STDMIN(representativeByteLength, digestSize));
+
+ if (digestSize*8 >= representativeBitLength)
{
- h.Decode(digest, BitsToBytes(modulusBits));
- h >>= BitsToBytes(modulusBits)*8 - modulusBits;
+ Integer h(representative, representativeByteLength);
+ h >>= representativeByteLength*8 - representativeBitLength + 1;
+ h.Encode(representative, representativeByteLength);
}
- return h;
}
bool DL_GroupParameters_IntegerBased::ValidateGroup(RandomNumberGenerator &rng, unsigned int level) const