openresty / lua-resty-string

String utilities and common hash functions for ngx_lua and LuaJIT
429 stars 143 forks source link

help: Is the option `salt` in `new` function in `aes.lua` file mean initialization value? #90

Open ccxhwmy opened 2 years ago

ccxhwmy commented 2 years ago

Hi~ I am reading python code about Crypto.Cipher in website: https://www.pycryptodome.org/src/cipher/classic#ctr-mode I found the new function defined to Crypto.Cipher.<algorithm>.new(key, mode, *, nonce=None, initial_value=None, counter=None) Is the initial_value means the salt in : https://github.com/openresty/lua-resty-string/blob/78e5020229718c557484191c891a68097907d818/lib/resty/aes.lua#L120

Thank you~

oyiadin commented 1 year ago

nope, the initial counter value is specified in this way:

local resty_aes  = require("resty.aes")
local counter = "a 16-chars string"
-- an example: counter = hex2bin("00000000000000000000000000000001") means initial_value=1
-- note: length of counter is fixed as 128bits
local aes, err = resty_aes:new(
        key,                           -- key
        nil,                            -- salt
        resty_aes.cipher(192, "ctr"),   -- cipher mode
        {iv=counter},                   -- hash or options
        nil,                            -- hash rounds
        nil,                            -- iv len
        false                           -- enable padding
)