earlgrey/cryptolib: Generate Rust FFI and safe bindings for libotcrypto using bindgen and syn crate - #452
Open
lchiawei wants to merge 3 commits into
Open
earlgrey/cryptolib: Generate Rust FFI and safe bindings for libotcrypto using bindgen and syn crate#452lchiawei wants to merge 3 commits into
lchiawei wants to merge 3 commits into
Conversation
…crypto Add a dedicated host tool to transform OpenTitan libotcrypto C bindings into idiomatic Rust FFI. Key changes in this commit: * Patch rules_rust_bindgen in MODULE.bazel to support static library binding workflows. * Parse raw Rust bindings with syn to inspect AST syntax nodes. * Convert type and enum names to PascalCase and field names to snake_case. * Strip C prefixes from enum variants and type identifiers. * Rewrite raw pointer fields (*mut u32) in key structs to u32 integers for IPC safety. * Generate inline accessor methods to safely retrieve pointer values. * Derive zerocopy traits (IntoBytes, FromBytes, Immutable, KnownLayout) on POD types. * Add Bazel unit tests to verify AST transformations and layout preservation.
Add the earlgrey_cryptolib crate with dynamic Bazel FFI bindings and safe wrappers for Earlgrey. Key changes in this commit: * Link precompiled libotcrypto.a via cc_import. * Generate raw Rust bindings dynamically from @lowrisc_opentitan using rust_bindgen. * Apply otcrypto_bindgen to generate the sanitized otcrypto_sys FFI module. * Implement CryptoStatus and CryptoError types for hardened status code conversion. * Add safe wrappers for initialization (init) and buffer checksum calculation. * Add safe one-shot hashing APIs for SHA-256, SHA-384, and SHA-512. * Configure presubmit license checks for cryptolib source files.
Add integration smoke tests for earlgrey_cryptolib on the Earlgrey target. Key changes in this commit: * Configure system memory mappings for crypto peripherals (HMAC, AES, OTBN, CSRNG, EDN). * Add alert handler and clkmgr peripheral mappings to system.json5. * Enable transactional crypto peripheral clocks in test runtime setup. * Add smoke test cases for otcrypto_init and NIST test vectors for SHA-256, SHA-384, and SHA-512. * Verify empty-string hash vectors and zerocopy key structure transformations. * Define opentitan_test targets for QEMU and FPGA (cw340, hyper310, hyper340).
lchiawei
marked this pull request as ready for review
September 2, 2026 03:14
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR introduces the
earlgrey_cryptolibcrate for OpenTitan Earlgrey:tools/otcrypto_bindgen) usingsynto sanitize bindgen FFI and derivezerocopyfor IPC.libotcrypto.a(SHA-2 hashing, status conversion, buffer checksums).