☕
Pause for minutes until .
Remaining:
Pius Walter
T4INF1202: Kryptologie
Part 8: Asymmetric Encryption
2026-05-19
Recap
  • Previously, we spoke about symmetric cryptography in depth and their implementation-specific traits
  • We have looked at LFSRLinear-feedback shift register and their specific advantages and disadvantages when used for cryptographic purposes
  • Today, we focus on asymmetric primitives and their implementation in practice
Asymmetric cryptography
Asymmetric cryptography
  • In RSA, the tuple Q4mta4Ck5NLH(n, e)Zf1qH71g5gJY is a public key for integers Q4mta4Ck5NLHnZf1qH71g5gJY and Q4mta4Ck5NLHeZf1qH71g5gJY
  • The private key is a tuple Q4mta4Ck5NLH(n, d)Zf1qH71g5gJY where Q4mta4Ck5NLHdZf1qH71g5gJY is also an integer
  • Encryption: Q4mta4Ck5NLHC = E(P) = P^e \mod nZf1qH71g5gJY
  • Decryption: Q4mta4Ck5NLHP = D(C) = C^d \mod nZf1qH71g5gJY
RSA
  • What this means is that in RSA, the modulus Q4mta4Ck5NLHnZf1qH71g5gJY is shared for both encryption and decryption
  • The integers Q4mta4Ck5NLHe, dZf1qH71g5gJY are the values specific for encryption and decryption
  • Since they both have the same type (integer), they are exchangeable
RSA signing
  • It follows that you can also use the private key to encrypt data, which then allows the public key to decrypt said data
  • This is the trick that is used when signing data using RSARivest-Shamir-Adleman: encrypting with the private key signs data; decrypting with the public key is used to check the signature
  • Only works if public and private key are interchangeable
ECC
  • In ECCEliptic Curve Cryptography, public and private keys are different types.
  • Private key Q4mta4Ck5NLHdZf1qH71g5gJY is a scalar value (integer) so that Q4mta4Ck5NLH0 < d < nZf1qH71g5gJY
  • Public key is scalar product Q4mta4Ck5NLHQ = dGZf1qH71g5gJY
  • Q4mta4Ck5NLHnZf1qH71g5gJY is the order of the generator point Q4mta4Ck5NLHGZf1qH71g5gJY
ECC signing
Practical RSA
Recap
10
RSA implementation
  • Back to RSARivest-Shamir-Adleman, there are specific implementation constraints that you may have briefly touched upon.
  • Quick recap:
    • What is a typical value for Q4mta4Ck5NLHeZf1qH71g5gJY?
    • What are restrictions for Q4mta4Ck5NLHeZf1qH71g5gJY or Q4mta4Ck5NLHdZf1qH71g5gJY that would make RSARivest-Shamir-Adleman insecure?
RSA implementation
  • Typically, Q4mta4Ck5NLHe \ge 3Zf1qH71g5gJY – in particular, in most cases Q4mta4Ck5NLHe = 65537Zf1qH71g5gJY
  • Why this particular value?
  • Note that RSARivest-Shamir-Adleman with Q4mta4Ck5NLHe = 2Zf1qH71g5gJY is the Rabin cryptosystem
  • Note that RSA with Q4mta4Ck5NLHe = 1Zf1qH71g5gJY is the identity function!
Textbook RSA
  • One issue with textbook RSARivest-Shamir-Adleman is its deterministic input/output relationship
  • RSA operation needs to be chunked into blocks of size Q4mta4Ck5NLH\lfloor\log_2 n\rfloorZf1qH71g5gJY bits
  • An attacker might not be able to decrypt blocks, but they can infer information from encrypted RSARivest-Shamir-Adleman chunks
Textbook RSA
  • For example, imagine that data would be chunked bytewise and each byte would run through an RSARivest-Shamir-Adleman encryption operation
  • Each byte would then become a ciphertext of Q4mta4Ck5NLH\lceil\log_2 n\rceilZf1qH71g5gJY bits
  • However, there would only be 256 of such ciphertexts in the complete message, in varying order
Textbook RSA
  • Under a CPAChosen-plaintext attack model, textbook RSARivest-Shamir-Adleman therefore does not provide indistinguishability
  • Imagine an attacker who has ciphertext Q4mta4Ck5NLHCZf1qH71g5gJY and who needs to distinguish if that decrypts to one of two plaintexts, Q4mta4Ck5NLHP_1Zf1qH71g5gJY or Q4mta4Ck5NLHP_2Zf1qH71g5gJY
  • An attacker who is able to query the CPAChosen-plaintext attack oracle can simply encrypt Q4mta4Ck5NLHP_1Zf1qH71g5gJY and Q4mta4Ck5NLHP_2Zf1qH71g5gJY; one of the ciphertexts will be equal to Q4mta4Ck5NLHCZf1qH71g5gJY
Textbook RSA
  • More generally, any deterministic encryption scheme cannot provide distinguishability under the CPAChosen-plaintext attack model
  • Therefore, while textbook RSARivest-Shamir-Adleman is theoretically secure, in practice it fails important security criteria
  • This is not surprising and, in fact, we have seen a similar situation with good block ciphers that are insecure in practice when using ECBElectronic Codebook
