Browse Source

Fix CTR mode with applecc

pull/773/head
Max Lv 8 years ago
parent
commit
8f72416f0f
1 changed files with 34 additions and 7 deletions
  1. 41
      src/encrypt.c

41
src/encrypt.c

@ -184,9 +184,9 @@ static const CCAlgorithm supported_ciphers_applecc[CIPHER_NUM] = {
kCCAlgorithmAES, kCCAlgorithmAES,
kCCAlgorithmAES, kCCAlgorithmAES,
kCCAlgorithmAES, kCCAlgorithmAES,
kCCAlgorithmInvalid,
kCCAlgorithmInvalid,
kCCAlgorithmInvalid,
kCCAlgorithmAES,
kCCAlgorithmAES,
kCCAlgorithmAES,
kCCAlgorithmBlowfish, kCCAlgorithmBlowfish,
kCCAlgorithmInvalid, kCCAlgorithmInvalid,
kCCAlgorithmInvalid, kCCAlgorithmInvalid,
@ -201,6 +201,29 @@ static const CCAlgorithm supported_ciphers_applecc[CIPHER_NUM] = {
kCCAlgorithmInvalid kCCAlgorithmInvalid
}; };
static const CCMode supported_modes_applecc[CIPHER_NUM] = {
kCCAlgorithmInvalid,
kCCAlgorithmInvalid,
kCCModeRC4,
kCCModeCFB,
kCCModeCFB,
kCCModeCFB,
kCCModeCTR,
kCCModeCTR,
kCCModeCTR,
kCCModeCFB,
kCCAlgorithmInvalid,
kCCAlgorithmInvalid,
kCCAlgorithmInvalid,
kCCModeCFB,
kCCModeCFB,
kCCModeCFB,
kCCModeCFB,
kCCAlgorithmInvalid,
kCCAlgorithmInvalid,
kCCAlgorithmInvalid,
kCCAlgorithmInvalid
};
#endif #endif
static const int supported_ciphers_iv_size[CIPHER_NUM] = { static const int supported_ciphers_iv_size[CIPHER_NUM] = {
@ -857,11 +880,15 @@ void cipher_context_init(cipher_ctx_t *ctx, int method, int enc)
} else { } else {
cc->valid = kCCContextValid; cc->valid = kCCContextValid;
if (cc->cipher == kCCAlgorithmRC4) { if (cc->cipher == kCCAlgorithmRC4) {
cc->mode = kCCModeRC4;
cc->mode = supported_modes_applecc[method];
cc->padding = ccNoPadding; cc->padding = ccNoPadding;
} else { } else {
cc->mode = kCCModeCFB;
cc->padding = ccPKCS7Padding;
cc->mode = supported_modes_applecc[method];
if (cc->mode == kCCModeCTR) {
cc->padding = ccNoPadding;
} else {
cc->padding = ccPKCS7Padding;
}
} }
return; return;
} }
@ -959,7 +986,7 @@ void cipher_context_set_iv(cipher_ctx_t *ctx, uint8_t *iv, size_t iv_len,
cc->cipher, cc->cipher,
cc->padding, cc->padding,
cc->iv, cc->key, cc->key_len, cc->iv, cc->key, cc->key_len,
NULL, 0, 0, 0,
NULL, 0, 0, kCCModeOptionCTR_BE,
&cc->cryptor); &cc->cryptor);
if (ret != kCCSuccess) { if (ret != kCCSuccess) {
if (cc->cryptor != NULL) { if (cc->cryptor != NULL) {

Loading…
Cancel
Save