///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
| 113 | |
| 114 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 115 | FSecure::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 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 133 | FSecure::ByteVector FSecure::Crypto::Sodium::SignMessage(ByteView message, PrivateSignature const& signature) |