Module: Botan::KDF
- Defined in:
- lib/botan/kdf.rb
Overview
Key Derivation Functions
Examples
examples/kdf.rb
Class Method Summary collapse
-
.kdf(secret:, key_length:, label: '', algo: DEFAULT_KDF_ALGO, salt: RNG.get(DEFAULT_KDF_SALT_LENGTH)) ⇒ String
Derives a key using the given KDF algorithm.
-
.pbkdf(password:, key_length:, algo: DEFAULT_PBKDF_ALGO, iterations: DEFAULT_KDF_ITERATIONS, salt: RNG.get(DEFAULT_KDF_SALT_LENGTH)) ⇒ String
Derives a key using the given PBKDF algorithm.
-
.pbkdf_timed(password:, key_length:, milliseconds:, algo: DEFAULT_PBKDF_ALGO, salt: RNG.get(DEFAULT_KDF_SALT_LENGTH)) ⇒ Hash<Symbol>
Derives a key using the given PBKDF algorithm.
Class Method Details
.kdf(secret:, key_length:, label: '', algo: DEFAULT_KDF_ALGO, salt: RNG.get(DEFAULT_KDF_SALT_LENGTH)) ⇒ String
Derives a key using the given KDF algorithm.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/botan/kdf.rb', line 25 def self.kdf(secret:, key_length:, label: '', algo: DEFAULT_KDF_ALGO, salt: RNG.get(DEFAULT_KDF_SALT_LENGTH)) out_buf = FFI::MemoryPointer.new(:uint8, key_length) secret_buf = FFI::MemoryPointer.from_data(secret) salt_buf = FFI::MemoryPointer.from_data(salt) label_buf = FFI::MemoryPointer.from_data(label) Botan.call_ffi(:botan_kdf, algo, out_buf, out_buf.size, secret_buf, secret_buf.size, salt_buf, salt_buf.size, label_buf, label_buf.size) out_buf.read_bytes(key_length) end |
.pbkdf(password:, key_length:, algo: DEFAULT_PBKDF_ALGO, iterations: DEFAULT_KDF_ITERATIONS, salt: RNG.get(DEFAULT_KDF_SALT_LENGTH)) ⇒ String
Derives a key using the given PBKDF algorithm.
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/botan/kdf.rb', line 50 def self.pbkdf(password:, key_length:, algo: DEFAULT_PBKDF_ALGO, iterations: DEFAULT_KDF_ITERATIONS, salt: RNG.get(DEFAULT_KDF_SALT_LENGTH)) out_buf = FFI::MemoryPointer.new(:uint8, key_length) salt_buf = FFI::MemoryPointer.from_data(salt) Botan.call_ffi(:botan_pbkdf, algo, out_buf, key_length, password, salt_buf, salt_buf.size, iterations) out_buf.read_bytes(key_length) end |
.pbkdf_timed(password:, key_length:, milliseconds:, algo: DEFAULT_PBKDF_ALGO, salt: RNG.get(DEFAULT_KDF_SALT_LENGTH)) ⇒ Hash<Symbol>
Derives a key using the given PBKDF algorithm.
72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/botan/kdf.rb', line 72 def self.pbkdf_timed(password:, key_length:, milliseconds:, algo: DEFAULT_PBKDF_ALGO, salt: RNG.get(DEFAULT_KDF_SALT_LENGTH)) out_buf = FFI::MemoryPointer.new(:uint8, key_length) salt_buf = FFI::MemoryPointer.from_data(salt) iterations_ptr = FFI::MemoryPointer.new(:size_t) Botan.call_ffi(:botan_pbkdf_timed, algo, out_buf, key_length, password, salt_buf, salt_buf.size, milliseconds, iterations_ptr) { iterations: iterations_ptr.read(:size_t), key: out_buf.read_bytes(key_length) } end |