r3013 - trunk/libmcrypto/source/gnutls

mikma at minisip.org mikma at minisip.org
Tue Dec 12 19:50:02 CET 2006


Author: mikma
Date: 2006-12-12 19:50:01 +0100 (Tue, 12 Dec 2006)
New Revision: 3013

Modified:
   trunk/libmcrypto/source/gnutls/ZrtpDH.cxx
   trunk/libmcrypto/source/gnutls/hmac256.cxx
   trunk/libmcrypto/source/gnutls/sha256.cxx
Log:
Customize sources imported from libzrtpcpp-0.9.0 for minisip.


Modified: trunk/libmcrypto/source/gnutls/ZrtpDH.cxx
===================================================================
--- trunk/libmcrypto/source/gnutls/ZrtpDH.cxx	2006-12-12 18:45:29 UTC (rev 3012)
+++ trunk/libmcrypto/source/gnutls/ZrtpDH.cxx	2006-12-12 18:50:01 UTC (rev 3013)
@@ -34,8 +34,10 @@
  * @author  Werner Dittmann <Werner.Dittmann at t-online.de>
  */
 
+#include <config.h>
 #include <gcrypt.h>
-#include <libzrtpcpp/crypto/ZrtpDH.h>
+#include <libmcrypto/ZrtpDH.h>
+#include <libmcrypto/gnutls/init.h>
 
 
 struct gcryptCtx {
@@ -44,8 +46,6 @@
     int32_t pLength;
 };
 
-extern void initializeGcrypt();
-
 static gcry_mpi_t bnP3072 = NULL;
 static gcry_mpi_t bnP4096 = NULL;
 static gcry_mpi_t two = NULL;
