盲目签署和验证的库或软件是什么?

问题描述 投票:5回答:2

我最近听说过盲人签名。我看到维基百科关于它们如何工作的文章,但不想实现它。我可以使用哪些库(最好与linux和windows兼容)来实现盲签名并验证文件是否已签名?

我试过看openssl手册页,但我不认为它支持盲签名http://www.openssl.org/docs/apps/dgst.html

我可以在C ++或.NET中实现我的应用程序,并且没有问题产生进程并解析它们的输出,但是lib优先于软件。

c++ security cryptography rsa digital-signature
2个回答
1
投票

我可以在C ++或.NET中实现我的应用程序......盲目地签署和验证哪些库或软件?

这是一个基于Crypto++的答案。 Crypto ++是Wei Dai编写的加密方案类库。这个例子来自维基上的Raw RSA | Blind Signatures

Jack Lloyd的Botan是一个C ++ 11加密和TLS库,可能有本机盲签名支持。

Crypto ++缺少盲签名类。下面的方法遵循Blind Signatures详述的基本算法。但是,它与维基百科不同,应用s(s'(x)) = x交叉检查。 Chaum's original paper中存在交叉检查,但维基文章中缺少这种交叉检查。与Chaum的论文和维基百科的第二个区别是,下面的代码使用H(m)而不是m。这是由于Rabin in 1979

您可能希望首先根据Usability of padding scheme in blinded RSA signature?RSA blind signatures in practice应用填充函数。另见Is there a standard padding/format for RSA Blind Signatures?


#include "cryptlib.h"
#include "integer.h"
#include "nbtheory.h"
#include "osrng.h"
#include "rsa.h"
#include "sha.h"
using namespace CryptoPP;

#include <iostream>
#include <stdexcept>
using std::cout;
using std::endl;
using std::runtime_error;

int main(int argc, char* argv[])
{
    // Bob artificially small key pair
    AutoSeededRandomPool prng;
    RSA::PrivateKey privKey;

    privKey.GenerateRandomWithKeySize(prng, 64);
    RSA::PublicKey pubKey(privKey);

    // Convenience
    const Integer& n = pubKey.GetModulus();
    const Integer& e = pubKey.GetPublicExponent();
    const Integer& d = privKey.GetPrivateExponent();

    // Print params
    cout << "Pub mod: " << std::hex << pubKey.GetModulus() << endl;
    cout << "Pub exp: " << std::hex << e << endl;
    cout << "Priv mod: " << std::hex << privKey.GetModulus() << endl;
    cout << "Priv exp: " << std::hex << d << endl;

    // For sizing the hashed message buffer. This should be SHA256 size.
    const size_t SIG_SIZE = UnsignedMin(SHA256::BLOCKSIZE, n.ByteCount());

    // Scratch
    SecByteBlock buff1, buff2, buff3;

    // Alice original message to be signed by Bob
    SecByteBlock orig((const byte*)"secret", 6);
    Integer m(orig.data(), orig.size());
    cout << "Message: " << std::hex << m << endl;

    // Hash message per Rabin (1979)
    buff1.resize(SIG_SIZE);
    SHA256 hash1;
    hash1.CalculateTruncatedDigest(buff1, buff1.size(), orig, orig.size());

    // H(m) as Integer
    Integer hm(buff1.data(), buff1.size());
    cout << "H(m): " << std::hex << hm << endl;

    // Alice blinding
    Integer r;
    do {
        r.Randomize(prng, Integer::One(), n - Integer::One());
    } while (!RelativelyPrime(r, n));

    // Blinding factor
    Integer b = a_exp_b_mod_c(r, e, n);
    cout << "Random: " << std::hex << b << endl;

    // Alice blinded message
    Integer mm = a_times_b_mod_c(hm, b, n);
    cout << "Blind msg: " << std::hex << mm << endl;

    // Bob sign
    Integer ss = privKey.CalculateInverse(prng, mm);
    cout << "Blind sign: " << ss << endl;

    // Alice checks s(s'(x)) = x. This is from Chaum's paper
    Integer c = pubKey.ApplyFunction(ss);
    cout << "Check sign: " << c << endl;
    if (c != mm)
        throw runtime_error("Alice cross-check failed");

    // Alice remove blinding
    Integer s = a_times_b_mod_c(ss, r.InverseMod(n), n);
    cout << "Unblind sign: " << s << endl;

    // Eve verifies
    Integer v = pubKey.ApplyFunction(s);    
    cout << "Verify: " << std::hex << v << endl;

    // Convert to a string
    size_t req = v.MinEncodedSize();
    buff2.resize(req);
    v.Encode(&buff2[0], buff2.size());

    // Hash message per Rabin (1979)
    buff3.resize(SIG_SIZE);
    SHA256 hash2;
    hash2.CalculateTruncatedDigest(buff3, buff3.size(), orig, orig.size());

    // Constant time compare
    bool equal = buff2.size() == buff3.size() && VerifyBufsEqual(
        buff2.data(), buff3.data(), buff3.size());

    if (!equal)
        throw runtime_error("Eve verified failed");

    cout << "Verified signature" << endl;

    return 0;
}

以下是构建和运行程序的结果:

$ g++ blind.cxx ./libcryptopp.a -o blind.exe
$ ./blind.exe
Pub mod: bbf62585f8486acbh
Pub exp: 11h
Priv mod: bbf62585f8486acbh
Priv exp: 31c1280c6bb08635h
Message: 736563726574h
H(m): 2bb80d537b1da3e3h
Random: 7db0ecdb0a09fad5h
Blinded msg: a8bf62a25b7b4b53h
Blind sign: 2646ab6b9d5b48dfh
Check sign: a8bf62a25b7b4b53h
Unblind sign: 418d211b9cbb2d00h
Verify: 2bb80d537b1da3e3h
Verified signature

-1
投票

盲人签名不需要任何特殊支持。您只需要能够签名并验证消息。盲区由使用非对称密码的系统决定。只需签署以特殊格式收到的内容即可构成盲目签名,表明在前往其他地方之前通过您的数据。 Just make sure you don't use RSA

编辑

根据本答复评论中的扩展讨论,上述文字可能具有误导性,具体取决于您所说的内容。如果您打算按照本答案的评论中所述完成盲目签名,那么您实际上需要特殊支持。我会说,如果你找不到经过审查和测试的东西,那么实现你自己的一个很酷的练习或项目并将它发布在GitHub等上。

© www.soinside.com 2019 - 2024. All rights reserved.