gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r327 - in GNUnet: . src/applications/fs src/applications/fs


From: grothoff
Subject: [GNUnet-SVN] r327 - in GNUnet: . src/applications/fs src/applications/fs/ecrs src/applications/identity src/applications/session src/include src/server src/util
Date: Sat, 26 Feb 2005 16:58:01 -0800 (PST)

Author: grothoff
Date: 2005-02-26 16:58:00 -0800 (Sat, 26 Feb 2005)
New Revision: 327

Modified:
   GNUnet/src/applications/fs/ecrs/download.c
   GNUnet/src/applications/fs/ecrs/ecrs.c
   GNUnet/src/applications/fs/ecrs/keyspace.c
   GNUnet/src/applications/fs/ecrs/namespace.c
   GNUnet/src/applications/fs/ecrs/search.c
   GNUnet/src/applications/fs/ecrs_core.c
   GNUnet/src/applications/identity/hostkey.c
   GNUnet/src/applications/session/connect.c
   GNUnet/src/include/gnunet_util.h
   GNUnet/src/server/connection.c
   GNUnet/src/server/handler.c
   GNUnet/src/util/hashing.c
   GNUnet/src/util/hashingtest.c
   GNUnet/src/util/hostkey_gcrypt.c
   GNUnet/src/util/hostkey_openssl.c
   GNUnet/src/util/hostkeytest.c
   GNUnet/src/util/kblockkey.c
   GNUnet/src/util/kblockkey_test.c
   GNUnet/src/util/symcipher_gcrypt.c
   GNUnet/src/util/symcipher_openssl.c
   GNUnet/src/util/symciphertest.c
   GNUnet/todo
Log:
changing PrivateKey to be an opaque struct

Modified: GNUnet/src/applications/fs/ecrs/download.c
===================================================================
--- GNUnet/src/applications/fs/ecrs/download.c  2005-02-26 23:08:34 UTC (rev 
326)
+++ GNUnet/src/applications/fs/ecrs/download.c  2005-02-27 00:58:00 UTC (rev 
327)
@@ -794,18 +794,18 @@
                          unsigned int size,
                          const HashCode160 * hashcode,
                          char * result){
-  unsigned char iv[BLOWFISH_BLOCK_LENGTH]; /* initial value */
+  INITVECTOR iv;
   SESSIONKEY skey;
 
   GNUNET_ASSERT((data!=NULL) && (hashcode != NULL) && (result != NULL));
   /* get key and init value from the hash code */
   hashToKey(hashcode,
            &skey,
-           &iv[0]);
+           &iv);
   return decryptBlock(&skey,
                      data,
                      size,
-                     iv,
+                     &iv,
                      result);
 }
 

