UNPKG

hsynchronous

Version:

Hybrid synchronous encryption protocol using NIST approved post-quantum algorithms.

1 lines 594 B
'use strict';var crypto=require('crypto');function i(f,e){let r=crypto.createHmac("sha256",f),t=Buffer.concat([e,Buffer.alloc(Math.max(0,256-e.length))]);return r.update(t),r.digest()}function h(f,e,r,t){let s=i(e,f),B=Math.ceil(t/32),a=[],u=Buffer.alloc(0);for(let n=0;n<B;n++){let o=crypto.createHmac("sha256",s);o.update(Buffer.concat([u,r,Buffer.from([n+1])])),u=o.digest(),a.push(u);}return Buffer.concat(a).subarray(0,t)}function m(f){for(let e=0;e<f.length;e++)f[e]=0;}function d(f,e=1024){let r=e-f.length%e;return f+"\0".repeat(r)}exports.hkdf=h;exports.padData=d;exports.secureZero=m;