///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
| 99 | |
| 100 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 101 | FSecure::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 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 115 | FSecure::ByteVector FSecure::Crypto::Sodium::DecryptAndAuthenticate(ByteView message, PublicKey const& theirPublicKey, PrivateKey const& myPrivateKey) |