//
// EVP_CipherInit_ex from 0x802f0c to 0x803328 (1052 bytes)
//
// 32 xrefs:
// > ssl3_change_cipher_state @ 0x7b82bc
// > tls1_change_cipher_state @ 0x7ba414
// > tls1_change_cipher_state @ 0x7ba490
// > tls1_change_cipher_state @ 0x7ba6b8
// > tls1_change_cipher_state @ 0x7ba74c
// > sub_8011CC @ 0x80129c
// > EVP_CipherInit @ 0x803390
// > EVP_EncryptInit_ex @ 0x8033ec
// > EVP_DecryptInit_ex @ 0x803410
// > PKCS12_PBE_keyivgen @ 0x824000
// > PKCS7_dataInit @ 0x826dd0
// > PKCS7_dataInit @ 0x826e1c
// > PKCS7_dataDecode @ 0x8276d8
// > PKCS7_dataDecode @ 0x82778c
// > CMS_RecipientInfo_kari_decrypt @ 0x87490c
// > cms_RecipientInfo_kari_encrypt @ 0x874d78
// > cms_RecipientInfo_pwri_crypt @ 0x8763e8
// > sub_8B509C @ 0x8b5210
// > BIO_set_cipher @ 0x8b5360
// > BIO_set_cipher @ 0x8b53b8
// > PKCS5_PBE_keyivgen @ 0x8b8118
// > PKCS5_v2_PBE_keyivgen @ 0x8b87d0
// > PKCS5_v2_PBKDF2_keyivgen @ 0x8b8acc
// > PKCS5_pbe2_set_iv @ 0x8c727c
// > PKCS5_pbe2_set_scrypt @ 0x8c7588
// > PKCS5_v2_scrypt_keyivgen @ 0x8c7a80
// > cms_EncryptedContent_init_bio @ 0x8cf490
// > cms_EncryptedContent_init_bio @ 0x8cf528
// > cms_EncryptedContent_init_bio @ 0x8cf5a8
// > cms_EncryptedContent_init_bio @ 0x8cf64c
// > cms_EncryptedContent_init_bio @ 0x8cf830
// > ??> @ 0x5dd1c
//
// This function is hookable on this platform!
//
// Using BromaIDA 8.0.0 @ https://github.com/Stazzical/BromaIDA
// Using bindings at commit ba9f177b at Thu Jul 16 22:52:06 2026 from https://github.com/geode-sdk/bindings
//
int __fastcall EVP_CipherInit_ex(int *a1, int *a2, _DWORD *cipher_engine, int a4, void *a5, int a6)
{
int *cipher; // r7
int v10; // r6
int *v11; // r3
int v12; // r5
int v13; // r0
int v14; // r0
int v15; // r2
int v16; // r2
int v18; // r5
int v19; // r0
int v20; // r3
int v22; // r0
int v23; // r0
size_t v24; // r0
size_t v25; // r0
int v26; // r0
size_t v27; // r0
cipher = a2;
if ( a6 == -1 )
{
v10 = a1[2];
}
else
{
v10 = a6 != 0;
a1[2] = v10;
}
v11 = (int *)*a1;
if ( a1[1] )
{
if ( v11 )
{
if ( !a2 || *a2 == *v11 )
goto LABEL_16;
goto LABEL_8;
}
if ( !a2 )
{
LABEL_38:
ERR_put_error(6, 123, 131, (int)"crypto/evp/evp_enc.c", 144);
return 0;
}
}
else
{
if ( !a2 )
{
if ( v11 )
goto LABEL_16;
goto LABEL_38;
}
if ( v11 )
{
LABEL_8:
v12 = a1[23];
EVP_CIPHER_CTX_reset(a1);
a1[23] = v12;
a1[2] = v10;
}
}
if ( !cipher_engine )
{
cipher_engine = (_DWORD *)ENGINE_get_cipher_engine(*cipher);
if ( !cipher_engine )
goto LABEL_12;
goto LABEL_11;
}
if ( ENGINE_init(cipher_engine) )
{
LABEL_11:
cipher = (int *)ENGINE_get_cipher((int)cipher_engine, *cipher);
if ( !cipher )
{
v18 = 0;
ERR_put_error(6, 123, 134, (int)"crypto/evp/evp_enc.c", 110);
return v18;
}
LABEL_12:
v13 = cipher[8];
a1[1] = (int)cipher_engine;
*a1 = (int)cipher;
if ( v13 )
{
v26 = CRYPTO_zalloc(v13, "crypto/evp/evp_enc.c", 126);
v18 = v26;
a1[24] = v26;
if ( !v26 )
{
ERR_put_error(6, 123, 65, (int)"crypto/evp/evp_enc.c", 128);
return v18;
}
v11 = (int *)*a1;
}
else
{
v11 = cipher;
a1[24] = 0;
}
v14 = v11[4];
v15 = a1[23] & 1;
a1[22] = cipher[2];
a1[23] = v15;
if ( (v14 & 0x40) != 0 )
{
v18 = EVP_CIPHER_CTX_ctrl((int)a1);
if ( !v18 )
{
ERR_put_error(6, 123, 134, (int)"crypto/evp/evp_enc.c", 139);
return v18;
}
v11 = (int *)*a1;
}
LABEL_16:
v16 = v11[1];
if ( v16 != 1 && ((v16 - 8) & 0xFFFFFFF7) != 0 )
OPENSSL_die(
"assertion failed: ctx->cipher->block_size == 1 || ctx->cipher->block_size == 8 || ctx->cipher->block_size == 16",
"crypto/evp/evp_enc.c",
153);
v18 = a1[23] & 1;
if ( !v18 )
{
v22 = EVP_CIPHER_CTX_cipher(a1);
if ( (EVP_CIPHER_flags(v22) & 0xF0007) == 0x10002 )
{
ERR_put_error(6, 123, 170, (int)"crypto/evp/evp_enc.c", 157);
return v18;
}
}
v19 = EVP_CIPHER_CTX_cipher(a1);
if ( (EVP_CIPHER_flags(v19) & 0x10) == 0 )
{
v23 = EVP_CIPHER_CTX_cipher(a1);
switch ( EVP_CIPHER_flags(v23) & 0xF0007 )
{
case 0:
case 1:
break;
case 2:
goto LABEL_40;
case 3:
case 4:
a1[20] = 0;
LABEL_40:
if ( EVP_CIPHER_CTX_iv_length(a1) > 16 )
OPENSSL_die(
"assertion failed: EVP_CIPHER_CTX_iv_length(ctx) <= (int)sizeof(ctx->iv)",
"crypto/evp/evp_enc.c",
177);
if ( a5 )
{
v24 = EVP_CIPHER_CTX_iv_length(a1);
memcpy(a1 + 4, a5, v24);
}
v25 = EVP_CIPHER_CTX_iv_length(a1);
memcpy(a1 + 8, a1 + 4, v25);
break;
case 5:
a1[20] = 0;
if ( a5 )
{
v27 = EVP_CIPHER_CTX_iv_length(a1);
memcpy(a1 + 8, a5, v27);
}
break;
default:
return 0;
}
}
v20 = *a1;
if ( a4 || (*(_DWORD *)(v20 + 16) & 0x20) != 0 )
{
v18 = (*(int (__fastcall **)(int *, int, void *, int))(v20 + 20))(a1, a4, a5, v10);
if ( !v18 )
return v18;
v20 = *a1;
}
v18 = 1;
a1[26] = *(_DWORD *)(v20 + 4) - 1;
a1[3] = 0;
a1[25] = 0;
return v18;
}
ERR_put_error(6, 123, 134, (int)"crypto/evp/evp_enc.c", 95);
return 0;
}