-/* $OpenBSD: cmac.c,v 1.2 2011/01/11 15:42:05 deraadt Exp $ */
+/* $OpenBSD: cmac.c,v 1.3 2017/05/02 17:07:06 mikeb Exp $ */
/*-
* Copyright (c) 2008 Damien Bergamini <damien.bergamini@free.fr>
#include <sys/param.h>
#include <sys/systm.h>
-#include <crypto/rijndael.h>
+#include <crypto/aes.h>
#include <crypto/cmac.h>
#define LSHIFT(v, r) do { \
void
AES_CMAC_SetKey(AES_CMAC_CTX *ctx, const u_int8_t key[AES_CMAC_KEY_LENGTH])
{
- rijndael_set_key_enc_only(&ctx->rijndael, key, 128);
+ AES_Setkey(&ctx->aesctx, key, 16);
}
void
if (ctx->M_n < 16 || len == mlen)
return;
XOR(ctx->M_last, ctx->X);
- rijndael_encrypt(&ctx->rijndael, ctx->X, ctx->X);
+ AES_Encrypt(&ctx->aesctx, ctx->X, ctx->X);
data += mlen;
len -= mlen;
}
while (len > 16) { /* not last block */
XOR(data, ctx->X);
- rijndael_encrypt(&ctx->rijndael, ctx->X, ctx->X);
+ AES_Encrypt(&ctx->aesctx, ctx->X, ctx->X);
data += 16;
len -= 16;
}
/* generate subkey K1 */
memset(K, 0, sizeof K);
- rijndael_encrypt(&ctx->rijndael, K, K);
+ AES_Encrypt(&ctx->aesctx, K, K);
if (K[0] & 0x80) {
LSHIFT(K, K);
XOR(K, ctx->M_last);
}
XOR(ctx->M_last, ctx->X);
- rijndael_encrypt(&ctx->rijndael, ctx->X, digest);
+ AES_Encrypt(&ctx->aesctx, ctx->X, digest);
explicit_bzero(K, sizeof K);
}
-/* $OpenBSD: key_wrap.c,v 1.4 2013/06/11 18:45:08 deraadt Exp $ */
+/* $OpenBSD: key_wrap.c,v 1.5 2017/05/02 17:07:06 mikeb Exp $ */
/*-
* Copyright (c) 2008 Damien Bergamini <damien.bergamini@free.fr>
#include <sys/param.h>
#include <sys/systm.h>
-#include <crypto/rijndael.h>
+#include <crypto/aes.h>
#include <crypto/key_wrap.h>
static const u_int8_t IV[8] =
void
aes_key_wrap_set_key(aes_key_wrap_ctx *ctx, const u_int8_t *K, size_t K_len)
{
- rijndael_set_key(&ctx->ctx, K, K_len * NBBY);
+ AES_Setkey(&ctx->ctx, K, K_len);
}
void
aes_key_wrap_set_key_wrap_only(aes_key_wrap_ctx *ctx, const u_int8_t *K,
size_t K_len)
{
- rijndael_set_key_enc_only(&ctx->ctx, K, K_len * NBBY);
+ AES_Setkey(&ctx->ctx, K, K_len);
}
void
memcpy(&B[0], A, 8);
memcpy(&B[1], R, 8);
/* B = AES(K, B) */
- rijndael_encrypt(&ctx->ctx, (caddr_t)B, (caddr_t)B);
+ AES_Encrypt(&ctx->ctx, (caddr_t)B, (caddr_t)B);
/* MSB(64, B) = MSB(64, B) ^ t */
B[0] ^= htobe64(t);
/* A = MSB(64, B) */
/* B = MSB(64, B) | R[i] */
memcpy(&B[1], R, 8);
/* B = AES-1(K, B) */
- rijndael_decrypt(&ctx->ctx, (caddr_t)B, (caddr_t)B);
+ AES_Decrypt(&ctx->ctx, (caddr_t)B, (caddr_t)B);
/* A = MSB(64, B) */
memcpy(A, &B[0], 8);
/* R[i] = LSB(64, B) */
-/* $OpenBSD: ieee80211_crypto_ccmp.c,v 1.19 2017/03/23 04:10:10 tb Exp $ */
+/* $OpenBSD: ieee80211_crypto_ccmp.c,v 1.20 2017/05/02 17:07:06 mikeb Exp $ */
/*-
* Copyright (c) 2008 Damien Bergamini <damien.bergamini@free.fr>
#include <net80211/ieee80211_var.h>
#include <net80211/ieee80211_crypto.h>
-#include <crypto/rijndael.h>
+#include <crypto/aes.h>
/* CCMP software crypto context */
struct ieee80211_ccmp_ctx {
- rijndael_ctx rijndael;
+ AES_CTX aesctx;
};
/*
ctx = malloc(sizeof(*ctx), M_DEVBUF, M_NOWAIT | M_ZERO);
if (ctx == NULL)
return ENOMEM;
- rijndael_set_key_enc_only(&ctx->rijndael, k->k_key, 128);
+ AES_Setkey(&ctx->aesctx, k->k_key, 16);
k->k_priv = ctx;
return 0;
}
* CCMP uses the following CCM parameters: M = 8, L = 2
*/
static void
-ieee80211_ccmp_phase1(rijndael_ctx *ctx, const struct ieee80211_frame *wh,
+ieee80211_ccmp_phase1(AES_CTX *ctx, const struct ieee80211_frame *wh,
u_int64_t pn, int lm, u_int8_t b[16], u_int8_t a[16], u_int8_t s0[16])
{
u_int8_t auth[32], nonce[13];
memcpy(&b[1], nonce, 13);
b[14] = lm >> 8;
b[15] = lm & 0xff;
- rijndael_encrypt(ctx, b, b);
+ AES_Encrypt(ctx, b, b);
for (i = 0; i < 16; i++)
b[i] ^= auth[i];
- rijndael_encrypt(ctx, b, b);
+ AES_Encrypt(ctx, b, b);
for (i = 0; i < 16; i++)
b[i] ^= auth[16 + i];
- rijndael_encrypt(ctx, b, b);
+ AES_Encrypt(ctx, b, b);
/* construct S_0 */
a[ 0] = 1; /* Flags = L' = (L-1) */
memcpy(&a[1], nonce, 13);
a[14] = a[15] = 0;
- rijndael_encrypt(ctx, a, s0);
+ AES_Encrypt(ctx, a, s0);
}
struct mbuf *
ivp[7] = k->k_tsc >> 40; /* PN5 */
/* construct initial B, A and S_0 blocks */
- ieee80211_ccmp_phase1(&ctx->rijndael, wh, k->k_tsc,
+ ieee80211_ccmp_phase1(&ctx->aesctx, wh, k->k_tsc,
m0->m_pkthdr.len - hdrlen, b, a, s0);
/* construct S_1 */
ctr = 1;
a[14] = ctr >> 8;
a[15] = ctr & 0xff;
- rijndael_encrypt(&ctx->rijndael, a, s);
+ AES_Encrypt(&ctx->aesctx, a, s);
/* encrypt frame body and compute MIC */
j = 0;
if (++j < 16)
continue;
/* we have a full block, encrypt MIC */
- rijndael_encrypt(&ctx->rijndael, b, b);
+ AES_Encrypt(&ctx->aesctx, b, b);
/* construct a new S_ctr block */
ctr++;
a[14] = ctr >> 8;
a[15] = ctr & 0xff;
- rijndael_encrypt(&ctx->rijndael, a, s);
+ AES_Encrypt(&ctx->aesctx, a, s);
j = 0;
}
left -= len;
}
if (j != 0) /* partial block, encrypt MIC */
- rijndael_encrypt(&ctx->rijndael, b, b);
+ AES_Encrypt(&ctx->aesctx, b, b);
/* reserve trailing space for MIC */
if (M_TRAILINGSPACE(n) < IEEE80211_CCMP_MICLEN) {
n0->m_len = n0->m_pkthdr.len;
/* construct initial B, A and S_0 blocks */
- ieee80211_ccmp_phase1(&ctx->rijndael, wh, pn,
+ ieee80211_ccmp_phase1(&ctx->aesctx, wh, pn,
n0->m_pkthdr.len - hdrlen, b, a, s0);
/* copy 802.11 header and clear protected bit */
ctr = 1;
a[14] = ctr >> 8;
a[15] = ctr & 0xff;
- rijndael_encrypt(&ctx->rijndael, a, s);
+ AES_Encrypt(&ctx->aesctx, a, s);
/* decrypt frame body and compute MIC */
j = 0;
if (++j < 16)
continue;
/* we have a full block, encrypt MIC */
- rijndael_encrypt(&ctx->rijndael, b, b);
+ AES_Encrypt(&ctx->aesctx, b, b);
/* construct a new S_ctr block */
ctr++;
a[14] = ctr >> 8;
a[15] = ctr & 0xff;
- rijndael_encrypt(&ctx->rijndael, a, s);
+ AES_Encrypt(&ctx->aesctx, a, s);
j = 0;
}
left -= len;
}
if (j != 0) /* partial block, encrypt MIC */
- rijndael_encrypt(&ctx->rijndael, b, b);
+ AES_Encrypt(&ctx->aesctx, b, b);
/* finalize MIC, U := T XOR first-M-bytes( S_0 ) */
for (i = 0; i < IEEE80211_CCMP_MICLEN; i++)