From d2a6fa4d6d02cc1acff27d3284845bf8a18b72dd Mon Sep 17 00:00:00 2001 From: DrKLO Date: Mon, 23 Dec 2013 15:54:31 +0400 Subject: [PATCH] fixed last commit --- .../java/org/telegram/messenger/HandshakeAction.java | 4 ++-- .../org/telegram/messenger/MessagesController.java | 4 ++-- .../main/java/org/telegram/messenger/Utilities.java | 10 ++-------- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/HandshakeAction.java b/TMessagesProj/src/main/java/org/telegram/messenger/HandshakeAction.java index afa92044d..a0673e421 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/HandshakeAction.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/HandshakeAction.java @@ -345,12 +345,12 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti } BigInteger p = new BigInteger(1, dhInnerData.dh_prime); - BigInteger g_b = BigInteger.valueOf(dhInnerData.g); BigInteger g_a = new BigInteger(1, dhInnerData.g_a); - if (!Utilities.isGoodGaAndGb(g_a, g_b, p)) { + if (!Utilities.isGoodGaAndGb(g_a, p)) { throw new RuntimeException("bad prime"); } + BigInteger g_b = BigInteger.valueOf(dhInnerData.g); g_b = g_b.modPow(new BigInteger(1, b), p); g_a = g_a.modPow(new BigInteger(1, b), p); diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java b/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java index 8445b6066..42350fd35 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java @@ -4814,7 +4814,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter BigInteger p = new BigInteger(1, MessagesStorage.secretPBytes); BigInteger i_authKey = new BigInteger(1, encryptedChat.g_a_or_b); - if (!Utilities.isGoodGaAndGb(null, i_authKey, p)) { + if (!Utilities.isGoodGaAndGb(i_authKey, p)) { declineSecretChat(encryptedChat.id); return; } @@ -4911,7 +4911,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter g_b = g_b.modPow(new BigInteger(1, salt), p); BigInteger g_a = new BigInteger(1, encryptedChat.g_a); - if (!Utilities.isGoodGaAndGb(g_a, g_b, p)) { + if (!Utilities.isGoodGaAndGb(g_a, p)) { acceptingChats.remove(encryptedChat.id); declineSecretChat(encryptedChat.id); return; diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/Utilities.java b/TMessagesProj/src/main/java/org/telegram/messenger/Utilities.java index 04b4cb12a..912bf2407 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/Utilities.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/Utilities.java @@ -124,14 +124,8 @@ public class Utilities { return true; } - public static boolean isGoodGaAndGb(BigInteger g_a, BigInteger g_b, BigInteger p) { - if (g_a != null && g_a.compareTo(BigInteger.valueOf(1)) != 1) { - return false; - } - if (g_b != null && p != null && g_b.compareTo(p.subtract(BigInteger.valueOf(1))) != -1) { - return false; - } - return true; + public static boolean isGoodGaAndGb(BigInteger g_a, BigInteger p) { + return !(g_a.compareTo(BigInteger.valueOf(1)) != 1 || g_a.compareTo(p.subtract(BigInteger.valueOf(1))) != -1); } public static TPFactorizedValue getFactorizedValue(long what) {