return mismatch;
}
-void crypto_lock_aead(u8 mac[16], u8 *cipher_text, const u8 key[32],
+void crypto_aead_lock(u8 *cipher_text, u8 mac[16], const u8 key[32],
const u8 nonce[24], const u8 *ad, size_t ad_size,
const u8 *plain_text, size_t text_size)
{
crypto_wipe(&ctx, sizeof(ctx));
}
-int crypto_unlock_aead(u8 *plain_text, const u8 key[32], const u8 nonce[24],
- const u8 mac[16], const u8 *ad, size_t ad_size,
+int crypto_aead_unlock(u8 *plain_text, const u8 mac[16], const u8 key[32],
+ const u8 nonce[24], const u8 *ad, size_t ad_size,
const u8 *cipher_text, size_t text_size)
{
crypto_aead_ctx ctx;
return mismatch;
}
-void crypto_lock(u8 mac[16], u8 *cipher_text, const u8 key[32],
- const u8 nonce[24], const u8 *plain_text, size_t text_size)
-{
- crypto_lock_aead(mac, cipher_text, key, nonce, 0, 0, plain_text, text_size);
-}
-
-int crypto_unlock(u8 *plain_text, const u8 key[32], const u8 nonce[24],
- const u8 mac[16], const u8 *cipher_text, size_t text_size)
-{
- return crypto_unlock_aead(plain_text, key, nonce, mac, 0, 0,
- cipher_text, text_size);
-}
-
#ifdef MONOCYPHER_CPP_NAMESPACE
}
#endif
// Authenticated encryption
// ------------------------
-void crypto_lock(uint8_t mac[16],
- uint8_t *cipher_text,
- const uint8_t key[32],
- const uint8_t nonce[24],
- const uint8_t *plain_text, size_t text_size);
-int crypto_unlock(uint8_t *plain_text,
- const uint8_t key[32],
- const uint8_t nonce[24],
- const uint8_t mac[16],
- const uint8_t *cipher_text, size_t text_size);
-
-// With additional data
-void crypto_lock_aead(uint8_t mac[16],
- uint8_t *cipher_text,
- const uint8_t key[32],
+void crypto_aead_lock(uint8_t *cipher_text,
+ uint8_t mac [16],
+ const uint8_t key [32],
const uint8_t nonce[24],
- const uint8_t *ad , size_t ad_size,
+ const uint8_t *ad, size_t ad_size,
const uint8_t *plain_text, size_t text_size);
-int crypto_unlock_aead(uint8_t *plain_text,
- const uint8_t key[32],
+int crypto_aead_unlock(uint8_t *plain_text,
+ const uint8_t mac [16],
+ const uint8_t key [32],
const uint8_t nonce[24],
- const uint8_t mac[16],
- const uint8_t *ad , size_t ad_size,
+ const uint8_t *ad, size_t ad_size,
const uint8_t *cipher_text, size_t text_size);
// Authenticated stream
RANDOM_INPUT(nonce, 24);
TIMING_START {
- crypto_lock(mac, out, key, nonce, in, SIZE);
+ crypto_aead_lock(mac, out, key, nonce, 0, 0, in, SIZE);
}
TIMING_END;
}
vector ad = next_input(reader);
vector text = next_input(reader);
vector out = next_output(reader);
- crypto_lock_aead(out.buf, out.buf + 16, key.buf, nonce.buf,
+ crypto_aead_lock(out.buf + 16, out.buf, key.buf, nonce.buf,
ad.buf, ad.size, text.buf, text.size);
}
RANDOM_INPUT(nonce , 24);
RANDOM_INPUT(ad , 4);
RANDOM_INPUT(plaintext, 8);
- u8 box[24], box2[24];
+ u8 box[24];
u8 out[8];
// AEAD roundtrip
- crypto_lock_aead(box, box+16, key, nonce, ad, 4, plaintext, 8);
- ASSERT_OK(crypto_unlock_aead(out, key, nonce, box, ad, 4, box+16, 8));
+ crypto_aead_lock(box+16, box, key, nonce, ad, 4, plaintext, 8);
+ ASSERT_OK(crypto_aead_unlock(out, box, key, nonce, ad, 4, box+16, 8));
ASSERT_EQUAL(plaintext, out, 8);
box[0]++;
- ASSERT_KO(crypto_unlock_aead(out, key, nonce, box, ad, 4, box+16, 8));
-
- // Authenticated roundtrip (easy interface)
- // Make and accept message
- crypto_lock(box, box + 16, key, nonce, plaintext, 8);
- ASSERT_OK(crypto_unlock(out, key, nonce, box, box + 16, 8));
- // Make sure decrypted text and original text are the same
- ASSERT_EQUAL(plaintext, out, 8);
- // Make and reject forgery
- box[0]++;
- ASSERT_KO(crypto_unlock(out, key, nonce, box, box + 16, 8));
- box[0]--; // undo forgery
-
- // Same result for both interfaces
- crypto_lock_aead(box2, box2 + 16, key, nonce, 0, 0, plaintext, 8);
- ASSERT_EQUAL(box, box2, 24);
+ ASSERT_KO(crypto_aead_unlock(out, box, key, nonce, ad, 4, box+16, 8));
}
printf("\taead incr (roundtrip)\n");
vector ad = next_input(reader);
vector text = next_input(reader);
vector out = next_output(reader);
- crypto_lock_aead(out.buf, out.buf + 16, key.buf, nonce.buf,
+ crypto_aead_lock(out.buf + 16, out.buf, key.buf, nonce.buf,
ad.buf, ad.size, text.buf, text.size);
}