--- title: ascad-v2-15k tags: - side-channel-analysis - cryptography - DLSCA parameters: HF_ORG: DLSCA CHUNK_SIZE_Y: 100000 TOTAL_CHUNKS_ON_Y: 6 CHUNK_SIZE_X: 10 TOTAL_CHUNKS_ON_X: 1500 NUM_JOBS: 10 CAN_RUN_LOCALLY: True CAN_RUN_ON_CLOUD: False COMPRESSED: True --- # ascad-v2-15k This script downloads, extracts, and uploads the ASCAD v2 extracted dataset to Hugging Face Hub. Profiling (500k) and attack (10k) traces are merged into a single flat dataset of 510k traces with 15k samples per trace. Chunks: CHUNK_SIZE_Y=100000, TOTAL_CHUNKS_ON_Y=6 (last chunk has 10000 traces). ## Dataset Structure This dataset is stored in Zarr format, optimized for chunked and compressed cloud storage. ### Traces (`/traces`) - **Shape**: `[510000, 15000]` (Traces x Time Samples) - **Data Type**: `int8` - **Chunk Shape**: `[100000, 10]` ### Metadata (`/metadata`) - **key**: shape `[510000, 16]`, dtype `uint8` - **mask**: shape `[510000, 16]`, dtype `uint8` - **mask_**: shape `[510000, 16]`, dtype `uint8` - **perm_index**: shape `[510000, 16]`, dtype `uint8` - **plaintext**: shape `[510000, 16]`, dtype `uint8` - **rin**: shape `[510000, 1]`, dtype `uint8` - **rin_**: shape `[510000, 1]`, dtype `uint8` - **rm**: shape `[510000, 1]`, dtype `uint8` - **rm_**: shape `[510000, 1]`, dtype `uint8` - **rout**: shape `[510000, 1]`, dtype `uint8` - **rout_**: shape `[510000, 1]`, dtype `uint8` - **sbox_masked**: shape `[510000, 16]`, dtype `uint8` - **sbox_masked_with_perm**: shape `[510000, 16]`, dtype `uint8` ## Leakage Analysis Targets The following targets are available for side-channel leakage analysis on this dataset: | Target Name | Description | | :--- | :--- | | `ciphertext` | Returns `metadata['ciphertext'][:, byte_index]` | | `key` | Returns `metadata['key'][:, byte_index]` | | `mask` | Returns `metadata['mask'][:, byte_index]` | | `mask_` | Returns `metadata['mask_'][:, byte_index]` | | `perm_index` | Returns `metadata['perm_index'][:, byte_index]` | | `plaintext` | Returns `metadata['plaintext'][:, byte_index]` | | `rin` | Returns `metadata['rin'][:, 0]` | | `rin_` | Returns `metadata['rin_'][:, 0]` | | `rm` | Returns `metadata['rm'][:, 0]` | | `rm_` | Returns `metadata['rm_'][:, 0]` | | `rout` | Returns `metadata['rout'][:, 0]` | | `rout_` | Returns `metadata['rout_'][:, 0]` | | `sbi` | Returns `np.bitwise_xor(metadata['plaintext'][:, byte_index], metadata['key'][:, byte_index])` | | `sbo` | Returns `SBOX[Targets.sbi(metadata=metadata, byte_index=byte_index, dataset_name=dataset_name)]` | | `sbox_masked` | Returns `metadata['sbox_masked'][:, byte_index]` | | `sbox_masked_with_perm` | Returns `metadata['sbox_masked_with_perm'][:, byte_index]` | | `v2_affine_ptx` | State after Map_in_G + Xor_states at slot ``byte_index``.

``rm * ptx[j] ^ mask[j]`` where ``j = perm[byte_index]``.

The affine-masked plaintext before any round key has been mixed in. | | `v2_key` | Plain key byte at the AES position consumed by shuffling slot ``byte_index``.

``key[j]`` where ``j = perm[byte_index]``.

The key byte is loaded unprotected from flash/ROM during AddRoundKey r=0 before being scaled into the GF(256) domain via ``gtab``. Classic first-order DPA target; ``v2_rm_key`` is the masked (GF-scaled) version. | | `v2_lut_idx` | sboxMasked LUT index computed during SubBytes at round 1, slot ``byte_index``.

``rm * (ptx[j] ^ key[j]) ^ rin`` where ``j = perm[byte_index]``.

Computed as ``state[j] ^ state2[j]`` inside the SubBytes loop: the additive masks (masksState) cancel, leaving only the multiplicatively-masked SBI XORed with rin. This is the value whose hamming weight leaks during the LUT address computation. | | `v2_mask_at_perm` | Per-byte additive mask at the AES position consumed by shuffling slot ``byte_index``.

