Provable Secure Signatures with RSA

PSS: Probabilistic Signature Scheme

Prof Bill Buchanan OBE
8 min readJun 10, 2023


After 45 years, RSA is still going strong and basically secures the Internet. Every time you connect to a Web site, there is a signature method there that proves the identity of the Web site you are connecting to. While some — such as Cloudflare use ECC — the majority still use RSA. Here is the Edinburgh Napier University public key, and which uses a 2,048-bit RSA modulus:

At the core of this, is the RSA signature. Basically, the site shows a trusted public key to the client, and will digitally sign some data with its private key. If the signature proves to be valid with the public key, the site can be trusted. In this case, Alice signs the hash of a message with her private key, and Bob checks with her public key:

But which one should you use? RSA-PKCS#1.5, RSA-OAEP or RSA-PSS?

First, let’s get the acronyms out of the way. With PKCS, we have Public-Key Cryptography Standards, and which are standards that were defined by RSA Labs. With PSS, we have Probabilistic Signature Scheme, and OAEP is Optimal Asymmetric Encryption Padding.

The PKCS standards are one of the foundation elements of the Internet and were drafted by RSA Labs. In one of the original specifications for RSA, we saw it defined in PKCS#1:

It contained the methods of PKCS#1.5 and OAEP:

Basically, we have since found that PKCS#1.5 is open to a range of attacks [2] and that the OAEP method was more secure. No one should ever code with PKCS#1.5 in a production environment these days. Then, in 2003, the PKCS#1 standard was upgraded with Version 2.1:

Its main addition was RSA-PSS, and which is based on a paper by Bellare & Rogaway [3]:

It should be noted that OAEP is based on other work by Bellare and Rogaway [1].

RSA — The Rock of Trust

The RSA method is still around and is still used fairly extensively in digital signing — in fact it is the default signing method used with JSON Web Tokens. Also, most of the digital certificates that are used on the Internet still use RSA as their signing method. So while Bitcoin and Ethereum have dumped RSA in favour of ECDSA (and based on ECC — Elliptic Curve Cryptography), RSA is often used in many applications, including with OpenSSL authentication.

RSA signing can be seen as the opposite of the encryption process, and where we operate on a hash of the message. In RSA, we have a modulus (N) which is based on two prime numbers (p and q):


We then have a public exponent (e- the verifier) and a private exponent (d — the signer). Initially, we hash the message (msg):


Then, we use the private exponent to determine the signature:

s=h^d (mod N))

To verify we take the public exponent and make sure that:

hash(msg)==s^e (mod N)

Unfortunately, pure RSA signing is open to a number of attacks, and which can be overcome using either RSA-OEAP or RSA-PSS.

PKCS#v1.5 Should Never Been Seen!

The simplest way to pad the input data to RSA is to use PKCS#v1.5. With this, we pad to the start of the message bytes, and where the first two bytes are 0x00 and 0x02, and followed by a number of non-zero bytes. We then add a 0x00 byte to identify the end of the padding and then followed by the message bytes:

0x00 0x02 [some non-zero bytes ] 0x00 [message bytes]

When unpadding, the 0x00, 0x02 sequence is detected, and then we search for the 0x00 byte and take remove all of the preceding bytes. Unfortunately, Daniel Bleichenbacher published a paper [2] that showed how the PKCS#v1.5 padding method could be cracked with a chosen cipher attack: [2]:

The Bleichenbacker’s attack has been continually compromising some systems for decades, but TLS 1.3 now overcomes it by dropping support for PKCS#v1.5. To overcome the weaknesses of PKCS#v1.5, we can either use OAEP (Optimal Asymmetric Encryption Padding) or PSS (Probabilistic Signature Scheme) methods to add padding which can be removed later.

Optimal Asymmetric Encryption Padding (OAEP)

So, our solution is to use padding, and one of the most popular methods is Optimal Asymmetric Encryption Padding (OAEP). The method was first published by Bellare and Rogaway as [here][1]:

It has since been standardized in PKCS#1 v2 and RFC 2437 [here]:

Overall we operate on n bits at a time, and where n is the number of bits in the modulus (Figure 1). This is based on a Feistel network, and where if we EX-OR sometime with the same value twice, we end up with the original value.

With this - as illustrated in Figure 1 - we have two fixed values of k0 and k1. k1 defines the number of zeros to pad onto the message, and k0 defines the number of bits in a random number (r). The number of bits we are processing in the message is thus nk0−k1 bits. We then have two hashing functions of G and H. The G function expands the k0 bits of r into nk0 bits, and which is EX-OR with the padded message. This produces X. Next, we take the value and feed it into H, and which hashes the bits to produce k0 bits. This is then EX-OR (⊕) with r to produce Y (and which has k0 bits).

Figure 1: Padding and unpadding for RSA OAEP

We now have X and Y for our padding (Mp=X||Y), and where the total number of bits will be n. This can then be operated on with a (mod N) operation. The values of X and Y can now go into our cipher for:

C=Mp^e (mod N)

and then decrypted with:

P=C^d (mod N)

We can now strip off the padding. To recover the message we first recover the random value (r) from:


and then with r we recover the padded message:


We then strip off k1 zeros from the end of this message and recover M.

PSS (Probabilistic Signature Scheme)

