var forge=require("./forge");require("./util"),require("./jsbn"),require("./random"),function(){if(forge.prime){module.exports=forge.prime;return}var e=module.exports=forge.prime=forge.prime||{},r=forge.jsbn.BigInteger,t=[6,4,2,4,2,4,6,2],n=new r(null);n.fromInt(30);var o=function(e,r){return e|r};function i(e,r,n,o){var i,f=a(e,r),u=(i=f.bitLength())<=100?27:i<=150?18:i<=200?15:i<=250?12:i<=300?9:i<=350?8:i<=400?7:i<=500?6:i<=600?5:i<=800?4:i<=1250?3:2;"millerRabinTests"in n&&(u=n.millerRabinTests);var s=10;"maxBlockTime"in n&&(s=n.maxBlockTime),function e(r,n,o,i,f,u,s){var m=+new Date;do{if(r.bitLength()>n&&(r=a(n,o)),r.isProbablePrime(f))return s(null,r);r.dAddOffset(t[i++%8],0)}while(u<0||new Date-m<u)forge.util.setImmediate(function(){e(r,n,o,i,f,u,s)})}(f,e,r,0,u,s,o)}function a(e,t){var i=new r(e,t),a=e-1;return i.testBit(a)||i.bitwiseTo(r.ONE.shiftLeft(a),o,i),i.dAddOffset(31-i.mod(n).byteValue(),0),i}e.generateProbablePrime=function(e,t,n){"function"==typeof t&&(n=t,t={});var o,f,u,s,m=(t=t||{}).algorithm||"PRIMEINC";"string"==typeof m&&(m={name:m}),m.options=m.options||{};var g=t.prng||forge.random;if("PRIMEINC"===m.name){return o=e,f={nextBytes:function(e){for(var r=g.getBytesSync(e.length),t=0;t<e.length;++t)e[t]=r.charCodeAt(t)}},u=m.options,s=n,"workers"in u?function(e,t,n,o){if("u"<typeof Worker)return i(e,t,n,o);var f=a(e,t),u=n.workers,s=n.workLoad||100,m=30*s/8,g=n.workerScript||"forge/prime.worker.js";if(-1===u)return forge.util.estimateCores(function(e,r){e&&(r=2),u=r-1,l()});function l(){u=Math.max(1,u);for(var n=[],i=0;i<u;++i)n[i]=new Worker(g);for(var l=u,i=0;i<u;++i)n[i].addEventListener("message",v);var d=!1;function v(i){if(!d){--l;var u=i.data;if(u.found){for(var g=0;g<n.length;++g)n[g].terminate();return d=!0,o(null,new r(u.prime,16))}f.bitLength()>e&&(f=a(e,t));var v=f.toString(16);i.target.postMessage({hex:v,workLoad:s}),f.dAddOffset(m,0)}}}l()}(o,f,u,s):i(o,f,u,s)}throw Error("Invalid prime generation algorithm: "+m.name)}}();