Exemplo n.º 1
0
def test_chacha20():
    from shadowsocks.crypto import util

    cipher = Salsa20Crypto(b'chacha20', b'k' * 32, b'i' * 16, 1)
    decipher = Salsa20Crypto(b'chacha20', b'k' * 32, b'i' * 16, 0)

    util.run_cipher(cipher, decipher)
Exemplo n.º 2
0
def test_encryption():
    from shadowsocks.crypto import util

    cipher = TableCipher('table', b'test', b'', 1)
    decipher = TableCipher('table', b'test', b'', 0)

    util.run_cipher(cipher, decipher)
Exemplo n.º 3
0
def test_chacha20_ietf():

    print("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)
Exemplo n.º 4
0
def test_salsa20():

    print("Test salsa20")
    cipher = SodiumCrypto('salsa20', b'k' * 32, b'i' * 16, 1)
    decipher = SodiumCrypto('salsa20', b'k' * 32, b'i' * 16, 0)

    util.run_cipher(cipher, decipher)
Exemplo n.º 5
0
def run_aead_method(method, key_len=16):

    key_len = int(key_len)
    cipher = OpenSSLAeadCrypto(method, b'k' * key_len, b'i' * key_len, 1)
    decipher = OpenSSLAeadCrypto(method, b'k' * key_len, b'i' * key_len, 0)

    util.run_cipher(cipher, decipher)
Exemplo n.º 6
0
def test_chacha20_poly1305():

    print("Test chacha20-poly1305")
    cipher = SodiumAeadCrypto('chacha20-poly1305', b'k' * 32, b'i' * 32, 1)
    decipher = SodiumAeadCrypto('chacha20-poly1305', b'k' * 32, b'i' * 32, 0)

    util.run_cipher(cipher, decipher)
Exemplo n.º 7
0
def test_chacha20_ietf():

    print("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)
Exemplo n.º 8
0
def run_method(method):

    print(method, ': [stream]', 32)
    cipher = OpenSSLStreamCrypto(method, b'k' * 32, b'i' * 16, 1)
    decipher = OpenSSLStreamCrypto(method, b'k' * 32, b'i' * 16, 0)

    util.run_cipher(cipher, decipher)
Exemplo n.º 9
0
def test():
    from shadowsocks.crypto import util

    cipher = create_cipher('rc4-md5', b'k' * 32, b'i' * 16, 1)
    decipher = create_cipher('rc4-md5', b'k' * 32, b'i' * 16, 0)

    util.run_cipher(cipher, decipher)
Exemplo n.º 10
0
def run_method(method):
    from shadowsocks.crypto import util

    cipher = CtypesCrypto(method, b'k' * 32, b'i' * 16, 1)
    decipher = CtypesCrypto(method, b'k' * 32, b'i' * 16, 0)

    util.run_cipher(cipher, decipher)
Exemplo n.º 11
0
def test():
    from shadowsocks.crypto import util

    cipher = Salsa20Cipher(b'salsa20-ctr', b'k' * 32, b'i' * 8, 1)
    decipher = Salsa20Cipher(b'salsa20-ctr', b'k' * 32, b'i' * 8, 1)

    util.run_cipher(cipher, decipher)
Exemplo n.º 12
0
def test():
    from shadowsocks.crypto import util

    cipher = create_cipher('rc4-md5', b'k' * 32, b'i' * 16, 1)
    decipher = create_cipher('rc4-md5', b'k' * 32, b'i' * 16, 0)

    util.run_cipher(cipher, decipher)
Exemplo n.º 13
0
def test_aes_256_gcm():

    print("Test sodium:aes-256-gcm [payload][tag]")
    cipher = SodiumAeadCrypto('sodium:aes-256-gcm', b'k' * 32, b'i' * 32, 1)
    decipher = SodiumAeadCrypto('sodium:aes-256-gcm', b'k' * 32, b'i' * 32, 0)

    util.run_cipher(cipher, decipher)
Exemplo n.º 14
0
def test_encryption():
    from shadowsocks.crypto import util

    cipher = TableCipher('table', b'test', b'', 1)
    decipher = TableCipher('table', b'test', b'', 0)

    util.run_cipher(cipher, decipher)
Exemplo n.º 15
0
def test_salsa20():

    print("Test salsa20")
    cipher = SodiumCrypto('salsa20', b'k' * 32, b'i' * 16, 1)
    decipher = SodiumCrypto('salsa20', b'k' * 32, b'i' * 16, 0)

    util.run_cipher(cipher, decipher)
Exemplo n.º 16
0
def test():
    from shadowsocks.crypto import util

    cipher = create_cipher("rc4-md5", b"k" * 32, b"i" * 16, 1)
    decipher = create_cipher("rc4-md5", b"k" * 32, b"i" * 16, 0)

    util.run_cipher(cipher, decipher)
Exemplo n.º 17
0
def test():
    from shadowsocks.crypto import util

    cipher = Salsa20Cipher(b'salsa20-ctr', b'k' * 32, b'i' * 8, 1)
    decipher = Salsa20Cipher(b'salsa20-ctr', b'k' * 32, b'i' * 8, 1)

    util.run_cipher(cipher, decipher)
Exemplo n.º 18
0
def run_method(method):

    print(method, ': [stream]', 32)
    cipher = OpenSSLStreamCrypto(method, b'k' * 32, b'i' * 16, 1)
    decipher = OpenSSLStreamCrypto(method, b'k' * 32, b'i' * 16, 0)

    util.run_cipher(cipher, decipher)
Exemplo n.º 19
0
def run_method(method):
    from shadowsocks.crypto import util

    cipher = CtypesCrypto(method, b'k' * 32, b'i' * 16, 1)
    decipher = CtypesCrypto(method, b'k' * 32, b'i' * 16, 0)

    util.run_cipher(cipher, decipher)
Exemplo n.º 20
0
def run_method(method):
    from shadowsocks.crypto import openssl

    print(method, ': [stream]', 32)
    cipher = MbedTLSStreamCrypto(method, b'k' * 32, b'i' * 16, 1)
    decipher = openssl.OpenSSLStreamCrypto(method, b'k' * 32, b'i' * 16, 0)

    util.run_cipher(cipher, decipher)
Exemplo n.º 21
0
def test_chacha20_ietf_poly1305():
    print("Test chacha20-ietf-poly1305 [payload][tag]")
    cipher = SodiumAeadCrypto('chacha20-ietf-poly1305', b'k' * 32, b'i' * 32,
                              1)
    decipher = SodiumAeadCrypto('chacha20-ietf-poly1305', b'k' * 32, b'i' * 32,
                                0)

    util.run_cipher(cipher, decipher)
Exemplo n.º 22
0
def test_aes_256_gcm():
    print("Test sodium:aes-256-gcm [payload][tag]")
    cipher = SodiumAeadCrypto('sodium:aes-256-gcm',
                              b'k' * 32, b'i' * 32, 1)
    decipher = SodiumAeadCrypto('sodium:aes-256-gcm',
                                b'k' * 32, b'i' * 32, 0)

    util.run_cipher(cipher, decipher)
Exemplo n.º 23
0
def test_chacha20_ietf_poly1305():
    print("Test chacha20-ietf-poly1305 [payload][tag]")
    cipher = SodiumAeadCrypto('chacha20-ietf-poly1305',
                              b'k' * 32, b'i' * 32, 1)
    decipher = SodiumAeadCrypto('chacha20-ietf-poly1305',
                                b'k' * 32, b'i' * 32, 0)

    util.run_cipher(cipher, decipher)
Exemplo n.º 24
0
def run_method(method):

    print(method, ': [stream]', 32)
    key_size, iv_size, kls = ciphers.get(method, ciphers.get('cng:' + method))
    cipher = kls(method, b'k' * key_size, b'i' * iv_size, 1)
    decipher = kls(method, b'k' * key_size, b'i' * iv_size, 0)

    util.run_cipher(cipher, decipher)
Exemplo n.º 25
0
def run_aead_method(method, key_len=16):

    print(method, ': [payload][tag]', key_len)
    key_len = int(key_len)
    cipher = MbedTLSAeadCrypto(method, b'k' * key_len, b'i' * key_len, 1)
    decipher = MbedTLSAeadCrypto(method, b'k' * key_len, b'i' * key_len, 0)

    util.run_cipher(cipher, decipher)
Exemplo n.º 26
0
def run_method(method):
    from shadowsocks.crypto import openssl

    print(method, ': [stream]', 32)
    cipher = MbedTLSStreamCrypto(method, b'k' * 32, b'i' * 16, 1)
    decipher = openssl.OpenSSLStreamCrypto(method, b'k' * 32, b'i' * 16, 0)

    util.run_cipher(cipher, decipher)
Exemplo n.º 27
0
def test_aes_256_gcm_chunk():
    print("Test sodium:aes-256-gcm chunk [size][tag][payload][tag]")
    cipher = SodiumAeadCrypto('sodium:aes-256-gcm', b'k' * 32, b'i' * 32, 1)
    decipher = SodiumAeadCrypto('sodium:aes-256-gcm', b'k' * 32, b'i' * 32, 0)

    cipher.encrypt_once = cipher.encrypt
    decipher.decrypt_once = decipher.decrypt

    util.run_cipher(cipher, decipher)
Exemplo n.º 28
0
def test_chacha20_poly1305_chunk():
    print("Test chacha20-poly1305 chunk [size][tag][payload][tag]")
    cipher = SodiumAeadCrypto('chacha20-poly1305', b'k' * 32, b'i' * 32, 1)
    decipher = SodiumAeadCrypto('chacha20-poly1305', b'k' * 32, b'i' * 32, 0)

    cipher.encrypt_once = cipher.encrypt
    decipher.decrypt_once = decipher.decrypt

    util.run_cipher(cipher, decipher)
Exemplo n.º 29
0
def run_aead_method(method, key_len=16):
    from shadowsocks.crypto import openssl

    print(method, ': [payload][tag]', key_len)
    key_len = int(key_len)
    cipher = MbedTLSAeadCrypto(method, b'k' * key_len, b'i' * key_len, 1)
    decipher = openssl.OpenSSLAeadCrypto(method, b'k' * key_len,
                                         b'i' * key_len, 0)

    util.run_cipher(cipher, decipher)
Exemplo n.º 30
0
def run_aead_method_chunk(method, key_len=16):

    print(method, ': chunk([size][tag][payload][tag]', key_len)
    key_len = int(key_len)
    cipher = MbedTLSAeadCrypto(method, b'k' * key_len, b'i' * key_len, 1)
    decipher = MbedTLSAeadCrypto(method, b'k' * key_len, b'i' * key_len, 0)

    cipher.encrypt_once = cipher.encrypt
    decipher.decrypt_once = decipher.decrypt
    util.run_cipher(cipher, decipher)
Exemplo n.º 31
0
def test_chacha20_ietf_poly1305_chunk():
    print("Test chacha20-ietf-poly1305 chunk [size][tag][payload][tag]")
    cipher = SodiumAeadCrypto('chacha20-ietf-poly1305',
                              b'k' * 32, b'i' * 32, 1)
    decipher = SodiumAeadCrypto('chacha20-ietf-poly1305',
                                b'k' * 32, b'i' * 32, 0)

    cipher.encrypt_once = cipher.encrypt
    decipher.decrypt_once = decipher.decrypt

    util.run_cipher(cipher, decipher)
Exemplo n.º 32
0
def run_aead_method(method, key_len=16):

    print(method, ': [payload][tag]', key_len)
    key_len = int(key_len)
    cipher = MbedTLSAeadCrypto(method, b'k' * key_len, b'i' * key_len, 1)
    decipher = MbedTLSAeadCrypto(
        method,
        b'k' * key_len, b'i' * key_len, 0
    )

    util.run_cipher(cipher, decipher)
Exemplo n.º 33
0
def test_aes_256_gcm_chunk():
    print("Test sodium:aes-256-gcm chunk [size][tag][payload][tag]")
    cipher = SodiumAeadCrypto('sodium:aes-256-gcm',
                              b'k' * 32, b'i' * 32, 1)
    decipher = SodiumAeadCrypto('sodium:aes-256-gcm',
                                b'k' * 32, b'i' * 32, 0)

    cipher.encrypt_once = cipher.encrypt
    decipher.decrypt_once = decipher.decrypt

    util.run_cipher(cipher, decipher)
Exemplo n.º 34
0
def run_method(method):
    """
    
    执行加密方法
    
    :param method: 加密方法名称
    """
    cipher = OpenSSLCrypto(method, b'k' * 32, b'i' * 16, 1)
    decipher = OpenSSLCrypto(method, b'k' * 32, b'i' * 16, 0)

    util.run_cipher(cipher, decipher)
Exemplo n.º 35
0
def run_aead_method(method, key_len=16):
    from shadowsocks.crypto import openssl

    print(method, ': [payload][tag]', key_len)
    key_len = int(key_len)
    cipher = MbedTLSAeadCrypto(method, b'k' * key_len, b'i' * key_len, 1)
    decipher = openssl.OpenSSLAeadCrypto(
        method,
        b'k' * key_len, b'i' * key_len, 0
    )

    util.run_cipher(cipher, decipher)
Exemplo n.º 36
0
def run_aead_method_chunk(method, key_len=16):
    from shadowsocks.crypto import openssl

    print(method, ': chunk([size][tag][payload][tag]', key_len)
    key_len = int(key_len)
    cipher = MbedTLSAeadCrypto(method, b'k' * key_len, b'i' * key_len, 1)
    decipher = openssl.OpenSSLAeadCrypto(method, b'k' * key_len,
                                         b'i' * key_len, 0)

    cipher.encrypt_once = cipher.encrypt
    decipher.decrypt_once = decipher.decrypt
    util.run_cipher(cipher, decipher)
Exemplo n.º 37
0
def run_aead_method_chunk(method, key_len=16):

    print(method, ': chunk([size][tag][payload][tag]', key_len)
    key_len = int(key_len)
    cipher = MbedTLSAeadCrypto(method, b'k' * key_len, b'i' * key_len, 1)
    decipher = MbedTLSAeadCrypto(
        method,
        b'k' * key_len, b'i' * key_len, 0
    )

    cipher.encrypt_once = cipher.encrypt
    decipher.decrypt_once = decipher.decrypt
    util.run_cipher(cipher, decipher)
Exemplo n.º 38
0
def run_aead_method(method, key_len=16):

    print(method, ': [payload][tag]', key_len)
    cipher = libcrypto.EVP_get_cipherbyname(common.to_bytes(method))
    if not cipher:
        cipher = load_cipher(common.to_bytes(method))
    if not cipher:
        print('cipher not avaiable, please upgrade openssl')
        return
    key_len = int(key_len)
    cipher = OpenSSLAeadCrypto(method, b'k' * key_len, b'i' * key_len, 1)
    decipher = OpenSSLAeadCrypto(method, b'k' * key_len, b'i' * key_len, 0)

    util.run_cipher(cipher, decipher)
Exemplo n.º 39
0
def run_aead_method_chunk(method, key_len=16):
    from shadowsocks.crypto import openssl

    print(method, ': chunk([size][tag][payload][tag]', key_len)
    key_len = int(key_len)
    cipher = MbedTLSAeadCrypto(method, b'k' * key_len, b'i' * key_len, 1)
    decipher = openssl.OpenSSLAeadCrypto(
        method,
        b'k' * key_len, b'i' * key_len, 0
    )

    cipher.encrypt_once = cipher.encrypt
    decipher.decrypt_once = decipher.decrypt
    util.run_cipher(cipher, decipher)
Exemplo n.º 40
0
def run_aead_method(method, key_len=16):

    print(method, ': [payload][tag]', key_len)
    cipher = libcrypto.EVP_get_cipherbyname(common.to_bytes(method))
    if not cipher:
        cipher = load_cipher(common.to_bytes(method))
    if not cipher:
        print('cipher not avaiable, please upgrade openssl')
        return
    key_len = int(key_len)
    cipher = OpenSSLAeadCrypto(method, b'k' * key_len, b'i' * key_len, 1)
    decipher = OpenSSLAeadCrypto(method, b'k' * key_len, b'i' * key_len, 0)

    util.run_cipher(cipher, decipher)
Exemplo n.º 41
0
def run_aead_method_chunk(method, key_len=16):

    if not loaded:
        load_openssl(None)
    print(method, ': chunk([size][tag][payload][tag]', key_len)
    cipher = libcrypto.EVP_get_cipherbyname(common.to_bytes(method))
    if not cipher:
        cipher = load_cipher(common.to_bytes(method))
    if not cipher:
        print('cipher not avaiable, please upgrade openssl')
        return
    key_len = int(key_len)
    cipher = OpenSSLAeadCrypto(method, b'k' * key_len, b'i' * key_len, 1)
    decipher = OpenSSLAeadCrypto(method, b'k' * key_len, b'i' * key_len, 0)

    cipher.encrypt_once = cipher.encrypt
    decipher.decrypt_once = decipher.decrypt
    util.run_cipher(cipher, decipher)
Exemplo n.º 42
0
def run_aead_method_chunk(method, key_len=16):

    if not loaded:
        load_openssl(None)
    print(method, ': chunk([size][tag][payload][tag]', key_len)
    cipher = libcrypto.EVP_get_cipherbyname(common.to_bytes(method))
    if not cipher:
        cipher = load_cipher(common.to_bytes(method))
    if not cipher:
        print('cipher not avaiable, please upgrade openssl')
        return
    key_len = int(key_len)
    cipher = OpenSSLAeadCrypto(method, b'k' * key_len, b'i' * key_len, 1)
    decipher = OpenSSLAeadCrypto(method, b'k' * key_len, b'i' * key_len, 0)

    cipher.encrypt_once = cipher.encrypt
    decipher.decrypt_once = decipher.decrypt
    util.run_cipher(cipher, decipher)
Exemplo n.º 43
0
def run_method(method):

    cipher = OpenSSLCrypto(method, b'k' * 32, b'i' * 16, 1)
    decipher = OpenSSLCrypto(method, b'k' * 32, b'i' * 16, 0)

    util.run_cipher(cipher, decipher)
Exemplo n.º 44
0
def test_chacha20():

    cipher = SodiumCrypto('chacha20', b'k' * 32, b'i' * 16, 1)
    decipher = SodiumCrypto('chacha20', b'k' * 32, b'i' * 16, 0)

    util.run_cipher(cipher, decipher)
Exemplo n.º 45
0
def test_salsa20():
    cipher = SodiumCrypto(b'salsa20', b'k' * 32, b'i' * 16, 1)
    decipher = SodiumCrypto(b'salsa20', b'k' * 32, b'i' * 16, 0)

    util.run_cipher(cipher, decipher)
Exemplo n.º 46
0
def test_xchacha20():
    print("Test xchacha20")
    cipher = SodiumCrypto('xchacha20', b'k' * 32, b'i' * 24, 1)
    decipher = SodiumCrypto('xchacha20', b'k' * 32, b'i' * 24, 0)

    util.run_cipher(cipher, decipher)
Exemplo n.º 47
0
def run_method(method):

    cipher = OpenSSLCrypto(method, b'k' * 32, b'i' * 16, 1)
    decipher = OpenSSLCrypto(method, b'k' * 32, b'i' * 16, 0)

    util.run_cipher(cipher, decipher)
Exemplo n.º 48
0
def test_chacha20():

    cipher = SodiumCrypto('chacha20', b'k' * 32, b'i' * 16, 1)
    decipher = SodiumCrypto('chacha20', b'k' * 32, b'i' * 16, 0)

    util.run_cipher(cipher, decipher)
Exemplo n.º 49
0
def test_salsa20():
    cipher = SodiumCrypto(b'salsa20', b'k' * 32, b'i' * 16, 1)
    decipher = SodiumCrypto(b'salsa20', b'k' * 32, b'i' * 16, 0)

    util.run_cipher(cipher, decipher)
Exemplo n.º 50
0
def test_xsalsa20():
    cipher = SodiumCrypto('xsalsa20', b'k' * 32, b'i' * 24, 1)
    decipher = SodiumCrypto('xsalsa20', b'k' * 32, b'i' * 24, 0)

    util.run_cipher(cipher, decipher)
Exemplo n.º 51
0
def test_xchacha20():
    print("Test xchacha20")
    cipher = SodiumCrypto('xchacha20', b'k' * 32, b'i' * 24, 1)
    decipher = SodiumCrypto('xchacha20', b'k' * 32, b'i' * 24, 0)

    util.run_cipher(cipher, decipher)