def test_ets_writer_add_trace_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(ths[0])
def test_ets_writer_add_trace(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(ths[0]) out_ths = out.get_reader() assert np.array_equal(out_ths[0].plaintext, plaintext[0]) assert np.array_equal(out_ths[0].ciphertext, ciphertext[0]) assert out_ths[0].chair == chair.tolist()[0] assert np.array_equal(out_ths[0].samples.array, datas[0])
def test_ets_writer_add_trace_raises_exception_if_trace_has_improper_types( ets_filenames): out = ETSWriter(filename) with pytest.raises(TypeError): out.add_trace({'not': 'a trace'})