Fix message packing
This commit is contained in:
parent
d9928e79dd
commit
a08966d8ec
|
@ -38,8 +38,8 @@ public class MTProtoState {
|
||||||
|
|
||||||
private Pair<byte[], byte[]> calcKey(final byte[] msgKey, final boolean client) {
|
private Pair<byte[], byte[]> calcKey(final byte[] msgKey, final boolean client) {
|
||||||
final int x = client ? 0 : 8;
|
final int x = client ? 0 : 8;
|
||||||
final byte[] sha256a = Utils.sha256digest(msgKey, ByteBuffer.wrap(authKey.key, x, 36).array());
|
final byte[] sha256a = Utils.sha256digest(msgKey, Arrays.copyOfRange(authKey.key, x, x + 36));
|
||||||
final byte[] sha256b = Utils.sha256digest(ByteBuffer.wrap(authKey.key, x + 40, 36).array(), msgKey);
|
final byte[] sha256b = Utils.sha256digest(Arrays.copyOfRange(authKey.key, x + 40, x + 76), msgKey);
|
||||||
|
|
||||||
final BinaryWriter writer = new BinaryWriter(32);
|
final BinaryWriter writer = new BinaryWriter(32);
|
||||||
writer.writeRaw(sha256a, 0, 8);
|
writer.writeRaw(sha256a, 0, 8);
|
||||||
|
@ -61,9 +61,7 @@ public class MTProtoState {
|
||||||
writer.write(message);
|
writer.write(message);
|
||||||
|
|
||||||
int padding = writer.size() % 16;
|
int padding = writer.size() % 16;
|
||||||
if (padding != 0) {
|
writer.writeRaw(Utils.randomBytes(32 - padding));
|
||||||
writer.writeRaw(Utils.randomBytes(16 - padding));
|
|
||||||
}
|
|
||||||
|
|
||||||
final byte[] paddedData = writer.toBytes();
|
final byte[] paddedData = writer.toBytes();
|
||||||
writer.clear();
|
writer.clear();
|
||||||
|
|
Loading…
Reference in New Issue