Exemple #1
0
 def hmac_md5(self,key,message):
     blocksize = md5().block_size
     if len(key) > blocksize:
         key = md5.digest(key)
     elif len(key) < blocksize:
         pad = '\x00'* (blocksize - len(key))
         key += pad
     o_key_pad = [ord('\x5c')^ord(b) for b in key]
     i_key_pad = [ord('\x36')^ord(b) for b in key]
     #print o_key_pad
     #print i_key_pad
     format = ">" + "B"*(blocksize)
     o_key_pad = struct.pack(format, *o_key_pad)
     i_key_pad = struct.pack(format, *i_key_pad)
     self.verboseprint("o_key_pad: {}\ni_key_pad: {}\nkey:       {}".format(o_key_pad.encode("hex"), i_key_pad.encode("hex"), key.encode("hex")))
     inner =  md5(i_key_pad + message).digest()
     result = md5(o_key_pad + inner).digest()
     self.verboseprint("Result  =  {} = md5( o_key_pad || md5( i_key_pad || message ) )".format(result.encode("hex")))
     return result
Exemple #2
0
 def hmac_md5(self, key, message):
     blocksize = md5().block_size
     if len(key) > blocksize:
         key = md5.digest(key)
     elif len(key) < blocksize:
         pad = '\x00' * (blocksize - len(key))
         key += pad
     o_key_pad = [ord('\x5c') ^ ord(b) for b in key]
     i_key_pad = [ord('\x36') ^ ord(b) for b in key]
     #print o_key_pad
     #print i_key_pad
     format = ">" + "B" * (blocksize)
     o_key_pad = struct.pack(format, *o_key_pad)
     i_key_pad = struct.pack(format, *i_key_pad)
     self.verboseprint("o_key_pad: {}\ni_key_pad: {}\nkey:       {}".format(
         o_key_pad.encode("hex"), i_key_pad.encode("hex"),
         key.encode("hex")))
     inner = md5(i_key_pad + message).digest()
     result = md5(o_key_pad + inner).digest()
     self.verboseprint(
         "Result  =  {} = md5( o_key_pad || md5( i_key_pad || message ) )".
         format(result.encode("hex")))
     return result
Exemple #3
0
def hexdigest(md5):  #XXX: argh. 1.5.2 doesn't have this.
    return ''.join(map(lambda x: hex(ord(x))[2:], md5.digest()))
def hexdigest(md5): #XXX: argh. 1.5.2 doesn't have this.
    return ''.join(map(lambda x: hex(ord(x))[2:], md5.digest()))
Exemple #5
0
 def md5optimal(a_file, block_size=65536):
     buf = a_file.read(block_size)
     while len(buf) > 0:
         md5.update(buf)
         buf = a_file.read(block_size)
     return md5.digest()
Exemple #6
0
def expand_to_128bit(key):
	return md5.digest(key)
Exemple #7
0
 def md5optimal(a_file, block_size=65536):
     buf = a_file.read(block_size)
     while len(buf) > 0:
         md5.update(buf)
         buf = a_file.read(block_size)
     return md5.digest()