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);
}
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
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