[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
using /dev/crypto
I'm trying to write code that uses the /dev/crypto pseudo-device. I've
read crypto(4) and /usr/src/sys/cryptodev.h, and tried the following:
#########################
#include <sys/types.h>
#include <crypto/crypto.h>
#include <crypto/cryptodev.h>
#include <sys/ioctl.h>
#include <stdio.h>
#include <fcntl.h>
int cryptodev_fd;
struct session_op session;
int main() {
if ((cryptodev_fd = open("/dev/crypto",O_RDWR,0)) < 0) {
perror("failed to open /dev/crypto");
exit(1);
}
session.cipher=CRYPTO_3DES_CBC;
session.mac=0;
session.keylen=24;
session.key=(caddr_t)"123456781234567812345678";
if (ioctl(cryptodev_fd, CIOCGSESSION, &session) == -1) {
perror("ioctl failed");
exit(1);
}
}
############################
The result is "ioctl failed: invalid argument"
By putting some printf statements in /usr/src/sys/crypto/cryptodev.c, I've
found that the function that's getting called there when I do the ioctl
isn't the one I expected; instead of cryptof_ioctl(), which contains code
to handle CIOCGSESSION, the function that's called is cryptoioctl(). The
latter function only understands a CRIOGET command. I've tried
ioctl(cryptodev_fd,CRIOGET), but that gives a "Bad address" error. I
believe this error comes from the falloc call in cryptoioctl(), but I
can't understand why.
Thanks in advance for any pointers to help. It's likely there's an
obvious error on my part here that I'm overlooking.... If so,
apologies.
---Bruce Fields