RSA
RSA 是基于整数因子分解困难性的公钥密码算法家族基础,可用于构造公钥加密、数字签名和部分密钥建立方案;实际安全性取决于 OAEP、PSS 等具体 scheme,而不是裸模幂运算本身。
[!info] related notes
RSA
一句话定义
RSA 是一种基于整数因子分解困难性的公钥密码算法基础。
它可以用于构造:
- public-key encryption;
- digital signature;
- 某些 key establishment / key transport scheme。
但裸 RSA 数学运算本身不是安全协议。真正部署时必须使用经过标准化的 padding、encoding 和 protocol。
密钥生成
典型 RSA key generation:
- 选择大素数 p 与 q;
- 计算 n = p × q;
- 计算与 p-1、q-1 相关的群结构参数;
- 选择 public exponent e;
- 计算 private exponent d。
公钥是 (n, e)。私钥核心是 d,实际实现还常保留 p、q 及 CRT 参数以加速运算。
教科书 RSA
教材常用 C = M^e mod n、M = C^d mod n 解释数学关系。
这不能直接作为安全加密方案,因为它:
- deterministic;
- 缺少 semantic security;
- 容易受到选择密文等攻击;
- 对 message space 和格式有严格约束。
实际加密应使用标准 scheme,例如 RSA-OAEP,而不是 textbook RSA。
RSA Encryption
公钥加密的典型方向:
recipient public key → encrypt
recipient private key → decrypt
RSA 通常只用于较小 secret / key material,不适合直接加密大文件。
现实系统更常:
public-key crypto → protect or establish symmetric key
symmetric AEAD → bulk data
RSA Signature
数字签名不是“私钥加密”。
现代 RSA signature scheme 例如 RSA-PSS,它有自己的 encoding、salt 和验证规则。
因此:
RSA-OAEP ≠ RSA-PSS
两者虽然都基于 RSA 数学结构,但安全目标不同。
RSA 的安全基础
攻击者已知 n = p × q 与 e。如果能高效恢复 p、q,就可以进一步恢复 private-key information。
但实际 RSA 安全还取决于:
- 随机数;
- padding;
- side-channel;
- key generation;
- protocol;
- implementation。
不能只说“分解 n 很难,所以 RSA 一定安全”。
Key Size
常见工程实践仍以至少 2048-bit RSA 为基础线;更高 security strength 可能需要更长 key。
key size 不能脱离:
- 使用期限;
- security strength;
- 标准/行业要求;
- 性能与兼容性;
独立判断。
与 ECC 比较时,也不能把 RSA 2048 与 ECC 256 直接按 bit 数大小比较。
CRT
RSA private operation 常用 Chinese Remainder Theorem 优化:
mod p + mod q → combine
它能显著加速 private-key operation,但 fault attack 也说明优化路径仍必须考虑 side-channel / fault resistance。
RSA 在现代协议中的位置
RSA 仍广泛用于:
- certificate public key;
- digital signature;
- legacy / compatible key transport;
- enterprise/security infrastructure。
但现代 TLS 的 ephemeral key agreement 通常更多依赖 ECDHE,而不是使用 RSA key transport 建立 session secret。
常见误区
RSA = 公钥加密
不完整。RSA 还可以构造 signature 和 key-establishment scheme。
RSA 私钥运算就是数字签名
错误。数字签名必须使用具体 signature scheme。
textbook RSA 可以直接用于业务加密
错误。必须使用安全 encoding/padding scheme。
RSA key 越长越绝对安全
错误。实现、协议和 side-channel 同样关键。
学习检查
- RSA 数学原语与 RSA-OAEP / RSA-PSS 的关系是什么?
- textbook RSA 为什么不能直接当作安全 encryption scheme?
- RSA 为什么通常不直接加密大文件?
- RSA-PSS 为什么不能简单理解成“私钥加密 hash”?
- key size 为什么不能脱离 security strength 与使用期限判断?
- 为什么现代 TLS 即使 certificate 是 RSA,也可能用 ECDHE 建立 session key?