bug-gnulib
[Top][All Lists]
Advanced

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

Re: RFC comments in lib / gc-pbkdf2-sha1.c


From: Vladimir 'phcoder' Serbinenko
Subject: Re: RFC comments in lib / gc-pbkdf2-sha1.c
Date: Sun, 15 Nov 2009 15:49:43 +0100
User-agent: Mozilla-Thunderbird 2.0.0.22 (X11/20091109)

>
>  =20
>> Hello, all. When importing some gnulib code to GRUB2 I stumbled across=
=20
>> lib / gc-pbkdf2-sha1.c having comments taken from RFC2898. As far as I=

>> know RFC licence prohibits modifications. This seems to be GPL-incompa=
tible.
>> So is there are any licencing problem with this file?
>>    =20
>
> Thanks for the report, I rewrote the comments to not use copyrighted
> words from elsewhere.
>
>  =20
Thanks. I imported it to my grub-crypto branch.
> /Simon
>
> >From 24a6641b053b7fc8bf13b4149722e85d77db9920 Mon Sep 17 00:00:00 2001=

> From: Simon Josefsson <address@hidden>
> Date: Sun, 15 Nov 2009 13:52:55 +0100
> Subject: [PATCH] lib/gc-pbkdf2-sha1.c: Remove comments from RFC 2898.
>
> ---
>  ChangeLog            |    5 +++
>  lib/gc-pbkdf2-sha1.c |   99 ++++--------------------------------------=
--------
>  2 files changed, 13 insertions(+), 91 deletions(-)
>
> diff --git a/ChangeLog b/ChangeLog
> index a241c5b..9fe5174 100644
> --- a/ChangeLog
> +++ b/ChangeLog
> @@ -1,3 +1,8 @@
> +2009-11-15  Simon Josefsson  <address@hidden>
> +
> +     * lib/gc-pbkdf2-sha1.c: Remove comments from RFC 2898.  Reported
> +     by Vladimir 'phcoder' Serbinenko <address@hidden>.
> +
>  2009-11-14  Eric Blake  <address@hidden>
> =20
>       fnmatch: avoid compiler warning
> diff --git a/lib/gc-pbkdf2-sha1.c b/lib/gc-pbkdf2-sha1.c
> index 3c864c6..0f5211b 100644
> --- a/lib/gc-pbkdf2-sha1.c
> +++ b/lib/gc-pbkdf2-sha1.c
> @@ -1,5 +1,5 @@
>  /* gc-pbkdf2-sha1.c --- Password-Based Key Derivation Function a'la PK=
CS#5
> -   Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation=
, Inc.
> +   Copyright (C) 2002, 2003, 2004, 2005, 2006, 2009 Free Software Foun=
dation, Inc.
> =20
>     This program is free software; you can redistribute it and/or modif=
y
>     it under the terms of the GNU General Public License as published b=
y
> @@ -15,8 +15,7 @@
>     along with this program; if not, write to the Free Software Foundat=
ion,
>     Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. =
 */
