Exemple #1
0
def test_ets_writer_add_ths_raises_exception_if_metadata_are_inconsistent(
        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_trace_header_set(ths)

    datas = np.random.randint(0,
                              256,
                              size=(nb_trace, nb_points),
                              dtype=np.uint8)
    plaintext_2 = 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_2=plaintext_2,
                                             ciphertext=ciphertext)
    with pytest.raises(estraces.ETSWriterException):
        out.add_trace_header_set(ths)
Exemple #2
0
def test_write_trace_with_scalar_metadata(ets_filenames):
    datas = np.random.randint(0,
                              256,
                              size=(nb_trace, nb_points),
                              dtype=np.uint8)
    scals = np.random.randint(0, 256, (nb_trace, ), dtype='uint8')

    ths = estraces.formats.read_ths_from_ram(datas, scals=scals)

    out = ETSWriter(filename)
    out.add_trace_header_set(ths)

    ths_2 = out.get_reader()

    assert len(ths_2.scals) == nb_trace
Exemple #3
0
def test_ets_writer_add_trace_header_set(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)
    new_meta = np.random.randint(0, 255, (len(ths), 1), dtype='uint8')
    ths.metadatas['new'] = new_meta
    out.add_trace_header_set(ths)
    out_ths = out.get_reader()
    assert np.array_equal(out_ths.plaintext, plaintext)
    assert np.array_equal(out_ths.ciphertext, ciphertext)
    assert out_ths.chair.tolist() == chair.tolist()
    assert np.array_equal(out_ths.samples.array, datas)
    assert np.array_equal(out_ths.new, new_meta)
Exemple #4
0
def test_ets_writer_add_ths_raises_exception_if_ths_has_improper_types(
        ets_filenames):
    out = ETSWriter(filename)
    with pytest.raises(TypeError):
        out.add_trace_header_set({'not': 'a ths'})