Quantcast
Channel: Active questions tagged kernel - Stack Overflow
Viewing all articles
Browse latest Browse all 6502

Is there any restrictions on digest size and block size when creating new synchronize hash algorithm using linux crypto api

$
0
0

I'm new to linux kernel development and try to create a demo synchronize hash (shash) algorithm using linux crypto api. Below is my example code:

#include <linux/init.h>#include <linux/module.h>#include <linux/types.h>#include <asm/unaligned.h>#define ISHAKE_128_DIGEST_SIZE  64#define ISHAKE_128_BLOCK_SIZE   128#define ISHAKE_256_DIGEST_SIZE  64#define ISHAKE_256_BLOCK_SIZE   128struct ishake_state {    u64     st[25];    unsigned int    rsiz;    unsigned int    rsizw;    unsigned int    partial;    u8      buf[ISHAKE_128_BLOCK_SIZE];};int ishake_init(struct shash_desc *desc) {    return 0;}EXPORT_SYMBOL(ishake_init);int ishake_update(struct shash_desc *desc, const u8 *data, unsigned int len) {    return 0;}EXPORT_SYMBOL(ishake_update);int ishake_final(struct shash_desc *desc, u8 *out) {    return 0;}EXPORT_SYMBOL(ishake_final);static struct shash_alg algs[] = {{      .digestsize  = ISHAKE_128_DIGEST_SIZE,      .init        = ishake_init,      .update      = ishake_update,      .final       = ishake_final,      .descsize    = sizeof(struct ishake_state),      .base.cra_name        = "ishake-128",      .base.cra_driver_name = "ishake-128-generic",      .base.cra_blocksize   = ISHAKE_128_BLOCK_SIZE,      .base.cra_module      = THIS_MODULE,},{      .digestsize  = ISHAKE_256_DIGEST_SIZE,      .init        = ishake_init,      .update      = ishake_update,      .final       = ishake_final,      .descsize    = sizeof(struct ishake_state),      .base.cra_name        = "ishake-256",      .base.cra_driver_name = "ishake-256-generic",      .base.cra_blocksize   = ISHAKE_256_BLOCK_SIZE,      .base.cra_module      = THIS_MODULE,}};static int __init ishake_mod_init(void) {    return crypto_register_shashes(algs, ARRAY_SIZE(algs));}static void __exit ishake_mod_fini(void) {    crypto_unregister_shashes(algs, ARRAY_SIZE(algs));}subsys_initcall(ishake_mod_init);module_exit(ishake_mod_fini);MODULE_LICENSE("GPL");MODULE_DESCRIPTION("Incremental SHAKE Algorithm");MODULE_ALIAS_CRYPTO("ishake-128");MODULE_ALIAS_CRYPTO("ishake-256");MODULE_ALIAS_CRYPTO("ishake-128-generic");MODULE_ALIAS_CRYPTO("ishake-256-generic");

Trouble is that, when I try to set digestsize or base.cra_blocksize to other values like 256, 512 and etc, the linux kernel will refuse to insert module:

➜  iSHAKE git:(master) ✗ makemake -C /lib/modules/5.17.6-1.el7.elrepo.x86_64/build M=/root/workspace/linux-crypto-benchmark/kernelspace/hash/iSHAKE modulesmake[1]: Entering directory `/usr/src/kernels/5.17.6-1.el7.elrepo.x86_64'  CC [M]  /root/workspace/linux-crypto-benchmark/kernelspace/hash/iSHAKE/ishake-generic.o  MODPOST /root/workspace/linux-crypto-benchmark/kernelspace/hash/iSHAKE/Module.symvers  CC [M]  /root/workspace/linux-crypto-benchmark/kernelspace/hash/iSHAKE/ishake-generic.mod.o  LD [M]  /root/workspace/linux-crypto-benchmark/kernelspace/hash/iSHAKE/ishake-generic.komake[1]: Leaving directory `/usr/src/kernels/5.17.6-1.el7.elrepo.x86_64'➜  iSHAKE git:(master) ✗ insmod ishake-generic.koinsmod: ERROR: could not insert module ishake-generic.ko: Invalid parameters➜  iSHAKE git:(master) ✗

I suspect that the linux crypto api has some kind of restrictions on digestsize and blocksize, but I don't know exactly what. Can anyone help me? Thanks a lot.


Viewing all articles
Browse latest Browse all 6502

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>