diff options
author | Nick Mathewson <nickm@torproject.org> | 2003-04-16 15:24:09 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2003-04-16 15:24:09 +0000 |
commit | acc33c18e2ea0e18cb0b2970a14c32ddbd7db833 (patch) | |
tree | 176142d3f232f5c309d78f0c88d41ee3906753d0 /src/common | |
parent | e1d37ed6abffca3bab3f43794a850709f8c4fe77 (diff) | |
download | tor-acc33c18e2ea0e18cb0b2970a14c32ddbd7db833.tar.gz tor-acc33c18e2ea0e18cb0b2970a14c32ddbd7db833.zip |
Tests for crypto; more tests for buffers
svn:r234
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/crypto.c | 14 | ||||
-rw-r--r-- | src/common/test.h | 10 |
2 files changed, 19 insertions, 5 deletions
diff --git a/src/common/crypto.c b/src/common/crypto.c index 3ddb854f64..626e2c48e3 100644 --- a/src/common/crypto.c +++ b/src/common/crypto.c @@ -13,6 +13,7 @@ #include <stdlib.h> #include <assert.h> +#include <stdio.h> #include "crypto.h" #include "../or/or.h" @@ -290,10 +291,10 @@ int crypto_pk_read_private_key_from_filename(crypto_pk_env_t *env, unsigned char if (strspn(keyfile,CONFIG_LEGAL_FILENAME_CHARACTERS) == strlen(keyfile)) /* filename contains legal characters only */ { /* open the keyfile */ - f_pr=fopen(keyfile,"r"); + f_pr=fopen(keyfile,"rb"); if (!f_pr) return -1; - + /* read the private key */ retval = crypto_pk_read_private_key_from_file(env, f_pr); fclose(f_pr); @@ -460,8 +461,9 @@ int crypto_pk_set_key(crypto_pk_env_t *env, unsigned char *key) case CRYPTO_PK_RSA: if (!env->key) return -1; - memcpy((void *)env->key, (void *)key, sizeof(RSA)); /* XXX BUG XXX you can't memcpy an RSA, it's got a bunch of subpointers */ + assert(0); + memcpy((void *)env->key, (void *)key, sizeof(RSA)); break; default : return -1; @@ -530,9 +532,11 @@ int crypto_pk_public_encrypt(crypto_pk_env_t *env, unsigned char *from, int from int crypto_pk_private_decrypt(crypto_pk_env_t *env, unsigned char *from, int fromlen, unsigned char *to, int padding) { assert(env && from && to); - + switch(env->type) { - case CRYPTO_PK_RSA: + case CRYPTO_PK_RSA: + if (!(((RSA*)env->key)->p)) + return -1; return RSA_private_decrypt(fromlen, from, to, (RSA *)env->key, padding); default: return -1; diff --git a/src/common/test.h b/src/common/test.h index fe37100940..8be3afd77e 100644 --- a/src/common/test.h +++ b/src/common/test.h @@ -88,6 +88,16 @@ return; \ } STMT_END +#define test_memneq(expr1, expr2, len) \ + STMT_BEGIN if(memcmp(expr1,expr2,len)) { printf("."); } else { \ + printf("\nFile %s: line %d (%s): Assertion failed: (%s!=%s)\n", \ + __FILE__, \ + __LINE__, \ + __PRETTY_FUNCTION__, \ + #expr1, #expr2); \ + return; \ + } STMT_END + #endif /* |