| | import h5py |
| | import numpy as np |
| | import argparse |
| | import os |
| |
|
| | CHUNK_SHAPE = 4_000 |
| | NSW = 128_000 |
| | TRACE_LENGHT = 200_000 |
| |
|
| | if __name__ == '__main__': |
| |
|
| | parser = argparse.ArgumentParser() |
| | parser.add_argument("-dd", "--dataset_dir", required=True, |
| | help="Directory containing the dataset chunks") |
| | args = vars(parser.parse_args()) |
| | dataset_dir = args['dataset_dir'] |
| |
|
| | |
| | profile_traces_layout = h5py.VirtualLayout( |
| | shape=(NSW, TRACE_LENGHT), dtype=np.float32) |
| | attack_traces_layout = h5py.VirtualLayout( |
| | shape=(NSW, TRACE_LENGHT), dtype=np.float32) |
| |
|
| | dt = h5py.vlen_dtype(np.uint32) |
| | label_dtype = np.dtype([('sample', dt), ('frequency', dt)]) |
| | profile_labels_layout = h5py.VirtualLayout(shape=(NSW,), dtype=label_dtype) |
| | attack_labels_layout = h5py.VirtualLayout(shape=(NSW,), dtype=label_dtype) |
| |
|
| | dt = np.dtype([('key', np.uint8, (16,)), ('plaintext', np.uint8, (16,))]) |
| | profile_meta_layout = h5py.VirtualLayout(shape=(NSW,), dtype=dt) |
| | attack_meta_layout = h5py.VirtualLayout(shape=(NSW,), dtype=dt) |
| |
|
| | |
| | for n in range(NSW//CHUNK_SHAPE): |
| | filename = os.path.join(dataset_dir, f'dfs_desynch_chunk_{n}.h5') |
| | profile_traces_layout[n*CHUNK_SHAPE:(n+1)*CHUNK_SHAPE] = h5py.VirtualSource( |
| | filename, 'profiling/traces', shape=(CHUNK_SHAPE, TRACE_LENGHT)) |
| | attack_traces_layout[n*CHUNK_SHAPE:(n+1)*CHUNK_SHAPE] = h5py.VirtualSource( |
| | filename, 'attack/traces', shape=(CHUNK_SHAPE, TRACE_LENGHT)) |
| |
|
| | profile_labels_layout[n*CHUNK_SHAPE:(n+1)*CHUNK_SHAPE] = h5py.VirtualSource( |
| | filename, 'profiling/labels', shape=(CHUNK_SHAPE,)) |
| | attack_labels_layout[n*CHUNK_SHAPE:(n+1)*CHUNK_SHAPE] = h5py.VirtualSource( |
| | filename, 'attack/labels', shape=(CHUNK_SHAPE,)) |
| |
|
| | profile_meta_layout[n*CHUNK_SHAPE:(n+1)*CHUNK_SHAPE] = h5py.VirtualSource( |
| | filename, 'profiling/metadata', shape=(CHUNK_SHAPE,)) |
| | attack_meta_layout[n*CHUNK_SHAPE:(n+1)*CHUNK_SHAPE] = h5py.VirtualSource( |
| | filename, 'attack/metadata', shape=(CHUNK_SHAPE,)) |
| |
|
| | |
| | dfs_desynch_path = os.path.join(dataset_dir, 'dfs_desynch.h5') |
| | with h5py.File(dfs_desynch_path, 'w', libver='latest') as f: |
| | profiling_group = f.create_group('profiling') |
| | attack_group = f.create_group('attack') |
| |
|
| | |
| | profiling_group.create_virtual_dataset('traces', profile_traces_layout) |
| | profiling_group.create_virtual_dataset('labels', profile_labels_layout) |
| | profiling_group.create_virtual_dataset('metadata', profile_meta_layout) |
| |
|
| | attack_group.create_virtual_dataset('traces', attack_traces_layout) |
| | attack_group.create_virtual_dataset('labels', attack_labels_layout) |
| | attack_group.create_virtual_dataset('metadata', attack_meta_layout) |
| |
|
| | print(f"DFS_DESYNCH dataset assembled in {dfs_desynch_path}") |
| |
|