diff options
author | Micah Anderson <micah@riseup.net> | 2013-08-22 16:39:52 -0400 |
---|---|---|
committer | Micah Anderson <micah@riseup.net> | 2013-08-22 16:39:52 -0400 |
commit | 5e60e0e3af85f22aa0afe8bf0ecf85619afacfeb (patch) | |
tree | 6a91a3de86fa8de0b4167cc947ab72991bf8da31 /src/pycryptopp/cipher/xsalsa20.py | |
parent | 30e9097985656920f01a72efc1088caa2b8d41b3 (diff) |
Imported Upstream version 0.6.0.12upstream/0.6.0.12
Diffstat (limited to 'src/pycryptopp/cipher/xsalsa20.py')
-rw-r--r-- | src/pycryptopp/cipher/xsalsa20.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/pycryptopp/cipher/xsalsa20.py b/src/pycryptopp/cipher/xsalsa20.py new file mode 100644 index 0000000..86ddcd3 --- /dev/null +++ b/src/pycryptopp/cipher/xsalsa20.py @@ -0,0 +1,31 @@ +from pycryptopp import _import_my_names + +_import_my_names(globals(), "xsalsa20_") + +del _import_my_names + +def selftest(): + # pyflakes doesn't know that XSalsa20 is made available above + XSalsa20 = globals()["XSalsa20"] + from binascii import unhexlify + key = unhexlify("ad5eadf7163b0d36e44c126037a03419" + "fcda2b3a1bb4ab064b6070e61b0fa5ca") + iv = unhexlify("6a059adb8c7d4acb1c537767d541506f" "c5ef0ace9a2a65bd") + encrypted = unhexlify("23a8ed0475150e988c545b11e3660de7" + "8bf88e6628c4c99ba36330c05cb919e7" + "901295db479c9a8a0401d5e040b8919b" + "7d64b2f728c59703c3") + p = XSalsa20(key, iv) + decrypted = p.process(encrypted) + expected = "crypto libraries should always test themselves at powerup" + assert decrypted == expected + + p = XSalsa20(key, iv) + decrypted = "" + offset = 0 + for chunksize in [13,11,1,2,3,20,999]: + decrypted += p.process(encrypted[offset:offset+chunksize]) + offset += chunksize + assert decrypted == expected + +selftest() |