aboutsummaryrefslogtreecommitdiff
path: root/src/Signature.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Signature.cpp')
-rw-r--r--src/Signature.cpp19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/Signature.cpp b/src/Signature.cpp
index 946d754..8d3654d 100644
--- a/src/Signature.cpp
+++ b/src/Signature.cpp
@@ -35,6 +35,19 @@ namespace odhtdb
return *this;
}
+ string PublicKey::unsign(const DataView &signedMessage) const
+ {
+ if(signedMessage.size < SIGNED_HASH_SIZE)
+ throw UnsignInvalidSizeException("Signed message is too small (corrupt or malicious signed message)");
+
+ string result;
+ result.resize(signedMessage.size - SIGNED_HASH_SIZE);
+ if(crypto_sign_ed25519_open((unsigned char*)&result[0], nullptr, (const unsigned char*)signedMessage.data, signedMessage.size, (unsigned char*)data) != 0)
+ throw UnsignWrongKeyException("Message was not signed with matching private key");
+
+ return result;
+ }
+
string PublicKey::toString() const
{
string result;
@@ -67,13 +80,13 @@ namespace odhtdb
return *this;
}
- string PrivateKey::sign(const string &dataToSign) const
+ string PrivateKey::sign(const DataView &dataToSign) const
{
string result;
- result.resize(crypto_sign_ed25519_BYTES + dataToSign.size());
+ result.resize(crypto_sign_ed25519_BYTES + dataToSign.size);
unsigned long long resultSize;
- if(crypto_sign_ed25519((unsigned char*)&result[0], &resultSize, (unsigned char*)dataToSign.data(), dataToSign.size(), (unsigned char*)data) != 0)
+ if(crypto_sign_ed25519((unsigned char*)&result[0], &resultSize, (unsigned char*)dataToSign.data, dataToSign.size, (unsigned char*)data) != 0)
throw DataSignException("Failed to sign data. Is private key invalid?");
if(resultSize != result.size())