1 /* cryptodev_test - simple benchmark tool for cryptodev
3 * Copyright (C) 2010 by Phil Sutter <phil.sutter@viprinet.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #include <sys/ioctl.h>
25 #include <sys/types.h>
26 #include "../cryptodev.h"
29 #define TEST_ALGO CRYPTO_AES_CBC
30 #define TEST_KEYLEN 32
32 #define TEST_ALGO CRYPTO_NULL
36 /* transcode a total of 1GB */
37 #define TOT_LEN (1024 * 1024 * 1024)
39 static long udifftimeval(struct timeval start
, struct timeval end
)
41 return (end
.tv_usec
- start
.tv_usec
) +
42 (end
.tv_sec
- start
.tv_sec
) * 1000 * 1000 + 0.5;
45 int encrypt_data(struct session_op
*sess
, int fdc
, int len
, int chunksize
, int flags
)
51 struct timeval start
, end
;
53 if (len
% chunksize
) {
54 printf("got milk?!\n");
58 buffercount
= len
/ chunksize
;
60 buffer
= malloc(chunksize
);
63 printf("Encrypting %d x %d bytes: ", buffercount
, chunksize
);
66 memset(buffer
, val
++, chunksize
);
68 gettimeofday(&start
, NULL
);
69 for (i
= 0; i
< buffercount
; i
++) {
70 memset(&cop
, 0, sizeof(cop
));
73 cop
.iv
= (unsigned char *)iv
;
76 cop
.src
= cop
.dst
= (unsigned char *)buffer
;
78 if (ioctl(fdc
, CIOCCRYPT
, &cop
)) {
79 perror("ioctl(CIOCCRYPT)");
83 gettimeofday(&end
, NULL
);
85 printf("done in %.5f seconds - %.5fMB/s\n", (double)udifftimeval(start
, end
) / 1000000.0,
86 (double)len
/ ((double)udifftimeval(start
, end
) / 1000000.0) / 1024 / 1024);
93 struct session_op sess
;
96 if ((fd
= open("/dev/crypto", O_RDWR
, 0)) < 0) {
100 if (ioctl(fd
, CRIOGET
, &fdc
)) {
101 perror("ioctl(CRIOGET)");
104 memset(&sess
, 0, sizeof(sess
));
105 sess
.cipher
= TEST_ALGO
;
106 sess
.keylen
= TEST_KEYLEN
;
107 memset(keybuf
, 0x42, 32);
108 sess
.key
= (unsigned char *)keybuf
;
109 if (ioctl(fdc
, CIOCGSESSION
, &sess
)) {
110 perror("ioctl(CIOCGSESSION)");
114 printf("Standard operation:\n");
115 for (i
= 256; i
<= (64 * 4096); i
*= 2) {
116 if (encrypt_data(&sess
, fdc
, TOT_LEN
, i
, 0))
119 printf("Zero-Copy operation:\n");
120 for (i
= 256; i
<= (64 * 4096); i
*= 2) {
121 if (encrypt_data(&sess
, fdc
, TOT_LEN
, i
, COP_FLAG_ZCOPY
))