| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
import binascii |
|---|
| 6 |
import camellia |
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 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' |
|---|