Upgrade dependencies
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package com.infendro.kdf
|
||||
|
||||
import com.infendro.bytes.bytearray.xorInto
|
||||
import com.infendro.bytes.int.copyInto
|
||||
import com.infendro.bytes.bytearray.xorWith
|
||||
import com.infendro.bytes.int.toByteArray
|
||||
import com.infendro.hash.HashFunction
|
||||
import com.infendro.kdf.util.ceilDiv
|
||||
import com.infendro.mac.HMAC
|
||||
@@ -17,21 +17,24 @@ class PBKDF2(
|
||||
}
|
||||
|
||||
private val hmac = HMAC(function)
|
||||
private val buffer = ByteArray(hmac.bytes)
|
||||
|
||||
override fun hashInto(value: ByteArray, salt: ByteArray, destination: ByteArray, destinationOffset: Int) {
|
||||
for (iteration in 1..bytes.ceilDiv(hmac.bytes)) {
|
||||
val offset = (iteration - 1) * hmac.bytes
|
||||
val block = minOf(bytes - offset, hmac.bytes)
|
||||
hmac.init(value)
|
||||
|
||||
val s = ByteArray(salt.size + 4)
|
||||
salt.copyInto(s)
|
||||
iteration.copyInto(s, salt.size)
|
||||
for (block in 1..bytes.ceilDiv(hmac.bytes)) {
|
||||
val offset = (block - 1) * hmac.bytes
|
||||
val bytes = minOf(bytes - offset, hmac.bytes)
|
||||
|
||||
val buffer = hmac.hash(value, s)
|
||||
buffer.copyInto(destination, destinationOffset + offset, endIndex = block)
|
||||
hmac.update(salt)
|
||||
hmac.update(block.toByteArray())
|
||||
hmac.digestInto(buffer)
|
||||
buffer.copyInto(destination, destinationOffset + offset, endIndex = bytes)
|
||||
repeat(iterations - 1) {
|
||||
hmac.hashInto(value, buffer, buffer)
|
||||
buffer.xorInto(destination, destinationOffset + offset, endIndex = block)
|
||||
hmac.update(buffer)
|
||||
hmac.digestInto(buffer)
|
||||
val offset = destinationOffset + offset
|
||||
destination.xorWith(buffer, offset, offset + bytes)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user