summaryrefslogtreecommitdiffstats
path: root/test_crypto_api.c
diff options
context:
space:
mode:
Diffstat (limited to 'test_crypto_api.c')
-rw-r--r--test_crypto_api.c54
1 files changed, 27 insertions, 27 deletions
diff --git a/test_crypto_api.c b/test_crypto_api.c
index 5a20c77..8ff9758 100644
--- a/test_crypto_api.c
+++ b/test_crypto_api.c
@@ -17,7 +17,7 @@
int main(void)
{
int i,j;
-
+
struct blowfish_ctx bf_ctx;
struct twofish_ctx tf_ctx;
struct aes_ctx a_ctx;
@@ -29,7 +29,7 @@ int main(void)
struct sha256_ctx sha256;
struct sha512_ctx sha512;
u32 flags;
-
+
u8 key[]="9_&pass/#word%_0";
const u8 phrase[64] = "this#is/only|a?test,@nothing%more&nothing~less 0123456789 voila";
@@ -43,13 +43,13 @@ int main(void)
const u8 T1[64] = "123456";
const u8 T2[64] = "789101";
-
- printf("crypto api tests\n");
- printf("\n\tused phrase : '%s'\n\tlength : %d\n\n",phrase,strlen((char*)phrase));
-
+
+ printf("crypto api tests\n");
+ printf("\n\tused phrase : '%s'\n\tlength : %zu\n\n",phrase,strlen((char*)phrase));
+
memset(encrypt,0,sizeof(encrypt));
memset(encrypt,0,sizeof(decrypt));
-
+
/* test blowfish */
printf("_Blwofish: A 64-Bit Block Cipher_ by Bruce Schneier...\n");
if(blowfish_setkey(&bf_ctx, key, strlen((char*)key), &flags)!=0){
@@ -66,7 +66,7 @@ int main(void)
}
printf("\n\tdecrypted => '%s'\n\n",decrypt);
assert(memcmp(phrase,decrypt,64)==0);
-
+
memset(encrypt,0,sizeof(encrypt));
memset(encrypt,0,sizeof(decrypt));
@@ -86,7 +86,7 @@ int main(void)
blowfish_decrypt(&bf_ctx, decrypt+strlen((char*)T1), encrypt+BF_BLOCK_SIZE);
printf("\n\tdecrypted => '%s'\n\n",decrypt);
assert(memcmp(decrypt,"123456789101",12)==0);
-
+
memset(encrypt,0,sizeof(encrypt));
memset(encrypt,0,sizeof(decrypt));
@@ -98,7 +98,7 @@ int main(void)
fprintf(stderr,"twofish_setkey error.\n");
_exit(1);
}
-
+
for(i=0; i<sizeof(phrase)/TF_BLOCK_SIZE; i++){
twofish_encrypt(&tf_ctx, encrypt, phrase+i*TF_BLOCK_SIZE);
twofish_decrypt(&tf_ctx, decrypt+i*TF_BLOCK_SIZE, encrypt);
@@ -110,7 +110,7 @@ int main(void)
printf("\n");
printf("\n\tdecrypted => '%s'\n\n",decrypt);
assert(memcmp(phrase,decrypt,64)==0);
-
+
memset(encrypt,0,sizeof(encrypt));
memset(encrypt,0,sizeof(decrypt));
@@ -130,7 +130,7 @@ int main(void)
twofish_decrypt(&bf_ctx, decrypt+strlen((char*)T1), encrypt+TF_BLOCK_SIZE);
printf("\n\tdecrypted => '%s'\n\n",decrypt);
assert(memcmp(decrypt,"123456789101",12)==0);
-
+
memset(encrypt,0,sizeof(encrypt));
memset(encrypt,0,sizeof(decrypt));
@@ -141,7 +141,7 @@ int main(void)
fprintf(stderr,"aes_setkey error.\n");
_exit(1);
}
-
+
for(i=0; i<sizeof(phrase)/AES_BLOCK_SIZE; i++){
aes_encrypt(&a_ctx, encrypt, phrase+i*AES_BLOCK_SIZE);
aes_decrypt(&a_ctx, decrypt+i*AES_BLOCK_SIZE, encrypt);
@@ -153,7 +153,7 @@ int main(void)
printf("\n");
printf("\n\tdecrypted => '%s'\n\n",decrypt);
assert(memcmp(phrase,decrypt,64)==0);
-
+
memset(encrypt,0,sizeof(encrypt));
memset(encrypt,0,sizeof(decrypt));
@@ -173,17 +173,17 @@ int main(void)
aes_decrypt(&a_ctx, decrypt+strlen((char*)T1), encrypt+AES_BLOCK_SIZE);
printf("\n\tdecrypted => '%s'\n\n",decrypt);
assert(memcmp(decrypt,"123456789101",12)==0);
-
+
memset(encrypt,0,sizeof(encrypt));
memset(encrypt,0,sizeof(decrypt));
-
+
/* test des */
printf("_des \n");
if(des_setkey(&d_ctx, key, strlen((char*)key),&flags)!=0){
fprintf(stderr,"des_setkey error.\n");
_exit(1);
}
-
+
for(i=0; i<sizeof(phrase)/DES_BLOCK_SIZE; i++){
des_encrypt(&d_ctx, encrypt, phrase+i*DES_BLOCK_SIZE);
des_decrypt(&d_ctx, decrypt+i*DES_BLOCK_SIZE, encrypt);
@@ -195,7 +195,7 @@ int main(void)
printf("\n");
printf("\n\tdecrypted => '%s'\n\n",decrypt);
assert(memcmp(phrase,decrypt,64)==0);
-
+
memset(encrypt,0,sizeof(encrypt));
memset(encrypt,0,sizeof(decrypt));
@@ -215,7 +215,7 @@ int main(void)
des_decrypt(&d_ctx, decrypt+strlen((char*)T1), encrypt+DES_BLOCK_SIZE);
printf("\n\tdecrypted => '%s'\n\n",decrypt);
assert(memcmp(decrypt,"123456789101",12)==0);
-
+
memset(encrypt,0,sizeof(encrypt));
memset(encrypt,0,sizeof(decrypt));
@@ -225,7 +225,7 @@ int main(void)
fprintf(stderr,"des_setkey error.\n");
_exit(1);
}
-
+
for(i=0; i<sizeof(phrase)/DES3_EDE_BLOCK_SIZE; i++){
des3_ede_encrypt(&d3_ctx, encrypt, phrase+i*DES3_EDE_BLOCK_SIZE);
des3_ede_decrypt(&d3_ctx, decrypt+i*DES3_EDE_BLOCK_SIZE, encrypt);
@@ -237,7 +237,7 @@ int main(void)
printf("\n");
printf("\n\tdecrypted => '%s'\n\n",decrypt);
assert(memcmp(phrase,decrypt,64)==0);
-
+
memset(encrypt,0,sizeof(encrypt));
memset(encrypt,0,sizeof(decrypt));
@@ -257,7 +257,7 @@ int main(void)
des3_ede_decrypt(&d3_ctx, decrypt+strlen((char*)T1), encrypt+DES3_EDE_BLOCK_SIZE);
printf("\n\tdecrypted => '%s'\n\n",decrypt);
assert(memcmp(decrypt,"123456789101",12)==0);
-
+
memset(encrypt,0,sizeof(encrypt));
memset(encrypt,0,sizeof(decrypt));
@@ -271,7 +271,7 @@ int main(void)
for(i=0; i<MD4_DIGEST_SIZE; i++)
printf("%02x",md4_hash[i]);
printf("\n\n");
-
+
/* md5 */
printf("MD5: one way hash with a %d bits output digest.\n",MD5_DIGEST_SIZE);
md5_init(&md5);
@@ -282,7 +282,7 @@ int main(void)
for(i=0; i<MD5_DIGEST_SIZE; i++)
printf("%02x",md5_hash[i]);
printf("\n\n");
-
+
/* sha1 */
printf("SHA1: one way hash with a %d bits output digest.\n",SHA1_DIGEST_SIZE);
sha1_init(&sha1);
@@ -293,7 +293,7 @@ int main(void)
for(i=0; i<SHA1_DIGEST_SIZE; i++)
printf("%02x",sha1_hash[i]);
printf("\n\n");
-
+
/* sha256 */
printf("SHA256: one way hash with a %d bits output digest.\n",SHA256_DIGEST_SIZE);
sha256_init(&sha256);
@@ -304,7 +304,7 @@ int main(void)
for(i=0; i<SHA256_DIGEST_SIZE; i++)
printf("%02x",sha256_hash[i]);
printf("\n\n");
-
+
/* sha512 */
printf("SHA512: one way hash with a %d bits output digest.\n",SHA512_DIGEST_SIZE);
sha512_init(&sha512);
@@ -320,6 +320,6 @@ int main(void)
printf("\n\n");
printf("tests ok\n");
-
+
return 0;
}