浏览器中的 Argon2 
Argon2是密码捕捉功能,是密码捕捉竞赛的得主. 这里的Argon2库是为浏览器运行时间而编译的.
数字
| 时间,ms(更低) | |
|---|---|
| 红色瓦斯姆 | 225 (韩语) |
| Chrome WASM+SIMD (英语) | 119国道 |
| Firefox 瓦斯姆语 | 195 (英语) |
| Firefox WASM+SIMD (火狐) 火狐WASM+SIMD | 135个 |
| 萨法里瓦斯姆 | 174国道 |
| 原生 - O3 SSE | 15个 |
| 原生 - O3 | 第42条 |
| 原生 - O1 | 第55条 |
| 原生 - O0 | 395个 |
测试环境
用于获取以上数字的环境:
算法参数( E)-d -t 100 -m 10 -p 1:
- 重复:100次
- 内存:1MiB(1024 KiB)
- 散列长度: 32
- 平行主义:1
- rg2d
环境:
- MacBook pro 2020, Intel Core i7, 2.3GHz (x64), macOS 10.14.6 (18G95) (英语)
- Chrome 85.0.4183 (官方建筑)
- Firefox 80.0.1 (英语)
- 萨法里 13.1.2 (15609.3.5.1.3)
- 已编译自 https://github.com/P-H-C/phc-winner-argon2 (中文(简体) ) @ 440ceb9 (韩语)
代码大小
ll -h dist
| 文件 | 代码大小, kB |
|---|---|
| rg2.js | 页:1 |
| rg2号 | 第25条 |
Argon2被修改了吗?
不,它使用的是上游的子模块.
锡默德
SIMD并不完全在WebAssembly, 但对于那些想尝试的人来说, 我们已经提供了一个工作建筑 与SIMD。 目前只在克罗姆工作, 要使用它,你需要添加 此起源审判 在你的网站上, 或启用 Chrome 旗帜中的 SIMD 特性.
更多关于V8的WebAssembly SIMD支持: https://v8.dev/features/simd (英语)
在 Firefox 上, 您需要启用 javascript.options.wasm_simd 选项.
要使用 SIMD 版本, 装入 argon2-simd.wasm 改为 argon2.wasm。 。 。 .
JS 图书馆
库可以从 npm 安装 :
npm install argon2-browser
然后将这个脚本添加到您的 HTML 或者使用您最喜欢的捆绑器 :
<script src="node_modules/argon2-browser/dist/argon2.min.js"></script>
或者,可以使用捆绑的版本,这样可以只包含一个脚本:
<script src="node_modules/argon2-browser/dist/argon2-bundled.min.js"></script>
计算散列 :
argon2.hash({ pass: 'password', salt: 'somesalt' })
.then(h => console.log(h.hash, h.hashHex, h.encoded))
.catch(e => console.error(e.message, e.code))
验证编码的散列( 如果您需要的话) :
argon2.verify({ pass: 'password', encoded: 'enc-hash' })
.then(() => console.log('OK'))
.catch(e => console.error(e.message, e.code))
其他参数:
argon2.hash({
// required
pass: 'password',
salt: 'salt',
// optional
time: 1, // the number of iterations
mem: 1024, // used memory, in KiB
hashLen: 24, // desired hash length
parallelism: 1, // desired parallelism (it won't be computed in parallel, however)
secret: new Uint8Array([...]), // optional secret data
ad: new Uint8Array([...]), // optional associated data
type: argon2.ArgonType.Argon2d, // Argon2d, Argon2i, Argon2id
})
// result
.then(res => {
res.hash // hash as Uint8Array
res.hashHex // hash as hex-string
res.encoded // encoded hash, as required by argon2
})
// or error
.catch(err => {
err.message // error message as string, if available
err.code // numeric error code
})
argon2.verify({
// required
pass: 'password',
encoded: 'enc-hash',
// optional
secret: new Uint8Array([...]), // optional secret data
ad: new Uint8Array([...]), // optional associated data
type: argon2.ArgonType.Argon2d, // Argon2d, Argon2i, Argon2id. default: guess
})
// result
.then(res => {
res.hash // hash as Uint8Array
res.hashHex // hash as hex-string
res.encoded // encoded hash, as required by argon2
})
// or error
.catch(err => {
err.message // error message as string, if available
err.code // numeric error code
})
使用量
您可以以几种方式使用此模块:
炸弹
节点.js 支持
当然 可使用 在节点.js中生成WASM,但是这不合理:通过将其编译为本土节点.js addon,你会得到更好的速度,这并非那么难. 等等,它已经做了,只是安装 此软件包。 。 。 .
它在什么地方用过吗?
没错! 基网 (网络密码管理器)正在使用它作为密码散列函数执行. 检查源代码如果你有兴趣的话.
大楼
你可以用它来建造一切
./build.sh
先决条件:
- 附有WebAssembly支持的标语(怎么样(中文(简体) )
- 计算