<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("GPL");<br> MODULE_DESCRIPTION("sha1 test with crypto API");<br> MODULE_AUTHOR("aymen<<a href="mailto:aymen.irt@gmail.com">aymen.irt@gmail.com</a>>");<br> MODULE_ALIAS("cryptoapi test");<br>
<br> printk(KERN_INFO "\nScatterlist crypto API test\n"); <br> desc.flags = 0;<br> desc.tfm = crypto_alloc_hash("sha1", 0, CRYPTO_ALG_ASYNC);<br> if(!desc.tfm){<br> printk(KERN_INFO "Error\n");<br>
}<br> <br> sg_init_one(&sg, m, 5);<br> <br> crypto_hash_init(&desc);<br> crypto_hash_update(&desc, &sg, 1);<br> crypto_hash_final(&desc, buf);<br> crypto_free_hash(desc.tfm);<br>
<br> printk("\n");<br> for (i=0; i<20; i++)<br> printk("%02x ", buf[i]);<br> printk("\n");<br>return 0;<br>}<br><br>void cleanup_module(void)<br>{<br> printk(KERN_INFO "\nScatterlist crypto API test end...\n");<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>