Update to PSEC v0.4

This commit is contained in:
Matéo Duparc 2021-07-25 16:01:06 +02:00
parent 37e4c0a105
commit d618eb87c7
Signed by: hardcoresushi
GPG Key ID: 007F84120107191E
1 changed files with 2 additions and 2 deletions

View File

@ -188,7 +188,7 @@ class Session(private val socket: SocketChannel, val outgoing: Boolean): Selecta
fun encrypt(plainText: ByteArray, usePadding: Boolean): ByteArray {
val padded = pad(plainText, usePadding)
val rawMsgLen = ByteBuffer.allocate(MESSAGE_LEN_LEN).putInt(padded.size).array()
val rawMsgLen = ByteBuffer.allocate(MESSAGE_LEN_LEN).putInt(padded.size+AES_TAG_LEN).array()
val nonce = ivToNonce(applicationKeys.localIv, localCounter)
localCounter++
localCipher.init(Cipher.ENCRYPT_MODE, SecretKeySpec(applicationKeys.localKey, "AES"), GCMParameterSpec(AES_TAG_LEN*8, nonce))
@ -219,7 +219,7 @@ class Session(private val socket: SocketChannel, val outgoing: Boolean): Selecta
val rawMessageLen = ByteBuffer.allocate(MESSAGE_LEN_LEN)
if (readAll(rawMessageLen)) {
rawMessageLen.position(0)
val messageLen = rawMessageLen.int + AES_TAG_LEN
val messageLen = rawMessageLen.int
if (messageLen in 1..MAX_RECV_SIZE) {
val cipherText = ByteBuffer.allocate(messageLen)
if (readAll(cipherText)) {