Module: PBKDF256

Extended by:
PBKDF256
Included in:
PBKDF256
Defined in:
lib/pbkdf256.rb,
lib/pbkdf256/version.rb,
ext/core/_pbkdf256.c

Constant Summary collapse

VERSION =

PBKDF256 version

"0.1.3"

Class Method Summary collapse

Class Method Details

.pbkdf2_sha256(passwd, salt, iter, key_len) ⇒ String Also known as: dk, pbkdf2_sha256

Returns Computed derived key.

Parameters:

  • passwd (String)

    Passphrase used to compute the derived key.

  • salt (String)

    A series of random bits to help prevent ‘rainbow table’/pre-computed attacks.

  • iter (Fixnum)

    Number of computing iterations. A value of at least 2000 is recommended.

  • key_len (Fixnum)

    Length of desired derived key.

Returns:

  • (String)

    Computed derived key



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'ext/core/_pbkdf256.c', line 16

static VALUE
m_pbkdf2_hmac_sha256(VALUE self, VALUE passwd, VALUE salt, VALUE iter, VALUE key_len)
{
  StringValue(passwd);
  StringValue(salt);
  
  size_t dk_buff_len = NUM2UINT(key_len);
  
  VALUE s;
  s = rb_str_new(0, dk_buff_len);

  s_PBKDF2_SHA256((const uint8_t *) RSTRING_PTR(passwd), RSTRING_LEN(passwd), 
    (const uint8_t *) RSTRING_PTR(salt), RSTRING_LEN(salt), NUM2ULL(iter), 
    RSTRING_PTR(s), dk_buff_len);

  return s;
}