-/* $OpenBSD: gmac.c,v 1.9 2016/09/19 18:09:40 tedu Exp $ */
+/* $OpenBSD: gmac.c,v 1.10 2017/05/02 11:44:32 mikeb Exp $ */
/*
* Copyright (c) 2010 Mike Belopuhov
#include <sys/param.h>
#include <sys/systm.h>
-#include <crypto/rijndael.h>
+#include <crypto/aes.h>
#include <crypto/gmac.h>
void ghash_gfmul(uint32_t *, uint32_t *, uint32_t *);
{
AES_GMAC_CTX *ctx = xctx;
- ctx->rounds = rijndaelKeySetupEnc(ctx->K, (u_char *)key,
- (klen - AESCTR_NONCESIZE) * 8);
+ AES_Setkey(&ctx->K, key, klen - AESCTR_NONCESIZE);
/* copy out salt to the counter block */
bcopy(key + klen - AESCTR_NONCESIZE, ctx->J, AESCTR_NONCESIZE);
/* prepare a hash subkey */
- rijndaelEncrypt(ctx->K, ctx->rounds, ctx->ghash.H, ctx->ghash.H);
+ AES_Encrypt(&ctx->K, ctx->ghash.H, ctx->ghash.H);
}
void
/* do one round of GCTR */
ctx->J[GMAC_BLOCK_LEN - 1] = 1;
- rijndaelEncrypt(ctx->K, ctx->rounds, ctx->J, keystream);
+ AES_Encrypt(&ctx->K, ctx->J, keystream);
for (i = 0; i < GMAC_DIGEST_LEN; i++)
digest[i] = ctx->ghash.S[i] ^ keystream[i];
explicit_bzero(keystream, sizeof(keystream));
-/* $OpenBSD: xform.c,v 1.55 2016/09/19 18:09:40 tedu Exp $ */
+/* $OpenBSD: xform.c,v 1.56 2017/05/02 11:44:32 mikeb Exp $ */
/*
* The authors of this code are John Ioannidis (ji@tla.org),
* Angelos D. Keromytis (kermit@csd.uch.gr),
#include <crypto/rmd160.h>
#include <crypto/blf.h>
#include <crypto/cast.h>
-#include <crypto/rijndael.h>
+#include <crypto/aes.h>
#include <crypto/cryptodev.h>
#include <crypto/xform.h>
#include <crypto/gmac.h>
int des3_setkey(void *, u_int8_t *, int);
int blf_setkey(void *, u_int8_t *, int);
int cast5_setkey(void *, u_int8_t *, int);
-int rijndael128_setkey(void *, u_int8_t *, int);
+int aes_setkey(void *, u_int8_t *, int);
int aes_ctr_setkey(void *, u_int8_t *, int);
int aes_xts_setkey(void *, u_int8_t *, int);
int null_setkey(void *, u_int8_t *, int);
void des3_encrypt(caddr_t, u_int8_t *);
void blf_encrypt(caddr_t, u_int8_t *);
void cast5_encrypt(caddr_t, u_int8_t *);
-void rijndael128_encrypt(caddr_t, u_int8_t *);
+void aes_encrypt(caddr_t, u_int8_t *);
void null_encrypt(caddr_t, u_int8_t *);
void aes_xts_encrypt(caddr_t, u_int8_t *);
void des3_decrypt(caddr_t, u_int8_t *);
void blf_decrypt(caddr_t, u_int8_t *);
void cast5_decrypt(caddr_t, u_int8_t *);
-void rijndael128_decrypt(caddr_t, u_int8_t *);
+void aes_decrypt(caddr_t, u_int8_t *);
void null_decrypt(caddr_t, u_int8_t *);
void aes_xts_decrypt(caddr_t, u_int8_t *);
#define AESCTR_BLOCKSIZE 16
struct aes_ctr_ctx {
- u_int32_t ac_ek[4*(AES_MAXROUNDS + 1)];
+ AES_CTX ac_key;
u_int8_t ac_block[AESCTR_BLOCKSIZE];
- int ac_nr;
};
#define AES_XTS_BLOCKSIZE 16
#define AES_XTS_ALPHA 0x87 /* GF(2^128) generator polynomial */
struct aes_xts_ctx {
- rijndael_ctx key1;
- rijndael_ctx key2;
+ AES_CTX key1;
+ AES_CTX key2;
u_int8_t tweak[AES_XTS_BLOCKSIZE];
};
NULL
};
-struct enc_xform enc_xform_rijndael128 = {
- CRYPTO_RIJNDAEL128_CBC, "Rijndael-128/AES",
+struct enc_xform enc_xform_aes = {
+ CRYPTO_AES_CBC, "AES",
16, 16, 16, 32,
- sizeof(rijndael_ctx),
- rijndael128_encrypt,
- rijndael128_decrypt,
- rijndael128_setkey,
+ sizeof(AES_CTX),
+ aes_encrypt,
+ aes_decrypt,
+ aes_setkey,
NULL
};
}
void
-rijndael128_encrypt(caddr_t key, u_int8_t *blk)
+aes_encrypt(caddr_t key, u_int8_t *blk)
{
- rijndael_encrypt((rijndael_ctx *) key, (u_char *) blk, (u_char *) blk);
+ AES_Encrypt((AES_CTX *)key, blk, blk);
}
void
-rijndael128_decrypt(caddr_t key, u_int8_t *blk)
+aes_decrypt(caddr_t key, u_int8_t *blk)
{
- rijndael_decrypt((rijndael_ctx *) key, (u_char *) blk, (u_char *) blk);
+ AES_Decrypt((AES_CTX *)key, blk, blk);
}
int
-rijndael128_setkey(void *sched, u_int8_t *key, int len)
+aes_setkey(void *sched, u_int8_t *key, int len)
{
- return rijndael_set_key((rijndael_ctx *)sched, (u_char *)key, len * 8);
+ return AES_Setkey((AES_CTX *)sched, key, len);
}
void
i >= AESCTR_NONCESIZE + AESCTR_IVSIZE; i--)
if (++ctx->ac_block[i]) /* continue on overflow */
break;
- rijndaelEncrypt(ctx->ac_ek, ctx->ac_nr, ctx->ac_block, keystream);
+ AES_Encrypt(&ctx->ac_key, ctx->ac_block, keystream);
for (i = 0; i < AESCTR_BLOCKSIZE; i++)
data[i] ^= keystream[i];
explicit_bzero(keystream, sizeof(keystream));
return -1;
ctx = (struct aes_ctr_ctx *)sched;
- ctx->ac_nr = rijndaelKeySetupEnc(ctx->ac_ek, (u_char *)key,
- (len - AESCTR_NONCESIZE) * 8);
- if (ctx->ac_nr == 0)
+ if (AES_Setkey(&ctx->ac_key, key, len - AESCTR_NONCESIZE) != 0)
return -1;
bcopy(key + len - AESCTR_NONCESIZE, ctx->ac_block, AESCTR_NONCESIZE);
return 0;
/* Last 64 bits of IV are always zero */
bzero(ctx->tweak + AES_XTS_IVSIZE, AES_XTS_IVSIZE);
- rijndael_encrypt(&ctx->key2, ctx->tweak, ctx->tweak);
+ AES_Encrypt(&ctx->key2, ctx->tweak, ctx->tweak);
}
void
block[i] = data[i] ^ ctx->tweak[i];
if (do_encrypt)
- rijndael_encrypt(&ctx->key1, block, data);
+ AES_Encrypt(&ctx->key1, block, data);
else
- rijndael_decrypt(&ctx->key1, block, data);
+ AES_Decrypt(&ctx->key1, block, data);
for (i = 0; i < AES_XTS_BLOCKSIZE; i++)
data[i] ^= ctx->tweak[i];
ctx = (struct aes_xts_ctx *)sched;
- rijndael_set_key(&ctx->key1, key, len * 4);
- rijndael_set_key(&ctx->key2, key + (len / 2), len * 4);
+ AES_Setkey(&ctx->key1, key, len / 2);
+ AES_Setkey(&ctx->key2, key + (len / 2), len / 2);
return 0;
}