]> zoso.dev Git - libnemo.git/commitdiff
Delete unused poly1305 function object and unused variables.
authorChris Duncan <chris@zoso.dev>
Mon, 25 Nov 2024 22:17:11 +0000 (14:17 -0800)
committerChris Duncan <chris@zoso.dev>
Mon, 25 Nov 2024 22:17:11 +0000 (14:17 -0800)
src/lib/workers/nacl-nano.ts

index 1c4eeeaec4bd5a513c795cc4b76894e79614335b..9c019e9c88c67313db9fbaad970714efb618bf99 100644 (file)
@@ -26,9 +26,6 @@ import blake2b from 'blake2b'
        //  Pluggable, initialized in high-level API below.\r
        var randombytes = function(/* x, n */) { throw new Error('no PRNG'); };\r
 \r
-       var _0 = new Uint8Array(16);\r
-       var _9 = new Uint8Array(32); _9[0] = 9;\r
-\r
        var gf0 = gf(),\r
                        gf1 = gf([1]),\r
                        D = gf([0x78a3, 0x1359, 0x4dca, 0x75eb, 0xd8ab, 0x4141, 0x0a4d, 0x0070, 0xe898, 0x7779, 0x4079, 0x8cc7, 0xfe73, 0x2b6f, 0x6cee, 0x5203]),\r
@@ -47,363 +44,6 @@ import blake2b from 'blake2b'
                return vn(x,xi,y,yi,32);\r
        }\r
 \r
