CVS: crypto/PublicKey RSA.py,1.12,1.13 __init__.py,1.3,1.4 pubkey.py,1.8,1.9
"A.M. Kuchling" <[email protected]> Thu, 03 Apr 2003 12:27:18 -0800
| Newsgroups | gmane.comp.python.cryptography.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/pycrypto/crypto/PublicKey
In directory sc8-pr-cvs1:/tmp/cvs-serv28086
Modified Files:
RSA.py __init__.py pubkey.py
Log Message:
Add support for RSA blinding
Index: RSA.py
===================================================================
RCS file: /cvsroot/pycrypto/crypto/PublicKey/RSA.py,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- RSA.py 3 Apr 2003 18:19:05 -0000 1.12
+++ RSA.py 3 Apr 2003 20:27:13 -0000 1.13
@@ -83,6 +83,23 @@
if m2[0]==M: return 1
else: return 0
+ def _blind(self, M, B):
+ tmp = pow(B, self.e, self.n)
+ return (M * tmp) % self.n
+
+ def _unblind(self, M, B):
+ tmp = pubkey.inverse(B, self.n)
+ return (M * tmp) % self.n
+
+ def canblind (self):
+ """canblind() : bool
+ Return a Boolean value recording whether this algorithm can
+ blind data. (This does not imply that this
+ particular key object has the private information required to
+ to blind a message.)
+ """
+ return 1
+
def size(self):
"""size() : int
Return the maximum number of bits that can be handled by this key.
@@ -150,6 +167,15 @@
def _verify(self, M, sig):
return self.key._verify(M, sig[0])
+
+ def _blind(self, M, B):
+ return self.key._blind(M, B)
+
+ def _unblind(self, M, B):
+ return self.key._unblind(M, B)
+
+ def canblind (self):
+ return 1
def size(self):
return self.key.size()
Index: __init__.py
===================================================================
RCS file: /cvsroot/pycrypto/crypto/PublicKey/__init__.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- __init__.py 11 Jul 2002 14:31:19 -0000 1.3
+++ __init__.py 3 Apr 2003 20:27:13 -0000 1.4
@@ -7,7 +7,7 @@
Crypto.PublicKey.DSA Digital Signature Algorithm. (Signature only)
Crypto.PublicKey.ElGamal (Signing and encryption)
-Crypto.PublicKey.RSA (Signing and encryption)
+Crypto.PublicKey.RSA (Signing, encryption, and blinding)
Crypto.PublicKey.qNEW (Signature only)
"""
Index: pubkey.py
===================================================================
RCS file: /cvsroot/pycrypto/crypto/PublicKey/pubkey.py,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- pubkey.py 28 Feb 2003 15:25:11 -0000 1.8
+++ pubkey.py 3 Apr 2003 20:27:13 -0000 1.9
@@ -88,6 +88,31 @@
warnings.warn("validate() method name is obsolete; use verify()",
DeprecationWarning)
+ def blind(self, M, B):
+ """blind(M : string|long, B : string|long) : string|long
+ Blind message M using blinding factor B.
+ """
+ wasString=0
+ if isinstance(M, types.StringType):
+ M=bytes_to_long(M) ; wasString=1
+ if isinstance(B, types.StringType): B=bytes_to_long(B)
+ blindedmessage=self._blind(M, B)
+ if wasString: return long_to_bytes(blindedmessage)
+ else: return blindedmessage
+
+ def unblind(self, M, B):
+ """unblind(M : string|long, B : string|long) : string|long
+ Unblind message M using blinding factor B.
+ """
+ wasString=0
+ if isinstance(M, types.StringType):
+ M=bytes_to_long(M) ; wasString=1
+ if isinstance(B, types.StringType): B=bytes_to_long(B)
+ unblindedmessage=self._unblind(M, B)
+ if wasString: return long_to_bytes(unblindedmessage)
+ else: return unblindedmessage
+
+
# The following methods will usually be left alone, except for
# signature-only algorithms. They both return Boolean values
# recording whether this key's algorithm can sign and encrypt.
@@ -108,6 +133,15 @@
to decrypt a message.)
"""
return 1
+
+ def canblind (self):
+ """canblind() : bool
+ Return a Boolean value recording whether this algorithm can
+ blind data. (This does not imply that this
+ particular key object has the private information required to
+ to blind a message.)
+ """
+ return 0
# The following methods will certainly be overridden by
# subclasses.
-------------------------------------------------------
This SF.net email is sponsored by: ValueWeb:
Dedicated Hosting for just $79/mo with 500 GB of bandwidth!
No other company gives more support or power for your dedicated server
http://click.atdmt.com/AFF/go/sdnxxaff00300020aff/direct/01/