add salsa20 test
This commit is contained in:
parent
77f74a0668
commit
7a98331655
2 changed files with 8 additions and 4 deletions
|
@ -109,7 +109,7 @@ def test():
|
||||||
decipher = Salsa20Cipher('salsa20-ctr', 'k' * 32, 'i' * 8, 1)
|
decipher = Salsa20Cipher('salsa20-ctr', 'k' * 32, 'i' * 8, 1)
|
||||||
results = []
|
results = []
|
||||||
pos = 0
|
pos = 0
|
||||||
print 'start'
|
print 'salsa20 test start'
|
||||||
start = time.time()
|
start = time.time()
|
||||||
while pos < len(plain):
|
while pos < len(plain):
|
||||||
l = random.randint(100, 32768)
|
l = random.randint(100, 32768)
|
||||||
|
@ -124,7 +124,7 @@ def test():
|
||||||
results.append(decipher.update(c[pos:pos + l]))
|
results.append(decipher.update(c[pos:pos + l]))
|
||||||
pos += l
|
pos += l
|
||||||
end = time.time()
|
end = time.time()
|
||||||
print BLOCK_SIZE * rounds / (end - start)
|
print 'speed: %d bytes/s' % (BLOCK_SIZE * rounds / (end - start))
|
||||||
assert ''.join(results) == plain
|
assert ''.join(results) == plain
|
||||||
|
|
||||||
|
|
||||||
|
|
8
test.py
8
test.py
|
@ -1,15 +1,17 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import sys
|
||||||
|
sys.path.insert(0, 'shadowsocks')
|
||||||
import os
|
import os
|
||||||
import signal
|
import signal
|
||||||
import sys
|
|
||||||
import select
|
import select
|
||||||
import struct
|
import struct
|
||||||
import hashlib
|
import hashlib
|
||||||
import string
|
import string
|
||||||
import time
|
import time
|
||||||
from subprocess import Popen, PIPE
|
from subprocess import Popen, PIPE
|
||||||
|
import encrypt_salsa20
|
||||||
|
|
||||||
target1 = [
|
target1 = [
|
||||||
[60, 53, 84, 138, 217, 94, 88, 23, 39, 242, 219, 35, 12, 157, 165, 181, 255, 143, 83, 247, 162, 16, 31, 209, 190,
|
[60, 53, 84, 138, 217, 94, 88, 23, 39, 242, 219, 35, 12, 157, 165, 181, 255, 143, 83, 247, 162, 16, 31, 209, 190,
|
||||||
|
@ -89,6 +91,8 @@ p2 = Popen(['python', 'shadowsocks/local.py', '-c', sys.argv[-1]], shell=False,
|
||||||
stdout=PIPE, stderr=PIPE, close_fds=True)
|
stdout=PIPE, stderr=PIPE, close_fds=True)
|
||||||
p3 = None
|
p3 = None
|
||||||
|
|
||||||
|
encrypt_salsa20.test()
|
||||||
|
|
||||||
print 'encryption test passed'
|
print 'encryption test passed'
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -120,7 +124,7 @@ try:
|
||||||
if r == 0:
|
if r == 0:
|
||||||
print 'test passed'
|
print 'test passed'
|
||||||
sys.exit(r)
|
sys.exit(r)
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
for p in [p1, p2]:
|
for p in [p1, p2]:
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in a new issue