ffjavascript
Advanced tools
Comparing version 0.2.35 to 0.2.36
{ | ||
"name": "ffjavascript", | ||
"type": "module", | ||
"version": "0.2.35", | ||
"version": "0.2.36", | ||
"description": "Finite Field Library in Javascript", | ||
@@ -6,0 +6,0 @@ "main": "./build/main.cjs", |
@@ -64,6 +64,12 @@ | ||
if (firstPage == lastPage) | ||
return this.buffers[firstPage].set(buff, offset % PAGE_SIZE); | ||
if (firstPage == lastPage) { | ||
if ((buff instanceof BigBuffer)&&(buff.buffers.length==1)) { | ||
return this.buffers[firstPage].set(buff.buffers[0], offset % PAGE_SIZE); | ||
} else { | ||
return this.buffers[firstPage].set(buff, offset % PAGE_SIZE); | ||
} | ||
} | ||
let p = firstPage; | ||
@@ -70,0 +76,0 @@ let o = offset % PAGE_SIZE; |
@@ -71,2 +71,4 @@ import {log2, buffReverseBits} from "./utils.js"; | ||
returnArray = true; | ||
} else { | ||
buff = buff.slice(0, buff.byteLength); | ||
} | ||
@@ -73,0 +75,0 @@ |
@@ -37,2 +37,3 @@ | ||
n8 = n8 || buff.byteLength; | ||
o = o || 0; | ||
const v = new Uint32Array(buff.buffer, o, n8/4); | ||
@@ -47,2 +48,3 @@ const a = new Array(n8/4); | ||
n8 = n8 || buff.byteLength; | ||
o = o || 0; | ||
const v = new DataView(buff.buffer, buff.byteOffset + o, n8); | ||
@@ -49,0 +51,0 @@ const a = new Array(n8/4); |
@@ -298,2 +298,12 @@ | ||
isValid(a) { | ||
if (this.isZero(a)) return true; | ||
const F = this.F; | ||
const aa = this.toAffine(a); | ||
const x = aa.slice(0, this.F.n8); | ||
const y = aa.slice(this.F.n8, this.F.n8*2); | ||
const x3b = F.add(F.mul(F.square(x),x), this.b); | ||
const y2 = F.square(y); | ||
return F.eq(x3b, y2); | ||
} | ||
@@ -300,0 +310,0 @@ fromRng(rng) { |
@@ -1,3 +0,1 @@ | ||
import * as Scalar from "./scalar.js"; | ||
@@ -7,2 +5,3 @@ import * as utils from "./utils.js"; | ||
import buildBatchConvert from "./engine_batchconvert.js"; | ||
import BigBuffer from "./bigbuffer.js"; | ||
@@ -230,2 +229,12 @@ | ||
toRprBE(buff, offset, a) { | ||
const buff2 = this.fromMontgomery(a); | ||
for (let i=0; i<this.n8/2; i++) { | ||
const aux = buff2[i]; | ||
buff2[i] = buff2[this.n8-1-i]; | ||
buff2[this.n8-1-i] = aux; | ||
} | ||
buff.set(buff2, offset); | ||
} | ||
fromRprLE(buff, offset) { | ||
@@ -237,5 +246,58 @@ offset = offset || 0; | ||
async batchInverse(buffIn) { | ||
const sIn = this.n8; | ||
const sOut = this.n8; | ||
const nPoints = Math.floor(buffIn.byteLength / sIn); | ||
if ( nPoints * sIn !== buffIn.byteLength) { | ||
throw new Error("Invalid buffer size"); | ||
} | ||
const pointsPerChunk = Math.floor(nPoints/this.tm.concurrency); | ||
const opPromises = []; | ||
for (let i=0; i<this.tm.concurrency; i++) { | ||
let n; | ||
if (i< this.tm.concurrency-1) { | ||
n = pointsPerChunk; | ||
} else { | ||
n = nPoints - i*pointsPerChunk; | ||
} | ||
if (n==0) continue; | ||
const buffChunk = buffIn.slice(i*pointsPerChunk*sIn, i*pointsPerChunk*sIn + n*sIn); | ||
const task = [ | ||
{cmd: "ALLOCSET", var: 0, buff:buffChunk}, | ||
{cmd: "ALLOC", var: 1, len:sOut * n}, | ||
{cmd: "CALL", fnName: this.prefix + "_batchInverse", params: [ | ||
{var: 0}, | ||
{val: sIn}, | ||
{val: n}, | ||
{var: 1}, | ||
{val: sOut}, | ||
]}, | ||
{cmd: "GET", out: 0, var: 1, len:sOut * n}, | ||
]; | ||
opPromises.push( | ||
this.tm.queueAction(task) | ||
); | ||
} | ||
const result = await Promise.all(opPromises); | ||
let fullBuffOut; | ||
if (buffIn instanceof BigBuffer) { | ||
fullBuffOut = new BigBuffer(nPoints*sOut); | ||
} else { | ||
fullBuffOut = new Uint8Array(nPoints*sOut); | ||
} | ||
let p =0; | ||
for (let i=0; i<result.length; i++) { | ||
fullBuffOut.set(result[i][0], p); | ||
p+=result[i][0].byteLength; | ||
} | ||
return fullBuffOut; | ||
}; | ||
} | ||
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
434986
11813