Skip to content

Commit b366a31

Browse files
anjiahao1xiaoxiang781216
authored andcommitted
crypto:add getfd for crypto testcase
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
1 parent 757fc30 commit b366a31

File tree

4 files changed

+56
-4
lines changed

4 files changed

+56
-4
lines changed

testing/crypto/3descbc.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,20 @@ static int syscrypt(FAR const unsigned char *key, size_t klen,
4848
struct session_op session;
4949
struct crypt_op cryp;
5050
int cryptodev_fd = -1;
51+
int fd = -1;
5152

52-
if ((cryptodev_fd = open("/dev/crypto", O_RDWR, 0)) < 0)
53+
if ((fd = open("/dev/crypto", O_RDWR, 0)) < 0)
5354
{
5455
warn("/dev/crypto");
5556
goto err;
5657
}
5758

59+
if (ioctl(fd, CRIOGET, &cryptodev_fd) == -1)
60+
{
61+
warn("CRIOGET");
62+
goto err;
63+
}
64+
5865
memset(&session, 0, sizeof(session));
5966
session.cipher = CRYPTO_3DES_CBC;
6067
session.key = (caddr_t) key;
@@ -88,6 +95,7 @@ static int syscrypt(FAR const unsigned char *key, size_t klen,
8895
}
8996

9097
close(cryptodev_fd);
98+
close(fd);
9199
return (0);
92100

93101
err:
@@ -96,6 +104,11 @@ static int syscrypt(FAR const unsigned char *key, size_t klen,
96104
close(cryptodev_fd);
97105
}
98106

107+
if (fd != -1)
108+
{
109+
close(fd);
110+
}
111+
99112
return (-1);
100113
}
101114

testing/crypto/aesctr.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,20 @@ static int syscrypt(FAR const unsigned char *key, size_t klen,
179179
struct session_op session;
180180
struct crypt_op cryp;
181181
int cryptodev_fd = -1;
182+
int fd = -1;
182183

183-
if ((cryptodev_fd = open("/dev/crypto", O_RDWR, 0)) < 0)
184+
if ((fd = open("/dev/crypto", O_RDWR, 0)) < 0)
184185
{
185186
warn("/dev/crypto");
186187
goto err;
187188
}
188189

190+
if (ioctl(fd, CRIOGET, &cryptodev_fd) == -1)
191+
{
192+
warn("CRIOGET");
193+
goto err;
194+
}
195+
189196
memset(&session, 0, sizeof(session));
190197
session.cipher = CRYPTO_AES_CTR;
191198
session.key = (caddr_t) key;
@@ -218,6 +225,7 @@ static int syscrypt(FAR const unsigned char *key, size_t klen,
218225
}
219226

220227
close(cryptodev_fd);
228+
close(fd);
221229
return (0);
222230

223231
err:
@@ -226,6 +234,11 @@ static int syscrypt(FAR const unsigned char *key, size_t klen,
226234
close(cryptodev_fd);
227235
}
228236

237+
if (fd != -1)
238+
{
239+
close(fd);
240+
}
241+
229242
return (-1);
230243
}
231244

testing/crypto/aesxts.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1763,13 +1763,20 @@ static int syscrypt(FAR const unsigned char *key, size_t klen,
17631763
struct session_op session;
17641764
struct crypt_op cryp;
17651765
int cryptodev_fd = -1;
1766+
int fd = -1;
17661767

1767-
if ((cryptodev_fd = open("/dev/crypto", O_RDWR, 0)) < 0)
1768+
if ((fd = open("/dev/crypto", O_RDWR, 0)) < 0)
17681769
{
17691770
warn("/dev/crypto");
17701771
goto err;
17711772
}
17721773

1774+
if (ioctl(fd, CRIOGET, &cryptodev_fd) == -1)
1775+
{
1776+
warn("CRIOGET");
1777+
goto err;
1778+
}
1779+
17731780
memset(&session, 0, sizeof(session));
17741781
session.cipher = CRYPTO_AES_XTS;
17751782
session.key = (caddr_t) key;
@@ -1802,6 +1809,7 @@ static int syscrypt(FAR const unsigned char *key, size_t klen,
18021809
}
18031810

18041811
close(cryptodev_fd);
1812+
close(fd);
18051813
return (0);
18061814

18071815
err:
@@ -1810,6 +1818,11 @@ static int syscrypt(FAR const unsigned char *key, size_t klen,
18101818
close(cryptodev_fd);
18111819
}
18121820

1821+
if (fd != -1)
1822+
{
1823+
close(fd);
1824+
}
1825+
18131826
return (-1);
18141827
}
18151828

testing/crypto/hmac.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,20 @@ int syshmac(int mac, FAR const char *key, size_t keylen,
9595
struct session_op session;
9696
struct crypt_op cryp;
9797
int cryptodev_fd = -1;
98+
int fd = -1;
9899

99-
if ((cryptodev_fd = open("/dev/crypto", O_RDWR, 0)) < 0)
100+
if ((fd = open("/dev/crypto", O_RDWR, 0)) < 0)
100101
{
101102
warn("/dev/crypto");
102103
goto err;
103104
}
104105

106+
if (ioctl(fd, CRIOGET, &cryptodev_fd) == -1)
107+
{
108+
warn("CRIOGET");
109+
goto err;
110+
}
111+
105112
memset(&session, 0, sizeof(session));
106113
session.cipher = 0;
107114
session.mac = mac;
@@ -135,13 +142,19 @@ int syshmac(int mac, FAR const char *key, size_t keylen,
135142
};
136143

137144
close(cryptodev_fd);
145+
close(fd);
138146
return 0;
139147
err:
140148
if (cryptodev_fd != -1)
141149
{
142150
close(cryptodev_fd);
143151
}
144152

153+
if (fd != -1)
154+
{
155+
close(fd);
156+
}
157+
145158
return 1;
146159
}
147160

0 commit comments

Comments
 (0)