Class: JWA::Support::ConcatKDF
- Inherits:
-
Object
- Object
- JWA::Support::ConcatKDF
- Defined in:
- lib/jwa/support/concat_kdf.rb
Instance Method Summary collapse
- #derive_key(reps, key_data_len, z, other_info) ⇒ Object
-
#initialize(hash) ⇒ ConcatKDF
constructor
A new instance of ConcatKDF.
- #run(z, other_info, key_data_len = nil) ⇒ Object
Constructor Details
#initialize(hash) ⇒ ConcatKDF
Returns a new instance of ConcatKDF.
4 5 6 7 |
# File 'lib/jwa/support/concat_kdf.rb', line 4 def initialize(hash) @hash = hash @default_key_len = hash.size * 8 end |
Instance Method Details
#derive_key(reps, key_data_len, z, other_info) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/jwa/support/concat_kdf.rb', line 16 def derive_key(reps, key_data_len, z, other_info) key_material = '' data = z + other_info (1..reps).each do |n| concatenation = [n, data].pack('Na*') key_material += @hash.digest(concatenation) end key_material[0...key_data_len / 8] end |
#run(z, other_info, key_data_len = nil) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/jwa/support/concat_kdf.rb', line 9 def run(z, other_info, key_data_len = nil) key_data_len ||= @default_key_len reps = (key_data_len / @default_key_len.to_f).ceil derive_key(reps, key_data_len, z, other_info) end |