Padding
Padding
1 Introduction
At a recent count ([Link] over 300 million RSA-enabled prod-
ucts had been shipped worldwide. This popularity, and the ongoing standard-
izations of signature and encryption formats [2, 13, 20, 21, 22, 36] highlight
the need to challenge claims that such standards eradicate RSA's multiplicative
properties.
1 an integer is `-smooth if it has no bigger factors than `.
Exponentiation is homomorphic and RSA-based protocols are traditionally
protected against chosen-plaintext forgeries [9, 11, 35] by using a padding (or
redundancy) function to make sure that :
RSA((x)) RSA((y)) 6= RSA((x y)) mod n
In general, (x) hashes x and concatenates its digest to pre-de ned strings;
in some cases, substitution and permutation are used as well.
While most padding schemes gain progressive recognition as time goes by,
several speci c results exist : a few functions were broken by ad-hoc analysis
([16, 24] showed, for instance, that homomorphic dependencies can still appear
in (m) = a m + b) while at the other extreme, assuming that the underlying
building-blocks are ideal, some functions [5, 6] are provably secure in the random
oracle model.
The contribution of this paper is that the complexity of forging chosen
message-signature pairs is sometimes much lower than that of breaking RSA
by frontal attacks (factoring and collision-search). The strategy introduced in
this article does not challenge RSA's traditional security assumptions; instead,
it seeks for multiplicative relations using the expected smoothness of moderate-
size integers (the technique is similar in this respect to the quadratic sieve [33],
the number eld sieve [32] and the index-calculus method for computing discrete
logarithm [1]).
As usual, our playground will be a setting in which the attacker A and the
signer S interact as follows :
A asks S to provide the signatures of ? 1 chosen messages ( being
polylogarithmically-bounded in n). S will, of course, correctly pad all the plain-
texts before raising them to his secret power d.
After the query phase and some post-processing, A must exhibit the sig-
nature of at least one message (m ) which has never been submitted to S .
Previous work : Misarsky's PKC'98 invited survey [30] is probably the best
documented reference on multiplicative RSA forgeries. Davida's observation [9]
is the basis of most RSA forgery techniques. [16, 24] forge signatures that are
similar to pkcs #1 v2.0 but do not produce their necessary SHA/MD5 digests
[31, 34]. [15] analyzes the security of RSA signatures in an interactive context.
Michels et al. [28] create relations between the exponents of de Jonge-Chaum
and Boyd's schemes; their technique extends to blind-RSA but does not apply
to any of the padding schemes attacked in this paper. Baudron and Stern [4]
apply lattice reduction to analyze the security of RSA in a security-proof
perspective.
A Desmedt-Odlyzko variant [11] applicable to padded RSA signatures is
sketched in section 3.5 of [30]. It consists in factoring (m ) into small primes
and obtaining the e-th roots of these primes from multiplicative combinations of
signatures of messages which (mi )-values are smooth. The signature of m is
forged by multiplying the e-th roots of the factors of (m ). The complexity of
this attack depends on the size of and not on the size of n; the approach is thus
inapplicable to padding formats having the modulus' size (e.g. iso 9796-2). In
this paper we extend this strategy to padding schemes for which a linear com-
bination of n and the padded value is small; when applied to William's scheme
our attack allows to factor n.
2 A general outline
Let fn; eg be an RSA public key and d be the corresponding secret key. Although
in this paper will alternatively denote iso 9796-2, pkcs #1 v2.0, ansi x9.31,
ssl-3.02 or an iso 9796-1 variant denoted F , we will start by describing our
attack in a simpler scenario where is SHA-1 or MD5 (in other words, messages
will only be hashed before being exponentiated); the attack will be later adapted
to the di erent padding standards mentioned above.
The outline of our idea is the following : since (m) is rather short (128 or 160
bits), the probability that (m) is `-smooth (for a reasonably small `) is small
but non-negligible; consequently, if A can obtain the signatures of chosen smooth
(mi )-values, then he could look for a message m such that (m ) has no bigger
factors than pk (the k-th prime) and construct (m )d mod n as a multiplicative
combination of the signatures of the chosen plaintexts m1 ; : : : ; m ?1.
The diculty of nding `-smooth digests is a function of ` and the size
of (m). De ning (x; y) = #fv < x, suchpthat v is y-smoothg, it is known
[12, 14, 19] that, for large x, the ratio (x; t x)=x is equivalent to Dickman's
function de ned by :
8
>
>
<
1 if 0 t 1
(t) = > Z t
(v ? 1) dv if n t n + 1
>
: (n) ? v
n
CL;k = O( (L=Flog
(L) kL log2 (pk ) kL log2 (k ln k)
(p )) ) = O( (L= log (p )) ) = O( (L= log (k ln k)) )
2 k 2 k 2
this is justi ed by the fact that pk -smooth L-bit digests are expected only
once per 1=(L= log2 (pk )) and that the most straightforward way to factor L
is k trial divisions by the rst primes (where each division costs L log2 (pi ) bit-
operations).
These formulae should, however, be handled with extreme caution for the
following reasons :
Although in complexity terms L can be analyzed as a variable, one should
constantly keep in mind that L is a xed value because the output size of speci c
hash functions is not extensible.
Trial division is de nitely not the best candidate for F (L). In practice, our
program used the following strategy to detect the small factors of (m) : since
very small divisors are very common, it is worthwhile attempting trial and error
division up to pi = 2048 before applying a primality test to (m) (the candidate
is of course rejected if the test fails). As a next step, trial and error division by
primes smaller than 15; 000 is performed and the resulting number is handed-
over to Pollard-Brent's algorithm [7] which is very good at nding small factors.
Since it costs O(pppi ) to pull-out pi using Pollard-Brent's method we can further
bound F (L) by L pk to obtain :
p
CL;k = O( (L=Llogk (lnk kln k)) )
2
3 The attack
The attack applies to RSA and Williams' scheme [37]; we assume that the reader
is familiar with RSA but brie y recall Williams' scheme, denoting by J(x), the
Jacobi symbol of x with respect to n.
In Williams' scheme (m) = 6 mod 16 and :
p = 3 mod 8 e=2
q = 7 mod 8 d = (n ? p ? q + 5)=8
Before signing, S must check that J((m)) = 1. If J((m)) = ?1, (m) is
replaced by (m)=2 to guarantee that J((m)) = 1 since J(2) = ?1.
A signature s is valid if w = s2 mod n is such that :
8
w >
>
<
if w = 6 mod 8
(m) = > 2nw? w
? if
if
w = 3 mod 8
w = 7 mod 8
>
:
2(n ? w) if w = 2 mod 8
sucient to guarantee that (at least) one of the vectors can be expressed as a
linear combination (easily found by Gaussian elimination) of the other vectors.
When e is the r-th power of a prime p, = k +1 vectors are again sucient
to ensure that (at least) one vector can be expressed as a linear combination of
the others. Using the p-adic expansion of the vectors' coecients and Gaus-
sian elimination on k + 1 vectors, we can write one of the vectors as a linear
combination of the others.
Finally, the previous argument can be extended to the most general case :
!
Y
e= pri i
i=1
where it appears that = 1 + !k = O(k log e) vectors are sucient to
guarantee that (at least) one vector is a linear combination of the others; modulo
each of the pri i , the attacker can nd a set Ti of (! ? 1)k + 1 vectors, each of
which can be expressed by Gaussian elimination as a linear combination of k
other vectors. Intersecting the Ti and using Chinese remaindering, one gets that
(at least) one vector must be a linear combination of the others modulo e.
The overall complexity of our attack can therefore be bounded by :
p
C0 Lk log e k ln k
L;k = O(CL;k ) = O( (L= log (k ln k )) )
2
0
and the attacker can optimize his resources by operating at a k where CL;k
is minimal.
Space complexity (dominated by the Gaussian elimination) is O(k2 log3 e).
4 Analyzing di erent signature formats
4.1 The security of iso/iec-9796-1-like signatures
iso/iec-9796-1 [21] was published in 1991 by ISO as the rst international stan-
dard for digital signatures. It speci es padding formats applicable to algorithms
providing message recovery (algorithms are not explicit but map r bits to r bits).
iso 9796-1 is not hashing-based and there are apparently no attacks [16, 18]
other than factoring on this scheme ([30] : \...iso 9796-1 remains beyond the
reach of all multiplicative attacks known today..."). The scheme is used to sign
messages of limited length and works as follows when n and m are respectively
N = 2 + 1 and -bit numbers and = 4` is a multiple of eight.
De ne by a b the concatenation of a and b, let !i be the i-th nibble of m
and denote by s(x) the hexadecimal substitution table2 :
x=0123456789ABCDEF
s(x) = E 3 5 8 9 4 2 F 0 D B 6 7 A C 1
Letting s(x) force the most signi cant bit in s(x) to 1 and s~(x) complement
the least signi cant bit of s(x), iso 9796-1 speci es :
(m) = s(!`?1 ) s~(!`?2 ) !`?1 !`?2
s(!`?3 ) s(!`?4 ) !`?3 !`?4
:::
s(!3 ) s(!2 ) !3 !2
s(!1 ) s(!0 ) !0 616
The attack that we are about to describe applies to a slight variant of iso
9796-1 where s~(x) is replaced by s(x); this variant (denoted F ) di
ers from iso
9796-1 by one single bit.
Let aj denote nibbles and consider messages of the form :
mi = a6 a5 a4 a3 a2 a1 6616
a6 a5 a4 a3 a2 a1 6616
:::
a6 a5 a4 a3 a2 a1 6616
which F -padding is :
(mi ) = s(a6 ) s(a5 ) a6 a5 s(a4 ) s(a3 ) a4 a3
s(a2 ) s(a1 ) a2 a1 216 216 616 616
:::
s(a6 ) s(a5 ) a6 a5 s(a4 ) s(a3 ) a4 a3
s(a2 ) s(a1 ) a2 a1 216 216 616 616
2 actually, the bits of s(x) are respectively x3 x1 x0 , x3 x2 x0 , x3 x2 x1
and x2 x1 x0 but this has no importance in our analysis.
Restricting the choice of a6 to the (eight) nibbles for which s = s, we can
generate 223 numbers of the form (mi ) = x ?23 where x is the 8-byte number
s(a6 ) s(a5 ) a6 a5 s(a4 ) s(a3 ) a4 a3 s(a2 ) s(a1 ) a2 a1 226616 and :
32?1
=X
?23 = 264i
i=0
Section 3 could thus apply (treat ?23 as an extra pi ) as soon as the expecta-
tion of pk -smooth x-values reaches k + 1 :
k + 1 223 log (64 (3)
2 k ln k )
Partial message recovery. For simplicity, assume that N , L and the size of
m are all multiples of eight and that the hash function is known to both parties.
The message m = m[1] m[2] is separated into two parts where m[1] consists of
the N ? L ? 16 most signi cant bits of m and m[2] of all the remaining bits of
m. The padding function is :
(m) = 6A16 m[1] HASH(m) BC16
and m[2] is transmitted in clear.
Dividing (6A16 + 1) 2N by n we obtain :
(6A16 + 1) 2N = i n + r with r < n < 2N
References
1. L. Adleman, A subexponential algorithm for the discrete logarithm prob-
lem with applications to cryptography, Proceedings of the IEEE 20-th
Annual symposium on the foundations of computer science, pp. 55-60,
1979.
2. ANSI X9.31, Digital signatures using reversible public-key cryptography
for the nancial services industry (rDSA), 1998.
3. E. Bach and R. Peralta, Asymptotic semismoothness probabilities, Math-
ematics of computation, vol. 65, no. 216, pp. 1701{1715, 1996.
4. O. Baudron and J. Stern, To pad or not to pad : does formatting degrade
security ?, 1999 RSA Data Security Conference proceeding book, 1999.
5. M. Bellare and P. Rogaway, Random oracles are practical : a paradigm for
designing ecient protocols, Proceedings of the rst annual conference on
computer and communication security, acm, 1993.
6. M. Bellare and P. Rogaway, The exact security of digital signatures : how
to sign with RSA and Rabin, Advances in cryptology eurocrypt'96,
Springer-Verlag, Lectures notes in computer science 1070, pp. 399{416,
1996.
7. R. Brent, An improved Monte Carlo factorization algorithm, Nordisk Tid-
skrift for Informationsbehandling (bit) vol. 20, pp. 176{184, 1980.
8. N. de Bruijn, On the number of positive integers x and free of prime
factors y, Indagationes Mathematicae, vol. 13, pp. 50{60, 1951. (cf. as
well to part II, vol. 28, pp. 236{247, 1966.).
9. G. Davida, Chosen signature cryptanalysis of the RSA (MIT) public-key
cryptosystem, TR-CS-82-2, Department of electrical engineering and com-
puter science, University of Wisconsin, Milwaukee, 1982.
10. D. Denning, Digital signatures with RSA and other public-key cryptosys-
tems, Communications of the ACM, vol. 27-4, pp. 388{392, 1984.
11. Y. Desmedt and A. Odlyzko. A chosen text attack on the RSA cryp-
tosystem and some discrete logarithm schemes, Advances in cryptology
crypto'85, Springer-Verlag, Lectures notes in computer science 218, pp.
516{522, 1986.
12. K. Dickman, On the frequency of numbers containing prime factors of a
certain relative magnitude, Arkiv for matematik, astronomi och fysik, vol.
22A, no. 10, pp. 1{14, 1930.
13. DIN NI-17.4, Speci cation of chipcard interface with digital signature ap-
plication/function according to SigG and SigV, version 1.0, 1998.
14. J. Dixon, Asymptotically fast factorization of integers, Mathematics of
computation, vol. 36, no. 153, pp. 255{260, 1981.
15. J. Evertse and E. van Heyst, Which new RSA-signatures can be computed
from certain given RSA signatures ?, Journal of cryptology vol. 5, no. 1,
41{52, 1992.
16. M. Girault, J.-F. Misarsky, Selective forgery of RSA signatures using re-
dundancy, Advances in cryptology eurocrypt'97, Springer-Verlag, Lec-
tures notes in computer science 1233, pp. 495{507, 1997.
17. J. Gordon, How to forge RSA key certi cates, Electronic Letters, vol. 21,
no. 9, April 25-th, 1985.
18. L. Guillou, J.-J. Quisquater, M. Walker, P. Landrock and C. Shaer, Pre-
cautions taken against various attacks in iso/iec dis 9796, Advances in
cryptology eurocrypt'90, Springer-Verlag, Lectures notes in computer
science 473, pp. 465{473, 1991.
19. H. Halberstam, On integers whose prime factors are small, Proceedings of
the London mathematical society, vol. 3, no. 21, pp. 102{107, 1970.
20. K. Hickman, The SSL Protocol, December 1995. Available electronically
at : [Link]
21. ISO/IEC 9796, Information technology - Security techniques - Digital sig-
nature scheme giving message recovery, Part 1 : Mechanisms using redun-
dancy, 1999.
22. ISO/IEC 9796-2, Information technology - Security techniques - Digital
signature scheme giving message recovery, Part 2 : Mechanisms using a
hash-function, 1997.
23. ISO/IEC 10118-2, Information technology - Security techniques - Hash-
functions; Part 2 : Hash functions using an n-bit block-cipher algorithm,
1994.
24. W. de Jonge and D. Chaum. Attacks on some RSA signatures, Advances
in cryptology crypto'85, Springer-Verlag, Lectures notes in computer sci-
ence 218, pp. 18{27, 1986.
25. A. Lenstra, Generating RSA moduli with a predetermined portion, Ad-
vances in cryptology asiacrypt'98, Springer-Verlag, Lectures notes in
computer science 1514, pp. 1{10, 1998.
26. A. Lenstra, de auditu, January 1999.
27. A. Menezes, P. van Oorschot and S. Vanstone, Handbook of applied cryp-
tography, crc Press.
28. M. Michels, M. Stadler and H.-M. Sun, On the security of some variants
of the RSA signature scheme, Computer security-esorics'98, Springer-
Verlag, Lectures notes in computer science 1485, pp. 85{96, 1998.
29. J.-F. Misarsky, A multiplicative attack using LLL algorithm on RSA sig-
natures with redundancy, Advances in cryptology crypto'97, Springer-
Verlag, Lectures notes in computer science 1294, pp. 221{234, 1997.
30. J.-F. Misarsky, How (not) to design RSA signature schemes, Public-key
cryptography, Springer-Verlag, Lectures notes in computer science 1431,
pp. 14{28, 1998.
31. National Institute of Standards and Technology, Secure hash standard,
FIPS publication 180-1, April 1994.
32. J. Pollard, Factoring with cubic integers, The development of the number
eld sieve, Springer-Verlag, Lectures notes in computer science 1554, pp.
4{10, 1993.
33. C. Pomerance, The quadratic sieve factoring algorithm, Advances in cryp-
tology eurocrypt'84, Springer-Verlag, Lectures notes in computer science
209, pp. 169{182, 1985.
34. R. Rivest, RFC 1321 : The MD5 message-digest algorithm, Internet activ-
ities board, April 1992.
35. R. Rivest, A. Shamir and L. Adleman, A method for obtaining digital sig-
natures and public-key cryptosystems, Communications of the ACM, vol.
21-2, pp. 120{126, 1978.
36. RSA Laboratories, pkcs #1 : RSA cryptography speci cations, version
2.0, September 1998.
37. H. Williams, A modi cation of the RSA public key encryption procedure,
IEEE TIT, vol. 26, pp. 726{729, 1980.
APPENDIX A
The following (redundant) look-up table lists for the various smoothness
and digest-size values concerned by this paper; (136=24), the probability that
a 136-bit number has no prime factors larger than 224 is 2?14:2 :
? log2 & 16 20 24 28 32 36 40 44 48 52 56 60 64 68 72
32 1.7 0.9 0.5 0.2 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
48 4.4 2.7 1.7 1.1 0.8 0.5 0.3 0.1 0.0 0.0 0.0 0.0 0.0 0.0 0.0
64 7.7 5.0 3.4 2.4 1.7 1.2 0.9 0.7 0.5 0.3 0.2 0.0 0.0 0.0 0.0
80 11.5 7.7 5.4 3.9 2.9 2.2 1.7 1.3 1.0 0.8 0.6 0.5 0.4 0.3 0.2
96 15.6 10.7 7.7 5.7 4.4 3.4 2.7 2.1 1.7 1.4 1.1 0.9 0.8 0.6 0.5
112 20.1 13.9 10.2 7.7 5.9 4.7 3.8 3.1 2.5 2.1 1.7 1.4 1.2 1.0 0.8
128 24.9 17.4 12.8 9.8 7.7 6.1 5.0 4.1 3.4 2.8 2.4 2.0 1.7 1.4 1.2
136 27.4 19.2 14.2 10.9 8.6 6.9 5.6 4.6 3.9 3.2 2.8 2.3 2.0 1.7 1.5
144 29.9 21.1 15.6 12.0 9.5 7.7 6.3 5.2 4.4 3.7 3.1 2.7 2.3 2.0 1.7
152 32.4 22.9 17.1 13.2 10.5 8.5 7.0 5.8 4.9 4.1 3.5 3.0 2.6 2.3 2.0
160 35.1 24.9 18.6 14.4 11.5 9.3 7.7 6.4 5.4 4.6 3.9 3.4 2.9 2.6 2.2
168 37.9 26.9 20.1 15.6 12.5 10.2 8.4 7.0 5.9 5.1 4.4 3.8 3.3 2.9 2.5
176 40.6 28.9 21.7 16.9 13.5 11.0 9.1 7.7 6.5 5.6 4.8 4.2 3.6 3.2 2.8
400 129. 95.2 73.9 59.2 49.0 41.5 35.1 30.2 26.5 23.1 20.8 18.5 16.7 15.1 13.7
512 179. 133 104 84.0 69.8 59.0 50.8 44.0 38.8 34.1 30.6 27.2 24.9 22.5 20.6
The table uses the exact formula (section 2) for t 10 and de Bruijn's
approximation [8] for t > 10 :
Z
(2t)?1=2 exp ? t + es ? 1 ds
(t) = s
0
where is the positive solution of e ? 1 = t and is Euler's constant.
APPENDIX B
The attack's time-consuming part is the exhaustive-search of k appropriate x-
strings; therefore, when one wants the x-strings to be 256-bits long, the increase
in k makes the attack impractical.
To overcome this problem, we suggest the following : as a rst step, col-
lect the signatures corresponding to moderate-size pk -smooth x-strings (which
are relatively easy to nd) and extract from their appropriate multiplicative
combinations the e-th roots of the k rst primes. Then, exhaustive-search two
plain-English 128-bit messages fm; m0 g ending by the letter such that (m)=?
f
i i
i=0 i=1
where pi denotes the i-th prime (with p0 = ?23 ) and beta[i] denotes the
elements of the following table :
1 2 1 2 2 2 2 1 2 2 2 1 1 2 2 2 1 1 2 1 2 2 2 2 2 1 1 2 1 1 2 1 1 2 1 1
1 1 1 1 1 1 2 1 1 1 1 2 1 1 1 1 2 2 1 1 2 1 2 1 1 2 2 1 1 1 1 2 1 1 2 1
1 1 1 1 2 2 1 2 1 2 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 2
1 1 1 2 2 2 2 1 2 2 1 1 2 2 2 2 1 1 2 1 2 2 2 2 1 1 1 2 1 1 2 1 1 1 1 2
2 1 1 1 1 2 2 1 2 2 1 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 1 2 1 2 2 1 1 2 1 1