Changeset View
Changeset View
Standalone View
Standalone View
head/sys/opencrypto/crypto.c
Show First 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | |||||
#include "opt_ddb.h" | #include "opt_ddb.h" | ||||
#include <sys/param.h> | #include <sys/param.h> | ||||
#include <sys/systm.h> | #include <sys/systm.h> | ||||
#include <sys/eventhandler.h> | #include <sys/eventhandler.h> | ||||
#include <sys/kernel.h> | #include <sys/kernel.h> | ||||
#include <sys/kthread.h> | #include <sys/kthread.h> | ||||
#include <sys/linker.h> | |||||
#include <sys/lock.h> | #include <sys/lock.h> | ||||
#include <sys/module.h> | #include <sys/module.h> | ||||
#include <sys/mutex.h> | #include <sys/mutex.h> | ||||
#include <sys/malloc.h> | #include <sys/malloc.h> | ||||
#include <sys/proc.h> | #include <sys/proc.h> | ||||
#include <sys/sdt.h> | #include <sys/sdt.h> | ||||
#include <sys/sysctl.h> | #include <sys/sysctl.h> | ||||
#include <ddb/ddb.h> | #include <ddb/ddb.h> | ||||
#include <vm/uma.h> | #include <vm/uma.h> | ||||
#include <crypto/intake.h> | |||||
#include <opencrypto/cryptodev.h> | #include <opencrypto/cryptodev.h> | ||||
#include <opencrypto/xform.h> /* XXX for M_XDATA */ | #include <opencrypto/xform.h> /* XXX for M_XDATA */ | ||||
#include <sys/kobj.h> | #include <sys/kobj.h> | ||||
#include <sys/bus.h> | #include <sys/bus.h> | ||||
#include "cryptodev_if.h" | #include "cryptodev_if.h" | ||||
#if defined(__i386__) || defined(__amd64__) || defined(__aarch64__) | #if defined(__i386__) || defined(__amd64__) || defined(__aarch64__) | ||||
#include <machine/pcb.h> | #include <machine/pcb.h> | ||||
#endif | #endif | ||||
#include <machine/metadata.h> | |||||
SDT_PROVIDER_DEFINE(opencrypto); | SDT_PROVIDER_DEFINE(opencrypto); | ||||
/* | /* | ||||
* Crypto drivers register themselves by allocating a slot in the | * Crypto drivers register themselves by allocating a slot in the | ||||
* crypto_drivers table with crypto_get_driverid() and then registering | * crypto_drivers table with crypto_get_driverid() and then registering | ||||
* each algorithm they support with crypto_register() and crypto_kregister(). | * each algorithm they support with crypto_register() and crypto_kregister(). | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 86 Lines • ▼ Show 20 Lines | SYSCTL_STRUCT(_kern, OID_AUTO, crypto_stats, CTLFLAG_RW, &cryptostats, | ||||
cryptostats, "Crypto system statistics"); | cryptostats, "Crypto system statistics"); | ||||
#ifdef CRYPTO_TIMING | #ifdef CRYPTO_TIMING | ||||
static int crypto_timing = 0; | static int crypto_timing = 0; | ||||
SYSCTL_INT(_debug, OID_AUTO, crypto_timing, CTLFLAG_RW, | SYSCTL_INT(_debug, OID_AUTO, crypto_timing, CTLFLAG_RW, | ||||
&crypto_timing, 0, "Enable/disable crypto timing support"); | &crypto_timing, 0, "Enable/disable crypto timing support"); | ||||
#endif | #endif | ||||
/* Try to avoid directly exposing the key buffer as a symbol */ | |||||
static struct keybuf *keybuf; | |||||
static struct keybuf empty_keybuf = { | |||||
.kb_nents = 0 | |||||
}; | |||||
/* Obtain the key buffer from boot metadata */ | |||||
static void | |||||
keybuf_init(void) | |||||
{ | |||||
caddr_t kmdp; | |||||
kmdp = preload_search_by_type("elf kernel"); | |||||
if (kmdp == NULL) | |||||
kmdp = preload_search_by_type("elf64 kernel"); | |||||
keybuf = (struct keybuf *)preload_search_info(kmdp, | |||||
MODINFO_METADATA | MODINFOMD_KEYBUF); | |||||
if (keybuf == NULL) | |||||
keybuf = &empty_keybuf; | |||||
} | |||||
/* It'd be nice if we could store these in some kind of secure memory... */ | |||||
struct keybuf * get_keybuf(void) { | |||||
return (keybuf); | |||||
} | |||||
static int | static int | ||||
crypto_init(void) | crypto_init(void) | ||||
{ | { | ||||
int error; | int error; | ||||
mtx_init(&crypto_drivers_mtx, "crypto", "crypto driver table", | mtx_init(&crypto_drivers_mtx, "crypto", "crypto driver table", | ||||
MTX_DEF|MTX_QUIET); | MTX_DEF|MTX_QUIET); | ||||
Show All 36 Lines | crypto_init(void) | ||||
error = kproc_create((void (*)(void *)) crypto_ret_proc, NULL, | error = kproc_create((void (*)(void *)) crypto_ret_proc, NULL, | ||||
&cryptoretproc, 0, 0, "crypto returns"); | &cryptoretproc, 0, 0, "crypto returns"); | ||||
if (error) { | if (error) { | ||||
printf("crypto_init: cannot start cryptoret thread; error %d", | printf("crypto_init: cannot start cryptoret thread; error %d", | ||||
error); | error); | ||||
goto bad; | goto bad; | ||||
} | } | ||||
keybuf_init(); | |||||
return 0; | return 0; | ||||
bad: | bad: | ||||
crypto_destroy(); | crypto_destroy(); | ||||
return error; | return error; | ||||
} | } | ||||
/* | /* | ||||
* Signal a crypto thread to terminate. We use the driver | * Signal a crypto thread to terminate. We use the driver | ||||
Show All 28 Lines | crypto_destroy(void) | ||||
*/ | */ | ||||
CRYPTO_DRIVER_LOCK(); | CRYPTO_DRIVER_LOCK(); | ||||
crypto_terminate(&cryptoproc, &crp_q); | crypto_terminate(&cryptoproc, &crp_q); | ||||
crypto_terminate(&cryptoretproc, &crp_ret_q); | crypto_terminate(&cryptoretproc, &crp_ret_q); | ||||
CRYPTO_DRIVER_UNLOCK(); | CRYPTO_DRIVER_UNLOCK(); | ||||
/* XXX flush queues??? */ | /* XXX flush queues??? */ | ||||
/* | /* | ||||
* Reclaim dynamically allocated resources. | * Reclaim dynamically allocated resources. | ||||
*/ | */ | ||||
if (crypto_drivers != NULL) | if (crypto_drivers != NULL) | ||||
free(crypto_drivers, M_CRYPTO_DATA); | free(crypto_drivers, M_CRYPTO_DATA); | ||||
if (cryptodesc_zone != NULL) | if (cryptodesc_zone != NULL) | ||||
uma_zdestroy(cryptodesc_zone); | uma_zdestroy(cryptodesc_zone); | ||||
if (cryptop_zone != NULL) | if (cryptop_zone != NULL) | ||||
▲ Show 20 Lines • Show All 1,284 Lines • Show Last 20 Lines |