Module: Crypto

Defined in:
lib/common.rb

Class Method Summary collapse

Class Method Details

.blake2_128(bytes) ⇒ Object



68
69
70
# File 'lib/common.rb', line 68

def self.blake2_128(bytes)
  Blake2b.hex bytes, 16
end

.blake2_128_concat(bytes) ⇒ Object



76
77
78
# File 'lib/common.rb', line 76

def self.blake2_128_concat(bytes)
  blake2_128(bytes) + bytes.bytes_to_hex[2..]
end

.blake2_256(bytes) ⇒ Object



72
73
74
# File 'lib/common.rb', line 72

def self.blake2_256(bytes)
  Blake2b.hex bytes, 32
end

.identity(bytes) ⇒ Object



44
45
46
# File 'lib/common.rb', line 44

def self.identity(bytes)
  bytes.bytes_to_hex[2..]
end

.twox128(data) ⇒ Object



54
55
56
57
58
59
60
61
# File 'lib/common.rb', line 54

def self.twox128(data)
  bytes = []
  2.times do |i|
    result = XXhash.xxh64 data, i
    bytes = bytes + result.to_s(16).rjust(16, '0').hex_to_bytes.reverse
  end
  bytes.bytes_to_hex[2..]
end

.twox64(data) ⇒ Object



48
49
50
51
52
# File 'lib/common.rb', line 48

def self.twox64(data)
  result = XXhash.xxh64 data, 0
  bytes = result.to_s(16).rjust(16, '0').hex_to_bytes.reverse
  bytes.bytes_to_hex[2..]
end

.twox64_concat(bytes) ⇒ Object



63
64
65
66
# File 'lib/common.rb', line 63

def self.twox64_concat(bytes)
  data = bytes.bytes_to_utf8
  twox64(data) + bytes.bytes_to_hex[2..]
end