add "chacha20-ietf", libsodium version must be higher than 1.0.4, see https://github.com/jedisct1/libsodium/releases/
This commit is contained in:
parent
202f0f6142
commit
3dec2377bb
1 changed files with 17 additions and 0 deletions
|
@ -52,6 +52,12 @@ def load_libsodium():
|
||||||
c_char_p, c_ulonglong,
|
c_char_p, c_ulonglong,
|
||||||
c_char_p)
|
c_char_p)
|
||||||
|
|
||||||
|
libsodium.crypto_stream_chacha20_ietf_xor_ic.restype = c_int
|
||||||
|
libsodium.crypto_stream_chacha20_ietf_xor_ic.argtypes = (c_void_p, c_char_p,
|
||||||
|
c_ulonglong,
|
||||||
|
c_char_p, c_ulonglong,
|
||||||
|
c_char_p)
|
||||||
|
|
||||||
buf = create_string_buffer(buf_size)
|
buf = create_string_buffer(buf_size)
|
||||||
loaded = True
|
loaded = True
|
||||||
|
|
||||||
|
@ -68,6 +74,8 @@ class SodiumCrypto(object):
|
||||||
self.cipher = libsodium.crypto_stream_salsa20_xor_ic
|
self.cipher = libsodium.crypto_stream_salsa20_xor_ic
|
||||||
elif cipher_name == 'chacha20':
|
elif cipher_name == 'chacha20':
|
||||||
self.cipher = libsodium.crypto_stream_chacha20_xor_ic
|
self.cipher = libsodium.crypto_stream_chacha20_xor_ic
|
||||||
|
elif cipher_name == 'chacha20-ietf':
|
||||||
|
self.cipher = libsodium.crypto_stream_chacha20_ietf_xor_ic
|
||||||
else:
|
else:
|
||||||
raise Exception('Unknown cipher')
|
raise Exception('Unknown cipher')
|
||||||
# byte counter, not block counter
|
# byte counter, not block counter
|
||||||
|
@ -97,6 +105,7 @@ class SodiumCrypto(object):
|
||||||
ciphers = {
|
ciphers = {
|
||||||
'salsa20': (32, 8, SodiumCrypto),
|
'salsa20': (32, 8, SodiumCrypto),
|
||||||
'chacha20': (32, 8, SodiumCrypto),
|
'chacha20': (32, 8, SodiumCrypto),
|
||||||
|
'chacha20-ietf': (32, 12, SodiumCrypto),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -115,6 +124,14 @@ def test_chacha20():
|
||||||
util.run_cipher(cipher, decipher)
|
util.run_cipher(cipher, decipher)
|
||||||
|
|
||||||
|
|
||||||
|
def test_chacha20_ietf():
|
||||||
|
|
||||||
|
cipher = SodiumCrypto('chacha20-ietf', b'k' * 32, b'i' * 16, 1)
|
||||||
|
decipher = SodiumCrypto('chacha20-ietf', b'k' * 32, b'i' * 16, 0)
|
||||||
|
|
||||||
|
util.run_cipher(cipher, decipher)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
test_chacha20_ietf()
|
||||||
test_chacha20()
|
test_chacha20()
|
||||||
test_salsa20()
|
test_salsa20()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue