Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
_testRandom2() {
this.setState({randombytes_buf:null})
let freq = [];
for (i = 0; i < 256; ++i) freq[i] = 0;
Sodium.randombytes_buf(20*256).then((value) => {
let a = Base64.toByteArray(value)
for (i = 0; i < a.length; ++i) ++freq[a[i]]
var fail = false
for (i = 0; i < 256 && !fail; ++i) if (!freq[i]) fail = true
this.setState({randombytes_buf:!fail})
})
}
Promise.all([Sodium.crypto_box_keypair(),Sodium.crypto_box_keypair()]).then(([alice,bob]) => {
let p = []
for (mlen = 0; mlen <= mlen_max; mlen++) {
p.push(
Promise.all([
Sodium.randombytes_buf(Sodium.crypto_box_NONCEBYTES),
Sodium.randombytes_buf(mlen)
]).then(([n,m]) =>
Sodium.crypto_box_easy(m,n,bob.pk,alice.sk)
.then((c) => Sodium.crypto_box_open_easy(c,n,alice.pk,bob.sk))
.then((mm) => mm === m))
)
}
Promise.all(p).then((pr) => {
let fail = false
for (i = 0; i < pr.length && !fail; ++i) if (!pr[i]) fail = true
this.setState({crypto_box1:!fail})
})
})
}