summaryrefslogtreecommitdiffstats
path: root/examples/ncr.c
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@gnutls.org>2010-07-12 12:57:11 +0200
committerNikos Mavrogiannopoulos <nmav@gnutls.org>2010-07-12 12:59:56 +0200
commit4f7b10f59b97b45d42577c4d6d33958d9565aef7 (patch)
tree0f78a952c73985d7e2d852f90f7319a52db785de /examples/ncr.c
parent8d2faf007636a936a5346426f6fe5c251a1255bb (diff)
downloadcryptodev-linux-4f7b10f59b97b45d42577c4d6d33958d9565aef7.tar.gz
cryptodev-linux-4f7b10f59b97b45d42577c4d6d33958d9565aef7.tar.xz
cryptodev-linux-4f7b10f59b97b45d42577c4d6d33958d9565aef7.zip
Initial additions to have PK encryption/decryption. Separated operations
on keys to read/write to prevent overwriting a key while using it. Several other cleanups.
Diffstat (limited to 'examples/ncr.c')
-rw-r--r--examples/ncr.c68
1 files changed, 32 insertions, 36 deletions
diff --git a/examples/ncr.c b/examples/ncr.c
index 3cfc206..cc7b463 100644
--- a/examples/ncr.c
+++ b/examples/ncr.c
@@ -385,7 +385,6 @@ test_ncr_wrap_key(int cfd)
{
int i;
struct ncr_data_init_st dinit;
- struct ncr_key_generate_st kgen;
ncr_key_t key, key2;
struct ncr_key_data_st keydata;
struct ncr_data_st kdata;
@@ -572,7 +571,6 @@ test_ncr_store_wrap_key(int cfd)
{
int i;
struct ncr_data_init_st dinit;
- struct ncr_key_generate_st kgen;
ncr_key_t key2;
struct ncr_key_data_st keydata;
struct ncr_data_st kdata;
@@ -709,29 +707,29 @@ struct aes_vectors_st {
const uint8_t* ciphertext;
} aes_vectors[] = {
{
- .key = "\xc0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
- .plaintext = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
- .ciphertext = "\x4b\xc3\xf8\x83\x45\x0c\x11\x3c\x64\xca\x42\xe1\x11\x2a\x9e\x87",
+ .key = (uint8_t*)"\xc0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
+ .plaintext = (uint8_t*)"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
+ .ciphertext = (uint8_t*)"\x4b\xc3\xf8\x83\x45\x0c\x11\x3c\x64\xca\x42\xe1\x11\x2a\x9e\x87",
},
{
- .key = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
- .plaintext = "\xf3\x44\x81\xec\x3c\xc6\x27\xba\xcd\x5d\xc3\xfb\x08\xf2\x73\xe6",
- .ciphertext = "\x03\x36\x76\x3e\x96\x6d\x92\x59\x5a\x56\x7c\xc9\xce\x53\x7f\x5e",
+ .key = (uint8_t*)"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
+ .plaintext = (uint8_t*)"\xf3\x44\x81\xec\x3c\xc6\x27\xba\xcd\x5d\xc3\xfb\x08\xf2\x73\xe6",
+ .ciphertext = (uint8_t*)"\x03\x36\x76\x3e\x96\x6d\x92\x59\x5a\x56\x7c\xc9\xce\x53\x7f\x5e",
},
{
- .key = "\x10\xa5\x88\x69\xd7\x4b\xe5\xa3\x74\xcf\x86\x7c\xfb\x47\x38\x59",
- .plaintext = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
- .ciphertext = "\x6d\x25\x1e\x69\x44\xb0\x51\xe0\x4e\xaa\x6f\xb4\xdb\xf7\x84\x65",
+ .key = (uint8_t*)"\x10\xa5\x88\x69\xd7\x4b\xe5\xa3\x74\xcf\x86\x7c\xfb\x47\x38\x59",
+ .plaintext = (uint8_t*)"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
+ .ciphertext = (uint8_t*)"\x6d\x25\x1e\x69\x44\xb0\x51\xe0\x4e\xaa\x6f\xb4\xdb\xf7\x84\x65",
},
{
- .key = "\xca\xea\x65\xcd\xbb\x75\xe9\x16\x9e\xcd\x22\xeb\xe6\xe5\x46\x75",
- .plaintext = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
- .ciphertext = "\x6e\x29\x20\x11\x90\x15\x2d\xf4\xee\x05\x81\x39\xde\xf6\x10\xbb",
+ .key = (uint8_t*)"\xca\xea\x65\xcd\xbb\x75\xe9\x16\x9e\xcd\x22\xeb\xe6\xe5\x46\x75",
+ .plaintext = (uint8_t*)"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
+ .ciphertext = (uint8_t*)"\x6e\x29\x20\x11\x90\x15\x2d\xf4\xee\x05\x81\x39\xde\xf6\x10\xbb",
},
{
- .key = "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe",
- .plaintext = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
- .ciphertext = "\x9b\xa4\xa9\x14\x3f\x4e\x5d\x40\x48\x52\x1c\x4f\x88\x77\xd8\x8e",
+ .key = (uint8_t*)"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe",
+ .plaintext = (uint8_t*)"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
+ .ciphertext = (uint8_t*)"\x9b\xa4\xa9\x14\x3f\x4e\x5d\x40\x48\x52\x1c\x4f\x88\x77\xd8\x8e",
},
};
@@ -740,7 +738,6 @@ static int
test_ncr_aes(int cfd)
{
struct ncr_data_init_st dinit;
- struct ncr_key_generate_st kgen;
ncr_key_t key;
struct ncr_key_data_st keydata;
struct ncr_data_st kdata;
@@ -961,20 +958,20 @@ struct hash_vectors_st {
.name = "SHA1",
.algorithm = NCR_ALG_SHA1,
.key = NULL,
- .plaintext = "what do ya want for nothing?",
+ .plaintext = (uint8_t*)"what do ya want for nothing?",
.plaintext_size = sizeof("what do ya want for nothing?")-1,
- .output = "\x8f\x82\x03\x94\xf9\x53\x35\x18\x20\x45\xda\x24\xf3\x4d\xe5\x2b\xf8\xbc\x34\x32",
+ .output = (uint8_t*)"\x8f\x82\x03\x94\xf9\x53\x35\x18\x20\x45\xda\x24\xf3\x4d\xe5\x2b\xf8\xbc\x34\x32",
.output_size = 20,
.op = NCR_OP_DIGEST,
},
{
.name = "HMAC-MD5",
.algorithm = NCR_ALG_HMAC_MD5,
- .key = "Jefe",
+ .key = (uint8_t*)"Jefe",
.key_size = 4,
- .plaintext = "what do ya want for nothing?",
+ .plaintext = (uint8_t*)"what do ya want for nothing?",
.plaintext_size = sizeof("what do ya want for nothing?")-1,
- .output = "\x75\x0c\x78\x3e\x6a\xb0\xb5\x03\xea\xa8\x6e\x31\x0a\x5d\xb7\x38",
+ .output = (uint8_t*)"\x75\x0c\x78\x3e\x6a\xb0\xb5\x03\xea\xa8\x6e\x31\x0a\x5d\xb7\x38",
.output_size = 16,
.op = NCR_OP_MAC,
},
@@ -982,44 +979,44 @@ struct hash_vectors_st {
{
.name = "HMAC-SHA224",
.algorithm = NCR_ALG_HMAC_SHA2_224,
- .key = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",
+ .key = (uint8_t*)"\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",
.key_size = 20,
- .plaintext = "Hi There",
+ .plaintext = (uint8_t*)"Hi There",
.plaintext_size = sizeof("Hi There")-1,
- .output = "\x89\x6f\xb1\x12\x8a\xbb\xdf\x19\x68\x32\x10\x7c\xd4\x9d\xf3\x3f\x47\xb4\xb1\x16\x99\x12\xba\x4f\x53\x68\x4b\x22",
+ .output = (uint8_t*)"\x89\x6f\xb1\x12\x8a\xbb\xdf\x19\x68\x32\x10\x7c\xd4\x9d\xf3\x3f\x47\xb4\xb1\x16\x99\x12\xba\x4f\x53\x68\x4b\x22",
.output_size = 28,
.op = NCR_OP_MAC,
},
{
.name = "HMAC-SHA256",
.algorithm = NCR_ALG_HMAC_SHA2_256,
- .key = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",
+ .key = (uint8_t*)"\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",
.key_size = 20,
- .plaintext = "Hi There",
+ .plaintext = (uint8_t*)"Hi There",
.plaintext_size = sizeof("Hi There")-1,
- .output = "\xb0\x34\x4c\x61\xd8\xdb\x38\x53\x5c\xa8\xaf\xce\xaf\x0b\xf1\x2b\x88\x1d\xc2\x00\xc9\x83\x3d\xa7\x26\xe9\x37\x6c\x2e\x32\xcf\xf7",
+ .output = (uint8_t*)"\xb0\x34\x4c\x61\xd8\xdb\x38\x53\x5c\xa8\xaf\xce\xaf\x0b\xf1\x2b\x88\x1d\xc2\x00\xc9\x83\x3d\xa7\x26\xe9\x37\x6c\x2e\x32\xcf\xf7",
.output_size = 32,
.op = NCR_OP_MAC,
},
{
.name = "HMAC-SHA384",
.algorithm = NCR_ALG_HMAC_SHA2_384,
- .key = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",
+ .key = (uint8_t*)"\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",
.key_size = 20,
- .plaintext = "Hi There",
+ .plaintext = (uint8_t*)"Hi There",
.plaintext_size = sizeof("Hi There")-1,
- .output = "\xaf\xd0\x39\x44\xd8\x48\x95\x62\x6b\x08\x25\xf4\xab\x46\x90\x7f\x15\xf9\xda\xdb\xe4\x10\x1e\xc6\x82\xaa\x03\x4c\x7c\xeb\xc5\x9c\xfa\xea\x9e\xa9\x07\x6e\xde\x7f\x4a\xf1\x52\xe8\xb2\xfa\x9c\xb6",
+ .output = (uint8_t*)"\xaf\xd0\x39\x44\xd8\x48\x95\x62\x6b\x08\x25\xf4\xab\x46\x90\x7f\x15\xf9\xda\xdb\xe4\x10\x1e\xc6\x82\xaa\x03\x4c\x7c\xeb\xc5\x9c\xfa\xea\x9e\xa9\x07\x6e\xde\x7f\x4a\xf1\x52\xe8\xb2\xfa\x9c\xb6",
.output_size = 48,
.op = NCR_OP_MAC,
},
{
.name = "HMAC-SHA512",
.algorithm = NCR_ALG_HMAC_SHA2_512,
- .key = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",
+ .key = (uint8_t*)"\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",
.key_size = 20,
- .plaintext = "Hi There",
+ .plaintext = (uint8_t*)"Hi There",
.plaintext_size = sizeof("Hi There")-1,
- .output = "\x87\xaa\x7c\xde\xa5\xef\x61\x9d\x4f\xf0\xb4\x24\x1a\x1d\x6c\xb0\x23\x79\xf4\xe2\xce\x4e\xc2\x78\x7a\xd0\xb3\x05\x45\xe1\x7c\xde\xda\xa8\x33\xb7\xd6\xb8\xa7\x02\x03\x8b\x27\x4e\xae\xa3\xf4\xe4\xbe\x9d\x91\x4e\xeb\x61\xf1\x70\x2e\x69\x6c\x20\x3a\x12\x68\x54",
+ .output = (uint8_t*)"\x87\xaa\x7c\xde\xa5\xef\x61\x9d\x4f\xf0\xb4\x24\x1a\x1d\x6c\xb0\x23\x79\xf4\xe2\xce\x4e\xc2\x78\x7a\xd0\xb3\x05\x45\xe1\x7c\xde\xda\xa8\x33\xb7\xd6\xb8\xa7\x02\x03\x8b\x27\x4e\xae\xa3\xf4\xe4\xbe\x9d\x91\x4e\xeb\x61\xf1\x70\x2e\x69\x6c\x20\x3a\x12\x68\x54",
.output_size = 64,
.op = NCR_OP_MAC,
},
@@ -1032,7 +1029,6 @@ static int
test_ncr_hash(int cfd)
{
struct ncr_data_init_st dinit;
- struct ncr_key_generate_st kgen;
ncr_key_t key;
struct ncr_key_data_st keydata;
struct ncr_data_st kdata;