switch to libsodium implementation of aegis256

This commit is contained in:
2020-06-09 20:59:55 +02:00
parent 0183b35acf
commit e4988b9e9c
2 changed files with 7 additions and 7 deletions

13
mud.c
View File

@@ -22,7 +22,6 @@
#include <netinet/in.h> #include <netinet/in.h>
#include <sodium.h> #include <sodium.h>
#include "aegis256/aegis256.h"
#if !defined MSG_CONFIRM #if !defined MSG_CONFIRM
#define MSG_CONFIRM 0 #define MSG_CONFIRM 0
@@ -168,18 +167,19 @@ mud_encrypt_opt(const struct mud_crypto_key *k,
const struct mud_crypto_opt *c) const struct mud_crypto_opt *c)
{ {
if (k->aes) { if (k->aes) {
unsigned char npub[AEGIS256_NPUBBYTES]; unsigned char npub[crypto_aead_aegis256_NPUBBYTES];
memcpy(npub, c->dst, MUD_TIME_SIZE); memcpy(npub, c->dst, MUD_TIME_SIZE);
memset(npub + MUD_TIME_SIZE, 0, sizeof(npub) - MUD_TIME_SIZE); memset(npub + MUD_TIME_SIZE, 0, sizeof(npub) - MUD_TIME_SIZE);
return aegis256_encrypt( return crypto_aead_aegis256_encrypt(
c->dst + MUD_TIME_SIZE, c->dst + MUD_TIME_SIZE,
NULL, NULL,
c->src, c->src,
c->size, c->size,
c->dst, c->dst,
MUD_TIME_SIZE, MUD_TIME_SIZE,
NULL, // nsec
npub, npub,
k->encrypt.key k->encrypt.key
); );
@@ -208,14 +208,15 @@ mud_decrypt_opt(const struct mud_crypto_key *k,
const struct mud_crypto_opt *c) const struct mud_crypto_opt *c)
{ {
if (k->aes) { if (k->aes) {
unsigned char npub[AEGIS256_NPUBBYTES]; unsigned char npub[crypto_aead_aegis256_NPUBBYTES];
memcpy(npub, c->src, MUD_TIME_SIZE); memcpy(npub, c->src, MUD_TIME_SIZE);
memset(npub + MUD_TIME_SIZE, 0, sizeof(npub) - MUD_TIME_SIZE); memset(npub + MUD_TIME_SIZE, 0, sizeof(npub) - MUD_TIME_SIZE);
return aegis256_decrypt( return crypto_aead_aegis256_decrypt(
c->dst, c->dst,
NULL, NULL,
NULL, // nsec
c->src + MUD_TIME_SIZE, c->src + MUD_TIME_SIZE,
c->size - MUD_TIME_SIZE, c->size - MUD_TIME_SIZE,
c->src, MUD_TIME_SIZE, c->src, MUD_TIME_SIZE,
@@ -832,7 +833,7 @@ mud_keyx_init(struct mud *mud, uint64_t now)
int int
mud_set_aes(struct mud *mud) mud_set_aes(struct mud *mud)
{ {
if (!aegis256_is_available()) { if (!crypto_aead_aegis256_is_available()) {
errno = ENOTSUP; errno = ENOTSUP;
return -1; return -1;
} }

1
test.c
View File

@@ -1,5 +1,4 @@
#include "mud.c" #include "mud.c"
#include "aegis256/aegis256.c"
#include <stdio.h> #include <stdio.h>
#include <poll.h> #include <poll.h>