diff options
author | Michael Smith <mikesmiffy128@gmail.com> | 2023-07-29 14:32:06 +0100 |
---|---|---|
committer | Michael Smith <mikesmiffy128@gmail.com> | 2023-08-02 21:02:31 +0100 |
commit | 9a0d8730fa977f666b5c12e4c5901e7d0391e245 (patch) | |
tree | 87eebcdcef04ae1e7348ef80e972c08aa4783649 /src/crypto.c | |
parent | d337b09936ecd90bad07b28b48b7103395d97ce5 (diff) |
Make various preparations for upcoming features
A lot of this is random WIP from a while back, at least a month ago, and
is being committed now to get it out of the way so that other patches
can be brought in and integrated against it without causing headaches.
Also rolled into this commit is a way to distinguish plugin_unload from
exiting the game. This is required for another soon-to-be-integrated
feature to avoid crashing on exit, and could in theory also be used to
speed up unloading on exit in future. While we're at it, this also
avoids the need to linearly scan through the plugin list to do the
old branch unloading fix, because we can.
Rough summary of the other smaller stuff I can remember doing:
- Rework bitbuf a bit
- Add some cryptographic nonsense in ac.c (not final at all)
- Introduce the first couple of "chunklets" libraries as a sort-of
subproject of this one
- Tidy up random small bits and bobs
- Add source for a small keypair generation tool
- Rework democustom to be very marginally more useful
Diffstat (limited to 'src/crypto.c')
-rw-r--r-- | src/crypto.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/crypto.c b/src/crypto.c index f7ccd78..6d0f2aa 100644 --- a/src/crypto.c +++ b/src/crypto.c @@ -3,4 +3,28 @@ #include "3p/monocypher/monocypher.c" #include "3p/monocypher/monocypher-rng.c" +// -- SST-specific extensions to 4.0.1 API below -- +void crypto_aead_lock_djb(u8 *cipher_text, u8 mac[16], const u8 key[32], + const u8 nonce[8], const u8 *ad, size_t ad_size, + const u8 *plain_text, size_t text_size) +{ + crypto_aead_ctx ctx; + crypto_aead_init_djb(&ctx, key, nonce); + crypto_aead_write(&ctx, cipher_text, mac, ad, ad_size, + plain_text, text_size); + crypto_wipe(&ctx, sizeof(ctx)); +} + +int crypto_aead_unlock_djb(u8 *plain_text, const u8 mac[16], const u8 key[32], + const u8 nonce[8], const u8 *ad, size_t ad_size, + const u8 *cipher_text, size_t text_size) +{ + crypto_aead_ctx ctx; + crypto_aead_init_djb(&ctx, key, nonce); + int mismatch = crypto_aead_read(&ctx, plain_text, mac, ad, ad_size, + cipher_text, text_size); + crypto_wipe(&ctx, sizeof(ctx)); + return mismatch; +} + // vi: sw=4 ts=4 noet tw=80 cc=80 |