Skip to content

Derive strong name key pairs deterministically from a seed instead of a static .snk - #1

Merged
Tyrrrz merged 9 commits into
primefrom
copilot/evaluate-strong-name-seed
Oct 3, 2026
Merged

Tyrrrz merged 9 commits into
primefrom
copilot/evaluate-strong-name-seed

Conversation

Copilot AI commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Previously Snek shipped a single static Snek.snk, giving every consuming assembly the exact same public key token. This replaces it with a key pair generated deterministically from a seed at build time — same seed always yields the same key, different seeds yield different keys.

Usage

<PropertyGroup>
  <AssemblyOriginatorKeySeed>my-custom-seed</AssemblyOriginatorKeySeed>
</PropertyGroup>

Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>

@Tyrrrz Tyrrrz left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot some review comments

Comment thread Snek.Demo/Snek.Demo.csproj Outdated
Comment thread Snek/GenerateStrongNameKeyPairTask.cs Outdated
Comment thread Snek/GenerateStrongNameKeyPairTask.cs Outdated
Comment thread Snek/GenerateStrongNameKeyPairTask.cs Outdated
Comment thread Snek/GenerateStrongNameKeyPairTask.cs Outdated
Comment thread Snek/Snek.targets
Comment thread Snek/StrongNameKeyGenerator.cs Outdated
Comment thread Snek/StrongNameKeyPair.cs Outdated
Comment thread Readme.md Outdated
Comment thread Readme.md Outdated
…ops, add error for manual key file, simplify Readme

Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>

@Tyrrrz Tyrrrz left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread Snek.Demo/Snek.Demo.csproj Outdated
Comment thread Snek/Snek.targets Outdated
Comment thread Snek/Snek.targets
Comment thread Snek/Snek.targets Outdated
Comment thread Readme.md Outdated
Comment thread Readme.md Outdated
…eorder demo imports, Readme tweaks

Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
…y type

Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>

@Tyrrrz Tyrrrz left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread Directory.Packages.props Outdated
Comment thread Snek/SeededRandom.cs Outdated
Comment thread Snek/SeededRandom.cs Outdated
Comment thread Snek/SeededRandom.cs Outdated
Comment thread Snek/SeededRandom.cs Outdated
Comment thread Snek/Utils/SeededRandom.cs
Comment thread Snek/StrongNameKeyPair.cs Outdated
Comment thread Snek/StrongNameKeyPair.cs Outdated
@Tyrrrz
Tyrrrz marked this pull request as ready for review October 3, 2026 18:07
Copilot AI balanced review requested due to automatic review settings October 3, 2026 18:07
…onstructors/collection expressions, remove unused package, reorder members

Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

Key generation can hang, produce undersized moduli, and vary across runtime byte orders.

Review effort: Balanced
Findings: None

What changed in this PR

Replaces Snek’s shared static signing key with keys derived deterministically from a configurable seed.

Changes:

  • Adds deterministic RSA key generation and build-time caching.
  • Integrates key generation into MSBuild and the demo.
  • Documents seed configuration and removes the static-key workflow.
File Description
Snek/​StrongNameTask.cs Generates and caches key files.
Snek/​StrongNameKeyPair.cs Implements seeded RSA key generation.
Snek/​Snek.targets Resolves seeds and invokes generation.
Snek/​Snek.props Registers the signing task.
Snek/​Snek.Local.props Configures local task assembly paths.
Snek/​Snek.csproj Packages targets instead of the static key.
Snek/​SeededRandom.cs Adds a hash-based deterministic byte generator.
Snek.Demo/​Snek.Demo.csproj Imports local signing integration.
Readme.md Documents derived keys and custom seeds.
Directory.Packages.props Updates PolyShim.
.github/​workflows/​snk.yml Removes manual static-key generation.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@Tyrrrz

Tyrrrz commented Oct 3, 2026

Copy link
Copy Markdown
Owner

@copilot is the modulus issue an easy fix? And how likely that it's going to manifest in a real environment?

As for endianess, BinaryPrimitives has methods with explicit endianess, can we use that?

Copilot AI commented Oct 3, 2026

Copy link
Copy Markdown
Contributor Author

@copilot is the modulus issue an easy fix? And how likely that it's going to manifest in a real environment?

As for endianess, BinaryPrimitives has methods with explicit endianess, can we use tha...

Yes, it’s a small fix: for the big-endian input, set bytes[0] |= 0b1100_0000; for oddness, set bytes[^1] |= 1. With the current code, each generated prime is about equally likely to be 511 or 512 bits, and the resulting modulus is 1024 bits only about 15% of the time; most are 1022–1023 bits. It will still generally function, but it doesn’t meet the stated 1024-bit size. BinaryPrimitives.WriteInt64BigEndian is the right way to make the counter encoding explicit; for netstandard2.0/net472, it may require a compatible System.Memory compile reference if one isn’t already available. Either fix changes derived keys, so it’s best to settle it before release.

@Tyrrrz

Tyrrrz commented Oct 3, 2026

Copy link
Copy Markdown
Owner

@copilot let's do that. The BinaryPrimitives method should be available uniformly via PolyShim.

Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>

Copilot AI commented Oct 3, 2026

Copy link
Copy Markdown
Contributor Author

@copilot let's do that. The BinaryPrimitives method should be available uniformly via PolyShim.

Implemented in commit $(git rev-parse --short HEAD): corrected the prime byte masks and used BinaryPrimitives.WriteInt64BigEndian for the seed counter. Both target frameworks and the demo build pass.

Comment thread Snek/Utils/StrongNameKeyPair.cs
Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
Comment thread Snek/Utils/Extensions/BigIntegerExtensions.cs Outdated
Comment thread Snek/Utils/StrongNameKeyPair.cs
Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
Copilot AI requested a review from Tyrrrz October 3, 2026 20:32
@Tyrrrz
Tyrrrz merged commit aa49f4e into prime Oct 3, 2026
8 checks passed
@Tyrrrz
Tyrrrz deleted the copilot/evaluate-strong-name-seed branch October 3, 2026 20:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants