Skip to content

Testing ‐‐ tcrypt with virtme (locally)

Armando Faz edited this page Nov 16, 2023 · 5 revisions

The tcrypt module contains test and benchmark scripts for some cryptographic algorithms (which are exposed as kernel modules).

Linux Compilation

Enable the tcrypt module. Either running make menuconfig and selecting under the menu option

└ Cryptography API
  └ Crypto core or helper
    └ <M> Testing Module

Or, setting CONFIG_CRYPTO_TEST=m in the .config file works too.

$ make defconfig
$ echo "CONFIG_CRYPTO_TEST=m" >> .config
$ make ARCH=x86_64

Virtme

virtme is a wrapper of QEMU that allows to run the Linux kernel.

How to install virtme?

$ git clone https://git.kernel.org/pub/scm/utils/kernel/virtme/virtme.git
$ cd virtme
$ pip install .

How to stop virtme? Ctrl-a x

After compilation

Run the kernel using virtme:

$ cd <PATH TO LINUX>
$ virtme-run --kdir . --mods=auto

Once it's loaded, a shell terminal prompts, and there run:

$ insmod <PATH to LINUX>/crypto/tcrypt.ko mode=300 alg=sha256-generic
$ insmod <PATH to LINUX>/crypto/tcrypt.ko mode=300 alg=sha256-hacl

where:

  • mode=300 tells tcrypt to pick a hash function by name.
  • alg=<name>-<variant> tells tcrypt to look for the algorithm <name> that is provided by the <variant> implementation.
  • sec=<N> when N>0, it measures the primitive for a period of N seconds, and reports opers/sec. When N=0, it measures clock cycles.

To see the results of testing, run $ dmesg. The output looks something like this:

root@(none): # insmod ./linux/crypto/tcrypt.ko mode=300 alg=sha256-generic
[   62.122941] tcrypt: testing speed of async sha256-generic (sha256-generic)
[   62.123244] tcrypt: test  0 (   16 byte blocks,   16 bytes per update,   1 updates):    668 cycles/operation,   41 cycles/byte
[   62.123725] tcrypt: test  1 (   64 byte blocks,   16 bytes per update,   4 updates):   1252 cycles/operation,   19 cycles/byte
[   62.124205] tcrypt: test  2 (   64 byte blocks,   64 bytes per update,   1 updates):   1192 cycles/operation,   18 cycles/byte

To stop the running instance, execute

$ poweroff -f