0

From the JavaScript documentation we see that, due to using double-precision floating-point format numbers, to go beyond 9007199254740991 a library is needed. We'll find a handy list of libraries to achieve that here.


While searching on homomorphic encryption I came across this question.
There you can find this link to an in-browser implementation of Pailler. After inspecting the code I saw the source included jsbn.js which made total sense (as you are gonna need BigInts for the crypto). However, the way it deals with the numbers to be encrypted looked a bit odd to me.

$('#btn_encrypt').click(function(event) {
      var valA = parseInt($('#inputA').val()),
        valB = parseInt($('#inputB').val()),
        startTime,
        elapsed;
      startTime = new Date().getTime();
      encA = keys.pub.encrypt(nbv(valA));
      elapsed = new Date().getTime() - startTime;
      $('#encA').html(encA.toString());
      $('#encAtime').html(elapsed);

From using parseInt and nbv function nbv(i) { var r = nbi(); r.fromInt(i); return r; } it seems clear that they are relying on integers to create the BigInt that will then be encrypted. Does that make any sense at all? Even less so when having a function to create BigInts directly from strings
// (protected) set from string and radix function bnpFromString(s,b) {
...
}
That link has been referenced in several other answers both in here, and the crypto site and as I said I am a newbie at JS so I wanted to check whether this is indeed an contraindicated way of implementing Pailler or I have understood something wrong. Thanks a lot for helping out!

Community
  • 1
  • 1
Alvai
  • 23
  • 1
  • 7
  • Btw, feel free to edit my question for clarity, I would like to get a grip on how to properly ask. – Alvai Dec 11 '16 at 02:16
  • Your question is almost un-readable due to formatting problems, typos, and grammar. I'd recommend to spend a bit of time to re-format your question. You can use apostrophes to have inline source code: `return bigint` – bman Dec 11 '16 at 03:07
  • Tnx for the input, hope it is better now. – Alvai Dec 11 '16 at 14:23

1 Answers1

1

It appears that the Pailler implementation you linked to is intended as a proof-of-concept demo rather than as a full-fledged implementation. Presumably, the author intended it for use only on toy examples such as (36+14)*7 or (97+5)*11 rather than "real" examples involving hundreds of digits.

Robert Lozyniak
  • 322
  • 1
  • 7
  • Yeap I fully agree with you there @Robert, at first sight I though it would be really easy just using instead function `bnpFromString(s,b)` on the input string directly. But then there are some scoping problems.Namely it uses `this.fromRadix(s,b)` inside that function which prompts an error since the former is in jsbn.js and the latter in jsbn2.js. Neither work plugging `.fromRadix` in jsbn.js since then calls like `this.fromInt(0)` prompt an error despite having `BigInteger.prototype.fromInt = bnpFromInt` at the end of the file.P.S:Sorry I could not upvote your answer since my rep is 0. – Alvai Dec 11 '16 at 14:45