Added blocking test util

This commit is contained in:
Ugljesa Jovanovic 2019-07-20 18:18:07 +02:00
parent 1852db686c
commit bebe05757d
No known key found for this signature in database
GPG Key ID: 46D004C9820EBB98
13 changed files with 560 additions and 150 deletions

View File

@ -1,6 +1,7 @@
(function (_, Kotlin, $module$bignum) { (function (_, Kotlin, $module$bignum, $module$kotlinx_coroutines_core) {
'use strict'; 'use strict';
var $$importsForInline$$ = _.$$importsForInline$$ || (_.$$importsForInline$$ = {}); var $$importsForInline$$ = _.$$importsForInline$$ || (_.$$importsForInline$$ = {});
var Kind_INTERFACE = Kotlin.Kind.INTERFACE;
var chunked = Kotlin.kotlin.collections.chunked_ba2ldo$; var chunked = Kotlin.kotlin.collections.chunked_ba2ldo$;
var joinToString = Kotlin.kotlin.collections.joinToString_fmv235$; var joinToString = Kotlin.kotlin.collections.joinToString_fmv235$;
var println = Kotlin.kotlin.io.println_s8jyv4$; var println = Kotlin.kotlin.io.println_s8jyv4$;
@ -12,26 +13,51 @@
var ArrayList_init = Kotlin.kotlin.collections.ArrayList_init_ww73n8$; var ArrayList_init = Kotlin.kotlin.collections.ArrayList_init_ww73n8$;
var UInt_init = Kotlin.kotlin.UInt; var UInt_init = Kotlin.kotlin.UInt;
var ULong_init = Kotlin.kotlin.ULong; var ULong_init = Kotlin.kotlin.ULong;
var Unit = Kotlin.kotlin.Unit;
var encodeToByteArray = Kotlin.kotlin.text.encodeToByteArray_pdl1vz$; var encodeToByteArray = Kotlin.kotlin.text.encodeToByteArray_pdl1vz$;
var toList = Kotlin.kotlin.collections.toList_7wnvza$; var toList = Kotlin.kotlin.collections.toList_7wnvza$;
var UByte = Kotlin.kotlin.UByte; var UByte = Kotlin.kotlin.UByte;
var toBigInteger = $module$bignum.com.ionspin.kotlin.bignum.integer.toBigInteger_s8ev3n$; var toBigInteger = $module$bignum.com.ionspin.kotlin.bignum.integer.toBigInteger_s8ev3n$;
var toList_0 = Kotlin.kotlin.collections.toList_us0mfu$; var toList_0 = Kotlin.kotlin.collections.toList_us0mfu$;
var IllegalStateException_init = Kotlin.kotlin.IllegalStateException_init_pdl1vj$; var IllegalStateException_init = Kotlin.kotlin.IllegalStateException_init_pdl1vj$;
var until = Kotlin.kotlin.ranges.until_dqglrj$;
var Kind_OBJECT = Kotlin.Kind.OBJECT; var Kind_OBJECT = Kotlin.Kind.OBJECT;
var RuntimeException_init = Kotlin.kotlin.RuntimeException_init_pdl1vj$;
var COROUTINE_SUSPENDED = Kotlin.kotlin.coroutines.intrinsics.COROUTINE_SUSPENDED;
var CoroutineImpl = Kotlin.kotlin.coroutines.CoroutineImpl;
var launch = $module$kotlinx_coroutines_core.kotlinx.coroutines.launch_s496o7$;
var Job = $module$kotlinx_coroutines_core.kotlinx.coroutines.Job_5dx9e$;
var coroutines = $module$kotlinx_coroutines_core.kotlinx.coroutines;
var CoroutineScope = $module$kotlinx_coroutines_core.kotlinx.coroutines.CoroutineScope_1fupul$;
var BigInteger = $module$bignum.com.ionspin.kotlin.bignum.integer.BigInteger;
var Kind_CLASS = Kotlin.Kind.CLASS; var Kind_CLASS = Kotlin.Kind.CLASS;
var L255 = Kotlin.Long.fromInt(255);
var Array_0 = Array; var Array_0 = Array;
var L255 = Kotlin.Long.fromInt(255);
var copyToArray = Kotlin.kotlin.collections.copyToArray; var copyToArray = Kotlin.kotlin.collections.copyToArray;
var collectionSizeOrDefault = Kotlin.kotlin.collections.collectionSizeOrDefault_ba2ldo$; var collectionSizeOrDefault = Kotlin.kotlin.collections.collectionSizeOrDefault_ba2ldo$;
var toByte = Kotlin.toByte;
var arrayCopy = Kotlin.kotlin.collections.arrayCopy; var arrayCopy = Kotlin.kotlin.collections.arrayCopy;
var toByte = Kotlin.toByte;
var ArrayList_init_0 = Kotlin.kotlin.collections.ArrayList_init_287e2$; var ArrayList_init_0 = Kotlin.kotlin.collections.ArrayList_init_287e2$;
var addAll = Kotlin.kotlin.collections.addAll_ipc267$; var addAll = Kotlin.kotlin.collections.addAll_ipc267$;
var until = Kotlin.kotlin.ranges.until_dqglrj$;
var RuntimeException_init = Kotlin.kotlin.RuntimeException_init_pdl1vj$;
var emptyList = Kotlin.kotlin.collections.emptyList_287e2$; var emptyList = Kotlin.kotlin.collections.emptyList_287e2$;
var slice = Kotlin.kotlin.collections.slice_l0m14x$; var slice = Kotlin.kotlin.collections.slice_l0m14x$;
var Result = Kotlin.kotlin.Result;
var intercepted = Kotlin.kotlin.coroutines.intrinsics.intercepted_f9mg25$;
var SafeContinuation_init = Kotlin.kotlin.coroutines.SafeContinuation_init_wj8d80$;
function Hash() {
}
Hash.$metadata$ = {
kind: Kind_INTERFACE,
simpleName: 'Hash',
interfaces: []
};
function UpdateableHash() {
}
UpdateableHash.$metadata$ = {
kind: Kind_INTERFACE,
simpleName: 'UpdateableHash',
interfaces: [Hash]
};
function hexColumsPrint$lambda$lambda(it) { function hexColumsPrint$lambda$lambda(it) {
return it.toUpperCase(); return it.toUpperCase();
} }
@ -137,8 +163,57 @@
var other = new ULong_init($receiver.data.shiftLeft(bitCount)); var other = new ULong_init($receiver.data.shiftLeft(bitCount));
return new ULong_init(tmp$.data.xor(other.data)); return new ULong_init(tmp$.data.xor(other.data));
} }
function Blake2b() { var chunked$lambda = wrapFunction(function () {
var copyToArray = Kotlin.kotlin.collections.copyToArray;
return function (it) {
return copyToArray(it);
};
});
function suspendCoroutine$lambda(closure$block) {
return function (c) {
var safe = SafeContinuation_init(intercepted(c));
closure$block(safe);
return safe.getOrThrow();
};
}
function Blake2b(key, hashLength) {
Blake2b$Companion_getInstance(); Blake2b$Companion_getInstance();
if (key === void 0)
key = null;
if (hashLength === void 0)
hashLength = 64;
this.key = key;
this.hashLength = hashLength;
this.job = Job();
this.scope = CoroutineScope(coroutines.Dispatchers.Default.plus_1fupul$(this.job));
this.h = Blake2b$Companion_getInstance().iv_0.slice();
this.counter = BigInteger.Companion.ZERO;
this.bufferCounter = 0;
var array = Array_0(128);
var tmp$;
tmp$ = array.length - 1 | 0;
for (var i = 0; i <= tmp$; i++) {
array[i] = new UByte(0);
}
this.buffer = array;
var tmp$_0, tmp$_1, tmp$_2, tmp$_3;
var $this = this.h[0];
var other = new ULong_init(Kotlin.Long.fromInt(16842752));
tmp$_3 = new ULong_init($this.data.xor(other.data));
tmp$_2 = (tmp$_1 = (tmp$_0 = this.key) != null ? new ULong_init((new ULong_init(Kotlin.Long.fromInt(tmp$_0.length))).data.shiftLeft(8)) : null) != null ? tmp$_1 : new ULong_init(Kotlin.Long.ZERO);
var tmp$_4 = this.h;
var tmp$_5 = new ULong_init(tmp$_3.data.xor(tmp$_2.data));
var $receiver = this.hashLength;
var other_0 = new ULong_init(Kotlin.Long.fromInt($receiver));
tmp$_4[0] = new ULong_init(tmp$_5.data.xor(other_0.data));
var $receiver_0 = this.key;
var tmp$_6 = $receiver_0 == null;
if (!tmp$_6) {
tmp$_6 = $receiver_0.length === 0;
}
if (!tmp$_6) {
this.appendToBuffer_0(Blake2b$Companion_getInstance().padToBlock_0(this.key), this.bufferCounter);
}
} }
function Blake2b$Companion() { function Blake2b$Companion() {
Blake2b$Companion_instance = this; Blake2b$Companion_instance = this;
@ -366,40 +441,14 @@
} }
} }
else { else {
var padToBlock_0$result; tmp$ = [this.padToBlock_0(secretKey)].concat(inputMessage);
padToBlock_0$break: do {
if (secretKey.length === 128) {
padToBlock_0$result = secretKey;
break padToBlock_0$break;
}
if (secretKey.length > 128) {
throw IllegalStateException_init('Block larger than 128 bytes');
}
var array_1 = Array_0(128);
var tmp$_7;
tmp$_7 = array_1.length - 1 | 0;
for (var i_1 = 0; i_1 <= tmp$_7; i_1++) {
var init$result;
if (0 <= i_1 && i_1 < secretKey.length) {
init$result = secretKey[i_1];
}
else {
init$result = new UByte(0);
}
array_1[i_1] = init$result;
}
padToBlock_0$result = array_1;
}
while (false);
tmp$ = [padToBlock_0$result].concat(inputMessage);
} }
var message = tmp$; var message = tmp$;
if (message.length > 1) { if (message.length > 1) {
tmp$_0 = message.length - 1 | 0; tmp$_0 = message.length - 1 | 0;
for (var i_2 = 0; i_2 < tmp$_0; i_2++) { for (var i_1 = 0; i_1 < tmp$_0; i_1++) {
var $receiver = this.compress_c1cv33$(h, message[i_2], toBigInteger((i_2 + 1 | 0) * 128 | 0), false); var $receiver = this.compress_c1cv33$(h, message[i_1], toBigInteger((i_1 + 1 | 0) * 128 | 0), false);
arrayCopy($receiver, h, 0, 0, $receiver.length); arrayCopy($receiver, h, 0, 0, $receiver.length);
hexColumsPrint_1(h);
} }
} }
switch (message.length) { switch (message.length) {
@ -414,114 +463,88 @@
} }
var lastSize = tmp$_1; var lastSize = tmp$_1;
if (!(message.length === 0)) { if (!(message.length === 0)) {
var unpadded = message[message.length - 1 | 0]; tmp$_2 = this.padToBlock_0(message[message.length - 1 | 0]);
var padToBlock_0$result_0;
padToBlock_0$break: do {
if (unpadded.length === 128) {
padToBlock_0$result_0 = unpadded;
break padToBlock_0$break;
}
if (unpadded.length > 128) {
throw IllegalStateException_init('Block larger than 128 bytes');
}
var array_2 = Array_0(128);
var tmp$_8;
tmp$_8 = array_2.length - 1 | 0;
for (var i_3 = 0; i_3 <= tmp$_8; i_3++) {
var init$result_0;
if (0 <= i_3 && i_3 < unpadded.length) {
init$result_0 = unpadded[i_3];
}
else {
init$result_0 = new UByte(0);
}
array_2[i_3] = init$result_0;
}
padToBlock_0$result_0 = array_2;
}
while (false);
tmp$_2 = padToBlock_0$result_0;
} }
else { else {
var array_3 = Array_0(16); var array_1 = Array_0(16);
var tmp$_9; var tmp$_7;
tmp$_9 = array_3.length - 1 | 0; tmp$_7 = array_1.length - 1 | 0;
for (var i_4 = 0; i_4 <= tmp$_9; i_4++) { for (var i_2 = 0; i_2 <= tmp$_7; i_2++) {
array_3[i_4] = new UByte(0); array_1[i_2] = new UByte(0);
} }
tmp$_2 = array_3; tmp$_2 = array_1;
} }
var lastBlockPadded = tmp$_2; var lastBlockPadded = tmp$_2;
var $receiver_0 = this.compress_c1cv33$(h, lastBlockPadded, toBigInteger(lastSize), true); var $receiver_0 = this.compress_c1cv33$(h, lastBlockPadded, toBigInteger(lastSize), true);
arrayCopy($receiver_0, h, 0, 0, $receiver_0.length); arrayCopy($receiver_0, h, 0, 0, $receiver_0.length);
return this.formatResult_0(h);
};
Blake2b$Companion.prototype.formatResult_0 = function (h) {
var destination = ArrayList_init(h.length); var destination = ArrayList_init(h.length);
var tmp$_10; var tmp$;
for (tmp$_10 = 0; tmp$_10 !== h.length; ++tmp$_10) { for (tmp$ = 0; tmp$ !== h.length; ++tmp$) {
var item = h[tmp$_10]; var item = h[tmp$];
var tmp$_11 = destination.add_11rb$; var tmp$_0 = destination.add_11rb$;
var other = new ULong_init(Kotlin.Long.fromInt(255));
var tmp$_1 = new UByte(toByte((new ULong_init(item.data.and(other.data))).data.toInt()));
var $this = new ULong_init(item.data.shiftRightUnsigned(8));
var other_0 = new ULong_init(Kotlin.Long.fromInt(255));
var tmp$_2 = new UByte(toByte((new ULong_init($this.data.and(other_0.data))).data.toInt()));
var $this_0 = new ULong_init(item.data.shiftRightUnsigned(16));
var other_1 = new ULong_init(Kotlin.Long.fromInt(255));
var tmp$_3 = new UByte(toByte((new ULong_init($this_0.data.and(other_1.data))).data.toInt()));
var $this_1 = new ULong_init(item.data.shiftRightUnsigned(24));
var other_2 = new ULong_init(Kotlin.Long.fromInt(255)); var other_2 = new ULong_init(Kotlin.Long.fromInt(255));
var tmp$_12 = new UByte(toByte((new ULong_init(item.data.and(other_2.data))).data.toInt())); var tmp$_4 = new UByte(toByte((new ULong_init($this_1.data.and(other_2.data))).data.toInt()));
var $this_0 = new ULong_init(item.data.shiftRightUnsigned(8)); var $this_2 = new ULong_init(item.data.shiftRightUnsigned(32));
var other_3 = new ULong_init(Kotlin.Long.fromInt(255)); var other_3 = new ULong_init(Kotlin.Long.fromInt(255));
var tmp$_13 = new UByte(toByte((new ULong_init($this_0.data.and(other_3.data))).data.toInt())); var tmp$_5 = new UByte(toByte((new ULong_init($this_2.data.and(other_3.data))).data.toInt()));
var $this_1 = new ULong_init(item.data.shiftRightUnsigned(16)); var $this_3 = new ULong_init(item.data.shiftRightUnsigned(40));
var other_4 = new ULong_init(Kotlin.Long.fromInt(255)); var other_4 = new ULong_init(Kotlin.Long.fromInt(255));
var tmp$_14 = new UByte(toByte((new ULong_init($this_1.data.and(other_4.data))).data.toInt())); var tmp$_6 = new UByte(toByte((new ULong_init($this_3.data.and(other_4.data))).data.toInt()));
var $this_2 = new ULong_init(item.data.shiftRightUnsigned(24)); var $this_4 = new ULong_init(item.data.shiftRightUnsigned(48));
var other_5 = new ULong_init(Kotlin.Long.fromInt(255)); var other_5 = new ULong_init(Kotlin.Long.fromInt(255));
var tmp$_15 = new UByte(toByte((new ULong_init($this_2.data.and(other_5.data))).data.toInt())); var tmp$_7 = new UByte(toByte((new ULong_init($this_4.data.and(other_5.data))).data.toInt()));
var $this_3 = new ULong_init(item.data.shiftRightUnsigned(32)); var $this_5 = new ULong_init(item.data.shiftRightUnsigned(56));
var other_6 = new ULong_init(Kotlin.Long.fromInt(255)); var other_6 = new ULong_init(Kotlin.Long.fromInt(255));
var tmp$_16 = new UByte(toByte((new ULong_init($this_3.data.and(other_6.data))).data.toInt())); tmp$_0.call(destination, [tmp$_1, tmp$_2, tmp$_3, tmp$_4, tmp$_5, tmp$_6, tmp$_7, new UByte(toByte((new ULong_init($this_5.data.and(other_6.data))).data.toInt()))]);
var $this_4 = new ULong_init(item.data.shiftRightUnsigned(40));
var other_7 = new ULong_init(Kotlin.Long.fromInt(255));
var tmp$_17 = new UByte(toByte((new ULong_init($this_4.data.and(other_7.data))).data.toInt()));
var $this_5 = new ULong_init(item.data.shiftRightUnsigned(48));
var other_8 = new ULong_init(Kotlin.Long.fromInt(255));
var tmp$_18 = new UByte(toByte((new ULong_init($this_5.data.and(other_8.data))).data.toInt()));
var $this_6 = new ULong_init(item.data.shiftRightUnsigned(56));
var other_9 = new ULong_init(Kotlin.Long.fromInt(255));
tmp$_11.call(destination, [tmp$_12, tmp$_13, tmp$_14, tmp$_15, tmp$_16, tmp$_17, tmp$_18, new UByte(toByte((new ULong_init($this_6.data.and(other_9.data))).data.toInt()))]);
} }
var destination_0 = ArrayList_init_0(); var destination_0 = ArrayList_init_0();
var tmp$_19; var tmp$_8;
tmp$_19 = destination.iterator(); tmp$_8 = destination.iterator();
while (tmp$_19.hasNext()) { while (tmp$_8.hasNext()) {
var element = tmp$_19.next(); var element = tmp$_8.next();
var list = toList_0(element); var list = toList_0(element);
addAll(destination_0, list); addAll(destination_0, list);
} }
return copyToArray(destination_0); return copyToArray(destination_0);
}; };
Blake2b$Companion.prototype.padToBlock_0 = wrapFunction(function () { Blake2b$Companion.prototype.padToBlock_0 = function (unpadded) {
var Array_0 = Array; if (unpadded.length === 128) {
return function (unpadded) { return unpadded;
if (unpadded.length === 128) { }
return unpadded; if (unpadded.length > 128) {
throw IllegalStateException_init('Block larger than 128 bytes');
}
var array = Array_0(128);
var tmp$;
tmp$ = array.length - 1 | 0;
for (var i = 0; i <= tmp$; i++) {
var init$result;
if (0 <= i && i < unpadded.length) {
init$result = unpadded[i];
} }
if (unpadded.length > 128) { else {
throw IllegalStateException_init('Block larger than 128 bytes'); init$result = new UByte(0);
} }
var array = Array_0(128); array[i] = init$result;
var tmp$; }
tmp$ = array.length - 1 | 0; return array;
for (var i = 0; i <= tmp$; i++) { };
var init$result;
if (0 <= i && i < unpadded.length) {
init$result = unpadded[i];
}
else {
init$result = new UByte(0);
}
array[i] = init$result;
}
return array;
};
});
Blake2b$Companion.$metadata$ = { Blake2b$Companion.$metadata$ = {
kind: Kind_OBJECT, kind: Kind_OBJECT,
simpleName: 'Companion', simpleName: 'Companion',
interfaces: [] interfaces: [Hash]
}; };
var Blake2b$Companion_instance = null; var Blake2b$Companion_instance = null;
function Blake2b$Companion_getInstance() { function Blake2b$Companion_getInstance() {
@ -530,17 +553,298 @@
} }
return Blake2b$Companion_instance; return Blake2b$Companion_instance;
} }
Blake2b.prototype.digest_jyasbz$ = function (inputString, key) { Blake2b.prototype.updateBlocking_ummv9a$ = function (array) {
if (key === void 0) if (array.length === 0) {
key = null; throw RuntimeException_init('Updating with empty array is not allowed. If you need empty hash, just call digest without updating');
return Blake2b$Companion_getInstance().digest_jyasbz$(inputString, key); }
if ((this.bufferCounter + array.length | 0) < 128)
this.appendToBuffer_0(array, this.bufferCounter);
else if ((this.bufferCounter + array.length | 0) >= 128) {
var last = array.length % 128;
var hasLast = last !== 0;
var numberOfSlices = array.length / 128 | 0;
var list = ArrayList_init(0);
for (var index = 0; index < 0; index++) {
list.add_11rb$(emptyList());
}
var result = list;
for (var i = 0; i < numberOfSlices; i++) {
result.add_11rb$(slice(array, until(Kotlin.imul(i, 128), Kotlin.imul(i + 1 | 0, 128))));
}
if (hasLast) {
result.add_11rb$(slice(array, until(Kotlin.imul(numberOfSlices, 128), array.length)));
}
var destination = ArrayList_init(collectionSizeOrDefault(result, 10));
var tmp$;
tmp$ = result.iterator();
while (tmp$.hasNext()) {
var item = tmp$.next();
destination.add_11rb$(copyToArray(item));
}
var chunked = copyToArray(destination);
var tmp$_0;
for (tmp$_0 = 0; tmp$_0 !== chunked.length; ++tmp$_0) {
var element = chunked[tmp$_0];
if ((this.bufferCounter + element.length | 0) < 128) {
this.appendToBuffer_0(element, this.bufferCounter);
}
else {
arrayCopy(element, this.buffer, this.bufferCounter, 0, 128 - this.bufferCounter | 0);
this.counter = this.counter.plus_za3lpa$(128);
this.consumeBlock_0(this.buffer);
var array_0 = Array_0(128);
var tmp$_1;
tmp$_1 = array_0.length - 1 | 0;
for (var i_0 = 0; i_0 <= tmp$_1; i_0++) {
var init$result;
var tmp$_2;
tmp$_2 = element.length - (128 - this.bufferCounter) | 0;
if (0 <= i_0 && i_0 < tmp$_2) {
init$result = element[i_0 + (128 - this.bufferCounter) | 0];
}
else {
init$result = new UByte(0);
}
array_0[i_0] = init$result;
}
this.buffer = array_0;
this.bufferCounter = element.length - (128 - this.bufferCounter) | 0;
}
}
}
};
Blake2b.prototype.updateBlocking_61zpoe$ = function (input) {
var $receiver = encodeToByteArray(input);
var destination = ArrayList_init($receiver.length);
var tmp$;
for (tmp$ = 0; tmp$ !== $receiver.length; ++tmp$) {
var item = $receiver[tmp$];
destination.add_11rb$(new UByte(item));
}
this.updateBlocking_ummv9a$(copyToArray(destination));
};
Blake2b.prototype.appendToBuffer_0 = function (array, start) {
arrayCopy(array, this.buffer, start, 0, array.length);
this.bufferCounter = this.bufferCounter + array.length | 0;
};
Blake2b.prototype.consumeBlock_0 = function (block) {
this.h = Blake2b$Companion_getInstance().compress_c1cv33$(this.h, block, this.counter, false);
};
function Coroutine$Blake2b$update$lambda$lambda(closure$array_0, this$Blake2b_0, closure$it_0, $receiver_0, controller, continuation_0) {
CoroutineImpl.call(this, continuation_0);
this.$controller = controller;
this.exceptionState_0 = 1;
this.local$closure$array = closure$array_0;
this.local$this$Blake2b = this$Blake2b_0;
this.local$closure$it = closure$it_0;
}
Coroutine$Blake2b$update$lambda$lambda.$metadata$ = {
kind: Kotlin.Kind.CLASS,
simpleName: null,
interfaces: [CoroutineImpl]
};
Coroutine$Blake2b$update$lambda$lambda.prototype = Object.create(CoroutineImpl.prototype);
Coroutine$Blake2b$update$lambda$lambda.prototype.constructor = Coroutine$Blake2b$update$lambda$lambda;
Coroutine$Blake2b$update$lambda$lambda.prototype.doResume = function () {
do
try {
switch (this.state_0) {
case 0:
this.local$this$Blake2b.updateBlocking_ummv9a$(this.local$closure$array);
this.local$closure$it.resumeWith_tl1gpc$(new Result(Unit));
return Unit;
case 1:
throw this.exception_0;
default:this.state_0 = 1;
throw new Error('State Machine Unreachable execution');
}
}
catch (e) {
if (this.state_0 === 1) {
this.exceptionState_0 = this.state_0;
throw e;
}
else {
this.state_0 = this.exceptionState_0;
this.exception_0 = e;
}
}
while (true);
};
function Blake2b$update$lambda$lambda(closure$array_0, this$Blake2b_0, closure$it_0) {
return function ($receiver_0, continuation_0, suspended) {
var instance = new Coroutine$Blake2b$update$lambda$lambda(closure$array_0, this$Blake2b_0, closure$it_0, $receiver_0, this, continuation_0);
if (suspended)
return instance;
else
return instance.doResume(null);
};
}
function Blake2b$update$lambda(this$Blake2b, closure$array) {
return function (it) {
launch(this$Blake2b.scope, this$Blake2b.job, void 0, Blake2b$update$lambda$lambda(closure$array, this$Blake2b, it));
return Unit;
};
}
function Coroutine$update_ummv9a$($this, array_0, continuation_0) {
CoroutineImpl.call(this, continuation_0);
this.exceptionState_0 = 1;
this.$this = $this;
this.local$array = array_0;
}
Coroutine$update_ummv9a$.$metadata$ = {
kind: Kotlin.Kind.CLASS,
simpleName: null,
interfaces: [CoroutineImpl]
};
Coroutine$update_ummv9a$.prototype = Object.create(CoroutineImpl.prototype);
Coroutine$update_ummv9a$.prototype.constructor = Coroutine$update_ummv9a$;
Coroutine$update_ummv9a$.prototype.doResume = function () {
do
try {
switch (this.state_0) {
case 0:
this.state_0 = 2;
this.result_0 = suspendCoroutine$lambda(Blake2b$update$lambda(this.$this, this.local$array))(this);
if (this.result_0 === COROUTINE_SUSPENDED)
return COROUTINE_SUSPENDED;
continue;
case 1:
throw this.exception_0;
case 2:
this.result_0;
return this.result_0;
default:this.state_0 = 1;
throw new Error('State Machine Unreachable execution');
}
}
catch (e) {
if (this.state_0 === 1) {
this.exceptionState_0 = this.state_0;
throw e;
}
else {
this.state_0 = this.exceptionState_0;
this.exception_0 = e;
}
}
while (true);
};
Blake2b.prototype.update_ummv9a$ = function (array_0, continuation_0, suspended) {
var instance = new Coroutine$update_ummv9a$(this, array_0, continuation_0);
if (suspended)
return instance;
else
return instance.doResume(null);
};
function Coroutine$update_61zpoe$($this, input_0, continuation_0) {
CoroutineImpl.call(this, continuation_0);
this.exceptionState_0 = 1;
this.$this = $this;
this.local$input = input_0;
}
Coroutine$update_61zpoe$.$metadata$ = {
kind: Kotlin.Kind.CLASS,
simpleName: null,
interfaces: [CoroutineImpl]
};
Coroutine$update_61zpoe$.prototype = Object.create(CoroutineImpl.prototype);
Coroutine$update_61zpoe$.prototype.constructor = Coroutine$update_61zpoe$;
Coroutine$update_61zpoe$.prototype.doResume = function () {
do
try {
switch (this.state_0) {
case 0:
var $receiver = encodeToByteArray(this.local$input);
var destination = ArrayList_init($receiver.length);
var tmp$;
for (tmp$ = 0; tmp$ !== $receiver.length; ++tmp$) {
var item = $receiver[tmp$];
destination.add_11rb$(new UByte(item));
}
this.state_0 = 2;
this.result_0 = this.$this.update_ummv9a$(copyToArray(destination), this);
if (this.result_0 === COROUTINE_SUSPENDED)
return COROUTINE_SUSPENDED;
continue;
case 1:
throw this.exception_0;
case 2:
return;
default:this.state_0 = 1;
throw new Error('State Machine Unreachable execution');
}
}
catch (e) {
if (this.state_0 === 1) {
this.exceptionState_0 = this.state_0;
throw e;
}
else {
this.state_0 = this.exceptionState_0;
this.exception_0 = e;
}
}
while (true);
};
Blake2b.prototype.update_61zpoe$ = function (input_0, continuation_0, suspended) {
var instance = new Coroutine$update_61zpoe$(this, input_0, continuation_0);
if (suspended)
return instance;
else
return instance.doResume(null);
};
Blake2b.prototype.digest = function () {
var lastBlockPadded = Blake2b$Companion_getInstance().padToBlock_0(this.buffer);
this.counter = this.counter.plus_za3lpa$(this.bufferCounter);
Blake2b$Companion_getInstance().compress_c1cv33$(this.h, lastBlockPadded, this.counter, true);
var result = Blake2b$Companion_getInstance().formatResult_0(this.h);
var destination = ArrayList_init(result.length);
var tmp$;
for (tmp$ = 0; tmp$ !== result.length; ++tmp$) {
var item = result[tmp$];
destination.add_11rb$(toString(item, 16));
}
println(joinToString(destination, ''));
return result;
};
Blake2b.prototype.digestString = function () {
var $receiver = this.digest();
var destination = ArrayList_init($receiver.length);
var tmp$;
for (tmp$ = 0; tmp$ !== $receiver.length; ++tmp$) {
var item = $receiver[tmp$];
destination.add_11rb$(toString(item, 16));
}
return joinToString(destination, '');
}; };
Blake2b.$metadata$ = { Blake2b.$metadata$ = {
kind: Kind_CLASS, kind: Kind_CLASS,
simpleName: 'Blake2b', simpleName: 'Blake2b',
interfaces: [] interfaces: [UpdateableHash]
}; };
var chunked$lambda = wrapFunction(function () { function Blake2b_init(key, requestedHashLenght, $this) {
if (requestedHashLenght === void 0)
requestedHashLenght = 64;
$this = $this || Object.create(Blake2b.prototype);
var tmp$, tmp$_0, tmp$_1;
var tmp$_2;
if ((tmp$ = key != null ? encodeToByteArray(key) : null) != null) {
var destination = ArrayList_init(tmp$.length);
var tmp$_3;
for (tmp$_3 = 0; tmp$_3 !== tmp$.length; ++tmp$_3) {
var item = tmp$[tmp$_3];
destination.add_11rb$(new UByte(item));
}
tmp$_2 = destination;
}
else
tmp$_2 = null;
Blake2b.call($this, (tmp$_1 = (tmp$_0 = tmp$_2) != null ? copyToArray(tmp$_0) : null) != null ? tmp$_1 : [], requestedHashLenght);
return $this;
}
var chunked$lambda_0 = wrapFunction(function () {
var copyToArray = Kotlin.kotlin.collections.copyToArray; var copyToArray = Kotlin.kotlin.collections.copyToArray;
return function (it) { return function (it) {
return copyToArray(it); return copyToArray(it);
@ -854,7 +1158,7 @@
simpleName: 'Sha256', simpleName: 'Sha256',
interfaces: [] interfaces: []
}; };
var chunked$lambda_0 = wrapFunction(function () { var chunked$lambda_1 = wrapFunction(function () {
var copyToArray = Kotlin.kotlin.collections.copyToArray; var copyToArray = Kotlin.kotlin.collections.copyToArray;
return function (it) { return function (it) {
return copyToArray(it); return copyToArray(it);
@ -1199,16 +1503,19 @@
var package$ionspin = package$com.ionspin || (package$com.ionspin = {}); var package$ionspin = package$com.ionspin || (package$com.ionspin = {});
var package$kotlin = package$ionspin.kotlin || (package$ionspin.kotlin = {}); var package$kotlin = package$ionspin.kotlin || (package$ionspin.kotlin = {});
var package$crypto = package$kotlin.crypto || (package$kotlin.crypto = {}); var package$crypto = package$kotlin.crypto || (package$kotlin.crypto = {});
package$crypto.Hash = Hash;
package$crypto.UpdateableHash = UpdateableHash;
package$crypto.hexColumsPrint_mgx7ee$ = hexColumsPrint; package$crypto.hexColumsPrint_mgx7ee$ = hexColumsPrint;
package$crypto.hexColumsPrint_q387ch$ = hexColumsPrint_0; package$crypto.hexColumsPrint_q387ch$ = hexColumsPrint_0;
package$crypto.hexColumsPrint_uo2ox1$ = hexColumsPrint_1; package$crypto.hexColumsPrint_uo2ox1$ = hexColumsPrint_1;
package$crypto.rotateRight_k13f4a$ = rotateRight; package$crypto.rotateRight_k13f4a$ = rotateRight;
package$crypto.rotateRight_hc3rh$ = rotateRight_0; package$crypto.rotateRight_hc3rh$ = rotateRight_0;
$$importsForInline$$['crypto-core'] = _;
Object.defineProperty(Blake2b, 'Companion', { Object.defineProperty(Blake2b, 'Companion', {
get: Blake2b$Companion_getInstance get: Blake2b$Companion_getInstance
}); });
$$importsForInline$$['crypto-core'] = _;
var package$blake2b = package$crypto.blake2b || (package$crypto.blake2b = {}); var package$blake2b = package$crypto.blake2b || (package$crypto.blake2b = {});
package$blake2b.Blake2b_init_9d67ql$ = Blake2b_init;
package$blake2b.Blake2b = Blake2b; package$blake2b.Blake2b = Blake2b;
Object.defineProperty(Sha256, 'Companion', { Object.defineProperty(Sha256, 'Companion', {
get: Sha256$Companion_getInstance get: Sha256$Companion_getInstance
@ -1221,6 +1528,6 @@
package$sha.Sha512 = Sha512; package$sha.Sha512 = Sha512;
Kotlin.defineModule('crypto-core', _); Kotlin.defineModule('crypto-core', _);
return _; return _;
}(module.exports, require('kotlin'), require('bignum'))); }(module.exports, require('kotlin'), require('bignum'), require('kotlinx-coroutines-core')));
//# sourceMappingURL=crypto-core.js.map //# sourceMappingURL=crypto-core.js.map

File diff suppressed because one or more lines are too long

View File

@ -1 +1 @@
// Kotlin.kotlin_module_metadata(393729, "crypto-core", "H4sIAAAAAAAAAKVWTXPaVhTlSUI8XwF+YOMQkjSO0zSJm6SYxEmmXbTGcQvxBx7Ak48NI4OCVIPEgMjEWXTSdCZdtKtMF5nuuumiv6D/oMvO9Af0d3TV6X3SAyTIRztdPB3d866uHu+8e0SEyunfZfiJQKxpDu0jowXqkeN2LBuiG/2+fgykDnODjtU0atZTA+Sy7ULSNJ5sOp1hd7DftzBWDmwLr8Vj14DogYAd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gYtMmJge8gkQH6oA4MSQByGwMuQ/IXAwpATIfQ5YBWYgh/wRkMYYUag4rTLLx8CtBLLV59kykC9KiC8CCPLPym05SheSy6EDnHc2qLJAFh4zK7YjueFusUbnpMNkGVKUQrFkn1ju32CY8LkKet2I99JEsiKzjEvsYXapTpdjJRztPABbbFs23c4PtXA9bvboPPsJtDs0WNAW4K8POItu9/iNhyKEB3SFf70wcHl7lRL7S7F2V1Rw8vifqLB6daJ+jp6XeHtzeBzkv3GbiKVJeG2BdwIQLni+I25Ikch1o/L8Z+h/jKTRuDNou0EzbLa/fizK4/PKjiq3r23/fUvQ9K8j0dH+jvnv6Ue1w//Rk++AYv9rmpk17hwcfj3g0LRylkVqfqHh6uwQXkHIbSLkNpNy+C9c6XPfgepNqFyMu1httZDbtczozomLYZF2Qc0kw4DV0jWp8zLtI1WM2NLruZ0CJHHgbaSY3aLR5c9jhGDL5yO0M+RS8RmfC4EhypoinNvdkApFZXV8rUypTod5+cRRhrfxWxQvHcZwv/hrbKJZJScYRMo3SRplFuYTyNsoXUb4qpcnuSMlETMUbX2oj3iCCN66PMlJbkKOMAgRd+B1JAfq7caTV1MerPcFNhc+zXNRfEJt2JCZifmrGjUbHN8Z4dBAxOgR/FEUIOF7PoHwW5Q0h1VGflWdPgDej4DKCtybgDbZSHH1iZ+AwPz/RFFu98PTViDyjQCSwxEtofjm67up1cH5MYLDS6hNhW7FIRpIAxZmQkfN/ojkxbTamzcW0+Zi2ENMWI1p+POOpzENksOTFP4VD0RkzT+4MBpV+LdoBosFEpSeB7WjglX+JOrPrdbYx8zZm3sbM29E621hSO1pnG4tv/4U6P2W16TrbWFI7WucpcB4+Pq4X9M/rbMfqbMfqbMfqbMfqbMfqbMfqbMfqjFq8rBr+5ysiMRTxP1dxEb/l70w+5cUj/z8XlvOWQRAAAA==");

View File

@ -23,5 +23,5 @@ package com.ionspin.kotlin.crypto
*/ */
interface Hash interface Hash
interface StreamingHash : Hash interface UpdateableHash : Hash

View File

@ -22,8 +22,6 @@ import com.ionspin.kotlin.crypto.*
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job import kotlinx.coroutines.Job
import kotlinx.coroutines.async
import kotlin.text.chunked
/** /**
* Created by Ugljesa Jovanovic * Created by Ugljesa Jovanovic
@ -32,7 +30,7 @@ import kotlin.text.chunked
*/ */
@ExperimentalStdlibApi @ExperimentalStdlibApi
@ExperimentalUnsignedTypes @ExperimentalUnsignedTypes
class Blake2b(val key: Array<UByte>? = null, val hashLength: Int = 64) : StreamingHash { class Blake2b(val key: Array<UByte>? = null, val hashLength: Int = 64) : UpdateableHash {
companion object : Hash { companion object : Hash {
const val BITS_IN_WORD = 64 const val BITS_IN_WORD = 64
@ -250,7 +248,7 @@ class Blake2b(val key: Array<UByte>? = null, val hashLength: Int = 64) : Streami
requestedHashLenght requestedHashLenght
) )
val job = Job() var job = Job()
val scope = CoroutineScope(Dispatchers.Default + job) val scope = CoroutineScope(Dispatchers.Default + job)
@ -268,7 +266,7 @@ class Blake2b(val key: Array<UByte>? = null, val hashLength: Int = 64) : Streami
} }
} }
fun updateBlocking(array: Array<UByte>) { fun update(array: Array<UByte>) {
if (array.isEmpty()) { if (array.isEmpty()) {
throw RuntimeException("Updating with empty array is not allowed. If you need empty hash, just call digest without updating") throw RuntimeException("Updating with empty array is not allowed. If you need empty hash, just call digest without updating")
} }
@ -309,8 +307,8 @@ class Blake2b(val key: Array<UByte>? = null, val hashLength: Int = 64) : Streami
} }
fun updateBlocking(input: String) { fun update(input: String) {
updateBlocking(input.encodeToByteArray().map { it.toUByte() }.toTypedArray()) update(input.encodeToByteArray().map { it.toUByte() }.toTypedArray())
} }
private fun appendToBuffer(array: Array<UByte>, start: Int) { private fun appendToBuffer(array: Array<UByte>, start: Int) {
@ -322,12 +320,6 @@ class Blake2b(val key: Array<UByte>? = null, val hashLength: Int = 64) : Streami
h = compress(h, block, counter, false) h = compress(h, block, counter, false)
} }
suspend fun update(array: Array<UByte>) {
}
fun digest(): Array<UByte> { fun digest(): Array<UByte> {
val lastBlockPadded = padToBlock(buffer) val lastBlockPadded = padToBlock(buffer)
counter += bufferCounter counter += bufferCounter

View File

@ -16,6 +16,9 @@
package com.ionspin.kotlin.crypto.blake2b package com.ionspin.kotlin.crypto.blake2b
import com.ionspin.kotlin.crypto.util.testBlocking
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import kotlin.test.Test import kotlin.test.Test
import kotlin.test.assertTrue import kotlin.test.assertTrue
@ -26,10 +29,10 @@ import kotlin.test.assertTrue
*/ */
@ExperimentalUnsignedTypes @ExperimentalUnsignedTypes
@ExperimentalStdlibApi @ExperimentalStdlibApi
class Blake2bStreaming { class Blake2bInstanceTest {
@Test @Test
fun testStreamingBlake2b() { fun testUpdateableBlake2b() {
val updates = 14 val updates = 14
val input = "1234567890" val input = "1234567890"
val expectedResult = arrayOf<UByte>( val expectedResult = arrayOf<UByte>(
@ -44,7 +47,7 @@ class Blake2bStreaming {
val blake2b = Blake2b() val blake2b = Blake2b()
for (i in 0 until updates) { for (i in 0 until updates) {
blake2b.updateBlocking(input) blake2b.update(input)
} }
val result = blake2b.digest() val result = blake2b.digest()
@ -62,7 +65,7 @@ class Blake2bStreaming {
val blake2b = Blake2b() val blake2b = Blake2b()
for (i in 0 until updates) { for (i in 0 until updates) {
blake2b.updateBlocking(input) blake2b.update(input)
} }
val result = blake2b.digestString() val result = blake2b.digestString()
assertTrue { assertTrue {
@ -75,7 +78,7 @@ class Blake2bStreaming {
val test = "abc" val test = "abc"
val key = "key" val key = "key"
val blake2b = Blake2b(key) val blake2b = Blake2b(key)
blake2b.updateBlocking(test) blake2b.update(test)
val result = blake2b.digest() val result = blake2b.digest()
val printout = result.map { it.toString(16) }.chunked(16) val printout = result.map { it.toString(16) }.chunked(16)
printout.forEach { println(it.joinToString(separator = " ") { it.toUpperCase() }) } printout.forEach { println(it.joinToString(separator = " ") { it.toUpperCase() }) }

View File

@ -49,13 +49,13 @@ class Blake2bKnowAnswerTests {
} }
@Test @Test
fun knownAnswerTestStreaming() { fun knownAnswerTestInstance() {
kat.forEach { kat -> kat.forEach { kat ->
val parsedInput = kat.input.chunked(2).map { it.toUByte(16) }.toTypedArray() val parsedInput = kat.input.chunked(2).map { it.toUByte(16) }.toTypedArray()
val chunkedInput = parsedInput.toList().chunked(128).map { it.toTypedArray() }.toTypedArray() val chunkedInput = parsedInput.toList().chunked(128).map { it.toTypedArray() }.toTypedArray()
val blake2b = Blake2b(key = kat.key.chunked(2).map { it.toUByte(16) }.toTypedArray()) val blake2b = Blake2b(key = kat.key.chunked(2).map { it.toUByte(16) }.toTypedArray())
chunkedInput.forEach { blake2b.updateBlocking(it) } chunkedInput.forEach { blake2b.update(it) }
val result = blake2b.digest() val result = blake2b.digest()
assertTrue("KAT ${kat.input} \nkey: ${kat.key} \nexpected: {${kat.hash}") { assertTrue("KAT ${kat.input} \nkey: ${kat.key} \nexpected: {${kat.hash}") {
result.contentEquals(kat.hash.chunked(2).map { it.toUByte(16) }.toTypedArray()) result.contentEquals(kat.hash.chunked(2).map { it.toUByte(16) }.toTypedArray())

View File

@ -0,0 +1,26 @@
/*
* Copyright 2019 Ugljesa Jovanovic
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ionspin.kotlin.crypto.util
import kotlinx.coroutines.CoroutineScope
/**
* Created by Ugljesa Jovanovic
* ugljesa.jovanovic@ionspin.com
* on 20-Jul-2019
*/
expect fun testBlocking(block : suspend (scope : CoroutineScope) -> Unit)

View File

@ -0,0 +1,28 @@
/*
* Copyright 2019 Ugljesa Jovanovic
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ionspin.kotlin.crypto.util
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.promise
/**
* Created by Ugljesa Jovanovic
* ugljesa.jovanovic@ionspin.com
* on 20-Jul-2019
*/
actual fun testBlocking(block: suspend (scope: CoroutineScope) -> Unit) : dynamic = GlobalScope.promise { block(this) }

View File

@ -0,0 +1,27 @@
/*
* Copyright 2019 Ugljesa Jovanovic
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ionspin.kotlin.crypto.util
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.runBlocking
/**
* Created by Ugljesa Jovanovic
* ugljesa.jovanovic@ionspin.com
* on 20-Jul-2019
*/
actual fun testBlocking(block: suspend (scope: CoroutineScope) -> Unit) = runBlocking { block(this) }

View File

@ -0,0 +1,27 @@
/*
* Copyright 2019 Ugljesa Jovanovic
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ionspin.kotlin.crypto.util
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.runBlocking
/**
* Created by Ugljesa Jovanovic
* ugljesa.jovanovic@ionspin.com
* on 20-Jul-2019
*/
actual fun testBlocking(block: suspend (scope: CoroutineScope) -> Unit) = runBlocking { block(this) }