Module: Crypto::OneTimeAuth
- Extended by:
- FFI::Library, Sodium::Utils
- Defined in:
- lib/crypto/one_time_auth.rb
Defined Under Namespace
Classes: State
Constant Summary
collapse
- PRIMITIVE =
primitive.freeze
- BYTES =
bytes.freeze
- KEYBYTES =
keybytes.freeze
Sodium::Utils::HEXY, Sodium::Utils::ZERO
Class Method Summary
collapse
bin2hex, check_length, get_size, hex2bin, zeros
Class Method Details
.final(state) ⇒ Object
72
73
74
75
76
|
# File 'lib/crypto/one_time_auth.rb', line 72
def final(state)
mac = zeros(BYTES)
crypto_onetimeauth_final(state, mac)
mac
end
|
.init(key) ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/crypto/one_time_auth.rb', line 56
def init(key)
check_length(key, KEYBYTES, :SecretKey)
state = State.new
key.readonly if key.is_a?(Sodium::SecretBuffer)
crypto_onetimeauth_init(state, key)
state
ensure
key.noaccess if key.is_a?(Sodium::SecretBuffer)
end
|
.onetimeauth(message, key) ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/crypto/one_time_auth.rb', line 34
def onetimeauth(message, key)
check_length(key, KEYBYTES, :SecretKey)
mac = zeros(BYTES)
key.readonly if key.is_a?(Sodium::SecretBuffer)
crypto_onetimeauth(mac, message, get_size(message), key)
mac
ensure
key.noaccess if key.is_a?(Sodium::SecretBuffer)
end
|
.update(state, message) ⇒ Object
68
69
70
|
# File 'lib/crypto/one_time_auth.rb', line 68
def update(state, message)
crypto_onetimeauth_update(state, message, get_size(message))
end
|
.verify(mac, message, key) ⇒ Object
46
47
48
49
50
51
52
53
54
|
# File 'lib/crypto/one_time_auth.rb', line 46
def verify(mac, message, key)
check_length(mac, BYTES, :Mac)
check_length(key, KEYBYTES, :SecretKey)
key.readonly if key.is_a?(Sodium::SecretBuffer)
crypto_onetimeauth_verify(mac, message, get_size(message), key) == 0
ensure
key.noaccess if key.is_a?(Sodium::SecretBuffer)
end
|