summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorMiloslav Trmač <mitr@redhat.com>2010-08-18 03:42:55 +0200
committerMiloslav Trmač <mitr@redhat.com>2010-08-24 22:52:39 +0200
commit2c51dc1a549816a34cb78230bf656537ecd21961 (patch)
treeef746b51a12d651384b4ae87db677630db4e578a /examples
parent491fc6dd6fff9b4d9676e03189ae76538184b51d (diff)
downloadcryptodev-linux-2c51dc1a549816a34cb78230bf656537ecd21961.tar.gz
cryptodev-linux-2c51dc1a549816a34cb78230bf656537ecd21961.tar.xz
cryptodev-linux-2c51dc1a549816a34cb78230bf656537ecd21961.zip
Convert *_KEY_GENERATE
Diffstat (limited to 'examples')
-rw-r--r--examples/ncr.c54
-rw-r--r--examples/speed.c30
2 files changed, 64 insertions, 20 deletions
diff --git a/examples/ncr.c b/examples/ncr.c
index 8b33206..568b63c 100644
--- a/examples/ncr.c
+++ b/examples/ncr.c
@@ -13,11 +13,15 @@
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
+#include <sys/socket.h>
+#include <linux/netlink.h>
#include "../ncr.h"
#include <stdlib.h>
#define DATA_SIZE 4096
+#define ALIGN_NL __attribute__((aligned(NLA_ALIGNTO)))
+
static void randomize_data(uint8_t * data, size_t data_size)
{
int i;
@@ -33,7 +37,15 @@ int i;
static int
test_ncr_key(int cfd)
{
- struct ncr_key_generate_st kgen;
+ struct __attribute__((packed)) {
+ struct ncr_key_generate f;
+ struct nlattr algo_head ALIGN_NL;
+ uint32_t algo ALIGN_NL;
+ struct nlattr flags_head ALIGN_NL;
+ uint32_t flags ALIGN_NL;
+ struct nlattr bits_head ALIGN_NL;
+ uint32_t bits ALIGN_NL;
+ } kgen;
ncr_key_t key;
struct ncr_key_data_st keydata;
uint8_t data[KEY_DATA_SIZE];
@@ -120,14 +132,22 @@ test_ncr_key(int cfd)
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 */
-
+ memset(&kgen.f, 0, sizeof(kgen.f));
+ kgen.f.input_size = sizeof(kgen);
+ kgen.f.key = key;
+ kgen.algo_head.nla_len = NLA_HDRLEN + sizeof(kgen.algo);
+ kgen.algo_head.nla_type = NCR_ATTR_ALGORITHM;
+ kgen.algo = NCR_ALG_AES_CBC;
+ kgen.flags_head.nla_len = NLA_HDRLEN + sizeof(kgen.flags);
+ kgen.flags_head.nla_type = NCR_ATTR_KEY_FLAGS;
+ kgen.flags = NCR_KEY_FLAG_EXPORTABLE;
+ kgen.bits_head.nla_len = NLA_HDRLEN + sizeof(kgen.bits);
+ kgen.bits_head.nla_type = NCR_ATTR_SECRET_KEY_BITS;
+ kgen.bits = 128; /* 16 bytes */
+
if (ioctl(cfd, NCRIO_KEY_GENERATE, &kgen)) {
fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
- perror("ioctl(NCRIO_KEY_IMPORT)");
+ perror("ioctl(NCRIO_KEY_GENERATE)");
return 1;
}
@@ -171,13 +191,21 @@ test_ncr_key(int cfd)
return 1;
}
- kgen.desc = key;
- kgen.params.algorithm = NCR_ALG_AES_CBC;
- kgen.params.keyflags = 0;
- kgen.params.params.secret.bits = 128; /* 16 bytes */
-
+ memset(&kgen.f, 0, sizeof(kgen.f));
+ kgen.f.input_size = sizeof(kgen);
+ kgen.f.key = key;
+ kgen.algo_head.nla_len = NLA_HDRLEN + sizeof(kgen.algo);
+ kgen.algo_head.nla_type = NCR_ATTR_ALGORITHM;
+ kgen.algo = NCR_ALG_AES_CBC;
+ kgen.flags_head.nla_len = NLA_HDRLEN + sizeof(kgen.flags);
+ kgen.flags_head.nla_type = NCR_ATTR_KEY_FLAGS;
+ kgen.flags = 0;
+ kgen.bits_head.nla_len = NLA_HDRLEN + sizeof(kgen.flags);
+ kgen.bits_head.nla_type = NCR_ATTR_SECRET_KEY_BITS;
+ kgen.bits = 128; /* 16 bytes */
+
if (ioctl(cfd, NCRIO_KEY_GENERATE, &kgen)) {
- perror("ioctl(NCRIO_KEY_IMPORT)");
+ perror("ioctl(NCRIO_KEY_GENERATE)");
return 1;
}
diff --git a/examples/speed.c b/examples/speed.c
index 6227cad..9c2e8b8 100644
--- a/examples/speed.c
+++ b/examples/speed.c
@@ -17,6 +17,7 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <fcntl.h>
+#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -24,10 +25,14 @@
#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
+#include <sys/socket.h>
#include <signal.h>
#include <unistd.h>
+#include <linux/netlink.h>
#include "../ncr.h"
+#define ALIGN_NL __attribute__((aligned(NLA_ALIGNTO)))
+
static double udifftimeval(struct timeval start, struct timeval end)
{
return (double)(end.tv_usec - start.tv_usec) +
@@ -76,7 +81,13 @@ int encrypt_data_ncr_direct(int cfd, int algo, int chunksize)
double secs, ddata, dspeed;
char metric[16];
ncr_key_t key;
- struct ncr_key_generate_st kgen;
+ struct __attribute__((packed)) {
+ struct ncr_key_generate f;
+ struct nlattr algo_head ALIGN_NL;
+ uint32_t algo ALIGN_NL;
+ struct nlattr bits_head ALIGN_NL;
+ uint32_t bits ALIGN_NL;
+ } kgen;
struct ncr_session_once_op_st nop;
key = ioctl(cfd, NCRIO_KEY_INIT);
@@ -86,14 +97,19 @@ int encrypt_data_ncr_direct(int cfd, int algo, int chunksize)
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 */
-
+ memset(&kgen.f, 0, sizeof(kgen.f));
+ kgen.f.input_size = sizeof(kgen);
+ kgen.f.key = key;
+ kgen.algo_head.nla_len = NLA_HDRLEN + sizeof(kgen.algo);
+ kgen.algo_head.nla_type = NCR_ATTR_ALGORITHM;
+ kgen.algo = NCR_ALG_AES_CBC;
+ kgen.bits_head.nla_len = NLA_HDRLEN + sizeof(kgen.bits);
+ kgen.bits_head.nla_type = NCR_ATTR_SECRET_KEY_BITS;
+ kgen.bits = 128; /* 16 bytes */
+
if (ioctl(cfd, NCRIO_KEY_GENERATE, &kgen)) {
fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__);
- perror("ioctl(NCRIO_KEY_IMPORT)");
+ perror("ioctl(NCRIO_KEY_GENERATE)");
return 1;
}