@@ -139,12 +139,12 @@
 
 ZrtpDH::ZrtpDH(int32_t pl) {
 
-    ctx = static_cast<void*>(new gcryptCtx);
-    gcryptCtx* tmpCtx = static_cast<gcryptCtx*>(ctx);
+    priv = static_cast<void*>(new gcryptCtx);
+    gcryptCtx* tmpCtx = static_cast<gcryptCtx*>(priv);
     tmpCtx->privKey = NULL;
     tmpCtx->pubKey = NULL;
 
-    initializeGcrypt();
+    libmcryptoGnutlsInit();
 
     if (!dhinit) {
         gcry_mpi_scan(&bnP3072, GCRYMPI_FMT_USG, P3072, sizeof(P3072), NULL);
@@ -168,7 +168,7 @@
 }
 
 ZrtpDH::~ZrtpDH() {
-    gcryptCtx* tmpCtx = static_cast<gcryptCtx*>(ctx);
+    gcryptCtx* tmpCtx = static_cast<gcryptCtx*>(priv);
 
     if (tmpCtx != NULL) {
         gcry_mpi_release(tmpCtx->privKey);
@@ -176,14 +176,14 @@
         gcry_mpi_release(tmpCtx->pubKey);
         tmpCtx->pubKey = NULL;
         delete tmpCtx;
-        ctx = NULL;
+        priv = NULL;
     }
 }
 
 int32_t ZrtpDH::computeKey(uint8_t *pubKeyBytes,
 			   int32_t length, uint8_t *secret) {
 
-    gcryptCtx* tmpCtx = static_cast<gcryptCtx*>(ctx);
+    gcryptCtx* tmpCtx = static_cast<gcryptCtx*>(priv);
 
     gcry_mpi_t pubKeyOther;
     gcry_mpi_scan(&pubKeyOther, GCRYMPI_FMT_USG, pubKeyBytes, length, NULL);
@@ -201,7 +201,7 @@
 
 int32_t ZrtpDH::generateKey()
 {
-    gcryptCtx* tmpCtx = static_cast<gcryptCtx*>(ctx);
+    gcryptCtx* tmpCtx = static_cast<gcryptCtx*>(priv);
 
     tmpCtx->pubKey = gcry_mpi_new(0);
     gcry_mpi_powm(tmpCtx->pubKey, two, tmpCtx->privKey, ((tmpCtx->pLength == 3072) ? bnP3072 : bnP4096));
@@ -210,7 +210,7 @@
 
 int32_t ZrtpDH::getPubKeyBytes(uint8_t *buf) const
 {
-    gcryptCtx* tmpCtx = static_cast<gcryptCtx*>(ctx);
+    gcryptCtx* tmpCtx = static_cast<gcryptCtx*>(priv);
     int32_t len = getPubKeySize();
 
     size_t i = 0;
@@ -220,22 +220,23 @@
 
 int32_t ZrtpDH::getSecretSize() const
 {
-    return ((static_cast<gcryptCtx*>(ctx)->pLength + 7) / 8);
+    return ((static_cast<gcryptCtx*>(priv)->pLength + 7) / 8);
 }
 
 int32_t ZrtpDH::getPubKeySize() const
 {
-    return ((gcry_mpi_get_nbits(static_cast<gcryptCtx*>(ctx)->pubKey) + 7) / 8);
+    return ((gcry_mpi_get_nbits(static_cast<gcryptCtx*>(priv)->pubKey) + 7) / 8);
 }
 
-void ZrtpDH::random(uint8_t *buf, int32_t length) {
+void ZrtpDH::random(uint8_t *buf, int32_t length) const{
     gcry_randomize(buf, length, GCRY_STRONG_RANDOM);
 }
 
+#if 0
 int32_t ZrtpDH::checkPubKey(uint8_t *pubKeyBytes,
                             int32_t length) const
 {
-    gcryptCtx* tmpCtx = static_cast<gcryptCtx*>(ctx);
+    gcryptCtx* tmpCtx = static_cast<gcryptCtx*>(priv);
 
     gcry_mpi_t pubKeyOther;
     gcry_mpi_scan(&pubKeyOther, GCRYMPI_FMT_USG, pubKeyBytes, length, NULL);
@@ -254,6 +255,8 @@
     gcry_mpi_release(pubKeyOther);
     return 1;
 }
+#endif
+
 /** EMACS **
  * Local variables:
  * mode: c++

Modified: trunk/libmcrypto/source/gnutls/hmac256.cxx
===================================================================
--- trunk/libmcrypto/source/gnutls/hmac256.cxx	2006-12-12 18:45:29 UTC (rev 3012)
+++ trunk/libmcrypto/source/gnutls/hmac256.cxx	2006-12-12 18:50:01 UTC (rev 3013)
@@ -35,9 +35,14 @@
  *          Johan Bilien <jobi at via.ecp.fr>
  */
 
+#include <config.h>
+#include <libmcrypto/hmac256.h>
 #include <gcrypt.h>
-#include <libzrtpcpp/crypto/hmac256.h>
 
+#ifndef SHA256_DIGEST_LENGTH
+# define SHA256_DIGEST_LENGTH 32
+#endif
+
 void hmac_sha256(uint8_t* key, uint32_t keyLength,
 		uint8_t* data, int32_t dataLength,
                 uint8_t* mac, uint32_t* macLength)

Modified: trunk/libmcrypto/source/gnutls/sha256.cxx
===================================================================
--- trunk/libmcrypto/source/gnutls/sha256.cxx	2006-12-12 18:45:29 UTC (rev 3012)
+++ trunk/libmcrypto/source/gnutls/sha256.cxx	2006-12-12 18:50:01 UTC (rev 3013)
@@ -35,9 +35,14 @@
  *	    Werner Dittmann <Werner.Dittmann at t-online.de>
  */
 
+#include <config.h>
+#include <libmcrypto/sha256.h>
 #include <gcrypt.h>
-#include <libzrtpcpp/crypto/sha256.h>
 
+#ifndef SHA256_DIGEST_LENGTH
+# define SHA256_DIGEST_LENGTH 20
+#endif
+
 void sha256(uint8_t* data, int32_t dataLength,
             uint8_t* mac)
 {



More information about the Minisip-devel mailing list