Expose internal tag length, 0 if none

This commit is contained in:
Davide De Rosa 2018-11-06 10:30:43 +01:00
parent 2fde43b1fc
commit 7ffbf41b30
6 changed files with 20 additions and 0 deletions

View File

@ -55,6 +55,7 @@ typedef struct {
- (void)configureEncryptionWithCipherKey:(nullable ZeroingData *)cipherKey hmacKey:(nullable ZeroingData *)hmacKey;
- (int)digestLength;
- (int)tagLength;
- (NSInteger)encryptionCapacityWithLength:(NSInteger)length;
- (BOOL)encryptBytes:(const uint8_t *)bytes length:(NSInteger)length dest:(uint8_t *)dest destLength:(NSInteger *)destLength flags:(const CryptoFlags *_Nullable)flags error:(NSError **)error;
@ -68,6 +69,7 @@ typedef struct {
- (void)configureDecryptionWithCipherKey:(nullable ZeroingData *)cipherKey hmacKey:(nullable ZeroingData *)hmacKey;
- (int)digestLength;
- (int)tagLength;
- (NSInteger)encryptionCapacityWithLength:(NSInteger)length;
- (BOOL)decryptBytes:(const uint8_t *)bytes length:(NSInteger)length dest:(uint8_t *)dest destLength:(NSInteger *)destLength flags:(const CryptoFlags *_Nullable)flags error:(NSError **)error;

View File

@ -97,6 +97,11 @@ static const NSInteger CryptoAEADTagLength = 16;
return 0;
}
- (int)tagLength
{
return CryptoAEADTagLength;
}
- (NSInteger)encryptionCapacityWithLength:(NSInteger)length
{
return safe_crypto_capacity(length, CryptoAEADTagLength);

View File

@ -73,6 +73,7 @@ NS_ASSUME_NONNULL_BEGIN
- (id<Decrypter>)decrypter;
- (NSInteger)digestLength;
- (NSInteger)tagLength;
@end

View File

@ -52,6 +52,7 @@
@property (nonatomic, strong) NSString *cipherAlgorithm;
@property (nonatomic, strong) NSString *digestAlgorithm;
@property (nonatomic, assign) NSInteger digestLength;
@property (nonatomic, assign) NSInteger tagLength;
@property (nonatomic, strong) id<Encrypter> encrypter;
@property (nonatomic, strong) id<Decrypter> decrypter;
@ -147,6 +148,7 @@
NSAssert(self.encrypter.digestLength == self.decrypter.digestLength, @"Digest length mismatch in encrypter/decrypter");
self.digestLength = self.encrypter.digestLength;
self.tagLength = self.encrypter.tagLength;
return YES;
}

View File

@ -113,6 +113,11 @@ const NSInteger CryptoCBCMaxHMACLength = 100;
self.digest = NULL;
}
- (int)tagLength
{
return 0;
}
- (NSInteger)encryptionCapacityWithLength:(NSInteger)length
{
return safe_crypto_capacity(length, self.digestLength + self.cipherIVLength);

View File

@ -95,6 +95,11 @@ static const NSInteger CryptoCTRTagLength = 32;
self.digest = NULL;
}
- (int)tagLength
{
return CryptoCTRTagLength;
}
- (NSInteger)encryptionCapacityWithLength:(NSInteger)length
{
return safe_crypto_capacity(length, PacketOpcodeLength + PacketSessionIdLength + PacketReplayIdLength + PacketReplayTimestampLength + CryptoCTRTagLength);