<div dir="ltr"><div><div><div><div><div>Hi all,<br><br></div>In order to test kernel crypto API, I tried different methods for computing a SHA1 digest. First, I tried sockets with AF_ALG. Then, I tried ioctl with /dev/crypto after loading cryptodev.ko module. These two methods returned the same hash value as the one computed by OpenSSL over the same input buffer. My input is simply a 5 bytes table where each byte is equal to 0x0a. The SHA1 output is the following: 31 78 9a ce 8f db 0f ae 29 76 e8 30 3b 61 4c 51 d0 a1 39 a9.<br>
<br>Then, I tried scatterlist crypto API. So, I tested the following module:<br>int init_module(void)<br>{<br>uint8_t i=0, buf[20]={0}, m[5]={0x0a,0x0a,0x0a,0x0a,0x0a};<br>struct scatterlist sg;<br>struct hash_desc desc;<br>
<br>    MODULE_LICENSE(&quot;GPL&quot;);<br>    MODULE_DESCRIPTION(&quot;sha1 test with crypto API&quot;);<br>    MODULE_AUTHOR(&quot;aymen&lt;<a href="mailto:aymen.irt@gmail.com">aymen.irt@gmail.com</a>&gt;&quot;);<br>    MODULE_ALIAS(&quot;cryptoapi test&quot;);<br>
<br>    printk(KERN_INFO &quot;\nScatterlist crypto API test\n&quot;);    <br>    desc.flags = 0;<br>    desc.tfm = crypto_alloc_hash(&quot;sha1&quot;, 0, CRYPTO_ALG_ASYNC);<br>    if(!desc.tfm){<br>        printk(KERN_INFO &quot;Error\n&quot;);<br>
    }<br>    <br>    sg_init_one(&amp;sg, m, 5);<br>    <br>    crypto_hash_init(&amp;desc);<br>    crypto_hash_update(&amp;desc, &amp;sg, 1);<br>    crypto_hash_final(&amp;desc, buf);<br>    crypto_free_hash(desc.tfm);<br>
<br>    printk(&quot;\n&quot;);<br>    for (i=0; i&lt;20; i++)<br>                printk(&quot;%02x &quot;, buf[i]);<br>        printk(&quot;\n&quot;);<br>return 0;<br>}<br><br>void cleanup_module(void)<br>{<br>    printk(KERN_INFO &quot;\nScatterlist crypto API test end...\n&quot;);<br>
}<br><br></div>My problem is when I insmod my test_cryptoapi.ko, i get a wrong SHA1 output. In fact, I get the following SHA1 digest:  ad c8 3b 19 e7 93 49 1b 1c 6e a0 fd 8b 46 cd 9f 32 e5 92 fc.<br><br></div>I would be grateful for any hint about this problem.<br>
<br></div>Best regards,<br></div>Aymen<br></div>