2 回答

TA贡献2019条经验 获得超9个赞
RFC 草案建议[2] time=1,memory=64*1024 是一个合理的数字。如果在某些情况下无法使用该内存量 (64 MB),则可以增加时间参数以进行补偿。
我认为这里的关键是“补偿”这个词,所以在这种情况下,它试图说:要实现与 相似的哈希复杂性IDKey([]byte("some password"), salt, 1, 64*1024, 4, 32)
,你可以尝试IDKey([]byte("some password"), salt, 4, 16*1024, 4, 32)
。
但是,如果您想降低散列结果的复杂性(并降低性能开销),您可以减小memory uint32
忽略time
参数的大小。
这应该是 4 倍,以便内存和时间的乘积保持不变?
我不这么认为,我相信memory
这里的意思是结果哈希的长度,但time
参数可能意味着“哈希结果需要重新哈希多少次,直到我得到最终结果”。
所以这两个参数是相互独立的。这些只是控制您想要实现多少“由于时间-内存权衡而节省的蛮力成本”

TA贡献2021条经验 获得超8个赞
难度大致等于time_cost * memory_cost (并且可能/ parallelism)。所以如果你0.25x的内存成本,你应该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(外来函数接口) ,所以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% 清楚线程数的影响,但我相信它确实并行化了散列,并且像任何多线程作业一样,这减少了大约1/NN 个内核所花费的总时间。显然,您应该将并行度设置为 cpu count。
- 2 回答
- 0 关注
- 486 浏览
添加回答
举报