incubator-heraldry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ket...@apache.org
Subject svn commit: r493246 - /incubator/heraldry/libraries/python/openid/branches/1.2/openid/dh.py
Date Fri, 05 Jan 2007 23:46:23 GMT
Author: keturn
Date: Fri Jan  5 15:46:23 2007
New Revision: 493246

URL: http://svn.apache.org/viewvc?view=rev&rev=493246
Log:
roll back r493235, mistaken patch

Modified:
    incubator/heraldry/libraries/python/openid/branches/1.2/openid/dh.py

Modified: incubator/heraldry/libraries/python/openid/branches/1.2/openid/dh.py
URL: http://svn.apache.org/viewvc/incubator/heraldry/libraries/python/openid/branches/1.2/openid/dh.py?view=diff&rev=493246&r1=493245&r2=493246
==============================================================================
--- incubator/heraldry/libraries/python/openid/branches/1.2/openid/dh.py (original)
+++ incubator/heraldry/libraries/python/openid/branches/1.2/openid/dh.py Fri Jan  5 15:46:23
2007
@@ -1,10 +1,42 @@
-import pickle
+from openid import cryptutil
+from openid import oidutil
 
-def encode_long(l):
-   if l == 0:
-       return '\x00'
+def strxor(x, y):
+    if len(x) != len(y):
+        raise ValueError('Inputs to strxor must have the same length')
 
-   return ''.join(reversed(pickle.encode_long(l)))
+    xor = lambda (a, b): chr(ord(a) ^ ord(b))
+    return "".join(map(xor, zip(x, y)))
 
-def decode_long(s):
-   return pickle.decode_long(''.join(reversed(s)))
+class DiffieHellman(object):
+    DEFAULT_MOD = 155172898181473697471232257763715539915724801966915404479707795314057629378541917580651227423698188993727816152646631438561595825688188889951272158842675419950341258706556549803580104870537681476726513255747040765857479291291572334510643245094715007229621094194349783925984760375594985848253359305585439638443L
+
+    DEFAULT_GEN = 2
+
+    def fromDefaults(cls):
+        return cls(cls.DEFAULT_MOD, cls.DEFAULT_GEN)
+
+    fromDefaults = classmethod(fromDefaults)
+
+    def __init__(self, modulus, generator):
+        self.modulus = long(modulus)
+        self.generator = long(generator)
+
+        self._setPrivate(cryptutil.randrange(1, modulus - 1))
+
+    def _setPrivate(self, private):
+        """This is here to make testing easier"""
+        self.private = private
+        self.public = pow(self.generator, self.private, self.modulus)
+
+    def usingDefaultValues(self):
+        return (self.modulus == self.DEFAULT_MOD and
+                self.generator == self.DEFAULT_GEN)
+
+    def getSharedSecret(self, composite):
+        return pow(composite, self.private, self.modulus)
+
+    def xorSecret(self, composite, secret):
+        dh_shared = self.getSharedSecret(composite)
+        sha1_dh_shared = cryptutil.sha1(cryptutil.longToBinary(dh_shared))
+        return strxor(secret, sha1_dh_shared)



Mime
View raw message