//
// PEM_read_bio_PrivateKey from 0x823410 to 0x823640 (560 bytes)
//
// 8 xrefs:
// > SSL_use_PrivateKey_file @ 0x79c0d0
// > SSL_CTX_use_PrivateKey_file @ 0x79c99c
// > PEM_read_bio_RSAPrivateKey @ 0x82072c
// > PEM_read_bio_DSAPrivateKey @ 0x820abc
// > PEM_read_bio_ECPrivateKey @ 0x820e4c
// > PEM_read_PrivateKey @ 0x823954
// > sub_8B3A24 @ 0x8b3a6c
// > ??> @ 0x5c90c
//
// 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 PEM_read_bio_PrivateKey(
_DWORD *a1,
int *a2,
int (__fastcall *a3)(char *, int, _DWORD, const char *),
const char *a4)
{
int result; // r0
char *v8; // r4
int v9; // r4
int v10; // r0
int v11; // r5
int v12; // r0
int v13; // r4
signed int v14; // r2
int *str; // r0
char *v16; // [sp+10h] [bp-414h] BYREF
_BYTE *v17; // [sp+14h] [bp-410h] BYREF
_BYTE *v18; // [sp+18h] [bp-40Ch] BYREF
unsigned int v19; // [sp+1Ch] [bp-408h] BYREF
char v20[1028]; // [sp+20h] [bp-404h] BYREF
v16 = nullptr;
v17 = nullptr;
v18 = nullptr;
result = PEM_bytes_read_bio(&v18, &v19, &v16, "ANY PRIVATE KEY", a1, a3, a4);
if ( result )
{
v8 = v16;
v17 = v18;
if ( !strcmp(v16, "PRIVATE KEY") )
{
v12 = d2i_PKCS8_PRIV_KEY_INFO(0, (int)&v17, v19);
v11 = v12;
if ( !v12 )
goto LABEL_21;
}
else
{
if ( strcmp(v8, "ENCRYPTED PRIVATE KEY") )
{
v14 = pem_check_suffix(v8, "PRIVATE KEY");
if ( v14 <= 0 )
goto LABEL_21;
str = (int *)EVP_PKEY_asn1_find_str(nullptr, v16, v14);
if ( !str || !str[24] )
goto LABEL_21;
v13 = d2i_PrivateKey(*str, a2, (int *)&v17, v19);
goto LABEL_13;
}
v9 = d2i_X509_SIG(0, &v17, v19);
if ( !v9 )
goto LABEL_21;
if ( a3 )
v10 = a3(v20, 1024, 0, a4);
else
v10 = PEM_def_callback(v20, 1024, 0, a4);
if ( v10 <= 0 )
{
ERR_put_error(9, 123, 104, (int)"crypto/pem/pem_pkey.c", 63);
X509_SIG_free(v9);
v13 = 0;
goto LABEL_14;
}
v11 = PKCS8_decrypt(v9, v20, v10);
X509_SIG_free(v9);
if ( !v11 )
goto LABEL_21;
v12 = v11;
}
v13 = EVP_PKCS82PKEY(v12);
if ( a2 )
{
EVP_PKEY_free(*a2);
*a2 = v13;
}
PKCS8_PRIV_KEY_INFO_free(v11);
LABEL_13:
if ( v13 )
{
LABEL_14:
CRYPTO_free(v16, (int)"crypto/pem/pem_pkey.c", 88);
CRYPTO_clear_free(v18, v19, (int)"crypto/pem/pem_pkey.c", 89);
return v13;
}
LABEL_21:
ERR_put_error(9, 123, 13, (int)"crypto/pem/pem_pkey.c", 86);
v13 = 0;
goto LABEL_14;
}
return result;
}