crypto:add getfd for crypto testcase
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
This commit is contained in:
parent
757fc307c3
commit
b366a31644
@ -48,13 +48,20 @@ static int syscrypt(FAR const unsigned char *key, size_t klen,
|
|||||||
struct session_op session;
|
struct session_op session;
|
||||||
struct crypt_op cryp;
|
struct crypt_op cryp;
|
||||||
int cryptodev_fd = -1;
|
int cryptodev_fd = -1;
|
||||||
|
int fd = -1;
|
||||||
|
|
||||||
if ((cryptodev_fd = open("/dev/crypto", O_RDWR, 0)) < 0)
|
if ((fd = open("/dev/crypto", O_RDWR, 0)) < 0)
|
||||||
{
|
{
|
||||||
warn("/dev/crypto");
|
warn("/dev/crypto");
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ioctl(fd, CRIOGET, &cryptodev_fd) == -1)
|
||||||
|
{
|
||||||
|
warn("CRIOGET");
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
|
||||||
memset(&session, 0, sizeof(session));
|
memset(&session, 0, sizeof(session));
|
||||||
session.cipher = CRYPTO_3DES_CBC;
|
session.cipher = CRYPTO_3DES_CBC;
|
||||||
session.key = (caddr_t) key;
|
session.key = (caddr_t) key;
|
||||||
@ -88,6 +95,7 @@ static int syscrypt(FAR const unsigned char *key, size_t klen,
|
|||||||
}
|
}
|
||||||
|
|
||||||
close(cryptodev_fd);
|
close(cryptodev_fd);
|
||||||
|
close(fd);
|
||||||
return (0);
|
return (0);
|
||||||
|
|
||||||
err:
|
err:
|
||||||
@ -96,6 +104,11 @@ err:
|
|||||||
close(cryptodev_fd);
|
close(cryptodev_fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fd != -1)
|
||||||
|
{
|
||||||
|
close(fd);
|
||||||
|
}
|
||||||
|
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,13 +179,20 @@ static int syscrypt(FAR const unsigned char *key, size_t klen,
|
|||||||
struct session_op session;
|
struct session_op session;
|
||||||
struct crypt_op cryp;
|
struct crypt_op cryp;
|
||||||
int cryptodev_fd = -1;
|
int cryptodev_fd = -1;
|
||||||
|
int fd = -1;
|
||||||
|
|
||||||
if ((cryptodev_fd = open("/dev/crypto", O_RDWR, 0)) < 0)
|
if ((fd = open("/dev/crypto", O_RDWR, 0)) < 0)
|
||||||
{
|
{
|
||||||
warn("/dev/crypto");
|
warn("/dev/crypto");
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ioctl(fd, CRIOGET, &cryptodev_fd) == -1)
|
||||||
|
{
|
||||||
|
warn("CRIOGET");
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
|
||||||
memset(&session, 0, sizeof(session));
|
memset(&session, 0, sizeof(session));
|
||||||
session.cipher = CRYPTO_AES_CTR;
|
session.cipher = CRYPTO_AES_CTR;
|
||||||
session.key = (caddr_t) key;
|
session.key = (caddr_t) key;
|
||||||
@ -218,6 +225,7 @@ static int syscrypt(FAR const unsigned char *key, size_t klen,
|
|||||||
}
|
}
|
||||||
|
|
||||||
close(cryptodev_fd);
|
close(cryptodev_fd);
|
||||||
|
close(fd);
|
||||||
return (0);
|
return (0);
|
||||||
|
|
||||||
err:
|
err:
|
||||||
@ -226,6 +234,11 @@ err:
|
|||||||
close(cryptodev_fd);
|
close(cryptodev_fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fd != -1)
|
||||||
|
{
|
||||||
|
close(fd);
|
||||||
|
}
|
||||||
|
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1763,13 +1763,20 @@ static int syscrypt(FAR const unsigned char *key, size_t klen,
|
|||||||
struct session_op session;
|
struct session_op session;
|
||||||
struct crypt_op cryp;
|
struct crypt_op cryp;
|
||||||
int cryptodev_fd = -1;
|
int cryptodev_fd = -1;
|
||||||
|
int fd = -1;
|
||||||
|
|
||||||
if ((cryptodev_fd = open("/dev/crypto", O_RDWR, 0)) < 0)
|
if ((fd = open("/dev/crypto", O_RDWR, 0)) < 0)
|
||||||
{
|
{
|
||||||
warn("/dev/crypto");
|
warn("/dev/crypto");
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ioctl(fd, CRIOGET, &cryptodev_fd) == -1)
|
||||||
|
{
|
||||||
|
warn("CRIOGET");
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
|
||||||
memset(&session, 0, sizeof(session));
|
memset(&session, 0, sizeof(session));
|
||||||
session.cipher = CRYPTO_AES_XTS;
|
session.cipher = CRYPTO_AES_XTS;
|
||||||
session.key = (caddr_t) key;
|
session.key = (caddr_t) key;
|
||||||
@ -1802,6 +1809,7 @@ static int syscrypt(FAR const unsigned char *key, size_t klen,
|
|||||||
}
|
}
|
||||||
|
|
||||||
close(cryptodev_fd);
|
close(cryptodev_fd);
|
||||||
|
close(fd);
|
||||||
return (0);
|
return (0);
|
||||||
|
|
||||||
err:
|
err:
|
||||||
@ -1810,6 +1818,11 @@ err:
|
|||||||
close(cryptodev_fd);
|
close(cryptodev_fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fd != -1)
|
||||||
|
{
|
||||||
|
close(fd);
|
||||||
|
}
|
||||||
|
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,13 +95,20 @@ int syshmac(int mac, FAR const char *key, size_t keylen,
|
|||||||
struct session_op session;
|
struct session_op session;
|
||||||
struct crypt_op cryp;
|
struct crypt_op cryp;
|
||||||
int cryptodev_fd = -1;
|
int cryptodev_fd = -1;
|
||||||
|
int fd = -1;
|
||||||
|
|
||||||
if ((cryptodev_fd = open("/dev/crypto", O_RDWR, 0)) < 0)
|
if ((fd = open("/dev/crypto", O_RDWR, 0)) < 0)
|
||||||
{
|
{
|
||||||
warn("/dev/crypto");
|
warn("/dev/crypto");
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ioctl(fd, CRIOGET, &cryptodev_fd) == -1)
|
||||||
|
{
|
||||||
|
warn("CRIOGET");
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
|
||||||
memset(&session, 0, sizeof(session));
|
memset(&session, 0, sizeof(session));
|
||||||
session.cipher = 0;
|
session.cipher = 0;
|
||||||
session.mac = mac;
|
session.mac = mac;
|
||||||
@ -135,6 +142,7 @@ int syshmac(int mac, FAR const char *key, size_t keylen,
|
|||||||
};
|
};
|
||||||
|
|
||||||
close(cryptodev_fd);
|
close(cryptodev_fd);
|
||||||
|
close(fd);
|
||||||
return 0;
|
return 0;
|
||||||
err:
|
err:
|
||||||
if (cryptodev_fd != -1)
|
if (cryptodev_fd != -1)
|
||||||
@ -142,6 +150,11 @@ err:
|
|||||||
close(cryptodev_fd);
|
close(cryptodev_fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fd != -1)
|
||||||
|
{
|
||||||
|
close(fd);
|
||||||
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user