This code never worked on a released version of FreeBSD in the form it's
been in in our tree, and certainly does not work on any version of FreeBSD now. Run through unifdef -D__NetBSD__ -U__FreeBSD__ yielding a small reduction of size and a dramatic improvement in readability. No, this does not yield any meaningful decrease in patchability (unlike mechanical changes that touch live source lines) -- try it and see.
This commit is contained in:
parent
3f5a745e04
commit
e17d3eea39
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: criov.c,v 1.5 2007/03/04 06:03:38 christos Exp $ */
|
||||
/* $NetBSD: criov.c,v 1.6 2008/02/01 04:52:35 tls Exp $ */
|
||||
/* $OpenBSD: criov.c,v 1.11 2002/06/10 19:36:43 espie Exp $ */
|
||||
|
||||
/*
|
||||
@ -29,7 +29,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: criov.c,v 1.5 2007/03/04 06:03:38 christos Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: criov.c,v 1.6 2008/02/01 04:52:35 tls Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
@ -120,37 +120,6 @@ cuio_copyback(uio, off, len, cp)
|
||||
/*
|
||||
* Return a pointer to iov/offset of location in iovec list.
|
||||
*/
|
||||
#ifdef __FreeBSD__
|
||||
struct iovec *
|
||||
cuio_getptr(struct uio *uio, int loc, int *off)
|
||||
{
|
||||
struct iovec *iov = uio->uio_iov;
|
||||
int iol = uio->uio_iovcnt;
|
||||
|
||||
while (loc >= 0) {
|
||||
/* Normal end of search */
|
||||
if (loc < iov->iov_len) {
|
||||
*off = loc;
|
||||
return (iov);
|
||||
}
|
||||
|
||||
loc -= iov->iov_len;
|
||||
if (iol == 0) {
|
||||
if (loc == 0) {
|
||||
/* Point at the end of valid data */
|
||||
*off = iov->iov_len;
|
||||
return (iov);
|
||||
} else
|
||||
return (NULL);
|
||||
} else {
|
||||
iov++, iol--;
|
||||
}
|
||||
}
|
||||
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
int
|
||||
cuio_getptr(struct uio *uio, int loc, int *off)
|
||||
@ -176,7 +145,6 @@ cuio_getptr(struct uio *uio, int loc, int *off)
|
||||
|
||||
return (-1);
|
||||
}
|
||||
#endif
|
||||
|
||||
int
|
||||
cuio_apply(struct uio *uio, int off, int len,
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: crypto.c,v 1.21 2007/10/08 16:18:05 ad Exp $ */
|
||||
/* $NetBSD: crypto.c,v 1.22 2008/02/01 04:52:35 tls Exp $ */
|
||||
/* $FreeBSD: src/sys/opencrypto/crypto.c,v 1.4.2.5 2003/02/26 00:14:05 sam Exp $ */
|
||||
/* $OpenBSD: crypto.c,v 1.41 2002/07/17 23:52:38 art Exp $ */
|
||||
|
||||
@ -24,7 +24,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.21 2007/10/08 16:18:05 ad Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.22 2008/02/01 04:52:35 tls Exp $");
|
||||
|
||||
/* XXX FIXME: should be defopt'ed */
|
||||
#define CRYPTO_TIMING /* enable cryptop timing stuff */
|
||||
@ -43,7 +43,6 @@ __KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.21 2007/10/08 16:18:05 ad Exp $");
|
||||
#include <opencrypto/cryptodev.h>
|
||||
#include <opencrypto/xform.h> /* XXX for M_XDATA */
|
||||
|
||||
#ifdef __NetBSD__
|
||||
#define splcrypto splnet
|
||||
/* below is kludges to check whats still missing */
|
||||
#define SWI_CRYPTO 17
|
||||
@ -51,7 +50,6 @@ __KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.21 2007/10/08 16:18:05 ad Exp $");
|
||||
softint_establish(SOFTINT_NET, (void (*)(void*))fn, NULL)
|
||||
#define unregister_swi(lvl, fn) softint_disestablish(softintr_cookie)
|
||||
#define setsoftcrypto(x) softint_schedule(x)
|
||||
#endif
|
||||
|
||||
#define SESID2HID(sid) (((sid) >> 32) & 0xffffffff)
|
||||
|
||||
@ -109,18 +107,6 @@ int crypto_userasymcrypto = 1; /* userland may do asym crypto reqs */
|
||||
*/
|
||||
int crypto_devallowsoft = 1; /* only use hardware crypto */
|
||||
|
||||
#ifdef __FreeBSD__
|
||||
SYSCTL_INT(_kern, OID_AUTO, usercrypto, CTLFLAG_RW,
|
||||
&crypto_usercrypto, 0,
|
||||
"Enable/disable user-mode access to crypto support");
|
||||
SYSCTL_INT(_kern, OID_AUTO, userasymcrypto, CTLFLAG_RW,
|
||||
&crypto_userasymcrypto, 0,
|
||||
"Enable/disable user-mode access to asymmetric crypto support");
|
||||
SYSCTL_INT(_kern, OID_AUTO, cryptodevallowsoft, CTLFLAG_RW,
|
||||
&crypto_devallowsoft, 0,
|
||||
"Enable/disable use of software asym crypto support");
|
||||
#endif
|
||||
#ifdef __NetBSD__
|
||||
SYSCTL_SETUP(sysctl_opencrypto_setup, "sysctl opencrypto subtree setup")
|
||||
{
|
||||
sysctl_createv(clog, 0, NULL, NULL,
|
||||
@ -150,7 +136,6 @@ SYSCTL_SETUP(sysctl_opencrypto_setup, "sysctl opencrypto subtree setup")
|
||||
NULL, 0, &crypto_devallowsoft, 0,
|
||||
CTL_KERN, CTL_CREATE, CTL_EOL);
|
||||
}
|
||||
#endif
|
||||
|
||||
MALLOC_DEFINE(M_CRYPTO_DATA, "crypto", "crypto session records");
|
||||
|
||||
@ -187,30 +172,12 @@ static int crypto_kinvoke(struct cryptkop *krp, int hint);
|
||||
static struct cryptostats cryptostats;
|
||||
static int crypto_timing = 0;
|
||||
|
||||
#ifdef __FreeBSD__
|
||||
SYSCTL_STRUCT(_kern, OID_AUTO, crypto_stats, CTLFLAG_RW, &cryptostats,
|
||||
cryptostats, "Crypto system statistics");
|
||||
|
||||
SYSCTL_INT(_debug, OID_AUTO, crypto_timing, CTLFLAG_RW,
|
||||
&crypto_timing, 0, "Enable/disable crypto timing support");
|
||||
SYSCTL_STRUCT(_kern, OID_AUTO, crypto_stats, CTLFLAG_RW, &cryptostats,
|
||||
cryptostats, "Crypto system statistics");
|
||||
#endif /* __FreeBSD__ */
|
||||
|
||||
static int
|
||||
crypto_init0(void)
|
||||
{
|
||||
int error;
|
||||
|
||||
#ifdef __FreeBSD__
|
||||
cryptop_zone = zinit("cryptop", sizeof (struct cryptop), 0, 0, 1);
|
||||
cryptodesc_zone = zinit("cryptodesc", sizeof (struct cryptodesc),
|
||||
0, 0, 1);
|
||||
if (cryptodesc_zone == NULL || cryptop_zone == NULL) {
|
||||
printf("crypto_init: cannot setup crypto zones\n");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
crypto_drivers = malloc(CRYPTO_DRIVERS_INITIAL *
|
||||
sizeof(struct cryptocap), M_CRYPTO_DATA, M_NOWAIT | M_ZERO);
|
||||
@ -221,13 +188,8 @@ crypto_init0(void)
|
||||
crypto_drivers_num = CRYPTO_DRIVERS_INITIAL;
|
||||
|
||||
softintr_cookie = register_swi(SWI_CRYPTO, cryptointr);
|
||||
#ifdef __FreeBSD__
|
||||
error = kthread_create((void (*)(void *)) cryptoret, NULL,
|
||||
&cryptothread, "cryptoret");
|
||||
#else
|
||||
error = kthread_create(PRI_NONE, 0, NULL, (void (*)(void*))cryptoret,
|
||||
NULL, &cryptothread, "cryptoret");
|
||||
#endif
|
||||
if (error) {
|
||||
printf("crypto_init: cannot start cryptoret thread; error %d",
|
||||
error);
|
||||
@ -971,29 +933,6 @@ crypto_done(struct cryptop *crp)
|
||||
* On netbsd 1.6O, CBIMM does its wake_one() before the requestor
|
||||
* has done its tsleep().
|
||||
*/
|
||||
#ifndef __NetBSD__
|
||||
if (crp->crp_flags & CRYPTO_F_CBIMM) {
|
||||
/*
|
||||
* Do the callback directly. This is ok when the
|
||||
* callback routine does very little (e.g. the
|
||||
* /dev/crypto callback method just does a wakeup).
|
||||
*/
|
||||
#ifdef CRYPTO_TIMING
|
||||
if (crypto_timing) {
|
||||
/*
|
||||
* NB: We must copy the timestamp before
|
||||
* doing the callback as the cryptop is
|
||||
* likely to be reclaimed.
|
||||
*/
|
||||
struct timespec t = crp->crp_tstamp;
|
||||
crypto_tstat(&cryptostats.cs_cb, &t);
|
||||
crp->crp_callback(crp);
|
||||
crypto_tstat(&cryptostats.cs_finis, &t);
|
||||
} else
|
||||
#endif
|
||||
crp->crp_callback(crp);
|
||||
} else
|
||||
#endif /* __NetBSD__ */
|
||||
{
|
||||
int s, wasempty;
|
||||
/*
|
||||
@ -1219,37 +1158,5 @@ cryptoret(void)
|
||||
}
|
||||
|
||||
|
||||
#ifdef __FreeBSD__
|
||||
/*
|
||||
* Initialization code, both for static and dynamic loading.
|
||||
*/
|
||||
static int
|
||||
crypto_modevent(module_t mod, int type, void *unused)
|
||||
{
|
||||
int error = EINVAL;
|
||||
|
||||
switch (type) {
|
||||
case MOD_LOAD:
|
||||
error = crypto_init();
|
||||
if (error == 0 && bootverbose)
|
||||
printf("crypto: <crypto core>\n");
|
||||
break;
|
||||
case MOD_UNLOAD:
|
||||
/*XXX disallow if active sessions */
|
||||
error = 0;
|
||||
crypto_destroy();
|
||||
break;
|
||||
}
|
||||
return error;
|
||||
}
|
||||
static moduledata_t crypto_mod = {
|
||||
"crypto",
|
||||
crypto_modevent,
|
||||
0
|
||||
};
|
||||
|
||||
MODULE_VERSION(crypto, 1);
|
||||
DECLARE_MODULE(crypto, crypto_mod, SI_SUB_DRIVERS, SI_ORDER_FIRST);
|
||||
#endif /* __FreeBSD__ */
|
||||
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: cryptodev.c,v 1.30 2008/01/29 20:33:44 tls Exp $ */
|
||||
/* $NetBSD: cryptodev.c,v 1.31 2008/02/01 04:52:35 tls Exp $ */
|
||||
/* $FreeBSD: src/sys/opencrypto/cryptodev.c,v 1.4.2.4 2003/06/03 00:09:02 sam Exp $ */
|
||||
/* $OpenBSD: cryptodev.c,v 1.53 2002/07/10 22:21:30 mickey Exp $ */
|
||||
|
||||
@ -35,7 +35,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: cryptodev.c,v 1.30 2008/01/29 20:33:44 tls Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: cryptodev.c,v 1.31 2008/02/01 04:52:35 tls Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
@ -55,9 +55,7 @@ __KERNEL_RCSID(0, "$NetBSD: cryptodev.c,v 1.30 2008/01/29 20:33:44 tls Exp $");
|
||||
#include <opencrypto/cryptodev.h>
|
||||
#include <opencrypto/xform.h>
|
||||
|
||||
#ifdef __NetBSD__
|
||||
#define splcrypto splnet
|
||||
#endif
|
||||
#ifdef CRYPTO_DEBUG
|
||||
#define DPRINTF(a) uprintf a
|
||||
#else
|
||||
@ -806,7 +804,6 @@ struct cdevsw crypto_cdevsw = {
|
||||
/* type */ D_OTHER,
|
||||
};
|
||||
|
||||
#ifdef __NetBSD__
|
||||
/*
|
||||
* Pseudo-device initialization routine for /dev/crypto
|
||||
*/
|
||||
@ -830,4 +827,3 @@ cryptoattach(int num)
|
||||
pool_prime(&fcrpl, 64);
|
||||
pool_prime(&csepl, 64 * 5);
|
||||
}
|
||||
#endif /* __NetBSD__ */
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: cryptodev.h,v 1.9 2008/01/19 08:08:20 tls Exp $ */
|
||||
/* $NetBSD: cryptodev.h,v 1.10 2008/02/01 04:52:35 tls Exp $ */
|
||||
/* $FreeBSD: src/sys/opencrypto/cryptodev.h,v 1.2.2.6 2003/07/02 17:04:50 sam Exp $ */
|
||||
/* $OpenBSD: cryptodev.h,v 1.33 2002/07/17 23:52:39 art Exp $ */
|
||||
|
||||
@ -413,17 +413,8 @@ struct mbuf *m_getptr(struct mbuf *, int, int *);
|
||||
struct uio;
|
||||
extern void cuio_copydata(struct uio* uio, int off, int len, void *cp);
|
||||
extern void cuio_copyback(struct uio* uio, int off, int len, void *cp);
|
||||
#ifdef __FreeBSD__
|
||||
extern struct iovec *cuio_getptr(struct uio *uio, int loc, int *off);
|
||||
#else
|
||||
extern int cuio_getptr(struct uio *, int loc, int *off);
|
||||
#endif
|
||||
|
||||
#ifdef __FreeBSD__ /* Standalone m_apply()/m_getptr() */
|
||||
extern int m_apply(struct mbuf *m, int off, int len,
|
||||
int (*f)(void *, void *, unsigned int), void *fstate);
|
||||
extern struct mbuf * m_getptr(struct mbuf *m, int loc, int *off);
|
||||
#endif /* Standalone m_apply()/m_getptr() */
|
||||
|
||||
#endif /* _KERNEL */
|
||||
#endif /* _CRYPTO_CRYPTO_H_ */
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: cryptosoft.c,v 1.17 2007/03/04 06:03:40 christos Exp $ */
|
||||
/* $NetBSD: cryptosoft.c,v 1.18 2008/02/01 04:52:35 tls Exp $ */
|
||||
/* $FreeBSD: src/sys/opencrypto/cryptosoft.c,v 1.2.2.1 2002/11/21 23:34:23 sam Exp $ */
|
||||
/* $OpenBSD: cryptosoft.c,v 1.35 2002/04/26 08:43:50 deraadt Exp $ */
|
||||
|
||||
@ -24,7 +24,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: cryptosoft.c,v 1.17 2007/03/04 06:03:40 christos Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: cryptosoft.c,v 1.18 2008/02/01 04:52:35 tls Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
@ -291,119 +291,6 @@ swcr_encdec(struct cryptodesc *crd, struct swcr_data *sw, void *bufv,
|
||||
} else if (outtype == CRYPTO_BUF_IOV) {
|
||||
struct uio *uio = (struct uio *) buf;
|
||||
|
||||
#ifdef __FreeBSD__
|
||||
struct iovec *iov;
|
||||
/* Find beginning of data */
|
||||
iov = cuio_getptr(uio, crd->crd_skip, &k);
|
||||
if (iov == NULL)
|
||||
return EINVAL;
|
||||
|
||||
i = crd->crd_len;
|
||||
|
||||
while (i > 0) {
|
||||
/*
|
||||
* If there's insufficient data at the end of
|
||||
* an iovec, we have to do some copying.
|
||||
*/
|
||||
if (iov->iov_len < k + blks && iov->iov_len != k) {
|
||||
cuio_copydata(uio, k, blks, blk);
|
||||
|
||||
/* Actual encryption/decryption */
|
||||
if (crd->crd_flags & CRD_F_ENCRYPT) {
|
||||
/* XOR with previous block */
|
||||
for (j = 0; j < blks; j++)
|
||||
blk[j] ^= ivp[j];
|
||||
|
||||
exf->encrypt(sw->sw_kschedule, blk);
|
||||
|
||||
/*
|
||||
* Keep encrypted block for XOR'ing
|
||||
* with next block
|
||||
*/
|
||||
bcopy(blk, iv, blks);
|
||||
ivp = iv;
|
||||
} else { /* decrypt */
|
||||
/*
|
||||
* Keep encrypted block for XOR'ing
|
||||
* with next block
|
||||
*/
|
||||
if (ivp == iv)
|
||||
bcopy(blk, piv, blks);
|
||||
else
|
||||
bcopy(blk, iv, blks);
|
||||
|
||||
exf->decrypt(sw->sw_kschedule, blk);
|
||||
|
||||
/* XOR with previous block */
|
||||
for (j = 0; j < blks; j++)
|
||||
blk[j] ^= ivp[j];
|
||||
|
||||
if (ivp == iv)
|
||||
bcopy(piv, iv, blks);
|
||||
else
|
||||
ivp = iv;
|
||||
}
|
||||
|
||||
/* Copy back decrypted block */
|
||||
cuio_copyback(uio, k, blks, blk);
|
||||
|
||||
/* Advance pointer */
|
||||
iov = cuio_getptr(uio, k + blks, &k);
|
||||
if (iov == NULL)
|
||||
return EINVAL;
|
||||
|
||||
i -= blks;
|
||||
|
||||
/* Could be done... */
|
||||
if (i == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
* Warning: idat may point to garbage here, but
|
||||
* we only use it in the while() loop, only if
|
||||
* there are indeed enough data.
|
||||
*/
|
||||
idat = (char *)iov->iov_base + k;
|
||||
|
||||
while (iov->iov_len >= k + blks && i > 0) {
|
||||
if (crd->crd_flags & CRD_F_ENCRYPT) {
|
||||
/* XOR with previous block/IV */
|
||||
for (j = 0; j < blks; j++)
|
||||
idat[j] ^= ivp[j];
|
||||
|
||||
exf->encrypt(sw->sw_kschedule, idat);
|
||||
ivp = idat;
|
||||
} else { /* decrypt */
|
||||
/*
|
||||
* Keep encrypted block to be used
|
||||
* in next block's processing.
|
||||
*/
|
||||
if (ivp == iv)
|
||||
bcopy(idat, piv, blks);
|
||||
else
|
||||
bcopy(idat, iv, blks);
|
||||
|
||||
exf->decrypt(sw->sw_kschedule, idat);
|
||||
|
||||
/* XOR with previous block/IV */
|
||||
for (j = 0; j < blks; j++)
|
||||
idat[j] ^= ivp[j];
|
||||
|
||||
if (ivp == iv)
|
||||
bcopy(piv, iv, blks);
|
||||
else
|
||||
ivp = iv;
|
||||
}
|
||||
|
||||
idat += blks;
|
||||
k += blks;
|
||||
i -= blks;
|
||||
}
|
||||
}
|
||||
|
||||
return 0; /* Done with mbuf encryption/decryption */
|
||||
#else /* !freebsd iov */
|
||||
/* Find beginning of data */
|
||||
count = crd->crd_skip;
|
||||
ind = cuio_getptr(uio, count, &k);
|
||||
@ -518,7 +405,6 @@ swcr_encdec(struct cryptodesc *crd, struct swcr_data *sw, void *bufv,
|
||||
i -= blks;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return 0; /* Done with mbuf encryption/decryption */
|
||||
}
|
||||
|
||||
@ -557,10 +443,6 @@ swcr_authcompute(struct cryptop *crp, struct cryptodesc *crd,
|
||||
return err;
|
||||
break;
|
||||
case CRYPTO_BUF_IOV:
|
||||
#ifdef __FreeBSD__
|
||||
/*XXX FIXME: handle iov case*/
|
||||
return EINVAL;
|
||||
#else
|
||||
err = cuio_apply((struct uio *) buf, crd->crd_skip,
|
||||
crd->crd_len,
|
||||
(int (*)(void *, void *, unsigned int)) axf->Update,
|
||||
@ -568,7 +450,6 @@ swcr_authcompute(struct cryptop *crp, struct cryptodesc *crd,
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
default:
|
||||
return EINVAL;
|
||||
@ -1145,11 +1026,7 @@ swcr_init(void)
|
||||
#undef REGISTER
|
||||
}
|
||||
|
||||
#ifdef __FreeBSD__
|
||||
SYSINIT(cryptosoft_init, SI_SUB_PSEUDO, SI_ORDER_ANY, swcr_init, NULL)
|
||||
#endif
|
||||
|
||||
#ifdef __NetBSD__
|
||||
/*
|
||||
* Pseudo-device init routine for software crypto.
|
||||
*/
|
||||
@ -1161,4 +1038,3 @@ swcryptoattach(int num)
|
||||
|
||||
swcr_init();
|
||||
}
|
||||
#endif /* __NetBSD__ */
|
||||
|
Loading…
Reference in New Issue
Block a user