|
Revision 14, 0.7 kB
(checked in by sgk, 4 years ago)
|
|
実行フラグ。
|
-
Property svn:executable set to
*
|
| Line | |
|---|
| 1 | #!/usr/bin/python |
|---|
| 2 | |
|---|
| 3 | # Copyright (c) 2006 by Accense Technology, Inc. |
|---|
| 4 | |
|---|
| 5 | import binascii |
|---|
| 6 | import camellia |
|---|
| 7 | |
|---|
| 8 | # Test vector |
|---|
| 9 | # 'http://info.isl.ntt.co.jp/crypt/camellia/dl/cryptrec/t_camellia.txt' |
|---|
| 10 | testFile = './t_camellia.txt' |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | for line in file(testFile).xreadlines(): |
|---|
| 14 | if line[1:5] != ' No.': |
|---|
| 15 | continue |
|---|
| 16 | op = line[0] |
|---|
| 17 | id = line[5:8] |
|---|
| 18 | line = binascii.a2b_hex(''.join(line[11:].rstrip().split(' '))) |
|---|
| 19 | |
|---|
| 20 | if op == 'K': |
|---|
| 21 | keyid = id |
|---|
| 22 | keytable = camellia.Ekeygen(line) |
|---|
| 23 | |
|---|
| 24 | elif op == 'P': |
|---|
| 25 | testid = id |
|---|
| 26 | plain = line |
|---|
| 27 | |
|---|
| 28 | elif op == 'C': |
|---|
| 29 | assert id == testid |
|---|
| 30 | assert camellia.EncryptBlock(plain, keytable) == line, 'Encrypt %s.%s' % (keyid, testid) |
|---|
| 31 | assert camellia.DecryptBlock(line, keytable) == plain, 'Encrypt %s.%s' % (keyid, testid) |
|---|
| 32 | |
|---|
| 33 | print 'ok' |
|---|