Skip to content

🚀[Feature]: Deterministic Key Generation #19

Description

Overview

Enhance the current Sodium module by adding deterministic key generation via a string-based seed. This enables seamless, non-interactive file encryption/decryption for users and improves clarity in API usage.

Why

  • Seamless User Experience:
    Users can encrypt and decrypt files automatically without needing to remember or input passwords. A consistent key is generated from a user-defined seed.

  • Deterministic Key Pair:
    Using a seed ensures that the same key pair is produced every time for a given seed, enabling reliable, repeatable encryption/decryption operations.

What

  • Extend Key Pair Generation:
    • Add an optional -Seed parameter to New-SodiumKeyPair.
    • When provided, derive a 32-byte seed (e.g., via SHA-256) from the input string.
    • Use the derived seed with LibSodium’s crypto_box_seed_keypair to generate a deterministic key pair.
    • Retain the existing random key generation if no seed is provided.

How

  1. Deterministic Key Generation:

    • In PowerShell:
      Check for the -Seed parameter in New-SodiumKeyPair.
      If provided, convert the seed string to bytes and compute a SHA-256 hash to produce a 32-byte value.
    • In C# Binding:
      Add a DllImport for crypto_box_seed_keypair:
      [DllImport("libsodium", CallingConvention = CallingConvention.Cdecl)]
      public static extern int crypto_box_seed_keypair(byte[] pk, byte[] sk, byte[] seed);
    • Call:
      Use crypto_box_seed_keypair when a seed is provided, otherwise fall back to crypto_box_keypair.
  2. Cross-Platform & Backward Compatibility:

    • Ensure that the changes work seamlessly on Windows, Linux, and macOS (using PowerShell 7.4 with .NET 8.0).
    • Maintain existing behavior for users who do not supply a seed.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions