Module: CcipherFactory::KDF::Scrypt
- Includes:
- Common, TR::CondUtils
- Defined in:
- lib/ccipher_factory/kdf/scrypt.rb
Instance Attribute Summary collapse
-
#attachedDigest ⇒ Object
Returns the value of attribute attachedDigest.
-
#attachedValue ⇒ Object
Returns the value of attribute attachedValue.
-
#blocksize ⇒ Object
Mixin methods.
-
#cost ⇒ Object
Mixin methods.
-
#derivedVal ⇒ Object
readonly
Returns the value of attribute derivedVal.
-
#digest ⇒ Object
Returns the value of attribute digest.
-
#digestAlgo ⇒ Object
Returns the value of attribute digestAlgo.
-
#outByteLength ⇒ Object
Mixin methods.
-
#parallel ⇒ Object
Mixin methods.
-
#salt ⇒ Object
Mixin methods.
Instance Method Summary collapse
- #derive_final(&block) ⇒ Object
- #derive_init(*args, &block) ⇒ Object
- #derive_update(val) ⇒ Object
- #is_attached_mode? ⇒ Boolean
Methods included from Common
#attach_mode, #cleanup_intOutputBuf, #cleanup_intOutputFile, #detach_mode, #disposeOutput, #intOutputBuf, #intOutputFile, #is_attach_mode?, #is_output_given?, #output, #output_obj, #sanitize_symbol, #write_to_output
Instance Attribute Details
#attachedDigest ⇒ Object
Returns the value of attribute attachedDigest.
17 18 19 |
# File 'lib/ccipher_factory/kdf/scrypt.rb', line 17 def attachedDigest @attachedDigest end |
#attachedValue ⇒ Object
Returns the value of attribute attachedValue.
17 18 19 |
# File 'lib/ccipher_factory/kdf/scrypt.rb', line 17 def attachedValue @attachedValue end |
#blocksize ⇒ Object
Mixin methods
15 16 17 |
# File 'lib/ccipher_factory/kdf/scrypt.rb', line 15 def blocksize @blocksize end |
#cost ⇒ Object
Mixin methods
15 16 17 |
# File 'lib/ccipher_factory/kdf/scrypt.rb', line 15 def cost @cost end |
#derivedVal ⇒ Object (readonly)
Returns the value of attribute derivedVal.
18 19 20 |
# File 'lib/ccipher_factory/kdf/scrypt.rb', line 18 def derivedVal @derivedVal end |
#digest ⇒ Object
Returns the value of attribute digest.
16 17 18 |
# File 'lib/ccipher_factory/kdf/scrypt.rb', line 16 def digest @digest end |
#digestAlgo ⇒ Object
Returns the value of attribute digestAlgo.
16 17 18 |
# File 'lib/ccipher_factory/kdf/scrypt.rb', line 16 def digestAlgo @digestAlgo end |
#outByteLength ⇒ Object
Mixin methods
15 16 17 |
# File 'lib/ccipher_factory/kdf/scrypt.rb', line 15 def outByteLength @outByteLength end |
#parallel ⇒ Object
Mixin methods
15 16 17 |
# File 'lib/ccipher_factory/kdf/scrypt.rb', line 15 def parallel @parallel end |
#salt ⇒ Object
Mixin methods
15 16 17 |
# File 'lib/ccipher_factory/kdf/scrypt.rb', line 15 def salt @salt end |
Instance Method Details
#derive_final(&block) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/ccipher_factory/kdf/scrypt.rb', line 67 def derive_final(&block) raise KDFError, "outByteLength is required" if is_empty?(@outByteLength) digMeta = @digest.digest_final sconf = Ccrypto::ScryptConfig.new sconf.outBitLength = @outByteLength*8 sconf.salt = @salt sconf.cost = @cost sconf.parallel = @parallel sconf.blockSize = @blocksize scrypt = Ccrypto::AlgoFactory.engine(sconf) @derivedVal = scrypt.derive(intOutputBuf.bytes) if is_output_given? write_to_output(@derivedVal) end ts = BinStruct.instance.struct(:kdf_scrypt) ts.digest = digMeta ts.salt = @salt ts.cost = @cost ts.blocksize = @blocksize ts.parallel = @parallel ts.outByteLength = @outByteLength if is_bool?(@attachedDigest) and @attachedDigest ts.value = @derivedVal else ts.value = "" end ts.encoded end |
#derive_init(*args, &block) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/ccipher_factory/kdf/scrypt.rb', line 19 def derive_init(*args, &block) len = args.first @outByteLength = len/8 if not_empty?(len) @cost = 65536 if is_empty?(@cost) @parallel = 1 if is_empty?(@parallel) @blocksize = 8 if is_empty?(@blocksize) @salt = SecureRandom.random_bytes(16) if is_empty?(@salt) logger.debug "Cost : #{@cost}" logger.debug "Parallel : #{@parallel}" logger.debug "Blocksize : #{@blocksize}" logger.debug "Salt : #{@salt.inspect}" logger.debug "Digest Algo : #{@digestAlgo}" logger.debug "Digest : #{@digest}" if @digest.nil? logger.debug "Initializing digest with algo #{@digestAlgo}" @digestAlgo = Digest::SupportedDigest.instance.default_digest if is_empty?(@digestAlgo) @digest = Digest.instance @digest.digest_init(@digestAlgo) else logger.debug "Setting digest algo value from digest #{@digest}" @digestAlgo = @digest.algo end @digest.output(intOutputBuf) if is_empty?(@attachedValue) @attachedDigest = false if is_empty?(@attachedDigest) else @attachedDigest = true end if block instance_eval(&block) derive_final else self end end |
#derive_update(val) ⇒ Object
63 64 65 |
# File 'lib/ccipher_factory/kdf/scrypt.rb', line 63 def derive_update(val) @digest.digest_update(val) end |
#is_attached_mode? ⇒ Boolean
104 105 106 107 108 109 110 |
# File 'lib/ccipher_factory/kdf/scrypt.rb', line 104 def is_attached_mode? if is_empty?(@attachedValue) @attachedDigest else true end end |