> =20
> -/* Written by Simon Josefsson.  The comments in this file are taken
> -   from RFC 2898.  */
> +/* Written by Simon Josefsson. */
> =20
>  #include <config.h>
> =20
> @@ -25,32 +24,12 @@
>  #include <stdlib.h>
>  #include <string.h>
> =20
> -/*
> - * 5.2 PBKDF2
> - *
> - *  PBKDF2 applies a pseudorandom function (see Appendix B.1 for an
> - *  example) to derive keys. The length of the derived key is essentia=
lly
> - *  unbounded. (However, the maximum effective search space for the
> - *  derived key may be limited by the structure of the underlying
> - *  pseudorandom function. See Appendix B.1 for further discussion.)
> - *  PBKDF2 is recommended for new applications.
> - *
> - *  PBKDF2 (P, S, c, dkLen)
> - *
> - *  Options:        PRF        underlying pseudorandom function (hLen
> - *                             denotes the length in octets of the
> - *                             pseudorandom function output)
> - *
> - *  Input:          P          password, an octet string (ASCII or UTF=
-8)
> - *                  S          salt, an octet string
> - *                  c          iteration count, a positive integer
> - *                  dkLen      intended length in octets of the derive=
d
> - *                             key, a positive integer, at most
> - *                             (2^32 - 1) * hLen
> - *
> - *  Output:         DK         derived key, a dkLen-octet string
> - */
> -
> +/* Implement PKCS#5 PBKDF2 as per RFC 2898.  The PRF to use is hard
> +   coded to be HMAC-SHA1.  Inputs are the password P of length PLEN,
> +   the salt S of length SLEN, the iteration counter C (> 0), and the
> +   desired derived output length DKLEN.  Output buffer is DK which
> +   must have room for at least DKLEN octets.  The output buffer will
> +   be filled with the derived data.  */
>  Gc_rc
>  gc_pbkdf2_sha1 (const char *P, size_t Plen,
>               const char *S, size_t Slen,
> @@ -75,74 +54,12 @@ gc_pbkdf2_sha1 (const char *P, size_t Plen,
>    if (dkLen =3D=3D 0)
>      return GC_PKCS5_INVALID_DERIVED_KEY_LENGTH;
> =20
> -  /*
> -   *
> -   *  Steps:
> -   *
> -   *     1. If dkLen > (2^32 - 1) * hLen, output "derived key too long=
" and
> -   *        stop.
> -   */
> -
>    if (dkLen > 4294967295U)
>      return GC_PKCS5_DERIVED_KEY_TOO_LONG;
> =20
> -  /*
> -   *     2. Let l be the number of hLen-octet blocks in the derived ke=
y,
> -   *        rounding up, and let r be the number of octets in the last=

> -   *        block:
> -   *
> -   *                  l =3D CEIL (dkLen / hLen) ,
> -   *                  r =3D dkLen - (l - 1) * hLen .
> -   *
> -   *        Here, CEIL (x) is the "ceiling" function, i.e. the smalles=
t
> -   *        integer greater than, or equal to, x.
> -   */
> -
>    l =3D ((dkLen - 1) / hLen) + 1;
>    r =3D dkLen - (l - 1) * hLen;
> =20
> -  /*
> -   *     3. For each block of the derived key apply the function F def=
ined
> -   *        below to the password P, the salt S, the iteration count c=
, and
> -   *        the block index to compute the block:
> -   *
> -   *                  T_1 =3D F (P, S, c, 1) ,
> -   *                  T_2 =3D F (P, S, c, 2) ,
> -   *                  ...
> -   *                  T_l =3D F (P, S, c, l) ,
> -   *
> -   *        where the function F is defined as the exclusive-or sum of=
 the
> -   *        first c iterates of the underlying pseudorandom function P=
RF
> -   *        applied to the password P and the concatenation of the sal=
t S
> -   *        and the block index i:
> -   *
> -   *                  F (P, S, c, i) =3D U_1 \xor U_2 \xor ... \xor U_=
c
> -   *
> -   *        where
> -   *
> -   *                  U_1 =3D PRF (P, S || INT (i)) ,
> -   *                  U_2 =3D PRF (P, U_1) ,
> -   *                  ...
> -   *                  U_c =3D PRF (P, U_{c-1}) .
> -   *
> -   *        Here, INT (i) is a four-octet encoding of the integer i, m=
ost
> -   *        significant octet first.
> -   *
> -   *     4. Concatenate the blocks and extract the first dkLen octets =
to
> -   *        produce a derived key DK:
> -   *
> -   *                  DK =3D T_1 || T_2 ||  ...  || T_l<0..r-1>
> -   *
> -   *     5. Output the derived key DK.
> -   *
> -   *  Note. The construction of the function F follows a "belt-and-
> -   *  suspenders" approach. The iterates U_i are computed recursively =
to
> -   *  remove a degree of parallelism from an opponent; they are exclus=
ive-
> -   *  ored together to reduce concerns about the recursion degeneratin=
g
> -   *  into a small set of values.
> -   *
> -   */
> -
>    tmp =3D malloc (tmplen);
>    if (tmp =3D=3D NULL)
>      return GC_MALLOC_ERROR;
>  =20


--=20
Regards
Vladimir 'phcoder' Serbinenko


Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

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