环签名 (RingSig)

该库用 Swift 实现了环签名方案。该算法基于 Rivest 等人于 2001 年发表的 "How to leak a secret"。

什么是环签名方案?

当使用 RSA 进行消息认证时,消息的作者使用其私钥创建签名。验证者获取签名者的公钥并检查接收到的消息是否与签名匹配。因此,验证者知道只有拥有签名者私钥访问权限的人才能创建签名。

环签名使签名者能够创建不透露其身份的签名。更准确地说,签名者将其公钥与根本不相关的实体的公钥捆绑在一起,并使用它们来创建签名。然后,签名向验证者证明,相应的消息是由其中一个公钥的所有者签名的。尽管如此,验证者无法分辨究竟是谁签名者。

安装

Swift Package Manager

.Package(url: "https://github.com/FabioTacke/RingSig.git", majorVersion: 1)

CocoaPods

pod 'RingSig', '~> 1.0'

用法

import RingSig

// Generate the signer's RSA keypair
let signerKeyPair = RSA.generateKeyPair()
    
// Generate keypairs for the other participants in the ring signature scheme (i.e. the non-signers)
let nonSignerKeyPairs = [RSA.generateKeyPair(), RSA.generateKeyPair(), RSA.generateKeyPair()]
let nonSignersPublicKeys = nonSignerKeyPairs.map { $0.publicKey }
    
// The message to be signed
let message = "Hello, World!"
    
// Sign the message
let signature = RingSig.ringSign(message: message.data(using: .utf8)!, nonSignersPublicKeys: nonSignersPublicKeys, signerKeyPair: signerKeyPair)
    
// Everybody can now verify that the message was signed by someone of those whose public keys were included in the signature. Still the verifier is not able to tell who of them is the actual signer.
let verified = RingSig.ringSigVerify(message: message.data(using: .utf8)!, signature: signature)
assert(verified)

免责声明

该库使用非常基本的 RSA 实现,因此不应被认为提供高加密安全性。此外,在创建该库时,性能不是设计目标。