Class: CcipherBox::Keybox
- Inherits:
-
Object
- Object
- CcipherBox::Keybox
- Includes:
- TR::CondUtils
- Defined in:
- lib/ccipher_box/keybox.rb
Overview
Abstraction of deriving a key from a given base key (baseMat) and the Key Derivation Function (KDF). With the two inputs, a derive key would be provided via dkey() API
Instance Attribute Summary collapse
-
#baseMat ⇒ Object
Returns the value of attribute baseMat.
-
#kdf ⇒ Object
Returns the value of attribute kdf.
-
#outBitLength ⇒ Object
Returns the value of attribute outBitLength.
Class Method Summary collapse
Instance Method Summary collapse
- #dkey ⇒ Object
- #encoded ⇒ Object
-
#initialize(kdfEngine = nil) ⇒ Keybox
constructor
A new instance of Keybox.
Constructor Details
#initialize(kdfEngine = nil) ⇒ Keybox
Returns a new instance of Keybox.
14 15 16 17 18 19 20 21 22 |
# File 'lib/ccipher_box/keybox.rb', line 14 def initialize(kdfEngine = nil) raise KeyboxException, "Instance of KDF engine (CcipherFactory::KDF::KDFEngine) required" if not_empty?(kdfEngine) and not kdfEngine.is_a?(CcipherFactory::KDF::KDFEngine) @kdfEng = kdfEngine if not @kdfEng.nil? @kdfOut = MemBuf.new @kdfEng.output(@kdfOut) end end |
Instance Attribute Details
#baseMat ⇒ Object
Returns the value of attribute baseMat.
12 13 14 |
# File 'lib/ccipher_box/keybox.rb', line 12 def baseMat @baseMat end |
#kdf ⇒ Object
Returns the value of attribute kdf.
12 13 14 |
# File 'lib/ccipher_box/keybox.rb', line 12 def kdf @kdf end |
#outBitLength ⇒ Object
Returns the value of attribute outBitLength.
12 13 14 |
# File 'lib/ccipher_box/keybox.rb', line 12 def outBitLength @outBitLength end |
Class Method Details
.from_encoded(bin) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/ccipher_box/keybox.rb', line 24 def self.from_encoded(bin) raise KeyboxException, "Given binary is empty" if is_empty?(bin) st = BinStruct.instance.struct_from_bin(bin) kdfEng = CcipherFactory::KDF.from_encoded(st.kdfConfig) Keybox.new(kdfEng) end |
Instance Method Details
#dkey ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/ccipher_box/keybox.rb', line 66 def dkey if @dkeyVal.nil? raise KeyboxException, "BaseMat not given" if is_empty?(@baseMat) kdfEng.derive_update(@baseMat) @kdfConfig = kdfEng.derive_final @dkeyVal = @kdfOut.bytes.clone @kdfOut.dispose end @dkeyVal end |
#encoded ⇒ Object
85 86 87 88 89 |
# File 'lib/ccipher_box/keybox.rb', line 85 def encoded st = BinStruct.instance.struct(:keybox) st.kdfConfig = @kdfConfig st.encoded end |