UNPKG

kyberkotlin

Version:

ML-KEM (NIST FIPS 203) optimized implementation on 100% Kotlin.

249 lines (247 loc) 9.8 kB
(function (factory) { if (typeof define === 'function' && define.amd) define(['exports', './kotlin-kotlin-stdlib.js', './error-library-error.js'], factory); else if (typeof exports === 'object') factory(module.exports, require('./kotlin-kotlin-stdlib.js'), require('./error-library-error.js')); else { if (typeof globalThis['kotlin-kotlin-stdlib'] === 'undefined') { throw new Error("Error loading module 'random-library-crypto-rand'. Its dependency 'kotlin-kotlin-stdlib' was not found. Please, check whether 'kotlin-kotlin-stdlib' is loaded prior to 'random-library-crypto-rand'."); } if (typeof globalThis['error-library-error'] === 'undefined') { throw new Error("Error loading module 'random-library-crypto-rand'. Its dependency 'error-library-error' was not found. Please, check whether 'error-library-error' is loaded prior to 'random-library-crypto-rand'."); } globalThis['random-library-crypto-rand'] = factory(typeof globalThis['random-library-crypto-rand'] === 'undefined' ? {} : globalThis['random-library-crypto-rand'], globalThis['kotlin-kotlin-stdlib'], globalThis['error-library-error']); } }(function (_, kotlin_kotlin, kotlin_org_kotlincrypto_error) { 'use strict'; //region block: imports var protoOf = kotlin_kotlin.$_$.q1; var initMetadataForObject = kotlin_kotlin.$_$.j1; var VOID = kotlin_kotlin.$_$.b; var initMetadataForClass = kotlin_kotlin.$_$.h1; var GeneralSecurityException_init_$Init$ = kotlin_org_kotlincrypto_error.$_$.a; var objectCreate = kotlin_kotlin.$_$.p1; var captureStack = kotlin_kotlin.$_$.b1; var GeneralSecurityException_init_$Init$_0 = kotlin_org_kotlincrypto_error.$_$.b; var GeneralSecurityException = kotlin_org_kotlincrypto_error.$_$.c; var THROW_CCE = kotlin_kotlin.$_$.c2; var isNumber = kotlin_kotlin.$_$.l1; var numberToByte = kotlin_kotlin.$_$.o1; var Unit_instance = kotlin_kotlin.$_$.o; var KProperty0 = kotlin_kotlin.$_$.w1; var getPropertyCallableRef = kotlin_kotlin.$_$.g1; var lazy = kotlin_kotlin.$_$.e2; //endregion //region block: pre-declaration initMetadataForClass(CryptoRand, 'CryptoRand'); initMetadataForObject(Default, 'Default', VOID, CryptoRand); initMetadataForClass(RandomnessProcurementException, 'RandomnessProcurementException', RandomnessProcurementException_init_$Create$, GeneralSecurityException); //endregion function Default() { Default_instance = this; CryptoRand.call(this); } protoOf(Default).a3 = function (buf) { // Inline function 'kotlin.collections.isEmpty' call if (buf.length === 0) return buf; cryptoRandFill(buf); return buf; }; protoOf(Default).toString = function () { return 'CryptoRand.Default'; }; var Default_instance; function Default_getInstance() { if (Default_instance == null) new Default(); return Default_instance; } function CryptoRand() { Default_getInstance(); } function RandomnessProcurementException_init_$Init$($this) { GeneralSecurityException_init_$Init$($this); RandomnessProcurementException.call($this); return $this; } function RandomnessProcurementException_init_$Create$() { var tmp = RandomnessProcurementException_init_$Init$(objectCreate(protoOf(RandomnessProcurementException))); captureStack(tmp, RandomnessProcurementException_init_$Create$); return tmp; } function RandomnessProcurementException_init_$Init$_0(message, cause, $this) { GeneralSecurityException_init_$Init$_0(message, cause, $this); RandomnessProcurementException.call($this); return $this; } function RandomnessProcurementException_init_$Create$_0(message, cause) { var tmp = RandomnessProcurementException_init_$Init$_0(message, cause, objectCreate(protoOf(RandomnessProcurementException))); captureStack(tmp, RandomnessProcurementException_init_$Create$_0); return tmp; } function RandomnessProcurementException() { captureStack(this, RandomnessProcurementException); } function get_IS_NODE_JS() { _init_properties_JsPlatform_kt__dfptms(); var tmp0 = IS_NODE_JS$delegate; // Inline function 'kotlin.getValue' call IS_NODE_JS$factory(); return tmp0.y2(); } var IS_NODE_JS$delegate; function get_CRYPTO() { _init_properties_JsPlatform_kt__dfptms(); var tmp0 = CRYPTO$delegate; // Inline function 'kotlin.getValue' call CRYPTO$factory(); return tmp0.y2(); } var CRYPTO$delegate; function isNodeJs() { _init_properties_JsPlatform_kt__dfptms(); var tmp = typeof process !== 'undefined' && process.versions != null && process.versions.node != null || (typeof window !== 'undefined' && typeof window.process !== 'undefined' && window.process.versions != null && window.process.versions.node != null); return (!(tmp == null) ? typeof tmp === 'boolean' : false) ? tmp : THROW_CCE(); } function cryptoNode() { _init_properties_JsPlatform_kt__dfptms(); // Inline function 'kotlin.js.unsafeCast' call return eval('require')('crypto'); } function cryptoBrowser() { _init_properties_JsPlatform_kt__dfptms(); // Inline function 'kotlin.js.unsafeCast' call return window ? window.crypto ? window.crypto : window.msCrypto : self.crypto; } function cryptoRandFill(_this__u8e3s4) { _init_properties_JsPlatform_kt__dfptms(); try { var tmp; if (get_IS_NODE_JS()) { tmp = Crypto$randomFillSync$ref(get_CRYPTO()); } else { tmp = Crypto$getRandomValues$ref(get_CRYPTO()); } var jsCryptoFill = tmp; if (_this__u8e3s4.length <= 8192) { // Inline function 'kotlin.js.asDynamic' call var bufDynamic = new Uint8Array(_this__u8e3s4.length); jsCryptoFill(bufDynamic); var inductionVariable = 0; var last = _this__u8e3s4.length - 1 | 0; if (inductionVariable <= last) do { var i = inductionVariable; inductionVariable = inductionVariable + 1 | 0; var tmp_0 = bufDynamic[i]; _this__u8e3s4[i] = numberToByte(isNumber(tmp_0) ? tmp_0 : THROW_CCE()); bufDynamic[i] = 0; } while (inductionVariable <= last); return Unit_instance; } var buf = new Uint8Array(8192); // Inline function 'kotlin.js.asDynamic' call var bufDynamic_0 = buf; var needed = _this__u8e3s4.length; var pos = 0; while (needed > 8192) { jsCryptoFill(bufDynamic_0); var inductionVariable_0 = 0; if (inductionVariable_0 < 8192) do { var i_0 = inductionVariable_0; inductionVariable_0 = inductionVariable_0 + 1 | 0; var _unary__edvuaz = pos; pos = _unary__edvuaz + 1 | 0; var tmp_1 = bufDynamic_0[i_0]; _this__u8e3s4[_unary__edvuaz] = numberToByte(isNumber(tmp_1) ? tmp_1 : THROW_CCE()); } while (inductionVariable_0 < 8192); needed = needed - 8192 | 0; } if (needed > 0) { // Inline function 'kotlin.js.asDynamic' call jsCryptoFill(buf.subarray(0, needed)); var inductionVariable_1 = 0; var last_0 = needed; if (inductionVariable_1 < last_0) do { var i_1 = inductionVariable_1; inductionVariable_1 = inductionVariable_1 + 1 | 0; var _unary__edvuaz_0 = pos; pos = _unary__edvuaz_0 + 1 | 0; var tmp_2 = bufDynamic_0[i_1]; _this__u8e3s4[_unary__edvuaz_0] = numberToByte(isNumber(tmp_2) ? tmp_2 : THROW_CCE()); bufDynamic_0[i_1] = 0; } while (inductionVariable_1 < last_0); } var inductionVariable_2 = needed; if (inductionVariable_2 < 8192) do { var i_2 = inductionVariable_2; inductionVariable_2 = inductionVariable_2 + 1 | 0; bufDynamic_0[i_2] = 0; } while (inductionVariable_2 < 8192); } catch ($p) { if ($p instanceof Error) { var t = $p; var fn = get_IS_NODE_JS() ? 'randomFillSync' : 'getRandomValues'; throw RandomnessProcurementException_init_$Create$_0('Failed to obtain bytes from [crypto.' + fn + ']', t); } else { throw $p; } } } function IS_NODE_JS$delegate$lambda() { _init_properties_JsPlatform_kt__dfptms(); return isNodeJs(); } function CRYPTO$delegate$lambda() { _init_properties_JsPlatform_kt__dfptms(); return get_IS_NODE_JS() ? cryptoNode() : cryptoBrowser(); } function Crypto$randomFillSync$ref($boundThis) { var l = function (p0) { $boundThis.randomFillSync(p0); return Unit_instance; }; l.callableName = 'randomFillSync'; return l; } function Crypto$getRandomValues$ref($boundThis) { var l = function (p0) { $boundThis.getRandomValues(p0); return Unit_instance; }; l.callableName = 'getRandomValues'; return l; } function IS_NODE_JS$factory() { return getPropertyCallableRef('IS_NODE_JS', 0, KProperty0, function () { return get_IS_NODE_JS(); }, null); } function CRYPTO$factory() { return getPropertyCallableRef('CRYPTO', 0, KProperty0, function () { return get_CRYPTO(); }, null); } var properties_initialized_JsPlatform_kt_vdfp0e; function _init_properties_JsPlatform_kt__dfptms() { if (!properties_initialized_JsPlatform_kt_vdfp0e) { properties_initialized_JsPlatform_kt_vdfp0e = true; IS_NODE_JS$delegate = lazy(IS_NODE_JS$delegate$lambda); CRYPTO$delegate = lazy(CRYPTO$delegate$lambda); } } //region block: exports _.$_$ = _.$_$ || {}; _.$_$.a = Default_getInstance; //endregion return _; })); //# sourceMappingURL=random-library-crypto-rand.js.map