-1

I'm quiet new to module coding and I need to run some calculation that uses the GMP library in a module.

So the first question: is it generally possible to run GMP in kernel? For testing, I wrote this Module:

#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);

I run it with the following command:

sudo make -C /lib/modules/$(uname -r)/build M=$PWD modules -lgmp

The makefile consists of

obj-m := gmpFile.o

I also tried to use the -lgmp in the makefile:

obj-m := halloGmp.o
ccflags-y := -lgmp

But I always get a Fatal error: gmp.h: No such file or directory Any suggestions? Would be thankful for help!

Balltasar
  • 1
  • 1
  • That's clearly an XY-problem. If you have excessice calculations, Do them in user-space, Kernel modules should be limited to the minimum required. As a sidenote: `%x` takes an `unsigned`, not an `int` -> undefined behaviour. – too honest for this site Jul 27 '17 at 11:59
  • Unfortunately, I can't do them in user-space. Finally I want to replace an enryption (ECDH) with its countermeasures against a certain attack with my implementation in order to analyse the security of certain connections. Therefore I need to run my code in Kernel – Balltasar Jul 27 '17 at 12:24
  • There are other ways to test encryption e.g. by using raw sockets, Fuse, etc. GMP is not suitable for encryption algorithms anyway. – too honest for this site Jul 27 '17 at 14:23

1 Answers1

0

I'm not familiar with GMP but it's unlikely that you can dynamically link a library to a kernel module.

The reason is that the kernel is a standalone program and don't know about any system library that you are used (such glib...) and very likely GMP uses those.

The only solution that I can think of is that you do a kernel module that communicate with a program in the userland and link the GMP to the userland part of your application.

dhia
  • 350
  • 1
  • 2
  • 7