wrong digest value using scatterlist crypto API
aymen irt
aymen.irt at gmail.com
Thu Apr 10 10:42:28 EDT 2014
Hi all,
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.
Then, I tried scatterlist crypto API. So, I tested the following module:
int init_module(void)
{
uint8_t i=0, buf[20]={0}, m[5]={0x0a,0x0a,0x0a,0x0a,0x0a};
struct scatterlist sg;
struct hash_desc desc;
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("sha1 test with crypto API");
MODULE_AUTHOR("aymen<aymen.irt at gmail.com>");
MODULE_ALIAS("cryptoapi test");
printk(KERN_INFO "\nScatterlist crypto API test\n");
desc.flags = 0;
desc.tfm = crypto_alloc_hash("sha1", 0, CRYPTO_ALG_ASYNC);
if(!desc.tfm){
printk(KERN_INFO "Error\n");
}
sg_init_one(&sg, m, 5);
crypto_hash_init(&desc);
crypto_hash_update(&desc, &sg, 1);
crypto_hash_final(&desc, buf);
crypto_free_hash(desc.tfm);
printk("\n");
for (i=0; i<20; i++)
printk("%02x ", buf[i]);
printk("\n");
return 0;
}
void cleanup_module(void)
{
printk(KERN_INFO "\nScatterlist crypto API test end...\n");
}
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.
I would be grateful for any hint about this problem.
Best regards,
Aymen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/linux-crypto/attachments/20140410/86de592b/attachment.html
More information about the Linux-crypto
mailing list