noise-c.wasm
Version:
rweather/noise-c compiled to WebAssembly using Emscripten and optimized for small size
57 lines (52 loc) • 17.3 kB
JavaScript
var __noise_c_wasm = (function() {
var _scriptDir = typeof document !== 'undefined' && document.currentScript ? document.currentScript.src : undefined;
return (
function(__noise_c_wasm) {
__noise_c_wasm = __noise_c_wasm || {};
var a;a||(a=typeof __noise_c_wasm !== 'undefined' ? __noise_c_wasm : {});var h={},l;for(l in a)a.hasOwnProperty(l)&&(h[l]=a[l]);a.arguments=[];a.thisProgram="./this.program";a.quit=function(b,c){throw c;};a.preRun=[];a.postRun=[];var m=!1,n=!1,p=!1,r=!1;m="object"===typeof window;n="function"===typeof importScripts;p="object"===typeof process&&"function"===typeof require&&!m&&!n;r=!m&&!p&&!n;var t="";function u(b){return a.locateFile?a.locateFile(b,t):t+b}
if(p){t=__dirname+"/";var v,w;a.read=function(b,c){v||(v=require("fs"));w||(w=require("path"));b=w.normalize(b);b=v.readFileSync(b);return c?b:b.toString()};a.readBinary=function(b){b=a.read(b,!0);b.buffer||(b=new Uint8Array(b));assert(b.buffer);return b};1<process.argv.length&&(a.thisProgram=process.argv[1].replace(/\\/g,"/"));a.arguments=process.argv.slice(2);process.on("uncaughtException",function(b){throw b;});process.on("unhandledRejection",function(){process.exit(1)});a.quit=function(b){process.exit(b)};
a.inspect=function(){return"[Emscripten Module object]"}}else if(r)"undefined"!=typeof read&&(a.read=function(b){return read(b)}),a.readBinary=function(b){if("function"===typeof readbuffer)return new Uint8Array(readbuffer(b));b=read(b,"binary");assert("object"===typeof b);return b},"undefined"!=typeof scriptArgs?a.arguments=scriptArgs:"undefined"!=typeof arguments&&(a.arguments=arguments),"function"===typeof quit&&(a.quit=function(b){quit(b)});else if(m||n)m?document.currentScript&&(t=document.currentScript.src):
t=self.location.href,_scriptDir&&(t=_scriptDir),0!==t.indexOf("blob:")?t=t.substr(0,t.lastIndexOf("/")+1):t="",a.read=function(b){var c=new XMLHttpRequest;c.open("GET",b,!1);c.send(null);return c.responseText},n&&(a.readBinary=function(b){var c=new XMLHttpRequest;c.open("GET",b,!1);c.responseType="arraybuffer";c.send(null);return new Uint8Array(c.response)}),a.readAsync=function(b,c,e){var d=new XMLHttpRequest;d.open("GET",b,!0);d.responseType="arraybuffer";d.onload=function(){200==d.status||0==d.status&&
d.response?c(d.response):e()};d.onerror=e;d.send(null)},a.setWindowTitle=function(b){document.title=b};var x=a.print||("undefined"!==typeof console?console.log.bind(console):"undefined"!==typeof print?print:null),y=a.printErr||("undefined"!==typeof printErr?printErr:"undefined"!==typeof console&&console.warn.bind(console)||x);for(l in h)h.hasOwnProperty(l)&&(a[l]=h[l]);h=void 0;function z(b){var c;c||(c=16);return Math.ceil(b/c)*c}
var aa={"f64-rem":function(b,c){return b%c},"debugger":function(){debugger}},A=!1;function assert(b,c){b||B("Assertion failed: "+c)}
function C(b){var c;if(0===c||!b)return"";for(var e=0,d,f=0;;){d=D[b+f>>0];e|=d;if(0==d&&!c)break;f++;if(c&&f==c)break}c||(c=f);d="";if(128>e){for(;0<c;)e=String.fromCharCode.apply(String,D.subarray(b,b+Math.min(c,1024))),d=d?d+e:e,b+=1024,c-=1024;return d}a:{c=D;for(e=b;c[e];)++e;if(16<e-b&&c.subarray&&E)b=E.decode(c.subarray(b,e));else for(e="";;){d=c[b++];if(!d){b=e;break a}if(d&128)if(f=c[b++]&63,192==(d&224))e+=String.fromCharCode((d&31)<<6|f);else{var k=c[b++]&63;if(224==(d&240))d=(d&15)<<12|
f<<6|k;else{var g=c[b++]&63;if(240==(d&248))d=(d&7)<<18|f<<12|k<<6|g;else{var q=c[b++]&63;if(248==(d&252))d=(d&3)<<24|f<<18|k<<12|g<<6|q;else{var J=c[b++]&63;d=(d&1)<<30|f<<24|k<<18|g<<12|q<<6|J}}}65536>d?e+=String.fromCharCode(d):(d-=65536,e+=String.fromCharCode(55296|d>>10,56320|d&1023))}else e+=String.fromCharCode(d)}}return b}var E="undefined"!==typeof TextDecoder?new TextDecoder("utf8"):void 0;"undefined"!==typeof TextDecoder&&new TextDecoder("utf-16le");var buffer,D,F;
function G(){a.HEAP8=new Int8Array(buffer);a.HEAP16=new Int16Array(buffer);a.HEAP32=F=new Int32Array(buffer);a.HEAPU8=D=new Uint8Array(buffer);a.HEAPU16=new Uint16Array(buffer);a.HEAPU32=new Uint32Array(buffer);a.HEAPF32=new Float32Array(buffer);a.HEAPF64=new Float64Array(buffer)}var H,I,K,L,M,N,O;H=I=K=L=M=N=O=0;
function P(){B("Cannot enlarge memory arrays. Either (1) compile with -s TOTAL_MEMORY=X with X higher than the current value "+Q+", (2) compile with -s ALLOW_MEMORY_GROWTH=1 which allows increasing the size at runtime, or (3) if you want malloc to return NULL (0) instead of this abort, compile with -s ABORTING_MALLOC=0 ")}var R=a.TOTAL_STACK||5242880,Q=a.TOTAL_MEMORY||16777216;Q<R&&y("TOTAL_MEMORY should be larger than TOTAL_STACK, was "+Q+"! (TOTAL_STACK="+R+")");
a.buffer?buffer=a.buffer:("object"===typeof WebAssembly&&"function"===typeof WebAssembly.Memory?(a.wasmMemory=new WebAssembly.Memory({initial:Q/65536,maximum:Q/65536}),buffer=a.wasmMemory.buffer):buffer=new ArrayBuffer(Q),a.buffer=buffer);G();function S(b){for(;0<b.length;){var c=b.shift();if("function"==typeof c)c();else{var e=c.g;"number"===typeof e?void 0===c.b?a.dynCall_v(e):a.dynCall_vi(e,c.b):e(void 0===c.b?null:c.b)}}}var T=[],ba=[],ca=[],da=[],ea=!1;
function fa(){var b=a.preRun.shift();T.unshift(b)}var U=0,V=null,W=null;a.preloadedImages={};a.preloadedAudios={};function X(b){return String.prototype.startsWith?b.startsWith("data:application/octet-stream;base64,"):0===b.indexOf("data:application/octet-stream;base64,")}
(function(){function b(){try{if(a.wasmBinary)return new Uint8Array(a.wasmBinary);if(a.readBinary)return a.readBinary(f);throw"both async and sync fetching of the wasm failed";}catch(ja){B(ja)}}function c(){return a.wasmBinary||!m&&!n||"function"!==typeof fetch?new Promise(function(c){c(b())}):fetch(f,{credentials:"same-origin"}).then(function(b){if(!b.ok)throw"failed to load wasm binary file at '"+f+"'";return b.arrayBuffer()}).catch(function(){return b()})}function e(b){function d(b){q=b.exports;
if(q.memory){b=q.memory;var c=a.buffer;b.byteLength<c.byteLength&&y("the new buffer in mergeMemory is smaller than the previous one. in native wasm, we should grow memory here");c=new Int8Array(c);(new Int8Array(b)).set(c);a.buffer=buffer=b;G()}a.asm=q;a.usingWasm=!0;U--;a.monitorRunDependencies&&a.monitorRunDependencies(U);0==U&&(null!==V&&(clearInterval(V),V=null),W&&(b=W,W=null,b()))}function e(b){d(b.instance)}function k(b){c().then(function(b){return WebAssembly.instantiate(b,g)}).then(b).catch(function(b){y("failed to asynchronously prepare wasm: "+
b);B(b)})}if("object"!==typeof WebAssembly)return y("no native wasm support detected"),!1;if(!(a.wasmMemory instanceof WebAssembly.Memory))return y("no native wasm Memory in use"),!1;b.memory=a.wasmMemory;g.global={NaN:NaN,Infinity:Infinity};g["global.Math"]=Math;g.env=b;U++;a.monitorRunDependencies&&a.monitorRunDependencies(U);if(a.instantiateWasm)try{return a.instantiateWasm(g,d)}catch(ka){return y("Module.instantiateWasm callback failed with error: "+ka),!1}a.wasmBinary||"function"!==typeof WebAssembly.instantiateStreaming||
X(f)||"function"!==typeof fetch?k(e):WebAssembly.instantiateStreaming(fetch(f,{credentials:"same-origin"}),g).then(e).catch(function(b){y("wasm streaming compile failed: "+b);y("falling back to ArrayBuffer instantiation");k(e)});return{}}var d="noise-c.wast",f="noise-c.wasm",k="noise-c.temp.asm.js";X(d)||(d=u(d));X(f)||(f=u(f));X(k)||(k=u(k));var g={global:null,env:null,asm2wasm:aa,parent:a},q=null;a.asmPreload=a.asm;var J=a.reallocBuffer;a.reallocBuffer=function(b){if("asmjs"===la)var c=J(b);else a:{var d=
a.usingWasm?65536:16777216;0<b%d&&(b+=d-b%d);d=a.buffer.byteLength;if(a.usingWasm)try{c=-1!==a.wasmMemory.grow((b-d)/65536)?a.buffer=a.wasmMemory.buffer:null;break a}catch(ra){c=null;break a}c=void 0}return c};var la="";a.asm=function(b,c){if(!c.table){b=a.wasmTableSize;void 0===b&&(b=1024);var d=a.wasmMaxTableSize;c.table="object"===typeof WebAssembly&&"function"===typeof WebAssembly.Table?void 0!==d?new WebAssembly.Table({initial:b,maximum:d,element:"anyfunc"}):new WebAssembly.Table({initial:b,
element:"anyfunc"}):Array(b);a.wasmTable=c.table}c.memoryBase||(c.memoryBase=a.STATIC_BASE);c.tableBase||(c.tableBase=0);c=e(c);assert(c,"no binaryen method succeeded.");return c}})();H=1024;I=H+42720;ba.push();a.STATIC_BASE=H;a.STATIC_BUMP=42720;I+=16;function Y(){Y.a||(Y.a=[]);Y.a.push(ha());return Y.a.length-1}var ia=I;I=I+4+15&-16;O=ia;K=L=z(I);M=K+R;N=z(M);F[O>>2]=N;a.wasmTableSize=68;a.wasmMaxTableSize=68;a.c={};
a.f={abort:B,enlargeMemory:function(){P()},getTotalMemory:function(){return Q},abortOnCannotGrowMemory:P,___assert_fail:function(b,c,e,d){B("Assertion failed: "+C(b)+", at: "+[c?C(c):"unknown filename",e,d?C(d):"unknown function"])},___setErrNo:function(b){a.___errno_location&&(F[a.___errno_location()>>2]=b);return b},_emscripten_memcpy_big:function(b,c,e){D.set(D.subarray(c,c+e),b);return b},_llvm_stackrestore:function(b){var c=Y.a[b];Y.a.splice(b,1);ma(c)},_llvm_stacksave:Y,_noise_rand_bytes:function(b,
c){D.set(a._random_bytes(c),b)},DYNAMICTOP_PTR:O,STACKTOP:L};var na=a.asm(a.c,a.f,buffer);a.asm=na;a._NoiseBuffer_create=function(){return a.asm._NoiseBuffer_create.apply(null,arguments)};a._NoiseBuffer_get_size=function(){return a.asm._NoiseBuffer_get_size.apply(null,arguments)};a._NoiseHandshakeState_get_hash_id=function(){return a.asm._NoiseHandshakeState_get_hash_id.apply(null,arguments)};a._SymmetricState_get_ck=function(){return a.asm._SymmetricState_get_ck.apply(null,arguments)};
var oa=a._free=function(){return a.asm._free.apply(null,arguments)},pa=a._malloc=function(){return a.asm._malloc.apply(null,arguments)};a._noise_cipherstate_decrypt_with_ad=function(){return a.asm._noise_cipherstate_decrypt_with_ad.apply(null,arguments)};a._noise_cipherstate_encrypt_with_ad=function(){return a.asm._noise_cipherstate_encrypt_with_ad.apply(null,arguments)};a._noise_cipherstate_free=function(){return a.asm._noise_cipherstate_free.apply(null,arguments)};
a._noise_cipherstate_get_mac_length=function(){return a.asm._noise_cipherstate_get_mac_length.apply(null,arguments)};a._noise_cipherstate_has_key=function(){return a.asm._noise_cipherstate_has_key.apply(null,arguments)};a._noise_cipherstate_init_key=function(){return a.asm._noise_cipherstate_init_key.apply(null,arguments)};a._noise_cipherstate_new_by_id=function(){return a.asm._noise_cipherstate_new_by_id.apply(null,arguments)};
a._noise_cipherstate_set_nonce=function(){return a.asm._noise_cipherstate_set_nonce.apply(null,arguments)};a._noise_dhstate_free=function(){return a.asm._noise_dhstate_free.apply(null,arguments)};a._noise_dhstate_generate_keypair=function(){return a.asm._noise_dhstate_generate_keypair.apply(null,arguments)};a._noise_dhstate_get_dh_id=function(){return a.asm._noise_dhstate_get_dh_id.apply(null,arguments)};a._noise_dhstate_get_keypair=function(){return a.asm._noise_dhstate_get_keypair.apply(null,arguments)};
a._noise_dhstate_get_public_key=function(){return a.asm._noise_dhstate_get_public_key.apply(null,arguments)};a._noise_dhstate_get_public_key_length=function(){return a.asm._noise_dhstate_get_public_key_length.apply(null,arguments)};a._noise_dhstate_new_by_id=function(){return a.asm._noise_dhstate_new_by_id.apply(null,arguments)};a._noise_dhstate_set_keypair_private=function(){return a.asm._noise_dhstate_set_keypair_private.apply(null,arguments)};
a._noise_dhstate_set_public_key=function(){return a.asm._noise_dhstate_set_public_key.apply(null,arguments)};a._noise_handshakestate_fallback_to=function(){return a.asm._noise_handshakestate_fallback_to.apply(null,arguments)};a._noise_handshakestate_free=function(){return a.asm._noise_handshakestate_free.apply(null,arguments)};a._noise_handshakestate_get_action=function(){return a.asm._noise_handshakestate_get_action.apply(null,arguments)};
a._noise_handshakestate_get_fixed_ephemeral_dh=function(){return a.asm._noise_handshakestate_get_fixed_ephemeral_dh.apply(null,arguments)};a._noise_handshakestate_get_fixed_hybrid_dh=function(){return a.asm._noise_handshakestate_get_fixed_hybrid_dh.apply(null,arguments)};a._noise_handshakestate_get_handshake_hash=function(){return a.asm._noise_handshakestate_get_handshake_hash.apply(null,arguments)};
a._noise_handshakestate_get_local_keypair_dh=function(){return a.asm._noise_handshakestate_get_local_keypair_dh.apply(null,arguments)};a._noise_handshakestate_get_protocol_id=function(){return a.asm._noise_handshakestate_get_protocol_id.apply(null,arguments)};a._noise_handshakestate_get_remote_public_key_dh=function(){return a.asm._noise_handshakestate_get_remote_public_key_dh.apply(null,arguments)};
a._noise_handshakestate_has_remote_public_key=function(){return a.asm._noise_handshakestate_has_remote_public_key.apply(null,arguments)};a._noise_handshakestate_needs_local_keypair=function(){return a.asm._noise_handshakestate_needs_local_keypair.apply(null,arguments)};a._noise_handshakestate_needs_pre_shared_key=function(){return a.asm._noise_handshakestate_needs_pre_shared_key.apply(null,arguments)};
a._noise_handshakestate_needs_remote_public_key=function(){return a.asm._noise_handshakestate_needs_remote_public_key.apply(null,arguments)};a._noise_handshakestate_new_by_name=function(){return a.asm._noise_handshakestate_new_by_name.apply(null,arguments)};a._noise_handshakestate_read_message=function(){return a.asm._noise_handshakestate_read_message.apply(null,arguments)};a._noise_handshakestate_set_pre_shared_key=function(){return a.asm._noise_handshakestate_set_pre_shared_key.apply(null,arguments)};
a._noise_handshakestate_set_prologue=function(){return a.asm._noise_handshakestate_set_prologue.apply(null,arguments)};a._noise_handshakestate_split=function(){return a.asm._noise_handshakestate_split.apply(null,arguments)};a._noise_handshakestate_start=function(){return a.asm._noise_handshakestate_start.apply(null,arguments)};a._noise_handshakestate_write_message=function(){return a.asm._noise_handshakestate_write_message.apply(null,arguments)};
a._noise_symmetricstate_decrypt_and_hash=function(){return a.asm._noise_symmetricstate_decrypt_and_hash.apply(null,arguments)};a._noise_symmetricstate_encrypt_and_hash=function(){return a.asm._noise_symmetricstate_encrypt_and_hash.apply(null,arguments)};a._noise_symmetricstate_free=function(){return a.asm._noise_symmetricstate_free.apply(null,arguments)};a._noise_symmetricstate_get_mac_length=function(){return a.asm._noise_symmetricstate_get_mac_length.apply(null,arguments)};
a._noise_symmetricstate_mix_hash=function(){return a.asm._noise_symmetricstate_mix_hash.apply(null,arguments)};a._noise_symmetricstate_mix_key=function(){return a.asm._noise_symmetricstate_mix_key.apply(null,arguments)};a._noise_symmetricstate_new_by_name=function(){return a.asm._noise_symmetricstate_new_by_name.apply(null,arguments)};a._noise_symmetricstate_split=function(){return a.asm._noise_symmetricstate_split.apply(null,arguments)};
var ma=a.stackRestore=function(){return a.asm.stackRestore.apply(null,arguments)},ha=a.stackSave=function(){return a.asm.stackSave.apply(null,arguments)};a.dynCall_vi=function(){return a.asm.dynCall_vi.apply(null,arguments)};a.asm=na;a.then=function(b){if(a.calledRun)b(a);else{var c=a.onRuntimeInitialized;a.onRuntimeInitialized=function(){c&&c();b(a)}}return a};W=function qa(){a.calledRun||Z();a.calledRun||(W=qa)};
function Z(){function b(){if(!a.calledRun&&(a.calledRun=!0,!A)){ea||(ea=!0,S(ba));S(ca);if(a.onRuntimeInitialized)a.onRuntimeInitialized();if(a.postRun)for("function"==typeof a.postRun&&(a.postRun=[a.postRun]);a.postRun.length;){var b=a.postRun.shift();da.unshift(b)}S(da)}}if(!(0<U)){if(a.preRun)for("function"==typeof a.preRun&&(a.preRun=[a.preRun]);a.preRun.length;)fa();S(T);0<U||a.calledRun||(a.setStatus?(a.setStatus("Running..."),setTimeout(function(){setTimeout(function(){a.setStatus("")},1);
b()},1)):b())}}a.run=Z;function B(b){if(a.onAbort)a.onAbort(b);void 0!==b?(x(b),y(b),b=JSON.stringify(b)):b="";A=!0;throw"abort("+b+"). Build with -s ASSERTIONS=1 for more info.";}a.abort=B;if(a.preInit)for("function"==typeof a.preInit&&(a.preInit=[a.preInit]);0<a.preInit.length;)a.preInit.pop()();a.noExitRuntime=!0;Z();
(function(){function b(b){if(b&&b.buffer instanceof ArrayBuffer)b=new Uint8Array(b.buffer,b.byteOffset,b.byteLength);else if("string"===typeof b){for(var c=b.length,d=new Uint8Array(c+1),f=0;f<c;++f)d[f]=b.charCodeAt(f);return d}return b}function c(f,e){var g=new Number(f);g.length=e;g.get=function(b){b=b||Uint8Array;return(new b(buffer,g,e/b.BYTES_PER_ELEMENT)).slice()};g.dereference=function(b){b=b||4;return c(g.get(Uint32Array)[0],b)};g.set=function(c){c=b(c);if(c.length>e)throw RangeError("invalid array length");
D.set(c,g)};g.free=function(){oa(g);d.splice(d.indexOf(g),1)};d.push(g);return g}function e(d,e){e=b(e);0===d&&(d=e.length);var f=c(pa(d),d);void 0!==e?(f.set(e),e.length<d&&D.fill(0,f+e.length,f+d)):D.fill(0,f,f+d);return f}var d=[];a.createPointer=c;a.allocatePointer=function(b){b&&(b=Uint32Array.of(b));return e(4,b)};a.allocateBytes=e;a.freeBytes=function(){for(var b=0,c=d.length;b<c;++b)oa(d[b]);d=[]}})();
return __noise_c_wasm;
}
);
})();
if (typeof exports === 'object' && typeof module === 'object')
module.exports = __noise_c_wasm;
else if (typeof define === 'function' && define['amd'])
define([], function() { return __noise_c_wasm; });
else if (typeof exports === 'object')
exports["__noise_c_wasm"] = __noise_c_wasm;