예제 #1
0
 def test(mode_name, enc_mode, dec_mode, block_size):
     print 'Test mode %s block size %d' % (mode_name, block_size)
     print '     one chank coding'
     iv = ''.join(map(chr, range(48 + block_size, 48, -1)))
     c = fake_chifer()
     text = 'ABCDEFGHabcdefgh'
     e = enc_mode(c, iv)
     cryp = e(text)
     d = dec_mode(c, iv)
     textb = d(cryp)
     print pad('%s %s' % (text, textb), 70), ok(text == textb)
     print '     stream coding'
     text = ''.join(map(lambda x: chr(x), xrange(65, 65+32)))
     e = enc_mode(c, iv)
     cryp = ''
     cryp += e(text[:16])
     cryp += e(text[16:])
     d = dec_mode(c, iv)
     textb = ''
     textb += d(cryp[:16])
     textb += d(cryp[16:])
     print pad('%s %s' % (text, textb), 70), ok(text == textb)
예제 #2
0
            salt = ref_cipher[8:16]
        else:
            salt = None
        e = enc_op(passphrase, text, salted, salt)
#        print repr(e)
#        print repr(ref_cipher)
        test_enc = ok(e == ref_cipher)
        t = dec_op(passphrase, e)
#        print repr(t)
#        print repr(text)
        test_dec = ok(t == text)
        # random salt
        t = dec_op(passphrase, enc_op(passphrase, text))
        test_rand = ok(t == text)
        print pad(rem, 50), \
              'enc:', test_enc, \
              'dec:', test_dec, \
              'rand_salt:', test_enc
    __how_to_preapre_test_vectors__=r'''
#!/bin/sh

data='Red leather, Yellow leather.'
pass='******'

echo "data = '$data'"
echo "password = '******'"
for mode in -bf-ecb -bf-cbc \
            -aes-128-ecb -aes-192-ecb -aes-256-ecb \
            -aes-128-cbc -aes-192-cbc -aes-256-cbc
do
  for saltmode in -salt -nosalt
  do
예제 #3
0
('Self PCBC/Blowfish/nosalt klen=16', enc_bf_pcbc, dec_bf_pcbc, 16, '', 'g\xec\x11\xc2(\xd4\xb5W\x80\xc8\xc7\xdc8\xa3.^\xf7?\x87\x9dC\xcf\x85c\x8b\xce\x12\x8a?#E"'),
('Self PCBC/Blowfish/salt klen=32 (=perl)', enc_bf_pcbc, dec_bf_pcbc, 32, '2,Y\x1d\xd0`y<', '\x1e\xca\xe8B\xa6\x82n\x1e\x90\x06L\xc21\xdbA\x05\xa2\x8b\xcbH\x0e\xa4Y\xf0\xc1\x81-\xf4lJ\xb0\x88'),
('Self PCBC/Blowfish/nosalt klen=32', enc_bf_pcbc, dec_bf_pcbc, 32, '', 'kkm\x87"\xb9{_\x06\x99\x15\xa8\x90m@uyo\xa5\xea\xcb"\xb5j\xfd\x9d\xaf\x9d \xfb\xa4\xd1'),
('Self PCBC/Blowfish/salt klen=48 (=perl)', enc_bf_pcbc, dec_bf_pcbc, 48, '9m\xa3\x7f\xb5N\x9b\x03', 'B\x9dm\xfa\xe0cr\xef\xdb\xe4\x06\x03\n\xb9\x0f\xdfn^\xbd\xb7j\x96\xed\x932R\xa5\xebg[ \xa8'),
('Self PCBC/Blowfish/nosalt klen=48', enc_bf_pcbc, dec_bf_pcbc, 48, '', 'g\xaf{\x0c\x1f\xdf\xeb_P=\x11\xdb\xf0\x03#\xfd\xc6I\xea\xa9g\xa5\x0e\xa9\xa3\xb6\r\xdb\x1d\x0em\x9e'),
('Self PCBC/Blowfish/salt klen=56 (=perl)', enc_bf_pcbc, dec_bf_pcbc, 56, '\x88\x90\xcdJ\r\\Z]', '\x03\x8c%\x83\xdd\x0f\x18^\xb0\x89\x96d-\xac\xb6\xf1\x1b\x0b\x87\x04\xac\x02\x06BzV\xab\xfe%\x1ao.'),
('Self PCBC/Blowfish/nosalt klen=56', enc_bf_pcbc, dec_bf_pcbc, 56, '', "#\xe8'(\xd8\x01\x05\xd1\xa5g\xe1\x9eU\x07\x18\xa4\x97\x1d\xe1rg1\xfe\xbb\x96\xc2\xa0J\xe1\x01K\x17"),

('Self ECB/AES/salt klen=16 (=openssl)', enc_aes_ecb, dec_aes_ecb, 16, '\xc9\xef8\xb8B\x97\xa7*', '\xf8\xdav\xbal\xf4\xcdN\xe8\x02\x15u\xf17\x80(y,\xc1\xb5\xa6j\x82\x072;\xdd\x90e\x98|\xb5'),
('Self ECB/AES/nosalt klen=16 (=openssl)', enc_aes_ecb, dec_aes_ecb, 16, '', '\xb2^\x0fO\xc4\xfd\xae\x8f\x99\xa8\x18\x93\x83\xd2:\x9b\x9a3\x98\xcbk\xdc\x195\xc85-\xab\xb6U\x9f\xd5'),
('Self ECB/AES/salt klen=24 (=openssl)', enc_aes_ecb, dec_aes_ecb, 24, 'Te\xe6\xcd\xb9\x92:\xd2', '\xac\x01Kg\xa0u\x92\xc3\xb1\x9f\x06\x9f \xa7\xc2\x8c\x0f\xd5\xe88\x90\x95\x10\xdej6\x96D\x9aFU\xd2'),
('Self ECB/AES/nosalt klen=24 (=openssl)', enc_aes_ecb, dec_aes_ecb, 24, '', "\xd7\xac*!\x84\x94O\xa3\xb7\x90\xcbj\xfb\xa8\xa0=\x11\xb1\x10#\xd4,\xebu4>\xe4\xddO\x12b'"),
('Self ECB/AES/salt klen=32 (=openssl)', enc_aes_ecb, dec_aes_ecb, 32, '\xf8\xed\xf7R\xdc\x89\xff\xab', '\xe1\x07\x85\x05\x04\xd9\xb7L\xa5\xfaq\x19\xe0\xf0\xc5W\x95!\xb9\xdbd\xa8\xc66\x1e\x1c\xb6\xc4\xd6u/\xba'),
('Self ECB/AES/nosalt klen=32 (=openssl)', enc_aes_ecb, dec_aes_ecb, 32, '', '\xce\xac6\xc4\xed\xcf\x98\xfa\x91o\x8b \xd0e\xd4x\x8ek5\xc3\xe7\x16\\\xa2\xb5Y\xc7\x89\x0f_\x07\xff'),
('Self CBC/AES/salt klen=16 (=openssl)', enc_aes_cbc, dec_aes_cbc, 16, '\x8fV\xab3\xe4\xda[6', '\xdb\xdc\x0cD\x88l\x19t\x8a\xa7\x00\xf2\x04\x9d\xdc\x84\xf52\x88\xd3\xf4o,I\xa4\xe4q\xbc\xde\xb1K\x05'),
('Self CBC/AES/nosalt klen=16 (=openssl)', enc_aes_cbc, dec_aes_cbc, 16, '', '\x04Us\x99\xbc\x0f\xaf\xdb\xeb\xd9\x91\xf1<\rr3\xf9\xa8\xe7i?F\xf7M#6\xa6\xc3XJ\x87\xda'),
('Self CBC/AES/salt klen=24 (=openssl)', enc_aes_cbc, dec_aes_cbc, 24, '\xa8\xf3:_e{k\xf8', '\x8e\xcdb-\xb8\xcaf\xe9\xdf\xd0"\xf3\x1f\x98\x01a\xc0\xdd+`\xe2\'\xcb\xf1#\'E\x86\xbeZc\x8d'),
('Self CBC/AES/nosalt klen=24 (=openssl)', enc_aes_cbc, dec_aes_cbc, 24, '', '\xc5\xbaF\xecm\xea\x00\xc4\x1bv\x01\xec\x99\x9c\x81\xe2\xd7\x1d\xe8>\x17\xf3\x89\x90\xbf[\x0b\x98Q\x00@G'),
('Self CBC/AES/salt klen=32 (=openssl)', enc_aes_cbc, dec_aes_cbc, 32, ':\x01W\xf4,\xbb\xd2G', '\xaf_\x9dD\x88\xc5)\xb1\x91\xfc\x91o\x1a\xa8\xd4\xb7B\xad_0\xd1\xe0\x0b,\xfa\x8cr\x11\xc7J\t\xc4'),
('Self CBC/AES/nosalt klen=32 (=openssl)', enc_aes_cbc, dec_aes_cbc, 32, '', "\xe1\xd7cS\xe5`\x1a'\xb8\xbce/\xfa\x06\xdc\x17\xef&\x91\x83:fG\x87\xb4\x9d\x0b5\xf7s\x9c\x02"),
('Self PCBC/AES/salt klen=16', enc_aes_pcbc, dec_aes_pcbc, 16, '\rp]\x1b\x90G\xd5_', '\xf8\x8c\x98\xd1\xe8_\xfbc\xa4\xc4p\x8b\x89&\xcc\x1a\xde&\x9aC\xfc&)W\x8aqDv\x99\xc3\x96\x8a'),
('Self PCBC/AES/nosalt klen=16', enc_aes_pcbc, dec_aes_pcbc, 16, '', '\x04Us\x99\xbc\x0f\xaf\xdb\xeb\xd9\x91\xf1<\rr3\xa1^U6+\xbd \xf8\xd2\x06\xac1f&K2'),
('Self PCBC/AES/salt klen=24', enc_aes_pcbc, dec_aes_pcbc, 24, '\xb6{\xd6\x87\xd2\x19e\xfa', '7\xf9\xe9\xddBI\xf2\xfb\x11\xd9\r\x8a\xb0w\xf1|\xcb\xed\xa15@\xe3\x8f\xde\xf4.\xf8\x94\x9d\xeeo\x9c'),
('Self PCBC/AES/nosalt klen=24', enc_aes_pcbc, dec_aes_pcbc, 24, '', '\xc5\xbaF\xecm\xea\x00\xc4\x1bv\x01\xec\x99\x9c\x81\xe2\x00\xaf\xe6r\xfcW\xd8\xde\xe3"\xb6\xdc\xe9\x93L\x8f'),
('Self PCBC/AES/salt klen=32', enc_aes_pcbc, dec_aes_pcbc, 32, 'i+\x94\xc2l=\xcb\xdc', 'X\x81\xa6\xd1|\xd5\x90\xb3\xeaX\xe9\xb6\xb4\x9d37DTe\x19\xad\xc0\xa0\xaf\xe2\x01\x17\x07\xdd9\xd5$'),
('Self PCBC/AES/nosalt klen=32', enc_aes_pcbc, dec_aes_pcbc, 32, '', "\xe1\xd7cS\xe5`\x1a'\xb8\xbce/\xfa\x06\xdc\x17\xcc\x0f\xcc\xf1\xba\xef\x87#\x85h}\xae\xb3\xbei "),
        ):
        c = enc_op(text, salt, passphrase, klen)
        t = dec_op(c, salt, passphrase, klen)
        print pad(rem, 50), 'enc:', ok(c == ref_cryp), 'dec:', ok(t == text)