Ejemplo n.º 1
0
def test_expansion_function():
    prg = PRG()

    key_16 = make_words(n=4, as_tuple=False)

    key_32 = make_words(n=8, as_tuple=False)
    key0_32 = key_32[0:128]
    key1_32 = key_32[128:256]

    n = make_words(n=4, as_tuple=False)

    output_16 = prg.expansion_function(key_16, key_16, n, False)
    output_32 = prg.expansion_function(key0_32, key1_32, n, True)

    assert len(output_16) == 512
    assert len(output_32) == 512
def compare_salsa_with_similar_inputs(flips):
    prg = PRG()

    #key = '0' * 256
    key = get_random_binary(256)
    key0 = key[:128]
    key1 = key[128:]
    nonce = get_random_binary(128)
    IV_0, IV_1, IV_2, IV_3 = prg.a_vects
    original_hash_input = IV_0 + key0 + IV_1 + nonce + IV_2 + key1 + IV_3
    original_hash_output = prg.expansion_function(key0,
                                                  key1,
                                                  nonce,
                                                  full_key=True)

    in_out_HDs = []
    in_in_HDs = []
    out_out_HDs = []

    for flip in range(flips):
        key0 = key[:128]
        key1 = key[128:]
        hash_output = prg.expansion_function(key0, key1, nonce, full_key=True)
        hash_input = IV_0 + key0 + IV_1 + nonce + IV_2 + key1 + IV_3

        in_out_HD = hamming_distance(hash_output, hash_input)
        in_out_HDs.append(in_out_HD)

        in_in_HD = hamming_distance(original_hash_input, hash_input)
        in_in_HDs.append(in_in_HD)

        #out_out_HD = hamming_distance(original_hash_output, hash_input)
        #out_out_HDs.append(out_out_HD)
        out_out_HDs.append(256)

        key = flip_random_bit(key)

    return in_out_HDs, in_in_HDs, out_out_HDs