Index: trunk/src/sh_srp.c
===================================================================
--- trunk/src/sh_srp.c	(revision 581)
+++ trunk/src/sh_srp.c	(revision 1)
@@ -48,5 +48,5 @@
 #define bignum MP_INT
 
-static
+inline
 int big_create (bignum * a)
 {
@@ -55,5 +55,5 @@
 }
 
-static
+inline
 int big_zerop (bignum * a)
 {
@@ -69,5 +69,5 @@
 }
 
-static
+inline
 int big_trunc (bignum * a, bignum * b, bignum * q, bignum *r)
 {
@@ -76,5 +76,5 @@
 }
 
-static
+inline
 int big_exptmod (bignum * a, bignum * b, bignum * c, bignum *d)
 {
@@ -86,5 +86,5 @@
 int    siz_str_internal = 0;
 
-static
+inline
 char * big_string (bignum * a, int base)
 {
@@ -96,5 +96,5 @@
   if (get_str_internal == NULL)
     {
-      get_str_internal = calloc(1,512);   /* only once */
+      get_str_internal = malloc(512);   /* only once */
       if (get_str_internal)
 	{
@@ -114,17 +114,5 @@
       size = strlen(str) + 1;
       if (size > siz_str_internal)
-	{
-	  char * ptr = realloc (get_str_internal, size);
-	  if (ptr)
-	    get_str_internal = ptr;
-	  else
-	    {
-	      /* "If realloc() fails, the original block is left untouched;
-	       * it is not freed or moved." */
-	      /* cppcheck-suppress doubleFree */
-	      free(get_str_internal);
-	      get_str_internal = NULL;
-	    }
-	}
+	get_str_internal = realloc (get_str_internal, size);
       if (get_str_internal == NULL)
 	{
@@ -133,5 +121,5 @@
 	}
       siz_str_internal = size;
-      sl_strlcpy (get_str_internal, str, siz_str_internal);
+      strcpy (get_str_internal, str);                   /* known to fit  */
       for (i = 0; i < (size-1); ++i)
 	if (get_str_internal[i] >= 'a' && get_str_internal[i] <= 'f' )
@@ -142,5 +130,5 @@
 }
 
-static 
+inline 
 int big_add(bignum * a, bignum * b, bignum * c)
 {
@@ -149,5 +137,5 @@
 }
 
-static 
+inline 
 int big_sub(bignum * a, bignum * b, bignum * c)
 {
@@ -156,5 +144,5 @@
 }
 
-static 
+inline 
 int big_mul(bignum * a, bignum * b, bignum * c)
 {
@@ -163,5 +151,5 @@
 }
 
-static 
+inline 
 int big_greaterp(bignum * a, bignum * b)
 {
@@ -169,5 +157,5 @@
 }
 
-static 
+inline 
 int big_set_big(bignum * a, bignum * b)
 {
@@ -177,5 +165,5 @@
 
 
-static 
+inline 
 int big_set_string(const char * str, int base, bignum * a)
 {
@@ -209,8 +197,7 @@
 
   char           *combi;
-  size_t          len, l2;
+  size_t          len;
   register int i;
   unsigned char * dez = NULL;
-  char hashbuf[KEYBUF_SIZE];
 
   SL_ENTER(_("sh_srp_x"));
@@ -231,13 +218,8 @@
 
   (void) sl_strlcpy (skey->vernam,
-		     sh_tiger_hash(skey->vernam, TIGER_DATA, PW_LEN, 
-				   hashbuf, sizeof(hashbuf)), 
-		     KEY_LEN);
+		     sh_tiger_hash(skey->vernam, TIGER_DATA, PW_LEN), KEY_LEN);
   skey->vernam[KEY_LEN] = '\0';
 
-  len = sl_strlen(salt) + 1;
-  l2  = sl_strlen(skey->vernam);
-  if (sl_ok_adds(len, l2))
-    len += l2;
+  len = sl_strlen(salt) + sl_strlen(skey->vernam) + 1;
 
   /* H(s,P)
@@ -248,6 +230,5 @@
   (void) sl_strlcpy (sh_srp.x, 
 		     sh_tiger_hash(combi, TIGER_DATA, 
-				   (unsigned long) sl_strlen(combi),
-				   hashbuf, sizeof(hashbuf)),
+				   (unsigned long) sl_strlen(combi)),
 		     KEY_LEN+1);
   SH_FREE (combi);
@@ -256,8 +237,9 @@
 }
 
-char * sh_srp_M (char * x1, char * x2, char * x3, char * hash, size_t size)
+char * sh_srp_M (char * x1, char * x2, char * x3)
 {
   char           *combi;
-  size_t          len, l2, l3;
+  size_t          len;
+  static char     hash[KEY_LEN+1];
   
   SL_ENTER(_("sh_srp_M"));
@@ -266,12 +248,5 @@
 	     _("x1 != NULL && x2 != NULL && x3 !=NULL"), NULL);
 
-  len = sl_strlen(x1) + 1;
-  l2  = sl_strlen(x2); 
-  l3  = sl_strlen(x3);
-
-  if (sl_ok_adds(len, l2))
-    len += l2;
-  if (sl_ok_adds(len, l3))
-    len += l3;
+  len = sl_strlen(x1) + sl_strlen(x2) + sl_strlen(x3) + 1;
   
   /* H(x1,x2,x3)
@@ -281,6 +256,7 @@
   (void) sl_strlcat (combi, x2, len);
   (void) sl_strlcat (combi, x3, len);
-  (void) sh_tiger_hash(combi, TIGER_DATA, (unsigned long) (len-1),
-		       hash, size);
+  (void) sl_strlcpy (hash, 
+		     sh_tiger_hash(combi, TIGER_DATA, (unsigned long) (len-1)),
+		     KEY_LEN+1);
   SH_FREE (combi);
   
@@ -349,15 +325,14 @@
   int    res;
   char   hash[KEY_LEN+1];
-  char hashbuf[KEYBUF_SIZE];
 
   SL_ENTER(_("sh_srp_make_a"));
 
   for (i = 0; i < 6; ++i)
-    randl[i] = (UINT32) taus_get ();
-
+    randl[i] = (UINT32) taus_get (&(skey->rng0[0]), 
+				  &(skey->rng1[0]),
+				  &(skey->rng2[0]));
   (void) sl_strlcpy (hash, 
 		     sh_tiger_hash((char *)&randl[0], TIGER_DATA, 
-				   (unsigned long) 6*sizeof(UINT32),
-				   hashbuf, sizeof(hashbuf)), 
+				   (unsigned long) 6*sizeof(UINT32)), 
 		     KEY_LEN+1);
 
@@ -400,5 +375,4 @@
   if (res != BIG_OK)             val = (-1);
   else if (0 != big_zerop(&AB) ) val = (-1); /* 0 != (sign == 0) */
-  else if (0 != big_zerop(&r) )  val = (-1); /* 0 != (sign == 0) */
   else                           val =    0;
 
@@ -410,5 +384,5 @@
 }
 
-#if defined(SH_WITH_CLIENT) || defined(SH_WITH_SERVER)
+#ifdef SH_WITH_CLIENT
   
 
@@ -418,4 +392,5 @@
   char    *str;
   char    *combi;
+  size_t   len;
   bigerr_t res;
 
@@ -433,5 +408,9 @@
   
   if (str != NULL)
-    combi = sh_util_strdup(str);
+    {
+      len = sl_strlen(str) + 1;
+      combi = SH_ALLOC(len);
+      (void) sl_strlcpy (combi, str, len);
+    }
   else
     combi = NULL;
@@ -451,4 +430,5 @@
   char    *str;
   char    *combi;
+  long     len;
   bigerr_t res;
 
@@ -489,5 +469,10 @@
   
   if (str != NULL)
-    combi = sh_util_strdup(str);
+    {
+      len = sl_strlen(str) + 1;
+      combi = SH_ALLOC(len);
+      sl_strlcpy (combi, str, len);
+      /* fprintf(stderr, "OK2a %ld %s\n", len, combi); */
+    }
   else
     combi = NULL;
@@ -504,5 +489,5 @@
   
   
-#if defined(SH_WITH_CLIENT) || defined(SH_WITH_SERVER)
+#ifdef SH_WITH_CLIENT
   
 char * sh_srp_S_c (char * u_str, char * B_str)
@@ -511,4 +496,5 @@
   char    *str;
   char    *combi;
+  size_t   len;
   bigerr_t res;
 
@@ -585,5 +571,9 @@
 
   if (str != NULL)
-    combi = sh_util_strdup(str);
+    {
+      len = sl_strlen(str) + 1;
+      combi = SH_ALLOC(len);
+      (void) sl_strlcpy (combi, str, len);
+    }
   else
     combi = NULL;
@@ -611,4 +601,5 @@
   char    *str;
   char    *combi;
+  size_t   len;
   bigerr_t res;
 
@@ -660,5 +651,9 @@
   
   if (str != NULL)
-    combi = sh_util_strdup(str);
+    {
+      len = sl_strlen(str) + 1;
+      combi = SH_ALLOC(len);
+      (void) sl_strlcpy (combi, str, len);
+    }
   else
     combi = NULL;
@@ -684,4 +679,5 @@
   char    *combi;
   char    *str;
+  size_t   len;
   bigerr_t res;
   
@@ -704,5 +700,9 @@
   
   if (str != NULL)
-    combi = sh_util_strdup(str);
+    {
+      len = sl_strlen(str) + 1;
+      combi = SH_ALLOC(len);
+      (void) sl_strlcpy (combi, str, len);
+    }
   else
     combi = NULL;
@@ -724,95 +724,4 @@
 
 
-#ifdef SH_CUTEST
-#include "CuTest.h"
-
-void Test_srp (CuTest *tc)
-{
-#if defined(USE_SRP_PROTOCOL) && (defined (SH_WITH_CLIENT) || defined (SH_WITH_SERVER))
-
-  int result;
-  char     modulus[80*4];
-  bignum   a, b, c;
-  bigerr_t res;
-  char    *str = NULL;
-
-  res = sh_srp_init();
-  CuAssertTrue(tc, res == 0);
-
-  (void) sl_strlcpy(modulus, SRP_MODULUS_1024_1, sizeof(modulus));
-  (void) sl_strlcat(modulus, SRP_MODULUS_1024_2, sizeof(modulus));
-  (void) sl_strlcat(modulus, SRP_MODULUS_1024_3, sizeof(modulus));
-  (void) sl_strlcat(modulus, SRP_MODULUS_1024_4, sizeof(modulus));
-
-  res = big_create(&a);
-  CuAssertTrue(tc, res == BIG_OK);
-
-  /* Check plain zero 
-   */
-  result = sh_srp_check_zero ("0");
-  CuAssertTrue(tc, result != 0);
-  
-  res = big_set_string ("0",  16, &a);
-  CuAssertTrue(tc, res == BIG_OK);
-
-  result = sh_srp_check_zero (big_string(&a, 16));
-  CuAssertTrue(tc, result != 0);
-
-  /* Check modulus (equals 0 % M) 
-   */
-  result = sh_srp_check_zero (modulus);
-  CuAssertTrue(tc, result != 0);
-
-  res = big_set_string (modulus,  16, &a);
-  CuAssertTrue(tc, res == BIG_OK);
-
-  result = sh_srp_check_zero (big_string(&a, 16));
-  CuAssertTrue(tc, result != 0);
-
-  /* Check non-zero 
-   */
-  modulus[0] = 'a';
-
-  result = sh_srp_check_zero (modulus);
-  CuAssertTrue(tc, result == 0);
-
-  res = big_set_string (modulus,  16, &a);
-  CuAssertTrue(tc, res == BIG_OK);
-
-  result = sh_srp_check_zero (big_string(&a, 16));
-  CuAssertTrue(tc, result == 0);
-
-  modulus[0] = 'f';
-
-  /* Check multiple of modulus 
-   */
-  res = big_set_string (modulus,  16, &a);
-  CuAssertTrue(tc, res == BIG_OK);
-
-  res = big_create(&b);
-  CuAssertTrue(tc, res == BIG_OK);
-
-  res = big_create(&c);
-  CuAssertTrue(tc, res == BIG_OK);
-
-  res = big_set_string ("deadbeef", 16, &b);
-  CuAssertTrue(tc, res == BIG_OK);
-
-  res = big_mul (&a, &b, &c);
-  CuAssertTrue(tc, res == BIG_OK);
-
-  str = strdup(big_string (&c, 16));
-  CuAssertPtrNotNull(tc, str);
-
-  result = sh_srp_check_zero (str);
-  CuAssertTrue(tc, result != 0);
-
-#else
-  (void) tc; /* fix compiler warning */
-#endif
-  return;
-}
-#endif
-
-
-
+
+
