]> git.codecow.com Git - Monocypher.git/commitdiff
detached interface for authenticated encryption
authorLoup Vaillant <loup@loup-vaillant.fr>
Sat, 29 Apr 2017 16:00:16 +0000 (18:00 +0200)
committerLoup Vaillant <loup@loup-vaillant.fr>
Sat, 29 Apr 2017 16:00:16 +0000 (18:00 +0200)
src/monocypher.c
src/monocypher.h
tests/test.c

index bcd37cf9fcfcc350a6f98e32a40c463c4a964ab2..04f44dfb9874027afc6514013be186467bbadaa7 100644 (file)
@@ -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);
 }
index e5a8f10e4eae569cb2789a015358f021fbd14657..cd17d1b89264a01fb8f6a871379b0016119d1d5b 100644 (file)
@@ -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
index 50969ba0b9da36b1f1434c3e57056e733e4a13b6..b28cb3f87ac5576e41f76eb7bb7f300b3a0100bb 100644 (file)
@@ -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