Crate df_share

Crate df_share 

Source
Expand description

§df-share: Secret Sharing

This module provides a straightforward API to securely exchange a secret between two parties (a client and a server) using ephemeral Diffie-Hellman keys. The server encrypts the secret in such a way that only the requesting client can decrypt it, assuming both sides derive the same shared secret key.

§Basic Usage

  1. Client creates an ephemeral key pair via EphemeralClient::new().
  2. Server receives the request, creates its own ephemeral key pair via EphemeralServer::new(), and calls EphemeralServer::encrypt_secret() to produce a response containing the encrypted secret.
  3. Client decrypts the response with the decryptor it previously obtained.

§Example

use df_share::{EphemeralClient, EphemeralServer};
use df_share::error::Unspecified;
// Client side
let client = EphemeralClient::new()?;
let (req, decryptor) = client.sendable();

let res;
let secret = "MyVerySecretPrivateKey010101010";

// Server side
{
    let server = EphemeralServer::new()?;
    res = server.encrypt_secret(&req, secret.as_bytes())?;
}

// Client side again: decrypt the server's response
let decrypted_secret = decryptor.decrypt(&res)?;

assert_eq!(secret.as_bytes(), &decrypted_secret);

Important Note: Because the server generates an ephemeral key pair each time, there’s no built-in guarantee of the server’s identity. If you need server authentication, you must maintain long-term server key material and pin the server public key on the client or use HTTPS/TLS with certificate validation.

Modules§

error

Structs§

ClientReq
EphemeralClient
Generate per request. Do not reuse.
EphemeralServer
Generate per request. Do not reuse.
ResponseDecryptor
ServerEncryptedRes

Functions§

from_hex_str
generate_ascii_art
Generate a 32×32 ASCII art grid by “walking” around based on the hash
to_hex_str