From ff00327647106ec06a2800449b1b7d4c84b30cad Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Thu, 3 Apr 2014 11:24:59 -0400 Subject: [PATCH] Switch from PyCrypto HMAC to standard python hmac This seems to be a wash performance and functionality wise. It does however mean one less segment of code that incurs an external dependency. Change-Id: I6691d95172d7d83eae4b4ed1265ba398b220f501 --- pyghmi/ipmi/private/session.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/pyghmi/ipmi/private/session.py b/pyghmi/ipmi/private/session.py index 56fc0986..052d9473 100644 --- a/pyghmi/ipmi/private/session.py +++ b/pyghmi/ipmi/private/session.py @@ -19,6 +19,7 @@ import atexit import collections import fcntl import hashlib +import hmac import os import random import select @@ -27,8 +28,6 @@ import struct import threading from Crypto.Cipher import AES -from Crypto.Hash import HMAC -from Crypto.Hash import SHA import pyghmi.exceptions as exc from pyghmi.ipmi.private import constants @@ -657,10 +656,10 @@ class Session(object): message.append(7) # reserved, 7 is the required value for the # specification followed integdata = message[4:] - authcode = HMAC.new(self.k1, + authcode = hmac.new(self.k1, struct.pack("%dB" % len(integdata), *integdata), - SHA).digest()[:12] # SHA1-96 + hashlib.sha1).digest()[:12] # SHA1-96 # per RFC2404 truncates to 96 bits message += struct.unpack("12B", authcode) self.netpacket = struct.pack("!%dB" % len(message), *message) @@ -1011,8 +1010,8 @@ class Session(object): if data[5] & 0b10000000: encrypted = 1 authcode = rawdata[-12:] - expectedauthcode = HMAC.new( - self.k1, rawdata[4:-12], SHA).digest()[:12] + expectedauthcode = hmac.new( + self.k1, rawdata[4:-12], hashlib.sha1).digest()[:12] if authcode != expectedauthcode: return # BMC failed to assure integrity to us, drop it sid = struct.unpack("