Modified: GNUnet/src/applications/fs/ecrs/ecrs.c
===================================================================
--- GNUnet/src/applications/fs/ecrs/ecrs.c      2005-02-26 23:08:34 UTC (rev 
326)
+++ GNUnet/src/applications/fs/ecrs/ecrs.c      2005-02-27 00:58:00 UTC (rev 
327)
@@ -34,15 +34,15 @@
                         unsigned int len) {
   char * tmp;
   SESSIONKEY skey;
-  char iv[16];
+  INITVECTOR iv;
 
-  hashToKey(hc, &skey, iv);
+  hashToKey(hc, &skey, &iv);
   tmp = MALLOC(len);
   GNUNET_ASSERT(len ==
                encryptBlock(data,
                             len,
                             &skey,
-                            iv,
+                            &iv,
                             tmp));
   memcpy(data, tmp, len);
   FREE(tmp);
@@ -53,15 +53,15 @@
                         unsigned int len) {
   char * tmp;
   SESSIONKEY skey;
-  char iv[16];
-
-  hashToKey(hc, &skey, iv);
+  INITVECTOR iv;
+  
+  hashToKey(hc, &skey, &iv);
   tmp = MALLOC(len);
   GNUNET_ASSERT(len ==
                decryptBlock(&skey,
                             data,
                             len,
-                            iv,
+                            &iv,
                             tmp));
   memcpy(data, tmp, len);
   FREE(tmp);

Modified: GNUnet/src/applications/fs/ecrs/keyspace.c
===================================================================
--- GNUnet/src/applications/fs/ecrs/keyspace.c  2005-02-26 23:08:34 UTC (rev 
326)
+++ GNUnet/src/applications/fs/ecrs/keyspace.c  2005-02-27 00:58:00 UTC (rev 
327)
@@ -59,7 +59,7 @@
   int ret;
   unsigned int size;
   unsigned int mdsize;
-  PrivateKey pk;
+  struct PrivateKey * pk;
   HashCode160 hc;
   char * dstURI;
   KBlock * kb;

Modified: GNUnet/src/applications/fs/ecrs/namespace.c
===================================================================
--- GNUnet/src/applications/fs/ecrs/namespace.c 2005-02-26 23:08:34 UTC (rev 
326)
+++ GNUnet/src/applications/fs/ecrs/namespace.c 2005-02-27 00:58:00 UTC (rev 
327)
@@ -102,7 +102,7 @@
                         struct ECRS_URI ** rootURI) {
   char * fileName;
   char tmp;
-  PrivateKey hk;
+  struct PrivateKey * hk;
   PrivateKeyEncoded * hke;
   char * dst;
   unsigned short len;
@@ -113,7 +113,7 @@
   int ret;
   unsigned int size;
   unsigned int mdsize;
-  PrivateKey pk;
+  struct PrivateKey * pk;
   NBlock * nb;
   KNBlock * knb;
   char ** keywords;
@@ -266,7 +266,7 @@
  */
 int ECRS_testNamespaceExists(const char * name,
                             const HashCode160 * hc) {
-  PrivateKey hk;
+  struct PrivateKey * hk;
   char * fileName;
   PrivateKeyEncoded * hke;
   char * dst;
@@ -336,7 +336,7 @@
   int ret;
   unsigned int size;
   unsigned int mdsize;
-  PrivateKey hk;
+  struct PrivateKey * hk;
   SBlock * sb;
   HashCode160 namespace;
   char * dstURI;

Modified: GNUnet/src/applications/fs/ecrs/search.c
===================================================================
--- GNUnet/src/applications/fs/ecrs/search.c    2005-02-26 23:08:34 UTC (rev 
326)
+++ GNUnet/src/applications/fs/ecrs/search.c    2005-02-27 00:58:00 UTC (rev 
327)
@@ -178,7 +178,7 @@
   case ksk: {
       HashCode160 hc;
       HashCode160 query;
-      PrivateKey pk;
+      struct PrivateKey * pk;
       PublicKey pub;
       int i;
 

Modified: GNUnet/src/applications/fs/ecrs_core.c
===================================================================
--- GNUnet/src/applications/fs/ecrs_core.c      2005-02-26 23:08:34 UTC (rev 
326)
+++ GNUnet/src/applications/fs/ecrs_core.c      2005-02-27 00:58:00 UTC (rev 
327)
@@ -48,7 +48,7 @@
                    Datastore_Value ** value) {
   HashCode160 hc;
   SESSIONKEY skey;
-  unsigned char iv[BLOWFISH_BLOCK_LENGTH];  /* initial value */
+  INITVECTOR iv;  /* initial value */
   Datastore_Value * val;
   DBlock * db;
 
@@ -57,7 +57,7 @@
   hash(&data[1], len - sizeof(DBlock), &hc);
   hashToKey(&hc,
            &skey,
-           &iv[0]);
+           &iv);
   val = MALLOC(sizeof(Datastore_Value) + len);
   val->size = htonl(sizeof(Datastore_Value) + len);
   val->type = htonl(D_BLOCK);
@@ -70,7 +70,7 @@
                == encryptBlock(&data[1],
                                len - sizeof(DBlock),
                                &skey,
-                               iv,
+                               &iv,
                                &db[1]));
   hash(&db[1],
        len - sizeof(DBlock),
@@ -111,7 +111,7 @@
   const char * data;
   HashCode160 hc;
   SESSIONKEY skey;
-  unsigned char iv[BLOWFISH_BLOCK_LENGTH];
+  INITVECTOR iv;
 
   GNUNET_ASSERT(len >= sizeof(DBlock));
   data = (const char*) &db[1];
@@ -119,12 +119,12 @@
   hash(data, len, &hc);
   hashToKey(&hc,
            &skey,
-           &iv[0]);
+           &iv);
   tmp = MALLOC(len);  
   GNUNET_ASSERT(len == encryptBlock(data,
                                    len,
                                    &skey,
-                                   &iv[0],
+                                   &iv,
                                    tmp));
   hash(tmp, len, query);
   FREE(tmp);

Modified: GNUnet/src/applications/identity/hostkey.c
===================================================================
--- GNUnet/src/applications/identity/hostkey.c  2005-02-26 23:08:34 UTC (rev 
326)
+++ GNUnet/src/applications/identity/hostkey.c  2005-02-27 00:58:00 UTC (rev 
327)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2001, 2002 Christian Grothoff (and other contributing authors)
+     (C) 2001, 2002, 2005 Christian Grothoff (and other contributing authors)
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -29,23 +29,25 @@
 #include "gnunet_util.h"
 #include "hostkey.h"
 
+/**
+ * Name of the file in which we store the hostkey.
+ */
 #define HOSTKEYFILE ".hostkey"
 
-
 /**
- * The SECRET hostkey. Keep local, never export outside of this
+ * The SECRET hostkey.  Keep local, never export outside of this
  * module!
  */
-static PrivateKey hostkey;
+static struct PrivateKey * hostkey;
 
 /**
  * The public hostkey
  */
 static PublicKey * publicKey;
 
-
 /**
  * Get the public key of the host
+ *
  * @return reference to the public key. Do not free it!
  */
 const PublicKey * getPublicPrivateKey() {
@@ -68,6 +70,7 @@
 
 /**
  * Decrypt a given block with the hostkey. 
+ *
  * @param block the data to decrypt, encoded as returned by encrypt, not 
consumed
  * @param result pointer to a location where the result can be stored
  * @param max the maximum number of bits to store for the result, if
@@ -78,9 +81,9 @@
                void * result,
                unsigned int max) {
   return decryptPrivateKey(hostkey, 
-                       block, 
-                       result, 
-                       max);
+                          block, 
+                          result, 
+                          max);
 }
 
 void initPrivateKey() {
@@ -108,7 +111,9 @@
   if (res == sizeof(unsigned short)) {
     encPrivateKey = (PrivateKeyEncoded*) MALLOC(ntohs(len));
     if (ntohs(len) != 
-       readFile(hostkeyfile, ntohs(len), encPrivateKey)) {
+       readFile(hostkeyfile,
+                ntohs(len),
+                encPrivateKey)) {
       FREE(encPrivateKey);
       LOG(LOG_WARNING,
          _("Existing hostkey in file '%s' failed format check, creating new 
hostkey.\n"),

Modified: GNUnet/src/applications/session/connect.c
===================================================================
--- GNUnet/src/applications/session/connect.c   2005-02-26 23:08:34 UTC (rev 
326)
+++ GNUnet/src/applications/session/connect.c   2005-02-27 00:58:00 UTC (rev 
327)
@@ -192,7 +192,7 @@
     GNUNET_ASSERT(-1 != encryptBlock(pt,
                                     size,
                                     sk,
-                                    (unsigned char*) &msg->signature,
+                                    (const INITVECTOR*) &msg->signature,
                                     &((char*)msg)[sizeof(SKEY_Message)]));
     FREE(pt);
   } 
@@ -503,7 +503,7 @@
     GNUNET_ASSERT(-1 != decryptBlock(&key,
                                     
&((char*)sessionkeySigned)[sizeof(SKEY_Message)],
                                     size,
-                                    (unsigned char*) 
&sessionkeySigned->signature,
+                                    (const INITVECTOR*) 
&sessionkeySigned->signature,
                                     plaintext));
     pos = 0;
     /* find pings & pongs! */

Modified: GNUnet/src/include/gnunet_util.h
===================================================================
--- GNUnet/src/include/gnunet_util.h    2005-02-26 23:08:34 UTC (rev 326)
+++ GNUnet/src/include/gnunet_util.h    2005-02-27 00:58:00 UTC (rev 327)
@@ -58,7 +58,7 @@
  * frequently, even between different CVS versions.
  */
 
-#define GNUNET_UTIL_VERSION 0x00060900
+#define GNUNET_UTIL_VERSION 0x00060901
 
 /**
  * We use an unsigned short in the protocol header, thus: 
@@ -73,13 +73,13 @@
 /**
  * Named constants for return values.
  */
-#define OK 1
+#define OK      1
 #define SYSERR -1
-#define YES 1
-#define NO 0
+#define YES     1
+#define NO      0
 
 /**
- * constants to specify time 
+ * @brief constants to specify time 
  */
 #define cronMILLIS ((cron_t)1)
 #define cronSECONDS ((cron_t)(1000 * cronMILLIS))
@@ -91,7 +91,7 @@
 #define cronYEARS ((cron_t)(365 * cronDAYS))
 
 /** 
- * log levels 
+ * @brief log levels 
  */
 #define LOG_NOTHING    0
 #define LOG_FATAL      1
@@ -105,31 +105,16 @@
 #define LOG_EVERYTHING 9
 
 /**
- * length of the sessionkey in bytes (128 BIT sessionkey) 
+ * @brief length of the sessionkey in bytes (128 BIT sessionkey) 
  */
 #define SESSIONKEY_LEN (128/8)
 
 /**
- * size of blowfish key in bytes 
+ * @brief Default names of the configuration files.
  */
-#define BF_KEYSIZE 16
-
-/** 
- * 64 bit, blowfish 
- */
-#define BLOWFISH_BLOCK_LENGTH 8 
-
-/**
- * Default names of the configuration files.
- */
 #define DEFAULT_CLIENT_CONFIG_FILE "~/.gnunet/gnunet.conf"
 #define DEFAULT_DAEMON_CONFIG_FILE "/etc/gnunet.conf"
 
-/* Names for the values of the `has_arg' field of `struct GNoption'.  */
-#define        no_argument             0
-#define required_argument      1
-#define optional_argument      2
-
 /**
  * @brief Length of RSA encrypted data (2048 bit)
  *
@@ -184,13 +169,11 @@
 
 /* **************** structs ****************** */
 
-/* FIXME: use 'struct PrivateKey' instead! */
-typedef struct {
-  void * internal;
-} _PrivateKey;
+/**
+ * The private information of an RSA key pair.
+ */
+struct PrivateKey;
 
-typedef _PrivateKey *PrivateKey;
-
 /**
  * Header for all Client-Server communications.
  */
@@ -345,8 +328,18 @@
   unsigned char encoding[33];
 } EncName;
 
+/**
+ * GNUnet mandates a certain format for the encoding
+ * of private RSA key information that is provided
+ * by the RSA implementations.  This format is used
+ * to serialize a private RSA key (typically when
+ * writing it to disk).  
+ */
 typedef struct {
-  unsigned short len; /*  in big-endian! */
+  /** 
+   * Total size of the structure, in bytes, in big-endian! 
+   */
+  unsigned short len; 
   unsigned short sizen;/*  in big-endian! */
   unsigned short sizee;/*  in big-endian! */
   unsigned short sized;/*  in big-endian! */
@@ -354,32 +347,41 @@
   unsigned short sizeq;/*  in big-endian! */
   unsigned short sizedmp1;/*  in big-endian! */
   unsigned short sizedmq1;/*  in big-endian! */
+  /* followed by the actual values */
 } PrivateKeyEncoded;
 
 /**
- * Generic version of PrivateKeyEncoded with field for accessing the end of
- * the data structure (use the other version for allocation)
+ * @brief an RSA signature
  */
 typedef struct {
-  PrivateKeyEncoded host_key_encoded;
-
-  /**
-   * Address of this field used for finding the end of the structure
-   */
-  unsigned char key[1];
-} PrivateKeyEncoded_GENERIC;
-
-typedef struct {
   unsigned char sig[RSA_ENC_LEN]; 
 } Signature;
 
+/**
+ * @brief A public key.
+ */
 typedef struct {
-  unsigned short len; /*  in big-endian, must be RSA_KEY_LEN+2 */
-  unsigned short sizen;  /*  in big-endian! */ 
+  /**
+   * In big-endian, must be RSA_KEY_LEN+2 
+   */
+  unsigned short len; 
+  /**
+   * Size of n in key; in big-endian! 
+   */ 
+  unsigned short sizen;  
+  /**
+   * The key itself, contains n followed by e.
+   */
   unsigned char key[RSA_KEY_LEN];
-  unsigned short padding; /* padding (must be 0) */
+  /**
+   * Padding (must be 0) 
+   */
+  unsigned short padding; 
 } PublicKey;
 
+/**
+ * RSA Encrypted data.
+ */
 typedef struct {
   unsigned char encoding[RSA_ENC_LEN];
 } RSAEncryptedData;
@@ -451,7 +453,7 @@
 } GNUNET_TCP_SOCKET;
 
 /** 
- * type for session keys 
+ * @brief type for session keys 
  */
 typedef struct {
   unsigned char key[SESSIONKEY_LEN];
@@ -459,6 +461,16 @@
 } SESSIONKEY;
 
 /**
+ * @brief IV for sym cipher
+ *
+ * NOTE: must be smaller (!) in size than the
+ * HashCode160.
+ */
+typedef struct {
+  unsigned char iv[SESSIONKEY_LEN/2];
+} INITVECTOR;
+
+/**
  * Method to parse the command line. The results
  * are to be stored in the configuration module.
  * @param argc the number of arguments
@@ -472,6 +484,9 @@
                                       const char * dirName,
                                       void * data);
 
+/**
+ * @brief description of a command line option (helptext)
+ */
 typedef struct {
   char shortArg;
   char * longArg;
@@ -1157,7 +1172,7 @@
 int encryptBlock(const void * block, 
                 unsigned short len,
                 const SESSIONKEY * sessionkey,
-                const unsigned char * iv,
+                const INITVECTOR * iv,
                 void * result);
 
 /**
@@ -1172,7 +1187,7 @@
 int decryptBlock(const SESSIONKEY * sessionkey, 
                 const void * block,
                 unsigned short size,
-                const unsigned char * iv,
+                const INITVECTOR * iv,
                 void * result);
 
 #define SEMAPHORE_NEW(value) semaphore_new_(value, __FILE__, __LINE__)
@@ -1402,7 +1417,7 @@
  */
 void hashToKey(const HashCode160 * hc,
               SESSIONKEY * skey,
-              unsigned char * iv);
+              INITVECTOR * iv);
 
 /**
  * Obtain a bit from a hashcode.
@@ -1433,25 +1448,25 @@
 /**
  * create a new hostkey. Callee must free return value.
  */
