AES-128-GCM 似乎不检查身份验证

Pat*_*ity 5 ruby encryption openssl cryptography

如果我正确理解 GCM 模式,它应该不仅提供加密,还提供密文的验证。然而,当我使用 Ruby 的 OpenSSL 实现以AES-256-GCM模式加密数据时,即使我篡改了auth_tag. 我在这里遗漏了一些东西还是实施确实被破坏了?

require 'openssl'

# ALICE encrypts some secret data

data = 'secret'
cipher = OpenSSL::Cipher.new('aes-128-gcm')
cipher.encrypt
key = cipher.random_key
iv = cipher.random_iv
cipher.auth_data = 'auth_data'
ciphertext = cipher.update(data) + cipher.final
auth_tag = cipher.auth_tag

# EVE tampers with the auth tag, e.g. dropping the last 10 bytes

auth_tag = auth_tag[0..-11]

# BOB decrypts the ciphertext

cipher = OpenSSL::Cipher.new('aes-128-gcm')
cipher.decrypt
cipher.key = key
cipher.iv = iv
cipher.auth_tag = auth_tag
cipher.auth_data = 'auth_data'
data = cipher.update(ciphertext) + cipher.final

# BOB is very sad because no error is raised!
Run Code Online (Sandbox Code Playgroud)

我正在使用内置 OpenSSL 版本的 OS X:

% openssl version
OpenSSL 0.9.8zg 14 July 2015
Run Code Online (Sandbox Code Playgroud)

Maa*_*wes 4

GCM 支持身份验证标签的多种尺寸。在这些版本中,通过删除右侧的字节来缩短身份验证标记。这正是攻击者所做的。

现在 API 非常不稳定。首先,(16 - 10) * 8 = 48,这不是AES -GCM 的有效大小(根据NIST SP 800-38D)。此外,身份验证标签大小应该是密码的输入或配置参数。至少,API 应警告用户自行检查身份验证标签大小,而不是只允许输入任何身份验证标签。

所以,是的,你错过了一些东西是的,我会说实现 - 或者至少是文档 - 被破坏了;接得好。