[or-cvs] Not every RSA decrypt should warn on failure.

Nick Mathewson nickm at seul.org
Wed May 12 19:30:30 UTC 2004


Update of /home/or/cvsroot/src/common
In directory moria.mit.edu:/tmp/cvs-serv25990/src/common

Modified Files:
	crypto.c crypto.h 
Log Message:
Not every RSA decrypt should warn on failure.

Index: crypto.c
===================================================================
RCS file: /home/or/cvsroot/src/common/crypto.c,v
retrieving revision 1.91
retrieving revision 1.92
diff -u -d -r1.91 -r1.92
--- crypto.c	10 May 2004 10:27:52 -0000	1.91
+++ crypto.c	12 May 2004 19:30:28 -0000	1.92
@@ -534,7 +534,7 @@
  * write the result to <b>to</b>, and return the number of bytes
  * written.  On failure, return -1.
  */
-int crypto_pk_private_decrypt(crypto_pk_env_t *env, const unsigned char *from, int fromlen, unsigned char *to, int padding)
+int crypto_pk_private_decrypt(crypto_pk_env_t *env, const unsigned char *from, int fromlen, unsigned char *to, int padding, int warnOnFailure)
 {
   int r;
   tor_assert(env && from && to && env->key);
@@ -545,7 +545,8 @@
   r = RSA_private_decrypt(fromlen, (unsigned char*)from, to, env->key,
                              crypto_get_rsa_padding(padding));
   if (r<0) {
-    crypto_log_errors(LOG_WARN, "performing RSA decryption");
+    crypto_log_errors(warnOnFailure?LOG_WARN:LOG_INFO,
+                      "performing RSA decryption");
     return -1;
   }
   return r;
@@ -714,7 +715,7 @@
 int crypto_pk_private_hybrid_decrypt(crypto_pk_env_t *env,
                                      const unsigned char *from,
                                      int fromlen, unsigned char *to,
-                                     int padding)
+                                     int padding, int warnOnFailure)
 {
   int overhead, pkeylen, outlen, r;
   crypto_cipher_env_t *cipher = NULL;
@@ -724,17 +725,15 @@
   pkeylen = crypto_pk_keysize(env);
 
   if (fromlen <= pkeylen) {
-    return crypto_pk_private_decrypt(env,from,fromlen,to,padding);
+    return crypto_pk_private_decrypt(env,from,fromlen,to,padding,warnOnFailure);
   }
-  outlen = crypto_pk_private_decrypt(env,from,pkeylen,buf,padding);
+  outlen = crypto_pk_private_decrypt(env,from,pkeylen,buf,padding,warnOnFailure);
   if (outlen<0) {
-    /* this is only log-levelinfo, because when we're decrypting
-     * onions, we try several keys to see which will work */
-    log_fn(LOG_INFO, "Error decrypting public-key data");
+    log_fn(warnOnFailure?LOG_WARN:LOG_INFO, "Error decrypting public-key data");
     return -1;
   }
   if (outlen < CIPHER_KEY_LEN) {
-    log_fn(LOG_WARN, "No room for a symmetric key");
+    log_fn(warnOnFailure?LOG_WARN:LOG_INFO, "No room for a symmetric key");
     return -1;
   }
   cipher = crypto_create_init_cipher(buf, 0);

Index: crypto.h
===================================================================
RCS file: /home/or/cvsroot/src/common/crypto.h,v
retrieving revision 1.47
retrieving revision 1.48
diff -u -d -r1.47 -r1.48
--- crypto.h	10 May 2004 07:54:13 -0000	1.47
+++ crypto.h	12 May 2004 19:30:28 -0000	1.48
@@ -68,7 +68,7 @@
 int crypto_pk_keysize(crypto_pk_env_t *env);
 
 int crypto_pk_public_encrypt(crypto_pk_env_t *env, const unsigned char *from, int fromlen, unsigned char *to, int padding);
-int crypto_pk_private_decrypt(crypto_pk_env_t *env, const unsigned char *from, int fromlen, unsigned char *to, int padding);
+int crypto_pk_private_decrypt(crypto_pk_env_t *env, const unsigned char *from, int fromlen, unsigned char *to, int padding, int warnOnFailure);
 int crypto_pk_private_sign(crypto_pk_env_t *env, const unsigned char *from, int fromlen, unsigned char *to);
 int crypto_pk_private_sign_digest(crypto_pk_env_t *env, const unsigned char *from, int fromlen, unsigned char *to);
 int crypto_pk_public_checksig(crypto_pk_env_t *env, const unsigned char *from, int fromlen, unsigned char *to);
@@ -78,7 +78,8 @@
                                     unsigned char *to, int padding, int force);
 int crypto_pk_private_hybrid_decrypt(crypto_pk_env_t *env,
                                      const unsigned char *from, int fromlen,
-                                     unsigned char *to,int padding);
+                                     unsigned char *to,int padding,
+                                     int warnOnFailure);
 
 int crypto_pk_asn1_encode(crypto_pk_env_t *pk, char *dest, int dest_len);
 crypto_pk_env_t *crypto_pk_asn1_decode(const char *str, int len);



More information about the tor-commits mailing list