Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3394096
D6821.id23261.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D6821.id23261.diff
View Options
diff --git a/native/cpp/CommonCpp/CryptoTools/CryptoModule.h b/native/cpp/CommonCpp/CryptoTools/CryptoModule.h
--- a/native/cpp/CommonCpp/CryptoTools/CryptoModule.h
+++ b/native/cpp/CommonCpp/CryptoTools/CryptoModule.h
@@ -66,6 +66,12 @@
const std::string &targetUserId,
EncryptedData encryptedData,
const OlmBuffer &theirIdentityKey);
+
+ std::string signMessage(const std::string &message);
+ static void verifySignature(
+ const std::string &publicKey,
+ const std::string &message,
+ const std::string &signature);
};
} // namespace crypto
diff --git a/native/cpp/CommonCpp/CryptoTools/CryptoModule.cpp b/native/cpp/CommonCpp/CryptoTools/CryptoModule.cpp
--- a/native/cpp/CommonCpp/CryptoTools/CryptoModule.cpp
+++ b/native/cpp/CommonCpp/CryptoTools/CryptoModule.cpp
@@ -302,5 +302,42 @@
return std::string{(char *)decryptedMessage.data(), decryptedSize};
}
+std::string CryptoModule::signMessage(const std::string &message) {
+ OlmBuffer signature;
+ signature.resize(::olm_account_signature_length(this->account));
+ size_t signatureLength = ::olm_account_sign(
+ this->account,
+ (uint8_t *)message.data(),
+ message.length(),
+ signature.data(),
+ signature.size());
+ if (signatureLength == -1) {
+ throw std::runtime_error{
+ "olm error: " + std::string{::olm_account_last_error(this->account)}};
+ }
+ return std::string{(char *)signature.data(), signatureLength};
+}
+
+void CryptoModule::verifySignature(
+ const std::string &publicKey,
+ const std::string &message,
+ const std::string &signature) {
+ OlmBuffer utilityBuffer;
+ utilityBuffer.resize(::olm_utility_size());
+ OlmUtility *olmUtility = ::olm_utility(utilityBuffer.data());
+ ssize_t verificationResult = ::olm_ed25519_verify(
+ olmUtility,
+ (uint8_t *)publicKey.data(),
+ publicKey.length(),
+ (uint8_t *)message.data(),
+ message.length(),
+ (uint8_t *)signature.data(),
+ signature.length());
+ if (verificationResult == -1) {
+ throw std::runtime_error{
+ "olm error: " + std::string{::olm_utility_last_error(olmUtility)}};
+ }
+}
+
} // namespace crypto
} // namespace comm
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Dec 1, 5:27 PM (20 h, 51 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2605498
Default Alt Text
D6821.id23261.diff (2 KB)
Attached To
Mode
D6821: Implement method to sign message
Attached
Detach File
Event Timeline
Log In to Comment