aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatej Pjafjar <badbytes@freehaven.net>2002-07-19 14:08:44 +0000
committerMatej Pjafjar <badbytes@freehaven.net>2002-07-19 14:08:44 +0000
commitf617a4e733a2af9bcba679be7821eca32ca0cbf6 (patch)
treea52a4f7209eaf447fd007b822737d04a39d1581f
parent5fc0bcf303deaf2b82f97c016f5dcefbc8021e95 (diff)
downloadtor-f617a4e733a2af9bcba679be7821eca32ca0cbf6.tar
tor-f617a4e733a2af9bcba679be7821eca32ca0cbf6.tar.gz
Test suite for onion.c - currently tests encrypt_onion() and decrypt_onion().
svn:r59
-rw-r--r--src/or/test_onion.c180
1 files changed, 180 insertions, 0 deletions
diff --git a/src/or/test_onion.c b/src/or/test_onion.c
new file mode 100644
index 000000000..b1affaf91
--- /dev/null
+++ b/src/or/test_onion.c
@@ -0,0 +1,180 @@
+#include "or.h"
+
+int main(int argc, char *argv[])
+{
+ /* START VARIABLES */
+ unsigned char onion_plain[268]; /* test onion */
+ /* onion_passx = ciphertext after x passes */
+ unsigned char onion_pass1[268];
+ unsigned char onion_pass2[268];
+ unsigned char onion_pass3[268];
+ unsigned char onion_pass4[268];
+ unsigned char onion_pass5[268];
+ unsigned char onion_pass6[268];
+
+ /* RSA keys for the six layers */
+ RSA *key1 = NULL;
+ RSA *key2 = NULL;
+ RSA *key3 = NULL;
+ RSA *key4 = NULL;
+ RSA *key5 = NULL;
+ RSA *key6 = NULL;
+
+ /* END VARIABLES */
+
+ ERR_load_crypto_strings();
+ printf("onion.c test suite ...\n");
+
+ printf("\nGenerating 6 RSA keys ...\n");
+ key1 = RSA_generate_key(1024,65535, NULL, NULL);
+ key2 = RSA_generate_key(1024,65535, NULL, NULL);
+ key3 = RSA_generate_key(1024,65535, NULL, NULL);
+ key4 = RSA_generate_key(1024,65535, NULL, NULL);
+ key5 = RSA_generate_key(1024,65535, NULL, NULL);
+ key6 = RSA_generate_key(1024,65535, NULL, NULL);
+
+ if (!key1 || !key2 || !key3 || !key4 || !key5 || !key6) {
+ printf("\nFailed!\n\n");
+ exit(1);
+ }
+ printf("\ndone.\n");
+
+ printf("\nGenerating onion ...\n");
+ memset((void *)onion_plain, 1, 28);
+ memset((void *)(onion_plain+28), 2, 28);
+ memset((void *)(onion_plain+56), 3, 28);
+ memset((void *)(onion_plain+84), 4, 28);
+ memset((void *)(onion_plain+112), 5, 28);
+ memset((void *)(onion_plain+140), 6, 28);
+ memset((void *)(onion_plain+168), 9, 100);
+
+ printf("\ndone.\n");
+
+ printf("\nEncrypting first layer ...\n");
+ memcpy((void *)onion_pass1, (void *)onion_plain, 268);
+ if (!encrypt_onion((onion_layer_t *)(onion_pass1+140), 128, key1)) {
+ printf("\nFailed!\n\n");
+ exit(1);
+ }
+ printf("\ndone.\n");
+
+ printf("\nEncrypting second layer ...\n");
+ memcpy((void *)onion_pass2, (void *)onion_pass1, 268);
+ if (!encrypt_onion((onion_layer_t *)(onion_pass2+112), 156, key2)) {
+ printf("\nFailed!\n\n");
+ exit(1);
+ }
+ printf("\ndone.\n");
+
+ printf("\nEncrypting third layer ...\n");
+ memcpy((void *)onion_pass3, (void *)onion_pass2, 268);
+ if (!encrypt_onion((onion_layer_t *)(onion_pass3+84), 184, key3)) {
+ printf("\nFailed!\n\n");
+ exit(1);
+ }
+ printf("\ndone.\n");
+
+ printf("\nEncrypting fourth layer ...\n");
+ memcpy((void *)onion_pass4, (void *)onion_pass3, 268);
+ if (!encrypt_onion((onion_layer_t *)(onion_pass4+56), 212, key4)) {
+ printf("\nFailed!\n\n");
+ exit(1);
+ }
+ printf("\ndone.\n");
+
+ printf("\nEncrypting fifth layer ...\n");
+ memcpy((void *)onion_pass5, (void *)onion_pass4, 268);
+ if (!encrypt_onion((onion_layer_t *)(onion_pass5+28), 240, key5)) {
+ printf("\nFailed!\n\n");
+ exit(1);
+ }
+ printf("\ndone.\n");
+
+ printf("\nEncrypting sixth layer ...\n");
+ memcpy((void *)onion_pass6, (void *)onion_pass5, 268);
+ if (!encrypt_onion((onion_layer_t *)onion_pass6, 268, key6)) {
+ printf("\nFailed!\n\n");
+ exit(1);
+ }
+ printf("\ndone.\n");
+
+ printf("\nDecrypting sixth layer ...\n");
+ if (!decrypt_onion((onion_layer_t *)onion_pass6, 268, key6)) {
+ printf("\nFailed!\n\n");
+ exit(1);
+ }
+ printf("\ndone.\n");
+ printf("\nChecking validity ...\n");
+ if (memcmp((void *)onion_pass6, (void *)onion_pass5, 268)) {
+ printf("\nTEST FAILED!\n\n");
+ exit(1);
+ }
+ printf("\nTEST PASSED.\n");
+
+ printf("\nDecrypting fifth layer ...\n");
+ if (!decrypt_onion((onion_layer_t *)(onion_pass5+28), 240, key5)) {
+ printf("\nFailed!\n\n");
+ exit(1);
+ }
+ printf("\ndone.\n");
+ printf("\nChecking validity ...\n");
+ if (memcmp((void *)onion_pass5, (void *)onion_pass4, 268)) {
+ printf("\nTEST FAILED!\n\n");
+ exit(1);
+ }
+ printf("\nTEST PASSED.\n");
+
+ printf("\nDecrypting fourth layer ...\n");
+ if (!decrypt_onion((onion_layer_t *)(onion_pass4+56), 212, key4)) {
+ printf("\nFailed!\n\n");
+ exit(1);
+ }
+ printf("\ndone.\n");
+ printf("\nChecking validity ...\n");
+ if (memcmp((void *)onion_pass4, (void *)onion_pass3, 268)) {
+ printf("\nTEST FAILED!\n\n");
+ exit(1);
+ }
+ printf("\nTEST PASSED.\n");
+
+ printf("\nDecrypting third layer ...\n");
+ if (!decrypt_onion((onion_layer_t *)(onion_pass3+84), 184, key3)) {
+ printf("\nFailed!\n\n");
+ exit(1);
+ }
+ printf("\ndone.\n");
+ printf("\nChecking validity ...\n");
+ if (memcmp((void *)(onion_pass3), (void *)(onion_pass2), 268)) {
+ printf("\nTEST FAILED!\n\n");
+ exit(1);
+ }
+ printf("\nTEST PASSED.\n");
+
+ printf("\nDecrypting second layer ...\n");
+ if (!decrypt_onion((onion_layer_t *)(onion_pass2+112), 156, key2)) {
+ printf("\nFailed!\n\n");
+ exit(1);
+ }
+ printf("\ndone.\n");
+ printf("\nChecking validity ...\n");
+ if (memcmp((void *)(onion_pass1), (void *)(onion_pass2), 268)) {
+ printf("\nTEST FAILED!\n\n");
+ exit(1);
+ }
+ printf("\nTEST PASSED.\n");
+
+ printf("\nDecrypting first layer ...\n");
+ if (!decrypt_onion((onion_layer_t *)(onion_pass1+140), 128, key1)) {
+ printf("\nFailed!\n\n");
+ exit(1);
+ }
+ printf("\ndone.\n");
+ printf("\nChecking validity ...\n");
+ if (memcmp((void *)(onion_plain), (void *)(onion_pass1), 268)) {
+ printf("\nTEST FAILED!\n\n");
+ exit(1);
+ }
+ printf("\nTEST PASSED.\n");
+ ERR_free_strings();
+ return 0;
+}