This project implements an HMAC (Hash-based Message Authentication Code) algorithm using the Linux Kernel Crypto API.
It demonstrates how to:
- Implement a kernel module
- Register a device for user-space communication
- Use the Crypto API for cryptographic operations
This project is designed for kernel module development and should be compiled within a Linux kernel environment.
- Uses HMAC-SHA1 to compute message authentication codes
- ...
Ensure you have:
- A Linux system with kernel headers installed
makeandgccfor building kernel modules- Root privileges for loading/unloading kernel modules
The Makefile contains the following targets:
all- Builds the kernel module into an.kofileload- Builds and loads the kernel moduleunload- Unloads the kernel modulereload- Unloads and loads the kernel moduleclean- Cleans the build directoryinfo- Displays information about the kernel modulelog- Displays the kernel loglogx- Displays the kernel log continuouslyhelp- Displays the Makefile help
- Clone the repository:
$ git clone https://github.com/NicolasReboule/OTPKernelModule.git- Go inside the
modulefolder
$ cd OTPKernelModule/module- Run the
make loadcommand to build and load the kernel module:
$ make load- Check the kernel log for module information:
$ make log- Use the
devicesinterfaces to interact with the module:
$ cat /dev/otp-hotp
$ 123456- Use the generatad otp to use the client
$ cd client
$ ./client 123456 upper bonjour
$ BONJOURcat /dev/otp-hotp: Generate a hotp code
Using echo:
- update -a <algo> -s <secret> : Update the device's algorihm and secret
- info : Shows devices current algorihm and secret
- default : Shows usage
where:
- <algo> : SHA1 or SHA256
- <secret> : Any string
cat /dev/otp-totp: Generate a totp code
Using echo:
- update -a <algo> -s <secret> -t : Update the device's algorihm and secret
- info : Shows devices current algorihm and secret
- default : Shows usage
where:
- <algo> : SHA1 or SHA256
- <secret> : Any string
- <timestep>: Number of seconds a TOTP code should be valid
cat /dev/otp-validator: Returns last validation result
Using echo:
- <otp> : Validate an otp
- help : Shows usage
where:
- <otp> : OTP code generated by this module
With admin rights, you can use debugfs tu modify the list of hotp codes.
The list can be found at /sys/kernel/debug/otp_manager/otp_list
cat /sys/kernel/debug/otp_manager/otp_list: Shows list of hotp codes
Using echo:
- add <code> : Adds code to hotp list
- delete <index> : Removes code at specified index from the list
where:
- <code> : Any number (less than 16 characters)
- <index> : Index number in the list
.
├── crypto.c # Main implementation of HMAC using Crypto API
├── Makefile # Build script for compiling the module
├── module.c # Kernel module initialization and cleanup
├── module.d/ # Directory for kernel module source files
│ └── * # Object files generated during compilation
├── ... # ...
├── ... # ...
└── README.md # User Documentation
Fazanwolf - GitHub
Salocin - GitHub
Nekomay - GitHub
This project is licensed under the GPLv3 License - see the LICENSE file for details.