diff options
-rw-r--r-- | go/blscgo/bls.go | 8 | ||||
-rw-r--r-- | go/main.go | 2 | ||||
-rw-r--r-- | include/bls.hpp | 2 | ||||
-rw-r--r-- | include/bls_if.h | 1 | ||||
-rw-r--r-- | src/bls.cpp | 7 | ||||
-rw-r--r-- | src/bls_if.cpp | 4 |
6 files changed, 24 insertions, 0 deletions
diff --git a/go/blscgo/bls.go b/go/blscgo/bls.go index 10968b8..35cf253 100644 --- a/go/blscgo/bls.go +++ b/go/blscgo/bls.go @@ -259,6 +259,14 @@ func (sec *SecretKey) Sign(m string) (sign *Sign) { C.blsSecretKeySign(sec.getPointer(), sign.getPointer(), (*C.char)(unsafe.Pointer(&buf[0])), C.size_t(len(buf))) return sign } +// Constant Time Sign -- +func (sec *SecretKey) SignCT(m string) (sign *Sign) { + sign = new(Sign) + buf := []byte(m) + // #nosec + C.blsSecretKeySignCT(sec.getPointer(), sign.getPointer(), (*C.char)(unsafe.Pointer(&buf[0])), C.size_t(len(buf))) + return sign +} // Add -- func (sign *Sign) Add(rhs *Sign) { @@ -70,6 +70,8 @@ func testSign() { verifyTrue(pubVec[i].String() == secVec[i].GetPublicKey().String()) signVec[i] = *secVec[i].Sign(m) + s := *secVec[i].SignCT(m) + verifyTrue(signVec[i] == s); verifyTrue(signVec[i].Verify(&pubVec[i], m)) } var sec1 blscgo.SecretKey diff --git a/include/bls.hpp b/include/bls.hpp index 28c6df6..2d6c313 100644 --- a/include/bls.hpp +++ b/include/bls.hpp @@ -119,6 +119,8 @@ public: void set(const uint64_t *p); void getPublicKey(PublicKey& pub) const; void sign(Sign& sign, const std::string& m) const; + // constant time sign + void signCT(Sign& sign, const std::string& m) const; /* make Pop(Proof of Possesion) pop = prv.sign(pub) diff --git a/include/bls_if.h b/include/bls_if.h index ce8463e..805ce10 100644 --- a/include/bls_if.h +++ b/include/bls_if.h @@ -77,6 +77,7 @@ void blsSecretKeyAdd(blsSecretKey *sec, const blsSecretKey *rhs); void blsSecretKeyInit(blsSecretKey *sec); void blsSecretKeyGetPublicKey(const blsSecretKey *sec, blsPublicKey *pub); void blsSecretKeySign(const blsSecretKey *sec, blsSign *sign, const char *m, size_t size); +void blsSecretKeySignCT(const blsSecretKey *sec, blsSign *sign, const char *m, size_t size); void blsSecretKeySet(blsSecretKey *sec, const blsSecretKey* msk, size_t k, const blsId *id); void blsSecretKeyRecover(blsSecretKey *sec, const blsSecretKey *secVec, const blsId *idVec, size_t n); void blsSecretKeyGetPop(const blsSecretKey *sec, blsSign *sign); diff --git a/src/bls.cpp b/src/bls.cpp index 8679ea5..6adc493 100644 --- a/src/bls.cpp +++ b/src/bls.cpp @@ -381,6 +381,13 @@ void SecretKey::sign(Sign& sign, const std::string& m) const HashAndMapToG1(Hm, m); G1::mul(sign.getInner().sHm, Hm, getInner().s); } +// constant time sign +void SecretKey::signCT(Sign& sign, const std::string& m) const +{ + G1 Hm; + HashAndMapToG1(Hm, m); + G1::mulCT(sign.getInner().sHm, Hm, getInner().s); +} void SecretKey::getPop(Sign& pop) const { diff --git a/src/bls_if.cpp b/src/bls_if.cpp index 8fd1a55..4080d70 100644 --- a/src/bls_if.cpp +++ b/src/bls_if.cpp @@ -134,6 +134,10 @@ void blsSecretKeySign(const blsSecretKey *sec, blsSign *sign, const char *m, siz { ((const bls::SecretKey*)sec)->sign(*(bls::Sign*)sign, std::string(m, size)); } +void blsSecretKeySignCT(const blsSecretKey *sec, blsSign *sign, const char *m, size_t size) +{ + ((const bls::SecretKey*)sec)->signCT(*(bls::Sign*)sign, std::string(m, size)); +} void blsSecretKeySet(blsSecretKey *sec, const blsSecretKey* msk, size_t k, const blsId *id) { |