From: Loup Vaillant Date: Sat, 29 Apr 2017 16:00:16 +0000 (+0200) Subject: detached interface for authenticated encryption X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=7d55e7c2a9edc35f2b8699146be218c4e221fa7d;p=Monocypher.git detached interface for authenticated encryption --- diff --git a/src/monocypher.c b/src/monocypher.c index bcd37cf..04f44df 100644 --- a/src/monocypher.c +++ b/src/monocypher.c @@ -1346,20 +1346,21 @@ int crypto_aead_unlock(u8 *plaintext, return 0; } -void crypto_lock(u8 *box, +void crypto_lock(u8 mac[16], + u8 *ciphertext, const u8 key[32], const u8 nonce[24], - const u8 *plaintext, - size_t text_size) + const u8 *plaintext, size_t text_size) { - crypto_aead_lock(box, box + 16, key, nonce, 0, 0, plaintext, text_size); + crypto_aead_lock(mac, ciphertext, key, nonce, 0, 0, plaintext, text_size); } int crypto_unlock(u8 *plaintext, const u8 key[32], const u8 nonce[24], - const u8 *box, size_t box_size) + const u8 mac[16], + const u8 *ciphertext, size_t text_size) { - return crypto_aead_unlock(plaintext, key, nonce, box, 0, 0, - box + 16, box_size -16); + return crypto_aead_unlock(plaintext, key, nonce, mac, 0, 0, + ciphertext, text_size); } diff --git a/src/monocypher.h b/src/monocypher.h index e5a8f10..cd17d1b 100644 --- a/src/monocypher.h +++ b/src/monocypher.h @@ -151,16 +151,16 @@ int crypto_aead_unlock(uint8_t *plaintext, const uint8_t *ad , size_t ad_size, const uint8_t *ciphertext, size_t text_size); -void crypto_lock(uint8_t *box, // text_size + 16 +void crypto_lock(uint8_t mac[16], + uint8_t *ciphertext, const uint8_t key[32], const uint8_t nonce[24], - const uint8_t *plaintext, - size_t text_size); + const uint8_t *plaintext, size_t text_size); -int crypto_unlock(uint8_t *plaintext, // box_size - 16 +int crypto_unlock(uint8_t *plaintext, const uint8_t key[32], const uint8_t nonce[24], - const uint8_t *box, - size_t box_size); + const uint8_t mac[16], + const uint8_t *ciphertext, size_t text_size); #endif // MONOCYPHER_H diff --git a/tests/test.c b/tests/test.c index 50969ba..b28cb3f 100644 --- a/tests/test.c +++ b/tests/test.c @@ -414,11 +414,11 @@ static int test_aead() printf("%s: aead (detached)\n", status != 0 ? "FAILED" : "OK"); // Authenticated roundtrip (easy interface) - crypto_lock(box, key, nonce, plaintext, 8); // make true message - status |= crypto_unlock(out, key, nonce, box, 8+16); // accept true message - status |= crypto_memcmp(plaintext, out, 8); // roundtrip - box[0]++; // make forgery - status |= !crypto_unlock(out, key, nonce, box, 8+16); // reject forgery + crypto_lock(box, box + 16, key, nonce, plaintext, 8); // make message + status |= crypto_unlock(out, key, nonce, box, box + 16, 8); // accept message + status |= crypto_memcmp(plaintext, out, 8); // roundtrip + box[0]++; // make forgery + status |= !crypto_unlock(out, key, nonce, box, box + 16, 8);// reject forgery printf("%s: aead (simplified)\n", status != 0 ? "FAILED" : "OK"); box[0]--; // undo forgery