``mask[j]`` where ``j = perm[byte_index]``.

Distinct from ``mask[byte_index]`` whenever the permutation is non-identity. This is the mask that enters and leaves every intermediate in the affine invariant for slot ``byte_index``. | | `v2_masked_sbi` | State entering round 1 at slot ``byte_index``: after AddRoundKey r=0.

``rm * (ptx[j] ^ key[j]) ^ mask[j]`` where ``j = perm[byte_index]``.

This is the affine-masked plaintext XOR key value that the round-1 SubBytes call will process. | | `v2_perm` | Shuffling permutation index at slot ``byte_index`` for ASCAD v2.

Returns ``j = perm[:, byte_index]`` — for each trace the AES byte position (0–15) processed in shuffling slot ``byte_index``. All other slot-indexed ``v2_*`` targets derive ``j`` via this method.

**Original-paper label:** ``perm_index[byte_index]`` in the ASCAD v2 HDF5 file. Derived as:

perm[n, i] = G[G[G[G[(15 - i) XOR x0[n]] XOR x1[n]] XOR x2[n]] XOR x3[n]]

where G = ``_V2_PERM_G`` and x0..x3 are the lower nibbles of mask[:, 0..3]. | | `v2_ptx` | Plaintext byte at the AES position consumed by shuffling slot ``byte_index``.

``ptx[j]`` where ``j = perm[byte_index]``.

The byte value loaded from the plaintext register before ``Map_in_G`` scales it into the GF(256) multiplicative domain. Classic first-order DPA target; ``v2_rm_ptx`` is the masked version after Map_in_G. | | `v2_raw_out` | SubBytes ``raw_out`` at round 1, slot ``byte_index``: the sboxMasked LUT output.

``rm * SBOX(ptx[j] ^ key[j]) ^ rout`` where ``j = perm[byte_index]``.

This is ``sboxMasked[lut_idx]`` — the value read from the firmware's masked S-Box LUT before it is XORed with ``state2[j]`` (masksState). It sits between :meth:`v2_lut_idx` (the LUT address) and :meth:`v2_sbo_mid` (the value written back into ``state[j]``).

**Original-paper label:** ``sbox_masked[byte_index]`` in the ASCAD v2 HDF5 file and the NCC Group ML-104 blog 34-task model. | | `v2_raw_out_direct` | SubBytes ``raw_out`` at round 1 indexed directly by AES byte position.

``rm * SBOX(ptx[i] ^ key[i]) ^ rout`` where ``i = byte_index`` (no perm).

Unlike :meth:`v2_raw_out`, the shuffle permutation is **not** applied — ``byte_index`` maps directly to the AES state byte position. This is the same formula as :meth:`v2_raw_out` but over the identity byte ordering, making it practical as an un-permuted SNR or model target.

**Original-paper label:** ``sbox_masked_with_perm[byte_index]`` in the ASCAD v2 HDF5 file and the NCC Group ML-104 blog 18-task model (``RMmSBOxROUT`` in scandal/crypto.py). | | `v2_rm_key` | Masked round-key contribution added during AddRoundKey r=0 at slot ``byte_index``.

``rm * key[j]`` where ``j = perm[byte_index]``.

This is ``gtab[key[j]]`` — the value XORed into state during the masked AddRoundKey call, scaled into the same multiplicative domain as the plaintext. | | `v2_rm_ptx` | Map_in_G output at slot ``byte_index``: ``rm * ptx[j]``, ``j = perm[byte_index]``.

The plaintext byte scaled into the GF(256) multiplicative domain. Additive mask (masksState) has not yet been applied at this point. | | `v2_sbi_perm` | Unmasked SBI at the AES byte position consumed by shuffling slot ``byte_index``.

``ptx[j] ^ key[j]`` where ``j = perm[byte_index]``.

Unlike :meth:`sbi`, which uses ``byte_index`` as a direct AES byte position, this target follows the actual byte consumed by the firmware SubBytes shuffle at slot ``byte_index``. | | `v2_sbo_affine` | Affine-masked SBO at slot ``byte_index`` after full SubBytes (post-loop rout strip).

``rm * SBOX(ptx[j] ^ key[j]) ^ mask[j]`` where ``j = perm[byte_index]``.

This is the state value after the post-loop ``state[j] ^= rout`` pass restores the affine invariant. The rout mask is gone; only the multiplicative mask rm and the per-byte additive mask remain. | | `v2_sbo_mid` | Mid-SubBytes state at slot ``byte_index`` before post-loop rout strip.

``rm * SBOX(ptx[j] ^ key[j]) ^ rout ^ mask[j]`` where ``j = perm[byte_index]``.

