var forge=require("./forge");require("./util"),require("./random"),require("./jsbn"),module.exports=forge.kem=forge.kem||{};var BigInteger=forge.jsbn.BigInteger;function _createKDF(e,t,r,n){e.generate=function(e,g){for(var o=new forge.util.ByteBuffer,i=Math.ceil(g/n)+r,f=new forge.util.ByteBuffer,u=r;u<i;++u){f.putInt32(u),t.start(),t.update(e+f.getBytes());var a=t.digest();o.putBytes(a.getBytes(n))}return o.truncate(o.length()-g),o.getBytes()}}forge.kem.rsa={},forge.kem.rsa.create=function(e,t){var r=(t=t||{}).prng||forge.random,n={};return n.encrypt=function(t,n){var g,o=Math.ceil(t.n.bitLength()/8);do g=new BigInteger(forge.util.bytesToHex(r.getBytesSync(o)),16).mod(t.n);while(0>=g.compareTo(BigInteger.ONE))var i=o-(g=forge.util.hexToBytes(g.toString(16))).length;return i>0&&(g=forge.util.fillString("\0",i)+g),{encapsulation:t.encrypt(g,"NONE"),key:e.generate(g,n)}},n.decrypt=function(t,r,n){var g=t.decrypt(r,"NONE");return e.generate(g,n)},n},forge.kem.kdf1=function(e,t){_createKDF(this,e,0,t||e.digestLength)},forge.kem.kdf2=function(e,t){_createKDF(this,e,1,t||e.digestLength)};