refactor package structure
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
package com.infendro.hash
|
||||
|
||||
sealed class HashFunction {
|
||||
abstract class HashFunction {
|
||||
abstract val bytes: Int
|
||||
@Suppress("UNUSED")
|
||||
val bits: Int
|
||||
get() = bytes * 8
|
||||
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package com.infendro.hash
|
||||
package com.infendro.hash.md
|
||||
|
||||
import com.infendro.bytearray.ByteOrder.LITTLE_ENDIAN
|
||||
import com.infendro.bytearray.ByteOrder
|
||||
import com.infendro.bytearray.addAll
|
||||
import com.infendro.bytearray.toByteArray
|
||||
import com.infendro.bytearray.toUIntArray
|
||||
import com.infendro.hash.HashFunction
|
||||
|
||||
@Suppress("UNUSED")
|
||||
object MD5 : HashFunction() {
|
||||
override val bytes: Int
|
||||
get() = 16
|
||||
@@ -62,14 +64,14 @@ object MD5 : HashFunction() {
|
||||
while (size % 64 != 56) {
|
||||
add(0x00.toByte())
|
||||
}
|
||||
addAll(ml.toByteArray(LITTLE_ENDIAN))
|
||||
addAll(ml.toByteArray(ByteOrder.LITTLE_ENDIAN))
|
||||
}
|
||||
|
||||
val chunks = paddedValue
|
||||
.chunked(64)
|
||||
for (chunk in chunks) {
|
||||
val w = buildList {
|
||||
addAll(chunk.toUIntArray(LITTLE_ENDIAN))
|
||||
addAll(chunk.toUIntArray(ByteOrder.LITTLE_ENDIAN))
|
||||
}
|
||||
|
||||
var a = a0
|
||||
@@ -103,10 +105,10 @@ object MD5 : HashFunction() {
|
||||
}
|
||||
|
||||
return byteArrayOf(
|
||||
*a0.toByteArray(LITTLE_ENDIAN),
|
||||
*b0.toByteArray(LITTLE_ENDIAN),
|
||||
*c0.toByteArray(LITTLE_ENDIAN),
|
||||
*d0.toByteArray(LITTLE_ENDIAN),
|
||||
*a0.toByteArray(ByteOrder.LITTLE_ENDIAN),
|
||||
*b0.toByteArray(ByteOrder.LITTLE_ENDIAN),
|
||||
*c0.toByteArray(ByteOrder.LITTLE_ENDIAN),
|
||||
*d0.toByteArray(ByteOrder.LITTLE_ENDIAN),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
package com.infendro.hash
|
||||
package com.infendro.hash.sha1
|
||||
|
||||
import com.infendro.bytearray.addAll
|
||||
import com.infendro.bytearray.toByteArray
|
||||
import com.infendro.bytearray.toUIntArray
|
||||
import com.infendro.hash.HashFunction
|
||||
|
||||
@Suppress("UNUSED")
|
||||
object SHA1 : HashFunction() {
|
||||
override val bytes: Int
|
||||
get() = 20
|
||||
@@ -80,4 +82,4 @@ object SHA1 : HashFunction() {
|
||||
*h4.toByteArray(),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,12 @@
|
||||
package com.infendro.hash
|
||||
package com.infendro.hash.sha2
|
||||
|
||||
import com.infendro.bytearray.addAll
|
||||
import com.infendro.bytearray.toByteArray
|
||||
import com.infendro.bytearray.toUIntArray
|
||||
import com.infendro.hash.HashFunction
|
||||
|
||||
object SHA224 : HashFunction() {
|
||||
@Suppress("UNUSED")
|
||||
object `SHA-224` : HashFunction() {
|
||||
override val bytes: Int
|
||||
get() = 28
|
||||
|
||||
@@ -63,10 +65,10 @@ object SHA224 : HashFunction() {
|
||||
var h = h7
|
||||
|
||||
for (i in 0..<64) {
|
||||
val s0 = a.rotateRight(2) xor a.rotateRight(13) xor a.rotateRight(22)
|
||||
val s1 = e.rotateRight(6) xor e.rotateRight(11) xor e.rotateRight(25)
|
||||
val ch = (e and f) xor (e.inv() and g)
|
||||
val temp1 = h + s1 + ch + k[i] + w[i]
|
||||
val s0 = a.rotateRight(2) xor a.rotateRight(13) xor a.rotateRight(22)
|
||||
val maj = (a and b) xor (a and c) xor (b and c)
|
||||
val temp2 = s0 + maj
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package com.infendro.hash
|
||||
package com.infendro.hash.sha2
|
||||
|
||||
import com.infendro.bytearray.addAll
|
||||
import com.infendro.bytearray.toByteArray
|
||||
import com.infendro.bytearray.toUIntArray
|
||||
import com.infendro.hash.HashFunction
|
||||
|
||||
object SHA256 : HashFunction() {
|
||||
@Suppress("UNUSED")
|
||||
object `SHA-256` : HashFunction() {
|
||||
override val bytes: Int
|
||||
get() = 32
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package com.infendro.hash
|
||||
package com.infendro.hash.sha2
|
||||
|
||||
import com.infendro.bytearray.addAll
|
||||
import com.infendro.bytearray.toByteArray
|
||||
import com.infendro.bytearray.toULongArray
|
||||
import com.infendro.hash.HashFunction
|
||||
|
||||
object SHA384 : HashFunction() {
|
||||
@Suppress("UNUSED")
|
||||
object `SHA-384` : HashFunction() {
|
||||
override val bytes: Int
|
||||
get() = 48
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package com.infendro.hash
|
||||
package com.infendro.hash.sha2
|
||||
|
||||
import com.infendro.bytearray.addAll
|
||||
import com.infendro.bytearray.toByteArray
|
||||
import com.infendro.bytearray.toULongArray
|
||||
import com.infendro.hash.HashFunction
|
||||
|
||||
object SHA512 : HashFunction() {
|
||||
@Suppress("UNUSED")
|
||||
object `SHA-512` : HashFunction() {
|
||||
override val bytes: Int
|
||||
get() = 64
|
||||
|
||||
Reference in New Issue
Block a user