예제 #1
0
def test_add_samples_2d(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.samples)
    ths_2 = out.get_reader()
    assert np.array_equal(ths.samples.array, ths_2.samples.array)
예제 #2
0
def test_ets_writer_add_metadata_with_inconsistent_sizes(ets_filenames):
    out = ETSWriter(filename)
    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')
    chair = np.array(['abcd' for i in range(nb_trace)])
    ciphertext = np.random.randint(0, 256, (nb_trace, 16), dtype='uint8')

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

    out.add_samples(ths.samples)
    out.add_metadata(ths.metadatas)

    datas = np.random.randint(0,
                              256,
                              size=(nb_trace, nb_points),
                              dtype=np.uint8)
    plaintext = np.random.randint(0, 256, (nb_trace, 18), dtype='uint8')
    ths = estraces.formats.read_ths_from_ram(datas,
                                             chair=chair,
                                             plaintext=plaintext,
                                             ciphertext=ciphertext)
    out.add_metadata(ths.metadatas)
    ths = out.get_reader()
    assert ths.plaintext.shape == (2 * nb_trace, 16)
예제 #3
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)
예제 #4
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)
예제 #5
0
def test_ets_writer_add_metadata_for_several_traces(ets_filenames):
    out = ETSWriter(filename)
    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')
    chair = np.array(['abcd' for i in range(nb_trace)])
    ciphertext = np.random.randint(0, 256, (nb_trace, 16), dtype='uint8')

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

    out.add_samples(ths.samples)
    out.add_metadata(ths.metadatas)
    out_ths = out.get_reader()
    assert np.array_equal(out_ths.plaintext, plaintext)
    assert np.array_equal(out_ths.ciphertext, ciphertext)
    assert np.array_equal(out_ths.chair.tolist(), chair.tolist())
예제 #6
0
def test_add_samples_truncate_samples_to_first_inserted_data_size(
        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.samples)
    ths_2 = estraces.formats.read_ths_from_ram(
        np.random.randint(100, size=(nb_trace, nb_points + 10),
                          dtype=np.uint8))
    out.add_samples(ths_2.samples)
    ths_4 = estraces.formats.read_ths_from_ram(
        np.random.randint(100, size=(nb_trace, nb_points - 10),
                          dtype=np.uint8))
    out.add_samples(ths_4.samples)
    ths_3 = out.get_reader()
    assert len(ths_3[0].samples) == nb_points
예제 #7
0
def test_add_samples_raise_exception_if_not_samples_instance(ets_filenames):
    out = ETSWriter(filename)
    with pytest.raises(TypeError):
        out.add_samples([1, 2, 3])