-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lib/sodium/SecretBox: wrappers for crypto_secretbox_*()
- Loading branch information
1 parent
1048d67
commit 842b90c
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// SPDX-License-Identifier: BSD-2-Clause | ||
// Copyright CM4all GmbH | ||
// author: Max Kellermann <[email protected]> | ||
|
||
#pragma once | ||
|
||
#include <sodium/crypto_secretbox.h> | ||
|
||
static inline void | ||
crypto_secretbox_easy(std::byte *ciphertext, | ||
std::span<const std::byte> message, | ||
std::span<const std::byte, crypto_secretbox_NONCEBYTES> nonce, | ||
std::span<const std::byte, crypto_secretbox_KEYBYTES> key) noexcept | ||
{ | ||
crypto_secretbox_easy(reinterpret_cast<unsigned char *>(ciphertext), | ||
reinterpret_cast<const unsigned char *>(message.data()), | ||
message.size(), | ||
reinterpret_cast<const unsigned char *>(nonce.data()), | ||
reinterpret_cast<const unsigned char *>(key.data())); | ||
} | ||
|
||
static inline bool | ||
crypto_secretbox_open_easy(std::byte *message, | ||
std::span<const std::byte> ciphertext, | ||
std::span<const std::byte, crypto_secretbox_NONCEBYTES> nonce, | ||
std::span<const std::byte, crypto_secretbox_KEYBYTES> key) noexcept | ||
{ | ||
return crypto_secretbox_open_easy(reinterpret_cast<unsigned char *>(message), | ||
reinterpret_cast<const unsigned char *>(ciphertext.data()), | ||
ciphertext.size(), | ||
reinterpret_cast<const unsigned char *>(nonce.data()), | ||
reinterpret_cast<const unsigned char *>(key.data())) == 0; | ||
} |