From 4cf9a68a196b1adc91457a93dff1c97eeedfa0eb Mon Sep 17 00:00:00 2001 From: Peter Date: Tue, 18 Apr 2017 19:52:37 +0300 Subject: [PATCH] no message --- MTNetworkUsageManager.h | 2 +- MTNetworkUsageManager.m | 6 +++++- MTProtoKit/MTEncryption.m | 6 ++++++ MTProtoKit/MTProto.m | 6 +++++- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/MTNetworkUsageManager.h b/MTNetworkUsageManager.h index d9d2b401f6..4bca6b5704 100644 --- a/MTNetworkUsageManager.h +++ b/MTNetworkUsageManager.h @@ -20,7 +20,7 @@ typedef struct { - (void)addIncomingBytes:(NSUInteger)incomingBytes interface:(MTNetworkUsageManagerInterface)interface; - (void)addOutgoingBytes:(NSUInteger)outgoingBytes interface:(MTNetworkUsageManagerInterface)interface; -- (void)resetKeys:(NSArray *)keys completion:(void (^)())completion; +- (void)resetKeys:(NSArray *)keys setKeys:(NSDictionary *)setKeys completion:(void (^)())completion; - (MTSignal *)currentStatsForKeys:(NSArray *)keys; @end diff --git a/MTNetworkUsageManager.m b/MTNetworkUsageManager.m index 816482459d..01af91d6b6 100644 --- a/MTNetworkUsageManager.m +++ b/MTNetworkUsageManager.m @@ -103,13 +103,17 @@ static int offsetForInterface(MTNetworkUsageCalculationInfo *info, MTNetworkUsag }]; } -- (void)resetKeys:(NSArray *)keys completion:(void (^)())completion { +- (void)resetKeys:(NSArray *)keys setKeys:(NSDictionary *)setKeys completion:(void (^)())completion { [_queue dispatchOnQueue:^{ if (_map) { for (NSNumber *key in keys) { int64_t *ptr = (int64_t *)(_map + [key intValue] * 8); *ptr = 0; } + [setKeys enumerateKeysAndObjectsUsingBlock:^(NSNumber *key, NSNumber *value, __unused BOOL *stop) { + int64_t *ptr = (int64_t *)(_map + [key intValue] * 8); + *ptr = [value longLongValue]; + }]; if (completion) { completion(); } diff --git a/MTProtoKit/MTEncryption.m b/MTProtoKit/MTEncryption.m index 426ae9b0be..259d201bd4 100644 --- a/MTProtoKit/MTEncryption.m +++ b/MTProtoKit/MTEncryption.m @@ -305,10 +305,16 @@ NSData *MTExp(NSData *base, NSData *exp, NSData *modulus) { BN_CTX *ctx = BN_CTX_new(); BIGNUM *bnBase = BN_bin2bn(base.bytes, (int)base.length, NULL); + BN_set_flags(bnBase, BN_FLG_CONSTTIME); + BIGNUM *bnExp = BN_bin2bn(exp.bytes, (int)exp.length, NULL); + BN_set_flags(bnExp, BN_FLG_CONSTTIME); + BIGNUM *bnModulus = BN_bin2bn(modulus.bytes, (int)modulus.length, NULL); + BN_set_flags(bnModulus, BN_FLG_CONSTTIME); BIGNUM *bnRes = BN_new(); + BN_set_flags(bnModulus, BN_FLG_CONSTTIME); BN_mod_exp(bnRes, bnBase, bnExp, bnModulus, ctx); diff --git a/MTProtoKit/MTProto.m b/MTProtoKit/MTProto.m index 0c1d30fbc4..121f693045 100644 --- a/MTProtoKit/MTProto.m +++ b/MTProtoKit/MTProto.m @@ -1765,8 +1765,12 @@ static const NSUInteger MTMaxUnacknowledgedMessageCount = 64; int32_t messageDataLength = 0; [decryptedData getBytes:&messageDataLength range:NSMakeRange(28, 4)]; - if (messageDataLength < 0 || messageDataLength > (int32_t)decryptedData.length) + if (messageDataLength < 0 || messageDataLength > (int32_t)decryptedData.length) { +#if MTProtoV2 + __unused NSData *result = MTSha256(decryptedData); +#endif return nil; + } #if MTProtoV2 int xValue = 8;