Skip to content

Commit

Permalink
Merge PR #54: MKCryptState: fix initialization of CryptState class.
Browse files Browse the repository at this point in the history
  • Loading branch information
mkrautz authored Sep 3, 2017
2 parents 5af6446 + 0c9e4d6 commit d42c780
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions src/MKCryptState_openssl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,8 @@

using namespace MumbleClient;

struct MKCryptStatePrivate {
CryptState cs;
};

@interface MKCryptState () {
struct MKCryptStatePrivate *_priv;
CryptState *_cs;
}
@end

Expand All @@ -32,35 +28,35 @@ - (id) init {
if (self == nil)
return nil;

_priv = (struct MKCryptStatePrivate *) malloc(sizeof(struct MKCryptStatePrivate));
_cs = new CryptState;

return self;
}

- (void) dealloc {
free(_priv);
delete _cs;

[super dealloc];
}

- (BOOL) valid {
return (BOOL)_priv->cs.isValid();
return (BOOL)_cs->isValid();
}

- (void) generateKey {
_priv->cs.genKey();
_cs->genKey();
}

- (void) setKey:(NSData *)key eiv:(NSData *)enc div:(NSData *)dec {
NSAssert([key length] == AES_BLOCK_SIZE, @"key length not AES_BLOCK_SIZE");
NSAssert([enc length] == AES_BLOCK_SIZE, @"enc length not AES_BLOCK_SIZE");
NSAssert([dec length] == AES_BLOCK_SIZE, @"dec length not AES_BLOCK_SIZE");
_priv->cs.setKey((const unsigned char *)[key bytes], (const unsigned char *)[enc bytes], (const unsigned char *)[dec bytes]);
_cs->setKey((const unsigned char *)[key bytes], (const unsigned char *)[enc bytes], (const unsigned char *)[dec bytes]);
}

- (void) setDecryptIV:(NSData *)dec {
NSAssert([dec length] == AES_BLOCK_SIZE, @"dec length not AES_BLOCK_SIZE");
_priv->cs.setDecryptIV((const unsigned char *)[dec bytes]);
_cs->setDecryptIV((const unsigned char *)[dec bytes]);

}

Expand All @@ -70,7 +66,7 @@ - (NSData *) encryptData:(NSData *)data {
}

NSMutableData *crypted = [[NSMutableData alloc] initWithLength:[data length]+4];
_priv->cs.encrypt((const unsigned char *)[data bytes], (unsigned char *)[crypted mutableBytes], (unsigned int)[data length]);
_cs->encrypt((const unsigned char *)[data bytes], (unsigned char *)[crypted mutableBytes], (unsigned int)[data length]);
return [crypted autorelease];
}

Expand All @@ -83,7 +79,7 @@ - (NSData *) decryptData:(NSData *)data {
}

NSMutableData *plain = [[NSMutableData alloc] initWithLength:[data length]-4];
if (_priv->cs.decrypt((const unsigned char *)[data bytes], (unsigned char *)[plain mutableBytes], (unsigned int)[data length])) {
if (_cs->decrypt((const unsigned char *)[data bytes], (unsigned char *)[plain mutableBytes], (unsigned int)[data length])) {
return [plain autorelease];
} else {
[plain release];
Expand Down

0 comments on commit d42c780

Please sign in to comment.