UNPKG

kyberkotlin

Version:

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

890 lines (888 loc) 41.6 kB
(function (factory) { if (typeof define === 'function' && define.amd) define(['exports', './kotlin-kotlin-stdlib.js'], factory); else if (typeof exports === 'object') factory(module.exports, require('./kotlin-kotlin-stdlib.js')); else { if (typeof globalThis['kotlin-kotlin-stdlib'] === 'undefined') { throw new Error("Error loading module 'KeccakKotlin'. Its dependency 'kotlin-kotlin-stdlib' was not found. Please, check whether 'kotlin-kotlin-stdlib' is loaded prior to 'KeccakKotlin'."); } globalThis.KeccakKotlin = factory(typeof KeccakKotlin === 'undefined' ? {} : KeccakKotlin, globalThis['kotlin-kotlin-stdlib']); } }(function (_, kotlin_kotlin) { 'use strict'; //region block: imports var imul = Math.imul; var THROW_CCE = kotlin_kotlin.$_$.c2; var isCharSequence = kotlin_kotlin.$_$.k1; var trim = kotlin_kotlin.$_$.x1; var toString = kotlin_kotlin.$_$.t1; var IllegalArgumentException_init_$Create$ = kotlin_kotlin.$_$.g; var charSequenceGet = kotlin_kotlin.$_$.c1; var _Char___init__impl__6a9atx = kotlin_kotlin.$_$.j; var toByte = kotlin_kotlin.$_$.r1; var protoOf = kotlin_kotlin.$_$.q1; var initMetadataForCompanion = kotlin_kotlin.$_$.i1; var Number_0 = kotlin_kotlin.$_$.b2; var compareTo = kotlin_kotlin.$_$.d1; var toLong = kotlin_kotlin.$_$.s1; var initMetadataForClass = kotlin_kotlin.$_$.h1; var VOID = kotlin_kotlin.$_$.b; var defineProp = kotlin_kotlin.$_$.e1; var objectCreate = kotlin_kotlin.$_$.p1; var get_indices = kotlin_kotlin.$_$.x; var get_lastIndex = kotlin_kotlin.$_$.y; var byteArrayIterator = kotlin_kotlin.$_$.a1; var arrayCopy = kotlin_kotlin.$_$.p; var Unit_instance = kotlin_kotlin.$_$.o; var copyOf = kotlin_kotlin.$_$.u; var fill = kotlin_kotlin.$_$.w; var _UByte___init__impl__g9hnc4 = kotlin_kotlin.$_$.k; var _UByte___get_data__impl__jof9qr = kotlin_kotlin.$_$.l; var _UInt___init__impl__l7qpdl = kotlin_kotlin.$_$.m; var _UInt___get_data__impl__f0vqqw = kotlin_kotlin.$_$.n; var fillArrayVal = kotlin_kotlin.$_$.f1; var longArray = kotlin_kotlin.$_$.n1; var IllegalStateException_init_$Create$ = kotlin_kotlin.$_$.h; var IndexOutOfBoundsException_init_$Create$ = kotlin_kotlin.$_$.i; var Long = kotlin_kotlin.$_$.a2; var longArrayOf = kotlin_kotlin.$_$.m1; var initMetadataForObject = kotlin_kotlin.$_$.j1; var copyOfRange = kotlin_kotlin.$_$.t; var THROW_IAE = kotlin_kotlin.$_$.d2; var Enum = kotlin_kotlin.$_$.y1; var rotateLeft = kotlin_kotlin.$_$.f2; //endregion //region block: pre-declaration initMetadataForCompanion(Companion); initMetadataForClass(FlexiByte, 'FlexiByte', VOID, Number_0); initMetadataForClass(FlexiByteArray, 'FlexiByteArray'); initMetadataForClass(KeccakByteStream, 'KeccakByteStream'); initMetadataForObject(KeccakConstants, 'KeccakConstants'); initMetadataForObject(KeccakHash, 'KeccakHash'); initMetadataForClass(KeccakParameter, 'KeccakParameter', VOID, Enum); initMetadataForObject(KeccakMath, 'KeccakMath'); //endregion function Companion() { } protoOf(Companion).fromString = function (string) { // Inline function 'kotlin.text.trim' call var cleanedInput = toString(trim(isCharSequence(string) ? string : THROW_CCE())); if (cleanedInput.length > 8) throw IllegalArgumentException_init_$Create$('A Byte can only have 8 binary values. Trimmed Length: ' + cleanedInput.length); var outputByte = 0; // Inline function 'kotlin.math.min' call var a = string.length; var bitIndex = Math.min(a, 8) - 1 | 0; var inductionVariable = 0; if (inductionVariable <= bitIndex) do { var i = inductionVariable; inductionVariable = inductionVariable + 1 | 0; var tmp3 = outputByte; // Inline function 'kotlin.experimental.or' call var other = toByte((charSequenceGet(cleanedInput, bitIndex - i | 0) === _Char___init__impl__6a9atx(49) ? 1 : 0) << i); outputByte = toByte(tmp3 | other); } while (!(i === bitIndex)); return new FlexiByte(outputByte, bitIndex); }; var Companion_instance; function Companion_getInstance() { return Companion_instance; } function FlexiByte(byte, bitIndex) { Number_0.call(this); this.b3_1 = byte; this.bitIndex = bitIndex; } protoOf(FlexiByte).c3 = function () { return this.bitIndex; }; protoOf(FlexiByte).d3 = function (other) { return compareTo(this.b3_1, other); }; protoOf(FlexiByte).o = function (other) { return this.d3((!(other == null) ? typeof other === 'number' : false) ? other : THROW_CCE()); }; protoOf(FlexiByte).f1 = function () { return this.b3_1; }; protoOf(FlexiByte).h1 = function () { return this.b3_1; }; protoOf(FlexiByte).e3 = function () { return this.b3_1; }; protoOf(FlexiByte).g1 = function () { return this.b3_1; }; protoOf(FlexiByte).f3 = function () { return toLong(this.b3_1); }; protoOf(FlexiByte).g3 = function () { return this.b3_1; }; function _set_bitIndex__qeg3aq($this, value) { var tmp = $this; // Inline function 'kotlin.math.max' call // Inline function 'kotlin.math.min' call var a = Math.max(0, value); tmp.i3_1 = Math.min(a, 7); } function FlexiByteArray_init_$Init$(size, init, $this) { FlexiByteArray.call($this); var tmp = $this; var tmp_0 = 0; var tmp_1 = new Int8Array(size); while (tmp_0 < size) { var tmp_2 = tmp_0; tmp_1[tmp_2] = init(tmp_2); tmp_0 = tmp_0 + 1 | 0; } tmp.h3_1 = tmp_1; return $this; } function init(size, init) { return FlexiByteArray_init_$Init$(size, init, objectCreate(protoOf(FlexiByteArray))); } function FlexiByteArray_init_$Init$_0(byteArray, bitIndex, $this) { bitIndex = bitIndex === VOID ? 7 : bitIndex; FlexiByteArray.call($this); var tmp = $this; // Inline function 'kotlin.collections.copyOf' call // Inline function 'kotlin.js.asDynamic' call tmp.h3_1 = byteArray.slice(); _set_bitIndex__qeg3aq($this, bitIndex); return $this; } function wrap(byteArray, bitIndex) { return FlexiByteArray_init_$Init$_0(byteArray, bitIndex, objectCreate(protoOf(FlexiByteArray))); } protoOf(FlexiByteArray).c3 = function () { return this.i3_1; }; protoOf(FlexiByteArray).j3 = function () { return get_indices(this.h3_1); }; protoOf(FlexiByteArray).k3 = function () { return get_lastIndex(this.h3_1); }; protoOf(FlexiByteArray).l3 = function () { return this.h3_1.length; }; protoOf(FlexiByteArray).get = function (index) { return this.h3_1[index]; }; protoOf(FlexiByteArray).iterator = function () { return byteArrayIterator(this.h3_1); }; protoOf(FlexiByteArray).set = function (index, value) { return this.h3_1[index] = value; }; protoOf(FlexiByteArray).copyOf = function () { // Inline function 'kotlin.collections.copyOf' call // Inline function 'kotlin.js.asDynamic' call var tmp$ret$1 = this.h3_1.slice(); return wrap(tmp$ret$1, this.i3_1); }; protoOf(FlexiByteArray).m3 = function (flexiByteArray, destinationOffset) { var tmp0 = this.h3_1; // Inline function 'kotlin.collections.copyInto' call var destination = flexiByteArray.h3_1; var endIndex = tmp0.length; // Inline function 'kotlin.js.unsafeCast' call // Inline function 'kotlin.js.asDynamic' call var tmp = tmp0; // Inline function 'kotlin.js.unsafeCast' call // Inline function 'kotlin.js.asDynamic' call arrayCopy(tmp, destination, destinationOffset, 0, endIndex); _set_bitIndex__qeg3aq(flexiByteArray, this.i3_1); }; protoOf(FlexiByteArray).copyInto = function (flexiByteArray, destinationOffset, $super) { destinationOffset = destinationOffset === VOID ? 0 : destinationOffset; return this.m3(flexiByteArray, destinationOffset); }; protoOf(FlexiByteArray).extend = function (nBytes) { this.h3_1 = copyOf(this.h3_1, this.h3_1.length + nBytes | 0); }; protoOf(FlexiByteArray).fill = function (byte) { fill(this.h3_1, byte); _set_bitIndex__qeg3aq(this, 7); }; protoOf(FlexiByteArray).moveBitIndex = function (index) { _set_bitIndex__qeg3aq(this, index); }; protoOf(FlexiByteArray).reset = function () { _set_bitIndex__qeg3aq(this, 7); }; protoOf(FlexiByteArray).toByteArray = function () { // Inline function 'kotlin.collections.copyOf' call // Inline function 'kotlin.js.asDynamic' call return this.h3_1.slice(); }; protoOf(FlexiByteArray).plus = function (flexiByte) { var totalIndex = (flexiByte.bitIndex + this.i3_1 | 0) + 1 | 0; var newArrayLength = this.h3_1.length; var newIndex = totalIndex % 8 | 0; if (totalIndex > 7) { newArrayLength = newArrayLength + 1 | 0; } var newByteArray = copyOf(this.h3_1, newArrayLength); if (totalIndex > 7) { var tmp = get_lastIndex(newByteArray); // Inline function 'kotlin.toUInt' call var this_0 = flexiByte.f1(); var tmp1 = _UInt___init__impl__l7qpdl(this_0); // Inline function 'kotlin.UInt.shl' call var bitCount = 7 - this.i3_1 | 0; // Inline function 'kotlin.UInt.toByte' call var this_1 = _UInt___init__impl__l7qpdl(_UInt___get_data__impl__f0vqqw(tmp1) << bitCount); newByteArray[tmp] = toByte(_UInt___get_data__impl__f0vqqw(this_1)); } else { var tmp_0 = get_lastIndex(this.h3_1); var tmp9 = newByteArray[get_lastIndex(this.h3_1)]; // Inline function 'kotlin.toUByte' call var this_2 = flexiByte.f1(); // Inline function 'kotlin.UByte.toUInt' call var this_3 = _UByte___init__impl__g9hnc4(this_2); var tmp6 = _UInt___init__impl__l7qpdl(_UByte___get_data__impl__jof9qr(this_3) & 255); // Inline function 'kotlin.UInt.shl' call var bitCount_0 = this.i3_1 + 1 | 0; // Inline function 'kotlin.UInt.toByte' call var this_4 = _UInt___init__impl__l7qpdl(_UInt___get_data__impl__f0vqqw(tmp6) << bitCount_0); // Inline function 'kotlin.experimental.or' call var other = toByte(_UInt___get_data__impl__f0vqqw(this_4)); newByteArray[tmp_0] = toByte(tmp9 | other); } return wrap(newByteArray, newIndex); }; protoOf(FlexiByteArray).completeFill = function (bit) { if (bit) { var tmp = this.h3_1; var tmp_0 = get_lastIndex(this.h3_1); // Inline function 'kotlin.toUInt' call var this_0 = this.h3_1[get_lastIndex(this.h3_1)]; var tmp3 = _UInt___init__impl__l7qpdl(this_0); var tmp1 = _UInt___init__impl__l7qpdl(255); // Inline function 'kotlin.UInt.shr' call var bitCount = this.i3_1 + 1 | 0; // Inline function 'kotlin.UInt.or' call var other = _UInt___init__impl__l7qpdl(_UInt___get_data__impl__f0vqqw(tmp1) >>> bitCount | 0); // Inline function 'kotlin.UInt.toByte' call var this_1 = _UInt___init__impl__l7qpdl(_UInt___get_data__impl__f0vqqw(tmp3) | _UInt___get_data__impl__f0vqqw(other)); tmp[tmp_0] = toByte(_UInt___get_data__impl__f0vqqw(this_1)); } else { var tmp_1 = this.h3_1; var tmp_2 = get_lastIndex(this.h3_1); // Inline function 'kotlin.toUInt' call var this_2 = this.h3_1[get_lastIndex(this.h3_1)]; var tmp9 = _UInt___init__impl__l7qpdl(this_2); var tmp7 = _UInt___init__impl__l7qpdl(255); // Inline function 'kotlin.UInt.shl' call var bitCount_0 = 7 - this.i3_1 | 0; // Inline function 'kotlin.UInt.and' call var other_0 = _UInt___init__impl__l7qpdl(_UInt___get_data__impl__f0vqqw(tmp7) << bitCount_0); // Inline function 'kotlin.UInt.toByte' call var this_3 = _UInt___init__impl__l7qpdl(_UInt___get_data__impl__f0vqqw(tmp9) & _UInt___get_data__impl__f0vqqw(other_0)); tmp_1[tmp_2] = toByte(_UInt___get_data__impl__f0vqqw(this_3)); } _set_bitIndex__qeg3aq(this, 7); }; function FlexiByteArray() { this.i3_1 = 0; } function squeeze($this) { if ($this.r3_1 < 0) { $this.absorb(KeccakMath_instance.supplyPadding($this.q3_1, $this.parameters.BITRATE, $this.parameters.SUFFIX)); } else $this.n3_1 = KeccakMath_instance.permute($this.n3_1); var tmp0 = KeccakMath_instance.matrixToBytes($this.n3_1); var tmp1 = $this.o3_1; // Inline function 'kotlin.collections.copyInto' call var endIndex = $this.parameters.BYTERATE; // Inline function 'kotlin.js.unsafeCast' call // Inline function 'kotlin.js.asDynamic' call var tmp = tmp0; // Inline function 'kotlin.js.unsafeCast' call // Inline function 'kotlin.js.asDynamic' call arrayCopy(tmp, tmp1, 0, 0, endIndex); $this.r3_1 = 0; } function KeccakByteStream(parameters) { this.parameters = parameters; var tmp = this; var tmp_0 = 0; // Inline function 'kotlin.arrayOfNulls' call var tmp_1 = fillArrayVal(Array(5), null); while (tmp_0 < 5) { tmp_1[tmp_0] = longArray(5); tmp_0 = tmp_0 + 1 | 0; } tmp.n3_1 = tmp_1; this.o3_1 = new Int8Array(this.parameters.BYTERATE); this.p3_1 = new Int8Array(this.parameters.BYTERATE); this.q3_1 = 0; this.r3_1 = -1; this.s3_1 = 0; } protoOf(KeccakByteStream).v3 = function () { return this.parameters; }; protoOf(KeccakByteStream).w3 = function () { return this.r3_1 < this.parameters.BYTERATE || (this.parameters.maxLength === 0 || this.s3_1 < (this.parameters.maxLength / 8 | 0)); }; protoOf(KeccakByteStream).reset = function () { var tmp = this; var tmp_0 = 0; // Inline function 'kotlin.arrayOfNulls' call var tmp_1 = fillArrayVal(Array(5), null); while (tmp_0 < 5) { tmp_1[tmp_0] = longArray(5); tmp_0 = tmp_0 + 1 | 0; } tmp.n3_1 = tmp_1; this.o3_1 = new Int8Array(this.parameters.BYTERATE); this.p3_1 = new Int8Array(this.parameters.BYTERATE); this.q3_1 = 0; this.r3_1 = -1; this.s3_1 = 0; }; protoOf(KeccakByteStream).absorb = function (byteArray) { if (this.r3_1 >= 0) throw IllegalStateException_init_$Create$('This KeccakByteStream has already been squeezed.'); var inputOffset = 0; while (inputOffset < byteArray.length) { var remainingBytes = byteArray.length - inputOffset | 0; var absorbCapacityLeft = this.p3_1.length - this.q3_1 | 0; // Inline function 'kotlin.math.min' call var bytesToCopy = Math.min(absorbCapacityLeft, remainingBytes); var tmp3 = this.p3_1; var tmp4 = this.q3_1; var tmp5 = inputOffset; // Inline function 'kotlin.collections.copyInto' call var endIndex = inputOffset + bytesToCopy | 0; // Inline function 'kotlin.js.unsafeCast' call // Inline function 'kotlin.js.asDynamic' call var tmp = byteArray; // Inline function 'kotlin.js.unsafeCast' call // Inline function 'kotlin.js.asDynamic' call arrayCopy(tmp, tmp3, tmp4, tmp5, endIndex); this.q3_1 = this.q3_1 + bytesToCopy | 0; inputOffset = inputOffset + bytesToCopy | 0; if (this.q3_1 === this.p3_1.length) { var permutationState = KeccakMath_instance.bytesToMatrix(this.p3_1); var inductionVariable = 0; if (inductionVariable < 5) do { var x = inductionVariable; inductionVariable = inductionVariable + 1 | 0; var inductionVariable_0 = 0; if (inductionVariable_0 < 5) do { var y = inductionVariable_0; inductionVariable_0 = inductionVariable_0 + 1 | 0; this.n3_1[x][y] = this.n3_1[x][y].e1(permutationState[x][y]); } while (inductionVariable_0 < 5); } while (inductionVariable < 5); this.n3_1 = KeccakMath_instance.permute(this.n3_1); this.q3_1 = 0; } } }; protoOf(KeccakByteStream).absorbByte = function (byte) { // Inline function 'kotlin.byteArrayOf' call var tmp$ret$0 = new Int8Array([byte]); this.absorb(tmp$ret$0); }; protoOf(KeccakByteStream).next = function () { if (this.r3_1 >= this.parameters.BYTERATE || this.r3_1 < 0) { if (!(this.parameters.maxLength === 0) && this.s3_1 >= (this.parameters.minLength / 8 | 0)) throw IndexOutOfBoundsException_init_$Create$('There are no further bytes to read. This is the limit of this Keccak parameter.'); squeeze(this); } var tmp = this.o3_1; var _unary__edvuaz = this.r3_1; this.r3_1 = _unary__edvuaz + 1 | 0; // Inline function 'kotlin.also' call var this_0 = tmp[_unary__edvuaz]; // Inline function 'asia.hombre.keccak.KeccakByteStream.next.<anonymous>' call this.s3_1 = this.s3_1 + 1 | 0; return this_0; }; function KeccakConstants() { KeccakConstants_instance = this; var tmp = this; // Inline function 'kotlin.longArrayOf' call tmp.ROUND = longArrayOf([new Long(1, 0), new Long(32898, 0), new Long(32906, -2147483648), new Long(-2147450880, -2147483648), new Long(32907, 0), new Long(-2147483647, 0), new Long(-2147450751, -2147483648), new Long(32777, -2147483648), new Long(138, 0), new Long(136, 0), new Long(-2147450871, 0), new Long(-2147483638, 0), new Long(-2147450741, 0), new Long(139, -2147483648), new Long(32905, -2147483648), new Long(32771, -2147483648), new Long(32770, -2147483648), new Long(128, -2147483648), new Long(32778, 0), new Long(-2147483638, -2147483648), new Long(-2147450751, -2147483648), new Long(32896, -2147483648), new Long(-2147483647, 0), new Long(-2147450872, -2147483648)]); } protoOf(KeccakConstants).x3 = function () { return this.ROUND; }; var KeccakConstants_instance; function KeccakConstants_getInstance() { if (KeccakConstants_instance == null) new KeccakConstants(); return KeccakConstants_instance; } function generatePadded($this, parameters, paddedBytes, lengthInBytes) { var tmp; if (parameters.maxLength === 0) { // Inline function 'kotlin.math.max' call var b = parameters.minLength / 8 | 0; tmp = Math.max(lengthInBytes, b); } else { // Inline function 'kotlin.math.min' call var b_0 = parameters.minLength / 8 | 0; tmp = Math.min(lengthInBytes, b_0); } var outputLength = tmp; var inputOffset = 0; var tmp_0 = 0; // Inline function 'kotlin.arrayOfNulls' call var tmp_1 = fillArrayVal(Array(5), null); while (tmp_0 < 5) { tmp_1[tmp_0] = longArray(5); tmp_0 = tmp_0 + 1 | 0; } var state = tmp_1; while (!(inputOffset === paddedBytes.length)) { var tmp_2 = KeccakMath_instance; var tmp_3 = inputOffset; var tmp5 = paddedBytes.length; // Inline function 'kotlin.math.min' call var b_1 = inputOffset + parameters.BYTERATE | 0; var tmp$ret$4 = Math.min(tmp5, b_1); var permutationState = tmp_2.bytesToMatrix(copyOfRange(paddedBytes, tmp_3, tmp$ret$4)); var inductionVariable = 0; if (inductionVariable < 5) do { var x = inductionVariable; inductionVariable = inductionVariable + 1 | 0; var inductionVariable_0 = 0; if (inductionVariable_0 < 5) do { var y = inductionVariable_0; inductionVariable_0 = inductionVariable_0 + 1 | 0; state[x][y] = state[x][y].e1(permutationState[x][y]); } while (inductionVariable_0 < 5); } while (inductionVariable < 5); state = KeccakMath_instance.permute(state); inputOffset = inputOffset + parameters.BYTERATE | 0; } var outputOffset = 0; var outputBytes = new Int8Array(outputLength); $l$loop: while (true) { var tmp9 = KeccakMath_instance.matrixToBytes(state); var tmp11 = outputOffset; var tmp7 = parameters.BYTERATE; // Inline function 'kotlin.math.min' call var b_2 = outputLength - outputOffset | 0; // Inline function 'kotlin.collections.copyInto' call var endIndex = Math.min(tmp7, b_2); // Inline function 'kotlin.js.unsafeCast' call // Inline function 'kotlin.js.asDynamic' call var tmp_4 = tmp9; // Inline function 'kotlin.js.unsafeCast' call // Inline function 'kotlin.js.asDynamic' call arrayCopy(tmp_4, outputBytes, tmp11, 0, endIndex); outputOffset = outputOffset + parameters.BYTERATE | 0; if ((outputOffset + 1 | 0) >= outputLength) break $l$loop; state = KeccakMath_instance.permute(state); } return outputBytes; } function generatePadded$default($this, parameters, paddedBytes, lengthInBytes, $super) { lengthInBytes = lengthInBytes === VOID ? parameters.minLength / 8 | 0 : lengthInBytes; return generatePadded($this, parameters, paddedBytes, lengthInBytes); } function KeccakHash() { } protoOf(KeccakHash).y3 = function (parameters, byteArray, lengthInBytes) { var paddedBytes = KeccakMath_instance.pad10n1(byteArray, parameters.BITRATE, parameters.SUFFIX); return generatePadded(this, parameters, paddedBytes, lengthInBytes); }; protoOf(KeccakHash).generate = function (parameters, byteArray, lengthInBytes, $super) { lengthInBytes = lengthInBytes === VOID ? parameters.minLength / 8 | 0 : lengthInBytes; return this.y3(parameters, byteArray, lengthInBytes); }; protoOf(KeccakHash).z3 = function (parameters, flexiByteArray, lengthInBytes) { var paddedBytes = KeccakMath_instance.pad10n1Flex(flexiByteArray.plus(parameters.SUFFIX), parameters.BITRATE).toByteArray(); return generatePadded(this, parameters, paddedBytes, lengthInBytes); }; protoOf(KeccakHash).generateFlex = function (parameters, flexiByteArray, lengthInBytes, $super) { lengthInBytes = lengthInBytes === VOID ? parameters.minLength / 8 | 0 : lengthInBytes; return this.z3(parameters, flexiByteArray, lengthInBytes); }; var KeccakHash_instance; function KeccakHash_getInstance() { return KeccakHash_instance; } var KeccakParameter_SHA3_224_instance; var KeccakParameter_SHA3_256_instance; var KeccakParameter_SHA3_384_instance; var KeccakParameter_SHA3_512_instance; var KeccakParameter_RAWSHAKE_128_instance; var KeccakParameter_RAWSHAKE_256_instance; var KeccakParameter_SHAKE_128_instance; var KeccakParameter_SHAKE_256_instance; function values() { return [KeccakParameter_SHA3_224_getInstance(), KeccakParameter_SHA3_256_getInstance(), KeccakParameter_SHA3_384_getInstance(), KeccakParameter_SHA3_512_getInstance(), KeccakParameter_RAWSHAKE_128_getInstance(), KeccakParameter_RAWSHAKE_256_getInstance(), KeccakParameter_SHAKE_128_getInstance(), KeccakParameter_SHAKE_256_getInstance()]; } function valueOf(value) { switch (value) { case 'SHA3_224': return KeccakParameter_SHA3_224_getInstance(); case 'SHA3_256': return KeccakParameter_SHA3_256_getInstance(); case 'SHA3_384': return KeccakParameter_SHA3_384_getInstance(); case 'SHA3_512': return KeccakParameter_SHA3_512_getInstance(); case 'RAWSHAKE_128': return KeccakParameter_RAWSHAKE_128_getInstance(); case 'RAWSHAKE_256': return KeccakParameter_RAWSHAKE_256_getInstance(); case 'SHAKE_128': return KeccakParameter_SHAKE_128_getInstance(); case 'SHAKE_256': return KeccakParameter_SHAKE_256_getInstance(); default: KeccakParameter_initEntries(); THROW_IAE('No enum constant value.'); break; } } var KeccakParameter_entriesInitialized; function KeccakParameter_initEntries() { if (KeccakParameter_entriesInitialized) return Unit_instance; KeccakParameter_entriesInitialized = true; KeccakParameter_SHA3_224_instance = new KeccakParameter('SHA3_224', 0, 224, 224, 1152, 448, new FlexiByte(2, 1)); KeccakParameter_SHA3_256_instance = new KeccakParameter('SHA3_256', 1, 256, 256, 1088, 512, new FlexiByte(2, 1)); KeccakParameter_SHA3_384_instance = new KeccakParameter('SHA3_384', 2, 384, 384, 832, 768, new FlexiByte(2, 1)); KeccakParameter_SHA3_512_instance = new KeccakParameter('SHA3_512', 3, 512, 512, 576, 1024, new FlexiByte(2, 1)); KeccakParameter_RAWSHAKE_128_instance = new KeccakParameter('RAWSHAKE_128', 4, 128, 0, 1344, 256, new FlexiByte(3, 1)); KeccakParameter_RAWSHAKE_256_instance = new KeccakParameter('RAWSHAKE_256', 5, 256, 0, 1088, 512, new FlexiByte(3, 1)); KeccakParameter_SHAKE_128_instance = new KeccakParameter('SHAKE_128', 6, 128, 0, 1344, 256, new FlexiByte(15, 3)); KeccakParameter_SHAKE_256_instance = new KeccakParameter('SHAKE_256', 7, 256, 0, 1088, 512, new FlexiByte(15, 3)); } function KeccakParameter(name, ordinal, minLength, maxLength, BITRATE, CAPACITY, SUFFIX) { Enum.call(this, name, ordinal); this.minLength = minLength; this.maxLength = maxLength; this.BITRATE = BITRATE; this.CAPACITY = CAPACITY; this.SUFFIX = SUFFIX; this.BYTERATE = this.BITRATE / 8 | 0; } protoOf(KeccakParameter).a4 = function () { return this.minLength; }; protoOf(KeccakParameter).b4 = function () { return this.maxLength; }; protoOf(KeccakParameter).c4 = function () { return this.BITRATE; }; protoOf(KeccakParameter).d4 = function () { return this.CAPACITY; }; protoOf(KeccakParameter).e4 = function () { return this.SUFFIX; }; protoOf(KeccakParameter).f4 = function () { return this.BYTERATE; }; function KeccakParameter_SHA3_224_getInstance() { KeccakParameter_initEntries(); return KeccakParameter_SHA3_224_instance; } function KeccakParameter_SHA3_256_getInstance() { KeccakParameter_initEntries(); return KeccakParameter_SHA3_256_instance; } function KeccakParameter_SHA3_384_getInstance() { KeccakParameter_initEntries(); return KeccakParameter_SHA3_384_instance; } function KeccakParameter_SHA3_512_getInstance() { KeccakParameter_initEntries(); return KeccakParameter_SHA3_512_instance; } function KeccakParameter_RAWSHAKE_128_getInstance() { KeccakParameter_initEntries(); return KeccakParameter_RAWSHAKE_128_instance; } function KeccakParameter_RAWSHAKE_256_getInstance() { KeccakParameter_initEntries(); return KeccakParameter_RAWSHAKE_256_instance; } function KeccakParameter_SHAKE_128_getInstance() { KeccakParameter_initEntries(); return KeccakParameter_SHAKE_128_instance; } function KeccakParameter_SHAKE_256_getInstance() { KeccakParameter_initEntries(); return KeccakParameter_SHAKE_256_instance; } function KeccakMath() { } protoOf(KeccakMath).pad10n1 = function (bytes, multiple, flexiByte) { var multipleInBytes = multiple >> 3; var paddedBytes = new Int8Array(bytes.length + (multipleInBytes - (bytes.length % multipleInBytes | 0) | 0) | 0); // Inline function 'kotlin.collections.copyInto' call var endIndex = bytes.length; // Inline function 'kotlin.js.unsafeCast' call // Inline function 'kotlin.js.asDynamic' call var tmp = bytes; // Inline function 'kotlin.js.unsafeCast' call // Inline function 'kotlin.js.asDynamic' call arrayCopy(tmp, paddedBytes, 0, 0, endIndex); var tmp_0 = bytes.length; var tmp5 = flexiByte.f1(); // Inline function 'kotlin.experimental.or' call var other = toByte(1 << (flexiByte.bitIndex + 1 | 0)); paddedBytes[tmp_0] = toByte(tmp5 | other); var tmp_1 = get_lastIndex(paddedBytes); // Inline function 'kotlin.experimental.or' call var this_0 = paddedBytes[get_lastIndex(paddedBytes)]; paddedBytes[tmp_1] = toByte(this_0 | -128); return paddedBytes; }; protoOf(KeccakMath).supplyPadding = function (size, multiple, flexiByte) { var multipleInBytes = multiple >> 3; var paddedBytes = new Int8Array(multipleInBytes - (size % multipleInBytes | 0) | 0); var tmp0 = flexiByte.f1(); // Inline function 'kotlin.experimental.or' call var other = toByte(1 << (flexiByte.bitIndex + 1 | 0)); paddedBytes[0] = toByte(tmp0 | other); var tmp = get_lastIndex(paddedBytes); // Inline function 'kotlin.experimental.or' call var this_0 = paddedBytes[get_lastIndex(paddedBytes)]; paddedBytes[tmp] = toByte(this_0 | -128); return paddedBytes; }; protoOf(KeccakMath).pad10n1Flex = function (bytes, multiple) { var totalBits = (imul(bytes.size - 1 | 0, 8) + bytes.i3_1 | 0) + 1 | 0; var zeroesN = multiple - ((totalBits + 2 | 0) % multiple | 0) | 0; if (zeroesN === multiple) zeroesN = 0; var paddedBytes = bytes.plus(Companion_instance.fromString('1')); var fullZeroBytes = zeroesN / 8 | 0; if (fullZeroBytes > 0) { paddedBytes.extend(fullZeroBytes); var inductionVariable = paddedBytes.size - fullZeroBytes | 0; var last = paddedBytes.size; if (inductionVariable < last) do { var i = inductionVariable; inductionVariable = inductionVariable + 1 | 0; paddedBytes.set(i, 0); } while (inductionVariable < last); } if (paddedBytes.i3_1 === 7) { paddedBytes.extend(1); } paddedBytes.moveBitIndex((paddedBytes.i3_1 + 1 | 0) % 8 | 0); paddedBytes.set(paddedBytes.size - 1 | 0, toByte(paddedBytes.get(paddedBytes.size - 1 | 0) | 128)); return paddedBytes; }; protoOf(KeccakMath).doRound = function (state, round) { // Inline function 'kotlin.longArrayOf' call var c = longArrayOf([state[0][0].e1(state[0][1]).e1(state[0][2]).e1(state[0][3]).e1(state[0][4]), state[1][0].e1(state[1][1]).e1(state[1][2]).e1(state[1][3]).e1(state[1][4]), state[2][0].e1(state[2][1]).e1(state[2][2]).e1(state[2][3]).e1(state[2][4]), state[3][0].e1(state[3][1]).e1(state[3][2]).e1(state[3][3]).e1(state[3][4]), state[4][0].e1(state[4][1]).e1(state[4][2]).e1(state[4][3]).e1(state[4][4])]); // Inline function 'kotlin.longArrayOf' call var d = longArrayOf([c[4].e1(rotateLeft(c[1], 1)), c[0].e1(rotateLeft(c[2], 1)), c[1].e1(rotateLeft(c[3], 1)), c[2].e1(rotateLeft(c[4], 1)), c[3].e1(rotateLeft(c[0], 1))]); // Inline function 'kotlin.longArrayOf' call var tmp = longArrayOf([rotateLeft(state[0][0].e1(d[0]), 0), rotateLeft(state[3][0].e1(d[3]), 28), rotateLeft(state[1][0].e1(d[1]), 1), rotateLeft(state[4][0].e1(d[4]), 27), rotateLeft(state[2][0].e1(d[2]), 62)]); // Inline function 'kotlin.longArrayOf' call var tmp_0 = longArrayOf([rotateLeft(state[1][1].e1(d[1]), 44), rotateLeft(state[4][1].e1(d[4]), 20), rotateLeft(state[2][1].e1(d[2]), 6), rotateLeft(state[0][1].e1(d[0]), 36), rotateLeft(state[3][1].e1(d[3]), 55)]); // Inline function 'kotlin.longArrayOf' call var tmp_1 = longArrayOf([rotateLeft(state[2][2].e1(d[2]), 43), rotateLeft(state[0][2].e1(d[0]), 3), rotateLeft(state[3][2].e1(d[3]), 25), rotateLeft(state[1][2].e1(d[1]), 10), rotateLeft(state[4][2].e1(d[4]), 39)]); // Inline function 'kotlin.longArrayOf' call var tmp_2 = longArrayOf([rotateLeft(state[3][3].e1(d[3]), 21), rotateLeft(state[1][3].e1(d[1]), 45), rotateLeft(state[4][3].e1(d[4]), 8), rotateLeft(state[2][3].e1(d[2]), 15), rotateLeft(state[0][3].e1(d[0]), 41)]); // Inline function 'kotlin.longArrayOf' call // Inline function 'kotlin.arrayOf' call // Inline function 'kotlin.js.unsafeCast' call // Inline function 'kotlin.js.asDynamic' call var newState = [tmp, tmp_0, tmp_1, tmp_2, longArrayOf([rotateLeft(state[4][4].e1(d[4]), 14), rotateLeft(state[2][4].e1(d[2]), 61), rotateLeft(state[0][4].e1(d[0]), 18), rotateLeft(state[3][4].e1(d[3]), 56), rotateLeft(state[1][4].e1(d[1]), 2)])]; // Inline function 'kotlin.longArrayOf' call var tmp_3 = longArrayOf([newState[0][0].e1(newState[1][0].z().c1(newState[2][0])).e1(KeccakConstants_getInstance().ROUND[round]), newState[0][1].e1(newState[1][1].z().c1(newState[2][1])), newState[0][2].e1(newState[1][2].z().c1(newState[2][2])), newState[0][3].e1(newState[1][3].z().c1(newState[2][3])), newState[0][4].e1(newState[1][4].z().c1(newState[2][4]))]); // Inline function 'kotlin.longArrayOf' call var tmp_4 = longArrayOf([newState[1][0].e1(newState[2][0].z().c1(newState[3][0])), newState[1][1].e1(newState[2][1].z().c1(newState[3][1])), newState[1][2].e1(newState[2][2].z().c1(newState[3][2])), newState[1][3].e1(newState[2][3].z().c1(newState[3][3])), newState[1][4].e1(newState[2][4].z().c1(newState[3][4]))]); // Inline function 'kotlin.longArrayOf' call var tmp_5 = longArrayOf([newState[2][0].e1(newState[3][0].z().c1(newState[4][0])), newState[2][1].e1(newState[3][1].z().c1(newState[4][1])), newState[2][2].e1(newState[3][2].z().c1(newState[4][2])), newState[2][3].e1(newState[3][3].z().c1(newState[4][3])), newState[2][4].e1(newState[3][4].z().c1(newState[4][4]))]); // Inline function 'kotlin.longArrayOf' call var tmp_6 = longArrayOf([newState[3][0].e1(newState[4][0].z().c1(newState[0][0])), newState[3][1].e1(newState[4][1].z().c1(newState[0][1])), newState[3][2].e1(newState[4][2].z().c1(newState[0][2])), newState[3][3].e1(newState[4][3].z().c1(newState[0][3])), newState[3][4].e1(newState[4][4].z().c1(newState[0][4]))]); // Inline function 'kotlin.longArrayOf' call // Inline function 'kotlin.arrayOf' call // Inline function 'kotlin.js.unsafeCast' call // Inline function 'kotlin.js.asDynamic' call var finalState = [tmp_3, tmp_4, tmp_5, tmp_6, longArrayOf([newState[4][0].e1(newState[0][0].z().c1(newState[1][0])), newState[4][1].e1(newState[0][1].z().c1(newState[1][1])), newState[4][2].e1(newState[0][2].z().c1(newState[1][2])), newState[4][3].e1(newState[0][3].z().c1(newState[1][3])), newState[4][4].e1(newState[0][4].z().c1(newState[1][4]))])]; return finalState; }; protoOf(KeccakMath).permute = function (state) { var newState = state; var inductionVariable = 0; if (inductionVariable < 24) do { var i = inductionVariable; inductionVariable = inductionVariable + 1 | 0; newState = this.doRound(newState, i); } while (inductionVariable < 24); return newState; }; protoOf(KeccakMath).bytesToMatrix = function (bytes) { var tmp = 0; // Inline function 'kotlin.arrayOfNulls' call var tmp_0 = fillArrayVal(Array(5), null); while (tmp < 5) { tmp_0[tmp] = longArray(5); tmp = tmp + 1 | 0; } var state = tmp_0; var emptyByteArray = new Int8Array(200); // Inline function 'kotlin.collections.copyInto' call var endIndex = bytes.length; // Inline function 'kotlin.js.unsafeCast' call // Inline function 'kotlin.js.asDynamic' call var tmp_1 = bytes; // Inline function 'kotlin.js.unsafeCast' call // Inline function 'kotlin.js.asDynamic' call arrayCopy(tmp_1, emptyByteArray, 0, 0, endIndex); var inductionVariable = 0; if (inductionVariable < 5) do { var x = inductionVariable; inductionVariable = inductionVariable + 1 | 0; var inductionVariable_0 = 0; if (inductionVariable_0 < 5) do { var y = inductionVariable_0; inductionVariable_0 = inductionVariable_0 + 1 | 0; state[x][y] = this.bytesToLong(copyOfRange(emptyByteArray, (x + imul(5, y) | 0) << 3, ((x + imul(5, y) | 0) << 3) + 8 | 0)); } while (inductionVariable_0 < 5); } while (inductionVariable < 5); return state; }; protoOf(KeccakMath).matrixToBytes = function (state) { var emptyByteArray = new Int8Array(200); var inductionVariable = 0; if (inductionVariable < 5) do { var x = inductionVariable; inductionVariable = inductionVariable + 1 | 0; var inductionVariable_0 = 0; if (inductionVariable_0 < 5) do { var y = inductionVariable_0; inductionVariable_0 = inductionVariable_0 + 1 | 0; var longBytes = this.longToBytes(state[x][y]); var index = (x + imul(5, y) | 0) << 3; emptyByteArray[index] = longBytes[0]; emptyByteArray[index + 1 | 0] = longBytes[1]; emptyByteArray[index + 2 | 0] = longBytes[2]; emptyByteArray[index + 3 | 0] = longBytes[3]; emptyByteArray[index + 4 | 0] = longBytes[4]; emptyByteArray[index + 5 | 0] = longBytes[5]; emptyByteArray[index + 6 | 0] = longBytes[6]; emptyByteArray[index + 7 | 0] = longBytes[7]; } while (inductionVariable_0 < 5); } while (inductionVariable < 5); return emptyByteArray; }; protoOf(KeccakMath).longToBytes = function (long) { // Inline function 'kotlin.byteArrayOf' call return new Int8Array([long.c1(new Long(255, 0)).f1(), long.b1(8).c1(new Long(255, 0)).f1(), long.b1(16).c1(new Long(255, 0)).f1(), long.b1(24).c1(new Long(255, 0)).f1(), long.b1(32).c1(new Long(255, 0)).f1(), long.b1(40).c1(new Long(255, 0)).f1(), long.b1(48).c1(new Long(255, 0)).f1(), long.b1(56).c1(new Long(255, 0)).f1()]); }; protoOf(KeccakMath).bytesToLong = function (bytes) { // Inline function 'kotlin.require' call if (!(bytes.length === 8)) { // Inline function 'asia.hombre.keccak.internal.KeccakMath.bytesToLong.<anonymous>' call var message = 'Requires 8 bytes! Size: ' + bytes.length; throw IllegalArgumentException_init_$Create$(toString(message)); } return toLong(bytes[0]).c1(new Long(255, 0)).d1(toLong(bytes[1]).c1(new Long(255, 0)).a1(8)).d1(toLong(bytes[2]).c1(new Long(255, 0)).a1(16)).d1(toLong(bytes[3]).c1(new Long(255, 0)).a1(24)).d1(toLong(bytes[4]).c1(new Long(255, 0)).a1(32)).d1(toLong(bytes[5]).c1(new Long(255, 0)).a1(40)).d1(toLong(bytes[6]).c1(new Long(255, 0)).a1(48)).d1(toLong(bytes[7]).a1(56)); }; var KeccakMath_instance; function KeccakMath_getInstance() { return KeccakMath_instance; } //region block: post-declaration defineProp(protoOf(FlexiByteArray), 'bitIndex', protoOf(FlexiByteArray).c3); defineProp(protoOf(FlexiByteArray), 'indices', protoOf(FlexiByteArray).j3); defineProp(protoOf(FlexiByteArray), 'lastIndex', protoOf(FlexiByteArray).k3); defineProp(protoOf(FlexiByteArray), 'size', protoOf(FlexiByteArray).l3); defineProp(protoOf(KeccakByteStream), 'hasNext', protoOf(KeccakByteStream).w3); defineProp(protoOf(KeccakParameter), 'name', protoOf(KeccakParameter).l); defineProp(protoOf(KeccakParameter), 'ordinal', protoOf(KeccakParameter).m); //endregion //region block: init Companion_instance = new Companion(); KeccakHash_instance = new KeccakHash(); KeccakMath_instance = new KeccakMath(); //endregion //region block: exports function $jsExportAll$(_) { var $asia = _.asia || (_.asia = {}); var $asia$hombre = $asia.hombre || ($asia.hombre = {}); var $asia$hombre$keccak = $asia$hombre.keccak || ($asia$hombre.keccak = {}); $asia$hombre$keccak.FlexiByte = FlexiByte; defineProp($asia$hombre$keccak.FlexiByte, 'Companion', Companion_getInstance); var $asia = _.asia || (_.asia = {}); var $asia$hombre = $asia.hombre || ($asia.hombre = {}); var $asia$hombre$keccak = $asia$hombre.keccak || ($asia$hombre.keccak = {}); $asia$hombre$keccak.FlexiByteArray = FlexiByteArray; $asia$hombre$keccak.FlexiByteArray.init = init; $asia$hombre$keccak.FlexiByteArray.wrap = wrap; var $asia = _.asia || (_.asia = {}); var $asia$hombre = $asia.hombre || ($asia.hombre = {}); var $asia$hombre$keccak = $asia$hombre.keccak || ($asia$hombre.keccak = {}); $asia$hombre$keccak.KeccakByteStream = KeccakByteStream; var $asia = _.asia || (_.asia = {}); var $asia$hombre = $asia.hombre || ($asia.hombre = {}); var $asia$hombre$keccak = $asia$hombre.keccak || ($asia$hombre.keccak = {}); defineProp($asia$hombre$keccak, 'KeccakConstants', KeccakConstants_getInstance); var $asia = _.asia || (_.asia = {}); var $asia$hombre = $asia.hombre || ($asia.hombre = {}); var $asia$hombre$keccak = $asia$hombre.keccak || ($asia$hombre.keccak = {}); defineProp($asia$hombre$keccak, 'KeccakHash', KeccakHash_getInstance); var $asia = _.asia || (_.asia = {}); var $asia$hombre = $asia.hombre || ($asia.hombre = {}); var $asia$hombre$keccak = $asia$hombre.keccak || ($asia$hombre.keccak = {}); $asia$hombre$keccak.KeccakParameter = KeccakParameter; $asia$hombre$keccak.KeccakParameter.values = values; $asia$hombre$keccak.KeccakParameter.valueOf = valueOf; defineProp($asia$hombre$keccak.KeccakParameter, 'SHA3_224', KeccakParameter_SHA3_224_getInstance); defineProp($asia$hombre$keccak.KeccakParameter, 'SHA3_256', KeccakParameter_SHA3_256_getInstance); defineProp($asia$hombre$keccak.KeccakParameter, 'SHA3_384', KeccakParameter_SHA3_384_getInstance); defineProp($asia$hombre$keccak.KeccakParameter, 'SHA3_512', KeccakParameter_SHA3_512_getInstance); defineProp($asia$hombre$keccak.KeccakParameter, 'RAWSHAKE_128', KeccakParameter_RAWSHAKE_128_getInstance); defineProp($asia$hombre$keccak.KeccakParameter, 'RAWSHAKE_256', KeccakParameter_RAWSHAKE_256_getInstance); defineProp($asia$hombre$keccak.KeccakParameter, 'SHAKE_128', KeccakParameter_SHAKE_128_getInstance); defineProp($asia$hombre$keccak.KeccakParameter, 'SHAKE_256', KeccakParameter_SHAKE_256_getInstance); } $jsExportAll$(_); _.$jsExportAll$ = $jsExportAll$; _.$_$ = _.$_$ || {}; _.$_$.a = KeccakByteStream; _.$_$.b = KeccakParameter_SHA3_256_getInstance; _.$_$.c = KeccakParameter_SHA3_512_getInstance; _.$_$.d = KeccakParameter_SHAKE_128_getInstance; _.$_$.e = KeccakParameter_SHAKE_256_getInstance; _.$_$.f = KeccakHash_instance; //endregion return _; })); //# sourceMappingURL=KeccakKotlin.js.map