aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorMITSUNARI Shigeo <herumi@nifty.com>2018-09-17 10:43:16 +0800
committerMITSUNARI Shigeo <herumi@nifty.com>2018-09-17 10:43:16 +0800
commitaf2e557d9eb824a0c8d5c42a8cf1c8f09c8d16a7 (patch)
tree920ea3ff57d5fe3dbacd7d4841394dcf25aeaa47 /include
parent5aac84e9ab6b14d6c6402389d28fc1d488766444 (diff)
downloaddexon-bls-af2e557d9eb824a0c8d5c42a8cf1c8f09c8d16a7.tar
dexon-bls-af2e557d9eb824a0c8d5c42a8cf1c8f09c8d16a7.tar.gz
dexon-bls-af2e557d9eb824a0c8d5c42a8cf1c8f09c8d16a7.tar.bz2
dexon-bls-af2e557d9eb824a0c8d5c42a8cf1c8f09c8d16a7.tar.lz
dexon-bls-af2e557d9eb824a0c8d5c42a8cf1c8f09c8d16a7.tar.xz
dexon-bls-af2e557d9eb824a0c8d5c42a8cf1c8f09c8d16a7.tar.zst
dexon-bls-af2e557d9eb824a0c8d5c42a8cf1c8f09c8d16a7.zip
add signHash and verifyHash for hashed value
Diffstat (limited to 'include')
-rw-r--r--include/bls/bls.h11
-rw-r--r--include/bls/bls.hpp35
2 files changed, 42 insertions, 4 deletions
diff --git a/include/bls/bls.h b/include/bls/bls.h
index 21cd5b0..b2b8604 100644
--- a/include/bls/bls.h
+++ b/include/bls/bls.h
@@ -72,6 +72,7 @@ BLS_DLL_API int blsSecretKeySetLittleEndian(blsSecretKey *sec, const void *buf,
BLS_DLL_API void blsGetPublicKey(blsPublicKey *pub, const blsSecretKey *sec);
+// calculate the has of m and sign the hash
BLS_DLL_API void blsSign(blsSignature *sig, const blsSecretKey *sec, const void *m, mclSize size);
// return 1 if valid
@@ -122,6 +123,16 @@ BLS_DLL_API int blsPublicKeyIsValidOrder(const blsPublicKey *pub);
#ifndef BLS_MINIMUM_API
+/*
+ sign the hash
+ use the low (bitSize of r) - 1 bit of h
+ return 0 if success else -1
+ NOTE : return false if h is zero or c1 or -c1 value for BN254. see hashTest() in test/bls_test.hpp
+*/
+BLS_DLL_API int blsSignHash(blsSignature *sig, const blsSecretKey *sec, const void *h, mclSize size);
+// return 1 if valid
+BLS_DLL_API int blsVerifyHash(const blsSignature *sig, const blsPublicKey *pub, const void *h, mclSize size);
+
// sub
BLS_DLL_API void blsSecretKeySub(blsSecretKey *sec, const blsSecretKey *rhs);
BLS_DLL_API void blsPublicKeySub(blsPublicKey *pub, const blsPublicKey *rhs);
diff --git a/include/bls/bls.hpp b/include/bls/bls.hpp
index a1aa444..3dbacd7 100644
--- a/include/bls/bls.hpp
+++ b/include/bls/bls.hpp
@@ -209,7 +209,18 @@ public:
}
void getPublicKey(PublicKey& pub) const;
// constant time sign
- void sign(Signature& sig, const std::string& m) const;
+ // sign hash(m)
+ void sign(Signature& sig, const void *m, size_t size) const;
+ void sign(Signature& sig, const std::string& m) const
+ {
+ sign(sig, m.c_str(), m.size());
+ }
+ // sign hashed value
+ void signHash(Signature& sig, const void *h, size_t size) const;
+ void signHash(Signature& sig, const std::string& h) const
+ {
+ signHash(sig, h.c_str(), h.size());
+ }
/*
make Pop(Proof of Possesion)
pop = prv.sign(pub)
@@ -392,9 +403,21 @@ public:
int ret = mclBnG1_setStr(&self_.v, str.c_str(), str.size(), ioMode);
if (ret != 0) throw std::runtime_error("mclBnG1_setStr");
}
+ bool verify(const PublicKey& pub, const void *m, size_t size) const
+ {
+ return blsVerify(&self_, &pub.self_, m, size) == 1;
+ }
bool verify(const PublicKey& pub, const std::string& m) const
{
- return blsVerify(&self_, &pub.self_, m.c_str(), m.size()) == 1;
+ return verify(pub, m.c_str(), m.size());
+ }
+ bool verifyHash(const PublicKey& pub, const void *h, size_t size) const
+ {
+ return blsVerifyHash(&self_, &pub.self_, h, size) == 1;
+ }
+ bool verifyHash(const PublicKey& pub, const std::string& h) const
+ {
+ return verifyHash(pub, h.c_str(), h.size());
}
/*
verify self(pop) with pub
@@ -445,9 +468,13 @@ inline void SecretKey::getPublicKey(PublicKey& pub) const
{
blsGetPublicKey(&pub.self_, &self_);
}
-inline void SecretKey::sign(Signature& sig, const std::string& m) const
+inline void SecretKey::sign(Signature& sig, const void *m, size_t size) const
+{
+ blsSign(&sig.self_, &self_, m, size);
+}
+inline void SecretKey::signHash(Signature& sig, const void *h, size_t size) const
{
- blsSign(&sig.self_, &self_, m.c_str(), m.size());
+ if (blsSignHash(&sig.self_, &self_, h, size) != 0) throw std::runtime_error("bad h");
}
inline void SecretKey::getPop(Signature& pop) const
{