I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Verified Commit 62fce859 authored by zzz's avatar zzz
Browse files

Ratchet: mixHash() not required after message for N pattern

parent 9fc97764
No related branches found
No related tags found
No related merge requests found
...@@ -648,10 +648,19 @@ public class HandshakeState implements Destroyable, Cloneable { ...@@ -648,10 +648,19 @@ public class HandshakeState implements Destroyable, Cloneable {
} }
// Add the payload to the message buffer and encrypt it. // Add the payload to the message buffer and encrypt it.
if (payload != null) if (payload != null) {
messagePosn += symmetric.encryptAndHash(payload, payloadOffset, message, messagePosn, payloadLength); // no need to hash for N, we don't split() and no more messages follow
else if (patternId.equals(PATTERN_ID_N))
messagePosn += symmetric.encryptAndHash(message, messagePosn, message, messagePosn, 0); messagePosn += symmetric.encryptOnly(payload, payloadOffset, message, messagePosn, payloadLength);
else
messagePosn += symmetric.encryptAndHash(payload, payloadOffset, message, messagePosn, payloadLength);
} else {
// no need to hash for N, we don't split() and no more messages follow
if (patternId.equals(PATTERN_ID_N))
messagePosn += symmetric.encryptOnly(message, messagePosn, message, messagePosn, 0);
else
messagePosn += symmetric.encryptAndHash(message, messagePosn, message, messagePosn, 0);
}
success = true; success = true;
} finally { } finally {
// If we failed, then clear any sensitive data that may have // If we failed, then clear any sensitive data that may have
...@@ -819,7 +828,12 @@ public class HandshakeState implements Destroyable, Cloneable { ...@@ -819,7 +828,12 @@ public class HandshakeState implements Destroyable, Cloneable {
} }
// Decrypt the message payload. // Decrypt the message payload.
int payloadLength = symmetric.decryptAndHash(message, messageOffset, payload, payloadOffset, messageEnd - messageOffset); int payloadLength;
// no need to hash for N, we don't split() and no more messages follow
if (patternId.equals(PATTERN_ID_N))
payloadLength = symmetric.decryptOnly(message, messageOffset, payload, payloadOffset, messageEnd - messageOffset);
else
payloadLength = symmetric.decryptAndHash(message, messageOffset, payload, payloadOffset, messageEnd - messageOffset);
success = true; success = true;
return payloadLength; return payloadLength;
} finally { } finally {
......
...@@ -273,6 +273,16 @@ class SymmetricState implements Destroyable, Cloneable { ...@@ -273,6 +273,16 @@ class SymmetricState implements Destroyable, Cloneable {
return ciphertextLength; return ciphertextLength;
} }
/**
* I2P - Same as encryptAndHash() but without the post-mixHash(), for N only.
* @since 0.9.49
*/
public int encryptOnly(byte[] plaintext, int plaintextOffset, byte[] ciphertext, int ciphertextOffset, int length) throws ShortBufferException
{
int ciphertextLength = cipher.encryptWithAd(h, plaintext, plaintextOffset, ciphertext, ciphertextOffset, length);
return ciphertextLength;
}
/** /**
* Decrypts a block of ciphertext and mixes it into the handshake hash. * Decrypts a block of ciphertext and mixes it into the handshake hash.
* *
...@@ -302,6 +312,15 @@ class SymmetricState implements Destroyable, Cloneable { ...@@ -302,6 +312,15 @@ class SymmetricState implements Destroyable, Cloneable {
return cipher.decryptWithAd(prev_h, ciphertext, ciphertextOffset, plaintext, plaintextOffset, length); return cipher.decryptWithAd(prev_h, ciphertext, ciphertextOffset, plaintext, plaintextOffset, length);
} }
/**
* I2P - Same as decryptAndHash() but without the post-mixHash(), for N only.
* @since 0.9.49
*/
public int decryptOnly(byte[] ciphertext, int ciphertextOffset, byte[] plaintext, int plaintextOffset, int length) throws ShortBufferException, BadPaddingException
{
return cipher.decryptWithAd(h, ciphertext, ciphertextOffset, plaintext, plaintextOffset, length);
}
/** /**
* Splits the symmetric state into two ciphers for session encryption. * Splits the symmetric state into two ciphers for session encryption.
* *
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment