convert HashFunction to interface
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
package com.infendro.hash
|
||||
|
||||
abstract class HashFunction {
|
||||
abstract val bytes: Int
|
||||
interface HashFunction {
|
||||
val bytes: Int
|
||||
val bits: Int
|
||||
get() = bytes * 8
|
||||
|
||||
abstract val block: Int
|
||||
val block: Int
|
||||
|
||||
abstract fun hash(
|
||||
fun hash(
|
||||
value: UByteArray,
|
||||
): UByteArray
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import com.infendro.bytearray.toUByteArray
|
||||
import com.infendro.bytearray.toUIntArray
|
||||
import com.infendro.hash.HashFunction
|
||||
|
||||
object `Blake-224` : HashFunction() {
|
||||
object `Blake-224` : HashFunction {
|
||||
override val bytes: Int
|
||||
get() = 28
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import com.infendro.bytearray.toUByteArray
|
||||
import com.infendro.bytearray.toUIntArray
|
||||
import com.infendro.hash.HashFunction
|
||||
|
||||
object `Blake-256` : HashFunction() {
|
||||
object `Blake-256` : HashFunction {
|
||||
override val bytes: Int
|
||||
get() = 32
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import com.infendro.bytearray.toUByteArray
|
||||
import com.infendro.bytearray.toULongArray
|
||||
import com.infendro.hash.HashFunction
|
||||
|
||||
object `Blake-384` : HashFunction() {
|
||||
object `Blake-384` : HashFunction {
|
||||
override val bytes: Int
|
||||
get() = 48
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import com.infendro.bytearray.toUByteArray
|
||||
import com.infendro.bytearray.toULongArray
|
||||
import com.infendro.hash.HashFunction
|
||||
|
||||
object `Blake-512` : HashFunction() {
|
||||
object `Blake-512` : HashFunction {
|
||||
override val bytes: Int
|
||||
get() = 64
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import com.infendro.hash.HashFunction
|
||||
|
||||
class Blake2b(
|
||||
override val bytes: Int,
|
||||
) : HashFunction() {
|
||||
) : HashFunction {
|
||||
init {
|
||||
if (bytes !in 1..64) throw IllegalArgumentException()
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import com.infendro.hash.HashFunction
|
||||
|
||||
class Blake2s(
|
||||
override val bytes: Int,
|
||||
) : HashFunction() {
|
||||
) : HashFunction {
|
||||
init {
|
||||
if (bytes !in 1..32) throw IllegalArgumentException()
|
||||
}
|
||||
|
||||
@@ -6,16 +6,11 @@ import com.infendro.bytearray.toULongArray
|
||||
import com.infendro.hash.HashFunction
|
||||
import kotlin.math.min
|
||||
|
||||
open class Keccak(
|
||||
abstract class Keccak(
|
||||
override val bytes: Int,
|
||||
private val rate: Int,
|
||||
private val domain: UByte,
|
||||
) : HashFunction() {
|
||||
init {
|
||||
if (bytes < 1) throw IllegalArgumentException()
|
||||
if (rate !in 8..168) throw IllegalArgumentException()
|
||||
}
|
||||
|
||||
) : HashFunction {
|
||||
override val block: Int
|
||||
get() = rate
|
||||
|
||||
@@ -108,7 +103,7 @@ open class Keccak(
|
||||
}
|
||||
}
|
||||
|
||||
fun squeeze(
|
||||
private fun squeeze(
|
||||
state: ULongArray,
|
||||
): UByteArray {
|
||||
return buildList {
|
||||
|
||||
@@ -5,7 +5,7 @@ import com.infendro.bytearray.toUByteArray
|
||||
import com.infendro.bytearray.toUIntArray
|
||||
import com.infendro.hash.HashFunction
|
||||
|
||||
object MD5 : HashFunction() {
|
||||
object MD5 : HashFunction {
|
||||
override val bytes: Int
|
||||
get() = 16
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import com.infendro.bytearray.toUByteArray
|
||||
import com.infendro.bytearray.toUIntArray
|
||||
import com.infendro.hash.HashFunction
|
||||
|
||||
object SHA1 : HashFunction() {
|
||||
object SHA1 : HashFunction {
|
||||
override val bytes: Int
|
||||
get() = 20
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import com.infendro.bytearray.toUByteArray
|
||||
import com.infendro.bytearray.toUIntArray
|
||||
import com.infendro.hash.HashFunction
|
||||
|
||||
object `SHA-224` : HashFunction() {
|
||||
object `SHA-224` : HashFunction {
|
||||
override val bytes: Int
|
||||
get() = 28
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import com.infendro.bytearray.toUByteArray
|
||||
import com.infendro.bytearray.toUIntArray
|
||||
import com.infendro.hash.HashFunction
|
||||
|
||||
object `SHA-256` : HashFunction() {
|
||||
object `SHA-256` : HashFunction {
|
||||
override val bytes: Int
|
||||
get() = 32
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import com.infendro.bytearray.toUByteArray
|
||||
import com.infendro.bytearray.toULongArray
|
||||
import com.infendro.hash.HashFunction
|
||||
|
||||
object `SHA-384` : HashFunction() {
|
||||
object `SHA-384` : HashFunction {
|
||||
override val bytes: Int
|
||||
get() = 48
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import com.infendro.bytearray.toUByteArray
|
||||
import com.infendro.bytearray.toULongArray
|
||||
import com.infendro.hash.HashFunction
|
||||
|
||||
object `SHA-512` : HashFunction() {
|
||||
object `SHA-512` : HashFunction {
|
||||
override val bytes: Int
|
||||
get() = 64
|
||||
|
||||
|
||||
Reference in New Issue
Block a user