{"id":26629858,"url":"https://github.com/xorbkpt/encryption-pico-compile","last_synced_at":"2025-07-14T09:05:55.609Z","repository":{"id":282692864,"uuid":"946861394","full_name":"XORBKPT/Encryption-Pico-Compile","owner":"XORBKPT","description":"TuM Institute for Advanced Study, Advanced Computation, Cryptography: Post Doc Bucket: 2","archived":false,"fork":false,"pushed_at":"2025-03-15T18:59:39.000Z","size":47,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-16T11:23:45.095Z","etag":null,"topics":["assembly-language-programming","computer-science","embedded-systems","encryption-decryption"],"latest_commit_sha":null,"homepage":"","language":"Assembly","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/XORBKPT.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-03-11T19:40:53.000Z","updated_at":"2025-03-15T20:16:31.000Z","dependencies_parsed_at":"2025-03-16T11:23:49.299Z","dependency_job_id":"8d8f2368-393e-46d3-ba40-60248247aadc","html_url":"https://github.com/XORBKPT/Encryption-Pico-Compile","commit_stats":null,"previous_names":["xorbkpt/encryption-pico-compile"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/XORBKPT%2FEncryption-Pico-Compile","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/XORBKPT%2FEncryption-Pico-Compile/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/XORBKPT%2FEncryption-Pico-Compile/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/XORBKPT%2FEncryption-Pico-Compile/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/XORBKPT","download_url":"https://codeload.github.com/XORBKPT/Encryption-Pico-Compile/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245276175,"owners_count":20588894,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["assembly-language-programming","computer-science","embedded-systems","encryption-decryption"],"created_at":"2025-03-24T13:15:30.183Z","updated_at":"2025-03-24T13:15:30.758Z","avatar_url":"https://github.com/XORBKPT.png","language":"Assembly","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\n# Pico Message Gadget C++ and Assembler Builds\nThe **Pico Message Gadget** is a message encryption tool for the Raspberry Pi Pico, implemented in both C++ and ARM assembly for students. It utilizes AES-CBC encryption with PKCS7 padding, built with the Pico SDK and mbedTLS library. The C++ version is designed to be accessible for beginners, while the ARM assembly version offers advanced students a dip into low-level programming on ARM Cortex-M0+ processors.\n## Features\n- Encrypts user-input messages using a 128-bit AES key and initialization vector (IV).\n- Displays ciphertext in a formatted, readable hex layout.\n- Includes input validation and error handling.\n- Demonstrates both high-level (C++) and low-level (ARM assembly) programming techniques.\n## Prerequisites\n- **Raspberry Pi Pico** with a USB cable.\n- **Pico SDK** installed (refer to [Pico SDK Setup](https://www.raspberrypi.com/documentation/microcontrollers/raspberry-pi-pico.html)).\n- **CMake** and **GNU ARM Toolchain** (e.g., `arm-none-eabi-gcc`).\n- **Git** for cloning the repository.\n## Repository Structure\n```\npico_message_gadget/\n├── main.cpp           # C++ implementation\n├── main.S             # ARM assembly implementation\n├── utils.c            # Helper functions (used by both versions)\n├── utils.h            # Header for utils.c\n├── CMakeLists.txt     # Build configuration\n├── pico_sdk_import.cmake  # Pico SDK import script (assumed available)\n├── README.md          # This file\n└── .gitignore         # Ignore build artifacts\n```\n## Setup Instructions\n1. **Clone the Repository**\n   ```bash\n   git clone https://github.com/yourusername/pico_message_gadget.git\n   cd pico_message_gadget\n   ```\n   Replace `yourusername` with your actual GitHub username.\n2. **Set Up Pico SDK**\n   - Ensure the Pico SDK is installed and the `PICO_SDK_PATH` environment variable is set:\n     ```bash\n     export PICO_SDK_PATH=/path/to/pico-sdk\n     ```\n   - Place `pico_sdk_import.cmake` in the project directory (available from the Pico SDK).\n3. **Choose Implementation**\n   - For **C++**: In `CMakeLists.txt`, uncomment `main.cpp` and comment out `main.S`.\n   - For **Assembly**: In `CMakeLists.txt`, uncomment `main.S` and comment out `main.cpp`.\n4. **Build the Project**\n   ```bash\n   mkdir build\n   cd build\n   cmake ..\n   make\n   ```\n   This generates a `pico_message_gadget.uf2` file.\n5. **Flash to Pico**\n   - Hold the **BOOTSEL** button on the Pico and connect it via USB.\n   - Copy the `.uf2` file to the Pico (it mounts as a USB drive).\n   - The Pico will reboot and run the program.\n6. **Run the Program**\n   - Open a terminal (e.g., PuTTY or Minicom) at 115200 baud.\n   - Follow the prompts to input a message, key, and IV.\n## Usage Example\n```\nPico Message Gadget\nEnter characters including spaces: Hello Pico\nEnter 32 capital hex letters (secret key): 0123456789ABCDEF0123456789ABCDEF\nEnter 32 capital hex letters (IV, PKCS7 padding): FEDCBA9876543210FEDCBA9876543210\n1 5E6A8 7F9B2 3C4D1 E5F06 \nKeys will be erased from RAM when the terminal closes.\n```\n## C++ Version Overview\nThe C++ implementation (`main.cpp`) provides a straightforward, high-level approach:\n- Initializes the Pico’s USB stdio for communication.\n- Prompts the user for a message, key, and IV.\n- Validates inputs and performs AES-CBC encryption with PKCS7 padding using mbedTLS.\n- Outputs the ciphertext in a formatted hex layout.\n## Assembly Version Overview\nThe ARM assembly implementation (`main.S`) replicates the C++ functionality at a low-level, tailored for the Raspberry Pi Pico’s ARM Cortex-M0+ processor. Key differences from the C++ version include:\n- **Manual Register Management**: Uses registers (e.g., `r0`-`r5`) instead of variables. Arguments are passed via `r0`, `r1`, etc., and registers are preserved manually as needed.\n- **Stack Handling**: Explicitly sets up and tears down the stack frame with `push` and `pop` instructions.\n- **Function Calls**: Calls C functions (e.g., from Pico SDK or mbedTLS) using `bl`, with arguments loaded into registers per the ARM calling convention.\n- **No Automatic Memory Management**: Pre-allocates memory for variables in the `.bss` section, unlike C++’s automatic stack-allocated locals.\n- **Comments**: Each section is annotated with the corresponding C++ code for educational clarity.\n## Research Objectives\n- Gain insight into the ARM Cortex-M0+ instruction set.\n- Explore low-level memory and register management.\n- Compare high-level abstraction (C++) with machine-level code (assembly).\n## Troubleshooting\n- **Build Errors**: Verify that the Pico SDK and mbedTLS are correctly linked in `CMakeLists.txt`.\n- **No Output**: Check the USB connection and terminal baud rate (115200).\n- **Assembly Issues**: Ensure proper register usage and stack alignment in `main.S`.\n## `.gitignore`\nThe `.gitignore` file excludes build artifacts:\n```\nbuild/\n*.uf2\n*.elf\n*.bin\n*.map\n*.hex\n*.dis\nCMakeCache.txt\nCMakeFiles/\nMakefile\ncmake_install.cmake\n```\n---\n### Instructions for Students ###\n1. **Switch Between Versions**\n   - Edit `CMakeLists.txt` to toggle between `main.cpp` (C++) and `main.S` (assembly).\n   - Rebuild the project after switching files.\n2. **Study the Code**\n   - Compare `main.cpp` and `main.S` side-by-side to understand how C++ constructs map to assembly.\n   - Pay attention to register usage, stack management, and function calls in `main.S`.\n3. **Build and Test**\n   - Follow the setup instructions to build the project.\n   - Test with sample inputs to confirm that encryption outputs match between the C++ and assembly versions.\n---\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxorbkpt%2Fencryption-pico-compile","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxorbkpt%2Fencryption-pico-compile","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxorbkpt%2Fencryption-pico-compile/lists"}