gcry_kdf_derive

Werner Koch wk at gnupg.org
Wed Mar 9 17:56:31 CET 2011


Hi,

Libgcrypt 1.5.0 will have a new fucntion:

 -- Function: gpg_error_t gcry_kdf_derive ( const void *PASSPHRASE,
          size_t PASSPHRASELEN, int ALGO, int SUBALGO,
          const void *SALT, size_t SALTLEN, unsigned long ITERATIONS,
          size_t KEYSIZE, void *KEYBUFFER )
     Derive a key from a passphrase.  KEYSIZE gives the requested size
     of the keys in octets.  KEYBUFFER is a caller provided buffer
     filled on success with the derived key.  The input passphrase is
     taken from PASSPHRASE which is an arbitrary memory buffer of
     PASSPHRASELEN octets.  ALGO specifies the KDF algorithm to use;
     see below.  SUBALGO specifies an algorithm used internally by the
     KDF algorithms; this is usually a hash algorithm but certain KDF
     algorithms may use it differently.  SALT is a salt of length
     SALTLEN octets, as needed by most KDF algorithms.  ITERATIONS is a
     positive integer parameter to most KDFs.

     On success 0 is returned; on failure an error code.

     Currently supported KDFs (parameter ALGO):

    `GCRY_KDF_SIMPLE_S2K'
          The OpenPGP simple S2K algorithm (cf. RFC4880).  Its use is
          strongly deprecated.  SALT and ITERATIONS are not needed and
          may be passed as `NULL'/`0'.

    `GCRY_KDF_SALTED_S2K'
          The OpenPGP salted S2K algorithm (cf. RFC4880).  Usually not
          used.  ITERATIONS is not needed and may be passed as `0'.
          SALTLEN must be given as 8.

    `GCRY_KDF_ITERSALTED_S2K'
          The OpenPGP iterated+salted S2K algorithm (cf. RFC4880).
          This is the default for most OpenPGP applications.  SALTLEN
          must be given as 8.  Note that OpenPGP defines a special
          encoding of the ITERATIONS; however this function takes the
          plain decoded iteration count.
          plain decoded iteration count.

    `GCRY_KDF_PBKDF2'
          The PKCS#5 Passphrase Based Key Derivation Function number 2.


This allows us to factor the S2k code from gpg and gpg-agent out to
Libgcrypt.  Created a bunch of test vectors using a hacked gpg 1.4.
    
The function also implements PBKDF2; tested against the RFC-6070 test
vectors.

See tests/t-kdf.c for usage examples.


Salam-Shalom,

   Werner

-- 
Die Gedanken sind frei.  Ausnahmen regelt ein Bundesgesetz.




More information about the Gcrypt-devel mailing list