/relevation/ext/cryptopy-1.2.5.patched/crypto/hash/__init__.py |
---|
0,0 → 1,3 |
""" The crypto.hash package. |
Part of the CryptoPy framework. |
""" |
/relevation/ext/cryptopy-1.2.5.patched/crypto/hash/sha1Hash_test.py |
---|
0,0 → 1,51 |
#!/usr/bin/env python |
""" sha1Hash_test.py |
Unit tests for sha1.py |
""" |
from crypto.hash.sha1Hash import SHA1 |
import unittest |
import struct |
assert struct.calcsize('!IIIII') == 20, '5 integers should be 20 bytes' |
class SHA1_FIPS180_TestCases(unittest.TestCase): |
""" SHA-1 tests from FIPS180-1 Appendix A, B and C """ |
def testFIPS180_1_Appendix_A(self): |
""" APPENDIX A. A SAMPLE MESSAGE AND ITS MESSAGE DIGEST """ |
hashAlg = SHA1() |
message = 'abc' |
message_digest = 0xA9993E36L, 0x4706816AL, 0xBA3E2571L, 0x7850C26CL, 0x9CD0D89DL |
md_string = _toBString(message_digest) |
assert( hashAlg(message) == md_string ), 'FIPS180 Appendix A test Failed' |
def testFIPS180_1_Appendix_B(self): |
""" APPENDIX B. A SECOND SAMPLE MESSAGE AND ITS MESSAGE DIGEST """ |
hashAlg = SHA1() |
message = 'abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq' |
message_digest = 0x84983E44L, 0x1C3BD26EL, 0xBAAE4AA1L, 0xF95129E5L, 0xE54670F1L |
md_string = _toBString(message_digest) |
assert( hashAlg(message) == md_string ), 'FIPS180 Appendix B test Failed' |
def testFIPS180_1_Appendix_C(self): |
""" APPENDIX C. A THIRD SAMPLE MESSAGE AND ITS MESSAGE DIGEST |
Let the message be the binary-coded form of the ASCII string which consists |
of 1,000,000 repetitions of "a". """ |
hashAlg = SHA1() |
message = 1000000*'a' |
message_digest = 0x34AA973CL, 0xD4C4DAA4L, 0xF61EEB2BL, 0xDBAD2731L, 0x6534016FL |
md_string = _toBString(message_digest) |
assert( hashAlg(message) == md_string ), 'FIPS180 Appendix C test Failed' |
def _toBlock(binaryString): |
""" Convert binary string to blocks of 5 words of uint32() """ |
return [uint32(word) for word in struct.unpack('!IIIII', binaryString)] |
def _toBString(block): |
""" Convert block (5 words of 32 bits to binary string """ |
return ''.join([struct.pack('!I',word) for word in block]) |
if __name__ == '__main__': |
# Run the tests from the command line |
unittest.main() |
/relevation/ext/cryptopy-1.2.5.patched/crypto/hash/sha1Hash.py |
---|
0,0 → 1,37 |
""" crypto.hash.sha1Hash |
Wrapper for python sha module to support crypo module standard interface |
Copyright © (c) 2002 by Paul A. Lambert |
Read LICENSE.txt for license information. |
""" |
import sha |
from crypto.hash.hash import Hash |
class SHA1(Hash): |
def __init__( self ): |
self.name = 'SHA1' |
self.blocksize = 1 # single octets can be hashed by padding to raw block size |
self.raw_block_size = 64 # SHA1 operates on 512 bit / 64 byte blocks |
self.digest_size = 20 # or 160 bits |
self.reset() |
def reset(self): |
self.pysha1 = sha.new() |
def update(self,data): |
""" Update the sha object with the string arg. Repeated calls are |
equivalent to a single call with the concatenation of all the |
arguments: m.update(a); m.update(b) is equivalent to m.update(a+b). |
""" |
self.pysha1.update(data) |
def digest(self): |
""" Return the digest of the strings passed to the update() |
method so far. This is a 20-byte string which may contain |
non-ASCII characters, including null bytes. |
""" |
return self.pysha1.digest() |
/relevation/ext/cryptopy-1.2.5.patched/crypto/hash/hash.py |
---|
0,0 → 1,36 |
""" crypto.cipher.hash |
Base class for cryptographic hash algorithms |
An alternate interface (no 'new'). |
Copyright © (c) 2002 by Paul A. Lambert. |
""" |
from binascii import b2a_hex |
class Hash: |
def __init__( self ): |
raise 'must overload' |
def reset(self): |
raise 'must overload' |
def __call__(self, data, more=None): |
return self.hash(data,more) |
def hash(self,data,more=None): |
self.update(data) |
digest = self.digest() |
if more==None: |
self.reset() # no more data, reset |
return digest |
def update(self,data): |
""" Update the hash object with the data. Repeated calls are |
equivalent to a single call with the concatenation of all the |
arguments: m.update(a); m.update(b) is equivalent to m.update(a+b). |
""" |
raise 'must overload' |
def digest(self): |
raise 'must overload' |
def final(self,data): |
return self.hash(data) |
def hexdigest(self): |
""" Return the digest of the data in ascii-hex format """ |
return b2a_hex(self.digest()) |
# def hexdigest(self): not supported yet |
# def copy(self): not supported yet ... may change |
/relevation/ext/cryptopy-1.2.5.patched/crypto/hash/md5Hash_test.py |
---|
0,0 → 1,26 |
#!/usr/bin/env python |
""" md5Hash_test.py |
Unit tests for md5Hash.py (not the default python library!) |
MD5 defined in RFC 1321 |
""" |
from crypto.hash.md5Hash import MD5 |
import unittest |
from binascii import a2b_hex |
class MD5_TestCases(unittest.TestCase): |
""" MD5 tests from ...""" |
def testFIPS180_1_Appendix_A(self): |
""" APPENDIX A. A SAMPLE MESSAGE AND ITS MESSAGE DIGEST """ |
hashAlg = MD5() |
message = 'abc' |
message_digest = '900150983cd24fb0d6963f7d28e17f72' |
md_string = a2b_hex(message_digest) |
assert( hashAlg(message) == md_string ), 'md5 test Failed' |
if __name__ == '__main__': |
# Run the tests from the command line |
unittest.main() |
/relevation/ext/cryptopy-1.2.5.patched/crypto/hash/md5Hash.py |
---|
0,0 → 1,31 |
""" md5Hash.py |
Wrapper for python md5 module to support crypo module standard interface |
""" |
import md5 |
from crypto.hash.hash import Hash |
class MD5(Hash): |
def __init__( self ): |
self.name = 'MD5' |
self.blocksize = 1 # single octets can be hashed by padding to raw block size |
self.raw_block_size = 64 # MD5 operates on 512 bits or 64 byte blocks |
self.digest_size = 16 # or 128 bits |
self.reset() |
def reset(self): |
self.pymd5 = md5.new() |
def update(self,data): |
""" Update the md5 object with the string arg. Repeated calls are |
equivalent to a single call with the concatenation of all the |
arguments: m.update(a); m.update(b) is equivalent to m.update(a+b). |
""" |
self.pymd5.update(data) |
def digest(self): |
""" Return the digest of the strings passed to the update() |
method so far. This is a 20-byte string which may contain |
non-ASCII characters, including null bytes. |
""" |
return self.pymd5.digest() |
/relevation/ext/cryptopy-1.2.5.patched/crypto/hash/. |
---|
Property changes: |
Added: bugtraq:number |
+true |
\ No newline at end of property |