Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MKCryptState: fix initialization of CryptState class. #54

Merged
merged 1 commit into from
Sep 3, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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