[or-cvs] Add new functions to wrap digest and sign/checksig.

Nick Mathewson nickm at seul.org
Thu Apr 1 22:10:35 UTC 2004


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

Modified Files:
	crypto.c crypto.h 
Log Message:
Add new functions to wrap digest and sign/checksig.

Index: crypto.c
===================================================================
RCS file: /home/or/cvsroot/src/common/crypto.c,v
retrieving revision 1.64
retrieving revision 1.65
diff -u -d -r1.64 -r1.65
--- crypto.c	1 Apr 2004 20:04:54 -0000	1.64
+++ crypto.c	1 Apr 2004 22:10:33 -0000	1.65
@@ -656,6 +656,44 @@
   }
 }
 
+/* Return 0 if sig is a correct signature for SHA1(data).  Else return -1.
+ */
+int crypto_pk_public_checksig_digest(crypto_pk_env_t *env, unsigned char *data, int datalen, unsigned char *sig, int siglen)
+{
+  char digest[CRYPTO_SHA1_DIGEST_LEN];
+  char buf[1024];
+  int r;
+
+  assert(env && data && sig);
+
+  if (crypto_SHA_digest(data,datalen,digest)<0) {
+    log_fn(LOG_WARN, "couldn't compute digest");
+    return -1;
+  }
+  r = crypto_pk_public_checksig(env,sig,siglen,buf);
+  if (r != CRYPTO_SHA1_DIGEST_LEN) {
+    log_fn(LOG_WARN, "Invalid signature");
+    return -1;
+  }
+  if (memcmp(buf, digest, CRYPTO_SHA1_DIGEST_LEN)) {
+    log_fn(LOG_WARN, "Signature mismatched with digest.");
+    return -1;
+  }
+
+  return 0;
+}
+
+/* Fill 'to' with a signature of SHA1(from).
+ */
+int crypto_pk_private_sign_digest(crypto_pk_env_t *env, unsigned char *from, int fromlen, unsigned char *to)
+{
+  char digest[CRYPTO_SHA1_DIGEST_LEN];
+  if (crypto_SHA_digest(from,fromlen,digest)<0)
+    return 0;
+  return crypto_pk_private_sign(env,digest,CRYPTO_SHA1_DIGEST_LEN,to);
+}
+
+
 /* Perform a hybrid (public/secret) encryption on 'fromlen' bytes of data
  * from 'from', with padding type 'padding', storing the results on 'to'.
  *

Index: crypto.h
===================================================================
RCS file: /home/or/cvsroot/src/common/crypto.h,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -d -r1.32 -r1.33
--- crypto.h	1 Apr 2004 20:04:54 -0000	1.32
+++ crypto.h	1 Apr 2004 22:10:33 -0000	1.33
@@ -58,7 +58,9 @@
 int crypto_pk_public_encrypt(crypto_pk_env_t *env, unsigned char *from, int fromlen, unsigned char *to, int padding);
 int crypto_pk_private_decrypt(crypto_pk_env_t *env, unsigned char *from, int fromlen, unsigned char *to, int padding);
 int crypto_pk_private_sign(crypto_pk_env_t *env, unsigned char *from, int fromlen, unsigned char *to);
+int crypto_pk_private_sign_digest(crypto_pk_env_t *env, unsigned char *from, int fromlen, unsigned char *to);
 int crypto_pk_public_checksig(crypto_pk_env_t *env, unsigned char *from, int fromlen, unsigned char *to);
+int crypto_pk_public_checksig_digest(crypto_pk_env_t *env, unsigned char *data, int datalen, unsigned char *sig, int siglen);
 int crypto_pk_public_hybrid_encrypt(crypto_pk_env_t *env, unsigned char *from,
 				    int fromlen, unsigned char *to,
 				    int padding);



More information about the tor-commits mailing list