This commit is contained in:
@@ -22,11 +22,12 @@ class HMAC(
|
||||
function.hashInto(outer, destination, destinationOffset)
|
||||
}
|
||||
|
||||
private fun pad(key: ByteArray): ByteArray =
|
||||
ByteArray(function.block).also {
|
||||
private fun pad(key: ByteArray): ByteArray {
|
||||
return ByteArray(function.block).also {
|
||||
when {
|
||||
key.size > function.block -> function.hashInto(key, it)
|
||||
else -> key.copyInto(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,18 +7,9 @@ interface MAC {
|
||||
|
||||
fun hashInto(key: ByteArray, value: ByteArray, destination: ByteArray, destinationOffset: Int = 0)
|
||||
|
||||
fun hashInto(key: ByteArray, value: ByteArray, destination: UByteArray, destinationOffset: Int = 0) =
|
||||
hashInto(key, value, destination.asByteArray(), destinationOffset)
|
||||
|
||||
fun hashInto(key: UByteArray, value: UByteArray, destination: ByteArray, destinationOffset: Int = 0) =
|
||||
hashInto(key.asByteArray(), value.asByteArray(), destination, destinationOffset)
|
||||
|
||||
fun hashInto(key: UByteArray, value: UByteArray, destination: UByteArray, destinationOffset: Int = 0) =
|
||||
hashInto(key.asByteArray(), value.asByteArray(), destination.asByteArray(), destinationOffset)
|
||||
|
||||
fun hash(key: ByteArray, value: ByteArray): ByteArray =
|
||||
ByteArray(bytes).also { hashInto(key, value, it) }
|
||||
|
||||
fun hash(key: UByteArray, value: UByteArray): UByteArray =
|
||||
UByteArray(bytes).also { hashInto(key, value, it) }
|
||||
fun hash(key: ByteArray, value: ByteArray): ByteArray {
|
||||
val result = ByteArray(bytes)
|
||||
hashInto(key, value, result)
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user