Class: BCryptPbkdf::Engine

Inherits:
Object
  • Object
show all
Defined in:
ext/mri/bcrypt_pbkdf_ext.c

Class Method Summary collapse

Class Method Details

.__bc_crypt_hash(pass, salt) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'ext/mri/bcrypt_pbkdf_ext.c', line 26

static VALUE bc_crypt_hash(VALUE self, VALUE pass, VALUE salt) {
  u_int8_t hash[BCRYPT_HASHSIZE];
  if (RSTRING_LEN(pass) != 64U)
    return Qnil;
  if (RSTRING_LEN(salt) != 64U)
    return Qnil;
  bcrypt_hash((const u_int8_t*)StringValuePtr(pass), (const u_int8_t*)StringValuePtr(salt), hash);
  return rb_str_new((const char*)hash, sizeof(hash));
}

.__bc_crypt_pbkdf(pass, salt, keylen, rounds) ⇒ Object

Given a secret and a salt a key and the number of rounds and returns the encrypted secret



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'ext/mri/bcrypt_pbkdf_ext.c', line 9

static VALUE bc_crypt_pbkdf(VALUE self, VALUE pass, VALUE salt, VALUE keylen, VALUE rounds) {
  size_t okeylen = NUM2ULONG(keylen);
  u_int8_t* okey = xmalloc(okeylen);
  VALUE out;

  int ret = bcrypt_pbkdf(
    StringValuePtr(pass), RSTRING_LEN(pass),
    (const u_int8_t*)StringValuePtr(salt), RSTRING_LEN(salt),
    okey, okeylen,
    NUM2ULONG(rounds));
  if (ret < 0)
    return Qnil;
  out = rb_str_new((const char*)okey, okeylen);
  xfree(okey);
  return out;
}