Don't Let the Cat Out!

Trapdoor functions and their importance in security

Blog Don't Let the Cat Out!
Contact us

Functions! I’m sure you have heard this concept in many ways: math, programming, economics, etc. And they all can be reduced to the same basic thing: something that takes some inputs and produces some outputs. Math is the case here, however, there is a lot to add to that short definition, specially when we apply it to computer security, because despite you might be unaware, your security totally depend on a special kind of functions called Trapdoors. [1] Let’s talk about trapdoor functions and how they save you from "letting the cat out".

When we talk about inputs producing an output we usually talk about the reverse process: given the outputs deduce the inputs, this is really useful in many applications…​ but not in security! knowing an input from an output is a serious problem, you will see why.

A Trapdoor is essentially something taking an input and producing an output, but it is extremely difficult to do the reverse process, this is because to do so you need to know a "secret" called a private key and you have to be the luckiest guy in all universes to guess it or to guess the input.


P : Plain text data
E : Encrypted data
K : Secret key

A Trapdoor is a function that encrypts with the properties:

E = f(P) (Easy to do)
P = f-1(E) (Really hard to do!)
P = f-1(E,K) (Easy to do)

Now, Trapdoors are not the same as the well known hash functions, hash functions are one-way functions as well, but they are not reversible by any means, whereas Trapdoors are reversible with the key. This is what makes them fundamental for Encryption of shared information.

Your lifesaving, precious data is always put in a Trapdoor, encrypted and transmitted and no one (except the possessor of the secret and the luckiest guy in all universes) can figure out the data.

Symmetric and Asymmetric Encryption

When two ends have to exchange sensitive data, they must agree on the key they both use, this is called Symmetric Encryption [2] where the same key is used to encrypt and to decrypt. This key has to be transmitted first for agreement before any other communication, but how can they prevent a third party sniffs and retrieve the key? they use a type of Encryption called Asymmetric Encryption: It encrypts the data with one public key and decrypts it with a different private key

Kp : Public key
Ks : Private key

The data is encrypted with

E = f(P,Kp)

And decrypted with

P = f-1(E,Kp)

This Encryption is slow and it’s not commonly used in data transmission. It’s only used between parties to agree on a shared key that they use for Symmetric Encryption which is the one used for large data exchange as it’s faster. The shared key for Symmetric Encryption is transmitted over Asymmetric Encryption so no attacker can retrieve this symmetric key.

Get started with Fluid Attacks' DevSecOps solution right now

RSA Encryption

Rivest, Shamir, Adleman, also know as RSA algorithm [3] is the most common algorithm for Asymmetric Encryption and it’s based on a Trapdoor function called modular exponentiation :

E = PKP mod N

In this case knowing P from E is impossible, you need to know a secret KS in order to compute it.

RSA algorithm uses prime number arithmetics and modular exponentiation to encrypt a message, the algorithm can be summarized like this :

  1. Choose two prime numbers p and q.

  2. Compute n = pq.

  3. Compute Euler’s function ϕ = (p - 1)(q - 1). [5]

  4. Choose a number e smaller and coprime [6] to ϕ.

  5. Choose a number d such that (ed - 1) mod ϕ = 0, This is know as the modular multiplicative inverse,[7] in other words, ed - 1 must be divisible entirely by ϕ.

  6. (e,n) are the public key whereas (s,n) are the private key.

A message m is encrypted into c by

c = me mod n

And decrypted by

m = cd mod n

Thus, anyone can know the public key value e to encrypt but not the private key value d used to decrypt. What about n ? could not they use it to come up with d ? Yes, they can, they will just take tenths of years to do it as n is chosen to be a very big number, so breaking it into the prime factors p, q used to get e and therefore d, would take long enough that an attacker cannot crack the key.

AES Encryption

AES (Advanced Encryption System) [4] algorithm, is usually the chosen one for Symmetric Encryption. This algorithm is rather procedural than hard mathematical formula computation, it basically encrypts a table of data in four steps:

  1. SubBytes : Each value in a table is substituted by another using a table.

  2. ShiftRows : Rows of the table are shifted by some offset.

  3. MixColumns : Columns are mixed by a matrix operation.

  4. AddRoundKey : The public key is performed over the table with an XOR operation.

All operations performed are reversible and they are made in order to eliminate or diffuse any possible pattern or relationship of the ciphered message to the original one and to the key that might hint an attack.


You can be sure your data is very well protected and that the communication won’t be disclosed to any attacker thanks to a Trapdoor, of course, as computing power continues to develop, we might need to create new traps, but now the assurance of your privacy on communication is really high, so every time you browse your social networks, bank accounts, etc; remember there is a Trapdoor that won’t let any cat out.


Subscribe to our blog

Sign up for Fluid Attacks' weekly newsletter.

Recommended blog posts

You might be interested in the following related posts.

Photo by FlyD on Unsplash

Software supply chain management in financial services

Photo by Robs on Unsplash

Consequential data breaches in the finance sector

Photo by Towfiqu barbhuiya on Unsplash

Data protection in the financial sector, tips and more

Photo by Jasmin Egger on Unsplash

If the essential security layer is flawed, you're toast

Photo by Christian Wiediger on Unsplash

The need to enhance security within the fintech sector

Photo by Claudio Schwarz on Unsplash

Is your financial service as secure as you think?

Photo by mitchell kavan on Unsplash

Bringing the zero trust model to life

Start your 21-day free trial

Discover the benefits of our Continuous Hacking solution, which hundreds of organizations are already enjoying.

Start your 21-day free trial
Fluid Logo Footer

Hacking software for over 20 years

Fluid Attacks tests applications and other systems, covering all software development stages. Our team assists clients in quickly identifying and managing vulnerabilities to reduce the risk of incidents and deploy secure technology.

Copyright © 0 Fluid Attacks. We hack your software. All rights reserved.