-       /*\r
-       * Port of Andrew Moon's Poly1305-donna-16. Public domain.\r
-       * https://github.com/floodyberry/poly1305-donna\r
-       */\r
-\r
-       var poly1305 = function(key) {\r
-               this.buffer = new Uint8Array(16);\r
-               this.r = new Uint16Array(10);\r
-               this.h = new Uint16Array(10);\r
-               this.pad = new Uint16Array(8);\r
-               this.leftover = 0;\r
-               this.fin = 0;\r
-\r
-               var t0, t1, t2, t3, t4, t5, t6, t7;\r
-\r
-               t0 = key[ 0] & 0xff | (key[ 1] & 0xff) << 8; this.r[0] = ( t0                     ) & 0x1fff;\r
-               t1 = key[ 2] & 0xff | (key[ 3] & 0xff) << 8; this.r[1] = ((t0 >>> 13) | (t1 <<  3)) & 0x1fff;\r
-               t2 = key[ 4] & 0xff | (key[ 5] & 0xff) << 8; this.r[2] = ((t1 >>> 10) | (t2 <<  6)) & 0x1f03;\r
-               t3 = key[ 6] & 0xff | (key[ 7] & 0xff) << 8; this.r[3] = ((t2 >>>  7) | (t3 <<  9)) & 0x1fff;\r
-               t4 = key[ 8] & 0xff | (key[ 9] & 0xff) << 8; this.r[4] = ((t3 >>>  4) | (t4 << 12)) & 0x00ff;\r
-               this.r[5] = ((t4 >>>  1)) & 0x1ffe;\r
-               t5 = key[10] & 0xff | (key[11] & 0xff) << 8; this.r[6] = ((t4 >>> 14) | (t5 <<  2)) & 0x1fff;\r
-               t6 = key[12] & 0xff | (key[13] & 0xff) << 8; this.r[7] = ((t5 >>> 11) | (t6 <<  5)) & 0x1f81;\r
-               t7 = key[14] & 0xff | (key[15] & 0xff) << 8; this.r[8] = ((t6 >>>  8) | (t7 <<  8)) & 0x1fff;\r
-               this.r[9] = ((t7 >>>  5)) & 0x007f;\r
-\r
-               this.pad[0] = key[16] & 0xff | (key[17] & 0xff) << 8;\r
-               this.pad[1] = key[18] & 0xff | (key[19] & 0xff) << 8;\r
-               this.pad[2] = key[20] & 0xff | (key[21] & 0xff) << 8;\r
-               this.pad[3] = key[22] & 0xff | (key[23] & 0xff) << 8;\r
-               this.pad[4] = key[24] & 0xff | (key[25] & 0xff) << 8;\r
-               this.pad[5] = key[26] & 0xff | (key[27] & 0xff) << 8;\r
-               this.pad[6] = key[28] & 0xff | (key[29] & 0xff) << 8;\r
-               this.pad[7] = key[30] & 0xff | (key[31] & 0xff) << 8;\r
-       };\r
-\r
-       poly1305.prototype.blocks = function(m, mpos, bytes) {\r
-               var hibit = this.fin ? 0 : (1 << 11);\r
-               var t0, t1, t2, t3, t4, t5, t6, t7, c;\r
-               var d0, d1, d2, d3, d4, d5, d6, d7, d8, d9;\r
-\r
-               var h0 = this.h[0],\r
-                               h1 = this.h[1],\r
-                               h2 = this.h[2],\r
-                               h3 = this.h[3],\r
-                               h4 = this.h[4],\r
-                               h5 = this.h[5],\r
-                               h6 = this.h[6],\r
-                               h7 = this.h[7],\r
-                               h8 = this.h[8],\r
-                               h9 = this.h[9];\r
-\r
-               var r0 = this.r[0],\r
-                               r1 = this.r[1],\r
-                               r2 = this.r[2],\r
-                               r3 = this.r[3],\r
-                               r4 = this.r[4],\r
-                               r5 = this.r[5],\r
-                               r6 = this.r[6],\r
-                               r7 = this.r[7],\r
-                               r8 = this.r[8],\r
-                               r9 = this.r[9];\r
-\r
-               while (bytes >= 16) {\r
-                       t0 = m[mpos+ 0] & 0xff | (m[mpos+ 1] & 0xff) << 8; h0 += ( t0                     ) & 0x1fff;\r
-                       t1 = m[mpos+ 2] & 0xff | (m[mpos+ 3] & 0xff) << 8; h1 += ((t0 >>> 13) | (t1 <<  3)) & 0x1fff;\r
-                       t2 = m[mpos+ 4] & 0xff | (m[mpos+ 5] & 0xff) << 8; h2 += ((t1 >>> 10) | (t2 <<  6)) & 0x1fff;\r
-                       t3 = m[mpos+ 6] & 0xff | (m[mpos+ 7] & 0xff) << 8; h3 += ((t2 >>>  7) | (t3 <<  9)) & 0x1fff;\r
-                       t4 = m[mpos+ 8] & 0xff | (m[mpos+ 9] & 0xff) << 8; h4 += ((t3 >>>  4) | (t4 << 12)) & 0x1fff;\r
-                       h5 += ((t4 >>>  1)) & 0x1fff;\r
-                       t5 = m[mpos+10] & 0xff | (m[mpos+11] & 0xff) << 8; h6 += ((t4 >>> 14) | (t5 <<  2)) & 0x1fff;\r
-                       t6 = m[mpos+12] & 0xff | (m[mpos+13] & 0xff) << 8; h7 += ((t5 >>> 11) | (t6 <<  5)) & 0x1fff;\r
-                       t7 = m[mpos+14] & 0xff | (m[mpos+15] & 0xff) << 8; h8 += ((t6 >>>  8) | (t7 <<  8)) & 0x1fff;\r
-                       h9 += ((t7 >>> 5)) | hibit;\r
-\r
-                       c = 0;\r
-\r
-                       d0 = c;\r
-                       d0 += h0 * r0;\r
-                       d0 += h1 * (5 * r9);\r
-                       d0 += h2 * (5 * r8);\r
-                       d0 += h3 * (5 * r7);\r
-                       d0 += h4 * (5 * r6);\r
-                       c = (d0 >>> 13); d0 &= 0x1fff;\r
-                       d0 += h5 * (5 * r5);\r
-                       d0 += h6 * (5 * r4);\r
-                       d0 += h7 * (5 * r3);\r
-                       d0 += h8 * (5 * r2);\r
-                       d0 += h9 * (5 * r1);\r
-                       c += (d0 >>> 13); d0 &= 0x1fff;\r
-\r
-                       d1 = c;\r
-                       d1 += h0 * r1;\r
-                       d1 += h1 * r0;\r
-                       d1 += h2 * (5 * r9);\r
-                       d1 += h3 * (5 * r8);\r
-                       d1 += h4 * (5 * r7);\r
-                       c = (d1 >>> 13); d1 &= 0x1fff;\r
-                       d1 += h5 * (5 * r6);\r
-                       d1 += h6 * (5 * r5);\r
-                       d1 += h7 * (5 * r4);\r
-                       d1 += h8 * (5 * r3);\r
-                       d1 += h9 * (5 * r2);\r
-                       c += (d1 >>> 13); d1 &= 0x1fff;\r
-\r
-                       d2 = c;\r
-                       d2 += h0 * r2;\r
-                       d2 += h1 * r1;\r
-                       d2 += h2 * r0;\r
-                       d2 += h3 * (5 * r9);\r
-                       d2 += h4 * (5 * r8);\r
-                       c = (d2 >>> 13); d2 &= 0x1fff;\r
-                       d2 += h5 * (5 * r7);\r
-                       d2 += h6 * (5 * r6);\r
-                       d2 += h7 * (5 * r5);\r
-                       d2 += h8 * (5 * r4);\r
-                       d2 += h9 * (5 * r3);\r
-                       c += (d2 >>> 13); d2 &= 0x1fff;\r
-\r
-                       d3 = c;\r
-                       d3 += h0 * r3;\r
-                       d3 += h1 * r2;\r
-                       d3 += h2 * r1;\r
-                       d3 += h3 * r0;\r
-                       d3 += h4 * (5 * r9);\r
-                       c = (d3 >>> 13); d3 &= 0x1fff;\r
-                       d3 += h5 * (5 * r8);\r
-                       d3 += h6 * (5 * r7);\r
-                       d3 += h7 * (5 * r6);\r
-                       d3 += h8 * (5 * r5);\r
-                       d3 += h9 * (5 * r4);\r
-                       c += (d3 >>> 13); d3 &= 0x1fff;\r
-\r
-                       d4 = c;\r
-                       d4 += h0 * r4;\r
-                       d4 += h1 * r3;\r
-                       d4 += h2 * r2;\r
-                       d4 += h3 * r1;\r
-                       d4 += h4 * r0;\r
-                       c = (d4 >>> 13); d4 &= 0x1fff;\r
-                       d4 += h5 * (5 * r9);\r
-                       d4 += h6 * (5 * r8);\r
-                       d4 += h7 * (5 * r7);\r
-                       d4 += h8 * (5 * r6);\r
-                       d4 += h9 * (5 * r5);\r
-                       c += (d4 >>> 13); d4 &= 0x1fff;\r
-\r
-                       d5 = c;\r
-                       d5 += h0 * r5;\r
-                       d5 += h1 * r4;\r
-                       d5 += h2 * r3;\r
-                       d5 += h3 * r2;\r
-                       d5 += h4 * r1;\r
-                       c = (d5 >>> 13); d5 &= 0x1fff;\r
-                       d5 += h5 * r0;\r
-                       d5 += h6 * (5 * r9);\r
-                       d5 += h7 * (5 * r8);\r
-                       d5 += h8 * (5 * r7);\r
-                       d5 += h9 * (5 * r6);\r
-                       c += (d5 >>> 13); d5 &= 0x1fff;\r
-\r
-                       d6 = c;\r
-                       d6 += h0 * r6;\r
-                       d6 += h1 * r5;\r
-                       d6 += h2 * r4;\r
-                       d6 += h3 * r3;\r
-                       d6 += h4 * r2;\r
-                       c = (d6 >>> 13); d6 &= 0x1fff;\r
-                       d6 += h5 * r1;\r
-                       d6 += h6 * r0;\r
-                       d6 += h7 * (5 * r9);\r
-                       d6 += h8 * (5 * r8);\r
-                       d6 += h9 * (5 * r7);\r
-                       c += (d6 >>> 13); d6 &= 0x1fff;\r
-\r
-                       d7 = c;\r
-                       d7 += h0 * r7;\r
-                       d7 += h1 * r6;\r
-                       d7 += h2 * r5;\r
-                       d7 += h3 * r4;\r
-                       d7 += h4 * r3;\r
-                       c = (d7 >>> 13); d7 &= 0x1fff;\r
-                       d7 += h5 * r2;\r
-                       d7 += h6 * r1;\r
-                       d7 += h7 * r0;\r
-                       d7 += h8 * (5 * r9);\r
-                       d7 += h9 * (5 * r8);\r
-                       c += (d7 >>> 13); d7 &= 0x1fff;\r
-\r
-                       d8 = c;\r
-                       d8 += h0 * r8;\r
-                       d8 += h1 * r7;\r
-                       d8 += h2 * r6;\r
-                       d8 += h3 * r5;\r
-                       d8 += h4 * r4;\r
-                       c = (d8 >>> 13); d8 &= 0x1fff;\r
-                       d8 += h5 * r3;\r
-                       d8 += h6 * r2;\r
-                       d8 += h7 * r1;\r
-                       d8 += h8 * r0;\r
-                       d8 += h9 * (5 * r9);\r
-                       c += (d8 >>> 13); d8 &= 0x1fff;\r
-\r
-                       d9 = c;\r
-                       d9 += h0 * r9;\r
-                       d9 += h1 * r8;\r
-                       d9 += h2 * r7;\r
-                       d9 += h3 * r6;\r
-                       d9 += h4 * r5;\r
-                       c = (d9 >>> 13); d9 &= 0x1fff;\r
-                       d9 += h5 * r4;\r
-                       d9 += h6 * r3;\r
-                       d9 += h7 * r2;\r
-                       d9 += h8 * r1;\r
-                       d9 += h9 * r0;\r
-                       c += (d9 >>> 13); d9 &= 0x1fff;\r
-\r
-                       c = (((c << 2) + c)) | 0;\r
-                       c = (c + d0) | 0;\r
-                       d0 = c & 0x1fff;\r
-                       c = (c >>> 13);\r
-                       d1 += c;\r
-\r
-                       h0 = d0;\r
-                       h1 = d1;\r
-                       h2 = d2;\r
-                       h3 = d3;\r
-                       h4 = d4;\r
-                       h5 = d5;\r
-                       h6 = d6;\r
-                       h7 = d7;\r
-                       h8 = d8;\r
-                       h9 = d9;\r
-\r
-                       mpos += 16;\r
-                       bytes -= 16;\r
-               }\r
-               this.h[0] = h0;\r
-               this.h[1] = h1;\r
-               this.h[2] = h2;\r
-               this.h[3] = h3;\r
-               this.h[4] = h4;\r
-               this.h[5] = h5;\r
-               this.h[6] = h6;\r
-               this.h[7] = h7;\r
-               this.h[8] = h8;\r
-               this.h[9] = h9;\r
-       };\r
-\r
-       poly1305.prototype.finish = function(mac, macpos) {\r
-               var g = new Uint16Array(10);\r
-               var c, mask, f, i;\r
-\r
-               if (this.leftover) {\r
-                       i = this.leftover;\r
-                       this.buffer[i++] = 1;\r
-                       for (; i < 16; i++) this.buffer[i] = 0;\r
-                       this.fin = 1;\r
-                       this.blocks(this.buffer, 0, 16);\r
-               }\r
-\r
-               c = this.h[1] >>> 13;\r
-               this.h[1] &= 0x1fff;\r
-               for (i = 2; i < 10; i++) {\r
-                       this.h[i] += c;\r
-                       c = this.h[i] >>> 13;\r
-                       this.h[i] &= 0x1fff;\r
-               }\r
-               this.h[0] += (c * 5);\r
-               c = this.h[0] >>> 13;\r
-               this.h[0] &= 0x1fff;\r
-               this.h[1] += c;\r
-               c = this.h[1] >>> 13;\r
-               this.h[1] &= 0x1fff;\r
-               this.h[2] += c;\r
-\r
-               g[0] = this.h[0] + 5;\r
-               c = g[0] >>> 13;\r
-               g[0] &= 0x1fff;\r
-               for (i = 1; i < 10; i++) {\r
-                       g[i] = this.h[i] + c;\r
-                       c = g[i] >>> 13;\r
-                       g[i] &= 0x1fff;\r
-               }\r
-               g[9] -= (1 << 13);\r
-\r
-               mask = (c ^ 1) - 1;\r
-               for (i = 0; i < 10; i++) g[i] &= mask;\r
-               mask = ~mask;\r
-               for (i = 0; i < 10; i++) this.h[i] = (this.h[i] & mask) | g[i];\r
-\r
-               this.h[0] = ((this.h[0]       ) | (this.h[1] << 13)                    ) & 0xffff;\r
-               this.h[1] = ((this.h[1] >>>  3) | (this.h[2] << 10)                    ) & 0xffff;\r
-               this.h[2] = ((this.h[2] >>>  6) | (this.h[3] <<  7)                    ) & 0xffff;\r
-               this.h[3] = ((this.h[3] >>>  9) | (this.h[4] <<  4)                    ) & 0xffff;\r
-               this.h[4] = ((this.h[4] >>> 12) | (this.h[5] <<  1) | (this.h[6] << 14)) & 0xffff;\r
-               this.h[5] = ((this.h[6] >>>  2) | (this.h[7] << 11)                    ) & 0xffff;\r
-               this.h[6] = ((this.h[7] >>>  5) | (this.h[8] <<  8)                    ) & 0xffff;\r
-               this.h[7] = ((this.h[8] >>>  8) | (this.h[9] <<  5)                    ) & 0xffff;\r
-\r
-               f = this.h[0] + this.pad[0];\r
-               this.h[0] = f & 0xffff;\r
-               for (i = 1; i < 8; i++) {\r
-                       f = (((this.h[i] + this.pad[i]) | 0) + (f >>> 16)) | 0;\r
-                       this.h[i] = f & 0xffff;\r
-               }\r
-\r
-               mac[macpos+ 0] = (this.h[0] >>> 0) & 0xff;\r
-               mac[macpos+ 1] = (this.h[0] >>> 8) & 0xff;\r
-               mac[macpos+ 2] = (this.h[1] >>> 0) & 0xff;\r
-               mac[macpos+ 3] = (this.h[1] >>> 8) & 0xff;\r
-               mac[macpos+ 4] = (this.h[2] >>> 0) & 0xff;\r
-               mac[macpos+ 5] = (this.h[2] >>> 8) & 0xff;\r
-               mac[macpos+ 6] = (this.h[3] >>> 0) & 0xff;\r
-               mac[macpos+ 7] = (this.h[3] >>> 8) & 0xff;\r
-               mac[macpos+ 8] = (this.h[4] >>> 0) & 0xff;\r
-               mac[macpos+ 9] = (this.h[4] >>> 8) & 0xff;\r
-               mac[macpos+10] = (this.h[5] >>> 0) & 0xff;\r
-               mac[macpos+11] = (this.h[5] >>> 8) & 0xff;\r
-               mac[macpos+12] = (this.h[6] >>> 0) & 0xff;\r
-               mac[macpos+13] = (this.h[6] >>> 8) & 0xff;\r
-               mac[macpos+14] = (this.h[7] >>> 0) & 0xff;\r
-               mac[macpos+15] = (this.h[7] >>> 8) & 0xff;\r
-       };\r
-\r
-       poly1305.prototype.update = function(m, mpos, bytes) {\r
-               var i, want;\r
-\r
-               if (this.leftover) {\r
-                       want = (16 - this.leftover);\r
-                       if (want > bytes)\r
-                               want = bytes;\r
-                       for (i = 0; i < want; i++)\r
-                               this.buffer[this.leftover + i] = m[mpos+i];\r
-                       bytes -= want;\r
-                       mpos += want;\r
-                       this.leftover += want;\r
-                       if (this.leftover < 16)\r
-                               return;\r
-                       this.blocks(this.buffer, 0, 16);\r
-                       this.leftover = 0;\r
-               }\r
-\r
-               if (bytes >= 16) {\r
-                       want = bytes - (bytes % 16);\r
-                       this.blocks(m, mpos, want);\r
-                       mpos += want;\r
-                       bytes -= want;\r
-               }\r
-\r
-               if (bytes) {\r
-                       for (i = 0; i < bytes; i++)\r
-                               this.buffer[this.leftover + i] = m[mpos+i];\r
-                       this.leftover += bytes;\r
-               }\r
-       };\r
-\r
        function set25519(r, a) {\r
                var i;\r
                for (i = 0; i < 16; i++) r[i] = a[i]|0;\r