Speed

A Small Exponent Is a Cube Root

With the public exponent 3, a short message cubed stays below the modulus, so the ciphertext is the plain cube of the message and a cube root gives the message back, with no key at all.

The question

RSA hides a message behind the reduction modulo n: m to the power e wraps around n many times and the result looks random. What if it never wraps? With a public exponent of 3 and a short message, m cubed can be smaller than n. Then nothing is reduced, the ciphertext is the plain number m cubed, and anyone can undo it with a cube root.

The key here, e3, is test material: a 512-bit key whose public exponent is 3 instead of the usual 65537. The lesson is arithmetic: it names no attack on any real system, and it shows why the next lessons add a padding.

Work it by hand

The message hi is the two bytes 68 69, the number 26,729. Its cube is 26,729 times 26,729 times 26,729, which is 19,096,251,818,489, or 115e314e61f9 in hexadecimal. The modulus has 512 bits, a number of 154 digits (about 1.0 followed by 154 zeros: 9.97 times 10 to the 153), so 19 trillion is far below it and no reduction takes place.

  • The ciphertext of hi under the test key is 64 bytes, but only the last six are not zero: 11 5e 31 4e 61 f9. The first 58 bytes are leading zeros.
  • To undo it, find the number whose cube is 19,096,251,818,489. Try 30,000: its cube is 27 trillion, too large. Try 20,000: 8 trillion, too small. The answer lies between them, and bisection finds 26,729.
  • Turn 26,729 back into bytes: 68 69, the text hi.

How short must a message be? A message of up to 21 bytes, 168 bits, cubes to at most 504 bits, which is below every 512-bit modulus. The step works at any key size as long as m cubed is below n.

Run it

The program takes the text message and the hexadecimal ciphertext. Line 10 turns the two bytes of the message into a number, and line 11 cubes it. The loop on lines 15 to 18 writes the cube in hexadecimal, 14 digits. The function on lines 1 to 9 drops leading zeros, so that the cube can be compared with the 128-digit ciphertext.

The extra value same is true: the ciphertext of hi from the test key is exactly the cube. This is a ciphertext that was made once with the key e3; the program has no key. It returns the cube as a number.

The message hi is the number 26729. Its cube in hexadecimal is 115e314e61f9 and the ciphertext without its leading zeros is 115e314e61f9; the two are the same.

Public test material, generated for this lesson. Never use it for anything real.

fn strip(text: string) -> string {
  let at = 0;
  for (i in range(0, str_len(text))) {
    if (at == 0) { if (str_substr(text, i, 1) != "0") { at = i + 1; } }
  }
  let kept = "0";
  if (at > 0) { kept = str_substr(text, at - 1, str_len(text) - at + 1); }
  return kept;
}
let m = hex_u16(ssl.hex(message), 0);
let cube = m * m * m;
let digits = "0123456789abcdef";
let text = "";
let rest = cube;
for (i in range(0, 14)) {
  text = str_substr(digits, rest % 16, 1) + text;
  rest = rest / 16;
}
lmcode_return_put("message_number", m);
lmcode_return_put("cube_hex", strip(text));
lmcode_return_put("ciphertext_hex", strip(ciphertext));
lmcode_return_put("same", strip(text) == strip(ciphertext));
let answer = cube;
{
  "answer": 19096251818489,
  "message_number": 26729,
  "cube_hex": "115e314e61f9",
  "ciphertext_hex": "115e314e61f9",
  "same": true
}

You can change the message to any two letters or digits, and the ciphertext to any hexadecimal text; same then says whether the two agree. Two-byte messages only: the program reads the first two bytes with hex_u16, and a message of one byte stops it with "byte 1 is past the end of the data", and an empty message with "byte 0 is past the end of the data". A message of three or more bytes is read as its first two bytes.

Your turn

The program below should return the whole number m whose cube is the number written as hexadecimal text in ciphertext: the ciphertext of a short message under an e = 3 key, so the number is below 2 to the power 53. Decide whether it does, and find the candidates that do. Check runs each candidate on the data shown and on five others.

A 64-byte ciphertext whose first 58 bytes are zero, and the whole number that the shown program returns.

Public test material, generated for this lesson. Never use it for anything real.

let digits = "0123456789abcdef";
let c = 0;
for (i in range(0, str_len(ciphertext))) {
  c = c * 16 + str_find(digits, str_substr(ciphertext, i, 1));
}
let answer = 0;
for (m in range(1, 208064)) {
  if (answer == 0) { if (m * m >= c) { answer = m; } }
}
{
  "answer": 0
}

ciphertext is the 64-byte ciphertext of a short message under an RSA key with public exponent 3, written as hexadecimal text with leading zeros; it is the cube of a whole number m between 1 and 208063, and it is below 2 to the power 53. Return m.

Read the result carefully

The cube root works because no reduction happened, not because RSA is weak in general. With a public exponent of 65537, or with a padded message that fills the modulus, m to the power e is far above n and wraps many times, and a cube root of the ciphertext gives nothing. A padding such as OAEP is what makes sure of that; the next lessons show it.

The numbers here are small on purpose: programs of this page stop at 2 to the power 53, so the cases use numbers whose cube is below 2 to the power 53: messages of up to three bytes. The page shows no attack on any deployed system and says nothing about how often small exponents are used. The ciphertexts come from a test key and must never be mistaken for real ones.

Recap

  • With e equal to 3, a ciphertext is m cubed modulo n, and when m cubed is below n it is just m cubed.
  • A cube root, here by bisection or a bounded search, returns the message without the private key.
  • Up to 21 bytes are enough for a 512-bit modulus; the arithmetic works at any key size while m cubed stays below n.
  • Padding makes the number to be raised to the power e as large as n, so this does not happen.