Ed25519
使用纯 Swift 编写的 Ed25519(EdDSA)
许可协议
Ed25519 可以使用、分发和修改,遵循 zlib 许可协议。
要求
Ed25519 需要 Swift5。
macOS,iOS
安装
CocoaPods
pod 'ed25519swift'
Swift 包管理器
Swift 包管理器(Swift Package Manager)是一个用于自动化Swift代码发布的工具,并集成到了swift
编译器中。
一旦你设置好Swift包,添加Ed25519作为依赖就像将其添加到你的Package.swift
中的dependencies
值那样简单。
dependencies: [
.package(url: "https://github.com/pebble8888/ed25519swift.git", from: "1.2.2")
]
依赖
CryptoSwift(用于sha512)
BigInt(用于不包含在主Ed25519库中的参考实现)
使用方法
密钥对创建
import Ed25519macOS // direct
or
import ed25519swift // pods or Swift Package Manager
static func generateKeyPair() -> (publicKey: [UInt8], secretKey: [UInt8])
签名
static func sign(message: [UInt8], secretKey: [UInt8]) -> [UInt8]
验证
static func verify(signature: [UInt8], message: [UInt8], publicKey: [UInt8]) -> Bool
从秘密密钥计算公钥
static func calcPublicKey(secretKey: [UInt8]) -> [UInt8]
检查密钥对的有效性
static func isValidKeyPair(publicKey: [UInt8], secretKey: [UInt8]) -> Bool
实现
由 SUPERCOP 转移而来
您可以在这些论文和RFC中检查算法。
Daniel J. Bernstein, Niels Duif, Tanja Lange, Peter Schwabe, and Bo-Yin Yang, High-speed high-security signatures. 2012
Huseyin Hisl, Kenneth Koon-Ho Wong, Gary Carter, Ed Dawson, Twisted Edwards curves revisited. 2008
RFC8032 Edward-Curve Digital Signature Algorithm (EdDSA)
性能
macOS
在 MacBook Pro 2017 2.3Ghz Intel Core i5 上
消息验证:每条消息 10.7 毫秒
密钥对创建:每对密钥 4.8 毫秒
iOS
未进行测量