| 标准 | NIST SP 800-38B / RFC 4493 |
|---|---|
| 基础算法 | AES(也可用 3DES 等分组密码) |
| 输出 | 分组长度(AES 下 16 字节,可截断) |
| 与 HMAC 对比 | 无需哈希函数,依赖分组密码实现 |
Python 示例(cryptography)
Python 示例(cryptography)
from cryptography.hazmat.primitives import cmac
from cryptography.hazmat.primitives.ciphers import algorithms
c = cmac.CMAC(algorithms.AES(key))
c.update(b"message")
tag = c.finalize()OpenSSL 3 也可直接计算:openssl mac -macopt cipher:AES-256-CBC -macopt hexkey:<32 字节 hex> -in msg.bin CMAC。