Hi,

I am trying to use PKCS5_PBKDF2_HMAC_SHA1() and below is my sample program.
I wanted to make sure if my result of PKCS5_PBKDF2_HMAC_SHA1() is correct so
i verified the same with the below wesbite http://anandam.name/pbkdf2/ and i
see a different result... Am i using the API correctly?
I am having doubts if i am passing salt value correctly...

I have pasted my result and website result after the program...

Please guide me to understand this...




===================================================

#include <stdio.h>
#include <openssl/rand.h>
#include <types.h>
#include <string.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#include <malloc.h>

#include <openssl/hmac.h>
#include <openssl/evp.h>
#include <openssl/engine.h>
#include <openssl/aes.h>

#include <proto.h>
#define KEY_LEN    32// 32 bytes - 256 bits
#define KEK_KEY_LEN   5
#define ITERATION   1000

//unsigned char salt_value[32]={"5d85947b4292ea6463faf6893451232"}; 
unsigned char salt_value[KEY_LEN];
unsigned char AESkey[KEY_LEN];
unsigned char XTSkey[KEY_LEN];
u8 fuse_key[KEY_LEN];


void main()
{
   
    s32 i=0;
    s32 len =0;
        u8 *out;
    u8 *rspHMAC;
        const s8 pwd[] = "test";
        s8 rspPKCS5[KEK_KEY_LEN * 2];
        s32 ret;
         
        rspHMAC = (unsigned char *) malloc(sizeof(char) * KEY_LEN);
    out = (unsigned char *) malloc(sizeof(char) * KEK_KEY_LEN);
        
    RAND_bytes(salt_value, KEY_LEN);

        
    printf("\n salt_value[0] = %x; salt_value[31]= %x", salt_value[0],
salt_value[31]);
    printf("\n strlen(salt_value) = %d; sizeof(salt_value) = %d\n",
strlen(salt_value), sizeof(salt_value));
        //printf("\n salt_value = %s", salt_value);
        
    for(i = 0; i < KEY_LEN; i++) {
        printf("%02x", salt_value[i]);
          
        }

        ret = PKCS5_PBKDF2_HMAC_SHA1(pwd, strlen(pwd), salt_value,
strlen(salt_value), ITERATION, KEK_KEY_LEN, out);
    printf("\n PKCS#5 :");

    for(len = 0; len < KEK_KEY_LEN; len++){
        printf("%02x", out[len]);
       /* o/p of PKCS5 is stored in buf "out". This cannot be used directly
as each out[len] will have 2 char
       but for key gen, we need to consider each char of out as a value. -
Needs sentence reframing
         */
        sprintf(&rspPKCS5[len * 2], "%02x", out[len]);
   }

        printf("\n");
}

Sample O/P:

salt_value[0] = e2; salt_value[31]= 12
 strlen(salt_value) = 32; sizeof(salt_value) = 32
e258017933f3e629a4166cece78f3162a3b0b7edb2e94c93d76fe6c38198ea12
 PKCS#5 :7d7ec9f411

Website result:
The derived 40-bit key is: a5caf6a0d3



-- 
View this message in context: 
http://old.nabble.com/How-to-use-PKCS5_PBKDF2_HMAC_SHA1%28%29-tp33529423p33529423.html
Sent from the OpenSSL - User mailing list archive at Nabble.com.

______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    openssl-users@openssl.org
Automated List Manager                           majord...@openssl.org

Reply via email to