diff options
author | MITSUNARI Shigeo <herumi@nifty.com> | 2017-06-14 05:55:51 +0800 |
---|---|---|
committer | MITSUNARI Shigeo <herumi@nifty.com> | 2017-06-14 05:55:51 +0800 |
commit | f84c000e102ed889a607a63819e305798359418a (patch) | |
tree | 1e62d4f6cf93399d03bca29bc5dfd4de6324617a | |
parent | 4bd6d96b71964c06fa710e591ee96e8c0282c1a9 (diff) | |
download | dexon-bls-f84c000e102ed889a607a63819e305798359418a.tar dexon-bls-f84c000e102ed889a607a63819e305798359418a.tar.gz dexon-bls-f84c000e102ed889a607a63819e305798359418a.tar.bz2 dexon-bls-f84c000e102ed889a607a63819e305798359418a.tar.lz dexon-bls-f84c000e102ed889a607a63819e305798359418a.tar.xz dexon-bls-f84c000e102ed889a607a63819e305798359418a.tar.zst dexon-bls-f84c000e102ed889a607a63819e305798359418a.zip |
add blsDHKeyExchange
-rw-r--r-- | go/bls/bls.go | 6 | ||||
-rw-r--r-- | go/bls/bls_test.go | 14 | ||||
-rw-r--r-- | include/bls/bls.h | 5 | ||||
-rw-r--r-- | src/bls_c.cpp | 5 |
4 files changed, 30 insertions, 0 deletions
diff --git a/go/bls/bls.go b/go/bls/bls.go index 2812697..61a96f5 100644 --- a/go/bls/bls.go +++ b/go/bls/bls.go @@ -288,3 +288,9 @@ func (sign *Sign) Verify(pub *PublicKey, m string) bool { func (sign *Sign) VerifyPop(pub *PublicKey) bool { return C.blsVerifyPop(sign.getPointer(), pub.getPointer()) == 1 } + +// DHKeyExchange -- +func DHKeyExchange(sec *SecretKey, pub *PublicKey) (out PublicKey) { + C.blsDHKeyExchange(out.getPointer(), sec.getPointer(), pub.getPointer()) + return out +} diff --git a/go/bls/bls_test.go b/go/bls/bls_test.go index 31f7f8a..998dd1f 100644 --- a/go/bls/bls_test.go +++ b/go/bls/bls_test.go @@ -305,6 +305,19 @@ func testOrder(t *testing.T, c int) { } } +func testDHKeyExchange(t *testing.T) { + var sec1, sec2 SecretKey + sec1.SetByCSPRNG() + sec2.SetByCSPRNG() + pub1 := sec1.GetPublicKey() + pub2 := sec2.GetPublicKey() + out1 := DHKeyExchange(&sec1, pub2) + out2 := DHKeyExchange(&sec2, pub1) + if !out1.IsEqual(&out2) { + t.Errorf("DH key is not equal") + } +} + func test(t *testing.T, c int) { err := Init(c) if err != nil { @@ -321,6 +334,7 @@ func test(t *testing.T, c int) { testData(t) testStringConversion(t) testOrder(t, c) + testDHKeyExchange(t) } func TestMain(t *testing.T) { diff --git a/include/bls/bls.h b/include/bls/bls.h index 37c337d..a56120c 100644 --- a/include/bls/bls.h +++ b/include/bls/bls.h @@ -170,6 +170,11 @@ BLS_DLL_API size_t blsPublicKeyGetHexStr(char *buf, size_t maxBufSize, const bls BLS_DLL_API int blsSignatureSetHexStr(blsSignature *sig, const char *buf, size_t bufSize); BLS_DLL_API size_t blsSignatureGetHexStr(char *buf, size_t maxBufSize, const blsSignature *sig); +/* + Diffie Hellman key exchange + out = sec * pub +*/ +BLS_DLL_API void blsDHKeyExchange(blsPublicKey *out, const blsSecretKey *sec, const blsPublicKey *pub); #ifdef __cplusplus } #endif diff --git a/src/bls_c.cpp b/src/bls_c.cpp index 27cf226..64ff5bc 100644 --- a/src/bls_c.cpp +++ b/src/bls_c.cpp @@ -391,3 +391,8 @@ size_t blsSignatureGetHexStr(char *buf, size_t maxBufSize, const blsSignature *s { return mclBnG1_getStr(buf, maxBufSize, &sig->v, 16); } +void blsDHKeyExchange(blsPublicKey *out, const blsSecretKey *sec, const blsPublicKey *pub) +{ + mclBnG2_mul(&out->v, &pub->v, &sec->v); +} + |