Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
22e9bee
Merged changes from u/vaiz/static2 and user/nnmkhang/static_103.8
nnmkhang Feb 6, 2025
1d3b1f5
regenerate bindings
nnmkhang Feb 6, 2025
1f98ce6
Cargo Fmt
nnmkhang Feb 6, 2025
94fcdba
minor fixes for static linking (#82)
Vaiz Feb 7, 2025
9bbc251
small comments
nnmkhang Feb 10, 2025
0a33546
Adding custom impl for symcrypt random
nnmkhang Feb 10, 2025
fcd36d3
Remove most reliant code for static linking
nnmkhang Feb 10, 2025
d6a38d8
generate new binding for SymCryptInit
nnmkhang Feb 11, 2025
23f576d
Adding default static lib impl for windows
nnmkhang Feb 11, 2025
70dc063
Cargo Fmt and adding some comments
nnmkhang Feb 11, 2025
712b19c
Removing symcryptinit from being exposes to test, updating some docum…
nnmkhang Feb 12, 2025
492d485
Updating bindings to not expose SymCryptInit()
nnmkhang Feb 12, 2025
013c5af
cargo fmt
nnmkhang Feb 12, 2025
3f7521c
Fixing linux build breaks
nnmkhang Feb 12, 2025
1216979
remove comment
nnmkhang Feb 12, 2025
5d79db1
Adding comments, and making minor improvements to the build system
nnmkhang Feb 12, 2025
623a660
Fixing spacing
nnmkhang Feb 12, 2025
fdcc638
cargo fmt
nnmkhang Feb 12, 2025
94808cd
Adding missing flags, updating some comments
nnmkhang Feb 13, 2025
8a0f142
fix linux build breaks
nnmkhang Feb 13, 2025
3f7afcb
removing c11 check
nnmkhang Feb 13, 2025
159bb4c
cargo fmt
nnmkhang Feb 13, 2025
8d5c9a2
Update to new bindings, add regex to conditionally compile init and r…
nnmkhang Feb 13, 2025
036df15
Adding bindings from the github artifacts
nnmkhang Feb 13, 2025
ad228d6
Adding new line for linux builds
nnmkhang Feb 13, 2025
d2e80dd
cargo fmt
nnmkhang Feb 13, 2025
4af7620
Addressing Max's comments, doing some cleanup
nnmkhang Feb 14, 2025
b9a6ced
Adding Sam's comments
nnmkhang Feb 24, 2025
cc28881
Cargo fmt + cargo clippy
nnmkhang Feb 24, 2025
099516f
User/nnmkhang/update workflows (#86)
nnmkhang Feb 25, 2025
48f4683
newline
nnmkhang Feb 25, 2025
3ecde34
newline
nnmkhang Feb 25, 2025
518ae4a
Prepping Cargo.toml and updating docs for version bump to 0.6.0
nnmkhang Feb 25, 2025
b1fc149
WIP
nnmkhang Feb 26, 2025
eadf174
updating documentation
nnmkhang Mar 5, 2025
9003cb6
updating documentation for install
nnmkhang Mar 5, 2025
4d3acbf
change author
nnmkhang Mar 5, 2025
c50fa13
fix clippy
nnmkhang Mar 5, 2025
4af8484
Fix docs
nnmkhang Mar 6, 2025
1bdad6b
minor buildscript tweak
nnmkhang Mar 6, 2025
c95763d
Add STATIC_LINKING.md for experimental branch
nnmkhang Mar 30, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/bindgen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ jobs:
sudo apt install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
}

- uses: Swatinem/rust-cache@v2

- name: Generate bindings
shell: pwsh
run: |
Expand Down
77 changes: 77 additions & 0 deletions .github/workflows/build_linux.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Build Linux

on:
push:
branches: [ "main" ]
pull_request:

env:
CARGO_TERM_COLOR: always
FEATURES_TO_TEST: md5,sha1,pkcs1-encrypt-decrypt

jobs:
build:
strategy:
fail-fast: false
matrix:
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
runs-on: ubuntu-latest
run-tests: true
- target: aarch64-unknown-linux-gnu
os: ubuntu-24.04-arm
runs-on: ubuntu-24.04-arm
run-tests: true

runs-on: ${{ matrix.os }}
name: ${{ matrix.target }}
env:
CARGO_BUILD_TARGET: ${{ matrix.target }}

steps:
- uses: actions/checkout@v4 # Checks out SymCrypt based on Github submodule
with:
submodules: true

- uses: Swatinem/rust-cache@v2

# Download SymCrypt via PMC
- name: Install SymCrypt via PMC
shell: bash
run: |
curl -sSL -O https://packages.microsoft.com/config/ubuntu/24.04/packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
sudo apt-get update
sudo apt-get install -y symcrypt

- name: Install host target
shell: pwsh
run: |
rustup target add ${{ matrix.target }}
if ("${{ matrix.target }}" -match "aarch64-unknown-linux-gnu") {
sudo apt update
sudo apt install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
}

- name: Debug build
run: cargo build --locked --verbose --target ${{ matrix.target }}

- name: Release build
run: cargo build --release --locked --verbose --target ${{ matrix.target }}

- name: Run tests (Debug, dynamic)
if: matrix.run-tests
run: cargo test --locked --verbose --all-features --target ${{ matrix.target }}

- name: Run tests (Release, dynamic)
if: matrix.run-tests
run: cargo test --release --locked --verbose --all-features --target ${{ matrix.target }}

- name: Run test (Debug, static)
if: matrix.run-tests
run: cargo test --features ${{ env.FEATURES_TO_TEST }} --locked --target ${{ matrix.target }}

- name: Run test (Release, static)
if: matrix.run-tests
run: cargo test --features ${{ env.FEATURES_TO_TEST }} --locked --target ${{ matrix.target }}
161 changes: 76 additions & 85 deletions .github/workflows/build.yml → .github/workflows/build_windows.yml
Original file line number Diff line number Diff line change
@@ -1,85 +1,76 @@
name: Build

on:
push:
branches: [ "main" ]
pull_request:

env:
CARGO_TERM_COLOR: always

jobs:
build:
strategy:
fail-fast: false
matrix:
include:
- target: x86_64-pc-windows-msvc
os: windows-latest
symcrypt: "https://github.com/microsoft/SymCrypt/releases/download/v103.8.0/symcrypt-windows-amd64-release-103.8.0-53be637d.zip"
run-tests: true
- target: aarch64-pc-windows-msvc
os: windows-latest
symcrypt: "https://github.com/microsoft/SymCrypt/releases/download/v103.8.0/symcrypt-windows-arm64-release-103.8.0-53be637d.zip"
run-tests: false # Windows doesn't support ARM64 emulation
- target: x86_64-unknown-linux-gnu
symcrypt: "https://github.com/microsoft/SymCrypt/releases/download/v103.8.0/symcrypt-linux-generic-amd64-release-103.8.0-53be637.tar.gz"
os: ubuntu-latest
run-tests: true
- target: aarch64-unknown-linux-gnu
os: ubuntu-latest
symcrypt: "https://github.com/microsoft/SymCrypt/releases/download/v103.8.0/symcrypt-linux-generic-arm64-release-103.8.0-53be637.tar.gz"
run-tests: false

runs-on: ${{ matrix.os }}
name: ${{ matrix.target }}
env:
CARGO_BUILD_TARGET: ${{ matrix.target }}

steps:
- uses: actions/checkout@v4

- name: Install host target
shell: pwsh
run: |
rustup target add ${{ matrix.target }}
if ("${{ matrix.target }}" -match "aarch64-unknown-linux-gnu") {
sudo apt update
sudo apt install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
}

- name: Download SymCrypt
shell: pwsh
run: |
$dir = $(Get-Item .).FullName
if ("${{ matrix.symcrypt }}" -match "\.tar\.gz$") {
Invoke-WebRequest -Uri ${{ matrix.symcrypt }} -OutFile symcrypt.tar.gz
New-Item -ItemType Directory -Force -Path symcrypt
tar -xzf symcrypt.tar.gz -C symcrypt
echo "$dir/symcrypt/lib" >> $env:GITHUB_PATH
echo "LD_LIBRARY_PATH=$dir/symcrypt/lib:$env:LD_LIBRARY_PATH" >> $env:GITHUB_ENV
echo "LIBRARY_PATH=$dir/symcrypt/lib:$env:LIBRARY_PATH" >> $env:GITHUB_ENV
echo "SYMCRYPT_LIB_PATH=$dir/symcrypt/lib" >> $env:GITHUB_ENV
} else {
Invoke-WebRequest -Uri ${{ matrix.symcrypt }} -OutFile symcrypt.zip
New-Item -ItemType Directory -Force -Path symcrypt
Expand-Archive -Path symcrypt.zip -DestinationPath symcrypt
echo "$dir/symcrypt/dll" >> $env:GITHUB_PATH
echo "SYMCRYPT_LIB_PATH=$dir/symcrypt/dll" >> $env:GITHUB_ENV
}

- name: Debug build
run: cargo build --locked --verbose --target ${{ matrix.target }}

- name: Release build
run: cargo build --release --locked --verbose --target ${{ matrix.target }}

- name: Run tests (Debug)
if: matrix.run-tests
shell: pwsh
run: cargo test --locked --verbose --all-features --target ${{ matrix.target }}

- name: Run tests (Release)
if: matrix.run-tests
shell: pwsh
run: cargo test --release --locked --verbose --all-features --target ${{ matrix.target }}
name: Build Windows

on:
push:
branches: [ "main" ]
pull_request:

env:
CARGO_TERM_COLOR: always
FEATURES_TO_TEST: md5,sha1,pkcs1-encrypt-decrypt

jobs:
build:
strategy:
fail-fast: false
matrix:
include:
- target: x86_64-pc-windows-msvc
os: windows-latest
runs-on: windows-latest
symcrypt: "https://github.com/microsoft/SymCrypt/releases/download/v103.8.0/symcrypt-windows-amd64-release-103.8.0-53be637d.zip"
run-tests: true
- target: aarch64-pc-windows-msvc
os: windows-latest
runs-on: windows-latest
symcrypt: "https://github.com/microsoft/SymCrypt/releases/download/v103.8.0/symcrypt-windows-arm64-release-103.8.0-53be637d.zip"
run-tests: false # Windows doesn't support ARM64 emulation
runs-on: ${{ matrix.os }}
name: ${{ matrix.target }}
env:
CARGO_BUILD_TARGET: ${{ matrix.target }}

steps:
- uses: actions/checkout@v4 # Checks out SymCrypt based on Github submodule
with:
submodules: true

- uses: Swatinem/rust-cache@v2

# Install host architecture, required for cross-compilation since there is no arm64-windows-msvc runner
- name: Install host target
shell: pwsh
run: |
rustup target add ${{ matrix.target }}

- name: Download SymCrypt and Set Environment Variables
shell: pwsh
run: |
Invoke-WebRequest -Uri ${{ matrix.symcrypt }} -OutFile symcrypt.zip
New-Item -ItemType Directory -Force -Path symcrypt
Expand-Archive -Path symcrypt.zip -DestinationPath symcrypt
echo "$env:GITHUB_WORKSPACE\symcrypt\dll" >> $env:GITHUB_PATH
echo "SYMCRYPT_LIB_PATH=$env:GITHUB_WORKSPACE\symcrypt\dll" >> $env:GITHUB_ENV
echo "PATH=$env:GITHUB_WORKSPACE\symcrypt\dll;$env:PATH" >> $env:GITHUB_ENV

- name: Debug build
run: cargo build --locked --verbose --target ${{ matrix.target }}

- name: Release build
run: cargo build --release --locked --verbose --target ${{ matrix.target }}

- name: Run tests (Debug, dynamic)
if: matrix.run-tests
run: cargo test --locked --verbose --all-features --target ${{ matrix.target }}

- name: Run tests (Release, dynamic)
if: matrix.run-tests
run: cargo test --release --locked --verbose --all-features --target ${{ matrix.target }}

- name: Run test (Debug, static)
if: matrix.run-tests
run: cargo test --features ${{ env.FEATURES_TO_TEST }} --locked --target ${{ matrix.target }}

- name: Run test (Release, static)
if: matrix.run-tests
run: cargo test --features ${{ env.FEATURES_TO_TEST }} --locked --target ${{ matrix.target }}
2 changes: 2 additions & 0 deletions .github/workflows/clippy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ jobs:
steps:
- name: Checkout sources
uses: actions/checkout@v4
with:
submodules: true

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
Expand Down
14 changes: 12 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions rust-symcrypt/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "symcrypt"
authors = ["nnmkhang"]
version = "0.5.1"
authors = ["Microsoft"]
version = "0.6.0"
license = "MIT OR Apache-2.0"
description = "Friendly and Idiomatic Wrappers for SymCrypt"
edition.workspace = true
Expand All @@ -15,7 +15,7 @@ readme = "README.md"
[dependencies]
# uses '../symcrypt-sys' when compiled locally, and uses
# crates.io versioning when published
symcrypt-sys = {path = "../symcrypt-sys", version = "0.4.0"}
symcrypt-sys = {path = "../symcrypt-sys", version = "0.5.0"}
libc = "0.2.0"
lazy_static = "1.4.0"

Expand All @@ -24,6 +24,7 @@ default = []
md5 = []
sha1 = []
pkcs1-encrypt-decrypt = []
dynamic = ["symcrypt-sys/dynamic"]

[dev-dependencies]
hex = "0.4.3"
28 changes: 11 additions & 17 deletions rust-symcrypt/INSTALL.md
Original file line number Diff line number Diff line change
@@ -1,48 +1,42 @@
# Detailed Build and Install
# Detailed Build and Install for Dynamic Linking

This page provides more detailed installation instructions
This page provides more detailed installation instructions for dynamic linking on Windows and Linux.

## Installation
For ease of use, the recommended usage is to obtain these binaries from the official SymCrypt [Repo](https://github.com/microsoft/SymCrypt/releases/tag/v103.4.2).
The `symcrypt` crate is a wrapper on top of the `SymCrypt` library, and requires access to the `SymCrypt` library during the build and execution stage for dynamic linking. For ease of use, the recommended way to configure your `SymCrypt` library dependancy is to obtain the required binaries from the official [SymCrypt Repo](https://github.com/microsoft/SymCrypt/releases/tag/v103.8.0).

**Note:** If you wish to build your own version please follow the [Build Instructions](https://github.com/microsoft/SymCrypt/blob/main/BUILD.md) that are provided by SymCrypt to install SymCrypt for your target architecture.

Once SymCrypt is installed on your machine, we must configure your machine so that the SymCrypt crate's build script can easily find `symcrypt.dll` and `symcrypt.lib` which are needed on Windows, or the `libsymcrypt.so*` files which are needed for Linux.
However, If you wish to build your own version of the underlying `SymCrypt` library please follow the [Build Instructions](https://github.com/microsoft/SymCrypt/blob/main/BUILD.md) that are provided by SymCrypt to install SymCrypt for your target architecture.

### Windows Install

The `symcrypt.lib` can be found in the the following path after SymCrypt has been downloaded and unzipped.
The `symcrypt.lib` can be found in the the following path after `SymCrypt` has been downloaded and unzipped.

`C:\Your-Path-To-SymCrypt-Release-Download\dll\`

The SymCrypt crate needs to link against the SymCrypt import library during build.
The SymCrypt crate needs to link against the `SymCrypt` import library during build.

To do so you must set the `SYMCRYPT_LIB_PATH` environment variable. You can do this by using the following command:

`setx SYMCRYPT_LIB_PATH "<your-path-to-symcrypt-lib-folder>"`

The `symcrypt.dll` can be found in the the following path after SymCrypt has been downloaded and unzipped.

`C:\Your-Path-To-SymCrypt-Release-Download\dll\`

During runtime, Windows will handle finding all needed `dll`'s in order to run the intended program, this includes our `symcrypt.dll` file. The places Windows will look are:

1. The folder from which the application loaded.
2. The system folder. Use the `GetSystemDirectory` function to retrieve the path of this folder.
3. The Windows folder. Use the `GetWindowsDirectory` function to get the path of this folder.
4. The current folder.
5. The directories listed in the PATH environment variable.

For more info please see: [Dynamic-link library search order](https://learn.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-search-order)

Here are 2 recommended options to ensure your `symcrypt.dll` is found by Windows during runtime.

1. Put the `symcrypt.dll` in the same folder as your output `.exe` file. If you are doing development (not release), the common path will be: `C:\your-project\target\debug\`.
2. Permanently add the `symcrypt.dll` path into your System PATH environment variable. Doing this will ensure that any project that uses the SymCrypt crate will be able to access `symcrypt.lib`

**NOTE:** By setting the `SYMCRYPT_LIB_PATH` via `setx SYMCRYPT_LIB_PATH "<your-path-to-symcrypt-lib-folder>"`; `symcrypt.dll` will already be on the `PATH` and you will not have to do any additional configuration for your program.

### Linux Install

Though the artifacts on the [SymCrypt Repo](https://github.com/microsoft/SymCrypt/releases/tag/v103.8.0). Have been built with `Ubuntu` in mind, the `SymCrypt` library has been built with very few standard library dependencies and should work on most Linux distributions.

After installing and unzipping SymCrypt on a Linux distro, the required `libsymcrypt.so*` files can be found in the following path:
`~/Your-Path-To-SymCrypt-Release-Download/lib/`

The symcrypt crate needs to be able to link with these libs during build/run time. In order to mimic the installation path for other libraries, you must place the `libsymcrypt.so*` files into linker load path. The way that this is set will vary between distros. On most distros it set via the environment variable `$LD_LIBRARY_PATH`.
The `symcrypt` crate needs to be able to link with these libs during build/run time. In order to mimic the installation path for other libraries, you must place the `libsymcrypt.so*` files into linker load path. The way that this is set will vary between distros. On most distros it set via the environment variable `$LD_LIBRARY_PATH`.
Loading
Loading