{
size_t clen = ciphertext_length;
+ if (!instance->cipher)
+ return 0;
+
if (nonce_length < 1 || assoc_length < 0 ||
plaintext_length < 0 || ciphertext_length < 0)
return 0;
{
size_t plen = plaintext_length;
+ if (!instance->cipher)
+ return 0;
+
if (nonce_length < 1 || assoc_length < 0 ||
plaintext_length < 0 || ciphertext_length < 0)
return 0;
struct SIV_Instance_Record {
struct siv_cmac_aes128_ctx siv;
+ int key_set;
};
/* ================================================== */
return NULL;
instance = MallocNew(struct SIV_Instance_Record);
+ instance->key_set = 0;
return instance;
}
siv_cmac_aes128_set_key(&instance->siv, key);
+ instance->key_set = 1;
+
return 1;
}
const void *plaintext, int plaintext_length,
unsigned char *ciphertext, int ciphertext_length)
{
+ if (!instance->key_set)
+ return 0;
+
if (nonce_length < SIV_MIN_NONCE_SIZE || assoc_length < 0 ||
plaintext_length < 0 || plaintext_length > ciphertext_length ||
plaintext_length + SIV_DIGEST_SIZE != ciphertext_length)
const unsigned char *ciphertext, int ciphertext_length,
void *plaintext, int plaintext_length)
{
+ if (!instance->key_set)
+ return 0;
+
if (nonce_length < SIV_MIN_NONCE_SIZE || assoc_length < 0 ||
plaintext_length < 0 || plaintext_length > ciphertext_length ||
plaintext_length + SIV_DIGEST_SIZE != ciphertext_length)
TEST_CHECK(SIV_GetKeyLength(tests[i].algorithm) == tests[i].key_length);
+ r = SIV_Encrypt(siv, tests[i].nonce, tests[i].nonce_length,
+ tests[i].assoc, tests[i].assoc_length,
+ tests[i].plaintext, tests[i].plaintext_length,
+ ciphertext, tests[i].ciphertext_length);
+ TEST_CHECK(!r);
+ r = SIV_Decrypt(siv, tests[i].nonce, tests[i].nonce_length,
+ tests[i].assoc, tests[i].assoc_length,
+ tests[i].ciphertext, tests[i].ciphertext_length,
+ plaintext, tests[i].plaintext_length);
+ TEST_CHECK(!r);
+
for (j = -1; j < 1024; j++) {
r = SIV_SetKey(siv, tests[i].key, j);
TEST_CHECK(r == (j == tests[i].key_length));