A bit of cleanup and README update
This commit is contained in:
parent
bebe05757d
commit
7b57a931ef
@ -3,6 +3,6 @@
|
||||
|
||||
|
||||
|
||||
#### Initial release/BigInteger - 0.0.1 - 20.7.2019
|
||||
#### Initial release - 0.0.1 - 20.7.2019
|
||||
- Implemented Blake2b and SHA256/512
|
||||
|
||||
|
66
README.md
66
README.md
@ -8,12 +8,23 @@ This is an extremely early release, currently only consisting of Blake2b and SHA
|
||||
|
||||
**The API will move fast and break often until v1.0**
|
||||
|
||||
Tenative plan is to add 25519 curve based signing and key exchange next.
|
||||
Make SHA hashes "updateable" like Blake2b
|
||||
|
||||
After that tenative plan is to add 25519 curve based signing and key exchange next.
|
||||
|
||||
## Should I use this in production?
|
||||
|
||||
No, it's untested and unproven.
|
||||
|
||||
## Supported
|
||||
|
||||
## Hashing functions
|
||||
* Blake2b
|
||||
* SHA512
|
||||
* SHA256
|
||||
|
||||
More to come.
|
||||
|
||||
## Integration
|
||||
|
||||
#### Gradle
|
||||
@ -34,7 +45,58 @@ implementation("com.ionspin.kotlin:crypto:0.0.1-SNAPSHOT")
|
||||
|
||||
## Usage
|
||||
|
||||
To be continued...
|
||||
### Blake2b
|
||||
|
||||
You can use Blake 2b in two modes
|
||||
|
||||
#### Using a `Blake2b` object
|
||||
You need to deliver the complete data that is to be hashed in one go
|
||||
|
||||
```kotlin
|
||||
val input = "abc"
|
||||
val result = Blake2b.digest(input)
|
||||
```
|
||||
|
||||
Result is returned as a `Array<Byte>`
|
||||
|
||||
#### Using a `Blake2b` instance
|
||||
You can create an instance and feed the data by using `update(input : Array<Byte>)` call. Once all data is supplied,
|
||||
you should call `digest()` or `digestString()` convinence method that converts the `Array<Byte>` into hexadecimal string.
|
||||
|
||||
If you want to use Blake2b with a key, you should supply it when creating the `Blake2b` instance.
|
||||
|
||||
```kotlin
|
||||
val test = "abc"
|
||||
val key = "key"
|
||||
val blake2b = Blake2b(key)
|
||||
blake2b.update(test)
|
||||
val result = blake2b.digest()
|
||||
```
|
||||
|
||||
After digest is called, the instance is reset and can be reused (Keep in mind key stays the same for the particular instance).
|
||||
### SHA2 (SHA256 and SHA512)
|
||||
|
||||
You need to deliver the complete data that is to be hashed in one go. You can either provide the `Array<Byte>` as input
|
||||
or `String`. Result is always returned as `Array<Byte>` (At least in verision 0.0.1)
|
||||
|
||||
```kotlin
|
||||
val input = "abc"
|
||||
val result = Sha256.digest(input)
|
||||
```
|
||||
|
||||
```kotlin
|
||||
val input ="abc"
|
||||
val result = Sha512.digest(message = input.encodeToByteArray().map { it.toUByte() }.toTypedArray())
|
||||
```
|
||||
|
||||
Result is returned as a `Array<Byte>`
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
585
crypto-core/node_modules/crypto-core.js
generated
vendored
585
crypto-core/node_modules/crypto-core.js
generated
vendored
@ -1,6 +1,7 @@
|
||||
(function (_, Kotlin, $module$bignum, $module$kotlinx_coroutines_core) {
|
||||
(function (_, Kotlin, $module$bignum) {
|
||||
'use strict';
|
||||
var $$importsForInline$$ = _.$$importsForInline$$ || (_.$$importsForInline$$ = {});
|
||||
var Kind_OBJECT = Kotlin.Kind.OBJECT;
|
||||
var Kind_INTERFACE = Kotlin.Kind.INTERFACE;
|
||||
var chunked = Kotlin.kotlin.collections.chunked_ba2ldo$;
|
||||
var joinToString = Kotlin.kotlin.collections.joinToString_fmv235$;
|
||||
@ -13,7 +14,6 @@
|
||||
var ArrayList_init = Kotlin.kotlin.collections.ArrayList_init_ww73n8$;
|
||||
var UInt_init = Kotlin.kotlin.UInt;
|
||||
var ULong_init = Kotlin.kotlin.ULong;
|
||||
var Unit = Kotlin.kotlin.Unit;
|
||||
var encodeToByteArray = Kotlin.kotlin.text.encodeToByteArray_pdl1vz$;
|
||||
var toList = Kotlin.kotlin.collections.toList_7wnvza$;
|
||||
var UByte = Kotlin.kotlin.UByte;
|
||||
@ -21,14 +21,7 @@
|
||||
var toList_0 = Kotlin.kotlin.collections.toList_us0mfu$;
|
||||
var IllegalStateException_init = Kotlin.kotlin.IllegalStateException_init_pdl1vj$;
|
||||
var until = Kotlin.kotlin.ranges.until_dqglrj$;
|
||||
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 Array_0 = Array;
|
||||
@ -41,9 +34,22 @@
|
||||
var addAll = Kotlin.kotlin.collections.addAll_ipc267$;
|
||||
var emptyList = Kotlin.kotlin.collections.emptyList_287e2$;
|
||||
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 Config() {
|
||||
Config_instance = this;
|
||||
this.DEBUG = false;
|
||||
}
|
||||
Config.$metadata$ = {
|
||||
kind: Kind_OBJECT,
|
||||
simpleName: 'Config',
|
||||
interfaces: []
|
||||
};
|
||||
var Config_instance = null;
|
||||
function Config_getInstance() {
|
||||
if (Config_instance === null) {
|
||||
new Config();
|
||||
}
|
||||
return Config_instance;
|
||||
}
|
||||
function Hash() {
|
||||
}
|
||||
Hash.$metadata$ = {
|
||||
@ -169,13 +175,6 @@
|
||||
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();
|
||||
if (key === void 0)
|
||||
@ -184,8 +183,6 @@
|
||||
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;
|
||||
@ -232,26 +229,9 @@
|
||||
this.R3 = 16;
|
||||
this.R4 = 63;
|
||||
}
|
||||
function Blake2b$Companion$mixRound$lambda$lambda(it) {
|
||||
return it.toUpperCase();
|
||||
}
|
||||
Blake2b$Companion.prototype.mixRound_r29y2p$ = function (input, message, round) {
|
||||
var v = input;
|
||||
var selectedSigma = this.sigma_0[round % 10];
|
||||
var $receiver = v;
|
||||
var destination = ArrayList_init($receiver.length);
|
||||
var tmp$;
|
||||
for (tmp$ = 0; tmp$ !== $receiver.length; ++tmp$) {
|
||||
var item = $receiver[tmp$];
|
||||
destination.add_11rb$(toString_0(item, 16));
|
||||
}
|
||||
var printout = chunked(destination, 3);
|
||||
var tmp$_0;
|
||||
tmp$_0 = printout.iterator();
|
||||
while (tmp$_0.hasNext()) {
|
||||
var element = tmp$_0.next();
|
||||
println(joinToString(element, ' ', void 0, void 0, void 0, void 0, Blake2b$Companion$mixRound$lambda$lambda));
|
||||
}
|
||||
v = this.mix_0(v, 0, 4, 8, 12, message[selectedSigma[0]], message[selectedSigma[1]]);
|
||||
v = this.mix_0(v, 1, 5, 9, 13, message[selectedSigma[2]], message[selectedSigma[3]]);
|
||||
v = this.mix_0(v, 2, 6, 10, 14, message[selectedSigma[4]], message[selectedSigma[5]]);
|
||||
@ -330,21 +310,22 @@
|
||||
accumulator = acc;
|
||||
}
|
||||
var m = accumulator;
|
||||
println('m');
|
||||
var destination = ArrayList_init(m.length);
|
||||
var tmp$_3;
|
||||
for (tmp$_3 = 0; tmp$_3 !== m.length; ++tmp$_3) {
|
||||
var item = m[tmp$_3];
|
||||
destination.add_11rb$(toString_0(item, 16));
|
||||
if (Config_getInstance().DEBUG) {
|
||||
var destination = ArrayList_init(m.length);
|
||||
var tmp$_3;
|
||||
for (tmp$_3 = 0; tmp$_3 !== m.length; ++tmp$_3) {
|
||||
var item = m[tmp$_3];
|
||||
destination.add_11rb$(toString_0(item, 16));
|
||||
}
|
||||
var printout = chunked(destination, 4);
|
||||
var tmp$_4;
|
||||
tmp$_4 = printout.iterator();
|
||||
while (tmp$_4.hasNext()) {
|
||||
var element_0 = tmp$_4.next();
|
||||
println(joinToString(element_0, ' ', void 0, void 0, void 0, void 0, Blake2b$Companion$compress$lambda$lambda));
|
||||
}
|
||||
println('Offset ' + offsetCounter);
|
||||
}
|
||||
var printout = chunked(destination, 4);
|
||||
var tmp$_4;
|
||||
tmp$_4 = printout.iterator();
|
||||
while (tmp$_4.hasNext()) {
|
||||
var element_0 = tmp$_4.next();
|
||||
println(joinToString(element_0, ' ', void 0, void 0, void 0, void 0, Blake2b$Companion$compress$lambda$lambda));
|
||||
}
|
||||
println('Offset ' + offsetCounter);
|
||||
var $this_0 = v[12];
|
||||
var other_0 = offsetCounter.ulongValue_6taknv$();
|
||||
v[12] = new ULong_init($this_0.data.xor(other_0.data));
|
||||
@ -553,7 +534,7 @@
|
||||
}
|
||||
return Blake2b$Companion_instance;
|
||||
}
|
||||
Blake2b.prototype.updateBlocking_ummv9a$ = function (array) {
|
||||
Blake2b.prototype.update_ummv9a$ = function (array) {
|
||||
if (array.length === 0) {
|
||||
throw RuntimeException_init('Updating with empty array is not allowed. If you need empty hash, just call digest without updating');
|
||||
}
|
||||
@ -613,7 +594,7 @@
|
||||
}
|
||||
}
|
||||
};
|
||||
Blake2b.prototype.updateBlocking_61zpoe$ = function (input) {
|
||||
Blake2b.prototype.update_61zpoe$ = function (input) {
|
||||
var $receiver = encodeToByteArray(input);
|
||||
var destination = ArrayList_init($receiver.length);
|
||||
var tmp$;
|
||||
@ -621,7 +602,7 @@
|
||||
var item = $receiver[tmp$];
|
||||
destination.add_11rb$(new UByte(item));
|
||||
}
|
||||
this.updateBlocking_ummv9a$(copyToArray(destination));
|
||||
this.update_ummv9a$(copyToArray(destination));
|
||||
};
|
||||
Blake2b.prototype.appendToBuffer_0 = function (array, start) {
|
||||
arrayCopy(array, this.buffer, start, 0, array.length);
|
||||
@ -630,183 +611,12 @@
|
||||
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, ''));
|
||||
this.reset_0();
|
||||
return result;
|
||||
};
|
||||
Blake2b.prototype.digestString = function () {
|
||||
@ -819,6 +629,18 @@
|
||||
}
|
||||
return joinToString(destination, '');
|
||||
};
|
||||
Blake2b.prototype.reset_0 = function () {
|
||||
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;
|
||||
};
|
||||
Blake2b.$metadata$ = {
|
||||
kind: Kind_CLASS,
|
||||
simpleName: 'Blake2b',
|
||||
@ -852,15 +674,6 @@
|
||||
});
|
||||
function Sha256() {
|
||||
Sha256$Companion_getInstance();
|
||||
this.h0 = new UInt_init(1779033703);
|
||||
this.h1 = new UInt_init(-1150833019);
|
||||
this.h2 = new UInt_init(1013904242);
|
||||
this.h3 = new UInt_init(-1521486534);
|
||||
this.h4 = new UInt_init(1359893119);
|
||||
this.h5 = new UInt_init(-1694144372);
|
||||
this.h6 = new UInt_init(528734635);
|
||||
this.h7 = new UInt_init(1541459225);
|
||||
this.k = [new UInt_init(1116352408), new UInt_init(1899447441), new UInt_init(-1245643825), new UInt_init(-373957723), new UInt_init(961987163), new UInt_init(1508970993), new UInt_init(-1841331548), new UInt_init(-1424204075), new UInt_init(-670586216), new UInt_init(310598401), new UInt_init(607225278), new UInt_init(1426881987), new UInt_init(1925078388), new UInt_init(-2132889090), new UInt_init(-1680079193), new UInt_init(-1046744716), new UInt_init(-459576895), new UInt_init(-272742522), new UInt_init(264347078), new UInt_init(604807628), new UInt_init(770255983), new UInt_init(1249150122), new UInt_init(1555081692), new UInt_init(1996064986), new UInt_init(-1740746414), new UInt_init(-1473132947), new UInt_init(-1341970488), new UInt_init(-1084653625), new UInt_init(-958395405), new UInt_init(-710438585), new UInt_init(113926993), new UInt_init(338241895), new UInt_init(666307205), new UInt_init(773529912), new UInt_init(1294757372), new UInt_init(1396182291), new UInt_init(1695183700), new UInt_init(1986661051), new UInt_init(-2117940946), new UInt_init(-1838011259), new UInt_init(-1564481375), new UInt_init(-1474664885), new UInt_init(-1035236496), new UInt_init(-949202525), new UInt_init(-778901479), new UInt_init(-694614492), new UInt_init(-200395387), new UInt_init(275423344), new UInt_init(430227734), new UInt_init(506948616), new UInt_init(659060556), new UInt_init(883997877), new UInt_init(958139571), new UInt_init(1322822218), new UInt_init(1537002063), new UInt_init(1747873779), new UInt_init(1955562222), new UInt_init(2024104815), new UInt_init(-2067236844), new UInt_init(-1933114872), new UInt_init(-1866530822), new UInt_init(-1538233109), new UInt_init(-1090935817), new UInt_init(-965641998)];
|
||||
}
|
||||
function Sha256$Companion() {
|
||||
Sha256$Companion_instance = this;
|
||||
@ -869,21 +682,29 @@
|
||||
this.UINT_MASK = new UInt_init(-1);
|
||||
this.BYTE_MASK_FROM_ULONG = new ULong_init(Kotlin.Long.fromInt(255));
|
||||
this.BYTE_MASK_FROM_UINT = new UInt_init(255);
|
||||
this.iv = [new UInt_init(1779033703), new UInt_init(-1150833019), new UInt_init(1013904242), new UInt_init(-1521486534), new UInt_init(1359893119), new UInt_init(-1694144372), new UInt_init(528734635), new UInt_init(1541459225)];
|
||||
this.k = [new UInt_init(1116352408), new UInt_init(1899447441), new UInt_init(-1245643825), new UInt_init(-373957723), new UInt_init(961987163), new UInt_init(1508970993), new UInt_init(-1841331548), new UInt_init(-1424204075), new UInt_init(-670586216), new UInt_init(310598401), new UInt_init(607225278), new UInt_init(1426881987), new UInt_init(1925078388), new UInt_init(-2132889090), new UInt_init(-1680079193), new UInt_init(-1046744716), new UInt_init(-459576895), new UInt_init(-272742522), new UInt_init(264347078), new UInt_init(604807628), new UInt_init(770255983), new UInt_init(1249150122), new UInt_init(1555081692), new UInt_init(1996064986), new UInt_init(-1740746414), new UInt_init(-1473132947), new UInt_init(-1341970488), new UInt_init(-1084653625), new UInt_init(-958395405), new UInt_init(-710438585), new UInt_init(113926993), new UInt_init(338241895), new UInt_init(666307205), new UInt_init(773529912), new UInt_init(1294757372), new UInt_init(1396182291), new UInt_init(1695183700), new UInt_init(1986661051), new UInt_init(-2117940946), new UInt_init(-1838011259), new UInt_init(-1564481375), new UInt_init(-1474664885), new UInt_init(-1035236496), new UInt_init(-949202525), new UInt_init(-778901479), new UInt_init(-694614492), new UInt_init(-200395387), new UInt_init(275423344), new UInt_init(430227734), new UInt_init(506948616), new UInt_init(659060556), new UInt_init(883997877), new UInt_init(958139571), new UInt_init(1322822218), new UInt_init(1537002063), new UInt_init(1747873779), new UInt_init(1955562222), new UInt_init(2024104815), new UInt_init(-2067236844), new UInt_init(-1933114872), new UInt_init(-1866530822), new UInt_init(-1538233109), new UInt_init(-1090935817), new UInt_init(-965641998)];
|
||||
}
|
||||
Sha256$Companion.$metadata$ = {
|
||||
kind: Kind_OBJECT,
|
||||
simpleName: 'Companion',
|
||||
interfaces: []
|
||||
};
|
||||
var Sha256$Companion_instance = null;
|
||||
function Sha256$Companion_getInstance() {
|
||||
if (Sha256$Companion_instance === null) {
|
||||
new Sha256$Companion();
|
||||
}
|
||||
return Sha256$Companion_instance;
|
||||
}
|
||||
Sha256.prototype.digest_ummv9a$ = function (message) {
|
||||
Sha256$Companion.prototype.digest_61zpoe$ = function (message) {
|
||||
var $receiver = encodeToByteArray(message);
|
||||
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));
|
||||
}
|
||||
return this.digest_ummv9a$(copyToArray(destination));
|
||||
};
|
||||
Sha256$Companion.prototype.digest_ummv9a$ = function (message) {
|
||||
var tmp$;
|
||||
var h0 = {v: new UInt_init(1779033703)};
|
||||
var h1 = {v: new UInt_init(-1150833019)};
|
||||
var h2 = {v: new UInt_init(1013904242)};
|
||||
var h3 = {v: new UInt_init(-1521486534)};
|
||||
var h4 = {v: new UInt_init(1359893119)};
|
||||
var h5 = {v: new UInt_init(-1694144372)};
|
||||
var h6 = {v: new UInt_init(528734635)};
|
||||
var h7 = {v: new UInt_init(1541459225)};
|
||||
var originalMessageSizeInBits = message.length * 8 | 0;
|
||||
var expandedRemainderOf512 = (originalMessageSizeInBits + 65 | 0) % 512;
|
||||
if (expandedRemainderOf512 === 0)
|
||||
@ -961,14 +782,14 @@
|
||||
var other_2 = w[i_2 - 7 | 0];
|
||||
w[i_2] = new UInt_init((new UInt_init($this.data + other_2.data | 0)).data + s1.data | 0);
|
||||
}
|
||||
var a = this.h0;
|
||||
var b = this.h1;
|
||||
var c = this.h2;
|
||||
var d = this.h3;
|
||||
var e = this.h4;
|
||||
var f = this.h5;
|
||||
var g = this.h6;
|
||||
var h = this.h7;
|
||||
var a = h0.v;
|
||||
var b = h1.v;
|
||||
var c = h2.v;
|
||||
var d = h3.v;
|
||||
var e = h4.v;
|
||||
var f = h5.v;
|
||||
var g = h6.v;
|
||||
var h = h7.v;
|
||||
for (var i_3 = 0; i_3 < 64; i_3++) {
|
||||
var s1_0 = this.compressionSigma1_0(e);
|
||||
var ch = this.ch_0(e, f, g);
|
||||
@ -989,102 +810,91 @@
|
||||
b = a;
|
||||
a = new UInt_init(temp1.data + temp2.data | 0);
|
||||
}
|
||||
var $this_2 = this.h0;
|
||||
var $this_2 = h0.v;
|
||||
var other_5 = a;
|
||||
this.h0 = new UInt_init($this_2.data + other_5.data | 0);
|
||||
var $this_3 = this.h1;
|
||||
h0.v = new UInt_init($this_2.data + other_5.data | 0);
|
||||
var $this_3 = h1.v;
|
||||
var other_6 = b;
|
||||
this.h1 = new UInt_init($this_3.data + other_6.data | 0);
|
||||
var $this_4 = this.h2;
|
||||
h1.v = new UInt_init($this_3.data + other_6.data | 0);
|
||||
var $this_4 = h2.v;
|
||||
var other_7 = c;
|
||||
this.h2 = new UInt_init($this_4.data + other_7.data | 0);
|
||||
var $this_5 = this.h3;
|
||||
h2.v = new UInt_init($this_4.data + other_7.data | 0);
|
||||
var $this_5 = h3.v;
|
||||
var other_8 = d;
|
||||
this.h3 = new UInt_init($this_5.data + other_8.data | 0);
|
||||
var $this_6 = this.h4;
|
||||
h3.v = new UInt_init($this_5.data + other_8.data | 0);
|
||||
var $this_6 = h4.v;
|
||||
var other_9 = e;
|
||||
this.h4 = new UInt_init($this_6.data + other_9.data | 0);
|
||||
var $this_7 = this.h5;
|
||||
h4.v = new UInt_init($this_6.data + other_9.data | 0);
|
||||
var $this_7 = h5.v;
|
||||
var other_10 = f;
|
||||
this.h5 = new UInt_init($this_7.data + other_10.data | 0);
|
||||
var $this_8 = this.h6;
|
||||
h5.v = new UInt_init($this_7.data + other_10.data | 0);
|
||||
var $this_8 = h6.v;
|
||||
var other_11 = g;
|
||||
this.h6 = new UInt_init($this_8.data + other_11.data | 0);
|
||||
var $this_9 = this.h7;
|
||||
h6.v = new UInt_init($this_8.data + other_11.data | 0);
|
||||
var $this_9 = h7.v;
|
||||
var other_12 = h;
|
||||
this.h7 = new UInt_init($this_9.data + other_12.data | 0);
|
||||
h7.v = new UInt_init($this_9.data + other_12.data | 0);
|
||||
}
|
||||
var $receiver_0 = this.toPaddedByteArray_1(this.h0);
|
||||
var elements_0 = this.toPaddedByteArray_1(this.h1);
|
||||
var $receiver_0 = this.toPaddedByteArray_1(h0.v);
|
||||
var elements_0 = this.toPaddedByteArray_1(h1.v);
|
||||
var $receiver_1 = $receiver_0.concat(elements_0);
|
||||
var elements_1 = this.toPaddedByteArray_1(this.h2);
|
||||
var elements_1 = this.toPaddedByteArray_1(h2.v);
|
||||
var $receiver_2 = $receiver_1.concat(elements_1);
|
||||
var elements_2 = this.toPaddedByteArray_1(this.h3);
|
||||
var elements_2 = this.toPaddedByteArray_1(h3.v);
|
||||
var $receiver_3 = $receiver_2.concat(elements_2);
|
||||
var elements_3 = this.toPaddedByteArray_1(this.h4);
|
||||
var elements_3 = this.toPaddedByteArray_1(h4.v);
|
||||
var $receiver_4 = $receiver_3.concat(elements_3);
|
||||
var elements_4 = this.toPaddedByteArray_1(this.h5);
|
||||
var elements_4 = this.toPaddedByteArray_1(h5.v);
|
||||
var $receiver_5 = $receiver_4.concat(elements_4);
|
||||
var elements_5 = this.toPaddedByteArray_1(this.h6);
|
||||
var elements_5 = this.toPaddedByteArray_1(h6.v);
|
||||
var $receiver_6 = $receiver_5.concat(elements_5);
|
||||
var elements_6 = this.toPaddedByteArray_1(this.h7);
|
||||
var elements_6 = this.toPaddedByteArray_1(h7.v);
|
||||
var digest = $receiver_6.concat(elements_6);
|
||||
this.reset_0();
|
||||
return digest;
|
||||
};
|
||||
Sha256.prototype.reset_0 = function () {
|
||||
this.h0 = new UInt_init(1779033703);
|
||||
this.h1 = new UInt_init(-1150833019);
|
||||
this.h2 = new UInt_init(1013904242);
|
||||
this.h3 = new UInt_init(-1521486534);
|
||||
this.h4 = new UInt_init(1359893119);
|
||||
this.h5 = new UInt_init(-1694144372);
|
||||
this.h6 = new UInt_init(528734635);
|
||||
this.h7 = new UInt_init(1541459225);
|
||||
};
|
||||
Sha256.prototype.scheduleSigma0_0 = function (value) {
|
||||
Sha256$Companion.prototype.scheduleSigma0_0 = function (value) {
|
||||
var $this = rotateRight(value, 7);
|
||||
var other = rotateRight(value, 18);
|
||||
var tmp$ = new UInt_init($this.data ^ other.data);
|
||||
var other_0 = new UInt_init(value.data >>> 3);
|
||||
return new UInt_init(tmp$.data ^ other_0.data);
|
||||
};
|
||||
Sha256.prototype.scheduleSigma1_0 = function (value) {
|
||||
Sha256$Companion.prototype.scheduleSigma1_0 = function (value) {
|
||||
var $this = rotateRight(value, 17);
|
||||
var other = rotateRight(value, 19);
|
||||
var tmp$ = new UInt_init($this.data ^ other.data);
|
||||
var other_0 = new UInt_init(value.data >>> 10);
|
||||
return new UInt_init(tmp$.data ^ other_0.data);
|
||||
};
|
||||
Sha256.prototype.compressionSigma0_0 = function (a) {
|
||||
Sha256$Companion.prototype.compressionSigma0_0 = function (a) {
|
||||
var $this = rotateRight(a, 2);
|
||||
var other = rotateRight(a, 13);
|
||||
var $this_0 = new UInt_init($this.data ^ other.data);
|
||||
var other_0 = rotateRight(a, 22);
|
||||
return new UInt_init($this_0.data ^ other_0.data);
|
||||
};
|
||||
Sha256.prototype.compressionSigma1_0 = function (e) {
|
||||
Sha256$Companion.prototype.compressionSigma1_0 = function (e) {
|
||||
var $this = rotateRight(e, 6);
|
||||
var other = rotateRight(e, 11);
|
||||
var $this_0 = new UInt_init($this.data ^ other.data);
|
||||
var other_0 = rotateRight(e, 25);
|
||||
return new UInt_init($this_0.data ^ other_0.data);
|
||||
};
|
||||
Sha256.prototype.ch_0 = function (x, y, z) {
|
||||
Sha256$Companion.prototype.ch_0 = function (x, y, z) {
|
||||
var tmp$ = new UInt_init(x.data & y.data);
|
||||
var other = Sha256$Companion_getInstance().UINT_MASK;
|
||||
var other = this.UINT_MASK;
|
||||
var other_0 = new UInt_init((new UInt_init(x.data ^ other.data)).data & z.data);
|
||||
return new UInt_init(tmp$.data ^ other_0.data);
|
||||
};
|
||||
Sha256.prototype.maj_0 = function (x, y, z) {
|
||||
Sha256$Companion.prototype.maj_0 = function (x, y, z) {
|
||||
var tmp$ = new UInt_init(x.data & y.data);
|
||||
var other = new UInt_init(x.data & z.data);
|
||||
var tmp$_0 = new UInt_init(tmp$.data ^ other.data);
|
||||
var other_0 = new UInt_init(y.data & z.data);
|
||||
return new UInt_init(tmp$_0.data ^ other_0.data);
|
||||
};
|
||||
Sha256.prototype.toPaddedByteArray_0 = function ($receiver) {
|
||||
var byteMask = Sha256$Companion_getInstance().BYTE_MASK_FROM_ULONG;
|
||||
Sha256$Companion.prototype.toPaddedByteArray_0 = function ($receiver) {
|
||||
var byteMask = this.BYTE_MASK_FROM_ULONG;
|
||||
var array = Array_0(8);
|
||||
var tmp$;
|
||||
tmp$ = array.length - 1 | 0;
|
||||
@ -1124,8 +934,8 @@
|
||||
}
|
||||
return array;
|
||||
};
|
||||
Sha256.prototype.toPaddedByteArray_1 = function ($receiver) {
|
||||
var byteMask = Sha256$Companion_getInstance().BYTE_MASK_FROM_UINT;
|
||||
Sha256$Companion.prototype.toPaddedByteArray_1 = function ($receiver) {
|
||||
var byteMask = this.BYTE_MASK_FROM_UINT;
|
||||
var array = Array_0(4);
|
||||
var tmp$;
|
||||
tmp$ = array.length - 1 | 0;
|
||||
@ -1153,10 +963,22 @@
|
||||
}
|
||||
return array;
|
||||
};
|
||||
Sha256$Companion.$metadata$ = {
|
||||
kind: Kind_OBJECT,
|
||||
simpleName: 'Companion',
|
||||
interfaces: []
|
||||
};
|
||||
var Sha256$Companion_instance = null;
|
||||
function Sha256$Companion_getInstance() {
|
||||
if (Sha256$Companion_instance === null) {
|
||||
new Sha256$Companion();
|
||||
}
|
||||
return Sha256$Companion_instance;
|
||||
}
|
||||
Sha256.$metadata$ = {
|
||||
kind: Kind_CLASS,
|
||||
simpleName: 'Sha256',
|
||||
interfaces: []
|
||||
interfaces: [Hash]
|
||||
};
|
||||
var chunked$lambda_1 = wrapFunction(function () {
|
||||
var copyToArray = Kotlin.kotlin.collections.copyToArray;
|
||||
@ -1166,35 +988,34 @@
|
||||
});
|
||||
function Sha512() {
|
||||
Sha512$Companion_getInstance();
|
||||
this.h0 = new ULong_init(new Kotlin.Long(-205731576, 1779033703));
|
||||
this.h1 = new ULong_init(new Kotlin.Long(-2067093701, -1150833019));
|
||||
this.h2 = new ULong_init(new Kotlin.Long(-23791573, 1013904242));
|
||||
this.h3 = new ULong_init(new Kotlin.Long(1595750129, -1521486534));
|
||||
this.h4 = new ULong_init(new Kotlin.Long(-1377402159, 1359893119));
|
||||
this.h5 = new ULong_init(new Kotlin.Long(725511199, -1694144372));
|
||||
this.h6 = new ULong_init(new Kotlin.Long(-79577749, 528734635));
|
||||
this.h7 = new ULong_init(new Kotlin.Long(327033209, 1541459225));
|
||||
}
|
||||
function Sha512$Companion() {
|
||||
Sha512$Companion_instance = this;
|
||||
this.BLOCK_SIZE = 1024;
|
||||
this.ULONG_MASK = new ULong_init(Kotlin.Long.NEG_ONE);
|
||||
this.k = [new ULong_init(new Kotlin.Long(-685199838, 1116352408)), new ULong_init(new Kotlin.Long(602891725, 1899447441)), new ULong_init(new Kotlin.Long(-330482897, -1245643825)), new ULong_init(new Kotlin.Long(-2121671748, -373957723)), new ULong_init(new Kotlin.Long(-213338824, 961987163)), new ULong_init(new Kotlin.Long(-1241133031, 1508970993)), new ULong_init(new Kotlin.Long(-1357295717, -1841331548)), new ULong_init(new Kotlin.Long(-630357736, -1424204075)), new ULong_init(new Kotlin.Long(-1560083902, -670586216)), new ULong_init(new Kotlin.Long(1164996542, 310598401)), new ULong_init(new Kotlin.Long(1323610764, 607225278)), new ULong_init(new Kotlin.Long(-704662302, 1426881987)), new ULong_init(new Kotlin.Long(-226784913, 1925078388)), new ULong_init(new Kotlin.Long(991336113, -2132889090)), new ULong_init(new Kotlin.Long(633803317, -1680079193)), new ULong_init(new Kotlin.Long(-815192428, -1046744716)), new ULong_init(new Kotlin.Long(-1628353838, -459576895)), new ULong_init(new Kotlin.Long(944711139, -272742522)), new ULong_init(new Kotlin.Long(-1953704523, 264347078)), new ULong_init(new Kotlin.Long(2007800933, 604807628)), new ULong_init(new Kotlin.Long(1495990901, 770255983)), new ULong_init(new Kotlin.Long(1856431235, 1249150122)), new ULong_init(new Kotlin.Long(-1119749164, 1555081692)), new ULong_init(new Kotlin.Long(-2096016459, 1996064986)), new ULong_init(new Kotlin.Long(-295247957, -1740746414)), new ULong_init(new Kotlin.Long(766784016, -1473132947)), new ULong_init(new Kotlin.Long(-1728372417, -1341970488)), new ULong_init(new Kotlin.Long(-1091629340, -1084653625)), new ULong_init(new Kotlin.Long(1034457026, -958395405)), new ULong_init(new Kotlin.Long(-1828018395, -710438585)), new ULong_init(new Kotlin.Long(-536640913, 113926993)), new ULong_init(new Kotlin.Long(168717936, 338241895)), new ULong_init(new Kotlin.Long(1188179964, 666307205)), new ULong_init(new Kotlin.Long(1546045734, 773529912)), new ULong_init(new Kotlin.Long(1522805485, 1294757372)), new ULong_init(new Kotlin.Long(-1651133473, 1396182291)), new ULong_init(new Kotlin.Long(-1951439906, 1695183700)), new ULong_init(new Kotlin.Long(1014477480, 1986661051)), new ULong_init(new Kotlin.Long(1206759142, -2117940946)), new ULong_init(new Kotlin.Long(344077627, -1838011259)), new ULong_init(new Kotlin.Long(1290863460, -1564481375)), new ULong_init(new Kotlin.Long(-1136513023, -1474664885)), new ULong_init(new Kotlin.Long(-789014639, -1035236496)), new ULong_init(new Kotlin.Long(106217008, -949202525)), new ULong_init(new Kotlin.Long(-688958952, -778901479)), new ULong_init(new Kotlin.Long(1432725776, -694614492)), new ULong_init(new Kotlin.Long(1467031594, -200395387)), new ULong_init(new Kotlin.Long(851169720, 275423344)), new ULong_init(new Kotlin.Long(-1194143544, 430227734)), new ULong_init(new Kotlin.Long(1363258195, 506948616)), new ULong_init(new Kotlin.Long(-544281703, 659060556)), new ULong_init(new Kotlin.Long(-509917016, 883997877)), new ULong_init(new Kotlin.Long(-976659869, 958139571)), new ULong_init(new Kotlin.Long(-482243893, 1322822218)), new ULong_init(new Kotlin.Long(2003034995, 1537002063)), new ULong_init(new Kotlin.Long(-692930397, 1747873779)), new ULong_init(new Kotlin.Long(1575990012, 1955562222)), new ULong_init(new Kotlin.Long(1125592928, 2024104815)), new ULong_init(new Kotlin.Long(-1578062990, -2067236844)), new ULong_init(new Kotlin.Long(442776044, -1933114872)), new ULong_init(new Kotlin.Long(593698344, -1866530822)), new ULong_init(new Kotlin.Long(-561857047, -1538233109)), new ULong_init(new Kotlin.Long(-1295615723, -1090935817)), new ULong_init(new Kotlin.Long(-479046869, -965641998)), new ULong_init(new Kotlin.Long(-366583396, -903397682)), new ULong_init(new Kotlin.Long(566280711, -779700025)), new ULong_init(new Kotlin.Long(-840897762, -354779690)), new ULong_init(new Kotlin.Long(-294727304, -176337025)), new ULong_init(new Kotlin.Long(1914138554, 116418474)), new ULong_init(new Kotlin.Long(-1563912026, 174292421)), new ULong_init(new Kotlin.Long(-1090974290, 289380356)), new ULong_init(new Kotlin.Long(320620315, 460393269)), new ULong_init(new Kotlin.Long(587496836, 685471733)), new ULong_init(new Kotlin.Long(1086792851, 852142971)), new ULong_init(new Kotlin.Long(365543100, 1017036298)), new ULong_init(new Kotlin.Long(-1676669620, 1126000580)), new ULong_init(new Kotlin.Long(-885112138, 1288033470)), new ULong_init(new Kotlin.Long(-60457430, 1501505948)), new ULong_init(new Kotlin.Long(987167468, 1607167915)), new ULong_init(new Kotlin.Long(1246189591, 1816402316))];
|
||||
this.iv = [new ULong_init(new Kotlin.Long(-205731576, 1779033703)), new ULong_init(new Kotlin.Long(-2067093701, -1150833019)), new ULong_init(new Kotlin.Long(-23791573, 1013904242)), new ULong_init(new Kotlin.Long(1595750129, -1521486534)), new ULong_init(new Kotlin.Long(-1377402159, 1359893119)), new ULong_init(new Kotlin.Long(725511199, -1694144372)), new ULong_init(new Kotlin.Long(-79577749, 528734635)), new ULong_init(new Kotlin.Long(327033209, 1541459225))];
|
||||
}
|
||||
Sha512$Companion.$metadata$ = {
|
||||
kind: Kind_OBJECT,
|
||||
simpleName: 'Companion',
|
||||
interfaces: []
|
||||
};
|
||||
var Sha512$Companion_instance = null;
|
||||
function Sha512$Companion_getInstance() {
|
||||
if (Sha512$Companion_instance === null) {
|
||||
new Sha512$Companion();
|
||||
}
|
||||
return Sha512$Companion_instance;
|
||||
}
|
||||
Sha512.prototype.digest_ummv9a$ = function (message) {
|
||||
Sha512$Companion.prototype.digest_61zpoe$ = function (message) {
|
||||
var $receiver = encodeToByteArray(message);
|
||||
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));
|
||||
}
|
||||
return this.digest_ummv9a$(copyToArray(destination));
|
||||
};
|
||||
Sha512$Companion.prototype.digest_ummv9a$ = function (message) {
|
||||
var tmp$;
|
||||
var h0 = {v: new ULong_init(new Kotlin.Long(-205731576, 1779033703))};
|
||||
var h1 = {v: new ULong_init(new Kotlin.Long(-2067093701, -1150833019))};
|
||||
var h2 = {v: new ULong_init(new Kotlin.Long(-23791573, 1013904242))};
|
||||
var h3 = {v: new ULong_init(new Kotlin.Long(1595750129, -1521486534))};
|
||||
var h4 = {v: new ULong_init(new Kotlin.Long(-1377402159, 1359893119))};
|
||||
var h5 = {v: new ULong_init(new Kotlin.Long(725511199, -1694144372))};
|
||||
var h6 = {v: new ULong_init(new Kotlin.Long(-79577749, 528734635))};
|
||||
var h7 = {v: new ULong_init(new Kotlin.Long(327033209, 1541459225))};
|
||||
var originalMessageSizeInBits = message.length * 8 | 0;
|
||||
var expandedRemainderOf1024 = (originalMessageSizeInBits + 129 | 0) % 1024;
|
||||
if (expandedRemainderOf1024 === 0)
|
||||
@ -1288,19 +1109,19 @@
|
||||
var other_6 = w[i_2 - 7 | 0];
|
||||
w[i_2] = new ULong_init((new ULong_init($this_7.data.add(other_6.data))).data.add(s1.data));
|
||||
}
|
||||
var a = this.h0;
|
||||
var b = this.h1;
|
||||
var c = this.h2;
|
||||
var d = this.h3;
|
||||
var e = this.h4;
|
||||
var f = this.h5;
|
||||
var g = this.h6;
|
||||
var h = this.h7;
|
||||
var a = h0.v;
|
||||
var b = h1.v;
|
||||
var c = h2.v;
|
||||
var d = h3.v;
|
||||
var e = h4.v;
|
||||
var f = h5.v;
|
||||
var g = h6.v;
|
||||
var h = h7.v;
|
||||
for (var i_3 = 0; i_3 < 80; i_3++) {
|
||||
var s1_0 = this.compressionSigma1_0(e);
|
||||
var ch = this.ch_0(e, f, g);
|
||||
var $this_8 = new ULong_init((new ULong_init(h.data.add(s1_0.data))).data.add(ch.data));
|
||||
var other_7 = Sha512$Companion_getInstance().k[i_3];
|
||||
var other_7 = this.k[i_3];
|
||||
var $this_9 = new ULong_init($this_8.data.add(other_7.data));
|
||||
var other_8 = w[i_3];
|
||||
var temp1 = new ULong_init($this_9.data.add(other_8.data));
|
||||
@ -1316,101 +1137,90 @@
|
||||
b = a;
|
||||
a = new ULong_init(temp1.data.add(temp2.data));
|
||||
}
|
||||
var $this_10 = this.h0;
|
||||
var $this_10 = h0.v;
|
||||
var other_9 = a;
|
||||
this.h0 = new ULong_init($this_10.data.add(other_9.data));
|
||||
var $this_11 = this.h1;
|
||||
h0.v = new ULong_init($this_10.data.add(other_9.data));
|
||||
var $this_11 = h1.v;
|
||||
var other_10 = b;
|
||||
this.h1 = new ULong_init($this_11.data.add(other_10.data));
|
||||
var $this_12 = this.h2;
|
||||
h1.v = new ULong_init($this_11.data.add(other_10.data));
|
||||
var $this_12 = h2.v;
|
||||
var other_11 = c;
|
||||
this.h2 = new ULong_init($this_12.data.add(other_11.data));
|
||||
var $this_13 = this.h3;
|
||||
h2.v = new ULong_init($this_12.data.add(other_11.data));
|
||||
var $this_13 = h3.v;
|
||||
var other_12 = d;
|
||||
this.h3 = new ULong_init($this_13.data.add(other_12.data));
|
||||
var $this_14 = this.h4;
|
||||
h3.v = new ULong_init($this_13.data.add(other_12.data));
|
||||
var $this_14 = h4.v;
|
||||
var other_13 = e;
|
||||
this.h4 = new ULong_init($this_14.data.add(other_13.data));
|
||||
var $this_15 = this.h5;
|
||||
h4.v = new ULong_init($this_14.data.add(other_13.data));
|
||||
var $this_15 = h5.v;
|
||||
var other_14 = f;
|
||||
this.h5 = new ULong_init($this_15.data.add(other_14.data));
|
||||
var $this_16 = this.h6;
|
||||
h5.v = new ULong_init($this_15.data.add(other_14.data));
|
||||
var $this_16 = h6.v;
|
||||
var other_15 = g;
|
||||
this.h6 = new ULong_init($this_16.data.add(other_15.data));
|
||||
var $this_17 = this.h7;
|
||||
h6.v = new ULong_init($this_16.data.add(other_15.data));
|
||||
var $this_17 = h7.v;
|
||||
var other_16 = h;
|
||||
this.h7 = new ULong_init($this_17.data.add(other_16.data));
|
||||
h7.v = new ULong_init($this_17.data.add(other_16.data));
|
||||
}
|
||||
var $receiver_0 = this.toPaddedByteArray_0(this.h0);
|
||||
var elements_0 = this.toPaddedByteArray_0(this.h1);
|
||||
var $receiver_0 = this.toPaddedByteArray_0(h0.v);
|
||||
var elements_0 = this.toPaddedByteArray_0(h1.v);
|
||||
var $receiver_1 = $receiver_0.concat(elements_0);
|
||||
var elements_1 = this.toPaddedByteArray_0(this.h2);
|
||||
var elements_1 = this.toPaddedByteArray_0(h2.v);
|
||||
var $receiver_2 = $receiver_1.concat(elements_1);
|
||||
var elements_2 = this.toPaddedByteArray_0(this.h3);
|
||||
var elements_2 = this.toPaddedByteArray_0(h3.v);
|
||||
var $receiver_3 = $receiver_2.concat(elements_2);
|
||||
var elements_3 = this.toPaddedByteArray_0(this.h4);
|
||||
var elements_3 = this.toPaddedByteArray_0(h4.v);
|
||||
var $receiver_4 = $receiver_3.concat(elements_3);
|
||||
var elements_4 = this.toPaddedByteArray_0(this.h5);
|
||||
var elements_4 = this.toPaddedByteArray_0(h5.v);
|
||||
var $receiver_5 = $receiver_4.concat(elements_4);
|
||||
var elements_5 = this.toPaddedByteArray_0(this.h6);
|
||||
var elements_5 = this.toPaddedByteArray_0(h6.v);
|
||||
var $receiver_6 = $receiver_5.concat(elements_5);
|
||||
var elements_6 = this.toPaddedByteArray_0(this.h7);
|
||||
var elements_6 = this.toPaddedByteArray_0(h7.v);
|
||||
var digest = $receiver_6.concat(elements_6);
|
||||
this.reset_0();
|
||||
return digest;
|
||||
};
|
||||
Sha512.prototype.reset_0 = function () {
|
||||
this.h0 = new ULong_init(new Kotlin.Long(-205731576, 1779033703));
|
||||
this.h1 = new ULong_init(new Kotlin.Long(-2067093701, -1150833019));
|
||||
this.h2 = new ULong_init(new Kotlin.Long(-23791573, 1013904242));
|
||||
this.h3 = new ULong_init(new Kotlin.Long(1595750129, -1521486534));
|
||||
this.h4 = new ULong_init(new Kotlin.Long(-1377402159, 1359893119));
|
||||
this.h5 = new ULong_init(new Kotlin.Long(725511199, -1694144372));
|
||||
this.h6 = new ULong_init(new Kotlin.Long(-79577749, 528734635));
|
||||
this.h7 = new ULong_init(new Kotlin.Long(327033209, 1541459225));
|
||||
};
|
||||
Sha512.prototype.scheduleSigma0_0 = function (value) {
|
||||
Sha512$Companion.prototype.scheduleSigma0_0 = function (value) {
|
||||
var $this = rotateRight_0(value, 1);
|
||||
var other = rotateRight_0(value, 8);
|
||||
var tmp$ = new ULong_init($this.data.xor(other.data));
|
||||
var other_0 = new ULong_init(value.data.shiftRightUnsigned(7));
|
||||
return new ULong_init(tmp$.data.xor(other_0.data));
|
||||
};
|
||||
Sha512.prototype.scheduleSigma1_0 = function (value) {
|
||||
Sha512$Companion.prototype.scheduleSigma1_0 = function (value) {
|
||||
var $this = rotateRight_0(value, 19);
|
||||
var other = rotateRight_0(value, 61);
|
||||
var tmp$ = new ULong_init($this.data.xor(other.data));
|
||||
var other_0 = new ULong_init(value.data.shiftRightUnsigned(6));
|
||||
return new ULong_init(tmp$.data.xor(other_0.data));
|
||||
};
|
||||
Sha512.prototype.compressionSigma0_0 = function (e) {
|
||||
Sha512$Companion.prototype.compressionSigma0_0 = function (e) {
|
||||
var $this = rotateRight_0(e, 28);
|
||||
var other = rotateRight_0(e, 34);
|
||||
var $this_0 = new ULong_init($this.data.xor(other.data));
|
||||
var other_0 = rotateRight_0(e, 39);
|
||||
return new ULong_init($this_0.data.xor(other_0.data));
|
||||
};
|
||||
Sha512.prototype.compressionSigma1_0 = function (a) {
|
||||
Sha512$Companion.prototype.compressionSigma1_0 = function (a) {
|
||||
var $this = rotateRight_0(a, 14);
|
||||
var other = rotateRight_0(a, 18);
|
||||
var $this_0 = new ULong_init($this.data.xor(other.data));
|
||||
var other_0 = rotateRight_0(a, 41);
|
||||
return new ULong_init($this_0.data.xor(other_0.data));
|
||||
};
|
||||
Sha512.prototype.ch_0 = function (x, y, z) {
|
||||
Sha512$Companion.prototype.ch_0 = function (x, y, z) {
|
||||
var tmp$ = new ULong_init(x.data.and(y.data));
|
||||
var other = Sha512$Companion_getInstance().ULONG_MASK;
|
||||
var other = this.ULONG_MASK;
|
||||
var other_0 = new ULong_init((new ULong_init(x.data.xor(other.data))).data.and(z.data));
|
||||
return new ULong_init(tmp$.data.xor(other_0.data));
|
||||
};
|
||||
Sha512.prototype.maj_0 = function (x, y, z) {
|
||||
Sha512$Companion.prototype.maj_0 = function (x, y, z) {
|
||||
var tmp$ = new ULong_init(x.data.and(y.data));
|
||||
var other = new ULong_init(x.data.and(z.data));
|
||||
var tmp$_0 = new ULong_init(tmp$.data.xor(other.data));
|
||||
var other_0 = new ULong_init(y.data.and(z.data));
|
||||
return new ULong_init(tmp$_0.data.xor(other_0.data));
|
||||
};
|
||||
Sha512.prototype.toPaddedByteArray_0 = function ($receiver) {
|
||||
Sha512$Companion.prototype.toPaddedByteArray_0 = function ($receiver) {
|
||||
var byteMask = new ULong_init(Kotlin.Long.fromInt(255));
|
||||
var array = Array_0(8);
|
||||
var tmp$;
|
||||
@ -1452,7 +1262,7 @@
|
||||
}
|
||||
return array;
|
||||
};
|
||||
Sha512.prototype.toPadded128BitByteArray_0 = function ($receiver) {
|
||||
Sha512$Companion.prototype.toPadded128BitByteArray_0 = function ($receiver) {
|
||||
var byteMask = new ULong_init(Kotlin.Long.fromInt(255));
|
||||
var array = Array_0(16);
|
||||
var tmp$;
|
||||
@ -1494,15 +1304,30 @@
|
||||
}
|
||||
return array;
|
||||
};
|
||||
Sha512$Companion.$metadata$ = {
|
||||
kind: Kind_OBJECT,
|
||||
simpleName: 'Companion',
|
||||
interfaces: []
|
||||
};
|
||||
var Sha512$Companion_instance = null;
|
||||
function Sha512$Companion_getInstance() {
|
||||
if (Sha512$Companion_instance === null) {
|
||||
new Sha512$Companion();
|
||||
}
|
||||
return Sha512$Companion_instance;
|
||||
}
|
||||
Sha512.$metadata$ = {
|
||||
kind: Kind_CLASS,
|
||||
simpleName: 'Sha512',
|
||||
interfaces: []
|
||||
interfaces: [Hash]
|
||||
};
|
||||
var package$com = _.com || (_.com = {});
|
||||
var package$ionspin = package$com.ionspin || (package$com.ionspin = {});
|
||||
var package$kotlin = package$ionspin.kotlin || (package$ionspin.kotlin = {});
|
||||
var package$crypto = package$kotlin.crypto || (package$kotlin.crypto = {});
|
||||
Object.defineProperty(package$crypto, 'Config', {
|
||||
get: Config_getInstance
|
||||
});
|
||||
package$crypto.Hash = Hash;
|
||||
package$crypto.UpdateableHash = UpdateableHash;
|
||||
package$crypto.hexColumsPrint_mgx7ee$ = hexColumsPrint;
|
||||
@ -1528,6 +1353,6 @@
|
||||
package$sha.Sha512 = Sha512;
|
||||
Kotlin.defineModule('crypto-core', _);
|
||||
return _;
|
||||
}(module.exports, require('kotlin'), require('bignum'), require('kotlinx-coroutines-core')));
|
||||
}(module.exports, require('kotlin'), require('bignum')));
|
||||
|
||||
//# sourceMappingURL=crypto-core.js.map
|
||||
|
2
crypto-core/node_modules/crypto-core.js.map
generated
vendored
2
crypto-core/node_modules/crypto-core.js.map
generated
vendored
File diff suppressed because one or more lines are too long
2
crypto-core/node_modules/crypto-core.meta.js
generated
vendored
2
crypto-core/node_modules/crypto-core.meta.js
generated
vendored
@ -1 +1 @@
|
||||
// Kotlin.kotlin_module_metadata(393729, "crypto-core", "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");
|
||||
// Kotlin.kotlin_module_metadata(393729, "crypto-core", "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");
|
||||
|
BIN
crypto-core/node_modules/crypto-core/com/ionspin/kotlin/crypto/blake2b/blake2b.kjsm
generated
vendored
BIN
crypto-core/node_modules/crypto-core/com/ionspin/kotlin/crypto/blake2b/blake2b.kjsm
generated
vendored
Binary file not shown.
BIN
crypto-core/node_modules/crypto-core/com/ionspin/kotlin/crypto/crypto.kjsm
generated
vendored
BIN
crypto-core/node_modules/crypto-core/com/ionspin/kotlin/crypto/crypto.kjsm
generated
vendored
Binary file not shown.
BIN
crypto-core/node_modules/crypto-core/com/ionspin/kotlin/crypto/sha/sha.kjsm
generated
vendored
BIN
crypto-core/node_modules/crypto-core/com/ionspin/kotlin/crypto/sha/sha.kjsm
generated
vendored
Binary file not shown.
@ -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
|
||||
|
||||
/**
|
||||
* Created by Ugljesa Jovanovic
|
||||
* ugljesa.jovanovic@ionspin.com
|
||||
* on 20-Jul-2019
|
||||
*/
|
||||
object Config {
|
||||
const val DEBUG = false
|
||||
}
|
@ -28,7 +28,7 @@ import kotlinx.coroutines.Job
|
||||
* ugljesa.jovanovic@ionspin.com
|
||||
* on 14-Jul-2019
|
||||
*/
|
||||
@ExperimentalStdlibApi
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
class Blake2b(val key: Array<UByte>? = null, val hashLength: Int = 64) : UpdateableHash {
|
||||
companion object : Hash {
|
||||
@ -75,8 +75,6 @@ class Blake2b(val key: Array<UByte>? = null, val hashLength: Int = 64) : Updatea
|
||||
internal fun mixRound(input: Array<ULong>, message: Array<ULong>, round: Int): Array<ULong> {
|
||||
var v = input
|
||||
val selectedSigma = sigma[round % 10]
|
||||
val printout = v.map { it.toString(16) }.chunked(3)
|
||||
printout.forEach { println(it.joinToString(separator = " ") { it.toUpperCase() }) }
|
||||
v = mix(v, 0, 4, 8, 12, message[selectedSigma[0]], message[selectedSigma[1]])
|
||||
v = mix(v, 1, 5, 9, 13, message[selectedSigma[2]], message[selectedSigma[3]])
|
||||
v = mix(v, 2, 6, 10, 14, message[selectedSigma[4]], message[selectedSigma[5]])
|
||||
@ -120,11 +118,11 @@ class Blake2b(val key: Array<UByte>? = null, val hashLength: Int = 64) : Updatea
|
||||
acc[slot] = acc[slot] + (byte.toULong() shl ((position) * 8))
|
||||
acc
|
||||
}
|
||||
|
||||
println("m")
|
||||
val printout = m.map { it.toString(16) }.chunked(4)
|
||||
printout.forEach { println(it.joinToString(separator = " ") { it.toUpperCase() }) }
|
||||
println("Offset ${offsetCounter}")
|
||||
if (Config.DEBUG) {
|
||||
val printout = m.map { it.toString(16) }.chunked(4)
|
||||
printout.forEach { println(it.joinToString(separator = " ") { it.toUpperCase() }) }
|
||||
println("Offset ${offsetCounter}")
|
||||
}
|
||||
|
||||
v[12] = v[12] xor offsetCounter.ulongValue()
|
||||
v[13] = v[13] xor (offsetCounter shr BITS_IN_WORD).ulongValue()
|
||||
@ -144,7 +142,7 @@ class Blake2b(val key: Array<UByte>? = null, val hashLength: Int = 64) : Updatea
|
||||
return h
|
||||
}
|
||||
|
||||
|
||||
@ExperimentalStdlibApi
|
||||
fun digest(inputString: String, key: String? = null): Array<UByte> {
|
||||
val chunked = inputString.encodeToByteArray().map { it.toUByte() }.toList().chunked(BLOCK_BYTES)
|
||||
.map { it.toTypedArray() }.toTypedArray()
|
||||
@ -239,7 +237,7 @@ class Blake2b(val key: Array<UByte>? = null, val hashLength: Int = 64) : Updatea
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ExperimentalStdlibApi
|
||||
constructor(
|
||||
key: String?,
|
||||
requestedHashLenght: Int = 64
|
||||
@ -248,10 +246,6 @@ class Blake2b(val key: Array<UByte>? = null, val hashLength: Int = 64) : Updatea
|
||||
requestedHashLenght
|
||||
)
|
||||
|
||||
var job = Job()
|
||||
val scope = CoroutineScope(Dispatchers.Default + job)
|
||||
|
||||
|
||||
var h = iv.copyOf()
|
||||
var counter = BigInteger.ZERO
|
||||
var bufferCounter = 0
|
||||
@ -306,7 +300,7 @@ class Blake2b(val key: Array<UByte>? = null, val hashLength: Int = 64) : Updatea
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ExperimentalStdlibApi
|
||||
fun update(input: String) {
|
||||
update(input.encodeToByteArray().map { it.toUByte() }.toTypedArray())
|
||||
}
|
||||
@ -326,7 +320,7 @@ class Blake2b(val key: Array<UByte>? = null, val hashLength: Int = 64) : Updatea
|
||||
compress(h, lastBlockPadded, counter, true)
|
||||
|
||||
val result = formatResult(h)
|
||||
println(result.map { it.toString(16) }.joinToString(separator = ""))
|
||||
reset()
|
||||
return result
|
||||
|
||||
}
|
||||
@ -335,6 +329,13 @@ class Blake2b(val key: Array<UByte>? = null, val hashLength: Int = 64) : Updatea
|
||||
return digest().map { it.toString(16) }.joinToString(separator = "")
|
||||
}
|
||||
|
||||
private fun reset() {
|
||||
h = iv.copyOf()
|
||||
counter = BigInteger.ZERO
|
||||
bufferCounter = 0
|
||||
buffer = Array<UByte>(BLOCK_BYTES) { 0U }
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
package com.ionspin.kotlin.crypto.sha
|
||||
|
||||
import com.ionspin.kotlin.crypto.Hash
|
||||
import com.ionspin.kotlin.crypto.chunked
|
||||
import com.ionspin.kotlin.crypto.rotateRight
|
||||
|
||||
@ -26,8 +27,10 @@ import com.ionspin.kotlin.crypto.rotateRight
|
||||
* on 17-Jul-2019
|
||||
*/
|
||||
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
class Sha256() {
|
||||
class Sha256() : Hash {
|
||||
|
||||
companion object {
|
||||
const val BLOCK_SIZE = 512
|
||||
const val W_SIZE = 64
|
||||
@ -35,181 +38,185 @@ class Sha256() {
|
||||
const val BYTE_MASK_FROM_ULONG = 0xFFUL
|
||||
const val BYTE_MASK_FROM_UINT = 0xFFU
|
||||
|
||||
}
|
||||
val iv = arrayOf(
|
||||
0x6a09e667U,
|
||||
0xbb67ae85U,
|
||||
0x3c6ef372U,
|
||||
0xa54ff53aU,
|
||||
0x510e527fU,
|
||||
0x9b05688cU,
|
||||
0x1f83d9abU,
|
||||
0x5be0cd19U
|
||||
)
|
||||
|
||||
var h0 = 0x6a09e667U
|
||||
var h1 = 0xbb67ae85U
|
||||
var h2 = 0x3c6ef372U
|
||||
var h3 = 0xa54ff53aU
|
||||
var h4 = 0x510e527fU
|
||||
var h5 = 0x9b05688cU
|
||||
var h6 = 0x1f83d9abU
|
||||
var h7 = 0x5be0cd19U
|
||||
val k = arrayOf(
|
||||
0x428a2f98U, 0x71374491U, 0xb5c0fbcfU, 0xe9b5dba5U, 0x3956c25bU, 0x59f111f1U, 0x923f82a4U, 0xab1c5ed5U,
|
||||
0xd807aa98U, 0x12835b01U, 0x243185beU, 0x550c7dc3U, 0x72be5d74U, 0x80deb1feU, 0x9bdc06a7U, 0xc19bf174U,
|
||||
0xe49b69c1U, 0xefbe4786U, 0x0fc19dc6U, 0x240ca1ccU, 0x2de92c6fU, 0x4a7484aaU, 0x5cb0a9dcU, 0x76f988daU,
|
||||
0x983e5152U, 0xa831c66dU, 0xb00327c8U, 0xbf597fc7U, 0xc6e00bf3U, 0xd5a79147U, 0x06ca6351U, 0x14292967U,
|
||||
0x27b70a85U, 0x2e1b2138U, 0x4d2c6dfcU, 0x53380d13U, 0x650a7354U, 0x766a0abbU, 0x81c2c92eU, 0x92722c85U,
|
||||
0xa2bfe8a1U, 0xa81a664bU, 0xc24b8b70U, 0xc76c51a3U, 0xd192e819U, 0xd6990624U, 0xf40e3585U, 0x106aa070U,
|
||||
0x19a4c116U, 0x1e376c08U, 0x2748774cU, 0x34b0bcb5U, 0x391c0cb3U, 0x4ed8aa4aU, 0x5b9cca4fU, 0x682e6ff3U,
|
||||
0x748f82eeU, 0x78a5636fU, 0x84c87814U, 0x8cc70208U, 0x90befffaU, 0xa4506cebU, 0xbef9a3f7U, 0xc67178f2U
|
||||
)
|
||||
|
||||
val k = arrayOf(
|
||||
0x428a2f98U, 0x71374491U, 0xb5c0fbcfU, 0xe9b5dba5U, 0x3956c25bU, 0x59f111f1U, 0x923f82a4U, 0xab1c5ed5U,
|
||||
0xd807aa98U, 0x12835b01U, 0x243185beU, 0x550c7dc3U, 0x72be5d74U, 0x80deb1feU, 0x9bdc06a7U, 0xc19bf174U,
|
||||
0xe49b69c1U, 0xefbe4786U, 0x0fc19dc6U, 0x240ca1ccU, 0x2de92c6fU, 0x4a7484aaU, 0x5cb0a9dcU, 0x76f988daU,
|
||||
0x983e5152U, 0xa831c66dU, 0xb00327c8U, 0xbf597fc7U, 0xc6e00bf3U, 0xd5a79147U, 0x06ca6351U, 0x14292967U,
|
||||
0x27b70a85U, 0x2e1b2138U, 0x4d2c6dfcU, 0x53380d13U, 0x650a7354U, 0x766a0abbU, 0x81c2c92eU, 0x92722c85U,
|
||||
0xa2bfe8a1U, 0xa81a664bU, 0xc24b8b70U, 0xc76c51a3U, 0xd192e819U, 0xd6990624U, 0xf40e3585U, 0x106aa070U,
|
||||
0x19a4c116U, 0x1e376c08U, 0x2748774cU, 0x34b0bcb5U, 0x391c0cb3U, 0x4ed8aa4aU, 0x5b9cca4fU, 0x682e6ff3U,
|
||||
0x748f82eeU, 0x78a5636fU, 0x84c87814U, 0x8cc70208U, 0x90befffaU, 0xa4506cebU, 0xbef9a3f7U, 0xc67178f2U
|
||||
)
|
||||
|
||||
fun digest(message: Array<UByte>) : Array<UByte> {
|
||||
|
||||
val originalMessageSizeInBits = message.size * 8
|
||||
|
||||
|
||||
//K such that L + 1 + K + 64 is a multiple of 512
|
||||
val expandedRemainderOf512 = (originalMessageSizeInBits + 65) % BLOCK_SIZE
|
||||
val zeroAddAmount = when (expandedRemainderOf512) {
|
||||
0 -> 0
|
||||
else -> (BLOCK_SIZE - expandedRemainderOf512) / 8
|
||||
@ExperimentalStdlibApi
|
||||
fun digest(message : String) : Array<UByte> {
|
||||
return digest(message.encodeToByteArray().map { it.toUByte() }.toTypedArray())
|
||||
}
|
||||
val expansionArray = Array<UByte>(zeroAddAmount + 1) {
|
||||
when (it) {
|
||||
0 -> 0b10000000U //TODO This wont work if there the byte needs to be shared with the L (length) ULong
|
||||
else -> 0U
|
||||
|
||||
fun digest(message: Array<UByte>) : Array<UByte> {
|
||||
|
||||
var h0 = 0x6a09e667U
|
||||
var h1 = 0xbb67ae85U
|
||||
var h2 = 0x3c6ef372U
|
||||
var h3 = 0xa54ff53aU
|
||||
var h4 = 0x510e527fU
|
||||
var h5 = 0x9b05688cU
|
||||
var h6 = 0x1f83d9abU
|
||||
var h7 = 0x5be0cd19U
|
||||
|
||||
val originalMessageSizeInBits = message.size * 8
|
||||
|
||||
|
||||
//K such that L + 1 + K + 64 is a multiple of 512
|
||||
val expandedRemainderOf512 = (originalMessageSizeInBits + 65) % BLOCK_SIZE
|
||||
val zeroAddAmount = when (expandedRemainderOf512) {
|
||||
0 -> 0
|
||||
else -> (BLOCK_SIZE - expandedRemainderOf512) / 8
|
||||
}
|
||||
}
|
||||
|
||||
val chunks = (message + expansionArray + originalMessageSizeInBits.toULong().toPaddedByteArray()).chunked(64)
|
||||
|
||||
chunks.forEach { chunk ->
|
||||
val w = Array<UInt>(W_SIZE) {
|
||||
val expansionArray = Array<UByte>(zeroAddAmount + 1) {
|
||||
when (it) {
|
||||
in 0 until 16 -> {
|
||||
var collected = (chunk[(it * 4)].toUInt() shl 24) +
|
||||
(chunk[(it * 4) + 1].toUInt() shl 16 ) +
|
||||
(chunk[(it * 4) + 2].toUInt() shl 8 ) +
|
||||
(chunk[(it * 4) + 3].toUInt())
|
||||
collected
|
||||
}
|
||||
0 -> 0b10000000U //TODO This wont work if there the byte needs to be shared with the L (length) ULong
|
||||
else -> 0U
|
||||
}
|
||||
}
|
||||
for (i in 16 until W_SIZE) {
|
||||
val s0 = scheduleSigma0(w[i - 15])
|
||||
val s1 = scheduleSigma1(w[i - 2])
|
||||
w[i] = w[i-16] + s0 + w[i - 7] + s1
|
||||
|
||||
val chunks = (message + expansionArray + originalMessageSizeInBits.toULong().toPaddedByteArray()).chunked(64)
|
||||
|
||||
chunks.forEach { chunk ->
|
||||
val w = Array<UInt>(W_SIZE) {
|
||||
when (it) {
|
||||
in 0 until 16 -> {
|
||||
var collected = (chunk[(it * 4)].toUInt() shl 24) +
|
||||
(chunk[(it * 4) + 1].toUInt() shl 16 ) +
|
||||
(chunk[(it * 4) + 2].toUInt() shl 8 ) +
|
||||
(chunk[(it * 4) + 3].toUInt())
|
||||
collected
|
||||
}
|
||||
else -> 0U
|
||||
}
|
||||
}
|
||||
for (i in 16 until W_SIZE) {
|
||||
val s0 = scheduleSigma0(w[i - 15])
|
||||
val s1 = scheduleSigma1(w[i - 2])
|
||||
w[i] = w[i-16] + s0 + w[i - 7] + s1
|
||||
}
|
||||
|
||||
var a = h0
|
||||
var b = h1
|
||||
var c = h2
|
||||
var d = h3
|
||||
var e = h4
|
||||
var f = h5
|
||||
var g = h6
|
||||
var h = h7
|
||||
|
||||
for (i in 0 until W_SIZE) {
|
||||
val s1 = compressionSigma1(e)
|
||||
val ch = ch(e, f, g)
|
||||
val temp1 = h + s1 + ch + k[i] + w[i]
|
||||
val s0 = compressionSigma0(a)
|
||||
val maj = maj(a,b,c)
|
||||
val temp2 = s0 + maj
|
||||
h = g
|
||||
g = f
|
||||
f = e
|
||||
e = d + temp1
|
||||
d = c
|
||||
c = b
|
||||
b = a
|
||||
a = temp1 + temp2
|
||||
}
|
||||
|
||||
h0 += a
|
||||
h1 += b
|
||||
h2 += c
|
||||
h3 += d
|
||||
h4 += e
|
||||
h5 += f
|
||||
h6 += g
|
||||
h7 += h
|
||||
|
||||
}
|
||||
|
||||
var a = h0
|
||||
var b = h1
|
||||
var c = h2
|
||||
var d = h3
|
||||
var e = h4
|
||||
var f = h5
|
||||
var g = h6
|
||||
var h = h7
|
||||
|
||||
for (i in 0 until W_SIZE) {
|
||||
val s1 = compressionSigma1(e)
|
||||
val ch = ch(e, f, g)
|
||||
val temp1 = h + s1 + ch + k[i] + w[i]
|
||||
val s0 = compressionSigma0(a)
|
||||
val maj = maj(a,b,c)
|
||||
val temp2 = s0 + maj
|
||||
h = g
|
||||
g = f
|
||||
f = e
|
||||
e = d + temp1
|
||||
d = c
|
||||
c = b
|
||||
b = a
|
||||
a = temp1 + temp2
|
||||
}
|
||||
|
||||
h0 += a
|
||||
h1 += b
|
||||
h2 += c
|
||||
h3 += d
|
||||
h4 += e
|
||||
h5 += f
|
||||
h6 += g
|
||||
h7 += h
|
||||
|
||||
val digest = h0.toPaddedByteArray() +
|
||||
h1.toPaddedByteArray() +
|
||||
h2.toPaddedByteArray() +
|
||||
h3.toPaddedByteArray() +
|
||||
h4.toPaddedByteArray() +
|
||||
h5.toPaddedByteArray() +
|
||||
h6.toPaddedByteArray() +
|
||||
h7.toPaddedByteArray()
|
||||
return digest
|
||||
}
|
||||
|
||||
val digest = h0.toPaddedByteArray() +
|
||||
h1.toPaddedByteArray() +
|
||||
h2.toPaddedByteArray() +
|
||||
h3.toPaddedByteArray() +
|
||||
h4.toPaddedByteArray() +
|
||||
h5.toPaddedByteArray() +
|
||||
h6.toPaddedByteArray() +
|
||||
h7.toPaddedByteArray()
|
||||
reset()
|
||||
return digest
|
||||
}
|
||||
private fun scheduleSigma0(value: UInt): UInt {
|
||||
return value.rotateRight(7) xor value.rotateRight(18) xor (value shr 3)
|
||||
}
|
||||
|
||||
private fun reset() {
|
||||
h0 = 0x6a09e667U
|
||||
h1 = 0xbb67ae85U
|
||||
h2 = 0x3c6ef372U
|
||||
h3 = 0xa54ff53aU
|
||||
h4 = 0x510e527fU
|
||||
h5 = 0x9b05688cU
|
||||
h6 = 0x1f83d9abU
|
||||
h7 = 0x5be0cd19U
|
||||
}
|
||||
private fun scheduleSigma1(value : UInt) : UInt {
|
||||
return value.rotateRight(17) xor value.rotateRight(19) xor (value shr 10)
|
||||
}
|
||||
|
||||
private fun scheduleSigma0(value: UInt): UInt {
|
||||
return value.rotateRight(7) xor value.rotateRight(18) xor (value shr 3)
|
||||
}
|
||||
private fun compressionSigma0(a : UInt) : UInt {
|
||||
return (a rotateRight 2) xor (a rotateRight 13) xor (a rotateRight 22)
|
||||
}
|
||||
|
||||
private fun scheduleSigma1(value : UInt) : UInt {
|
||||
return value.rotateRight(17) xor value.rotateRight(19) xor (value shr 10)
|
||||
}
|
||||
private fun compressionSigma1(e : UInt) : UInt {
|
||||
return (e rotateRight 6) xor (e rotateRight 11) xor (e rotateRight 25)
|
||||
}
|
||||
|
||||
private fun compressionSigma0(a : UInt) : UInt {
|
||||
return (a rotateRight 2) xor (a rotateRight 13) xor (a rotateRight 22)
|
||||
}
|
||||
private fun ch(x : UInt, y : UInt, z : UInt) : UInt {
|
||||
return ((x and y) xor ((x xor UINT_MASK) and z))
|
||||
}
|
||||
|
||||
private fun compressionSigma1(e : UInt) : UInt {
|
||||
return (e rotateRight 6) xor (e rotateRight 11) xor (e rotateRight 25)
|
||||
}
|
||||
private fun maj(x : UInt, y : UInt, z : UInt) : UInt {
|
||||
return (((x and y) xor (x and z) xor (y and z)))
|
||||
}
|
||||
|
||||
private fun ch(x : UInt, y : UInt, z : UInt) : UInt {
|
||||
return ((x and y) xor ((x xor UINT_MASK) and z))
|
||||
}
|
||||
|
||||
private fun maj(x : UInt, y : UInt, z : UInt) : UInt {
|
||||
return (((x and y) xor (x and z) xor (y and z)))
|
||||
}
|
||||
|
||||
|
||||
|
||||
private fun ULong.toPaddedByteArray(): Array<UByte> {
|
||||
val byteMask = BYTE_MASK_FROM_ULONG
|
||||
return Array(8) {
|
||||
when (it) {
|
||||
7 -> (this and byteMask).toUByte()
|
||||
6 -> ((this shr 8) and byteMask).toUByte()
|
||||
5 -> ((this shr 16) and byteMask).toUByte()
|
||||
4 -> ((this shr 24) and byteMask).toUByte()
|
||||
3 -> ((this shr 32) and byteMask).toUByte()
|
||||
2 -> ((this shr 40) and byteMask).toUByte()
|
||||
1 -> ((this shr 48) and byteMask).toUByte()
|
||||
0 -> ((this shr 54) and byteMask).toUByte()
|
||||
else -> throw RuntimeException("Invalid conversion")
|
||||
private fun ULong.toPaddedByteArray(): Array<UByte> {
|
||||
val byteMask = BYTE_MASK_FROM_ULONG
|
||||
return Array(8) {
|
||||
when (it) {
|
||||
7 -> (this and byteMask).toUByte()
|
||||
6 -> ((this shr 8) and byteMask).toUByte()
|
||||
5 -> ((this shr 16) and byteMask).toUByte()
|
||||
4 -> ((this shr 24) and byteMask).toUByte()
|
||||
3 -> ((this shr 32) and byteMask).toUByte()
|
||||
2 -> ((this shr 40) and byteMask).toUByte()
|
||||
1 -> ((this shr 48) and byteMask).toUByte()
|
||||
0 -> ((this shr 54) and byteMask).toUByte()
|
||||
else -> throw RuntimeException("Invalid conversion")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun UInt.toPaddedByteArray(): Array<UByte> {
|
||||
val byteMask = BYTE_MASK_FROM_UINT
|
||||
return Array(4) {
|
||||
when (it) {
|
||||
3 -> (this and byteMask).toUByte()
|
||||
2 -> ((this shr 8) and byteMask).toUByte()
|
||||
1 -> ((this shr 16) and byteMask).toUByte()
|
||||
0 -> ((this shr 24) and byteMask).toUByte()
|
||||
else -> throw RuntimeException("Invalid conversion")
|
||||
private fun UInt.toPaddedByteArray(): Array<UByte> {
|
||||
val byteMask = BYTE_MASK_FROM_UINT
|
||||
return Array(4) {
|
||||
when (it) {
|
||||
3 -> (this and byteMask).toUByte()
|
||||
2 -> ((this shr 8) and byteMask).toUByte()
|
||||
1 -> ((this shr 16) and byteMask).toUByte()
|
||||
0 -> ((this shr 24) and byteMask).toUByte()
|
||||
else -> throw RuntimeException("Invalid conversion")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -217,4 +224,6 @@ class Sha256() {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -16,6 +16,7 @@
|
||||
|
||||
package com.ionspin.kotlin.crypto.sha
|
||||
|
||||
import com.ionspin.kotlin.crypto.Hash
|
||||
import com.ionspin.kotlin.crypto.chunked
|
||||
import com.ionspin.kotlin.crypto.rotateRight
|
||||
|
||||
@ -26,206 +27,272 @@ import com.ionspin.kotlin.crypto.rotateRight
|
||||
*/
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
class Sha512 {
|
||||
class Sha512 : Hash {
|
||||
companion object {
|
||||
const val BLOCK_SIZE = 1024
|
||||
const val ULONG_MASK = 0xFFFFFFFFFFFFFFFFUL
|
||||
|
||||
val k = arrayOf(
|
||||
0x428a2f98d728ae22UL, 0x7137449123ef65cdUL, 0xb5c0fbcfec4d3b2fUL, 0xe9b5dba58189dbbcUL, 0x3956c25bf348b538UL,
|
||||
0x59f111f1b605d019UL, 0x923f82a4af194f9bUL, 0xab1c5ed5da6d8118UL, 0xd807aa98a3030242UL, 0x12835b0145706fbeUL,
|
||||
0x243185be4ee4b28cUL, 0x550c7dc3d5ffb4e2UL, 0x72be5d74f27b896fUL, 0x80deb1fe3b1696b1UL, 0x9bdc06a725c71235UL,
|
||||
0xc19bf174cf692694UL, 0xe49b69c19ef14ad2UL, 0xefbe4786384f25e3UL, 0x0fc19dc68b8cd5b5UL, 0x240ca1cc77ac9c65UL,
|
||||
0x2de92c6f592b0275UL, 0x4a7484aa6ea6e483UL, 0x5cb0a9dcbd41fbd4UL, 0x76f988da831153b5UL, 0x983e5152ee66dfabUL,
|
||||
0xa831c66d2db43210UL, 0xb00327c898fb213fUL, 0xbf597fc7beef0ee4UL, 0xc6e00bf33da88fc2UL, 0xd5a79147930aa725UL,
|
||||
0x06ca6351e003826fUL, 0x142929670a0e6e70UL, 0x27b70a8546d22ffcUL, 0x2e1b21385c26c926UL, 0x4d2c6dfc5ac42aedUL,
|
||||
0x53380d139d95b3dfUL, 0x650a73548baf63deUL, 0x766a0abb3c77b2a8UL, 0x81c2c92e47edaee6UL, 0x92722c851482353bUL,
|
||||
0xa2bfe8a14cf10364UL, 0xa81a664bbc423001UL, 0xc24b8b70d0f89791UL, 0xc76c51a30654be30UL, 0xd192e819d6ef5218UL,
|
||||
0xd69906245565a910UL, 0xf40e35855771202aUL, 0x106aa07032bbd1b8UL, 0x19a4c116b8d2d0c8UL, 0x1e376c085141ab53UL,
|
||||
0x2748774cdf8eeb99UL, 0x34b0bcb5e19b48a8UL, 0x391c0cb3c5c95a63UL, 0x4ed8aa4ae3418acbUL, 0x5b9cca4f7763e373UL,
|
||||
0x682e6ff3d6b2b8a3UL, 0x748f82ee5defb2fcUL, 0x78a5636f43172f60UL, 0x84c87814a1f0ab72UL, 0x8cc702081a6439ecUL,
|
||||
0x90befffa23631e28UL, 0xa4506cebde82bde9UL, 0xbef9a3f7b2c67915UL, 0xc67178f2e372532bUL, 0xca273eceea26619cUL,
|
||||
0xd186b8c721c0c207UL, 0xeada7dd6cde0eb1eUL, 0xf57d4f7fee6ed178UL, 0x06f067aa72176fbaUL, 0x0a637dc5a2c898a6UL,
|
||||
0x113f9804bef90daeUL, 0x1b710b35131c471bUL, 0x28db77f523047d84UL, 0x32caab7b40c72493UL, 0x3c9ebe0a15c9bebcUL,
|
||||
0x431d67c49c100d4cUL, 0x4cc5d4becb3e42b6UL, 0x597f299cfc657e2aUL, 0x5fcb6fab3ad6faecUL, 0x6c44198c4a475817UL
|
||||
0x428a2f98d728ae22UL,
|
||||
0x7137449123ef65cdUL,
|
||||
0xb5c0fbcfec4d3b2fUL,
|
||||
0xe9b5dba58189dbbcUL,
|
||||
0x3956c25bf348b538UL,
|
||||
0x59f111f1b605d019UL,
|
||||
0x923f82a4af194f9bUL,
|
||||
0xab1c5ed5da6d8118UL,
|
||||
0xd807aa98a3030242UL,
|
||||
0x12835b0145706fbeUL,
|
||||
0x243185be4ee4b28cUL,
|
||||
0x550c7dc3d5ffb4e2UL,
|
||||
0x72be5d74f27b896fUL,
|
||||
0x80deb1fe3b1696b1UL,
|
||||
0x9bdc06a725c71235UL,
|
||||
0xc19bf174cf692694UL,
|
||||
0xe49b69c19ef14ad2UL,
|
||||
0xefbe4786384f25e3UL,
|
||||
0x0fc19dc68b8cd5b5UL,
|
||||
0x240ca1cc77ac9c65UL,
|
||||
0x2de92c6f592b0275UL,
|
||||
0x4a7484aa6ea6e483UL,
|
||||
0x5cb0a9dcbd41fbd4UL,
|
||||
0x76f988da831153b5UL,
|
||||
0x983e5152ee66dfabUL,
|
||||
0xa831c66d2db43210UL,
|
||||
0xb00327c898fb213fUL,
|
||||
0xbf597fc7beef0ee4UL,
|
||||
0xc6e00bf33da88fc2UL,
|
||||
0xd5a79147930aa725UL,
|
||||
0x06ca6351e003826fUL,
|
||||
0x142929670a0e6e70UL,
|
||||
0x27b70a8546d22ffcUL,
|
||||
0x2e1b21385c26c926UL,
|
||||
0x4d2c6dfc5ac42aedUL,
|
||||
0x53380d139d95b3dfUL,
|
||||
0x650a73548baf63deUL,
|
||||
0x766a0abb3c77b2a8UL,
|
||||
0x81c2c92e47edaee6UL,
|
||||
0x92722c851482353bUL,
|
||||
0xa2bfe8a14cf10364UL,
|
||||
0xa81a664bbc423001UL,
|
||||
0xc24b8b70d0f89791UL,
|
||||
0xc76c51a30654be30UL,
|
||||
0xd192e819d6ef5218UL,
|
||||
0xd69906245565a910UL,
|
||||
0xf40e35855771202aUL,
|
||||
0x106aa07032bbd1b8UL,
|
||||
0x19a4c116b8d2d0c8UL,
|
||||
0x1e376c085141ab53UL,
|
||||
0x2748774cdf8eeb99UL,
|
||||
0x34b0bcb5e19b48a8UL,
|
||||
0x391c0cb3c5c95a63UL,
|
||||
0x4ed8aa4ae3418acbUL,
|
||||
0x5b9cca4f7763e373UL,
|
||||
0x682e6ff3d6b2b8a3UL,
|
||||
0x748f82ee5defb2fcUL,
|
||||
0x78a5636f43172f60UL,
|
||||
0x84c87814a1f0ab72UL,
|
||||
0x8cc702081a6439ecUL,
|
||||
0x90befffa23631e28UL,
|
||||
0xa4506cebde82bde9UL,
|
||||
0xbef9a3f7b2c67915UL,
|
||||
0xc67178f2e372532bUL,
|
||||
0xca273eceea26619cUL,
|
||||
0xd186b8c721c0c207UL,
|
||||
0xeada7dd6cde0eb1eUL,
|
||||
0xf57d4f7fee6ed178UL,
|
||||
0x06f067aa72176fbaUL,
|
||||
0x0a637dc5a2c898a6UL,
|
||||
0x113f9804bef90daeUL,
|
||||
0x1b710b35131c471bUL,
|
||||
0x28db77f523047d84UL,
|
||||
0x32caab7b40c72493UL,
|
||||
0x3c9ebe0a15c9bebcUL,
|
||||
0x431d67c49c100d4cUL,
|
||||
0x4cc5d4becb3e42b6UL,
|
||||
0x597f299cfc657e2aUL,
|
||||
0x5fcb6fab3ad6faecUL,
|
||||
0x6c44198c4a475817UL
|
||||
)
|
||||
}
|
||||
|
||||
var h0 = 0x6a09e667f3bcc908UL
|
||||
var h1 = 0xbb67ae8584caa73bUL
|
||||
var h2 = 0x3c6ef372fe94f82bUL
|
||||
var h3 = 0xa54ff53a5f1d36f1UL
|
||||
var h4 = 0x510e527fade682d1UL
|
||||
var h5 = 0x9b05688c2b3e6c1fUL
|
||||
var h6 = 0x1f83d9abfb41bd6bUL
|
||||
var h7 = 0x5be0cd19137e2179UL
|
||||
|
||||
val iv = arrayOf(
|
||||
0x6a09e667f3bcc908UL,
|
||||
0xbb67ae8584caa73bUL,
|
||||
0x3c6ef372fe94f82bUL,
|
||||
0xa54ff53a5f1d36f1UL,
|
||||
0x510e527fade682d1UL,
|
||||
0x9b05688c2b3e6c1fUL,
|
||||
0x1f83d9abfb41bd6bUL,
|
||||
0x5be0cd19137e2179UL
|
||||
)
|
||||
|
||||
|
||||
|
||||
fun digest(message: Array<UByte>) : Array<UByte> {
|
||||
|
||||
val originalMessageSizeInBits = message.size * 8
|
||||
|
||||
|
||||
//K such that L + 1 + K + 64 is a multiple of 512
|
||||
val expandedRemainderOf1024 = (originalMessageSizeInBits + 129) % BLOCK_SIZE
|
||||
val zeroAddAmount = when (expandedRemainderOf1024) {
|
||||
0 -> 0
|
||||
else -> (BLOCK_SIZE - expandedRemainderOf1024) / 8
|
||||
@ExperimentalStdlibApi
|
||||
fun digest(message: String): Array<UByte> {
|
||||
return digest(message.encodeToByteArray().map { it.toUByte() }.toTypedArray())
|
||||
}
|
||||
val expansionArray = Array<UByte>(zeroAddAmount + 1) {
|
||||
when (it) {
|
||||
0 -> 0b10000000U //TODO This wont work if there the byte needs to be shared with the L (length) ULong
|
||||
else -> 0U
|
||||
|
||||
fun digest(message: Array<UByte>): Array<UByte> {
|
||||
|
||||
var h0 = 0x6a09e667f3bcc908UL
|
||||
var h1 = 0xbb67ae8584caa73bUL
|
||||
var h2 = 0x3c6ef372fe94f82bUL
|
||||
var h3 = 0xa54ff53a5f1d36f1UL
|
||||
var h4 = 0x510e527fade682d1UL
|
||||
var h5 = 0x9b05688c2b3e6c1fUL
|
||||
var h6 = 0x1f83d9abfb41bd6bUL
|
||||
var h7 = 0x5be0cd19137e2179UL
|
||||
|
||||
val originalMessageSizeInBits = message.size * 8
|
||||
|
||||
|
||||
//K such that L + 1 + K + 64 is a multiple of 512
|
||||
val expandedRemainderOf1024 = (originalMessageSizeInBits + 129) % BLOCK_SIZE
|
||||
val zeroAddAmount = when (expandedRemainderOf1024) {
|
||||
0 -> 0
|
||||
else -> (BLOCK_SIZE - expandedRemainderOf1024) / 8
|
||||
}
|
||||
}
|
||||
|
||||
val chunks = (message + expansionArray + originalMessageSizeInBits.toULong().toPadded128BitByteArray()).chunked(128)
|
||||
|
||||
chunks.forEach { chunk ->
|
||||
val w = Array<ULong>(80) {
|
||||
val expansionArray = Array<UByte>(zeroAddAmount + 1) {
|
||||
when (it) {
|
||||
in 0 until 16 -> {
|
||||
var collected = (chunk[(it * 8)].toULong() shl 56) +
|
||||
(chunk[(it * 8) + 1].toULong() shl 48 ) +
|
||||
(chunk[(it * 8) + 2].toULong() shl 40 ) +
|
||||
(chunk[(it * 8) + 3].toULong() shl 32 ) +
|
||||
(chunk[(it * 8) + 4].toULong() shl 24 ) +
|
||||
(chunk[(it * 8) + 5].toULong() shl 16 ) +
|
||||
(chunk[(it * 8) + 6].toULong() shl 8 ) +
|
||||
(chunk[(it * 8) + 7].toULong())
|
||||
collected
|
||||
}
|
||||
else -> 0UL
|
||||
0 -> 0b10000000U //TODO This wont work if there the byte needs to be shared with the L (length) ULong
|
||||
else -> 0U
|
||||
}
|
||||
}
|
||||
for (i in 16 until 80) {
|
||||
val s0 = scheduleSigma0(w[i - 15])
|
||||
val s1 = scheduleSigma1(w[i - 2])
|
||||
w[i] = w[i-16] + s0 + w[i - 7] + s1
|
||||
|
||||
val chunks =
|
||||
(message + expansionArray + originalMessageSizeInBits.toULong().toPadded128BitByteArray()).chunked(128)
|
||||
|
||||
chunks.forEach { chunk ->
|
||||
val w = Array<ULong>(80) {
|
||||
when (it) {
|
||||
in 0 until 16 -> {
|
||||
var collected = (chunk[(it * 8)].toULong() shl 56) +
|
||||
(chunk[(it * 8) + 1].toULong() shl 48) +
|
||||
(chunk[(it * 8) + 2].toULong() shl 40) +
|
||||
(chunk[(it * 8) + 3].toULong() shl 32) +
|
||||
(chunk[(it * 8) + 4].toULong() shl 24) +
|
||||
(chunk[(it * 8) + 5].toULong() shl 16) +
|
||||
(chunk[(it * 8) + 6].toULong() shl 8) +
|
||||
(chunk[(it * 8) + 7].toULong())
|
||||
collected
|
||||
}
|
||||
else -> 0UL
|
||||
}
|
||||
}
|
||||
for (i in 16 until 80) {
|
||||
val s0 = scheduleSigma0(w[i - 15])
|
||||
val s1 = scheduleSigma1(w[i - 2])
|
||||
w[i] = w[i - 16] + s0 + w[i - 7] + s1
|
||||
}
|
||||
|
||||
var a = h0
|
||||
var b = h1
|
||||
var c = h2
|
||||
var d = h3
|
||||
var e = h4
|
||||
var f = h5
|
||||
var g = h6
|
||||
var h = h7
|
||||
|
||||
for (i in 0 until 80) {
|
||||
val s1 = compressionSigma1(e)
|
||||
val ch = ch(e, f, g)
|
||||
val temp1 = h + s1 + ch + k[i] + w[i]
|
||||
val s0 = compressionSigma0(a)
|
||||
val maj = maj(a, b, c)
|
||||
val temp2 = s0 + maj
|
||||
h = g
|
||||
g = f
|
||||
f = e
|
||||
e = d + temp1
|
||||
d = c
|
||||
c = b
|
||||
b = a
|
||||
a = temp1 + temp2
|
||||
}
|
||||
|
||||
h0 += a
|
||||
h1 += b
|
||||
h2 += c
|
||||
h3 += d
|
||||
h4 += e
|
||||
h5 += f
|
||||
h6 += g
|
||||
h7 += h
|
||||
|
||||
}
|
||||
|
||||
var a = h0
|
||||
var b = h1
|
||||
var c = h2
|
||||
var d = h3
|
||||
var e = h4
|
||||
var f = h5
|
||||
var g = h6
|
||||
var h = h7
|
||||
|
||||
for (i in 0 until 80) {
|
||||
val s1 = compressionSigma1(e)
|
||||
val ch = ch(e, f, g)
|
||||
val temp1 = h + s1 + ch + k[i] + w[i]
|
||||
val s0 = compressionSigma0(a)
|
||||
val maj = maj(a,b,c)
|
||||
val temp2 = s0 + maj
|
||||
h = g
|
||||
g = f
|
||||
f = e
|
||||
e = d + temp1
|
||||
d = c
|
||||
c = b
|
||||
b = a
|
||||
a = temp1 + temp2
|
||||
}
|
||||
|
||||
h0 += a
|
||||
h1 += b
|
||||
h2 += c
|
||||
h3 += d
|
||||
h4 += e
|
||||
h5 += f
|
||||
h6 += g
|
||||
h7 += h
|
||||
|
||||
val digest = h0.toPaddedByteArray() +
|
||||
h1.toPaddedByteArray() +
|
||||
h2.toPaddedByteArray() +
|
||||
h3.toPaddedByteArray() +
|
||||
h4.toPaddedByteArray() +
|
||||
h5.toPaddedByteArray() +
|
||||
h6.toPaddedByteArray() +
|
||||
h7.toPaddedByteArray()
|
||||
return digest
|
||||
}
|
||||
|
||||
val digest = h0.toPaddedByteArray() +
|
||||
h1.toPaddedByteArray() +
|
||||
h2.toPaddedByteArray() +
|
||||
h3.toPaddedByteArray() +
|
||||
h4.toPaddedByteArray() +
|
||||
h5.toPaddedByteArray() +
|
||||
h6.toPaddedByteArray() +
|
||||
h7.toPaddedByteArray()
|
||||
reset()
|
||||
return digest
|
||||
}
|
||||
private fun scheduleSigma0(value: ULong): ULong {
|
||||
return value.rotateRight(1) xor value.rotateRight(8) xor (value shr 7)
|
||||
}
|
||||
|
||||
private fun reset() {
|
||||
h0 = 0x6a09e667f3bcc908UL
|
||||
h1 = 0xbb67ae8584caa73bUL
|
||||
h2 = 0x3c6ef372fe94f82bUL
|
||||
h3 = 0xa54ff53a5f1d36f1UL
|
||||
h4 = 0x510e527fade682d1UL
|
||||
h5 = 0x9b05688c2b3e6c1fUL
|
||||
h6 = 0x1f83d9abfb41bd6bUL
|
||||
h7 = 0x5be0cd19137e2179UL
|
||||
}
|
||||
private fun scheduleSigma1(value: ULong): ULong {
|
||||
return value.rotateRight(19) xor value.rotateRight(61) xor (value shr 6)
|
||||
}
|
||||
|
||||
private fun scheduleSigma0(value: ULong): ULong {
|
||||
return value.rotateRight(1) xor value.rotateRight(8) xor (value shr 7)
|
||||
}
|
||||
private fun compressionSigma0(e: ULong): ULong {
|
||||
return (e rotateRight 28) xor (e rotateRight 34) xor (e rotateRight 39)
|
||||
}
|
||||
|
||||
private fun scheduleSigma1(value : ULong) : ULong {
|
||||
return value.rotateRight(19) xor value.rotateRight(61) xor (value shr 6)
|
||||
}
|
||||
private fun compressionSigma1(a: ULong): ULong {
|
||||
return (a rotateRight 14) xor (a rotateRight 18) xor (a rotateRight 41)
|
||||
}
|
||||
|
||||
private fun compressionSigma0(e : ULong) : ULong {
|
||||
return (e rotateRight 28) xor (e rotateRight 34) xor (e rotateRight 39)
|
||||
}
|
||||
private fun ch(x: ULong, y: ULong, z: ULong): ULong {
|
||||
return ((x and y) xor ((x xor ULONG_MASK) and z))
|
||||
}
|
||||
|
||||
private fun compressionSigma1(a : ULong) : ULong {
|
||||
return (a rotateRight 14) xor (a rotateRight 18) xor (a rotateRight 41)
|
||||
}
|
||||
|
||||
private fun ch(x : ULong, y : ULong, z : ULong) : ULong {
|
||||
return ((x and y) xor ((x xor ULONG_MASK) and z))
|
||||
}
|
||||
|
||||
private fun maj(x : ULong, y : ULong, z : ULong) : ULong {
|
||||
return ((x and y) xor (x and z) xor (y and z))
|
||||
}
|
||||
private fun maj(x: ULong, y: ULong, z: ULong): ULong {
|
||||
return ((x and y) xor (x and z) xor (y and z))
|
||||
}
|
||||
|
||||
|
||||
private fun ULong.toPaddedByteArray(): Array<UByte> {
|
||||
val byteMask = 0xFFUL
|
||||
//Ignore messages longer than 64 bits for now
|
||||
return Array(8) {
|
||||
when (it) {
|
||||
7 -> (this and byteMask).toUByte()
|
||||
6 -> ((this shr 8) and byteMask).toUByte()
|
||||
5 -> ((this shr 16) and byteMask).toUByte()
|
||||
4 -> ((this shr 24) and byteMask).toUByte()
|
||||
3 -> ((this shr 32) and byteMask).toUByte()
|
||||
2 -> ((this shr 40) and byteMask).toUByte()
|
||||
1 -> ((this shr 48) and byteMask).toUByte()
|
||||
0 -> ((this shr 56) and byteMask).toUByte()
|
||||
else -> 0U
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun ULong.toPaddedByteArray(): Array<UByte> {
|
||||
val byteMask = 0xFFUL
|
||||
//Ignore messages longer than 64 bits for now
|
||||
return Array(8) {
|
||||
when (it) {
|
||||
7 -> (this and byteMask).toUByte()
|
||||
6 -> ((this shr 8) and byteMask).toUByte()
|
||||
5 -> ((this shr 16) and byteMask).toUByte()
|
||||
4 -> ((this shr 24) and byteMask).toUByte()
|
||||
3 -> ((this shr 32) and byteMask).toUByte()
|
||||
2 -> ((this shr 40) and byteMask).toUByte()
|
||||
1 -> ((this shr 48) and byteMask).toUByte()
|
||||
0 -> ((this shr 56) and byteMask).toUByte()
|
||||
else -> 0U
|
||||
private fun ULong.toPadded128BitByteArray(): Array<UByte> {
|
||||
val byteMask = 0xFFUL
|
||||
//Ignore messages longer than 64 bits for now
|
||||
return Array(16) {
|
||||
when (it) {
|
||||
15 -> (this and byteMask).toUByte()
|
||||
14 -> ((this shr 8) and byteMask).toUByte()
|
||||
13 -> ((this shr 16) and byteMask).toUByte()
|
||||
12 -> ((this shr 24) and byteMask).toUByte()
|
||||
11 -> ((this shr 32) and byteMask).toUByte()
|
||||
10 -> ((this shr 40) and byteMask).toUByte()
|
||||
9 -> ((this shr 48) and byteMask).toUByte()
|
||||
8 -> ((this shr 54) and byteMask).toUByte()
|
||||
else -> 0U
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun ULong.toPadded128BitByteArray(): Array<UByte> {
|
||||
val byteMask = 0xFFUL
|
||||
//Ignore messages longer than 64 bits for now
|
||||
return Array(16) {
|
||||
when (it) {
|
||||
15 -> (this and byteMask).toUByte()
|
||||
14 -> ((this shr 8) and byteMask).toUByte()
|
||||
13 -> ((this shr 16) and byteMask).toUByte()
|
||||
12 -> ((this shr 24) and byteMask).toUByte()
|
||||
11 -> ((this shr 32) and byteMask).toUByte()
|
||||
10 -> ((this shr 40) and byteMask).toUByte()
|
||||
9 -> ((this shr 48) and byteMask).toUByte()
|
||||
8 -> ((this shr 54) and byteMask).toUByte()
|
||||
else -> 0U
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,100 @@
|
||||
/*
|
||||
* 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
|
||||
|
||||
import com.ionspin.kotlin.crypto.blake2b.Blake2b
|
||||
import com.ionspin.kotlin.crypto.sha.Sha256
|
||||
import com.ionspin.kotlin.crypto.sha.Sha512
|
||||
import kotlin.test.Test
|
||||
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
/**
|
||||
* Created by Ugljesa Jovanovic
|
||||
* ugljesa.jovanovic@ionspin.com
|
||||
* on 20-Jul-2019
|
||||
*/
|
||||
@ExperimentalUnsignedTypes
|
||||
@ExperimentalStdlibApi
|
||||
class ReadmeTest {
|
||||
|
||||
@Test
|
||||
fun blake2bObjectExample() {
|
||||
val input = "abc"
|
||||
val result = Blake2b.digest(input)
|
||||
//@formatter:off
|
||||
val expectedResult = arrayOf<UByte>(
|
||||
0xBAU,0x80U,0xA5U,0x3FU,0x98U,0x1CU,0x4DU,0x0DU,0x6AU,0x27U,0x97U,0xB6U,0x9FU,0x12U,0xF6U,0xE9U,
|
||||
0x4CU,0x21U,0x2FU,0x14U,0x68U,0x5AU,0xC4U,0xB7U,0x4BU,0x12U,0xBBU,0x6FU,0xDBU,0xFFU,0xA2U,0xD1U,
|
||||
0x7DU,0x87U,0xC5U,0x39U,0x2AU,0xABU,0x79U,0x2DU,0xC2U,0x52U,0xD5U,0xDEU,0x45U,0x33U,0xCCU,0x95U,
|
||||
0x18U,0xD3U,0x8AU,0xA8U,0xDBU,0xF1U,0x92U,0x5AU,0xB9U,0x23U,0x86U,0xEDU,0xD4U,0x00U,0x99U,0x23U
|
||||
)
|
||||
//@formatter:on
|
||||
|
||||
assertTrue {
|
||||
result.contentEquals(expectedResult)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun blake2bInstanceExample() {
|
||||
val test = "abc"
|
||||
val key = "key"
|
||||
val blake2b = Blake2b(key)
|
||||
blake2b.update(test)
|
||||
val result = blake2b.digest()
|
||||
|
||||
assertTrue {
|
||||
result.isNotEmpty()
|
||||
}
|
||||
val expectedResult = ("5c6a9a4ae911c02fb7e71a991eb9aea371ae993d4842d206e" +
|
||||
"6020d46f5e41358c6d5c277c110ef86c959ed63e6ecaaaceaaff38019a43264ae06acf73b9550b1")
|
||||
.chunked(2).map { it.toUByte(16) }.toTypedArray()
|
||||
|
||||
assertTrue {
|
||||
result.contentEquals(expectedResult)
|
||||
}
|
||||
}
|
||||
|
||||
@ExperimentalStdlibApi
|
||||
@Test
|
||||
fun sha256Example() {
|
||||
val input ="abc"
|
||||
val result = Sha256.digest(message = input)
|
||||
val expectedResult = "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"
|
||||
assertTrue {
|
||||
result.contentEquals(expectedResult.chunked(2).map { it.toUByte(16) }.toTypedArray())
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ExperimentalStdlibApi
|
||||
@Test
|
||||
fun sha512Example() {
|
||||
val input ="abc"
|
||||
val result = Sha512.digest(message = input.encodeToByteArray().map { it.toUByte() }.toTypedArray())
|
||||
println(result.map {it.toString(16)})
|
||||
val expectedResult = "ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a" +
|
||||
"2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f"
|
||||
assertTrue {
|
||||
result.contentEquals(expectedResult.chunked(2).map { it.toUByte(16) }.toTypedArray())
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -44,7 +44,6 @@ class Blake2BTest {
|
||||
"1234567890" +
|
||||
"1234567890" +
|
||||
"1234567890"
|
||||
print("|$test|")
|
||||
|
||||
val result = Blake2b.digest(test)
|
||||
//Generated with b2sum 8.31
|
||||
@ -58,9 +57,6 @@ class Blake2BTest {
|
||||
//@formatter:on
|
||||
)
|
||||
|
||||
val printout = result.map { it.toString(16) }.chunked(16)
|
||||
printout.forEach { println(it.joinToString(separator = " ") { it.toUpperCase() }) }
|
||||
|
||||
assertTrue {
|
||||
result.contentEquals(expectedResult)
|
||||
}
|
||||
@ -79,7 +75,6 @@ class Blake2BTest {
|
||||
"1234567890" +
|
||||
"1234567890"
|
||||
|
||||
print("|$test|")
|
||||
|
||||
val result = Blake2b.digest(test)
|
||||
val expectedResultString = "800bb78cd4da18995c8074713bb674" +
|
||||
@ -87,9 +82,6 @@ class Blake2BTest {
|
||||
"4ce1935a76154d7ea7c410493557741d18ec3a08da75"
|
||||
val expectedResult = expectedResultString.chunked(2).map { it.toUByte(16) }.toTypedArray()
|
||||
|
||||
val printout = result.map { it.toString(16) }.chunked(16)
|
||||
printout.forEach { println(it.joinToString(separator = " ") { it.toUpperCase() }) }
|
||||
|
||||
assertTrue {
|
||||
result.contentEquals(expectedResult)
|
||||
}
|
||||
@ -111,9 +103,6 @@ class Blake2BTest {
|
||||
//@formatter:on
|
||||
)
|
||||
|
||||
val printout = result.map { it.toString(16) }.chunked(16)
|
||||
printout.forEach { println(it.joinToString(separator = " ") { it.toUpperCase() }) }
|
||||
|
||||
assertTrue {
|
||||
result.contentEquals(expectedResult)
|
||||
}
|
||||
@ -126,10 +115,6 @@ class Blake2BTest {
|
||||
val key = "key"
|
||||
|
||||
val result = Blake2b.digest(test, key)
|
||||
val printout = result.map { it.toString(16) }.chunked(16)
|
||||
printout.forEach { println(it.joinToString(separator = " ") { it.toUpperCase() }) }
|
||||
|
||||
|
||||
|
||||
assertTrue {
|
||||
result.isNotEmpty()
|
||||
@ -159,9 +144,6 @@ class Blake2BTest {
|
||||
|
||||
)
|
||||
//@formatter:on
|
||||
val printout = result.map { it.toString(16) }.chunked(16)
|
||||
printout.forEach { println(it.joinToString(separator = " ") { it.toUpperCase() }) }
|
||||
|
||||
assertTrue {
|
||||
result.contentEquals(expectedResult)
|
||||
}
|
||||
@ -290,9 +272,6 @@ class Blake2BTest {
|
||||
val inputRound = mixChain[i]
|
||||
val round = i
|
||||
val result = Blake2b.mixRound(inputRound, message, round)
|
||||
println("Result: ")
|
||||
val printout = result.map { it.toString(16) }.chunked(3)
|
||||
printout.forEach { println(it.joinToString(separator = " ") { it.toUpperCase() }) }
|
||||
val expectedResult = mixChain[i + 1]
|
||||
assertTrue {
|
||||
result.contentEquals(expectedResult)
|
||||
|
@ -80,10 +80,6 @@ class Blake2bInstanceTest {
|
||||
val blake2b = Blake2b(key)
|
||||
blake2b.update(test)
|
||||
val result = blake2b.digest()
|
||||
val printout = result.map { it.toString(16) }.chunked(16)
|
||||
printout.forEach { println(it.joinToString(separator = " ") { it.toUpperCase() }) }
|
||||
|
||||
|
||||
|
||||
assertTrue {
|
||||
result.isNotEmpty()
|
||||
|
@ -30,10 +30,8 @@ class Sha256Test {
|
||||
@ExperimentalStdlibApi
|
||||
@Test
|
||||
fun testWellKnownValue() {
|
||||
val sha = Sha256()
|
||||
|
||||
val result = sha.digest(message = "abc".encodeToByteArray().map { it.toUByte() }.toTypedArray())
|
||||
println(result.map {it.toString(16)})
|
||||
val result = Sha256.digest(message = "abc")
|
||||
val expectedResult = "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"
|
||||
assertTrue {
|
||||
result.contentEquals(expectedResult.chunked(2).map { it.toUByte(16) }.toTypedArray())
|
||||
@ -45,9 +43,8 @@ class Sha256Test {
|
||||
@ExperimentalStdlibApi
|
||||
@Test
|
||||
fun testWellKnownDoubleBlock() {
|
||||
val sha = Sha256()
|
||||
|
||||
val resultDoubleBlock = sha.digest(message = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq".encodeToByteArray().map { it.toUByte() }.toTypedArray())
|
||||
val resultDoubleBlock = Sha256.digest(message = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq")
|
||||
val expectedResultForDoubleBlock = "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1"
|
||||
assertTrue {
|
||||
resultDoubleBlock.contentEquals(expectedResultForDoubleBlock.chunked(2).map { it.toUByte(16) }.toTypedArray())
|
||||
|
@ -29,9 +29,8 @@ class Sha512Test {
|
||||
@ExperimentalStdlibApi
|
||||
@Test
|
||||
fun testWellKnownValue() {
|
||||
val sha = Sha512()
|
||||
|
||||
val result = sha.digest(message = "abc".encodeToByteArray().map { it.toUByte() }.toTypedArray())
|
||||
val result = Sha512.digest(message = "abc".encodeToByteArray().map { it.toUByte() }.toTypedArray())
|
||||
println(result.map {it.toString(16)})
|
||||
val expectedResult = "ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a" +
|
||||
"2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f"
|
||||
@ -42,14 +41,13 @@ class Sha512Test {
|
||||
|
||||
}
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
@ExperimentalStdlibApi
|
||||
@Test
|
||||
fun testWellKnownDoubleBlock() {
|
||||
val sha = Sha512()
|
||||
|
||||
val resultDoubleBlock = sha.digest(message = ("abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmn" +
|
||||
"hijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu").encodeToByteArray().map { it.toUByte() }.toTypedArray())
|
||||
println(resultDoubleBlock.map {it.toString(16)})
|
||||
val resultDoubleBlock = Sha512.digest(message = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmn" +
|
||||
"hijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu")
|
||||
val expectedResultForDoubleBlock = "8e959b75dae313da8cf4f72814fc143f8f7779c6eb9f7fa17299aeadb6889018" +
|
||||
"501d289e4900f7e4331b99dec4b5433ac7d329eeb6dd26545e96e55b874be909"
|
||||
assertTrue {
|
||||
@ -60,16 +58,11 @@ class Sha512Test {
|
||||
@ExperimentalStdlibApi
|
||||
@Test
|
||||
fun testWellKnownLong() {
|
||||
val sha = Sha512()
|
||||
val inputBuilder = StringBuilder()
|
||||
for (i in 0 until 1000000) {
|
||||
inputBuilder.append("a")
|
||||
if (i % 100000 == 0) {
|
||||
println("$i / 1000000")
|
||||
}
|
||||
}
|
||||
val resultDoubleBlock = sha.digest(message = (inputBuilder.toString()).encodeToByteArray().map { it.toUByte() }.toTypedArray())
|
||||
println(resultDoubleBlock.map {it.toString(16)})
|
||||
val resultDoubleBlock = Sha512.digest(message = (inputBuilder.toString()).encodeToByteArray().map { it.toUByte() }.toTypedArray())
|
||||
val expectedResultForDoubleBlock = "e718483d0ce769644e2e42c7bc15b4638e1f98b13b2044285632a803afa973ebde0ff244877ea60a4cb0432ce577c31beb009c5c2c49aa2e4eadb217ad8cc09b"
|
||||
assertTrue {
|
||||
resultDoubleBlock.contentEquals(expectedResultForDoubleBlock.chunked(2).map { it.toUByte(16) }.toTypedArray())
|
||||
|
Loading…
x
Reference in New Issue
Block a user