This is ``raw_out ^ state2[j]``, i.e. the value written back into ``state[j]`` inside the SubBytes inner loop, before the post-loop ``state[j] ^= rout`` pass. The rout mask has not yet been removed. | | `v2_sbo_perm` | Unmasked SBO at the AES byte position consumed by shuffling slot ``byte_index``.

``SBOX(ptx[j] ^ key[j])`` where ``j = perm[byte_index]``. | | `v2_xw_state` | State after Xor_Word at round 1 (before SubBytes) at slot ``byte_index``.

``rm * (ptx[j] ^ key[j]) ^ mask[j] ^ rin`` where ``j = perm[byte_index]``.

This is the state byte written to the register immediately before the firmware issues the sboxMasked lookup. | ## Auto-Generated Leakage Plots | Dataset | Target | Byte Index | Plot | | :--- | :--- | :---: | :---: | | ascad-v2-15k | key | 0 | ascad-v2-15k key | | ascad-v2-15k | mask | 0 | ascad-v2-15k mask | | ascad-v2-15k | mask_ | 0 | ascad-v2-15k mask_ | | ascad-v2-15k | perm_index | 0 | ascad-v2-15k perm_index | | ascad-v2-15k | plaintext | 0 | ascad-v2-15k plaintext | | ascad-v2-15k | sbi | 0 | ascad-v2-15k sbi | | ascad-v2-15k | sbo | 0 | ascad-v2-15k sbo | | ascad-v2-15k | sbox_masked | 0 | ascad-v2-15k sbox_masked | | ascad-v2-15k | sbox_masked_with_perm | 0 | ascad-v2-15k sbox_masked_with_perm | | ascad-v2-15k | v2_affine_ptx | 0 | ascad-v2-15k v2_affine_ptx | | ascad-v2-15k | v2_key | 0 | ascad-v2-15k v2_key | | ascad-v2-15k | v2_lut_idx | 0 | ascad-v2-15k v2_lut_idx | | ascad-v2-15k | v2_mask_at_perm | 0 | ascad-v2-15k v2_mask_at_perm | | ascad-v2-15k | v2_masked_sbi | 0 | ascad-v2-15k v2_masked_sbi | | ascad-v2-15k | v2_perm | 0 | ascad-v2-15k v2_perm | | ascad-v2-15k | v2_ptx | 0 | ascad-v2-15k v2_ptx | | ascad-v2-15k | v2_raw_out | 0 | ascad-v2-15k v2_raw_out | | ascad-v2-15k | v2_raw_out_direct | 0 | ascad-v2-15k v2_raw_out_direct | | ascad-v2-15k | v2_rm_key | 0 | ascad-v2-15k v2_rm_key | | ascad-v2-15k | v2_rm_ptx | 0 | ascad-v2-15k v2_rm_ptx | | ascad-v2-15k | v2_sbi_perm | 0 | ascad-v2-15k v2_sbi_perm | | ascad-v2-15k | v2_sbo_affine | 0 | ascad-v2-15k v2_sbo_affine | | ascad-v2-15k | v2_sbo_mid | 0 | ascad-v2-15k v2_sbo_mid | | ascad-v2-15k | v2_sbo_perm | 0 | ascad-v2-15k v2_sbo_perm | | ascad-v2-15k | v2_xw_state | 0 | ascad-v2-15k v2_xw_state | | ascad-v2-15k | rin | none | ascad-v2-15k rin | | ascad-v2-15k | rin_ | none | ascad-v2-15k rin_ | | ascad-v2-15k | rm | none | ascad-v2-15k rm | | ascad-v2-15k | rm_ | none | ascad-v2-15k rm_ | | ascad-v2-15k | rout | none | ascad-v2-15k rout | | ascad-v2-15k | rout_ | none | ascad-v2-15k rout_ | ## Parameters Used for Generation - **HF_ORG**: `DLSCA` - **CHUNK_SIZE_Y**: `100000` - **TOTAL_CHUNKS_ON_Y**: `6` - **CHUNK_SIZE_X**: `10` - **TOTAL_CHUNKS_ON_X**: `1500` - **NUM_JOBS**: `10` - **CAN_RUN_LOCALLY**: `True` - **CAN_RUN_ON_CLOUD**: `False` - **COMPRESSED**: `True` ## Usage You can load this dataset directly using Zarr and Hugging Face File System: ```python import zarr from huggingface_hub import HfFileSystem fs = HfFileSystem() # Map only once to the dataset root root = zarr.open_group(fs.get_mapper("datasets/DLSCA/ascad-v2-15k"), mode="r") # Access traces directly traces = root["traces"] print("Traces shape:", traces.shape) # Access plaintext metadata directly plaintext = root["metadata"]["plaintext"] print("Plaintext shape:", plaintext.shape) ```