aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMITSUNARI Shigeo <herumi@nifty.com>2017-10-10 16:01:38 +0800
committerMITSUNARI Shigeo <herumi@nifty.com>2017-10-10 16:01:38 +0800
commit31cdd3294f352f94f6f6c699372f8fcb9015b245 (patch)
tree0d1cf02300ca4ffefc55f3a204e347cff03ad4ae
parent8f1d217f654ee9e8e4cf769e0140e3c511a9fdaf (diff)
downloaddexon-bls-31cdd3294f352f94f6f6c699372f8fcb9015b245.tar
dexon-bls-31cdd3294f352f94f6f6c699372f8fcb9015b245.tar.gz
dexon-bls-31cdd3294f352f94f6f6c699372f8fcb9015b245.tar.bz2
dexon-bls-31cdd3294f352f94f6f6c699372f8fcb9015b245.tar.lz
dexon-bls-31cdd3294f352f94f6f6c699372f8fcb9015b245.tar.xz
dexon-bls-31cdd3294f352f94f6f6c699372f8fcb9015b245.tar.zst
dexon-bls-31cdd3294f352f94f6f6c699372f8fcb9015b245.zip
[js] add SecretKey.setByCSPRNG
-rw-r--r--docs/demo/bls-demo.js3
-rw-r--r--docs/demo/bls.html1
-rw-r--r--docs/demo/bls.js51
3 files changed, 38 insertions, 17 deletions
diff --git a/docs/demo/bls-demo.js b/docs/demo/bls-demo.js
index cd5f8e9..e656902 100644
--- a/docs/demo/bls-demo.js
+++ b/docs/demo/bls-demo.js
@@ -79,6 +79,9 @@ function benchPairing() {
mcl_free(Q)
mcl_free(P)
mcl_free(a)
+
+ let sec = new BlsSecretKey()
+ bench('time_setByCSPRNG', 50, () => sec.setByCSPRNG())
}
function benchBls() {
diff --git a/docs/demo/bls.html b/docs/demo/bls.html
index 3f6ae74..9c68d62 100644
--- a/docs/demo/bls.html
+++ b/docs/demo/bls.html
@@ -23,6 +23,7 @@ library status <span name="status">initializing...</span>
<div>group order : <span name="curveOrder">0</span></div>
</p>
<button type="text" id="benchmark" onclick="onClickBenchmark()">benchmark</button>
+<div>setByCSPRNG time : <span name="time_setByCSPRNG">0</span>msec</div>
<div>pairing time : <span name="time_pairing">0</span>msec</div>
<div>G1 scalar mul : <span name="time_g1mul">0</span>msec</div>
<div>G2 scalar mul : <span name="time_g2mul">0</span>msec</div>
diff --git a/docs/demo/bls.js b/docs/demo/bls.js
index 9b2433c..20ea3a0 100644
--- a/docs/demo/bls.js
+++ b/docs/demo/bls.js
@@ -241,69 +241,86 @@ function define_bls_extra_functions(mod) {
blsPublicKeyRecover = wrap_recover(_blsPublicKeyRecover, BLS_PUBLICKEY_SIZE, BLS_ID_SIZE)
blsSignatureRecover = wrap_recover(_blsSignatureRecover, BLS_SIGNATURE_SIZE, BLS_ID_SIZE)
- var copyToUint32Array = function(a, pos) {
+ let crypto = window.crypto || window.msCrypto
+
+ let copyToUint32Array = function(a, pos) {
for (let i = 0; i < a.length; i++) {
a[i] = mod.HEAP32[pos / 4 + i]
}
}
- var callSetter1 = function(func, a, p1) {
+ let callSetter = function(func, a, p1, p2) {
let pos = mod._malloc(a.length * 4)
- mod.HEAP32.set(a, pos / 4)
- func(pos, p1)
+ func(pos, p1, p2) // p1, p2 may be undefined
copyToUint32Array(a, pos)
mod._free(pos)
}
- var callGetter0 = function(func, a) {
+ let callGetter = function(func, a, p1, p2) {
let pos = mod._malloc(a.length * 4)
mod.HEAP32.set(a, pos / 4)
- let s = func(pos)
+ let s = func(pos, p1, p2)
mod._free(pos)
return s
}
+ let callModifier = function(func, a, p1, p2) {
+ let pos = mod._malloc(a.length * 4)
+ mod.HEAP32.set(a, pos / 4)
+ func(pos, p1, p2) // p1, p2 may be undefined
+ copyToUint32Array(a, pos)
+ mod._free(pos)
+ }
/// BlsId
BlsId.prototype.setInt = function(x) {
- callSetter1(blsIdSetInt, this.a_, x)
+ callSetter(blsIdSetInt, this.a_, x)
}
BlsId.prototype.setStr = function(s, base = 10) {
switch (base) {
case 10:
- callSetter1(blsIdSetDecStr, this.a_, s)
+ callSetter(blsIdSetDecStr, this.a_, s)
return
case 16:
- callSetter1(blsIdSetHexStr, this.a_, s)
+ callSetter(blsIdSetHexStr, this.a_, s)
return
default:
throw('BlsId.setStr:bad base:' + base)
}
}
BlsId.prototype.deserialize = function(s) {
- callSetter1(blsIdDeserialize, this.a_, s)
+ callSetter(blsIdDeserialize, this.a_, s)
}
BlsId.prototype.getStr = function(base = 10) {
switch (base) {
case 10:
- return callGetter0(blsIdGetDecStr, this.a_)
+ return callGetter(blsIdGetDecStr, this.a_)
case 16:
- return callGetter0(blsIdGetHexStr, this.a_)
+ return callGetter(blsIdGetHexStr, this.a_)
default:
throw('BlsId.getStr:bad base:' + base)
}
}
BlsId.prototype.serialize = function() {
- return callGetter0(blsIdSerialize, this.a_)
+ return callGetter(blsIdSerialize, this.a_)
}
/// BlsSecretKey
BlsSecretKey.prototype.setInt = function(x) {
- callSetter1(blsIdSetInt, this.a_, x) // same as Id
+ callSetter(blsIdSetInt, this.a_, x) // same as Id
}
BlsSecretKey.prototype.deserialize = function(s) {
- callSetter1(blsSecretKeyDeserialize, this.a_, s)
+ callSetter(blsSecretKeyDeserialize, this.a_, s)
}
BlsSecretKey.prototype.setLittleEndian = function(s) {
- callSetter1(blsSecretKeySetLittleEndian, this.a_, s)
+ callSetter(blsSecretKeySetLittleEndian, this.a_, s)
}
BlsSecretKey.prototype.serialize = function() {
- return callGetter0(blsSecretKeySerialize, this.a_)
+ return callGetter(blsSecretKeySerialize, this.a_)
+ }
+ BlsSecretKey.prototype.setHashOf = function(s) {
+ callSetter(blsHashToSecretKey, this.a_, s)
+ }
+ BlsSecretKey.prototype.setByCSPRNG = function() {
+ let a = new Uint8Array(BLS_SECRETKEY_SIZE)
+ crypto.getRandomValues(a)
+ this.setLittleEndian(a)
+// callSetter(blsSecretKeySetByCSPRNG, this.a_)
}
}