summaryrefslogtreecommitdiffstats
path: root/CryptoPP/emsa2.cpp
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-08-30 23:06:13 +0200
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-08-30 23:06:13 +0200
commit539364846a89987ac2679988653f50332cb91d26 (patch)
treef1695473c1f493a19c5fbdb70f7f1faccf99d7f3 /CryptoPP/emsa2.cpp
parentUpdated to V6 - "Stop" and "Progress report" functionality (diff)
downloadcuberite-539364846a89987ac2679988653f50332cb91d26.tar
cuberite-539364846a89987ac2679988653f50332cb91d26.tar.gz
cuberite-539364846a89987ac2679988653f50332cb91d26.tar.bz2
cuberite-539364846a89987ac2679988653f50332cb91d26.tar.lz
cuberite-539364846a89987ac2679988653f50332cb91d26.tar.xz
cuberite-539364846a89987ac2679988653f50332cb91d26.tar.zst
cuberite-539364846a89987ac2679988653f50332cb91d26.zip
Diffstat (limited to 'CryptoPP/emsa2.cpp')
-rw-r--r--CryptoPP/emsa2.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/CryptoPP/emsa2.cpp b/CryptoPP/emsa2.cpp
new file mode 100644
index 000000000..3dbb7e8c0
--- /dev/null
+++ b/CryptoPP/emsa2.cpp
@@ -0,0 +1,34 @@
+// emsa2.cpp - written and placed in the public domain by Wei Dai
+
+#include "pch.h"
+#include "emsa2.h"
+
+#ifndef CRYPTOPP_IMPORTS
+
+NAMESPACE_BEGIN(CryptoPP)
+
+void EMSA2Pad::ComputeMessageRepresentative(RandomNumberGenerator &rng,
+ const byte *recoverableMessage, size_t recoverableMessageLength,
+ HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty,
+ byte *representative, size_t representativeBitLength) const
+{
+ assert(representativeBitLength >= MinRepresentativeBitLength(hashIdentifier.second, hash.DigestSize()));
+
+ if (representativeBitLength % 8 != 7)
+ throw PK_SignatureScheme::InvalidKeyLength("EMSA2: EMSA2 requires a key length that is a multiple of 8");
+
+ size_t digestSize = hash.DigestSize();
+ size_t representativeByteLength = BitsToBytes(representativeBitLength);
+
+ representative[0] = messageEmpty ? 0x4b : 0x6b;
+ memset(representative+1, 0xbb, representativeByteLength-digestSize-4); // pad with 0xbb
+ byte *afterP2 = representative+representativeByteLength-digestSize-3;
+ afterP2[0] = 0xba;
+ hash.Final(afterP2+1);
+ representative[representativeByteLength-2] = *hashIdentifier.first;
+ representative[representativeByteLength-1] = 0xcc;
+}
+
+NAMESPACE_END
+
+#endif