summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorNiels Provos <provos@cvs.openbsd.org>2002-03-01 02:46:58 +0000
committerNiels Provos <provos@cvs.openbsd.org>2002-03-01 02:46:58 +0000
commit41dd550fc5e50c388ef8925accf8df9d2d03ae0b (patch)
treef09aa27d7354773820603e813b854112af808224 /sys
parent5b14225046061a5e8ce9430e75b27fcacaa2b7e7 (diff)
helper functions for uio (cuio_apply and cuio_getptr) okay deraadt@
Diffstat (limited to 'sys')
-rw-r--r--sys/crypto/criov.c66
-rw-r--r--sys/crypto/cryptodev.h5
2 files changed, 69 insertions, 2 deletions
diff --git a/sys/crypto/criov.c b/sys/crypto/criov.c
index f9fb59f7386..9ce848e1469 100644
--- a/sys/crypto/criov.c
+++ b/sys/crypto/criov.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: criov.c,v 1.9 2002/01/29 15:48:29 jason Exp $ */
+/* $OpenBSD: criov.c,v 1.10 2002/03/01 02:46:57 provos Exp $ */
/*
* Copyright (c) 1999 Theo de Raadt
@@ -110,3 +110,67 @@ cuio_copyback(uio, off, len, cp)
iov++;
}
}
+
+int
+cuio_getptr(struct uio *uio, int loc, int *off)
+{
+ int ind, len;
+
+ ind = 0;
+ while (loc >= 0 && ind < uio->uio_iovcnt) {
+ len = uio->uio_iov[ind].iov_len;
+ if (len > loc) {
+ *off = loc;
+ return (ind);
+ }
+ loc -= len;
+ ind++;
+ }
+
+ if (ind > 0 && loc == 0) {
+ ind--;
+ *off = uio->uio_iov[ind].iov_len;
+ return (ind);
+ }
+
+ return (-1);
+}
+
+int
+cuio_apply(struct uio *uio, int off, int len,
+ int (*f)(caddr_t, caddr_t, unsigned int), caddr_t fstate)
+{
+ int rval, ind, uiolen;
+ unsigned int count;
+
+ if (len < 0)
+ panic("%s: len %d < 0", __FUNCTION__, len);
+ if (off < 0)
+ panic("%s: off %d < 0", __FUNCTION__, off);
+
+ ind = 0;
+ while (off > 0) {
+ if (ind >= uio->uio_iovcnt)
+ panic("m_apply: null mbuf in skip");
+ uiolen = uio->uio_iov[ind].iov_len;
+ if (off < uiolen)
+ break;
+ off -= uiolen;
+ ind++;
+ }
+ while (len > 0) {
+ if (ind >= uio->uio_iovcnt)
+ panic("m_apply: null mbuf");
+ count = min(uio->uio_iov[ind].iov_len - off, len);
+
+ rval = f(fstate, uio->uio_iov[ind].iov_base + off, count);
+ if (rval)
+ return (rval);
+
+ len -= count;
+ off = 0;
+ ind++;
+ }
+
+ return (0);
+}
diff --git a/sys/crypto/cryptodev.h b/sys/crypto/cryptodev.h
index 8b970a05e82..0a3551f27b2 100644
--- a/sys/crypto/cryptodev.h
+++ b/sys/crypto/cryptodev.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: cryptodev.h,v 1.17 2002/02/24 00:30:00 deraadt Exp $ */
+/* $OpenBSD: cryptodev.h,v 1.18 2002/03/01 02:46:57 provos Exp $ */
/*
* The author of this code is Angelos D. Keromytis (angelos@cis.upenn.edu)
@@ -372,6 +372,9 @@ int crypto_check_alg(struct cryptoini *);
void cuio_copydata __P((struct uio *, int, int, caddr_t));
void cuio_copyback __P((struct uio *, int, int, caddr_t));
+int cuio_getptr(struct uio *, int, int *);
+int cuio_apply(struct uio *, int, int,
+ int (*f)(caddr_t, caddr_t, unsigned int), caddr_t);
struct cryptop *crypto_getreq(int);
void crypto_freereq(struct cryptop *);