コード例 #1
0
 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'
コード例 #2
0
 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'
コード例 #3
0
 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'
コード例 #4
0
 def testSHA1_oneByteKey(self):
     """ HMAC_SHA1 oneByteKey of 0xFF"""
     ki = ''.join([chr(0x36) for i in range(64)])
     ko = ''.join([chr(0x5C) for i in range(64)])
     ki = chr(ord(ki[0]) ^ 0xFF) + ki[1:]
     ko = chr(ord(ko[0]) ^ 0xFF) + ko[1:]
     h = SHA1()
     keyedHashAlg = HMAC(SHA1, chr(0xff))
     assert (keyedHashAlg('') == h(ko +
                                   h(ki))), 'one byte key, Null data test'
     assert (
         keyedHashAlg('a') == h(ko +
                                h(ki + 'a'))), 'one byte key, a data test'
     assert (keyedHashAlg('ab') == h(ko + h(ki + 'ab'))
             ), 'one byte key, ab data test'
     assert (keyedHashAlg(
         50 * 'a') == h(ko +
                        h(ki + 50 * 'a'))), 'one byte key, 50*a data test'
コード例 #5
0
 def testSHA1_NullKey(self):
     """ HMAC_SHA1 testNullKey """
     ki = ''.join([chr(0x36) for i in range(64)])
     ko = ''.join([chr(0x5C) for i in range(64)])
     h = SHA1()
     keyedHashAlg = HMAC(SHA1, key='')
     assert (keyedHashAlg('') == h(ko + h(ki))), 'Null key, Null data test'
     assert (keyedHashAlg('a') == h(ko +
                                    h(ki + 'a'))), 'Null key, a data test'
     assert (
         keyedHashAlg('ab') == h(ko +
                                 h(ki + 'ab'))), 'Null key, ab data test'
     assert (keyedHashAlg(
         50 * 'a') == h(ko + h(ki + 50 * 'a'))), 'Null key, 50*a data test'
     # try hmac in two steps of 25 chrs
     manual_hmac = h(ko + h(ki + 50 * 'a'))
     keyedHashAlg.update(25 * 'a')
     keyedHashAlg.update(25 * 'a')
     hm = keyedHashAlg.digest()
     assert (hm == manual_hmac), 'HMAC as update, update and digest'