Reputation: 31
I'm working on a kernel module which uses asymmetric cipher of kernel crypto api, kernel version 6.5.0. I generate asymmetric key pairs by openssl, convert them into DER format and import it into the kernel module with crypto_akcipher_set_pub_key and crypto_akcipher_set_priv_key. However, crypto_akcipher_set_priv_key always returns the error number: -38 (0xffffffda).
The code is shown below:
char priv_key[] = {0x30, 0x5f, 0x02, 0x01, 0x01, 0x04, 0x18, 0xC3, 0xE9, 0x7D, 0xAB, 0x01, 0x49, 0xB0, 0x60, 0x74, 0x3A, 0x97, 0xDD, 0x64,
0xBF, 0x04, 0x5A, 0x6F, 0xFB, 0x1C, 0xEE, 0x91, 0x2D, 0x3A, 0xCA, 0xA1, 0x34, 0x03, 0x32, 0x00, 0x04, 0xDA, 0x29, 0x77, 0x8E, 0x9D, 0x7F,
0xF9, 0xFA, 0x14, 0x5A, 0x81, 0xD3, 0xDD, 0xE3, 0x71, 0x94, 0x17, 0xF9, 0xFA, 0xB0, 0x41, 0x90, 0xE9, 0x0C, 0xBD, 0xDB, 0x6D, 0xC6, 0x57,
0xE0, 0x00, 0x5A, 0xCD, 0xF8, 0xC7, 0x45, 0xE2, 0x27, 0xF4, 0x1B, 0x16, 0x2C, 0x3D, 0x9D, 0xBD, 0xDC, 0x0E, 0xD9};
tfm = crypto_alloc_akcipher("ecdsa-nist-p256", 0, 0);
if (IS_ERR(tfm)) {
printk(KERN_ERR "Failed to allocate akcipher handle\n");
kfree(priv_key);
return PTR_ERR(tfm);
}
ret = crypto_akcipher_set_priv_key(tfm, priv_key, PRIV_KEY_SIZE);
if (ret) {
printk(KERN_ERR "Failed to set private key for signing, ret = %x\n", ret);
crypto_free_akcipher(tfm);
kfree(priv_key);
return ret;
}
My question is similar to crypto_akcipher_set_pub_key in kernel asymmetric crypto always returns error
Unfortunately, the above question focuses on RSA, while I need ECC such as ECDSA, and the solution above does not work for me.
Alternatively, I wonder whether there is a method to generate ECC keys that are compatiable with the Linux crypto API within the kernel module. That would help too.
Thanks
Upvotes: 0
Views: 88