Exemple #1
0
def test_writer_open_a_new_file(ets_filenames):
    out = ETSWriter(filename, overwrite=True)
    datas = np.random.randint(100, size=(nb_trace, nb_points), dtype=np.uint8)
    ths = estraces.formats.read_ths_from_ram(datas)
    out.add_samples(ths[0].samples)
    out.close()
    ths_2 = estraces.read_ths_from_ets_file(filename)
    assert np.array_equal(ths_2[0].samples.array, ths[0].samples.array)
    assert len(ths_2) == 1
    os.remove(filename)
Exemple #2
0
def test_writer_open_an_existing_file_and_append_to(ets_filenames):
    out = ETSWriter(filename)
    datas = np.random.randint(100, size=(nb_trace, nb_points), dtype=np.uint8)
    ths = estraces.formats.read_ths_from_ram(datas)
    out.add_samples(ths[0].samples)
    out.close()
    out = ETSWriter(filename)
    out.add_samples(ths[1].samples)
    out.close()
    ths_2 = estraces.read_ths_from_ets_file(filename)
    assert len(ths_2) == 2
    assert np.array_equal(ths_2.samples.array, ths[0:2].samples.array)
    os.remove(filename)
Exemple #3
0
def test_write_samples_1d(ets_filenames):
    out = ETSWriter(filename, overwrite=True)
    datas = np.random.randint(100, size=(nb_trace, nb_points), dtype=np.uint8)
    ths = estraces.formats.read_ths_from_ram(datas)
    out.add_samples(ths[0].samples)
    out.add_samples(ths[1].samples)
    ths_2 = out.get_reader()
    assert np.array_equal(ths[0].samples.array, ths_2[0].samples.array)
    assert np.array_equal(ths[1].samples.array, ths_2[1].samples.array)
    out.close()
    out = ETSWriter(filename)
    out.add_samples(ths[2].samples)
    ths_2 = out.get_reader()
    assert np.array_equal(ths[2].samples.array, ths_2[2].samples.array)
Exemple #4
0
def test_ets_writer_raises_exception_if_trying_to_replace_existing_data_wo_overwrite_mode(
        ets_filenames):
    out = ETSWriter(filename)
    datas = np.random.randint(100, size=(nb_trace, nb_points), dtype=np.uint8)
    out.write_samples(datas)
    out.close()
    out = ETSWriter(filename)
    with pytest.raises(estraces.ETSWriterException):
        out.write_samples(datas, index=0)
    out.close()
    out = ETSWriter(filename, overwrite=True)
    replacement = np.random.randint(100,
                                    size=(nb_trace - 5, nb_points),
                                    dtype=np.uint8)
    out.write_samples(replacement, index=0)
    ths = out.get_reader()
    assert np.array_equal(ths.samples[:nb_trace - 5], replacement)
Exemple #5
0
def test_write_trace_with_new_metadata(ets_filenames):
    datas = np.random.randint(0,
                              256,
                              size=(nb_trace, nb_points),
                              dtype=np.uint8)
    plaintext = np.random.randint(0, 256, (nb_trace, 16), dtype='uint8')
    ciphertext = np.random.randint(0, 256, (nb_trace, 16), dtype='uint8')

    ths = estraces.formats.read_ths_from_ram(datas,
                                             plaintext=plaintext,
                                             ciphertext=ciphertext)

    for index, trace in enumerate(ths):
        trace.new_meta = 'oups'
        out = ETSWriter(filename)
        out.write_trace_object_and_points(trace, trace.samples[:], index)
    out.close()

    ths_2 = estraces.read_ths_from_ets_file(filename)

    assert ths_2[0].new_meta == 'oups'
Exemple #6
0
def test_ets_writer_works_whatever_is_the_index_order(ets_filenames):
    base_trace = np.random.randint(0,
                                   256, (nb_trace, nb_points),
                                   dtype='uint8')

    ets1 = ETSWriter(filename_1, overwrite=True)
    indexes = np.arange(nb_trace)
    for ind in indexes:
        ets1.write_samples(base_trace[ind], index=ind)
    ets1.close()

    ets2 = ETSWriter(filename_2, overwrite=True)

    for ind in reversed(indexes):
        ets2.write_samples(base_trace[ind], index=ind)
    ets2.close()

    ets3 = ETSWriter(filename_3, overwrite=True)
    indexes_3 = [nb_trace - 1, 2, 1]
    for ind in indexes_3:
        ets3.write_samples(base_trace[ind], index=ind)
    ets3.close()

    d1 = read_ths_from_ets_file(filename_1).samples[:]
    d2 = read_ths_from_ets_file(filename_2).samples[:]
    d3 = read_ths_from_ets_file(filename_3).samples[:]
    assert np.array_equal(d1[nb_trace - 1], d3[nb_trace - 1])
    assert np.array_equal(d1[2], d3[2])
    assert np.array_equal(d1[1], d3[1])

    assert d1.shape == d2.shape
    assert d1.shape == d3.shape

    s1 = os.path.getsize(filename_1)
    s2 = os.path.getsize(filename_2)

    assert s1 == s2