From d7a1643bea147082a84f5c258ea21ecddd6b7b5f Mon Sep 17 00:00:00 2001 From: Alberto Solavagione Date: Wed, 27 Mar 2024 13:45:13 +0100 Subject: [PATCH] fix keygen --- Cargo.toml | 2 +- README.md | 4 ++-- src/bbsplus/keys.rs | 23 ++++++++++++++++++++++- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f655c6f..2f96508 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "zkryptium" -version = "0.2.0" +version = "0.2.1" edition = "2021" license = "Apache-2.0" authors = ["LINKS Foundation"] diff --git a/README.md b/README.md index 3db31d3..3357928 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ This library enables the creation of zero-knowledge proofs, exposing cryptograph ```toml [dependencies] -zkryptium = { version = "0.2.0", default-features = false, features = ["bbsplus"] } +zkryptium = { version = "0.2.1", default-features = false, features = ["bbsplus"] } ``` ##### CL2003: @@ -41,7 +41,7 @@ zkryptium = { version = "0.2.0", default-features = false, features = ["bbsplus" ```toml [dependencies] -zkryptium = { version = "0.2.0", default-features = false, features = ["cl03"] } +zkryptium = { version = "0.2.1", default-features = false, features = ["cl03"] } ``` ### Examples diff --git a/src/bbsplus/keys.rs b/src/bbsplus/keys.rs index d43c5b3..21938cc 100644 --- a/src/bbsplus/keys.rs +++ b/src/bbsplus/keys.rs @@ -21,7 +21,7 @@ use crate::{ }, schemes::algorithms::BBSplus, utils::util::bbsplus_utils::{ - hash_to_scalar, i2osp, parse_g2_projective_compressed, parse_g2_projective_uncompressed, + generate_random_secret, hash_to_scalar, i2osp, parse_g2_projective_compressed, parse_g2_projective_uncompressed }, }; use bls12_381_plus::{G2Affine, G2Projective, Scalar}; @@ -164,6 +164,27 @@ impl KeyPair> { private: BBSplusSecretKey(sk), }) } + + /// # Description + /// This operation generates a random keypair (SK, PK) + /// + /// # Output: + /// * a keypair [`KeyPair`] + pub fn random() -> Result + where + CS::Expander: for<'a> ExpandMsg<'a>, + { + let key_material = generate_random_secret(64); + + let sk = key_gen::(&key_material, None, None)?; + + let pk = sk_to_pk(sk); + + Ok(Self { + public: BBSplusPublicKey(pk), + private: BBSplusSecretKey(sk), + }) + } } /// https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-bbs-signatures-05#name-secret-key -> SK = KeyGen(key_material, key_info, key_dst)