Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src-draft/trunk]: src/sys/uvm uvm(9): Switch from legacy rijndael API to new...
details: https://anonhg.NetBSD.org/src-all/rev/b7131a05bde7
branches: trunk
changeset: 934749:b7131a05bde7
user: Taylor R Campbell <riastradh%NetBSD.org@localhost>
date: Sun Jun 14 19:57:23 2020 +0000
description:
uvm(9): Switch from legacy rijndael API to new aes API.
diffstat:
sys/uvm/files.uvm | 2 +-
sys/uvm/uvm_swap.c | 43 +++++++++++--------------------------------
2 files changed, 12 insertions(+), 33 deletions(-)
diffs (109 lines):
diff -r f2bfdffcb27b -r b7131a05bde7 sys/uvm/files.uvm
--- a/sys/uvm/files.uvm Sun Jun 14 19:56:07 2020 +0000
+++ b/sys/uvm/files.uvm Sun Jun 14 19:57:23 2020 +0000
@@ -8,7 +8,7 @@
defparam opt_uvmhist.h UVMHIST_MAPHIST_SIZE UVMHIST_PDHIST_SIZE
defflag opt_uvm.h USE_TOPDOWN_VM UVMMAP_COUNTERS
defparam opt_uvm.h UVM_RESERVED_PAGES_PER_CPU
-defflag opt_vmswap.h VMSWAP : rijndael
+defflag opt_vmswap.h VMSWAP : aes
defflag opt_readahead.h READAHEAD_STATS
defflag opt_ubc.h UBC_STATS
defparam opt_pagermap.h PAGER_MAP_SIZE
diff -r f2bfdffcb27b -r b7131a05bde7 sys/uvm/uvm_swap.c
--- a/sys/uvm/uvm_swap.c Sun Jun 14 19:56:07 2020 +0000
+++ b/sys/uvm/uvm_swap.c Sun Jun 14 19:57:23 2020 +0000
@@ -65,7 +65,7 @@
#include <miscfs/specfs/specdev.h>
-#include <crypto/rijndael/rijndael-api-fst.h>
+#include <crypto/aes/aes.h>
/*
* uvm_swap.c: manage configuration and i/o to swap space.
@@ -148,8 +148,8 @@
int swd_active; /* number of active buffers */
volatile uint32_t *swd_encmap; /* bitmap of encrypted slots */
- keyInstance swd_enckey; /* AES key expanded for enc */
- keyInstance swd_deckey; /* AES key expanded for dec */
+ struct aesenc swd_enckey; /* AES key expanded for enc */
+ struct aesdec swd_deckey; /* AES key expanded for dec */
bool swd_encinit; /* true if keys initialized */
};
@@ -2073,8 +2073,8 @@
KASSERT(!sdp->swd_encinit);
cprng_strong(kern_cprng, key, sizeof key, 0);
- rijndael_makeKey(&sdp->swd_enckey, DIR_ENCRYPT, 256, key);
- rijndael_makeKey(&sdp->swd_deckey, DIR_DECRYPT, 256, key);
+ aes_setenckey256(&sdp->swd_enckey, key);
+ aes_setdeckey256(&sdp->swd_deckey, key);
explicit_memset(key, 0, sizeof key);
sdp->swd_encinit = true;
@@ -2089,27 +2089,17 @@
static void
uvm_swap_encryptpage(struct swapdev *sdp, void *kva, int slot)
{
- cipherInstance aes;
uint8_t preiv[16] = {0}, iv[16];
- int ok __diagused, nbits __diagused;
/* iv := AES_k(le32enc(slot) || 0^96) */
le32enc(preiv, slot);
- ok = rijndael_cipherInit(&aes, MODE_ECB, NULL);
- KASSERT(ok);
- nbits = rijndael_blockEncrypt(&aes, &sdp->swd_enckey, preiv,
- /*length in bits*/128, iv);
- KASSERT(nbits == 128);
+ aes_enc(&sdp->swd_enckey, (const void *)preiv, iv, AES_256_NROUNDS);
/* *kva := AES-CBC_k(iv, *kva) */
- ok = rijndael_cipherInit(&aes, MODE_CBC, iv);
- KASSERT(ok);
- nbits = rijndael_blockEncrypt(&aes, &sdp->swd_enckey, kva,
- /*length in bits*/PAGE_SIZE*NBBY, kva);
- KASSERT(nbits == PAGE_SIZE*NBBY);
+ aes_cbc_enc(&sdp->swd_enckey, kva, kva, PAGE_SIZE, iv,
+ AES_256_NROUNDS);
explicit_memset(&iv, 0, sizeof iv);
- explicit_memset(&aes, 0, sizeof aes);
}
/*
@@ -2121,28 +2111,17 @@
static void
uvm_swap_decryptpage(struct swapdev *sdp, void *kva, int slot)
{
- cipherInstance aes;
uint8_t preiv[16] = {0}, iv[16];
- int ok __diagused, nbits __diagused;
/* iv := AES_k(le32enc(slot) || 0^96) */
le32enc(preiv, slot);
- ok = rijndael_cipherInit(&aes, MODE_ECB, NULL);
- KASSERT(ok);
- nbits = rijndael_blockEncrypt(&aes, &sdp->swd_enckey, preiv,
- /*length in bits*/128, iv);
- KASSERTMSG(nbits == 128, "nbits=%d expected %d\n", nbits, 128);
+ aes_enc(&sdp->swd_enckey, (const void *)preiv, iv, AES_256_NROUNDS);
/* *kva := AES-CBC^{-1}_k(iv, *kva) */
- ok = rijndael_cipherInit(&aes, MODE_CBC, iv);
- KASSERT(ok);
- nbits = rijndael_blockDecrypt(&aes, &sdp->swd_deckey, kva,
- /*length in bits*/PAGE_SIZE*NBBY, kva);
- KASSERTMSG(nbits == PAGE_SIZE*NBBY,
- "nbits=%d expected %d\n", nbits, PAGE_SIZE*NBBY);
+ aes_cbc_dec(&sdp->swd_deckey, kva, kva, PAGE_SIZE, iv,
+ AES_256_NROUNDS);
explicit_memset(&iv, 0, sizeof iv);
- explicit_memset(&aes, 0, sizeof aes);
}
SYSCTL_SETUP(sysctl_uvmswap_setup, "sysctl uvmswap setup")
Home |
Main Index |
Thread Index |
Old Index