### Installing AISY Framework - Bash Source: https://github.com/aisylab/aisy_docs/blob/master/docs/index.md This snippet provides the commands to install the AISY Framework. It involves cloning the repository from GitHub, navigating into the project directory, and installing the required Python dependencies using pip from the `requirements.txt` file. ```bash git clone https://github.com/AISyLab/AISY_Framework.git cd AISY_framework pip install -r requirements.txt ``` -------------------------------- ### Starting AISY Web Application - Bash Source: https://github.com/aisylab/aisy_docs/blob/master/docs/index.md This command sequence navigates into the AISY_Framework directory and then starts the Flask web application. This allows users to access the web homepage and visualize project results in a browser. ```Bash cd AISY_Framework/ flask run ``` -------------------------------- ### Installing AISY Framework Source: https://github.com/aisylab/aisy_docs/blob/master/site/index.html This snippet provides the command-line instructions to clone the AISY Framework repository from GitHub, navigate into its directory, and install all required Python dependencies using pip. ```Shell git clone https://github.com/AISyLab/AISY_Framework.git cd AISY_framework pip install -r requirements.txt ``` -------------------------------- ### Configuring and Running Side-Channel Analysis with AISY Framework - Python Source: https://github.com/aisylab/aisy_docs/blob/master/site/simple_example/index.html This Python snippet demonstrates the basic setup and execution of a side-channel analysis attack using the AISY Framework. It initializes the framework, configures root folders for resources, databases, and datasets, specifies the target dataset ('ascad-variable.h5'), sets an AES leakage model (Hamming Weight for byte 2), defines training parameters like batch size and epochs, and integrates a neural network model ('mlp') before initiating the analysis. Dependencies include 'aisy_sca' and custom application/model imports. ```Python import aisy_sca from app import * from custom.custom_models.neural_networks import * aisy = aisy_sca.Aisy() aisy.set_resources_root_folder(resources_root_folder) aisy.set_database_root_folder(databases_root_folder) aisy.set_datasets_root_folder(datasets_root_folder) aisy.set_database_name("database_ascad.sqlite") aisy.set_dataset(datasets_dict["ascad-variable.h5"]) aisy.set_aes_leakage_model(leakage_model="HW", byte=2) aisy.set_batch_size(400) aisy.set_epochs(20) aisy.set_neural_network(mlp) aisy.run() ``` -------------------------------- ### Defining Distribution Option Finalizers for Setuptools Source: https://github.com/aisylab/aisy_docs/blob/master/venv/Lib/site-packages/setuptools-59.6.0.dist-info/entry_points.txt This section registers functions that are called to finalize or process distribution options before the build or installation process begins. These functions ensure that setup keywords are correctly handled and integrated, providing a last-minute opportunity for data manipulation or validation. ```Configuration keywords = setuptools.dist:Distribution._finalize_setup_keywords parent_finalize = setuptools.dist:_Distribution.finalize_options ``` -------------------------------- ### Complete Script for Aisy Analysis and Custom Table Insertion (Python) Source: https://github.com/aisylab/aisy_docs/blob/master/site/custom_database_table/index.html This comprehensive example combines the initialization of the Aisy framework, execution of an analysis, and subsequent insertion of custom data into a database table. It demonstrates the full workflow from setup to data persistence. ```Python import aisy_sca from app import * from custom.custom_models.neural_networks import * from custom.custom_tables.tables import * aisy = aisy_sca.Aisy() aisy.set_resources_root_folder(resources_root_folder) aisy.set_database_root_folder(databases_root_folder) aisy.set_datasets_root_folder(datasets_root_folder) aisy.set_database_name("database_ascad.sqlite") aisy.set_dataset(datasets_dict["ascad-variable.h5"]) aisy.set_aes_leakage_model(leakage_model="HW", byte=2) aisy.set_batch_size(400) aisy.set_epochs(20) aisy.set_neural_network(mlp) aisy.run() start_custom_tables(databases_root_folder + "database_ascad.sqlite") session = start_custom_tables_session(databases_root_folder + "database_ascad.sqlite") new_insert = CustomTable(value1=10, value2=20, value3=30, analysis_id=aisy.get_analysis_id()) session.add(new_insert) session.commit() ``` -------------------------------- ### Defining Setup Keywords for Setuptools Source: https://github.com/aisylab/aisy_docs/blob/master/venv/Lib/site-packages/setuptools-59.6.0.dist-info/entry_points.txt This section registers custom keywords that can be used in a `setup.py` script, mapping them to validation or processing functions within setuptools. These keywords extend the standard `distutils` setup options, enabling richer package metadata and build configurations. ```Configuration dependency_links = setuptools.dist:assert_string_list eager_resources = setuptools.dist:assert_string_list entry_points = setuptools.dist:check_entry_points exclude_package_data = setuptools.dist:check_package_data extras_require = setuptools.dist:check_extras include_package_data = setuptools.dist:assert_bool install_requires = setuptools.dist:check_requirements namespace_packages = setuptools.dist:check_nsp package_data = setuptools.dist:check_package_data packages = setuptools.dist:check_packages python_requires = setuptools.dist:check_specifier setup_requires = setuptools.dist:check_requirements test_loader = setuptools.dist:check_importable test_runner = setuptools.dist:check_importable test_suite = setuptools.dist:check_test_suite tests_require = setuptools.dist:check_requirements use_2to3 = setuptools.dist:invalid_unless_false zip_safe = setuptools.dist:assert_bool ``` -------------------------------- ### Starting AISY Framework Web Application Source: https://github.com/aisylab/aisy_docs/blob/master/site/index.html This snippet provides the shell commands required to navigate into the AISY Framework directory and launch the Flask-based web application, which is used to visualize project results and interact with the framework's GUI. ```Shell cd AISY_Framework/ flask run ``` -------------------------------- ### Full Script Example for Aisy Analysis and Custom Table Insertion in Python Source: https://github.com/aisylab/aisy_docs/blob/master/docs/custom_database_table.md This complete script combines the Aisy analysis setup with custom table creation and data insertion. It initializes the Aisy object, configures analysis parameters, runs the analysis, then initializes the custom table schema and session, and finally inserts a new record into the `CustomTable`, linking it to the analysis's ID. This demonstrates the end-to-end process. ```python import aisy_sca from app import * from custom.custom_models.neural_networks import * from custom.custom_tables.tables import * aisy = aisy_sca.Aisy() aisy.set_resources_root_folder(resources_root_folder) aisy.set_database_root_folder(databases_root_folder) aisy.set_datasets_root_folder(datasets_root_folder) aisy.set_database_name("database_ascad.sqlite") aisy.set_dataset(datasets_dict["ascad-variable.h5"]) aisy.set_aes_leakage_model(leakage_model="HW", byte=2) aisy.set_batch_size(400) aisy.set_epochs(20) aisy.set_neural_network(mlp) aisy.run() start_custom_tables(databases_root_folder + "database_ascad.sqlite") session = start_custom_tables_session(databases_root_folder + "database_ascad.sqlite") new_insert = CustomTable(value1=10, value2=20, value3=30, analysis_id=aisy.get_analysis_id()) session.add(new_insert) session.commit() ``` -------------------------------- ### Initializing Syntax Highlighting - JavaScript Source: https://github.com/aisylab/aisy_docs/blob/master/site/search.html This JavaScript snippet initializes the `highlight.js` library to automatically highlight code blocks on page load, improving readability of code examples within the documentation. ```JavaScript hljs.initHighlightingOnLoad(); ``` -------------------------------- ### Example Structure of the `settings` Dictionary in Python Source: https://github.com/aisylab/aisy_docs/blob/master/site/custom_metrics/index.html This snippet illustrates the typical structure and common parameters found within the `settings` dictionary. It provides configuration details for key rank attacks, leakage models, dataset paths, trace counts, and model-specific hyperparameters, guiding users on how to configure their analysis. ```Python settings = { "key_rank_attack_traces": 1000, "key_rank_report_interval": 1, "key_rank_executions": 100, "leakage_model": { "leakage_model": "HW", "bit": 0, "byte": 0, "round": 1, "round_first": 1, # for Hamming Distance "round_second": 1, # for Hamming Distance "cipher": "AES128", "target_state": "Sbox", "target_state_first": "Sbox", # for Hamming Distance "target_state_second": "Sbox", # for Hamming Distance "direction": "Encryption", "attack_direction": "input" }, "datasets_root_folder": "", "database_root_folder": "", "resources_root_folder": "", "database_name": "", "filename": "", "first_sample": 0, "number_of_samples": 700, "number_of_profiling_traces": 50000, "number_of_attack_traces": 10000, "key": "00112233445566778899AABBCCDDEEFF", "good_key": 22, "batch_size": 400, "epochs": 100, "classes": 256, "models": { "0": { "model_name": "my_model", "method_name": "mlp_best", "seed": 123456, "model": null, "index": 0 } }, ... } ``` -------------------------------- ### Downloading Open-source AES Datasets (Linux) Source: https://github.com/aisylab/aisy_docs/blob/master/site/datasets/index.html This snippet provides `wget` commands for Linux users to download various open-source AES side-channel analysis datasets, including ASCAD fixed key, ASCAD variable key, AES_HD, and AES_HD_ext. These commands download the datasets as `.zip` or `.h5` files to the current directory. Users need `wget` installed on their system. ```Shell wget https://www.data.gouv.fr/s/resources/ascad/20180530-163000/ASCAD_data.zip wget https://static.data.gouv.fr/resources/ascad-atmega-8515-variable-key/20190903-083349/ascad-variable.h5 wget http://aisylabdatasets.ewi.tudelft.nl/aes_hd.h5 wget http://aisylabdatasets.ewi.tudelft.nl/aes_hd_ext.h5 ``` -------------------------------- ### Initializing Syntax Highlighting in JavaScript Source: https://github.com/aisylab/aisy_docs/blob/master/site/404.html This JavaScript snippet initializes the Highlight.js library, which automatically detects and highlights code blocks on the page when the document is loaded. It ensures that code examples are presented with proper syntax coloring for improved readability. ```JavaScript hljs.initHighlightingOnLoad(); ``` -------------------------------- ### Initializing Syntax Highlighting - JavaScript Source: https://github.com/aisylab/aisy_docs/blob/master/site/custom_loss/index.html This JavaScript snippet initializes the Highlight.js library, which automatically detects and highlights code syntax on the page when the document is loaded. It's a common practice for displaying code examples in web documentation. ```JavaScript hljs.initHighlightingOnLoad(); ``` -------------------------------- ### Downloading Open-source AES Datasets (Windows) Source: https://github.com/aisylab/aisy_docs/blob/master/site/datasets/index.html This snippet provides `curl.exe` commands for Windows 10 users to download various open-source AES side-channel analysis datasets, including ASCAD fixed key, ASCAD variable key, AES_HD, and AES_HD_ext. These commands save the datasets as `.zip` or `.h5` files to the current directory. Users need `curl.exe` installed and accessible in their system's PATH. ```Shell curl.exe -o ASCAD_data.zip https://www.data.gouv.fr/s/resources/ascad/20180530-163000/ASCAD_data.zip curl.exe -o ascad-variable.h5 https://static.data.gouv.fr/resources/ascad-atmega-8515-variable-key/20190903-083349/ascad-variable.h5 curl.exe -o ches_ctf.h5 http://aisylabdatasets.ewi.tudelft.nl/aes_hd.h5 curl.exe -o ches_ctf.h5 http://aisylabdatasets.ewi.tudelft.nl/aes_hd_ext.h5 ``` -------------------------------- ### Calling a Pre-defined MLP Model in AISY Framework (Python) Source: https://github.com/aisylab/aisy_docs/blob/master/docs/neuralnetworks.md This example demonstrates how to initialize the AISY Framework and set a pre-defined neural network model (e.g., `mlp`) for execution. The `aisy.set_neural_network()` method automatically handles the `classes` and `number_of_samples` parameters based on the dataset and leakage model settings, simplifying model integration. ```Python import aisy_sca from app import * from custom.custom_models.neural_networks import * aisy = aisy_sca.Aisy() aisy.set_resources_root_folder(resources_root_folder) aisy.set_database_root_folder(databases_root_folder) aisy.set_datasets_root_folder(datasets_root_folder) aisy.set_database_name("database_ascad.sqlite") aisy.set_dataset(datasets_dict["ascad-variable.h5"]) aisy.set_aes_leakage_model(leakage_model="HW", byte=2) aisy.set_batch_size(400) aisy.set_epochs(20) aisy.set_neural_network(mlp) aisy.run() ``` -------------------------------- ### Starting Custom Table Session (Python) Source: https://github.com/aisylab/aisy_docs/blob/master/site/custom_database_table/index.html This code initializes and establishes a session for interacting with custom tables in the specified SQLite database. It first ensures the tables are set up and then creates a session object for subsequent database operations. ```Python start_custom_tables(databases_root_folder + "database_ascad.sqlite") session = start_custom_tables_session(databases_root_folder + "database_ascad.sqlite") ``` -------------------------------- ### Starting Custom Table Session in Python Source: https://github.com/aisylab/aisy_docs/blob/master/docs/custom_database_table.md This snippet initializes the custom tables and establishes a database session for them. It first calls `start_custom_tables` to ensure the table schema exists in the specified SQLite database, then uses `start_custom_tables_session` to create and return a SQLAlchemy session object, which is necessary for performing database operations like insertions. ```python start_custom_tables(databases_root_folder + "database_ascad.sqlite") session = start_custom_tables_session(databases_root_folder + "database_ascad.sqlite") ``` -------------------------------- ### Defining Pip Console Scripts in Python Source: https://github.com/aisylab/aisy_docs/blob/master/venv/Lib/site-packages/pip-21.3.1.dist-info/entry_points.txt This snippet configures console script entry points for different versions of the pip command (pip, pip3, pip3.9). Each entry point maps a command-line alias to the `main` function within `pip._internal.cli.main`, allowing these commands to be executed directly from the terminal after installation. ```Python pip = pip._internal.cli.main:main pip3 = pip._internal.cli.main:main pip3.9 = pip._internal.cli.main:main ``` -------------------------------- ### Setting Database Location and Name in Script (Python) Source: https://github.com/aisylab/aisy_docs/blob/master/docs/databases.md This example illustrates how to programmatically set the database root folder and the specific SQLite database file name directly within a Python script using the AISY framework's API. This provides flexibility for dynamic database path and name configuration during runtime. ```Python aisy = aisy_sca.Aisy() aisy.set_database_root_folder("my_location/") aisy.set_database_name("my_database.sqlite") ``` -------------------------------- ### Initializing CNN Grid Search Parameters in AISY Framework (Python) Source: https://github.com/aisylab/aisy_docs/blob/master/docs/hyperparamatersearch.md This Python snippet initializes the AISY Framework for a Convolutional Neural Network (CNN) hyperparameter search. It sets up root folders for resources, databases, and datasets, specifies the database and dataset files, defines the AES leakage model, and configures batch size and epochs. This forms the initial setup for a CNN grid search. ```python import aisy_sca from app import * aisy = aisy_sca.Aisy() aisy.set_resources_root_folder(resources_root_folder) aisy.set_database_root_folder(databases_root_folder) aisy.set_datasets_root_folder(datasets_root_folder) aisy.set_database_name("database_ascad.sqlite") aisy.set_dataset(datasets_dict["ascad-variable.h5"]) aisy.set_aes_leakage_model(leakage_model="HW", byte=2) aisy.set_batch_size(400) aisy.set_epochs(20) ``` -------------------------------- ### Example Structure of AisyLab Settings Dictionary in Python Source: https://github.com/aisylab/aisy_docs/blob/master/site/custom_callbacks/index.html This Python dictionary defines the structure and typical parameters found within the `settings` object passed to AisyLab callbacks. It includes configuration for key rank attacks, leakage models (e.g., 'HW' for Hamming Weight), dataset paths, trace counts, cryptographic details like key and cipher, and model configurations. This object is crucial for controlling the analysis and training process. ```Python settings = { "key_rank_attack_traces": 1000, "key_rank_report_interval": 1, "key_rank_executions": 100, "leakage_model": { "leakage_model": "HW", "bit": 0, "byte": 0, "round": 1, "round_first": 1, # for Hamming Distance "round_second": 1, # for Hamming Distance "cipher": "AES128", "target_state": "Sbox", "target_state_first": "Sbox", # for Hamming Distance "target_state_second": "Sbox", # for Hamming Distance "direction": "Encryption", "attack_direction": "input" }, "datasets_root_folder": "", "database_root_folder": "", "resources_root_folder": "", "database_name": "", "filename": "", "first_sample": 0, "number_of_samples": 700, "number_of_profiling_traces": 50000, "number_of_attack_traces": 10000, "key": "00112233445566778899AABBCCDDEEFF", "good_key": 22, "batch_size": 400, "epochs": 100, "classes": 256, "models": { "0": { "model_name": "my_model", "method_name": "mlp_best", "seed": 123456, "model": null, "index": 0 } }, ... } ``` -------------------------------- ### Example `settings` Dictionary Structure (Python) Source: https://github.com/aisylab/aisy_docs/blob/master/docs/custom_metrics.md This Python dictionary illustrates the structure of the `settings` object passed to custom metric functions. It contains various configuration parameters for the analysis, including key rank settings, leakage model details, dataset paths, training parameters like batch size and epochs, and model configurations. ```Python settings = { "key_rank_attack_traces": 1000, "key_rank_report_interval": 1, "key_rank_executions": 100, "leakage_model": { "leakage_model": "HW", "bit": 0, "byte": 0, "round": 1, "round_first": 1, "round_second": 1, "cipher": "AES128", "target_state": "Sbox", "target_state_first": "Sbox", "target_state_second": "Sbox", "direction": "Encryption", "attack_direction": "input" }, "datasets_root_folder": "", "database_root_folder": "", "resources_root_folder": "", "database_name": "", "filename": "", "first_sample": 0, "number_of_samples": 700, "number_of_profiling_traces": 50000, "number_of_attack_traces": 10000, "key": "00112233445566778899AABBCCDDEEFF", "good_key": 22, "batch_size": 400, "epochs": 100, "classes": 256, "models": { "0": { "model_name": "my_model", "method_name": "mlp_best", "seed": 123456, "model": null, "index": 0 } } } ``` -------------------------------- ### Calculating Guessing Entropy Metric in Python Source: https://github.com/aisylab/aisy_docs/blob/master/docs/custom_metrics.md This Python snippet provides a comprehensive example for calculating guessing entropy. The `run` method processes validation traces to compute labels for key hypotheses, predicts output probabilities, and performs key ranking to determine the guessing entropy. It requires `numpy` and `aisy_sca.crypto.sca_aes_create_intermediates`. ```Python from aisy_sca.crypto.sca_aes_create_intermediates import * def run(dataset, settings, model, *args): nt = len(dataset.x_validation) # ---------------------------------------------------------------------------------------------------------# # compute labels for key hypothesis # ---------------------------------------------------------------------------------------------------------# labels_key_hypothesis = np.zeros((256, nt)) for key_byte_hypothesis in range(0, 256): key_h = bytearray.fromhex(settings["key"]) key_h[settings["leakage_model"]["byte"]] = key_byte_hypothesis labels_key_hypothesis[key_byte_hypothesis][:] = aes_intermediates(dataset.plaintext_validation, dataset.ciphertext_validation, key_h, settings["leakage_model"]) good_key = [int(x) for x in bytearray.fromhex(settings["key"])][settings["leakage_model"]["byte"]] # ---------------------------------------------------------------------------------------------------------# # predict output probabilities for shuffled test or validation set # ---------------------------------------------------------------------------------------------------------# output_probabilities = model.predict(dataset.x_validation) probabilities_kg_all_traces = np.zeros((nt, 256)) for index in range(nt): probabilities_kg_all_traces[index] = output_probabilities[index][ np.asarray([int(leakage[index]) for leakage in labels_key_hypothesis[:]]) # array with 256 leakage values (1 per key guess) ] key_ranking_sum = 0 for key_rank_execution in range(settings["key_rank_executions"]): r = np.random.choice(range(nt), settings["key_rank_attack_traces"], replace=False) probabilities_kg_all_traces_shuffled = probabilities_kg_all_traces[r] key_probabilities = np.sum(probabilities_kg_all_traces_shuffled[:settings["key_rank_attack_traces"]], axis=0) key_probabilities_sorted = np.argsort(key_probabilities)[::-1] key_ranking_sum += list(key_probabilities_sorted).index(good_key) + 1 guessing_entropy = key_ranking_sum / settings["key_rank_executions"] print(f"GE = {guessing_entropy}") return guessing_entropy ``` -------------------------------- ### Defining Egg-Info Writers for Setuptools Source: https://github.com/aisylab/aisy_docs/blob/master/venv/Lib/site-packages/setuptools-59.6.0.dist-info/entry_points.txt This section specifies the functions responsible for writing various metadata files into the `.egg-info` directory during the `egg_info` command execution. Each entry maps a specific filename (e.g., `PKG-INFO`, `entry_points.txt`) to its corresponding writer function within setuptools. ```Configuration PKG-INFO = setuptools.command.egg_info:write_pkg_info dependency_links.txt = setuptools.command.egg_info:overwrite_arg depends.txt = setuptools.command.egg_info:warn_depends_obsolete eager_resources.txt = setuptools.command.egg_info:overwrite_arg entry_points.txt = setuptools.command.egg_info:write_entries namespace_packages.txt = setuptools.command.egg_info:overwrite_arg requires.txt = setuptools.command.egg_info:write_requirements top_level.txt = setuptools.command.egg_info:write_toplevel_names ``` -------------------------------- ### Defining Distutils Commands for Setuptools Source: https://github.com/aisylab/aisy_docs/blob/master/venv/Lib/site-packages/setuptools-59.6.0.dist-info/entry_points.txt This section maps standard distutils commands to their corresponding setuptools implementations, allowing setuptools to extend or override default build and distribution processes. Each entry associates a command name with its specific setuptools handler. ```Configuration alias = setuptools.command.alias:alias bdist_egg = setuptools.command.bdist_egg:bdist_egg bdist_rpm = setuptools.command.bdist_rpm:bdist_rpm build_clib = setuptools.command.build_clib:build_clib build_ext = setuptools.command.build_ext:build_ext build_py = setuptools.command.build_py:build_py develop = setuptools.command.develop:develop dist_info = setuptools.command.dist_info:dist_info easy_install = setuptools.command.easy_install:easy_install egg_info = setuptools.command.egg_info:egg_info install = setuptools.command.install:install install_egg_info = setuptools.command.install_egg_info:install_egg_info install_lib = setuptools.command.install_lib:install_lib install_scripts = setuptools.command.install_scripts:install_scripts rotate = setuptools.command.rotate:rotate saveopts = setuptools.command.saveopts:saveopts sdist = setuptools.command.sdist:sdist setopt = setuptools.command.setopt:setopt test = setuptools.command.test:test upload_docs = setuptools.command.upload_docs:upload_docs ``` -------------------------------- ### Running AISY Framework Analysis Script Source: https://github.com/aisylab/aisy_docs/blob/master/site/index.html This Python code demonstrates how to set up and execute an AISY Framework analysis script. It includes configuring system paths, initializing the Aisy object, setting resource and dataset folders, defining the database, dataset, leakage model, batch size, epochs, and the neural network before running the analysis. ```Python import sys sys.path.append('my_path/AISY_framework') import aisy_sca from app import * from custom.custom_models.neural_networks import * aisy = aisy_sca.Aisy() aisy.set_resources_root_folder(resources_root_folder) aisy.set_database_root_folder(databases_root_folder) aisy.set_datasets_root_folder(datasets_root_folder) aisy.set_database_name("database_ascad.sqlite") aisy.set_dataset(datasets_dict["ascad-variable.h5"]) aisy.set_aes_leakage_model(leakage_model="HW", byte=2) aisy.set_batch_size(400) aisy.set_epochs(20) aisy.set_neural_network(mlp) aisy.run() ``` -------------------------------- ### Configuring and Running Input Gradient Visualization with AISY Framework (Python) Source: https://github.com/aisylab/aisy_docs/blob/master/site/visualization/index.html This Python snippet demonstrates how to initialize the AISY Framework, configure its resources, database, dataset, leakage model, batch size, epochs, and neural network, and then run the input gradient visualization feature. The `visualization` parameter in `aisy.run()` specifies the number of profiling traces to use for computation. ```Python import aisy_sca from app import * from custom.custom_models.neural_networks import * aisy = aisy_sca.Aisy() aisy.set_resources_root_folder(resources_root_folder) aisy.set_database_root_folder(databases_root_folder) aisy.set_datasets_root_folder(datasets_root_folder) aisy.set_database_name("database_ascad.sqlite") aisy.set_dataset(datasets_dict["ascad-variable.h5"]) aisy.set_aes_leakage_model(leakage_model="HW", byte=2) aisy.set_batch_size(400) aisy.set_epochs(20) aisy.set_neural_network(mlp) aisy.run(visualization=[4000]) ``` -------------------------------- ### Initializing SphinxRtdTheme Navigation (JavaScript) Source: https://github.com/aisylab/aisy_docs/blob/master/site/errors/index.html This JavaScript snippet initializes the base URL for the documentation and enables the Sphinx Read the Docs theme navigation functionality once the web page has fully loaded. It ensures that interactive navigation features are available to the user. ```JavaScript var base_url = '..'; window.onload = function () { SphinxRtdTheme.Navigation.enable(true); }; ``` -------------------------------- ### Configuring Identity Leakage Model for AES S-Box Output (Round 1) Source: https://github.com/aisylab/aisy_docs/blob/master/docs/leakage_models.md This example shows how to configure the AISY framework to use an Identity (ID) leakage model. It focuses on the S-Box output of byte 0 in the first round during AES encryption for a 128-bit AES cipher. ```python aisy = aisy_sca.Aisy() aisy.set_aes_leakage_model(leakage_model="ID", byte=0, target_state="Sbox", direction="Encryption", cipher="AES128") ``` -------------------------------- ### Initializing SphinxRtdTheme Navigation in JavaScript Source: https://github.com/aisylab/aisy_docs/blob/master/site/databases/index.html This JavaScript snippet initializes the navigation functionality provided by the Sphinx Read the Docs theme when the window has finished loading. It sets a base URL and then enables the theme's navigation, ensuring the UI is interactive upon page load. ```JavaScript var base_url = '..'; window.onload = function () { SphinxRtdTheme.Navigation.enable(true); }; ``` -------------------------------- ### Configuring Bit-Level Leakage Model for AES S-Box Output (Round 1) Source: https://github.com/aisylab/aisy_docs/blob/master/docs/leakage_models.md This snippet provides an example of setting a bit-level leakage model in AISY. It specifically targets bit 3 of byte 5 in the S-Box output of the first round during AES encryption for a 128-bit AES cipher. ```python aisy = aisy_sca.Aisy() aisy.set_aes_leakage_model(leakage_model="bit", bit=3, byte=5, target_state="Sbox", direction="Encryption", cipher="AES128") ``` -------------------------------- ### Configuring HW Leakage Model for AES S-Box Output (Round 1) Source: https://github.com/aisylab/aisy_docs/blob/master/docs/leakage_models.md This example demonstrates how to configure the AISY framework to use a Hamming Weight (HW) leakage model. It targets the S-Box output of byte 0 in the first round during AES encryption for a 128-bit AES cipher. ```python aisy = aisy_sca.Aisy() aisy.set_aes_leakage_model(leakage_model="HW", byte=0, target_state="Sbox", direction="Encryption", cipher="AES128") ``` -------------------------------- ### Running Profiling Analysis with AISY Framework - Python Source: https://github.com/aisylab/aisy_docs/blob/master/site/profiling_analyzer/index.html This snippet demonstrates how to initialize the AISY framework and configure it to run a profiling analysis. It sets up resource paths, specifies the database and dataset, defines the AES leakage model, and configures training parameters like batch size, epochs, and the neural network model. The profiling analyzer is then invoked with a list of 'steps', indicating the varying amounts of profiling traces for which the model will be trained and evaluated. ```Python import aisy_sca from app import * from custom.custom_models.neural_networks import * aisy = aisy_sca.Aisy() aisy.set_resources_root_folder(resources_root_folder) aisy.set_database_root_folder(databases_root_folder) aisy.set_datasets_root_folder(datasets_root_folder) aisy.set_database_name("database_ascad.sqlite") aisy.set_dataset(datasets_dict["ascad-variable.h5"]) aisy.set_aes_leakage_model(leakage_model="HW", byte=2) aisy.set_batch_size(400) aisy.set_epochs(20) aisy.set_neural_network(mlp) aisy.run( profiling_analyzer= { "steps": [1000, 5000, 10000, 25000, 50000] } ) ``` -------------------------------- ### Executing Hyperparameter Grid Search with aisy.run Source: https://github.com/aisylab/aisy_docs/blob/master/site/hyperparamatersearch/index.html This Python code snippet demonstrates how to initiate a hyperparameter grid search using the `aisy.run` function. It takes a `grid_search` dictionary, which defines the neural network type and hyperparameters to explore, and `key_rank_attack_traces` as parameters. The `grid_search` dictionary is expected to be configured as described in the surrounding documentation. ```python aisy.run( grid_search=grid_search, key_rank_attack_traces=500 ) ``` -------------------------------- ### Configuring HD Leakage Model between AES S-Box Input and Output Source: https://github.com/aisylab/aisy_docs/blob/master/docs/leakage_models.md This example demonstrates configuring a Hamming Distance (HD) leakage model in AISY. It calculates the distance between the S-Box input and the final ciphertext output for byte 0 in round 10 of AES encryption, with an output attack direction for a 128-bit AES cipher. ```python aisy = AisyAes() aisy.set_aes_leakage_model(leakage_model="HD", byte=0, direction="Encryption", cipher="AES128", target_state_first="Output", round_first=10, target_state_second="Sbox", round_second=10, attack_direction="output") ``` -------------------------------- ### Initializing Aisy and Running Analysis (Python) Source: https://github.com/aisylab/aisy_docs/blob/master/site/custom_database_table/index.html This snippet demonstrates how to initialize the `aisy_sca.Aisy` object, configure its resource paths, database, dataset, and analysis parameters (like leakage model, batch size, epochs, and neural network). It then executes the analysis using `aisy.run()`. ```Python import aisy_sca from app import * from custom.custom_models.neural_networks import * from custom.custom_tables.tables import * aisy = aisy_sca.Aisy() aisy.set_resources_root_folder(resources_root_folder) aisy.set_database_root_folder(databases_root_folder) aisy.set_datasets_root_folder(datasets_root_folder) aisy.set_database_name("database_ascad.sqlite") aisy.set_dataset(datasets_dict["ascad-variable.h5"]) aisy.set_aes_leakage_model(leakage_model="HW", byte=2) aisy.set_batch_size(400) aisy.set_epochs(20) aisy.set_neural_network(mlp) aisy.run() ``` -------------------------------- ### Downloading Open-Source AES Datasets using Wget (Linux) Source: https://github.com/aisylab/aisy_docs/blob/master/docs/datasets.md This snippet provides commands for Linux users to download various open-source AES side-channel analysis datasets, including ASCAD fixed key, ASCAD variable key, AES_HD, and AES_HD_ext, using the `wget` utility. These datasets are crucial for side-channel analysis research and are compatible with the AISY Framework. ```Shell wget https://www.data.gouv.fr/s/resources/ascad/20180530-163000/ASCAD_data.zip wget https://static.data.gouv.fr/resources/ascad-atmega-8515-variable-key/20190903-083349/ascad-variable.h5 wget http://aisylabdatasets.ewi.tudelft.nl/aes_hd.h5 wget http://aisylabdatasets.ewi.tudelft.nl/aes_hd_ext.h5 ``` -------------------------------- ### Enabling Sphinx Read the Docs Theme Navigation - JavaScript Source: https://github.com/aisylab/aisy_docs/blob/master/site/search.html This JavaScript code sets the base URL for the documentation and enables the navigation functionality provided by the Sphinx Read the Docs theme once the entire page has loaded. This ensures the sidebar navigation is interactive. ```JavaScript var base_url = '.'; window.onload = function () { SphinxRtdTheme.Navigation.enable(true); }; ``` -------------------------------- ### Complete Custom Database Table Definition File - Python Source: https://github.com/aisylab/aisy_docs/blob/master/site/custom_database_table/index.html This snippet provides the complete `tables.py` file, demonstrating how to define custom database tables within the AISY Framework. It includes necessary SQLAlchemy imports, a declarative base, functions to initialize the database (`start_custom_tables`) and create a session (`start_custom_tables_session`), and the `CustomTable` class definition. This file is crucial for setting up custom data structures. ```Python import datetime from sqlalchemy import * from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import relationship from aisy.sca_tables import Analysis from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker Base = declarative_base() def base(): return Base def start_custom_tables(database_name): engine = create_engine('sqlite:///{}'.format(database_name), echo=False) base().metadata.create_all(engine) def start_custom_tables_session(database_name): engine = create_engine('sqlite:///{}'.format(database_name), echo=False) return sessionmaker(bind=engine)() class CustomTable(Base): __tablename__ = 'custom_table' id = Column(Integer, primary_key=True) value1 = Column(Integer) value2 = Column(Integer) value3 = Column(Integer) datetime = Column(DateTime, default=datetime.datetime.utcnow) analysis_id = Column(Integer, ForeignKey(Analysis.id)) analysis = relationship(Analysis) def __repr__(self): return "" % self.id ``` -------------------------------- ### Example Keras Training Settings Dictionary in Python Source: https://github.com/aisylab/aisy_docs/blob/master/docs/custom_callbacks.md This Python dictionary defines various configuration settings for a Keras training process, particularly for side-channel analysis. It includes parameters for key rank attacks, leakage model specifications (e.g., `HW`, `AES128`, `Sbox`), dataset paths, trace counts, batch size, epochs, and model configurations. This `settings` dictionary is typically passed to custom callbacks to provide context for their operations. ```python settings = { "key_rank_attack_traces": 1000, "key_rank_report_interval": 1, "key_rank_executions": 100, "leakage_model": { "leakage_model": "HW", "bit": 0, "byte": 0, "round": 1, "round_first": 1, # for Hamming Distance "round_second": 1, # for Hamming Distance "cipher": "AES128", "target_state": "Sbox", "target_state_first": "Sbox", # for Hamming Distance "target_state_second": "Sbox", # for Hamming Distance "direction": "Encryption", "attack_direction": "input" }, "datasets_root_folder": "", "database_root_folder": "", "resources_root_folder": "", "database_name": "", "filename": "", "first_sample": 0, "number_of_samples": 700, "number_of_profiling_traces": 50000, "number_of_attack_traces": 10000, "key": "00112233445566778899AABBCCDDEEFF", "good_key": 22, "batch_size": 400, "epochs": 100, "classes": 256, "models": { "0": { "model_name": "my_model", "method_name": "mlp_best", "seed": 123456, "model": null, "index": 0 } }, ... } ``` -------------------------------- ### Running Input Gradient Visualization with AISY Framework (Python) Source: https://github.com/aisylab/aisy_docs/blob/master/docs/visualization.md This snippet demonstrates how to configure and run the input gradient visualization feature using the AISY Framework. It sets up the framework with specific resource paths, database, dataset, AES leakage model, batch size, epochs, and a neural network, then executes the visualization for a specified number of profiling traces. ```python import aisy_sca from app import * from custom.custom_models.neural_networks import * aisy = aisy_sca.Aisy() aisy.set_resources_root_folder(resources_root_folder) aisy.set_database_root_folder(databases_root_folder) aisy.set_datasets_root_folder(datasets_root_folder) aisy.set_database_name("database_ascad.sqlite") aisy.set_dataset(datasets_dict["ascad-variable.h5"]) aisy.set_aes_leakage_model(leakage_model="HW", byte=2) aisy.set_batch_size(400) aisy.set_epochs(20) aisy.set_neural_network(mlp) aisy.run(visualization=[4000]) ``` -------------------------------- ### Initializing Sphinx Read the Docs Theme Navigation Source: https://github.com/aisylab/aisy_docs/blob/master/site/index.html This JavaScript snippet, typically found in documentation generated by tools like MkDocs with Sphinx themes, initializes the navigation functionality provided by the Sphinx Read the Docs Theme upon the page loading. It ensures interactive navigation elements are enabled. ```JavaScript var base_url = '.'; window.onload = function () { SphinxRtdTheme.Navigation.enable(true); }; ``` -------------------------------- ### Calling Early Stopping Custom Metrics in Aisy-SCA Python Source: https://github.com/aisylab/aisy_docs/blob/master/docs/custom_metrics.md This Python example demonstrates how to configure and run an Aisy-SCA experiment using custom metrics for early stopping. It initializes Aisy, sets various parameters like dataset, leakage model, batch size, and neural network, then defines multiple custom metrics (accuracy, loss, number of traces, success rate) with their directions for early stopping. Finally, it executes the Aisy run and retrieves the validation metrics. ```Python import aisy_sca from app import * from custom.custom_models.neural_networks import * aisy = aisy_sca.Aisy() aisy.set_resources_root_folder(resources_root_folder) aisy.set_database_root_folder(databases_root_folder) aisy.set_datasets_root_folder(datasets_root_folder) aisy.set_database_name("database_ascad.sqlite") aisy.set_dataset(datasets_dict["ascad-variable.h5"]) aisy.set_aes_leakage_model(leakage_model="HW", byte=2) aisy.set_batch_size(400) aisy.set_epochs(10) aisy.set_neural_network(mlp) early_stopping = { "metrics": { "accuracy": { "direction": "max", "class": "custom.custom_metrics.accuracy", "parameters": [] }, "loss": { "direction": "min", "class": "custom.custom_metrics.loss", "parameters": [] }, "number_of_traces": { "direction": "min", "class": "custom.custom_metrics.number_of_traces", "parameters": [] }, "success_rate": { "direction": "max", "class": "custom.custom_metrics.success_rate", "parameters": [] } } } aisy.run( early_stopping=early_stopping, key_rank_attack_traces=500 ) metrics_validation = aisy.get_metrics_validation() for metric in metrics_validation: print("{}: {}".format(metric['metric'], metric['values'])) ``` -------------------------------- ### Generating Custom Dataset Object for AISY SCA (Python) Source: https://github.com/aisylab/aisy_docs/blob/master/site/custom_dataset/index.html This comprehensive example demonstrates how to manually create and configure a `Dataset` object for the AISY framework, bypassing its automatic label generation. It initializes profiling, validation, and attack traces and labels using NumPy and Keras utilities, then constructs a `Dataset` instance. Finally, it integrates this custom dataset into the `aisy_sca.Aisy` class, setting various parameters like batch size, epochs, and neural network models before running the analysis. This approach allows users to define custom labels, such as those based on masks, for non-AES datasets. ```Python import aisy_sca from app import * from custom.custom_models.neural_networks import * from aisy_sca.datasets.Dataset import Dataset from tensorflow.keras.utils import to_categorical import numpy as np """ set profiling, validation and attack traces""" x_profiling = np.random.rand(10000, 100) x_attack = np.random.rand(1000, 100) x_validation = np.random.rand(1000, 100) """ set profiling, validation and attack labels""" y_profiling = to_categorical(np.random.randint(0, 256, 10000), num_classes=256) y_attack = to_categorical(np.random.randint(0, 256, 1000), num_classes=256) y_validation = to_categorical(np.random.randint(0, 256, 1000), num_classes=256) """ create list of key guesses for attack and validation sets """ labels_key_guess_validation_set = np.random.randint(0, 256, (256, 1000)) labels_key_guess_attack_set = np.random.randint(0, 256, (256, 1000)) """ create dataset object """ new_dataset = Dataset(x_profiling, y_profiling, x_attack, y_attack, x_validation, y_validation) new_dataset_dict = { "filename": "new_dataset.h5", "key": "4DFBE0F27221FE10A78D4ADC8E490469", "first_sample": 0, "number_of_samples": 100, "number_of_profiling_traces": 10000, "number_of_attack_traces": 1000 } aisy = aisy_sca.Aisy() aisy.set_resources_root_folder(resources_root_folder) aisy.set_database_root_folder(databases_root_folder) aisy.set_datasets_root_folder(datasets_root_folder) aisy.set_database_name("database_ascad_variable.sqlite") """ User must set dataset object and value of good key for GE and SR """ aisy.set_classes(256) aisy.set_good_key(224) aisy.set_dataset(new_dataset_dict, dataset=new_dataset) aisy.set_labels_key_guesses_attack_set(labels_key_guess_attack_set) aisy.set_labels_key_guesses_validation_set(labels_key_guess_validation_set) aisy.set_batch_size(400) aisy.set_epochs(10) aisy.add_neural_network(mlp) aisy.run() ``` -------------------------------- ### Initializing Aisy Object and Running Analysis in Python Source: https://github.com/aisylab/aisy_docs/blob/master/docs/custom_database_table.md This snippet demonstrates the initialization of the `Aisy` object and configuration of its settings for an analysis. It sets various root folders, the database name, the dataset, AES leakage model, batch size, epochs, and the neural network. Finally, it calls `aisy.run()` to execute the analysis, which is a prerequisite for inserting data into custom tables linked to an analysis ID. ```python import aisy_sca from app import * from custom.custom_models.neural_networks import * from custom.custom_tables.tables import * aisy = aisy_sca.Aisy() aisy.set_resources_root_folder(resources_root_folder) aisy.set_database_root_folder(databases_root_folder) aisy.set_datasets_root_folder(datasets_root_folder) aisy.set_database_name("database_ascad.sqlite") aisy.set_dataset(datasets_dict["ascad-variable.h5"]) aisy.set_aes_leakage_model(leakage_model="HW", byte=2) aisy.set_batch_size(400) aisy.set_epochs(20) aisy.set_neural_network(mlp) aisy.run() ``` -------------------------------- ### Configuring AISY Framework for Random Search - Python Source: https://github.com/aisylab/aisy_docs/blob/master/docs/hyperparamatersearch.md This snippet initializes the AISY Framework and configures various essential parameters for a side-channel analysis experiment. It sets paths for resources, databases, and datasets, specifies the database and dataset files, defines the AES leakage model, and sets training parameters like batch size and epochs. These configurations are crucial prerequisites for running hyperparameter random search. ```python import aisy_sca from app import * aisy = aisy_sca.Aisy() aisy.set_resources_root_folder(resources_root_folder) aisy.set_database_root_folder(databases_root_folder) aisy.set_datasets_root_folder(datasets_root_folder) aisy.set_database_name("database_ascad.sqlite") aisy.set_dataset(datasets_dict["ascad-variable.h5"]) aisy.set_aes_leakage_model(leakage_model="HW", byte=2) aisy.set_batch_size(400) aisy.set_epochs(10) ``` -------------------------------- ### Enabling Sphinx Read the Docs Navigation in JavaScript Source: https://github.com/aisylab/aisy_docs/blob/master/site/404.html This JavaScript code sets the base URL for the site and enables the navigation functionality provided by the Sphinx Read the Docs theme upon the window's full load. It ensures the sidebar navigation is interactive and functional for users browsing the documentation. ```JavaScript var base_url = '/'; window.onload = function () { SphinxRtdTheme.Navigation.enable(true); }; ``` -------------------------------- ### Running AISY SCA Script with Path Configuration - Python Source: https://github.com/aisylab/aisy_docs/blob/master/docs/index.md This snippet demonstrates how to run an AISY framework script from a subfolder by dynamically adding the project root to the Python path. It initializes the AISY SCA object, configures resource and database paths, sets the dataset and leakage model, and then executes the SCA analysis using a specified neural network. ```Python import sys sys.path.append('my_path/AISY_framework') import aisy_sca from app import * from custom.custom_models.neural_networks import * aisy = aisy_sca.Aisy() aisy.set_resources_root_folder(resources_root_folder) aisy.set_database_root_folder(databases_root_folder) aisy.set_datasets_root_folder(datasets_root_folder) aisy.set_database_name("database_ascad.sqlite") aisy.set_dataset(datasets_dict["ascad-variable.h5"]) aisy.set_aes_leakage_model(leakage_model="HW", byte=2) aisy.set_batch_size(400) aisy.set_epochs(20) aisy.set_neural_network(mlp) aisy.run() ``` -------------------------------- ### Enabling Sphinx Read the Docs Navigation - JavaScript Source: https://github.com/aisylab/aisy_docs/blob/master/site/custom_loss/index.html This JavaScript code sets a base URL and then, upon the window loading, enables the navigation functionality provided by the Sphinx Read the Docs theme. This is crucial for interactive navigation features in documentation generated with MkDocs and Sphinx themes. ```JavaScript var base_url = '..'; window.onload = function () { SphinxRtdTheme.Navigation.enable(true); }; ```