Skip to main content
← All libraries
Crypto · C

How to fuzz LibTomCrypt

A portable crypto toolkit common in embedded firmware — wide deployment, niche test coverage.

LibTomCrypt's portability focus means it avoids OS-specific mitigations, making overflows more exploitable. Its RSA and ECC key import paths parse DER-encoded structures with hand-rolled length arithmetic that rarely receives the same fuzzing attention as OpenSSL-equivalent paths, yet it appears in many embedded and IoT firmware images.

Common bug classes

  • Heap buffer overflow in DER SEQUENCE length decode
  • Integer overflow in RSA key size to buffer allocation
  • Out-of-bounds write in ECC point decompression
  • Null dereference in PKCS#1 v1.5 padding check on empty input
  • Use-after-free in error path of multi-step key import

Recommended setup

Fuzzers

  • AFL++
  • libFuzzer

Sanitizers

  • ASan
  • UBSan

Harness scaffold

#include <stdint.h>
#include <stddef.h>
#include <tomcrypt.h>

int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
  rsa_key key;
  /* Attempt DER import of RSA key */
  rsa_import(data, (unsigned long)size, &key);
  rsa_free(&key);
  /* Attempt ECC import */
  ecc_key ekey;
  ecc_import(data, (unsigned long)size, &ekey);
  ecc_free(&ekey);
  return 0;
}

Save this as fuzz_target.cc, build with your compiler + sanitizer flags, and you have a working starting point.

Start fuzzing LibTomCrypt on Fuzze.rs →

Push the harness above + a Dockerfile. First month 50% off.