forked from GmSSL/GmSSL-Python
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy patheasy_zuc_test.py
More file actions
32 lines (23 loc) · 928 Bytes
/
easy_zuc_test.py
File metadata and controls
32 lines (23 loc) · 928 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import unittest
from .easy_zuc import EasyZuc
from .easy_random_data import EasyRandomData
from .gmssl import ZUC_IV_SIZE, ZUC_KEY_SIZE
class MyTestCase(unittest.TestCase):
def test_zuc(self):
key = EasyRandomData().GetRandomData(ZUC_KEY_SIZE)
iv = EasyRandomData().GetRandomData(ZUC_IV_SIZE)
test = EasyZuc(key, iv)
plain1 = 'hello,world'.encode('utf-8')
cipher1 = test.Update(plain1)
plain2 = '1234567890'.encode('utf-8')
cipher2 = test.Update(plain2)
cipher3 = test.Finish()
self.assertTrue(len(cipher1 + cipher2 + cipher3) == len(plain1 + plain2))
test2 = EasyZuc(key, iv)
ret1 = test2.Update(cipher1)
ret2 = test2.Update(cipher2)
ret3 = test2.Update(cipher3)
ret4 = test2.Finish()
self.assertTrue(ret1 + ret2 + ret3 + ret4 == plain1 + plain2)
if __name__ == '__main__':
unittest.main()