Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use PKCS5_PBKDF2_HMAC_SHA1()
    primarykey
    data
    text
    <p>I am trying to use <code>PKCS5_PBKDF2_HMAC_SHA1()</code> and below is my sample program. I wanted to make sure if my result of <code>PKCS5_PBKDF2_HMAC_SHA1()</code> is correct so I verified the same with the website <a href="http://anandam.name/pbkdf2/" rel="nofollow noreferrer">http://anandam.name/pbkdf2/</a> and I see a different result. Am I using the API correctly? </p> <p>I am having doubts if I am passing salt value correctly.</p> <p>I have pasted my result and website result after the program.</p> <p>Please help me understand this.</p> <pre class="lang-c prettyprint-override"><code>#include &lt;stdio.h&gt; #include &lt;types.h&gt; #include &lt;string.h&gt; #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;malloc.h&gt; #include &lt;openssl/hmac.h&gt; #include &lt;openssl/evp.h&gt; #include &lt;openssl/engine.h&gt; #include &lt;openssl/aes.h&gt; #include &lt;openssl/rand.h&gt; #include &lt;proto.h&gt; #define KEY_LEN 32// 32 bytes - 256 bits #define KEK_KEY_LEN 5 #define ITERATION 1000 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)); for(i = 0; i &lt; 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 &lt; KEK_KEY_LEN; len++){ printf("%02x", out[len]); sprintf(&amp;rspPKCS5[len * 2], "%02x", out[len]); } printf("\n"); } </code></pre> <p><strong>Sample Output:</strong></p> <pre><code>salt_value[0] = e2; salt_value[31]= 12 strlen(salt_value) = 32; sizeof(salt_value) = 32 e258017933f3e629a4166cece78f3162a3b0b7edb2e94c93d76fe6c38198ea12 PKCS#5 :7d7ec9f411 </code></pre> <p>Website result: </p> <pre><code>The derived 40-bit key is: a5caf6a0d3 </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload