summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@gnutls.org>2010-07-24 18:46:50 +0200
committerNikos Mavrogiannopoulos <nmav@gnutls.org>2010-07-24 18:46:50 +0200
commit174add36f5b6592db7573145f5c59d0207856e07 (patch)
treebc04ac83ec719bada349705c7a2d1f15084d3b5f /examples
parentffb3e747f8b50ca18701530d1729a4ee3aa4ae69 (diff)
downloadcryptodev-linux-174add36f5b6592db7573145f5c59d0207856e07.tar.gz
cryptodev-linux-174add36f5b6592db7573145f5c59d0207856e07.tar.xz
cryptodev-linux-174add36f5b6592db7573145f5c59d0207856e07.zip
Added the NCR-DIRECT to speed test.
Diffstat (limited to 'examples')
-rw-r--r--examples/speed.c93
1 files changed, 89 insertions, 4 deletions
diff --git a/examples/speed.c b/examples/speed.c
index 1416411..d49faa9 100644
--- a/examples/speed.c
+++ b/examples/speed.c
@@ -218,6 +218,78 @@ int encrypt_data_ncr(int cfd, int algo, int chunksize)
return 0;
}
+int encrypt_data_ncr_direct(int cfd, int algo, int chunksize)
+{
+ char *buffer, iv[32];
+ static int val = 23;
+ struct timeval start, end;
+ double total = 0;
+ double secs, ddata, dspeed;
+ char metric[16];
+ ncr_key_t key;
+ struct ncr_key_generate_st kgen;
+ struct ncr_session_once_op_st nop;
+
+ if (ioctl(cfd, NCRIO_KEY_INIT, &key)) {
+ fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
+ perror("ioctl(NCRIO_KEY_INIT)");
+ return 1;
+ }
+
+ kgen.desc = key;
+ kgen.params.algorithm = NCR_ALG_AES_CBC;
+ kgen.params.keyflags = NCR_KEY_FLAG_EXPORTABLE;
+ kgen.params.params.secret.bits = 128; /* 16 bytes */
+
+ if (ioctl(cfd, NCRIO_KEY_GENERATE, &kgen)) {
+ fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
+ perror("ioctl(NCRIO_KEY_IMPORT)");
+ return 1;
+ }
+
+
+ buffer = malloc(chunksize);
+ memset(iv, 0x23, 32);
+
+ printf("\tEncrypting in chunks of %d bytes: ", chunksize);
+ fflush(stdout);
+
+ memset(buffer, val++, chunksize);
+
+ must_finish = 0;
+ alarm(5);
+
+ gettimeofday(&start, NULL);
+ do {
+ memset(&nop, 0, sizeof(nop));
+ nop.init.algorithm = algo;
+ nop.init.key = key;
+ nop.init.op = NCR_OP_ENCRYPT;
+ nop.op.data.udata.input = buffer;
+ nop.op.data.udata.input_size = chunksize;
+ nop.op.data.udata.output = buffer;
+ nop.op.data.udata.output_size = chunksize;
+ nop.op.type = NCR_DIRECT_DATA;
+
+ if (ioctl(cfd, NCRIO_SESSION_ONCE, &nop)) {
+ fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
+ perror("ioctl(NCRIO_SESSION_ONCE)");
+ return 1;
+ }
+
+ total+=chunksize;
+ } while(must_finish==0);
+ gettimeofday(&end, NULL);
+
+ secs = udifftimeval(start, end)/ 1000000.0;
+
+ value2human(total, secs, &ddata, &dspeed, metric);
+ printf ("done. %.2f %s in %.2f secs: ", ddata, metric, secs);
+ printf ("%.2f %s/sec\n", dspeed, metric);
+
+ return 0;
+}
+
int main(void)
{
int fd, i, fdc = -1;
@@ -250,6 +322,19 @@ int main(void)
break;
}
+ fprintf(stderr, "\nTesting NCR with NULL cipher: \n");
+ for (i = 256; i <= (64 * 1024); i *= 2) {
+ if (encrypt_data_ncr(fdc, NCR_ALG_NULL, i))
+ break;
+ }
+
+ fprintf(stderr, "\nTesting NCR-DIRECT with NULL cipher: \n");
+ for (i = 256; i <= (64 * 1024); i *= 2) {
+ if (encrypt_data_ncr_direct(fdc, NCR_ALG_NULL, i))
+ break;
+ }
+
+
fprintf(stderr, "\nTesting AES-128-CBC cipher: \n");
memset(&sess, 0, sizeof(sess));
sess.cipher = CRYPTO_AES_CBC;
@@ -266,15 +351,15 @@ int main(void)
break;
}
- fprintf(stderr, "\nTesting NCR with NULL cipher: \n");
+ fprintf(stderr, "\nTesting NCR with AES-128-CBC cipher: \n");
for (i = 256; i <= (64 * 1024); i *= 2) {
- if (encrypt_data_ncr(fdc, NCR_ALG_NULL, i))
+ if (encrypt_data_ncr(fdc, NCR_ALG_AES_CBC, i))
break;
}
- fprintf(stderr, "\nTesting NCR with AES-128-CBC cipher: \n");
+ fprintf(stderr, "\nTesting NCR-DIRECT with AES-128-CBC cipher: \n");
for (i = 256; i <= (64 * 1024); i *= 2) {
- if (encrypt_data_ncr(fdc, NCR_ALG_AES_CBC, i))
+ if (encrypt_data_ncr_direct(fdc, NCR_ALG_AES_CBC, i))
break;
}