2 回答

TA貢獻2019條經(jīng)驗 獲得超9個贊
RFC 草案建議[2] time=1,memory=64*1024 是一個合理的數(shù)字。如果在某些情況下無法使用該內(nèi)存量 (64 MB),則可以增加時間參數(shù)以進行補償。
我認為這里的關鍵是“補償”這個詞,所以在這種情況下,它試圖說:要實現(xiàn)與 相似的哈希復雜性IDKey([]byte("some password"), salt, 1, 64*1024, 4, 32)
,你可以嘗試IDKey([]byte("some password"), salt, 4, 16*1024, 4, 32)
。
但是,如果您想降低散列結(jié)果的復雜性(并降低性能開銷),您可以減小memory uint32
忽略time
參數(shù)的大小。
這應該是 4 倍,以便內(nèi)存和時間的乘積保持不變?
我不這么認為,我相信memory
這里的意思是結(jié)果哈希的長度,但time
參數(shù)可能意味著“哈希結(jié)果需要重新哈希多少次,直到我得到最終結(jié)果”。
所以這兩個參數(shù)是相互獨立的。這些只是控制您想要實現(xiàn)多少“由于時間-內(nèi)存權(quán)衡而節(jié)省的蠻力成本”

TA貢獻2021條經(jīng)驗 獲得超8個贊
難度大致等于time_cost * memory_cost (并且可能/ parallelism)。所以如果你0.25x的內(nèi)存成本,你應該4x時間成本。另請參閱此答案。
// The time parameter specifies the number of passes over the memory and the
// memory parameter specifies the size of the memory in KiB.
查看 Argon2 API 本身。我將稍微交叉引用并使用argon2-cffi 文檔。貌似go接口在底層使用了C-FFI(外來函數(shù)接口) ,所以protoype應該是一樣的。
Parameters
time_cost (int) – Defines the amount of computation realized and therefore the execution time, given in number of iterations.
memory_cost (int) – Defines the memory usage, given in kibibytes.
parallelism (int) – Defines the number of parallel threads (changes the resulting hash value).
hash_len (int) – Length of the hash in bytes.
salt_len (int) – Length of random salt to be generated for each password.
encoding (str) – The Argon2 C library expects bytes. So if hash() or verify() are passed an unicode string, it will be encoded using this encoding.
type (Type) – Argon2 type to use. Only change for interoperability with legacy systems.
事實上,如果我們查看 Go 文檔:
// The draft RFC recommends[2] time=1, and memory=64*1024 is a sensible number.
// If using that amount of memory (64 MB) is not possible in some contexts then
// the time parameter can be increased to compensate.
//
// The time parameter specifies the number of passes over the memory and the
// memory parameter specifies the size of the memory in KiB. For example
// memory=64*1024 sets the memory cost to ~64 MB. The number of threads can be
// adjusted to the numbers of available CPUs. The cost parameters should be
// increased as memory latency and CPU parallelism increases. Remember to get a
// good random salt.
我不是 100% 清楚線程數(shù)的影響,但我相信它確實并行化了散列,并且像任何多線程作業(yè)一樣,這減少了大約1/NN 個內(nèi)核所花費的總時間。顯然,您應該將并行度設置為 cpu count。
- 2 回答
- 0 關注
- 424 瀏覽
添加回答
舉報