Skip to content

Commit

Permalink
- Replace COPYDATA() and COPYBACK() macros with crypto_copydata() and
Browse files Browse the repository at this point in the history
  crypto_copyback() functions.
- Add crypto_apply() function.

This will allow for more code simplification.
  • Loading branch information
pjd authored and pjd committed Jun 4, 2006
1 parent 60fac15 commit f055dbf
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 27 deletions.
40 changes: 40 additions & 0 deletions sys/opencrypto/criov.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ __FBSDID("$FreeBSD$");
#include <sys/errno.h>
#include <sys/malloc.h>
#include <sys/kernel.h>
#include <sys/mbuf.h>
#include <sys/uio.h>

#include <opencrypto/cryptodev.h>
Expand Down Expand Up @@ -156,3 +157,42 @@ cuio_apply(struct uio *uio, int off, int len, int (*f)(void *, void *, u_int),
}
return (0);
}

void
crypto_copyback(int flags, caddr_t buf, int off, int size, caddr_t in)
{

if ((flags & CRYPTO_F_IMBUF) != 0)
m_copyback((struct mbuf *)buf, off, size, in);
else if ((flags & CRYPTO_F_IOV) != 0)
cuio_copyback((struct uio *)buf, off, size, in);
else
bcopy(in, buf + off, size);
}

void
crypto_copydata(int flags, caddr_t buf, int off, int size, caddr_t out)
{

if ((flags & CRYPTO_F_IMBUF) != 0)
m_copydata((struct mbuf *)buf, off, size, out);
else if ((flags & CRYPTO_F_IOV) != 0)
cuio_copydata((struct uio *)buf, off, size, out);
else
bcopy(buf + off, out, size);
}

int
crypto_apply(int flags, caddr_t buf, int off, int len,
int (*f)(void *, void *, u_int), void *arg)
{
int error;

if ((flags & CRYPTO_F_IMBUF) != 0)
error = m_apply((struct mbuf *)buf, off, len, f, arg);
else if ((flags & CRYPTO_F_IOV) != 0)
error = cuio_apply((struct uio *)buf, off, len, f, arg);
else
error = (*f)(arg, buf + off, len);
return (error);
}
34 changes: 7 additions & 27 deletions sys/opencrypto/cryptodev.h
Original file line number Diff line number Diff line change
Expand Up @@ -413,32 +413,12 @@ extern void cuio_copyback(struct uio* uio, int off, int len, caddr_t cp);
extern struct iovec *cuio_getptr(struct uio *uio, int loc, int *off);
extern int cuio_apply(struct uio *uio, int off, int len,
int (*f)(void *, void *, u_int), void *arg);
struct mbuf;
#define COPYBACK(type, buf, off, size, in) do { \
switch (type) { \
case CRYPTO_BUF_CONTIG: \
bcopy(in, (u_char *)(buf) + (off), size); \
break; \
case CRYPTO_BUF_MBUF: \
m_copyback((struct mbuf *)(buf), off, size, in); \
break; \
case CRYPTO_BUF_IOV: \
cuio_copyback((struct uio *)(buf), off, size, in); \
break; \
} \
} while (0)
#define COPYDATA(type, buf, off, size, out) do { \
switch (type) { \
case CRYPTO_BUF_CONTIG: \
bcopy((u_char *)(buf) + (off), out, size); \
break; \
case CRYPTO_BUF_MBUF: \
m_copydata((struct mbuf *)(buf), off, size, out); \
break; \
case CRYPTO_BUF_IOV: \
cuio_copydata((struct uio *)(buf), off, size, out); \
break; \
} \
} while (0)

extern void crypto_copyback(int flags, caddr_t buf, int off, int size,
caddr_t in);
extern void crypto_copydata(int flags, caddr_t buf, int off, int size,
caddr_t out);
extern int crypto_apply(int flags, caddr_t buf, int off, int len,
int (*f)(void *, void *, u_int), void *arg);
#endif /* _KERNEL */
#endif /* _CRYPTO_CRYPTO_H_ */

0 comments on commit f055dbf

Please sign in to comment.