Compare commits
2 Commits
fec960065d
...
cff4a4e7a4
| Author | SHA1 | Date | |
|---|---|---|---|
|
cff4a4e7a4
|
|||
|
0229457a20
|
@@ -1,5 +1,5 @@
|
|||||||
group = "com.infendro"
|
group = "com.infendro"
|
||||||
version = "1.2.0"
|
version = "1.2.1"
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
maven("https://git.infendro.com/api/packages/Infendro/maven")
|
maven("https://git.infendro.com/api/packages/Infendro/maven")
|
||||||
@@ -23,9 +23,6 @@ kotlin {
|
|||||||
implementation(libs.hash)
|
implementation(libs.hash)
|
||||||
implementation(libs.bytearray)
|
implementation(libs.bytearray)
|
||||||
}
|
}
|
||||||
commonTest.dependencies {
|
|
||||||
implementation(libs.test)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
compilerOptions {
|
compilerOptions {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
[versions]
|
[versions]
|
||||||
kotlin = "2.1.20"
|
kotlin = "2.1.20"
|
||||||
hash = "1.3.2"
|
hash = "1.3.1"
|
||||||
bytearray = "1.2.2"
|
bytearray = "1.2.1"
|
||||||
|
|
||||||
[plugins]
|
[plugins]
|
||||||
multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
|
multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
|
||||||
@@ -9,4 +9,3 @@ multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotl
|
|||||||
[libraries]
|
[libraries]
|
||||||
hash = { module = "com.infendro:hash", version.ref = "hash" }
|
hash = { module = "com.infendro:hash", version.ref = "hash" }
|
||||||
bytearray = { module = "com.infendro:bytearray", version.ref = "bytearray" }
|
bytearray = { module = "com.infendro:bytearray", version.ref = "bytearray" }
|
||||||
test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ class HMAC(
|
|||||||
key: UByteArray,
|
key: UByteArray,
|
||||||
): UByteArray {
|
): UByteArray {
|
||||||
return when {
|
return when {
|
||||||
key.size > function.block -> function.hash(key)
|
key.size > function.block -> function.hash(key).padEnd(function.block, 0x00U)
|
||||||
key.size < function.block -> key.padEnd(function.block, 0x00U)
|
key.size < function.block -> key.padEnd(function.block, 0x00U)
|
||||||
else -> key
|
else -> key
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package com.infendro.mac
|
|||||||
|
|
||||||
abstract class MAC {
|
abstract class MAC {
|
||||||
abstract val bytes: Int
|
abstract val bytes: Int
|
||||||
|
|
||||||
|
@Suppress("UNUSED")
|
||||||
val bits: Int
|
val bits: Int
|
||||||
get() = bytes * 8
|
get() = bytes * 8
|
||||||
|
|
||||||
|
|||||||
@@ -1,36 +0,0 @@
|
|||||||
package com.infendro.mac
|
|
||||||
|
|
||||||
import com.infendro.hash.sha2.`SHA-256`
|
|
||||||
import kotlin.test.Test
|
|
||||||
import kotlin.test.assertContentEquals
|
|
||||||
import kotlin.test.assertEquals
|
|
||||||
|
|
||||||
class `HMAC Test` {
|
|
||||||
val hmac = HMAC(`SHA-256`)
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun bytes() {
|
|
||||||
assertEquals(32, hmac.bytes)
|
|
||||||
assertEquals(256, hmac.bits)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `hash() - example`() {
|
|
||||||
assertContentEquals(
|
|
||||||
ubyteArrayOf(
|
|
||||||
0xf7U, 0xbcU, 0x83U, 0xf4U,
|
|
||||||
0x30U, 0x53U, 0x84U, 0x24U,
|
|
||||||
0xb1U, 0x32U, 0x98U, 0xe6U,
|
|
||||||
0xaaU, 0x6fU, 0xb1U, 0x43U,
|
|
||||||
0xefU, 0x4dU, 0x59U, 0xa1U,
|
|
||||||
0x49U, 0x46U, 0x17U, 0x59U,
|
|
||||||
0x97U, 0x47U, 0x9dU, 0xbcU,
|
|
||||||
0x2dU, 0x1aU, 0x3cU, 0xd8U,
|
|
||||||
),
|
|
||||||
hmac.hash(
|
|
||||||
"key".encodeToByteArray().asUByteArray(),
|
|
||||||
"The quick brown fox jumps over the lazy dog".encodeToByteArray().asUByteArray()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user