c - OpenSSL using EVP vs. algorithm API for symmetric crypto -


hi have installed openssl on linux machine , going through header files , documentation (which highly insufficint :( ).

i trying build project(in 'c') uses symmetric crypto algos (i focusing on aes256cbc). problem confused in how use library functions in code.

for implementation of aes256cbc can directly use functions defined in 'aes.h' header file(which appeared me @ first place).

but on googling came accross tutorial using 'evp.h' functions http://saju.net.in/code/misc/openssl_aes.c.txt

is there specific reason or directly accessing aes.h functions better.

and if can point me documentation/tutorial of kind on using crypto library of openssl appreciated.

many thanks

p.s forgive me if being naive

using evp api has advantage can use same api symmetric ciphers openssl supports, in generic way. makes way easier replace algorithm used, or make algorithm user-configurable @ later stage. of code write not specific encryption algorithm selected.

here's simple example encryption aes-256 in cbc mode:

#include <stdio.h> #include <openssl/evp.h>  int main() {     evp_cipher_ctx ctx;     unsigned char key[32] = {0};     unsigned char iv[16] = {0};     unsigned char in[16] = {0};     unsigned char out[32]; /* @ least 1 block longer in[] */     int outlen1, outlen2;      evp_encryptinit(&ctx, evp_aes_256_cbc(), key, iv);     evp_encryptupdate(&ctx, out, &outlen1, in, sizeof(in));     evp_encryptfinal(&ctx, out + outlen1, &outlen2);      printf("ciphertext length: %d\n", outlen1 + outlen2);      return 0; } 

for simplicity, omitted error handling.

imo 1 of important pieces of documentation on openssl network security openssl viega/messier/chandra. 2002 (0.9.7), not cover changes openssl during last 10 years, imo still less painful way learn openssl using manual pages.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -