Fixed native (i forgot to account for tag length. Added debug list of js functions, can be usefull when defining interface

This commit is contained in:
Ugljesa Jovanovic 2020-08-27 22:07:03 +02:00 committed by Ugljesa Jovanovic
parent 9e10677165
commit 89e5ae62e4
No known key found for this signature in database
GPG Key ID: 178E6DFCECCB0E0F
9 changed files with 543 additions and 97 deletions

395
libsodium_js_debug_list.txt Normal file
View File

@ -0,0 +1,395 @@
add = function(e,t){if(!(e instanceof Uint8Array&&t instanceof Uint8Array))throw new TypeError("Only Uint8Array instances can added");var r=e.length,a=0,_=0;if(t.length!=e.length)throw new TypeError("Arguments must have the same length");for(_=0;_<r;_++)a>>=8,a+=e[_]+t[_],e[_]=255&a}
base64_variants = Object {ORIGINAL: 1,
ORIGINAL_NO_PADDING: 3,
URLSAFE: 5,
URLSAFE_NO_PADDING: 7}
compare = function(e,t){if(!(e instanceof Uint8Array&&t instanceof Uint8Array))throw new TypeError("Only Uint8Array instances can be compared");if(e.length!==t.length)throw new TypeError("Only instances of identical length can be compared");for(var r=0,a=1,_=e.length;_-- >0;)r|=t[_]-e[_]>>8&a,a&=(t[_]^e[_])-1>>8;return r+r+a-1}
from_base64 = function(e,t){t=o(t);var a,_=[],n=new l(3*(e=m(_,e,"input")).length/4),s=u(e),c=d(4),h=d(4);return _.push(s),_.push(n.address),_.push(n.result_bin_len_p),_.push(n.b64_end_p),0!==r._sodium_base642bin(n.address,n.length,s,e.length,0,c,h,t)&&g(_,"invalid input"),r.getValue(h,"i32")-s!==e.length&&g(_,"incomplete input"),n.length=r.getValue(c,"i32"),a=n.to_Uint8Array(),v(_),a}
from_hex = function(e){var t,a=[],_=new l((e=m(a,e,"input")).length/2),n=u(e),s=d(4);return a.push(n),a.push(_.address),a.push(_.hex_end_p),0!==r._sodium_hex2bin(_.address,_.length,n,e.length,0,0,s)&&g(a,"invalid input"),r.getValue(s,"i32")-n!==e.length&&g(a,"incomplete input"),t=_.to_Uint8Array(),v(a),t}
from_string = function _(e){if("function"==typeof TextEncoder)return(new TextEncoder).encode(e);e=unescape(encodeURIComponent(e));for(var t=new Uint8Array(e.length),r=0,a=e.length;r<a;r++)t[r]=e.charCodeAt(r);return t}
increment = function(e){if(!(e instanceof Uint8Array))throw new TypeError("Only Uint8Array instances can be incremented");for(var t=256,r=0,a=e.length;r<a;r++)t>>=8,t+=e[r],e[r]=255&t}
is_zero = function(e){if(!(e instanceof Uint8Array))throw new TypeError("Only Uint8Array instances can be checked");for(var t=0,r=0,a=e.length;r<a;r++)t|=e[r];return 0===t}
libsodium = Object {onAbort: Function,
print: Function,
printErr: Function,
onRuntimeInitialized: Function,
useBackupModule: Function,
...}
memcmp = function(e,t){if(!(e instanceof Uint8Array&&t instanceof Uint8Array))throw new TypeError("Only Uint8Array instances can be compared");if(e.length!==t.length)throw new TypeError("Only instances of identical length can be compared");for(var r=0,a=0,_=e.length;a<_;a++)r|=e[a]^t[a];return 0===r}
memzero = function(e){if(!(e instanceof Uint8Array))throw new TypeError("Only Uint8Array instances can be wiped");for(var t=0,r=e.length;t<r;t++)e[t]=0}
output_formats = function(){return["uint8array","text","hex","base64"]}
pad = function(e,t){if(!(e instanceof Uint8Array))throw new TypeError("buffer must be a Uint8Array");if((t|=0)<=0)throw new Error("block size must be > 0");var a,_=[],n=d(4),s=1,c=0,o=0|e.length,h=new l(o+t);_.push(n),_.push(h.address);for(var p=h.address,y=h.address+o+t;p<y;p++)r.HEAPU8[p]=e[c],c+=s=1&~((65535&((o-=s)>>>48|o>>>32|o>>>16|o))-1>>16);return 0!==r._sodium_pad(n,h.address,e.length,t,h.length)&&g(_,"internal error"),h.length=r.getValue(n,"i32"),a=h.to_Uint8Array(),v(_),a}
unpad = function(e,t){if(!(e instanceof Uint8Array))throw new TypeError("buffer must be a Uint8Array");if((t|=0)<=0)throw new Error("block size must be > 0");var a=[],_=u(e),n=d(4);return a.push(_),a.push(n),0!==r._sodium_unpad(n,_,e.length,t)&&g(a,"unsupported/invalid padding"),e=(e=new Uint8Array(e)).subarray(0,r.getValue(n,"i32")),v(a),e}
ready = Promise {[[PromiseStatus]]: "resolved",
[[PromiseValue]]: undefined}
symbols = function(){return Object.keys(e).sort()}
to_base64 = function h(e,t){t=o(t),e=m(_,e,"input");var a,_=[],s=0|Math.floor(e.length/3),c=e.length-3*s,h=4*s+(0!==c?0==(2&t)?4:2+(c>>>1):0),p=new l(h+1),y=u(e);return _.push(y),_.push(p.address),0===r._sodium_bin2base64(p.address,p.length,y,e.length,t)&&g(_,"conversion failed"),p.length=h,a=n(p.to_Uint8Array()),v(_),a}
to_hex = function s(e){e=m(null,e,"input");for(var t,r,a,_="",n=0;n<e.length;n++)a=87+(r=15&e[n])+(r-10>>8&-39)<<8|87+(t=e[n]>>>4)+(t-10>>8&-39),_+=String.fromCharCode(255&a)+String.fromCharCode(a>>>8);return _}
to_string = function n(e){if("function"==typeof TextDecoder)return new TextDecoder("utf-8",{fatal:!0}).decode(e);var t=Math.ceil(e.length/8192);if(t<=1)try{return decodeURIComponent(escape(String.fromCharCode.apply(null,e)))}catch(e){throw new TypeError("The encoded data was not valid.")}for(var r="",a=0,_=0;_<t;_++){var s=Array.prototype.slice.call(e,8192*_+a,8192*(_+1)+a);if(0!=s.length){var c,o=s.length,h=0;do{var p=s[--o];p>=240?(h=4,c=!0):p>=224?(h=3,c=!0):p>=192?(h=2,c=!0):p<128&&(h=1,c=!0)}while(!c);for(var y=h-(s.length-o),i=0;i<y;i++)a--,s.pop();r+=n(s)}}return r}
crypto_aead_chacha20poly1305_decrypt = function E(e,t,a,_,n,s){var c=[];i(s);var o=null;null!=e&&(o=u(e=m(c,e,"secret_nonce")),e.length,c.push(o)),t=m(c,t,"ciphertext");var h,y=r._crypto_aead_chacha20poly1305_abytes(),d=t.length;d<y&&b(c,"ciphertext is too short"),h=u(t),c.push(h);var f=null,E=0;null!=a&&(f=u(a=m(c,a,"additional_data")),E=a.length,c.push(f)),_=m(c,_,"public_nonce");var x,k=0|r._crypto_aead_chacha20poly1305_npubbytes();_.length!==k&&b(c,"invalid public_nonce length"),x=u(_),c.push(x),n=m(c,n,"key");var S,T=0|r._crypto_aead_chacha20poly1305_keybytes();n.length!==T&&b(c,"invalid key length"),S=u(n),c.push(S);var w=new l(d-r._crypto_aead_chacha20poly1305_abytes()|0),Y=w.address;if(c.push(Y),0===r._crypto_aead_chacha20poly1305_decrypt(Y,null,o,h,d,0,f,E,0,x,S)){var B=p(w,s);return v(c),B}g(c,"ciphertext cannot be decrypted using that key")}
crypto_aead_chacha20poly1305_decrypt_detached = function x(e,t,a,_,n,s,c){var o=[];i(c);var h=null;null!=e&&(h=u(e=m(o,e,"secret_nonce")),e.length,o.push(h));var y=u(t=m(o,t,"ciphertext")),d=t.length;o.push(y),a=m(o,a,"mac");var f,E=0|r._crypto_box_macbytes();a.length!==E&&b(o,"invalid mac length"),f=u(a),o.push(f);var x=null,k=0;null!=_&&(x=u(_=m(o,_,"additional_data")),k=_.length,o.push(x)),n=m(o,n,"public_nonce");var S,T=0|r._crypto_aead_chacha20poly1305_npubbytes();n.length!==T&&b(o,"invalid public_nonce length"),S=u(n),o.push(S),s=m(o,s,"key");var w,Y=0|r._crypto_aead_chacha20poly1305_keybytes();s.length!==Y&&b(o,"invalid key length"),w=u(s),o.push(w);var B=new l(0|d),A=B.address;if(o.push(A),0===r._crypto_aead_chacha20poly1305_decrypt_detached(A,h,y,d,0,f,x,k,0,S,w)){var K=p(B,c);return v(o),K}g(o,"ciphertext cannot be decrypted using that key")}
crypto_aead_chacha20poly1305_encrypt = function k(e,t,a,_,n,s){var c=[];i(s);var o=u(e=m(c,e,"message")),h=e.length;c.push(o);var y=null,d=0;null!=t&&(y=u(t=m(c,t,"additional_data")),d=t.length,c.push(y));var f=null;null!=a&&(f=u(a=m(c,a,"secret_nonce")),a.length,c.push(f)),_=m(c,_,"public_nonce");var E,x=0|r._crypto_aead_chacha20poly1305_npubbytes();_.length!==x&&b(c,"invalid public_nonce length"),E=u(_),c.push(E),n=m(c,n,"key");var k,S=0|r._crypto_aead_chacha20poly1305_keybytes();n.length!==S&&b(c,"invalid key length"),k=u(n),c.push(k);var T=new l(h+r._crypto_aead_chacha20poly1305_abytes()|0),w=T.address;if(c.push(w),0===r._crypto_aead_chacha20poly1305_encrypt(w,null,o,h,0,y,d,0,f,E,k)){var Y=p(T,s);return v(c),Y}g(c,"invalid usage")}
crypto_aead_chacha20poly1305_encrypt_detached = function S(e,t,a,_,n,s){var c=[];i(s);var o=u(e=m(c,e,"message")),h=e.length;c.push(o);var y=null,d=0;null!=t&&(y=u(t=m(c,t,"additional_data")),d=t.length,c.push(y));var f=null;null!=a&&(f=u(a=m(c,a,"secret_nonce")),a.length,c.push(f)),_=m(c,_,"public_nonce");var E,x=0|r._crypto_aead_chacha20poly1305_npubbytes();_.length!==x&&b(c,"invalid public_nonce length"),E=u(_),c.push(E),n=m(c,n,"key");var k,S=0|r._crypto_aead_chacha20poly1305_keybytes();n.length!==S&&b(c,"invalid key length"),k=u(n),c.push(k);var T=new l(0|h),w=T.address;c.push(w);var Y=new l(0|r._crypto_aead_chacha20poly1305_abytes()),B=Y.address;if(c.push(B),0===r._crypto_aead_chacha20poly1305_encrypt_detached(w,B,null,o,h,0,y,d,0,f,E,k)){var A=p({ciphertext:T,mac:Y},s);return v(c),A}g(c,"invalid usage")}
crypto_aead_chacha20poly1305_ietf_decrypt = function T(e,t,a,_,n,s){var c=[];i(s);var o=null;null!=e&&(o=u(e=m(c,e,"secret_nonce")),e.length,c.push(o)),t=m(c,t,"ciphertext");var h,y=r._crypto_aead_chacha20poly1305_ietf_abytes(),d=t.length;d<y&&b(c,"ciphertext is too short"),h=u(t),c.push(h);var f=null,E=0;null!=a&&(f=u(a=m(c,a,"additional_data")),E=a.length,c.push(f)),_=m(c,_,"public_nonce");var x,k=0|r._crypto_aead_chacha20poly1305_ietf_npubbytes();_.length!==k&&b(c,"invalid public_nonce length"),x=u(_),c.push(x),n=m(c,n,"key");var S,T=0|r._crypto_aead_chacha20poly1305_ietf_keybytes();n.length!==T&&b(c,"invalid key length"),S=u(n),c.push(S);var w=new l(d-r._crypto_aead_chacha20poly1305_ietf_abytes()|0),Y=w.address;if(c.push(Y),0===r._crypto_aead_chacha20poly1305_ietf_decrypt(Y,null,o,h,d,0,f,E,0,x,S)){var B=p(w,s);return v(c),B}g(c,"ciphertext cannot be decrypted using that key")}
crypto_aead_chacha20poly1305_ietf_decrypt_detached = function w(e,t,a,_,n,s,c){var o=[];i(c);var h=null;null!=e&&(h=u(e=m(o,e,"secret_nonce")),e.length,o.push(h));var y=u(t=m(o,t,"ciphertext")),d=t.length;o.push(y),a=m(o,a,"mac");var f,E=0|r._crypto_box_macbytes();a.length!==E&&b(o,"invalid mac length"),f=u(a),o.push(f);var x=null,k=0;null!=_&&(x=u(_=m(o,_,"additional_data")),k=_.length,o.push(x)),n=m(o,n,"public_nonce");var S,T=0|r._crypto_aead_chacha20poly1305_ietf_npubbytes();n.length!==T&&b(o,"invalid public_nonce length"),S=u(n),o.push(S),s=m(o,s,"key");var w,Y=0|r._crypto_aead_chacha20poly1305_ietf_keybytes();s.length!==Y&&b(o,"invalid key length"),w=u(s),o.push(w);var B=new l(0|d),A=B.address;if(o.push(A),0===r._crypto_aead_chacha20poly1305_ietf_decrypt_detached(A,h,y,d,0,f,x,k,0,S,w)){var K=p(B,c);return v(o),K}g(o,"ciphertext cannot be decrypted using that key")}
crypto_aead_chacha20poly1305_ietf_encrypt = function Y(e,t,a,_,n,s){var c=[];i(s);var o=u(e=m(c,e,"message")),h=e.length;c.push(o);var y=null,d=0;null!=t&&(y=u(t=m(c,t,"additional_data")),d=t.length,c.push(y));var f=null;null!=a&&(f=u(a=m(c,a,"secret_nonce")),a.length,c.push(f)),_=m(c,_,"public_nonce");var E,x=0|r._crypto_aead_chacha20poly1305_ietf_npubbytes();_.length!==x&&b(c,"invalid public_nonce length"),E=u(_),c.push(E),n=m(c,n,"key");var k,S=0|r._crypto_aead_chacha20poly1305_ietf_keybytes();n.length!==S&&b(c,"invalid key length"),k=u(n),c.push(k);var T=new l(h+r._crypto_aead_chacha20poly1305_ietf_abytes()|0),w=T.address;if(c.push(w),0===r._crypto_aead_chacha20poly1305_ietf_encrypt(w,null,o,h,0,y,d,0,f,E,k)){var Y=p(T,s);return v(c),Y}g(c,"invalid usage")}
crypto_aead_chacha20poly1305_ietf_encrypt_detached = function B(e,t,a,_,n,s){var c=[];i(s);var o=u(e=m(c,e,"message")),h=e.length;c.push(o);var y=null,d=0;null!=t&&(y=u(t=m(c,t,"additional_data")),d=t.length,c.push(y));var f=null;null!=a&&(f=u(a=m(c,a,"secret_nonce")),a.length,c.push(f)),_=m(c,_,"public_nonce");var E,x=0|r._crypto_aead_chacha20poly1305_ietf_npubbytes();_.length!==x&&b(c,"invalid public_nonce length"),E=u(_),c.push(E),n=m(c,n,"key");var k,S=0|r._crypto_aead_chacha20poly1305_ietf_keybytes();n.length!==S&&b(c,"invalid key length"),k=u(n),c.push(k);var T=new l(0|h),w=T.address;c.push(w);var Y=new l(0|r._crypto_aead_chacha20poly1305_ietf_abytes()),B=Y.address;if(c.push(B),0===r._crypto_aead_chacha20poly1305_ietf_encrypt_detached(w,B,null,o,h,0,y,d,0,f,E,k)){var A=p({ciphertext:T,mac:Y},s);return v(c),A}g(c,"invalid usage")}
crypto_aead_chacha20poly1305_ietf_keygen = function A(e){var t=[];i(e);var a=new l(0|r._crypto_aead_chacha20poly1305_ietf_keybytes()),_=a.address;t.push(_),r._crypto_aead_chacha20poly1305_ietf_keygen(_);var n=p(a,e);return v(t),n}
crypto_aead_chacha20poly1305_keygen = function K(e){var t=[];i(e);var a=new l(0|r._crypto_aead_chacha20poly1305_keybytes()),_=a.address;t.push(_),r._crypto_aead_chacha20poly1305_keygen(_);var n=p(a,e);return v(t),n}
crypto_aead_xchacha20poly1305_ietf_decrypt = function M(e,t,a,_,n,s){var c=[];i(s);var o=null;null!=e&&(o=u(e=m(c,e,"secret_nonce")),e.length,c.push(o)),t=m(c,t,"ciphertext");var h,y=r._crypto_aead_xchacha20poly1305_ietf_abytes(),d=t.length;d<y&&b(c,"ciphertext is too short"),h=u(t),c.push(h);var f=null,E=0;null!=a&&(f=u(a=m(c,a,"additional_data")),E=a.length,c.push(f)),_=m(c,_,"public_nonce");var x,k=0|r._crypto_aead_xchacha20poly1305_ietf_npubbytes();_.length!==k&&b(c,"invalid public_nonce length"),x=u(_),c.push(x),n=m(c,n,"key");var S,T=0|r._crypto_aead_xchacha20poly1305_ietf_keybytes();n.length!==T&&b(c,"invalid key length"),S=u(n),c.push(S);var w=new l(d-r._crypto_aead_xchacha20poly1305_ietf_abytes()|0),Y=w.address;if(c.push(Y),0===r._crypto_aead_xchacha20poly1305_ietf_decrypt(Y,null,o,h,d,0,f,E,0,x,S)){var B=p(w,s);return v(c),B}g(c,"ciphertext cannot be decrypted using that key")}
crypto_aead_xchacha20poly1305_ietf_decrypt_detached = function I(e,t,a,_,n,s,c){var o=[];i(c);var h=null;null!=e&&(h=u(e=m(o,e,"secret_nonce")),e.length,o.push(h));var y=u(t=m(o,t,"ciphertext")),d=t.length;o.push(y),a=m(o,a,"mac");var f,E=0|r._crypto_box_macbytes();a.length!==E&&b(o,"invalid mac length"),f=u(a),o.push(f);var x=null,k=0;null!=_&&(x=u(_=m(o,_,"additional_data")),k=_.length,o.push(x)),n=m(o,n,"public_nonce");var S,T=0|r._crypto_aead_xchacha20poly1305_ietf_npubbytes();n.length!==T&&b(o,"invalid public_nonce length"),S=u(n),o.push(S),s=m(o,s,"key");var w,Y=0|r._crypto_aead_xchacha20poly1305_ietf_keybytes();s.length!==Y&&b(o,"invalid key length"),w=u(s),o.push(w);var B=new l(0|d),A=B.address;if(o.push(A),0===r._crypto_aead_xchacha20poly1305_ietf_decrypt_detached(A,h,y,d,0,f,x,k,0,S,w)){var K=p(B,c);return v(o),K}g(o,"ciphertext cannot be decrypted using that key")}
crypto_aead_xchacha20poly1305_ietf_encrypt = function N(e,t,a,_,n,s){var c=[];i(s);var o=u(e=m(c,e,"message")),h=e.length;c.push(o);var y=null,d=0;null!=t&&(y=u(t=m(c,t,"additional_data")),d=t.length,c.push(y));var f=null;null!=a&&(f=u(a=m(c,a,"secret_nonce")),a.length,c.push(f)),_=m(c,_,"public_nonce");var E,x=0|r._crypto_aead_xchacha20poly1305_ietf_npubbytes();_.length!==x&&b(c,"invalid public_nonce length"),E=u(_),c.push(E),n=m(c,n,"key");var k,S=0|r._crypto_aead_xchacha20poly1305_ietf_keybytes();n.length!==S&&b(c,"invalid key length"),k=u(n),c.push(k);var T=new l(h+r._crypto_aead_xchacha20poly1305_ietf_abytes()|0),w=T.address;if(c.push(w),0===r._crypto_aead_xchacha20poly1305_ietf_encrypt(w,null,o,h,0,y,d,0,f,E,k)){var Y=p(T,s);return v(c),Y}g(c,"invalid usage")}
crypto_aead_xchacha20poly1305_ietf_encrypt_detached = function L(e,t,a,_,n,s){var c=[];i(s);var o=u(e=m(c,e,"message")),h=e.length;c.push(o);var y=null,d=0;null!=t&&(y=u(t=m(c,t,"additional_data")),d=t.length,c.push(y));var f=null;null!=a&&(f=u(a=m(c,a,"secret_nonce")),a.length,c.push(f)),_=m(c,_,"public_nonce");var E,x=0|r._crypto_aead_xchacha20poly1305_ietf_npubbytes();_.length!==x&&b(c,"invalid public_nonce length"),E=u(_),c.push(E),n=m(c,n,"key");var k,S=0|r._crypto_aead_xchacha20poly1305_ietf_keybytes();n.length!==S&&b(c,"invalid key length"),k=u(n),c.push(k);var T=new l(0|h),w=T.address;c.push(w);var Y=new l(0|r._crypto_aead_xchacha20poly1305_ietf_abytes()),B=Y.address;if(c.push(B),0===r._crypto_aead_xchacha20poly1305_ietf_encrypt_detached(w,B,null,o,h,0,y,d,0,f,E,k)){var A=p({ciphertext:T,mac:Y},s);return v(c),A}g(c,"invalid usage")}
crypto_aead_xchacha20poly1305_ietf_keygen = function U(e){var t=[];i(e);var a=new l(0|r._crypto_aead_xchacha20poly1305_ietf_keybytes()),_=a.address;t.push(_),r._crypto_aead_xchacha20poly1305_ietf_keygen(_);var n=p(a,e);return v(t),n}
crypto_auth = function O(e,t,a){var _=[];i(a);var n=u(e=m(_,e,"message")),s=e.length;_.push(n),t=m(_,t,"key");var c,o=0|r._crypto_auth_keybytes();t.length!==o&&b(_,"invalid key length"),c=u(t),_.push(c);var h=new l(0|r._crypto_auth_bytes()),y=h.address;if(_.push(y),0==(0|r._crypto_auth(y,n,s,0,c))){var d=p(h,a);return v(_),d}g(_,"invalid usage")}
crypto_auth_hmacsha256 = function C(e,t,a){var _=[];i(a);var n=u(e=m(_,e,"message")),s=e.length;_.push(n),t=m(_,t,"key");var c,o=0|r._crypto_auth_hmacsha256_keybytes();t.length!==o&&b(_,"invalid key length"),c=u(t),_.push(c);var h=new l(0|r._crypto_auth_hmacsha256_bytes()),y=h.address;if(_.push(y),0==(0|r._crypto_auth_hmacsha256(y,n,s,0,c))){var d=p(h,a);return v(_),d}g(_,"invalid usage")}
crypto_auth_hmacsha256_keygen = function R(e){var t=[];i(e);var a=new l(0|r._crypto_auth_hmacsha256_keybytes()),_=a.address;t.push(_),r._crypto_auth_hmacsha256_keygen(_);var n=p(a,e);return v(t),n}
crypto_auth_hmacsha256_verify = function P(e,t,a){var _=[];e=m(_,e,"tag");var n,s=0|r._crypto_auth_hmacsha256_bytes();e.length!==s&&b(_,"invalid tag length"),n=u(e),_.push(n);var c=u(t=m(_,t,"message")),o=t.length;_.push(c),a=m(_,a,"key");var h,p=0|r._crypto_auth_hmacsha256_keybytes();a.length!==p&&b(_,"invalid key length"),h=u(a),_.push(h);var y=0==(0|r._crypto_auth_hmacsha256_verify(n,c,o,0,h));return v(_),y}
crypto_auth_hmacsha512 = function G(e,t,a){var _=[];i(a);var n=u(e=m(_,e,"message")),s=e.length;_.push(n),t=m(_,t,"key");var c,o=0|r._crypto_auth_hmacsha512_keybytes();t.length!==o&&b(_,"invalid key length"),c=u(t),_.push(c);var h=new l(0|r._crypto_auth_hmacsha512_bytes()),y=h.address;if(_.push(y),0==(0|r._crypto_auth_hmacsha512(y,n,s,0,c))){var d=p(h,a);return v(_),d}g(_,"invalid usage")}
crypto_auth_hmacsha512_keygen = function X(e){var t=[];i(e);var a=new l(0|r._crypto_auth_hmacsha512_keybytes()),_=a.address;t.push(_),r._crypto_auth_hmacsha512_keygen(_);var n=p(a,e);return v(t),n}
crypto_auth_hmacsha512_verify = function D(e,t,a){var _=[];e=m(_,e,"tag");var n,s=0|r._crypto_auth_hmacsha512_bytes();e.length!==s&&b(_,"invalid tag length"),n=u(e),_.push(n);var c=u(t=m(_,t,"message")),o=t.length;_.push(c),a=m(_,a,"key");var h,p=0|r._crypto_auth_hmacsha512_keybytes();a.length!==p&&b(_,"invalid key length"),h=u(a),_.push(h);var y=0==(0|r._crypto_auth_hmacsha512_verify(n,c,o,0,h));return v(_),y}
crypto_auth_keygen = function F(e){var t=[];i(e);var a=new l(0|r._crypto_auth_keybytes()),_=a.address;t.push(_),r._crypto_auth_keygen(_);var n=p(a,e);return v(t),n}
crypto_auth_verify = function V(e,t,a){var _=[];e=m(_,e,"tag");var n,s=0|r._crypto_auth_bytes();e.length!==s&&b(_,"invalid tag length"),n=u(e),_.push(n);var c=u(t=m(_,t,"message")),o=t.length;_.push(c),a=m(_,a,"key");var h,p=0|r._crypto_auth_keybytes();a.length!==p&&b(_,"invalid key length"),h=u(a),_.push(h);var y=0==(0|r._crypto_auth_verify(n,c,o,0,h));return v(_),y}
crypto_box_beforenm = function H(e,t,a){var _=[];i(a),e=m(_,e,"publicKey");var n,s=0|r._crypto_box_publickeybytes();e.length!==s&&b(_,"invalid publicKey length"),n=u(e),_.push(n),t=m(_,t,"privateKey");var c,o=0|r._crypto_box_secretkeybytes();t.length!==o&&b(_,"invalid privateKey length"),c=u(t),_.push(c);var h=new l(0|r._crypto_box_beforenmbytes()),y=h.address;if(_.push(y),0==(0|r._crypto_box_beforenm(y,n,c))){var d=p(h,a);return v(_),d}g(_,"invalid usage")}
crypto_box_curve25519xchacha20poly1305_keypair = function z(e){var t=[];i(e);var a=new l(0|r._crypto_box_curve25519xchacha20poly1305_publickeybytes()),_=a.address;t.push(_);var n=new l(0|r._crypto_box_curve25519xchacha20poly1305_secretkeybytes()),s=n.address;t.push(s),r._crypto_box_curve25519xchacha20poly1305_keypair(_,s);var c=p({publicKey:a,privateKey:n,keyType:"curve25519"},e);return v(t),c}
crypto_box_curve25519xchacha20poly1305_seal = function j(e,t,a){var _=[];i(a);var n=u(e=m(_,e,"message")),s=e.length;_.push(n),t=m(_,t,"publicKey");var c,o=0|r._crypto_box_curve25519xchacha20poly1305_publickeybytes();t.length!==o&&b(_,"invalid publicKey length"),c=u(t),_.push(c);var h=new l(s+r._crypto_box_curve25519xchacha20poly1305_sealbytes()|0),y=h.address;_.push(y),r._crypto_box_curve25519xchacha20poly1305_seal(y,n,s,0,c);var d=p(h,a);return v(_),d}
crypto_box_curve25519xchacha20poly1305_seal_open = function q(e,t,a,_){var n=[];i(_),e=m(n,e,"ciphertext");var s,c=r._crypto_box_curve25519xchacha20poly1305_sealbytes(),o=e.length;o<c&&b(n,"ciphertext is too short"),s=u(e),n.push(s),t=m(n,t,"publicKey");var h,y=0|r._crypto_box_curve25519xchacha20poly1305_publickeybytes();t.length!==y&&b(n,"invalid publicKey length"),h=u(t),n.push(h),a=m(n,a,"secretKey");var d,g=0|r._crypto_box_curve25519xchacha20poly1305_secretkeybytes();a.length!==g&&b(n,"invalid secretKey length"),d=u(a),n.push(d);var f=new l(o-r._crypto_box_curve25519xchacha20poly1305_sealbytes()|0),E=f.address;n.push(E),r._crypto_box_curve25519xchacha20poly1305_seal_open(E,s,o,0,h,d);var x=p(f,_);return v(n),x}
crypto_box_detached = function W(e,t,a,_,n){var s=[];i(n);var c=u(e=m(s,e,"message")),o=e.length;s.push(c),t=m(s,t,"nonce");var h,y=0|r._crypto_box_noncebytes();t.length!==y&&b(s,"invalid nonce length"),h=u(t),s.push(h),a=m(s,a,"publicKey");var d,f=0|r._crypto_box_publickeybytes();a.length!==f&&b(s,"invalid publicKey length"),d=u(a),s.push(d),_=m(s,_,"privateKey");var E,x=0|r._crypto_box_secretkeybytes();_.length!==x&&b(s,"invalid privateKey length"),E=u(_),s.push(E);var k=new l(0|o),S=k.address;s.push(S);var T=new l(0|r._crypto_box_macbytes()),w=T.address;if(s.push(w),0==(0|r._crypto_box_detached(S,w,c,o,0,h,d,E))){var Y=p({ciphertext:k,mac:T},n);return v(s),Y}g(s,"invalid usage")}
crypto_box_easy = function J(e,t,a,_,n){var s=[];i(n);var c=u(e=m(s,e,"message")),o=e.length;s.push(c),t=m(s,t,"nonce");var h,y=0|r._crypto_box_noncebytes();t.length!==y&&b(s,"invalid nonce length"),h=u(t),s.push(h),a=m(s,a,"publicKey");var d,f=0|r._crypto_box_publickeybytes();a.length!==f&&b(s,"invalid publicKey length"),d=u(a),s.push(d),_=m(s,_,"privateKey");var E,x=0|r._crypto_box_secretkeybytes();_.length!==x&&b(s,"invalid privateKey length"),E=u(_),s.push(E);var k=new l(o+r._crypto_box_macbytes()|0),S=k.address;if(s.push(S),0==(0|r._crypto_box_easy(S,c,o,0,h,d,E))){var T=p(k,n);return v(s),T}g(s,"invalid usage")}
crypto_box_easy_afternm = function Q(e,t,a,_){var n=[];i(_);var s=u(e=m(n,e,"message")),c=e.length;n.push(s),t=m(n,t,"nonce");var o,h=0|r._crypto_box_noncebytes();t.length!==h&&b(n,"invalid nonce length"),o=u(t),n.push(o),a=m(n,a,"sharedKey");var y,d=0|r._crypto_box_beforenmbytes();a.length!==d&&b(n,"invalid sharedKey length"),y=u(a),n.push(y);var f=new l(c+r._crypto_box_macbytes()|0),E=f.address;if(n.push(E),0==(0|r._crypto_box_easy_afternm(E,s,c,0,o,y))){var x=p(f,_);return v(n),x}g(n,"invalid usage")}
crypto_box_keypair = function Z(e){var t=[];i(e);var a=new l(0|r._crypto_box_publickeybytes()),_=a.address;t.push(_);var n=new l(0|r._crypto_box_secretkeybytes()),s=n.address;if(t.push(s),0==(0|r._crypto_box_keypair(_,s))){var c={publicKey:p(a,e),privateKey:p(n,e),keyType:"x25519"};return v(t),c}g(t,"internal error")}
crypto_box_open_detached = function $(e,t,a,_,n,s){var c=[];i(s);var o=u(e=m(c,e,"ciphertext")),h=e.length;c.push(o),t=m(c,t,"mac");var y,d=0|r._crypto_box_macbytes();t.length!==d&&b(c,"invalid mac length"),y=u(t),c.push(y),a=m(c,a,"nonce");var f,E=0|r._crypto_box_noncebytes();a.length!==E&&b(c,"invalid nonce length"),f=u(a),c.push(f),_=m(c,_,"publicKey");var x,k=0|r._crypto_box_publickeybytes();_.length!==k&&b(c,"invalid publicKey length"),x=u(_),c.push(x),n=m(c,n,"privateKey");var S,T=0|r._crypto_box_secretkeybytes();n.length!==T&&b(c,"invalid privateKey length"),S=u(n),c.push(S);var w=new l(0|h),Y=w.address;if(c.push(Y),0==(0|r._crypto_box_open_detached(Y,o,y,h,0,f,x,S))){var B=p(w,s);return v(c),B}g(c,"incorrect key pair for the given ciphertext")}
crypto_box_open_easy = function ee(e,t,a,_,n){var s=[];i(n),e=m(s,e,"ciphertext");var c,o=r._crypto_box_macbytes(),h=e.length;h<o&&b(s,"ciphertext is too short"),c=u(e),s.push(c),t=m(s,t,"nonce");var y,d=0|r._crypto_box_noncebytes();t.length!==d&&b(s,"invalid nonce length"),y=u(t),s.push(y),a=m(s,a,"publicKey");var f,E=0|r._crypto_box_publickeybytes();a.length!==E&&b(s,"invalid publicKey length"),f=u(a),s.push(f),_=m(s,_,"privateKey");var x,k=0|r._crypto_box_secretkeybytes();_.length!==k&&b(s,"invalid privateKey length"),x=u(_),s.push(x);var S=new l(h-r._crypto_box_macbytes()|0),T=S.address;if(s.push(T),0==(0|r._crypto_box_open_easy(T,c,h,0,y,f,x))){var w=p(S,n);return v(s),w}g(s,"incorrect key pair for the given ciphertext")}
crypto_box_open_easy_afternm = function te(e,t,a,_){var n=[];i(_);var s=u(e=m(n,e,"ciphertext")),c=e.length;n.push(s),t=m(n,t,"nonce");var o,h=0|r._crypto_box_noncebytes();t.length!==h&&b(n,"invalid nonce length"),o=u(t),n.push(o),a=m(n,a,"sharedKey");var y,d=0|r._crypto_box_beforenmbytes();a.length!==d&&b(n,"invalid sharedKey length"),y=u(a),n.push(y);var f=new l(c-r._crypto_box_macbytes()|0),E=f.address;if(n.push(E),0==(0|r._crypto_box_open_easy_afternm(E,s,c,0,o,y))){var x=p(f,_);return v(n),x}g(n,"incorrect secret key for the given ciphertext")}
crypto_box_seal = function re(e,t,a){var _=[];i(a);var n=u(e=m(_,e,"message")),s=e.length;_.push(n),t=m(_,t,"publicKey");var c,o=0|r._crypto_box_publickeybytes();t.length!==o&&b(_,"invalid publicKey length"),c=u(t),_.push(c);var h=new l(s+r._crypto_box_sealbytes()|0),y=h.address;if(_.push(y),0==(0|r._crypto_box_seal(y,n,s,0,c))){var d=p(h,a);return v(_),d}g(_,"invalid usage")}
crypto_box_seal_open = function ae(e,t,a,_){var n=[];i(_),e=m(n,e,"ciphertext");var s,c=r._crypto_box_sealbytes(),o=e.length;o<c&&b(n,"ciphertext is too short"),s=u(e),n.push(s),t=m(n,t,"publicKey");var h,y=0|r._crypto_box_publickeybytes();t.length!==y&&b(n,"invalid publicKey length"),h=u(t),n.push(h),a=m(n,a,"privateKey");var d,f=0|r._crypto_box_secretkeybytes();a.length!==f&&b(n,"invalid privateKey length"),d=u(a),n.push(d);var E=new l(o-r._crypto_box_sealbytes()|0),x=E.address;if(n.push(x),0==(0|r._crypto_box_seal_open(x,s,o,0,h,d))){var k=p(E,_);return v(n),k}g(n,"incorrect key pair for the given ciphertext")}
crypto_box_seed_keypair = function _e(e,t){var a=[];i(t),e=m(a,e,"seed");var _,n=0|r._crypto_box_seedbytes();e.length!==n&&b(a,"invalid seed length"),_=u(e),a.push(_);var s=new l(0|r._crypto_box_publickeybytes()),c=s.address;a.push(c);var o=new l(0|r._crypto_box_secretkeybytes()),h=o.address;if(a.push(h),0==(0|r._crypto_box_seed_keypair(c,h,_))){var y={publicKey:p(s,t),privateKey:p(o,t),keyType:"x25519"};return v(a),y}g(a,"invalid usage")}
crypto_core_ristretto255_add = function ne(e,t,a){var _=[];i(a),e=m(_,e,"p");var n,s=0|r._crypto_core_ristretto255_bytes();e.length!==s&&b(_,"invalid p length"),n=u(e),_.push(n),t=m(_,t,"q");var c,o=0|r._crypto_core_ristretto255_bytes();t.length!==o&&b(_,"invalid q length"),c=u(t),_.push(c);var h=new l(0|r._crypto_core_ristretto255_bytes()),y=h.address;if(_.push(y),0==(0|r._crypto_core_ristretto255_add(y,n,c))){var d=p(h,a);return v(_),d}g(_,"inputs is invalid element")}
crypto_core_ristretto255_from_hash = function se(e,t){var a=[];i(t);var _=u(e=m(a,e,"r"));e.length,a.push(_);var n=new l(0|r._crypto_core_ristretto255_bytes()),s=n.address;if(a.push(s),0==(0|r._crypto_core_ristretto255_from_hash(s,_))){var c=p(n,t);return v(a),c}g(a,"invalid usage")}
crypto_core_ristretto255_is_valid_point = function ce(e,t){var a=[];i(t);var _=u(e=m(a,e,"point"));e.length,a.push(_);var n=1==(0|r._crypto_core_ristretto255_is_valid_point(_));return v(a),n}
crypto_core_ristretto255_random = function oe(e){var t=[];i(e);var a=new l(0|r._crypto_core_ristretto255_bytes()),_=a.address;t.push(_),r._crypto_core_ristretto255_random(_);var n=p(a,e);return v(t),n}
crypto_core_ristretto255_scalar_add = function he(e,t,a){var _=[];i(a),e=m(_,e,"x");var n,s=0|r._crypto_core_ristretto255_scalarbytes();e.length!==s&&b(_,"invalid x length"),n=u(e),_.push(n),t=m(_,t,"y");var c,o=0|r._crypto_core_ristretto255_scalarbytes();t.length!==o&&b(_,"invalid y length"),c=u(t),_.push(c);var h=new l(0|r._crypto_core_ristretto255_scalarbytes()),y=h.address;_.push(y),r._crypto_core_ristretto255_scalar_add(y,n,c);var d=p(h,a);return v(_),d}
crypto_core_ristretto255_scalar_complement = function pe(e,t){var a=[];i(t);var _=u(e=m(a,e,"s"));e.length,a.push(_);var n=new l(0|r._crypto_core_ristretto255_scalarbytes()),s=n.address;a.push(s),r._crypto_core_ristretto255_scalar_complement(s,_);var c=p(n,t);return v(a),c}
crypto_core_ristretto255_scalar_invert = function ye(e,t){var a=[];i(t);var _=u(e=m(a,e,"s"));e.length,a.push(_);var n=new l(0|r._crypto_core_ristretto255_scalarbytes()),s=n.address;if(a.push(s),0==(0|r._crypto_core_ristretto255_scalar_invert(s,_))){var c=p(n,t);return v(a),c}g(a,"invalid reciprocate")}
crypto_core_ristretto255_scalar_mul = function ie(e,t,a){var _=[];i(a),e=m(_,e,"x");var n,s=0|r._crypto_core_ristretto255_scalarbytes();e.length!==s&&b(_,"invalid x length"),n=u(e),_.push(n),t=m(_,t,"y");var c,o=0|r._crypto_core_ristretto255_scalarbytes();t.length!==o&&b(_,"invalid y length"),c=u(t),_.push(c);var h=new l(0|r._crypto_core_ristretto255_scalarbytes()),y=h.address;_.push(y),r._crypto_core_ristretto255_scalar_mul(y,n,c);var d=p(h,a);return v(_),d}
crypto_core_ristretto255_scalar_negate = function le(e,t){var a=[];i(t);var _=u(e=m(a,e,"s"));e.length,a.push(_);var n=new l(0|r._crypto_core_ristretto255_scalarbytes()),s=n.address;a.push(s),r._crypto_core_ristretto255_scalar_negate(s,_);var c=p(n,t);return v(a),c}
crypto_core_ristretto255_scalar_random = function ue(e){var t=[];i(e);var a=new l(0|r._crypto_core_ristretto255_scalarbytes()),_=a.address;t.push(_),r._crypto_core_ristretto255_random(_);var n=p(a,e);return v(t),n}
crypto_core_ristretto255_scalar_reduce = function de(e,t){var a=[];i(t);var _=u(e=m(a,e,"sample"));e.length,a.push(_);var n=new l(0|r._crypto_core_ristretto255_scalarbytes()),s=n.address;a.push(s),r._crypto_core_ristretto255_scalar_reduce(s,_);var c=p(n,t);return v(a),c}
crypto_core_ristretto255_scalar_sub = function ve(e,t,a){var _=[];i(a),e=m(_,e,"x");var n,s=0|r._crypto_core_ristretto255_scalarbytes();e.length!==s&&b(_,"invalid x length"),n=u(e),_.push(n),t=m(_,t,"y");var c,o=0|r._crypto_core_ristretto255_scalarbytes();t.length!==o&&b(_,"invalid y length"),c=u(t),_.push(c);var h=new l(0|r._crypto_core_ristretto255_scalarbytes()),y=h.address;_.push(y),r._crypto_core_ristretto255_scalar_sub(y,n,c);var d=p(h,a);return v(_),d}
crypto_core_ristretto255_sub = function ge(e,t,a){var _=[];i(a),e=m(_,e,"p");var n,s=0|r._crypto_core_ristretto255_bytes();e.length!==s&&b(_,"invalid p length"),n=u(e),_.push(n),t=m(_,t,"q");var c,o=0|r._crypto_core_ristretto255_bytes();t.length!==o&&b(_,"invalid q length"),c=u(t),_.push(c);var h=new l(0|r._crypto_core_ristretto255_bytes()),y=h.address;if(_.push(y),0==(0|r._crypto_core_ristretto255_sub(y,n,c))){var d=p(h,a);return v(_),d}g(_,"inputs is invalid element")}
crypto_generichash = function be(e,t,a,_){var n=[];i(_),f(n,e,"hash_length"),("number"!=typeof e||(0|e)!==e||e<0)&&b(n,"hash_length must be an unsigned integer");var s=u(t=m(n,t,"message")),c=t.length;n.push(s);var o=null,h=0;null!=a&&(o=u(a=m(n,a,"key")),h=a.length,n.push(o));var y=new l(e|=0),d=y.address;if(n.push(d),0==(0|r._crypto_generichash(d,e,s,c,0,o,h))){var E=p(y,_);return v(n),E}g(n,"invalid usage")}
crypto_generichash_blake2b_salt_personal = function fe(e,t,a,_,n){var s=[];i(n),f(s,e,"subkey_len"),("number"!=typeof e||(0|e)!==e||e<0)&&b(s,"subkey_len must be an unsigned integer");var c=null,o=0;null!=t&&(c=u(t=m(s,t,"key")),o=t.length,s.push(c)),a=m(s,a,"id");var h,y=0|r._crypto_generichash_blake2b_saltbytes();a.length!==y&&b(s,"invalid id length"),h=u(a),s.push(h),_=m(s,_,"ctx");var d,E=0|r._crypto_generichash_blake2b_personalbytes();_.length!==E&&b(s,"invalid ctx length"),d=u(_),s.push(d);var x=new l(0|e),k=x.address;if(s.push(k),0==(0|r._crypto_generichash_blake2b_salt_personal(k,e,null,0,0,c,o,h,d))){var S=p(x,n);return v(s),S}g(s,"invalid usage")}
crypto_generichash_final = function me(e,t,a){var _=[];i(a),f(_,e,"state_address"),f(_,t,"hash_length"),("number"!=typeof t||(0|t)!==t||t<0)&&b(_,"hash_length must be an unsigned integer");var n=new l(t|=0),s=n.address;if(_.push(s),0==(0|r._crypto_generichash_final(e,s,t))){var c=(r._free(e),p(n,a));return v(_),c}g(_,"invalid usage")}
crypto_generichash_init = function Ee(e,t,a){var _=[];i(a);var n=null,s=0;null!=e&&(n=u(e=m(_,e,"key")),s=e.length,_.push(n)),f(_,t,"hash_length"),("number"!=typeof t||(0|t)!==t||t<0)&&b(_,"hash_length must be an unsigned integer");var c=new l(357).address;if(0==(0|r._crypto_generichash_init(c,n,s,t))){var o=c;return v(_),o}g(_,"invalid usage")}
crypto_generichash_keygen = function xe(e){var t=[];i(e);var a=new l(0|r._crypto_generichash_keybytes()),_=a.address;t.push(_),r._crypto_generichash_keygen(_);var n=p(a,e);return v(t),n}
crypto_generichash_update = function ke(e,t,a){var _=[];i(a),f(_,e,"state_address");var n=u(t=m(_,t,"message_chunk")),s=t.length;_.push(n),0!=(0|r._crypto_generichash_update(e,n,s))&&g(_,"invalid usage"),v(_)}
crypto_hash = function Se(e,t){var a=[];i(t);var _=u(e=m(a,e,"message")),n=e.length;a.push(_);var s=new l(0|r._crypto_hash_bytes()),c=s.address;if(a.push(c),0==(0|r._crypto_hash(c,_,n,0))){var o=p(s,t);return v(a),o}g(a,"invalid usage")}
crypto_hash_sha256 = function Te(e,t){var a=[];i(t);var _=u(e=m(a,e,"message")),n=e.length;a.push(_);var s=new l(0|r._crypto_hash_sha256_bytes()),c=s.address;if(a.push(c),0==(0|r._crypto_hash_sha256(c,_,n,0))){var o=p(s,t);return v(a),o}g(a,"invalid usage")}
crypto_hash_sha256_final = function we(e,t){var a=[];i(t),f(a,e,"state_address");var _=new l(0|r._crypto_hash_sha256_bytes()),n=_.address;if(a.push(n),0==(0|r._crypto_hash_sha256_final(e,n))){var s=(r._free(e),p(_,t));return v(a),s}g(a,"invalid usage")}
crypto_hash_sha256_init = function Ye(e){var t=[];i(e);var a=new l(104).address;if(0==(0|r._crypto_hash_sha256_init(a))){var _=a;return v(t),_}g(t,"invalid usage")}
crypto_hash_sha256_update = function Be(e,t,a){var _=[];i(a),f(_,e,"state_address");var n=u(t=m(_,t,"message_chunk")),s=t.length;_.push(n),0!=(0|r._crypto_hash_sha256_update(e,n,s))&&g(_,"invalid usage"),v(_)}
crypto_hash_sha512 = function Ae(e,t){var a=[];i(t);var _=u(e=m(a,e,"message")),n=e.length;a.push(_);var s=new l(0|r._crypto_hash_sha512_bytes()),c=s.address;if(a.push(c),0==(0|r._crypto_hash_sha512(c,_,n,0))){var o=p(s,t);return v(a),o}g(a,"invalid usage")}
crypto_hash_sha512_final = function Ke(e,t){var a=[];i(t),f(a,e,"state_address");var _=new l(0|r._crypto_hash_sha512_bytes()),n=_.address;if(a.push(n),0==(0|r._crypto_hash_sha512_final(e,n))){var s=(r._free(e),p(_,t));return v(a),s}g(a,"invalid usage")}
crypto_hash_sha512_init = function Me(e){var t=[];i(e);var a=new l(208).address;if(0==(0|r._crypto_hash_sha512_init(a))){var _=a;return v(t),_}g(t,"invalid usage")}
crypto_hash_sha512_update = function Ie(e,t,a){var _=[];i(a),f(_,e,"state_address");var n=u(t=m(_,t,"message_chunk")),s=t.length;_.push(n),0!=(0|r._crypto_hash_sha512_update(e,n,s))&&g(_,"invalid usage"),v(_)}
crypto_kdf_derive_from_key = function Ne(e,t,a,n,s){var c=[];i(s),f(c,e,"subkey_len"),("number"!=typeof e||(0|e)!==e||e<0)&&b(c,"subkey_len must be an unsigned integer"),f(c,t,"subkey_id"),("number"!=typeof t||(0|t)!==t||t<0)&&b(c,"subkey_id must be an unsigned integer"),"string"!=typeof a&&b(c,"ctx must be a string"),a=_(a+"\0"),null!=h&&a.length-1!==h&&b(c,"invalid ctx length");var o=u(a),h=a.length-1;c.push(o),n=m(c,n,"key");var y,d=0|r._crypto_kdf_keybytes();n.length!==d&&b(c,"invalid key length"),y=u(n),c.push(y);var g=new l(0|e),E=g.address;c.push(E),r._crypto_kdf_derive_from_key(E,e,t,t>>>24>>>8,o,y);var x=p(g,s);return v(c),x}
crypto_kdf_keygen = function Le(e){var t=[];i(e);var a=new l(0|r._crypto_kdf_keybytes()),_=a.address;t.push(_),r._crypto_kdf_keygen(_);var n=p(a,e);return v(t),n}
crypto_kx_client_session_keys = function Ue(e,t,a,_){var n=[];i(_),e=m(n,e,"clientPublicKey");var s,c=0|r._crypto_kx_publickeybytes();e.length!==c&&b(n,"invalid clientPublicKey length"),s=u(e),n.push(s),t=m(n,t,"clientSecretKey");var o,h=0|r._crypto_kx_secretkeybytes();t.length!==h&&b(n,"invalid clientSecretKey length"),o=u(t),n.push(o),a=m(n,a,"serverPublicKey");var y,d=0|r._crypto_kx_publickeybytes();a.length!==d&&b(n,"invalid serverPublicKey length"),y=u(a),n.push(y);var f=new l(0|r._crypto_kx_sessionkeybytes()),E=f.address;n.push(E);var x=new l(0|r._crypto_kx_sessionkeybytes()),k=x.address;if(n.push(k),0==(0|r._crypto_kx_client_session_keys(E,k,s,o,y))){var S=p({sharedRx:f,sharedTx:x},_);return v(n),S}g(n,"invalid usage")}
crypto_kx_keypair = function Oe(e){var t=[];i(e);var a=new l(0|r._crypto_kx_publickeybytes()),_=a.address;t.push(_);var n=new l(0|r._crypto_kx_secretkeybytes()),s=n.address;if(t.push(s),0==(0|r._crypto_kx_keypair(_,s))){var c={publicKey:p(a,e),privateKey:p(n,e),keyType:"x25519"};return v(t),c}g(t,"internal error")}
crypto_kx_seed_keypair = function Ce(e,t){var a=[];i(t),e=m(a,e,"seed");var _,n=0|r._crypto_kx_seedbytes();e.length!==n&&b(a,"invalid seed length"),_=u(e),a.push(_);var s=new l(0|r._crypto_kx_publickeybytes()),c=s.address;a.push(c);var o=new l(0|r._crypto_kx_secretkeybytes()),h=o.address;if(a.push(h),0==(0|r._crypto_kx_seed_keypair(c,h,_))){var y={publicKey:p(s,t),privateKey:p(o,t),keyType:"x25519"};return v(a),y}g(a,"internal error")}
crypto_kx_server_session_keys = function Re(e,t,a,_){var n=[];i(_),e=m(n,e,"serverPublicKey");var s,c=0|r._crypto_kx_publickeybytes();e.length!==c&&b(n,"invalid serverPublicKey length"),s=u(e),n.push(s),t=m(n,t,"serverSecretKey");var o,h=0|r._crypto_kx_secretkeybytes();t.length!==h&&b(n,"invalid serverSecretKey length"),o=u(t),n.push(o),a=m(n,a,"clientPublicKey");var y,d=0|r._crypto_kx_publickeybytes();a.length!==d&&b(n,"invalid clientPublicKey length"),y=u(a),n.push(y);var f=new l(0|r._crypto_kx_sessionkeybytes()),E=f.address;n.push(E);var x=new l(0|r._crypto_kx_sessionkeybytes()),k=x.address;if(n.push(k),0==(0|r._crypto_kx_server_session_keys(E,k,s,o,y))){var S=p({sharedRx:f,sharedTx:x},_);return v(n),S}g(n,"invalid usage")}
crypto_onetimeauth = function Pe(e,t,a){var _=[];i(a);var n=u(e=m(_,e,"message")),s=e.length;_.push(n),t=m(_,t,"key");var c,o=0|r._crypto_onetimeauth_keybytes();t.length!==o&&b(_,"invalid key length"),c=u(t),_.push(c);var h=new l(0|r._crypto_onetimeauth_bytes()),y=h.address;if(_.push(y),0==(0|r._crypto_onetimeauth(y,n,s,0,c))){var d=p(h,a);return v(_),d}g(_,"invalid usage")}
crypto_onetimeauth_final = function Ge(e,t){var a=[];i(t),f(a,e,"state_address");var _=new l(0|r._crypto_onetimeauth_bytes()),n=_.address;if(a.push(n),0==(0|r._crypto_onetimeauth_final(e,n))){var s=(r._free(e),p(_,t));return v(a),s}g(a,"invalid usage")}
crypto_onetimeauth_init = function Xe(e,t){var a=[];i(t);var _=null;null!=e&&(_=u(e=m(a,e,"key")),e.length,a.push(_));var n=new l(144).address;if(0==(0|r._crypto_onetimeauth_init(n,_))){var s=n;return v(a),s}g(a,"invalid usage")}
crypto_onetimeauth_keygen = function De(e){var t=[];i(e);var a=new l(0|r._crypto_onetimeauth_keybytes()),_=a.address;t.push(_),r._crypto_onetimeauth_keygen(_);var n=p(a,e);return v(t),n}
crypto_onetimeauth_update = function Fe(e,t,a){var _=[];i(a),f(_,e,"state_address");var n=u(t=m(_,t,"message_chunk")),s=t.length;_.push(n),0!=(0|r._crypto_onetimeauth_update(e,n,s))&&g(_,"invalid usage"),v(_)}
crypto_onetimeauth_verify = function Ve(e,t,a){var _=[];e=m(_,e,"hash");var n,s=0|r._crypto_onetimeauth_bytes();e.length!==s&&b(_,"invalid hash length"),n=u(e),_.push(n);var c=u(t=m(_,t,"message")),o=t.length;_.push(c),a=m(_,a,"key");var h,p=0|r._crypto_onetimeauth_keybytes();a.length!==p&&b(_,"invalid key length"),h=u(a),_.push(h);var y=0==(0|r._crypto_onetimeauth_verify(n,c,o,0,h));return v(_),y}
crypto_pwhash = function He(e,t,a,_,n,s,c){var o=[];i(c),f(o,e,"keyLength"),("number"!=typeof e||(0|e)!==e||e<0)&&b(o,"keyLength must be an unsigned integer");var h=u(t=m(o,t,"password")),y=t.length;o.push(h),a=m(o,a,"salt");var d,E=0|r._crypto_pwhash_saltbytes();a.length!==E&&b(o,"invalid salt length"),d=u(a),o.push(d),f(o,_,"opsLimit"),("number"!=typeof _||(0|_)!==_||_<0)&&b(o,"opsLimit must be an unsigned integer"),f(o,n,"memLimit"),("number"!=typeof n||(0|n)!==n||n<0)&&b(o,"memLimit must be an unsigned integer"),f(o,s,"algorithm"),("number"!=typeof s||(0|s)!==s||s<0)&&b(o,"algorithm must be an unsigned integer");var x=new l(0|e),k=x.address;if(o.push(k),0==(0|r._crypto_pwhash(k,e,0,h,y,0,d,_,0,n,s))){var S=p(x,c);return v(o),S}g(o,"invalid usage")}
crypto_pwhash_scryptsalsa208sha256 = function ze(e,t,a,_,n,s){var c=[];i(s),f(c,e,"keyLength"),("number"!=typeof e||(0|e)!==e||e<0)&&b(c,"keyLength must be an unsigned integer");var o=u(t=m(c,t,"password")),h=t.length;c.push(o),a=m(c,a,"salt");var y,d=0|r._crypto_pwhash_scryptsalsa208sha256_saltbytes();a.length!==d&&b(c,"invalid salt length"),y=u(a),c.push(y),f(c,_,"opsLimit"),("number"!=typeof _||(0|_)!==_||_<0)&&b(c,"opsLimit must be an unsigned integer"),f(c,n,"memLimit"),("number"!=typeof n||(0|n)!==n||n<0)&&b(c,"memLimit must be an unsigned integer");var E=new l(0|e),x=E.address;if(c.push(x),0==(0|r._crypto_pwhash_scryptsalsa208sha256(x,e,0,o,h,0,y,_,0,n))){var k=p(E,s);return v(c),k}g(c,"invalid usage")}
crypto_pwhash_scryptsalsa208sha256_ll = function je(e,t,a,_,n,s,c){var o=[];i(c);var h=u(e=m(o,e,"password")),y=e.length;o.push(h);var d=u(t=m(o,t,"salt")),E=t.length;o.push(d),f(o,a,"opsLimit"),("number"!=typeof a||(0|a)!==a||a<0)&&b(o,"opsLimit must be an unsigned integer"),f(o,_,"r"),("number"!=typeof _||(0|_)!==_||_<0)&&b(o,"r must be an unsigned integer"),f(o,n,"p"),("number"!=typeof n||(0|n)!==n||n<0)&&b(o,"p must be an unsigned integer"),f(o,s,"keyLength"),("number"!=typeof s||(0|s)!==s||s<0)&&b(o,"keyLength must be an unsigned integer");var x=new l(0|s),k=x.address;if(o.push(k),0==(0|r._crypto_pwhash_scryptsalsa208sha256_ll(h,y,d,E,a,0,_,n,k,s))){var S=p(x,c);return v(o),S}g(o,"invalid usage")}
crypto_pwhash_scryptsalsa208sha256_str = function qe(e,t,a,_){var n=[];i(_);var s=u(e=m(n,e,"password")),c=e.length;n.push(s),f(n,t,"opsLimit"),("number"!=typeof t||(0|t)!==t||t<0)&&b(n,"opsLimit must be an unsigned integer"),f(n,a,"memLimit"),("number"!=typeof a||(0|a)!==a||a<0)&&b(n,"memLimit must be an unsigned integer");var o=new l(0|r._crypto_pwhash_scryptsalsa208sha256_strbytes()).address;if(n.push(o),0==(0|r._crypto_pwhash_scryptsalsa208sha256_str(o,s,c,0,t,0,a))){var h=r.UTF8ToString(o);return v(n),h}g(n,"invalid usage")}
crypto_pwhash_scryptsalsa208sha256_str_verify = function We(e,t,a){var n=[];i(a),"string"!=typeof e&&b(n,"hashed_password must be a string"),e=_(e+"\0"),null!=c&&e.length-1!==c&&b(n,"invalid hashed_password length");var s=u(e),c=e.length-1;n.push(s);var o=u(t=m(n,t,"password")),h=t.length;n.push(o);var p=0==(0|r._crypto_pwhash_scryptsalsa208sha256_str_verify(s,o,h,0));return v(n),p}
crypto_pwhash_str = function Je(e,t,a,_){var n=[];i(_);var s=u(e=m(n,e,"password")),c=e.length;n.push(s),f(n,t,"opsLimit"),("number"!=typeof t||(0|t)!==t||t<0)&&b(n,"opsLimit must be an unsigned integer"),f(n,a,"memLimit"),("number"!=typeof a||(0|a)!==a||a<0)&&b(n,"memLimit must be an unsigned integer");var o=new l(0|r._crypto_pwhash_strbytes()).address;if(n.push(o),0==(0|r._crypto_pwhash_str(o,s,c,0,t,0,a))){var h=r.UTF8ToString(o);return v(n),h}g(n,"invalid usage")}
crypto_pwhash_str_needs_rehash = function Qe(e,t,a,n){var s=[];i(n),"string"!=typeof e&&b(s,"hashed_password must be a string"),e=_(e+"\0"),null!=o&&e.length-1!==o&&b(s,"invalid hashed_password length");var c=u(e),o=e.length-1;s.push(c),f(s,t,"opsLimit"),("number"!=typeof t||(0|t)!==t||t<0)&&b(s,"opsLimit must be an unsigned integer"),f(s,a,"memLimit"),("number"!=typeof a||(0|a)!==a||a<0)&&b(s,"memLimit must be an unsigned integer");var h=0!=(0|r._crypto_pwhash_str_needs_rehash(c,t,0,a));return v(s),h}
crypto_pwhash_str_verify = function Ze(e,t,a){var n=[];i(a),"string"!=typeof e&&b(n,"hashed_password must be a string"),e=_(e+"\0"),null!=c&&e.length-1!==c&&b(n,"invalid hashed_password length");var s=u(e),c=e.length-1;n.push(s);var o=u(t=m(n,t,"password")),h=t.length;n.push(o);var p=0==(0|r._crypto_pwhash_str_verify(s,o,h,0));return v(n),p}
crypto_scalarmult = function $e(e,t,a){var _=[];i(a),e=m(_,e,"privateKey");var n,s=0|r._crypto_scalarmult_scalarbytes();e.length!==s&&b(_,"invalid privateKey length"),n=u(e),_.push(n),t=m(_,t,"publicKey");var c,o=0|r._crypto_scalarmult_scalarbytes();t.length!==o&&b(_,"invalid publicKey length"),c=u(t),_.push(c);var h=new l(0|r._crypto_scalarmult_bytes()),y=h.address;if(_.push(y),0==(0|r._crypto_scalarmult(y,n,c))){var d=p(h,a);return v(_),d}g(_,"weak public key")}
crypto_scalarmult_base = function et(e,t){var a=[];i(t),e=m(a,e,"privateKey");var _,n=0|r._crypto_scalarmult_scalarbytes();e.length!==n&&b(a,"invalid privateKey length"),_=u(e),a.push(_);var s=new l(0|r._crypto_scalarmult_scalarbytes()),c=s.address;if(a.push(c),0==(0|r._crypto_scalarmult_base(c,_))){var o=p(s,t);return v(a),o}g(a,"insecure scalar")}
crypto_scalarmult_ristretto255 = function tt(e,t,a){var _=[];i(a),e=m(_,e,"scalar");var n,s=0|r._crypto_scalarmult_ristretto255_scalarbytes();e.length!==s&&b(_,"invalid scalar length"),n=u(e),_.push(n),t=m(_,t,"privateKey");var c,o=0|r._crypto_scalarmult_ristretto255_bytes();t.length!==o&&b(_,"invalid privateKey length"),c=u(t),_.push(c);var h=new l(0|r._crypto_scalarmult_ristretto255_bytes()),y=h.address;if(_.push(y),0==(0|r._crypto_scalarmult_ristretto255(y,n,c))){var d=p(h,a);return v(_),d}g(_,"input is zero element")}
crypto_scalarmult_ristretto255_base = function rt(e,t){var a=[];i(t);var _=u(e=m(a,e,"scalar"));e.length,a.push(_);var n=new l(0|r._crypto_core_ristretto255_bytes()),s=n.address;if(a.push(s),0==(0|r._crypto_scalarmult_ristretto255_base(s,_))){var c=p(n,t);return v(a),c}g(a,"scalar is 0")}
crypto_secretbox_detached = function at(e,t,a,_){var n=[];i(_);var s=u(e=m(n,e,"message")),c=e.length;n.push(s),t=m(n,t,"nonce");var o,h=0|r._crypto_secretbox_noncebytes();t.length!==h&&b(n,"invalid nonce length"),o=u(t),n.push(o),a=m(n,a,"key");var y,d=0|r._crypto_secretbox_keybytes();a.length!==d&&b(n,"invalid key length"),y=u(a),n.push(y);var f=new l(0|c),E=f.address;n.push(E);var x=new l(0|r._crypto_secretbox_macbytes()),k=x.address;if(n.push(k),0==(0|r._crypto_secretbox_detached(E,k,s,c,0,o,y))){var S=p({mac:x,cipher:f},_);return v(n),S}g(n,"invalid usage")}
crypto_secretbox_easy = function _t(e,t,a,_){var n=[];i(_);var s=u(e=m(n,e,"message")),c=e.length;n.push(s),t=m(n,t,"nonce");var o,h=0|r._crypto_secretbox_noncebytes();t.length!==h&&b(n,"invalid nonce length"),o=u(t),n.push(o),a=m(n,a,"key");var y,d=0|r._crypto_secretbox_keybytes();a.length!==d&&b(n,"invalid key length"),y=u(a),n.push(y);var f=new l(c+r._crypto_secretbox_macbytes()|0),E=f.address;if(n.push(E),0==(0|r._crypto_secretbox_easy(E,s,c,0,o,y))){var x=p(f,_);return v(n),x}g(n,"invalid usage")}
crypto_secretbox_keygen = function nt(e){var t=[];i(e);var a=new l(0|r._crypto_secretbox_keybytes()),_=a.address;t.push(_),r._crypto_secretbox_keygen(_);var n=p(a,e);return v(t),n}
crypto_secretbox_open_detached = function st(e,t,a,_,n){var s=[];i(n);var c=u(e=m(s,e,"ciphertext")),o=e.length;s.push(c),t=m(s,t,"mac");var h,y=0|r._crypto_secretbox_macbytes();t.length!==y&&b(s,"invalid mac length"),h=u(t),s.push(h),a=m(s,a,"nonce");var d,f=0|r._crypto_secretbox_noncebytes();a.length!==f&&b(s,"invalid nonce length"),d=u(a),s.push(d),_=m(s,_,"key");var E,x=0|r._crypto_secretbox_keybytes();_.length!==x&&b(s,"invalid key length"),E=u(_),s.push(E);var k=new l(0|o),S=k.address;if(s.push(S),0==(0|r._crypto_secretbox_open_detached(S,c,h,o,0,d,E))){var T=p(k,n);return v(s),T}g(s,"wrong secret key for the given ciphertext")}
crypto_secretbox_open_easy = function ct(e,t,a,_){var n=[];i(_),e=m(n,e,"ciphertext");var s,c=r._crypto_secretbox_macbytes(),o=e.length;o<c&&b(n,"ciphertext is too short"),s=u(e),n.push(s),t=m(n,t,"nonce");var h,y=0|r._crypto_secretbox_noncebytes();t.length!==y&&b(n,"invalid nonce length"),h=u(t),n.push(h),a=m(n,a,"key");var d,f=0|r._crypto_secretbox_keybytes();a.length!==f&&b(n,"invalid key length"),d=u(a),n.push(d);var E=new l(o-r._crypto_secretbox_macbytes()|0),x=E.address;if(n.push(x),0==(0|r._crypto_secretbox_open_easy(x,s,o,0,h,d))){var k=p(E,_);return v(n),k}g(n,"wrong secret key for the given ciphertext")}
crypto_secretstream_xchacha20poly1305_init_pull = function ot(e,t,a){var _=[];i(a),e=m(_,e,"header");var n,s=0|r._crypto_secretstream_xchacha20poly1305_headerbytes();e.length!==s&&b(_,"invalid header length"),n=u(e),_.push(n),t=m(_,t,"key");var c,o=0|r._crypto_secretstream_xchacha20poly1305_keybytes();t.length!==o&&b(_,"invalid key length"),c=u(t),_.push(c);var h=new l(52).address;if(0==(0|r._crypto_secretstream_xchacha20poly1305_init_pull(h,n,c))){var p=h;return v(_),p}g(_,"invalid usage")}
crypto_secretstream_xchacha20poly1305_init_push = function ht(e,t){var a=[];i(t),e=m(a,e,"key");var _,n=0|r._crypto_secretstream_xchacha20poly1305_keybytes();e.length!==n&&b(a,"invalid key length"),_=u(e),a.push(_);var s=new l(52).address,c=new l(0|r._crypto_secretstream_xchacha20poly1305_headerbytes()),o=c.address;if(a.push(o),0==(0|r._crypto_secretstream_xchacha20poly1305_init_push(s,o,_))){var h={state:s,header:p(c,t)};return v(a),h}g(a,"invalid usage")}
crypto_secretstream_xchacha20poly1305_keygen = function pt(e){var t=[];i(e);var a=new l(0|r._crypto_secretstream_xchacha20poly1305_keybytes()),_=a.address;t.push(_),r._crypto_secretstream_xchacha20poly1305_keygen(_);var n=p(a,e);return v(t),n}
crypto_secretstream_xchacha20poly1305_pull = function yt(e,t,a,_){var n=[];i(_),f(n,e,"state_address"),t=m(n,t,"cipher");var s,c=r._crypto_secretstream_xchacha20poly1305_abytes(),o=t.length;o<c&&b(n,"cipher is too short"),s=u(t),n.push(s);var h=null,y=0;null!=a&&(h=u(a=m(n,a,"ad")),y=a.length,n.push(h));var g=new l(o-r._crypto_secretstream_xchacha20poly1305_abytes()|0),E=g.address;n.push(E);var x,k=(x=d(1),n.push(x),(k=0===r._crypto_secretstream_xchacha20poly1305_pull(e,E,0,x,s,o,0,h,y)&&{tag:r.HEAPU8[x],message:g})&&{message:p(k.message,_),tag:k.tag});return v(n),k}
crypto_secretstream_xchacha20poly1305_push = function it(e,t,a,_,n){var s=[];i(n),f(s,e,"state_address");var c=u(t=m(s,t,"message_chunk")),o=t.length;s.push(c);var h=null,y=0;null!=a&&(h=u(a=m(s,a,"ad")),y=a.length,s.push(h)),f(s,_,"tag"),("number"!=typeof _||(0|_)!==_||_<0)&&b(s,"tag must be an unsigned integer");var d=new l(o+r._crypto_secretstream_xchacha20poly1305_abytes()|0),E=d.address;if(s.push(E),0==(0|r._crypto_secretstream_xchacha20poly1305_push(e,E,0,c,o,0,h,y,0,_))){var x=p(d,n);return v(s),x}g(s,"invalid usage")}
crypto_secretstream_xchacha20poly1305_rekey = function lt(e,t){var a=[];return i(t),f(a,e,"state_address"),r._crypto_secretstream_xchacha20poly1305_rekey(e),v(a),!0}
crypto_shorthash = function ut(e,t,a){var _=[];i(a);var n=u(e=m(_,e,"message")),s=e.length;_.push(n),t=m(_,t,"key");var c,o=0|r._crypto_shorthash_keybytes();t.length!==o&&b(_,"invalid key length"),c=u(t),_.push(c);var h=new l(0|r._crypto_shorthash_bytes()),y=h.address;if(_.push(y),0==(0|r._crypto_shorthash(y,n,s,0,c))){var d=p(h,a);return v(_),d}g(_,"invalid usage")}
crypto_shorthash_keygen = function dt(e){var t=[];i(e);var a=new l(0|r._crypto_shorthash_keybytes()),_=a.address;t.push(_),r._crypto_shorthash_keygen(_);var n=p(a,e);return v(t),n}
crypto_shorthash_siphashx24 = function vt(e,t,a){var _=[];i(a);var n=u(e=m(_,e,"message")),s=e.length;_.push(n),t=m(_,t,"key");var c,o=0|r._crypto_shorthash_siphashx24_keybytes();t.length!==o&&b(_,"invalid key length"),c=u(t),_.push(c);var h=new l(0|r._crypto_shorthash_siphashx24_bytes()),y=h.address;if(_.push(y),0==(0|r._crypto_shorthash_siphashx24(y,n,s,0,c))){var d=p(h,a);return v(_),d}g(_,"invalid usage")}
crypto_sign = function gt(e,t,a){var _=[];i(a);var n=u(e=m(_,e,"message")),s=e.length;_.push(n),t=m(_,t,"privateKey");var c,o=0|r._crypto_sign_secretkeybytes();t.length!==o&&b(_,"invalid privateKey length"),c=u(t),_.push(c);var h=new l(e.length+r._crypto_sign_bytes()|0),y=h.address;if(_.push(y),0==(0|r._crypto_sign(y,null,n,s,0,c))){var d=p(h,a);return v(_),d}g(_,"invalid usage")}
crypto_sign_detached = function bt(e,t,a){var _=[];i(a);var n=u(e=m(_,e,"message")),s=e.length;_.push(n),t=m(_,t,"privateKey");var c,o=0|r._crypto_sign_secretkeybytes();t.length!==o&&b(_,"invalid privateKey length"),c=u(t),_.push(c);var h=new l(0|r._crypto_sign_bytes()),y=h.address;if(_.push(y),0==(0|r._crypto_sign_detached(y,null,n,s,0,c))){var d=p(h,a);return v(_),d}g(_,"invalid usage")}
crypto_sign_ed25519_pk_to_curve25519 = function ft(e,t){var a=[];i(t),e=m(a,e,"edPk");var _,n=0|r._crypto_sign_publickeybytes();e.length!==n&&b(a,"invalid edPk length"),_=u(e),a.push(_);var s=new l(0|r._crypto_scalarmult_scalarbytes()),c=s.address;if(a.push(c),0==(0|r._crypto_sign_ed25519_pk_to_curve25519(c,_))){var o=p(s,t);return v(a),o}g(a,"invalid key")}
crypto_sign_ed25519_sk_to_curve25519 = function mt(e,t){var a=[];i(t),e=m(a,e,"edSk");var _,n=0|r._crypto_sign_secretkeybytes();e.length!==n&&b(a,"invalid edSk length"),_=u(e),a.push(_);var s=new l(0|r._crypto_scalarmult_scalarbytes()),c=s.address;if(a.push(c),0==(0|r._crypto_sign_ed25519_sk_to_curve25519(c,_))){var o=p(s,t);return v(a),o}g(a,"invalid key")}
crypto_sign_ed25519_sk_to_pk = function Et(e,t){var a=[];i(t),e=m(a,e,"privateKey");var _,n=0|r._crypto_sign_secretkeybytes();e.length!==n&&b(a,"invalid privateKey length"),_=u(e),a.push(_);var s=new l(0|r._crypto_sign_publickeybytes()),c=s.address;if(a.push(c),0==(0|r._crypto_sign_ed25519_sk_to_pk(c,_))){var o=p(s,t);return v(a),o}g(a,"invalid key")}
crypto_sign_ed25519_sk_to_seed = function xt(e,t){var a=[];i(t),e=m(a,e,"privateKey");var _,n=0|r._crypto_sign_secretkeybytes();e.length!==n&&b(a,"invalid privateKey length"),_=u(e),a.push(_);var s=new l(0|r._crypto_sign_seedbytes()),c=s.address;if(a.push(c),0==(0|r._crypto_sign_ed25519_sk_to_seed(c,_))){var o=p(s,t);return v(a),o}g(a,"invalid key")}
crypto_sign_final_create = function kt(e,t,a){var _=[];i(a),f(_,e,"state_address"),t=m(_,t,"privateKey");var n,s=0|r._crypto_sign_secretkeybytes();t.length!==s&&b(_,"invalid privateKey length"),n=u(t),_.push(n);var c=new l(0|r._crypto_sign_bytes()),o=c.address;if(_.push(o),0==(0|r._crypto_sign_final_create(e,o,null,n))){var h=(r._free(e),p(c,a));return v(_),h}g(_,"invalid usage")}
crypto_sign_final_verify = function St(e,t,a,_){var n=[];i(_),f(n,e,"state_address"),t=m(n,t,"signature");var s,c=0|r._crypto_sign_bytes();t.length!==c&&b(n,"invalid signature length"),s=u(t),n.push(s),a=m(n,a,"publicKey");var o,h=0|r._crypto_sign_publickeybytes();a.length!==h&&b(n,"invalid publicKey length"),o=u(a),n.push(o);var p=0==(0|r._crypto_sign_final_verify(e,s,o));return v(n),p}
crypto_sign_init = function Tt(e){var t=[];i(e);var a=new l(208).address;if(0==(0|r._crypto_sign_init(a))){var _=a;return v(t),_}g(t,"internal error")}
crypto_sign_keypair = function wt(e){var t=[];i(e);var a=new l(0|r._crypto_sign_publickeybytes()),_=a.address;t.push(_);var n=new l(0|r._crypto_sign_secretkeybytes()),s=n.address;if(t.push(s),0==(0|r._crypto_sign_keypair(_,s))){var c={publicKey:p(a,e),privateKey:p(n,e),keyType:"ed25519"};return v(t),c}g(t,"internal error")}
crypto_sign_open = function Yt(e,t,a){var _=[];i(a),e=m(_,e,"signedMessage");var n,s=r._crypto_sign_bytes(),c=e.length;c<s&&b(_,"signedMessage is too short"),n=u(e),_.push(n),t=m(_,t,"publicKey");var o,h=0|r._crypto_sign_publickeybytes();t.length!==h&&b(_,"invalid publicKey length"),o=u(t),_.push(o);var y=new l(c-r._crypto_sign_bytes()|0),d=y.address;if(_.push(d),0==(0|r._crypto_sign_open(d,null,n,c,0,o))){var f=p(y,a);return v(_),f}g(_,"incorrect signature for the given public key")}
crypto_sign_seed_keypair = function Bt(e,t){var a=[];i(t),e=m(a,e,"seed");var _,n=0|r._crypto_sign_seedbytes();e.length!==n&&b(a,"invalid seed length"),_=u(e),a.push(_);var s=new l(0|r._crypto_sign_publickeybytes()),c=s.address;a.push(c);var o=new l(0|r._crypto_sign_secretkeybytes()),h=o.address;if(a.push(h),0==(0|r._crypto_sign_seed_keypair(c,h,_))){var y={publicKey:p(s,t),privateKey:p(o,t),keyType:"ed25519"};return v(a),y}g(a,"invalid usage")}
crypto_sign_update = function At(e,t,a){var _=[];i(a),f(_,e,"state_address");var n=u(t=m(_,t,"message_chunk")),s=t.length;_.push(n),0!=(0|r._crypto_sign_update(e,n,s))&&g(_,"invalid usage"),v(_)}
crypto_sign_verify_detached = function Kt(e,t,a){var _=[];e=m(_,e,"signature");var n,s=0|r._crypto_sign_bytes();e.length!==s&&b(_,"invalid signature length"),n=u(e),_.push(n);var c=u(t=m(_,t,"message")),o=t.length;_.push(c),a=m(_,a,"publicKey");var h,p=0|r._crypto_sign_publickeybytes();a.length!==p&&b(_,"invalid publicKey length"),h=u(a),_.push(h);var y=0==(0|r._crypto_sign_verify_detached(n,c,o,0,h));return v(_),y}
crypto_stream_chacha20 = function Mt(e,t,a,_){var n=[];i(_),f(n,e,"outLength"),("number"!=typeof e||(0|e)!==e||e<0)&&b(n,"outLength must be an unsigned integer"),t=m(n,t,"key");var s,c=0|r._crypto_stream_chacha20_keybytes();t.length!==c&&b(n,"invalid key length"),s=u(t),n.push(s),a=m(n,a,"nonce");var o,h=0|r._crypto_stream_chacha20_noncebytes();a.length!==h&&b(n,"invalid nonce length"),o=u(a),n.push(o);var y=new l(0|e),d=y.address;n.push(d),r._crypto_stream_chacha20(d,e,0,o,s);var g=p(y,_);return v(n),g}
crypto_stream_chacha20_ietf_xor = function It(e,t,a,_){var n=[];i(_);var s=u(e=m(n,e,"input_message")),c=e.length;n.push(s),t=m(n,t,"nonce");var o,h=0|r._crypto_stream_chacha20_ietf_noncebytes();t.length!==h&&b(n,"invalid nonce length"),o=u(t),n.push(o),a=m(n,a,"key");var y,d=0|r._crypto_stream_chacha20_ietf_keybytes();a.length!==d&&b(n,"invalid key length"),y=u(a),n.push(y);var f=new l(0|c),E=f.address;if(n.push(E),0===r._crypto_stream_chacha20_ietf_xor(E,s,c,0,o,y)){var x=p(f,_);return v(n),x}g(n,"invalid usage")}
crypto_stream_chacha20_ietf_xor_ic = function Nt(e,t,a,_,n){var s=[];i(n);var c=u(e=m(s,e,"input_message")),o=e.length;s.push(c),t=m(s,t,"nonce");var h,y=0|r._crypto_stream_chacha20_ietf_noncebytes();t.length!==y&&b(s,"invalid nonce length"),h=u(t),s.push(h),f(s,a,"nonce_increment"),("number"!=typeof a||(0|a)!==a||a<0)&&b(s,"nonce_increment must be an unsigned integer"),_=m(s,_,"key");var d,E=0|r._crypto_stream_chacha20_ietf_keybytes();_.length!==E&&b(s,"invalid key length"),d=u(_),s.push(d);var x=new l(0|o),k=x.address;if(s.push(k),0===r._crypto_stream_chacha20_ietf_xor_ic(k,c,o,0,h,a,0,d)){var S=p(x,n);return v(s),S}g(s,"invalid usage")}
crypto_stream_chacha20_keygen = function Lt(e){var t=[];i(e);var a=new l(0|r._crypto_stream_chacha20_keybytes()),_=a.address;t.push(_),r._crypto_stream_chacha20_keygen(_);var n=p(a,e);return v(t),n}
crypto_stream_chacha20_xor = function Ut(e,t,a,_){var n=[];i(_);var s=u(e=m(n,e,"input_message")),c=e.length;n.push(s),t=m(n,t,"nonce");var o,h=0|r._crypto_stream_chacha20_noncebytes();t.length!==h&&b(n,"invalid nonce length"),o=u(t),n.push(o),a=m(n,a,"key");var y,d=0|r._crypto_stream_chacha20_keybytes();a.length!==d&&b(n,"invalid key length"),y=u(a),n.push(y);var f=new l(0|c),E=f.address;if(n.push(E),0===r._crypto_stream_chacha20_xor(E,s,c,0,o,y)){var x=p(f,_);return v(n),x}g(n,"invalid usage")}
crypto_stream_chacha20_xor_ic = function Ot(e,t,a,_,n){var s=[];i(n);var c=u(e=m(s,e,"input_message")),o=e.length;s.push(c),t=m(s,t,"nonce");var h,y=0|r._crypto_stream_chacha20_noncebytes();t.length!==y&&b(s,"invalid nonce length"),h=u(t),s.push(h),f(s,a,"nonce_increment"),("number"!=typeof a||(0|a)!==a||a<0)&&b(s,"nonce_increment must be an unsigned integer"),_=m(s,_,"key");var d,E=0|r._crypto_stream_chacha20_keybytes();_.length!==E&&b(s,"invalid key length"),d=u(_),s.push(d);var x=new l(0|o),k=x.address;if(s.push(k),0===r._crypto_stream_chacha20_xor_ic(k,c,o,0,h,a,0,d)){var S=p(x,n);return v(s),S}g(s,"invalid usage")}
crypto_stream_keygen = function Ct(e){var t=[];i(e);var a=new l(0|r._crypto_stream_keybytes()),_=a.address;t.push(_),r._crypto_stream_keygen(_);var n=p(a,e);return v(t),n}
crypto_stream_xchacha20_keygen = function Rt(e){var t=[];i(e);var a=new l(0|r._crypto_stream_xchacha20_keybytes()),_=a.address;t.push(_),r._crypto_stream_xchacha20_keygen(_);var n=p(a,e);return v(t),n}
crypto_stream_xchacha20_xor = function Pt(e,t,a,_){var n=[];i(_);var s=u(e=m(n,e,"input_message")),c=e.length;n.push(s),t=m(n,t,"nonce");var o,h=0|r._crypto_stream_xchacha20_noncebytes();t.length!==h&&b(n,"invalid nonce length"),o=u(t),n.push(o),a=m(n,a,"key");var y,d=0|r._crypto_stream_xchacha20_keybytes();a.length!==d&&b(n,"invalid key length"),y=u(a),n.push(y);var f=new l(0|c),E=f.address;if(n.push(E),0===r._crypto_stream_xchacha20_xor(E,s,c,0,o,y)){var x=p(f,_);return v(n),x}g(n,"invalid usage")}
crypto_stream_xchacha20_xor_ic = function Gt(e,t,a,_,n){var s=[];i(n);var c=u(e=m(s,e,"input_message")),o=e.length;s.push(c),t=m(s,t,"nonce");var h,y=0|r._crypto_stream_xchacha20_noncebytes();t.length!==y&&b(s,"invalid nonce length"),h=u(t),s.push(h),f(s,a,"nonce_increment"),("number"!=typeof a||(0|a)!==a||a<0)&&b(s,"nonce_increment must be an unsigned integer"),_=m(s,_,"key");var d,E=0|r._crypto_stream_xchacha20_keybytes();_.length!==E&&b(s,"invalid key length"),d=u(_),s.push(d);var x=new l(0|o),k=x.address;if(s.push(k),0===r._crypto_stream_xchacha20_xor_ic(k,c,o,0,h,a,0,d)){var S=p(x,n);return v(s),S}g(s,"invalid usage")}
randombytes_buf = function Xt(e,t){var a=[];i(t),f(a,e,"length"),("number"!=typeof e||(0|e)!==e||e<0)&&b(a,"length must be an unsigned integer");var _=new l(0|e),n=_.address;a.push(n),r._randombytes_buf(n,e);var s=p(_,t);return v(a),s}
randombytes_buf_deterministic = function Dt(e,t,a){var _=[];i(a),f(_,e,"length"),("number"!=typeof e||(0|e)!==e||e<0)&&b(_,"length must be an unsigned integer"),t=m(_,t,"seed");var n,s=0|r._randombytes_seedbytes();t.length!==s&&b(_,"invalid seed length"),n=u(t),_.push(n);var c=new l(0|e),o=c.address;_.push(o),r._randombytes_buf_deterministic(o,e,n);var h=p(c,a);return v(_),h}
randombytes_close = function Ft(e){i(e),r._randombytes_close()}
randombytes_random = function Vt(e){i(e);var t=r._randombytes_random()>>>0;return v([]),t}
randombytes_stir = function zt(e){i(e),r._randombytes_stir()}
randombytes_uniform = function jt(e,t){var a=[];i(t),f(a,e,"upper_bound"),("number"!=typeof e||(0|e)!==e||e<0)&&b(a,"upper_bound must be an unsigned integer");var _=r._randombytes_uniform(e)>>>0;return v(a),_}
sodium_version_string = function qt(){var e=r._sodium_version_string(),t=r.UTF8ToString(e);return v([]),t}
SODIUM_LIBRARY_VERSION_MAJOR = 10
SODIUM_LIBRARY_VERSION_MINOR = 3
crypto_aead_chacha20poly1305_ABYTES = 16
crypto_aead_chacha20poly1305_IETF_ABYTES = 16
crypto_aead_chacha20poly1305_IETF_KEYBYTES = 32
crypto_aead_chacha20poly1305_IETF_MESSAGEBYTES_MAX = -17
crypto_aead_chacha20poly1305_IETF_NPUBBYTES = 12
crypto_aead_chacha20poly1305_IETF_NSECBYTES = 0
crypto_aead_chacha20poly1305_KEYBYTES = 32
crypto_aead_chacha20poly1305_MESSAGEBYTES_MAX = -17
crypto_aead_chacha20poly1305_NPUBBYTES = 8
crypto_aead_chacha20poly1305_NSECBYTES = 0
crypto_aead_chacha20poly1305_ietf_ABYTES = 16
crypto_aead_chacha20poly1305_ietf_KEYBYTES = 32
crypto_aead_chacha20poly1305_ietf_MESSAGEBYTES_MAX = -17
crypto_aead_chacha20poly1305_ietf_NPUBBYTES = 12
crypto_aead_chacha20poly1305_ietf_NSECBYTES = 0
crypto_aead_xchacha20poly1305_IETF_ABYTES = 16
crypto_aead_xchacha20poly1305_IETF_KEYBYTES = 32
crypto_aead_xchacha20poly1305_IETF_MESSAGEBYTES_MAX = -17
crypto_aead_xchacha20poly1305_IETF_NPUBBYTES = 24
crypto_aead_xchacha20poly1305_IETF_NSECBYTES = 0
crypto_aead_xchacha20poly1305_ietf_ABYTES = 16
crypto_aead_xchacha20poly1305_ietf_KEYBYTES = 32
crypto_aead_xchacha20poly1305_ietf_MESSAGEBYTES_MAX = -17
crypto_aead_xchacha20poly1305_ietf_NPUBBYTES = 24
crypto_aead_xchacha20poly1305_ietf_NSECBYTES = 0
crypto_auth_BYTES = 32
crypto_auth_KEYBYTES = 32
crypto_auth_hmacsha256_BYTES = 32
crypto_auth_hmacsha256_KEYBYTES = 32
crypto_auth_hmacsha512256_BYTES = 32
crypto_auth_hmacsha512256_KEYBYTES = 32
crypto_auth_hmacsha512_BYTES = 64
crypto_auth_hmacsha512_KEYBYTES = 32
crypto_box_BEFORENMBYTES = 32
crypto_box_MACBYTES = 16
crypto_box_MESSAGEBYTES_MAX = -17
crypto_box_NONCEBYTES = 24
crypto_box_PUBLICKEYBYTES = 32
crypto_box_SEALBYTES = 48
crypto_box_SECRETKEYBYTES = 32
crypto_box_SEEDBYTES = 32
crypto_box_curve25519xchacha20poly1305_BEFORENMBYTES = 32
crypto_box_curve25519xchacha20poly1305_MACBYTES = 16
crypto_box_curve25519xchacha20poly1305_MESSAGEBYTES_MAX = -17
crypto_box_curve25519xchacha20poly1305_NONCEBYTES = 24
crypto_box_curve25519xchacha20poly1305_PUBLICKEYBYTES = 32
crypto_box_curve25519xchacha20poly1305_SEALBYTES = 48
crypto_box_curve25519xchacha20poly1305_SECRETKEYBYTES = 32
crypto_box_curve25519xchacha20poly1305_SEEDBYTES = 32
crypto_box_curve25519xsalsa20poly1305_BEFORENMBYTES = 32
crypto_box_curve25519xsalsa20poly1305_MACBYTES = 16
crypto_box_curve25519xsalsa20poly1305_MESSAGEBYTES_MAX = -17
crypto_box_curve25519xsalsa20poly1305_NONCEBYTES = 24
crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES = 32
crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES = 32
crypto_box_curve25519xsalsa20poly1305_SEEDBYTES = 32
crypto_core_ed25519_BYTES = 32
crypto_core_ed25519_HASHBYTES = 64
crypto_core_ed25519_NONREDUCEDSCALARBYTES = 64
crypto_core_ed25519_SCALARBYTES = 32
crypto_core_ed25519_UNIFORMBYTES = 32
crypto_core_hchacha20_CONSTBYTES = 16
crypto_core_hchacha20_INPUTBYTES = 16
crypto_core_hchacha20_KEYBYTES = 32
crypto_core_hchacha20_OUTPUTBYTES = 32
crypto_core_hsalsa20_CONSTBYTES = 16
crypto_core_hsalsa20_INPUTBYTES = 16
crypto_core_hsalsa20_KEYBYTES = 32
crypto_core_hsalsa20_OUTPUTBYTES = 32
crypto_core_ristretto255_BYTES = 32
crypto_core_ristretto255_HASHBYTES = 64
crypto_core_ristretto255_NONREDUCEDSCALARBYTES = 64
crypto_core_ristretto255_SCALARBYTES = 32
crypto_core_salsa2012_CONSTBYTES = 16
crypto_core_salsa2012_INPUTBYTES = 16
crypto_core_salsa2012_KEYBYTES = 32
crypto_core_salsa2012_OUTPUTBYTES = 64
crypto_core_salsa20_CONSTBYTES = 16
crypto_core_salsa20_INPUTBYTES = 16
crypto_core_salsa20_KEYBYTES = 32
crypto_core_salsa20_OUTPUTBYTES = 64
crypto_generichash_BYTES = 32
crypto_generichash_BYTES_MAX = 64
crypto_generichash_BYTES_MIN = 16
crypto_generichash_KEYBYTES = 32
crypto_generichash_KEYBYTES_MAX = 64
crypto_generichash_KEYBYTES_MIN = 16
crypto_generichash_blake2b_BYTES = 32
crypto_generichash_blake2b_BYTES_MAX = 64
crypto_generichash_blake2b_BYTES_MIN = 16
crypto_generichash_blake2b_KEYBYTES = 32
crypto_generichash_blake2b_KEYBYTES_MAX = 64
crypto_generichash_blake2b_KEYBYTES_MIN = 16
crypto_generichash_blake2b_PERSONALBYTES = 16
crypto_generichash_blake2b_SALTBYTES = 16
crypto_hash_BYTES = 64
crypto_hash_sha256_BYTES = 32
crypto_hash_sha512_BYTES = 64
crypto_kdf_BYTES_MAX = 64
crypto_kdf_BYTES_MIN = 16
crypto_kdf_CONTEXTBYTES = 8
crypto_kdf_KEYBYTES = 32
crypto_kdf_blake2b_BYTES_MAX = 64
crypto_kdf_blake2b_BYTES_MIN = 16
crypto_kdf_blake2b_CONTEXTBYTES = 8
crypto_kdf_blake2b_KEYBYTES = 32
crypto_kx_PUBLICKEYBYTES = 32
crypto_kx_SECRETKEYBYTES = 32
crypto_kx_SEEDBYTES = 32
crypto_kx_SESSIONKEYBYTES = 32
crypto_onetimeauth_BYTES = 16
crypto_onetimeauth_KEYBYTES = 32
crypto_onetimeauth_poly1305_BYTES = 16
crypto_onetimeauth_poly1305_KEYBYTES = 32
crypto_pwhash_ALG_ARGON2I13 = 1
crypto_pwhash_ALG_ARGON2ID13 = 2
crypto_pwhash_ALG_DEFAULT = 2
crypto_pwhash_BYTES_MAX = -1
crypto_pwhash_BYTES_MIN = 16
crypto_pwhash_MEMLIMIT_INTERACTIVE = 67108864
crypto_pwhash_MEMLIMIT_MAX = -2147483648
crypto_pwhash_MEMLIMIT_MIN = 8192
crypto_pwhash_MEMLIMIT_MODERATE = 268435456
crypto_pwhash_MEMLIMIT_SENSITIVE = 1073741824
crypto_pwhash_OPSLIMIT_INTERACTIVE = 2
crypto_pwhash_OPSLIMIT_MAX = -1
crypto_pwhash_OPSLIMIT_MIN = 1
crypto_pwhash_OPSLIMIT_MODERATE = 3
crypto_pwhash_OPSLIMIT_SENSITIVE = 4
crypto_pwhash_PASSWD_MAX = -1
crypto_pwhash_PASSWD_MIN = 0
crypto_pwhash_SALTBYTES = 16
crypto_pwhash_STRBYTES = 128
crypto_pwhash_argon2i_BYTES_MAX = -1
crypto_pwhash_argon2i_BYTES_MIN = 16
crypto_pwhash_argon2i_SALTBYTES = 16
crypto_pwhash_argon2i_STRBYTES = 128
crypto_pwhash_argon2id_BYTES_MAX = -1
crypto_pwhash_argon2id_BYTES_MIN = 16
crypto_pwhash_argon2id_SALTBYTES = 16
crypto_pwhash_argon2id_STRBYTES = 128
crypto_pwhash_scryptsalsa208sha256_BYTES_MAX = -1
crypto_pwhash_scryptsalsa208sha256_BYTES_MIN = 16
crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_INTERACTIVE = 16777216
crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_MAX = -1
crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_MIN = 16777216
crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_SENSITIVE = 1073741824
crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_INTERACTIVE = 524288
crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_MAX = -1
crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_MIN = 32768
crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_SENSITIVE = 33554432
crypto_pwhash_scryptsalsa208sha256_SALTBYTES = 32
crypto_pwhash_scryptsalsa208sha256_STRBYTES = 102
crypto_scalarmult_BYTES = 32
crypto_scalarmult_SCALARBYTES = 32
crypto_scalarmult_curve25519_BYTES = 32
crypto_scalarmult_curve25519_SCALARBYTES = 32
crypto_scalarmult_ed25519_BYTES = 32
crypto_scalarmult_ed25519_SCALARBYTES = 32
crypto_scalarmult_ristretto255_BYTES = 32
crypto_scalarmult_ristretto255_SCALARBYTES = 32
crypto_secretbox_KEYBYTES = 32
crypto_secretbox_MACBYTES = 16
crypto_secretbox_MESSAGEBYTES_MAX = -17
crypto_secretbox_NONCEBYTES = 24
crypto_secretbox_xchacha20poly1305_KEYBYTES = 32
crypto_secretbox_xchacha20poly1305_MACBYTES = 16
crypto_secretbox_xchacha20poly1305_MESSAGEBYTES_MAX = -17
crypto_secretbox_xchacha20poly1305_NONCEBYTES = 24
crypto_secretbox_xsalsa20poly1305_KEYBYTES = 32
crypto_secretbox_xsalsa20poly1305_MACBYTES = 16
crypto_secretbox_xsalsa20poly1305_MESSAGEBYTES_MAX = -17
crypto_secretbox_xsalsa20poly1305_NONCEBYTES = 24
crypto_secretstream_xchacha20poly1305_ABYTES = 17
crypto_secretstream_xchacha20poly1305_HEADERBYTES = 24
crypto_secretstream_xchacha20poly1305_KEYBYTES = 32
crypto_secretstream_xchacha20poly1305_MESSAGEBYTES_MAX = -18
crypto_secretstream_xchacha20poly1305_TAG_FINAL = 3
crypto_secretstream_xchacha20poly1305_TAG_MESSAGE = 0
crypto_secretstream_xchacha20poly1305_TAG_PUSH = 1
crypto_secretstream_xchacha20poly1305_TAG_REKEY = 2
crypto_shorthash_BYTES = 8
crypto_shorthash_KEYBYTES = 16
crypto_shorthash_siphash24_BYTES = 8
crypto_shorthash_siphash24_KEYBYTES = 16
crypto_shorthash_siphashx24_BYTES = 16
crypto_shorthash_siphashx24_KEYBYTES = 16
crypto_sign_BYTES = 64
crypto_sign_MESSAGEBYTES_MAX = -65
crypto_sign_PUBLICKEYBYTES = 32
crypto_sign_SECRETKEYBYTES = 64
crypto_sign_SEEDBYTES = 32
crypto_sign_ed25519_BYTES = 64
crypto_sign_ed25519_MESSAGEBYTES_MAX = -65
crypto_sign_ed25519_PUBLICKEYBYTES = 32
crypto_sign_ed25519_SECRETKEYBYTES = 64
crypto_sign_ed25519_SEEDBYTES = 32
crypto_stream_KEYBYTES = 32
crypto_stream_MESSAGEBYTES_MAX = -1
crypto_stream_NONCEBYTES = 24
crypto_stream_chacha20_IETF_KEYBYTES = 32
crypto_stream_chacha20_IETF_MESSAGEBYTES_MAX = -1
crypto_stream_chacha20_IETF_NONCEBYTES = 12
crypto_stream_chacha20_KEYBYTES = 32
crypto_stream_chacha20_MESSAGEBYTES_MAX = -1
crypto_stream_chacha20_NONCEBYTES = 8
crypto_stream_chacha20_ietf_KEYBYTES = 32
crypto_stream_chacha20_ietf_MESSAGEBYTES_MAX = -1
crypto_stream_chacha20_ietf_NONCEBYTES = 12
crypto_stream_salsa2012_KEYBYTES = 32
crypto_stream_salsa2012_MESSAGEBYTES_MAX = -1
crypto_stream_salsa2012_NONCEBYTES = 8
crypto_stream_salsa208_KEYBYTES = 32
crypto_stream_salsa208_MESSAGEBYTES_MAX = -1
crypto_stream_salsa208_NONCEBYTES = 8
crypto_stream_salsa20_KEYBYTES = 32
crypto_stream_salsa20_MESSAGEBYTES_MAX = -1
crypto_stream_salsa20_NONCEBYTES = 8
crypto_stream_xchacha20_KEYBYTES = 32
crypto_stream_xchacha20_MESSAGEBYTES_MAX = -1
crypto_stream_xchacha20_NONCEBYTES = 24
crypto_stream_xsalsa20_KEYBYTES = 32
crypto_stream_xsalsa20_MESSAGEBYTES_MAX = -1
crypto_stream_xsalsa20_NONCEBYTES = 24
crypto_verify_16_BYTES = 16
crypto_verify_32_BYTES = 32
crypto_verify_64_BYTES = 64
SODIUM_VERSION_STRING = "1.0.18"
crypto_pwhash_STRPREFIX = "$argon2id$"
crypto_pwhash_scryptsalsa208sha256_STRPREFIX = "$7$"

View File

@ -1,76 +1,89 @@
//package com.ionspin.kotlin.crypto.secretstream package com.ionspin.kotlin.crypto.secretstream
//
//import com.ionspin.kotlin.bignum.integer.util.hexColumsPrint import com.ionspin.kotlin.bignum.integer.util.hexColumsPrint
//import com.ionspin.kotlin.crypto.Initializer import com.ionspin.kotlin.crypto.LibsodiumInitializer
//import com.ionspin.kotlin.crypto.util.encodeToUByteArray import com.ionspin.kotlin.crypto.util.encodeToUByteArray
//import com.ionspin.kotlin.crypto.util.testBlocking import com.ionspin.kotlin.crypto.util.testBlocking
//import debug.test.Crypto import kotlin.test.BeforeTest
//import kotlin.math.exp import kotlin.test.Test
//import kotlin.test.Test import kotlin.test.assertTrue
//import kotlin.test.assertTrue
// /**
///** * Created by Ugljesa Jovanovic
// * Created by Ugljesa Jovanovic * ugljesa.jovanovic@ionspin.com
// * ugljesa.jovanovic@ionspin.com * on 15-Aug-2020
// * on 15-Aug-2020 */
// */ class SecretStreamTest {
//class SecretStreamTest {
// @Test @BeforeTest
// fun testSecretStream() = testBlocking { fun initialize() = testBlocking {
// Initializer.initializeWithCallback { LibsodiumInitializer.initialize()
// assertTrue { }
// val message = ("Ladies and Gentlemen of the class of '99: If I could offer you " +
// "only one tip for the future, sunscreen would be it.").encodeToUByteArray() @Test
// fun testSecretStream() = testBlocking {
// val additionalData = ubyteArrayOf( val message = ("Ladies and Gentlemen of the class of '99: If I could offer you " +
// 0x50U, 0x51U, 0x52U, 0x53U, 0xc0U, 0xc1U, 0xc2U, 0xc3U, 0xc4U, 0xc5U, 0xc6U, 0xc7U "only one tip for the future, sunscreen would be it.").encodeToUByteArray()
// )
// val key = ubyteArrayOf( val additionalData = ubyteArrayOf(
// 0x80U, 0x81U, 0x82U, 0x83U, 0x84U, 0x85U, 0x86U, 0x87U, 0x50U, 0x51U, 0x52U, 0x53U, 0xc0U, 0xc1U, 0xc2U, 0xc3U, 0xc4U, 0xc5U, 0xc6U, 0xc7U
// 0x88U, 0x89U, 0x8aU, 0x8bU, 0x8cU, 0x8dU, 0x8eU, 0x8fU, )
// 0x90U, 0x91U, 0x92U, 0x93U, 0x94U, 0x95U, 0x96U, 0x97U, val key = ubyteArrayOf(
// 0x98U, 0x99U, 0x9aU, 0x9bU, 0x9cU, 0x9dU, 0x9eU, 0x9fU, 0x80U, 0x81U, 0x82U, 0x83U, 0x84U, 0x85U, 0x86U, 0x87U,
// ) 0x88U, 0x89U, 0x8aU, 0x8bU, 0x8cU, 0x8dU, 0x8eU, 0x8fU,
// 0x90U, 0x91U, 0x92U, 0x93U, 0x94U, 0x95U, 0x96U, 0x97U,
// val nonce = ubyteArrayOf( 0x98U, 0x99U, 0x9aU, 0x9bU, 0x9cU, 0x9dU, 0x9eU, 0x9fU,
// 0x40U, 0x41U, 0x42U, 0x43U, 0x44U, 0x45U, 0x46U, 0x47U, )
// 0x48U, 0x49U, 0x4aU, 0x4bU, 0x4cU, 0x4dU, 0x4eU, 0x4fU,
// 0x50U, 0x51U, 0x52U, 0x53U, 0x54U, 0x55U, 0x56U, 0x57U, val nonce = ubyteArrayOf(
// ) 0x40U, 0x41U, 0x42U, 0x43U, 0x44U, 0x45U, 0x46U, 0x47U,
// 0x48U, 0x49U, 0x4aU, 0x4bU, 0x4cU, 0x4dU, 0x4eU, 0x4fU,
// val expected = ubyteArrayOf( 0x50U, 0x51U, 0x52U, 0x53U, 0x54U, 0x55U, 0x56U, 0x57U,
// 0xbdU, 0x6dU, 0x17U, 0x9dU, 0x3eU, 0x83U, 0xd4U, 0x3bU, )
// 0x95U, 0x76U, 0x57U, 0x94U, 0x93U, 0xc0U, 0xe9U, 0x39U,
// 0x57U, 0x2aU, 0x17U, 0x00U, 0x25U, 0x2bU, 0xfaU, 0xccU, val expected = ubyteArrayOf(
// 0xbeU, 0xd2U, 0x90U, 0x2cU, 0x21U, 0x39U, 0x6cU, 0xbbU, 0xbdU, 0x6dU, 0x17U, 0x9dU, 0x3eU, 0x83U, 0xd4U, 0x3bU,
// 0x73U, 0x1cU, 0x7fU, 0x1bU, 0x0bU, 0x4aU, 0xa6U, 0x44U, 0x95U, 0x76U, 0x57U, 0x94U, 0x93U, 0xc0U, 0xe9U, 0x39U,
// 0x0bU, 0xf3U, 0xa8U, 0x2fU, 0x4eU, 0xdaU, 0x7eU, 0x39U, 0x57U, 0x2aU, 0x17U, 0x00U, 0x25U, 0x2bU, 0xfaU, 0xccU,
// 0xaeU, 0x64U, 0xc6U, 0x70U, 0x8cU, 0x54U, 0xc2U, 0x16U, 0xbeU, 0xd2U, 0x90U, 0x2cU, 0x21U, 0x39U, 0x6cU, 0xbbU,
// 0xcbU, 0x96U, 0xb7U, 0x2eU, 0x12U, 0x13U, 0xb4U, 0x52U, 0x73U, 0x1cU, 0x7fU, 0x1bU, 0x0bU, 0x4aU, 0xa6U, 0x44U,
// 0x2fU, 0x8cU, 0x9bU, 0xa4U, 0x0dU, 0xb5U, 0xd9U, 0x45U, 0x0bU, 0xf3U, 0xa8U, 0x2fU, 0x4eU, 0xdaU, 0x7eU, 0x39U,
// 0xb1U, 0x1bU, 0x69U, 0xb9U, 0x82U, 0xc1U, 0xbbU, 0x9eU, 0xaeU, 0x64U, 0xc6U, 0x70U, 0x8cU, 0x54U, 0xc2U, 0x16U,
// 0x3fU, 0x3fU, 0xacU, 0x2bU, 0xc3U, 0x69U, 0x48U, 0x8fU, 0xcbU, 0x96U, 0xb7U, 0x2eU, 0x12U, 0x13U, 0xb4U, 0x52U,
// 0x76U, 0xb2U, 0x38U, 0x35U, 0x65U, 0xd3U, 0xffU, 0xf9U, 0x2fU, 0x8cU, 0x9bU, 0xa4U, 0x0dU, 0xb5U, 0xd9U, 0x45U,
// 0x21U, 0xf9U, 0x66U, 0x4cU, 0x97U, 0x63U, 0x7dU, 0xa9U, 0xb1U, 0x1bU, 0x69U, 0xb9U, 0x82U, 0xc1U, 0xbbU, 0x9eU,
// 0x76U, 0x88U, 0x12U, 0xf6U, 0x15U, 0xc6U, 0x8bU, 0x13U, 0x3fU, 0x3fU, 0xacU, 0x2bU, 0xc3U, 0x69U, 0x48U, 0x8fU,
// 0xb5U, 0x2eU, 0xc0U, 0x87U, 0x59U, 0x24U, 0xc1U, 0xc7U, 0x76U, 0xb2U, 0x38U, 0x35U, 0x65U, 0xd3U, 0xffU, 0xf9U,
// 0x98U, 0x79U, 0x47U, 0xdeU, 0xafU, 0xd8U, 0x78U, 0x0aU, 0x21U, 0xf9U, 0x66U, 0x4cU, 0x97U, 0x63U, 0x7dU, 0xa9U,
// 0xcfU, 0x49U 0x76U, 0x88U, 0x12U, 0xf6U, 0x15U, 0xc6U, 0x8bU, 0x13U,
// ) 0xb5U, 0x2eU, 0xc0U, 0x87U, 0x59U, 0x24U, 0xc1U, 0xc7U,
// message.hexColumsPrint() 0x98U, 0x79U, 0x47U, 0xdeU, 0xafU, 0xd8U, 0x78U, 0x0aU,
// val crypto = Crypto() 0xcfU, 0x49U
// val stateAndHeader = crypto.crypto_secretstream_xchacha20poly1305_init_push(key) )
// val encrypted = message.hexColumsPrint()
// crypto.crypto_secretstream_xchacha20poly1305_push(stateAndHeader.state, message, ubyteArrayOf(), 0U) println("---- init enc ----")
// encrypted.hexColumsPrint() val stateAndHeader = SecretStream.xChaCha20Poly1305InitPush(key)
// val decryptState = crypto.crypto_secretstream_xchacha20poly1305_init_pull(stateAndHeader.header, key) println("---- encrypt ----")
// val decrypted = val encrypted =
// crypto.crypto_secretstream_xchacha20poly1305_pull(decryptState, encrypted, ubyteArrayOf()) SecretStream.xChaCha20Poly1305Push(stateAndHeader.state, message, ubyteArrayOf(), 0U)
// decrypted.hexColumsPrint() encrypted.hexColumsPrint()
// decrypted.contentEquals(message) println("---- init dec ----")
// val decryptState = SecretStream.xChaCha20Poly1305InitPull(key, stateAndHeader.header)
// } println("---- decrypt ----")
// } val decrypted =
// } SecretStream.xChaCha20Poly1305Pull(decryptState.state, encrypted, ubyteArrayOf())
// decrypted.decryptedData.hexColumsPrint()
//} assertTrue {
decrypted.decryptedData.contentEquals(message)
}
}
}
expect fun modifyState(state: SecretStreamState, forceNonce: UByteArray)

View File

@ -45,12 +45,12 @@ interface JsSodiumInterface {
//XChaCha20Poly1305 //XChaCha20Poly1305
//encrypt //encrypt
fun crypto_secretstream_xchacha20poly1305_init_push(header: Uint8Array) : dynamic fun crypto_secretstream_xchacha20poly1305_init_push(key: Uint8Array) : dynamic
fun crypto_secretstream_xchacha20poly1305_push(state: dynamic, message: Uint8Array, additionalData: Uint8Array, tag: UByte) : Uint8Array fun crypto_secretstream_xchacha20poly1305_push(state: dynamic, message: Uint8Array, additionalData: Uint8Array, tag: UByte) : Uint8Array
//decrypt //decrypt
fun crypto_secretstream_xchacha20poly1305_init_pull(header: Uint8Array, key: Uint8Array) : dynamic fun crypto_secretstream_xchacha20poly1305_init_pull(header: Uint8Array, key: Uint8Array) : dynamic
fun crypto_secretstream_xchacha20poly1305_pull(state: dynamic, ciphertext: Uint8Array, additionalData: Uint8Array) : Uint8Array fun crypto_secretstream_xchacha20poly1305_pull(state: dynamic, ciphertext: Uint8Array, additionalData: Uint8Array) : dynamic
//util //util
fun memzero(array: Uint8Array) fun memzero(array: Uint8Array)

View File

@ -1,10 +1,16 @@
package com.ionspin.kotlin.crypto.secretstream package com.ionspin.kotlin.crypto.secretstream
import com.ionspin.kotlin.crypto.getSodium
import ext.libsodium.com.ionspin.kotlin.crypto.toUByteArray
import ext.libsodium.com.ionspin.kotlin.crypto.toUInt8Array
import org.khronos.webgl.Uint8Array
actual typealias SecretStreamState = Any actual typealias SecretStreamState = Any
actual object SecretStream { actual object SecretStream {
actual fun xChaCha20Poly1305InitPush(key: UByteArray): SecretStreamStateAndHeader { actual fun xChaCha20Poly1305InitPush(key: UByteArray): SecretStreamStateAndHeader {
TODO("not implemented yet") val state = getSodium().crypto_secretstream_xchacha20poly1305_init_push(key.toUInt8Array())
return SecretStreamStateAndHeader(state.state, (state.header as Uint8Array).toUByteArray())
} }
actual fun xChaCha20Poly1305Push( actual fun xChaCha20Poly1305Push(
@ -13,14 +19,17 @@ actual object SecretStream {
additionalData: UByteArray, additionalData: UByteArray,
tag: UByte tag: UByte
): UByteArray { ): UByteArray {
TODO("not implemented yet") return getSodium().crypto_secretstream_xchacha20poly1305_push(
state, message.toUInt8Array(), additionalData.toUInt8Array(), tag
).toUByteArray()
} }
actual fun xChaCha20Poly1305InitPull( actual fun xChaCha20Poly1305InitPull(
key: UByteArray, key: UByteArray,
header: UByteArray header: UByteArray
): SecretStreamStateAndHeader { ): SecretStreamStateAndHeader {
TODO("not implemented yet") val state = getSodium().crypto_secretstream_xchacha20poly1305_init_pull(header.toUInt8Array(), key.toUInt8Array())
return SecretStreamStateAndHeader(state, header)
} }
actual fun xChaCha20Poly1305Pull( actual fun xChaCha20Poly1305Pull(
@ -28,7 +37,11 @@ actual object SecretStream {
ciphertext: UByteArray, ciphertext: UByteArray,
additionalData: UByteArray additionalData: UByteArray
): DecryptedDataAndTag { ): DecryptedDataAndTag {
TODO("not implemented yet") val dataAndTag = getSodium().crypto_secretstream_xchacha20poly1305_pull(
state, ciphertext.toUInt8Array(), additionalData.toUInt8Array()
)
return DecryptedDataAndTag((dataAndTag.message as Uint8Array).toUByteArray(), dataAndTag.tag)
} }
} }

View File

@ -0,0 +1,4 @@
package com.ionspin.kotlin.crypto.secretstream
actual fun modifyState(state: SecretStreamState, forceNonce: UByteArray) {
}

View File

@ -0,0 +1,6 @@
package com.ionspin.kotlin.crypto.secretstream
actual fun modifyState(state: SecretStreamState, forceNonce: UByteArray) {
state.nonce = forceNonce.sliceArray(12 until 24).asByteArray()
println("Nonce modified ${state.nonce}")
}

View File

@ -1,13 +1,12 @@
package com.ionspin.kotlin.crypto.secretstream package com.ionspin.kotlin.crypto.secretstream
import com.ionspin.kotlin.crypto.util.toPtr import com.ionspin.kotlin.crypto.util.toPtr
import kotlinx.cinterop.UByteVar
import kotlinx.cinterop.convert import kotlinx.cinterop.convert
import kotlinx.cinterop.pin import kotlinx.cinterop.pin
import kotlinx.cinterop.pointed import kotlinx.cinterop.pointed
import kotlinx.cinterop.ptr import kotlinx.cinterop.ptr
import kotlinx.cinterop.reinterpret import kotlinx.cinterop.reinterpret
import kotlinx.cinterop.toCPointer import libsodium.crypto_secretstream_xchacha20poly1305_ABYTES
import libsodium.crypto_secretstream_xchacha20poly1305_headerbytes import libsodium.crypto_secretstream_xchacha20poly1305_headerbytes
import libsodium.crypto_secretstream_xchacha20poly1305_init_pull import libsodium.crypto_secretstream_xchacha20poly1305_init_pull
import libsodium.crypto_secretstream_xchacha20poly1305_init_push import libsodium.crypto_secretstream_xchacha20poly1305_init_push
@ -42,23 +41,28 @@ actual object SecretStream {
additionalData: UByteArray, additionalData: UByteArray,
tag: UByte tag: UByte
): UByteArray { ): UByteArray {
val ciphertext = UByteArray(message.size) val ciphertext = UByteArray(message.size + crypto_secretstream_xchacha20poly1305_ABYTES.toInt()) { 0U }
val ciphertextPinned = ciphertext.pin() val ciphertextPinned = ciphertext.pin()
val messagePinned = message.pin() val messagePinned = message.pin()
val additionalDataPinned = additionalData.pin() val additionalDataPinned = if (additionalData.isNotEmpty()) {
additionalData.pin()
} else {
null
}
crypto_secretstream_xchacha20poly1305_push( crypto_secretstream_xchacha20poly1305_push(
state.ptr, state.ptr,
ciphertextPinned.toPtr(), ciphertextPinned.toPtr(),
null, null,
messagePinned.toPtr(), messagePinned.toPtr(),
message.size.convert(), message.size.convert(),
additionalDataPinned.toPtr(), additionalDataPinned?.toPtr(),
additionalData.size.convert(), additionalData.size.convert(),
tag tag
) )
ciphertextPinned.unpin() ciphertextPinned.unpin()
messagePinned.unpin() messagePinned.unpin()
additionalDataPinned.unpin() additionalDataPinned?.unpin()
return ciphertext return ciphertext
} }
@ -85,27 +89,33 @@ actual object SecretStream {
ciphertext: UByteArray, ciphertext: UByteArray,
additionalData: UByteArray additionalData: UByteArray
): DecryptedDataAndTag { ): DecryptedDataAndTag {
val message = UByteArray(ciphertext.size) val message = UByteArray(ciphertext.size - crypto_secretstream_xchacha20poly1305_ABYTES.toInt())
val messagePinned = message.pin() val messagePinned = message.pin()
val ciphertextPinned = ciphertext.pin() val ciphertextPinned = ciphertext.pin()
val additionalDataPinned = additionalData.pin() val additionalDataPinned = if (additionalData.isNotEmpty()) {
additionalData.pin()
} else {
null
}
val tag = UByteArray(1) { 0U } val tag = UByteArray(1) { 0U }
val tagPinned = tag.pin() val tagPinned = tag.pin()
crypto_secretstream_xchacha20poly1305_pull( val validTag = crypto_secretstream_xchacha20poly1305_pull(
state.ptr, state.ptr,
messagePinned.toPtr(), messagePinned.toPtr(),
null, null,
tagPinned.toPtr(), tagPinned.toPtr(),
ciphertextPinned.toPtr(), ciphertextPinned.toPtr(),
ciphertext.size.convert(), ciphertext.size.convert(),
additionalDataPinned.toPtr(), additionalDataPinned?.toPtr(),
additionalData.size.convert(), additionalData.size.convert()
)
)
ciphertextPinned.unpin() ciphertextPinned.unpin()
messagePinned.unpin() messagePinned.unpin()
additionalDataPinned.unpin() additionalDataPinned?.unpin()
tagPinned.unpin() tagPinned.unpin()
if (validTag != 0) {
throw RuntimeException("Invalid tag")
}
return DecryptedDataAndTag(message, tag[0]) return DecryptedDataAndTag(message, tag[0])
} }

View File

@ -4,10 +4,11 @@ import kotlinx.cinterop.CPointer
import kotlinx.cinterop.Pinned import kotlinx.cinterop.Pinned
import kotlinx.cinterop.UByteVar import kotlinx.cinterop.UByteVar
import kotlinx.cinterop.addressOf import kotlinx.cinterop.addressOf
import kotlinx.cinterop.toCPointer
/** /**
* Created by Ugljesa Jovanovic * Created by Ugljesa Jovanovic
* ugljesa.jovanovic@ionspin.com * ugljesa.jovanovic@ionspin.com
* on 27-Aug-2020 * on 27-Aug-2020
*/ */
fun Pinned<UByteArray>.toPtr() : CPointer<UByteVar> = addressOf(0) fun Pinned<UByteArray>.toPtr() : CPointer<UByteVar>? = addressOf(0)

View File

@ -0,0 +1,4 @@
package com.ionspin.kotlin.crypto.secretstream
actual fun modifyState(state: SecretStreamState, forceNonce: UByteArray) {
}