MCPcopy Create free account
hub / github.com/ReversecLabs/C3 / EncryptAndAuthenticate

Method EncryptAndAuthenticate

Src/Common/FSecure/Crypto/Sodium.cpp:101–112  ·  view source on GitHub ↗

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

99
100////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
101FSecure::ByteVector FSecure::Crypto::Sodium::EncryptAndAuthenticate(ByteView plaintext, PublicKey const& theirPublicKey, PrivateKey const& myPrivateKey)
102{
103 Nonce<false> nonce;
104 ByteVector encryptedMessage(plaintext.size() + crypto_box_MACBYTES + Nonce<false>::Size);
105
106 // Perpend ciphertext with nonce.
107 memcpy(encryptedMessage.data(), nonce, Nonce<false>::Size);
108 if (crypto_box_easy(encryptedMessage.data() + Nonce<false>::Size, plaintext.data(), plaintext.size(), nonce, theirPublicKey.data(), myPrivateKey.data()))
109 throw std::runtime_error{ OBF("Encryption failed.") };
110
111 return encryptedMessage;
112}
113
114////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
115FSecure::ByteVector FSecure::Crypto::Sodium::DecryptAndAuthenticate(ByteView message, PublicKey const& theirPublicKey, PrivateKey const& myPrivateKey)

Callers

nothing calls this directly

Calls 2

sizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected