From afa3750ba89b7b016ff076ba513472cbd392c24e Mon Sep 17 00:00:00 2001 From: markus <> Date: Tue, 18 Jun 2002 14:36:53 +0000 Subject: unbreak sshd with privsep: open /dev/crypto, keep fd, and call CRIOGET per EVP_Init(); ok niklas@, miod@ --- src/lib/libcrypto/engine/hw_cryptodev.c | 25 ++++++++++++++++++++----- src/lib/libssl/src/crypto/engine/hw_cryptodev.c | 25 ++++++++++++++++++++----- 2 files changed, 40 insertions(+), 10 deletions(-) diff --git a/src/lib/libcrypto/engine/hw_cryptodev.c b/src/lib/libcrypto/engine/hw_cryptodev.c index 859af048ee..b8217cdea1 100644 --- a/src/lib/libcrypto/engine/hw_cryptodev.c +++ b/src/lib/libcrypto/engine/hw_cryptodev.c @@ -111,18 +111,33 @@ static struct { /* * Return a fd if /dev/crypto seems usable, 0 otherwise. */ +static int +open_dev_crypto() +{ + static int fd = -1; + + if (fd == -1) { + if (fd = open("/dev/crypto", O_RDWR, 0) == -1) + return (-1); + /* close on exec */ + if (fcntl(fd, F_SETFD, 1) == -1) { + close(fd); + fd = -1; + return (-1); + } + } + return (fd); +} + static int get_dev_crypto() { int fd, retfd; - if ((fd = open("/dev/crypto", O_RDWR, 0)) == -1) + if ((fd = open_dev_crypto()) == -1) return (-1); - if (ioctl(fd, CRIOGET, &retfd) == -1) { - close(fd); + if (ioctl(fd, CRIOGET, &retfd) == -1) return (-1); - } - close(fd); /* close on exec */ if (fcntl(retfd, F_SETFD, 1) == -1) { diff --git a/src/lib/libssl/src/crypto/engine/hw_cryptodev.c b/src/lib/libssl/src/crypto/engine/hw_cryptodev.c index 859af048ee..b8217cdea1 100644 --- a/src/lib/libssl/src/crypto/engine/hw_cryptodev.c +++ b/src/lib/libssl/src/crypto/engine/hw_cryptodev.c @@ -111,18 +111,33 @@ static struct { /* * Return a fd if /dev/crypto seems usable, 0 otherwise. */ +static int +open_dev_crypto() +{ + static int fd = -1; + + if (fd == -1) { + if (fd = open("/dev/crypto", O_RDWR, 0) == -1) + return (-1); + /* close on exec */ + if (fcntl(fd, F_SETFD, 1) == -1) { + close(fd); + fd = -1; + return (-1); + } + } + return (fd); +} + static int get_dev_crypto() { int fd, retfd; - if ((fd = open("/dev/crypto", O_RDWR, 0)) == -1) + if ((fd = open_dev_crypto()) == -1) return (-1); - if (ioctl(fd, CRIOGET, &retfd) == -1) { - close(fd); + if (ioctl(fd, CRIOGET, &retfd) == -1) return (-1); - } - close(fd); /* close on exec */ if (fcntl(retfd, F_SETFD, 1) == -1) { -- cgit v1.2.3-55-g6feb