Textbook RSA
  • Another issue with textbook RSARivest-Shamir-Adleman is its malleability
  • Even if an attacker cannot decrypt data, they might be able to manipulate data
  • For example, consider Q4mta4Ck5NLHC = E(P) = m^e \mod nZf1qH71g5gJY
  • An attacker wants to double whatever value Q4mta4Ck5NLHPZf1qH71g5gJY is, without knowing either Q4mta4Ck5NLHdZf1qH71g5gJY or Q4mta4Ck5NLHPZf1qH71g5gJY
Textbook RSA
  • The attacker can compute Q4mta4Ck5NLHz = 2^e \mod nZf1qH71g5gJY
  • Then, they compute Q4mta4Ck5NLHC' = CzZf1qH71g5gJY
QBEntEozXWioD(C') = (m^e \cdot 2^e)^d \mod n =kIt7msRdzcHK
QBEntEozXWio= ((2m)^e)^d \mod n = 2mkIt7msRdzcHK
Textbook RSA
  • Both properties are quite undesirable
  • This is why textbook RSARivest-Shamir-Adleman is considered generally insecure.
  • To encrypt data using RSARivest-Shamir-Adleman, proper padding of the plaintext is required before performing the modular exponentiation.
Practical RSA
PKCS#1
20
PKCS#1
  • The PKCS#1 v1.5 standard, also RFC2313, defines probably the most commonly used RSARivest-Shamir-Adleman padding today
  • There are two ways of padding, a deterministic and a non-deterministic scheme
  • Deterministic is intended for private-key operations (signing), while non-deterministic is intended for public-key operations (encryption)
PKCS#1
  • For encryption, nondeterministic padding is better
  • It ensures that there is no information leak under the chosen plaintext oracle model
  • Same data is encrypted to various different ciphertexts (injective, but not bijective)
  • The values need to be large to thwart various attacks (e.g., Desmedt and Odlyzko 1984: “A chosen text attack on the RSA cryptosystem and some discrete logarithm schemes”)
PKCS#1 padding, nondeterministic
PKCS#1 padding, nondeterministic
$ openssl genrsa -out private.key 512
$ openssl rsa -in private.key -pubout -out public.key
$ echo Kryptologie | \
    openssl pkeyutl -encrypt -inkey public.key -pubin | \
    openssl pkeyutl -decrypt -inkey private.key -pkeyopt rsa_padding_mode:none | \
    hexdump -C
00000000  00 02 f1 54 8c 5b 1c f4  52 9c 73 d3 e1 7a e2 95  |...T.[..R.s..z..|
00000010  a5 b6 d8 a7 c5 d9 5d bc  e0 42 b3 44 06 21 25 2c  |......]..B.D.!%,|
00000020  69 24 bc 91 40 08 29 e9  97 8c cd bc 88 2a 8a 07  |i$..@.)......*..|
00000030  cf 47 1b 00 4b 72 79 70  74 6f 6c 6f 67 69 65 0a  |.G..Kryptologie.|
00000040
PKCS#1
  • Unambiguous recovery possible since random data is always nonzero
  • Walk through the recovered plaintext block left-to-right until zero is found: Delimiter for data
  • Padding needs to be at least 8 bytes per PKCS#1 to guarantee a sufficiently large ciphertext space
PKCS#1
  • In contrast, for signature operations a deterministic way of creating the signature is preferable
  • The chosen-plaintext model does not apply since we are talking about private key operations here
  • Different signatures of identical data may otherwise leak information; avoided by always returning the same one
PKCS#1
  • Note the ideal order of operations here is EtAEncrypt-then-Authenticate (encrypt then sign) to avoid the possibility of the signature leaking information about the plaintext
  • I.e., the ciphertext is signed, not the plaintext
  • Otherwise an unencrypted signature would reintroduce a distinguisher
RSA signing
  • When signing with RSARivest-Shamir-Adleman, typically what is done is the following:
    • Compute a hashvalue over the data to be signed
    • Encrypt this hashvalue using the private key to sign the data
    • Decrypt the hashvalue using the public key to verify the signature
PKCS#1
  • In this case, as discussed previously, a deterministic output value is advantageous
  • This can also be performed using PKCS#1 with a different block type, namely 01
  • The padding is also constant and deterministic
PKCS#1 padding, deterministic
PKCS#1 padding, deterministic
$ openssl genrsa -out private.key 512
$ openssl rsa -in private.key -pubout -out public.key
$ echo Kryptologie | \
    openssl pkeyutl -sign -inkey private.key | \
    openssl pkeyutl -encrypt -inkey public.key -pubin -pkeyopt rsa_padding_mode:none | \
    hexdump -C -v
