Exemple #1
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)
Exemple #2
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())
Exemple #3
0
def test_ets_writer_raises_exception_if_metadatas_is_not_proper_type(
        ets_filenames):
    out = ETSWriter(filename)
    with pytest.raises(TypeError):
        out.add_metadata({"dic": 1})