[or-cvs] Helper functions to perform our truncated base64 encoding o...

Nick Mathewson nickm at seul.org
Sun Sep 18 02:19:01 UTC 2005


Update of /home/or/cvsroot/tor/src/common
In directory moria:/tmp/cvs-serv6805/src/common

Modified Files:
	crypto.c crypto.h 
Log Message:
Helper functions to perform our truncated base64 encoding on hexdigests.

Index: crypto.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/common/crypto.c,v
retrieving revision 1.155
retrieving revision 1.156
diff -u -d -r1.155 -r1.156
--- crypto.c	9 Sep 2005 22:07:15 -0000	1.155
+++ crypto.c	18 Sep 2005 02:18:59 -0000	1.156
@@ -1688,6 +1688,31 @@
   return ret;
 }
 
+int
+digest_to_base64(char *d64, const char *digest)
+{
+  char buf[256];
+  base64_encode(buf, sizeof(buf), digest, DIGEST_LEN);
+  buf[BASE64_DIGEST_LEN] = '\0';
+  memcpy(d64, buf, BASE64_DIGEST_LEN+1);
+  return 0;
+}
+
+int
+digest_from_base64(char *digest, const char *d64)
+{
+  char buf_in[BASE64_DIGEST_LEN+3];
+  char buf[256];
+  if (strlen(d64) != BASE64_DIGEST_LEN)
+    return -1;
+  memcpy(buf_in, d64, BASE64_DIGEST_LEN);
+  memcpy(buf_in+BASE64_DIGEST_LEN, "=\n\0", 3);
+  if (base64_decode(buf, sizeof(buf), buf_in, strlen(buf_in)) != DIGEST_LEN)
+    return -1;
+  memcpy(digest, buf, DIGEST_LEN);
+  return 0;
+}
+
 /** Implements base32 encoding as in rfc3548.  Limitation: Requires
  * that srclen*8 is a multiple of 5.
  */

Index: crypto.h
===================================================================
RCS file: /home/or/cvsroot/tor/src/common/crypto.h,v
retrieving revision 1.65
retrieving revision 1.66
diff -u -d -r1.65 -r1.66
--- crypto.h	20 Jun 2005 18:56:34 -0000	1.65
+++ crypto.h	18 Sep 2005 02:18:59 -0000	1.66
@@ -24,6 +24,9 @@
 /** Length of our DH keys. */
 #define DH_BYTES (1024/8)
 
+/* DOCDOC */
+#define BASE64_DIGEST_LEN 27
+
 /** Constants used to indicate no padding for public-key encryption */
 #define PK_NO_PADDING         60000
 /** Constants used to indicate PKCS1 padding for public-key encryption */
@@ -155,6 +158,9 @@
 #define BASE32_CHARS "abcdefghijklmnopqrstuvwxyz234567"
 void base32_encode(char *dest, size_t destlen, const char *src, size_t srclen);
 
+int digest_to_base64(char *d64, const char *digest);
+int digest_from_base64(char *digest, const char *d64);
+
 #define S2K_SPECIFIER_LEN 9
 void secret_to_key(char *key_out, size_t key_out_len, const char *secret,
                    size_t secret_len, const char *s2k_specifier);



More information about the tor-commits mailing list