本列表收录了存在潜在不安全的 ed25519 签名库,这些库提供了一个公共 API,允许将私钥和公钥作为签名函数的输入独立提供。误用这些公共 API 可能导致私钥泄露。
我们分析中的大多数仓库已收录于 IANIX :: 使用 Ed25519 的项目。
受影响库数量:45
公告发布后修复该问题的库数量:8
最后更新:2023 年 5 月 4 日
请注意,通常情况下,根据相关的 rfc8032,EdDSA 签名是确定性的,因此对于要签名的同一输入消息,会返回一个唯一的签名输出,其中包含两个元素:一个曲线点 R 和一个标量 S。
一个算法细节是,签名者的公钥只参与签名中 S 部分的确定性计算,而不参与 R 值的计算。后者意味着,如果攻击者能以某种方式将签名函数用作预言机(Oracle,接受任意公钥作为输入),那么对于同一条消息,有可能获得两个共享相同 R、仅在 S 部分有所不同的签名。遗憾的是,一旦发生这种情况,攻击者就可以轻松提取私钥;这篇 StackOverflow 帖子 解释了为何这是可行的。
话虽如此,公共 API 不应允许将解耦的私钥/公钥对作为签名输入。为了规避这一点,许多实现将公钥与私钥(或种子)一起存储,并将整个密钥对视为秘密,或者总是在签名函数内部重新派生公钥。不幸的是,大量现有库未能解决这个问题,它们允许任意公钥作为输入,却不检查输入的公钥是否与输入的私钥对应。
当然,这并不意味着所有依赖这些库的应用程序都容易遭受密钥泄露攻击;实际上,大多数可能是安全的,因为通常不会向用户公开受影响的 API,并且会在调用 sign 之前将公钥/私钥对绑定在一起。另一方面,即使这些 API 未公开,也有一些应用程序在私钥和公钥的管理与存储方面采用了不同的 TCB 威胁模型策略。话虽如此,为防止此攻击,开发人员还应对公钥强制执行完整性保护协议。
在此,我们列出一些受影响的库及其相关代码引用。
图 1. ed25519-dalek Rust crate 中 API 误用的示例。
C: OpenGNB
https://github.com/gnbdev/opengnb/blob/master/libs/ed25519/sign.c#L7
C: GNU Nettle
https://github.com/gnutls/nettle/blob/fe7ae87d1b837e82f7c7968b068bca7d853a4cec/ed25519-sha512-sign.c#L43
ASM/C: iroha-ed25519(Hyperledger 项目)
https://github.com/hyperledger/iroha-ed25519/blob/main/lib/ed25519/ref10/ed25519.c#L27
以及
https://github.com/hyperledger/iroha-ed25519/blob/main/lib/ed25519/amd64-64-24k-pic/ed25519.c#L30
C: ed25519-donna (Andrew Moon)
https://github.com/floodyberry/ed25519-donna/blob/master/ed25519.c#L59
C: ed25519 (Orson Peters)
https://github.com/orlp/ed25519/blob/master/src/sign.c#L7
C: libbrine (Kevin Smith)
https://github.com/kevsmith/libbrine/blob/master/src/ed25519/sign.c#L7
C++: Ed25519 (ArduinoLibs)
https://rweather.github.io/arduinolibs/classEd25519.html#a36ecf67b4c5d2d39a31888f56af1f8a5
C#: ed25519 (Hans Wolff)
https://github.com/hanswolff/ed25519/blob/master/Ed25519/Ed25519.cs#L146
C#: Ed25519 (CryptoManiac)
https://github.com/CryptoManiac/Ed25519/blob/972829ac688847895d5105f19ca1e5777131b421/Chaos.NaCl/Internal/Ed25519Ref10/keypair.cs#L7
Dart: ed25519_dart (Oleksii Semeshchuk)
https://github.com/semolex/ed25519_dart/blob/master/lib/src/ed25519_dart_base.dart#L200
C: Trezor firmware
修复在此 PR 中:https://github.com/trezor/trezor-firmware/pull/2349 (修复合并于 2022 年 6 月 27 日)
Java: ed25519-elisabeth (Jack Grigg)
修复在此提交中:https://github.com/cryptography-cafe/ed25519-elisabeth/commit/49545ce47d550fed807522dff86546c812ccbbac (修复合并于 2022 年 6 月 19 日)
C: Harbour (Viktor Szakats)
修复在此提交中:https://github.com/vszakats/hb/commit/bae610b63d35c6c1793d94a3bf9467c3b1eded18 (修复合并于 2022 年 6 月 30 日)
Rust/Wasm: polkadot-js/wasm
修复在此 PR 中:https://github.com/polkadot-js/wasm/pull/381/files (修复合并于 2022 年 7 月 3 日)
C: horse25519 (Yawning Angel)
修复在此 PR 中:https://github.com/Yawning/horse25519/pull/3 (修复合并于 2022 年 8 月 15 日)
Erlang: erlang-libdecaf
修复在此提交中:https://github.com/potatosalad/erlang-libdecaf/commit/16ba07ea122660e95f6cfa9107e28ed58bada713。逻辑问题在此 issue 中解决:ed25519-unsafe-libs/issues/7 (修复合并于 2022 年 8 月 28 日)
Rust: ed25519-dalek (Isis Agora Lovecruft)
修复在此 PR 中:https://github.com/dalek-cryptography/ed25519-dalek/pull/205 (修复合并于 2022 年 10 月 22 日)
C: Monocypher (Loup Vaillant)
修复在此提交中:https://github.com/LoupVaillant/Monocypher/commit/da7b5407d20329f21a53ea993f516fb55e2f5e26 (修复合并于 2023 年 2 月 27 日)
最初被报告为易受攻击、但根据社区反馈已从列表中移除的库。
Dart: riclava_ed25519 (riclava)
https://github.com/riclava/ed25519/blob/master/lib/ed25519.dart#L125
Clojure: ed25519 (Kevin Downey)
https://github.com/hiredman/ed25519/blob/master/src/ed25519/core.clj#L168
Haskell: hs-scraps (Vincent Hanquez)
https://github.com/vincenthz/hs-scraps/blob/master/Crypto/Signature/Ed25519.hs#L115
Java: ed25519-java (k3d3)
https://github.com/k3d3/ed25519-java/blob/master/ed25519.java#L144
Java: ed25519 (Bjorn Arnelid)
https://github.com/BjornArnelid/ed25519/blob/master/src/ed25519/application/Ed25519.java#L32
Java: Punisher.NaCl (Arpan Jati)
https://github.com/arpanj/Punisher.NaCl/blob/c9619ca3028b90d0556c0473e4eba1d429a3744c/Punisher.NaCl/src/Punisher/NaCl/Ed25519Operations.java#L72
Java: ED25519 (Mick Michalski)
https://github.com/michami/ED25519/blob/master/ED25519.java#L60
Java: vRallev/ECC-25519 (Ralf Wondratschek)
https://github.com/vRallev/ECC-25519/blob/master/ECC-25519-Java/src/main/java/net/vrallev/java/ecc/Ecc25519Helper.java#L102
Perl: Crypt::Ed25519 (Marc Lehmann)
https://metacpan.org/release/MLEHMANN/Crypt-Ed25519-0.9/view/Ed25519.pm#$signature-=-Crypt::Ed25519::sign-$message,-$public_key,-$private_key
Python: ed25519.py (Ed25519 作者)
https://ed25519.cr.yp.to/python/ed25519.py
Python: ed25519 (Python Cryptographic Authority)
https://github.com/pyca/ed25519/blob/main/ed25519.py#L243
(作者提到,它本来就不适合对抗侧信道攻击)
Python: python-pure25519 (Brian Warner)
https://github.com/warner/python-pure25519/blob/master/pure25519/eddsa.py#L21
Python: nmed25519 (naturalmessage)
https://github.com/naturalmessage/nmed25519/blob/master/nmed25519.py#L150
Python: ed25519.py (Shiho Midorikawa)
https://gist.github.com/elliptic-shiho/f41fd75cc30646a61d7ad63043fdd56e#file-ed25519-py-L77
Python: ed25519-dalek 的绑定:py-ed25519-bindings
https://github.com/polkascan/py-ed25519-bindings/blob/master/src/lib.rs#L111
Swift: ed25519swift (pebble8888)
https://github.com/pebble8888/ed25519swift/blob/master/Ed25519ref/ed25519s.swift#L120
JS: supercop.js (1p6 Flynx)
https://github.com/1p6/supercop.js/blob/master/index.js#L29
JS: substack/ed25519-supercop (James Halliday)
https://github.com/substack/ed25519-supercop/blob/master/index.js#L3
C: libeddsa (Philipp Lay)
https://github.com/phlay/libeddsa/blob/master/lib/ed25519-sha512.c#L85
C#: SommerEngineering/Ed25519 (Thorsten Sommer)
https://github.com/SommerEngineering/Ed25519/blob/master/Ed25519/Signer.cs#L80
CUDA: ChorusOne/solanity
https://github.com/ChorusOne/solanity/blob/master/src/cuda-ecc-ed25519/sign.cu#L10
C: ncme/c25519 (Daniel Beer and Nikolas Rösener)
https://github.com/ncme/c25519/blob/master/src/edsign.c#L115
C: luazen (Phil Leblanc)
https://github.com/philanc/luazen/blob/master/src/x25519.c#L508(作者修改了该函数,使其接受 pk,而不是原始的 nacl 64 字节 sk,后者将 pk 包含在最后 32 个字节中)
C++: amber (Pelayo Bernedo)
https://github.com/bernedogit/amber/blob/master/src/group25519.cpp#L1661
C: FLD ECC AVX2 (Armando Faz-Hern'{a}ndez and Julio L'{o}pez and Ricardo Dahab)
https://github.com/armfazh/fld-ecc-vec/blob/master/src/sign255.c#L391
Elixir: mwmiller/ed25519_ex (Matt Miller)
https://github.com/mwmiller/ed25519_ex/blob/master/lib/ed25519.ex#L146(公钥是可选的。根据作者评论:如果只提供私钥,则会从私钥推导出公钥。这会增加显著的开销)
PHP(C 包装器):php-ed25519-ext
https://github.com/encedo/php-ed25519-ext/blob/master/ed25519-ext.c#L93
Nim: niv/ed25519.nim (Bernhard Stöckner)
https://github.com/niv/ed25519.nim/blob/master/ed25519.nim#L26
Typescript: mipher (Marco Paland)
https://github.com/mpaland/mipher/blob/master/src/x25519.ts#L936
Lua: LuaMonocypher
https://github.com/philanc/luamonocypher/blob/main/src/luamonocypher.c#L268
Crystal: monocypher.cr
https://github.com/konovod/monocypher.cr/blob/master/src/monocypher.cr#L39
Python: py_ssh_keygen_ed25519 (Péter Szabó)
https://github.com/pts/py_ssh_keygen_ed25519/blob/master/ed25519_compact.py#L128(公钥是可选的)
Javascript: KinomaJS
https://github.com/Kinoma/kinomajs/blob/701879d37e7fe5001420e0053cd60df6b91e4553/xs6/extensions/crypt/crypt_ed25519.js#L92(公钥是可选的)
Haskell: gen-ed25-keypair
https://github.com/awakesecurity/gen-ed25-keypair
C: horse25519 (Yawning Angel)
https://github.com/Yawning/horse25519/blob/master/src/ref10/sign.c#L7 注意:该仓库包含从 supercop 中提取的 djb 的 ref10 ed25519 实现副本,以避免引入另一个依赖项,但其目的是提供一个独立的可执行文件,用于生成 ed25519 虚荣密钥对。虽然它以奇怪的方式使用该 API,但这是有意为之,因为它在密钥生成方面已经做了极其特殊和非同寻常的事情,并且该库并非用于签名。