-PrivateKey makePrivateKey(); 
+struct PrivateKey * makePrivateKey(); 
 
 /**
  * Deterministically (!) create a hostkey using only the
  * given HashCode as input to the PRNG.
  */
-PrivateKey makeKblockKey(const HashCode160 * input);
+struct PrivateKey * makeKblockKey(const HashCode160 * input);
 
 /**
  * Free memory occupied by hostkey
  * @param hostkey pointer to the memory to free
  */
-void freePrivateKey(PrivateKey hostkey); 
+void freePrivateKey(struct PrivateKey * hostkey); 
 
 /**
  * Extract the public key of the host.
  * @param result where to write the result.
  */
-void getPublicKey(const PrivateKey hostkey,
+void getPublicKey(const struct PrivateKey * hostkey,
                  PublicKey * result);
 
 /**
@@ -1460,7 +1475,7 @@
  * @param hostkey the hostkey to use
  * @returns encoding of the private key.
  */
-PrivateKeyEncoded * encodePrivateKey(const PrivateKey hostkey);
+PrivateKeyEncoded * encodePrivateKey(const struct PrivateKey * hostkey);
 
 /**
  * Decode the private key from the file-format back
@@ -1468,11 +1483,12 @@
  * @param encoded the encoded hostkey
  * @returns the decoded hostkey
  */
-PrivateKey decodePrivateKey(const PrivateKeyEncoded * encoding);
+struct PrivateKey * decodePrivateKey(const PrivateKeyEncoded * encoding);
 
 /**
- * Encrypt a block with the public key of another
- * host that uses the same cyper.
+ * Encrypt a block with the public key of another host that uses the
+ * same cyper.
+ *
  * @param block the block to encrypt
  * @param size the size of block
  * @param publicKey the encoded public key used to encrypt
@@ -1486,26 +1502,28 @@
 
 /**
  * Decrypt a given block with the hostkey. 
- * @param hostkey the hostkey to use
+ *
+ * @param key the key to use
  * @param block the data to decrypt, encoded as returned by encrypt, not 
consumed
  * @param result pointer to a location where the result can be stored
  * @param max the maximum number of bits to store for the result, if
  *        the decrypted block is bigger, an error is returned
  * @returns the size of the decrypted block, -1 on error
  */
-int decryptPrivateKey(const PrivateKey hostkey, 
+int decryptPrivateKey(const struct PrivateKey * key, 
                      const RSAEncryptedData * block,
                      void * result,
                      unsigned int max);
 
 /**
  * Sign a given block.
+ *
  * @param block the data to sign, first unsigned short_SIZE bytes give length
  * @param size how many bytes to sign
  * @param result where to write the signature
  * @return SYSERR on error, OK on success
  */
-int sign(const PrivateKey hostkey, 
+int sign(const struct PrivateKey * key, 
         unsigned short size,
         const void * block,
         Signature * result);

Modified: GNUnet/src/server/connection.c
===================================================================
--- GNUnet/src/server/connection.c      2005-02-26 23:08:34 UTC (rev 326)
+++ GNUnet/src/server/connection.c      2005-02-27 00:58:00 UTC (rev 327)
@@ -1140,7 +1140,7 @@
   encryptBlock(&p2pHdr->sequenceNumber,
               p - sizeof(HashCode160),
               &be->skey_local,
-              (const char*) encryptedMsg, /* IV */
+              (const INITVECTOR*) encryptedMsg, /* IV */
               &((P2P_Message*)encryptedMsg)->sequenceNumber);
 #if DEBUG_CONNECTION
   LOG(LOG_DEBUG,
@@ -1900,7 +1900,7 @@
   res = decryptBlock(&be->skey_remote, 
                     &msg->sequenceNumber,
                     size - sizeof(HashCode160),
-                    (const unsigned char*) &msg->hash, /* IV */
+                    (const INITVECTOR*) &msg->hash, /* IV */
                     tmp);
   hash(tmp,
        size - sizeof(HashCode160),

Modified: GNUnet/src/server/handler.c
===================================================================
--- GNUnet/src/server/handler.c 2005-02-26 23:08:34 UTC (rev 326)
+++ GNUnet/src/server/handler.c 2005-02-27 00:58:00 UTC (rev 327)
@@ -311,7 +311,7 @@
     memcpy(&cpart,
           &msg[pos],
           sizeof(p2p_HEADER));
-    plen = htons(cpart->size);
+    plen = htons(cpart.size);
     if (pos + plen > size) {
       IFLOG(LOG_WARNING,
            hash2enc(&sender->hashPubKey,

Modified: GNUnet/src/util/hashing.c
===================================================================
--- GNUnet/src/util/hashing.c   2005-02-26 23:08:34 UTC (rev 326)
+++ GNUnet/src/util/hashing.c   2005-02-27 00:58:00 UTC (rev 327)
@@ -384,18 +384,20 @@
  */
 void hashToKey(const HashCode160 * hc,
               SESSIONKEY * skey,
-              unsigned char * iv) {
+              INITVECTOR * iv) {
   memcpy(skey,
         hc,
         sizeof(SESSIONKEY));
   skey->crc32 = htonl(crc32N(skey, 
                             SESSIONKEY_LEN));
-  memcpy(iv, 
-        &(((char *)hc)[BF_KEYSIZE]), 
-        BLOWFISH_BLOCK_LENGTH/2);
-  memcpy(&iv[BLOWFISH_BLOCK_LENGTH/2], 
-        &(((char *)hc)[BF_KEYSIZE]),
-         BLOWFISH_BLOCK_LENGTH/2);
+  memcpy(&iv->iv[0], 
+        &(((char *)hc)[sizeof(SESSIONKEY)]), 
+        sizeof(HashCode160) - sizeof(SESSIONKEY));
+  GNUNET_ASSERT(sizeof(HashCode160) - sizeof(SESSIONKEY) ==
+               sizeof(INITVECTOR) - (sizeof(HashCode160) - 
sizeof(SESSIONKEY)));
+  memcpy(&iv->iv[sizeof(HashCode160) - sizeof(SESSIONKEY)],
+        &(((char *)hc)[sizeof(SESSIONKEY)]), 
+        sizeof(HashCode160) - sizeof(SESSIONKEY));
 }
 
 

Modified: GNUnet/src/util/hashingtest.c
===================================================================
--- GNUnet/src/util/hashingtest.c       2005-02-26 23:08:34 UTC (rev 326)
+++ GNUnet/src/util/hashingtest.c       2005-02-27 00:58:00 UTC (rev 327)
@@ -7,6 +7,11 @@
 #include "gnunet_util.h"
 #include "platform.h"
 
+#if ! USE_OPENSSL
+void initLockingGcrypt();
+void doneLockingGcrypt();
+#endif
+
 static int test(int number) {
   HashCode160 h1;
   HashCode160 h2;
@@ -35,9 +40,14 @@
 
 int main(int argc, char * argv[]) {
   int failureCount = 0;
-  
+
+#if ! USE_OPENSSL
+  initLockingGcrypt();
+#endif
   failureCount += testEncoding();
-
+#if ! USE_OPENSSL
+  doneLockingGcrypt();
+#endif
   if (failureCount == 0)
     return 0;
   else 

Modified: GNUnet/src/util/hostkey_gcrypt.c
===================================================================
--- GNUnet/src/util/hostkey_gcrypt.c    2005-02-26 23:08:34 UTC (rev 326)
+++ GNUnet/src/util/hostkey_gcrypt.c    2005-02-27 00:58:00 UTC (rev 327)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2001, 2002, 2003, 2004 Christian Grothoff (and other contributing 
authors)
+     (C) 2001, 2002, 2003, 2004, 2005 Christian Grothoff (and other 
contributing authors)
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -36,9 +36,13 @@
 #include "locking_gcrypt.h"
 
 #include <gcrypt.h>
-#define HOSTKEY(a) ((gcry_sexp_t)(a)->internal)
-#define HOSTKEYL(a) ((a)->internal)
 
+/**
+ * The private information of an RSA key pair.
+ */
+struct PrivateKey {
+  gcry_sexp_t sexp;
+};
 
 #define HOSTKEY_LEN 2048
 #define EXTRA_CHECKS YES
@@ -81,8 +85,8 @@
 /**
  * This HostKey implementation uses RSA.
  */
-PrivateKey makePrivateKey() {
-  PrivateKey ret;
+struct PrivateKey * makePrivateKey() {
+  struct PrivateKey * ret;
   gcry_sexp_t s_key;
   gcry_sexp_t s_keyparam;
   int rc;
@@ -114,17 +118,17 @@
   }
 #endif
   unlockGcrypt();
-  ret = MALLOC(sizeof(PrivateKey));
-  HOSTKEYL(ret) = s_key;
+  ret = MALLOC(sizeof(struct PrivateKey));
+  ret->sexp = s_key;
   return ret;
 }
 
 /**
  * Free memory occupied by hostkey
  */
-void freePrivateKey(PrivateKey hostkey) {
+void freePrivateKey(struct PrivateKey * hostkey) {
   lockGcrypt();
-  gcry_sexp_release(HOSTKEY(hostkey));
+  gcry_sexp_release(hostkey->sexp);
   unlockGcrypt();
   FREE(hostkey);
 }
@@ -185,7 +189,7 @@
  * @param hostkey the hostkey to extract into the result.
  * @param result where to write the result.
  */
-void getPublicKey(PrivateKey hostkey,
+void getPublicKey(const struct PrivateKey * hostkey,
                  PublicKey * result) {
   gcry_mpi_t skey[2];
   int size;
@@ -193,17 +197,17 @@
   
   lockGcrypt();
   rc = key_from_sexp(skey, 
-                    HOSTKEY(hostkey), 
+                    hostkey->sexp, 
                     "public-key", 
                     "ne");
   if (rc)
     rc = key_from_sexp(skey, 
-                      HOSTKEY(hostkey), 
+                      hostkey->sexp, 
                       "private-key", 
                       "ne");    
   if (rc)
     rc = key_from_sexp(skey, 
-                      HOSTKEY(hostkey), 
+                      hostkey->sexp, 
                       "rsa", 
                       "ne");    
   if (rc) 
@@ -239,10 +243,13 @@
 
 
 /**
- * Internal: publicKey => RSA-Key
+ * Internal: publicKey => RSA-Key.
+ *
+ * Note that the return type is not actually a private
+ * key but rather an sexpression for the public key!
  */
-static PrivateKey public2PrivateKey(const PublicKey * publicKey) {
-  PrivateKey ret;
+static struct PrivateKey * public2PrivateKey(const PublicKey * publicKey) {
+  struct PrivateKey * ret;
   gcry_sexp_t result;
   gcry_mpi_t n;
   gcry_mpi_t e;
@@ -292,8 +299,8 @@
     return NULL;
   }  
   unlockGcrypt();
-  ret = MALLOC(sizeof(PrivateKey));
-  HOSTKEYL(ret) = result;
+  ret = MALLOC(sizeof(struct PrivateKey));
+  ret->sexp = result;
   return ret;
 }
 
@@ -303,7 +310,7 @@
  * @returns encoding of the private key.
  *    The first 4 bytes give the size of the array, as usual.
  */
-PrivateKeyEncoded * encodePrivateKey(PrivateKey hostkey) {
+PrivateKeyEncoded * encodePrivateKey(const struct PrivateKey * hostkey) {
   /* libgcrypt */
 
   PrivateKeyEncoded * retval;
@@ -316,7 +323,7 @@
 
   lockGcrypt();    
 #if EXTRA_CHECKS
-  if (gcry_pk_testkey(HOSTKEY(hostkey))) {
+  if (gcry_pk_testkey(hostkey->sexp)) {
     BREAK();
     unlockGcrypt();
     return NULL;
@@ -325,32 +332,32 @@
 
   memset(pkv, 0, sizeof(gcry_mpi_t) * 6);
   rc = key_from_sexp(pkv,
-                    HOSTKEY(hostkey),
+                    hostkey->sexp,
                     "private-key",
                     "nedpqu");
   if (rc)
     rc = key_from_sexp(pkv,
-                      HOSTKEY(hostkey),
+                      hostkey->sexp,
                       "rsa",
                       "nedpqu");
   if (rc) 
     rc = key_from_sexp(pkv,
-                      HOSTKEY(hostkey),
+                      hostkey->sexp,
                       "private-key",
                       "nedpq");
   if (rc)
     rc = key_from_sexp(pkv,
-                      HOSTKEY(hostkey),
+                      hostkey->sexp,
                       "rsa",
                       "nedpq");
   if (rc) 
     rc = key_from_sexp(pkv,
-                      HOSTKEY(hostkey),
+                      hostkey->sexp,
                       "private-key",
                       "ned");
   if (rc)
     rc = key_from_sexp(pkv,
-                      HOSTKEY(hostkey),
+                      hostkey->sexp,
                       "rsa",
                       "ned");
   if (rc) {
@@ -387,34 +394,34 @@
   retval->len = htons(size);
   i = 0;
   retval->sizen = htons(sizes[0]);
-  memcpy(&((PrivateKeyEncoded_GENERIC*)retval)->key[i], 
+  memcpy(&((char*)(&retval[1]))[i], 
         pbu[0],
         sizes[0]);
   i += sizes[0];
   retval->sizee = htons(sizes[1]);
-  memcpy(&((PrivateKeyEncoded_GENERIC*)retval)->key[i], 
+  memcpy(&((char*)(&retval[1]))[i], 
         pbu[1],
         sizes[1]);
   i += sizes[1];
   retval->sized = htons(sizes[2]);
-  memcpy(&((PrivateKeyEncoded_GENERIC*)retval)->key[i], 
+  memcpy(&((char*)(&retval[1]))[i], 
         pbu[2],
         sizes[2]);
   i += sizes[2];
   /* swap p and q! */
   retval->sizep = htons(sizes[4]);
-  memcpy(&((PrivateKeyEncoded_GENERIC*)retval)->key[i], 
+  memcpy(&((char*)(&retval[1]))[i], 
         pbu[4],
         sizes[4]);
   i += sizes[4];
   retval->sizeq = htons(sizes[3]);
-  memcpy(&((PrivateKeyEncoded_GENERIC*)retval)->key[i], 
+  memcpy(&((char*)(&retval[1]))[i], 
         pbu[3],
         sizes[3]);
   i += sizes[3];
   retval->sizedmp1 = htons(0);
   retval->sizedmq1 = htons(0);
-  memcpy(&((PrivateKeyEncoded_GENERIC*)retval)->key[i], 
+  memcpy(&((char*)(&retval[1]))[i], 
         pbu[5],
         sizes[5]);
   for (i=0;i<6;i++) {
@@ -431,8 +438,8 @@
  * Decode the private key from the file-format back
  * to the "normal", internal format.
  */
-PrivateKey decodePrivateKey(const PrivateKeyEncoded * encoding) {
-  PrivateKey ret;
+struct PrivateKey * decodePrivateKey(const PrivateKeyEncoded * encoding) {
+  struct PrivateKey * ret;
   gcry_sexp_t res;
   gcry_mpi_t n,e,d,p,q,u;
   int rc;
@@ -444,7 +451,7 @@
   lockGcrypt();
   rc = gcry_mpi_scan(&n,
                     GCRYMPI_FMT_USG,
-                    &((PrivateKeyEncoded_GENERIC*)encoding)->key[pos],
+                    &((char*)(&encoding[1]))[pos], 
                     size,
                     &size);
   pos += ntohs(encoding->sizen);
@@ -456,7 +463,7 @@
   size = ntohs(encoding->sizee);
   rc = gcry_mpi_scan(&e,
                     GCRYMPI_FMT_USG,
-                    &((PrivateKeyEncoded_GENERIC*)encoding)->key[pos],
+                    &((char*)(&encoding[1]))[pos], 
                     size,
                     &size);
   pos += ntohs(encoding->sizee);
@@ -469,7 +476,7 @@
   size = ntohs(encoding->sized);
   rc = gcry_mpi_scan(&d,
                     GCRYMPI_FMT_USG,
-                    &((PrivateKeyEncoded_GENERIC*)encoding)->key[pos],
+                    &((char*)(&encoding[1]))[pos], 
                     size,
                     &size);
   pos += ntohs(encoding->sized);
@@ -485,7 +492,7 @@
   if (size > 0) {
     rc = gcry_mpi_scan(&q,
                       GCRYMPI_FMT_USG,
-                      &((PrivateKeyEncoded_GENERIC*)encoding)->key[pos],
+                      &((char*)(&encoding[1]))[pos], 
                       size,
                       &size);
     pos += ntohs(encoding->sizep);
@@ -503,7 +510,7 @@
   if (size > 0) {
     rc = gcry_mpi_scan(&p,
                       GCRYMPI_FMT_USG,
-                      &((PrivateKeyEncoded_GENERIC*)encoding)->key[pos],
+                      &((char*)(&encoding[1]))[pos], 
                       size,
                       &size);
     pos += ntohs(encoding->sizeq);
@@ -526,7 +533,7 @@
   if (size > 0) {
     rc = gcry_mpi_scan(&u,
                       GCRYMPI_FMT_USG,
-                      &((PrivateKeyEncoded_GENERIC*)encoding)->key[pos],
+                      &((char*)(&encoding[1]))[pos], 
                       size,
                       &size);
     if (rc) {
@@ -584,8 +591,8 @@
     return NULL;
   }
 #endif
-  ret = MALLOC(sizeof(PrivateKey));
-  HOSTKEYL(ret) = res;
+  ret = MALLOC(sizeof(struct PrivateKey));
+  ret->sexp = res;
   unlockGcrypt();
   return ret;
 }
@@ -606,7 +613,7 @@
                      RSAEncryptedData * target) {
   gcry_sexp_t result;
   gcry_sexp_t data;
-  PrivateKey pubkey;
+  struct PrivateKey * pubkey;
   gcry_mpi_t val;
   gcry_mpi_t rval;
   size_t isize;
@@ -640,7 +647,7 @@
     return SYSERR;
   }
   
-  rc = gcry_pk_encrypt(&result, data, HOSTKEY(pubkey));
+  rc = gcry_pk_encrypt(&result, data, pubkey->sexp);
   if (rc) {
     LOG_GCRY(LOG_ERROR, "gcry_pk_encrypt", rc); 
     gcry_sexp_release(data);
@@ -690,10 +697,10 @@
  *        the decrypted block is bigger, an error is returned
  * @returns the size of the decrypted block, -1 on error
  */
-int decryptPrivateKey(const PrivateKey hostkey, 
-                  const RSAEncryptedData * block,
-                  void * result,
-                  unsigned int max) {
+int decryptPrivateKey(const struct PrivateKey * hostkey, 
+                     const RSAEncryptedData * block,
+                     void * result,
+                     unsigned int max) {
   gcry_sexp_t resultsexp;
   gcry_sexp_t data;
   size_t erroff;
@@ -705,7 +712,7 @@
 
   lockGcrypt();
 #if EXTRA_CHECKS
-  rc = gcry_pk_testkey(HOSTKEY(hostkey));
+  rc = gcry_pk_testkey(hostkey->sexp);
   if (rc) {
     LOG_GCRY(LOG_ERROR, "gcry_pk_testkey", rc);
     unlockGcrypt();
@@ -735,7 +742,7 @@
   }
   rc = gcry_pk_decrypt(&resultsexp,
                       data,
-                      HOSTKEY(hostkey));
+                      hostkey->sexp);
   gcry_sexp_release(data);
   if (rc) {
     LOG_GCRY(LOG_ERROR, "gcry_pk_decrypt", rc);
@@ -817,7 +824,7 @@
  * @param sig where to write the signature
  * @return SYSERR on error, OK on success
  */
-int sign(const PrivateKey hostkey, 
+int sign(const struct PrivateKey * hostkey, 
         unsigned short size,
         const void * block,
         Signature * sig) {
@@ -851,7 +858,7 @@
     unlockGcrypt();
     return SYSERR;
   }
-  rc = gcry_pk_sign(&result, data, HOSTKEY(hostkey));
+  rc = gcry_pk_sign(&result, data, hostkey->sexp);
   gcry_sexp_release(data);
   if (rc) {
     LOG_GCRY(LOG_ERROR, "gcry_pk_sign", rc);
@@ -904,7 +911,7 @@
   gcry_sexp_t sigdata;
   size_t size;
   gcry_mpi_t val;
-  PrivateKey hostkey;
+  struct PrivateKey * hostkey;
   HashCode160 hc;
   char * buff;
   int bufSize;
@@ -950,7 +957,7 @@
   hostkey = public2PrivateKey(publicKey);
   rc = gcry_pk_verify(sigdata,
                      data,
-                     HOSTKEY(hostkey));  
+                     hostkey->sexp);  
   freePrivateKey(hostkey);
   gcry_sexp_release(data);
   gcry_sexp_release(sigdata);

Modified: GNUnet/src/util/hostkey_openssl.c
===================================================================
--- GNUnet/src/util/hostkey_openssl.c   2005-02-26 23:08:34 UTC (rev 326)
+++ GNUnet/src/util/hostkey_openssl.c   2005-02-27 00:58:00 UTC (rev 327)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2001, 2002, 2003, 2004 Christian Grothoff (and other contributing 
authors)
+     (C) 2001, 2002, 2003, 2004, 2005 Christian Grothoff (and other 
contributing authors)
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -31,20 +31,18 @@
 #include <openssl/bn.h>
 #include <openssl/err.h>
 
+struct PrivateKey {
+  RSA * rsa;
+};
 
-#define HOSTKEY(a) ((RSA *)(a)->internal)
-#define HOSTKEYL(a) ((a)->internal)
-
-
-
 #define HOSTKEY_LEN 2048
 #define EXTRA_CHECKS YES
 
 /**
  * This HostKey implementation uses RSA.
  */
-PrivateKey makePrivateKey() {
-  PrivateKey ret;
+struct PrivateKey * makePrivateKey() {
+  struct PrivateKey * ret;
   RSA * hk;
 
   hk = RSA_generate_key(HOSTKEY_LEN, 65535, NULL, 0);
@@ -56,16 +54,16 @@
        ERR_error_string(ERR_get_error(), NULL));  
     return NULL;
   }
-  ret = MALLOC(sizeof(PrivateKey));
-  HOSTKEYL(ret) = hk;
+  ret = MALLOC(sizeof(struct PrivateKey));
+  ret->rsa = hk;
   return ret;
 }
 
 /**
  * Free memory occupied by hostkey
  */
-void freePrivateKey(PrivateKey hostkey) {
-  RSA_free(HOSTKEY(hostkey));
+void freePrivateKey(struct PrivateKey * hostkey) {
+  RSA_free(hostkey->rsa);
   FREE(hostkey);
 }
 
@@ -75,27 +73,27 @@
  * @param hostkey the hostkey to extract into the result.
  * @param result where to write the result.
  */
-void getPublicKey(PrivateKey hostkey,
+void getPublicKey(const struct PrivateKey * hostkey,
                  PublicKey * result) {
   unsigned short sizen;
   unsigned short sizee;
   unsigned short size;
 
-  sizen = BN_num_bytes(HOSTKEY(hostkey)->n);
-  sizee = BN_num_bytes(HOSTKEY(hostkey)->e);
+  sizen = BN_num_bytes(hostkey->rsa->n);
+  sizee = BN_num_bytes(hostkey->rsa->e);
   size = sizen + sizee+2*sizeof(unsigned short);
   GNUNET_ASSERT(size == sizeof(PublicKey)-sizeof(result->padding));
   GNUNET_ASSERT(RSA_KEY_LEN == sizen+sizee);
   result->len = htons(size);
   result->sizen = htons(sizen);
   result->padding = 0;  
-  if (sizen != BN_bn2bin(HOSTKEY(hostkey)->n,
+  if (sizen != BN_bn2bin(hostkey->rsa->n,
                         &result->key[0])) 
     errexit(_("Function '%s' did not return expected size %u: %s\n"),
            "BN_bn2bin(n)",
            sizen, 
            ERR_error_string(ERR_get_error(), NULL));
-  if (sizee != BN_bn2bin(HOSTKEY(hostkey)->e,
+  if (sizee != BN_bn2bin(hostkey->rsa->e,
                         &result->key[sizen]))
     errexit(_("Function '%s' did not return expected size %u: %s\n"),
            "BN_bn2bin(e)",
@@ -106,9 +104,12 @@
 
 /**
  * Internal: publicKey => RSA-Key
+ *
+ * Note that this function returns a public key, despite
+ * of what the type says.
  */
-static PrivateKey public2PrivateKey(const PublicKey * publicKey) {
-  PrivateKey ret;
+static struct PrivateKey * public2PrivateKey(const PublicKey * publicKey) {
+  struct PrivateKey * ret;
   RSA * result;
   int sizen;
   int sizee;
@@ -131,8 +132,8 @@
   result->e = BN_bin2bn(&publicKey->key[sizen],
                        sizee, 
                        NULL);
-  ret = MALLOC(sizeof(PrivateKey));
-  HOSTKEYL(ret) = result;
+  ret = MALLOC(sizeof(struct PrivateKey));
+  ret->rsa = result;
   return ret;
 }
 
@@ -142,7 +143,7 @@
  * @returns encoding of the private key.
  *    The first 4 bytes give the size of the array, as usual.
  */
-PrivateKeyEncoded * encodePrivateKey(PrivateKey hostkey) {
+PrivateKeyEncoded * encodePrivateKey(const struct PrivateKey * hostkey) {
   /*
                BIGNUM *n;               public modulus
                BIGNUM *e;               public exponent
@@ -164,27 +165,27 @@
   unsigned short size;
   PrivateKeyEncoded * retval;
 
-  sizen = BN_num_bytes(HOSTKEY(hostkey)->n);
-  sizee = BN_num_bytes(HOSTKEY(hostkey)->e);
-  sized = BN_num_bytes(HOSTKEY(hostkey)->d);
-  if (HOSTKEY(hostkey)->p != NULL)
-    sizep = BN_num_bytes(HOSTKEY(hostkey)->p);
+  sizen = BN_num_bytes(hostkey->rsa->n);
+  sizee = BN_num_bytes(hostkey->rsa->e);
+  sized = BN_num_bytes(hostkey->rsa->d);
+  if (hostkey->rsa->p != NULL)
+    sizep = BN_num_bytes(hostkey->rsa->p);
   else
     sizep = 0;
-  if (HOSTKEY(hostkey)->q != NULL)
-    sizeq = BN_num_bytes(HOSTKEY(hostkey)->q);
+  if (hostkey->rsa->q != NULL)
+    sizeq = BN_num_bytes(hostkey->rsa->q);
   else
     sizeq = 0;
-  if (HOSTKEY(hostkey)->dmp1 != NULL)
-    sizedmp1 = BN_num_bytes(HOSTKEY(hostkey)->dmp1);
+  if (hostkey->rsa->dmp1 != NULL)
+    sizedmp1 = BN_num_bytes(hostkey->rsa->dmp1);
   else
     sizedmp1 = 0;
-  if (HOSTKEY(hostkey)->dmq1 != NULL)
-    sizedmq1 = BN_num_bytes(HOSTKEY(hostkey)->dmq1);
+  if (hostkey->rsa->dmq1 != NULL)
+    sizedmq1 = BN_num_bytes(hostkey->rsa->dmq1);
   else
     sizedmq1 = 0;
-  if (HOSTKEY(hostkey)->iqmp != NULL)
-    sizeiqmp = BN_num_bytes(HOSTKEY(hostkey)->iqmp);
+  if (hostkey->rsa->iqmp != NULL)
+    sizeiqmp = BN_num_bytes(hostkey->rsa->iqmp);
   else
     sizeiqmp = 0;
   size = 
sizen+sizee+sized+sizep+sizeq+sizedmp1+sizedmq1+sizeiqmp+sizeof(PrivateKeyEncoded);
@@ -197,29 +198,31 @@
   retval->sizeq = htons(sizeq);
   retval->sizedmp1 = htons(sizedmp1);
   retval->sizedmq1 = htons(sizedmq1);
-  BN_bn2bin(HOSTKEY(hostkey)->n, &((PrivateKeyEncoded_GENERIC 
*)retval)->key[0]);
-  BN_bn2bin(HOSTKEY(hostkey)->e, &((PrivateKeyEncoded_GENERIC 
*)retval)->key[0+sizen]);
-  BN_bn2bin(HOSTKEY(hostkey)->d, &((PrivateKeyEncoded_GENERIC *)retval)->key[0+
-            sizen+sizee]);
-  if (HOSTKEY(hostkey)->p != NULL)
-    BN_bn2bin(HOSTKEY(hostkey)->p, 
-             &((PrivateKeyEncoded_GENERIC *)retval)->key[0+sizen+sizee+sized]);
-  if (HOSTKEY(hostkey)->q != NULL)
-    BN_bn2bin(HOSTKEY(hostkey)->q, 
-             &((PrivateKeyEncoded_GENERIC *)retval)->key[0+sizen+sizee+sized+
-              sizep]);
-  if (HOSTKEY(hostkey)->dmp1 != NULL)
-    BN_bn2bin(HOSTKEY(hostkey)->dmp1, 
-             &((PrivateKeyEncoded_GENERIC *)retval)->key[0+sizen+sizee+sized+
-              sizep+sizeq]);
-  if (HOSTKEY(hostkey)->dmq1 != NULL)
-    BN_bn2bin(HOSTKEY(hostkey)->dmq1, 
-             &((PrivateKeyEncoded_GENERIC *)retval)->key[0+sizen+sizee+sized+
-              sizep+sizeq+sizedmp1]);
-  if (HOSTKEY(hostkey)->iqmp != NULL)
-    BN_bn2bin(HOSTKEY(hostkey)->iqmp, 
-             &((PrivateKeyEncoded_GENERIC *)retval)->key[0+sizen+sizee+sized+
-              sizep+sizeq+sizedmp1+sizedmq1]);
+  BN_bn2bin(hostkey->rsa->n, 
+           &((char*)&retval[1])[0]);
+  BN_bn2bin(hostkey->rsa->e, 
+           &((char*)&retval[1])[0+sizen]);
+  BN_bn2bin(hostkey->rsa->d, 
+           &((char*)&retval[1])[0+sizen+sizee]);
+  if (hostkey->rsa->p != NULL)
+    BN_bn2bin(hostkey->rsa->p, 
+             &((char*)&retval[1])[0+sizen+sizee+sized]);
+  if (hostkey->rsa->q != NULL)
+    BN_bn2bin(hostkey->rsa->q, 
+             &((char*)&retval[1])[0+sizen+sizee+sized+
+                                  sizep]);
+  if (hostkey->rsa->dmp1 != NULL)
+    BN_bn2bin(hostkey->rsa->dmp1, 
+             &((char*)&retval[1])[0+sizen+sizee+sized+
+                                  sizep+sizeq]);
+  if (hostkey->rsa->dmq1 != NULL)
+    BN_bn2bin(hostkey->rsa->dmq1, 
+             &((char*)&retval[1])[0+sizen+sizee+sized+
+                                  sizep+sizeq+sizedmp1]);
+  if (hostkey->rsa->iqmp != NULL)
+    BN_bn2bin(hostkey->rsa->iqmp, 
+             &((char*)&retval[1])[0+sizen+sizee+sized+
+                                  sizep+sizeq+sizedmp1+sizedmq1]);
   return retval;
 }
 
@@ -227,7 +230,7 @@
  * Decode the private key from the file-format back
  * to the "normal", internal format.
  */
-PrivateKey decodePrivateKey(const PrivateKeyEncoded * encoding) {
+struct PrivateKey * decodePrivateKey(const PrivateKeyEncoded * encoding) {
   unsigned short sizen;
   unsigned short sizee;
   unsigned short sized;
@@ -238,7 +241,7 @@
   unsigned short size;
   unsigned short sum;
   RSA * result;
-  PrivateKey ret;
+  struct PrivateKey * ret;
 
   result = RSA_new();
   size    = ntohs(encoding->len) - sizeof(PrivateKeyEncoded);
@@ -250,39 +253,53 @@
   sizedmp1= ntohs(encoding->sizedmp1);
   sizedmq1= ntohs(encoding->sizedmq1);
   sum = 0;
-  result->n= BN_bin2bn(&((PrivateKeyEncoded_GENERIC *)encoding)->key[sum], 
sizen,
-                       NULL); sum += sizen;
-  result->e= BN_bin2bn(&((PrivateKeyEncoded_GENERIC *)encoding)->key[sum], 
sizee,
-                       NULL); sum += sizee;
-  result->d= BN_bin2bn(&((PrivateKeyEncoded_GENERIC *)encoding)->key[sum], 
sized,
-                       NULL); sum += sized;
+  result->n= BN_bin2bn(&((char*)&encoding[1])[sum], 
+                      sizen,
+                       NULL); 
+  sum += sizen;
+  result->e= BN_bin2bn(&((char*)&encoding[1])[sum], 
+                      sizee,
+                       NULL); 
+  sum += sizee;
+  result->d= BN_bin2bn(&((char*)&encoding[1])[sum], 
+                      sized,
+                       NULL);
+  sum += sized;
   if (sizep != 0) {
-    result->p = BN_bin2bn(&((PrivateKeyEncoded_GENERIC *)encoding)->key[sum],
-                          sizep, NULL); sum += sizep;
+    result->p = BN_bin2bn(&((char*)&encoding[1])[sum],
+                          sizep, NULL);
+    sum += sizep;
   } else
     result->p = NULL;
   if (sizeq != 0) {
-    result->q = BN_bin2bn(&((PrivateKeyEncoded_GENERIC *)encoding)->key[sum],
-                          sizeq, NULL); sum += sizeq;
+    result->q = BN_bin2bn(&((char*)&encoding[1])[sum],
+                          sizeq,
+                         NULL);
+    sum += sizeq;
   } else
     result->q = NULL;
   if (sizedmp1 != 0) {
-    result->dmp1= BN_bin2bn(&((PrivateKeyEncoded_GENERIC *)encoding)->key[sum],
-                            sizedmp1, NULL); sum += sizedmp1;
+    result->dmp1= BN_bin2bn(&((char*)&encoding[1])[sum],
+                            sizedmp1, 
+                           NULL); 
+    sum += sizedmp1;
   } else
     result->dmp1 = NULL;
   if (sizedmq1 != 0) {
-    result->dmq1 = BN_bin2bn(&((PrivateKeyEncoded_GENERIC 
*)encoding)->key[sum],
-                             sizedmq1, NULL); sum += sizedmq1;
+    result->dmq1 = BN_bin2bn(&((char*)&encoding[1])[sum],
+                             sizedmq1,
+                            NULL); 
+    sum += sizedmq1;
   } else
     result->dmq1 = NULL;
   if (size - sum > 0) 
-    result->iqmp= BN_bin2bn(&((PrivateKeyEncoded_GENERIC *)encoding)->key[sum],
-                            size-sum, NULL);
+    result->iqmp= BN_bin2bn(&((char*)&encoding[1])[sum],
+                            size-sum,
+                           NULL);
   else
     result->iqmp = NULL;
-  ret = MALLOC(sizeof(PrivateKey));
-  HOSTKEYL(ret) = result;
+  ret = MALLOC(sizeof(struct PrivateKey));
+  ret->rsa = result;
   return ret;
 }
 
@@ -297,17 +314,17 @@
  * @returns SYSERR on error, OK if ok
  */
 int encryptPrivateKey(const void * block, 
-                  unsigned short size,
-                  const PublicKey * publicKey,
-                  RSAEncryptedData * target) {
-  PrivateKey foreignkey;
+                     unsigned short size,
+                     const PublicKey * publicKey,
+                     RSAEncryptedData * target) {
+  struct PrivateKey * foreignkey;
   int rs;
   int len;
 
   foreignkey = public2PrivateKey(publicKey);
   if (foreignkey == NULL)
     return SYSERR;
-  rs = RSA_size(HOSTKEY(foreignkey));
+  rs = RSA_size(foreignkey->rsa);
   /* now encrypt. First get size of the block */
   if (size > (rs - 41)) {
     BREAK();
@@ -322,7 +339,7 @@
   len = RSA_public_encrypt(size, 
                           (void*)block,  /* cast for old OpenSSL versions */
                           &target->encoding[0], 
-                          HOSTKEY(foreignkey),
+                          foreignkey->rsa,
                           RSA_PKCS1_PADDING);
   if (len != RSA_ENC_LEN) {
     if (len == -1)
@@ -353,10 +370,10 @@
  *        the decrypted block is bigger, an error is returned
  * @returns the size of the decrypted block, -1 on error
  */
-int decryptPrivateKey(const PrivateKey hostkey, 
-                  const RSAEncryptedData * block,
-                  void * result,
-                  unsigned int max) {
+int decryptPrivateKey(const struct PrivateKey * hostkey, 
+                     const RSAEncryptedData * block,
+                     void * result,
+                     unsigned int max) {
   RSAEncryptedData tmp; /* this is as big as the result can possibly get */
   int size;
 
@@ -366,7 +383,7 @@
   size = RSA_private_decrypt(sizeof(RSAEncryptedData), 
                             (void*)&block->encoding[0], /* cast for old 
OpenSSL versions */
                             &tmp.encoding[0], 
-                            HOSTKEY(hostkey),
+                            hostkey->rsa,
                             RSA_PKCS1_PADDING);
   if ( (size == -1) || 
        (size > max) ) {
@@ -394,14 +411,14 @@
  * @param sig where to write the signature
  * @return SYSERR on error, OK on success
  */
-int sign(const PrivateKey hostkey, 
+int sign(const struct PrivateKey * hostkey, 
         unsigned short size,
         const void * block,
         Signature * sig) {
 #if EXTRA_CHECKS
   PublicKey pkey;
 #endif
-  int rs = RSA_size(HOSTKEY(hostkey));
+  int rs = RSA_size(hostkey->rsa);
   unsigned int sigSize;
   HashCode160 hc;
 
@@ -419,7 +436,7 @@
                    sizeof(HashCode160),
                    &sig->sig[0],
                    &sigSize,
-                   HOSTKEY(hostkey))) {
+                   hostkey->rsa)) {
     LOG(LOG_ERROR,
        _("'%s' failed at %s:%d with error: %s\n"),
        "RSA_sign",
@@ -437,7 +454,7 @@
                      sizeof(HashCode160),
                      &sig->sig[0],
                      sizeof(Signature),
-                     HOSTKEY(hostkey))) 
+                     hostkey->rsa)) 
     BREAK();
   
   getPublicKey(hostkey, &pkey);
@@ -448,7 +465,7 @@
                        sizeof(HashCode160),
                        &sig->sig[0],
                        sizeof(Signature),
-                       HOSTKEY(hostkey))) 
+                       hostkey->rsa)) 
       BREAK();
    return SYSERR;
   }
@@ -469,7 +486,7 @@
              unsigned short len,
              const Signature * sig,          
              const PublicKey * publicKey) {
-  PrivateKey hostkey;
+  struct PrivateKey * hostkey;
   int rs;
   HashCode160 hc;
  
@@ -478,7 +495,7 @@
        (sig == NULL) || 
        (block == NULL))
     return SYSERR; /* hey, no data !? */
-  rs = RSA_size(HOSTKEY(hostkey));
+  rs = RSA_size(hostkey->rsa);
   if (rs != RSA_ENC_LEN) {
     BREAK();
     return SYSERR;
@@ -491,7 +508,7 @@
                      sizeof(HashCode160),
                      (unsigned char*) &sig->sig[0], /* cast because OpenSSL 
may not declare const */
                      sizeof(Signature),
-                     HOSTKEY(hostkey))) {
+                     hostkey->rsa)) {
     LOG(LOG_INFO,
        _("RSA signature verification failed at %s:%d: %s\n"),
        __FILE__, __LINE__,

Modified: GNUnet/src/util/hostkeytest.c
===================================================================
--- GNUnet/src/util/hostkeytest.c       2005-02-26 23:08:34 UTC (rev 326)
+++ GNUnet/src/util/hostkeytest.c       2005-02-27 00:58:00 UTC (rev 327)
@@ -12,7 +12,7 @@
 #define ITER 10
 
 static int testEncryptDecrypt() {
-  PrivateKey hostkey;
+  struct PrivateKey * hostkey;
   PublicKey pkey;
   RSAEncryptedData target;
   char result[MAX_TESTVAL];
@@ -68,7 +68,7 @@
 }
 
 static int testSignVerify() {
-  PrivateKey hostkey;
+  struct PrivateKey * hostkey;
   Signature sig;
   PublicKey pkey;
   int i;
@@ -101,7 +101,7 @@
 }
 
 static int testPrivateKeyEncoding() {
-  PrivateKey hostkey;
+  struct PrivateKey * hostkey;
   PrivateKeyEncoded * encoding;
   PublicKey pkey;
   RSAEncryptedData target;

Modified: GNUnet/src/util/kblockkey.c
===================================================================
--- GNUnet/src/util/kblockkey.c 2005-02-26 23:08:34 UTC (rev 326)
+++ GNUnet/src/util/kblockkey.c 2005-02-27 00:58:00 UTC (rev 327)
@@ -426,7 +426,7 @@
  * Deterministically (!) create a hostkey using only the
  * given HashCode as input to the PRNG.
  */
-PrivateKey makeKblockKey(const HashCode160 * hc) {
+struct PrivateKey * makeKblockKey(const HashCode160 * hc) {
   KBlock_secret_key sk;
   HashCode160 hx;
   void * pbu[6];
@@ -434,7 +434,7 @@
   size_t sizes[6];
   PrivateKeyEncoded * retval;
   int i;
-  PrivateKey ret;
+  struct PrivateKey * ret;
   size_t size;
 
   hx = *hc;
@@ -463,34 +463,34 @@
   retval->len = htons(size);
   i = 0;
   retval->sizen = htons(sizes[0]);
-  memcpy(&((PrivateKeyEncoded_GENERIC*)retval)->key[i], 
+  memcpy(&((char*)&retval[1])[i], 
         pbu[0],
         sizes[0]);
   i += sizes[0];
   retval->sizee = htons(sizes[1]);
-  memcpy(&((PrivateKeyEncoded_GENERIC*)retval)->key[i], 
+  memcpy(&((char*)&retval[1])[i], 
         pbu[1],
         sizes[1]);
   i += sizes[1];
   retval->sized = htons(sizes[2]);
-  memcpy(&((PrivateKeyEncoded_GENERIC*)retval)->key[i], 
+  memcpy(&((char*)&retval[1])[i], 
         pbu[2],
         sizes[2]);
   i += sizes[2];
   /* swap p and q! */
   retval->sizep = htons(sizes[4]);
-  memcpy(&((PrivateKeyEncoded_GENERIC*)retval)->key[i], 
+  memcpy(&((char*)&retval[1])[i], 
         pbu[4],
         sizes[4]);
   i += sizes[4];
   retval->sizeq = htons(sizes[3]);
-  memcpy(&((PrivateKeyEncoded_GENERIC*)retval)->key[i], 
+  memcpy(&((char*)&retval[1])[i], 
         pbu[3],
         sizes[3]);
   i += sizes[3];
   retval->sizedmp1 = htons(0);
   retval->sizedmq1 = htons(0);
-  memcpy(&((PrivateKeyEncoded_GENERIC*)retval)->key[i], 
+  memcpy(&((char*)&retval[1])[i], 
         pbu[5],
         sizes[5]);
   for (i=0;i<6;i++) {

Modified: GNUnet/src/util/kblockkey_test.c
===================================================================
--- GNUnet/src/util/kblockkey_test.c    2005-02-26 23:08:34 UTC (rev 326)
+++ GNUnet/src/util/kblockkey_test.c    2005-02-27 00:58:00 UTC (rev 327)
@@ -15,7 +15,7 @@
 
 static int testMultiKey(const char * word) {
   HashCode160 in;  
-  PrivateKey hostkey;
+  struct PrivateKey * hostkey;
   PublicKey pkey;
   PublicKey pkey1;
   int i;
@@ -57,7 +57,7 @@
 }
 
 
-static int testEncryptDecrypt(PrivateKey hostkey) {
+static int testEncryptDecrypt(struct PrivateKey * hostkey) {
   PublicKey pkey;
   RSAEncryptedData target;
   char result[MAX_TESTVAL];
@@ -110,7 +110,7 @@
     return SYSERR;
 }
 
-static int testSignVerify(PrivateKey hostkey) {
+static int testSignVerify(struct PrivateKey * hostkey) {
   Signature sig;
   PublicKey pkey;
   int i;
@@ -140,7 +140,7 @@
   return ok;
 }
 
-static int testPrivateKeyEncoding(PrivateKey hostkey) {
+static int testPrivateKeyEncoding(struct PrivateKey * hostkey) {
   PrivateKeyEncoded * encoding;
   PublicKey pkey;
   RSAEncryptedData target;
@@ -207,7 +207,7 @@
 int main(int argc, char * argv[]) {
   int failureCount = 0;
   HashCode160 in;
-  PrivateKey hostkey;
+  struct PrivateKey * hostkey;
 
 #if USE_GCRYPT
   initLockingGcrypt();

Modified: GNUnet/src/util/symcipher_gcrypt.c
===================================================================
--- GNUnet/src/util/symcipher_gcrypt.c  2005-02-26 23:08:34 UTC (rev 326)
+++ GNUnet/src/util/symcipher_gcrypt.c  2005-02-27 00:58:00 UTC (rev 327)
@@ -78,7 +78,7 @@
 int encryptBlock(const void * block, 
                 unsigned short len,
                 const SESSIONKEY * sessionkey,
-                const unsigned char * iv,
+                const INITVECTOR * iv,
                 void * result) {
   gcry_cipher_hd_t handle;
   int rc;
@@ -117,7 +117,7 @@
   }
   rc != gcry_cipher_setiv(handle, 
                          iv,
-                         SESSIONKEY_LEN/2);
+                         sizeof(INITVECTOR));
 
   if (rc && ((char)rc != GPG_ERR_WEAK_KEY)) {    
     LOG_GCRY(LOG_FAILURE, "gcry_cipher_setiv", rc);
@@ -155,7 +155,7 @@
 int decryptBlock(const SESSIONKEY * sessionkey, 
                 const void * block,
                 unsigned short size,
-                const unsigned char * iv,
+                const INITVECTOR * iv,
                 void * result) {
   gcry_cipher_hd_t handle;
   int rc;
@@ -194,7 +194,7 @@
   }
   rc = gcry_cipher_setiv(handle, 
                         iv,
-                        SESSIONKEY_LEN/2);
+                        sizeof(INITVECTOR));
 
   if (rc && ((char)rc != GPG_ERR_WEAK_KEY)) {    
     LOG_GCRY(LOG_FAILURE, "gcry_cipher_setiv", rc);

Modified: GNUnet/src/util/symcipher_openssl.c
===================================================================
--- GNUnet/src/util/symcipher_openssl.c 2005-02-26 23:08:34 UTC (rev 326)
+++ GNUnet/src/util/symcipher_openssl.c 2005-02-27 00:58:00 UTC (rev 327)
@@ -55,7 +55,7 @@
 int encryptBlock(const void * block, 
                 unsigned short len,
                 const SESSIONKEY * sessionkey,
-                const unsigned char * iv,
+                const INITVECTOR * iv,
                 void * result) {
   int outlen = 0;
   EVP_CIPHER_CTX ctx;
@@ -118,7 +118,7 @@
 int decryptBlock(const SESSIONKEY * sessionkey, 
                 const void * block,
                 unsigned short size,
-                const unsigned char * iv,
+                const INITVECTOR * iv,
                 void * result) {
   int outlen = 0;
   EVP_CIPHER_CTX ctx;

Modified: GNUnet/src/util/symciphertest.c
===================================================================
--- GNUnet/src/util/symciphertest.c     2005-02-26 23:08:34 UTC (rev 326)
+++ GNUnet/src/util/symciphertest.c     2005-02-27 00:58:00 UTC (rev 327)
@@ -8,7 +8,7 @@
 #include "platform.h"
 
 #define TESTSTRING "Hello World!"
-#define INITVALUE "InitValu"
+#define INITVALUE "InitializationVectorValue"
 
 static int testSymcipher() {
   SESSIONKEY key;
@@ -20,7 +20,7 @@
   size = encryptBlock(TESTSTRING,
                      strlen(TESTSTRING)+1,
                      &key,
-                     INITVALUE,
+                     (const INITVECTOR*) INITVALUE,
                      result);
   if (size == -1) {
     printf("symciphertest failed: encryptBlock returned %d\n",
@@ -30,7 +30,7 @@
   size = decryptBlock(&key,
                      result,
                      size,
-                     INITVALUE,
+                     (const INITVECTOR*) INITVALUE,
                      res);
   if (strlen(TESTSTRING)+1 
       != size) {
@@ -54,6 +54,7 @@
 int main(int argc, char * argv[]) {
   int failureCount = 0;
   
+  GNUNET_ASSERT(strlen(INITVALUE) > sizeof(INITVECTOR));
 #if ! USE_OPENSSL
   initLockingGcrypt();
 #endif

Modified: GNUnet/todo
===================================================================
--- GNUnet/todo 2005-02-26 23:08:34 UTC (rev 326)
+++ GNUnet/todo 2005-02-27 00:58:00 UTC (rev 327)
@@ -20,8 +20,6 @@
   * gnunet-pseudonym
 - FSUI:
   * API changes (Krista discussion, anonymity level)
-- UTIL:
-  * API changes (hostkey struct, other structs? HashCode160)
 
 0.7.0pre1 [4'05] (aka "preview"):
 - util:





reply via email to

[Prev in Thread] Current Thread [Next in Thread]