Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any C API in openssl to derive a key from given string

Tags:

c

openssl

I need a C API in openssl library for deriving the Key from a given string. Where can i get sample source code for this?

like image 269
Raja Avatar asked Jul 21 '11 07:07

Raja


1 Answers

A standard algorithm to do this is PBKDF2 (an acronym for Password-Based Key Derivation Function version 2). There is an implementation of PBKDF2 in OpenSSL, declared in openssl/evp.h:

int PKCS5_PBKDF2_HMAC_SHA1(const char *pass, int passlen,
                           unsigned char *salt, int saltlen, int iter,
                           int keylen, unsigned char *out);

When you are generating a new key you should use RAND_bytes() from openssl/rand.h to create the salt. iter is the iteration count, which should be as large as your intended application can tolerate - at least something like 20,000.

like image 160
caf Avatar answered Nov 15 '22 05:11

caf