lua-argon2-ffi

Argon2 密码哈希函数的 LuaJIT FFI 绑定

$ opm get thibaultcha/lua-argon2-ffi

lua-argon2-ffi

[![模块版本][badge-version-image]][luarocks-argon2-ffi] [![构建状态][badge-travis-image]][badge-travis-url] [![覆盖率状态][badge-coveralls-image]][badge-coveralls-url]

LuaJIT FFI 绑定用于 [Argon2] 密码哈希函数。

虽然 [lua-argon2] 通过 Lua C API 提供了 PUC Lua 绑定,但此模块是 LuaJIT FFI 的绑定,特别适合用于 [ngx_lua]/[OpenResty]。

需求

必须编译 [Argon2] 共享库并在您的系统中可用。

兼容性

  • 此模块的 0.x 版本与 Argon2 `20151206` 兼容

  • 此模块的 1.x 版本与 Argon2 `20160406` 及更高版本兼容。

  • 此模块的 3.x 版本与 Argon2 `20161029` 及更高版本兼容。

请参阅 [CI 构建][badge-coveralls-url] 以了解当前支持版本的状况。

安装

此绑定可以通过 Luarocks 安装

    $ luarocks install argon2-ffi

或通过 opm 安装

    $ opm get thibaultcha/lua-argon2-ffi

或者只需将 src/argon2.lua 文件复制到您的 LUA_PATH 中。

文档

注意:lua-argon2-ffi 使用与 [lua-argon2] 相同的 API,除了 lua-argon2 的默认设置功能。

此绑定的文档可在 <http://thibaultcha.github.io/lua-argon2/> 获取。

Argon2 密码哈希函数文档可在 <https://github.com/P-H-C/phc-winner-argon2> 获取。

示例

将密码哈希到编码字符串

    local argon2 = require "argon2"
    --- Prototype
    -- local encoded, err = argon2.hash_encoded(pwd, salt, opts)
    
    --- Argon2i
    local encoded = assert(argon2.hash_encoded("password", "somesalt"))
    -- encoded is "$argon2i$v=19$m=4096,t=3,p=1$c29tZXNhbHQ$iWh06vD8Fy27wf9npn6FXWiCX4K6pW6Ue1Bnzz07Z8A"
    
    --- Argon2d
    local encoded = assert(argon2.hash_encoded("password", "somesalt", {
      variant = argon2.variants.argon2_d
    }))
    -- encoded is "$argon2d$v=19$m=4096,t=3,p=1$c29tZXNhbHQ$2+JCoQtY/2x5F0VB9pEVP3xBNguWP1T25Ui0PtZuk8o"
    
    --- Argon2id
    local encoded = assert(argon2.hash_encoded("password", "somesalt", {
      variant = argon2.variants.argon2_id
    }))
    -- encoded is "$argon2id$v=19$m=4096,t=3,p=1$c29tZXNhbHQ$qLml5cbqFAO6YxVHhrSBHP0UWdxrIxkNcM8aMX3blzU"
    
    -- Hashing options
    local encoded = assert(argon2.hash_encoded("password", "somesalt", {
      t_cost = 4,
      m_cost = math.pow(2, 16), -- 65536 KiB
      parallelism = 2
    }))
    -- encoded is "$argon2i$v=19$m=65536,t=4,p=2$c29tZXNhbHQ$n6x5DKNWV8BOeKemQJRk7BU3hcaCVomtn9TCyEA0inM"

验证密码与编码字符串

    local argon2 = require "argon2"
    --- Prototype
    -- local ok, err = argon2.decrypt(hash, plain)
    
    local encoded = assert(argon2.hash_encoded("password", "somesalt"))
    -- encoded: argon2i encoded hash
    
    local ok, err = argon2.verify(encoded, "password")
    if err then
      error("could not verify: " .. err)
    end
    
    if not ok then
      error("The password does not match the supplied hash")
    end

许可证

工作在 MIT 许可证下授权。请查看 [P-H-C/phc-winner-argon2][Argon2] 以获取 Argon2 及参考实现的许可证。

[Argon2]: https://github.com/P-H-C/phc-winner-argon2 [lua-argon2]: https://github.com/thibaultCha/lua-argon2 [luarocks-argon2-ffi]: http://luarocks.org/modules/thibaultcha/argon2-ffi

[ngx_lua]: https://github.com/openresty/lua-nginx-module [OpenResty]: https://openresty.org.cn

[badge-travis-url]: https://travis-ci.org/thibaultcha/lua-argon2-ffi [badge-travis-image]: https://travis-ci.org/thibaultcha/lua-argon2-ffi.svg?branch=master [badge-version-image]: https://img.shields.io/badge/version-3.0.0-blue.svg?style=flat [badge-coveralls-url]: https://coveralls.io/github/thibaultcha/lua-argon2-ffi?branch=master [badge-coveralls-image]: https://coveralls.io/repos/github/thibaultcha/lua-argon2-ffi/badge.svg?branch=master

作者

Thibault Charbonnier (thibaultcha)

许可证

mit

依赖项

luajit

版本