Fixed GCM, now use threadlocal for hashing

This commit is contained in:
Robinson 2021-08-23 00:38:55 -06:00
parent d4efe418e6
commit d8107860e5

View File

@ -15,6 +15,7 @@
*/ */
package dorkbox.network.connection package dorkbox.network.connection
import dorkbox.bytes.Hash
import dorkbox.netUtil.IP import dorkbox.netUtil.IP
import dorkbox.network.handshake.ClientConnectionInfo import dorkbox.network.handshake.ClientConnectionInfo
import dorkbox.network.serialization.AeronInput import dorkbox.network.serialization.AeronInput
@ -28,7 +29,6 @@ import java.math.BigInteger
import java.net.InetAddress import java.net.InetAddress
import java.security.KeyFactory import java.security.KeyFactory
import java.security.KeyPairGenerator import java.security.KeyPairGenerator
import java.security.MessageDigest
import java.security.SecureRandom import java.security.SecureRandom
import java.security.interfaces.XECPrivateKey import java.security.interfaces.XECPrivateKey
import java.security.interfaces.XECPublicKey import java.security.interfaces.XECPublicKey
@ -55,8 +55,7 @@ internal class CryptoManagement(val logger: KLogger,
private val keyFactory = KeyFactory.getInstance(X25519) // key size is 32 bytes (256 bits) private val keyFactory = KeyFactory.getInstance(X25519) // key size is 32 bytes (256 bits)
private val keyAgreement = KeyAgreement.getInstance("XDH") private val keyAgreement = KeyAgreement.getInstance("XDH")
private val aesCipher = Cipher.getInstance("AES/GCM/PKCS5Padding") private val aesCipher = Cipher.getInstance("AES/GCM/NoPadding")
private val hash = MessageDigest.getInstance("SHA-256");
companion object { companion object {
const val curve25519 = "curve25519" const val curve25519 = "curve25519"
@ -178,6 +177,7 @@ internal class CryptoManagement(val logger: KLogger,
val sharedSecret = keyAgreement.generateSecret() val sharedSecret = keyAgreement.generateSecret()
// Derive a key from the shared secret and both public keys // Derive a key from the shared secret and both public keys
val hash = Hash.sha256
hash.reset() hash.reset()
hash.update(sharedSecret) hash.update(sharedSecret)
hash.update(bytesA) hash.update(bytesA)