diff options
-rw-r--r-- | include/bls.hpp | 11 | ||||
-rw-r--r-- | src/bls.cpp | 17 | ||||
-rw-r--r-- | test/bls_test.cpp | 9 |
3 files changed, 37 insertions, 0 deletions
diff --git a/include/bls.hpp b/include/bls.hpp index 955702a..cf251d5 100644 --- a/include/bls.hpp +++ b/include/bls.hpp @@ -88,6 +88,8 @@ class SecretKey { friend void LagrangeInterpolation(G& r, const T& vec, const IdVec& idVec); template<class T, class G> friend struct Wrap; + template<class T, class G> + friend struct WrapPointer; public: SecretKey(); ~SecretKey(); @@ -129,6 +131,13 @@ public: add secret key */ void add(const SecretKey& rhs); + + // the following methods are for C api + /* + the size of msk must be k + */ + void set(const SecretKey *const *msk, size_t k, const Id& id); + void recover(const SecretKey *const *secVec, const Id *const *idVec, size_t n); }; /* @@ -142,6 +151,8 @@ class PublicKey { friend void LagrangeInterpolation(G& r, const T& vec, const IdVec& idVec); template<class T, class G> friend struct Wrap; + template<class T, class G> + friend struct WrapPointer; public: PublicKey(); ~PublicKey(); diff --git a/src/bls.cpp b/src/bls.cpp index 03f7d16..3dfab45 100644 --- a/src/bls.cpp +++ b/src/bls.cpp @@ -87,6 +87,18 @@ struct Wrap { size_t size() const { return pv->size(); } }; +template<class T, class G> +struct WrapPointer { + const T *const *v; + size_t k; + WrapPointer(const T *const *v, size_t k) : v(v), k(k) {} + const G& operator[](size_t i) const + { + return v[i]->self_->get(); + } + size_t size() const { return k; } +}; + struct Polynomial { FrVec c; // f[x] = sum_{i=0}^{k-1} c[i] x^i void init(const Fr& s, int k) @@ -426,6 +438,11 @@ void SecretKey::set(const SecretKeyVec& msk, const Id& id) Wrap<SecretKey, Fr> w(msk); evalPoly(self_->s, id.self_->v, w); } +void SecretKey::set(const SecretKey *const *msk, size_t k, const Id& id) +{ + WrapPointer<SecretKey, Fr> w(msk, k); + evalPoly(self_->s, id.self_->v, w); +} void SecretKey::recover(const SecretKeyVec& secVec, const IdVec& idVec) { diff --git a/test/bls_test.cpp b/test/bls_test.cpp index e9ff953..47ba330 100644 --- a/test/bls_test.cpp +++ b/test/bls_test.cpp @@ -72,12 +72,21 @@ CYBOZU_TEST_AUTO(k_of_n) bls::SecretKeyVec msk; sec0.getMasterSecretKey(msk, k); + std::vector<const bls::SecretKey*> pmsk(k); + for (size_t i = 0; i < k; i++) { + pmsk[i] = &msk[i]; + } + bls::SecretKeyVec allPrvVec(n); bls::IdVec allIdVec(n); for (int i = 0; i < n; i++) { int id = i + 1; allPrvVec[i].set(msk, id); allIdVec[i] = id; + + bls::SecretKey p; + p.set(&pmsk[0], k, id); + CYBOZU_TEST_EQUAL(allPrvVec[i], p); } bls::SignVec allSignVec(n); |