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

Method DecryptAndAuthenticate

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

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

Source from the content-addressed store, hash-verified

113
114////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
115FSecure::ByteVector FSecure::Crypto::Sodium::DecryptAndAuthenticate(ByteView message, PublicKey const& theirPublicKey, PrivateKey const& myPrivateKey)
116{
117 // Sanity check.
118 if (message.size() < Nonce<false>::Size + crypto_box_MACBYTES)
119 throw std::invalid_argument{ OBF("Ciphertext too short.") };
120
121 // Retrieve nonce.
122 auto nonce = message.SubString(0, Nonce<false>::Size), ciphertext = message.SubString(Nonce<false>::Size);
123
124 // Decrypt.
125 ByteVector decryptedMessage(ciphertext.size() - crypto_box_MACBYTES);
126 if (crypto_box_open_easy(decryptedMessage.data(), ciphertext.data(), ciphertext.size(), nonce.data(), theirPublicKey.data(), myPrivateKey.data()))
127 throw std::runtime_error{ OBF("Message forged.") };
128
129 return decryptedMessage;
130}
131
132////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
133FSecure::ByteVector FSecure::Crypto::Sodium::SignMessage(ByteView message, PrivateSignature const& signature)

Callers

nothing calls this directly

Calls 3

SubStringMethod · 0.80
sizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected