From b673efed4a10dc31567b1c29b140b7910daeaf95 Mon Sep 17 00:00:00 2001 From: Nikos Mavrogiannopoulos Date: Wed, 7 Jul 2010 19:33:33 +0200 Subject: Public and private keys are being generated in a new workqueue. Some other fixes and optimizations. --- examples/Makefile | 29 +- examples/cipher.c | 24 +- examples/ncr.c | 1220 +++++++++++++++++++++++++++++++++++++++++++++++++++++ examples/new.c | 1220 ----------------------------------------------------- 4 files changed, 1253 insertions(+), 1240 deletions(-) create mode 100644 examples/ncr.c delete mode 100644 examples/new.c (limited to 'examples') diff --git a/examples/Makefile b/examples/Makefile index 3190c4a..9dce9b7 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -1,14 +1,27 @@ -KERNEL_DIR ?= /lib/modules/$(shell uname -r)/build +CC = gcc +CFLAGS = -Wall -g -O2 -hostprogs := cipher hmac new -example-cipher-objs := cipher.o -example-hmac-objs := hmac.o -new-objs := new.o +progs := cipher hmac ncr pk -check: $(hostprogs) - ./new +all: $(progs) + +cipher: cipher.c + $(CC) $(CFLAGS) $< -o $@ + +hmac: hmac.c + $(CC) $(CFLAGS) $< -o $@ + +ncr: ncr.c + $(CC) $(CFLAGS) $< -o $@ + +pk: pk.c + $(CC) $(CFLAGS) $< -o $@ -L/usr/local/lib -lgnutls + +check: $(progs) + ./ncr + ./pk ./cipher ./hmac clean: - rm -f *.o *~ hmac cipher new + rm -f *.o *~ hmac cipher ncr pk diff --git a/examples/cipher.c b/examples/cipher.c index c7ce2c2..1334f02 100644 --- a/examples/cipher.c +++ b/examples/cipher.c @@ -19,10 +19,10 @@ static int test_crypto(int cfd) { - char plaintext[DATA_SIZE]; - char ciphertext[DATA_SIZE]; - char iv[BLOCK_SIZE]; - char key[KEY_SIZE]; + uint8_t plaintext[DATA_SIZE]; + uint8_t ciphertext[DATA_SIZE]; + uint8_t iv[BLOCK_SIZE]; + uint8_t key[KEY_SIZE]; struct session_op sess; struct crypt_op cryp; @@ -91,14 +91,14 @@ test_crypto(int cfd) static int test_aes(int cfd) { - char plaintext1[BLOCK_SIZE]; - char ciphertext1[BLOCK_SIZE] = { 0xdf, 0x55, 0x6a, 0x33, 0x43, 0x8d, 0xb8, 0x7b, 0xc4, 0x1b, 0x17, 0x52, 0xc5, 0x5e, 0x5e, 0x49 }; - char iv1[BLOCK_SIZE]; - char key1[KEY_SIZE] = { 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - char plaintext2[BLOCK_SIZE] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00 }; - char ciphertext2[BLOCK_SIZE] = { 0xb7, 0x97, 0x2b, 0x39, 0x41, 0xc4, 0x4b, 0x90, 0xaf, 0xa7, 0xb2, 0x64, 0xbf, 0xba, 0x73, 0x87 }; - char iv2[BLOCK_SIZE]; - char key2[KEY_SIZE]; + uint8_t plaintext1[BLOCK_SIZE]; + uint8_t ciphertext1[BLOCK_SIZE] = { 0xdf, 0x55, 0x6a, 0x33, 0x43, 0x8d, 0xb8, 0x7b, 0xc4, 0x1b, 0x17, 0x52, 0xc5, 0x5e, 0x5e, 0x49 }; + uint8_t iv1[BLOCK_SIZE]; + uint8_t key1[KEY_SIZE] = { 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + uint8_t plaintext2[BLOCK_SIZE] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00 }; + uint8_t ciphertext2[BLOCK_SIZE] = { 0xb7, 0x97, 0x2b, 0x39, 0x41, 0xc4, 0x4b, 0x90, 0xaf, 0xa7, 0xb2, 0x64, 0xbf, 0xba, 0x73, 0x87 }; + uint8_t iv2[BLOCK_SIZE]; + uint8_t key2[KEY_SIZE]; struct session_op sess; struct crypt_op cryp; diff --git a/examples/ncr.c b/examples/ncr.c new file mode 100644 index 0000000..3cfc206 --- /dev/null +++ b/examples/ncr.c @@ -0,0 +1,1220 @@ +/* + * Demo on how to use /dev/crypto device for HMAC. + * + * Placed under public domain. + * + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include "../ncr.h" +#include + +#define DATA_SIZE 4096 + +static void randomize_data(uint8_t * data, size_t data_size) +{ +int i; + + srand(time(0)*getpid()); + for (i=0;i -#include -#include -#include -#include -#include -#include -#include -#include "../ncr.h" -#include - -#define DATA_SIZE 4096 - -static void randomize_data(uint8_t * data, size_t data_size) -{ -int i; - - srand(time(0)*getpid()); - for (i=0;i