<div dir="ltr"><div><div>PKCS#1v1.5 happens to be a deterministic signature scheme, so in theory the assertion should not fail.<br><br></div>I believe that the RSA key that Wang Gang is using is not correct.<br></div>For instance, some of the CRT coefficients may not be matching the private exponent.<br>
<div><br></div><div>When that happens, the blinding countermeasures will not cancel out and the result of RSA operations will be random (in addition to being incorrect).<br></div><div><br><div><div><div><div class="gmail_extra">
<div class="gmail_quote">2014-03-12 6:55 GMT+01:00 Philip Horger <span dir="ltr"><<a href="mailto:campadrenalin@gmail.com" target="_blank">campadrenalin@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">I'm not the king of crypto, but if I recall correctly, some signature standards (and I think PKCS1 is one of them) include a random salt in the signature. This happens automatically, behind the scenes, on your behalf. So two signatures can be of the same content, with the same key, and not be equal - in fact, it's dramatically more likely than not! So you can't rely on bit-for-bit equality of signatures.<br>
</div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Mar 11, 2014 at 8:22 PM, wanggang <span dir="ltr"><<a href="mailto:wanggang@goldenapptechnology.com" target="_blank">wanggang@goldenapptechnology.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi pycrypto,<br>
<br>
This may be a simple problem since I am a newbiee to crypto.<br>
I am not sure why I got different result from PKCS1_v1_5.new(RSA.construct(lst)).sign(SHA.new(a2b(m))) ,<br>
I have mentioned the 'stateful' comment in API doc, but still can't fix the code below.<br>
besides I have used DES for a lot, & never got stuck in such situation.<br>
<br>
if __name__ == "__main__":<br>
t = (modulus, publicExponent, privateExponent, prime1, prime2, coefficient)<br>
lst = [long(x,16) for x in t]<br>
<br>
k = '1234'<br>
e1 = RSA.construct(lst).encrypt(m, k)<br>
e2 = RSA.construct(lst).encrypt(m, k)<br>
assert e1 == e2 # passed<br>
<br>
signature1 = PKCS1_v1_5.new(RSA.construct(lst)).sign(SHA.new(a2b(m)))<br>
print binascii.b2a_hex(signature1)<br>
signature2 = PKCS1_v1_5.new(RSA.construct(lst)).sign(SHA.new(a2b(m)))<br>
print binascii.b2a_hex(signature2)<br>
assert signature1==signature2 # why this assertion failed ?<br>
<br>
Thank you in advance!<br>
--------------<br>
Wang Gang<br>
_______________________________________________<br>
pycrypto mailing list<br>
<a href="mailto:pycrypto@lists.dlitz.net" target="_blank">pycrypto@lists.dlitz.net</a><br>
<a href="http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto" target="_blank">http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto</a><br>
</blockquote></div><br></div>
</div></div><br>_______________________________________________<br>
pycrypto mailing list<br>
<a href="mailto:pycrypto@lists.dlitz.net">pycrypto@lists.dlitz.net</a><br>
<a href="http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto" target="_blank">http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto</a><br>
<br></blockquote></div><br></div></div></div></div></div></div>