incubator-heraldry-commits mailing list archives

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

URL: http://svn.apache.org/viewvc?view=rev&rev=493235
Log:
[python-1.2-to-heraldry @ Initial checkin of diffie-hellman openid code]

Original author: Grant Monroe <grant@janrain.com>
Date: 2005-06-10 18:42:22+00:00

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=493235&r1=493234&r2=493235
==============================================================================
--- 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:20:08
2007
@@ -1,42 +1,10 @@
-from openid import cryptutil
-from openid import oidutil
+import pickle
 
-def strxor(x, y):
-    if len(x) != len(y):
-        raise ValueError('Inputs to strxor must have the same length')
+def encode_long(l):
+   if l == 0:
+       return '\x00'
 
-    xor = lambda (a, b): chr(ord(a) ^ ord(b))
-    return "".join(map(xor, zip(x, y)))
+   return ''.join(reversed(pickle.encode_long(l)))
 
-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)
+def decode_long(s):
+   return pickle.decode_long(''.join(reversed(s)))



Mime
View raw message