Skip to content

Instantly share code, notes, and snippets.

@astrokin
Created April 22, 2022 12:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save astrokin/36c698ded66707f317412e53994837d4 to your computer and use it in GitHub Desktop.
Save astrokin/36c698ded66707f317412e53994837d4 to your computer and use it in GitHub Desktop.
Decrypt on iOS (CBC, Pkcs7, EVP_BytesToKey) (C part)
#include "EVP_KDF_Salted.h"
#include <openssl/evp.h>
#include <string.h>
int
gen_evp_kdf_aes256cbc(const unsigned char *password, const unsigned char *salt, unsigned char key[], unsigned char iv[]) {
const EVP_CIPHER *cipher;
const EVP_MD *dgst = NULL;
OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_CIPHERS | OPENSSL_INIT_ADD_ALL_DIGESTS | OPENSSL_INIT_LOAD_CONFIG, NULL);
cipher = EVP_get_cipherbyname("aes-256-cbc");
if(!cipher) { fprintf(stderr, "no such cipher\n"); return 1; }
dgst=EVP_get_digestbyname("md5");
if(!dgst) { fprintf(stderr, "no such digest\n"); return 1; }
int result = EVP_BytesToKey(cipher, dgst, salt, password, strlen(password), 1, key, iv);
if (!result) {
fprintf(stderr, "EVP_BytesToKey failed\n");
return 1;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment