Esempio n. 1
0
def test_write_points_length_1(ets_filenames):
    out = ETSWriter(filename, overwrite=True)

    datas = np.random.randint(100, size=(nb_trace, nb_points), dtype=np.uint8)
    for index, data in enumerate(datas):
        out.write_samples(np.array([10]), index=index)
    ths = out.get_reader()
    assert np.array_equal(ths[0].samples[:], np.array([10]))
Esempio n. 2
0
def test_write_meta_string(ets_filenames):
    out = ETSWriter(filename, overwrite=True)

    datas = np.random.randint(100, size=(nb_trace, nb_points), dtype=np.uint8)
    for index, data in enumerate(datas):
        out.write_samples(data, index=index)
        out.write_metadata('plaintext', 'azerty', index=index)

    ths = out.get_reader()
    assert ths[0].plaintext == 'azerty'
Esempio n. 3
0
def test_write_meta_length_1(ets_filenames):
    out = ETSWriter(filename, overwrite=True)

    datas = np.random.randint(100, size=(nb_trace, nb_points), dtype=np.uint8)
    for index, data in enumerate(datas):
        out.write_samples(data, index=index)
        out.write_metadata('plaintext', 22, index=index)

    ths = out.get_reader()
    assert np.array_equal(ths[0].plaintext, np.array([22]))
Esempio n. 4
0
def test_write_samples(ets_filenames):
    out = ETSWriter(filename, overwrite=True)

    datas = np.random.randint(100, size=(nb_trace, nb_points), dtype=np.uint8)
    plaintext = np.random.randint(256, size=(nb_trace, 16), dtype=np.uint8)
    for index, data in enumerate(datas):
        out.write_samples(data, index=index)
        out.write_metadata('plaintext', plaintext[index], index=index)

    ths = out.get_reader()
    for i, t in enumerate(ths):
        assert np.array_equal(t.samples[:], datas[i])
        assert np.array_equal(t.plaintext, plaintext[i])
Esempio n. 5
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)
Esempio n. 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
Esempio n. 7
0
def test_write_2d_ndarray_points(ets_filenames):
    out = ETSWriter(filename, overwrite=True)
    datas = np.random.randint(100, size=(nb_trace, nb_points), dtype=np.uint8)
    out.write_samples(datas)
    ths = out.get_reader()
    assert np.array_equal(ths.samples.array, datas)