Crates.io | rsa-fdh |
lib.rs | rsa-fdh |
version | 0.5.0 |
source | src |
created_at | 2019-04-04 17:49:36.356672 |
updated_at | 2020-11-24 17:04:55.122112 |
description | RSA-FDH is a is provably secure blind-signing signature scheme that uses RSA and a full domain hash and support blind signing / blind signatures |
homepage | |
repository | https://github.com/phayes/rsa-fdh |
max_upload_size | |
id | 125852 |
size | 24,485 |
RSA-FDH is a is provably secure blind-signing signature scheme that uses RSA and a full domain hash.
This project implements two RSA-FDH signature schemes:
A regular signature scheme with Full Domain Hash (FDH) padding.
A blind signature scheme that that supports blind-signing to keep the message being signed secret from the signer.
When using the blind signature scheme, the signing key should only be used as part of RSA-FDH blind-signing. Key re-use for encryption or as part of other protocols can result in key disclosure.
This project and it's dependencies have not undergone a security audit. The 1.0 version will not be released until it does. If you are interested in performing a security audit, please see this ticket.
use rsa_fdh;
use rsa::{RSAPrivateKey, RSAPublicKey};
use sha2::{Sha256, Digest};
// Set up rng and message
let mut rng = rand::thread_rng();
let message = b"NEVER GOING TO GIVE YOU UP";
// Create the keys
let signer_priv_key = RSAPrivateKey::new(&mut rng, 256)?;
let signer_pub_key: RSAPublicKey = signer_priv_key.clone().into();
// Apply a standard digest to the message
let mut hasher = Sha256::new();
hasher.input(message);
let digest = hasher.result();
// Obtain a signture
let signature = rsa_fdh::sign::<Sha256, _>(&mut rng, &signer_priv_key, &digest)?;
// Verify the signature
rsa_fdh::verify::<Sha256, _>(&signer_pub_key, &digest, &signature)?;
use rsa_fdh;
use rsa::{RSAPrivateKey, RSAPublicKey};
use sha2::{Sha256, Digest};
// Set up rng and message
let mut rng = rand::thread_rng();
let message = b"NEVER GOING TO GIVE YOU UP";
// Create the keys
let signer_priv_key = RSAPrivateKey::new(&mut rng, 256)?;
let signer_pub_key: RSAPublicKey = signer_priv_key.clone().into();
// Hash the contents of the message with a Full Domain Hash, getting the digest
let digest = blind::hash_message::<Sha256, _>(&signer_pub_key, message)?;
// Get the blinded digest and the secret unblinder
let (blinded_digest, unblinder) = blind::blind(&mut rng, &signer_pub_key, &digest);
// Send the blinded-digest to the signer and get their signature
let blind_signature = blind::sign(&mut rng, &signer_priv_key, &blinded_digest)?;
// Unblind the signature
let signature = blind::unblind(&signer_pub_key, &blind_signature, &unblinder);
// Verify the signature
blind::verify(&signer_pub_key, &digest, &signature)?;
A full domain hash (FDH) is constructed as follows:
FDH(π, πΌπ) = H(π β π β πΌπ + 0) β H(π β π β πΌπ + 1) β H(π β π β πΌπ + 2) ...
Where:
The message is hashed (along with π and πΌπ + incrementing suffix) in rounds until the length of the hash is greater than or equal to the length of π. The hash is truncated as needed to produce the digest π· with the same length as π.
π· must also be smaller than π, so we increment πΌπ until we find a π· that is smaller than π.
Pseudocode:
fn generate_digest(message, public_key):
fdh = create_fdh(algo=sha256, length=public_key.bitlen())
iv = 0
digest = fdh(message, iv)
while digest.as_int() > public_key.n():
iv++
digest = fdh(message, iv)
return digest
The while
loop finishes within a minimal number of iterations because π generally occurs around (2^bitlen) / 2
.
Two signature schemes are supported:
In the regular signature scheme, the signer applies the FDH before signing the message.
In the blind-signature scheme, the sender applies the FDH to the message before blinding the resulting digest and sending it to the signer, who signs the blinded digest directly. The signer must not re-use their private keys for encryption outside of the RSA-FDH blind-signature protocol.
Blinding, unblinding, signing and verification are done in the usual way for RSA.