//
// EVP_CipherInit_ex from 0xda9d24 to 0xdaa12c (1032 bytes)
//
// 32 xrefs:
// > ssl3_change_cipher_state @ 0xd5ee04
// > tls1_change_cipher_state @ 0xd60d98
// > tls1_change_cipher_state @ 0xd60e00
// > tls1_change_cipher_state @ 0xd61010
// > tls1_change_cipher_state @ 0xd61090
// > sub_DA7C88 @ 0xda7d20
// > EVP_CipherInit @ 0xdaa17c
// > EVP_EncryptInit_ex @ 0xdaa194
// > EVP_DecryptInit_ex @ 0xdaa19c
// > PKCS12_PBE_keyivgen @ 0xdc98b0
// > PKCS7_dataInit @ 0xdcc6f0
// > PKCS7_dataInit @ 0xdcc72c
// > PKCS7_dataDecode @ 0xdccf3c
// > PKCS7_dataDecode @ 0xdccfe0
// > CMS_RecipientInfo_kari_decrypt @ 0xe1f204
// > cms_RecipientInfo_kari_encrypt @ 0xe1f6ac
// > cms_RecipientInfo_pwri_crypt @ 0xe20da4
// > sub_E5EF10 @ 0xe5f0c8
// > BIO_set_cipher @ 0xe5f22c
// > BIO_set_cipher @ 0xe5f28c
// > PKCS5_PBE_keyivgen @ 0xe622c4
// > PKCS5_v2_PBE_keyivgen @ 0xe62bdc
// > PKCS5_v2_PBKDF2_keyivgen @ 0xe62f70
// > PKCS5_pbe2_set_iv @ 0xe72c18
// > PKCS5_pbe2_set_scrypt @ 0xe72ef4
// > PKCS5_v2_scrypt_keyivgen @ 0xe7337c
// > cms_EncryptedContent_init_bio @ 0xe7b138
// > cms_EncryptedContent_init_bio @ 0xe7b1d0
// > cms_EncryptedContent_init_bio @ 0xe7b260
// > cms_EncryptedContent_init_bio @ 0xe7b2f0
// > cms_EncryptedContent_init_bio @ 0xe7b4e0
// > ??> @ 0x97a28
//
// 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
//
__int64 __fastcall EVP_CipherInit_ex(
__int64 a1,
unsigned int *a2,
__int64 cipher_engine,
__int64 a4,
const void *a5,
int a6)
{
unsigned int *cipher; // x20
unsigned int v11; // w23
__int64 v12; // x5
__int64 v13; // x21
signed int v14; // w0
__int64 v15; // x1
__int64 v16; // x0
int v17; // w0
unsigned int v18; // w21
__int64 v19; // x0
__int64 v20; // x0
int v21; // w0
__int64 v23; // x0
__int64 v24; // x0
unsigned __int64 v25; // x0
__int64 v26; // x0
const void *v27; // x20
int v28; // w0
int v29; // w0
int v30; // w0
cipher = a2;
if ( a6 == -1 )
{
v11 = *(_DWORD *)(a1 + 16);
if ( *(_QWORD *)(a1 + 8) )
{
LABEL_3:
v12 = *(_QWORD *)a1;
if ( *(_QWORD *)a1 )
{
if ( !a2 || *a2 == *(_DWORD *)v12 )
goto LABEL_13;
goto LABEL_6;
}
if ( !a2 )
{
LABEL_36:
v18 = 0;
ERR_put_error(6, 123, 131, (__int64)"crypto/evp/evp_enc.c", 144);
return v18;
}
goto LABEL_7;
}
}
else
{
v11 = a6 != 0;
*(_DWORD *)(a1 + 16) = v11;
if ( *(_QWORD *)(a1 + 8) )
goto LABEL_3;
}
if ( !a2 )
{
v12 = *(_QWORD *)a1;
if ( *(_QWORD *)a1 )
goto LABEL_13;
goto LABEL_36;
}
if ( *(_QWORD *)a1 )
{
LABEL_6:
v13 = *(_QWORD *)(a1 + 112);
EVP_CIPHER_CTX_reset((__int64 *)a1);
*(_DWORD *)(a1 + 16) = v11;
*(_QWORD *)(a1 + 112) = v13;
}
LABEL_7:
if ( !cipher_engine )
{
cipher_engine = ENGINE_get_cipher_engine(*cipher);
if ( !cipher_engine )
goto LABEL_10;
goto LABEL_9;
}
if ( (unsigned int)ENGINE_init(cipher_engine) )
{
LABEL_9:
cipher = (unsigned int *)ENGINE_get_cipher(cipher_engine, *cipher);
if ( !cipher )
{
v18 = 0;
ERR_put_error(6, 123, 134, (__int64)"crypto/evp/evp_enc.c", 110);
return v18;
}
LABEL_10:
v14 = cipher[12];
*(_QWORD *)(a1 + 8) = cipher_engine;
*(_QWORD *)a1 = cipher;
if ( v14 )
{
v26 = CRYPTO_zalloc(v14, "crypto/evp/evp_enc.c", 126);
*(_QWORD *)(a1 + 120) = v26;
v18 = v26;
if ( !v26 )
{
ERR_put_error(6, 123, 65, (__int64)"crypto/evp/evp_enc.c", 128);
return v18;
}
v12 = *(_QWORD *)a1;
}
else
{
*(_QWORD *)(a1 + 120) = 0;
v12 = (__int64)cipher;
}
v15 = *(_QWORD *)(v12 + 16);
v16 = *(_QWORD *)(a1 + 112) & 1LL;
*(_DWORD *)(a1 + 104) = cipher[2];
*(_QWORD *)(a1 + 112) = v16;
if ( (v15 & 0x40) != 0 )
{
v18 = EVP_CIPHER_CTX_ctrl(a1);
if ( !v18 )
{
ERR_put_error(6, 123, 134, (__int64)"crypto/evp/evp_enc.c", 139);
return v18;
}
v17 = *(_DWORD *)(*(_QWORD *)a1 + 4LL);
if ( ((v17 - 8) & 0xFFFFFFF7) == 0 )
{
LABEL_15:
v18 = *(_QWORD *)(a1 + 112) & 1;
if ( !v18 )
{
v23 = EVP_CIPHER_CTX_cipher(a1);
if ( (EVP_CIPHER_flags(v23) & 0xF0007) == 0x10002 )
{
ERR_put_error(6, 123, 170, (__int64)"crypto/evp/evp_enc.c", 157);
return v18;
}
}
v19 = EVP_CIPHER_CTX_cipher(a1);
if ( (EVP_CIPHER_flags(v19) & 0x10) == 0 )
{
v24 = EVP_CIPHER_CTX_cipher(a1);
v25 = EVP_CIPHER_flags(v24) & 0xF0007;
if ( v25 > 5 )
return 0;
switch ( (int)v25 )
{
case 0:
case 1:
break;
case 2:
goto LABEL_44;
case 3:
case 4:
*(_DWORD *)(a1 + 88) = 0;
LABEL_44:
if ( (int)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);
v27 = (const void *)(a1 + 24);
if ( a5 )
{
v27 = (const void *)(a1 + 24);
v28 = EVP_CIPHER_CTX_iv_length(a1);
memcpy((void *)(a1 + 24), a5, v28);
}
v29 = EVP_CIPHER_CTX_iv_length(a1);
memcpy((void *)(a1 + 40), v27, v29);
break;
case 5:
*(_DWORD *)(a1 + 88) = 0;
if ( a5 )
{
v30 = EVP_CIPHER_CTX_iv_length(a1);
memcpy((void *)(a1 + 40), a5, v30);
}
break;
}
}
v20 = *(_QWORD *)a1;
if ( a4 || (*(_QWORD *)(v20 + 16) & 0x20) != 0 )
{
v18 = (*(__int64 (__fastcall **)(__int64, __int64, const void *, _QWORD))(v20 + 24))(a1, a4, a5, v11);
if ( !v18 )
return v18;
v20 = *(_QWORD *)a1;
}
v21 = *(_DWORD *)(v20 + 4);
v18 = 1;
*(_DWORD *)(a1 + 20) = 0;
*(_DWORD *)(a1 + 128) = 0;
*(_DWORD *)(a1 + 132) = v21 - 1;
return v18;
}
LABEL_14:
if ( v17 != 1 )
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);
goto LABEL_15;
}
LABEL_13:
v17 = *(_DWORD *)(v12 + 4);
if ( ((v17 - 8) & 0xFFFFFFF7) == 0 )
goto LABEL_15;
goto LABEL_14;
}
ERR_put_error(6, 123, 134, (__int64)"crypto/evp/evp_enc.c", 95);
return 0;
}