aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMITSUNARI Shigeo <herumi@nifty.com>2016-09-08 15:24:03 +0800
committerMITSUNARI Shigeo <herumi@nifty.com>2016-09-08 15:24:03 +0800
commit102c9b797a89039b8f79f6727a017e2f4d5610b7 (patch)
tree7ebc2bf4be36a9eaaf647c24dfbf060fd796cf3c
parent1ada521ca01a12654337ce292b6c6e6f18a90580 (diff)
downloaddexon-bls-102c9b797a89039b8f79f6727a017e2f4d5610b7.tar
dexon-bls-102c9b797a89039b8f79f6727a017e2f4d5610b7.tar.gz
dexon-bls-102c9b797a89039b8f79f6727a017e2f4d5610b7.tar.bz2
dexon-bls-102c9b797a89039b8f79f6727a017e2f4d5610b7.tar.lz
dexon-bls-102c9b797a89039b8f79f6727a017e2f4d5610b7.tar.xz
dexon-bls-102c9b797a89039b8f79f6727a017e2f4d5610b7.tar.zst
dexon-bls-102c9b797a89039b8f79f6727a017e2f4d5610b7.zip
mask the top two bit of array for Id::set and SecretKey::set
-rw-r--r--src/bls.cpp4
-rw-r--r--test/bls_test.cpp24
2 files changed, 23 insertions, 5 deletions
diff --git a/src/bls.cpp b/src/bls.cpp
index a37834c..eb441fe 100644
--- a/src/bls.cpp
+++ b/src/bls.cpp
@@ -239,7 +239,7 @@ bool Id::isZero() const
void Id::set(const uint64_t *p)
{
- self_->v.setArray(p, keySize);
+ self_->v.setArrayMask(p, keySize);
}
Sign::Sign()
@@ -423,7 +423,7 @@ void SecretKey::init()
void SecretKey::set(const uint64_t *p)
{
- self_->s.setArray(p, keySize);
+ self_->s.setArrayMask(p, keySize);
}
void SecretKey::getPublicKey(PublicKey& pub) const
diff --git a/test/bls_test.cpp b/test/bls_test.cpp
index 9d3a7cb..013b242 100644
--- a/test/bls_test.cpp
+++ b/test/bls_test.cpp
@@ -49,13 +49,31 @@ CYBOZU_TEST_AUTO(id)
}
{
/*
- exception if the value >= r
+ mask value to be less than r if the value >= r
*/
- const uint64_t id1[] = { 0, 0, 0, uint64_t(-1) };
- CYBOZU_TEST_EXCEPTION(id.set(id1), std::exception);
+ const uint64_t tbl1[] = { 0, 0, 0, uint64_t(-1) };
+ id.set(tbl1);
+ const uint64_t tbl2[] = { 0, 0, 0, uint64_t(-1) & ((uint64_t(1) << 63) - 1) };
+ bls::Id id2;
+ id2.set(tbl2);
+ CYBOZU_TEST_EQUAL(id, id2);
}
}
+CYBOZU_TEST_AUTO(SecretKey_set)
+{
+ /*
+ mask value to be less than r if the value >= r
+ */
+ bls::SecretKey sec1, sec2;
+ const uint64_t tbl1[] = { 0, 0, 0, uint64_t(-1) };
+ sec1.set(tbl1);
+ const uint64_t tbl2[] = { 0, 0, 0, uint64_t(-1) & ((uint64_t(1) << 63) - 1) };
+ bls::Id expected;
+ sec2.set(tbl2);
+ CYBOZU_TEST_EQUAL(sec1, sec2);
+}
+
CYBOZU_TEST_AUTO(k_of_n)
{
const std::string m = "abc";