bug-gnulib
[Top][All Lists]
Advanced

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

Re: gc-pbkdf2-sha1


From: Ralf Wildenhues
Subject: Re: gc-pbkdf2-sha1
Date: Wed, 12 Oct 2005 15:39:36 +0200
User-agent: Mutt/1.5.11

Hi Simon,

* Simon Josefsson wrote on Wed, Oct 12, 2005 at 03:13:28PM CEST:
> I have installed this.  Comments most welcome, as always!

Here you go.

>
*snip header with nice documentation*

By the way, has anyone suggested to use one of these documentation-
from-source-comments generators for gnulib yet?  Has it been rejected?

> Index: lib/gc-pbkdf2-sha1.c
> ===================================================================
> RCS file: lib/gc-pbkdf2-sha1.c
> diff -N lib/gc-pbkdf2-sha1.c
> --- /dev/null 1 Jan 1970 00:00:00 -0000
> +++ lib/gc-pbkdf2-sha1.c      12 Oct 2005 13:12:57 -0000
*snip*

> +  for (i = 1; i <= l; i++)
> +    {
> +      memset (T, 0, hLen);
> +
> +      for (u = 1; u <= c; u++)
> +     {
> +       if (u == 1)
> +         {
> +           char *tmp;
> +           size_t tmplen = Slen + 4;
> +
> +           tmp = malloc (tmplen);

Allocating (even the same amount of!) memory inside a loop
is a performance killer, as is freeing it.  Please do that
as far outside as possible, even then it might dominate the
rest of the function.  Can't you even have that be done by
the caller through some init routine that encapsulates this?

> +           if (tmp == NULL)
> +             return GC_MALLOC_ERROR;
> +
> +           memcpy (tmp, S, Slen);
> +           tmp[Slen + 0] = (i & 0xff000000) >> 24;
> +           tmp[Slen + 1] = (i & 0x00ff0000) >> 16;
> +           tmp[Slen + 2] = (i & 0x0000ff00) >> 8;
> +           tmp[Slen + 3] = (i & 0x000000ff) >> 0;
> +
> +           rc = gc_hmac_sha1 (P, Plen, tmp, tmplen, U);
> +
> +           free (tmp);
> +         }
> +       else
> +         rc = gc_hmac_sha1 (P, Plen, U, hLen, U);
> +
> +       if (rc != GC_OK)
> +         return rc;
> +
> +       for (k = 0; k < hLen; k++)
> +         T[k] ^= U[k];
> +     }
> +
> +      memcpy (DK + (i - 1) * hLen, T, i == l ? r : hLen);
> +    }
> +
> +  return GC_OK;
> +}
*snip*




reply via email to

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