00000000  00 01 ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
00000010  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
00000020  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
00000030  ff ff ff 00 4b 72 79 70  74 6f 6c 6f 67 69 65 0a  |....Kryptologie.|
00000040
PKCS#1
  • Note that PKCS#1 also has a padding mode 00 which has constant zero padding
  • Essentially, that makes PKCS#1 padding collapse into textbook RSARivest-Shamir-Adleman!
  • There only for legacy reasons (and omitted in later versions of PKCS#1); should never be used
Validating certificate signatures
$ openssl genrsa -out private.key 512
$ openssl rsa -in private.key -pubout -out public.key
$ openssl req -key private.key -x509 -new -subj "/CN=Testcert" -out testcert.crt
$ openssl asn1parse -in testcert.crt | tail -n 1
  318:d=1  hl=2 l=  65 prim: BIT STRING
$ openssl x509 -in testcert.crt -outform der | tail -c -64 >signature.bin
$ openssl pkeyutl -in signature.bin -encrypt -inkey public.key -pubin -pkeyopt rsa_padding_mode:none | \
    hexdump -C
00000000  00 01 ff ff ff ff ff ff  ff ff ff ff 00 30 31 30  |.............010|
00000010  0d 06 09 60 86 48 01 65  03 04 02 01 05 00 04 20  |...`.H.e....... |
00000020  0c fc 6d 0c f6 36 53 04  b9 43 50 be 83 b7 fc 59  |..m..6S..CP....Y|
00000030  6c 1d 2a 86 44 d5 4a 42  11 0e 13 19 8d 34 42 eb  |l.*.D.JB.....4B.|
00000040
Validating certificate signatures
$ openssl pkeyutl -in signature.bin -encrypt -inkey public.key -pubin -pkeyopt rsa_padding_mode:none | \
    tail -c +14 | \
    openssl asn1parse -inform der -i
0:d=0  hl=2 l=  49 cons: SEQUENCE
2:d=1  hl=2 l=  13 cons:  SEQUENCE
4:d=2  hl=2 l=   9 prim:   OBJECT            :sha256
15:d=2  hl=2 l=   0 prim:   NULL
17:d=1  hl=2 l=  32 prim:  OCTET STRING      [HEX DUMP]:0CFC6D0CF6365304B94350BE83B7FC596C1D2A8644D54A42110E13198D3442EB
Practical RSA
OAEP
35
Issues with PKCS#1
  • PKCS#1 has one major problem that may be an issue in practice: padding oracles
  • As you have seen from the structure of a PKCS#1 message, there are various ways to construct a message that constitutes invalid padding
  • A padding oracle is an implementation weakness in which the party who has the secret key tells you if the padding was correct or not
Issues with PKCS#1
  • In essence, this constitutes an information leak that causes some data to be sent to the attacker
  • If an attacker structures their requests properly, they may be able to decrypt data through smart manipulation of the ciphertexts and repeated oracle queries
  • In practice, padding oracles appear for many cryptosystems and are quite difficult to defend against
Issues with PKCS#1
  • We will not discuss this at length during the course of this lecture, but it is something you will get intimately familiar in the 5th semester
  • Quite surprising consequences: attacker is able to decrypt data without the key
Improving RSA padding
OAEP
MGF
MGF1
  • MGF1 is an MGFMask generation function that is also specified in PKCS#1
  • Internally, it relies on a hash function
  • For a given seed Q4mta4Ck5NLHsZf1qH71g5gJY and block number Q4mta4Ck5NLHnZf1qH71g5gJY, it computes the next output mask block by using Q4mta4Ck5NLHH(s\ ||\ n)Zf1qH71g5gJY
  • Q4mta4Ck5NLHnZf1qH71g5gJY is encoded as big endian 32-bit integer values and starts from 0
MGF1
  • A good MGFMask generation function retains the avalanche property of the underlying function
  • This means for a changed seed, the generated mask is also entirely different
  • That property is easy to see in MGF1, since it directly inputs the seed into a hash function (which should have an avalanche property)
OAEP
  • OAEPOptimal Asymmetric Encryption Padding can additionally authenticate data using a hash function; by default the message Q4mta4Ck5NLHmZf1qH71g5gJY is authenticated
  • This is typically also used when there is no data to be authenticated present, then the input to the hash function will be empty
  • I am going to show you the actual construction that is used in practice, specified as NIST SP800-56B Rev. 2
RSA OAEP
RSA OAEP
RSA OAEP
RSA OAEP
Procedure
  • Most fields (leading 00, seed, Q4mta4Ck5NLHH(m)Zf1qH71g5gJY, fixed 01 and message Q4mta4Ck5NLHmZf1qH71g5gJY) have static length
  • Seed length is typically the output of the authentication function output Q4mta4Ck5NLHHZf1qH71g5gJY, typically 20 bytes because SHA-1 is the default
  • The only variable-length field is the 00...00 block
  • It is expanded so that the whole concatenation is exactly the length of the modulus
Procedure
  • Seed length needs to be specified out-of-band (as metadata), but defaults to the hash length (e.g., RFC8071 Sect. 7.1.1)
  • If message is too long, it cannot be encoded and needs to be split up
OAEP properties
  • You will see that the complete block that is output after OAEPOptimal Asymmetric Encryption Padding padding is entirely pseudorandom
  • Every single bit changed in the plaintext leads to a completely destroyed message (as per the avalanche property of the MGFMask generation function)
  • This is referred to as the “all-or-nothing” property
Conclusion
49
Takeaway
Thank you!
Any questions?