Using a blinding factor for RSA in pycrypto

旧城冷巷雨未停 提交于 2019-11-30 19:02:56

问题


In python, I am trying to blind and unblind a message. When I unblind the message, I don't get the original message. Does anyone know what I might be doing wrong. The following is my code:

s = 'Hello'
loadedPublic = get_publickey()
loadedPrivate = get_privatekey()

pub = loadedPublic.blind(s,23L)
pub2 = loadedPublic.unblind(pub,23L)
return HttpResponse(pub2)

回答1:


Blinding is a sort of encryption with a random element. It is usually used for Blind Signatures which would look like this:

from Crypto.PublicKey import RSA
from Crypto.Hash import SHA256
from random import SystemRandom

# Signing authority (SA) key
priv = RSA.generate(3072)
pub = priv.publickey()

## Protocol: Blind signature ##

# must be guaranteed to be chosen uniformly at random
r = SystemRandom().randrange(pub.n >> 10, pub.n)
msg = "my message" * 50 # large message (larger than the modulus)

# hash message so that messages of arbitrary length can be signed
hash = SHA256.new()
hash.update(msg)
msgDigest = hash.digest()

# user computes
msg_blinded = pub.blind(msgDigest, r)

# SA computes
msg_blinded_signature = priv.sign(msg_blinded, 0)

# user computes
msg_signature = pub.unblind(msg_blinded_signature[0], r)

# Someone verifies
hash = SHA256.new()
hash.update(msg)
msgDigest = hash.digest()
print("Message is authentic: " + str(pub.verify(msgDigest, (msg_signature,))))

This is how it is implemented, so you cannot directly unblind the message, because you don't have d, so the blinded element must be signed first. In order for the blind signature to be secure, you need to randomly generate the blinding factor r in the range of the signing modulus.



来源:https://stackoverflow.com/questions/33979213/using-a-blinding-factor-for-rsa-in-pycrypto

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!