Browse Source

add ed2curve to lib

english
Ev Bogue 3 years ago
parent
commit
e73ba7b9c6
  1. 1
      lib/ed2curve.min.js

1
lib/ed2curve.min.js vendored

@ -0,0 +1 @@
!function(r,n){"use strict";"undefined"!=typeof module&&module.exports?module.exports=n(require("tweetnacl")):r.ed2curve=n(r.nacl)}(this,function(r){"use strict";function n(r){var n,o;for(o=0;o<16;o++)r[o]+=65536,n=Math.floor(r[o]/65536),r[(o+1)*(o<15?1:0)]+=n-1+37*(n-1)*(15===o?1:0),r[o]-=65536*n}function o(r,n,o){for(var t,e=~(o-1),f=0;f<16;f++)t=e&(r[f]^n[f]),r[f]^=t,n[f]^=t}function t(r,n){var o;for(o=0;o<16;o++)r[o]=n[2*o]+(n[2*o+1]<<8);r[15]&=32767}function e(r,n,o){var t;for(t=0;t<16;t++)r[t]=n[t]+o[t]|0}function f(r,n,o){var t;for(t=0;t<16;t++)r[t]=n[t]-o[t]|0}function u(r,o,t){var e,f,u=new Float64Array(31);for(e=0;e<31;e++)u[e]=0;for(e=0;e<16;e++)for(f=0;f<16;f++)u[e+f]+=o[e]*t[f];for(e=0;e<15;e++)u[e]+=38*u[e+16];for(e=0;e<16;e++)r[e]=u[e];n(r),n(r)}function i(r,n){u(r,n,n)}function c(r,n){var o,t=U();for(o=0;o<16;o++)t[o]=n[o];for(o=253;o>=0;o--)i(t,t),2!==o&&4!==o&&u(t,t,n);for(o=0;o<16;o++)r[o]=t[o]}function a(r,t){var e,f,u,i=U(),c=U();for(e=0;e<16;e++)c[e]=t[e];for(n(c),n(c),n(c),f=0;f<2;f++){for(i[0]=c[0]-65517,e=1;e<15;e++)i[e]=c[e]-65535-(i[e-1]>>16&1),i[e-1]&=65535;i[15]=c[15]-32767-(i[14]>>16&1),u=i[15]>>16&1,i[14]&=65535,o(c,i,1-u)}for(e=0;e<16;e++)r[2*e]=255&c[e],r[2*e+1]=c[e]>>8}function v(r){var n=new Uint8Array(32);return a(n,r),1&n[0]}function l(r,n,o,t,e){var f,u=0;for(f=0;f<e;f++)u|=r[n+f]^o[t+f];return(1&u-1>>>8)-1}function y(r,n,o,t){return l(r,n,o,t,32)}function w(r,n){var o=new Uint8Array(32),t=new Uint8Array(32);return a(o,r),a(t,n),y(o,0,t,0)}function s(r,n){var o,t=U();for(o=0;o<16;o++)t[o]=n[o];for(o=250;o>=0;o--)i(t,t),1!==o&&u(t,t,n);for(o=0;o<16;o++)r[o]=t[o]}function d(r,n){var o;for(o=0;o<16;o++)r[o]=0|n[o]}function A(r,n){var o=U(),c=U(),a=U(),l=U(),y=U(),A=U(),K=U();return d(r[2],m),t(r[1],n),i(a,r[1]),u(l,a,x),f(a,a,r[2]),e(l,r[2],l),i(y,l),i(A,y),u(K,A,y),u(o,K,a),u(o,o,l),s(o,o),u(o,o,a),u(o,o,l),u(o,o,l),u(r[0],o,l),i(c,r[0]),u(c,c,l),w(c,a)&&u(r[0],r[0],F),i(c,r[0]),u(c,c,l),w(c,a)?-1:(v(r[0])===n[31]>>7&&f(r[0],b,r[0]),u(r[3],r[0],r[1]),0)}function K(r){var n=new Uint8Array(32),o=[U(),U(),U(),U()],t=U(),i=U();if(A(o,r))return null;var v=o[1];return e(t,m,v),f(i,m,v),c(i,i),u(t,t,i),a(n,t),n}function h(n){var o,t=new Uint8Array(64),e=new Uint8Array(32);for(r.lowlevel.crypto_hash(t,n,32),t[0]&=248,t[31]&=127,t[31]|=64,o=0;o<32;o++)e[o]=t[o];for(o=0;o<64;o++)t[o]=0;return e}function p(r){var n=K(r.publicKey);return n?{publicKey:n,secretKey:h(r.secretKey)}:null}if(!r)throw new Error("tweetnacl not loaded");var U=function(r){var n,o=new Float64Array(16);if(r)for(n=0;n<r.length;n++)o[n]=r[n];return o},b=U(),m=U([1]),x=U([30883,4953,19914,30187,55467,16705,2637,112,59544,30585,16505,36039,65139,11119,27886,20995]),F=U([41136,18958,6951,50414,58488,44335,6150,12099,55207,15867,153,11085,57099,20417,9344,11139]);return{convertPublicKey:K,convertSecretKey:h,convertKeyPair:p}});
Loading…
Cancel
Save