OpenSSL 3.2.0新增Argon2支持——防GPU暴力攻击

1. 引言

OpenSSL新发布的3.20版本中,引入了一些新特性,包括:

  • post-quantum方法
  • Brainpool曲线
  • QUIC
  • Argon2:Argon2 是一种慢哈希函数,在 2015 年获得 Password Hashing Competition 冠军,利用大量内存计算抵御 GPU 和其他定制硬件的破解,提高哈希结果的安全性。
  • 等等

    Argon2开源实现见:
  • https://github.com/P-H-C/phc-winner-argon2(C)

Argon2: the memory-hard function for password hashing and other applications 由Alex Biryukov、Daniel Dinu 和 Dmitry Khovratovich 设计,为密钥派生函数(KDF,Key Derivation Function),可用于:

  • 创建密码的哈希值
  • 基于密码创建加密密钥
  • 2015年7月获得 Password Hashing Competition 冠军
  • 可抵抗GPU和侧道攻击。

Argon2利用大量内存和大量计算资源进行 Hash 计算,有三个变种:

  • 1)Argon2i:Argon2i使用独立于数据的内存访问,这是密码散列和基于密码的密钥派生的首选方法,但速度较慢,因为它会在内存中进行更多的传递,以防止受到折衷攻击。
  • 2)Argon2d:Argon2d是比较快的,被用于数据依赖的内存访问,这使得它对GPU破解攻击具有很高的抵抗力,适用于不受侧信道攻击威胁的应用程序(如加密货币)。
  • 3)Argon2id:Argon2id是Argon2i和Argon2d的混合体,使用依赖于数据和独立于数据的内存访问的组合,这使Argon2i能够抵抗侧通道缓存计时攻击,并使Argon2d能够抵抗GPU破解攻击。

Argon2i、Argon2d和Argon2id之间通过参数区分:

  • A time cost, which defines the amount of computation realized and therefore the execution time, given in number of iterations
  • A memory cost, which defines the memory usage, given in kibibytes
  • A parallelism degree, which defines the number of parallel threads

2. Password

Password 是 Web 服务主要的认证方式之一。

Password 一般以 Hash 后的形式存储在数据库中。这些数据库如果被拖库,使用 Dictionary Attack 可以轻松破解,因为他们的熵很低。相同的密码会被不同的用户使用或同一个用户在不同系统中使用。

为了解决这个问题,设计者在密码 Hash 的过程里加入了 salt。

Dictionary Attack 一个字典文件,储存了单词、短语、常用密码和他们 hash 后结果。将密码与 hash 结果对比,就能破解2

Brute Force Attack 尝试每一个给定长度下的字符组合,效率很低。

加盐已经可以解决大部分问题,但无法阻止 Brute Force Attack,借助 GPU、FPGA、ASIC 等定制硬件可以非常低成本的进行 Hash 计算。此外,如果 salt 和 password 被一起被拖库(甚至代码),会使得破解成本更加低。

这里核心的问题是,Hash 方法使用的是无内存计算的,而 GPU、ASIC 等硬件可以让无内存计算变得非常高效。但是,当一个 Hash 方法需要用到一大块内存去计算的时候,这些硬件就会束手无策。所以 memory-hard hash function 开始被设计和使用。

Memory-hard hash function 也可以被用在加密货币的工作量证明中,用来压制 GPU 和 ASIC 在加密货币中的滥用。例如 scrypt 被用作莱特币的工作量证明算法。

当今,8个(小写)字母的密码,可在10秒内暴力破解。若使用9个(小写)字母的密码,则可在10分钟内破解。若只是在密码末尾添加一个数字或让首字母大写,对破解速度几乎无影响。具体见Calculate Passwords

Argon2是抗GPU攻击的,同时具有内存开销。其开销包括:

  • 执行时长:CPU开销
  • 所需内存:内存开销
  • degree of parallelism并行度:以 p p p来表示

Argon2的参数有:

  • Password §: Defines the password bytes to be hashed
  • Salt (S): Defines the bytes to be used for salting.
  • Parallelism §: Defines the number of threads that are required for the parallelism.
  • TagLength (T): Define the number of bytes to return for the hash.
  • MemorySizeKB (m): Amount of memory (in KB) to use.

具体的bench性能为:【其中 n n n用于time cost, p p p用于parallelism, m m m为message】

由上图可发现:

  • 当 n = 128 n=128 n=128时,计算哈希值用时为0.105秒,即每秒可做10次哈希运算。
  • 当 n = 8192 n=8192 n=8192时,计算哈希值用时为5.78秒,这个时间对用户登录来说有点过长。

实际使用时,应选择哈希计算时长合理,且抵抗攻击足够强健的参数。

OpenSSL Argon2指令示例:

复制代码
Command: openssl kdf -keylen 24 -kdfopt pass:Hello -kdfopt salt:NaCl1234 -kdfopt iter:1 -kdfopt memcost:8 ARGON2I

Password: Hello
KDF: ARGON2
Salt: NaCl1234
Length: 24
Iterations: 1
Memcost: 8
-----------------
ARGON2I
7E:C8:58:7D:85:96:F6:9C:5A:13:F3:78:27:7C:DC:D5:FA:28:FF:B4:EC:C8:2F:00
ARGON2D
BB:13:EE:29:A3:38:95:D4:C5:81:5A:1B:0B:05:48:0E:22:53:F1:3F:13:12:16:F7
ARGON2ID
07:65:6A:7F:16:81:C8:85:39:68:0E:F4:64:92:2A:38:CE:7E:71:83:DE:72:39:0D

参考资料

1 Prof Bill Buchanan OBE 2023年11月博客 An Early Cybersecurity Christmas Present From OpenSSL: Some Argon

2 Argon2算法简介

相关推荐
小龙8 个月前
【基础理论】位置向量|位置编码学习笔记
大模型·transformer·基础理论·位置编码
mutourend3 年前
FRI及相关SNARKs的Fiat-Shamir安全
基础理论
mutourend3 年前
基于ASCON的AEAD
基础理论
mutourend3 年前
Hard Problems简介
基础理论
mutourend3 年前
GPU/CPU友好的模乘算法:Multi-Precision Fast Modular Multiplication
基础理论