-1
我對模塊編碼很陌生,我需要運行一些在模塊中使用GMP庫的計算。內核中的GMP模塊
所以第一個問題:通常是可以在內核中運行GMP嗎? 爲了測試,我寫了這個模塊:
#include <linux/init.h>
#include <linux/module.h>
#include <gmp.h>
int hallo_init(void)
{
mpz_t testFactor;
mpz_init(testFactor, NULL);
mpz_set_str(testFactor, "19", 10);
int length = (int) mpz_sizeinbase(testFactor,2);
printk(KERN_ALERT "That is testFactor: %x \n",length);
return 0;
}
void hallo_exit(void)
{
printk(KERN_ALERT "exit \n");
}
module_init(hallo_init);
module_exit(hallo_exit);
我用下面的命令來運行它:
sudo make -C /lib/modules/$(uname -r)/build M=$PWD modules -lgmp
生成文件由
obj-m := gmpFile.o
我也試過用-lgmp在makefile中:
obj-m := halloGmp.o
ccflags-y := -lgmp
但我總是得到一個致命錯誤:gmp.h: No such file or directory
有什麼建議嗎?將感謝幫助!
這顯然是一個XY問題。如果您有超量計算,請在用戶空間中執行它們,內核模塊應限制爲最低要求。作爲旁註:'%x'採用'unsigned',而不是'int' - >未定義的行爲。 – Olaf
不幸的是,我不能在用戶空間中完成它們。最後,爲了分析某些連接的安全性,我想用我的實現來替換Encryption(ECDH),以及針對某種攻擊的對策。因此我需要在內核中運行我的代碼 – Balltasar
還有其他一些測試加密的方法,例如通過使用原始套接字,保險絲等。無論如何,GMP不適用於加密算法。 – Olaf