Skip to content

Commit

Permalink
Merge pull request iden3#61 from 0xtsukino/ensure-buffer
Browse files Browse the repository at this point in the history
ensure leInt2Buff return Buffer
  • Loading branch information
jbaylina authored Sep 24, 2021
2 parents e387ad8 + 9b8afa4 commit 32ce547
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/eddsa.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ exports.unpackSignature = unpackSignature;
exports.pruneBuffer = pruneBuffer;


function ensureBuffer(_buff) {
if (Buffer.isBuffer(_buff)) return buff;
return Buffer.from(_buff);
}

function pruneBuffer(_buff) {
const buff = Buffer.from(_buff);
buff[0] = buff[0] & 0xF8;
Expand Down Expand Up @@ -66,7 +71,7 @@ function signMiMC(prv, msg) {
const s = utils.leBuff2int(sBuff);
const A = babyJub.mulPointEscalar(babyJub.Base8, Scalar.shr(s, 3));

const msgBuff = utils.leInt2Buff(msg, 32);
const msgBuff = ensureBuffer(utils.leInt2Buff(msg, 32));
const rBuff = createBlakeHash("blake512").update(Buffer.concat([h1.slice(32,64), msgBuff])).digest();
let r = utils.leBuff2int(rBuff);
const Fr = new F1Field(babyJub.subOrder);
Expand All @@ -86,7 +91,7 @@ function signMiMCSponge(prv, msg) {
const s = utils.leBuff2int(sBuff);
const A = babyJub.mulPointEscalar(babyJub.Base8, Scalar.shr(s, 3));

const msgBuff = utils.leInt2Buff(msg, 32);
const msgBuff = ensureBuffer(utils.leInt2Buff(msg, 32));
const rBuff = createBlakeHash("blake512").update(Buffer.concat([h1.slice(32,64), msgBuff])).digest();
let r = utils.leBuff2int(rBuff);
const Fr = new F1Field(babyJub.subOrder);
Expand All @@ -106,7 +111,7 @@ function signPoseidon(prv, msg) {
const s = utils.leBuff2int(sBuff);
const A = babyJub.mulPointEscalar(babyJub.Base8, Scalar.shr(s, 3));

const msgBuff = utils.leInt2Buff(msg, 32);
const msgBuff = ensureBuffer(utils.leInt2Buff(msg, 32));
const rBuff = createBlakeHash("blake512").update(Buffer.concat([h1.slice(32,64), msgBuff])).digest();
let r = utils.leBuff2int(rBuff);
const Fr = new F1Field(babyJub.subOrder);
Expand Down

0 comments on commit 32ce547

Please sign in to comment.