Created
December 11, 2018 23:34
-
-
Save gr33n7007h/4f7f5e4b1a3cb7d55024eb9635575643 to your computer and use it in GitHub Desktop.
argon2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'fiddle/import' | |
module Test | |
extend Fiddle::Importer | |
dlload '/usr/lib/libargon2.so.1' | |
typealias 'uint8_t', 'unsigned char' | |
typealias 'uint32_t', 'unsigned int' | |
Argon2_Context = struct [ | |
'uint8_t *out', # output array | |
'uint32_t outlen', # digest length | |
'uint8_t *pwd', # password array | |
'uint32_t pwdlen', # password len | |
'uint8_t *salt', # salt array | |
'uint32_t saltlen', # salt length | |
'uint8_t *secret', # key array | |
'uint32_t secretlen', # key length | |
'uint8_t *ad', # associated data array | |
'uint32_t adlen', # associated data length | |
'uint32_t t_cost', # number of iterations | |
'uint32_t m_cost', # amount of memory requested (KB) | |
'uint32_t lanes', # number of lanes | |
'uint32_t threads', # maximum number of threads | |
'uint32_t version', # version number | |
'void **allocate_cbk', | |
'void *free_cbk', | |
'uint32_t flags' # array of bool options | |
] | |
extern 'int argon2i_ctx(Argon2_Context *context)' | |
extern 'int argon2i_verify_ctx(Argon2_Context *context, const char *hash)' | |
end | |
hash = [''].pack('a128') | |
hashlen = hash.bytesize | |
pwd = 'password' | |
pwdlen = pwd.bytesize | |
secret = "i am a secret" | |
secretlen = secret.bytesize | |
salt = 'salty soy sauce' | |
saltlen = salt.bytesize | |
t_cost = 8 | |
m_cost = 1 << 16 | |
parallelism = 2 | |
argon2_context = Test::Argon2_Context.malloc | |
argon2_context.out = hash | |
argon2_context.outlen = hashlen | |
argon2_context.pwd = pwd | |
argon2_context.pwdlen = pwdlen | |
argon2_context.salt = salt | |
argon2_context.saltlen = saltlen | |
argon2_context.secret = secret | |
argon2_context.secretlen = secretlen | |
argon2_context.ad = nil | |
argon2_context.adlen = 0 | |
argon2_context.t_cost = t_cost | |
argon2_context.m_cost = m_cost | |
argon2_context.lanes = parallelism | |
argon2_context.threads = parallelism | |
argon2_context.version = 0x13 | |
argon2_context.allocate_cbk = Fiddle::NULL | |
argon2_context.free_cbk = Fiddle::NULL | |
argon2_context.flags = 0 | |
p Test.argon2i_ctx(argon2_context) | |
p argon2_context.out.to_s | |
p Test.argon2i_verify_ctx(argon2_context, argon2_context.out) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment