diff --git a/auth/auth_systems/facebookclient/__init__.py b/auth/auth_systems/facebookclient/__init__.py index 7ee9e0c37c4bf1aef85d0e1b11bb6c1dec3dfb09..6e5e6ce923af35606e8a305609f3e5435a865fca 100644 --- a/auth/auth_systems/facebookclient/__init__.py +++ b/auth/auth_systems/facebookclient/__init__.py @@ -50,10 +50,7 @@ import struct import urllib import urllib2 import httplib -try: - import hashlib -except ImportError: - import md5 as hashlib +import hashlib import binascii import urlparse import mimetypes diff --git a/auth/security/oauth.py b/auth/security/oauth.py index 04cc4bb2ba294c9f50a1eb91fe9ba9ef3e3aaa15..4addf22677a22f19bdc350497ab1fab3746689a1 100644 --- a/auth/security/oauth.py +++ b/auth/security/oauth.py @@ -14,6 +14,7 @@ import urlparse import hmac import base64 import logging +import hashlib VERSION = '1.0' # Hi Blaine! HTTP_METHOD = 'GET' @@ -513,12 +514,7 @@ class OAuthSignatureMethod_HMAC_SHA1(OAuthSignatureMethod): key, raw = self.build_signature_base_string(oauth_request, consumer, token) # hmac object - try: - import hashlib # 2.5 - hashed = hmac.new(key, raw, hashlib.sha1) - except: - import sha # deprecated - hashed = hmac.new(key, raw, sha) + hashed = hmac.new(key, raw, hashlib.sha1) # calculate the digest base 64 return base64.b64encode(hashed.digest()) diff --git a/helios/crypto/algs.py b/helios/crypto/algs.py index 78e83c2a85c8f2789c21a296af3b9623a9c3e38f..c0c6e33acb8074fccf31d9628aab8d2bdea8b038 100644 --- a/helios/crypto/algs.py +++ b/helios/crypto/algs.py @@ -7,7 +7,7 @@ Ben Adida ben@adida.net """ -import math, sha, logging +import math, hashlib, logging import randpool, number import numtheory @@ -323,7 +323,7 @@ class EGSecretKey: a = pow(self.pk.g, w, self.pk.p) b = pow(ciphertext.alpha, w, self.pk.p) - c = int(sha.new(str(a) + "," + str(b)).hexdigest(),16) + c = int(hashlib.sha1(str(a) + "," + str(b)).hexdigest(),16) t = (w + self.x * c) % self.pk.q @@ -717,7 +717,7 @@ def EG_disjunctive_challenge_generator(commitments): array_to_hash.append(str(commitment['B'])) string_to_hash = ",".join(array_to_hash) - return int(sha.new(string_to_hash).hexdigest(),16) + return int(hashlib.sha1(string_to_hash).hexdigest(),16) # a challenge generator for Fiat-Shamir with A,B commitment def EG_fiatshamir_challenge_generator(commitment): @@ -725,5 +725,5 @@ def EG_fiatshamir_challenge_generator(commitment): def DLog_challenge_generator(commitment): string_to_hash = str(commitment) - return int(sha.new(string_to_hash).hexdigest(),16) + return int(hashlib.sha1(string_to_hash).hexdigest(),16) diff --git a/helios/crypto/randpool.py b/helios/crypto/randpool.py index 389d41e8b0e051af1c4b5004a122278cb6e7fd2d..53a8acc035c225b23ea9e6edd2a8b27b39b75082 100644 --- a/helios/crypto/randpool.py +++ b/helios/crypto/randpool.py @@ -54,7 +54,7 @@ class RandomPool: def __init__(self, numbytes = 160, cipher=None, hash=None): if hash is None: - import sha as hash + from hashlib import sha1 as hash # The cipher argument is vestigial; it was removed from # version 1.1 so RandomPool would work even in the limited @@ -79,7 +79,7 @@ class RandomPool: self._event1 = self._event2 = 0 self._addPos = 0 - self._getPos = hash.digest_size + self._getPos = hash().digest_size self._lastcounter=time.time() self.__counter = 0 @@ -155,13 +155,13 @@ class RandomPool: # Loop over the randomness pool: hash its contents # along with a counter, and add the resulting digest # back into the pool. - for i in range(self.bytes / self._hash.digest_size): - h = self._hash.new(self._randpool) + for i in range(self.bytes / self._hash().digest_size): + h = self._hash(self._randpool) h.update(str(self.__counter) + str(i) + str(self._addPos) + s) self._addBytes( h.digest() ) self.__counter = (self.__counter + 1) & 0xFFFFffffL - self._addPos, self._getPos = 0, self._hash.digest_size + self._addPos, self._getPos = 0, self._hash().digest_size self.add_event() # Restore the old value of the entropy. @@ -175,8 +175,8 @@ class RandomPool: s='' i, pool = self._getPos, self._randpool - h=self._hash.new() - dsize = self._hash.digest_size + h=self._hash() + dsize = self._hash().digest_size num = N while num > 0: h.update( self._randpool[i:i+dsize] ) @@ -247,7 +247,7 @@ class RandomPool: # between measurements, and taking the median of the resulting # list. (We also hash all the times and add them to the pool) interval = [None] * 100 - h = self._hash.new(`(id(self),id(interval))`) + h = self._hash(`(id(self),id(interval))`) # Compute 100 differences t=time.time() diff --git a/helios/crypto/utils.py b/helios/crypto/utils.py index f34583ebf056a424b7081c58a88ef3857f40e036..ad364dc87bab1a806e471b2a4171eb37ac50fe97 100644 --- a/helios/crypto/utils.py +++ b/helios/crypto/utils.py @@ -2,7 +2,7 @@ Crypto Utils """ -import sha, hmac, base64 +import hmac, base64 from django.utils import simplejson diff --git a/helios/utils.py b/helios/utils.py index 3d8d4dadd7260356947210bacf1ca98bd0f09ff5..2ed4a77270d5b094002b1edb414460c11a9af7aa 100644 --- a/helios/utils.py +++ b/helios/utils.py @@ -14,13 +14,13 @@ from auth.utils import * from django.conf import settings import random, logging -import sha, hmac, base64 +import hashlib, hmac, base64 def do_hmac(k,s): """ HMAC a value with a key, hex output """ - mac = hmac.new(k, s, sha) + mac = hmac.new(k, s, hashlib.sha1) return mac.hexdigest()