Four years after the OEAP paper, Bellare and Rogaway produced their PSS paper [3]:

As we have seen PKCS#v1.5 is weak in its padding, and suffers from many weaknesses:

  • It is deterministic. With this, we do not have a random element that changes the signature when we sign for the same data.
  • The hashed value can be extracted from the signature. An intruder can extract the hash from the signature and reveal the hashed value. While this does not reveal the original message, an intruder could eventually match it to a given message.
  • It has no formal security proof.

RSA-PSS overcomes these weaknesses. It uses randomized signatures for the same message — and is thus probabilistic rather than deterministic. For this, we have a random salt value which is added to the signature process. It also stops the message hash from being extracted from the signature. Along with this, it has a formal security proof of its security.

As with OAEP, it uses a mask generation function (MGF) and which is pseudorandom. This produces a non-deterministic output signature. With this, we use a salt value to produce the random signature, and where this salt value can be extracted from the signature (or contained in the signature).

The padding method is fully defined in RFC 2447:

Notice that the end part of the encoding is “0xbc”. This hex value defines the trailer to the encoded data.


The outline code is [here]:

package main
import (


func main() {
input_string := "This is a test"
argCount := len(os.Args[1:])
if argCount > 0 {
input_string = string(os.Args[1])
if argCount > 1 {
size,_ = strconv.Atoi(os.Args[2])
private_key, _ := rsa.GenerateKey(rand.Reader, size)
public_key := &private_key.PublicKey

message := []byte(input_string)

hashed := sha256.Sum256(message)
signature, _ := rsa.SignPSS(rand.Reader, private_key, crypto.SHA256, hashed[:],nil)
verify:= rsa.VerifyPSS(public_key, crypto.SHA256, hashed[:], signature,nil)
fmt.Printf("\nInput message: [%s]", input_string)
fmt.Printf("\nMessage hash (SHA-256): [%x]", hashed[:])
fmt.Printf("\nKey size: [%d]",size)
fmt.Printf("\n\nPrivate key:\nd=%x\nN=%x\n", private_key.D,private_key.N)
fmt.Printf("\nPublic key:\ne=%x\nN=%x\n", public_key.E,public_key.N)
fmt.Printf("\n\nSignature: %x\n",signature)
if (verify==nil) {
fmt.Printf("\nRSA signature verified")

A sample run for a 1,024 bit modulus:

Input message: [Test]
Message hash (SHA-256): [532eaabd9574880dbf76b9b8cc00832c20a6ec113d682299550d7a6e0f345e25]
Key size: [1024]
Private key:
Public key:

Signature: 0449096ac1871dcd322effa068360e972960b0ce37339b21c181d4ed60a4c3cfe4fb871655d379bfcf7c4c7727899272c1a4bc0af8a2962a469827b21d382cdab7df518537c502203fad30532be53d4c46d2712b27f1bb4af206f3291f1250560b8e51229d70c784f2c5af019de7b1e903572d1f2d430979f47def19066b7b03
RSA signature verified

If you count the number of hex characters in the modulus (N), you see that we have 256 characters. Two hex characters make one byte, thus we have 128 bytes, and which is 1,024 bits. This will be created from two 512-bit prime numbers. For a 2,048-bit modulus:

Input message: [Test]
Message hash (SHA-256): [532eaabd9574880dbf76b9b8cc00832c20a6ec113d682299550d7a6e0f345e25]
Key size: [2048]
Private key:
Public key:

Signature: 78a7675e7032ca93ab5acbe689cf9d1c963bce18514f28401c61a2c15dd909c43e5c1d376c918ab76fa8a403ed4f5097030cbe8e4bf73445f46f1febe7a7577a8e62a9ed347fc39304091ea4a3468cbff725b081b9a3190694fa4295cfdf655803f68e618018c8b46258b57217285fde22be5bc2fe696d785212ded7d3a96af5793aa4ace962f46851b1140e698e5f1314d6c5fa637163df39b024c780047fdba59b512a66d035807cddb0dceb85e0fa7fb94ef39c7ca0a4dfe27f96dfef746402edab909d493a9c0ad88dbbeeb34ce005d4247a6265f471539f084f45d00241d092ad180a620f42fc97a4a32e934e54d1c7b3d19396ce9c8f5299dadc7629d5
RSA signature verified

If you count the number of hex characters in the modulus (N) you see that we have 512 characters. Two hex characters make one byte, thus we have 256 bytes, and which is 2,048 bytes. This will be created from two 1,024-bit prime numbers.


[1] Bellare, M., & Rogaway, P. (1994, May). Optimal asymmetric encryption. In Workshop on the Theory and Application of Cryptographic Techniques (pp. 92–111). Springer, Berlin, Heidelberg.

[2] Bleichenbacher, D. (1998, August). Chosen ciphertext attacks against protocols based on the RSA encryption standard PKCS# 1. In Annual International Cryptology Conference (pp. 1–12). Springer, Berlin, Heidelberg.

[3] Bellare, M., & Rogaway, P. (1998). PSS: Provably secure encoding method for digital signatures. IEEE P1363a: Provably secure signatures.




Prof Bill Buchanan OBE

Professor of Cryptography. Serial innovator. Believer in fairness, justice & freedom. Based in Edinburgh. Old World Breaker. New World Creator. Building trust.