From ea600930c3e920b75d15fa1bffe3d48d818a294b Mon Sep 17 00:00:00 2001 From: MITSUNARI Shigeo Date: Sat, 27 Aug 2016 18:03:04 +0900 Subject: init by user defined p --- include/bls.hpp | 5 ++++- src/bls.cpp | 12 ++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/include/bls.hpp b/include/bls.hpp index 2c4017e..be6d17d 100644 --- a/include/bls.hpp +++ b/include/bls.hpp @@ -41,6 +41,8 @@ class SecretKey; class PublicKey; class Sign; +const size_t keySize = 32; + typedef std::vector SecretKeyVec; typedef std::vector PublicKeyVec; typedef std::vector SignVec; @@ -67,8 +69,9 @@ public: friend std::istream& operator>>(std::istream& is, SecretKey& sec); /* make a secret key for id = 0 + set p[keySize] if p != 0 */ - void init(); + void init(const uint64_t *p = 0); void getPublicKey(PublicKey& pub) const; void sign(Sign& sign, const std::string& m) const; /* diff --git a/src/bls.cpp b/src/bls.cpp index ab3d68b..40599af 100644 --- a/src/bls.cpp +++ b/src/bls.cpp @@ -180,9 +180,13 @@ inline bool Sign::verify(const PublicKey& pub, const std::string& m) const struct SecretKey { Fr s; const Fr& get() const { return s; } - void init() + void init(const uint64_t *p) { - s.setRand(getRG()); + if (p) { + s.setArray(p, keySize); + } else { + s.setRand(getRG()); + } } void getPublicKey(PublicKey& pub) const { @@ -367,9 +371,9 @@ std::istream& operator>>(std::istream& is, SecretKey& sec) return is >> sec.id_ >> sec.self_->s; } -void SecretKey::init() +void SecretKey::init(const uint64_t *p) { - self_->init(); + self_->init(p); } void SecretKey::getPublicKey(PublicKey& pub) const -- cgit v1.2.3