objective c - CCCrypt decrypting in AES CBC works even without IV -


i have confusing problem, decrypting file encrypted using cccrypt's aes-cbc mode randomized, 16byte iv produces exact same output whether pass in same correct iv used encryption or none @ all.

what expect: using null iv decrypting should not result in correct decryption. observe: using null iv results in same result iv used encryption.

below sake of completeness, here's important code snippets, iv passed in 16-byte securely randomized nsdata.

what not understanding here? cccrypt somehow figuring out iv encrypted data itself? couldn't find around in docs.

- (nsdata *)encrypteddatafordata:(nsdata *)rawdata                          withkey:(nsdata *)key                               iv:(nsdata *)iv                            error:(nserror __autoreleasing**)error {     size_t outlength;     nsmutabledata *cipherdata = [nsmutabledata datawithlength:rawdata.length + kalgorithmblocksize];      cccryptorstatus result = cccrypt(kccencrypt,                                      kccalgorithmaes128,                                      kccoptionpkcs7padding | kccmodecbc,                                      key.bytes,                                      key.length,                                      iv.bytes,                                      rawdata.bytes,                                      rawdata.length,                                      cipherdata.mutablebytes,                                      cipherdata.length,                                      &outlength);     if (result == kccsuccess) {         cipherdata.length = outlength;         return cipherdata;     } else {         return nil;     } }  - (nsdata *)decrypteddatafordata:(nsdata *)encrypteddata withkey:(nsdata *)key error:(nserror __autoreleasing**)error {     size_t outlength;     nsmutabledata *decrypteddata = [nsmutabledata datawithlength:encrypteddata.length];      // line illustrate how setting exact same iv here - if 1     // used encryption - results in same output when passing iv = null     nsdata *iv = [cryptor dataforhex:@"724a7fc0 0d8ac9d5 f09ff4c1 64d2d1bb"];      cccryptorstatus result = cccrypt(kccdecrypt,                                      kccalgorithmaes128,                                      kccoptionpkcs7padding | kccmodecbc,                                      key.bytes,                                      key.length,                                      iv.bytes, // iv or null --> same result o_o                                      encrypteddata.bytes,                                      encrypteddata.length,                                      decrypteddata.mutablebytes,                                      decrypteddata.length,                                      &outlength);     if (result == kccsuccess) {         decrypteddata.length = outlength;         return decrypteddata;     } else {         return nil;     } } 

edit:

to elaborate on this, no matter iv use decryption (tried out couple of different randomized iv's) byte byte identical results. when decrypt partial chunk of encrypted file somewhere middle of encrypted file.

is maybe related actual data en/decrypting (mp3 files)?

when pass arbitrary chunk of actual encrypted file decryptor, shouldn't require block right before chunk of data (which not provide explicitly iv) proper decryption? explanation think of here cccrypt uses first 16-bytes iv , not decrypt drops them in output.

edit 2:

output of en/decryption, showing first 2 blocks of in , output data, key , iv:

# encryption data <4cd9b050 30c04bf9 2a0cb024 19010a31 400c2261 0069196a d77bcae6 9799ae26> iv <724a7fc0 0d8ac9d5 f09ff4c1 64d2d1bb> key <78656a1a 337fddd6 fa52e34d 9156d187> encrypted <cf85cdbe 10a87309 a6fb4c4e ce640619 8f445b70 3738018a e78291a7 b4ea26ce>  # decryption correct iv data <cf85cdbe 10a87309 a6fb4c4e ce640619 8f445b70 3738018a e78291a7 b4ea26ce> iv <724a7fc0 0d8ac9d5 f09ff4c1 64d2d1bb> key <78656a1a 337fddd6 fa52e34d 9156d187> decrypted <4cd9b050 30c04bf9 2a0cb024 19010a31 400c2261 0069196a d77bcae6 9799ae26>  # decryption 0 iv data <cf85cdbe 10a87309 a6fb4c4e ce640619 8f445b70 3738018a e78291a7 b4ea26ce> iv <00000000 00000000 00000000 00000000> key <78656a1a 337fddd6 fa52e34d 9156d187> decrypted <4cd9b050 30c04bf9 2a0cb024 19010a31 400c2261 0069196a d77bcae6 9799ae26>  # decryption different iv data <cf85cdbe 10a87309 a6fb4c4e ce640619 8f445b70 3738018a e78291a7 b4ea26ce> iv <12345678 9abcdef1 23456789 abcdef12> key <78656a1a 337fddd6 fa52e34d 9156d187> decrypted <4cd9b050 30c04bf9 2a0cb024 19010a31 400c2261 0069196a d77bcae6 9799ae26> 

edit 3:

the code -dataforhex: is:

+ (nsdata *)dataforhex:(nsstring *)hex {     nsstring *hexnospaces = [[[hex stringbyreplacingoccurrencesofstring:@" " withstring:@""]             stringbyreplacingoccurrencesofstring:@"<" withstring:@""]             stringbyreplacingoccurrencesofstring:@">" withstring:@""];      nsmutabledata *data = [[nsmutabledata alloc] init];     unsigned char whole_byte = 0;     char byte_chars[3] = {'\0','\0','\0'};     (nsuinteger = 0; < [hexnospaces length] / 2; i++) {         byte_chars[0] = (unsigned char) [hexnospaces characteratindex:(nsuinteger) (i * 2)];         byte_chars[1] = (unsigned char) [hexnospaces characteratindex:(nsuinteger) (i * 2 + 1)];         whole_byte = (unsigned char)strtol(byte_chars, null, 16);         [data appendbytes:&whole_byte length:1];     }     return data; } 

used formatting comment.

with iv:

clear data:   <4cd9b050 30c04bf9 2a0cb024 19010a31> iv data:      <724a7fc0 0d8ac9d5 f09ff4c1 64d2d1bb> key data:     <78656a1a 337fddd6 fa52e34d 9156d187> crypt data:   <d2c2efee 54e43781 549eec03 9db688e1 7c4248e7 e2ac1d80 7105ffae 4043ffb3> decrypt data: <4cd9b050 30c04bf9 2a0cb024 19010a31> 

with iv of 0's:

clear data:   <4cd9b050 30c04bf9 2a0cb024 19010a31> iv data:      <00000000 00000000 00000000 00000000> key data:     <78656a1a 337fddd6 fa52e34d 9156d187> crypt data:   <cf85cdbe 10a87309 a6fb4c4e ce640619 6be7b155 9db3f066 97e461e7 ced7960f> decrypt data: <4cd9b050 30c04bf9 2a0cb024 19010a31> 

it clear iv not being used in op code.

code above:

cccryptorstatus ccstatus   = kccsuccess; size_t          cryptbytes = 0; nsmutabledata  *dataout    = [nsmutabledata datawithlength:datain.length + kccblocksizeaes128];  ccstatus = cccrypt( encryptordecrypt, // kccencrypt or kccdecrypt                    kccalgorithmaes128,                    kccoptionpkcs7padding,                    key.bytes,                     kcckeysizeaes128,                    iv.bytes,                    datain.bytes,                    datain.length,                    dataout.mutablebytes,                    dataout.length,                    &cryptbytes);  dataout.length = cryptbytes; 

Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -