summaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/Makefile.am39
-rw-r--r--src/tests/icastats_test.c822
-rw-r--r--src/tests/libica_3des_cbc_test.c181
-rw-r--r--src/tests/libica_3des_cfb_test.c204
-rw-r--r--src/tests/libica_3des_ctr_test.c188
-rw-r--r--src/tests/libica_3des_ecb_test.c320
-rw-r--r--src/tests/libica_3des_ofb_test.c186
-rw-r--r--src/tests/libica_3des_test.c156
-rw-r--r--src/tests/libica_aes128_test.c303
-rw-r--r--src/tests/libica_aes192_test.c180
-rw-r--r--src/tests/libica_aes256_test.c182
-rw-r--r--src/tests/libica_aes_cbc_test.c649
-rw-r--r--src/tests/libica_aes_cfb_test.c832
-rw-r--r--src/tests/libica_aes_ctr_test.c661
-rw-r--r--src/tests/libica_aes_ecb_test.c511
-rw-r--r--src/tests/libica_aes_gcm_test.c1075
-rw-r--r--src/tests/libica_aes_ofb_test.c555
-rw-r--r--src/tests/libica_aes_xts_test.c669
-rw-r--r--src/tests/libica_cbccs_test.c575
-rw-r--r--src/tests/libica_ccm_test.c225
-rw-r--r--src/tests/libica_cmac_test.c349
-rw-r--r--src/tests/libica_des_cbc_test.c335
-rw-r--r--src/tests/libica_des_cfb_test.c204
-rw-r--r--src/tests/libica_des_ctr_test.c197
-rw-r--r--src/tests/libica_des_ecb_test.c164
-rw-r--r--src/tests/libica_des_ofb_test.c187
-rw-r--r--src/tests/libica_des_test.c159
-rw-r--r--src/tests/libica_get_functionlist.c76
-rw-r--r--src/tests/libica_get_version.c71
-rw-r--r--src/tests/libica_keygen_test.c295
-rw-r--r--src/tests/libica_rng_test.c73
-rw-r--r--src/tests/libica_rsa_key_check_test.c127
-rw-r--r--src/tests/libica_rsa_test.c150
-rw-r--r--src/tests/libica_rsa_test.h2175
-rw-r--r--src/tests/libica_sha1_test.c220
-rw-r--r--src/tests/libica_sha256_test.c209
-rw-r--r--src/tests/libica_sha_test/Makefile.am26
-rw-r--r--src/tests/libica_sha_test/README5
-rw-r--r--src/tests/libica_sha_test/include/critical_error.h14
-rw-r--r--src/tests/libica_sha_test/include/queue_t.h33
-rw-r--r--src/tests/libica_sha_test/include/read_rsp.h14
-rw-r--r--src/tests/libica_sha_test/include/sha_tests.h22
-rw-r--r--src/tests/libica_sha_test/libica_sha_test.c115
-rw-r--r--src/tests/libica_sha_test/queue_t.c60
-rw-r--r--src/tests/libica_sha_test/read_rsp.c200
-rw-r--r--src/tests/libica_sha_test/sha_test_vectors/SHA1.txt36
-rw-r--r--src/tests/libica_sha_test/sha_test_vectors/SHA224.txt39
-rw-r--r--src/tests/libica_sha_test/sha_test_vectors/SHA256.txt39
-rw-r--r--src/tests/libica_sha_test/sha_test_vectors/SHA384.txt43
-rw-r--r--src/tests/libica_sha_test/sha_test_vectors/SHA512.txt43
-rw-r--r--src/tests/libica_sha_test/sha_tests.c189
-rwxr-xr-xsrc/tests/suite.run57
-rw-r--r--src/tests/test_mech_list.c34
53 files changed, 14473 insertions, 0 deletions
diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am
new file mode 100644
index 0000000..f941c49
--- /dev/null
+++ b/src/tests/Makefile.am
@@ -0,0 +1,39 @@
+#OPTS = -O0 -g -Wall -fprofile-arcs -ftest-coverage -fPIC
+#OPTS = -O0 -g -Wall -m31 -D_LINUX_S390_
+OPTS = -O0 -g -Wall -D_LINUX_S390_
+LIBS = -L../.libs
+INCLUDE = -I. -I../include -I../../include
+CC = gcc
+
+TARGETS = icastats_test \
+ libica_des_test libica_3des_test \
+ libica_aes128_test libica_aes192_test libica_aes256_test \
+ libica_sha1_test \
+ libica_sha256_test \
+ libica_rsa_test libica_rsa_key_check_test \
+ libica_rng_test libica_keygen_test \
+ test_mech_list \
+ libica_cmac_test \
+ libica_aes_xts_test libica_aes_gcm_test libica_ccm_test \
+ libica_aes_ctr_test libica_aes_ofb_test libica_aes_cfb_test \
+ libica_aes_cbc_test libica_aes_ecb_test \
+ libica_des_ctr_test libica_3des_ctr_test \
+ libica_des_cfb_test libica_3des_cfb_test \
+ libica_des_cbc_test libica_3des_cbc_test \
+ libica_des_ecb_test libica_cbccs_test libica_3des_ecb_test \
+ libica_des_ofb_test libica_3des_ofb_test \
+ libica_get_version \
+ libica_get_functionlist
+
+all: $(TARGETS)
+
+# Every target is created from a single .c file.
+%: %.c
+ gcc $(OPTS) -o $@ $^ $(LIBS) $(INCLUDE) -lica -lcrypto
+
+clean:
+ rm -f $(TARGETS)
+
+distclean:
+ rm -f Makefile
+ rm -f $(TARGETS)
diff --git a/src/tests/icastats_test.c b/src/tests/icastats_test.c
new file mode 100644
index 0000000..a2110c4
--- /dev/null
+++ b/src/tests/icastats_test.c
@@ -0,0 +1,822 @@
+/* This program is released under the Common Public License V1.0
+ *
+ * You should have received a copy of Common Public License V1.0 along with
+ * with this program.
+ **/
+
+/* Copyright IBM Corp. 2014 */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <dirent.h>
+#include <string.h>
+#include "ica_api.h"
+
+#define DATA_LENGHT 32
+#define DES_CIPHER_BLOCK 8
+#define AES_CIPHER_BLOCK 16
+#define RSA_BYTE_LENGHT 128
+
+unsigned char plain_data[] = {
+ 0x55, 0x73, 0x69, 0x6e, 0x67, 0x20, 0x6c, 0x69,
+ 0x62, 0x69, 0x63, 0x61, 0x20, 0x69, 0x73, 0x20,
+ 0x73, 0x6d, 0x61, 0x72, 0x74, 0x20, 0x61, 0x6e,
+ 0x64, 0x20, 0x65, 0x61, 0x73, 0x79, 0x21, 0x00,
+};
+
+int hw_flag;
+unsigned int mech_len;
+libica_func_list_element *pmech_list = NULL;
+
+static int handle_ica_error(int rc, char *message);
+static int is_crypto_card_loaded();
+void create_hw_info();
+int check_hw(int algo_id);
+unsigned int silent = 0;
+void check_icastats(int algo_id, char *stat);
+void des_tests(unsigned char *iv, unsigned char *cmac, unsigned char *ctr);
+void tdes_tests(unsigned char *iv, unsigned char *cmac, unsigned char *ctr);
+void sha_tests();
+void rsa_tests(ica_adapter_handle_t handle);
+void aes_tests(unsigned char *iv, unsigned char *cmac, unsigned char *ctr);
+
+int main (int argc, char **argv)
+{
+ int rc = 0;
+ ica_adapter_handle_t adapter_handle;
+
+ if (argc > 1) {
+ if (strstr(argv[1], "silent"))
+ silent = 1;
+ }
+
+ unsigned char *cmac;
+ unsigned char *ctr;
+ unsigned char *iv;
+
+ if((cmac = malloc(AES_CIPHER_BLOCK*sizeof(char))) == NULL){
+ perror("Error in malloc: ");
+ exit(EXIT_FAILURE);
+ }
+ if((ctr = malloc(AES_CIPHER_BLOCK*sizeof(char))) == NULL){
+ perror("Error in malloc: ");
+ exit(EXIT_FAILURE);
+ }
+
+ if((iv = malloc(AES_CIPHER_BLOCK*sizeof(char))) == NULL){
+ perror("Error in malloc: ");
+ exit(EXIT_FAILURE);
+ }
+
+ /*
+ * Open crypto adapter
+ **/
+ rc = ica_open_adapter(&adapter_handle);
+ if (rc != 0) {
+ printf("ica_open_adapter failed and returned %d (0x%x).\n", rc, rc);
+ }
+
+ create_hw_info();
+
+
+ /*
+ * Reset Counters
+ **/
+ system("icastats -r");
+ rc = ica_random_number_generate(AES_CIPHER_BLOCK, ctr);
+ if (rc)
+ exit(handle_ica_error(rc, "ica_random_number_generate"));
+
+ /*
+ * Check if counter for Random operations has incremneted
+ **/
+ check_icastats(P_RNG, "P_RNG");
+
+ rc = ica_random_number_generate(AES_CIPHER_BLOCK, iv);
+ if (rc)
+ exit(handle_ica_error(rc, "ica_random_number_generate"));
+
+ /*
+ * Check counters for all crypto operations
+ **/
+ des_tests(iv, cmac, ctr);
+ tdes_tests(iv, cmac, ctr);
+ sha_tests();
+ rsa_tests(adapter_handle);
+ aes_tests(iv, cmac, ctr);
+
+ free(cmac);
+ free(ctr);
+ free(iv);
+
+ printf("All icastats testcases finished successfully\n");
+ return 0;
+}
+
+
+int is_crypto_card_loaded()
+{
+ DIR* sysDir;
+ FILE *file;
+ char dev[PATH_MAX] = "/sys/devices/ap/";
+ struct dirent *direntp;
+ char *type = NULL;
+ size_t size;
+ char c;
+
+ if ((sysDir = opendir(dev)) == NULL )
+ return 0;
+
+ while((direntp = readdir(sysDir)) != NULL){
+ if(strstr(direntp->d_name, "card") != 0){
+ snprintf(dev, PATH_MAX, "/sys/devices/ap/%s/type",
+ direntp->d_name);
+
+ if ((file = fopen(dev, "r")) == NULL){
+ closedir(sysDir);
+ return 0;
+ }
+
+ if (getline(&type, &size, file) == -1){
+ fclose(file);
+ closedir(sysDir);
+ return 0;
+ }
+
+ /* ignore \n
+ * looking for CEX??A and CEX??C
+ * Skip type CEX??P cards
+ **/
+ if (type[strlen(type)-2] == 'P'){
+ free(type);
+ type = NULL;
+ fclose(file);
+ continue;
+ }
+ free(type);
+ type = NULL;
+ fclose(file);
+
+ snprintf(dev, PATH_MAX, "/sys/devices/ap/%s/online",
+ direntp->d_name);
+ if ((file = fopen(dev, "r")) == NULL){
+ closedir(sysDir);
+ return 0;
+ }
+ if((c = fgetc(file)) == '1'){
+ fclose(file);
+ return 1;
+ }
+ fclose(file);
+ }
+ }
+ closedir(sysDir);
+ return 0;
+}
+
+/*
+ * Create Hardware Info database
+ **/
+void create_hw_info()
+{
+ if (ica_get_functionlist(NULL, &mech_len) != 0){
+ perror("get_functionlist: ");
+ exit(EXIT_FAILURE);
+ }
+ pmech_list = malloc(sizeof(libica_func_list_element)*mech_len);
+ if (ica_get_functionlist(pmech_list, &mech_len) != 0){
+ perror("get_functionlist: ");
+ free(pmech_list);
+ exit(EXIT_FAILURE);
+ }
+
+ hw_flag = is_crypto_card_loaded();
+}
+
+/*
+ * check if a cryptp operation is supported in hardware
+ **/
+int check_hw(int algo_id)
+{
+ int i = 0;
+ while(pmech_list[i].mech_mode_id != algo_id)
+ i++;
+
+ if(hw_flag){
+ if(pmech_list[i].flags & (ICA_FLAG_SHW | ICA_FLAG_DHW))
+ return 1;
+ else
+ return 0;
+ } else{
+ if(pmech_list[i].flags & ICA_FLAG_SHW)
+ return 1;
+ else
+ return 0;
+ }
+}
+
+/*
+ * Check if icastats has counted correctly
+ **/
+void check_icastats(int algo_id, char *stat)
+{
+ char awk[255];
+ FILE *fp;
+ int i, hw, enc, dec;
+
+ hw = check_hw(algo_id);
+ sprintf(awk, "icastats | awk '{ if($0~\"%s\") if(NR>13) print $%d,$%d;\
+ else print $%d,-1\
+ }'",
+ stat, hw?4:7, hw?5:8, hw?3:5);
+
+ fp = popen(awk,"r");
+ if(fp == NULL){
+ perror("error in peopen");
+ exit(EXIT_FAILURE);
+ }
+
+ fscanf(fp, "%d %d", &enc, &dec);
+ if(dec == -1){
+ if(enc == 0){
+ printf("Test %s FAILED: Could not count crypto operations!\n",
+ stat);
+ } else if(enc > 0){
+ if (!silent)
+ printf("Test %s SUCCESS.\n", stat);
+ } else{
+ fprintf(stderr, "icastats parsing by %s FAILED!\n", stat);
+ exit(EXIT_FAILURE);
+ }
+ } else{
+ if(enc > 0 && dec > 0){
+ if (!silent)
+ printf("Test %s SUCCESS.\n", stat);
+ } else if(enc == 0 && dec == 0){
+ printf("Test %s FAILED: Could not count crypto operation!\n",
+ stat);
+ } else if(enc == 0){
+ printf("Test %s FAILED: Could not count encryption operations\n",
+ stat);
+ } else if(dec == 0){
+ printf("Test %s FAILED: Could not count decryption operations\n",
+ stat);
+ } else{
+ fprintf(stderr, "icastats parsing of %s FAILED!\n", stat);
+ exit(EXIT_FAILURE);
+ }
+ }
+ if((i = pclose(fp)) != 0){
+ fprintf(stderr, "awk script failed with %d", i);
+ exit(EXIT_FAILURE);
+ }
+}
+
+static int handle_ica_error(int rc, char *message)
+{
+ printf("Error in %s: ", message);
+ switch (rc) {
+ case 0:
+ printf("OK\n");
+ break;
+ case EINVAL:
+ printf("Incorrect parameter.\n");
+ break;
+ case EPERM:
+ printf("Operation not permitted by Hardware.\n");
+ break;
+ case EIO:
+ printf("I/O error.\n");
+ break;
+ default:
+ perror("");
+ }
+ return rc;
+}
+
+
+
+void des_tests(unsigned char *iv, unsigned char *cmac, unsigned char *ctr)
+{
+ int rc = 0;
+ int mode;
+ unsigned char *out_buffer;
+ unsigned char *inp_buffer = plain_data;
+ unsigned char des_key[] = {
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ };
+
+ if((out_buffer = malloc(DATA_LENGHT*sizeof(char))) == NULL){
+ perror("Error in malloc: ");
+ exit(EXIT_FAILURE);
+ }
+
+
+ system("icastats -r");
+ for(mode = 1; mode >= 0; mode--){
+ rc = ica_des_ecb(inp_buffer, out_buffer, DATA_LENGHT,
+ des_key, mode);
+ if (rc)
+ exit(handle_ica_error(rc, "ica_des_ecb"));
+
+ if(mode == ICA_ENCRYPT)
+ inp_buffer = out_buffer;
+ else if(mode == ICA_DECRYPT)
+ inp_buffer = plain_data;
+ }
+ check_icastats(DES_ECB, "DES ECB");
+
+ system("icastats -r");
+ for(mode = 1; mode >= 0; mode--){
+ rc = ica_des_cbc(inp_buffer, out_buffer, DATA_LENGHT,
+ des_key, iv, mode);
+ if(rc)
+ exit(handle_ica_error(rc, "ica_des_ecb"));
+
+ if(mode == ICA_ENCRYPT)
+ inp_buffer = out_buffer;
+ else if(mode == ICA_DECRYPT)
+ inp_buffer = plain_data;
+ }
+ check_icastats(DES_CBC, "DES CBC");
+
+ system("icastats -r");
+ for(mode = 1; mode >= 0; mode--){
+ rc = ica_des_cfb(inp_buffer, out_buffer, DATA_LENGHT,
+ des_key, iv, DES_CIPHER_BLOCK, mode);
+ if(rc)
+ exit(handle_ica_error(rc, "ica_des_cfb"));
+
+ if(mode == ICA_ENCRYPT)
+ inp_buffer = out_buffer;
+ else if(mode == ICA_DECRYPT)
+ inp_buffer = plain_data;
+ }
+ check_icastats(DES_CFB, "DES CFB");
+
+ system("icastats -r");
+ for(mode = 1; mode >= 0; mode--){
+ rc = ica_des_cmac(inp_buffer, DATA_LENGHT, cmac, DES_CIPHER_BLOCK,
+ des_key, mode);
+ if(rc)
+ exit(handle_ica_error(rc, "ica_des_cmac"));
+ }
+ check_icastats(DES_CMAC, "DES CMAC");
+
+ system("icastats -r");
+ for(mode = 1; mode >= 0; mode--){
+ rc = ica_des_ctr(inp_buffer, out_buffer, DATA_LENGHT, des_key,
+ ctr, DES_CIPHER_BLOCK, mode);
+ if(rc)
+ exit(handle_ica_error(rc, "ica_des_ctr"));
+
+ if(mode == ICA_ENCRYPT)
+ inp_buffer = out_buffer;
+ else if(mode == ICA_DECRYPT)
+ inp_buffer = plain_data;
+ }
+ check_icastats(DES_CTR, "DES CTR");
+
+ system("icastats -r");
+ for(mode = 1; mode >= 0; mode--){
+ rc = ica_des_ofb(inp_buffer, out_buffer, DATA_LENGHT,
+ des_key, iv, mode);
+ if(rc)
+ exit(handle_ica_error(rc, "ica_des_ofb"));
+
+ if(mode == ICA_ENCRYPT)
+ inp_buffer = out_buffer;
+ else if(mode == ICA_DECRYPT)
+ inp_buffer = plain_data;
+ }
+ check_icastats(DES_OFB, "DES OFB");
+
+ free(out_buffer);
+}
+
+void tdes_tests(unsigned char *iv, unsigned char *cmac, unsigned char *ctr)
+{
+ int rc = 0;
+ int mode;
+ unsigned char *out_buffer;
+ unsigned char *inp_buffer = plain_data;
+ unsigned char des_key[] = {
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ };
+
+ if((out_buffer = malloc(DATA_LENGHT*sizeof(char))) == NULL){
+ perror("Error in malloc: ");
+ exit(EXIT_FAILURE);
+ }
+
+ system("icastats -r");
+ for(mode = 1; mode >= 0; mode--){
+ rc = ica_3des_ecb(inp_buffer, out_buffer, DATA_LENGHT,
+ des_key, mode);
+ if (rc)
+ exit(handle_ica_error(rc, "ica_3des_ecb"));
+
+ if(mode == ICA_ENCRYPT)
+ inp_buffer = out_buffer;
+ else if(mode == ICA_DECRYPT)
+ inp_buffer = plain_data;
+ }
+ check_icastats(DES3_ECB, "3DES ECB");
+
+ system("icastats -r");
+ for(mode = 1; mode >= 0; mode--){
+ rc = ica_3des_cbc(inp_buffer, out_buffer, DATA_LENGHT,
+ des_key, iv, mode);
+ if(rc)
+ exit(handle_ica_error(rc, "ica_3des_cbc"));
+
+ if(mode == ICA_ENCRYPT)
+ inp_buffer = out_buffer;
+ else if(mode == ICA_DECRYPT)
+ inp_buffer = plain_data;
+ }
+ check_icastats(DES3_CBC, "3DES CBC");
+
+ system("icastats -r");
+ for(mode = 1; mode >= 0; mode--){
+ rc = ica_3des_cfb(inp_buffer, out_buffer, DATA_LENGHT,
+ des_key, iv, DES_CIPHER_BLOCK, mode);
+ if(rc)
+ exit(handle_ica_error(rc, "ica_3des_cfb"));
+
+ if(mode == ICA_ENCRYPT)
+ inp_buffer = out_buffer;
+ else if(mode == ICA_DECRYPT)
+ inp_buffer = plain_data;
+ }
+ check_icastats(DES3_CFB, "3DES CFB");
+
+ system("icastats -r");
+ for(mode = 1; mode >= 0; mode--){
+ rc = ica_3des_cmac(inp_buffer, DATA_LENGHT, cmac, DES_CIPHER_BLOCK,
+ des_key, mode);
+ if(rc)
+ exit(handle_ica_error(rc, "ica_3des_cmac"));
+ }
+ check_icastats(DES3_CMAC, "3DES CMAC");
+
+ system("icastats -r");
+ for(mode = 1; mode >= 0; mode--){
+ rc = ica_3des_ctr(inp_buffer, out_buffer, DATA_LENGHT, des_key,
+ ctr, DES_CIPHER_BLOCK, mode);
+ if(rc)
+ exit(handle_ica_error(rc, "ica_3des_ctr"));
+
+ if(mode == ICA_ENCRYPT)
+ inp_buffer = out_buffer;
+ else if(mode == ICA_DECRYPT)
+ inp_buffer = plain_data;
+ }
+ check_icastats(DES3_CTR, "3DES CTR");
+
+ system("icastats -r");
+ for(mode = 1; mode >= 0; mode--){
+ rc = ica_3des_ofb(inp_buffer, out_buffer, DATA_LENGHT,
+ des_key, iv, mode);
+ if(rc)
+ exit(handle_ica_error(rc, "ica_3des_ofb"));
+
+ if(mode == ICA_ENCRYPT)
+ inp_buffer = out_buffer;
+ else if(mode == ICA_DECRYPT)
+ inp_buffer = plain_data;
+ }
+ check_icastats(DES3_OFB, "3DES OFB");
+
+ free(out_buffer);
+}
+
+void sha_tests()
+{
+ int rc = 0;
+ unsigned char hash[SHA512_HASH_LENGTH];
+
+ sha_context_t sha_context0;
+ sha256_context_t sha_context1;
+ sha512_context_t sha_context2;
+
+
+ system("icastats -r");
+ rc = ica_sha1(SHA_MSG_PART_ONLY, DATA_LENGHT,
+ plain_data, &sha_context0, hash);
+ if(rc)
+ exit(handle_ica_error(rc, "ica_sha1"));
+ check_icastats(SHA1, "SHA-1");
+
+ system("icastats -r");
+ rc = ica_sha224(SHA_MSG_PART_ONLY, DATA_LENGHT,
+ plain_data, &sha_context1, hash);
+ if(rc)
+ exit(handle_ica_error(rc, "ica_sha224"));
+ check_icastats(SHA224, "SHA-224");
+
+ system("icastats -r");
+ rc = ica_sha256(SHA_MSG_PART_ONLY, DATA_LENGHT,
+ plain_data, &sha_context1, hash);
+ if(rc)
+ exit(handle_ica_error(rc, "ica_sha256"));
+ check_icastats(SHA256, "SHA-256");
+
+ system("icastats -r");
+ rc = ica_sha384(SHA_MSG_PART_ONLY, DATA_LENGHT,
+ plain_data, &sha_context2, hash);
+ if(rc)
+ exit(handle_ica_error(rc, "ica_sha384"));
+ check_icastats(SHA384, "SHA-384");
+
+ system("icastats -r");
+ rc = ica_sha512(SHA_MSG_PART_ONLY, DATA_LENGHT,
+ plain_data, &sha_context2, hash);
+ if(rc)
+ exit(handle_ica_error(rc, "ica_sha512"));
+ check_icastats(SHA512, "SHA-512");
+}
+
+void rsa_tests(ica_adapter_handle_t handle)
+{
+
+unsigned char e[] =
+ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03 };
+
+unsigned char n[] =
+ { 0xec, 0x51, 0xab, 0xa1, 0xf8, 0x40, 0x2c, 0x08,
+ 0x2e, 0x24, 0x52, 0x2e, 0x3c, 0x51, 0x6d, 0x98,
+ 0xad, 0xee, 0xc7, 0x7d, 0x00, 0xaf, 0xe1, 0xa8,
+ 0x61, 0xda, 0x32, 0x97, 0xb4, 0x32, 0x97, 0xe3,
+ 0x52, 0xda, 0x28, 0x45, 0x55, 0xc6, 0xb2, 0x46,
+ 0x65, 0x1b, 0x02, 0xcb, 0xbe, 0xf4, 0x2c, 0x6b,
+ 0x2a, 0x5f, 0xe1, 0xdf, 0xe9, 0xe3, 0xbc, 0x47,
+ 0xb7, 0x38, 0xb5, 0xa2, 0x78, 0x9d, 0x15, 0xe2,
+ 0x59, 0x81, 0x77, 0x6b, 0x6b, 0x2e, 0xa9, 0xdb,
+ 0x13, 0x26, 0x9c, 0xca, 0x5e, 0x0a, 0x1f, 0x3c,
+ 0x50, 0x9d, 0xd6, 0x79, 0x59, 0x99, 0x50, 0xe5,
+ 0x68, 0x1a, 0x98, 0xca, 0x11, 0xce, 0x37, 0x63,
+ 0x58, 0x22, 0x40, 0x19, 0x29, 0x72, 0x4c, 0x41,
+ 0x89, 0x0b, 0x56, 0x9e, 0x3e, 0xd5, 0x6d, 0x75,
+ 0x9e, 0x3f, 0x8a, 0x50, 0xf1, 0x0a, 0x59, 0x4a,
+ 0xc3, 0x59, 0x4b, 0xf6, 0xbb, 0xc9, 0xa5, 0x93 };
+
+unsigned char input_data[] =
+ { 0x00, 0x02, 0x08, 0x68, 0x30, 0x9a, 0x32, 0x08,
+ 0x57, 0xb0, 0x28, 0xaa, 0x76, 0x30, 0x3d, 0x84,
+ 0x5f, 0x92, 0x0d, 0x8e, 0x34, 0xe0, 0xd5, 0xcc,
+ 0x36, 0x97, 0xed, 0x00, 0x00, 0x01, 0x02, 0x03,
+ 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
+ 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13,
+ 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b,
+ 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23,
+ 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b,
+ 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33,
+ 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b,
+ 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43,
+ 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b,
+ 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53,
+ 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b,
+ 0x5c, 0x5d, 0x5e, 0x5f, 0x60, 0x61, 0x62, 0x63 };
+
+unsigned char p[] =
+ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0xfb, 0xb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
+ unsigned char *output_data;
+ unsigned char *data = input_data;
+ int rc = 0;
+
+ if((output_data = malloc(RSA_BYTE_LENGHT*sizeof(char))) == NULL){
+ perror("error in malloc: ");
+ exit(EXIT_FAILURE);
+ }
+
+ ica_rsa_key_mod_expo_t mod_expo_key= {RSA_BYTE_LENGHT, n, e};
+ ica_rsa_key_crt_t crt_key = {RSA_BYTE_LENGHT, p, q, dp, dq, qinv};
+
+ system("icastats -r");
+ rc = ica_rsa_mod_expo(handle, data, &mod_expo_key,
+ output_data);
+ if(rc)
+ exit(handle_ica_error(rc, "ica_rsa_key_mod_expo"));
+ check_icastats(RSA_ME, "RSA-ME");
+
+ system("icastats -r");
+ rc = ica_rsa_crt(handle, data, &crt_key,
+ output_data);
+ if(rc)
+ exit(handle_ica_error(rc, "ica_rsa_crt"));
+ check_icastats(RSA_CRT, "RSA-CRT");
+
+ free(output_data);
+}
+
+void aes_tests(unsigned char *iv, unsigned char *cmac, unsigned char *ctr)
+{
+ int rc = 0;
+ int mode;
+ unsigned char *output_buffer, *tag, *nonce;
+ unsigned char *input_buffer = plain_data;
+
+
+
+ unsigned char aes_key[] = {
+ 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
+ 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c,
+
+ };
+
+ unsigned char tweak[] = {
+ 0x72, 0xf3, 0xb0, 0x54, 0xcb, 0xdc, 0x2f, 0x9e,
+ 0x3c, 0x5b, 0xc5, 0x51, 0xd4, 0x4d, 0xdb, 0xa0,
+ };
+
+ #define NONCE_LENGHT 10
+
+ if((nonce = malloc(NONCE_LENGHT*sizeof(char))) == NULL){
+ perror("Error in malloc: ");
+ exit(EXIT_FAILURE);
+ }
+
+ if((tag = malloc(AES_CIPHER_BLOCK*sizeof(char))) == NULL){
+ perror("Error in malloc: ");
+ exit(EXIT_FAILURE);
+ }
+
+ if((output_buffer = malloc((DATA_LENGHT+AES_CIPHER_BLOCK)
+ *sizeof(char))) == NULL){
+ perror("Error in malloc: ");
+ exit(EXIT_FAILURE);
+ }
+
+ system("icastats -r");
+ for(mode = 1;mode >= 0;mode--){
+ rc = ica_aes_cbc(input_buffer, output_buffer, DATA_LENGHT,
+ aes_key, AES_KEY_LEN128, iv, mode);
+ if(rc)
+ exit(handle_ica_error(rc, "ica_aes_cbc"));
+ if(mode == ICA_ENCRYPT)
+ input_buffer = output_buffer;
+ else if(mode == ICA_DECRYPT)
+ input_buffer = plain_data;
+ }
+ check_icastats(AES_CBC, "AES CBC");
+
+ system("icastats -r");
+ for(mode = 1;mode >= 0;mode--){
+ rc = ica_aes_cfb(input_buffer, output_buffer, DATA_LENGHT,
+ aes_key, AES_KEY_LEN128, iv, AES_CIPHER_BLOCK,
+ mode);
+ if(rc)
+ exit(handle_ica_error(rc, "ica_aes_cfb"));
+
+ if(mode == ICA_ENCRYPT)
+ input_buffer = output_buffer;
+ else if(mode == ICA_DECRYPT)
+ input_buffer = plain_data;
+ }
+ check_icastats(AES_CFB, "AES CFB");
+
+ system("icastats -r");
+ for(mode = 1;mode >= 0;mode--){
+ rc = ica_aes_cmac(input_buffer, DATA_LENGHT, cmac,
+ AES_CIPHER_BLOCK, aes_key,
+ AES_KEY_LEN128, mode);
+ if(rc)
+ exit(handle_ica_error(rc, "ica_aes_cmac"));
+ }
+ check_icastats(AES_CMAC, "AES CMAC");
+
+ system("icastats -r");
+ for(mode = 1;mode >= 0;mode--){
+ rc = ica_aes_ctr(input_buffer, output_buffer, DATA_LENGHT,
+ aes_key, AES_KEY_LEN128, ctr, AES_CIPHER_BLOCK,
+ mode);
+ if(rc)
+ exit(handle_ica_error(rc, "ica_aes_ctr"));
+
+ if(mode == ICA_ENCRYPT)
+ input_buffer = output_buffer;
+ else if(mode == ICA_DECRYPT)
+ input_buffer = plain_data;
+ }
+ check_icastats(AES_CTR, "AES CTR");
+
+ system("icastats -r");
+ for(mode = 1;mode >= 0;mode--){
+ rc = ica_aes_ecb(input_buffer, output_buffer, DATA_LENGHT,
+ aes_key, AES_KEY_LEN128, mode);
+ if (rc)
+ exit(handle_ica_error(rc, "ica_aes_ecb"));
+
+ if(mode == ICA_ENCRYPT)
+ input_buffer = output_buffer;
+ else if(mode == ICA_DECRYPT)
+ input_buffer = plain_data;
+ }
+ check_icastats(AES_ECB, "AES ECB");
+
+ system("icastats -r");
+ for(mode = 1;mode >= 0;mode--){
+ rc = ica_aes_ofb(input_buffer, output_buffer, DATA_LENGHT,
+ aes_key, AES_KEY_LEN128, iv, mode);
+
+ if(rc)
+ exit(handle_ica_error(rc, "ica_aes_ofb"));
+
+ if(mode == ICA_ENCRYPT)
+ input_buffer = output_buffer;
+ else if(mode == ICA_DECRYPT)
+ input_buffer = plain_data;
+ }
+ check_icastats(AES_OFB, "AES OFB");
+
+ system("icastats -r");
+ for(mode = 1;mode >= 0;mode--){
+ rc = ica_aes_xts(input_buffer, output_buffer, DATA_LENGHT,
+ aes_key, aes_key, AES_KEY_LEN128, tweak, mode);
+
+ if(rc)
+ exit(handle_ica_error(rc, "ica_aes_xts"));
+
+ if(mode == ICA_ENCRYPT)
+ input_buffer = output_buffer;
+ else if(mode == ICA_DECRYPT)
+ input_buffer = plain_data;
+ }
+ check_icastats(AES_XTS, "AES XTS");
+
+ free(tag);
+ free(output_buffer);
+ free(nonce);
+}
+
+
+
diff --git a/src/tests/libica_3des_cbc_test.c b/src/tests/libica_3des_cbc_test.c
new file mode 100644
index 0000000..79d283e
--- /dev/null
+++ b/src/tests/libica_3des_cbc_test.c
@@ -0,0 +1,181 @@
+/* This program is released under the Common Public License V1.0
+ *
+ * You should have received a copy of Common Public License V1.0 along with
+ * with this program.
+ */
+
+/* Copyright IBM Corp. 2010, 2011 */
+#include <fcntl.h>
+#include <sys/errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+#include <stdlib.h>
+#include "ica_api.h"
+
+#define NR_RANDOM_TESTS 10000
+
+void dump_array(unsigned char *ptr, unsigned int size)
+{
+ unsigned char *ptr_end;
+ unsigned char *h;
+ int i = 1;
+
+ h = ptr;
+ ptr_end = ptr + size;
+ while (h < (unsigned char *)ptr_end) {
+ printf("0x%02x ",(unsigned char ) *h);
+ h++;
+ if (i == 8) {
+ printf("\n");
+ i = 1;
+ } else {
+ ++i;
+ }
+ }
+ printf("\n");
+}
+
+void dump_cbc_data(unsigned char *iv, unsigned int iv_length,
+ unsigned char *key, unsigned int key_length,
+ unsigned char *input_data, unsigned int data_length,
+ unsigned char *output_data)
+{
+ printf("IV \n");
+ dump_array(iv, iv_length);
+ printf("Key \n");
+ dump_array(key, key_length);
+ printf("Input Data\n");
+ dump_array(input_data, data_length);
+ printf("Output Data\n");
+ dump_array(output_data, data_length);
+}
+
+int load_random_test_data(unsigned char *data, unsigned int data_length,
+ unsigned char *iv, unsigned int iv_length,
+ unsigned char *key, unsigned int key_length)
+{
+ int rc;
+ rc = ica_random_number_generate(data_length, data);
+ if (rc) {
+ printf("ica_random_number_generate with rc = %i errnor = %i\n",
+ rc, errno);
+ return rc;
+ }
+ rc = ica_random_number_generate(iv_length, iv);
+ if (rc) {
+ printf("ica_random_number_generate with rc = %i errnor = %i\n",
+ rc, errno);
+ return rc;
+ }
+ rc = ica_random_number_generate(key_length, key);
+ if (rc) {
+ printf("ica_random_number_generate with rc = %i errnor = %i\n",
+ rc, errno);
+ return rc;
+ }
+ return rc;
+}
+
+int random_3des_cbc(int iteration, int silent, unsigned int data_length)
+{
+ unsigned int iv_length = sizeof(ica_des_vector_t);
+ unsigned int key_length = sizeof(ica_des_key_triple_t);
+
+ unsigned char iv[iv_length];
+ unsigned char tmp_iv[iv_length];
+ unsigned char key[key_length];
+ unsigned char input_data[data_length];
+ unsigned char encrypt[data_length];
+ unsigned char decrypt[data_length];
+
+ int rc = 0;
+ memset(encrypt, 0x00, data_length);
+ memset(decrypt, 0x00, data_length);
+
+ load_random_test_data(input_data, data_length, iv, iv_length, key,
+ key_length);
+ memcpy(tmp_iv, iv, iv_length);
+
+ if (!silent) {
+ printf("Test Parameters for iteration = %i\n", iteration);
+ printf("key length = %i, data length = %i, iv length = %i\n",
+ key_length, data_length, iv_length);
+ }
+
+ rc = ica_3des_cbc(input_data, encrypt, data_length, key, tmp_iv, 1);
+ if (rc) {
+ printf("ica_3des_cbc encrypt failed with rc = %i\n", rc);
+ dump_cbc_data(iv, iv_length, key, key_length, input_data,
+ data_length, encrypt);
+ }
+ if (!silent && !rc) {
+ printf("Encrypt:\n");
+ dump_cbc_data(iv, iv_length, key, key_length, input_data,
+ data_length, encrypt);
+ }
+
+ if (rc) {
+ printf("3DES CBC test exited after encryption\n");
+ return rc;
+ }
+
+ memcpy(tmp_iv, iv, iv_length);
+
+ rc = ica_3des_cbc(encrypt, decrypt, data_length, key, tmp_iv,
+ 0);
+ if (rc) {
+ printf("ica_3des_cbc decrypt failed with rc = %i\n", rc);
+ dump_cbc_data(iv, iv_length, key, key_length, encrypt,
+ data_length, decrypt);
+ return rc;
+ }
+
+
+ if (!silent && !rc) {
+ printf("Decrypt:\n");
+ dump_cbc_data(iv, iv_length, key, key_length, encrypt,
+ data_length, decrypt);
+ }
+
+ if (memcmp(decrypt, input_data, data_length)) {
+ printf("Decryption Result does not match the original data!\n");
+ printf("Original data:\n");
+ dump_array(input_data, data_length);
+ printf("Decryption Result:\n");
+ dump_array(decrypt, data_length);
+ rc++;
+ }
+ return rc;
+}
+
+int main(int argc, char **argv)
+{
+ // Default mode is 0. ECB,CBC and CFQ tests will be performed.
+ unsigned int silent = 0;
+ if (argc > 1) {
+ if (strstr(argv[1], "silent"))
+ silent = 1;
+ }
+ int rc = 0;
+ int error_count = 0;
+ int iteration;
+ unsigned int data_length = sizeof(ica_des_vector_t);
+ for(iteration = 1; iteration <= NR_RANDOM_TESTS; iteration++) {
+ rc = random_3des_cbc(iteration, silent, data_length);
+ if (rc) {
+ printf("random_3des_cbc failed with rc = %i\n", rc);
+ error_count++;
+ goto out;
+ }
+ data_length += sizeof(ica_des_vector_t);
+ }
+out:
+ if (error_count)
+ printf("%i testcases failed\n", error_count);
+ else
+ printf("All 3des_cbc testcases finished successfully\n");
+
+ return rc;
+}
+
diff --git a/src/tests/libica_3des_cfb_test.c b/src/tests/libica_3des_cfb_test.c
new file mode 100644
index 0000000..44ad1e0
--- /dev/null
+++ b/src/tests/libica_3des_cfb_test.c
@@ -0,0 +1,204 @@
+/* This program is released under the Common Public License V1.0
+ *
+ * You should have received a copy of Common Public License V1.0 along with
+ * with this program.
+ */
+
+/* Copyright IBM Corp. 2010, 2011 */
+#include <fcntl.h>
+#include <sys/errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+#include <stdlib.h>
+#include "ica_api.h"
+
+#define NR_TESTS 12
+#define NR_RANDOM_TESTS 1000
+
+void dump_array(unsigned char *ptr, unsigned int size)
+{
+ unsigned char *ptr_end;
+ unsigned char *h;
+ int i = 1;
+
+ h = ptr;
+ ptr_end = ptr + size;
+ while (h < (unsigned char *)ptr_end) {
+ printf("0x%02x ",(unsigned char ) *h);
+ h++;
+ if (i == 8) {
+ printf("\n");
+ i = 1;
+ } else {
+ ++i;
+ }
+ }
+ printf("\n");
+}
+
+void dump_cfb_data(unsigned char *iv, unsigned int iv_length,
+ unsigned char *key, unsigned int key_length,
+ unsigned char *input_data, unsigned int data_length,
+ unsigned char *output_data)
+{
+ printf("IV \n");
+ dump_array(iv, iv_length);
+ printf("Key \n");
+ dump_array(key, key_length);
+ printf("Input Data\n");
+ dump_array(input_data, data_length);
+ printf("Output Data\n");
+ dump_array(output_data, data_length);
+}
+
+int load_random_test_data(unsigned char *data, unsigned int data_length,
+ unsigned char *iv, unsigned int iv_length,
+ unsigned char *key, unsigned int key_length)
+{
+ int rc;
+ rc = ica_random_number_generate(data_length, data);
+ if (rc) {
+ printf("ica_random_number_generate with rc = %i errnor = %i\n",
+ rc, errno);
+ return rc;
+ }
+ rc = ica_random_number_generate(iv_length, iv);
+ if (rc) {
+ printf("ica_random_number_generate with rc = %i errnor = %i\n",
+ rc, errno);
+ return rc;
+ }
+ rc = ica_random_number_generate(key_length, key);
+ if (rc) {
+ printf("ica_random_number_generate with rc = %i errnor = %i\n",
+ rc, errno);
+ return rc;
+ }
+ return rc;
+}
+
+int random_des_cfb(int iteration, int silent, unsigned int data_length,
+ unsigned int lcfb)
+{
+ unsigned int iv_length = sizeof(ica_des_vector_t);
+ unsigned int key_length = sizeof(ica_des_key_triple_t);
+
+ unsigned char iv[iv_length];
+ unsigned char tmp_iv[iv_length];
+ unsigned char key[key_length];
+ unsigned char input_data[data_length];
+ unsigned char encrypt[data_length];
+ unsigned char decrypt[data_length];
+
+ int rc = 0;
+ memset(encrypt, 0x00, data_length);
+ memset(decrypt, 0x00, data_length);
+
+ load_random_test_data(input_data, data_length, iv, iv_length, key,
+ key_length);
+ memcpy(tmp_iv, iv, iv_length);
+
+ if (!silent) {
+ printf("Test Parameters for iteration = %i\n", iteration);
+ printf("key length = %i, data length = %i, iv length = %i,"
+ " lcfb = %i\n", key_length, data_length, iv_length, lcfb);
+ }
+
+ rc = ica_3des_cfb(input_data, encrypt, data_length, key, tmp_iv, lcfb,
+ 1);
+ if (rc) {
+ printf("ica_3des_cfb encrypt failed with rc = %i\n", rc);
+ dump_cfb_data(iv, iv_length, key, key_length, input_data,
+ data_length, encrypt);
+ }
+ if (!silent && !rc) {
+ printf("Encrypt:\n");
+ dump_cfb_data(iv, iv_length, key, key_length, input_data,
+ data_length, encrypt);
+ }
+
+ if (rc) {
+ printf("3DES OFB test exited after encryption\n");
+ return rc;
+ }
+
+ memcpy(tmp_iv, iv, iv_length);
+
+ rc = ica_3des_cfb(encrypt, decrypt, data_length, key, tmp_iv,
+ lcfb, 0);
+ if (rc) {
+ printf("ica_3des_cfb decrypt failed with rc = %i\n", rc);
+ dump_cfb_data(iv, iv_length, key, key_length, encrypt,
+ data_length, decrypt);
+ return rc;
+ }
+
+
+ if (!silent && !rc) {
+ printf("Decrypt:\n");
+ dump_cfb_data(iv, iv_length, key, key_length, encrypt,
+ data_length, decrypt);
+ }
+
+ if (memcmp(decrypt, input_data, data_length)) {
+ printf("Decryption Result does not match the original data!\n");
+ printf("Original data:\n");
+ dump_array(input_data, data_length);
+ printf("Decryption Result:\n");
+ dump_array(decrypt, data_length);
+ rc++;
+ }
+ return rc;
+}
+
+int main(int argc, char **argv)
+{
+ int rc = 0;
+ int error_count = 0;
+ int iteration;
+ unsigned int silent = 0;
+ unsigned int rdata;
+ unsigned int data_length = 1;
+ unsigned int lcfb = 1;
+ unsigned int j;
+
+ if (argc > 1) {
+ if (strstr(argv[1], "silent"))
+ silent = 1;
+ }
+
+ for(iteration = 1; iteration <= NR_RANDOM_TESTS; iteration++) {
+ for (j = 1; j <= 2; j++) {
+ if (!(data_length % lcfb)) {
+ rc = random_des_cfb(iteration, silent, data_length, lcfb);
+ if (rc) {
+ printf("random_des_cfb failed with rc = %i\n", rc);
+ error_count++;
+ }
+ }
+ switch (j) {
+ case 1:
+ lcfb = 1;
+ break;
+ case 2:
+ lcfb = 8;
+ break;
+ }
+ }
+ // add a value between 1 and 8 to data_length
+ if (ica_random_number_generate(sizeof(rdata), (unsigned char*) &rdata)) {
+ printf("ica_random_number_generate failed with errnor = %i\n",
+ errno);
+ exit(1);
+ }
+ data_length += (rdata % 8) + 1;
+ }
+ if (error_count)
+ printf("%i testcases failed\n", error_count);
+ else
+ printf("All 3des_cfb testcases finished successfully\n");
+
+ return rc;
+}
+
diff --git a/src/tests/libica_3des_ctr_test.c b/src/tests/libica_3des_ctr_test.c
new file mode 100644
index 0000000..636c763
--- /dev/null
+++ b/src/tests/libica_3des_ctr_test.c
@@ -0,0 +1,188 @@
+/* This program is released under the Common Public License V1.0
+ *
+ * You should have received a copy of Common Public License V1.0 along with
+ * with this program.
+ */
+
+/* Copyright IBM Corp. 2010, 2011 */
+#include <fcntl.h>
+#include <sys/errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+#include <stdlib.h>
+#include "ica_api.h"
+
+#define NR_RANDOM_TESTS 1000
+
+void dump_array(unsigned char *ptr, unsigned int size)
+{
+ unsigned char *ptr_end;
+ unsigned char *h;
+ int i = 1;
+
+ h = ptr;
+ ptr_end = ptr + size;
+ while (h < (unsigned char *)ptr_end) {
+ printf("0x%02x ",(unsigned char ) *h);
+ h++;
+ if (i == 8) {
+ printf("\n");
+ i = 1;
+ } else {
+ ++i;
+ }
+ }
+ printf("\n");
+}
+
+void dump_ctr_data(unsigned char *iv, unsigned int iv_length,
+ unsigned char *key, unsigned int key_length,
+ unsigned char *input_data, unsigned int data_length,
+ unsigned char *output_data)
+{
+ printf("IV \n");
+ dump_array(iv, iv_length);
+ printf("Key \n");
+ dump_array(key, key_length);
+ printf("Input Data\n");
+ dump_array(input_data, data_length);
+ printf("Output Data\n");
+ dump_array(output_data, data_length);
+}
+
+int random_3des_ctr(int iteration, int silent, unsigned int data_length)
+{
+ unsigned int key_length = sizeof(ica_des_key_triple_t);
+ unsigned int iv_length = sizeof(ica_des_vector_t);
+
+ if (!silent) {
+ printf("Test Parameters for iteration = %i\n", iteration);
+ printf("key length = %i, data length = %i, iv length = %i\n",
+ key_length, data_length, iv_length);
+ }
+
+ unsigned char iv[iv_length];
+ unsigned char tmp_iv[iv_length];
+ unsigned char key[key_length];
+ unsigned char input_data[data_length];
+ unsigned char encrypt[data_length];
+ unsigned char decrypt[data_length];
+
+ int rc = 0;
+ rc = ica_random_number_generate(data_length, input_data);
+ if (rc) {
+ printf("random number generate returned rc = %i, errno = %i\n", rc, errno);
+ return rc;
+ }
+ rc = ica_random_number_generate(iv_length, iv);
+ if (rc) {
+ printf("random number generate returned rc = %i, errno = %i\n", rc, errno);
+ return rc;
+ }
+
+ rc = ica_random_number_generate(key_length, key);
+ if (rc) {
+ printf("random number generate returned rc = %i, errno = %i\n", rc, errno);
+ return rc;
+ }
+ memcpy(tmp_iv, iv, iv_length);
+
+ rc = ica_3des_ctr(input_data, encrypt, data_length, key, tmp_iv,
+ 32, 1);
+ if (rc) {
+ printf("ica_3des_ctr encrypt failed with rc = %i\n", rc);
+ dump_ctr_data(iv, iv_length, key, key_length, input_data,
+ data_length, encrypt);
+ return rc;
+ }
+ if (!silent && !rc) {
+ printf("Encrypt:\n");
+ dump_ctr_data(iv, iv_length, key, key_length, input_data,
+ data_length, encrypt);
+ }
+
+ memcpy(tmp_iv, iv, iv_length);
+ rc = ica_3des_ctr(encrypt, decrypt, data_length, key, tmp_iv,
+ 32, 0);
+ if (rc) {
+ printf("ica_3des_ctr decrypt failed with rc = %i\n", rc);
+ dump_ctr_data(iv, iv_length, key, key_length, encrypt,
+ data_length, decrypt);
+ return rc;
+ }
+
+
+ if (!silent && !rc) {
+ printf("Decrypt:\n");
+ dump_ctr_data(iv, iv_length, key, key_length, encrypt,
+ data_length, decrypt);
+ }
+
+ if (memcmp(decrypt, input_data, data_length)) {
+ printf("Decryption Result does not match the original data!\n");
+ printf("Original data:\n");
+ dump_array(input_data, data_length);
+ printf("Decryption Result:\n");
+ dump_array(decrypt, data_length);
+ rc++;
+ }
+ return rc;
+}
+
+int main(int argc, char **argv)
+{
+ unsigned int silent = 0;
+ unsigned int endless = 0;
+ unsigned int data_length = 1;
+ unsigned int rdata;
+ int error_count = 0;
+ int i = 0;
+ int rc = 0;
+
+ if (argc > 1) {
+ if (strstr(argv[1], "silent"))
+ silent = 1;
+ if (strstr(argv[1], "endless"))
+ endless = 1;
+ }
+
+ if (endless) {
+ silent = 1;
+ while (1) {
+ printf("i = %i\n",i);
+ rc = random_3des_ctr(i, silent, 320);
+ if (rc) {
+ printf("kat_3des_ctr failed with rc = %i\n",
+ rc);
+ return rc;
+ } else
+ printf("kat_3des_ctr finished successfully\n");
+ i++;
+ }
+ } else {
+ silent = 1;
+ for (i = 1; i < NR_RANDOM_TESTS; i++) {
+ rc = random_3des_ctr(i, silent, data_length);
+ if (rc) {
+ printf("random_3des_ctr failed with rc = %i\n", rc);
+ error_count++;
+ }
+ // add a value between 1 and 8 to data_length
+ if (ica_random_number_generate(sizeof(rdata), (unsigned char*) &rdata)) {
+ printf("ica_random_number_generate failed with errnor = %i\n",
+ errno);
+ exit(1);
+ }
+ data_length += (rdata % 8) + 1;
+ }
+ }
+
+ if (error_count)
+ printf("%i testcases failed\n", error_count);
+ else
+ printf("All 3des_ctr testcases finished successfully\n");
+
+ return rc;
+}
+
diff --git a/src/tests/libica_3des_ecb_test.c b/src/tests/libica_3des_ecb_test.c
new file mode 100644
index 0000000..b5ea610
--- /dev/null
+++ b/src/tests/libica_3des_ecb_test.c
@@ -0,0 +1,320 @@
+/* This program is released under the Common Public License V1.0
+ *
+ * You should have received a copy of Common Public License V1.0 along with
+ * with this program.
+ */
+
+/* Copyright IBM Corp. 2010, 2011 */
+#include <fcntl.h>
+#include <sys/errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+#include <stdlib.h>
+#include "ica_api.h"
+
+#define NR_TESTS 2
+#define NR_RANDOM_TESTS 10000
+
+/* ECB data - 1 for 3DES192 */
+unsigned char NIST_KEY_ECB_E1[] = {
+ 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
+ 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0x01,
+ 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0x01, 0x23,
+};
+
+unsigned char NIST_TEST_DATA_ECB_E1[] = {
+ 0x6B, 0x20, 0x62, 0x72, 0x6F, 0x77, 0x6E, 0x20,
+};
+
+unsigned char NIST_TEST_RESULT_ECB_E1[] = {
+ 0xCC, 0xE2, 0x1C, 0x81, 0x12, 0x25, 0x6F, 0xE6,
+};
+
+/* ECB data - 2 - for 3DES128 */
+unsigned char NIST_KEY_ECB_E2[] = {
+ 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
+ 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0x01,
+ 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0x01, 0x23,
+
+};
+
+unsigned char NIST_TEST_DATA_ECB_E2[] = {
+ 0x54, 0x68, 0x65, 0x20, 0x71, 0x75, 0x66, 0x63,
+ 0x6B, 0x20, 0x62, 0x72, 0x6F, 0x77, 0x6E, 0x20,
+ 0x66, 0x6F, 0x78, 0x20, 0x6A, 0x75, 0x6D, 0x70,
+};
+
+unsigned char NIST_TEST_RESULT_ECB_E2[] = {
+ 0xA8, 0x26, 0xFD, 0x8C, 0xE5, 0x3B, 0x85, 0x5F,
+ 0xCC, 0xE2, 0x1C, 0x81, 0x12, 0x25, 0x6F, 0xE6,
+ 0x68, 0xD5, 0xC0, 0x5D, 0xD9, 0xB6, 0xB9, 0x00,
+};
+
+void dump_array(unsigned char *ptr, unsigned int size)
+{
+ unsigned char *ptr_end;
+ unsigned char *h;
+ int i = 1;
+
+ h = ptr;
+ ptr_end = ptr + size;
+ while (h < (unsigned char *)ptr_end) {
+ printf("0x%02x ",(unsigned char ) *h);
+ h++;
+ if (i == 8) {
+ printf("\n");
+ i = 1;
+ } else {
+ ++i;
+ }
+ }
+ printf("\n");
+}
+
+void dump_ecb_data(unsigned char *key, unsigned int key_length,
+ unsigned char *input_data, unsigned int data_length,
+ unsigned char *output_data)
+{
+ printf("Key \n");
+ dump_array(key, key_length);
+ printf("Input Data\n");
+ dump_array(input_data, data_length);
+ printf("Output Data\n");
+ dump_array(output_data, data_length);
+}
+
+void get_sizes(unsigned int *data_length,
+ unsigned int *key_length, unsigned int iteration)
+{
+ switch (iteration) {
+ case 1:
+ *data_length = sizeof(NIST_TEST_DATA_ECB_E1);
+ *key_length = sizeof(NIST_KEY_ECB_E1);
+ break;
+ case 2:
+ *data_length = sizeof(NIST_TEST_DATA_ECB_E2);
+ *key_length = sizeof(NIST_KEY_ECB_E2);
+ break;
+ }
+
+}
+
+void load_test_data(unsigned char *data, unsigned int data_length,
+ unsigned char *result,
+ unsigned char *key, unsigned int key_length,
+ unsigned int iteration)
+{
+ switch (iteration) {
+ case 1:
+ memcpy(data, NIST_TEST_DATA_ECB_E1, data_length);
+ memcpy(result, NIST_TEST_RESULT_ECB_E1, data_length);
+ memcpy(key, NIST_KEY_ECB_E1, key_length);
+ break;
+ case 2:
+ memcpy(data, NIST_TEST_DATA_ECB_E2, data_length);
+ memcpy(result, NIST_TEST_RESULT_ECB_E2, data_length);
+ memcpy(key, NIST_KEY_ECB_E2, key_length);
+ break;
+ }
+
+}
+
+int kat_3des_ecb(int iteration, int silent)
+{
+ unsigned int data_length;
+ unsigned int key_length;
+
+ get_sizes(&data_length, &key_length, iteration);
+
+ if (!silent) {
+ printf("Test Parameters for iteration = %i\n", iteration);
+ printf("key length = %i, data length = %i",
+ key_length, data_length);
+ }
+
+ unsigned char key[key_length];
+ unsigned char input_data[data_length];
+ unsigned char encrypt[data_length];
+ unsigned char decrypt[data_length];
+ unsigned char result[data_length];
+
+ int rc = 0;
+
+ load_test_data(input_data, data_length, result, key, key_length,
+ iteration);
+
+ rc = ica_3des_ecb(input_data, encrypt, data_length, key, 1);
+ if (rc) {
+ printf("ica_3des_ecb encrypt failed with rc = %i\n", rc);
+ dump_ecb_data(key, key_length, input_data,
+ data_length, encrypt);
+ }
+ if (!silent && !rc) {
+ printf("Encrypt:\n");
+ dump_ecb_data(key, key_length, input_data,
+ data_length, encrypt);
+ }
+
+ if (memcmp(result, encrypt, data_length)) {
+ printf("Encryption Result does not match the known ciphertext!\n");
+ printf("Expected data:\n");
+ dump_array(result, data_length);
+ printf("Encryption Result:\n");
+ dump_array(encrypt, data_length);
+ rc++;
+ }
+
+ if (rc) {
+ printf("3DES ECB test exited after encryption\n");
+ return rc;
+ }
+
+ rc = ica_3des_ecb(encrypt, decrypt, data_length, key, 0);
+ if (rc) {
+ printf("ica_3des_ecb decrypt failed with rc = %i\n", rc);
+ dump_ecb_data(key, key_length, encrypt,
+ data_length, decrypt);
+ return rc;
+ }
+
+
+ if (!silent && !rc) {
+ printf("Decrypt:\n");
+ dump_ecb_data(key, key_length, encrypt,
+ data_length, decrypt);
+ }
+
+ if (memcmp(decrypt, input_data, data_length)) {
+ printf("Decryption Result does not match the original data!\n");
+ printf("Original data:\n");
+ dump_array(input_data, data_length);
+ printf("Decryption Result:\n");
+ dump_array(decrypt, data_length);
+ rc++;
+ }
+ return rc;
+}
+
+int load_random_test_data(unsigned char *data, unsigned int data_length,
+ unsigned char *key, unsigned int key_length)
+{
+ int rc;
+ rc = ica_random_number_generate(data_length, data);
+ if (rc) {
+ printf("ica_random_number_generate with rc = %i errnor = %i\n",
+ rc, errno);
+ return rc;
+ }
+ rc = ica_random_number_generate(key_length, key);
+ if (rc) {
+ printf("ica_random_number_generate with rc = %i errnor = %i\n",
+ rc, errno);
+ return rc;
+ }
+ return rc;
+}
+
+int random_3des_ecb(int iteration, int silent, unsigned int data_length)
+{
+ int rc = 0;
+ unsigned int key_length = sizeof(ica_des_key_triple_t);
+ unsigned char input_data[data_length];
+ unsigned char encrypt[data_length];
+ unsigned char decrypt[data_length];
+ unsigned char key[key_length];
+
+ memset(encrypt, 0x00, data_length);
+ memset(decrypt, 0x00, data_length);
+
+ load_random_test_data(input_data, data_length, key, key_length);
+ if (!silent) {
+ printf("Test Parameters for iteration = %i\n", iteration);
+ printf("key length = %i, data length = %i\n", key_length, data_length);
+ }
+
+ rc = ica_3des_ecb(input_data, encrypt, data_length, key, 1);
+ if (rc) {
+ printf("ica_3des_ecb encrypt failed with rc = %i\n", rc);
+ dump_ecb_data(key, key_length, input_data, data_length,
+ encrypt);
+ }
+ if (!silent && !rc) {
+ printf("Encrypt:\n");
+ dump_ecb_data(key, key_length, input_data,
+ data_length, encrypt);
+ }
+
+ if (rc) {
+ printf("3DES ECB test exited after encryption\n");
+ return rc;
+ }
+
+ rc = ica_3des_ecb(encrypt, decrypt, data_length, key, 0);
+ if (rc) {
+ printf("ica_3des_ecb decrypt failed with rc = %i\n", rc);
+ dump_ecb_data(key, key_length, encrypt,
+ data_length, decrypt);
+ return rc;
+ }
+
+
+ if (!silent && !rc) {
+ printf("Decrypt:\n");
+ dump_ecb_data(key, key_length, encrypt,
+ data_length, decrypt);
+ }
+
+ if (memcmp(decrypt, input_data, data_length)) {
+ printf("Decryption Result does not match the original data!\n");
+ printf("Original data:\n");
+ dump_array(input_data, data_length);
+ printf("Decryption Result:\n");
+ dump_array(decrypt, data_length);
+ rc++;
+ return rc;
+ }
+
+ return rc;
+}
+
+int main(int argc, char **argv)
+{
+ // Default mode is 0. ECB,ECB and CFQ tests will be performed.
+ unsigned int silent = 0;
+ if (argc > 1) {
+ if (strstr(argv[1], "silent"))
+ silent = 1;
+ }
+ int rc = 0;
+ int error_count = 0;
+ int iteration;
+ unsigned int data_length = sizeof(ica_des_vector_t);
+ for(iteration = 1; iteration <= NR_TESTS; iteration++) {
+ rc = kat_3des_ecb(iteration, silent);
+ if (rc) {
+ printf("kat_3des_ecb failed with rc = %i\n", rc);
+ error_count++;
+ }
+ }
+
+ for(iteration = 1; iteration <= NR_RANDOM_TESTS; iteration++) {
+ int silent = 1;
+ rc = random_3des_ecb(iteration, silent, data_length);
+ if (rc) {
+ printf("random_3des_ecb failed with rc = %i\n", rc);
+ error_count++;
+ goto out;
+ }
+ data_length += sizeof(ica_des_vector_t);
+ }
+
+out:
+ if (error_count)
+ printf("%i testcases failed\n", error_count);
+ else
+ printf("All 3des_ecb testcases finished successfully\n");
+
+ return rc;
+}
+
diff --git a/src/tests/libica_3des_ofb_test.c b/src/tests/libica_3des_ofb_test.c
new file mode 100644
index 0000000..3b984dc
--- /dev/null
+++ b/src/tests/libica_3des_ofb_test.c
@@ -0,0 +1,186 @@
+/* This program is released under the Common Public License V1.0
+ *
+ * You should have received a copy of Common Public License V1.0 along with
+ * with this program.
+ */
+
+/* Copyright IBM Corp. 2010, 2011 */
+#include <fcntl.h>
+#include <sys/errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+#include <stdlib.h>
+#include "ica_api.h"
+
+#define NR_RANDOM_TESTS 10000
+
+void dump_array(unsigned char *ptr, unsigned int size)
+{
+ unsigned char *ptr_end;
+ unsigned char *h;
+ int i = 1;
+
+ h = ptr;
+ ptr_end = ptr + size;
+ while (h < (unsigned char *)ptr_end) {
+ printf("0x%02x ",(unsigned char ) *h);
+ h++;
+ if (i == 8) {
+ printf("\n");
+ i = 1;
+ } else {
+ ++i;
+ }
+ }
+ printf("\n");
+}
+
+void dump_ofb_data(unsigned char *iv, unsigned int iv_length,
+ unsigned char *key, unsigned int key_length,
+ unsigned char *input_data, unsigned int data_length,
+ unsigned char *output_data)
+{
+ printf("IV \n");
+ dump_array(iv, iv_length);
+ printf("Key \n");
+ dump_array(key, key_length);
+ printf("Input Data\n");
+ dump_array(input_data, data_length);
+ printf("Output Data\n");
+ dump_array(output_data, data_length);
+}
+
+int load_random_test_data(unsigned char *data, unsigned int data_length,
+ unsigned char *iv, unsigned int iv_length,
+ unsigned char *key, unsigned int key_length)
+{
+ int rc;
+ rc = ica_random_number_generate(data_length, data);
+ if (rc) {
+ printf("ica_random_number_generate with rc = %i errnor = %i\n",
+ rc, errno);
+ return rc;
+ }
+ rc = ica_random_number_generate(iv_length, iv);
+ if (rc) {
+ printf("ica_random_number_generate with rc = %i errnor = %i\n",
+ rc, errno);
+ return rc;
+ }
+ rc = ica_random_number_generate(key_length, key);
+ if (rc) {
+ printf("ica_random_number_generate with rc = %i errnor = %i\n",
+ rc, errno);
+ return rc;
+ }
+ return rc;
+}
+
+int random_3des_ofb(int iteration, int silent, unsigned int data_length)
+{
+ unsigned int iv_length = sizeof(ica_des_vector_t);
+ unsigned int key_length = sizeof(ica_des_key_triple_t);
+
+ unsigned char iv[iv_length];
+ unsigned char tmp_iv[iv_length];
+ unsigned char key[key_length];
+ unsigned char input_data[data_length];
+ unsigned char encrypt[data_length];
+ unsigned char decrypt[data_length];
+
+ int rc = 0;
+ memset(encrypt, 0x00, data_length);
+ memset(decrypt, 0x00, data_length);
+
+ load_random_test_data(input_data, data_length, iv, iv_length, key,
+ key_length);
+ memcpy(tmp_iv, iv, iv_length);
+
+ if (!silent) {
+ printf("Test Parameters for iteration = %i\n", iteration);
+ printf("key length = %i, data length = %i, iv length = %i\n",
+ key_length, data_length, iv_length);
+ }
+
+ rc = ica_3des_ofb(input_data, encrypt, data_length, key, tmp_iv, 1);
+ if (rc) {
+ printf("ica_3des_ofb encrypt failed with rc = %i\n", rc);
+ dump_ofb_data(iv, iv_length, key, key_length, input_data,
+ data_length, encrypt);
+ }
+ if (!silent && !rc) {
+ printf("Encrypt:\n");
+ dump_ofb_data(iv, iv_length, key, key_length, input_data,
+ data_length, encrypt);
+ }
+
+ if (rc) {
+ printf("3DES OFB test exited after encryption\n");
+ return rc;
+ }
+
+ memcpy(tmp_iv, iv, iv_length);
+
+ rc = ica_3des_ofb(encrypt, decrypt, data_length, key, tmp_iv, 0);
+ if (rc) {
+ printf("ica_3des_ofb decrypt failed with rc = %i\n", rc);
+ dump_ofb_data(iv, iv_length, key, key_length, encrypt,
+ data_length, decrypt);
+ return rc;
+ }
+
+
+ if (!silent && !rc) {
+ printf("Decrypt:\n");
+ dump_ofb_data(iv, iv_length, key, key_length, encrypt,
+ data_length, decrypt);
+ }
+
+ if (memcmp(decrypt, input_data, data_length)) {
+ printf("Decryption Result does not match the original data!\n");
+ printf("Original data:\n");
+ dump_array(input_data, data_length);
+ printf("Decryption Result:\n");
+ dump_array(decrypt, data_length);
+ rc++;
+ }
+ return rc;
+}
+
+int main(int argc, char **argv)
+{
+ unsigned int silent = 0;
+ if (argc > 1) {
+ if (strstr(argv[1], "silent"))
+ silent = 1;
+ }
+ int rc = 0;
+ int error_count = 0;
+ int iteration;
+ unsigned int rdata;
+ unsigned int data_length = 1;
+ for(iteration = 1; iteration <= NR_RANDOM_TESTS; iteration++) {
+ rc = random_3des_ofb(iteration, silent, data_length);
+ if (rc) {
+ printf("random_3des_ofb failed with rc = %i\n", rc);
+ error_count++;
+ goto out;
+ }
+ // add a value between 1 and 8 to data_length
+ if (ica_random_number_generate(sizeof(rdata), (unsigned char*) &rdata)) {
+ printf("ica_random_number_generate failed with errnor = %i\n",
+ errno);
+ exit(1);
+ }
+ data_length += (rdata % 8) + 1;
+ }
+out:
+ if (error_count)
+ printf("%i testcases failed\n", error_count);
+ else
+ printf("All 3des_ofb testcases finished successfully\n");
+
+ return rc;
+}
+
diff --git a/src/tests/libica_3des_test.c b/src/tests/libica_3des_test.c
new file mode 100644
index 0000000..baad4e9
--- /dev/null
+++ b/src/tests/libica_3des_test.c
@@ -0,0 +1,156 @@
+/* This program is released under the Common Public License V1.0
+ *
+ * You should have received a copy of Common Public License V1.0 along with
+ * with this program.
+ */
+
+/* Copyright IBM Corp. 2001, 2009, 2011 */
+#include <fcntl.h>
+#include <sys/errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+#include "ica_api.h"
+
+
+unsigned char NIST_KEY1[] =
+ { 0x7c, 0xa1, 0x10, 0x45, 0x4a, 0x1a, 0x6e, 0x57 };
+
+unsigned char NIST_KEY2[] =
+ { 0x7c, 0xa1, 0x10, 0x45, 0x4a, 0x1a, 0x6e, 0x57 };
+
+unsigned char NIST_KEY3[] =
+ { 0x7c, 0xa1, 0x10, 0x45, 0x4a, 0x1a, 0x6e, 0x57 };
+
+unsigned char NIST_TEST_DATA[] =
+ { 0x01, 0xa1, 0xd6, 0xd0, 0x39, 0x77, 0x67, 0x42 };
+
+unsigned char NIST_TEST_RESULT[] =
+ { 0x69, 0x0f, 0x5b, 0x0d, 0x9a, 0x26, 0x93, 0x9b };
+
+int silent = 1;
+
+void dump_array(unsigned char *ptr, unsigned int size)
+{
+ unsigned char *ptr_end;
+ unsigned char *h;
+ int i = 1;
+
+ h = ptr;
+ ptr_end = ptr + size;
+ while (h < (unsigned char *)ptr_end) {
+ printf("0x%02x ",(unsigned char ) *h);
+ h++;
+ if (i == 8) {
+ printf("\n");
+ i = 1;
+ } else {
+ ++i;
+ }
+ }
+ printf("\n");
+}
+
+int test_3des_new_api(int mode)
+{
+ ica_des_vector_t iv;
+ ica_des_key_triple_t key;
+ int rc = 0;
+ unsigned char dec_text[sizeof(NIST_TEST_DATA)],
+ enc_text[sizeof(NIST_TEST_DATA)];
+
+ bzero(dec_text, sizeof(dec_text));
+ bzero(enc_text, sizeof(enc_text));
+ bzero(iv, sizeof(iv));
+ bcopy(NIST_KEY1, key.key1, sizeof(NIST_KEY1));
+ bcopy(NIST_KEY2, key.key2, sizeof(NIST_KEY2));
+ bcopy(NIST_KEY3, key.key3, sizeof(NIST_KEY3));
+
+ printf("\nOriginal data:\n");
+ dump_array(NIST_TEST_DATA, sizeof(NIST_TEST_DATA));
+
+ rc = ica_3des_encrypt(mode, sizeof(NIST_TEST_DATA), NIST_TEST_DATA,
+ &iv, &key, enc_text);
+ if (rc != 0) {
+ printf("ica_3des_encrypt failed with errno %d (0x%x).\n", rc, rc);
+ return rc;
+ }
+
+ printf("\nEncrypted data:\n");
+ dump_array(enc_text, sizeof(enc_text));
+ if (memcmp(enc_text, NIST_TEST_RESULT, sizeof NIST_TEST_RESULT) != 0) {
+ printf("This does NOT match the known result.\n");
+ return -1;
+ } else {
+ printf("Yep, it's what it should be.\n");
+ }
+
+ bzero(iv, sizeof(iv));
+ rc = ica_3des_decrypt(mode, sizeof(enc_text), enc_text,
+ &iv, &key, dec_text);
+ if (rc != 0) {
+ printf("ica_3des_decrypt failed with errno %d (0x%x).\n", rc, rc);
+ return rc;
+ }
+
+ printf("\nDecrypted data:\n");
+ dump_array(dec_text, sizeof(dec_text));
+ if (memcmp(dec_text, NIST_TEST_DATA, sizeof(NIST_TEST_DATA)) != 0) {
+ printf("This does NOT match the original data.\n");
+ return -1;
+ } else {
+ printf("Successful!\n");
+ }
+
+ return 0;
+}
+
+int main(int argc, char **argv)
+{
+ // Default mode is 0. ECB and CBC tests will be performed.
+ unsigned int mode = 0;
+ if (argc > 1) {
+ if (strstr(argv[1], "ecb"))
+ mode = MODE_ECB;
+ if (strstr(argv[1], "cbc"))
+ mode = MODE_CBC;
+ printf("mode = %i \n", mode);
+ }
+ if (mode != 0 && mode != MODE_ECB && mode != MODE_CBC) {
+ printf("Usage: %s [ ecb | cbc ]\n", argv[0]);
+ return -1;
+ }
+
+ int rc = 0;
+ int error_count = 0;
+ if (!mode) {
+ /* This is the standard loop that will perform all testcases */
+ mode = 2;
+ while (mode) {
+ rc = test_3des_new_api(mode);
+ if (rc) {
+ error_count++;
+ printf ("test_des_new_api mode = %i failed \n", mode);
+ }
+ else
+ printf ("test_des_new_api mode = %i finished successfully \n", mode);
+
+ mode--;
+ }
+ if (error_count)
+ printf("%i testcases failed\n", error_count);
+ else
+ printf("All testcases finished successfully\n");
+ } else {
+ /* Perform only either in ECB or CBC mode */
+ silent = 0;
+ rc = test_3des_new_api(mode);
+ if (rc)
+ printf ("test_des_new_api mode = %i failed \n", mode);
+ else
+ printf ("test_des_new_api mode = %i finished successfully \n", mode);
+ }
+
+ return rc;
+}
+
diff --git a/src/tests/libica_aes128_test.c b/src/tests/libica_aes128_test.c
new file mode 100644
index 0000000..45d7508
--- /dev/null
+++ b/src/tests/libica_aes128_test.c
@@ -0,0 +1,303 @@
+/* This program is released under the Common Public License V1.0
+ *
+ * You should have received a copy of Common Public License V1.0 along with
+ * with this program.
+ */
+
+/* Copyright IBM Corp. 2005, 2009, 2011 */
+#include <fcntl.h>
+#include <sys/errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+#include <unistd.h>
+#include "ica_api.h"
+#include <stdlib.h>
+#include <openssl/aes.h>
+
+int silent = 0;
+
+unsigned char NIST_KEY1[] = {
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+};
+
+unsigned char NIST_TEST_DATA[] = {
+ 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
+ 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff,
+};
+
+unsigned char NIST_TEST_RESULT[] = {
+ 0x69, 0xc4, 0xe0, 0xd8, 0x6a, 0x7b, 0x04, 0x30,
+ 0xd8, 0xcd, 0xb7, 0x80, 0x70, 0xb4, 0xc5, 0x5a,
+};
+
+void dump_array(unsigned char *ptr, unsigned int size)
+{
+ unsigned char *ptr_end;
+ unsigned char *h;
+ int i = 1;
+
+ h = ptr;
+ ptr_end = ptr + size;
+ while (h < (unsigned char *)ptr_end) {
+ printf("0x%02x ",(unsigned char ) *h);
+ h++;
+ if (i == 8) {
+ printf("\n");
+ i = 1;
+ } else {
+ ++i;
+ }
+ }
+ printf("\n");
+}
+
+int test_aes128_new_api(int mode)
+{
+ ica_aes_vector_t iv;
+ unsigned char key[AES_KEY_LEN128];
+ int rc = 0;
+ unsigned char dec_text[sizeof(NIST_TEST_DATA)],
+ enc_text[sizeof(NIST_TEST_DATA)];
+
+ bzero(dec_text, sizeof(dec_text));
+ bzero(enc_text, sizeof(enc_text));
+ bzero(iv, sizeof(iv));
+ bcopy(NIST_KEY1, key, sizeof(NIST_KEY1));
+
+ rc = ica_aes_encrypt(mode, sizeof(NIST_TEST_DATA), NIST_TEST_DATA, &iv,
+ AES_KEY_LEN128, key, enc_text);
+ if (rc) {
+ printf("key \n");
+ dump_array((unsigned char *) key, sizeof(NIST_KEY1));
+ printf("\nOriginal data:\n");
+ dump_array((unsigned char *) NIST_TEST_DATA, sizeof(NIST_TEST_DATA));
+ printf("test iv\n");
+ dump_array((unsigned char *) &iv, sizeof(ica_aes_vector_t));
+ printf("key\n");
+ dump_array((unsigned char *) key, AES_KEY_LEN128);
+ printf("ica_aes_encrypt failed with errno %d (0x%x).\n", rc, rc);
+ return 1;
+ }
+
+ if (memcmp(enc_text, NIST_TEST_RESULT, sizeof(NIST_TEST_RESULT)) != 0) {
+ printf("key \n");
+ dump_array((unsigned char *) key, sizeof(NIST_KEY1));
+ printf("\nOriginal data:\n");
+ dump_array((unsigned char *) NIST_TEST_DATA, sizeof(NIST_TEST_DATA));
+ printf("test iv\n");
+ dump_array((unsigned char *) &iv, sizeof(ica_aes_vector_t));
+ printf("key\n");
+ dump_array((unsigned char *) key, AES_KEY_LEN128);
+ printf("\nEncrypted data:\n");
+ dump_array((unsigned char *) enc_text, sizeof(enc_text));
+ printf("This does NOT match the known result.\n");
+ return 1;
+ } else {
+ if (!silent) {
+ printf("Yep, it's what it should be.\n");
+ }
+ }
+
+ bzero(iv, sizeof(iv));
+ rc = ica_aes_decrypt(mode, sizeof(enc_text), enc_text, &iv,
+ AES_KEY_LEN128, key, dec_text);
+ if (rc) {
+ printf("key \n");
+ dump_array((unsigned char *) key, sizeof(NIST_KEY1));
+ printf("\nOriginal data:\n");
+ dump_array((unsigned char *) NIST_TEST_DATA, sizeof(NIST_TEST_DATA));
+ printf("test iv\n");
+ dump_array((unsigned char *) &iv, sizeof(ica_aes_vector_t));
+ printf("key\n");
+ dump_array((unsigned char *) key, AES_KEY_LEN128);
+ printf("\nEncrypted data:\n");
+ dump_array((unsigned char *) enc_text, sizeof(enc_text));
+ printf("\nDecrypted data:\n");
+ dump_array((unsigned char *) dec_text, sizeof(dec_text));
+ printf("ica_aes_decrypt failed with errno %d (0x%x).\n", rc, rc);
+ return 1;
+ }
+
+ if (memcmp(dec_text, NIST_TEST_DATA, sizeof(NIST_TEST_DATA)) != 0) {
+ printf("This does NOT match the original data.\n");
+ return 1;
+ } else {
+ if (!silent) {
+ printf("Successful!\n");
+ printf("key \n");
+ dump_array((unsigned char *) key, sizeof(NIST_KEY1));
+ printf("\nOriginal data:\n");
+ dump_array((unsigned char *) NIST_TEST_DATA, sizeof(NIST_TEST_DATA));
+ printf("test iv\n");
+ dump_array((unsigned char *) &iv, sizeof(ica_aes_vector_t));
+ printf("key\n");
+ dump_array((unsigned char *) key, AES_KEY_LEN128);
+ printf("\nEncrypted data:\n");
+ dump_array((unsigned char *) enc_text, sizeof(enc_text));
+ printf("\nDecrypted data:\n");
+ dump_array((unsigned char *) dec_text, sizeof(dec_text));
+ }
+ }
+
+// Test 2
+
+ rc = 0;
+ bzero(dec_text, sizeof(dec_text));
+ bzero(enc_text, sizeof(enc_text));
+ bzero(iv, sizeof(iv));
+ bzero(key, sizeof(key));
+
+ unsigned int length = 64;
+ unsigned char *decrypt = malloc(length);
+ unsigned char *encrypt = malloc(length);
+ unsigned char *original = malloc(length);
+ ica_aes_key_len_128_t key2;
+
+ rc = ica_random_number_generate(length, original);
+ if (rc) {
+ printf("ica_random_number_generate returned rc = %i\n", rc);
+ return rc;
+ }
+
+ rc = ica_random_number_generate(AES_KEY_LEN128, (unsigned char *) &key2);
+ if (rc) {
+ printf("ica_random_number_generate returned rc = %i\n", rc);
+ return rc;
+ }
+
+ rc = ica_aes_encrypt(mode, length, original, &iv, AES_KEY_LEN128, (unsigned char *) &key2,
+ (unsigned char *) encrypt);
+ if (rc) {
+ printf("\nOriginal data:\n");
+ dump_array((unsigned char *) original, length);
+ printf("KEY: \n");
+ dump_array((unsigned char *) &key2, AES_KEY_LEN128);
+ printf("ica_aes_encrypt failed with errno %d (0x%x).\n", rc, rc);
+ return rc;
+ }
+
+ if (memcmp(encrypt, original, length) == 0) {
+ printf("Encrypt and original are the same.\n");
+ return 1;
+ }
+
+ bzero(iv, sizeof(iv));
+ rc = ica_aes_decrypt(mode, length, encrypt, &iv, AES_KEY_LEN128,
+ (unsigned char *) &key2, decrypt);
+ if (rc) {
+ printf("\nOriginal data:\n");
+ dump_array((unsigned char *) original, length);
+ printf("KEY: \n");
+ dump_array((unsigned char *) &key2, AES_KEY_LEN128);
+ printf("\nEncrypted data:\n");
+ dump_array((unsigned char *) encrypt, length);
+ printf("ica_aes_decrypt failed with errno %d (0x%x).\n", rc, rc);
+ goto free;
+ }
+
+ if (memcmp(decrypt, original, length) != 0) {
+ printf("\nOriginal data:\n");
+ dump_array((unsigned char *) original, length);
+ printf("KEY: \n");
+ dump_array((unsigned char *) &key2, AES_KEY_LEN128);
+ printf("\nEncrypted data:\n");
+ dump_array((unsigned char *) encrypt, length);
+ printf("\nDecrypted data:\n");
+ dump_array((unsigned char *) decrypt, length);
+ printf("This does NOT match the original data.\n");
+ rc = -1;
+ goto free;
+ }
+
+ if(memcmp(decrypt, encrypt, length) == 0) {
+ printf("\nOriginal data:\n");
+ dump_array((unsigned char *) original, length);
+ printf("KEY: \n");
+ dump_array((unsigned char *) &key2, AES_KEY_LEN128);
+ printf("\nEncrypted data:\n");
+ dump_array((unsigned char *) encrypt, length);
+ printf("\nDecrypted data:\n");
+ dump_array((unsigned char *) decrypt, length);
+ printf("decrypt and encrypt are the same\n");
+ rc = -1;
+ goto free;
+
+ } else {
+ if (!silent) {
+ printf("Successful!\n");
+ }
+ }
+ free:
+ free(original);
+ free(encrypt);
+ free(decrypt);
+
+ return rc;
+}
+
+int main(int argc, char **argv)
+{
+ // Default mode is 0. ECB and CBC tests will be performed.
+ unsigned int mode = 0;
+ if (argc > 1) {
+ if (strstr(argv[1], "ecb"))
+ mode = MODE_ECB;
+ if (strstr(argv[1], "cbc"))
+ mode = MODE_CBC;
+ if (strstr(argv[1], "silent"))
+ silent = 1;
+ }
+
+ if (argc > 2) {
+ if (strstr(argv[2], "ecb"))
+ mode = MODE_ECB;
+ if (strstr(argv[2], "cbc"))
+ mode = MODE_CBC;
+ if (strstr(argv[2], "silent"))
+ silent = 1;
+ }
+
+ if (mode != 0 && mode != MODE_ECB && mode != MODE_CBC) {
+ printf("Usage: %s [ ecb | cbc ]\n", argv[0]);
+ return -1;
+ }
+ int rc = 0;
+ int error_count = 0;
+
+ if (!mode) {
+ // silent = 0;
+ /* This is the standard loop that will perform all testcases */
+ mode = 2;
+ while (mode) {
+ rc = test_aes128_new_api(mode);
+ if (rc) {
+ error_count++;
+ printf ("test_aes_new_api mode = %i failed \n", mode);
+ }
+ else {
+ if (!silent) {
+ printf ("test_aes_new_api mode = %i finished successfully \n", mode);
+ }
+ }
+ mode--;
+ }
+ if (error_count)
+ printf("%i testcases failed\n", error_count);
+ else
+ printf("All AES128 (ECB/CBC) testcases finished successfully\n");
+ } else {
+ /* Perform only either in ECB or CBC mode */
+ rc = test_aes128_new_api(mode);
+ if (rc)
+ printf ("test_aes_new_api mode = %i failed \n", mode);
+ else {
+ if (!silent) {
+ printf ("test_aes_new_api mode = %i finished successfully \n", mode);
+ }
+ }
+ }
+ return rc;
+}
+
diff --git a/src/tests/libica_aes192_test.c b/src/tests/libica_aes192_test.c
new file mode 100644
index 0000000..7cb3098
--- /dev/null
+++ b/src/tests/libica_aes192_test.c
@@ -0,0 +1,180 @@
+/* This program is released under the Common Public License V1.0
+ *
+ * You should have received a copy of Common Public License V1.0 along with
+ * with this program.
+ */
+
+/* Copyright IBM Corp. 2005, 2009, 2011 */
+#include <fcntl.h>
+#include <sys/errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+#include <stdlib.h>
+#include "ica_api.h"
+
+unsigned char NIST_KEY2[] = {
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
+};
+
+unsigned char NIST_TEST_DATA[] = {
+ 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
+ 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff,
+};
+
+unsigned char NIST_TEST_RESULT[] = {
+ 0xdd, 0xa9, 0x7c, 0xa4, 0x86, 0x4c, 0xdf, 0xe0,
+ 0x6e, 0xaf, 0x70, 0xa0, 0xec, 0x0d, 0x71, 0x91,
+};
+
+int silent;
+
+void dump_array(unsigned char *ptr, unsigned int size)
+{
+ unsigned char *ptr_end;
+ unsigned char *h;
+ int i = 1;
+
+ h = ptr;
+ ptr_end = ptr + size;
+ while (h < (unsigned char *)ptr_end) {
+ printf("0x%02x ",(unsigned char ) *h);
+ h++;
+ if (i == 8) {
+ printf("\n");
+ i = 1;
+ } else {
+ ++i;
+ }
+ }
+ printf("\n");
+}
+
+int test_aes192_new_api(int mode)
+{
+ ica_aes_vector_t iv;
+ ica_aes_key_len_192_t key;
+ int rc = 0;
+ unsigned char dec_text[sizeof(NIST_TEST_DATA)],
+ enc_text[sizeof(NIST_TEST_DATA)];
+
+ bzero(dec_text, sizeof(dec_text));
+ bzero(enc_text, sizeof(enc_text));
+ bzero(iv, sizeof(iv));
+ bcopy(NIST_KEY2, key, sizeof(NIST_KEY2));
+
+ rc = ica_aes_encrypt(mode, sizeof(NIST_TEST_DATA), NIST_TEST_DATA, &iv,
+ AES_KEY_LEN192, (unsigned char *) &key, enc_text);
+ if (rc) {
+ printf("\nOriginal data:\n");
+ dump_array((unsigned char*)NIST_TEST_DATA, sizeof(NIST_TEST_DATA));
+ printf("ica_aes_encrypt failed with errno %d (0x%x).\n", rc, rc);
+ return rc;
+ }
+
+ if (memcmp(enc_text, NIST_TEST_RESULT, sizeof(NIST_TEST_RESULT)) != 0) {
+ printf("\nOriginal data:\n");
+ dump_array((unsigned char*)NIST_TEST_DATA, sizeof(NIST_TEST_DATA));
+ printf("\nEncrypted data:\n");
+ dump_array((unsigned char*)enc_text, sizeof(enc_text));
+ printf("This does NOT match the known result.\n");
+ return 1;
+ } else {
+ if (!silent) {
+ printf("Yep, it's what it should be.\n");
+ }
+ }
+
+ bzero(iv, sizeof(iv));
+ rc = ica_aes_decrypt(mode, sizeof(enc_text), enc_text, &iv,
+ AES_KEY_LEN192, (unsigned char *) &key, dec_text);
+ if (rc != 0) {
+ printf("ica_aes_decrypt failed with errno %d (0x%x).\n", rc, rc);
+ return 1;
+ }
+
+ if (memcmp(dec_text, NIST_TEST_DATA, sizeof(NIST_TEST_DATA)) != 0) {
+ printf("\nOriginal data:\n");
+ dump_array((unsigned char*)NIST_TEST_DATA, sizeof(NIST_TEST_DATA));
+ printf("\nEncrypted data:\n");
+ dump_array((unsigned char*)enc_text, sizeof(enc_text));
+ printf("\nDecrypted data:\n");
+ dump_array((unsigned char*)dec_text, sizeof(dec_text));
+ printf("This does NOT match the original data.\n");
+ return 1;
+ } else {
+ if (!silent) {
+ printf("Successful!\n");
+ printf("\nOriginal data:\n");
+ dump_array((unsigned char*)NIST_TEST_DATA, sizeof(NIST_TEST_DATA));
+ printf("\nEncrypted data:\n");
+ dump_array((unsigned char*)enc_text, sizeof(enc_text));
+ printf("\nDecrypted data:\n");
+ dump_array((unsigned char*)dec_text, sizeof(dec_text));
+ }
+ }
+
+ return 0;
+}
+
+int main(int argc, char **argv)
+{
+ // Default mode is 0. ECB and CBC tests will be performed.
+ unsigned int mode = 0;
+ if (argc > 1) {
+ if (strstr(argv[1], "ecb"))
+ mode = MODE_ECB;
+ if (strstr(argv[1], "cbc"))
+ mode = MODE_CBC;
+ if (strstr(argv[1], "silent"))
+ silent = 1;
+ }
+ if (argc > 2) {
+ if (strstr(argv[2], "ecb"))
+ mode = MODE_ECB;
+ if (strstr(argv[2], "cbc"))
+ mode = MODE_CBC;
+ if (strstr(argv[2], "silent"))
+ silent = 1;
+ }
+ if (mode != 0 && mode != MODE_ECB && mode != MODE_CBC) {
+ printf("Usage: %s [ ecb | cbc ]\n", argv[0]);
+ return -1;
+ }
+ int rc = 0;
+ int error_count = 0;
+ if (!mode) {
+ /* This is the standard loop that will perform all testcases */
+ mode = 2;
+ while (mode) {
+ rc = test_aes192_new_api(mode);
+ if (rc) {
+ error_count++;
+ printf ("test_aes_new_api mode = %i failed \n", mode);
+ } else {
+ if (!silent) {
+ printf ("test_aes_new_api mode = %i finished successfully \n", mode);
+ }
+ }
+ mode--;
+ }
+ if (error_count)
+ printf("%i testcases failed\n", error_count);
+ else
+ printf("All AES192 (ECB/CBC) testcases finished successfully\n");
+ } else {
+ /* Perform only either in ECB or CBC mode */
+ rc = test_aes192_new_api(mode);
+ if (rc)
+ printf ("test_aes_new_api mode = %i failed \n", mode);
+ else {
+ if (!silent) {
+ printf ("test_aes_new_api mode = %i finished successfully \n", mode);
+ }
+ }
+ }
+ return rc;
+}
+
diff --git a/src/tests/libica_aes256_test.c b/src/tests/libica_aes256_test.c
new file mode 100644
index 0000000..5c663a8
--- /dev/null
+++ b/src/tests/libica_aes256_test.c
@@ -0,0 +1,182 @@
+/* This program is released under the Common Public License V1.0
+ *
+ * You should have received a copy of Common Public License V1.0 along with
+ * with this program.
+ */
+
+/* Copyright IBM Corp. 2005, 2009, 2011 */
+#include <fcntl.h>
+#include <sys/errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+#include <stdlib.h>
+#include "ica_api.h"
+
+unsigned char NIST_KEY3[] = {
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
+ 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
+};
+
+unsigned char NIST_TEST_DATA[] = {
+ 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
+ 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff,
+};
+
+unsigned char NIST_TEST_RESULT[] = {
+ 0x8e, 0xa2, 0xb7, 0xca, 0x51, 0x67, 0x45, 0xbf,
+ 0xea, 0xfc, 0x49, 0x90, 0x4b, 0x49, 0x60, 0x89,
+};
+
+int silent;
+
+void dump_array(unsigned char *ptr, unsigned int size)
+{
+ unsigned char *ptr_end;
+ unsigned char *h;
+ int i = 1;
+
+ h = ptr;
+ ptr_end = ptr + size;
+ while (h < (unsigned char *)ptr_end) {
+ printf("0x%02x ",(unsigned char ) *h);
+ h++;
+ if (i == 8) {
+ printf("\n");
+ i = 1;
+ } else {
+ ++i;
+ }
+ }
+ printf("\n");
+}
+
+int test_aes256_new_api(int mode)
+{
+ ica_aes_vector_t iv;
+ unsigned char key[AES_KEY_LEN256];
+ int rc = 0;
+ unsigned char dec_text[sizeof(NIST_TEST_DATA)],
+ enc_text[sizeof(NIST_TEST_DATA)];
+
+ bzero(dec_text, sizeof(dec_text));
+ bzero(enc_text, sizeof(enc_text));
+ bzero(iv, sizeof(iv));
+ bcopy(NIST_KEY3, key, sizeof(NIST_KEY3));
+
+ rc = ica_aes_encrypt(mode, sizeof(NIST_TEST_DATA), NIST_TEST_DATA, &iv,
+ AES_KEY_LEN256, key, enc_text);
+ if (rc) {
+ printf("ica_aes_encrypt failed with errno %d (0x%x).\n", rc, rc);
+ return 1;
+ }
+
+ if (memcmp(enc_text, NIST_TEST_RESULT, sizeof(NIST_TEST_RESULT)) != 0) {
+ printf("\nOriginal data:\n");
+ dump_array((unsigned char *) NIST_TEST_DATA, sizeof(NIST_TEST_DATA));
+ printf("\nEncrypted data:\n");
+ dump_array((unsigned char *) enc_text, sizeof(enc_text));
+ printf("This does NOT match the known result.\n");
+ return 1;
+ } else {
+ if (!silent) {
+ printf("Yep, it's what it should be.\n");
+ }
+ }
+
+ bzero(iv, sizeof(iv));
+ rc = ica_aes_decrypt(mode, sizeof(enc_text), enc_text, &iv,
+ AES_KEY_LEN256, key, dec_text);
+ if (rc) {
+ printf("ica_aes_decrypt failed with errno %d (0x%x).\n", rc, rc);
+ return 1;
+ }
+
+ if (memcmp(dec_text, NIST_TEST_DATA, sizeof(NIST_TEST_DATA)) != 0) {
+ printf("\nOriginal data:\n");
+ dump_array((unsigned char *) NIST_TEST_DATA, sizeof(NIST_TEST_DATA));
+ printf("\nEncrypted data:\n");
+ dump_array((unsigned char *) enc_text, sizeof(enc_text));
+ printf("\nDecrypted data:\n");
+ dump_array((unsigned char *) dec_text, sizeof(dec_text));
+ printf("This does NOT match the original data.\n");
+ return 1;
+ } else {
+ if (!silent) {
+ printf("\nOriginal data:\n");
+ dump_array((unsigned char *) NIST_TEST_DATA, sizeof(NIST_TEST_DATA));
+ printf("\nEncrypted data:\n");
+ dump_array((unsigned char *) enc_text, sizeof(enc_text));
+ printf("\nDecrypted data:\n");
+ dump_array((unsigned char *) dec_text, sizeof(dec_text));
+ printf("Successful!\n");
+ }
+ }
+
+ return 0;
+}
+
+int main(int argc, char **argv)
+{
+ // Default mode is 0. ECB and CBC tests will be performed.
+ unsigned int mode = 0;
+ if (argc > 1) {
+ if (strstr(argv[1], "ecb"))
+ mode = MODE_ECB;
+ if (strstr(argv[1], "cbc"))
+ mode = MODE_CBC;
+ if (strstr(argv[1], "silent"))
+ silent = 1;
+ }
+ if (argc > 2) {
+ if (strstr(argv[2], "ecb"))
+ mode = MODE_ECB;
+ if (strstr(argv[2], "cbc"))
+ mode = MODE_CBC;
+ if (strstr(argv[2], "silent"))
+ silent = 1;
+ }
+
+ if (mode != 0 && mode != MODE_ECB && mode != MODE_CBC) {
+ printf("Usage: %s [ ecb | cbc ]\n", argv[0]);
+ return -1;
+ }
+ int rc = 0;
+ int error_count = 0;
+ if (!mode) {
+ /* This is the standard loop that will perform all testcases */
+ mode = 2;
+ while (mode) {
+ rc = test_aes256_new_api(mode);
+ if (rc) {
+ error_count++;
+ printf ("test_aes_new_api mode = %i failed \n", mode);
+ }
+ else {
+ if (!silent) {
+ printf ("test_aes_new_api mode = %i finished successfully \n", mode);
+ }
+ }
+ mode--;
+ }
+ if (error_count)
+ printf("%i testcases failed\n", error_count);
+ else
+ printf("All AES256 (ECB/CBC) testcases finished successfully\n");
+ } else {
+ /* Perform only either in ECB or CBC mode */
+ rc = test_aes256_new_api(mode);
+ if (rc)
+ printf("test_aes_new_api mode = %i failed \n", mode);
+ else {
+ if (!silent) {
+ printf("test_aes_new_api mode = %i finished successfully \n", mode);
+ }
+ }
+ }
+
+ return rc;
+}
+
diff --git a/src/tests/libica_aes_cbc_test.c b/src/tests/libica_aes_cbc_test.c
new file mode 100644
index 0000000..0225771
--- /dev/null
+++ b/src/tests/libica_aes_cbc_test.c
@@ -0,0 +1,649 @@
+/* This program is released under the Common Public License V1.0
+ *
+ * You should have received a copy of Common Public License V1.0 along with
+ * with this program.
+ */
+
+/* Copyright IBM Corp. 2010, 2011 */
+#include <fcntl.h>
+#include <sys/errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+#include <stdlib.h>
+#include "ica_api.h"
+
+#define NR_TESTS 7
+#define NR_RANDOM_TESTS 10000
+
+/* CBC data - 1 for AES128 */
+unsigned char NIST_KEY_CBC_E1[] = {
+ 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
+ 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c,
+};
+
+unsigned char NIST_IV_CBC_E1[] = {
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+};
+
+unsigned char NIST_EXPECTED_IV_CBC_E1[] = {
+ 0x76, 0x49, 0xab, 0xac, 0x81, 0x19, 0xb2, 0x46,
+ 0xce, 0xe9, 0x8e, 0x9b, 0x12, 0xe9, 0x19, 0x7d,
+};
+
+unsigned char NIST_TEST_DATA_CBC_E1[] = {
+ 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
+ 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
+};
+
+unsigned char NIST_TEST_RESULT_CBC_E1[] = {
+ 0x76, 0x49, 0xab, 0xac, 0x81, 0x19, 0xb2, 0x46,
+ 0xce, 0xe9, 0x8e, 0x9b, 0x12, 0xe9, 0x19, 0x7d,
+};
+
+/* CBC data - 2 for AES128 */
+unsigned char NIST_KEY_CBC_E2[] = {
+ 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
+ 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c,
+};
+
+unsigned char NIST_IV_CBC_E2[] = {
+ 0x76, 0x49, 0xab, 0xac, 0x81, 0x19, 0xb2, 0x46,
+ 0xce, 0xe9, 0x8e, 0x9b, 0x12, 0xe9, 0x19, 0x7d,
+};
+
+unsigned char NIST_EXPECTED_IV_CBC_E2[] = {
+ 0x50, 0x86, 0xcb, 0x9b, 0x50, 0x72, 0x19, 0xee,
+ 0x95, 0xdb, 0x11, 0x3a, 0x91, 0x76, 0x78, 0xb2,
+};
+
+unsigned char NIST_TEST_DATA_CBC_E2[] = {
+ 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
+ 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
+};
+
+unsigned char NIST_TEST_RESULT_CBC_E2[] = {
+ 0x50, 0x86, 0xcb, 0x9b, 0x50, 0x72, 0x19, 0xee,
+ 0x95, 0xdb, 0x11, 0x3a, 0x91, 0x76, 0x78, 0xb2,
+};
+
+/* CBC data - 3 - for AES128 */
+unsigned char NIST_KEY_CBC_E3[] = {
+ 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
+ 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c,
+
+};
+
+unsigned char NIST_IV_CBC_E3[] = {
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+};
+
+unsigned char NIST_EXPECTED_IV_CBC_E3[] = {
+ 0x3f, 0xf1, 0xca, 0xa1, 0x68, 0x1f, 0xac, 0x09,
+ 0x12, 0x0e, 0xca, 0x30, 0x75, 0x86, 0xe1, 0xa7,
+};
+
+unsigned char NIST_TEST_DATA_CBC_E3[] = {
+ 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
+ 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
+ 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
+ 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
+ 0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11,
+ 0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef,
+ 0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17,
+ 0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10,
+};
+
+unsigned char NIST_TEST_RESULT_CBC_E3[] = {
+ 0x76, 0x49, 0xab, 0xac, 0x81, 0x19, 0xb2, 0x46,
+ 0xce, 0xe9, 0x8e, 0x9b, 0x12, 0xe9, 0x19, 0x7d,
+ 0x50, 0x86, 0xcb, 0x9b, 0x50, 0x72, 0x19, 0xee,
+ 0x95, 0xdb, 0x11, 0x3a, 0x91, 0x76, 0x78, 0xb2,
+ 0x73, 0xbe, 0xd6, 0xb8, 0xe3, 0xc1, 0x74, 0x3b,
+ 0x71, 0x16, 0xe6, 0x9e, 0x22, 0x22, 0x95, 0x16,
+ 0x3f, 0xf1, 0xca, 0xa1, 0x68, 0x1f, 0xac, 0x09,
+ 0x12, 0x0e, 0xca, 0x30, 0x75, 0x86, 0xe1, 0xa7,
+};
+
+/* CBC data - 4 - for AES192 */
+unsigned char NIST_KEY_CBC_E4[] = {
+ 0x8e, 0x73, 0xb0, 0xf7, 0xda, 0x0e, 0x64, 0x52,
+ 0xc8, 0x10, 0xf3, 0x2b, 0x80, 0x90, 0x79, 0xe5,
+ 0x62, 0xf8, 0xea, 0xd2, 0x52, 0x2c, 0x6b, 0x7b,
+};
+
+unsigned char NIST_IV_CBC_E4[] = {
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+};
+
+unsigned char NIST_EXPECTED_IV_CBC_E4[] = {
+ 0x4f, 0x02, 0x1d, 0xb2, 0x43, 0xbc, 0x63, 0x3d,
+ 0x71, 0x78, 0x18, 0x3a, 0x9f, 0xa0, 0x71, 0xe8,
+};
+
+unsigned char NIST_TEST_DATA_CBC_E4[] = {
+ 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
+ 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
+};
+
+unsigned char NIST_TEST_RESULT_CBC_E4[] = {
+ 0x4f, 0x02, 0x1d, 0xb2, 0x43, 0xbc, 0x63, 0x3d,
+ 0x71, 0x78, 0x18, 0x3a, 0x9f, 0xa0, 0x71, 0xe8,
+};
+
+/* CBC data 5 - for AES 192 */
+unsigned char NIST_KEY_CBC_E5[] = {
+ 0x8e, 0x73, 0xb0, 0xf7, 0xda, 0x0e, 0x64, 0x52,
+ 0xc8, 0x10, 0xf3, 0x2b, 0x80, 0x90, 0x79, 0xe5,
+ 0x62, 0xf8, 0xea, 0xd2, 0x52, 0x2c, 0x6b, 0x7b,
+};
+
+unsigned char NIST_IV_CBC_E5[] = {
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+};
+
+unsigned char NIST_EXPECTED_IV_CBC_E5[] = {
+ 0x08, 0xb0, 0xe2, 0x79, 0x88, 0x59, 0x88, 0x81,
+ 0xd9, 0x20, 0xa9, 0xe6, 0x4f, 0x56, 0x15, 0xcd,
+};
+
+unsigned char NIST_TEST_DATA_CBC_E5[] = {
+ 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
+ 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
+ 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
+ 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
+ 0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11,
+ 0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef,
+ 0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17,
+ 0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10,
+};
+
+unsigned char NIST_TEST_RESULT_CBC_E5[] = {
+ 0x4f, 0x02, 0x1d, 0xb2, 0x43, 0xbc, 0x63, 0x3d,
+ 0x71, 0x78, 0x18, 0x3a, 0x9f, 0xa0, 0x71, 0xe8,
+ 0xb4, 0xd9, 0xad, 0xa9, 0xad, 0x7d, 0xed, 0xf4,
+ 0xe5, 0xe7, 0x38, 0x76, 0x3f, 0x69, 0x14, 0x5a,
+ 0x57, 0x1b, 0x24, 0x20, 0x12, 0xfb, 0x7a, 0xe0,
+ 0x7f, 0xa9, 0xba, 0xac, 0x3d, 0xf1, 0x02, 0xe0,
+ 0x08, 0xb0, 0xe2, 0x79, 0x88, 0x59, 0x88, 0x81,
+ 0xd9, 0x20, 0xa9, 0xe6, 0x4f, 0x56, 0x15, 0xcd,
+};
+
+/* CBC data 6 - for AES 256 */
+unsigned char NIST_KEY_CBC_E6[] = {
+ 0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe,
+ 0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81,
+ 0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7,
+ 0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4,
+};
+
+unsigned char NIST_IV_CBC_E6[] = {
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+};
+
+unsigned char NIST_EXPECTED_IV_CBC_E6[] = {
+ 0xf5, 0x8c, 0x4c, 0x04, 0xd6, 0xe5, 0xf1, 0xba,
+ 0x77, 0x9e, 0xab, 0xfb, 0x5f, 0x7b, 0xfb, 0xd6,
+};
+
+unsigned char NIST_TEST_DATA_CBC_E6[] = {
+ 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
+ 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
+};
+
+unsigned char NIST_TEST_RESULT_CBC_E6[] = {
+ 0xf5, 0x8c, 0x4c, 0x04, 0xd6, 0xe5, 0xf1, 0xba,
+ 0x77, 0x9e, 0xab, 0xfb, 0x5f, 0x7b, 0xfb, 0xd6,
+};
+
+/* CBC data 7 - for AES 256 */
+unsigned char NIST_KEY_CBC_E7[] = {
+ 0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe,
+ 0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81,
+ 0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7,
+ 0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4,
+};
+
+unsigned char NIST_IV_CBC_E7[] = {
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+};
+
+unsigned char NIST_EXPECTED_IV_CBC_E7[] = {
+ 0xb2, 0xeb, 0x05, 0xe2, 0xc3, 0x9b, 0xe9, 0xfc,
+ 0xda, 0x6c, 0x19, 0x07, 0x8c, 0x6a, 0x9d, 0x1b,
+};
+
+unsigned char NIST_TEST_DATA_CBC_E7[] = {
+ 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
+ 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
+ 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
+ 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
+ 0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11,
+ 0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef,
+ 0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17,
+ 0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10,
+};
+
+unsigned char NIST_TEST_RESULT_CBC_E7[] = {
+ 0xf5, 0x8c, 0x4c, 0x04, 0xd6, 0xe5, 0xf1, 0xba,
+ 0x77, 0x9e, 0xab, 0xfb, 0x5f, 0x7b, 0xfb, 0xd6,
+ 0x9c, 0xfc, 0x4e, 0x96, 0x7e, 0xdb, 0x80, 0x8d,
+ 0x67, 0x9f, 0x77, 0x7b, 0xc6, 0x70, 0x2c, 0x7d,
+ 0x39, 0xf2, 0x33, 0x69, 0xa9, 0xd9, 0xba, 0xcf,
+ 0xa5, 0x30, 0xe2, 0x63, 0x04, 0x23, 0x14, 0x61,
+ 0xb2, 0xeb, 0x05, 0xe2, 0xc3, 0x9b, 0xe9, 0xfc,
+ 0xda, 0x6c, 0x19, 0x07, 0x8c, 0x6a, 0x9d, 0x1b,
+};
+
+void dump_array(unsigned char *ptr, unsigned int size)
+{
+ unsigned char *ptr_end;
+ unsigned char *h;
+ int i = 1;
+
+ h = ptr;
+ ptr_end = ptr + size;
+ while (h < (unsigned char *)ptr_end) {
+ printf("0x%02x ",(unsigned char ) *h);
+ h++;
+ if (i == 8) {
+ printf("\n");
+ i = 1;
+ } else {
+ ++i;
+ }
+ }
+ printf("\n");
+}
+
+void dump_cbc_data(unsigned char *iv, unsigned int iv_length,
+ unsigned char *key, unsigned int key_length,
+ unsigned char *input_data, unsigned int data_length,
+ unsigned char *output_data)
+{
+ printf("IV \n");
+ dump_array(iv, iv_length);
+ printf("Key \n");
+ dump_array(key, key_length);
+ printf("Input Data\n");
+ dump_array(input_data, data_length);
+ printf("Output Data\n");
+ dump_array(output_data, data_length);
+}
+
+void get_sizes(unsigned int *data_length, unsigned int *iv_length,
+ unsigned int *key_length, unsigned int iteration)
+{
+ switch (iteration) {
+ case 1:
+ *data_length = sizeof(NIST_TEST_DATA_CBC_E1);
+ *iv_length = sizeof(NIST_IV_CBC_E1);
+ *key_length = sizeof(NIST_KEY_CBC_E1);
+ break;
+ case 2:
+ *data_length = sizeof(NIST_TEST_DATA_CBC_E2);
+ *iv_length = sizeof(NIST_IV_CBC_E2);
+ *key_length = sizeof(NIST_KEY_CBC_E2);
+ break;
+ case 3:
+ *data_length = sizeof(NIST_TEST_DATA_CBC_E3);
+ *iv_length = sizeof(NIST_IV_CBC_E3);
+ *key_length = sizeof(NIST_KEY_CBC_E3);
+ break;
+ case 4:
+ *data_length = sizeof(NIST_TEST_DATA_CBC_E4);
+ *iv_length = sizeof(NIST_IV_CBC_E4);
+ *key_length = sizeof(NIST_KEY_CBC_E4);
+ break;
+ case 5:
+ *data_length = sizeof(NIST_TEST_DATA_CBC_E5);
+ *iv_length = sizeof(NIST_IV_CBC_E5);
+ *key_length = sizeof(NIST_KEY_CBC_E5);
+ break;
+ case 6:
+ *data_length = sizeof(NIST_TEST_DATA_CBC_E6);
+ *iv_length = sizeof(NIST_IV_CBC_E6);
+ *key_length = sizeof(NIST_KEY_CBC_E6);
+ break;
+ case 7:
+ *data_length = sizeof(NIST_TEST_DATA_CBC_E7);
+ *iv_length = sizeof(NIST_IV_CBC_E7);
+ *key_length = sizeof(NIST_KEY_CBC_E7);
+ break;
+ case 8:
+ break;
+ case 9:
+ break;
+ case 10:
+ break;
+ case 11:
+ break;
+ case 12:
+ break;
+ }
+
+}
+
+void load_test_data(unsigned char *data, unsigned int data_length,
+ unsigned char *result,
+ unsigned char *iv, unsigned char *expected_iv,
+ unsigned int iv_length,
+ unsigned char *key, unsigned int key_length,
+ unsigned int iteration)
+{
+ switch (iteration) {
+ case 1:
+ memcpy(data, NIST_TEST_DATA_CBC_E1, data_length);
+ memcpy(result, NIST_TEST_RESULT_CBC_E1, data_length);
+ memcpy(iv, NIST_IV_CBC_E1, iv_length);
+ memcpy(expected_iv, NIST_EXPECTED_IV_CBC_E1, iv_length);
+ memcpy(key, NIST_KEY_CBC_E1, key_length);
+ break;
+ case 2:
+ memcpy(data, NIST_TEST_DATA_CBC_E2, data_length);
+ memcpy(result, NIST_TEST_RESULT_CBC_E2, data_length);
+ memcpy(iv, NIST_IV_CBC_E2, iv_length);
+ memcpy(expected_iv, NIST_EXPECTED_IV_CBC_E2, iv_length);
+ memcpy(key, NIST_KEY_CBC_E2, key_length);
+ break;
+ case 3:
+ memcpy(data, NIST_TEST_DATA_CBC_E3, data_length);
+ memcpy(result, NIST_TEST_RESULT_CBC_E3, data_length);
+ memcpy(iv, NIST_IV_CBC_E3, iv_length);
+ memcpy(expected_iv, NIST_EXPECTED_IV_CBC_E3, iv_length);
+ memcpy(key, NIST_KEY_CBC_E3, key_length);
+ break;
+ case 4:
+ memcpy(data, NIST_TEST_DATA_CBC_E4, data_length);
+ memcpy(result, NIST_TEST_RESULT_CBC_E4, data_length);
+ memcpy(iv, NIST_IV_CBC_E4, iv_length);
+ memcpy(expected_iv, NIST_EXPECTED_IV_CBC_E4, iv_length);
+ memcpy(key, NIST_KEY_CBC_E4, key_length);
+ break;
+ case 5:
+ memcpy(data, NIST_TEST_DATA_CBC_E5, data_length);
+ memcpy(result, NIST_TEST_RESULT_CBC_E5, data_length);
+ memcpy(iv, NIST_IV_CBC_E5, iv_length);
+ memcpy(expected_iv, NIST_EXPECTED_IV_CBC_E5, iv_length);
+ memcpy(key, NIST_KEY_CBC_E5, key_length);
+ break;
+ case 6:
+ memcpy(data, NIST_TEST_DATA_CBC_E6, data_length);
+ memcpy(result, NIST_TEST_RESULT_CBC_E6, data_length);
+ memcpy(iv, NIST_IV_CBC_E6, iv_length);
+ memcpy(expected_iv, NIST_EXPECTED_IV_CBC_E6, iv_length);
+ memcpy(key, NIST_KEY_CBC_E6, key_length);
+ break;
+ case 7:
+ memcpy(data, NIST_TEST_DATA_CBC_E7, data_length);
+ memcpy(result, NIST_TEST_RESULT_CBC_E7, data_length);
+ memcpy(iv, NIST_IV_CBC_E7, iv_length);
+ memcpy(expected_iv, NIST_EXPECTED_IV_CBC_E7, iv_length);
+ memcpy(key, NIST_KEY_CBC_E7, key_length);
+ break;
+ case 8:
+ break;
+ case 9:
+ break;
+ case 10:
+ break;
+ case 11:
+ break;
+ case 12:
+ break;
+ }
+
+}
+
+int kat_aes_cbc(int iteration, int silent)
+{
+ unsigned int data_length;
+ unsigned int iv_length;
+ unsigned int key_length;
+
+ get_sizes(&data_length, &iv_length, &key_length, iteration);
+
+ if (!silent) {
+ printf("Test Parameters for iteration = %i\n", iteration);
+ printf("key length = %i, data length = %i, iv length = %i\n",
+ key_length, data_length, iv_length);
+ }
+
+ unsigned char iv[iv_length];
+ unsigned char tmp_iv[iv_length];
+ unsigned char expected_iv[iv_length];
+ unsigned char key[key_length];
+ unsigned char input_data[data_length];
+ unsigned char encrypt[data_length];
+ unsigned char decrypt[data_length];
+ unsigned char result[data_length];
+
+ int rc = 0;
+
+ load_test_data(input_data, data_length, result, iv, expected_iv,
+ iv_length, key, key_length, iteration);
+ memcpy(tmp_iv, iv, iv_length);
+
+ rc = ica_aes_cbc(input_data, encrypt, data_length, key, key_length,
+ tmp_iv, 1);
+ if (rc) {
+ printf("ica_aes_cbc encrypt failed with rc = %i\n", rc);
+ dump_cbc_data(iv, iv_length, key, key_length, input_data,
+ data_length, encrypt);
+ }
+ if (!silent && !rc) {
+ printf("Encrypt:\n");
+ dump_cbc_data(iv, iv_length, key, key_length, input_data,
+ data_length, encrypt);
+ }
+
+ if (memcmp(result, encrypt, data_length)) {
+ printf("Encryption Result does not match the known ciphertext!\n");
+ printf("Expected data:\n");
+ dump_array(result, data_length);
+ printf("Encryption Result:\n");
+ dump_array(encrypt, data_length);
+ rc++;
+ }
+
+ if (memcmp(expected_iv, tmp_iv, iv_length)) {
+ printf("Update of IV does not match the expected IV!\n");
+ printf("Expected IV:\n");
+ dump_array(expected_iv, iv_length);
+ printf("Updated IV:\n");
+ dump_array(tmp_iv, iv_length);
+ printf("Original IV:\n");
+ dump_array(iv, iv_length);
+ rc++;
+ }
+ if (rc) {
+ printf("AES CBC test exited after encryption\n");
+ return rc;
+ }
+
+ memcpy(tmp_iv, iv, iv_length);
+ rc = ica_aes_cbc(encrypt, decrypt, data_length, key, key_length,
+ tmp_iv, 0);
+ if (rc) {
+ printf("ica_aes_cbc decrypt failed with rc = %i\n", rc);
+ dump_cbc_data(iv, iv_length, key, key_length, encrypt,
+ data_length, decrypt);
+ return rc;
+ }
+
+
+ if (!silent && !rc) {
+ printf("Decrypt:\n");
+ dump_cbc_data(iv, iv_length, key, key_length, encrypt,
+ data_length, decrypt);
+ }
+
+ if (memcmp(decrypt, input_data, data_length)) {
+ printf("Decryption Result does not match the original data!\n");
+ printf("Original data:\n");
+ dump_array(input_data, data_length);
+ printf("Decryption Result:\n");
+ dump_array(decrypt, data_length);
+ rc++;
+ }
+ return rc;
+}
+
+int load_random_test_data(unsigned char *data, unsigned int data_length,
+ unsigned char *iv, unsigned int iv_length,
+ unsigned char *key, unsigned int key_length)
+{
+ int rc;
+ rc = ica_random_number_generate(data_length, data);
+ if (rc) {
+ printf("ica_random_number_generate with rc = %i errnor = %i\n",
+ rc, errno);
+ return rc;
+ }
+ rc = ica_random_number_generate(iv_length, iv);
+ if (rc) {
+ printf("ica_random_number_generate with rc = %i errnor = %i\n",
+ rc, errno);
+ return rc;
+ }
+ rc = ica_random_number_generate(key_length, key);
+ if (rc) {
+ printf("ica_random_number_generate with rc = %i errnor = %i\n",
+ rc, errno);
+ return rc;
+ }
+ return rc;
+}
+
+int random_aes_cbc(int iteration, int silent, unsigned int data_length)
+{
+ int i;
+ int rc = 0;
+ unsigned int iv_length = sizeof(ica_aes_vector_t);
+ unsigned int key_length = AES_KEY_LEN128;
+ unsigned char iv[iv_length];
+ unsigned char tmp_iv[iv_length];
+ unsigned char input_data[data_length];
+ unsigned char encrypt[data_length];
+ unsigned char decrypt[data_length];
+for (i = 1; i <= 2; i++) {
+
+ unsigned char key[key_length];
+
+ memset(encrypt, 0x00, data_length);
+ memset(decrypt, 0x00, data_length);
+
+ load_random_test_data(input_data, data_length, iv, iv_length, key,
+ key_length);
+ memcpy(tmp_iv, iv, iv_length);
+
+ if (!silent) {
+ printf("Test Parameters for iteration = %i\n", iteration);
+ printf("key length = %i, data length = %i, iv length = %i\n",
+ key_length, data_length, iv_length);
+ }
+
+ rc = ica_aes_cbc(input_data, encrypt, data_length, key, key_length,
+ tmp_iv, 1);
+ if (rc) {
+ printf("ica_aes_cbc encrypt failed with rc = %i\n", rc);
+ dump_cbc_data(iv, iv_length, key, key_length, input_data,
+ data_length, encrypt);
+ }
+ if (!silent && !rc) {
+ printf("Encrypt:\n");
+ dump_cbc_data(iv, iv_length, key, key_length, input_data,
+ data_length, encrypt);
+ }
+
+ if (rc) {
+ printf("AES CBC test exited after encryption\n");
+ return rc;
+ }
+
+ memcpy(tmp_iv, iv, iv_length);
+
+ rc = ica_aes_cbc(encrypt, decrypt, data_length, key, key_length,
+ tmp_iv, 0);
+ if (rc) {
+ printf("ica_aes_cbc decrypt failed with rc = %i\n", rc);
+ dump_cbc_data(iv, iv_length, key, key_length, encrypt,
+ data_length, decrypt);
+ return rc;
+ }
+
+
+ if (!silent && !rc) {
+ printf("Decrypt:\n");
+ dump_cbc_data(iv, iv_length, key, key_length, encrypt,
+ data_length, decrypt);
+ }
+
+ if (memcmp(decrypt, input_data, data_length)) {
+ printf("Decryption Result does not match the original data!\n");
+ printf("Original data:\n");
+ dump_array(input_data, data_length);
+ printf("Decryption Result:\n");
+ dump_array(decrypt, data_length);
+ rc++;
+ return rc;
+ }
+ key_length += 8;
+}
+
+ return rc;
+}
+
+int main(int argc, char **argv)
+{
+ unsigned int silent = 0;
+ if (argc > 1) {
+ if (strstr(argv[1], "silent"))
+ silent = 1;
+ }
+ int rc = 0;
+ int error_count = 0;
+ int iteration;
+ unsigned int data_length = sizeof(ica_aes_vector_t);
+ for(iteration = 1; iteration <= NR_TESTS; iteration++) {
+ rc = kat_aes_cbc(iteration, silent);
+ if (rc) {
+ printf("kat_aes_cbc failed with rc = %i\n", rc);
+ error_count++;
+ } else {
+ if (!silent) {
+ printf("kat_aes_cbc finished successfully\n");
+ }
+ }
+ }
+ for(iteration = 1; iteration <= NR_RANDOM_TESTS; iteration++) {
+ //int silent = 1;
+ rc = random_aes_cbc(iteration, silent, data_length);
+ if (rc) {
+ printf("random_aes_cbc failed with rc = %i\n", rc);
+ error_count++;
+ goto out;
+ } else {
+ if (!silent) {
+ printf("random_aes_cbc finished successfully\n");
+ }
+ }
+ data_length += sizeof(ica_aes_vector_t);
+ }
+
+out:
+ if (error_count)
+ printf("%i testcases failed\n", error_count);
+ else {
+ printf("All AES-CBC testcases finished successfully\n");
+ }
+
+ return rc;
+}
+
diff --git a/src/tests/libica_aes_cfb_test.c b/src/tests/libica_aes_cfb_test.c
new file mode 100644
index 0000000..2663dfa
--- /dev/null
+++ b/src/tests/libica_aes_cfb_test.c
@@ -0,0 +1,832 @@
+/* This program is released under the Common Public License V1.0
+ *
+ * You should have received a copy of Common Public License V1.0 along with
+ * with this program.
+ */
+
+/* Copyright IBM Corp. 2010, 2011 */
+#include <fcntl.h>
+#include <sys/errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+#include <stdlib.h>
+#include "ica_api.h"
+
+#define NR_TESTS 12
+#define NR_RANDOM_TESTS 1000
+
+/* CFB128 data -1- AES128 */
+unsigned char NIST_KEY_CFB_E1[] = {
+ 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
+ 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c,
+};
+
+unsigned char NIST_IV_CFB_E1[] = {
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+};
+
+unsigned char NIST_EXPECTED_IV_CFB_E1[] = {
+ 0x3b, 0x3f, 0xd9, 0x2e, 0xb7, 0x2d, 0xad, 0x20,
+ 0x33, 0x34, 0x49, 0xf8, 0xe8, 0x3c, 0xfb, 0x4a,
+};
+
+unsigned char NIST_TEST_DATA_CFB_E1[] = {
+ 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
+ 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
+};
+
+unsigned char NIST_TEST_RESULT_CFB_E1[] = {
+ 0x3b, 0x3f, 0xd9, 0x2e, 0xb7, 0x2d, 0xad, 0x20,
+ 0x33, 0x34, 0x49, 0xf8, 0xe8, 0x3c, 0xfb, 0x4a,
+};
+
+unsigned int NIST_LCFB_E1 = 128 / 8;
+
+/* CFB128 data -2- AES128 */
+unsigned char NIST_KEY_CFB_E2[] = {
+ 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
+ 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c,
+};
+
+unsigned char NIST_IV_CFB_E2[] = {
+ 0x3b, 0x3f, 0xd9, 0x2e, 0xb7, 0x2d, 0xad, 0x20,
+ 0x33, 0x34, 0x49, 0xf8, 0xe8, 0x3c, 0xfb, 0x4a,
+};
+
+unsigned char NIST_EXPECTED_IV_CFB_E2[] = {
+ 0xc8, 0xa6, 0x45, 0x37, 0xa0, 0xb3, 0xa9, 0x3f,
+ 0xcd, 0xe3, 0xcd, 0xad, 0x9f, 0x1c, 0xe5, 0x8b,
+};
+
+unsigned char NIST_TEST_DATA_CFB_E2[] = {
+ 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
+ 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
+};
+
+unsigned char NIST_TEST_RESULT_CFB_E2[] = {
+ 0xc8, 0xa6, 0x45, 0x37, 0xa0, 0xb3, 0xa9, 0x3f,
+ 0xcd, 0xe3, 0xcd, 0xad, 0x9f, 0x1c, 0xe5, 0x8b,
+};
+
+unsigned int NIST_LCFB_E2 = 128 / 8;
+
+/* CFB8 data -3- AES128 */
+unsigned char NIST_KEY_CFB_E3[] = {
+ 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
+ 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c,
+};
+
+unsigned char NIST_IV_CFB_E3[] = {
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+};
+
+unsigned char NIST_EXPECTED_IV_CFB_E3[] = {
+ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
+ 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x3b,
+};
+unsigned char NIST_TEST_DATA_CFB_E3[] = {
+ 0x6b,
+};
+
+unsigned char NIST_TEST_RESULT_CFB_E3[] = {
+ 0x3b,
+};
+unsigned int NIST_LCFB_E3 = 8 / 8;
+
+/* CFB8 data -4- AES128 */
+unsigned char NIST_KEY_CFB_E4[] = {
+ 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
+ 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c,
+};
+
+unsigned char NIST_IV_CFB_E4[] = {
+ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
+ 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x3b,
+};
+
+unsigned char NIST_EXPECTED_IV_CFB_E4[] = {
+ 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
+ 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x3b, 0x79,
+};
+unsigned char NIST_TEST_DATA_CFB_E4[] = {
+ 0xc1,
+};
+
+unsigned char NIST_TEST_RESULT_CFB_E4[] = {
+ 0x79,
+};
+
+unsigned int NIST_LCFB_E4 = 8 / 8;
+
+
+/* CFB 128 data -5- for AES192 */
+unsigned char NIST_KEY_CFB_E5[] = {
+ 0x8e, 0x73, 0xb0, 0xf7, 0xda, 0x0e, 0x64, 0x52,
+ 0xc8, 0x10, 0xf3, 0x2b, 0x80, 0x90, 0x79, 0xe5,
+ 0x62, 0xf8, 0xea, 0xd2, 0x52, 0x2c, 0x6b, 0x7b,
+};
+
+unsigned char NIST_IV_CFB_E5[] = {
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+};
+
+unsigned char NIST_EXPECTED_IV_CFB_E5[] = {
+ 0xcd, 0xc8, 0x0d, 0x6f, 0xdd, 0xf1, 0x8c, 0xab,
+ 0x34, 0xc2, 0x59, 0x09, 0xc9, 0x9a, 0x41, 0x74,
+};
+
+unsigned char NIST_TEST_DATA_CFB_E5[] = {
+ 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
+ 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
+};
+
+unsigned char NIST_TEST_RESULT_CFB_E5[] = {
+ 0xcd, 0xc8, 0x0d, 0x6f, 0xdd, 0xf1, 0x8c, 0xab,
+ 0x34, 0xc2, 0x59, 0x09, 0xc9, 0x9a, 0x41, 0x74,
+};
+
+unsigned int NIST_LCFB_E5 = 128 / 8;
+
+/* CFB 128 data -6- for AES192 */
+unsigned char NIST_KEY_CFB_E6[] = {
+ 0x8e, 0x73, 0xb0, 0xf7, 0xda, 0x0e, 0x64, 0x52,
+ 0xc8, 0x10, 0xf3, 0x2b, 0x80, 0x90, 0x79, 0xe5,
+ 0x62, 0xf8, 0xea, 0xd2, 0x52, 0x2c, 0x6b, 0x7b,
+};
+
+unsigned char NIST_IV_CFB_E6[] = {
+ 0xcd, 0xc8, 0x0d, 0x6f, 0xdd, 0xf1, 0x8c, 0xab,
+ 0x34, 0xc2, 0x59, 0x09, 0xc9, 0x9a, 0x41, 0x74,
+};
+
+unsigned char NIST_EXPECTED_IV_CFB_E6[] = {
+ 0x67, 0xce, 0x7f, 0x7f, 0x81, 0x17, 0x36, 0x21,
+ 0x96, 0x1a, 0x2b, 0x70, 0x17, 0x1d, 0x3d, 0x7a,
+};
+
+unsigned char NIST_TEST_DATA_CFB_E6[] = {
+ 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
+ 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
+};
+
+unsigned char NIST_TEST_RESULT_CFB_E6[] = {
+ 0x67, 0xce, 0x7f, 0x7f, 0x81, 0x17, 0x36, 0x21,
+ 0x96, 0x1a, 0x2b, 0x70, 0x17, 0x1d, 0x3d, 0x7a,
+};
+
+unsigned int NIST_LCFB_E6 = 128 / 8;
+
+/* CFB 128 data -7- for AES192 */
+unsigned char NIST_KEY_CFB_E7[] = {
+ 0x8e, 0x73, 0xb0, 0xf7, 0xda, 0x0e, 0x64, 0x52,
+ 0xc8, 0x10, 0xf3, 0x2b, 0x80, 0x90, 0x79, 0xe5,
+ 0x62, 0xf8, 0xea, 0xd2, 0x52, 0x2c, 0x6b, 0x7b,
+};
+
+unsigned char NIST_IV_CFB_E7[] = {
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+};
+
+unsigned char NIST_EXPECTED_IV_CFB_E7[] = {
+ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
+ 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0xcd,
+};
+
+unsigned char NIST_TEST_DATA_CFB_E7[] = {
+ 0x6b,
+};
+
+unsigned char NIST_TEST_RESULT_CFB_E7[] = {
+ 0xcd,
+};
+
+unsigned int NIST_LCFB_E7 = 8 / 8;
+
+/* CFB 128 data -8- for AES192 */
+unsigned char NIST_KEY_CFB_E8[] = {
+ 0x8e, 0x73, 0xb0, 0xf7, 0xda, 0x0e, 0x64, 0x52,
+ 0xc8, 0x10, 0xf3, 0x2b, 0x80, 0x90, 0x79, 0xe5,
+ 0x62, 0xf8, 0xea, 0xd2, 0x52, 0x2c, 0x6b, 0x7b,
+};
+
+unsigned char NIST_IV_CFB_E8[] = {
+ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
+ 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0xcd,
+};
+
+unsigned char NIST_EXPECTED_IV_CFB_E8[] = {
+ 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
+ 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0xcd, 0xa2,
+};
+
+unsigned char NIST_TEST_DATA_CFB_E8[] = {
+ 0xc1,
+};
+
+unsigned char NIST_TEST_RESULT_CFB_E8[] = {
+ 0xa2,
+};
+
+unsigned int NIST_LCFB_E8 = 8 / 8;
+
+
+
+/* CFB128 data -9- for AES256 */
+unsigned char NIST_KEY_CFB_E9[] = {
+ 0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe,
+ 0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81,
+ 0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7,
+ 0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4,
+};
+
+unsigned char NIST_IV_CFB_E9[] = {
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+};
+
+unsigned char NIST_EXPECTED_IV_CFB_E9[] = {
+ 0xdc, 0x7e, 0x84, 0xbf, 0xda, 0x79, 0x16, 0x4b,
+ 0x7e, 0xcd, 0x84, 0x86, 0x98, 0x5d, 0x38, 0x60,
+};
+
+unsigned char NIST_TEST_DATA_CFB_E9[] = {
+ 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
+ 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
+};
+
+unsigned char NIST_TEST_RESULT_CFB_E9[] = {
+ 0xdc, 0x7e, 0x84, 0xbf, 0xda, 0x79, 0x16, 0x4b,
+ 0x7e, 0xcd, 0x84, 0x86, 0x98, 0x5d, 0x38, 0x60,
+};
+
+unsigned int NIST_LCFB_E9 = 128 / 8;
+
+/* CFB128 data -10- for AES256 */
+unsigned char NIST_KEY_CFB_E10[] = {
+ 0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe,
+ 0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81,
+ 0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7,
+ 0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4,
+};
+
+unsigned char NIST_IV_CFB_E10[] = {
+ 0xdc, 0x7e, 0x84, 0xbf, 0xda, 0x79, 0x16, 0x4b,
+ 0x7e, 0xcd, 0x84, 0x86, 0x98, 0x5d, 0x38, 0x60,
+};
+
+unsigned char NIST_EXPECTED_IV_CFB_E10[] = {
+ 0x39, 0xff, 0xed, 0x14, 0x3b, 0x28, 0xb1, 0xc8,
+ 0x32, 0x11, 0x3c, 0x63, 0x31, 0xe5, 0x40, 0x7b,
+};
+
+unsigned char NIST_TEST_DATA_CFB_E10[] = {
+ 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
+ 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
+};
+
+unsigned char NIST_TEST_RESULT_CFB_E10[] = {
+ 0x39, 0xff, 0xed, 0x14, 0x3b, 0x28, 0xb1, 0xc8,
+ 0x32, 0x11, 0x3c, 0x63, 0x31, 0xe5, 0x40, 0x7b,
+};
+
+unsigned int NIST_LCFB_E10 = 128 / 8;
+
+/* CFB8 data -11- for AES256 */
+unsigned char NIST_KEY_CFB_E11[] = {
+ 0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe,
+ 0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81,
+ 0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7,
+ 0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4,
+};
+
+unsigned char NIST_IV_CFB_E11[] = {
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+};
+
+unsigned char NIST_EXPECTED_IV_CFB_E11[] = {
+ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
+ 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0xdc,
+};
+
+unsigned char NIST_TEST_DATA_CFB_E11[] = {
+ 0x6b,
+};
+
+unsigned char NIST_TEST_RESULT_CFB_E11[] = {
+ 0xdc,
+};
+
+unsigned int NIST_LCFB_E11 = 8 / 8;
+
+/* CFB8 data -12- for AES256 */
+unsigned char NIST_KEY_CFB_E12[] = {
+ 0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe,
+ 0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81,
+ 0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7,
+ 0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4,
+};
+
+unsigned char NIST_IV_CFB_E12[] = {
+ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
+ 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0xdc,
+};
+
+unsigned char NIST_EXPECTED_IV_CFB_E12[] = {
+ 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
+ 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0xdc, 0x1f,
+};
+
+unsigned char NIST_TEST_DATA_CFB_E12[] = {
+ 0xc1,
+};
+
+unsigned char NIST_TEST_RESULT_CFB_E12[] = {
+ 0x1f,
+};
+
+unsigned int NIST_LCFB_E12 = 8 / 8;
+
+
+void dump_array(unsigned char *ptr, unsigned int size)
+{
+ unsigned char *ptr_end;
+ unsigned char *h;
+ int i = 1;
+
+ h = ptr;
+ ptr_end = ptr + size;
+ while (h < (unsigned char *)ptr_end) {
+ printf("0x%02x ",(unsigned char ) *h);
+ h++;
+ if (i == 8) {
+ printf("\n");
+ i = 1;
+ } else {
+ ++i;
+ }
+ }
+ printf("\n");
+}
+
+void dump_cfb_data(unsigned char *iv, unsigned int iv_length,
+ unsigned char *key, unsigned int key_length,
+ unsigned char *input_data, unsigned int data_length,
+ unsigned char *output_data)
+{
+ printf("IV \n");
+ dump_array(iv, iv_length);
+ printf("Key \n");
+ dump_array(key, key_length);
+ printf("Input Data\n");
+ dump_array(input_data, data_length);
+ printf("Output Data\n");
+ dump_array(output_data, data_length);
+}
+
+void get_sizes(unsigned int *data_length, unsigned int *iv_length,
+ unsigned int *key_length, unsigned int iteration)
+{
+ switch (iteration) {
+ case 1:
+ *data_length = sizeof(NIST_TEST_DATA_CFB_E1);
+ *iv_length = sizeof(NIST_IV_CFB_E1);
+ *key_length = sizeof(NIST_KEY_CFB_E1);
+ break;
+ case 2:
+ *data_length = sizeof(NIST_TEST_DATA_CFB_E2);
+ *iv_length = sizeof(NIST_IV_CFB_E2);
+ *key_length = sizeof(NIST_KEY_CFB_E2);
+ break;
+ case 3:
+ *data_length = sizeof(NIST_TEST_DATA_CFB_E3);
+ *iv_length = sizeof(NIST_IV_CFB_E3);
+ *key_length = sizeof(NIST_KEY_CFB_E3);
+ break;
+ case 4:
+ *data_length = sizeof(NIST_TEST_DATA_CFB_E4);
+ *iv_length = sizeof(NIST_IV_CFB_E4);
+ *key_length = sizeof(NIST_KEY_CFB_E4);
+ break;
+ case 5:
+ *data_length = sizeof(NIST_TEST_DATA_CFB_E5);
+ *iv_length = sizeof(NIST_IV_CFB_E5);
+ *key_length = sizeof(NIST_KEY_CFB_E5);
+ break;
+ case 6:
+ *data_length = sizeof(NIST_TEST_DATA_CFB_E6);
+ *iv_length = sizeof(NIST_IV_CFB_E6);
+ *key_length = sizeof(NIST_KEY_CFB_E6);
+ break;
+ case 7:
+ *data_length = sizeof(NIST_TEST_DATA_CFB_E7);
+ *iv_length = sizeof(NIST_IV_CFB_E7);
+ *key_length = sizeof(NIST_KEY_CFB_E7);
+ break;
+ case 8:
+ *data_length = sizeof(NIST_TEST_DATA_CFB_E8);
+ *iv_length = sizeof(NIST_IV_CFB_E8);
+ *key_length = sizeof(NIST_KEY_CFB_E8);
+ break;
+ case 9:
+ *data_length = sizeof(NIST_TEST_DATA_CFB_E9);
+ *iv_length = sizeof(NIST_IV_CFB_E9);
+ *key_length = sizeof(NIST_KEY_CFB_E9);
+ break;
+ case 10:
+ *data_length = sizeof(NIST_TEST_DATA_CFB_E10);
+ *iv_length = sizeof(NIST_IV_CFB_E10);
+ *key_length = sizeof(NIST_KEY_CFB_E10);
+ break;
+ case 11:
+ *data_length = sizeof(NIST_TEST_DATA_CFB_E11);
+ *iv_length = sizeof(NIST_IV_CFB_E11);
+ *key_length = sizeof(NIST_KEY_CFB_E11);
+ break;
+ case 12:
+ *data_length = sizeof(NIST_TEST_DATA_CFB_E12);
+ *iv_length = sizeof(NIST_IV_CFB_E12);
+ *key_length = sizeof(NIST_KEY_CFB_E12);
+ break;
+ }
+
+}
+
+void load_test_data(unsigned char *data, unsigned int data_length,
+ unsigned char *result,
+ unsigned char *iv, unsigned char *expected_iv,
+ unsigned int iv_length,
+ unsigned char *key, unsigned int key_length,
+ unsigned int *lcfb, unsigned int iteration)
+{
+ switch (iteration) {
+ case 1:
+ memcpy(data, NIST_TEST_DATA_CFB_E1, data_length);
+ memcpy(result, NIST_TEST_RESULT_CFB_E1, data_length);
+ memcpy(iv, NIST_IV_CFB_E1, iv_length);
+ memcpy(expected_iv, NIST_EXPECTED_IV_CFB_E1, iv_length);
+ memcpy(key, NIST_KEY_CFB_E1, key_length);
+ *lcfb = NIST_LCFB_E1;
+ break;
+ case 2:
+ memcpy(data, NIST_TEST_DATA_CFB_E2, data_length);
+ memcpy(result, NIST_TEST_RESULT_CFB_E2, data_length);
+ memcpy(iv, NIST_IV_CFB_E2, iv_length);
+ memcpy(expected_iv, NIST_EXPECTED_IV_CFB_E2, iv_length);
+ memcpy(key, NIST_KEY_CFB_E2, key_length);
+ *lcfb = NIST_LCFB_E2;
+ break;
+ case 3:
+ memcpy(data, NIST_TEST_DATA_CFB_E3, data_length);
+ memcpy(result, NIST_TEST_RESULT_CFB_E3, data_length);
+ memcpy(iv, NIST_IV_CFB_E3, iv_length);
+ memcpy(expected_iv, NIST_EXPECTED_IV_CFB_E3, iv_length);
+ memcpy(key, NIST_KEY_CFB_E3, key_length);
+ *lcfb = NIST_LCFB_E3;
+ break;
+ case 4:
+ memcpy(data, NIST_TEST_DATA_CFB_E4, data_length);
+ memcpy(result, NIST_TEST_RESULT_CFB_E4, data_length);
+ memcpy(iv, NIST_IV_CFB_E4, iv_length);
+ memcpy(expected_iv, NIST_EXPECTED_IV_CFB_E4, iv_length);
+ memcpy(key, NIST_KEY_CFB_E4, key_length);
+ *lcfb = NIST_LCFB_E4;
+ break;
+ case 5:
+ memcpy(data, NIST_TEST_DATA_CFB_E5, data_length);
+ memcpy(result, NIST_TEST_RESULT_CFB_E5, data_length);
+ memcpy(iv, NIST_IV_CFB_E5, iv_length);
+ memcpy(expected_iv, NIST_EXPECTED_IV_CFB_E5, iv_length);
+ memcpy(key, NIST_KEY_CFB_E5, key_length);
+ *lcfb = NIST_LCFB_E5;
+ break;
+ case 6:
+ memcpy(data, NIST_TEST_DATA_CFB_E6, data_length);
+ memcpy(result, NIST_TEST_RESULT_CFB_E6, data_length);
+ memcpy(iv, NIST_IV_CFB_E6, iv_length);
+ memcpy(expected_iv, NIST_EXPECTED_IV_CFB_E6, iv_length);
+ memcpy(key, NIST_KEY_CFB_E6, key_length);
+ *lcfb = NIST_LCFB_E6;
+ break;
+ case 7:
+ memcpy(data, NIST_TEST_DATA_CFB_E7, data_length);
+ memcpy(result, NIST_TEST_RESULT_CFB_E7, data_length);
+ memcpy(iv, NIST_IV_CFB_E7, iv_length);
+ memcpy(expected_iv, NIST_EXPECTED_IV_CFB_E7, iv_length);
+ memcpy(key, NIST_KEY_CFB_E7, key_length);
+ *lcfb = NIST_LCFB_E7;
+ break;
+ case 8:
+ memcpy(data, NIST_TEST_DATA_CFB_E8, data_length);
+ memcpy(result, NIST_TEST_RESULT_CFB_E8, data_length);
+ memcpy(iv, NIST_IV_CFB_E8, iv_length);
+ memcpy(expected_iv, NIST_EXPECTED_IV_CFB_E8, iv_length);
+ memcpy(key, NIST_KEY_CFB_E8, key_length);
+ *lcfb = NIST_LCFB_E8;
+ break;
+ case 9:
+ memcpy(data, NIST_TEST_DATA_CFB_E9, data_length);
+ memcpy(result, NIST_TEST_RESULT_CFB_E9, data_length);
+ memcpy(iv, NIST_IV_CFB_E9, iv_length);
+ memcpy(expected_iv, NIST_EXPECTED_IV_CFB_E9, iv_length);
+ memcpy(key, NIST_KEY_CFB_E9, key_length);
+ *lcfb = NIST_LCFB_E9;
+ break;
+ case 10:
+ memcpy(data, NIST_TEST_DATA_CFB_E10, data_length);
+ memcpy(result, NIST_TEST_RESULT_CFB_E10, data_length);
+ memcpy(iv, NIST_IV_CFB_E10, iv_length);
+ memcpy(expected_iv, NIST_EXPECTED_IV_CFB_E10, iv_length);
+ memcpy(key, NIST_KEY_CFB_E10, key_length);
+ *lcfb = NIST_LCFB_E10;
+ break;
+ case 11:
+ memcpy(data, NIST_TEST_DATA_CFB_E11, data_length);
+ memcpy(result, NIST_TEST_RESULT_CFB_E11, data_length);
+ memcpy(iv, NIST_IV_CFB_E11, iv_length);
+ memcpy(expected_iv, NIST_EXPECTED_IV_CFB_E11, iv_length);
+ memcpy(key, NIST_KEY_CFB_E11, key_length);
+ *lcfb = NIST_LCFB_E11;
+ break;
+ case 12:
+ memcpy(data, NIST_TEST_DATA_CFB_E12, data_length);
+ memcpy(result, NIST_TEST_RESULT_CFB_E12, data_length);
+ memcpy(iv, NIST_IV_CFB_E12, iv_length);
+ memcpy(expected_iv, NIST_EXPECTED_IV_CFB_E12, iv_length);
+ memcpy(key, NIST_KEY_CFB_E12, key_length);
+ *lcfb = NIST_LCFB_E12;
+ break;
+ }
+
+}
+
+int kat_aes_cfb(int iteration, int silent)
+{
+ unsigned int data_length;
+ unsigned int iv_length;
+ unsigned int key_length;
+
+ get_sizes(&data_length, &iv_length, &key_length, iteration);
+
+
+ unsigned char iv[iv_length];
+ unsigned char tmp_iv[iv_length];
+ unsigned char expected_iv[iv_length];
+ unsigned char key[key_length];
+ unsigned char input_data[data_length];
+ unsigned char encrypt[data_length];
+ unsigned char decrypt[data_length];
+ unsigned char result[data_length];
+
+ int rc = 0;
+ unsigned int lcfb;
+ memset(encrypt, 0x00, data_length);
+ memset(decrypt, 0x00, data_length);
+
+ load_test_data(input_data, data_length, result, iv, expected_iv,
+ iv_length, key, key_length, &lcfb, iteration);
+ memcpy(tmp_iv, iv, iv_length);
+
+ if (!silent) {
+ printf("Test Parameters for iteration = %i\n", iteration);
+ printf("key length = %i, data length = %i, iv length = %i,"
+ " lcfb = %i\n", key_length, data_length, iv_length, lcfb);
+ }
+ if (iteration == 3)
+ rc = ica_aes_cfb(input_data, encrypt, lcfb, key, key_length, tmp_iv,
+ lcfb, 1);
+ else
+ rc = ica_aes_cfb(input_data, encrypt, data_length, key, key_length,
+ tmp_iv, lcfb, 1);
+ if (rc) {
+ printf("ica_aes_cfb encrypt failed with rc = %i\n", rc);
+ dump_cfb_data(iv, iv_length, key, key_length, input_data,
+ data_length, encrypt);
+ }
+ if (!silent && !rc) {
+ printf("Encrypt:\n");
+ dump_cfb_data(iv, iv_length, key, key_length, input_data,
+ data_length, encrypt);
+ }
+
+ if (memcmp(result, encrypt, data_length)) {
+ printf("Encryption Result does not match the known ciphertext!\n");
+ printf("Expected data:\n");
+ dump_array(result, data_length);
+ printf("Encryption Result:\n");
+ dump_array(encrypt, data_length);
+ rc++;
+ }
+
+ if (memcmp(expected_iv, tmp_iv, iv_length)) {
+ printf("Update of IV does not match the expected IV!\n");
+ printf("Expected IV:\n");
+ dump_array(expected_iv, iv_length);
+ printf("Updated IV:\n");
+ dump_array(tmp_iv, iv_length);
+ printf("Original IV:\n");
+ dump_array(iv, iv_length);
+ rc++;
+ }
+ if (rc) {
+ printf("AES OFB test exited after encryption\n");
+ return rc;
+ }
+
+ memcpy(tmp_iv, iv, iv_length);
+ if (iteration == 3)
+ rc = ica_aes_cfb(encrypt, decrypt, lcfb, key, key_length, tmp_iv,
+ lcfb, 0);
+ else
+ rc = ica_aes_cfb(encrypt, decrypt, data_length, key, key_length,
+ tmp_iv, lcfb, 0);
+ if (rc) {
+ printf("ica_aes_cfb decrypt failed with rc = %i\n", rc);
+ dump_cfb_data(iv, iv_length, key, key_length, encrypt,
+ data_length, decrypt);
+ return rc;
+ }
+
+
+ if (!silent && !rc) {
+ printf("Decrypt:\n");
+ dump_cfb_data(iv, iv_length, key, key_length, encrypt,
+ data_length, decrypt);
+ }
+
+ if (memcmp(decrypt, input_data, data_length)) {
+ printf("Decryption Result does not match the original data!\n");
+ printf("Original data:\n");
+ dump_array(input_data, data_length);
+ printf("Decryption Result:\n");
+ dump_array(decrypt, data_length);
+ rc++;
+ }
+ return rc;
+}
+
+int load_random_test_data(unsigned char *data, unsigned int data_length,
+ unsigned char *iv, unsigned int iv_length,
+ unsigned char *key, unsigned int key_length)
+{
+ int rc;
+ rc = ica_random_number_generate(data_length, data);
+ if (rc) {
+ printf("ica_random_number_generate with rc = %i errnor = %i\n",
+ rc, errno);
+ return rc;
+ }
+ rc = ica_random_number_generate(iv_length, iv);
+ if (rc) {
+ printf("ica_random_number_generate with rc = %i errnor = %i\n",
+ rc, errno);
+ return rc;
+ }
+ rc = ica_random_number_generate(key_length, key);
+ if (rc) {
+ printf("ica_random_number_generate with rc = %i errnor = %i\n",
+ rc, errno);
+ return rc;
+ }
+ return rc;
+}
+
+int random_aes_cfb(int iteration, int silent, unsigned int data_length,
+ unsigned int lcfb)
+{
+ unsigned int iv_length = sizeof(ica_aes_vector_t);
+ unsigned int key_length = AES_KEY_LEN128;
+
+ unsigned char iv[iv_length];
+ unsigned char tmp_iv[iv_length];
+ unsigned char key[key_length];
+ unsigned char input_data[data_length];
+ unsigned char encrypt[data_length];
+ unsigned char decrypt[data_length];
+
+ int rc = 0;
+ for (key_length = AES_KEY_LEN128; key_length <= AES_KEY_LEN256; key_length += 8) {
+ memset(encrypt, 0x00, data_length);
+ memset(decrypt, 0x00, data_length);
+
+ load_random_test_data(input_data, data_length, iv, iv_length, key,
+ key_length);
+ memcpy(tmp_iv, iv, iv_length);
+
+ if (!silent) {
+ printf("Test Parameters for iteration = %i\n", iteration);
+ printf("key length = %i, data length = %i, iv length = %i,"
+ " lcfb = %i\n", key_length, data_length, iv_length, lcfb);
+ }
+ rc = ica_aes_cfb(input_data, encrypt, data_length, key, key_length,
+ tmp_iv, lcfb, 1);
+ if (rc) {
+ printf("ica_aes_cfb encrypt failed with rc = %i\n", rc);
+ dump_cfb_data(iv, iv_length, key, key_length, input_data,
+ data_length, encrypt);
+ }
+ if (!silent && !rc) {
+ printf("Encrypt:\n");
+ dump_cfb_data(iv, iv_length, key, key_length, input_data,
+ data_length, encrypt);
+ }
+
+ if (rc) {
+ printf("AES OFB test exited after encryption\n");
+ return rc;
+ }
+
+ memcpy(tmp_iv, iv, iv_length);
+
+ rc = ica_aes_cfb(encrypt, decrypt, data_length, key, key_length,
+ tmp_iv, lcfb, 0);
+ if (rc) {
+ printf("ica_aes_cfb decrypt failed with rc = %i\n", rc);
+ dump_cfb_data(iv, iv_length, key, key_length, encrypt,
+ data_length, decrypt);
+ return rc;
+ }
+
+
+ if (!silent && !rc) {
+ printf("Decrypt:\n");
+ dump_cfb_data(iv, iv_length, key, key_length, encrypt,
+ data_length, decrypt);
+ }
+
+ if (memcmp(decrypt, input_data, data_length)) {
+ printf("Decryption Result does not match the original data!\n");
+ printf("Original data:\n");
+ dump_array(input_data, data_length);
+ printf("Decryption Result:\n");
+ dump_array(decrypt, data_length);
+ rc++;
+ }
+ }
+ return rc;
+}
+
+int main(int argc, char **argv)
+{
+ unsigned int silent = 0;
+ if (argc > 1) {
+ if (strstr(argv[1], "silent"))
+ silent = 1;
+ }
+ int rc = 0;
+ int error_count = 0;
+ int iteration;
+ for(iteration = 1; iteration <= NR_TESTS; iteration++) {
+ rc = kat_aes_cfb(iteration, silent);
+ if (rc) {
+ printf("kat_aes_cfb failed with rc = %i\n", rc);
+ error_count++;
+ }
+ }
+
+ unsigned int data_length = 1;
+ unsigned int lcfb = 1;
+ unsigned int j;
+ unsigned int rdata;
+ for(iteration = 1; iteration <= NR_RANDOM_TESTS; iteration++) {
+ for (j = 1; j <= 3; j++) {
+ if (!(data_length % lcfb)) {
+ rc = random_aes_cfb(iteration, silent, data_length, lcfb);
+ if (rc) {
+ printf("random_aes_cfb failed with rc = %i\n", rc);
+ error_count++;
+ }
+ }
+ switch (j) {
+ case 1:
+ lcfb = 1;
+ break;
+ case 2:
+ lcfb = 8;
+ break;
+ case 3:
+ lcfb = 16;
+ break;
+ }
+ }
+ // add a value between 1 and 8 to data_length
+ if (ica_random_number_generate(sizeof(rdata), (unsigned char*) &rdata)) {
+ printf("ica_random_number_generate failed with errnor = %i\n",
+ errno);
+ exit(1);
+ }
+ data_length += (rdata % 8) + 1;
+ }
+ if (error_count)
+ printf("%i testcases failed\n", error_count);
+ else
+ printf("All AES-CFB testcases finished successfully\n");
+
+ return rc;
+}
+
diff --git a/src/tests/libica_aes_ctr_test.c b/src/tests/libica_aes_ctr_test.c
new file mode 100644
index 0000000..6195c9d
--- /dev/null
+++ b/src/tests/libica_aes_ctr_test.c
@@ -0,0 +1,661 @@
+/* This program is released under the Common Public License V1.0
+ *
+ * You should have received a copy of Common Public License V1.0 along with
+ * with this program.
+ */
+
+/* Copyright IBM Corp. 2010, 2011 */
+#include <fcntl.h>
+#include <sys/errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+#include <stdlib.h>
+#include "ica_api.h"
+
+#define NR_TESTS 7
+#define NR_RANDOM_TESTS 1000
+
+/* CTR data - 1 for AES128 */
+unsigned char NIST_KEY_CTR_E1[] = {
+ 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
+ 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c,
+};
+
+unsigned char NIST_IV_CTR_E1[] = {
+ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
+ 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
+};
+
+unsigned char NIST_EXPECTED_IV_CTR_E1[] = {
+ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
+ 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xff, 0x00,
+};
+
+unsigned char NIST_TEST_DATA_CTR_E1[] = {
+ 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
+ 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
+};
+
+unsigned char NIST_TEST_RESULT_CTR_E1[] = {
+ 0x87, 0x4d, 0x61, 0x91, 0xb6, 0x20, 0xe3, 0x26,
+ 0x1b, 0xef, 0x68, 0x64, 0x99, 0x0d, 0xb6, 0xce,
+};
+
+/* CTR data - 2 for AES128 */
+unsigned char NIST_KEY_CTR_E2[] = {
+ 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
+ 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c,
+};
+
+unsigned char NIST_I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, 0xd1,
+ 0x79, 0x21, 0x70, 0xa0, 0xf3, 0x00, 0x9c, 0xee,
+};
+
+/* CTR data - 3 - for AES192 */
+unsigned char NIST_KEY_CTR_E3[] = {
+ 0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe,
+ 0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81,
+ 0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7,
+ 0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4,
+};
+
+unsigned char NIST_IV_CTR_E3[] = {
+ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
+ 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
+};
+
+unsigned char NIST_EXPECTED_IV_CTR_E3[] = {
+ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
+ 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xff, 0x00,
+};
+
+unsigned char NIST_TEST_DATA_CTR_E3[] = {
+ 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
+ 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
+};
+
+unsigned char NIST_TEST_RESULT_CTR_E3[] = {
+ 0x60, 0x1e, 0xc3, 0x13, 0x77, 0x57, 0x89, 0xa5,
+ 0xb7, 0xa7, 0xf5, 0x04, 0xbb, 0xf3, 0xd2, 0x28,
+};
+
+/* CTR data - 4 - for AES192 */
+unsigned char NIST_KEY_CTR_E4[] = {
+ 0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe,
+ 0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81,
+ 0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7,
+ 0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4,
+};
+
+unsigned char NIST_IV_CTR_E4[] = {
+ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
+ 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xff, 0x00,
+};
+
+unsigned char NIST_EXPECTED_IV_CTR_E4[] = {
+ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
+ 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xff, 0x01,
+};
+
+unsigned char NIST_TEST_DATA_CTR_E4[] = {
+ 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
+ 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
+};
+
+unsigned char NIST_TEST_RESULT_CTR_E4[] = {
+ 0xf4, 0x43, 0xe3, 0xca, 0x4d, 0x62, 0xb5, 0x9a,
+ 0xca, 0x84, 0xe9, 0x90, 0xca, 0xca, 0xf5, 0xc5,
+};
+
+/* CTR data 5 - for AES 256 */
+unsigned char NIST_KEY_CTR_E5[] = {
+ 0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe,
+ 0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81,
+ 0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7,
+ 0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4,
+};
+
+unsigned char NIST_IV_CTR_E5[] = {
+ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
+ 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
+};
+
+unsigned char NIST_EXPECTED_IV_CTR_E5[] = {
+ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
+ 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xff, 0x03,
+};
+
+unsigned char NIST_TEST_DATA_CTR_E5[] = {
+ 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
+ 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
+ 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
+ 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
+ 0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11,
+ 0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef,
+ 0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17,
+ 0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10,
+};
+
+unsigned char NIST_TEST_RESULT_CTR_E5[] = {
+ 0x60, 0x1e, 0xc3, 0x13, 0x77, 0x57, 0x89, 0xa5,
+ 0xb7, 0xa7, 0xf5, 0x04, 0xbb, 0xf3, 0xd2, 0x28,
+ 0xf4, 0x43, 0xe3, 0xca, 0x4d, 0x62, 0xb5, 0x9a,
+ 0xca, 0x84, 0xe9, 0x90, 0xca, 0xca, 0xf5, 0xc5,
+ 0x2b, 0x09, 0x30, 0xda, 0xa2, 0x3d, 0xe9, 0x4c,
+ 0xe8, 0x70, 0x17, 0xba, 0x2d, 0x84, 0x98, 0x8d,
+ 0xdf, 0xc9, 0xc5, 0x8d, 0xb6, 0x7a, 0xad, 0xa6,
+ 0x13, 0xc2, 0xdd, 0x08, 0x45, 0x79, 0x41, 0xa6,
+};
+
+/* CTR data 6 - for AES 256.
+ * Data is != BLOCK_SIZE */
+unsigned char NIST_KEY_CTR_E6[] = {
+ 0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe,
+ 0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81,
+ 0x1f, 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84, 0x98, 0x8d,
+ 0xdf, 0xc9, 0xc5, 0x8d, 0xb6, 0x7a, 0xad, 0xa6,
+};
+
+/* CTR data 7 - for AES 256
+ * Counter as big as the data. Therefore the counter
+ * should not be updated. Because it is already pre
+ * computed. */
+unsigned char NIST_KEY_CTR_E7[] = {
+ 0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe,
+ 0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81,
+ 0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7,
+ 0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4,
+};
+
+unsigned char NIST_IV_CTR_E7[] = {
+ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
+ 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
+ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
+ 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xff, 0x00,
+ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
+ 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xff, 0x01,
+ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
+ 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xff, 0x02,
+};
+
+unsigned char NIST_EXPECTED_IV_CTR_E7[] = {
+ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
+ 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
+ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
+ 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xff, 0x00,
+ 0xf0, 0xf1, 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dump_array(unsigned char *ptr, unsigned int size)
+{
+ unsigned char *ptr_end;
+ unsigned char *h;
+ int i = 1;
+
+ h = ptr;
+ ptr_end = ptr + size;
+ while (h < (unsigned char *)ptr_end) {
+ printf("0x%02x ",(unsigned char ) *h);
+ h++;
+ if (i == 8) {
+ printf("\n");
+ i = 1;
+ } else {
+ ++i;
+ }
+ }
+ printf("\n");
+}
+
+void dump_ctr_data(unsigned char *iv, unsigned int iv_length,
+ unsigned char *key, unsigned int key_length,
+ unsigned char *input_data, unsigned int data_length,
+ unsigned char *output_data)
+{
+ printf("IV \n");
+ dump_array(iv, iv_length);
+ printf("Key \n");
+ dump_array(key, key_length);
+ printf("Input Data\n");
+ dump_array(input_data, data_length);
+ printf("Output Data\n");
+ dump_array(output_data, data_length);
+}
+
+void get_sizes(unsigned int *data_length, unsigned int *iv_length,
+ unsigned int *key_length, unsigned int iteration)
+{
+ switch (iteration) {
+ case 1:
+ *data_length = sizeof(NIST_TEST_DATA_CTR_E1);
+ *iv_length = sizeof(NIST_IV_CTR_E1);
+ *key_length = sizeof(NIST_KEY_CTR_E1);
+ break;
+ case 2:
+ *data_length = sizeof(NIST_TEST_DATA_CTR_E2);
+ *iv_length = sizeof(NIST_IV_CTR_E2);
+ *key_length = sizeof(NIST_KEY_CTR_E2);
+ break;
+ case 3:
+ *data_length = sizeof(NIST_TEST_DATA_CTR_E3);
+ *iv_length = sizeof(NIST_IV_CTR_E3);
+ *key_length = sizeof(NIST_KEY_CTR_E3);
+ break;
+ case 4:
+ *data_length = sizeof(NIST_TEST_DATA_CTR_E4);
+ *iv_length = sizeof(NIST_IV_CTR_E4);
+ *key_length = sizeof(NIST_KEY_CTR_E4);
+ break;
+ case 5:
+ *data_length = sizeof(NIST_TEST_DATA_CTR_E5);
+ *iv_length = sizeof(NIST_IV_CTR_E5);
+ *key_length = sizeof(NIST_KEY_CTR_E5);
+ break;
+ case 6:
+ *data_length = sizeof(NIST_TEST_DATA_CTR_E6);
+ *iv_length = sizeof(NIST_IV_CTR_E6);
+ *key_length = sizeof(NIST_KEY_CTR_E6);
+ break;
+ case 7:
+ *data_length = sizeof(NIST_TEST_DATA_CTR_E7);
+ *iv_length = sizeof(NIST_IV_CTR_E7);
+ *key_length = sizeof(NIST_KEY_CTR_E7);
+ break;
+ }
+
+}
+
+void load_test_data(unsigned char *data, unsigned int data_length,
+ unsigned char *result,
+ unsigned char *iv, unsigned char *expected_iv,
+ unsigned int iv_length,
+ unsigned char *key, unsigned int key_length,
+ unsigned int iteration)
+{
+ switch (iteration) {
+ case 1:
+ memcpy(data, NIST_TEST_DATA_CTR_E1, data_length);
+ memcpy(result, NIST_TEST_RESULT_CTR_E1, data_length);
+ memcpy(iv, NIST_IV_CTR_E1, iv_length);
+ memcpy(expected_iv, NIST_EXPECTED_IV_CTR_E1, iv_length);
+ memcpy(key, NIST_KEY_CTR_E1, key_length);
+ break;
+ case 2:
+ memcpy(data, NIST_TEST_DATA_CTR_E2, data_length);
+ memcpy(result, NIST_TEST_RESULT_CTR_E2, data_length);
+ memcpy(iv, NIST_IV_CTR_E2, iv_length);
+ memcpy(expected_iv, NIST_EXPECTED_IV_CTR_E2, iv_length);
+ memcpy(key, NIST_KEY_CTR_E2, key_length);
+ break;
+ case 3:
+ memcpy(data, NIST_TEST_DATA_CTR_E3, data_length);
+ memcpy(result, NIST_TEST_RESULT_CTR_E3, data_length);
+ memcpy(iv, NIST_IV_CTR_E3, iv_length);
+ memcpy(expected_iv, NIST_EXPECTED_IV_CTR_E3, iv_length);
+ memcpy(key, NIST_KEY_CTR_E3, key_length);
+ break;
+ case 4:
+ memcpy(data, NIST_TEST_DATA_CTR_E4, data_length);
+ memcpy(result, NIST_TEST_RESULT_CTR_E4, data_length);
+ memcpy(iv, NIST_IV_CTR_E4, iv_length);
+ memcpy(expected_iv, NIST_EXPECTED_IV_CTR_E4, iv_length);
+ memcpy(key, NIST_KEY_CTR_E4, key_length);
+ break;
+ case 5:
+ memcpy(data, NIST_TEST_DATA_CTR_E5, data_length);
+ memcpy(result, NIST_TEST_RESULT_CTR_E5, data_length);
+ memcpy(iv, NIST_IV_CTR_E5, iv_length);
+ memcpy(expected_iv, NIST_EXPECTED_IV_CTR_E5, iv_length);
+ memcpy(key, NIST_KEY_CTR_E5, key_length);
+ break;
+ case 6:
+ memcpy(data, NIST_TEST_DATA_CTR_E6, data_length);
+ memcpy(result, NIST_TEST_RESULT_CTR_E6, data_length);
+ memcpy(iv, NIST_IV_CTR_E6, iv_length);
+ memcpy(expected_iv, NIST_EXPECTED_IV_CTR_E6, iv_length);
+ memcpy(key, NIST_KEY_CTR_E6, key_length);
+ break;
+ case 7:
+ memcpy(data, NIST_TEST_DATA_CTR_E7, data_length);
+ memcpy(result, NIST_TEST_RESULT_CTR_E7, data_length);
+ memcpy(iv, NIST_IV_CTR_E7, iv_length);
+ memcpy(expected_iv, NIST_EXPECTED_IV_CTR_E7, iv_length);
+ memcpy(key, NIST_KEY_CTR_E7, key_length);
+ break;
+ }
+
+}
+
+int random_aes_ctr(int iteration, int silent, unsigned int data_length, unsigned int iv_length)
+{
+ unsigned int key_length = AES_KEY_LEN256;
+ if (data_length % sizeof(ica_aes_vector_t))
+ iv_length = sizeof(ica_aes_vector_t);
+
+ if (!silent) {
+ printf("Test Parameters for iteration = %i\n", iteration);
+ printf("key length = %i, data length = %i, iv length = %i\n",
+ key_length, data_length, iv_length);
+ }
+ unsigned char iv[iv_length];
+ unsigned char tmp_iv[iv_length];
+ unsigned char key[key_length];
+ unsigned char input_data[data_length];
+ unsigned char encrypt[data_length];
+ unsigned char decrypt[data_length];
+
+ int rc = 0;
+ rc = ica_random_number_generate(data_length, input_data);
+ if (rc) {
+ printf("random number generate returned rc = %i, errno = %i\n", rc, errno);
+ return rc;
+ }
+ rc = ica_random_number_generate(iv_length, iv);
+ if (rc) {
+ printf("random number generate returned rc = %i, errno = %i\n", rc, errno);
+ return rc;
+ }
+
+ rc = ica_random_number_generate(key_length, key);
+ if (rc) {
+ printf("random number generate returned rc = %i, errno = %i\n", rc, errno);
+ return rc;
+ }
+ memcpy(tmp_iv, iv, iv_length);
+
+ rc = ica_aes_ctr(input_data, encrypt, data_length, key, key_length,
+ tmp_iv, 32, 1);
+ if (rc) {
+ printf("ica_aes_ctr encrypt failed with rc = %i\n", rc);
+ dump_ctr_data(iv, iv_length, key, key_length, input_data,
+ data_length, encrypt);
+ return rc;
+ }
+ if (!silent && !rc) {
+ printf("Encrypt:\n");
+ dump_ctr_data(iv, iv_length, key, key_length, input_data,
+ data_length, encrypt);
+ }
+
+ memcpy(tmp_iv, iv, iv_length);
+ rc = ica_aes_ctr(encrypt, decrypt, data_length, key, key_length,
+ tmp_iv, 32, 0);
+ if (rc) {
+ printf("ica_aes_ctr decrypt failed with rc = %i\n", rc);
+ dump_ctr_data(iv, iv_length, key, key_length, encrypt,
+ data_length, decrypt);
+ return rc;
+ }
+
+
+ if (!silent && !rc) {
+ printf("Decrypt:\n");
+ dump_ctr_data(iv, iv_length, key, key_length, encrypt,
+ data_length, decrypt);
+ }
+
+ if (memcmp(decrypt, input_data, data_length)) {
+ printf("Decryption Result does not match the original data!\n");
+ printf("Original data:\n");
+ dump_array(input_data, data_length);
+ printf("Decryption Result:\n");
+ dump_array(decrypt, data_length);
+ rc++;
+ }
+ return rc;
+}
+
+int kat_aes_ctr(int iteration, int silent)
+{
+ unsigned int data_length;
+ unsigned int iv_length;
+ unsigned int key_length;
+
+ get_sizes(&data_length, &iv_length, &key_length, iteration);
+
+ if (!silent) {
+ printf("Test Parameters for iteration = %i\n", iteration);
+ printf("key length = %i, data length = %i, iv length = %i\n",
+ key_length, data_length, iv_length);
+ }
+ unsigned char iv[iv_length];
+ unsigned char tmp_iv[iv_length];
+ unsigned char expected_iv[iv_length];
+ unsigned char key[key_length];
+ unsigned char input_data[data_length];
+ unsigned char encrypt[data_length];
+ unsigned char decrypt[data_length];
+ unsigned char result[data_length];
+
+ int rc = 0;
+
+ load_test_data(input_data, data_length, result, iv, expected_iv,
+ iv_length, key, key_length, iteration);
+ memcpy(tmp_iv, iv, iv_length);
+
+ if (iv_length == 16)
+ rc = ica_aes_ctr(input_data, encrypt, data_length, key, key_length,
+ tmp_iv, 32, 1);
+ else
+ rc = ica_aes_ctrlist(input_data, encrypt, data_length, key, key_length,
+ tmp_iv, 1);
+ if (rc) {
+ printf("ica_aes_ctr encrypt failed with rc = %i\n", rc);
+ dump_ctr_data(iv, iv_length, key, key_length, input_data,
+ data_length, encrypt);
+ }
+ if (!silent && !rc) {
+ printf("Encrypt:\n");
+ dump_ctr_data(iv, iv_length, key, key_length, input_data,
+ data_length, encrypt);
+ }
+
+ if (memcmp(result, encrypt, data_length)) {
+ printf("Encryption Result does not match the known ciphertext!\n");
+ printf("Expected data:\n");
+ dump_array(result, data_length);
+ printf("Encryption Result:\n");
+ dump_array(encrypt, data_length);
+ rc++;
+ }
+
+ if (memcmp(expected_iv, tmp_iv, iv_length)) {
+ printf("Update of IV does not match the expected IV!\n");
+ printf("Expected IV:\n");
+ dump_array(expected_iv, iv_length);
+ printf("Updated IV:\n");
+ dump_array(tmp_iv, iv_length);
+ printf("Original IV:\n");
+ dump_array(iv, iv_length);
+ rc++;
+ }
+ if (rc) {
+ printf("AES CTR test exited after encryption\n");
+ return rc;
+ }
+
+ memcpy(tmp_iv, iv, iv_length);
+ rc = ica_aes_ctr(encrypt, decrypt, data_length, key, key_length,
+ tmp_iv, 32,0);
+ if (rc) {
+ printf("ica_aes_ctr decrypt failed with rc = %i\n", rc);
+ dump_ctr_data(iv, iv_length, key, key_length, encrypt,
+ data_length, decrypt);
+ return rc;
+ }
+
+
+ if (!silent && !rc) {
+ printf("Decrypt:\n");
+ dump_ctr_data(iv, iv_length, key, key_length, encrypt,
+ data_length, decrypt);
+ }
+
+ if (memcmp(decrypt, input_data, data_length)) {
+ printf("Decryption Result does not match the original data!\n");
+ printf("Original data:\n");
+ dump_array(input_data, data_length);
+ printf("Decryption Result:\n");
+ dump_array(decrypt, data_length);
+ rc++;
+ }
+ return rc;
+}
+
+int main(int argc, char **argv)
+{
+ // Default mode is 0. ECB,CBC and CFQ tests will be performed.
+ unsigned int silent = 0;
+ unsigned int endless = 0;
+ int i = 0;
+ int rc = 0;
+ int error_count = 0;
+ int iteration;
+ unsigned int data_length = 1;
+ unsigned int iv_length = sizeof(ica_aes_vector_t);
+ unsigned int rdata;
+
+ if (argc > 1) {
+ if (strstr(argv[1], "silent"))
+ silent = 1;
+ if (strstr(argv[1], "endless"))
+ endless = 1;
+ }
+
+ if (!endless) {
+
+ // not endless mode
+ // run the verification tests with known test vectors
+ for(iteration = 1; iteration <= NR_TESTS; iteration++) {
+ rc = kat_aes_ctr(iteration, silent);
+ if (rc) {
+ printf("kat_aes_ctr failed with rc = %i\n", rc);
+ error_count++;
+ }
+ }
+ // run random tests
+ silent = 1;
+ for(iteration = 1; iteration <= NR_RANDOM_TESTS; iteration++) {
+ rc = random_aes_ctr(iteration, silent, data_length, iv_length);
+ if (rc) {
+ printf("random_aes_ctr failed with rc = %i\n", rc);
+ error_count++;
+ }
+ // add a value between 1 and 8 to data_length
+ if (ica_random_number_generate(sizeof(rdata), (unsigned char*) &rdata)) {
+ printf("ica_random_number_generate failed with errnor = %i\n",
+ errno);
+ exit(1);
+ }
+ data_length += (rdata % 8) + 1;
+ }
+
+ } else {
+
+ // endless mode
+ while (1) {
+ printf("i = %i\n",i);
+ silent = 1;
+ rc = random_aes_ctr(i, silent, 320, 320);
+ if (rc) {
+ printf("random_aes_ctr failed with rc = %i\n", rc);
+ return rc;
+ }
+ i++;
+ }
+
+ }
+
+ if (error_count)
+ printf("%i testcases failed\n", error_count);
+ else
+ printf("All AES-CTR testcases finished successfully\n");
+
+ return rc;
+}
+
diff --git a/src/tests/libica_aes_ecb_test.c b/src/tests/libica_aes_ecb_test.c
new file mode 100644
index 0000000..d88ed87
--- /dev/null
+++ b/src/tests/libica_aes_ecb_test.c
@@ -0,0 +1,511 @@
+/* This program is released under the Common Public License V1.0
+ *
+ * You should have received a copy of Common Public License V1.0 along with
+ * with this program.
+ */
+
+/* Copyright IBM Corp. 2010, 2011 */
+#include <fcntl.h>
+#include <sys/errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+#include <stdlib.h>
+#include "ica_api.h"
+
+#define NR_TESTS 7
+#define NR_RANDOM_TESTS 10000
+
+/* ECB data - 1 for AES128 */
+unsigned char NIST_KEY_ECB_E1[] = {
+ 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
+ 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c,
+};
+
+unsigned char NIST_TEST_DATA_ECB_E1[] = {
+ 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
+ 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
+};
+
+unsigned char NIST_TEST_RESULT_ECB_E1[] = {
+ 0x3a, 0xd7, 0x7b, 0xb4, 0x0d, 0x7a, 0x36, 0x60,
+ 0xa8, 0x9e, 0xca, 0xf3, 0x24, 0x66, 0xef, 0x97,
+};
+
+/* ECB data - 2 for AES128 */
+unsigned char NIST_KEY_ECB_E2[] = {
+ 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
+ 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c,
+};
+
+unsigned char NIST_TEST_DATA_ECB_E2[] = {
+ 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
+ 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
+};
+
+unsigned char NIST_TEST_RESULT_ECB_E2[] = {
+ 0xf5, 0xd3, 0xd5, 0x85, 0x03, 0xb9, 0x69, 0x9d,
+ 0xe7, 0x85, 0x89, 0x5a, 0x96, 0xfd, 0xba, 0xaf,
+};
+
+/* ECB data - 3 - for AES128 */
+unsigned char NIST_KEY_ECB_E3[] = {
+ 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
+ 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c,
+
+};
+
+unsigned char NIST_TEST_DATA_ECB_E3[] = {
+ 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
+ 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
+ 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
+ 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
+ 0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11,
+ 0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef,
+ 0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17,
+ 0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10,
+};
+
+unsigned char NIST_TEST_RESULT_ECB_E3[] = {
+ 0x3a, 0xd7, 0x7b, 0xb4, 0x0d, 0x7a, 0x36, 0x60,
+ 0xa8, 0x9e, 0xca, 0xf3, 0x24, 0x66, 0xef, 0x97,
+ 0xf5, 0xd3, 0xd5, 0x85, 0x03, 0xb9, 0x69, 0x9d,
+ 0xe7, 0x85, 0x89, 0x5a, 0x96, 0xfd, 0xba, 0xaf,
+ 0x43, 0xb1, 0xcd, 0x7f, 0x59, 0x8e, 0xce, 0x23,
+ 0x88, 0x1b, 0x00, 0xe3, 0xed, 0x03, 0x06, 0x88,
+ 0x7b, 0x0c, 0x78, 0x5e, 0x27, 0xe8, 0xad, 0x3f,
+ 0x82, 0x23, 0x20, 0x71, 0x04, 0x72, 0x5d, 0xd4,
+};
+
+/* ECB data - 4 - for AES192 */
+unsigned char NIST_KEY_ECB_E4[] = {
+ 0x8e, 0x73, 0xb0, 0xf7, 0xda, 0x0e, 0x64, 0x52,
+ 0xc8, 0x10, 0xf3, 0x2b, 0x80, 0x90, 0x79, 0xe5,
+ 0x62, 0xf8, 0xea, 0xd2, 0x52, 0x2c, 0x6b, 0x7b,
+};
+
+unsigned char NIST_TEST_DATA_ECB_E4[] = {
+ 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
+ 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
+};
+
+unsigned char NIST_TEST_RESULT_ECB_E4[] = {
+ 0xbd, 0x33, 0x4f, 0x1d, 0x6e, 0x45, 0xf2, 0x5f,
+ 0xf7, 0x12, 0xa2, 0x14, 0x57, 0x1f, 0xa5, 0xcc,
+};
+
+/* ECB data 5 - for AES 192 */
+unsigned char NIST_KEY_ECB_E5[] = {
+ 0x8e, 0x73, 0xb0, 0xf7, 0xda, 0x0e, 0x64, 0x52,
+ 0xc8, 0x10, 0xf3, 0x2b, 0x80, 0x90, 0x79, 0xe5,
+ 0x62, 0xf8, 0xea, 0xd2, 0x52, 0x2c, 0x6b, 0x7b,
+};
+
+unsigned char NIST_TEST_DATA_ECB_E5[] = {
+ 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
+ 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
+ 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
+ 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
+ 0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11,
+ 0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef,
+ 0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17,
+ 0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10,
+};
+
+unsigned char NIST_TEST_RESULT_ECB_E5[] = {
+ 0xbd, 0x33, 0x4f, 0x1d, 0x6e, 0x45, 0xf2, 0x5f,
+ 0xf7, 0x12, 0xa2, 0x14, 0x57, 0x1f, 0xa5, 0xcc,
+ 0x97, 0x41, 0x04, 0x84, 0x6d, 0x0a, 0xd3, 0xad,
+ 0x77, 0x34, 0xec, 0xb3, 0xec, 0xee, 0x4e, 0xef,
+ 0xef, 0x7a, 0xfd, 0x22, 0x70, 0xe2, 0xe6, 0x0a,
+ 0xdc, 0xe0, 0xba, 0x2f, 0xac, 0xe6, 0x44, 0x4e,
+ 0x9a, 0x4b, 0x41, 0xba, 0x73, 0x8d, 0x6c, 0x72,
+ 0xfb, 0x16, 0x69, 0x16, 0x03, 0xc1, 0x8e, 0x0e,
+};
+
+/* ECB data 6 - for AES 256 */
+unsigned char NIST_KEY_ECB_E6[] = {
+ 0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe,
+ 0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81,
+ 0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7,
+ 0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4,
+};
+
+unsigned char NIST_TEST_DATA_ECB_E6[] = {
+ 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
+ 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
+};
+
+unsigned char NIST_TEST_RESULT_ECB_E6[] = {
+ 0xf3, 0xee, 0xd1, 0xbd, 0xb5, 0xd2, 0xa0, 0x3c,
+ 0x06, 0x4b, 0x5a, 0x7e, 0x3d, 0xb1, 0x81, 0xf8,
+};
+
+/* ECB data 7 - for AES 256 */
+unsigned char NIST_KEY_ECB_E7[] = {
+ 0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe,
+ 0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81,
+ 0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7,
+ 0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4,
+};
+
+unsigned char NIST_TEST_DATA_ECB_E7[] = {
+ 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
+ 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
+ 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
+ 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
+ 0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11,
+ 0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef,
+ 0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17,
+ 0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10,
+};
+
+unsigned char NIST_TEST_RESULT_ECB_E7[] = {
+ 0xf3, 0xee, 0xd1, 0xbd, 0xb5, 0xd2, 0xa0, 0x3c,
+ 0x06, 0x4b, 0x5a, 0x7e, 0x3d, 0xb1, 0x81, 0xf8,
+ 0x59, 0x1c, 0xcb, 0x10, 0xd4, 0x10, 0xed, 0x26,
+ 0xdc, 0x5b, 0xa7, 0x4a, 0x31, 0x36, 0x28, 0x70,
+ 0xb6, 0xed, 0x21, 0xb9, 0x9c, 0xa6, 0xf4, 0xf9,
+ 0xf1, 0x53, 0xe7, 0xb1, 0xbe, 0xaf, 0xed, 0x1d,
+ 0x23, 0x30, 0x4b, 0x7a, 0x39, 0xf9, 0xf3, 0xff,
+ 0x06, 0x7d, 0x8d, 0x8f, 0x9e, 0x24, 0xec, 0xc7,
+};
+
+void dump_array(unsigned char *ptr, unsigned int size)
+{
+ unsigned char *ptr_end;
+ unsigned char *h;
+ int i = 1;
+
+ h = ptr;
+ ptr_end = ptr + size;
+ while (h < (unsigned char *)ptr_end) {
+ printf("0x%02x ",(unsigned char ) *h);
+ h++;
+ if (i == 8) {
+ printf("\n");
+ i = 1;
+ } else {
+ ++i;
+ }
+ }
+ printf("\n");
+}
+
+void dump_ecb_data(unsigned char *key, unsigned int key_length,
+ unsigned char *input_data, unsigned int data_length,
+ unsigned char *output_data)
+{
+ printf("Key \n");
+ dump_array(key, key_length);
+ printf("Input Data\n");
+ dump_array(input_data, data_length);
+ printf("Output Data\n");
+ dump_array(output_data, data_length);
+}
+
+void get_sizes(unsigned int *data_length,
+ unsigned int *key_length, unsigned int iteration)
+{
+ switch (iteration) {
+ case 1:
+ *data_length = sizeof(NIST_TEST_DATA_ECB_E1);
+ *key_length = sizeof(NIST_KEY_ECB_E1);
+ break;
+ case 2:
+ *data_length = sizeof(NIST_TEST_DATA_ECB_E2);
+ *key_length = sizeof(NIST_KEY_ECB_E2);
+ break;
+ case 3:
+ *data_length = sizeof(NIST_TEST_DATA_ECB_E3);
+ *key_length = sizeof(NIST_KEY_ECB_E3);
+ break;
+ case 4:
+ *data_length = sizeof(NIST_TEST_DATA_ECB_E4);
+ *key_length = sizeof(NIST_KEY_ECB_E4);
+ break;
+ case 5:
+ *data_length = sizeof(NIST_TEST_DATA_ECB_E5);
+ *key_length = sizeof(NIST_KEY_ECB_E5);
+ break;
+ case 6:
+ *data_length = sizeof(NIST_TEST_DATA_ECB_E6);
+ *key_length = sizeof(NIST_KEY_ECB_E6);
+ break;
+ case 7:
+ *data_length = sizeof(NIST_TEST_DATA_ECB_E7);
+ *key_length = sizeof(NIST_KEY_ECB_E7);
+ break;
+ case 8:
+ break;
+ case 9:
+ break;
+ case 10:
+ break;
+ case 11:
+ break;
+ case 12:
+ break;
+ }
+
+}
+
+void load_test_data(unsigned char *data, unsigned int data_length,
+ unsigned char *result,
+ unsigned char *key, unsigned int key_length,
+ unsigned int iteration)
+{
+ switch (iteration) {
+ case 1:
+ memcpy(data, NIST_TEST_DATA_ECB_E1, data_length);
+ memcpy(result, NIST_TEST_RESULT_ECB_E1, data_length);
+ memcpy(key, NIST_KEY_ECB_E1, key_length);
+ break;
+ case 2:
+ memcpy(data, NIST_TEST_DATA_ECB_E2, data_length);
+ memcpy(result, NIST_TEST_RESULT_ECB_E2, data_length);
+ memcpy(key, NIST_KEY_ECB_E2, key_length);
+ break;
+ case 3:
+ memcpy(data, NIST_TEST_DATA_ECB_E3, data_length);
+ memcpy(result, NIST_TEST_RESULT_ECB_E3, data_length);
+ memcpy(key, NIST_KEY_ECB_E3, key_length);
+ break;
+ case 4:
+ memcpy(data, NIST_TEST_DATA_ECB_E4, data_length);
+ memcpy(result, NIST_TEST_RESULT_ECB_E4, data_length);
+ memcpy(key, NIST_KEY_ECB_E4, key_length);
+ break;
+ case 5:
+ memcpy(data, NIST_TEST_DATA_ECB_E5, data_length);
+ memcpy(result, NIST_TEST_RESULT_ECB_E5, data_length);
+ memcpy(key, NIST_KEY_ECB_E5, key_length);
+ break;
+ case 6:
+ memcpy(data, NIST_TEST_DATA_ECB_E6, data_length);
+ memcpy(result, NIST_TEST_RESULT_ECB_E6, data_length);
+ memcpy(key, NIST_KEY_ECB_E6, key_length);
+ break;
+ case 7:
+ memcpy(data, NIST_TEST_DATA_ECB_E7, data_length);
+ memcpy(result, NIST_TEST_RESULT_ECB_E7, data_length);
+ memcpy(key, NIST_KEY_ECB_E7, key_length);
+ break;
+ case 8:
+ break;
+ case 9:
+ break;
+ case 10:
+ break;
+ case 11:
+ break;
+ case 12:
+ break;
+ }
+
+}
+
+int kat_aes_ecb(int iteration, int silent)
+{
+ unsigned int data_length;
+ unsigned int key_length;
+
+ get_sizes(&data_length, &key_length, iteration);
+
+ if (!silent) {
+ printf("Test Parameters for iteration = %i\n", iteration);
+ printf("key length = %i, data length = %i",
+ key_length, data_length);
+ }
+ unsigned char key[key_length];
+ unsigned char input_data[data_length];
+ unsigned char encrypt[data_length];
+ unsigned char decrypt[data_length];
+ unsigned char result[data_length];
+
+ int rc = 0;
+
+ load_test_data(input_data, data_length, result, key, key_length,
+ iteration);
+
+ rc = ica_aes_ecb(input_data, encrypt, data_length, key, key_length, 1);
+ if (rc) {
+ printf("ica_aes_ecb encrypt failed with rc = %i\n", rc);
+ dump_ecb_data(key, key_length, input_data,
+ data_length, encrypt);
+ }
+ if (!silent && !rc) {
+ printf("Encrypt:\n");
+ dump_ecb_data(key, key_length, input_data,
+ data_length, encrypt);
+ }
+
+ if (memcmp(result, encrypt, data_length)) {
+ printf("Encryption Result does not match the known ciphertext!\n");
+ printf("Expected data:\n");
+ dump_array(result, data_length);
+ printf("Encryption Result:\n");
+ dump_array(encrypt, data_length);
+ rc++;
+ }
+
+ if (rc) {
+ printf("AES ECB test exited after encryption\n");
+ return rc;
+ }
+
+ rc = ica_aes_ecb(encrypt, decrypt, data_length, key, key_length, 0);
+ if (rc) {
+ printf("ica_aes_ecb decrypt failed with rc = %i\n", rc);
+ dump_ecb_data(key, key_length, encrypt,
+ data_length, decrypt);
+ return rc;
+ }
+
+
+ if (!silent && !rc) {
+ printf("Decrypt:\n");
+ dump_ecb_data(key, key_length, encrypt,
+ data_length, decrypt);
+ }
+
+ if (memcmp(decrypt, input_data, data_length)) {
+ printf("Decryption Result does not match the original data!\n");
+ printf("Original data:\n");
+ dump_array(input_data, data_length);
+ printf("Decryption Result:\n");
+ dump_array(decrypt, data_length);
+ rc++;
+ }
+ return rc;
+}
+
+int load_random_test_data(unsigned char *data, unsigned int data_length,
+ unsigned char *key, unsigned int key_length)
+{
+ int rc;
+ rc = ica_random_number_generate(data_length, data);
+ if (rc) {
+ printf("ica_random_number_generate with rc = %i errnor = %i\n",
+ rc, errno);
+ return rc;
+ }
+ rc = ica_random_number_generate(key_length, key);
+ if (rc) {
+ printf("ica_random_number_generate with rc = %i errnor = %i\n",
+ rc, errno);
+ return rc;
+ }
+ return rc;
+}
+
+int random_aes_ecb(int iteration, int silent, unsigned int data_length)
+{
+ int i;
+ int rc = 0;
+ unsigned int key_length = AES_KEY_LEN128;
+ unsigned char input_data[data_length];
+ unsigned char encrypt[data_length];
+ unsigned char decrypt[data_length];
+for (i = 1; i <= 2; i++) {
+
+ unsigned char key[key_length];
+
+ memset(encrypt, 0x00, data_length);
+ memset(decrypt, 0x00, data_length);
+
+ load_random_test_data(input_data, data_length, key, key_length);
+
+ if (!silent) {
+ printf("Test Parameters for iteration = %i\n", iteration);
+ printf("key length = %i, data length = %i\n", key_length, data_length);
+ }
+ rc = ica_aes_ecb(input_data, encrypt, data_length, key, key_length,
+ 1);
+ if (rc) {
+ printf("ica_aes_ecb encrypt failed with rc = %i\n", rc);
+ dump_ecb_data(key, key_length, input_data,
+ data_length, encrypt);
+ }
+ if (!silent && !rc) {
+ printf("Encrypt:\n");
+ dump_ecb_data(key, key_length, input_data,
+ data_length, encrypt);
+ }
+
+ if (rc) {
+ printf("AES ECB test exited after encryption\n");
+ return rc;
+ }
+
+ rc = ica_aes_ecb(encrypt, decrypt, data_length, key, key_length, 0);
+ if (rc) {
+ printf("ica_aes_ecb decrypt failed with rc = %i\n", rc);
+ dump_ecb_data(key, key_length, encrypt,
+ data_length, decrypt);
+ return rc;
+ }
+
+
+ if (!silent && !rc) {
+ printf("Decrypt:\n");
+ dump_ecb_data(key, key_length, encrypt,
+ data_length, decrypt);
+ }
+
+ if (memcmp(decrypt, input_data, data_length)) {
+ printf("Decryption Result does not match the original data!\n");
+ printf("Original data:\n");
+ dump_array(input_data, data_length);
+ printf("Decryption Result:\n");
+ dump_array(decrypt, data_length);
+ rc++;
+ return rc;
+ }
+ key_length += 8;
+}
+
+ return rc;
+}
+
+int main(int argc, char **argv)
+{
+ // Default mode is 0. ECB,ECB and CFQ tests will be performed.
+ unsigned int silent = 0;
+ if (argc > 1) {
+ if (strstr(argv[1], "silent"))
+ silent = 1;
+ }
+ int rc = 0;
+ int error_count = 0;
+ int iteration;
+ unsigned int data_length = sizeof(ica_aes_vector_t);
+ for(iteration = 1; iteration <= NR_TESTS; iteration++) {
+ rc = kat_aes_ecb(iteration, silent);
+ if (rc) {
+ printf("kat_aes_ecb failed with rc = %i\n", rc);
+ error_count++;
+ }
+
+ }
+ for(iteration = 1; iteration <= NR_RANDOM_TESTS; iteration++) {
+ int silent = 1;
+ rc = random_aes_ecb(iteration, silent, data_length);
+ if (rc) {
+ printf("random_aes_ecb failed with rc = %i\n", rc);
+ error_count++;
+ goto out;
+ }
+ data_length += sizeof(ica_aes_vector_t);
+ }
+
+out:
+
+ if (error_count)
+ printf("%i testcases failed\n", error_count);
+ else
+ printf("All AES-ECB testcases finished successfully\n");
+
+ return rc;
+}
+
diff --git a/src/tests/libica_aes_gcm_test.c b/src/tests/libica_aes_gcm_test.c
new file mode 100644
index 0000000..d5bfb52
--- /dev/null
+++ b/src/tests/libica_aes_gcm_test.c
@@ -0,0 +1,1075 @@
+/* This program is released under the Common Public License V1.0
+ *
+ * You should have received a copy of Common Public License V1.0 along with
+ * with this program.
+ */
+
+/* (C) COPYRIGHT International Business Machines Corp. 2011 */
+#include <fcntl.h>
+#include <sys/errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+#include <stdlib.h>
+#include "ica_api.h"
+
+#define NR_TESTS 12
+#define AES_BLOCK_SIZE 16
+
+/* GCM data - 1*/
+unsigned char NIST_KEY_GCM_E1[] = {
+ 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
+ 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08,
+};
+
+unsigned char NIST_TEST_DATA_GCM_E1[] = {
+ 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5,
+ 0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a,
+ 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda,
+ 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72,
+ 0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53,
+ 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25,
+ 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57,
+ 0xba, 0x63, 0x7b, 0x39, 0x1a, 0xaf, 0xd2, 0x55,
+};
+
+unsigned char NIST_AAD_GCM_E1[] = {
+};
+
+unsigned char NIST_IV_GCM_E1[] = {
+ 0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad,
+ 0xde, 0xca, 0xf8, 0x88,
+};
+
+unsigned char NIST_TAG_GCM_E1[] = {
+ 0x4d, 0x5c, 0x2a, 0xf3, 0x27, 0xcd, 0x64, 0xa6,
+ 0x2c, 0xf3, 0x5a, 0xbd, 0x2b, 0xa6, 0xfa, 0xb4,
+};
+
+unsigned char NIST_TEST_RESULT_GCM_E1[] = {
+ 0x42, 0x83, 0x1e, 0xc2, 0x21, 0x77, 0x74, 0x24,
+ 0x4b, 0x72, 0x21, 0xb7, 0x84, 0xd0, 0xd4, 0x9c,
+ 0xe3, 0xaa, 0x21, 0x2f, 0x2c, 0x02, 0xa4, 0xe0,
+ 0x35, 0xc1, 0x7e, 0x23, 0x29, 0xac, 0xa1, 0x2e,
+ 0x21, 0xd5, 0x14, 0xb2, 0x54, 0x66, 0x93, 0x1c,
+ 0x7d, 0x8f, 0x6a, 0x5a, 0xac, 0x84, 0xaa, 0x05,
+ 0x1b, 0xa3, 0x0b, 0x39, 0x6a, 0x0a, 0xac, 0x97,
+ 0x3d, 0x58, 0xe0, 0x91, 0x47, 0x3f, 0x59, 0x85,
+};
+
+unsigned char NIST_CHUNKS_GCM_E1[] = { 16, 16, 16, 16 };
+
+/* GCM data - 2*/
+unsigned char NIST_KEY_GCM_E2[] = {
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+};
+
+unsigned char NIST_TEST_DATA_GCM_E2[] = {
+};
+
+unsigned char NIST_AAD_GCM_E2[] = {
+};
+
+unsigned char NIST_IV_GCM_E2[] = {
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+};
+
+unsigned char NIST_TAG_GCM_E2[] = {
+ 0x58, 0xe2, 0xfc, 0xce, 0xfa, 0x7e, 0x30, 0x61,
+ 0x36, 0x7f, 0x1d, 0x57, 0xa4, 0xe7, 0x45, 0x5a
+};
+
+unsigned char NIST_TEST_RESULT_GCM_E2[] = {
+};
+
+unsigned char NIST_CHUNKS_GCM_E2[] = { };
+
+/* GCM data - 3*/
+unsigned char NIST_KEY_GCM_E3[] = {
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+};
+
+unsigned char NIST_TEST_DATA_GCM_E3[] = {
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+};
+
+unsigned char NIST_AAD_GCM_E3[] = {
+};
+
+unsigned char NIST_IV_GCM_E3[] = {
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+};
+
+unsigned char NIST_TAG_GCM_E3[] = {
+ 0xab, 0x6e, 0x47, 0xd4, 0x2c, 0xec, 0x13, 0xbd,
+ 0xf5, 0x3a, 0x67, 0xb2, 0x12, 0x57, 0xbd, 0xdf,
+};
+
+unsigned char NIST_TEST_RESULT_GCM_E3[] = {
+ 0x03, 0x88, 0xda, 0xce, 0x60, 0xb6, 0xa3, 0x92,
+ 0xf3, 0x28, 0xc2, 0xb9, 0x71, 0xb2, 0xfe, 0x78,
+};
+
+unsigned char NIST_CHUNKS_GCM_E3[] = { 16 };
+
+/* GCM data - 4*/
+unsigned char NIST_KEY_GCM_E4[] = {
+ 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
+ 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08,
+};
+
+unsigned char NIST_TEST_DATA_GCM_E4[] = {
+ 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5,
+ 0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a,
+ 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda,
+ 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72,
+ 0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53,
+ 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25,
+ 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57,
+ 0xba, 0x63, 0x7b, 0x39,
+};
+
+unsigned char NIST_AAD_GCM_E4[] = {
+ 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
+ 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
+ 0xab, 0xad, 0xda, 0xd2,
+};
+
+unsigned char NIST_IV_GCM_E4[] = {
+ 0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad,
+ 0xde, 0xca, 0xf8, 0x88,
+};
+
+unsigned char NIST_TAG_GCM_E4[] = {
+ 0x5b, 0xc9, 0x4f, 0xbc, 0x32, 0x21, 0xa5, 0xdb,
+ 0x94, 0xfa, 0xe9, 0x5a, 0xe7, 0x12, 0x1a, 0x47,
+};
+
+unsigned char NIST_TEST_RESULT_GCM_E4[] = {
+ 0x42, 0x83, 0x1e, 0xc2, 0x21, 0x77, 0x74, 0x24,
+ 0x4b, 0x72, 0x21, 0xb7, 0x84, 0xd0, 0xd4, 0x9c,
+ 0xe3, 0xaa, 0x21, 0x2f, 0x2c, 0x02, 0xa4, 0xe0,
+ 0x35, 0xc1, 0x7e, 0x23, 0x29, 0xac, 0xa1, 0x2e,
+ 0x21, 0xd5, 0x14, 0xb2, 0x54, 0x66, 0x93, 0x1c,
+ 0x7d, 0x8f, 0x6a, 0x5a, 0xac, 0x84, 0xaa, 0x05,
+ 0x1b, 0xa3, 0x0b, 0x39, 0x6a, 0x0a, 0xac, 0x97,
+ 0x3d, 0x58, 0xe0, 0x91,
+};
+
+unsigned char NIST_CHUNKS_GCM_E4[] = { 16, 16, 16, 12 };
+
+/* GCM data - 5 - AES 192 - Test Case 7*/
+unsigned char NIST_KEY_GCM_E5[] = {
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+};
+
+unsigned char NIST_TEST_DATA_GCM_E5[] = {
+};
+
+unsigned char NIST_AAD_GCM_E5[] = {
+};
+
+unsigned char NIST_IV_GCM_E5[] = {
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+};
+
+unsigned char NIST_TAG_GCM_E5[] = {
+ 0xcd, 0x33, 0xb2, 0x8a, 0xc7, 0x73, 0xf7, 0x4b,
+ 0xa0, 0x0e, 0xd1, 0xf3, 0x12, 0x57, 0x24, 0x35,
+};
+
+unsigned char NIST_TEST_RESULT_GCM_E5[] = {
+};
+
+unsigned char NIST_CHUNKS_GCM_E5[] = { };
+
+/* GCM data - 6 - AES 192 - Test Case 8*/
+unsigned char NIST_KEY_GCM_E6[] = {
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+};
+
+unsigned char NIST_TEST_DATA_GCM_E6[] = {
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+};
+
+unsigned char NIST_AAD_GCM_E6[] = {
+};
+
+unsigned char NIST_IV_GCM_E6[] = {
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+};
+
+unsigned char NIST_TAG_GCM_E6[] = {
+ 0x2f, 0xf5, 0x8d, 0x80, 0x03, 0x39, 0x27, 0xab,
+ 0x8e, 0xf4, 0xd4, 0x58, 0x75, 0x14, 0xf0, 0xfb,
+};
+
+unsigned char NIST_TEST_RESULT_GCM_E6[] = {
+ 0x98, 0xe7, 0x24, 0x7c, 0x07, 0xf0, 0xfe, 0x41,
+ 0x1c, 0x26, 0x7e, 0x43, 0x84, 0xb0, 0xf6, 0x00,
+};
+
+unsigned char NIST_CHUNKS_GCM_E6[] = { 16 };
+
+/* GCM data - 7 - AES 192 - Test Case 9*/
+unsigned char NIST_KEY_GCM_E7[] = {
+ 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
+ 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08,
+ 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
+};
+
+unsigned char NIST_TEST_DATA_GCM_E7[] = {
+ 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5,
+ 0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a,
+ 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda,
+ 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72,
+ 0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53,
+ 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25,
+ 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57,
+ 0xba, 0x63, 0x7b, 0x39, 0x1a, 0xaf, 0xd2, 0x55,
+};
+
+unsigned char NIST_AAD_GCM_E7[] = {
+};
+
+unsigned char NIST_IV_GCM_E7[] = {
+ 0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad,
+ 0xde, 0xca, 0xf8, 0x88,
+};
+
+unsigned char NIST_TAG_GCM_E7[] = {
+ 0x99, 0x24, 0xa7, 0xc8, 0x58, 0x73, 0x36, 0xbf,
+ 0xb1, 0x18, 0x02, 0x4d, 0xb8, 0x67, 0x4a, 0x14,
+};
+
+unsigned char NIST_TEST_RESULT_GCM_E7[] = {
+ 0x39, 0x80, 0xca, 0x0b, 0x3c, 0x00, 0xe8, 0x41,
+ 0xeb, 0x06, 0xfa, 0xc4, 0x87, 0x2a, 0x27, 0x57,
+ 0x85, 0x9e, 0x1c, 0xea, 0xa6, 0xef, 0xd9, 0x84,
+ 0x62, 0x85, 0x93, 0xb4, 0x0c, 0xa1, 0xe1, 0x9c,
+ 0x7d, 0x77, 0x3d, 0x00, 0xc1, 0x44, 0xc5, 0x25,
+ 0xac, 0x61, 0x9d, 0x18, 0xc8, 0x4a, 0x3f, 0x47,
+ 0x18, 0xe2, 0x44, 0x8b, 0x2f, 0xe3, 0x24, 0xd9,
+ 0xcc, 0xda, 0x27, 0x10, 0xac, 0xad, 0xe2, 0x56,
+};
+
+unsigned char NIST_CHUNKS_GCM_E7[] = { 16, 16, 16, 16 };
+
+/* GCM data - 8 - AES 192 - Test Case 10*/
+unsigned char NIST_KEY_GCM_E8[] = {
+ 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
+ 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08,
+ 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
+};
+
+unsigned char NIST_TEST_DATA_GCM_E8[] = {
+ 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5,
+ 0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a,
+ 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda,
+ 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72,
+ 0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53,
+ 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25,
+ 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57,
+ 0xba, 0x63, 0x7b, 0x39,
+};
+
+unsigned char NIST_AAD_GCM_E8[] = {
+ 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
+ 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
+ 0xab, 0xad, 0xda, 0xd2,
+};
+
+unsigned char NIST_IV_GCM_E8[] = {
+ 0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad,
+ 0xde, 0xca, 0xf8, 0x88,
+};
+
+unsigned char NIST_TAG_GCM_E8[] = {
+ 0x25, 0x19, 0x49, 0x8e, 0x80, 0xf1, 0x47, 0x8f,
+ 0x37, 0xba, 0x55, 0xbd, 0x6d, 0x27, 0x61, 0x8c,
+};
+
+unsigned char NIST_TEST_RESULT_GCM_E8[] = {
+ 0x39, 0x80, 0xca, 0x0b, 0x3c, 0x00, 0xe8, 0x41,
+ 0xeb, 0x06, 0xfa, 0xc4, 0x87, 0x2a, 0x27, 0x57,
+ 0x85, 0x9e, 0x1c, 0xea, 0xa6, 0xef, 0xd9, 0x84,
+ 0x62, 0x85, 0x93, 0xb4, 0x0c, 0xa1, 0xe1, 0x9c,
+ 0x7d, 0x77, 0x3d, 0x00, 0xc1, 0x44, 0xc5, 0x25,
+ 0xac, 0x61, 0x9d, 0x18, 0xc8, 0x4a, 0x3f, 0x47,
+ 0x18, 0xe2, 0x44, 0x8b, 0x2f, 0xe3, 0x24, 0xd9,
+ 0xcc, 0xda, 0x27, 0x10,
+};
+
+unsigned char NIST_CHUNKS_GCM_E8[] = { 16, 16, 16, 12 };
+
+/* GCM data - 9 - AES 256 - Test Case 13*/
+unsigned char NIST_KEY_GCM_E9[] = {
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+};
+
+unsigned char NIST_TEST_DATA_GCM_E9[] = {
+};
+
+unsigned char NIST_AAD_GCM_E9[] = {
+};
+
+unsigned char NIST_IV_GCM_E9[] = {
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+};
+
+unsigned char NIST_TAG_GCM_E9[] = {
+ 0x53, 0x0f, 0x8a, 0xfb, 0xc7, 0x45, 0x36, 0xb9,
+ 0xa9, 0x63, 0xb4, 0xf1, 0xc4, 0xcb, 0x73, 0x8b,
+};
+
+unsigned char NIST_TEST_RESULT_GCM_E9[] = {
+};
+
+unsigned char NIST_CHUNKS_GCM_E9[] = { };
+
+/* GCM data - 10 - AES 256 - Test Case 14*/
+unsigned char NIST_KEY_GCM_E10[] = {
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+};
+
+unsigned char NIST_TEST_DATA_GCM_E10[] = {
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+};
+
+unsigned char NIST_AAD_GCM_E10[] = {
+};
+
+unsigned char NIST_IV_GCM_E10[] = {
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+};
+
+unsigned char NIST_TAG_GCM_E10[] = {
+ 0xd0, 0xd1, 0xc8, 0xa7, 0x99, 0x99, 0x6b, 0xf0,
+ 0x26, 0x5b, 0x98, 0xb5, 0xd4, 0x8a, 0xb9, 0x19,
+};
+
+unsigned char NIST_TEST_RESULT_GCM_E10[] = {
+ 0xce, 0xa7, 0x40, 0x3d, 0x4d, 0x60, 0x6b, 0x6e,
+ 0x07, 0x4e, 0xc5, 0xd3, 0xba, 0xf3, 0x9d, 0x18,
+};
+
+unsigned char NIST_CHUNKS_GCM_E10[] = { 16 };
+
+/* GCM data - 11 - AES 256 - Test Case 15*/
+unsigned char NIST_KEY_GCM_E11[] = {
+ 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
+ 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08,
+ 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
+ 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08,
+};
+
+unsigned char NIST_TEST_DATA_GCM_E11[] = {
+ 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5,
+ 0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a,
+ 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda,
+ 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72,
+ 0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53,
+ 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25,
+ 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57,
+ 0xba, 0x63, 0x7b, 0x39, 0x1a, 0xaf, 0xd2, 0x55,
+};
+
+unsigned char NIST_AAD_GCM_E11[] = {
+};
+
+unsigned char NIST_IV_GCM_E11[] = {
+ 0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad,
+ 0xde, 0xca, 0xf8, 0x88,
+};
+
+unsigned char NIST_TAG_GCM_E11[] = {
+ 0xb0, 0x94, 0xda, 0xc5, 0xd9, 0x34, 0x71, 0xbd,
+ 0xec, 0x1a, 0x50, 0x22, 0x70, 0xe3, 0xcc, 0x6c,
+};
+
+unsigned char NIST_TEST_RESULT_GCM_E11[] = {
+ 0x52, 0x2d, 0xc1, 0xf0, 0x99, 0x56, 0x7d, 0x07,
+ 0xf4, 0x7f, 0x37, 0xa3, 0x2a, 0x84, 0x42, 0x7d,
+ 0x64, 0x3a, 0x8c, 0xdc, 0xbf, 0xe5, 0xc0, 0xc9,
+ 0x75, 0x98, 0xa2, 0xbd, 0x25, 0x55, 0xd1, 0xaa,
+ 0x8c, 0xb0, 0x8e, 0x48, 0x59, 0x0d, 0xbb, 0x3d,
+ 0xa7, 0xb0, 0x8b, 0x10, 0x56, 0x82, 0x88, 0x38,
+ 0xc5, 0xf6, 0x1e, 0x63, 0x93, 0xba, 0x7a, 0x0a,
+ 0xbc, 0xc9, 0xf6, 0x62, 0x89, 0x80, 0x15, 0xad,
+};
+
+unsigned char NIST_CHUNKS_GCM_E11[] = { 16, 16, 16, 16 };
+
+/* GCM data */
+unsigned char NIST_KEY_GCM_E12[] = {
+ 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
+ 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08,
+ 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
+ 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08,
+};
+
+unsigned char NIST_TEST_DATA_GCM_E12[] = {
+ 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5,
+ 0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a,
+ 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda,
+ 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72,
+ 0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53,
+ 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25,
+ 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57,
+ 0xba, 0x63, 0x7b, 0x39,
+};
+
+unsigned char NIST_AAD_GCM_E12[] = {
+ 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
+ 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
+ 0xab, 0xad, 0xda, 0xd2,
+};
+
+unsigned char NIST_IV_GCM_E12[] = {
+ 0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad,
+ 0xde, 0xca, 0xf8, 0x88,
+};
+
+unsigned char NIST_TAG_GCM_E12[] = {
+ 0x76, 0xfc, 0x6e, 0xce, 0x0f, 0x4e, 0x17, 0x68,
+ 0xcd, 0xdf, 0x88, 0x53, 0xbb, 0x2d, 0x55, 0x1b,
+};
+
+unsigned char NIST_TEST_RESULT_GCM_E12[] = {
+ 0x52, 0x2d, 0xc1, 0xf0, 0x99, 0x56, 0x7d, 0x07,
+ 0xf4, 0x7f, 0x37, 0xa3, 0x2a, 0x84, 0x42, 0x7d,
+ 0x64, 0x3a, 0x8c, 0xdc, 0xbf, 0xe5, 0xc0, 0xc9,
+ 0x75, 0x98, 0xa2, 0xbd, 0x25, 0x55, 0xd1, 0xaa,
+ 0x8c, 0xb0, 0x8e, 0x48, 0x59, 0x0d, 0xbb, 0x3d,
+ 0xa7, 0xb0, 0x8b, 0x10, 0x56, 0x82, 0x88, 0x38,
+ 0xc5, 0xf6, 0x1e, 0x63, 0x93, 0xba, 0x7a, 0x0a,
+ 0xbc, 0xc9, 0xf6, 0x62,
+};
+
+unsigned char NIST_CHUNKS_GCM_E12[] = { 16, 16, 16, 12 };
+
+
+void dump_array(unsigned char *ptr, unsigned int size)
+{
+ unsigned char *ptr_end;
+ unsigned char *h;
+ int i = 1;
+
+ h = ptr;
+ ptr_end = ptr + size;
+ while (h < ptr_end) {
+ printf("0x%02x ",*h);
+ h++;
+ if (i == 8) {
+ printf("\n");
+ i = 1;
+ } else {
+ ++i;
+ }
+ }
+ printf("\n");
+}
+
+void dump_gcm_data(unsigned char *iv, unsigned int iv_length,
+ unsigned char *aad, unsigned int aad_length,
+ unsigned char *key, unsigned int key_length,
+ unsigned char *input_data, unsigned int data_length,
+ unsigned char *output_data,
+ unsigned char *t, unsigned int t_size)
+{
+ printf("IV \n");
+ dump_array(iv, iv_length);
+ printf("AAD \n");
+ dump_array(aad, aad_length);
+ printf("Key \n");
+ dump_array(key, key_length);
+ printf("Input Data\n");
+ dump_array(input_data, data_length);
+ printf("Output Data\n");
+ dump_array(output_data, data_length);
+ printf("T\n");
+ dump_array(t, t_size);
+}
+
+void get_sizes(unsigned int *aad_length, unsigned int *data_length,
+ unsigned int *t_length, unsigned int *iv_length,
+ unsigned int *key_length, unsigned int *num_chunks,
+ unsigned int iteration)
+{
+ switch (iteration) {
+ case 1:
+ *aad_length = sizeof(NIST_AAD_GCM_E1);
+ *data_length = sizeof(NIST_TEST_DATA_GCM_E1);
+ *t_length = sizeof(NIST_TAG_GCM_E1);
+ *iv_length = sizeof(NIST_IV_GCM_E1);
+ *key_length = sizeof(NIST_KEY_GCM_E1);
+ *num_chunks = sizeof(NIST_CHUNKS_GCM_E1);
+ break;
+ case 2:
+ *aad_length = sizeof(NIST_AAD_GCM_E2);
+ *data_length = sizeof(NIST_TEST_DATA_GCM_E2);
+ *t_length = sizeof(NIST_TAG_GCM_E2);
+ *iv_length = sizeof(NIST_IV_GCM_E2);
+ *key_length = sizeof(NIST_KEY_GCM_E2);
+ *num_chunks = sizeof(NIST_CHUNKS_GCM_E2);
+ break;
+ case 3:
+ *aad_length = sizeof(NIST_AAD_GCM_E3);
+ *data_length = sizeof(NIST_TEST_DATA_GCM_E3);
+ *t_length = sizeof(NIST_TAG_GCM_E3);
+ *iv_length = sizeof(NIST_IV_GCM_E3);
+ *key_length = sizeof(NIST_KEY_GCM_E3);
+ *num_chunks = sizeof(NIST_CHUNKS_GCM_E3);
+ break;
+ case 4:
+ *aad_length = sizeof(NIST_AAD_GCM_E4);
+ *data_length = sizeof(NIST_TEST_DATA_GCM_E4);
+ *t_length = sizeof(NIST_TAG_GCM_E4);
+ *iv_length = sizeof(NIST_IV_GCM_E4);
+ *key_length = sizeof(NIST_KEY_GCM_E4);
+ *num_chunks = sizeof(NIST_CHUNKS_GCM_E4);
+ break;
+ case 5:
+ *aad_length = sizeof(NIST_AAD_GCM_E5);
+ *data_length = sizeof(NIST_TEST_DATA_GCM_E5);
+ *t_length = sizeof(NIST_TAG_GCM_E5);
+ *iv_length = sizeof(NIST_IV_GCM_E5);
+ *key_length = sizeof(NIST_KEY_GCM_E5);
+ *num_chunks = sizeof(NIST_CHUNKS_GCM_E5);
+ break;
+ case 6:
+ *aad_length = sizeof(NIST_AAD_GCM_E6);
+ *data_length = sizeof(NIST_TEST_DATA_GCM_E6);
+ *t_length = sizeof(NIST_TAG_GCM_E6);
+ *iv_length = sizeof(NIST_IV_GCM_E6);
+ *key_length = sizeof(NIST_KEY_GCM_E6);
+ *num_chunks = sizeof(NIST_CHUNKS_GCM_E6);
+ break;
+ case 7:
+ *aad_length = sizeof(NIST_AAD_GCM_E7);
+ *data_length = sizeof(NIST_TEST_DATA_GCM_E7);
+ *t_length = sizeof(NIST_TAG_GCM_E7);
+ *iv_length = sizeof(NIST_IV_GCM_E7);
+ *key_length = sizeof(NIST_KEY_GCM_E7);
+ *num_chunks = sizeof(NIST_CHUNKS_GCM_E7);
+ break;
+ case 8:
+ *aad_length = sizeof(NIST_AAD_GCM_E8);
+ *data_length = sizeof(NIST_TEST_DATA_GCM_E8);
+ *t_length = sizeof(NIST_TAG_GCM_E8);
+ *iv_length = sizeof(NIST_IV_GCM_E8);
+ *key_length = sizeof(NIST_KEY_GCM_E8);
+ *num_chunks = sizeof(NIST_CHUNKS_GCM_E8);
+ break;
+ case 9:
+ *aad_length = sizeof(NIST_AAD_GCM_E9);
+ *data_length = sizeof(NIST_TEST_DATA_GCM_E9);
+ *t_length = sizeof(NIST_TAG_GCM_E9);
+ *iv_length = sizeof(NIST_IV_GCM_E9);
+ *key_length = sizeof(NIST_KEY_GCM_E9);
+ *num_chunks = sizeof(NIST_CHUNKS_GCM_E9);
+ break;
+ case 10:
+ *aad_length = sizeof(NIST_AAD_GCM_E10);
+ *data_length = sizeof(NIST_TEST_DATA_GCM_E10);
+ *t_length = sizeof(NIST_TAG_GCM_E10);
+ *iv_length = sizeof(NIST_IV_GCM_E10);
+ *key_length = sizeof(NIST_KEY_GCM_E10);
+ *num_chunks = sizeof(NIST_CHUNKS_GCM_E10);
+ break;
+ case 11:
+ *aad_length = sizeof(NIST_AAD_GCM_E11);
+ *data_length = sizeof(NIST_TEST_DATA_GCM_E11);
+ *t_length = sizeof(NIST_TAG_GCM_E11);
+ *iv_length = sizeof(NIST_IV_GCM_E11);
+ *key_length = sizeof(NIST_KEY_GCM_E11);
+ *num_chunks = sizeof(NIST_CHUNKS_GCM_E11);
+ break;
+ case 12:
+ *aad_length = sizeof(NIST_AAD_GCM_E12);
+ *data_length = sizeof(NIST_TEST_DATA_GCM_E12);
+ *t_length = sizeof(NIST_TAG_GCM_E12);
+ *iv_length = sizeof(NIST_IV_GCM_E12);
+ *key_length = sizeof(NIST_KEY_GCM_E12);
+ *num_chunks = sizeof(NIST_CHUNKS_GCM_E12);
+ break;
+ }
+
+}
+
+void load_test_data(unsigned char *aad, unsigned int aad_length,
+ unsigned char *data, unsigned int data_length,
+ unsigned char *result,
+ unsigned char *t, unsigned int t_length,
+ unsigned char *iv, unsigned int iv_length,
+ unsigned char *key, unsigned int key_length,
+ unsigned char *chunks, unsigned int num_chunks,
+ unsigned int iteration)
+{
+ switch (iteration) {
+ case 1:
+ memcpy(iv, NIST_IV_GCM_E1, iv_length);
+ memcpy(aad, NIST_AAD_GCM_E1, aad_length);
+ memcpy(key, NIST_KEY_GCM_E1, key_length);
+ memcpy(data, NIST_TEST_DATA_GCM_E1, data_length);
+ memcpy(result, NIST_TEST_RESULT_GCM_E1, data_length);
+ memcpy(t, NIST_TAG_GCM_E1, t_length);
+ memcpy(chunks, NIST_CHUNKS_GCM_E1, num_chunks);
+ break;
+ case 2:
+ memcpy(iv, NIST_IV_GCM_E2, iv_length);
+ memcpy(aad, NIST_AAD_GCM_E2, aad_length);
+ memcpy(key, NIST_KEY_GCM_E2, key_length);
+ memcpy(data, NIST_TEST_DATA_GCM_E2, data_length);
+ memcpy(result, NIST_TEST_RESULT_GCM_E2, data_length);
+ memcpy(t, NIST_TAG_GCM_E2, t_length);
+ memcpy(chunks, NIST_CHUNKS_GCM_E2, num_chunks);
+ break;
+ case 3:
+ memcpy(iv, NIST_IV_GCM_E3, iv_length);
+ memcpy(aad, NIST_AAD_GCM_E3, aad_length);
+ memcpy(key, NIST_KEY_GCM_E3, key_length);
+ memcpy(data, NIST_TEST_DATA_GCM_E3, data_length);
+ memcpy(result, NIST_TEST_RESULT_GCM_E3, data_length);
+ memcpy(t, NIST_TAG_GCM_E3, t_length);
+ memcpy(chunks, NIST_CHUNKS_GCM_E3, num_chunks);
+ break;
+ case 4:
+ memcpy(iv, NIST_IV_GCM_E4, iv_length);
+ memcpy(aad, NIST_AAD_GCM_E4, aad_length);
+ memcpy(key, NIST_KEY_GCM_E4, key_length);
+ memcpy(data, NIST_TEST_DATA_GCM_E4, data_length);
+ memcpy(result, NIST_TEST_RESULT_GCM_E4, data_length);
+ memcpy(t, NIST_TAG_GCM_E4, t_length);
+ memcpy(chunks, NIST_CHUNKS_GCM_E4, num_chunks);
+ break;
+ case 5:
+ memcpy(iv, NIST_IV_GCM_E5, iv_length);
+ memcpy(aad, NIST_AAD_GCM_E5, aad_length);
+ memcpy(key, NIST_KEY_GCM_E5, key_length);
+ memcpy(data, NIST_TEST_DATA_GCM_E5, data_length);
+ memcpy(result, NIST_TEST_RESULT_GCM_E5, data_length);
+ memcpy(t, NIST_TAG_GCM_E5, t_length);
+ memcpy(chunks, NIST_CHUNKS_GCM_E5, num_chunks);
+ break;
+ case 6:
+ memcpy(iv, NIST_IV_GCM_E6, iv_length);
+ memcpy(aad, NIST_AAD_GCM_E6, aad_length);
+ memcpy(key, NIST_KEY_GCM_E6, key_length);
+ memcpy(data, NIST_TEST_DATA_GCM_E6, data_length);
+ memcpy(result, NIST_TEST_RESULT_GCM_E6, data_length);
+ memcpy(t, NIST_TAG_GCM_E6, t_length);
+ memcpy(chunks, NIST_CHUNKS_GCM_E6, num_chunks);
+ break;
+ case 7:
+ memcpy(iv, NIST_IV_GCM_E7, iv_length);
+ memcpy(aad, NIST_AAD_GCM_E7, aad_length);
+ memcpy(key, NIST_KEY_GCM_E7, key_length);
+ memcpy(data, NIST_TEST_DATA_GCM_E7, data_length);
+ memcpy(result, NIST_TEST_RESULT_GCM_E7, data_length);
+ memcpy(t, NIST_TAG_GCM_E7, t_length);
+ memcpy(chunks, NIST_CHUNKS_GCM_E7, num_chunks);
+ break;
+ case 8:
+ memcpy(iv, NIST_IV_GCM_E8, iv_length);
+ memcpy(aad, NIST_AAD_GCM_E8, aad_length);
+ memcpy(key, NIST_KEY_GCM_E8, key_length);
+ memcpy(data, NIST_TEST_DATA_GCM_E8, data_length);
+ memcpy(result, NIST_TEST_RESULT_GCM_E8, data_length);
+ memcpy(t, NIST_TAG_GCM_E8, t_length);
+ memcpy(chunks, NIST_CHUNKS_GCM_E8, num_chunks);
+ break;
+ case 9:
+ memcpy(iv, NIST_IV_GCM_E9, iv_length);
+ memcpy(aad, NIST_AAD_GCM_E9, aad_length);
+ memcpy(key, NIST_KEY_GCM_E9, key_length);
+ memcpy(data, NIST_TEST_DATA_GCM_E9, data_length);
+ memcpy(result, NIST_TEST_RESULT_GCM_E9, data_length);
+ memcpy(t, NIST_TAG_GCM_E9, t_length);
+ memcpy(chunks, NIST_CHUNKS_GCM_E9, num_chunks);
+ break;
+ case 10:
+ memcpy(iv, NIST_IV_GCM_E10, iv_length);
+ memcpy(aad, NIST_AAD_GCM_E10, aad_length);
+ memcpy(key, NIST_KEY_GCM_E10, key_length);
+ memcpy(data, NIST_TEST_DATA_GCM_E10, data_length);
+ memcpy(result, NIST_TEST_RESULT_GCM_E10, data_length);
+ memcpy(t, NIST_TAG_GCM_E10, t_length);
+ memcpy(chunks, NIST_CHUNKS_GCM_E10, num_chunks);
+ break;
+ case 11:
+ memcpy(iv, NIST_IV_GCM_E11, iv_length);
+ memcpy(aad, NIST_AAD_GCM_E11, aad_length);
+ memcpy(key, NIST_KEY_GCM_E11, key_length);
+ memcpy(data, NIST_TEST_DATA_GCM_E11, data_length);
+ memcpy(result, NIST_TEST_RESULT_GCM_E11, data_length);
+ memcpy(t, NIST_TAG_GCM_E11, t_length);
+ memcpy(chunks, NIST_CHUNKS_GCM_E11, num_chunks);
+ break;
+ case 12:
+ memcpy(iv, NIST_IV_GCM_E12, iv_length);
+ memcpy(aad, NIST_AAD_GCM_E12, aad_length);
+ memcpy(key, NIST_KEY_GCM_E12, key_length);
+ memcpy(data, NIST_TEST_DATA_GCM_E12, data_length);
+ memcpy(result, NIST_TEST_RESULT_GCM_E12, data_length);
+ memcpy(t, NIST_TAG_GCM_E12, t_length);
+ memcpy(chunks, NIST_CHUNKS_GCM_E12, num_chunks);
+ break;
+ }
+
+}
+
+int test_gcm_kat(int iteration, int silent)
+{
+ unsigned int aad_length;
+ unsigned int data_length;
+ unsigned int t_length;
+ unsigned int iv_length;
+ unsigned int key_length;
+ unsigned int num_chunks;
+
+ get_sizes(&aad_length, &data_length, &t_length, &iv_length,
+ &key_length, &num_chunks, iteration);
+
+ if (!silent) {
+ printf("Test Parameters for iteration = %i\n", iteration);
+ printf("key length = %i, data length = %i, tag length = %i,"
+ "iv length = %i aad_length = %i\n", key_length, data_length,
+ t_length, iv_length, aad_length);
+ }
+ unsigned char iv[iv_length];
+ unsigned char input_data[data_length];
+ unsigned char encrypt[data_length];
+ unsigned char decrypt[data_length];
+ unsigned char result[data_length];
+ unsigned char aad[aad_length];
+ unsigned char key[key_length];
+ unsigned char t[t_length];
+ unsigned char t_result[t_length];
+ unsigned char chunks[num_chunks];
+
+ int rc = 0;
+
+ load_test_data(aad, aad_length, input_data, data_length, result,
+ t_result, t_length, iv, iv_length, key, key_length,
+ chunks, num_chunks, iteration);
+
+ rc = ica_aes_gcm(input_data, data_length,
+ encrypt,
+ iv, iv_length,
+ aad, aad_length,
+ t, t_length,
+ key, key_length,
+ 1);
+ if (rc == EPERM) {
+ printf("ica_aes_gcm returns with EPERM (%d).\n", rc);
+ printf("Operation is not permitted on this machine. Test skipped!\n");
+ return 0;
+ }
+ if (rc) {
+ printf("ica_aes_gcm encrypt failed with rc = %i\n", rc);
+ dump_gcm_data(iv, iv_length, aad, aad_length, key, key_length,
+ input_data, data_length, encrypt, t, t_length);
+ }
+ if (!silent && !rc) {
+ printf("Encrypt:\n");
+ dump_gcm_data(iv, iv_length, aad, aad_length, key, key_length,
+ input_data, data_length, encrypt, t,
+ t_length);
+ }
+
+ if (memcmp(result, encrypt, data_length)) {
+ printf("Encryption Result does not match the known ciphertext!\n");
+ printf("Expected data:\n");
+ dump_array(result, data_length);
+ printf("Encryption Result:\n");
+ dump_array(encrypt, data_length);
+ rc++;
+ }
+ if (memcmp(t, t_result, t_length)) {
+ printf("Tag result does not match the expected tag!\n");
+ printf("Expected tag:\n");
+ dump_array(t_result, t_length);
+ printf("Tag Result:\n");
+ dump_array(t, t_length);
+ rc++;
+ }
+ if (rc) {
+ printf("GCM test exited after encryption\n");
+ return rc;
+ }
+ rc = ica_aes_gcm(decrypt, data_length,
+ encrypt,
+ iv, iv_length,
+ aad, aad_length,
+ t, t_length,
+ key, key_length,
+ 0);
+ if (rc == EPERM) {
+ printf("ica_aes_gcm returns with EPERM (%d).\n", rc);
+ printf("Operation is not permitted on this machine. Test skipped!\n");
+ return 0;
+ }
+ if (rc) {
+ printf("ica_aes_gcm decrypt failed with rc = %i\n", rc);
+ dump_gcm_data(iv, iv_length, aad, aad_length, key, key_length,
+ encrypt, data_length, decrypt, t,
+ t_length);
+ }
+
+
+ if (!silent && !rc) {
+ printf("Decrypt:\n");
+ dump_gcm_data(iv, iv_length, aad, aad_length, key, key_length,
+ encrypt, data_length, decrypt, t,
+ t_length);
+ }
+
+ if (memcmp(decrypt, input_data, data_length)) {
+ printf("Decryption Result does not match the original data!\n");
+ printf("Original data:\n");
+ dump_array(input_data, data_length);
+ printf("Decryption Result:\n");
+ dump_array(decrypt, data_length);
+ rc++;
+ }
+ if (memcmp(t, t_result, t_length)) {
+ printf("Tag result does not match the expected tag!\n");
+ printf("Expected tag:\n");
+ dump_array(t_result, t_length);
+ printf("Tag Result:\n");
+ dump_array(t, t_length);
+ rc++;
+ }
+ return rc;
+}
+
+int test_gcm_kat_update(int iteration, int silent)
+{
+ unsigned int aad_length;
+ unsigned int aad_length_tmp;
+ unsigned int data_length;
+ unsigned int t_length;
+ unsigned int iv_length;
+ unsigned int key_length;
+ unsigned int num_chunks;
+
+ get_sizes(&aad_length, &data_length, &t_length, &iv_length,
+ &key_length, &num_chunks, iteration);
+
+ if (!silent) {
+ printf("Test Parameters for iteration = %i\n", iteration);
+ printf("key length = %i, data length = %i, tag length = %i,"
+ "iv length = %i aad_length = %i\n", key_length, data_length,
+ t_length, iv_length, aad_length);
+ }
+ unsigned char iv[iv_length];
+ unsigned char input_data[data_length];
+ unsigned char encrypt[data_length];
+ unsigned char decrypt[data_length];
+ unsigned char result[data_length];
+ unsigned char aad[aad_length];
+ unsigned char key[key_length];
+ unsigned char t[t_length];
+ unsigned char t_result[t_length];
+ unsigned char chunks[num_chunks];
+ unsigned int chunk_len;
+ unsigned int offset;
+ unsigned char *chunk_data;
+ unsigned char icb[AES_BLOCK_SIZE];
+ unsigned char ucb[AES_BLOCK_SIZE];
+ unsigned char subkey[AES_BLOCK_SIZE];
+ unsigned char running_tag[AES_BLOCK_SIZE];
+ unsigned int sum_A_len;
+ unsigned int sum_C_len;
+ int rc = 0, i;
+
+
+ load_test_data(aad, aad_length, input_data, data_length, result,
+ t_result, t_length, iv, iv_length, key, key_length,
+ chunks, num_chunks, iteration);
+
+ aad_length_tmp = aad_length;
+ memset(running_tag, 0, AES_BLOCK_SIZE);
+ rc = ica_aes_gcm_initialize(iv, iv_length, key, key_length,
+ icb, ucb, subkey, 1);
+
+ offset = 0;
+ for (i = 0; i < num_chunks; i++) {
+ chunk_len = chunks[i];
+ chunk_data = input_data + offset;
+
+ rc = ica_aes_gcm_intermediate(chunk_data, chunk_len, encrypt + offset,
+ ucb, aad, aad_length,
+ running_tag, AES_BLOCK_SIZE,
+ key, key_length, subkey, 1);
+ /* clear aad_length after first run*/
+ aad_length = 0;
+ offset += chunk_len;
+ }
+ sum_A_len = aad_length_tmp;
+ sum_C_len = offset;
+ rc = ica_aes_gcm_last(icb, sum_A_len, sum_C_len, running_tag,
+ t, t_length, key, key_length, subkey, 1);
+
+ if (rc == EPERM) {
+ printf("ica_aes_gcm returns with EPERM (%d).\n", rc);
+ printf("Operation is not permitted on this machine. Test skipped!\n");
+ return 0;
+ }
+ if (rc) {
+ printf("ica_aes_gcm encrypt failed with rc = %i\n", rc);
+ dump_gcm_data(iv, iv_length, aad, aad_length, key, key_length,
+ input_data, data_length, encrypt, t, t_length);
+ }
+ if (!silent && !rc) {
+ printf("Encrypt:\n");
+ dump_gcm_data(iv, iv_length, aad, aad_length, key, key_length,
+ input_data, data_length, encrypt, running_tag,
+ t_length);
+ }
+
+ if (memcmp(result, encrypt, data_length)) {
+ printf("Encryption Result does not match the known ciphertext!\n");
+ printf("Expected data:\n");
+ dump_array(result, data_length);
+ printf("Encryption Result:\n");
+ dump_array(encrypt, data_length);
+ rc++;
+ }
+ if (memcmp(running_tag, t_result, t_length)) {
+ printf("Tag result does not match the expected tag!\n");
+ printf("Expected tag:\n");
+ dump_array(t_result, t_length);
+ printf("Tag Result:\n");
+ dump_array(t, t_length);
+ rc++;
+ }
+ if (rc) {
+ printf("GCM test exited after encryption\n");
+ return rc;
+ }
+
+ aad_length = aad_length_tmp;
+ memset(running_tag, 0, AES_BLOCK_SIZE);
+ rc = ica_aes_gcm_initialize(iv, iv_length, key, key_length,
+ icb, ucb, subkey, 0);
+
+ offset = 0;
+ for (i = 0; i < num_chunks; i++) {
+ chunk_len = chunks[i];
+ chunk_data = encrypt + offset;
+
+ rc = ica_aes_gcm_intermediate(decrypt + offset, chunk_len, chunk_data,
+ ucb, aad, aad_length,
+ running_tag, AES_BLOCK_SIZE,
+ key, key_length, subkey, 0);
+
+ /* clear aad_length after first run*/
+ aad_length = 0;
+ offset += chunk_len;
+ }
+ sum_A_len = aad_length_tmp;
+ sum_C_len = offset;
+ rc = ica_aes_gcm_last(icb, sum_A_len, sum_C_len, running_tag,
+ t_result, t_length, key, key_length, subkey, 0);
+
+
+ if (rc == EPERM) {
+ printf("ica_aes_gcm returns with EPERM (%d).\n", rc);
+ printf("Operation is not permitted on this machine. Test skipped!\n");
+ return 0;
+ }
+ if (rc) {
+ printf("ica_aes_gcm decrypt failed with rc = %i\n", rc);
+ dump_gcm_data(iv, iv_length, aad, aad_length, key, key_length,
+ encrypt, data_length, decrypt, running_tag,
+ t_length);
+ }
+
+
+ if (!silent && !rc) {
+ printf("Decrypt:\n");
+ dump_gcm_data(iv, iv_length, aad, aad_length, key, key_length,
+ encrypt, data_length, decrypt, running_tag,
+ t_length);
+ }
+
+ if (memcmp(decrypt, input_data, data_length)) {
+ printf("Decryption Result does not match the original data!\n");
+ printf("Original data:\n");
+ dump_array(input_data, data_length);
+ printf("Decryption Result:\n");
+ dump_array(decrypt, data_length);
+ rc++;
+ }
+ if (memcmp(running_tag, t_result, t_length)) {
+ printf("Tag result does not match the expected tag!\n");
+ printf("Expected tag:\n");
+ dump_array(t_result, t_length);
+ printf("Tag Result:\n");
+ dump_array(t, t_length);
+ rc++;
+ }
+ return rc;
+}
+
+int main(int argc, char **argv)
+{
+ // Default mode is 0. ECB,CBC and CFQ tests will be performed.
+ unsigned int silent = 0;
+ if (argc > 1) {
+ if (strstr(argv[1], "silent"))
+ silent = 1;
+ if (argc == 3)
+ if (strstr(argv[2], "silent"))
+ silent = 1;
+
+ }
+
+ int rc = 0;
+ int error_count = 0;
+ int iteration;
+ for(iteration = 1; iteration <= NR_TESTS; iteration++) {
+
+ rc = test_gcm_kat(iteration, silent);
+ if (rc) {
+ printf("test_gcm_kat failed with rc = %i\n", rc);
+ error_count++;
+ }
+
+ rc = test_gcm_kat_update(iteration, silent);
+ if (rc) {
+ printf("test_gcm_kat_update failed with rc = %i\n", rc);
+ error_count++;
+ }
+
+
+ }
+ if (error_count)
+ printf("%i of %i testcases failed\n", error_count, iteration);
+ else
+ printf("All AES-GCM testcases finished successfully.\n");
+ return rc;
+}
diff --git a/src/tests/libica_aes_ofb_test.c b/src/tests/libica_aes_ofb_test.c
new file mode 100644
index 0000000..717d36d
--- /dev/null
+++ b/src/tests/libica_aes_ofb_test.c
@@ -0,0 +1,555 @@
+/* This program is released under the Common Public License V1.0
+ *
+ * You should have received a copy of Common Public License V1.0 along with
+ * with this program.
+ */
+
+/* Copyright IBM Corp. 2010, 2011 */
+#include <fcntl.h>
+#include <sys/errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+#include <stdlib.h>
+#include "ica_api.h"
+
+#define NR_TESTS 6
+#define NR_RANDOM_TESTS 10000
+
+/* OFB data - 1 for AES128 */
+unsigned char NIST_KEY_OFB_E1[] = {
+ 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
+ 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c,
+};
+
+unsigned char NIST_IV_OFB_E1[] = {
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+};
+
+unsigned char NIST_EXPECTED_IV_OFB_E1[] = {
+ 0x50, 0xfe, 0x67, 0xcc, 0x99, 0x6d, 0x32, 0xb6,
+ 0xda, 0x09, 0x37, 0xe9, 0x9b, 0xaf, 0xec, 0x60,
+};
+
+unsigned char NIST_TEST_DATA_OFB_E1[] = {
+ 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
+ 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
+};
+
+unsigned char NIST_TEST_RESULT_OFB_E1[] = {
+ 0x3b, 0x3f, 0xd9, 0x2e, 0xb7, 0x2d, 0xad, 0x20,
+ 0x33, 0x34, 0x49, 0xf8, 0xe8, 0x3c, 0xfb, 0x4a,
+};
+
+/* OFB data - 2 for AES128 */
+unsigned char NIST_KEY_OFB_E2[] = {
+ 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
+ 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c,
+};
+
+unsigned char NIST_IV_OFB_E2[] = {
+ 0x50, 0xfe, 0x67, 0xcc, 0x99, 0x6d, 0x32, 0xb6,
+ 0xda, 0x09, 0x37, 0xe9, 0x9b, 0xaf, 0xec, 0x60,
+};
+
+unsigned char NIST_EXPECTED_IV_OFB_E2[] = {
+ 0xd9, 0xa4, 0xda, 0xda, 0x08, 0x92, 0x23, 0x9f,
+ 0x6b, 0x8b, 0x3d, 0x76, 0x80, 0xe1, 0x56, 0x74,
+};
+
+unsigned char NIST_TEST_DATA_OFB_E2[] = {
+ 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
+ 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
+};
+
+unsigned char NIST_TEST_RESULT_OFB_E2[] = {
+ 0x77, 0x89, 0x50, 0x8d, 0x16, 0x91, 0x8f, 0x03,
+ 0xf5, 0x3c, 0x52, 0xda, 0xc5, 0x4e, 0xd8, 0x25,
+};
+
+/* OFB data - 3 - for AES192 */
+unsigned char NIST_KEY_OFB_E3[] = {
+ 0x8e, 0x73, 0xb0, 0xf7, 0xda, 0x0e, 0x64, 0x52,
+ 0xc8, 0x10, 0xf3, 0x2b, 0x80, 0x90, 0x79, 0xe5,
+ 0x62, 0xf8, 0xea, 0xd2, 0x52, 0x2c, 0x6b, 0x7b,
+};
+
+unsigned char NIST_IV_OFB_E3[] = {
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+};
+
+unsigned char NIST_EXPECTED_IV_OFB_E3[] = {
+ 0xa6, 0x09, 0xb3, 0x8d, 0xf3, 0xb1, 0x13, 0x3d,
+ 0xdd, 0xff, 0x27, 0x18, 0xba, 0x09, 0x56, 0x5e,
+};
+
+unsigned char NIST_TEST_DATA_OFB_E3[] = {
+ 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
+ 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
+};
+
+unsigned char NIST_TEST_RESULT_OFB_E3[] = {
+ 0xcd, 0xc8, 0x0d, 0x6f, 0xdd, 0xf1, 0x8c, 0xab,
+ 0x34, 0xc2, 0x59, 0x09, 0xc9, 0x9a, 0x41, 0x74,
+};
+
+/* OFB data - 4 - for AES192 */
+unsigned char NIST_KEY_OFB_E4[] = {
+ 0x8e, 0x73, 0xb0, 0xf7, 0xda, 0x0e, 0x64, 0x52,
+ 0xc8, 0x10, 0xf3, 0x2b, 0x80, 0x90, 0x79, 0xe5,
+ 0x62, 0xf8, 0xea, 0xd2, 0x52, 0x2c, 0x6b, 0x7b,
+};
+
+unsigned char NIST_IV_OFB_E4[] = {
+ 0xa6, 0x09, 0xb3, 0x8d, 0xf3, 0xb1, 0x13, 0x3d,
+ 0xdd, 0xff, 0x27, 0x18, 0xba, 0x09, 0x56, 0x5e,
+};
+
+unsigned char NIST_EXPECTED_IV_OFB_E4[] = {
+ 0x52, 0xef, 0x01, 0xda, 0x52, 0x60, 0x2f, 0xe0,
+ 0x97, 0x5f, 0x78, 0xac, 0x84, 0xbf, 0x8a, 0x50,
+};
+
+unsigned char NIST_TEST_DATA_OFB_E4[] = {
+ 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
+ 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
+};
+
+unsigned char NIST_TEST_RESULT_OFB_E4[] = {
+ 0xfc, 0xc2, 0x8b, 0x8d, 0x4c, 0x63, 0x83, 0x7c,
+ 0x09, 0xe8, 0x17, 0x00, 0xc1, 0x10, 0x04, 0x01,
+};
+
+/* OFB data 5 - for AES 256 */
+unsigned char NIST_KEY_OFB_E5[] = {
+ 0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe,
+ 0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81,
+ 0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7,
+ 0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4,
+};
+
+unsigned char NIST_IV_OFB_E5[] = {
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+};
+
+unsigned char NIST_EXPECTED_IV_OFB_E5[] = {
+ 0xb7, 0xbf, 0x3a, 0x5d, 0xf4, 0x39, 0x89, 0xdd,
+ 0x97, 0xf0, 0xfa, 0x97, 0xeb, 0xce, 0x2f, 0x4a,
+};
+
+unsigned char NIST_TEST_DATA_OFB_E5[] = {
+ 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
+ 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
+};
+
+unsigned char NIST_TEST_RESULT_OFB_E5[] = {
+ 0xdc, 0x7e, 0x84, 0xbf, 0xda, 0x79, 0x16, 0x4b,
+ 0x7e, 0xcd, 0x84, 0x86, 0x98, 0x5d, 0x38, 0x60,
+};
+
+/* OFB data 6 - for AES 256 */
+unsigned char NIST_KEY_OFB_E6[] = {
+ 0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe,
+ 0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81,
+ 0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7,
+ 0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4,
+};
+
+unsigned char NIST_IV_OFB_E6[] = {
+ 0xb7, 0xbf, 0x3a, 0x5d, 0xf4, 0x39, 0x89, 0xdd,
+ 0x97, 0xf0, 0xfa, 0x97, 0xeb, 0xce, 0x2f, 0x4a,
+};
+
+unsigned char NIST_EXPECTED_IV_OFB_E6[] = {
+ 0xe1, 0xc6, 0x56, 0x30, 0x5e, 0xd1, 0xa7, 0xa6,
+ 0x56, 0x38, 0x05, 0x74, 0x6f, 0xe0, 0x3e, 0xdc,
+};
+
+unsigned char NIST_TEST_DATA_OFB_E6[] = {
+ 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
+ 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
+};
+
+unsigned char NIST_TEST_RESULT_OFB_E6[] = {
+ 0x4f, 0xeb, 0xdc, 0x67, 0x40, 0xd2, 0x0b, 0x3a,
+ 0xc8, 0x8f, 0x6a, 0xd8, 0x2a, 0x4f, 0xb0, 0x8d,
+};
+
+
+void dump_array(unsigned char *ptr, unsigned int size)
+{
+ unsigned char *ptr_end;
+ unsigned char *h;
+ int i = 1;
+
+ h = ptr;
+ ptr_end = ptr + size;
+ while (h < (unsigned char *)ptr_end) {
+ printf("0x%02x ",(unsigned char ) *h);
+ h++;
+ if (i == 8) {
+ printf("\n");
+ i = 1;
+ } else {
+ ++i;
+ }
+ }
+ printf("\n");
+}
+
+void dump_ofb_data(unsigned char *iv, unsigned int iv_length,
+ unsigned char *key, unsigned int key_length,
+ unsigned char *input_data, unsigned int data_length,
+ unsigned char *output_data)
+{
+ printf("IV \n");
+ dump_array(iv, iv_length);
+ printf("Key \n");
+ dump_array(key, key_length);
+ printf("Input Data\n");
+ dump_array(input_data, data_length);
+ printf("Output Data\n");
+ dump_array(output_data, data_length);
+}
+
+void get_sizes(unsigned int *data_length, unsigned int *iv_length,
+ unsigned int *key_length, unsigned int iteration)
+{
+ switch (iteration) {
+ case 1:
+ *data_length = sizeof(NIST_TEST_DATA_OFB_E1);
+ *iv_length = sizeof(NIST_IV_OFB_E1);
+ *key_length = sizeof(NIST_KEY_OFB_E1);
+ break;
+ case 2:
+ *data_length = sizeof(NIST_TEST_DATA_OFB_E2);
+ *iv_length = sizeof(NIST_IV_OFB_E2);
+ *key_length = sizeof(NIST_KEY_OFB_E2);
+ break;
+ case 3:
+ *data_length = sizeof(NIST_TEST_DATA_OFB_E3);
+ *iv_length = sizeof(NIST_IV_OFB_E3);
+ *key_length = sizeof(NIST_KEY_OFB_E3);
+ break;
+ case 4:
+ *data_length = sizeof(NIST_TEST_DATA_OFB_E4);
+ *iv_length = sizeof(NIST_IV_OFB_E4);
+ *key_length = sizeof(NIST_KEY_OFB_E4);
+ break;
+ case 5:
+ *data_length = sizeof(NIST_TEST_DATA_OFB_E5);
+ *iv_length = sizeof(NIST_IV_OFB_E5);
+ *key_length = sizeof(NIST_KEY_OFB_E5);
+ break;
+ case 6:
+ *data_length = sizeof(NIST_TEST_DATA_OFB_E6);
+ *iv_length = sizeof(NIST_IV_OFB_E6);
+ *key_length = sizeof(NIST_KEY_OFB_E6);
+ break;
+ }
+
+}
+
+void load_test_data(unsigned char *data, unsigned int data_length,
+ unsigned char *result,
+ unsigned char *iv, unsigned char *expected_iv,
+ unsigned int iv_length,
+ unsigned char *key, unsigned int key_length,
+ unsigned int iteration)
+{
+ switch (iteration) {
+ case 1:
+ memcpy(data, NIST_TEST_DATA_OFB_E1, data_length);
+ memcpy(result, NIST_TEST_RESULT_OFB_E1, data_length);
+ memcpy(iv, NIST_IV_OFB_E1, iv_length);
+ memcpy(expected_iv, NIST_EXPECTED_IV_OFB_E1, iv_length);
+ memcpy(key, NIST_KEY_OFB_E1, key_length);
+ break;
+ case 2:
+ memcpy(data, NIST_TEST_DATA_OFB_E2, data_length);
+ memcpy(result, NIST_TEST_RESULT_OFB_E2, data_length);
+ memcpy(iv, NIST_IV_OFB_E2, iv_length);
+ memcpy(expected_iv, NIST_EXPECTED_IV_OFB_E2, iv_length);
+ memcpy(key, NIST_KEY_OFB_E2, key_length);
+ break;
+ case 3:
+ memcpy(data, NIST_TEST_DATA_OFB_E3, data_length);
+ memcpy(result, NIST_TEST_RESULT_OFB_E3, data_length);
+ memcpy(iv, NIST_IV_OFB_E3, iv_length);
+ memcpy(expected_iv, NIST_EXPECTED_IV_OFB_E3, iv_length);
+ memcpy(key, NIST_KEY_OFB_E3, key_length);
+ break;
+ case 4:
+ memcpy(data, NIST_TEST_DATA_OFB_E4, data_length);
+ memcpy(result, NIST_TEST_RESULT_OFB_E4, data_length);
+ memcpy(iv, NIST_IV_OFB_E4, iv_length);
+ memcpy(expected_iv, NIST_EXPECTED_IV_OFB_E4, iv_length);
+ memcpy(key, NIST_KEY_OFB_E4, key_length);
+ break;
+ case 5:
+ memcpy(data, NIST_TEST_DATA_OFB_E5, data_length);
+ memcpy(result, NIST_TEST_RESULT_OFB_E5, data_length);
+ memcpy(iv, NIST_IV_OFB_E5, iv_length);
+ memcpy(expected_iv, NIST_EXPECTED_IV_OFB_E5, iv_length);
+ memcpy(key, NIST_KEY_OFB_E5, key_length);
+ break;
+ case 6:
+ memcpy(data, NIST_TEST_DATA_OFB_E6, data_length);
+ memcpy(result, NIST_TEST_RESULT_OFB_E6, data_length);
+ memcpy(iv, NIST_IV_OFB_E6, iv_length);
+ memcpy(expected_iv, NIST_EXPECTED_IV_OFB_E6, iv_length);
+ memcpy(key, NIST_KEY_OFB_E6, key_length);
+ break;
+ }
+
+}
+
+int load_random_test_data(unsigned char *data, unsigned int data_length,
+ unsigned char *iv, unsigned int iv_length,
+ unsigned char *key, unsigned int key_length)
+{
+ int rc;
+ rc = ica_random_number_generate(data_length, data);
+ if (rc) {
+ printf("ica_random_number_generate with rc = %i errnor = %i\n",
+ rc, errno);
+ return rc;
+ }
+ rc = ica_random_number_generate(iv_length, iv);
+ if (rc) {
+ printf("ica_random_number_generate with rc = %i errnor = %i\n",
+ rc, errno);
+ return rc;
+ }
+ rc = ica_random_number_generate(key_length, key);
+ if (rc) {
+ printf("ica_random_number_generate with rc = %i errnor = %i\n",
+ rc, errno);
+ return rc;
+ }
+ return rc;
+}
+
+int random_aes_ofb(int iteration, int silent, unsigned int data_length)
+{
+ int i;
+ int rc = 0;
+ unsigned int iv_length = sizeof(ica_aes_vector_t);
+ unsigned int key_length = AES_KEY_LEN128;
+ unsigned char iv[iv_length];
+ unsigned char tmp_iv[iv_length];
+ unsigned char input_data[data_length];
+ unsigned char encrypt[data_length];
+ unsigned char decrypt[data_length];
+for (i = 0; i <= 2; i++) {
+
+ unsigned char key[key_length];
+
+ memset(encrypt, 0x00, data_length);
+ memset(decrypt, 0x00, data_length);
+
+ load_random_test_data(input_data, data_length, iv, iv_length, key,
+ key_length);
+ memcpy(tmp_iv, iv, iv_length);
+
+ if (!silent) {
+ printf("Test Parameters for iteration = %i\n", iteration);
+ printf("key length = %i, data length = %i, iv length = %i\n",
+ key_length, data_length, iv_length);
+ }
+ rc = ica_aes_ofb(input_data, encrypt, data_length, key, key_length,
+ tmp_iv, 1);
+ if (rc) {
+ printf("ica_aes_ofb encrypt failed with rc = %i\n", rc);
+ dump_ofb_data(iv, iv_length, key, key_length, input_data,
+ data_length, encrypt);
+ }
+ if (!silent && !rc) {
+ printf("Encrypt:\n");
+ dump_ofb_data(iv, iv_length, key, key_length, input_data,
+ data_length, encrypt);
+ }
+
+ if (rc) {
+ printf("AES OFB test exited after encryption\n");
+ return rc;
+ }
+
+ memcpy(tmp_iv, iv, iv_length);
+
+ rc = ica_aes_ofb(encrypt, decrypt, data_length, key, key_length,
+ tmp_iv, 0);
+ if (rc) {
+ printf("ica_aes_ofb decrypt failed with rc = %i\n", rc);
+ dump_ofb_data(iv, iv_length, key, key_length, encrypt,
+ data_length, decrypt);
+ return rc;
+ }
+
+
+ if (!silent && !rc) {
+ printf("Decrypt:\n");
+ dump_ofb_data(iv, iv_length, key, key_length, encrypt,
+ data_length, decrypt);
+ }
+
+ if (memcmp(decrypt, input_data, data_length)) {
+ printf("Decryption Result does not match the original data!\n");
+ printf("Original data:\n");
+ dump_array(input_data, data_length);
+ printf("Decryption Result:\n");
+ dump_array(decrypt, data_length);
+ rc++;
+ return rc;
+ }
+ key_length += 8;
+}
+
+ return rc;
+}
+
+int kat_aes_ofb(int iteration, int silent)
+{
+ unsigned int data_length;
+ unsigned int iv_length;
+ unsigned int key_length;
+
+ get_sizes(&data_length, &iv_length, &key_length, iteration);
+
+ if (!silent) {
+ printf("Test Parameters for iteration = %i\n", iteration);
+ printf("key length = %i, data length = %i, iv length = %i\n",
+ key_length, data_length, iv_length);
+ }
+ unsigned char iv[iv_length];
+ unsigned char tmp_iv[iv_length];
+ unsigned char expected_iv[iv_length];
+ unsigned char key[key_length];
+ unsigned char input_data[data_length];
+ unsigned char encrypt[data_length];
+ unsigned char decrypt[data_length];
+ unsigned char result[data_length];
+
+ int rc = 0;
+
+ load_test_data(input_data, data_length, result, iv, expected_iv,
+ iv_length, key, key_length, iteration);
+ memcpy(tmp_iv, iv, iv_length);
+
+ rc = ica_aes_ofb(input_data, encrypt, data_length, key, key_length,
+ tmp_iv, 1);
+ if (rc) {
+ printf("ica_aes_ofb encrypt failed with rc = %i\n", rc);
+ dump_ofb_data(iv, iv_length, key, key_length, input_data,
+ data_length, encrypt);
+ }
+ if (!silent && !rc) {
+ printf("Encrypt:\n");
+ dump_ofb_data(iv, iv_length, key, key_length, input_data,
+ data_length, encrypt);
+ }
+
+ if (memcmp(result, encrypt, data_length)) {
+ printf("Encryption Result does not match the known ciphertext!\n");
+ printf("Expected data:\n");
+ dump_array(result, data_length);
+ printf("Encryption Result:\n");
+ dump_array(encrypt, data_length);
+ rc++;
+ }
+
+ if (memcmp(expected_iv, tmp_iv, iv_length)) {
+ printf("Update of IV does not match the expected IV!\n");
+ printf("Expected IV:\n");
+ dump_array(expected_iv, iv_length);
+ printf("Updated IV:\n");
+ dump_array(tmp_iv, iv_length);
+ printf("Original IV:\n");
+ dump_array(iv, iv_length);
+ rc++;
+ }
+ if (rc) {
+ printf("AES OFB test exited after encryption\n");
+ return rc;
+ }
+
+ memcpy(tmp_iv, iv, iv_length);
+ rc = ica_aes_ofb(encrypt, decrypt, data_length, key, key_length,
+ tmp_iv, 0);
+ if (rc) {
+ printf("ica_aes_ofb decrypt failed with rc = %i\n", rc);
+ dump_ofb_data(iv, iv_length, key, key_length, encrypt,
+ data_length, decrypt);
+ return rc;
+ }
+
+
+ if (!silent && !rc) {
+ printf("Decrypt:\n");
+ dump_ofb_data(iv, iv_length, key, key_length, encrypt,
+ data_length, decrypt);
+ }
+
+ if (memcmp(decrypt, input_data, data_length)) {
+ printf("Decryption Result does not match the original data!\n");
+ printf("Original data:\n");
+ dump_array(input_data, data_length);
+ printf("Decryption Result:\n");
+ dump_array(decrypt, data_length);
+ rc++;
+ }
+ return rc;
+}
+
+int main(int argc, char **argv)
+{
+ int rc = 0;
+ int error_count = 0;
+ int iteration;
+ unsigned int rdata;
+ unsigned int data_length = 1;
+ unsigned int silent = 0;
+
+ if (argc > 1) {
+ if (strstr(argv[1], "silent"))
+ silent = 1;
+ }
+
+ for(iteration = 1; iteration <= NR_TESTS; iteration++) {
+ rc = kat_aes_ofb(iteration, silent);
+ if (rc) {
+ printf("kat_aes_ofb failed with rc = %i\n", rc);
+ error_count++;
+ }
+
+ }
+
+ for(iteration = 1; iteration <= NR_RANDOM_TESTS; iteration++) {
+ int silent = 1;
+ rc = random_aes_ofb(iteration, silent, data_length);
+ if (rc) {
+ printf("random_aes_ofb failed with rc = %i\n", rc);
+ error_count++;
+ goto out;
+ }
+ // add a value between 1 and 8 to data_length
+ if (ica_random_number_generate(sizeof(rdata), (unsigned char*) &rdata)) {
+ printf("ica_random_number_generate failed with errnor = %i\n",
+ errno);
+ exit(1);
+ }
+ data_length += (rdata % 8) + 1;
+ }
+
+out:
+ if (error_count)
+ printf("%i testcases failed\n", error_count);
+ else
+ printf("All AES-OFB testcases finished successfully\n");
+
+ return rc;
+}
+
diff --git a/src/tests/libica_aes_xts_test.c b/src/tests/libica_aes_xts_test.c
new file mode 100644
index 0000000..0e14f4a
--- /dev/null
+++ b/src/tests/libica_aes_xts_test.c
@@ -0,0 +1,669 @@
+/* This program is released under the Common Public License V1.0
+ *
+ * You should have recetweaked a copy of Common Public License V1.0 along with
+ * with this program.
+ */
+
+/* Copyright IBM Corp. 2010, 2011 */
+#include <fcntl.h>
+#include <sys/errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+#include <stdlib.h>
+#include "ica_api.h"
+
+#define NR_TESTS 5
+#define NR_RANDOM_TESTS 20000
+
+/* XTS data -1- AES128 */
+unsigned char NIST_KEY_XTS_E1[] = {
+ 0x46, 0xe6, 0xed, 0x9e, 0xf4, 0x2d, 0xcd, 0xb3,
+ 0xc8, 0x93, 0x09, 0x3c, 0x28, 0xe1, 0xfc, 0x0f,
+ 0x91, 0xf5, 0xca, 0xa3, 0xb6, 0xe0, 0xbc, 0x5a,
+ 0x14, 0xe7, 0x83, 0x21, 0x5c, 0x1d, 0x5b, 0x61,
+};
+
+unsigned char NIST_TWEAK_XTS_E1[] = {
+ 0x72, 0xf3, 0xb0, 0x54, 0xcb, 0xdc, 0x2f, 0x9e,
+ 0x3c, 0x5b, 0xc5, 0x51, 0xd4, 0x4d, 0xdb, 0xa0,
+};
+
+/* TWEAK should not be updated, so the exptected tweak is the same as the
+ * original TWEAK.
+ */
+unsigned char NIST_EXPECTED_TWEAK_XTS_E1[] = {
+ 0x72, 0xf3, 0xb0, 0x54, 0xcb, 0xdc, 0x2f, 0x9e,
+ 0x3c, 0x5b, 0xc5, 0x51, 0xd4, 0x4d, 0xdb, 0xa0,
+};
+
+unsigned char NIST_TEST_DATA_XTS_E1[] = {
+ 0xe3, 0x77, 0x8d, 0x68, 0xe7, 0x30, 0xef, 0x94,
+ 0x5b, 0x4a, 0xe3, 0xbc, 0x5b, 0x93, 0x6b, 0xdd,
+};
+
+unsigned char NIST_TEST_RESULT_XTS_E1[] = {
+ 0x97, 0x40, 0x9f, 0x1f, 0x71, 0xae, 0x45, 0x21,
+ 0xcb, 0x49, 0xa3, 0x29, 0x73, 0xde, 0x4d, 0x05,
+};
+
+/* XTS data -2- AES128 */
+unsigned char NIST_KEY_XTS_E2[] = {
+ 0x93, 0x56, 0xcd, 0xad, 0x25, 0x1a, 0xb6, 0x11,
+ 0x14, 0xce, 0xc2, 0xc4, 0x4a, 0x60, 0x92, 0xdd,
+ 0xe9, 0xf7, 0x46, 0xcc, 0x65, 0xae, 0x3b, 0xd4,
+ 0x96, 0x68, 0x64, 0xaa, 0x36, 0x26, 0xd1, 0x88,
+};
+
+unsigned char NIST_TWEAK_XTS_E2[] = {
+ 0x68, 0x88, 0x27, 0x83, 0x65, 0x24, 0x36, 0xc4,
+ 0x85, 0x7a, 0x88, 0xc0, 0xc3, 0x73, 0x41, 0x7e,
+};
+
+unsigned char NIST_EXPECTED_TWEAK_XTS_E2[] = {
+ 0x68, 0x88, 0x27, 0x83, 0x65, 0x24, 0x36, 0xc4,
+ 0x85, 0x7a, 0x88, 0xc0, 0xc3, 0x73, 0x41, 0x7e,
+};
+
+unsigned char NIST_TEST_DATA_XTS_E2[] = {
+ 0xce, 0x17, 0x6b, 0xdd, 0xe3, 0x39, 0x50, 0x5b,
+ 0xa1, 0x5d, 0xea, 0x36, 0xd2, 0x8c, 0xe8, 0x7d,
+};
+
+unsigned char NIST_TEST_RESULT_XTS_E2[] = {
+ 0x22, 0xf5, 0xf9, 0x37, 0xdf, 0xb3, 0x9e, 0x5b,
+ 0x74, 0x25, 0xed, 0x86, 0x3d, 0x31, 0x0b, 0xe1,
+};
+
+/* XTS data -3- AES128 */
+unsigned char NIST_KEY_XTS_E3[] = {
+ 0x63, 0xf3, 0x6e, 0x9c, 0x39, 0x7c, 0x65, 0x23,
+ 0xc9, 0x9f, 0x16, 0x44, 0xec, 0xb1, 0xa5, 0xd9,
+ 0xbc, 0x0f, 0x2f, 0x55, 0xfb, 0xe3, 0x24, 0x44,
+ 0x4c, 0x39, 0x0f, 0xae, 0x75, 0x2a, 0xd4, 0xd7,
+};
+
+unsigned char NIST_TWEAK_XTS_E3[] = {
+ 0xcd, 0xb1, 0xbd, 0x34, 0x86, 0xf3, 0x53, 0xcc,
+ 0x16, 0x0a, 0x84, 0x0b, 0xea, 0xdf, 0x03, 0x29,
+};
+
+unsigned char NIST_EXPECTED_TWEAK_XTS_E3[] = {
+ 0xcd, 0xb1, 0xbd, 0x34, 0x86, 0xf3, 0x53, 0xcc,
+ 0x16, 0x0a, 0x84, 0x0b, 0xea, 0xdf, 0x03, 0x29,
+};
+
+unsigned char NIST_TEST_DATA_XTS_E3[] = {
+ 0x9a, 0x01, 0x49, 0x88, 0x8b, 0xf7, 0x61, 0x60,
+ 0xa8, 0x14, 0x28, 0xbc, 0x91, 0x40, 0xec, 0xcd,
+ 0x26, 0xed, 0x18, 0x36, 0x8e, 0x24, 0xd4, 0x9b,
+ 0x9c, 0xc5, 0x12, 0x92, 0x9a, 0x88, 0xad, 0x1e,
+ 0x66, 0xc7, 0x63, 0xf4, 0xf5, 0x6b, 0x63, 0xbb,
+ 0x9d, 0xd9, 0x50, 0x8c, 0x5d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x73, 0x32, 0x14, 0x68, 0xd1, 0xab,
+ 0x3f, 0xad, 0x8a, 0xd9, 0x1f, 0xcd, 0xc6, 0x2a,
+ 0xbe, 0x07, 0xbf, 0xf8, 0xef, 0x96, 0x1b, 0x6b,
+};
+
+unsigned char NIST_TWEAK_XTS_E4[] = {
+ 0x15, 0x60, 0x1e, 0x2e, 0x35, 0x85, 0x10, 0xa0,
+ 0x9d, 0xdc, 0xa4, 0xea, 0x17, 0x51, 0xf4, 0x3c,
+};
+
+unsigned char NIST_EXPECTED_TWEAK_XTS_E4[] = {
+ 0x15, 0x60, 0x1e, 0x2e, 0x35, 0x85, 0x10, 0xa0,
+ 0x9d, 0xdc, 0xa4, 0xea, 0x17, 0x51, 0xf4, 0x3c,
+};
+
+unsigned char NIST_TEST_DATA_XTS_E4[] = {
+ 0xd1, 0x9c, 0xfb, 0x38, 0x3b, 0xaf, 0x87, 0x2e,
+ 0x6f, 0x12, 0x16, 0x87, 0x45, 0x1d, 0xe1, 0x5c,
+};
+
+unsigned char NIST_TEST_RESULT_XTS_E4[] = {
+ 0xeb, 0x22, 0x26, 0x9b, 0x14, 0x90, 0x50, 0x27,
+ 0xdc, 0x73, 0xc4, 0xa4, 0x0f, 0x93, 0x80, 0x69,
+};
+
+
+/* XTS data -5- AES256 */
+unsigned char NIST_KEY_XTS_E5[] = {
+ 0xfb, 0xf0, 0x77, 0x6e, 0x7d, 0xbe, 0x49, 0x10,
+ 0xfb, 0x0c, 0x12, 0x0f, 0x41, 0x85, 0x71, 0x21,
+ 0x92, 0x6c, 0x05, 0x2f, 0xd6, 0x5a, 0x27, 0x8c,
+ 0xd2, 0xf0, 0xd9, 0x8d, 0xa5, 0x4e, 0xdf, 0xd5,
+ 0x08, 0x03, 0xa4, 0x2f, 0xbe, 0x6f, 0xd1, 0x33,
+ 0x58, 0x49, 0x00, 0xe8, 0xdc, 0x7a, 0x11, 0x52,
+ 0x39, 0x1f, 0x82, 0x2d, 0x76, 0xa7, 0x56, 0x68,
+ 0xcf, 0xce, 0x7f, 0x8d, 0xde, 0x20, 0x3e, 0xc8,
+};
+
+unsigned char NIST_TWEAK_XTS_E5[] = {
+ 0x39, 0x5b, 0x6a, 0xcf, 0x9a, 0xdc, 0xd2, 0x91,
+ 0xc2, 0xc9, 0x48, 0x86, 0x36, 0x33, 0xaf, 0xf8,
+};
+
+unsigned char NIST_EXPECTED_TWEAK_XTS_E5[] = {
+ 0x39, 0x5b, 0x6a, 0xcf, 0x9a, 0xdc, 0xd2, 0x91,
+ 0xc2, 0xc9, 0x48, 0x86, 0x36, 0x33, 0xaf, 0xf8,
+};
+
+unsigned char NIST_TEST_DATA_XTS_E5[] = {
+ 0x3e, 0x2e, 0x26, 0x9d, 0x78, 0x3a, 0x2b, 0x29,
+ 0xe8, 0x73, 0xd6, 0x73, 0x47, 0x9f, 0x51, 0x16,
+ 0x73, 0x4f, 0xe0, 0x3e, 0xe3, 0x29, 0x65, 0xed,
+ 0xc4, 0x79, 0x35, 0xc0, 0xea, 0x99, 0xa0, 0x64,
+ 0xbd, 0x44, 0x4b, 0xec, 0x12, 0x5b, 0x2c, 0x78,
+ 0x9d, 0xb9, 0xde, 0x6d, 0x18, 0x35, 0x92, 0x05,
+ 0x3b, 0x48, 0xa8, 0x77, 0xa9, 0x5a, 0xc2, 0x55,
+ 0x9c, 0x3d, 0xdf, 0xc7, 0xb4, 0xdb, 0x99, 0x07,
+};
+
+unsigned char NIST_TEST_RESULT_XTS_E5[] = {
+ 0x4c, 0x70, 0xbd, 0xbb, 0x77, 0x30, 0x2b, 0x7f,
+ 0x1f, 0xdd, 0xca, 0x50, 0xdc, 0x70, 0x73, 0x1e,
+ 0x00, 0x8a, 0x26, 0x55, 0xd2, 0x2a, 0xd0, 0x20,
+ 0x0c, 0x11, 0x1f, 0xd3, 0x2a, 0x67, 0x5a, 0x7e,
+ 0x09, 0x97, 0x11, 0x43, 0x6f, 0x98, 0xd2, 0x1c,
+ 0x72, 0x77, 0x2e, 0x0d, 0xd7, 0x67, 0x2f, 0xf5,
+ 0xfd, 0x00, 0xdd, 0xcb, 0xe1, 0x1e, 0xb9, 0x7e,
+ 0x69, 0x87, 0x83, 0xbf, 0xa4, 0x05, 0x46, 0xe3,
+};
+
+void dump_array(unsigned char *ptr, unsigned int size)
+{
+ unsigned char *ptr_end;
+ unsigned char *h;
+ int i = 1;
+
+ h = ptr;
+ ptr_end = ptr + size;
+ while (h < (unsigned char *)ptr_end) {
+ printf("0x%02x ",(unsigned char ) *h);
+ h++;
+ if (i == 8) {
+ printf("\n");
+ i = 1;
+ } else {
+ ++i;
+ }
+ }
+ printf("\n");
+}
+
+void dump_xts_data(unsigned char *tweak, unsigned int tweak_length,
+ unsigned char *key, unsigned int key_length,
+ unsigned char *input_data, unsigned int data_length,
+ unsigned char *output_data)
+{
+ printf("TWEAK \n");
+ dump_array(tweak, tweak_length);
+ printf("Key \n");
+ dump_array(key, key_length);
+ printf("Input Data\n");
+ dump_array(input_data, data_length);
+ printf("Output Data\n");
+ dump_array(output_data, data_length);
+}
+
+void get_sizes(unsigned int *data_length, unsigned int *tweak_length,
+ unsigned int *key_length, unsigned int iteration)
+{
+ switch (iteration) {
+ case 1:
+ *data_length = sizeof(NIST_TEST_DATA_XTS_E1);
+ *tweak_length = sizeof(NIST_TWEAK_XTS_E1);
+ *key_length = sizeof(NIST_KEY_XTS_E1);
+ break;
+ case 2:
+ *data_length = sizeof(NIST_TEST_DATA_XTS_E2);
+ *tweak_length = sizeof(NIST_TWEAK_XTS_E2);
+ *key_length = sizeof(NIST_KEY_XTS_E2);
+ break;
+ case 3:
+ *data_length = sizeof(NIST_TEST_DATA_XTS_E3);
+ *tweak_length = sizeof(NIST_TWEAK_XTS_E3);
+ *key_length = sizeof(NIST_KEY_XTS_E3);
+ break;
+ case 4:
+ *data_length = sizeof(NIST_TEST_DATA_XTS_E4);
+ *tweak_length = sizeof(NIST_TWEAK_XTS_E4);
+ *key_length = sizeof(NIST_KEY_XTS_E4);
+ break;
+ case 5:
+ *data_length = sizeof(NIST_TEST_DATA_XTS_E5);
+ *tweak_length = sizeof(NIST_TWEAK_XTS_E5);
+ *key_length = sizeof(NIST_KEY_XTS_E5);
+ break;
+ }
+
+}
+
+void load_test_data(unsigned char *data, unsigned int data_length,
+ unsigned char *result,
+ unsigned char *tweak, unsigned char *expected_tweak,
+ unsigned int tweak_length,
+ unsigned char *key, unsigned int key_length,
+ unsigned int iteration)
+{
+ switch (iteration) {
+ case 1:
+ memcpy(data, NIST_TEST_DATA_XTS_E1, data_length);
+ memcpy(result, NIST_TEST_RESULT_XTS_E1, data_length);
+ memcpy(tweak, NIST_TWEAK_XTS_E1, tweak_length);
+ memcpy(expected_tweak, NIST_EXPECTED_TWEAK_XTS_E1,
+ tweak_length);
+ memcpy(key, NIST_KEY_XTS_E1, key_length);
+ break;
+ case 2:
+ memcpy(data, NIST_TEST_DATA_XTS_E2, data_length);
+ memcpy(result, NIST_TEST_RESULT_XTS_E2, data_length);
+ memcpy(tweak, NIST_TWEAK_XTS_E2, tweak_length);
+ memcpy(expected_tweak, NIST_EXPECTED_TWEAK_XTS_E2,
+ tweak_length);
+ memcpy(key, NIST_KEY_XTS_E2, key_length);
+ break;
+ case 3:
+ memcpy(data, NIST_TEST_DATA_XTS_E3, data_length);
+ memcpy(result, NIST_TEST_RESULT_XTS_E3, data_length);
+ memcpy(tweak, NIST_TWEAK_XTS_E3, tweak_length);
+ memcpy(expected_tweak, NIST_EXPECTED_TWEAK_XTS_E3,
+ tweak_length);
+ memcpy(key, NIST_KEY_XTS_E3, key_length);
+ break;
+ case 4:
+ memcpy(data, NIST_TEST_DATA_XTS_E4, data_length);
+ memcpy(result, NIST_TEST_RESULT_XTS_E4, data_length);
+ memcpy(tweak, NIST_TWEAK_XTS_E4, tweak_length);
+ memcpy(expected_tweak, NIST_EXPECTED_TWEAK_XTS_E4,
+ tweak_length);
+ memcpy(key, NIST_KEY_XTS_E4, key_length);
+ break;
+ case 5:
+ memcpy(data, NIST_TEST_DATA_XTS_E5, data_length);
+ memcpy(result, NIST_TEST_RESULT_XTS_E5, data_length);
+ memcpy(tweak, NIST_TWEAK_XTS_E5, tweak_length);
+ memcpy(expected_tweak, NIST_EXPECTED_TWEAK_XTS_E5,
+ tweak_length);
+ memcpy(key, NIST_KEY_XTS_E5, key_length);
+ break;
+ }
+
+}
+
+int kat_aes_xts(int iteration, int silent)
+{
+ unsigned int data_length;
+ unsigned int tweak_length;
+ unsigned int key_length;
+
+ get_sizes(&data_length, &tweak_length, &key_length, iteration);
+
+ unsigned char tweak[tweak_length];
+ unsigned char tmp_tweak[tweak_length];
+ unsigned char expected_tweak[tweak_length];
+ unsigned char key[key_length];
+ unsigned char input_data[data_length];
+ unsigned char encrypt[data_length];
+ unsigned char decrypt[data_length];
+ unsigned char result[data_length];
+
+ int rc = 0;
+ memset(encrypt, 0x00, data_length);
+ memset(decrypt, 0x00, data_length);
+
+ load_test_data(input_data, data_length, result, tweak, expected_tweak,
+ tweak_length, key, key_length, iteration);
+ memcpy(tmp_tweak, tweak, tweak_length);
+
+ if (!silent) {
+ printf("Test Parameters for iteration = %i\n", iteration);
+ printf("key length = %i, data length = %i, tweak length = %i,",
+ key_length, data_length, tweak_length);
+ }
+ rc = ica_aes_xts(input_data, encrypt, data_length,
+ key, key+(key_length/2), (key_length/2),
+ tmp_tweak, 1);
+ if (rc) {
+ printf("ica_aes_xts encrypt failed with rc = %i\n", rc);
+ dump_xts_data(tweak, tweak_length, key, key_length, input_data,
+ data_length, encrypt);
+ }
+ if (!silent && !rc) {
+ printf("Encrypt:\n");
+ dump_xts_data(tweak, tweak_length, key, key_length, input_data,
+ data_length, encrypt);
+ }
+
+ if (memcmp(result, encrypt, data_length)) {
+ printf("Encryption Result does not match the known ciphertext!\n");
+ printf("Expected data:\n");
+ dump_array(result, data_length);
+ printf("Encryption Result:\n");
+ dump_array(encrypt, data_length);
+ rc++;
+ }
+
+ if (memcmp(expected_tweak, tmp_tweak, tweak_length)) {
+ printf("Update of TWEAK does not match the expected TWEAK!\n");
+ printf("Expected TWEAK:\n");
+ dump_array(expected_tweak, tweak_length);
+ printf("Updated TWEAK:\n");
+ dump_array(tmp_tweak, tweak_length);
+ printf("Original TWEAK:\n");
+ dump_array(tweak, tweak_length);
+ rc++;
+ }
+ if (rc) {
+ printf("AES XTS test exited after encryption\n");
+ return rc;
+ }
+
+ memcpy(tmp_tweak, tweak, tweak_length);
+ rc = ica_aes_xts(encrypt, decrypt, data_length,
+ key, key+(key_length/2), (key_length/2),
+ tmp_tweak, 0);
+ if (rc) {
+ printf("ica_aes_xts decrypt failed with rc = %i\n", rc);
+ dump_xts_data(tweak, tweak_length, key, key_length, encrypt,
+ data_length, decrypt);
+ return rc;
+ }
+
+
+ if (!silent && !rc) {
+ printf("Decrypt:\n");
+ dump_xts_data(tweak, tweak_length, key, key_length, encrypt,
+ data_length, decrypt);
+ }
+
+ if (memcmp(decrypt, input_data, data_length)) {
+ printf("Decryption Result does not match the original data!\n");
+ printf("Original data:\n");
+ dump_array(input_data, data_length);
+ printf("Decryption Result:\n");
+ dump_array(decrypt, data_length);
+ rc++;
+ }
+ return rc;
+}
+
+int load_random_test_data(unsigned char *data, unsigned int data_length,
+ unsigned char *iv, unsigned int iv_length,
+ unsigned char *key, unsigned int key_length)
+{
+ int rc;
+ rc = ica_random_number_generate(data_length, data);
+ if (rc) {
+ printf("ica_random_number_generate with rc = %i errnor = %i\n",
+ rc, errno);
+ return rc;
+ }
+ rc = ica_random_number_generate(iv_length, iv);
+ if (rc) {
+ printf("ica_random_number_generate with rc = %i errnor = %i\n",
+ rc, errno);
+ return rc;
+ }
+ rc = ica_random_number_generate(key_length, key);
+ if (rc) {
+ printf("ica_random_number_generate with rc = %i errnor = %i\n",
+ rc, errno);
+ return rc;
+ }
+ return rc;
+}
+
+int random_aes_xts(int iteration, int silent, unsigned int data_length)
+{
+ int i;
+ int rc = 0;
+ unsigned int iv_length = sizeof(ica_aes_vector_t);
+ unsigned int key_length = AES_KEY_LEN128 * 2;
+ unsigned char iv[iv_length];
+ unsigned char tmp_iv[iv_length];
+ unsigned char input_data[data_length];
+ unsigned char encrypt[data_length];
+ unsigned char decrypt[data_length];
+for (i = 1; i <= 2; i++) {
+
+ unsigned char key[key_length];
+
+ memset(encrypt, 0x00, data_length);
+ memset(decrypt, 0x00, data_length);
+
+ load_random_test_data(input_data, data_length, iv, iv_length, key,
+ key_length);
+ memcpy(tmp_iv, iv, iv_length);
+
+ if (!silent) {
+ printf("Test Parameters for iteration = %i\n", iteration);
+ printf("key length = %i, data length = %i, iv length = %i\n",
+ key_length, data_length, iv_length);
+ }
+ rc = ica_aes_xts(input_data, encrypt, data_length,
+ key, key+(key_length/2), (key_length/2),
+ tmp_iv, 1);
+ if (rc) {
+ printf("ica_aes_xts encrypt failed with rc = %i\n", rc);
+ dump_xts_data(iv, iv_length, key, key_length, input_data,
+ data_length, encrypt);
+ }
+ if (!silent && !rc) {
+ printf("Encrypt:\n");
+ dump_xts_data(iv, iv_length, key, key_length, input_data,
+ data_length, encrypt);
+ }
+
+ if (rc) {
+ printf("AES XTS test exited after encryption\n");
+ return rc;
+ }
+
+ memcpy(tmp_iv, iv, iv_length);
+
+ rc = ica_aes_xts(encrypt, decrypt, data_length,
+ key, key+(key_length/2), (key_length/2),
+ tmp_iv, 0);
+ if (rc) {
+ printf("ica_aes_xts decrypt failed with rc = %i\n", rc);
+ dump_xts_data(iv, iv_length, key, key_length, encrypt,
+ data_length, decrypt);
+ return rc;
+ }
+
+
+ if (!silent && !rc) {
+ printf("Decrypt:\n");
+ dump_xts_data(iv, iv_length, key, key_length, encrypt,
+ data_length, decrypt);
+ }
+
+ if (memcmp(decrypt, input_data, data_length)) {
+ printf("Decryption Result does not match the original data!\n");
+ printf("Original data:\n");
+ dump_array(input_data, data_length);
+ printf("Decryption Result:\n");
+ dump_array(decrypt, data_length);
+ rc++;
+ return rc;
+ }
+ key_length = AES_KEY_LEN256 * 2;
+}
+
+ return rc;
+}
+
+int main(int argc, char **argv)
+{
+ unsigned int silent = 0;
+ if (argc > 1) {
+ if (strstr(argv[1], "silent"))
+ silent = 1;
+ }
+ int rc = 0;
+ int error_count = 0;
+ int iteration;
+ unsigned int data_length = sizeof(ica_aes_vector_t);
+ for(iteration = 1; iteration <= NR_TESTS; iteration++) {
+ rc = kat_aes_xts(iteration, silent);
+ if (rc) {
+ printf("kat_aes_xts failed with rc = %i\n", rc);
+ error_count++;
+ }
+
+ }
+ for(iteration = 1; iteration <= NR_RANDOM_TESTS; iteration++) {
+ int silent = 1;
+ rc = random_aes_xts(iteration, silent, data_length);
+ if (rc) {
+ printf("random_aes_xts failed with rc = %i\n", rc);
+ error_count++;
+ goto out;
+ }
+ data_length += sizeof(ica_aes_vector_t) / 2;
+ }
+
+out:
+ if (error_count)
+ printf("%i testcases failed\n", error_count);
+ else
+ printf("All AES-XTS testcases finished successfully\n");
+
+ return rc;
+}
+
diff --git a/src/tests/libica_cbccs_test.c b/src/tests/libica_cbccs_test.c
new file mode 100644
index 0000000..741ad31
--- /dev/null
+++ b/src/tests/libica_cbccs_test.c
@@ -0,0 +1,575 @@
+/* This program is released under the Common Public License V1.0
+*
+* You should have received a copy of Common Public License V1.0 along with
+* with this program.
+*/
+
+/* (C) COPYRIGHT International Business Machines Corp. 2010 */
+#include <fcntl.h>
+#include <sys/errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+#include <unistd.h>
+#include "ica_api.h"
+#include <stdlib.h>
+#include <openssl/aes.h>
+
+/* CBC_CS data */
+unsigned char NIST_KEY[] = {
+ 0x63, 0x68, 0x69, 0x63, 0x6b, 0x65, 0x6e, 0x20,
+ 0x74, 0x65, 0x72, 0x69, 0x79, 0x61, 0x6b, 0x69
+};
+unsigned int key_size[6] = { 24, 24, 24, 32, 32, 32 };
+unsigned char key[6][256] = {
+ {
+ 0x63, 0x68, 0x69, 0x63, 0x6b, 0x65, 0x6e, 0x20,
+ 0x74, 0x65, 0x72, 0x69, 0x79, 0x61, 0x6b, 0x69,
+ 0x63, 0x68, 0x69, 0x63, 0x6b, 0x65, 0x6e, 0x20
+ },{
+ 0x63, 0x68, 0x69, 0x63, 0x6b, 0x65, 0x6e, 0x20,
+ 0x74, 0x65, 0x72, 0x69, 0x79, 0x61, 0x6b, 0x69,
+ 0x63, 0x68, 0x69, 0x63, 0x6b, 0x65, 0x6e, 0x20
+ },{
+ 0x63, 0x68, 0x69, 0x63, 0x6b, 0x65, 0x6e, 0x20,
+ 0x74, 0x65, 0x72, 0x69, 0x79, 0x61, 0x6b, 0x69,
+ 0x63, 0x68, 0x69, 0x63, 0x6b, 0x65, 0x6e, 0x20
+ },{
+ 0x63, 0x68, 0x69, 0x63, 0x6b, 0x65, 0x6e, 0x20,
+ 0x74, 0x65, 0x72, 0x69, 0x79, 0x61, 0x6b, 0x69,
+ 0x63, 0x68, 0x69, 0x63, 0x6b, 0x65, 0x6e, 0x20,
+ 0x74, 0x65, 0x72, 0x69, 0x79, 0x61, 0x6b, 0x69
+ },{
+ 0x63, 0x68, 0x69, 0x63, 0x6b, 0x65, 0x6e, 0x20,
+ 0x74, 0x65, 0x72, 0x69, 0x79, 0x61, 0x6b, 0x69,
+ 0x63, 0x68, 0x69, 0x63, 0x6b, 0x65, 0x6e, 0x20,
+ 0x74, 0x65, 0x72, 0x69, 0x79, 0x61, 0x6b, 0x69
+ },{
+ 0x63, 0x68, 0x69, 0x63, 0x6b, 0x65, 0x6e, 0x20,
+ 0x74, 0x65, 0x72, 0x69, 0x79, 0x61, 0x6b, 0x69,
+ 0x63, 0x68, 0x69, 0x63, 0x6b, 0x65, 0x6e, 0x20,
+ 0x74, 0x65, 0x72, 0x69, 0x79, 0x61, 0x6b, 0x69
+ }
+};
+
+unsigned char key_512[] = {
+ 0x63, 0x68, 0x69, 0x63, 0x6b, 0x65, 0x6e, 0x20,
+ 0x74, 0x65, 0x72, 0x69, 0x79, 0x61, 0x6b, 0x69,
+ 0x63, 0x68, 0x69, 0x63, 0x6b, 0x65, 0x6e, 0x20,
+ 0x74, 0x65, 0x72, 0x69, 0x79, 0x61, 0x6b, 0x69,
+ 0x63, 0x68, 0x69, 0x63, 0x6b, 0x65, 0x6e, 0x20,
+ 0x74, 0x65, 0x72, 0x69, 0x79, 0x61, 0x6b, 0x69
+};
+
+unsigned char NIST_IV[] = {
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+};
+
+unsigned int NIST_TEST_DATA_LENGTH[6] = { 17, 31, 32, 47, 48, 64 };
+unsigned char NIST_TEST_DATA[6][100] = {
+ { 0x49, 0x20, 0x77, 0x6f, 0x75, 0x6c, 0x64, 0x20,
+ 0x6c, 0x69, 0x6b, 0x65, 0x20, 0x74, 0x68, 0x65, 0x20
+ },{
+ 0x49, 0x20, 0x77, 0x6f, 0x75, 0x6c, 0x64, 0x20,
+ 0x6c, 0x69, 0x6b, 0x65, 0x20, 0x74, 0x68, 0x65,
+ 0x20, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c,
+ 0x20, 0x47, 0x61, 0x75, 0x27, 0x73, 0x20
+ },{
+ 0x49, 0x20, 0x77, 0x6f, 0x75, 0x6c, 0x64, 0x20,
+ 0x6c, 0x69, 0x6b, 0x65, 0x20, 0x74, 0x68, 0x65,
+ 0x20, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c,
+ 0x20, 0x47, 0x61, 0x75, 0x27, 0x73, 0x20, 0x43
+ },{
+ 0x49, 0x20, 0x77, 0x6f, 0x75, 0x6c, 0x64, 0x20,
+ 0x6c, 0x69, 0x6b, 0x65, 0x20, 0x74, 0x68, 0x65,
+ 0x20, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c,
+ 0x20, 0x47, 0x61, 0x75, 0x27, 0x73, 0x20, 0x43,
+ 0x68, 0x69, 0x63, 0x6b, 0x65, 0x6e, 0x2c, 0x20,
+ 0x70, 0x6c, 0x65, 0x61, 0x73, 0x65, 0x2c
+ },{
+ 0x49, 0x20, 0x77, 0x6f, 0x75, 0x6c, 0x64, 0x20,
+ 0x6c, 0x69, 0x6b, 0x65, 0x20, 0x74, 0x68, 0x65,
+ 0x20, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c,
+ 0x20, 0x47, 0x61, 0x75, 0x27, 0x73, 0x20, 0x43,
+ 0x68, 0x69, 0x63, 0x6b, 0x65, 0x6e, 0x2c, 0x20,
+ 0x70, 0x6c, 0x65, 0x61, 0x73, 0x65, 0x2c, 0x20
+ },{
+ 0x49, 0x20, 0x77, 0x6f, 0x75, 0x6c, 0x64, 0x20,
+ 0x6c, 0x69, 0x6b, 0x65, 0x20, 0x74, 0x68, 0x65,
+ 0x20, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c,
+ 0x20, 0x47, 0x61, 0x75, 0x27, 0x73, 0x20, 0x43,
+ 0x68, 0x69, 0x63, 0x6b, 0x65, 0x6e, 0x2c, 0x20,
+ 0x70, 0x6c, 0x65, 0x61, 0x73, 0x65, 0x2c, 0x20,
+ 0x61, 0x6e, 0x64, 0x20, 0x77, 0x6f, 0x6e, 0x74,
+ 0x6f, 0x6e, 0x20, 0x73, 0x6f, 0x75, 0x70, 0x2e
+ }
+};
+
+unsigned char NIST_TEST_RESULT[6][100] = {
+ {
+ 0xc6, 0x35, 0x35, 0x68, 0xf2, 0xbf, 0x8c, 0xb4,
+ 0xd8, 0xa5, 0x80, 0x36, 0x2d, 0xa7, 0xff, 0x7f, 0x97
+ },{
+ 0xfc, 0x00, 0x78, 0x3e, 0x0e, 0xfd, 0xb2, 0xc1,
+ 0xd4, 0x45, 0xd4, 0xc8, 0xef, 0xf7, 0xed, 0x22,
+ 0x97, 0x68, 0x72, 0x68, 0xd6, 0xec, 0xcc, 0xc0,
+ 0xc0, 0x7b, 0x25, 0xe2, 0x5e, 0xcf, 0xe5
+ },{
+ 0x39, 0x31, 0x25, 0x23, 0xa7, 0x86, 0x62, 0x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 0x8b, 0xbb, 0x96, 0xc4, 0xcd, 0xc0,
+ 0x3b, 0xc1, 0x03, 0xe1, 0xa1, 0x94, 0xbb, 0xd8
+ }
+};
+
+unsigned char NIST_NEXT_IV[6][16] = {
+ {
+ 0xc6, 0x35, 0x35, 0x68, 0xf2, 0xbf, 0x8c, 0xb4,
+ 0xd8, 0xa5, 0x80, 0x36, 0x2d, 0xa7, 0xff, 0x7f
+ },{
+ 0xfc, 0x00, 0x78, 0x3e, 0x0e, 0xfd, 0xb2, 0xc1,
+ 0xd4, 0x45, 0xd4, 0xc8, 0xef, 0xf7, 0xed, 0x22
+ },{
+ 0x39, 0x31, 0x25, 0x23, 0xa7, 0x86, 0x62, 0xd5,
+ 0xbe, 0x7f, 0xcb, 0xcc, 0x98, 0xeb, 0xf5, 0xa8
+ },{
+ 0xb3, 0xff, 0xfd, 0x94, 0x0c, 0x16, 0xa1, 0x8c,
+ 0x1b, 0x55, 0x49, 0xd2, 0xf8, 0x38, 0x02, 0x9e
+ },{
+ 0x9d, 0xad, 0x8b, 0xbb, 0x96, 0xc4, 0xcd, 0xc0,
+ 0x3b, 0xc1, 0x03, 0xe1, 0xa1, 0x94, 0xbb, 0xd8
+ },{
+ 0x48, 0x07, 0xef, 0xe8, 0x36, 0xee, 0x89, 0xa5,
+ 0x26, 0x73, 0x0d, 0xbc, 0x2f, 0x7b, 0xc8, 0x40
+ }
+};
+
+
+void dump_array(char *ptr, int size)
+{
+ char *ptr_end;
+ unsigned char *h;
+ int i = 1;
+
+ h = (unsigned char *)ptr;
+ ptr_end = ptr + size;
+ while (h < (unsigned char *)ptr_end) {
+ printf("0x%02x ",(unsigned char ) *h);
+ h++;
+ if ((i == 16) & (h <(unsigned char *)ptr_end)) {
+ printf("\n");
+ i = 1;
+ } else {
+ ++i;
+ }
+ }
+ printf("\n");
+}
+
+int compare_decrypt_result_with_expected_result(
+ unsigned char *, unsigned char *,
+ unsigned int, unsigned char *,
+ unsigned int, unsigned char *,
+ unsigned int, char *,
+ unsigned int);
+
+inline int compare_decrypt_result_with_expected_result(
+ unsigned char * decrypt_out,
+ unsigned char * expected_result,
+ unsigned int compare_length,
+ unsigned char * key,
+ unsigned int key_length,
+ unsigned char * iv,
+ unsigned int iv_size,
+ char * out_text,
+ unsigned int test_case_number)
+{
+ if (memcmp(decrypt_out, expected_result, compare_length) != 0) {
+ printf("This does NOT match the original data.\n");
+ printf("Test case number %i for %s with CBC_CS mode failed\n",
+ test_case_number, out_text) ;
+ printf("\nkey \n");
+ dump_array((char *) key, key_length);
+ printf("\nOriginal data:\n");
+ dump_array((char *) expected_result, compare_length);
+ printf("\ntmp iv\n");
+ dump_array((char *) iv, iv_size);
+ printf("\nExpected Result:\n");
+ dump_array((char *) expected_result, compare_length);
+ printf("\nDecrypted data:\n");
+ dump_array((char *) decrypt_out, compare_length);
+ return 1;
+ }
+ return 0;
+}
+
+
+int test_3des_new_api(unsigned int mode, unsigned int variant, int silent)
+{
+ /* Test 3des */
+ unsigned int iv_size = sizeof(ica_des_vector_t);
+ unsigned char iv[iv_size];
+ unsigned char tmp_iv[iv_size];
+ unsigned char enc_text[100] ,dec_text[100] ;
+ unsigned int number_of_testcases = 6;
+ int rc = 0, i = 0;
+
+ for (i = 0; i < number_of_testcases ; i++) {
+ memcpy(tmp_iv, NIST_IV, iv_size);
+ rc = ica_3des_cbc_cs(NIST_TEST_DATA[i], enc_text,
+ NIST_TEST_DATA_LENGTH[i], key[i],
+ tmp_iv, 1, variant);
+ if (rc) {
+ printf("key \n");
+ dump_array((char *) key[i], 8);
+ printf("\nOriginal data:\n");
+ dump_array((char *) NIST_TEST_DATA[i],
+ NIST_TEST_DATA_LENGTH[i]);
+ printf("\ntest iv\n");
+ dump_array((char *) tmp_iv, iv_size);
+ printf("\nica_3des_cbc_cs encrypt testcase %i failed with "
+ "errno %d (0x%x).\n", i, rc, rc);
+ return 1;
+ }
+ memcpy(tmp_iv, NIST_IV, iv_size);
+ memset(dec_text,0,NIST_TEST_DATA_LENGTH[i]);
+ rc = ica_3des_cbc_cs(enc_text, dec_text,
+ NIST_TEST_DATA_LENGTH[i], key[i],
+ tmp_iv, 0, variant);
+ if (rc) {
+ printf("key \n");
+ dump_array((char *) key[i], 8);
+ printf("\nOriginal data:\n");
+ dump_array((char *) NIST_TEST_DATA[i],
+ NIST_TEST_DATA_LENGTH[i]);
+ printf("\noriginal iv\n");
+ dump_array((char *) &iv, iv_size);
+ printf("\ntmp iv\n");
+ dump_array((char *) tmp_iv, iv_size);
+ printf("\nEncrypted data:\n");
+ dump_array((char *) enc_text, NIST_TEST_DATA_LENGTH[i]);
+ printf("\nDecrypted data:\n");
+ dump_array((char *) dec_text, NIST_TEST_DATA_LENGTH[i]);
+ printf("\nica_3des_cbc_cs decrypt testcase %i failed with "
+ "errno %d (0x%x).\n", i, rc, rc);
+ return 1;
+ }
+ if (compare_decrypt_result_with_expected_result(dec_text,
+ NIST_TEST_DATA[i], NIST_TEST_DATA_LENGTH[i],
+ key[i], 24, tmp_iv, iv_size,
+ (char *) "3DES", i))
+ return 1;
+ else {
+ if (!silent) {
+ printf("Test case number %i for 3DES with CBC_CS mode was "
+ "successful!\n", i);
+ }
+ }
+ }
+ return rc;
+}
+int test_des_new_api(unsigned int mode, unsigned int variant, int silent)
+{
+ /* Test des */
+ unsigned int iv_size = sizeof(ica_des_vector_t);
+ unsigned char iv[iv_size];
+ unsigned char tmp_iv[iv_size];
+ unsigned char enc_text[100] ,dec_text[100] ;
+ unsigned int number_of_testcases = 6;
+ int rc = 0, i = 0;
+
+ for (i = 0; i < number_of_testcases ; i++) {
+ memcpy(tmp_iv, NIST_IV, iv_size);
+ rc = ica_des_cbc_cs(NIST_TEST_DATA[i], enc_text,
+ NIST_TEST_DATA_LENGTH[i], key[i],
+ tmp_iv, 1, variant);
+ if (rc) {
+ printf("key \n");
+ dump_array((char *) key[i], 8);
+ printf("\nOriginal data:\n");
+ dump_array((char *) NIST_TEST_DATA[i],
+ NIST_TEST_DATA_LENGTH[i]);
+ printf("\ntest iv\n");
+ dump_array((char *) tmp_iv, iv_size);
+ printf("\nica_des_cbc_cs encrypt testcase %i failed with "
+ "errno %d (0x%x).\n", i, rc, rc);
+ return 1;
+ }
+ memcpy(tmp_iv, NIST_IV, iv_size);
+ memset(dec_text,0,NIST_TEST_DATA_LENGTH[i]);
+ rc = ica_des_cbc_cs(enc_text, dec_text,
+ NIST_TEST_DATA_LENGTH[i], key[i],
+ tmp_iv, 0, variant);
+ if (rc) {
+ printf("key \n");
+ dump_array((char *) key[i], 8);
+ printf("\nOriginal data:\n");
+ dump_array((char *) NIST_TEST_DATA[i],
+ NIST_TEST_DATA_LENGTH[i]);
+ printf("\noriginal iv\n");
+ dump_array((char *) &iv, iv_size);
+ printf("\ntmp iv\n");
+ dump_array((char *) tmp_iv, iv_size);
+ printf("\nEncrypted data:\n");
+ dump_array((char *) enc_text, NIST_TEST_DATA_LENGTH[i]);
+ printf("\nDecrypted data:\n");
+ dump_array((char *) dec_text, NIST_TEST_DATA_LENGTH[i]);
+ printf("\nica_des_cbc_cs decrypt testcase %i failed with "
+ "errno %d (0x%x).\n", i, rc, rc);
+ return 1;
+ }
+ if (compare_decrypt_result_with_expected_result(
+ dec_text, NIST_TEST_DATA[i],
+ NIST_TEST_DATA_LENGTH[i], key[i],
+ (sizeof(key[i]) / 8), tmp_iv, iv_size,
+ (char *) "DES", i))
+ return 1;
+ else {
+ if (!silent) {
+ printf("Test case number %i for DES with CBC_CS mode was "
+ "successful!\n", i);
+ }
+ }
+ }
+ return rc;
+}
+int test_aes_new_api(unsigned int mode, unsigned int variant, int silent)
+{
+ /* Test with 192 & 256 byte keys */
+ unsigned int iv_size = sizeof(ica_aes_vector_t);
+ unsigned char iv[iv_size];
+ unsigned char tmp_iv[iv_size];
+ char text[2][8] = {
+ { 0x41, 0x45, 0x53, 0x2d, 0x31, 0x39, 0x32, 0x00 },
+ { 0x41, 0x45, 0x53, 0x2d, 0x32, 0x35, 0x36, 0x00 }};
+ unsigned char enc_text[100] ,dec_text[100] ;
+ unsigned int number_of_testcases = 6;
+
+ int rc = 0, i = 0;
+
+ for (i = 0; i < number_of_testcases ; i++) {
+ memcpy(tmp_iv, NIST_IV, iv_size);
+ rc = ica_aes_cbc_cs(NIST_TEST_DATA[i], enc_text,
+ NIST_TEST_DATA_LENGTH[i], key[i],
+ key_size[i], tmp_iv, 1, variant);
+ if (rc) {
+ printf("key \n");
+ dump_array((char *) key[i], key_size[i]);
+ printf("\nOriginal data:\n");
+ dump_array((char *) NIST_TEST_DATA[i],
+ NIST_TEST_DATA_LENGTH[i]);
+ printf("\ntest iv\n");
+ dump_array((char *) tmp_iv, iv_size);
+ printf("\nica_aes_cbc_cs encrypt testcase %i failed with "
+ " errno %d (0x%x).\n", i, rc, rc);
+ return 1;
+ }
+ memcpy(tmp_iv, NIST_IV, iv_size);
+ memset(dec_text,0,NIST_TEST_DATA_LENGTH[i]);
+ rc = ica_aes_cbc_cs(enc_text, dec_text,
+ NIST_TEST_DATA_LENGTH[i], key[i],
+ key_size[i], tmp_iv, 0, variant);
+ if (rc) {
+ printf("key \n");
+ dump_array((char *) key[i], key_size[i]);
+ printf("\nOriginal data:\n");
+ dump_array((char *) NIST_TEST_DATA[i],
+ NIST_TEST_DATA_LENGTH[i]);
+ printf("\noriginal iv\n");
+ dump_array((char *) &iv, iv_size);
+ printf("\ntmp iv\n");
+ dump_array((char *) tmp_iv, iv_size);
+ printf("\nEncrypted data:\n");
+ dump_array((char *) enc_text, NIST_TEST_DATA_LENGTH[i]);
+ printf("\nDecrypted data:\n");
+ dump_array((char *) dec_text, NIST_TEST_DATA_LENGTH[i]);
+ printf("\nica_aes_cbc_cs decrypt testcase %i failed with "
+ "errno %d (0x%x).\n", i, rc, rc);
+ return 1;
+ }
+ if (compare_decrypt_result_with_expected_result(dec_text,
+ NIST_TEST_DATA[i], NIST_TEST_DATA_LENGTH[i],
+ key[i], key_size[i], tmp_iv, iv_size,
+ (i < 3) ? text[0] : text[1], i))
+ return 1;
+ else {
+ if (!silent) {
+ printf("Test case number %i for %s with CBC_CS mode was "
+ "successful!\n", i, (i < 3) ? text[0] : text[1]);
+ }
+ }
+ }
+ return rc;
+}
+
+int test_aes128_new_api(unsigned int mode, int silent)
+{
+ /* AES128 Known Answer Tests*/
+ unsigned int iv_size = sizeof(ica_aes_vector_t);
+ unsigned int key_size = AES_KEY_LEN128;
+ unsigned char iv[iv_size];
+ unsigned char tmp_iv[iv_size];
+ unsigned char key[key_size];
+ unsigned char enc_text[100] ,dec_text[100] ;
+ unsigned int number_of_testcases = 6;
+ int rc = 0, i = 0;
+
+ memcpy(key, NIST_KEY, sizeof(key));
+ for (i = 0; i < number_of_testcases ; i++) {
+ memcpy(tmp_iv, NIST_IV, iv_size);
+ rc = ica_aes_cbc_cs(NIST_TEST_DATA[i], enc_text,
+ NIST_TEST_DATA_LENGTH[i], key,
+ sizeof(key), tmp_iv, 1, ICA_CBCCS_VARIANT3);
+ if (rc) {
+ printf("key \n");
+ dump_array((char *) key, sizeof(key));
+ printf("\nOriginal data:\n");
+ dump_array((char *) NIST_TEST_DATA[i],
+ NIST_TEST_DATA_LENGTH[i]);
+ printf("\ntest iv\n");
+ dump_array((char *) tmp_iv, iv_size);
+ printf("\nica_aes_cbc_cs encrypt testcase %i failed with "
+ "errno %d (0x%x).\n", i, rc, rc);
+ return 1;
+ }
+
+ if (compare_decrypt_result_with_expected_result(enc_text,
+ NIST_TEST_RESULT[i], NIST_TEST_DATA_LENGTH[i],
+ key, sizeof(key), tmp_iv, iv_size,
+ (char *) "AES-128", i))
+ return 1;
+
+ if (compare_decrypt_result_with_expected_result(tmp_iv,
+ NIST_NEXT_IV[i], iv_size,
+ key, sizeof(key), tmp_iv, iv_size,
+ (char *) "AES-128", i))
+ return 1;
+
+ memcpy(tmp_iv, NIST_IV, iv_size);
+ memset(dec_text,0,NIST_TEST_DATA_LENGTH[i]);
+ rc = ica_aes_cbc_cs(enc_text, dec_text,
+ NIST_TEST_DATA_LENGTH[i], key, sizeof(key),
+ tmp_iv, 0, ICA_CBCCS_VARIANT3);
+ if (rc) {
+ printf("key \n");
+ dump_array((char *) key, sizeof(key));
+ printf("\nOriginal data:\n");
+ dump_array((char *) NIST_TEST_DATA[i],
+ NIST_TEST_DATA_LENGTH[i]);
+ printf("\noriginal iv\n");
+ dump_array((char *) &iv, iv_size);
+ printf("\ntmp iv\n");
+ dump_array((char *) tmp_iv, iv_size);
+ printf("\nkey\n");
+ dump_array((char *) key, sizeof(key));
+ printf("\nEncrypted data:\n");
+ dump_array((char *) enc_text, NIST_TEST_DATA_LENGTH[i]);
+ printf("\nDecrypted data:\n");
+ dump_array((char *) dec_text, NIST_TEST_DATA_LENGTH[i]);
+ printf("\nica_aes_cbc_cs decrypt testcase %i failed"
+ "with errno %d (0x%x).\n", i, rc, rc);
+ return 1;
+ }
+
+ if (compare_decrypt_result_with_expected_result(dec_text,
+ NIST_TEST_DATA[i], NIST_TEST_DATA_LENGTH[i],
+ key, sizeof(key), tmp_iv, iv_size,
+ (char *) "AES-128", i))
+ return 1;
+ else {
+ if (!silent) {
+ printf("Test case number %i for AES-128 with CBC_CS "
+ "mode was successful!\n", i);
+ }
+ }
+ }
+ return rc;
+}
+
+int main(int argc, char **argv)
+{
+ unsigned int mode;
+ unsigned int variant;
+ int rc, error_count;
+ unsigned int silent = 0;
+
+ if (argc > 1) {
+ if (strstr(argv[1], "silent"))
+ silent = 1;
+ }
+
+ mode = MODE_CBCCS;
+ rc = 0;
+ error_count = 0;
+
+ /* known answer tests for AES128 */
+ rc = test_aes128_new_api(mode, silent);
+ if (rc) {
+ error_count++;
+ printf("test_aes128_new_api for CBC_CS mode with AES-128 "
+ "failed \n");
+ return rc;
+ }
+
+ for (variant = ICA_CBCCS_VARIANT1;
+ variant <= ICA_CBCCS_VARIANT3;
+ variant++) {
+ if (!silent) {
+ printf("\n--- Test cycle with CBCCS variant %d ---\n", variant);
+ }
+ /* AES 192 & 256 test */
+ rc = test_aes_new_api(mode, variant, silent);
+ if (rc) {
+ error_count++;
+ printf("test_aes_new_api for CBC_CS mode with AES (192|256) "
+ "failed \n");
+ return rc;
+ }
+
+ /* DES tests */
+ rc = test_des_new_api(mode, variant, silent);
+ if (rc) {
+ error_count++;
+ printf("test_des_new_api for CBC_CS mode with DES "
+ "failed \n");
+ return rc;
+ }
+
+ /* 3DES tests */
+ rc = test_3des_new_api(mode, variant, silent);
+ if (rc) {
+ error_count++;
+ printf("test_des_new_api for CBC_CS mode with 3DES "
+ "failed \n");
+ return rc;
+ }
+ }
+
+ printf("All CBC-CS mode tests finished successfully\n");
+ return rc;
+}
+
diff --git a/src/tests/libica_ccm_test.c b/src/tests/libica_ccm_test.c
new file mode 100644
index 0000000..dc0b02c
--- /dev/null
+++ b/src/tests/libica_ccm_test.c
@@ -0,0 +1,225 @@
+/* This program is released under the Common Public License V1.0
+ *
+ * You should have received a copy of Common Public License V1.0 along with
+ * with this program.
+ */
+
+/* (C) COPYRIGHT International Business Machines Corp. 2011 */
+
+#include <fcntl.h>
+#include <sys/errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "ica_api.h"
+
+#define BYTE 8
+
+#define NUM_CCM_TESTS 4
+unsigned char input_data[1000000];
+unsigned char parameter_block[32];
+unsigned char *to = parameter_block;
+
+unsigned int key_length[4] = {16, 16, 16, 16};
+unsigned char key[4][16] = {
+{0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f },
+{0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f },
+{0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f },
+{0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f }};
+
+#define CASE3_ASSOC_LEN 256
+/* Number of bytes in string for case 3 */
+
+unsigned int assoc_data_length[4] = {8, 16, 20, 65536};
+unsigned char assoc_data[4][65536] = {
+{ 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07 },
+{ 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f },
+{ 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,
+ 0x10,0x11,0x12,0x13 }};
+unsigned int i = 0;
+unsigned char repeated_string[256] = {
+0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,
+0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,
+0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,
+0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f,
+0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,
+0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5a,0x5b,0x5c,0x5d,0x5e,0x5f,
+0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,0x6f,
+0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7a,0x7b,0x7c,0x7d,0x7e,0x7f,
+0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,
+0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f,
+0xa0,0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf,
+0xb0,0xb1,0xb2,0xb3,0xb4,0xb5,0xb6,0xb7,0xb8,0xb9,0xba,0xbb,0xbc,0xbd,0xbe,0xbf,
+0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf,
+0xd0,0xd1,0xd2,0xd3,0xd4,0xd5,0xd6,0xd7,0xd8,0xd9,0xda,0xdb,0xdc,0xdd,0xde,0xdf,
+0xe0,0xe1,0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,0xe9,0xea,0xeb,0xec,0xed,0xee,0xef,
+0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff};
+unsigned int payload_length[4] = {4, 16, 24, 32};
+unsigned char payload[4][32] = {
+{ 0x20,0x21,0x22,0x23 },
+{ 0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f},
+{ 0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,
+ 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37 },
+{ 0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f ,
+ 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f }};
+
+unsigned char payload_after_decrypt[4][32] = {
+{ 0x20,0x21,0x22,0x23 },
+{ 0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f},
+{ 0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,
+ 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37 },
+{ 0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f ,
+ 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f }};
+unsigned int nonce_length[4] = {7,8,12,13};
+unsigned char nonce[4][13] = {
+{ 0x10,0x11,0x12,0x13,0x14,0x15,0x16},
+{ 0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17},
+{ 0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1a,0x1b},
+{ 0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c}};
+
+unsigned int cbc_mac_length[4] = {4, 6, 8, 14};
+
+unsigned int cipher_text_length[4] = {8, 22, 32, 46};
+unsigned char cipher_text[4][46] = {
+{ 0x71,0x62,0x01,0x5b,0x4d,0xac,0x25,0x5d },
+{ 0xd2,0xa1,0xf0,0xe0,0x51,0xea,0x5f,0x62,0x08,0x1a,0x77,0x92,0x07,0x3d,0x59,0x3d,
+ 0x1f,0xc6,0x4f,0xbf,0xac,0xcd },
+{ 0xe3,0xb2,0x01,0xa9,0xf5,0xb7,0x1a,0x7a,0x9b,0x1c,0xea,0xec,0xcd,0x97,0xe7,0x0b,
+ 0x61,0x76,0xaa,0xd9,0xa4,0x42,0x8a,0xa5,0x48,0x43,0x92,0xfb,0xc1,0xb0,0x99,0x51},
+{0x69,0x91,0x5d,0xad,0x1e,0x84,0xc6,0x37,0x6a,0x68,0xc2,0x96,0x7e,0x4d,0xab,0x61,
+ 0x5a,0xe0,0xfd,0x1f,0xae,0xc4,0x4c,0xc4,0x84,0x82,0x85,0x29,0x46,0x3c,0xcf,0x72,
+ 0xb4,0xac,0x6b,0xec,0x93,0xe8,0x59,0x8e,0x7f,0x0d,0xad,0xbc,0xea,0x5b}
+};
+static void dump_array(unsigned char *ptr, unsigned int size)
+{
+ unsigned char *ptr_end;
+ unsigned char *h;
+ int i = 1, trunc = 0;
+ int maxsize = 2000;
+
+ puts("Dump:");
+
+ if (size > maxsize) {
+ trunc = size - maxsize;
+ size = maxsize;
+ }
+
+ h = ptr;
+ ptr_end = ptr + size;
+ while (h < ptr_end) {
+ printf("0x%02x ", *h);
+ h++;
+ if (i == 8) {
+ if (h != ptr_end)
+ printf("\n");
+ i = 1;
+ } else {
+ ++i;
+ }
+ }
+ printf("\n");
+ if (trunc > 0)
+ printf("... %d bytes not printed\n", trunc);
+}
+
+int api_ccm_test(int silent)
+{
+ unsigned char *out_data;
+
+ if (!silent) {
+ printf("Test of CCM api\n");
+ }
+ while ( i < 65536 ) { // init big assoc_data
+ memcpy(assoc_data[3] + i, repeated_string, 256);
+ i= i + 256;
+ }
+ int rc = 0;
+ for (i = 0; i < NUM_CCM_TESTS; i++) {
+ if (!silent) {
+ printf("\nOriginal data for test %d:\n", i);
+ }
+ if (!(out_data = malloc(cipher_text_length[i])))
+ return EINVAL;
+ memset(out_data, 0, cipher_text_length[i]);
+ rc = (ica_aes_ccm(payload[i], payload_length[i],
+ out_data,
+ cbc_mac_length[i],
+ assoc_data[i], assoc_data_length[i],
+ nonce[i], nonce_length[i],
+ key[i], key_length[i],
+ ICA_ENCRYPT));
+ if (rc) {
+ printf("icaccm encrypt failed with errno %d (0x%x).\n",
+ rc, rc);
+ return rc;
+ }
+ if (!silent) {
+ printf("\nOutput Cipher text for test %d:\n", i);
+ dump_array(out_data, cipher_text_length[i]);
+ printf("\nExpected Cipher Text for test %d:\n", i);
+ dump_array(cipher_text[i], cipher_text_length[i]);
+ }
+
+ if (memcmp(cipher_text[i], out_data, cipher_text_length[i]) != 0) {
+ printf("This does NOT match the known result.\n");
+ return 1;
+ }
+
+ if (!silent) {
+ printf("Yep, that's how it should be encrypted.\n");
+ }
+ // start decrypt / verify
+ memset(payload[i], 0, payload_length[i]);
+ rc = (ica_aes_ccm(out_data, payload_length[i],
+ cipher_text[i], cbc_mac_length[i],
+ assoc_data[i], assoc_data_length[i],
+ nonce[i], nonce_length[i],
+ key[i], key_length[i],
+ ICA_DECRYPT));
+ if (rc) {
+ printf("icaccm decrypt failed with errno %d (0x%x).\n",
+ rc,rc);
+ return rc;
+ }
+
+ if (!silent) {
+ printf("\nOutput payload for test %d:\n", i);
+ dump_array(out_data, payload_length[i]);
+ printf("\nExpected payload for test %d:\n", i);
+ dump_array(payload_after_decrypt[i], payload_length[i]);
+ }
+
+ if (memcmp(out_data, payload_after_decrypt[i],
+ payload_length[i]) == 0 ) {
+ if (!silent) {
+ printf("Yep, payload matches to original.\n");
+ }
+ } else {
+ printf("This does NOT match the known result.\n");
+ return 1;
+ }
+ free(out_data);
+ }
+ return 0;
+}
+
+int main(int argc, char **argv)
+{
+ int rc = 0;
+ int silent = 0;
+
+ if (argc > 1) {
+ if (strstr(argv[1], "silent"))
+ silent = 1;
+ }
+
+ rc = api_ccm_test(silent);
+ if (rc) {
+ printf("api_ccm_test failed with rc = %i\n", rc);
+ return rc;
+ }
+ printf("All AES-CCM mode tests finished successfully\n");
+ return 0;
+}
+
+
diff --git a/src/tests/libica_cmac_test.c b/src/tests/libica_cmac_test.c
new file mode 100644
index 0000000..82ec5a7
--- /dev/null
+++ b/src/tests/libica_cmac_test.c
@@ -0,0 +1,349 @@
+/* This program is released under the Common Public License V1.0
+ *
+ * You should have received a copy of Common Public License V1.0 along with
+ * with this program.
+ */
+
+/* Copyright IBM Corp. 2010, 2011 */
+#include <fcntl.h>
+#include <sys/errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "ica_api.h"
+
+#define BYTE 8
+
+#define NUM_TESTS 12
+
+unsigned int key_length[12] = {16, 16, 16, 16, 24, 24, 24, 24, 32, 32, 32,
+ 32};
+unsigned char key[12][32] = {{
+ 0x2b, 0x7e, 0x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, 0x81, 0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61,
+ 0x08, 0xd7, 0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4},{
+ 0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe, 0x2b, 0x73, 0xae,
+ 0xf0, 0x85, 0x7d, 0x77, 0x81, 0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61,
+ 0x08, 0xd7, 0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4},{
+ 0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe, 0x2b, 0x73, 0xae,
+ 0xf0, 0x85, 0x7d, 0x77, 0x81, 0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61,
+ 0x08, 0xd7, 0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4},{
+ 0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe, 0x2b, 0x73, 0xae,
+ 0xf0, 0x85, 0x7d, 0x77, 0x81, 0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61,
+ 0x08, 0xd7, 0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4}
+};
+
+unsigned char last_block[3][16] = {{
+ 0x7d, 0xf7, 0x6b, 0x0c, 0x1a, 0xb8, 0x99, 0xb3, 0x3e, 0x42, 0xf0,
+ 0x47, 0xb9, 0x1b, 0x54, 0x6f},{
+ 0x22, 0x45, 0x2d, 0x8e, 0x49, 0xa8, 0xa5, 0x93, 0x9f, 0x73, 0x21,
+ 0xce, 0xea, 0x6d, 0x51, 0x4b},{
+ 0xe5, 0x68, 0xf6, 0x81, 0x94, 0xcf, 0x76, 0xd6, 0x17, 0x4d, 0x4c,
+ 0xc0, 0x43, 0x10, 0xa8, 0x54}
+};
+
+unsigned long mlen[12] = { 0, 16, 40, 64, 0,16, 40, 64, 0, 16, 40, 64};
+unsigned char message[12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f, 0x45, 0x2e, 0x8f, 0x82, 0xbd, 0x4b, 0xf2,
+ 0x8d, 0x8c, 0x37, 0xc3, 0x5c},{
+ 0xaa, 0xf3, 0xd8, 0xf1, 0xde, 0x56, 0x40, 0xc2, 0x32, 0xf5, 0xb1,
+ 0x69, 0xb9, 0xc9, 0x11, 0xe6},{
+ 0xe1, 0x99, 0x21, 0x90, 0x54, 0x9f, 0x6e, 0xd5, 0x69, 0x6a, 0x2c,
+ 0x05, 0x6c, 0x31, 0x54, 0x10}
+};
+
+unsigned int ica_aes_cmac_chaining(unsigned char *, unsigned long,
+ unsigned char *, unsigned int,
+ unsigned char *, unsigned int,
+ unsigned int);
+
+unsigned int i = 0;
+
+void dump_array(unsigned char *ptr, unsigned int size)
+{
+ unsigned char *ptr_end;
+ unsigned char *h;
+ int i = 1, trunc = 0;
+ int maxsize = 2000;
+
+ puts("Dump:");
+
+ if (size > maxsize) {
+ trunc = size - maxsize;
+ size = maxsize;
+ }
+ h = ptr;
+ ptr_end = ptr + size;
+ while (h < ptr_end) {
+ printf("0x%02x ", *h);
+ h++;
+ if (i == 16) {
+ if (h != ptr_end)
+ printf("\n");
+ i = 1;
+ } else {
+ ++i;
+ }
+ }
+ printf("\n");
+ if (trunc > 0)
+ printf("... %d bytes not printed\n", trunc);
+}
+unsigned char *cmac;
+unsigned int cmac_length = 16;
+
+int api_cmac_test(int silent)
+{
+ if (!silent) {
+ printf("Test of CMAC api\n");
+ }
+ int rc = 0;
+ for (i = 0 ; i < NUM_TESTS; i++) {
+ if (!(cmac = malloc(cmac_length)))
+ return EINVAL;
+ memset(cmac, 0, cmac_length);
+ rc = (ica_aes_cmac(message[i], mlen[i],
+ cmac, cmac_length,
+ key[i], key_length[i],
+ ICA_ENCRYPT));
+ if (rc) {
+ printf("ica_aes_cmac generate failed with errno %d (0x%x)."
+ "\n",rc,rc);
+ return rc;
+ }
+ if (memcmp(cmac, expected_cmac[i], cmac_length) != 0) {
+ printf("This does NOT match the known result. "
+ "Testcase %i failed\n",i);
+ printf("\nOutput MAC for test %d:\n", i);
+ dump_array((unsigned char *)cmac, cmac_length);
+ printf("\nExpected MAC for test %d:\n", i);
+ dump_array((unsigned char *)expected_cmac[i], 16);
+ free(cmac);
+ return 1;
+ }
+ if (!silent) {
+ printf("Expected MAC has been generated.\n");
+ }
+ rc = (ica_aes_cmac(message[i], mlen[i],
+ cmac, cmac_length,
+ key[i], key_length[i],
+ ICA_DECRYPT));
+ if (rc) {
+ printf("ica_aes_cmac verify failed with errno %d (0x%x).\n",
+ rc, rc);
+ free(cmac);
+ return rc;
+ }
+ free(cmac);
+ if (! rc) {
+ if (!silent) {
+ printf("MAC was successful verified. testcase %i "
+ "succeeded\n",i);
+ }
+ }
+ else {
+ printf("MAC verification failed for testcase %i "
+ "with RC=%i\n",i,rc);
+ return rc;
+ }
+ }
+ return 0;
+}
+
+#define AES_BLOCK_SIZE 16
+
+inline unsigned int ica_aes_cmac_chaining(unsigned char *in,
+ unsigned long in_length,
+ unsigned char *cmac,
+ unsigned int cmac_length,
+ unsigned char *key,
+ unsigned int key_length,
+ unsigned int direction)
+{
+ unsigned char *last_block = NULL;
+ unsigned long tmp_length;
+ unsigned char tmp_iv[AES_BLOCK_SIZE];
+ unsigned int rc;
+
+ memset(tmp_iv, 0x00, AES_BLOCK_SIZE);
+
+ for (last_block = in, tmp_length = in_length;
+ tmp_length > (AES_BLOCK_SIZE);
+ last_block += AES_BLOCK_SIZE, tmp_length -= AES_BLOCK_SIZE) {
+ rc = ica_aes_cmac_intermediate(last_block, AES_BLOCK_SIZE,
+ key, key_length,
+ tmp_iv);
+ if (rc)
+ return rc;
+ }
+
+ return ica_aes_cmac_last(last_block, tmp_length,
+ cmac, cmac_length,
+ key, key_length,
+ tmp_iv,
+ direction);
+}
+
+int api_cmac_chaining_test(int silent)
+{
+ if (!silent) {
+ printf("Test of CMAC chaining api\n");
+ }
+ int rc = 0;
+ for (i = 0 ; i < NUM_TESTS; i++) {
+ if (!(cmac = malloc(cmac_length)))
+ return EINVAL;
+ memset(cmac, 0, cmac_length);
+ rc = ica_aes_cmac_chaining(message[i], mlen[i],
+ cmac, cmac_length,
+ key[i], key_length[i],
+ ICA_ENCRYPT);
+ if (rc) {
+ printf("ica_aes_cmac chaining generate failed with errno %d (0x%x)."
+ "\n",rc,rc);
+ return rc;
+ }
+ if (memcmp(cmac, expected_cmac[i], cmac_length) != 0) {
+ printf("This does NOT match the known result. "
+ "Testcase %i failed\n",i);
+ printf("\nOutput MAC for test %d:\n", i);
+ dump_array((unsigned char *)cmac, cmac_length);
+ printf("\nExpected MAC for test %d:\n", i);
+ dump_array((unsigned char *)expected_cmac[i], 16);
+ free(cmac);
+ return 1;
+ }
+ if (!silent) {
+ printf("Expected MAC has been generated.\n");
+ }
+ rc = ica_aes_cmac_chaining(message[i], mlen[i],
+ cmac, cmac_length,
+ key[i], key_length[i],
+ ICA_DECRYPT);
+ if (rc) {
+ printf("ica_aes_cmac verify failed with errno %d (0x%x).\n",
+ rc, rc);
+ free(cmac);
+ return rc;
+ }
+ free(cmac);
+ if (! rc ) {
+ if (!silent) {
+ printf("MAC was successful verified. testcase %i "
+ "succeeded\n",i);
+ }
+ }
+ else {
+ printf("MAC verification failed for testcase %i "
+ "with RC=%i\n",i,rc);
+ return rc;
+ }
+ }
+ return 0;
+}
+
+int main(int argc, char **argv)
+{
+ int rc = 0;
+ int silent = 0;
+
+ if (argc > 1) {
+ if (strstr(argv[1], "silent"))
+ silent = 1;
+ }
+
+ rc = api_cmac_test(silent);
+ if (rc) {
+ printf("api_cmac_test failed with rc = %i\n", rc);
+ return rc;
+ }
+
+ rc = api_cmac_chaining_test(silent);
+ if (rc) {
+ printf("api_cmac_test failed with rc = %i\n", rc);
+ return rc;
+ }
+
+ printf("All CMAC tests finished successfully\n");
+ return 0;
+}
diff --git a/src/tests/libica_des_cbc_test.c b/src/tests/libica_des_cbc_test.c
new file mode 100644
index 0000000..351a42f
--- /dev/null
+++ b/src/tests/libica_des_cbc_test.c
@@ -0,0 +1,335 @@
+/* This program is released under the Common Public License V1.0
+ *
+ * You should have received a copy of Common Public License V1.0 along with
+ * with this program.
+ */
+
+/* Copyright IBM Corp. 2010, 2011 */
+#include <fcntl.h>
+#include <sys/errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+#include <stdlib.h>
+#include "ica_api.h"
+
+#define NR_TESTS 1
+#define NR_RANDOM_TESTS 10000
+
+/* CBC data - 1 for DES128 */
+unsigned char NIST_KEY_CBC_E1[] = {
+ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+};
+
+unsigned char NIST_IV_CBC_E1[] = {
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+};
+
+unsigned char NIST_EXPECTED_IV_CBC_E1[] = {
+ 0x95, 0xf8, 0xa5, 0xe5, 0xdd, 0x31, 0xd9, 0x00,
+};
+
+unsigned char NIST_TEST_DATA_CBC_E1[] = {
+ 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+};
+
+unsigned char NIST_TEST_RESULT_CBC_E1[] = {
+ 0x95, 0xf8, 0xa5, 0xe5, 0xdd, 0x31, 0xd9, 0x00,
+};
+
+
+void dump_array(unsigned char *ptr, unsigned int size)
+{
+ unsigned char *ptr_end;
+ unsigned char *h;
+ int i = 1;
+
+ h = ptr;
+ ptr_end = ptr + size;
+ while (h < (unsigned char *)ptr_end) {
+ printf("0x%02x ",(unsigned char ) *h);
+ h++;
+ if (i == 8) {
+ printf("\n");
+ i = 1;
+ } else {
+ ++i;
+ }
+ }
+ printf("\n");
+}
+
+void dump_cbc_data(unsigned char *iv, unsigned int iv_length,
+ unsigned char *key, unsigned int key_length,
+ unsigned char *input_data, unsigned int data_length,
+ unsigned char *output_data)
+{
+ printf("IV \n");
+ dump_array(iv, iv_length);
+ printf("Key \n");
+ dump_array(key, key_length);
+ printf("Input Data\n");
+ dump_array(input_data, data_length);
+ printf("Output Data\n");
+ dump_array(output_data, data_length);
+}
+
+void get_sizes(unsigned int *data_length, unsigned int *iv_length,
+ unsigned int *key_length, unsigned int iteration)
+{
+ switch (iteration) {
+ case 1:
+ *data_length = sizeof(NIST_TEST_DATA_CBC_E1);
+ *iv_length = sizeof(NIST_IV_CBC_E1);
+ *key_length = sizeof(NIST_KEY_CBC_E1);
+ break;
+ }
+
+}
+
+void load_test_data(unsigned char *data, unsigned int data_length,
+ unsigned char *result,
+ unsigned char *iv, unsigned char *expected_iv,
+ unsigned int iv_length,
+ unsigned char *key, unsigned int key_length,
+ unsigned int iteration)
+{
+ switch (iteration) {
+ case 1:
+ memcpy(data, NIST_TEST_DATA_CBC_E1, data_length);
+ memcpy(result, NIST_TEST_RESULT_CBC_E1, data_length);
+ memcpy(iv, NIST_IV_CBC_E1, iv_length);
+ memcpy(expected_iv, NIST_EXPECTED_IV_CBC_E1, iv_length);
+ memcpy(key, NIST_KEY_CBC_E1, key_length);
+ break;
+ }
+
+}
+
+int kat_des_cbc(int iteration, int silent)
+{
+ unsigned int data_length;
+ unsigned int iv_length;
+ unsigned int key_length;
+
+ get_sizes(&data_length, &iv_length, &key_length, iteration);
+
+ if (!silent) {
+ printf("Test Parameters for iteration = %i\n", iteration);
+ printf("key length = %i, data length = %i, iv length = %i\n",
+ key_length, data_length, iv_length);
+ }
+ unsigned char iv[iv_length];
+ unsigned char tmp_iv[iv_length];
+ unsigned char expected_iv[iv_length];
+ unsigned char key[key_length];
+ unsigned char input_data[data_length];
+ unsigned char encrypt[data_length];
+ unsigned char decrypt[data_length];
+ unsigned char result[data_length];
+
+ int rc = 0;
+
+ load_test_data(input_data, data_length, result, iv, expected_iv,
+ iv_length, key, key_length, iteration);
+ memcpy(tmp_iv, iv, iv_length);
+
+ rc = ica_des_cbc(input_data, encrypt, data_length, key, tmp_iv, 1);
+ if (rc) {
+ printf("ica_des_cbc encrypt failed with rc = %i\n", rc);
+ dump_cbc_data(iv, iv_length, key, key_length, input_data,
+ data_length, encrypt);
+ }
+ if (!silent && !rc) {
+ printf("Encrypt:\n");
+ dump_cbc_data(iv, iv_length, key, key_length, input_data,
+ data_length, encrypt);
+ }
+
+ if (memcmp(result, encrypt, data_length)) {
+ printf("Encryption Result does not match the known ciphertext!\n");
+ printf("Expected data:\n");
+ dump_array(result, data_length);
+ printf("Encryption Result:\n");
+ dump_array(encrypt, data_length);
+ rc++;
+ }
+
+ if (memcmp(expected_iv, tmp_iv, iv_length)) {
+ printf("Update of IV does not match the expected IV!\n");
+ printf("Expected IV:\n");
+ dump_array(expected_iv, iv_length);
+ printf("Updated IV:\n");
+ dump_array(tmp_iv, iv_length);
+ printf("Original IV:\n");
+ dump_array(iv, iv_length);
+ rc++;
+ }
+ if (rc) {
+ printf("DES CBC test exited after encryption\n");
+ return rc;
+ }
+
+ memcpy(tmp_iv, iv, iv_length);
+ rc = ica_des_cbc(encrypt, decrypt, data_length, key, tmp_iv, 0);
+ if (rc) {
+ printf("ica_des_cbc decrypt failed with rc = %i\n", rc);
+ dump_cbc_data(iv, iv_length, key, key_length, encrypt,
+ data_length, decrypt);
+ return rc;
+ }
+
+
+ if (!silent && !rc) {
+ printf("Decrypt:\n");
+ dump_cbc_data(iv, iv_length, key, key_length, encrypt,
+ data_length, decrypt);
+ }
+
+ if (memcmp(decrypt, input_data, data_length)) {
+ printf("Decryption Result does not match the original data!\n");
+ printf("Original data:\n");
+ dump_array(input_data, data_length);
+ printf("Decryption Result:\n");
+ dump_array(decrypt, data_length);
+ rc++;
+ }
+ return rc;
+}
+
+int load_random_test_data(unsigned char *data, unsigned int data_length,
+ unsigned char *iv, unsigned int iv_length,
+ unsigned char *key, unsigned int key_length)
+{
+ int rc;
+ rc = ica_random_number_generate(data_length, data);
+ if (rc) {
+ printf("ica_random_number_generate with rc = %i errnor = %i\n",
+ rc, errno);
+ return rc;
+ }
+ rc = ica_random_number_generate(iv_length, iv);
+ if (rc) {
+ printf("ica_random_number_generate with rc = %i errnor = %i\n",
+ rc, errno);
+ return rc;
+ }
+ rc = ica_random_number_generate(key_length, key);
+ if (rc) {
+ printf("ica_random_number_generate with rc = %i errnor = %i\n",
+ rc, errno);
+ return rc;
+ }
+ return rc;
+}
+
+int random_des_cbc(int iteration, int silent, unsigned int data_length)
+{
+ unsigned int iv_length = sizeof(ica_des_vector_t);
+ unsigned int key_length = sizeof(ica_des_key_single_t);
+
+ unsigned char iv[iv_length];
+ unsigned char tmp_iv[iv_length];
+ unsigned char key[key_length];
+ unsigned char input_data[data_length];
+ unsigned char encrypt[data_length];
+ unsigned char decrypt[data_length];
+
+ int rc = 0;
+ memset(encrypt, 0x00, data_length);
+ memset(decrypt, 0x00, data_length);
+
+ load_random_test_data(input_data, data_length, iv, iv_length, key,
+ key_length);
+ memcpy(tmp_iv, iv, iv_length);
+
+ if (!silent) {
+ printf("Test Parameters for iteration = %i\n", iteration);
+ printf("key length = %i, data length = %i, iv length = %i\n",
+ key_length, data_length, iv_length);
+ }
+
+ rc = ica_des_cbc(input_data, encrypt, data_length, key, tmp_iv, 1);
+ if (rc) {
+ printf("ica_des_cbc encrypt failed with rc = %i\n", rc);
+ dump_cbc_data(iv, iv_length, key, key_length, input_data,
+ data_length, encrypt);
+ }
+ if (!silent && !rc) {
+ printf("Encrypt:\n");
+ dump_cbc_data(iv, iv_length, key, key_length, input_data,
+ data_length, encrypt);
+ }
+
+ if (rc) {
+ printf("DES CBC test exited after encryption\n");
+ return rc;
+ }
+
+ memcpy(tmp_iv, iv, iv_length);
+
+ rc = ica_des_cbc(encrypt, decrypt, data_length, key, tmp_iv, 0);
+ if (rc) {
+ printf("ica_des_cbc decrypt failed with rc = %i\n", rc);
+ dump_cbc_data(iv, iv_length, key, key_length, encrypt,
+ data_length, decrypt);
+ return rc;
+ }
+
+
+ if (!silent && !rc) {
+ printf("Decrypt:\n");
+ dump_cbc_data(iv, iv_length, key, key_length, encrypt,
+ data_length, decrypt);
+ }
+
+ if (memcmp(decrypt, input_data, data_length)) {
+ printf("Decryption Result does not match the original data!\n");
+ printf("Original data:\n");
+ dump_array(input_data, data_length);
+ printf("Decryption Result:\n");
+ dump_array(decrypt, data_length);
+ rc++;
+ }
+ return rc;
+}
+
+int main(int argc, char **argv)
+{
+ // Default mode is 0. ECB,CBC and CFQ tests will be performed.
+ unsigned int silent = 0;
+ if (argc > 1) {
+ if (strstr(argv[1], "silent"))
+ silent = 1;
+ }
+ int rc = 0;
+ int error_count = 0;
+ int iteration;
+ unsigned int data_length = sizeof(ica_des_vector_t);
+ for(iteration = 1; iteration <= NR_TESTS; iteration++) {
+ rc = kat_des_cbc(iteration, silent);
+ if (rc) {
+ printf("kat_des_cbc failed with rc = %i\n", rc);
+ error_count++;
+ }
+
+ }
+
+ for(iteration = 1; iteration <= NR_RANDOM_TESTS; iteration++) {
+ rc = random_des_cbc(iteration, silent, data_length);
+ if (rc) {
+ printf("random_des_cbc failed with rc = %i\n", rc);
+ error_count++;
+ goto out;
+ }
+ data_length += sizeof(ica_des_vector_t);
+ }
+out:
+ if (error_count)
+ printf("%i testcases failed\n", error_count);
+ else
+ printf("All DES-CBC testcases finished successfully\n");
+
+ return rc;
+}
+
diff --git a/src/tests/libica_des_cfb_test.c b/src/tests/libica_des_cfb_test.c
new file mode 100644
index 0000000..2087852
--- /dev/null
+++ b/src/tests/libica_des_cfb_test.c
@@ -0,0 +1,204 @@
+/* This program is released under the Common Public License V1.0
+ *
+ * You should have received a copy of Common Public License V1.0 along with
+ * with this program.
+ */
+
+/* Copyright IBM Corp. 2010, 2011 */
+#include <fcntl.h>
+#include <sys/errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+#include <stdlib.h>
+#include "ica_api.h"
+
+#define NR_TESTS 12
+#define NR_RANDOM_TESTS 1000
+
+void dump_array(unsigned char *ptr, unsigned int size)
+{
+ unsigned char *ptr_end;
+ unsigned char *h;
+ int i = 1;
+
+ h = ptr;
+ ptr_end = ptr + size;
+ while (h < (unsigned char *)ptr_end) {
+ printf("0x%02x ",(unsigned char ) *h);
+ h++;
+ if (i == 8) {
+ printf("\n");
+ i = 1;
+ } else {
+ ++i;
+ }
+ }
+ printf("\n");
+}
+
+void dump_cfb_data(unsigned char *iv, unsigned int iv_length,
+ unsigned char *key, unsigned int key_length,
+ unsigned char *input_data, unsigned int data_length,
+ unsigned char *output_data)
+{
+ printf("IV \n");
+ dump_array(iv, iv_length);
+ printf("Key \n");
+ dump_array(key, key_length);
+ printf("Input Data\n");
+ dump_array(input_data, data_length);
+ printf("Output Data\n");
+ dump_array(output_data, data_length);
+}
+
+int load_random_test_data(unsigned char *data, unsigned int data_length,
+ unsigned char *iv, unsigned int iv_length,
+ unsigned char *key, unsigned int key_length)
+{
+ int rc;
+ rc = ica_random_number_generate(data_length, data);
+ if (rc) {
+ printf("ica_random_number_generate with rc = %i errnor = %i\n",
+ rc, errno);
+ return rc;
+ }
+ rc = ica_random_number_generate(iv_length, iv);
+ if (rc) {
+ printf("ica_random_number_generate with rc = %i errnor = %i\n",
+ rc, errno);
+ return rc;
+ }
+ rc = ica_random_number_generate(key_length, key);
+ if (rc) {
+ printf("ica_random_number_generate with rc = %i errnor = %i\n",
+ rc, errno);
+ return rc;
+ }
+ return rc;
+}
+
+int random_des_cfb(int iteration, int silent, unsigned int data_length,
+ unsigned int lcfb)
+{
+ unsigned int iv_length = sizeof(ica_des_vector_t);
+ unsigned int key_length = sizeof(ica_des_key_single_t);
+
+ unsigned char iv[iv_length];
+ unsigned char tmp_iv[iv_length];
+ unsigned char key[key_length];
+ unsigned char input_data[data_length];
+ unsigned char encrypt[data_length];
+ unsigned char decrypt[data_length];
+
+ int rc = 0;
+ memset(encrypt, 0x00, data_length);
+ memset(decrypt, 0x00, data_length);
+
+ load_random_test_data(input_data, data_length, iv, iv_length, key,
+ key_length);
+ memcpy(tmp_iv, iv, iv_length);
+
+ if (!silent) {
+ printf("Test Parameters for iteration = %i\n", iteration);
+ printf("key length = %i, data length = %i, iv length = %i,"
+ " lcfb = %i\n", key_length, data_length, iv_length, lcfb);
+ }
+
+ rc = ica_des_cfb(input_data, encrypt, data_length, key, tmp_iv,
+ lcfb, 1);
+ if (rc) {
+ printf("ica_des_cfb encrypt failed with rc = %i\n", rc);
+ dump_cfb_data(iv, iv_length, key, key_length, input_data,
+ data_length, encrypt);
+ }
+ if (!silent && !rc) {
+ printf("Encrypt:\n");
+ dump_cfb_data(iv, iv_length, key, key_length, input_data,
+ data_length, encrypt);
+ }
+
+ if (rc) {
+ printf("DES OFB test exited after encryption\n");
+ return rc;
+ }
+
+ memcpy(tmp_iv, iv, iv_length);
+
+ rc = ica_des_cfb(encrypt, decrypt, data_length, key, tmp_iv,
+ lcfb, 0);
+ if (rc) {
+ printf("ica_des_cfb decrypt failed with rc = %i\n", rc);
+ dump_cfb_data(iv, iv_length, key, key_length, encrypt,
+ data_length, decrypt);
+ return rc;
+ }
+
+
+ if (!silent && !rc) {
+ printf("Decrypt:\n");
+ dump_cfb_data(iv, iv_length, key, key_length, encrypt,
+ data_length, decrypt);
+ }
+
+ if (memcmp(decrypt, input_data, data_length)) {
+ printf("Decryption Result does not match the original data!\n");
+ printf("Original data:\n");
+ dump_array(input_data, data_length);
+ printf("Decryption Result:\n");
+ dump_array(decrypt, data_length);
+ rc++;
+ }
+ return rc;
+}
+
+int main(int argc, char **argv)
+{
+ int rc = 0;
+ int error_count = 0;
+ int iteration;
+ unsigned int silent = 0;
+ unsigned int rdata;
+ unsigned int data_length = 1;
+ unsigned int lcfb = 1;
+ unsigned int j;
+
+ if (argc > 1) {
+ if (strstr(argv[1], "silent"))
+ silent = 1;
+ }
+
+ for(iteration = 1; iteration <= NR_RANDOM_TESTS; iteration++) {
+ for (j = 1; j <= 2; j++) {
+ if (!(data_length % lcfb)) {
+ rc = random_des_cfb(iteration, silent, data_length, lcfb);
+ if (rc) {
+ printf("random_des_cfb failed with rc = %i\n", rc);
+ error_count++;
+ }
+ }
+ switch (j) {
+ case 1:
+ lcfb = 1;
+ break;
+ case 2:
+ lcfb = 8;
+ break;
+ }
+ }
+ // add a value between 1 and 8 to data_length
+ if (ica_random_number_generate(sizeof(rdata), (unsigned char*) &rdata)) {
+ printf("ica_random_number_generate failed with errnor = %i\n",
+ errno);
+ exit(1);
+ }
+ data_length += (rdata % 8) + 1;
+ }
+ if (error_count)
+ printf("%i testcases failed\n", error_count);
+ else
+ printf("All DES-CFB testcases finished successfully\n");
+
+ return rc;
+}
+
diff --git a/src/tests/libica_des_ctr_test.c b/src/tests/libica_des_ctr_test.c
new file mode 100644
index 0000000..8180e7e
--- /dev/null
+++ b/src/tests/libica_des_ctr_test.c
@@ -0,0 +1,197 @@
+/* This program is released under the Common Public License V1.0
+ *
+ * You should have received a copy of Common Public License V1.0 along with
+ * with this program.
+ */
+
+/* Copyright IBM Corp. 2010, 2011 */
+#include <fcntl.h>
+#include <sys/errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+#include <stdlib.h>
+#include "ica_api.h"
+
+#define NR_RANDOM_TESTS 1000
+
+void dump_array(unsigned char *ptr, unsigned int size)
+{
+ unsigned char *ptr_end;
+ unsigned char *h;
+ int i = 1;
+
+ h = ptr;
+ ptr_end = ptr + size;
+ while (h < (unsigned char *)ptr_end) {
+ printf("0x%02x ",(unsigned char ) *h);
+ h++;
+ if (i == 8) {
+ printf("\n");
+ i = 1;
+ } else {
+ ++i;
+ }
+ }
+ printf("\n");
+}
+
+void dump_ctr_data(unsigned char *iv, unsigned int iv_length,
+ unsigned char *key, unsigned int key_length,
+ unsigned char *input_data, unsigned int data_length,
+ unsigned char *output_data)
+{
+ printf("IV \n");
+ dump_array(iv, iv_length);
+ printf("Key \n");
+ dump_array(key, key_length);
+ printf("Input Data\n");
+ dump_array(input_data, data_length);
+ printf("Output Data\n");
+ dump_array(output_data, data_length);
+}
+
+int random_des_ctr(int iteration, int silent, unsigned int data_length, unsigned int iv_length)
+{
+ unsigned int key_length = sizeof(ica_des_key_single_t);
+ if (data_length % sizeof(ica_des_vector_t))
+ iv_length = sizeof(ica_des_vector_t);
+
+ if (!silent) {
+ printf("Test Parameters for iteration = %i\n", iteration);
+ printf("key length = %i, data length = %i, iv length = %i\n",
+ key_length, data_length, iv_length);
+ }
+
+ unsigned char iv[iv_length];
+ unsigned char tmp_iv[iv_length];
+ unsigned char key[key_length];
+ unsigned char input_data[data_length];
+ unsigned char encrypt[data_length];
+ unsigned char decrypt[data_length];
+
+ int rc = 0;
+ rc = ica_random_number_generate(data_length, input_data);
+ if (rc) {
+ printf("random number generate returned rc = %i, errno = %i\n", rc, errno);
+ return rc;
+ }
+ rc = ica_random_number_generate(iv_length, iv);
+ if (rc) {
+ printf("random number generate returned rc = %i, errno = %i\n", rc, errno);
+ return rc;
+ }
+
+ rc = ica_random_number_generate(key_length, key);
+ if (rc) {
+ printf("random number generate returned rc = %i, errno = %i\n", rc, errno);
+ return rc;
+ }
+ memcpy(tmp_iv, iv, iv_length);
+
+ rc = ica_des_ctr(input_data, encrypt, data_length, key, tmp_iv,
+ 32,1);
+ if (rc) {
+ printf("ica_des_ctr encrypt failed with rc = %i\n", rc);
+ dump_ctr_data(iv, iv_length, key, key_length, input_data,
+ data_length, encrypt);
+ return rc;
+ }
+ if (!silent && !rc) {
+ printf("Encrypt:\n");
+ dump_ctr_data(iv, iv_length, key, key_length, input_data,
+ data_length, encrypt);
+ }
+
+ memcpy(tmp_iv, iv, iv_length);
+ rc = ica_des_ctr(encrypt, decrypt, data_length, key, tmp_iv,
+ 32, 0);
+ if (rc) {
+ printf("ica_des_ctr decrypt failed with rc = %i\n", rc);
+ dump_ctr_data(iv, iv_length, key, key_length, encrypt,
+ data_length, decrypt);
+ return rc;
+ }
+
+
+ if (!silent && !rc) {
+ printf("Decrypt:\n");
+ dump_ctr_data(iv, iv_length, key, key_length, encrypt,
+ data_length, decrypt);
+ }
+
+ if (memcmp(decrypt, input_data, data_length)) {
+ printf("Decryption Result does not match the original data!\n");
+ printf("Original data:\n");
+ dump_array(input_data, data_length);
+ printf("Decryption Result:\n");
+ dump_array(decrypt, data_length);
+ rc++;
+ }
+ return rc;
+}
+
+int main(int argc, char **argv)
+{
+ int rc = 0;
+ int error_count = 0;
+ int i = 0;
+ unsigned int silent = 0;
+ unsigned int endless = 0;
+ unsigned int rdata;
+ unsigned int data_length = 1;
+ unsigned int iv_length = sizeof(ica_des_key_single_t);
+
+ if (argc > 1) {
+ if (strstr(argv[1], "silent"))
+ silent = 1;
+ if (strstr(argv[1], "endless"))
+ endless = 1;
+ }
+
+ if (endless) {
+ silent = 1;
+ while (1) {
+ printf("i = %i\n",i);
+ rc = random_des_ctr(i, silent, 320, 320);
+ if (rc) {
+ printf("kat_des_ctr failed with rc = %i\n", rc);
+ return rc;
+ }
+ i++;
+ }
+ } else {
+ silent = 1;
+ for (i = 1; i < NR_RANDOM_TESTS; i++) {
+ rc = random_des_ctr(i, silent, data_length, iv_length);
+ if (rc) {
+ printf("random_des_ctr failed with rc = %i\n", rc);
+ error_count++;
+ }
+ if (!(data_length % sizeof(ica_des_key_single_t))) {
+ /* Always when the full block size is reached use a
+ * counter with the same size as the data */
+ rc = random_des_ctr(i, silent, data_length, data_length);
+ if (rc) {
+ printf("random_des_ctr failed with rc = %i\n", rc);
+ error_count++;
+ }
+ }
+ // add a value between 1 and 8 to data_length
+ if (ica_random_number_generate(sizeof(rdata), (unsigned char*) &rdata)) {
+ printf("ica_random_number_generate failed with errnor = %i\n",
+ errno);
+ exit(1);
+ }
+ data_length += (rdata % 8) + 1;
+ }
+ }
+
+ if (error_count)
+ printf("%i testcases failed\n", error_count);
+ else
+ printf("All DES-CTR testcases finished successfully\n");
+
+ return rc;
+}
+
diff --git a/src/tests/libica_des_ecb_test.c b/src/tests/libica_des_ecb_test.c
new file mode 100644
index 0000000..6ca81b6
--- /dev/null
+++ b/src/tests/libica_des_ecb_test.c
@@ -0,0 +1,164 @@
+/* This program is released under the Common Public License V1.0
+ *
+ * You should have received a copy of Common Public License V1.0 along with
+ * with this program.
+ */
+
+/* Copyright IBM Corp. 2010, 2011 */
+#include <fcntl.h>
+#include <sys/errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+#include <stdlib.h>
+#include "ica_api.h"
+
+#define NR_RANDOM_TESTS 10000
+
+void dump_array(unsigned char *ptr, unsigned int size)
+{
+ unsigned char *ptr_end;
+ unsigned char *h;
+ int i = 1;
+
+ h = ptr;
+ ptr_end = ptr + size;
+ while (h < (unsigned char *)ptr_end) {
+ printf("0x%02x ",(unsigned char ) *h);
+ h++;
+ if (i == 8) {
+ printf("\n");
+ i = 1;
+ } else {
+ ++i;
+ }
+ }
+ printf("\n");
+}
+
+void dump_ecb_data(unsigned char *key, unsigned int key_length,
+ unsigned char *input_data, unsigned int data_length,
+ unsigned char *output_data)
+{
+ printf("Key \n");
+ dump_array(key, key_length);
+ printf("Input Data\n");
+ dump_array(input_data, data_length);
+ printf("Output Data\n");
+ dump_array(output_data, data_length);
+}
+
+int load_random_test_data(unsigned char *data, unsigned int data_length,
+ unsigned char *key, unsigned int key_length)
+{
+ int rc;
+ rc = ica_random_number_generate(data_length, data);
+ if (rc) {
+ printf("ica_random_number_generate with rc = %i errnor = %i\n",
+ rc, errno);
+ return rc;
+ }
+ rc = ica_random_number_generate(key_length, key);
+ if (rc) {
+ printf("ica_random_number_generate with rc = %i errnor = %i\n",
+ rc, errno);
+ return rc;
+ }
+ return rc;
+}
+
+int random_des_ecb(int iteration, int silent, unsigned int data_length)
+{
+ int rc = 0;
+ unsigned int key_length = sizeof(ica_des_key_triple_t);
+ unsigned char input_data[data_length];
+ unsigned char encrypt[data_length];
+ unsigned char decrypt[data_length];
+ unsigned char key[key_length];
+
+ memset(encrypt, 0x00, data_length);
+ memset(decrypt, 0x00, data_length);
+
+ load_random_test_data(input_data, data_length, key, key_length);
+
+ if (!silent) {
+ printf("Test Parameters for iteration = %i\n", iteration);
+ printf("key length = %i, data length = %i\n", key_length, data_length);
+ }
+
+ rc = ica_des_ecb(input_data, encrypt, data_length, key, 1);
+ if (rc) {
+ printf("ica_des_ecb encrypt failed with rc = %i\n", rc);
+ dump_ecb_data(key, key_length, input_data, data_length,
+ encrypt);
+ }
+ if (!silent && !rc) {
+ printf("Encrypt:\n");
+ dump_ecb_data(key, key_length, input_data,
+ data_length, encrypt);
+ }
+
+ if (rc) {
+ printf("3DES ECB test exited after encryption\n");
+ return rc;
+ }
+
+ rc = ica_des_ecb(encrypt, decrypt, data_length, key, 0);
+ if (rc) {
+ printf("ica_des_ecb decrypt failed with rc = %i\n", rc);
+ dump_ecb_data(key, key_length, encrypt,
+ data_length, decrypt);
+ return rc;
+ }
+
+
+ if (!silent && !rc) {
+ printf("Decrypt:\n");
+ dump_ecb_data(key, key_length, encrypt,
+ data_length, decrypt);
+ }
+
+ if (memcmp(decrypt, input_data, data_length)) {
+ printf("Decryption Result does not match the original data!\n");
+ printf("Original data:\n");
+ dump_array(input_data, data_length);
+ printf("Decryption Result:\n");
+ dump_array(decrypt, data_length);
+ rc++;
+ return rc;
+ }
+
+ return rc;
+}
+
+int main(int argc, char **argv)
+{
+ // Default mode is 0. ECB,ECB and CFQ tests will be performed.
+ unsigned int silent = 0;
+ if (argc > 1) {
+ if (strstr(argv[1], "silent"))
+ silent = 1;
+ }
+ int rc = 0;
+ int error_count = 0;
+ int iteration;
+ unsigned int data_length = sizeof(ica_des_vector_t);
+ for(iteration = 1; iteration <= NR_RANDOM_TESTS; iteration++) {
+ rc = random_des_ecb(iteration, silent, data_length);
+ if (rc) {
+ printf("random_des_ecb failed with rc = %i\n", rc);
+ error_count++;
+ goto out;
+ }
+ data_length += sizeof(ica_des_vector_t);
+ }
+
+out:
+ if (error_count)
+ printf("%i testcases failed\n", error_count);
+ else
+ printf("All DES-ECB testcases finished successfully\n");
+
+ return rc;
+}
+
diff --git a/src/tests/libica_des_ofb_test.c b/src/tests/libica_des_ofb_test.c
new file mode 100644
index 0000000..b63a53e
--- /dev/null
+++ b/src/tests/libica_des_ofb_test.c
@@ -0,0 +1,187 @@
+/* This program is released under the Common Public License V1.0
+ *
+ * You should have received a copy of Common Public License V1.0 along with
+ * with this program.
+ */
+
+/* Copyright IBM Corp. 2010, 2011 */
+#include <fcntl.h>
+#include <sys/errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+#include <stdlib.h>
+#include "ica_api.h"
+
+#define NR_RANDOM_TESTS 10000
+
+void dump_array(unsigned char *ptr, unsigned int size)
+{
+ unsigned char *ptr_end;
+ unsigned char *h;
+ int i = 1;
+
+ h = ptr;
+ ptr_end = ptr + size;
+ while (h < (unsigned char *)ptr_end) {
+ printf("0x%02x ",(unsigned char ) *h);
+ h++;
+ if (i == 8) {
+ printf("\n");
+ i = 1;
+ } else {
+ ++i;
+ }
+ }
+ printf("\n");
+}
+
+void dump_ofb_data(unsigned char *iv, unsigned int iv_length,
+ unsigned char *key, unsigned int key_length,
+ unsigned char *input_data, unsigned int data_length,
+ unsigned char *output_data)
+{
+ printf("IV \n");
+ dump_array(iv, iv_length);
+ printf("Key \n");
+ dump_array(key, key_length);
+ printf("Input Data\n");
+ dump_array(input_data, data_length);
+ printf("Output Data\n");
+ dump_array(output_data, data_length);
+}
+
+int load_random_test_data(unsigned char *data, unsigned int data_length,
+ unsigned char *iv, unsigned int iv_length,
+ unsigned char *key, unsigned int key_length)
+{
+ int rc;
+ rc = ica_random_number_generate(data_length, data);
+ if (rc) {
+ printf("ica_random_number_generate with rc = %i errnor = %i\n",
+ rc, errno);
+ return rc;
+ }
+ rc = ica_random_number_generate(iv_length, iv);
+ if (rc) {
+ printf("ica_random_number_generate with rc = %i errnor = %i\n",
+ rc, errno);
+ return rc;
+ }
+ rc = ica_random_number_generate(key_length, key);
+ if (rc) {
+ printf("ica_random_number_generate with rc = %i errnor = %i\n",
+ rc, errno);
+ return rc;
+ }
+ return rc;
+}
+
+int random_des_ofb(int iteration, int silent, unsigned int data_length)
+{
+ unsigned int iv_length = sizeof(ica_des_vector_t);
+ unsigned int key_length = sizeof(ica_des_key_single_t);
+
+ unsigned char iv[iv_length];
+ unsigned char tmp_iv[iv_length];
+ unsigned char key[key_length];
+ unsigned char input_data[data_length];
+ unsigned char encrypt[data_length];
+ unsigned char decrypt[data_length];
+
+ int rc = 0;
+ memset(encrypt, 0x00, data_length);
+ memset(decrypt, 0x00, data_length);
+
+ load_random_test_data(input_data, data_length, iv, iv_length, key,
+ key_length);
+ memcpy(tmp_iv, iv, iv_length);
+
+ if (!silent) {
+ printf("Test Parameters for iteration = %i\n", iteration);
+ printf("key length = %i, data length = %i, iv length = %i\n",
+ key_length, data_length, iv_length);
+ }
+
+ rc = ica_des_ofb(input_data, encrypt, data_length, key, tmp_iv, 1);
+ if (rc) {
+ printf("ica_des_ofb encrypt failed with rc = %i\n", rc);
+ dump_ofb_data(iv, iv_length, key, key_length, input_data,
+ data_length, encrypt);
+ }
+ if (!silent && !rc) {
+ printf("Encrypt:\n");
+ dump_ofb_data(iv, iv_length, key, key_length, input_data,
+ data_length, encrypt);
+ }
+
+ if (rc) {
+ printf("DES OFB test exited after encryption\n");
+ return rc;
+ }
+
+ memcpy(tmp_iv, iv, iv_length);
+
+ rc = ica_des_ofb(encrypt, decrypt, data_length, key, tmp_iv, 0);
+ if (rc) {
+ printf("ica_des_ofb decrypt failed with rc = %i\n", rc);
+ dump_ofb_data(iv, iv_length, key, key_length, encrypt,
+ data_length, decrypt);
+ return rc;
+ }
+
+
+ if (!silent && !rc) {
+ printf("Decrypt:\n");
+ dump_ofb_data(iv, iv_length, key, key_length, encrypt,
+ data_length, decrypt);
+ }
+
+ if (memcmp(decrypt, input_data, data_length)) {
+ printf("Decryption Result does not match the original data!\n");
+ printf("Original data:\n");
+ dump_array(input_data, data_length);
+ printf("Decryption Result:\n");
+ dump_array(decrypt, data_length);
+ rc++;
+ }
+ return rc;
+}
+
+int main(int argc, char **argv)
+{
+ unsigned int silent = 0;
+
+ if (argc > 1) {
+ if (strstr(argv[1], "silent"))
+ silent = 1;
+ }
+ int rc = 0;
+ int error_count = 0;
+ int iteration;
+ unsigned int rdata;
+ unsigned int data_length = 1;
+ for(iteration = 1; iteration <= NR_RANDOM_TESTS; iteration++) {
+ rc = random_des_ofb(iteration, silent, data_length);
+ if (rc) {
+ printf("random_des_ofb failed with rc = %i\n", rc);
+ error_count++;
+ goto out;
+ }
+ // add a value between 1 and 8 to data_length
+ if (ica_random_number_generate(sizeof(rdata), (unsigned char*) &rdata)) {
+ printf("ica_random_number_generate failed with errnor = %i\n",
+ errno);
+ exit(1);
+ }
+ data_length += (rdata % 8) + 1;
+ }
+out:
+ if (error_count)
+ printf("%i testcases failed\n", error_count);
+ else
+ printf("All DES-OFB testcases finished successfully\n");
+
+ return rc;
+}
+
diff --git a/src/tests/libica_des_test.c b/src/tests/libica_des_test.c
new file mode 100644
index 0000000..37734a1
--- /dev/null
+++ b/src/tests/libica_des_test.c
@@ -0,0 +1,159 @@
+/* This program is released under the Common Public License V1.0
+ *
+ * You should have received a copy of Common Public License V1.0 along with
+ * with this program.
+ */
+
+/* Copyright IBM Corp. 2001, 2009, 2011 */
+#include <fcntl.h>
+#include <sys/errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+#include <stdlib.h>
+#include "ica_api.h"
+
+const int cipher_buf_length = 8;
+
+unsigned char NIST_KEY1[] =
+ { 0x7c, 0xa1, 0x10, 0x45, 0x4a, 0x1a, 0x6e, 0x57 };
+
+unsigned char NIST_TEST_DATA[] =
+ { 0x01, 0xa1, 0xd6, 0xd0, 0x39, 0x77, 0x67, 0x42 };
+
+unsigned char NIST_TEST_RESULT[] =
+ { 0x69, 0x0f, 0x5b, 0x0d, 0x9a, 0x26, 0x93, 0x9b };
+
+int silent = 1;
+
+void dump_array(unsigned char *ptr, unsigned int size)
+{
+ unsigned char *ptr_end;
+ unsigned char *h;
+ int i = 1;
+
+ h = ptr;
+ ptr_end = ptr + size;
+ while (h < (unsigned char *)ptr_end) {
+ printf("0x%02x ",(unsigned char ) *h);
+ h++;
+ if (i == 8) {
+ printf("\n");
+ i = 1;
+ } else {
+ ++i;
+ }
+ }
+ printf("\n");
+}
+
+int test_des_new_api(int mode)
+{
+ ica_des_vector_t iv;
+ ica_des_key_single_t key;
+ int rc = 0;
+ unsigned char dec_text[sizeof NIST_TEST_DATA],
+ enc_text[sizeof NIST_TEST_DATA];
+
+ bzero(dec_text, sizeof dec_text);
+ bzero(enc_text, sizeof enc_text);
+ bzero(iv, sizeof iv);
+ bcopy(NIST_KEY1, key, sizeof NIST_KEY1);
+
+ rc = ica_des_encrypt(mode, sizeof NIST_TEST_DATA, NIST_TEST_DATA, &iv,
+ &key, enc_text);
+ if (rc) {
+ printf("\nOriginal data:\n");
+ dump_array(NIST_TEST_DATA, sizeof NIST_TEST_DATA);
+ printf("ica_des_encrypt failed with errno %d (0x%x).\n", rc, rc);
+ printf("\nEncrypted data:\n");
+ dump_array(enc_text, sizeof enc_text);
+ return rc;
+ }
+
+ if (memcmp(enc_text, NIST_TEST_RESULT, sizeof NIST_TEST_RESULT) != 0) {
+ printf("This does NOT match the known result.\n");
+ return -1;
+ } else {
+ printf("Yep, it's what it should be.\n");
+ }
+
+ bzero(iv, sizeof iv);
+ rc = ica_des_decrypt(mode, sizeof enc_text, enc_text, &iv, &key,
+ dec_text);
+ if (rc) {
+ printf("\nOriginal data:\n");
+ dump_array(NIST_TEST_DATA, sizeof NIST_TEST_DATA);
+ printf("ica_des_encrypt failed with errno %d (0x%x).\n", rc, rc);
+ printf("\nEncrypted data:\n");
+ dump_array(enc_text, sizeof enc_text);
+ printf("\nDecrypted data:\n");
+ dump_array(dec_text, sizeof dec_text);
+ printf("ica_des_decrypt failed with errno %d (0x%x).\n", rc, rc);
+ return rc;
+ }
+
+ if (memcmp(dec_text, NIST_TEST_DATA, sizeof NIST_TEST_DATA) != 0) {
+ printf("\nOriginal data:\n");
+ dump_array(NIST_TEST_DATA, sizeof NIST_TEST_DATA);
+ printf("ica_des_encrypt failed with errno %d (0x%x).\n", rc, rc);
+ printf("\nEncrypted data:\n");
+ dump_array(enc_text, sizeof enc_text);
+ printf("\nDecrypted data:\n");
+ dump_array(dec_text, sizeof dec_text);
+ printf("This does NOT match the original data.\n");
+ return -1;
+ } else {
+ printf("Successful!\n");
+ }
+
+ return 0;
+}
+
+int main(int argc, char **argv)
+{
+ // Default mode is 0. ECB and CBC tests will be performed.
+ unsigned int mode = 0;
+ if (argc > 1) {
+ if (strstr(argv[1], "ecb"))
+ mode = MODE_ECB;
+ if (strstr(argv[1], "cbc"))
+ mode = MODE_CBC;
+ printf("mode = %i \n", mode);
+ }
+ if (mode != 0 && mode != MODE_ECB && mode != MODE_CBC) {
+ printf("Usage: %s [ ecb | cbc ]\n", argv[0]);
+ return -1;
+ }
+ int rc = 0;
+ int error_count = 0;
+ if (!mode) {
+ /* This is the standard loop that will perform all testcases */
+ mode = 2;
+ while (mode) {
+ rc = test_des_new_api(mode);
+ if (rc) {
+ error_count++;
+ printf ("test_des_new_api mode = %i failed \n", mode);
+ }
+ else
+ printf ("test_des_new_api mode = %i finished successfully \n", mode);
+
+ mode--;
+ }
+ if (error_count)
+ printf("%i testcases failed\n", error_count);
+ else
+ printf("All testcases finished successfully\n");
+ } else {
+ /* Perform only either in ECB or CBC mode */
+ silent = 0;
+ rc = test_des_new_api(mode);
+ if (rc)
+ printf ("test_des_new_api mode = %i failed \n", mode);
+ else
+ printf ("test_des_new_api mode = %i finished successfully \n", mode);
+ }
+ return rc;
+}
+
diff --git a/src/tests/libica_get_functionlist.c b/src/tests/libica_get_functionlist.c
new file mode 100644
index 0000000..7d080b9
--- /dev/null
+++ b/src/tests/libica_get_functionlist.c
@@ -0,0 +1,76 @@
+/* This program is released under the Common Public License V1.0
+ *
+ * You should have received a copy of Common Public License V1.0 along with
+ * with this program.
+ */
+
+/* Copyright IBM Corp. 2010, 2013 */
+
+/*
+ * Test program for libica API call ica_get_version().
+ *
+ * Test 1: invalid input.
+ * Test 2: Valid input.
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include "ica_api.h"
+#include <string.h>
+
+int main(int argc, char **argv)
+{
+ libica_func_list_element* libica_func_list;
+ int rc, x;
+ int failed = 0;
+ unsigned int count;
+ unsigned int silent = 0;
+
+ if (argc > 1) {
+ if (strstr(argv[1], "silent"))
+ silent = 1;
+ }
+ //========== Test#1 good case ============
+ if (!silent) {
+ printf("Testing libica API ica_get_functionlist().\n");
+ }
+ rc = ica_get_functionlist(NULL, &count);
+ if (rc) {
+ printf("ica_get_functionlist failed with rc=%02x\n", rc);
+ return -1;
+ }
+ if (!silent) {
+ printf("Retrieved number of elements: %d\n", count);
+ }
+
+ libica_func_list = malloc(sizeof(libica_func_list_element) * count);
+ rc = ica_get_functionlist(libica_func_list, &count);
+ if (rc) {
+ printf("Retrieving function list failed with rc=%02x\n", rc);
+ failed++;
+ }
+ else {
+ if (!silent) {
+ for (x=0; x<count; x++) {
+ printf("ID: %d Flags: %d Property: %d\n",
+ libica_func_list[x].mech_mode_id,
+ libica_func_list[x].flags, libica_func_list[x].property);
+ }
+ }
+ }
+
+ //========== Test#2 bad parameter ============
+ rc = ica_get_functionlist(NULL, NULL);
+ if (rc != EINVAL) {
+ printf("Operation failed: Expected: %d Actual: %d\n", EINVAL, rc);
+ failed++;
+ }
+
+ if (failed) {
+ printf("Testcases failed!\n");
+ return 1;
+ } else {
+ printf("All ica_get_functionlist tests completed sucessfully\n");
+ return 0;
+ }
+}
diff --git a/src/tests/libica_get_version.c b/src/tests/libica_get_version.c
new file mode 100644
index 0000000..e49eee7
--- /dev/null
+++ b/src/tests/libica_get_version.c
@@ -0,0 +1,71 @@
+/* This program is released under the Common Public License V1.0
+ *
+ * You should have received a copy of Common Public License V1.0 along with
+ * with this program.
+ */
+
+/* Copyright IBM Corp. 2010, 2011 */
+
+/*
+ * Test program for libica API call ica_get_version().
+ *
+ * Test 1: invalid input.
+ * Test 2: Valid input.
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include "ica_api.h"
+#include <string.h>
+
+int main(int argc, char **argv)
+{
+ libica_version_info version_info;
+ int rc;
+ int failed = 0;
+ unsigned int silent = 0;
+
+ if (argc > 1) {
+ if (strstr(argv[1], "silent"))
+ silent = 1;
+ }
+
+ if (!silent) {
+ printf("Testing libica API ica_get_version() w/ invalid input (NULL).\n");
+ }
+ rc = ica_get_version(NULL);
+ if (rc == EINVAL) {
+ if (!silent) {
+ printf("Test successful\n");
+ }
+ }
+ else {
+ printf("Test failed: rc=%x, expected: %x \n", rc, EINVAL);
+ failed++;
+ }
+
+ if (!silent) {
+ printf("Testing libica API ica_get_version_() w/ valid input.\n");
+ }
+ rc = ica_get_version(&version_info);
+ if (rc == 0) {
+ if (!silent) {
+ printf("Test successful\n");
+ printf("Major_version:%d, minor_version %d, fixpack_version %d\n",
+ version_info.major_version, version_info.minor_version,
+ version_info.fixpack_version);
+ }
+ }
+ else {
+ printf("Test failed rc=%d, expected: %d \n", rc, 0);
+ failed++;
+ }
+
+ if (failed) {
+ printf("Failed ica_get_version tests: %d\n", failed);
+ return 1;
+ } else {
+ printf("All ica_get_version tests completed sucessfully\n");
+ return 0;
+ }
+}
diff --git a/src/tests/libica_keygen_test.c b/src/tests/libica_keygen_test.c
new file mode 100644
index 0000000..3355d50
--- /dev/null
+++ b/src/tests/libica_keygen_test.c
@@ -0,0 +1,295 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <string.h>
+#include "ica_api.h"
+#include <sys/time.h>
+
+#define ZERO_PADDING 8
+
+#define BITSTOBYTES(bits) (((bits)+7)/8)
+#define EXPO_TYPE_3 3
+#define EXPO_TYPE_65537 65537
+#define EXPO_TYPE_R 1
+
+/* print error report after function return */
+static void print_error_report(unsigned int rc_sv, int errno_sv,
+ const char *func_name);
+/* print bytes in hex */
+static void dump_array(const char *array, int size);
+
+extern int errno;
+
+int main(int argc, char **argv)
+{
+ unsigned int rc = 0, rc_test = 0, expo_type = 0, key_bit_length = 0;
+ unsigned int silent = 0;
+ struct timeval start,end;
+
+ if(argc < 3){
+ printf( "usage: %s <key_bit_length> (57..4096) <exponent_type> "
+ "(3, 65537 or r [random])\n", argv[0]);
+ return EXIT_FAILURE;
+ }
+
+ if((0 == (key_bit_length=strtol(argv[1], &argv[1], 10))) ||
+ ('\0' != *argv[1]) ){
+ printf( "error - possible values for"
+ " <key_bit_length> are integers"
+ " greater than 0.\n");
+ return EXIT_FAILURE;
+ }
+
+ if(BITSTOBYTES(key_bit_length) < 8){
+ printf("error - <key_bit_length> must be at least 57.\n");
+ return EXIT_FAILURE;
+ }
+
+ if(0 == (strcmp(argv[2], "3")))
+ expo_type = EXPO_TYPE_3;
+ else if(0 == (strcmp(argv[2], "65537")))
+ expo_type = EXPO_TYPE_65537;
+ else if(0 == (strcmp(argv[2], "r")))
+ expo_type = EXPO_TYPE_R;
+ else {
+ printf( "error - possible values for <exponent_type>"
+ " are 3, 65537 or r (random)\n");
+ return EXIT_FAILURE;
+ }
+
+ if (argv[3]) {
+ if (strstr(argv[3], "silent"))
+ silent = 1;
+ }
+
+ unsigned char ciphertext[BITSTOBYTES(key_bit_length)],
+ decrypted[BITSTOBYTES(key_bit_length)],
+ plaintext[BITSTOBYTES(key_bit_length)];
+ memset(ciphertext, 0, (size_t) BITSTOBYTES(key_bit_length));
+ memset(decrypted, 0, (size_t) BITSTOBYTES(key_bit_length));
+ memset(plaintext, 0, (size_t) BITSTOBYTES(key_bit_length));
+
+ unsigned char modexpo_public_e[BITSTOBYTES(key_bit_length)];
+ memset(modexpo_public_e, 0, (size_t) BITSTOBYTES(key_bit_length));
+ unsigned char modexpo_public_n[BITSTOBYTES(key_bit_length)];
+ memset(modexpo_public_n, 0, (size_t) BITSTOBYTES(key_bit_length));
+
+ unsigned char crt_private_p[BITSTOBYTES(key_bit_length) / 2 + 1 + ZERO_PADDING];
+ memset(crt_private_p, 0, (size_t) (BITSTOBYTES(key_bit_length) / 2 + 1 + ZERO_PADDING));
+ unsigned char crt_private_q[BITSTOBYTES(key_bit_length) / 2 + 1];
+ memset(crt_private_q, 0, (size_t) (BITSTOBYTES(key_bit_length) / 2 + 1));
+ unsigned char crt_private_dp[BITSTOBYTES(key_bit_length) / 2 + 1 + ZERO_PADDING];
+ memset(crt_private_dp, 0, (size_t) (BITSTOBYTES(key_bit_length) / 2 + 1 + ZERO_PADDING));
+ unsigned char crt_private_dq[BITSTOBYTES(key_bit_length) / 2 + 1];
+ memset(crt_private_dq, 0, (size_t) (BITSTOBYTES(key_bit_length) / 2 + 1));
+ unsigned char crt_private_inv_q[BITSTOBYTES(key_bit_length) / 2 + 1 + ZERO_PADDING];
+ memset(crt_private_inv_q, 0, (size_t) (BITSTOBYTES(key_bit_length) / 2 + 1 + ZERO_PADDING));
+
+ ica_rsa_key_mod_expo_t modexpo_public_key = {
+ .modulus = modexpo_public_n, .exponent = modexpo_public_e,
+ .key_length = BITSTOBYTES(key_bit_length)};
+
+ ica_rsa_key_crt_t crt_private_key = {
+ .p = crt_private_p, .q = crt_private_q, .dp = crt_private_dp,
+ .dq = crt_private_dq, .qInverse = crt_private_inv_q,
+ .key_length = BITSTOBYTES(key_bit_length)};
+
+ ica_adapter_handle_t adapter_handle = 0;
+
+ if (!silent) {
+ printf("[TEST RSA CRT]\n");
+ printf("generate random plaintext\t...");
+ }
+ if((rc = ica_random_number_generate(BITSTOBYTES(key_bit_length) ,plaintext)) != 0){
+ ++rc_test;
+ print_error_report(rc, errno, "ica_random_number_generate");
+ }
+
+ /* make sure that plaintext < modulus */
+ plaintext[0] = 0;
+
+ if (!silent) {
+ printf("plaintext:\n");
+ dump_array((char *)plaintext, BITSTOBYTES(key_bit_length));
+ }
+ if((rc = ica_open_adapter(&adapter_handle)) != 0){
+ ++rc_test;
+ print_error_report(rc, errno, "ica_open_adapter");
+ }
+
+ switch(expo_type){
+ case EXPO_TYPE_3:
+ *(unsigned long*)((unsigned char *)modexpo_public_key.exponent +
+ modexpo_public_key.key_length -
+ sizeof(unsigned long)) = (unsigned long) EXPO_TYPE_3;
+ break;
+ case EXPO_TYPE_65537:
+ *(unsigned long*)((unsigned char *)modexpo_public_key.exponent +
+ modexpo_public_key.key_length -
+ sizeof(unsigned long)) = (unsigned long) EXPO_TYPE_65537;
+ break;
+ case EXPO_TYPE_R:
+ /* .exponent element is not set here.
+ * if .exponent element is not set, ica_rsa_generate_mod_expo
+ * will randomly generate it */
+ break;
+ default:
+ printf( "error - unknown <exponent_type>\n");
+ return EXIT_FAILURE;
+ }
+
+ if (!silent) {
+ printf("generate keys\t\t\t...\n");
+ }
+
+ gettimeofday(&start, NULL);
+ if((rc = ica_rsa_key_generate_crt(adapter_handle,
+ key_bit_length,
+ &modexpo_public_key,
+ &crt_private_key)) != 0){
+ ++rc_test;
+ print_error_report(rc, errno, "ica_rsa_key_generate_crt");
+ }
+ gettimeofday(&end, NULL);
+ if (!silent)
+ printf("RSA CRT Key_gen with key length %d took: %06lu µs.\n",
+ key_bit_length, (end.tv_sec*1000000+end.tv_usec)-
+ (start.tv_sec*1000000+start.tv_usec));
+
+ if (!silent) {
+ printf("public key (e,n):\ne =\n");
+ dump_array((char *) (char *)modexpo_public_key.exponent,
+ BITSTOBYTES(key_bit_length));
+ printf("n =\n");
+ dump_array((char *) (char *)modexpo_public_key.modulus,
+ BITSTOBYTES(key_bit_length));
+ printf("private key (p,q,dp,dq,q^-1):\np =\n");
+ dump_array((char *) (char *) crt_private_key.p,
+ BITSTOBYTES(key_bit_length) / 2 + 1 + ZERO_PADDING);
+ printf("q =\n");
+ dump_array((char *) (char *)crt_private_key.q,
+ BITSTOBYTES(key_bit_length) / 2 + 1);
+ printf("dp =\n");
+ dump_array((char *) (char *)crt_private_key.dp,
+ BITSTOBYTES(key_bit_length) / 2 + 1 +ZERO_PADDING);
+ printf("dq =\n");
+ dump_array((char *) (char *)crt_private_key.dq,
+ BITSTOBYTES(key_bit_length) / 2 + 1);
+ printf("q^-1 =\n");
+ dump_array((char *) (char *)crt_private_key.qInverse,
+ BITSTOBYTES(key_bit_length) / 2 + 1 + ZERO_PADDING);
+ }
+
+ if (!silent) {
+ printf("encrypt...\n");
+ }
+ if((rc = ica_rsa_mod_expo(adapter_handle, plaintext, &modexpo_public_key,
+ ciphertext)) != 0){
+ ++rc_test;
+ print_error_report(rc, errno, "ica_rsa_mod_expo");
+ }
+
+ if (!silent) {
+ printf("ciphertext:\n");
+ dump_array((char *) ciphertext, BITSTOBYTES(key_bit_length));
+ }
+
+ if (!silent) {
+ printf("decrypt...\n");
+ }
+ if((rc = ica_rsa_crt(adapter_handle, ciphertext, &crt_private_key,
+ decrypted)) != 0){
+ ++rc_test;
+ print_error_report(rc, errno, "ica_rsa_crt");
+ }
+
+ if (!silent) {
+ printf("result:\n");
+ dump_array((char *) decrypted, BITSTOBYTES(key_bit_length));
+ }
+
+ if((rc = ica_close_adapter(adapter_handle)) != 0){
+ ++rc_test;
+ print_error_report(rc, errno, "ica_close_adapter");
+ }
+
+ if (!silent) {
+ printf("compare ciphertext to plaintext...\n");
+ }
+ if(memcmp(plaintext,ciphertext,BITSTOBYTES(key_bit_length)) == 0) {
+ printf("\t\tFAILED\nerror - ciphertext equals plaintext.\n");
+ ++rc_test;
+ }
+
+ if (!silent) {
+ printf("compare result to plaintext...\n");
+ }
+ if(memcmp(plaintext,decrypted,BITSTOBYTES(key_bit_length)) != 0) {
+ printf("\t\tFAILED\nerror - decryption result doesn't match plaintext.\n");
+ ++rc_test;
+ }
+
+ if(0 == rc_test)
+ printf("All Keygen tests passed successfully\n");
+ else
+ printf("Keygen tests failed: %u errors\n",rc_test);
+
+ return rc_test;
+}
+
+static void print_error_report(unsigned int rc_sv, int errno_sv,
+ const char *func_name)
+{
+ printf( "\t\tFAILED\nerror - %s returned %u: ", func_name, rc_sv);
+ switch (rc_sv) {
+ case EFAULT:
+ printf( "the message authentication failed.\n");
+ break;
+ case EINVAL:
+ printf( "incorrect parameter.\n");
+ break;
+ case EIO:
+ printf( "I/O error.\n");
+ break;
+ case EPERM:
+ printf(
+ "operation not permitted by hardware (CPACF).\n");
+ break;
+ case ENODEV:
+ printf( "no such device.\n");
+ break;
+ case ENOMEM:
+ printf( "not enough memory.\n");
+ break;
+ default:
+ printf(
+ "unknown return code. this shouldn't happen.\n");
+ }
+
+ printf( "\terrno ");
+ if (0 == errno_sv)
+ printf("not set.\n");
+ else
+ printf("set to %d: %s.\n",
+ errno_sv, strerror(errno_sv));
+}
+
+static void dump_array(const char *array, int size)
+{
+ const char *ptr;
+ int i = 1;
+
+ ptr = array;
+ while (ptr < array+size) {
+ printf("0x%02x ",(unsigned char ) *ptr);
+ ++ptr;
+ if (8 == i) {
+ printf("\n");
+ i = 1;
+ } else {
+ ++i;
+ }
+ }
+ if((i > 1) && (i <= 8))
+ printf("\n");
+}
diff --git a/src/tests/libica_rng_test.c b/src/tests/libica_rng_test.c
new file mode 100644
index 0000000..5c2a1b7
--- /dev/null
+++ b/src/tests/libica_rng_test.c
@@ -0,0 +1,73 @@
+/* This program is released under the Common Public License V1.0
+ *
+ * You should have received a copy of Common Public License V1.0 along with
+ * with this program.
+ */
+
+/* Copyright IBM Corp. 2010, 2011 */
+#include <fcntl.h>
+#include <sys/errno.h>
+#include <stdio.h>
+#include "ica_api.h"
+#include <string.h>
+
+unsigned char R[512];
+
+extern int errno;
+
+void dump_array(unsigned char *ptr, unsigned int size)
+{
+ unsigned char *ptr_end;
+ unsigned char *h;
+ int i = 1;
+
+ h = ptr;
+ ptr_end = ptr + size;
+ while (h < (unsigned char *)ptr_end) {
+ printf("0x%02x ",(unsigned char ) *h);
+ h++;
+ if (i == 8) {
+ printf("\n");
+ i = 1;
+ } else {
+ ++i;
+ }
+ }
+ printf("\n");
+}
+
+int main(int argc, char **argv)
+{
+ int rc;
+ ICA_ADAPTER_HANDLE adapter_handle;
+ unsigned int silent = 0;
+
+ if (argc > 1) {
+ if (strstr(argv[1], "silent"))
+ silent = 1;
+ }
+
+ rc = ica_open_adapter(&adapter_handle);
+ if (rc != 0) {
+ printf("ica_open_adapter failed and returned %d (0x%x).\n", rc, rc);
+ }
+
+ rc = ica_random_number_generate(sizeof R, R);
+ if (rc != 0) {
+ printf("ica_random_number_generate failed and returned %d (0x%x).\n", rc, rc);
+#ifdef __s390__
+ if (rc == ENODEV)
+ printf("The usual cause of this on zSeries is that the CPACF instruction is not available.\n");
+#endif
+ return -1;
+ }
+
+ if (!silent) {
+ dump_array(R, sizeof R);
+ printf("\nWell, does it look random?\n\n");
+ }
+
+ ica_close_adapter(adapter_handle);
+ printf("All DES-OFB testcases finished successfully\n");
+ return 0;
+}
diff --git a/src/tests/libica_rsa_key_check_test.c b/src/tests/libica_rsa_key_check_test.c
new file mode 100644
index 0000000..00e07f8
--- /dev/null
+++ b/src/tests/libica_rsa_key_check_test.c
@@ -0,0 +1,127 @@
+/* This program is released under the Common Public License V1.0
+ *
+ * You should have received a copy of Common Public License V1.0 along with
+ * with this program.
+ */
+
+/* Copyright IBM Corp. 2001, 2015 */
+
+#include <fcntl.h>
+#include <memory.h>
+#include <sys/errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <strings.h>
+#include "ica_api.h"
+#include <sys/time.h>
+
+#include "libica_rsa_test.h"
+
+extern int errno;
+
+void dump_array(unsigned char *ptr, unsigned int size)
+{
+ unsigned char *ptr_end;
+ unsigned char *h;
+ int i = 1;
+
+ h = ptr;
+ ptr_end = ptr + size;
+ while (h < (unsigned char *)ptr_end) {
+ printf("0x%02x ",(unsigned char ) *h);
+ h++;
+ if (i == 8) {
+ printf("\n");
+ i = 1;
+ } else {
+ ++i;
+ }
+ }
+ printf("\n");
+}
+
+int main(int argc, char **argv)
+{
+ int i, rc;
+ unsigned int silent = 0;
+ struct timeval start,end;
+
+ if (argc > 1) {
+ if (strstr(argv[1], "silent"))
+ silent = 1;
+ }
+
+ /* Iterate over keys (1024, 2048 and 4096 bit length */
+ /* privileged keys */
+ for (i = 0; i < 3; i++) {
+ if (!silent) {
+ printf("modulus size = %d\n", RSA_BYTE_LENGHT[i]);
+ }
+
+ ica_rsa_key_crt_t crt_key = {RSA_BYTE_LENGHT[i], p[i], q[i], dp[i],
+ dq[i], qinv[i]};
+
+ gettimeofday(&start, NULL);
+ rc = ica_rsa_crt_key_check(&crt_key);
+ if(rc)
+ printf("ica_rsa_crt_key_check failed!\n");
+
+ gettimeofday(&end, NULL);
+ if (!silent)
+ printf("RSA CRT Key check: key[%d], l=%d (keyset I): %06lu µs.\n",
+ i, RSA_BYTE_LENGHT[i], (end.tv_sec*1000000+end.tv_usec)-
+ (start.tv_sec*1000000+start.tv_usec));
+ }
+
+ /* unprivileged keys */
+ for (i = 3; i < 6; i++) {
+ if (!silent) {
+ printf("modulus size = %d\n", RSA_BYTE_LENGHT[i]);
+ }
+
+ ica_rsa_key_crt_t crt_key = {RSA_BYTE_LENGHT[i], p[i], q[i], dp[i],
+ dq[i], qinv[i]};
+
+ gettimeofday(&start, NULL);
+ rc = ica_rsa_crt_key_check(&crt_key);
+ if(!rc)
+ printf("ica_rsa_crt_key_check failed!\n");
+
+ gettimeofday(&end, NULL);
+ if (!silent)
+ printf("RSA CRT key check: key[%d], l=%d (keyset II): %06lu µs.\n",
+ i, RSA_BYTE_LENGHT[i], (end.tv_sec*1000000+end.tv_usec)-
+ (start.tv_sec*1000000+start.tv_usec));
+
+ if (!silent) {
+ printf("Result of recalculated key part (qInv)\n");
+ dump_array((unsigned char *)crt_key.qInverse, RSA_BYTE_LENGHT[i]/2);
+ printf("Result of expected key part (qInv)\n");
+ dump_array((unsigned char *)qinv[i-3], RSA_BYTE_LENGHT[i]/2);
+ }
+ if( memcmp(crt_key.qInverse, qinv[i-3], RSA_BYTE_LENGHT[i]/2) != 0) {
+ printf("Calculated 'qInv' do not match. Failure!\n");
+ return -1;
+ }
+ if( memcmp(crt_key.p, p[i-3], RSA_BYTE_LENGHT[i]/2 + 8) != 0) {
+ printf("Prime 'p' do not match. Failure!\n");
+ return -1;
+ }
+ if( memcmp(crt_key.q, q[i-3], RSA_BYTE_LENGHT[i]/2) != 0) {
+ printf("Prime 'q' do not match. Failure!\n");
+ return -1;
+ }
+ if( memcmp(crt_key.dp, dp[i-3], RSA_BYTE_LENGHT[i]/2 + 8) != 0) {
+ printf("Parameter 'dp' do not match. Failure!\n");
+ return -1;
+ }
+ if( memcmp(crt_key.dq, dq[i-3], RSA_BYTE_LENGHT[i]/2) != 0) {
+ printf("Parameter 'dq' do not match. Failure!\n");
+ return -1;
+ }
+
+ } // end loop
+
+ printf("All RSA KEY Check testcases finished successfully\n");
+ return 0;
+}
diff --git a/src/tests/libica_rsa_test.c b/src/tests/libica_rsa_test.c
new file mode 100644
index 0000000..194182d
--- /dev/null
+++ b/src/tests/libica_rsa_test.c
@@ -0,0 +1,150 @@
+/* This program is released under the Common Public License V1.0
+ *
+ * You should have received a copy of Common Public License V1.0 along with
+ * with this program.
+ */
+
+/* Copyright IBM Corp. 2001, 2015 */
+
+#include <fcntl.h>
+#include <memory.h>
+#include <sys/errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <strings.h>
+#include "ica_api.h"
+#include <sys/time.h>
+#include "libica_rsa_test.h"
+
+extern int errno;
+
+static int handle_ica_error(int rc, char *message)
+{
+ printf("Error in %s: ", message);
+ switch (rc) {
+ case 0:
+ printf("OK\n");
+ break;
+ case EINVAL:
+ printf("Incorrect parameter.\n");
+ break;
+ case EPERM:
+ printf("Operation not permitted by Hardware.\n");
+ break;
+ case EIO:
+ printf("I/O error.\n");
+ break;
+ default:
+ perror("");
+ }
+ return rc;
+}
+
+void dump_array(unsigned char *ptr, unsigned int size)
+{
+ unsigned char *ptr_end;
+ unsigned char *h;
+ int i = 1;
+
+ h = ptr;
+ ptr_end = ptr + size;
+ while (h < (unsigned char *)ptr_end) {
+ printf("0x%02x ",(unsigned char ) *h);
+ h++;
+ if (i == 8) {
+ printf("\n");
+ i = 1;
+ } else {
+ ++i;
+ }
+ }
+ printf("\n");
+}
+
+int main(int argc, char **argv)
+{
+ ica_adapter_handle_t adapter_handle;
+ unsigned char* my_result;
+ unsigned char* my_result2;
+ int i, rc;
+ unsigned int silent = 0;
+ struct timeval start,end;
+
+ if (argc > 1) {
+ if (strstr(argv[1], "silent"))
+ silent = 1;
+ }
+
+ rc = ica_open_adapter(&adapter_handle);
+ if (rc != 0) {
+ printf("ica_open_adapter failed and returned %d (0x%x).\n", rc, rc);
+ }
+
+ /* Iterate over key sizes (1024, 2048 and 4096) */
+ for (i = 0; i < 6; i++) {
+
+ /* encrypt with public key (ME) */
+ if (!silent) {
+ printf("modulus size = %d\n", RSA_BYTE_LENGHT[i]);
+ }
+
+ my_result = malloc(RESULT_LENGTH);
+ bzero(my_result, RESULT_LENGTH);
+
+ my_result2 = malloc(RESULT_LENGTH);
+ bzero(my_result2, RESULT_LENGTH);
+
+ ica_rsa_key_mod_expo_t mod_expo_key = {RSA_BYTE_LENGHT[i], n[i], e[i]};
+
+ rc = ica_rsa_mod_expo(adapter_handle, input_data,
+ &mod_expo_key, my_result);
+ if (rc)
+ exit(handle_ica_error(rc, "ica_rsa_key_mod_expo"));
+
+ if (!silent) {
+ printf("\n\n\n\n\n result of encrypt with public key\n");
+ dump_array((unsigned char *)my_result, RSA_BYTE_LENGHT[i]);
+ printf("Ciphertext \n");
+ dump_array(ciphertext[i],RSA_BYTE_LENGHT[i]);
+ }
+ if (memcmp(my_result,ciphertext[i],RSA_BYTE_LENGHT[i])){
+ printf("Ciphertext mismatch\n");
+ return -1;
+ }
+
+ /* decrypt with private key (CRT) */
+ ica_rsa_key_crt_t crt_key = {RSA_BYTE_LENGHT[i], p[i], q[i], dp[i],
+ dq[i], qinv[i]};
+
+ gettimeofday(&start, NULL);
+
+ rc = ica_rsa_crt(adapter_handle, ciphertext[i], &crt_key, my_result2);
+ if(rc)
+ exit(handle_ica_error(rc, "ica_rsa_crt"));
+
+ gettimeofday(&end, NULL);
+ if (!silent) {
+ printf("RSA decrypt with key[%d] (l=%d) took %06lu µs.\n", i,
+ RSA_BYTE_LENGHT[i], (end.tv_sec*1000000+end.tv_usec)-
+ (start.tv_sec*1000000+start.tv_usec));
+
+ printf("Result of decrypt\n");
+ dump_array((unsigned char *)my_result2, sizeof(input_data));
+ printf("original data\n");
+ dump_array(input_data, sizeof(input_data));
+ }
+ if (memcmp(input_data,my_result2,sizeof(input_data)) != 0) {
+ printf("Results do not match. Failure!\n");
+ return -1;
+ }
+
+ } // end loop
+
+ rc = ica_open_adapter(&adapter_handle);
+ if (rc != 0) {
+ printf("ica_close_adapter failed and returned %d (0x%x).\n", rc, rc);
+ }
+ printf("All RSA testcases finished successfully\n");
+ return 0;
+}
+
diff --git a/src/tests/libica_rsa_test.h b/src/tests/libica_rsa_test.h
new file mode 100644
index 0000000..f7e2d10
--- /dev/null
+++ b/src/tests/libica_rsa_test.h
@@ -0,0 +1,2175 @@
+/* This program is released under the Common Public License V1.0
+ *
+ * You should have received a copy of Common Public License V1.0 along with
+ * with this program.
+ */
+
+/* Copyright IBM Corp. 2001, 2015 */
+
+#define RESULT_LENGTH 4096
+
+int RSA_BYTE_LENGHT[] = {128, 256, 512, 128, 256, 512};
+
+unsigned char e[6][512] =
+ /* 1024,[p>q] */{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
+ /* 2048,[p>q] */ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
+ /* 4096,[p>q] */ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03},
+ /* 1024,[p<q] */ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
+ /* 2048,[p<q] */ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
+ /* 4096,[p<q] */ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03}};
+
+unsigned char n[6][512] =
+ /* 1024,[p>q] */{{0xec, 0x51, 0xab, 0xa1, 0xf8, 0x40, 0x2c, 0x08,
+ 0x2e, 0x24, 0x52, 0x2e, 0x3c, 0x51, 0x6d, 0x98,
+ 0xad, 0xee, 0xc7, 0x7d, 0x00, 0xaf, 0xe1, 0xa8,
+ 0x61, 0xda, 0x32, 0x97, 0xb4, 0x32, 0x97, 0xe3,
+ 0x52, 0xda, 0x28, 0x45, 0x55, 0xc6, 0xb2, 0x46,
+ 0x65, 0x1b, 0x02, 0xcb, 0xbe, 0xf4, 0x2c, 0x6b,
+ 0x2a, 0x5f, 0xe1, 0xdf, 0xe9, 0xe3, 0xbc, 0x47,
+ 0xb7, 0x38, 0xb5, 0xa2, 0x78, 0x9d, 0x15, 0xe2,
+ 0x59, 0x81, 0x77, 0x6b, 0x6b, 0x2e, 0xa9, 0xdb,
+ 0x13, 0x26, 0x9c, 0xca, 0x5e, 0x0a, 0x1f, 0x3c,
+ 0x50, 0x9d, 0xd6, 0x79, 0x59, 0x99, 0x50, 0xe5,
+ 0x68, 0x1a, 0x98, 0xca, 0x11, 0xce, 0x37, 0x63,
+ 0x58, 0x22, 0x40, 0x19, 0x29, 0x72, 0x4c, 0x41,
+ 0x89, 0x0b, 0x56, 0x9e, 0x3e, 0xd5, 0x6d, 0x75,
+ 0x9e, 0x3f, 0x8a, 0x50, 0xf1, 0x0a, 0x59, 0x4a,
+ 0xc3, 0x59, 0x4b, 0xf6, 0xbb, 0xc9, 0xa5, 0x93,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
+ /* 2048,[p>q] */ {0xdf, 0x27, 0x1f, 0xd2, 0x5f, 0x86, 0x44, 0x49,
+ 0x6b, 0x0c, 0x81, 0xbe, 0x4b, 0xd5, 0x02, 0x97,
+ 0xef, 0x09, 0x9b, 0x00, 0x2a, 0x6f, 0xd6, 0x77,
+ 0x27, 0xeb, 0x44, 0x9c, 0xea, 0x56, 0x6e, 0xd6,
+ 0xa3, 0x98, 0x1a, 0x71, 0x31, 0x2a, 0x14, 0x1c,
+ 0xab, 0xc9, 0x81, 0x5c, 0x12, 0x09, 0xe3, 0x20,
+ 0xa2, 0x5b, 0x32, 0x46, 0x4e, 0x99, 0x99, 0xf1,
+ 0x8c, 0xa1, 0x3a, 0x9f, 0xd3, 0x89, 0x25, 0x58,
+ 0xf9, 0xe0, 0xad, 0xef, 0xdd, 0x36, 0x50, 0xdd,
+ 0x23, 0xa3, 0xf0, 0x36, 0xd6, 0x0f, 0xe3, 0x98,
+ 0x84, 0x37, 0x06, 0xa4, 0x0b, 0x0b, 0x84, 0x62,
+ 0xc8, 0xbe, 0xe3, 0xbc, 0xe1, 0x2f, 0x1f, 0x28,
+ 0x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0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x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a5, 0x93,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 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, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
+ /* 4096,[p<q] */ {0xce, 0xb2, 0x27, 0xcb, 0xd8, 0x0c, 0xc7, 0xfc,
+ 0x52, 0xf5, 0xec, 0xfd, 0xcb, 0x87, 0xa8, 0xaa,
+ 0xba, 0xf3, 0x3b, 0xfd, 0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04, 0x16, 0xd9, 0xa6, 0x8b,
+ 0x90, 0x4a, 0x19, 0x6d, 0x64, 0xb7, 0x17, 0x67,
+ 0x53, 0xfa, 0x4e, 0x8d, 0xde, 0xa6, 0x94, 0x32,
+ 0x5d, 0xcf, 0x58, 0x3e, 0x90, 0xbb, 0x30, 0x19,
+ 0x96, 0x38, 0x95, 0xb6, 0xca, 0x2f, 0xfa, 0x22,
+ 0x81, 0x65, 0x3b, 0x3c, 0x95, 0x9e, 0x79, 0x75,
+ 0xe4, 0x93, 0x50, 0xf1, 0x88, 0x6b, 0xc1, 0x87,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
+ /* 2048,[p>q] */ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0xed, 0x10, 0x2a, 0xcd, 0xb2, 0x68, 0x71, 0x53,
+ 0x4d, 0x1c, 0x41, 0x4e, 0xca, 0xd9, 0xa4, 0xd7,
+ 0x32, 0xfe, 0x95, 0xb1, 0x0e, 0xea, 0x37, 0x0d,
+ 0xa6, 0x2f, 0x05, 0xde, 0x2c, 0x39, 0x3b, 0x1a,
+ 0x63, 0x33, 0x03, 0xea, 0x74, 0x1b, 0x6b, 0x32,
+ 0x69, 0xc9, 0x7f, 0x70, 0x4b, 0x35, 0x27, 0x02,
+ 0xc9, 0xae, 0x79, 0x92, 0x2f, 0x7b, 0xe8, 0xd1,
+ 0x0d, 0xb6, 0x7f, 0x02, 0x6a, 0x81, 0x45, 0xde,
+ 0x41, 0xb3, 0x0c, 0x0a, 0x42, 0xbf, 0x92, 0x3b,
+ 0xac, 0x5f, 0x75, 0x04, 0xc2, 0x48, 0x60, 0x4b,
+ 0x9f, 0xaa, 0x57, 0xed, 0x6b, 0x32, 0x46, 0xc6,
+ 0xba, 0x15, 0x8e, 0x36, 0xc6, 0x44, 0xf8, 0xb9,
+ 0x54, 0x8f, 0xcf, 0x4f, 0x07, 0xe0, 0x54, 0xa5,
+ 0x6f, 0x76, 0x86, 0x74, 0x05, 0x44, 0x40, 0xbc,
+ 0x0d, 0xcb, 0xbc, 0x9b, 0x52, 0x8f, 0x64, 0xa0,
+ 0x17, 0x06, 0xe0, 0x5b, 0x0b, 0x91, 0x10, 0x6f,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
+ /* 4096,[p>q] */ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x9c, 0x30, 0x60, 0xcf, 0xaa, 0xed, 0x64, 0xa0,
+ 0xe2, 0xa4, 0x24, 0x0d, 0x59, 0x5f, 0x1b, 0xda,
+ 0x92, 0x6e, 0xc1, 0xb6, 0x77, 0x25, 0x26, 0x93,
+ 0xbc, 0x00, 0xba, 0xc9, 0x1c, 0x22, 0xb4,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0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
+ /* 2048,[p<q] */ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x68, 0x27, 0x92, 0x4a, 0x85, 0xe8, 0x8b, 0x55,
+ 0xba, 0x00, 0xf8, 0x21, 0x91, 0x28, 0xbd, 0x37,
+ 0x24, 0xc6, 0xb7, 0xd1, 0xdf, 0xe5, 0x62, 0x9e,
+ 0xf1, 0x97, 0x92, 0x5f, 0xec, 0xaf, 0xf5, 0xed,
+ 0xb9, 0xcd, 0xf3,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xf0, 0x1f, 0x68, 0x9a, 0xc5,
+ 0x2b, 0xf3, 0x5a, 0xfc, 0x2c, 0xf5, 0xa7, 0xec,
+ 0xd9, 0xa2, 0xac, 0x49, 0xcc, 0x76, 0x9c, 0xd8,
+ 0x4c, 0x59, 0x5e, 0x38, 0xd2, 0x85, 0xd3, 0x3b,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 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, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
+ /* 4096,[p>q] */ {0x96, 0x91, 0xf7, 0x52, 0x11, 0xdc, 0x4a, 0x26,
+ 0xf8, 0x51, 0xa6, 0x1a, 0x75, 0xd1, 0xbe, 0x32,
+ 0xe9, 0x34, 0x39, 0x1f, 0xb3, 0x05, 0x58, 0x35,
+ 0xaa, 0x51, 0xf6, 0x53, 0x1e, 0xa5, 0x5f, 0x38,
+ 0x02, 0xa8, 0xdb, 0xa5, 0x58, 0xfc, 0x95, 0x21,
+ 0xa3, 0x6a, 0x1c, 0x4e, 0xd5, 0x64, 0x1a, 0x94,
+ 0xeb, 0xfb, 0xca, 0x56, 0x6e, 0xfc, 0xd7, 0xb1,
+ 0x82, 0x95, 0x8a, 0x8c, 0x17, 0xbd, 0x24, 0xd9,
+ 0xfd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c, 0xa8, 0x4f, 0xc6,
+ 0x05, 0xa7, 0x26, 0x91, 0xd6, 0xf7, 0x8b, 0x41,
+ 0xf3, 0x52, 0x08, 0x3d, 0x95, 0x6e, 0x70, 0xff},
+ /* 1024,[p<q] */ {0xa7, 0xcf, 0xa2, 0x18, 0x2c, 0xa9, 0xb4, 0xb9,
+ 0xf5, 0x9e, 0xc9, 0x04, 0x16, 0xd9, 0xa6, 0x8b,
+ 0x90, 0x4a, 0x19, 0x6d, 0x64, 0xb7, 0x17, 0x67,
+ 0x53, 0xfa, 0x4e, 0x8d, 0xde, 0xa6, 0x94, 0x32,
+ 0x5d, 0xcf, 0x58, 0x3e, 0x90, 0xbb, 0x30, 0x19,
+ 0x96, 0x38, 0x95, 0xb6, 0xca, 0x2f, 0xfa, 0x22,
+ 0x81, 0x65, 0x3b, 0x3c, 0x95, 0x9e, 0x79, 0x75,
+ 0xe4, 0x93, 0x50, 0xf1, 0x88, 0x6b, 0xc1, 0x87,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
+ /* 2048,[p<q] */ {0xed, 0x10, 0x2a, 0xcd, 0xb2, 0x68, 0x71, 0x53,
+ 0x4d, 0x1c, 0x41, 0x4e, 0xca, 0xd9, 0xa4, 0xd7,
+ 0x32, 0xfe, 0x95, 0xb1, 0x0e, 0xea, 0x37, 0x0d,
+ 0xa6, 0x2f, 0x05, 0xde, 0x2c, 0x39, 0x3b, 0x1a,
+ 0x63, 0x33, 0x03, 0xea, 0x74, 0x1b, 0x6b, 0x32,
+ 0x69, 0xc9, 0x7f, 0x70, 0x4b, 0x35, 0x27, 0x02,
+ 0xc9, 0xae, 0x79, 0x92, 0x2f, 0x7b, 0xe8, 0xd1,
+ 0x0d, 0xb6, 0x7f, 0x02, 0x6a, 0x81, 0x45, 0xde,
+ 0x41, 0xb3, 0x0c, 0x0a, 0x42, 0xbf, 0x92, 0x3b,
+ 0xac, 0x5f, 0x75, 0x04, 0xc2, 0x48, 0x60, 0x4b,
+ 0x9f, 0xaa, 0x57, 0xed, 0x6b, 0x32, 0x46, 0xc6,
+ 0xba, 0x15, 0x8e, 0x36, 0xc6, 0x44, 0xf8, 0xb9,
+ 0x54, 0x8f, 0xcf, 0x4f, 0x07, 0xe0, 0x54, 0xa5,
+ 0x6f, 0x76, 0x86, 0x74, 0x05, 0x44, 0x40, 0xbc,
+ 0x0d, 0xcb, 0xbc, 0x9b, 0x52, 0x8f, 0x64, 0xa0,
+ 0x17, 0x06, 0xe0, 0x5b, 0x0b, 0x91, 0x10, 0x6f,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
+ /* 4096,[p<q] */ {0x9c, 0x30, 0x60, 0xcf, 0xaa, 0xed, 0x64, 0xa0,
+ 0xe2, 0xa4, 0x24, 0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 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
+ /* 2048,[p>q] */ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0xf4, 0x4f, 0x5e, 0x42, 0x46, 0x39, 0x1f, 0x48,
+ 0x2b, 0x2f, 0x52, 0x96, 0xe3, 0x60,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 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
+ /* 4096,[p>q] */ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0xea, 0x48, 0x91, 0x37, 0x80, 0x64, 0x16, 0xf1,
+ 0x53, 0xf6, 0x36, 0x14, 0x06, 0x0e, 0xa9, 0xc7,
+ 0xdb, 0xa6, 0x22, 0x91, 0xb2, 0xb7, 0xb9, 0xdd,
+ 0x9a, 0x01, 0x18, 0x2d, 0xaa, 0x34, 0x0e, 0xd9,
+ 0xca, 0x5b, 0xfe, 0x63, 0xec, 0x02, 0x9c, 0xdb,
+ 0x91, 0x2f, 0x82, 0x27, 0x13, 0xa3, 0xe3, 0x39,
+ 0x07, 0x42, 0xe6, 0x2d, 0xe9, 0xb0, 0xb8, 0x56,
+ 0xf5, 0xd8, 0x67, 0x68, 0x0f, 0xc3, 0x18, 0x14,
+ 0x1f, 0x48, 0x71, 0xed, 0x19, 0x20, 0x7c, 0xc4,
+ 0xb7, 0xf8, 0x0f, 0x39, 0xb7, 0xf2, 0xc8, 0x45,
+ 0x7b, 0x91, 0x9d, 0x42, 0x15, 0x2d, 0x48, 0xb1,
+ 0x11, 0x49, 0x03, 0x8c, 0x7a, 0x80, 0x20, 0x65,
+ 0xe3, 0xee, 0x12, 0xb2, 0x43, 0x03, 0xd2, 0x60,
+ 0xbe, 0x04, 0x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36, 0x4f, 0x6d,
+ 0xd8, 0xbc, 0xa7, 0x2f, 0xbd, 0x43, 0xdc, 0x9a,
+ 0x0e, 0x2a, 0x36, 0xb9, 0x21, 0x05, 0xfa, 0x22,
+ 0x6c, 0xe8, 0x22, 0x68, 0x2f, 0x1c, 0xe8, 0x27,
+ 0xc1, 0xed, 0x08, 0x7a, 0x43, 0x70, 0x7b, 0xe3,
+ 0x46, 0x74, 0x02, 0x6e, 0xb2, 0xb1, 0xeb, 0x44,
+ 0x72, 0x86, 0x0d, 0x55, 0x3b, 0xc8, 0xbc, 0xd9,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
+ /* 2048,[p<q] */ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0xe9, 0xd4, 0x98, 0x41, 0xe0, 0xe0, 0xa6, 0xad,
+ 0x0d, 0x51, 0x78, 0x57, 0x13, 0x3e, 0x36, 0xdc,
+ 0x72, 0xc1, 0xbd, 0xd9, 0x0f, 0x91, 0x74, 0xb5,
+ 0x2e, 0x26, 0x57, 0x0f, 0x37, 0x36, 0x40, 0xf1,
+ 0xc1, 0x85, 0xe7, 0xea, 0x8e, 0x2e, 0xd7, 0xf1,
+ 0xe4, 0xeb, 0xb9, 0x51, 0xf7, 0x0a, 0x58, 0x02,
+ 0x36, 0x33, 0xb0, 0x09, 0x7a, 0xec, 0x67, 0xc6,
+ 0xdc, 0xb8, 0x00, 0xfc, 0x1a, 0x67, 0xf9, 0xbb,
+ 0x05, 0x63, 0x61, 0x0f, 0x08, 0xeb, 0xc8, 0x74,
+ 0x6a, 0xd1, 0x29, 0x77, 0x21, 0x36, 0xeb, 0x1d,
+ 0xda, 0xf4, 0x64, 0x36, 0x45, 0x0d, 0x31, 0x83,
+ 0x32, 0xa8, 0x49, 0x82, 0xfe, 0x5d, 0x28, 0xdb,
+ 0xe5, 0xb3, 0xe9, 0x12, 0x40, 0x7c, 0x3e, 0x0e,
+ 0x03, 0x10, 0x0d, 0x87, 0xd4, 0x36, 0xee, 0x40,
+ 0x9e, 0xec, 0x1c, 0xf8, 0x5e, 0x80, 0xab, 0xa0,
+ 0x79, 0xb2, 0xe6, 0x10, 0x6b, 0x97, 0xbc, 0xed,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
+ /* 4096,[p<q] */ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0xe1, 0xda, 0xf2, 0xfb, 0x1a, 0xca, 0x6f, 0x3a,
+ 0x74, 0x7a, 0x79, 0x27, 0xb0, 0xba, 0x9d, 0x4c,
+ 0x5d, 0xce, 0x55, 0xaf, 0x8c, 0x88, 0x04, 0x50,
+ 0x7f, 0x7a, 0xf1, 0x7c, 0xad, 0xf8, 0x0e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 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
+ /* 2048,[p>q] */ {0xe9, 0xd4, 0x98, 0x41, 0xe0, 0xe0, 0xa6, 0xad,
+ 0x0d, 0x51, 0x78, 0x57, 0x13, 0x3e, 0x36, 0xdc,
+ 0x72, 0xc1, 0xbd, 0xd9, 0x0f, 0x91, 0x74, 0xb5,
+ 0x2e, 0x26, 0x57, 0x0f, 0x37, 0x36, 0x40, 0xf1,
+ 0xc1, 0x85, 0xe7, 0xea, 0x8e, 0x2e, 0xd7, 0xf1,
+ 0xe4, 0xeb, 0xb9, 0x51, 0xf7, 0x0a, 0x58, 0x02,
+ 0x36, 0x33, 0xb0, 0x09, 0x7a, 0xec, 0x67, 0xc6,
+ 0xdc, 0xb8, 0x00, 0xfc, 0x1a, 0x67, 0xf9, 0xbb,
+ 0x05, 0x63, 0x61, 0x0f, 0x08, 0xeb, 0xc8, 0x74,
+ 0x6a, 0xd1, 0x29, 0x77, 0x21, 0x36, 0xeb, 0x1d,
+ 0xda, 0xf4, 0x64, 0x36, 0x45, 0x0d, 0x31, 0x83,
+ 0x32, 0xa8, 0x49, 0x82, 0xfe, 0x5d, 0x28, 0xdb,
+ 0xe5, 0xb3, 0xe9, 0x12, 0x40, 0x7c, 0x3e, 0x0e,
+ 0x03, 0x10, 0x0d, 0x87, 0xd4, 0x36, 0xee, 0x40,
+ 0x9e, 0xec, 0x1c, 0xf8, 0x5e, 0x80, 0xab, 0xa0,
+ 0x79, 0xb2, 0xe6, 0x10, 0x6b, 0x97, 0xbc, 0xed,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 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xf9, 0x6a, 0x4c, 0xa1, 0xa2, 0x4b,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
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00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
+ /* 4096,[p<q] */ {0xea, 0x48, 0x91, 0x37, 0x80, 0x64, 0x16, 0xf1,
+ 0x53, 0xf6, 0x36, 0x14, 0x06, 0x0e, 0xa9, 0xc7,
+ 0xdb, 0xa6, 0x22, 0x91, 0xb2, 0xb7, 0xb9, 0xdd,
+ 0x9a, 0x01, 0x18, 0x2d, 0xaa, 0x34, 0x0e, 0xd9,
+ 0xca, 0x5b, 0xfe, 0x63, 0xec, 0x02, 0x9c, 0xdb,
+ 0x91, 0x2f, 0x82, 0x27, 0x13, 0xa3, 0xe3, 0x39,
+ 0x07, 0x42, 0xe6, 0x2d, 0xe9, 0xb0, 0xb8, 0x56,
+ 0xf5, 0xd8, 0x67, 0x68, 0x0f, 0xc3, 0x18, 0x14,
+ 0x1f, 0x48, 0x71, 0xed, 0x19, 0x20, 0x7c, 0xc4,
+ 0xb7, 0xf8, 0x0f, 0x39, 0xb7, 0xf2, 0xc8, 0x45,
+ 0x7b, 0x91, 0x9d, 0x42, 0x15, 0x2d, 0x48, 0xb1,
+ 0x11, 0x49,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0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x83, 0xf1, 0xca, 0x06, 0x58, 0x4a, 0x04, 0x5e,
+ 0x96, 0xb5, 0x30, 0x32, 0x40, 0x36, 0x48, 0xb9,
+ 0x02, 0x0c, 0xe3, 0x37, 0xb7, 0x51, 0xbc, 0x22,
+ 0x26, 0x5d, 0x74, 0x03, 0x47, 0xd3, 0x33, 0x20,
+ 0x8e, 0x75, 0x62, 0xf2, 0x9d, 0x4e, 0xc8, 0x7d,
+ 0x5d, 0x8e, 0xb6, 0xd9, 0x69, 0x4a, 0x9a, 0xe1,
+ 0x36, 0x6e, 0x1c, 0xbe, 0x8a, 0x14, 0xb1, 0x85,
+ 0x39, 0x74, 0x7c, 0x25, 0xd8, 0xa4, 0x4f, 0xde,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
+ /* 2048,[p>q] */ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x57, 0xb7, 0x38, 0x88, 0xd1, 0x83, 0xa9, 0x9a,
+ 0x63, 0x07, 0x42, 0x22, 0x77, 0x55, 0x1a, 0x3d,
+ 0x9e, 0x18, 0xad, 0xf0, 0x6a, 0x91, 0xe8, 0xb5,
+ 0x5c, 0xef, 0xfe, 0xf9, 0x07, 0x7c, 0x84, 0x96,
+ 0x94, 0x8e, 0xcb, 0x3b, 0x16, 0xb7, 0x81, 0x55,
+ 0xcb, 0x2a, 0x3a, 0x57, 0xc1, 0x19, 0xd3, 0x79,
+ 0x95, 0x1c, 0x01, 0x0a, 0xa6, 0x35, 0xed, 0xcf,
+ 0x62, 0xd8, 0x4c, 0x5a, 0x12, 0x2a, 0x8d, 0x67,
+ 0xab, 0x5f, 0xa9, 0xe5, 0xa4, 0xa8, 0x77, 0x2a,
+ 0x1e, 0x94, 0x3b, 0xaf, 0xc7, 0x0a, 0xe3, 0xa4,
+ 0xc1, 0xf0, 0xf3, 0xa4, 0xdd, 0xff, 0xae, 0xfd,
+ 0x18, 0x92, 0xc8, 0xcb, 0x33, 0xbb, 0x0d, 0x0b,
+ 0x95, 0x90, 0xe9, 0x63, 0xa6, 0x91, 0x10, 0xfb,
+ 0x34, 0xdb, 0x7b, 0x90, 0x6f, 0xc4, 0xba, 0x28,
+ 0x36, 0x99, 0x5a, 0xac, 0x7e, 0x52, 0x74, 0x90,
+ 0xac, 0x95, 0x2a, 0x02, 0x26, 0x8a, 0x4f, 0x18,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
+ /* 4096,[p>q] */ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x27, 0x0f, 0x83, 0x44, 0x1b, 0x11, 0xce, 0x9f,
+ 0xe6, 0xdf, 0xd5, 0x1b, 0xed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00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
+ /* 2048,[p<q] */ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x95, 0xe0, 0x94, 0xf5, 0xf7, 0x5f, 0x9e, 0x7a,
+ 0xe3, 0xe0, 0x5f, 0x09, 0xb5, 0x77, 0x81, 0x49,
+ 0x64, 0xbf, 0x0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00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
+ /* 4096,[p<q] */ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0xbc, 0x33, 0x29, 0x91, 0x3c, 0x49, 0x8a, 0x8c,
+ 0x1f, 0x0c, 0x5e, 0x1b, 0x47, 0x96, 0x98, 0xab,
+ 0xf6, 0xb6, 0xdb, 0xf9, 0xaa, 0x86, 0xad, 0x48,
+ 0x2d, 0x59, 0xf8, 0xf4, 0xbc, 0x8c, 0x2e, 0x4d,
+ 0x52, 0x0e, 0x48, 0x03, 0xc5, 0xb9, 0x83, 0x66,
+ 0x15, 0x45, 0xff, 0x0e, 0x69, 0xe9, 0x31, 0x70,
+ 0xc5, 0x21, 0xfa, 0x8b, 0x64, 0xef, 0x4c, 0x53,
+ 0x32, 0x51, 0xe7, 0x2f, 0x70, 0x52, 0x89, 0xa2,
+ 0x2b, 0xff, 0x88, 0x9d, 0x93, 0x78, 0x33, 0x03,
+ 0x6e, 0x2a, 0xd4, 0x67, 0x3d, 0xb2, 0xa9, 0x5a,
+ 0x23, 0x3d, 0xfc, 0xaf, 0x6d, 0x41, 0x09, 0x47,
+ 0x7c, 0xa4, 0x28, 0x8b, 0x00, 0x8b, 0xc9, 0x48,
+ 0x75, 0x80, 0x4a, 0x68, 0x3a, 0x6d, 0x96, 0x46,
+ 0x37, 0xb9, 0x68, 0x01, 0x6b, 0xeb, 0x6f, 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 0x54, 0x13, 0x2b,
+ 0xaa, 0xe7, 0xc3, 0x50, 0x3b, 0x69, 0x3b, 0x0b,
+ 0x9a, 0xa9, 0x9d, 0x15, 0x8a, 0x06, 0x45, 0x71,
+ 0x40, 0x7a, 0x80, 0x85, 0x4a, 0xbe, 0x68, 0x48,
+ 0x6c, 0xe6, 0xdd, 0x96, 0xb0, 0xdc, 0xf4, 0x23,
+ 0xa8, 0xea, 0x21, 0x9f, 0xbc, 0x6b, 0x15, 0xa4,
+ 0x87, 0x6e, 0x93, 0x56, 0xae, 0xa7, 0x17, 0x4e,
+ 0xd7, 0x14, 0xe4, 0x69, 0x04, 0xd5, 0x2e, 0x62,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,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0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x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, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
+ /* 2048,[p<q] */ {0x6d, 0xdc, 0x9c, 0xba, 0xd4, 0xfa, 0xfe, 0xd0,
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xe7, 0x7d, 0x5a, 0xf3,
+ 0x42, 0xff, 0xf8, 0xf6, 0x8d, 0xd2, 0x22, 0x95,
+ 0xdf, 0xf2, 0x7e, 0xfc, 0x34, 0xf4, 0x6d, 0x8e,
+ 0x37, 0x02, 0x34, 0x30, 0xf8, 0x31, 0xfb, 0xa8,
+ 0x97, 0x74, 0xac, 0xf3, 0x4a, 0x67, 0x4a, 0xee,
+ 0x12, 0xed, 0x9d, 0x19, 0xcd, 0x4a, 0xe2, 0x13,
+ 0x43, 0x25, 0xf7, 0x00, 0xd8, 0xbd, 0x91, 0xc2,
+ 0x38, 0xc4, 0x68, 0xeb, 0xb1, 0x74, 0xd0, 0x8c,
+ 0xdb, 0x76, 0x79, 0xe2, 0xd0, 0x85, 0x0d, 0x03,
+ 0xdc, 0xdc, 0x8e, 0x79, 0x7f, 0xdb, 0xea, 0x36,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
+ /* 4096,[p<q] */ {0xac, 0x34, 0x9f, 0xe1, 0x4d, 0x4a, 0xf8, 0x8f,
+ 0x3a, 0xa0, 0xf5, 0x78, 0xe3, 0x30, 0x7e, 0x80,
+ 0x55, 0x7a, 0x93, 0x96, 0x47, 0xb8, 0x28, 0xc7,
+ 0x34, 0x33, 0xcf, 0x97, 0x90, 0x71, 0xbc, 0xc6,
+ 0x37, 0x13, 0x8b, 0x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b, 0x4e, 0xaa,
+ 0xdd, 0x47, 0x24, 0xa4, 0x1a, 0x1d, 0x5b, 0xa1,
+ 0x8e, 0xcf, 0x4a, 0x51, 0x0a, 0x7b, 0x24, 0xfc,
+ 0x54, 0x20, 0x31, 0x5a, 0x97, 0x42, 0x9d, 0x36,
+ 0x84, 0x07, 0x89, 0x3e, 0x39, 0x34, 0x5e, 0x40,
+ 0xae, 0xe7, 0xf8, 0x82, 0xd7, 0xb3, 0xa9, 0x25,
+ 0xfe, 0xc5, 0x45, 0xd5, 0xde, 0x6f, 0x02, 0x61,
+ 0x25, 0x12, 0x90, 0xfe, 0xe7, 0x10, 0x1d, 0x60,
+ 0x55, 0xf8, 0xd2, 0xff, 0x26, 0xb3, 0xbb, 0xea,
+ 0xb7, 0x6d, 0x14, 0xd9, 0x54, 0xef, 0xc3, 0x5f,
+ 0x73, 0x46, 0xdc, 0xd1, 0xfa, 0xd8, 0x31, 0xc6,
+ 0xff, 0xd8, 0xc7, 0xf7, 0x84, 0xc0, 0x87, 0x70,
+ 0x97, 0xab, 0xdf, 0xa7, 0x8c, 0x0b, 0xf1, 0xcf,
+ 0x81, 0x2a, 0xce, 0xf2, 0x02, 0xfd, 0x41, 0xb2,
+ 0x54, 0x9f, 0x49, 0x17, 0xe7, 0xbb, 0xa5, 0x37,
+ 0x6e, 0x4d, 0xeb, 0x2b, 0x62, 0x1c, 0x36, 0xb3,
+ 0x01, 0x86, 0x45, 0x82, 0xc1, 0x4f, 0x60, 0x77}};
diff --git a/src/tests/libica_sha1_test.c b/src/tests/libica_sha1_test.c
new file mode 100644
index 0000000..da73aef
--- /dev/null
+++ b/src/tests/libica_sha1_test.c
@@ -0,0 +1,220 @@
+/* This program is released under the Common Public License V1.0
+ *
+ * You should have received a copy of Common Public License V1.0 along with
+ * with this program.
+ */
+
+/* Copyright IBM Corp. 2001, 2009, 2011 */
+
+#include <fcntl.h>
+#include <sys/errno.h>
+#include <stdio.h>
+#include <string.h>
+#include "ica_api.h"
+
+#define NUM_FIPS_TESTS 4
+
+unsigned char FIPS_TEST_DATA[NUM_FIPS_TESTS][64] = {
+ // Test 0: NULL
+ { 0x00 },
+ // Test 1: "abc"
+ { 0x61,0x62,0x63 },
+ // Test 2: "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
+ {
+0x61,0x62,0x63,0x64,0x62,0x63,0x64,0x65,0x63,0x64,0x65,0x66,0x64,0x65,0x66,0x67,
+0x65,0x66,0x67,0x68,0x66,0x67,0x68,0x69,0x67,0x68,0x69,0x6a,0x68,0x69,0x6a,0x6b,
+0x69,0x6a,0x6b,0x6c,0x6a,0x6b,0x6c,0x6d,0x6b,0x6c,0x6d,0x6e,0x6c,0x6d,0x6e,0x6f,
+0x6d,0x6e,0x6f,0x70,0x6e,0x6f,0x70,0x71,
+ },
+ // Test 3: 1,000,000 'a' -- don't actually use this... see the special case
+ // in the loop below.
+ {
+0x61,
+ },
+};
+
+unsigned int FIPS_TEST_DATA_SIZE[NUM_FIPS_TESTS] = {
+ // Test 0: NULL
+ 0,
+ // Test 1: "abc"
+ 3,
+ // Test 2: "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
+ 56,
+ // Test 3: 1,000,000 'a'
+ 1000000,
+};
+
+unsigned char FIPS_TEST_RESULT[NUM_FIPS_TESTS][LENGTH_SHA_HASH] =
+{
+ // Hash for test 0: NULL
+ {
+0xda,0x39,0xa3,0xee,0x5e,0x6b,0x4b,0x0d,0x32,0x55,0xbf,0xef,0x95,0x60,0x18,0x90,
+0xaf,0xd8,0x07,0x09,
+ },
+ // Hash for test 1: "abc"
+ {
+0xA9,0x99,0x3E,0x36,0x47,0x06,0x81,0x6A,0xBA,0x3E,0x25,0x71,0x78,0x50,0xC2,0x6C,
+0x9C,0xD0,0xD8,0x9D,
+ },
+ // Hash for test 2: "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
+ {
+0x84,0x98,0x3E,0x44,0x1C,0x3B,0xD2,0x6E,0xBA,0xAE,0x4A,0xA1,0xF9,0x51,0x29,0xE5,
+0xE5,0x46,0x70,0xF1,
+ },
+ // Hash for test 3: 1,000,000 'a'
+ {
+0x34,0xAA,0x97,0x3C,0xD4,0xC4,0xDA,0xA4,0xF6,0x1E,0xEB,0x2B,0xDB,0xAD,0x27,0x31,
+0x65,0x34,0x01,0x6F,
+ },
+};
+
+void dump_array(unsigned char *ptr, unsigned int size)
+{
+ unsigned char *ptr_end;
+ unsigned char *h;
+ int i = 1, trunc = 0;
+
+ if (size > 64) {
+ trunc = size - 64;
+ size = 64;
+ }
+ h = ptr;
+ ptr_end = ptr + size;
+ while (h < ptr_end) {
+ printf("0x%02x ", *h);
+ h++;
+ if (i == 8) {
+ if (h != ptr_end)
+ printf("\n");
+ i = 1;
+ } else {
+ ++i;
+ }
+ }
+ printf("\n");
+ if (trunc > 0)
+ printf("... %d bytes not printed\n", trunc);
+}
+
+int new_api_sha_test(void)
+{
+ printf("Test of new sha api\n");
+ sha_context_t sha_context;
+ int rc = 0, i = 0;
+ unsigned char input_data[1000000];
+ unsigned int output_hash_length = LENGTH_SHA_HASH;
+ unsigned char output_hash[LENGTH_SHA_HASH];
+
+ for (i = 0; i < NUM_FIPS_TESTS; i++) {
+ // Test 3 is a special one, because we want to keep the size of the
+ // executable down, so we build it special, instead of using a static
+ if (i != 3)
+ memcpy(input_data, FIPS_TEST_DATA[i], FIPS_TEST_DATA_SIZE[i]);
+ else
+ memset(input_data, 'a', FIPS_TEST_DATA_SIZE[i]);
+
+ printf("\nOriginal data for test %d:\n", i);
+ dump_array(input_data, FIPS_TEST_DATA_SIZE[i]);
+
+ rc = ica_sha1(SHA_MSG_PART_ONLY, FIPS_TEST_DATA_SIZE[i], input_data,
+ &sha_context, output_hash);
+
+ if (rc != 0) {
+ printf("icaSha1 failed with errno %d (0x%x).\n", rc, rc);
+ return rc;
+ }
+
+ printf("\nOutput hash for test %d:\n", i);
+ dump_array(output_hash, output_hash_length);
+ if (memcmp(output_hash, FIPS_TEST_RESULT[i], LENGTH_SHA_HASH) != 0)
+ printf("This does NOT match the known result.\n");
+ else
+ printf("Yep, it's what it should be.\n");
+ }
+
+ // This test is the same as test 3, except that we use the SHA_CONTEXT
+ // and break it into calls of 1024 bytes each.
+ printf("\nOriginal data for test 3(chunks = 1024) is calls of 1024"
+ "'a's at a time\n");
+ i = FIPS_TEST_DATA_SIZE[3];
+ while (i > 0) {
+ unsigned int sha_message_part;
+ memset(input_data, 'a', 1024);
+
+ if (i == FIPS_TEST_DATA_SIZE[3])
+ sha_message_part = SHA_MSG_PART_FIRST;
+ else if (i <= 1024)
+ sha_message_part = SHA_MSG_PART_FINAL;
+ else
+ sha_message_part = SHA_MSG_PART_MIDDLE;
+
+ rc = ica_sha1(sha_message_part, (i < 1024) ? i : 1024,
+ input_data, &sha_context, output_hash);
+
+ if (rc != 0) {
+ printf("ica_sha1 failed with errno %d (0x%x) on"
+ " iteration %d.\n", rc, rc, i);
+ return rc;
+ }
+ i -= 1024;
+ }
+
+ printf("\nOutput hash for test 3(chunks = 1024):\n");
+ dump_array(output_hash, output_hash_length);
+ if (memcmp(output_hash, FIPS_TEST_RESULT[3], LENGTH_SHA_HASH) != 0)
+ printf("This does NOT match the known result.\n");
+ else
+ printf("Yep, it's what it should be.\n");
+
+ // This test is the same as test 3, except that we use the SHA_CONTEXT
+ // and break it into calls of 64 bytes each.
+ printf("\nOriginal data for test 3(chunks = 64) is calls of 64 'a's at"
+ "a time\n");
+ i = FIPS_TEST_DATA_SIZE[3];
+ while (i > 0) {
+ unsigned int sha_message_part;
+ memset(input_data, 'a', 64);
+
+ if (i == FIPS_TEST_DATA_SIZE[3])
+ sha_message_part = SHA_MSG_PART_FIRST;
+ else if (i <= 64)
+ sha_message_part = SHA_MSG_PART_FINAL;
+ else
+ sha_message_part = SHA_MSG_PART_MIDDLE;
+
+ rc = ica_sha1(sha_message_part, (i < 64) ? i : 64, input_data,
+ &sha_context, output_hash);
+
+ if (rc != 0) {
+ printf("ica_sha1 failed with errno %d (0x%x) on"
+ " iteration %d.\n", rc, rc, i);
+ return rc;
+ }
+ i -= 64;
+ }
+
+ printf("\nOutput hash for test 3(chunks = 64):\n");
+ dump_array(output_hash, output_hash_length);
+ if (memcmp(output_hash, FIPS_TEST_RESULT[3], LENGTH_SHA_HASH) != 0)
+ printf("This does NOT match the known result.\n");
+ else
+ printf("Yep, it's what it should be.\n");
+
+ printf("\nAll SHA1 tests completed successfully\n");
+
+ return 0;
+}
+
+int main(int argc, char **argv)
+{
+ int rc = 0;
+
+ rc = new_api_sha_test();
+ if (rc) {
+ printf("new_api_sha_test failed with rc = %i\n", rc);
+ return rc;
+ }
+
+ return 0;
+}
+
diff --git a/src/tests/libica_sha256_test.c b/src/tests/libica_sha256_test.c
new file mode 100644
index 0000000..91ef7d3
--- /dev/null
+++ b/src/tests/libica_sha256_test.c
@@ -0,0 +1,209 @@
+/* This program is released under the Common Public License V1.0
+ *
+ * You should have received a copy of Common Public License V1.0 along with
+ * with this program.
+ */
+
+/* Copyright IBM Corp. 2005, 2009, 2011 */
+/* (C) COPYRIGHT International Business Machines Corp. 2005, 2009 */
+#include <fcntl.h>
+#include <sys/errno.h>
+#include <stdio.h>
+#include <string.h>
+#include "ica_api.h"
+
+#define NUM_FIPS_TESTS 3
+
+unsigned char FIPS_TEST_DATA[NUM_FIPS_TESTS][64] = {
+ // Test 0: "abc"
+ { 0x61,0x62,0x63 },
+ // Test 1: "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
+ {
+0x61,0x62,0x63,0x64,0x62,0x63,0x64,0x65,0x63,0x64,0x65,0x66,0x64,0x65,0x66,0x67,
+0x65,0x66,0x67,0x68,0x66,0x67,0x68,0x69,0x67,0x68,0x69,0x6a,0x68,0x69,0x6a,0x6b,
+0x69,0x6a,0x6b,0x6c,0x6a,0x6b,0x6c,0x6d,0x6b,0x6c,0x6d,0x6e,0x6c,0x6d,0x6e,0x6f,
+0x6d,0x6e,0x6f,0x70,0x6e,0x6f,0x70,0x71,
+ },
+ // Test 2: 1,000,000 'a' -- don't actually use this... see the special case
+ // in the loop below.
+ {
+0x61,
+ },
+};
+
+unsigned int FIPS_TEST_DATA_SIZE[NUM_FIPS_TESTS] = {
+ // Test 0: "abc"
+ 3,
+ // Test 1: "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
+ 56,
+ // Test 2: 1,000,000 'a'
+ 1000000,
+};
+
+unsigned char FIPS_TEST_RESULT[NUM_FIPS_TESTS][LENGTH_SHA256_HASH] =
+{
+ // Hash for test 0: "abc"
+ {
+0xBA,0x78,0x16,0xBF,0x8F,0x01,0xCF,0xEA,0x41,0x41,0x40,0xDE,0x5D,0xAE,0x22,0x23,
+0xB0,0x03,0x61,0xA3,0x96,0x17,0x7A,0x9C,0xB4,0x10,0xFF,0x61,0xF2,0x00,0x15,0xAD,
+ },
+ // Hash for test 1: "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
+ {
+0x24,0x8D,0x6A,0x61,0xD2,0x06,0x38,0xB8,0xE5,0xC0,0x26,0x93,0x0C,0x3E,0x60,0x39,
+0xA3,0x3C,0xE4,0x59,0x64,0xFF,0x21,0x67,0xF6,0xEC,0xED,0xD4,0x19,0xDB,0x06,0xC1,
+ },
+ // Hash for test 2: 1,000,000 'a'
+ {
+0xCD,0xC7,0x6E,0x5C,0x99,0x14,0xFB,0x92,0x81,0xA1,0xC7,0xE2,0x84,0xD7,0x3E,0x67,
+0xF1,0x80,0x9A,0x48,0xA4,0x97,0x20,0x0E,0x04,0x6D,0x39,0xCC,0xC7,0x11,0x2C,0xD0,
+ },
+};
+
+void dump_array(unsigned char *ptr, unsigned int size)
+{
+ unsigned char *ptr_end;
+ unsigned char *h;
+ int i = 1, trunc = 0;
+
+ if (size > 64) {
+ trunc = size - 64;
+ size = 64;
+ }
+ h = ptr;
+ ptr_end = ptr + size;
+ while (h < ptr_end) {
+ printf("0x%02x ", *h);
+ h++;
+ if (i == 8) {
+ if (h != ptr_end)
+ printf("\n");
+ i = 1;
+ } else {
+ ++i;
+ }
+ }
+ printf("\n");
+ if (trunc > 0)
+ printf("... %d bytes not printed\n", trunc);
+}
+
+int new_api_sha256_test(void)
+{
+ sha256_context_t sha256_context;
+ int rc = 0, i = 0;
+ unsigned char input_data[1000000];
+ unsigned int output_hash_length = LENGTH_SHA256_HASH;
+ unsigned char output_hash[LENGTH_SHA256_HASH];
+
+ for (i = 0; i < NUM_FIPS_TESTS; i++) {
+ // Test 2 is a special one, because we want to keep the size of the
+ // executable down, so we build it special, instead of using a static
+ if (i != 2)
+ memcpy(input_data, FIPS_TEST_DATA[i], FIPS_TEST_DATA_SIZE[i]);
+ else
+ memset(input_data, 'a', FIPS_TEST_DATA_SIZE[i]);
+
+ printf("\nOriginal data for test %d:\n", i);
+ dump_array(input_data, FIPS_TEST_DATA_SIZE[i]);
+
+ rc = ica_sha256(SHA_MSG_PART_ONLY, FIPS_TEST_DATA_SIZE[i], input_data,
+ &sha256_context, output_hash);
+
+ if (rc != 0) {
+ printf("icaSha256 failed with errno %d (0x%x).\n", rc, rc);
+ return rc;
+ }
+
+ printf("\nOutput hash for test %d:\n", i);
+ dump_array(output_hash, output_hash_length);
+ if (memcmp(output_hash, FIPS_TEST_RESULT[i], LENGTH_SHA256_HASH) != 0)
+ printf("This does NOT match the known result.\n");
+ else
+ printf("Yep, it's what it should be.\n");
+ }
+
+ // This test is the same as test 2, except that we use the SHA256_CONTEXT and
+ // break it into calls of 1024 bytes each.
+ printf("\nOriginal data for test 2(chunks = 1024) is calls of 1024"
+ " 'a's at a time\n");
+ i = FIPS_TEST_DATA_SIZE[2];
+ while (i > 0) {
+ unsigned int sha_message_part;
+ memset(input_data, 'a', 1024);
+
+ if (i == FIPS_TEST_DATA_SIZE[2])
+ sha_message_part = SHA_MSG_PART_FIRST;
+ else if (i <= 1024)
+ sha_message_part = SHA_MSG_PART_FINAL;
+ else
+ sha_message_part = SHA_MSG_PART_MIDDLE;
+
+ rc = ica_sha256(sha_message_part, (i < 1024) ? i : 1024,
+ input_data, &sha256_context, output_hash);
+
+ if (rc != 0) {
+ printf("ica_sha256 failed with errno %d (0x%x) on"
+ " iteration %d.\n", rc, rc, i);
+ return rc;
+ }
+ i -= 1024;
+ }
+
+ printf("\nOutput hash for test 2(chunks = 1024):\n");
+ dump_array(output_hash, output_hash_length);
+ if (memcmp(output_hash, FIPS_TEST_RESULT[2], LENGTH_SHA256_HASH) != 0)
+ printf("This does NOT match the known result.\n");
+ else
+ printf("Yep, it's what it should be.\n");
+
+ // This test is the same as test 2, except that we use the
+ // SHA256_CONTEXT and break it into calls of 64 bytes each.
+ printf("\nOriginal data for test 2(chunks = 64) is calls of 64 'a's at"
+ " a time\n");
+ i = FIPS_TEST_DATA_SIZE[2];
+ while (i > 0) {
+ unsigned int sha_message_part;
+ memset(input_data, 'a', 64);
+
+ if (i == FIPS_TEST_DATA_SIZE[2])
+ sha_message_part = SHA_MSG_PART_FIRST;
+ else if (i <= 64)
+ sha_message_part = SHA_MSG_PART_FINAL;
+ else
+ sha_message_part = SHA_MSG_PART_MIDDLE;
+
+ rc = ica_sha256(sha_message_part, (i < 64) ? i : 64,
+ input_data, &sha256_context, output_hash);
+
+ if (rc != 0) {
+ printf("ica_sha256 failed with errno %d (0x%x) on iteration"
+ " %d.\n", rc, rc, i);
+ return rc;
+ }
+ i -= 64;
+ }
+
+ printf("\nOutput hash for test 2(chunks = 64):\n");
+ dump_array(output_hash, output_hash_length);
+ if (memcmp(output_hash, FIPS_TEST_RESULT[2], LENGTH_SHA256_HASH) != 0)
+ printf("This does NOT match the known result.\n");
+ else
+ printf("Yep, it's what it should be.\n");
+
+ printf("\nAll SHA256 tests completed successfully\n");
+
+ return 0;
+}
+
+int main(int argc, char **argv)
+{
+ int rc = 0;
+
+ rc = new_api_sha256_test();
+ if (rc) {
+ printf("new_api_sha256_test: returned rc = %i\n", rc);
+ return rc;
+ }
+
+ return rc;
+}
diff --git a/src/tests/libica_sha_test/Makefile.am b/src/tests/libica_sha_test/Makefile.am
new file mode 100644
index 0000000..b6b4fc4
--- /dev/null
+++ b/src/tests/libica_sha_test/Makefile.am
@@ -0,0 +1,26 @@
+OPTS = -O0 -g -Wall -D_LINUX_S390_
+LIBS = -L../../.libs
+INCLUDE = -I. -I./include -I../../../include
+SOURCES = libica_sha_test.c queue_t.c sha_tests.c read_rsp.c
+CC = gcc
+FILES = libica_sha_test.c~ \
+ libica_sha_test.o \
+ queue_t.c~ \
+ queue_t.o \
+ include/queue_t.h~ \
+ sha_tests.c~ \
+ sha_tests.o \
+ include/sha_tests.h~ \
+ read_rsp.c~ \
+ include/read_rsp.h~ \
+ include/critical_error.h~
+
+all:
+ $(CC) $(OPTS) -o libica_sha_test $(SOURCES) $(LIBS) $(INCLUDE) -lica -lcrypto
+
+clean:
+ rm -f libica_sha_test
+
+distclean:
+ rm -f Makefile
+ rm -f $(FILES)
diff --git a/src/tests/libica_sha_test/README b/src/tests/libica_sha_test/README
new file mode 100644
index 0000000..a2c8163
--- /dev/null
+++ b/src/tests/libica_sha_test/README
@@ -0,0 +1,5 @@
+usage: libica_sha_test filelist
+test for old and new libica api for sha1/224/256/384/512
+test vectors are read from .rsp files and put in the queue
+the included .rsp files are obtained from nist:
+http://csrc.nist.gov/groups/STM/cavp/index.html#03
diff --git a/src/tests/libica_sha_test/include/critical_error.h b/src/tests/libica_sha_test/include/critical_error.h
new file mode 100644
index 0000000..18891a2
--- /dev/null
+++ b/src/tests/libica_sha_test/include/critical_error.h
@@ -0,0 +1,14 @@
+#ifndef CRITICAL_ERROR_H
+#define CRITICAL_ERROR_H
+
+#include <stdio.h>
+#include <stdlib.h>
+
+/* terminate on critical error */
+#define CRITICAL_ERROR(msg) \
+do { \
+ fprintf(stderr, "critical error in %s: " msg "\n",__func__); \
+ exit(EXIT_FAILURE); \
+} while(0)
+
+#endif
diff --git a/src/tests/libica_sha_test/include/queue_t.h b/src/tests/libica_sha_test/include/queue_t.h
new file mode 100644
index 0000000..1ba9295
--- /dev/null
+++ b/src/tests/libica_sha_test/include/queue_t.h
@@ -0,0 +1,33 @@
+#ifndef QUEUE_T_H
+#define QUEUE_T_H
+
+#define NO_TYPE_SET 0
+#define NO_LENGTH_SET 0
+
+/* type: NO_TYPE_SET, SHA1, SHA224, SHA256, SHA384, SHA512
+ * msg_digest_length: SHA1_HASH_LENGTH, SHA224_HASH_LENGHT, SHA256_HASH_LENGTH, SHA384_HASH_LENGTH, SHA512_HASH_LENGTH
+ * */
+typedef struct test_t {
+ unsigned int type;
+ unsigned char *msg;
+ unsigned int msg_length;
+ unsigned char *msg_digest;
+ unsigned int msg_digest_length;
+ struct test_t *next;
+} test_t;
+
+test_t new_test_t(void);
+
+typedef struct queue_t {
+ unsigned int size;
+ unsigned int passed;
+ unsigned int failed;
+ test_t *head;
+ test_t *tail;
+} queue_t;
+
+queue_t new_queue_t(void);
+
+void push(queue_t * queue, test_t test);
+
+#endif
diff --git a/src/tests/libica_sha_test/include/read_rsp.h b/src/tests/libica_sha_test/include/read_rsp.h
new file mode 100644
index 0000000..b4746af
--- /dev/null
+++ b/src/tests/libica_sha_test/include/read_rsp.h
@@ -0,0 +1,14 @@
+#ifndef READ_RSP_H
+#define READ_RSP_H
+
+#include <stdio.h>
+#include "queue_t.h"
+
+#define BUFFER_SIZE 32768
+
+extern queue_t queue;
+
+/* read test data from .rsp file into queue */
+int read_test_data(FILE * test_data);
+
+#endif
diff --git a/src/tests/libica_sha_test/include/sha_tests.h b/src/tests/libica_sha_test/include/sha_tests.h
new file mode 100644
index 0000000..239f3de
--- /dev/null
+++ b/src/tests/libica_sha_test/include/sha_tests.h
@@ -0,0 +1,22 @@
+#ifndef SHA_TESTS_H
+#define SHA_TESTS_H
+
+#include "queue_t.h"
+
+int sha1_old_api_test(test_t * test);
+int sha1_new_api_test(test_t * test);
+
+int sha224_old_api_test(test_t * test);
+int sha224_new_api_test(test_t * test);
+
+int sha256_old_api_test(test_t * test);
+int sha256_new_api_test(test_t * test);
+
+int sha384_old_api_test(test_t * test);
+int sha384_new_api_test(test_t * test);
+
+int sha512_old_api_test(test_t * test);
+int sha512_new_api_test(test_t * test);
+
+int silent;
+#endif
diff --git a/src/tests/libica_sha_test/libica_sha_test.c b/src/tests/libica_sha_test/libica_sha_test.c
new file mode 100644
index 0000000..7e6adc3
--- /dev/null
+++ b/src/tests/libica_sha_test/libica_sha_test.c
@@ -0,0 +1,115 @@
+/*
+ * usage: libica_sha_test filelist
+ * test for old and new libica api for sha1/224/256/384/512
+ * test vectors are read from .rsp files and put in the queue
+ * the included .rsp files are obtained from nist:
+ * http://csrc.nist.gov/groups/STM/cavp/index.html#03
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include "ica_api.h"
+#include "sha_tests.h"
+#include "read_rsp.h"
+#include "queue_t.h"
+#include "critical_error.h"
+
+queue_t queue;
+
+int main(int argc, char *argv[])
+{
+ test_t *curr_test;
+ FILE *test_data;
+ int i, rc, first = 1;
+
+ queue = new_queue_t();
+
+ if (argc < 2) {
+ printf("error: no input files.\n");
+ }
+
+ if (argv[1]) {
+ if (strstr(argv[1], "silent")) {
+ silent = 1; first = 2;
+ }
+ }
+ /* read test vectors from .rsp file(s) and put on queue */
+ for (i = first; i < argc; i++) {
+ if ((test_data = fopen(argv[i], "r")) != NULL) {
+ //printf("reading test data from %s ... ", argv[i]);
+ if (read_test_data(test_data) == EXIT_SUCCESS)
+ // printf("done.\n");
+ if ((fclose(test_data)) == EOF)
+ printf("error: couldn't close file %s.\n",
+ argv[i]);
+ } else
+ printf("error: couldn't open file %s.\n", argv[i]);
+ }
+
+ if (!silent) {
+ printf("%u test vectors found.\n", queue.size);
+ }
+ if (queue.size > 0)
+ if (!silent) {
+ printf("starting tests ...\n\n");
+ }
+ /* run each test in queue with new and old api */
+ for (curr_test = queue.head, i = 1; curr_test != NULL;
+ curr_test = curr_test->next, i++) {
+ if (!silent)
+ printf("test #%d : %u byte input message, ", i,
+ curr_test->msg_length);
+ switch (curr_test->type) {
+ case SHA1:
+ if (!silent)
+ printf("SHA1 ...\n");
+ rc = sha1_new_api_test(curr_test);
+ break;
+ case SHA224:
+ if (!silent)
+ printf("SHA224 ...\n");
+ rc = sha224_new_api_test(curr_test);
+ break;
+ case SHA256:
+ if (!silent)
+ printf("SHA256 ...\n");
+ rc = sha256_new_api_test(curr_test);
+ break;
+ case SHA384:
+ if (!silent)
+ printf("SHA384 ...\n");
+ rc = sha384_new_api_test(curr_test);
+ break;
+ case SHA512:
+ if (!silent)
+ printf("SHA512 ...\n");
+ rc = sha512_new_api_test(curr_test);
+ break;
+ default:
+ CRITICAL_ERROR("Unknown algorithm.\n");
+ rc = -1;
+ break;
+ }
+ if (!rc) {
+ if (!silent)
+ printf("... Passed.\n");
+ queue.passed++;
+ }
+ else {
+ printf("error: (%x).\n", rc);
+ queue.failed++;
+ }
+
+ }
+ if (!silent) {
+ printf("[SHA test case results: tests: %u, passed: %u, failed: %u]\n",
+ queue.passed + queue.failed, queue.passed, queue.failed);
+ }
+ else {
+ if (queue.failed == 0)
+ printf("All SHA testcases finished successfully\n");
+ else
+ printf("SHA testcases failed\n");
+ }
+ return EXIT_SUCCESS;
+}
diff --git a/src/tests/libica_sha_test/queue_t.c b/src/tests/libica_sha_test/queue_t.c
new file mode 100644
index 0000000..4df26bc
--- /dev/null
+++ b/src/tests/libica_sha_test/queue_t.c
@@ -0,0 +1,60 @@
+#include <stdlib.h>
+#include <string.h>
+#include "queue_t.h"
+#include "critical_error.h"
+
+test_t new_test_t(void)
+{
+ test_t test;
+
+ test.type = NO_TYPE_SET;
+ test.msg = NULL;
+ test.msg_length = 0;
+ test.msg_digest = NULL;
+ test.msg_digest_length = 0;
+ test.next = NULL;
+
+ return test;
+}
+
+queue_t new_queue_t(void)
+{
+ queue_t queue;
+
+ queue.size = 0;
+ queue.passed = 0;
+ queue.failed = 0;
+ queue.head = NULL;
+ queue.tail = NULL;
+
+ return queue;
+}
+
+void push(queue_t * queue, test_t test)
+{
+ test_t *new_test;
+
+ if ((new_test = (test_t *) malloc(sizeof(test_t))) == NULL)
+ CRITICAL_ERROR("out of memory.");
+
+ new_test->type = test.type;
+ new_test->msg_length = test.msg_length;
+ new_test->msg_digest_length = test.msg_digest_length;
+
+ new_test->msg = (unsigned char *)malloc((size_t) test.msg_length);
+ memcpy(new_test->msg, test.msg, (size_t) test.msg_length);
+
+ new_test->msg_digest =
+ (unsigned char *)malloc((size_t) test.msg_digest_length);
+ memcpy(new_test->msg_digest, test.msg_digest,
+ (size_t) test.msg_digest_length);
+
+ new_test->next = NULL;
+
+ if (queue->head == NULL)
+ queue->head = new_test;
+ else
+ queue->tail->next = new_test;
+ queue->tail = new_test;
+ queue->size++;
+}
diff --git a/src/tests/libica_sha_test/read_rsp.c b/src/tests/libica_sha_test/read_rsp.c
new file mode 100644
index 0000000..ae2c9d6
--- /dev/null
+++ b/src/tests/libica_sha_test/read_rsp.c
@@ -0,0 +1,200 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "ica_api.h"
+#include "queue_t.h"
+#include "critical_error.h"
+#include "read_rsp.h"
+
+static int line_to_bytes(char *line, int length);
+
+int read_test_data(FILE * test_data)
+{
+ char buffer[BUFFER_SIZE];
+ enum { MSG_LENGTH, MSG, MSG_DIGEST } search_term;
+
+ test_t tmp_test = new_test_t();
+ unsigned int current_type = NO_TYPE_SET;
+ unsigned int current_msg_digest_length = NO_LENGTH_SET;
+
+ unsigned int line_number = 0;
+
+ char *tmp = NULL;
+ search_term = MSG_LENGTH;
+
+ while (fgets(buffer, (int)sizeof buffer, test_data) != NULL) {
+
+ line_number++;
+
+ /* remove comments */
+ if ((tmp = memchr(buffer, (int)'#', strlen(buffer))) != NULL)
+ memset(tmp, 0, strlen(tmp));
+
+ /* scan for: type/msg_digest_length */
+ if (((sscanf(buffer, "[L = %u]", &current_msg_digest_length))
+ == 1)
+ || (current_type == NO_TYPE_SET)) {
+ if (tmp_test.type != NO_TYPE_SET) {
+ printf
+ ("error:\nincorrect file format [line %u]: test type mustn't change during test definition. closing file.\n",
+ line_number);
+ return EXIT_FAILURE;
+ }
+ switch (current_msg_digest_length) {
+ case NO_LENGTH_SET:
+ continue;
+ case SHA1_HASH_LENGTH:
+ current_type = SHA1;
+ break;
+ case SHA224_HASH_LENGTH:
+ current_type = SHA224;
+ break;
+ case SHA256_HASH_LENGTH:
+ current_type = SHA256;
+ break;
+ case SHA384_HASH_LENGTH:
+ current_type = SHA384;
+ break;
+ case SHA512_HASH_LENGTH:
+ current_type = SHA512;
+ break;
+ default:
+ CRITICAL_ERROR("this shouldn't happen.");
+ break;
+ }
+ }
+
+ /* scan for: 1st msg_length, 2nd msg, 3rd msg_digest. repeat */
+ switch (search_term) {
+ case MSG_LENGTH:
+ if (sscanf(buffer, "Len = %u", &tmp_test.msg_length) ==
+ 1) {
+ if ((tmp_test.msg_length % 8) != 0) {
+ printf
+ ("error:\nincorrect file format [line %u]: message bit-length must be a multiple of 8. closing file.",
+ line_number);
+ return EXIT_FAILURE;
+ }
+ tmp_test.msg_length /= 8;
+ search_term = MSG;
+ }
+ break;
+ case MSG:
+ if (sscanf(buffer, "Msg = %s", buffer) == 1) {
+ if ((int)strlen(buffer) % 2 != 0) {
+ printf
+ ("error:\nincorrect file format [line %u]: message should be bytes. closing file.\n",
+ line_number);
+ return EXIT_FAILURE;
+ }
+ if (line_to_bytes
+ (buffer,
+ (int)strlen(buffer)) == EXIT_FAILURE) {
+ printf
+ ("error:\nincorrect file format [line %u]: message contains characters different from hex values. closing file.\n",
+ line_number);
+ return EXIT_FAILURE;
+ }
+ if ((tmp_test.msg = (unsigned char *)
+ malloc((size_t) tmp_test.msg_length))
+ == NULL)
+ CRITICAL_ERROR("out of memory.");
+ memcpy(tmp_test.msg, buffer,
+ (size_t) tmp_test.msg_length);
+ search_term = MSG_DIGEST;
+ }
+ break;
+ case MSG_DIGEST:
+ if (sscanf(buffer, "MD = %s", buffer)
+ == 1) {
+ if (((int)strlen(buffer) % 2 != 0)
+ || (((int)strlen(buffer) / 2) !=
+ current_msg_digest_length)) {
+ printf
+ ("error:\nincorrect file format [line %u]: message digest length doesn't match test type. closing file.\n",
+ line_number);
+ free(tmp_test.msg);
+ return EXIT_FAILURE;
+ }
+ if (line_to_bytes
+ (buffer,
+ (int)strlen(buffer)) == EXIT_FAILURE) {
+ printf
+ ("error:\nincorrect file format [line %u]: message digest contains characters different from hex values. closing file.\n",
+ line_number);
+ free(tmp_test.msg);
+ return EXIT_FAILURE;
+ }
+ if ((tmp_test.msg_digest = (unsigned char *)
+ malloc((size_t)
+ current_msg_digest_length))
+ == NULL)
+ CRITICAL_ERROR("out of memory.");
+ memcpy(tmp_test.msg_digest, buffer,
+ (size_t) current_msg_digest_length);
+ tmp_test.type = current_type;
+ tmp_test.msg_digest_length =
+ current_msg_digest_length;
+ push(&queue, tmp_test);
+ free(tmp_test.msg);
+ free(tmp_test.msg_digest);
+ tmp_test = new_test_t();
+ search_term = MSG_LENGTH;
+ }
+ break;
+ default:
+ CRITICAL_ERROR("this shouldn't happen.");
+ break;
+ }
+ if (feof(test_data) != 0) {
+ CRITICAL_ERROR("read error.");
+ }
+ }
+ free(tmp_test.msg);
+ free(tmp_test.msg_digest);
+
+ if (feof(test_data) == 0) {
+ printf("error:\ndidn't reach end of file. closing file.\n");
+ return EXIT_FAILURE;
+ }
+
+ return EXIT_SUCCESS;
+}
+
+static int line_to_bytes(char *line, int length)
+{
+ int i;
+ unsigned char *bytes;
+ if ((bytes = (unsigned char *)
+ malloc((size_t) (length / 2))) == NULL)
+ CRITICAL_ERROR("out of memory.");
+ for (i = 0; i <= ((length / 2) - 1); i++) {
+ if (line[2 * i] >= 'a' && line[2 * i] <= 'f')
+ line[2 * i] = line[2 * i] - 'a' + (char)10;
+ else if (line[2 * i] >= '0' && line[2 * i] <= '9')
+ line[2 * i] = line[2 * i] - '0';
+ else if (line[2 * i] >= 'A' && line[2 * i] <= 'F')
+ line[2 * i] = line[2 * i] - 'A' + (char)10;
+ else {
+ free(bytes);
+ return EXIT_FAILURE;
+ }
+ bytes[i] = (unsigned char)(line[2 * i] * (char)16);
+ if (line[2 * i + 1] >= 'a' && line[2 * i + 1] <= 'f')
+ line[2 * i + 1] = line[2 * i + 1] - (char)87;
+ else if (line[2 * i + 1] >= '0' && line[2 * i + 1] <= '9')
+ line[2 * i + 1] = line[2 * i + 1] - (char)48;
+ else if (line[2 * i + 1] >= 'A' && line[2 * i + 1] <= 'F')
+ line[2 * i + 1] = line[2 * i + 1] - 'A' + (char)10;
+ else {
+ free(bytes);
+ return EXIT_FAILURE;
+ }
+ bytes[i] += (unsigned char)line[2 * i + 1];
+ }
+ memcpy(line, bytes, (size_t) (length / 2));
+ memset(line + length / 2, 0, (size_t) (length / 2 + 1));
+ free(bytes);
+
+ return EXIT_SUCCESS;
+}
diff --git a/src/tests/libica_sha_test/sha_test_vectors/SHA1.txt b/src/tests/libica_sha_test/sha_test_vectors/SHA1.txt
new file mode 100644
index 0000000..a283e3f
--- /dev/null
+++ b/src/tests/libica_sha_test/sha_test_vectors/SHA1.txt
@@ -0,0 +1,36 @@
+# SHA1 tests
+
+[L = 20]
+
+Len = 0
+Msg = 00
+MD = da39a3ee5e6b4b0d3255bfef95601890afd80709
+
+Len = 8
+Msg = 36
+MD = c1dfd96eea8cc2b62785275bca38ac261256e278
+
+Len = 16
+Msg = 195a
+MD = 0a1c2d555bbe431ad6288af5a54f93e0449c9232
+
+Len = 32
+Msg = 549e959e
+MD = b78bae6d14338ffccfd5d5b5674a275f6ef9c717
+
+Len = 64
+Msg = 7e3d7b3eada98866
+MD = 24a2c34b976305277ce58c2f42d5092031572520
+
+Len = 128
+Msg = 3552694cdf663fd94b224747ac406aaf
+MD = a150de927454202d94e656de4c7c0ca691de955d
+
+Len = 256
+Msg = 0321794b739418c24e7c2e565274791c4be749752ad234ed56cb0a6347430c6b
+MD = b89962c94d60f6a332fd60f6f07d4f032a586b76
+
+Len = 512
+Msg = 45927e32ddf801caf35e18e7b5078b7f5435278212ec6bb99df884f49b327c6486feae46ba187dc1cc9145121e1492e6b06e9007394dc33b7748f86ac3207cfe
+MD = a70cfbfe7563dd0e665c7c6715a96a8d756950c0
+
diff --git a/src/tests/libica_sha_test/sha_test_vectors/SHA224.txt b/src/tests/libica_sha_test/sha_test_vectors/SHA224.txt
new file mode 100644
index 0000000..8d6b1d7
--- /dev/null
+++ b/src/tests/libica_sha_test/sha_test_vectors/SHA224.txt
@@ -0,0 +1,39 @@
+# CAVS 11.0
+# "SHA-224 ShortMsg" information
+# SHA-224 tests are configured for BYTE oriented implementations
+# Generated on Tue Mar 15 08:23:36 2011
+
+[L = 28]
+
+Len = 0
+Msg = 00
+MD = d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f
+
+Len = 8
+Msg = 84
+MD = 3cd36921df5d6963e73739cf4d20211e2d8877c19cff087ade9d0e3a
+
+Len = 16
+Msg = 5c7b
+MD = daff9bce685eb831f97fc1225b03c275a6c112e2d6e76f5faf7a36e6
+
+Len = 32
+Msg = 6084347e
+MD = ae57c0a6d49739ba338adfa53bdae063e5c09122b77604780a8eeaa3
+
+Len = 64
+Msg = 5f77b3664823c33e
+MD = bdf21ff325f754157ccf417f4855360a72e8fd117d28c8fe7da3ea38
+
+Len = 128
+Msg = b776708ffb91b3515ac46598ab9fa796
+MD = 427311b1d7ab2488791c4deeb4251d783fe5f9806bfdfb5188c5443d
+
+Len = 256
+Msg = fe1f0fb02c9011f4c8c5905934ed15136771737ce31c5859e67f235fe594f5f6
+MD = bbeaacc632c2a3db2a9b47f157ab54aa27776c6e74cf0bcaa91b06d5
+
+Len = 512
+Msg = a3310ba064be2e14ad32276e18cd0310c933a6e650c3c754d0243c6c61207865b4b65248f66a08edf6e0832689a9dc3a2e5d2095eeea50bd862bac88c8bd318d
+MD = b2a5586d9cbf0baa999157b4af06d88ae08d7c9faab4bc1a96829d65
+
diff --git a/src/tests/libica_sha_test/sha_test_vectors/SHA256.txt b/src/tests/libica_sha_test/sha_test_vectors/SHA256.txt
new file mode 100644
index 0000000..c8bc15b
--- /dev/null
+++ b/src/tests/libica_sha_test/sha_test_vectors/SHA256.txt
@@ -0,0 +1,39 @@
+# CAVS 11.0
+# "SHA-256 ShortMsg" information
+# SHA-256 tests are configured for BYTE oriented implementations
+# Generated on Tue Mar 15 08:23:38 2011
+
+[L = 32]
+
+Len = 0
+Msg = 00
+MD = e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
+
+Len = 8
+Msg = d3
+MD = 28969cdfa74a12c82f3bad960b0b000aca2ac329deea5c2328ebc6f2ba9802c1
+
+Len = 16
+Msg = 11af
+MD = 5ca7133fa735326081558ac312c620eeca9970d1e70a4b95533d956f072d1f98
+
+Len = 32
+Msg = 74ba2521
+MD = b16aa56be3880d18cd41e68384cf1ec8c17680c45a02b1575dc1518923ae8b0e
+
+Len = 64
+Msg = 5738c929c4f4ccb6
+MD = 963bb88f27f512777aab6c8b1a02c70ec0ad651d428f870036e1917120fb48bf
+
+Len = 128
+Msg = 0a27847cdc98bd6f62220b046edd762b
+MD = 80c25ec1600587e7f28b18b1b18e3cdc89928e39cab3bc25e4d4a4c139bcedc4
+
+Len = 256
+Msg = 09fc1accc230a205e4a208e64a8f204291f581a12756392da4b8c0cf5ef02b95
+MD = 4f44c1c7fbebb6f9601829f3897bfd650c56fa07844be76489076356ac1886a4
+
+Len = 512
+Msg = 5a86b737eaea8ee976a0a24da63e7ed7eefad18a101c1211e2b3650c5187c2a8a650547208251f6d4237e661c7bf4c77f335390394c37fa1a9f9be836ac28509
+MD = 42e61e174fbb3897d6dd6cef3dd2802fe67b331953b06114a65c772859dfc1aa
+
diff --git a/src/tests/libica_sha_test/sha_test_vectors/SHA384.txt b/src/tests/libica_sha_test/sha_test_vectors/SHA384.txt
new file mode 100644
index 0000000..6f2acb4
--- /dev/null
+++ b/src/tests/libica_sha_test/sha_test_vectors/SHA384.txt
@@ -0,0 +1,43 @@
+# CAVS 11.0
+# "SHA-384 ShortMsg" information
+# SHA-384 tests are configured for BYTE oriented implementations
+# Generated on Tue Mar 15 08:23:39 2011
+
+[L = 48]
+
+Len = 0
+Msg = 00
+MD = 38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b
+
+Len = 8
+Msg = c5
+MD = b52b72da75d0666379e20f9b4a79c33a329a01f06a2fb7865c9062a28c1de860ba432edfd86b4cb1cb8a75b46076e3b1
+
+Len = 16
+Msg = 6ece
+MD = 53d4773da50d8be4145d8f3a7098ff3691a554a29ae6f652cc7121eb8bc96fd2210e06ae2fa2a36c4b3b3497341e70f0
+
+Len = 32
+Msg = 50e3853d
+MD = 936a3c3991716ba4c413bc03de20f5ce1c63703b3a5bdb6ab558c9ff70d537e46eb4a15d9f2c85e68d8678de5682695e
+
+Len = 64
+Msg = de60275bdafce4b1
+MD = a3d861d866c1362423eb21c6bec8e44b74ce993c55baa2b6640567560ebecdaeda07183dbbbd95e0f522caee5ddbdaf0
+
+Len = 128
+Msg = e1bb967b5d379a4aa39050274d09bd93
+MD = 3b04f96965ad2fbabd4df25d5d8c95589d069c312ee48539090b2d7b495d2446c31eb2b8f8ffb3012bdce065323d9f48
+
+Len = 256
+Msg = be01e520e69f04174ccf95455b1c81445298264d9adc4958574a52843d95b8ba
+MD = c5cf54b8e3105b1c7bf7a43754d915b0947f28b6dc94a019182929b5c848e11441c9e4e90c7449f4c3cd12954f0f5d99
+
+Len = 512
+Msg = 93035d3a13ae1b06dd033e764aca0124961da79c366c6c756bc4bcc11850a3a8d120854f34290fff7c8d6d83531dbdd1e81cc4ed4246e00bd4113ef451334daa
+MD = 8d46cc84b6c2deb206aa5c861798798751a26ee74b1daf3a557c41aebd65adc027559f7cd92b255b374c83bd55568b45
+
+Len = 1024
+Msg = 3bf52cc5ee86b9a0190f390a5c0366a560b557000dbe5115fd9ee11630a62769011575f15881198f227876e8fe685a6939bc8b89fd48a34ec5e71e131462b2886794dffa68ccc6d564733e67ffef25e627c6f4b5460796e3bce67bf58ca6e8e555bc916a8531697ac948b90dc8616f25101db90b50c3d3dbc9e21e42ff387187
+MD = 12b6cb35eda92ee37356ddee77781a17b3d90e563824a984faffc6fdd1693bd7626039635563cfc3b9a2b00f9c65eefd
+
diff --git a/src/tests/libica_sha_test/sha_test_vectors/SHA512.txt b/src/tests/libica_sha_test/sha_test_vectors/SHA512.txt
new file mode 100644
index 0000000..2c5b38d
--- /dev/null
+++ b/src/tests/libica_sha_test/sha_test_vectors/SHA512.txt
@@ -0,0 +1,43 @@
+# CAVS 11.0
+# "SHA-512 ShortMsg" information
+# SHA-512 tests are configured for BYTE oriented implementations
+# Generated on Tue Mar 15 08:23:49 2011
+
+[L = 64]
+
+Len = 0
+Msg = 00
+MD = cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e
+
+Len = 8
+Msg = 21
+MD = 3831a6a6155e509dee59a7f451eb35324d8f8f2df6e3708894740f98fdee23889f4de5adb0c5010dfb555cda77c8ab5dc902094c52de3278f35a75ebc25f093a
+
+Len = 16
+Msg = 9083
+MD = 55586ebba48768aeb323655ab6f4298fc9f670964fc2e5f2731e34dfa4b0c09e6e1e12e3d7286b3145c61c2047fb1a2a1297f36da64160b31fa4c8c2cddd2fb4
+
+Len = 32
+Msg = 23be86d5
+MD = 76d42c8eadea35a69990c63a762f330614a4699977f058adb988f406fb0be8f2ea3dce3a2bbd1d827b70b9b299ae6f9e5058ee97b50bd4922d6d37ddc761f8eb
+
+Len = 64
+Msg = 6f8d58b7cab1888c
+MD = a3941def2803c8dfc08f20c06ba7e9a332ae0c67e47ae57365c243ef40059b11be22c91da6a80c2cff0742a8f4bcd941bdee0b861ec872b215433ce8dcf3c031
+
+Len = 128
+Msg = cd67bd4054aaa3baa0db178ce232fd5a
+MD = 0d8521f8f2f3900332d1a1a55c60ba81d04d28dfe8c504b6328ae787925fe0188f2ba91c3a9f0c1653c4bf0ada356455ea36fd31f8e73e3951cad4ebba8c6e04
+
+Len = 256
+Msg = 8ccb08d2a1a282aa8cc99902ecaf0f67a9f21cffe28005cb27fcf129e963f99d
+MD = 4551def2f9127386eea8d4dae1ea8d8e49b2add0509f27ccbce7d9e950ac7db01d5bca579c271b9f2d806730d88f58252fd0c2587851c3ac8a0e72b4e1dc0da6
+
+Len = 512
+Msg = c1ca70ae1279ba0b918157558b4920d6b7fba8a06be515170f202fafd36fb7f79d69fad745dba6150568db1e2b728504113eeac34f527fc82f2200b462ecbf5d
+MD = 046e46623912b3932b8d662ab42583423843206301b58bf20ab6d76fd47f1cbbcf421df536ecd7e56db5354e7e0f98822d2129c197f6f0f222b8ec5231f3967d
+
+Len = 1024
+Msg = fd2203e467574e834ab07c9097ae164532f24be1eb5d88f1af7748ceff0d2c67a21f4e4097f9d3bb4e9fbf97186e0db6db0100230a52b453d421f8ab9c9a6043aa3295ea20d2f06a2f37470d8a99075f1b8a8336f6228cf08b5942fc1fb4299c7d2480e8e82bce175540bdfad7752bc95b577f229515394f3ae5cec870a4b2f8
+MD = a21b1077d52b27ac545af63b32746c6e3c51cb0cb9f281eb9f3580a6d4996d5c9917d2a6e484627a9d5a06fa1b25327a9d710e027387fc3e07d7c4d14c6086cc
+
diff --git a/src/tests/libica_sha_test/sha_tests.c b/src/tests/libica_sha_test/sha_tests.c
new file mode 100644
index 0000000..f2cae3b
--- /dev/null
+++ b/src/tests/libica_sha_test/sha_tests.c
@@ -0,0 +1,189 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/errno.h>
+#include <fcntl.h>
+#include <string.h>
+#include "ica_api.h"
+#include "queue_t.h"
+#include "sha_tests.h"
+#include "critical_error.h"
+
+static void dump_array(unsigned char *ptr, unsigned int size);
+
+int sha1_new_api_test(test_t * test)
+{
+
+ sha_context_t sha_context;
+ int rc = 0;
+ unsigned char output[LENGTH_SHA_HASH];
+
+ if (test->msg_digest_length != LENGTH_SHA_HASH)
+ CRITICAL_ERROR("this shouldn't happen.");
+
+ rc = (int)ica_sha1(SHA_MSG_PART_ONLY, test->msg_length, test->msg,
+ &sha_context, output);
+
+ if (rc != 0) {
+ printf("ica_sha1 failed with errno %d (0x%x).\n", rc,
+ (unsigned int)rc);
+ return rc;
+ }
+
+ if (!silent) {
+ printf("message digest (new api)\n");
+ dump_array(output, LENGTH_SHA_HASH);
+ }
+
+ if (memcmp(output, test->msg_digest, LENGTH_SHA_HASH) != 0) {
+ printf("output is not what it should be.\n");
+ return 2;
+ }
+ return 0;
+}
+
+int sha224_new_api_test(test_t * test)
+{
+ sha256_context_t sha256_context;
+ int rc = 0;
+ unsigned char output[LENGTH_SHA224_HASH];
+
+ if (test->msg_digest_length != LENGTH_SHA224_HASH)
+ CRITICAL_ERROR("this shouldn't happen.");
+
+ rc = (int)ica_sha224(SHA_MSG_PART_ONLY, test->msg_length, test->msg,
+ &sha256_context, output);
+
+ if (rc != 0) {
+ printf("ica_sha224 failed with errno %d (0x%x).\n", rc,
+ (unsigned int)rc);
+ return rc;
+ }
+
+ if (!silent) {
+ printf("message digest (new api)\n");
+ dump_array(output, LENGTH_SHA224_HASH);
+ }
+ if (memcmp(output, test->msg_digest, LENGTH_SHA224_HASH) != 0) {
+ printf("output is not what it should be.\n");
+ return 2;
+ }
+
+ return 0;
+}
+
+int sha256_new_api_test(test_t * test)
+{
+ sha256_context_t sha256_context;
+ int rc = 0;
+ unsigned char output[LENGTH_SHA256_HASH];
+
+ if (test->msg_digest_length != LENGTH_SHA256_HASH)
+ CRITICAL_ERROR("this shouldn't happen.");
+
+ rc = (int)ica_sha256(SHA_MSG_PART_ONLY, test->msg_length, test->msg,
+ &sha256_context, output);
+
+ if (rc != 0) {
+ printf("ica_sha256 failed with errno %d (0x%x).\n", rc,
+ (unsigned int)rc);
+ return rc;
+ }
+
+ if (!silent) {
+ printf("message digest (new api)\n");
+ dump_array(output, LENGTH_SHA256_HASH);
+ }
+ if (memcmp(output, test->msg_digest, LENGTH_SHA256_HASH) != 0) {
+ printf("output is not what it should be.\n");
+ return 2;
+ }
+
+ return 0;
+}
+
+int sha384_new_api_test(test_t * test)
+{
+ sha512_context_t sha512_context;
+ int rc = 0;
+ unsigned char output[LENGTH_SHA384_HASH];
+
+ if (test->msg_digest_length != LENGTH_SHA384_HASH)
+ CRITICAL_ERROR("this shouldn't happen.");
+
+ rc = (int)ica_sha384(SHA_MSG_PART_ONLY, test->msg_length, test->msg,
+ &sha512_context, output);
+
+ if (rc != 0) {
+ printf("ica_sha384 failed with errno %d (0x%x).\n", rc,
+ (unsigned int)rc);
+ return rc;
+ }
+
+ if (!silent) {
+ printf("message digest (new api)\n");
+ dump_array(output, LENGTH_SHA384_HASH);
+ }
+ if (memcmp(output, test->msg_digest, LENGTH_SHA384_HASH) != 0) {
+ printf("output is not what it should be.\n");
+ return 2;
+ }
+
+ return 0;
+}
+
+int sha512_new_api_test(test_t * test)
+{
+ sha512_context_t sha512_context;
+ int rc = 0;
+ unsigned char output[LENGTH_SHA512_HASH];
+
+ if (test->msg_digest_length != LENGTH_SHA512_HASH)
+ CRITICAL_ERROR("this shouldn't happen.");
+
+ rc = (int)ica_sha512(SHA_MSG_PART_ONLY, test->msg_length, test->msg,
+ &sha512_context, output);
+
+ if (rc != 0) {
+ printf("ica_sha512 failed with errno %d (0x%x).\n", rc,
+ (unsigned int)rc);
+ return rc;
+ }
+
+ if (!silent) {
+ printf("message digest (new api)\n");
+ dump_array(output, LENGTH_SHA512_HASH);
+ }
+ if (memcmp(output, test->msg_digest, LENGTH_SHA512_HASH) != 0) {
+ printf("output is not what it should be.\n");
+ return 2;
+ }
+ return 0;
+}
+
+static void dump_array(unsigned char *ptr, unsigned int size)
+{
+ unsigned char *ptr_end;
+ unsigned char *h;
+ int i = 1, trunc = 0;
+
+ if (size > 64) {
+ trunc = (int)size - 64;
+ size = 64;
+ }
+ h = ptr;
+ ptr_end = ptr + size;
+ while (h < ptr_end) {
+ printf("0x%02x ", (unsigned int)*h);
+ h++;
+ if (i == 8) {
+ if (h != ptr_end)
+ printf("\n");
+ i = 1;
+ } else {
+ ++i;
+ }
+ }
+ printf("\n");
+ if (trunc > 0)
+ printf("... %d bytes not printed\n", trunc);
+}
diff --git a/src/tests/suite.run b/src/tests/suite.run
new file mode 100755
index 0000000..e45d966
--- /dev/null
+++ b/src/tests/suite.run
@@ -0,0 +1,57 @@
+#!/bin/bash
+set -e
+
+# Libica test suite
+#
+# Test output will be stored in suite.out
+#
+silent=${1}
+
+echo -ne 'Starting libica test suite ...\n'
+echo -ne '-------------------------------------------------- (0%)\r'
+./icastats_test $silent
+echo -ne '#------------------------------------------------- (2%)\r'
+./libica_3des_cbc_test $silent
+./libica_3des_cfb_test $silent
+./libica_3des_ctr_test $silent
+./libica_3des_ecb_test $silent
+./libica_3des_ofb_test $silent
+echo -ne '#######------------------------------------------ (15%)\r'
+./libica_aes128_test $silent
+./libica_aes192_test $silent
+./libica_aes256_test $silent
+./libica_aes_cbc_test $silent
+./libica_aes_cfb_test $silent
+./libica_aes_ctr_test $silent
+./libica_aes_ecb_test $silent
+./libica_aes_gcm_test $silent
+./libica_aes_ofb_test $silent
+./libica_aes_xts_test $silent
+echo -ne '###############---------------------------------- (30%)\r'
+./libica_cbccs_test $silent
+./libica_ccm_test $silent
+./libica_cmac_test $silent
+echo -ne '######################--------------------------- (45%)\r'
+./libica_des_cbc_test $silent
+./libica_des_cfb_test $silent
+./libica_des_ctr_test $silent
+./libica_des_ecb_test $silent
+./libica_des_ofb_test $silent
+echo -ne '#############################-------------------- (60%)\r'
+./libica_get_functionlist $silent
+./libica_get_version $silent
+./libica_keygen_test 512 r $silent
+./libica_keygen_test 1024 r $silent
+./libica_keygen_test 2048 r $silent
+./libica_keygen_test 4096 r $silent
+./libica_keygen_test 1234 r $silent
+./libica_rng_test $silent
+echo -ne '#####################################------------ (70%)\r'
+./libica_rsa_test $silent
+./libica_rsa_key_check_test $silent
+echo -ne '############################################----- (80%)\r'
+PARMS="libica_sha_test/sha_test_vectors/*"
+./libica_sha_test/libica_sha_test $silent $PARMS
+#./libica_sha_test/libica_sha_test 'libica_sha_test/sha_test_vectors/*'
+echo -ne '################################################# (100%) Done\r'
+echo -ne '\n'
diff --git a/src/tests/test_mech_list.c b/src/tests/test_mech_list.c
new file mode 100644
index 0000000..de2f107
--- /dev/null
+++ b/src/tests/test_mech_list.c
@@ -0,0 +1,34 @@
+/* This program is released under the Common Public License V1.0
+ *
+ * You should have received a copy of Common Public License V1.0 along with
+ * with this program.
+ */
+
+/**
+ * This is something like what you can expect openCryptoki to do when
+ * it requests a mechanism list from your library.
+ *
+ * Copyright IBM Corp. 2005, 2009
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "mech_types.h"
+#include "ica_api.h"
+
+int
+main(void)
+{
+ struct mech_list_item head;
+ struct mech_list_item *item, *next;
+ generate_pkcs11_mech_list(&head);
+ item = head.next;
+ while (item) {
+ next = item->next;
+ printf("Mechanism type: [%8lX]\n", item->element.mech_type);
+ free(item);
+ item = next;
+ }
+ return 0;
+}
+