[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] Tests for crypto; more tests for buffers
Update of /home/or/cvsroot/src/common
In directory moria.mit.edu:/tmp/cvs-serv27379/src/common
Modified Files:
crypto.c test.h
Log Message:
Tests for crypto; more tests for buffers
Index: crypto.c
===================================================================
RCS file: /home/or/cvsroot/src/common/crypto.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- crypto.c 19 Mar 2003 21:27:21 -0000 1.12
+++ crypto.c 16 Apr 2003 15:24:09 -0000 1.13
@@ -13,6 +13,7 @@
#include <stdlib.h>
#include <assert.h>
+#include <stdio.h>
#include "crypto.h"
#include "../or/or.h"
@@ -290,10 +291,10 @@
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 @@
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_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;
Index: test.h
===================================================================
RCS file: /home/or/cvsroot/src/common/test.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- test.h 15 Apr 2003 19:10:18 -0000 1.2
+++ test.h 16 Apr 2003 15:24:09 -0000 1.3
@@ -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
/*