RFC3447 - Public-Key Cryptography Standards (PKCS) #1: RSA C

时间:2005-02-17 来源: 作者: 点击:
Network Working Group J. Jonsson Request for Comments: 3447 B. Kaliski Obsoletes: 2437 RSA Laboratories Category: Informational February 2003 Public-Key Cryptography Standards (PKCS) #1: RSA Cryptography Specifications Version 2.1 Status of this Memo
  Network Working Group J. Jonsson
Request for Comments: 3447 B. Kaliski
Obsoletes: 2437 RSA Laboratories
Category: Informational February 2003

Public-Key Cryptography Standards (PKCS) #1: RSA Cryptography
Specifications Version 2.1

Status of this Memo

This memo provides information for the Internet community. It does
not specify an Internet standard of any kind. Distribution of this
memo is unlimited.

Copyright Notice

Copyright (C) The Internet Society (2003). All Rights Reserved.

Abstract

This memo represents a republication of PKCS #1 v2.1 from RSA
Laboratories' Public-Key Cryptography Standards (PKCS) series, and
change control is retained within the PKCS process. The body of this
document is taken directly from the PKCS #1 v2.1 document, with
certain corrections made during the publication process.

Table of Contents

1. Introduction...............................................2
2. Notation...................................................3
3. Key types..................................................6
3.1 RSA public key..........................................6
3.2 RSA private key.........................................7
4. Data conversion primitives.................................8
4.1 I2OSP...................................................9
4.2 OS2IP...................................................9
5. Cryptographic primitives..................................10
5.1 Encryption and decryption primitives...................10
5.2 Signature and verification primitives..................12
6. Overview of schemes.......................................14
7. Encryption schemes........................................15
7.1 RSAES-OAEP.............................................16
7.2 RSAES-PKCS1-v1_5.......................................23
8. Signature schemes with appendix...........................27
8.1 RSASSA-PSS.............................................29
8.2 RSASSA-PKCS1-v1_5......................................32
9. Encoding methods for signatures with appendix.............35

9.1 EMSA-PSS...............................................36
9.2 EMSA-PKCS1-v1_5........................................41
Appendix A. ASN.1 syntax...........................................44
A.1 RSA key representation.................................44
A.2 Scheme identification..................................46
Appendix B. Supporting techniques..................................52
B.1 Hash functions.........................................52
B.2 Mask generation functions..............................54
Appendix C. ASN.1 module...........................................56
Appendix D. Intellectual Property Considerations...................63
Appendix E. Revision history.......................................64
Appendix F. References.............................................65
Appendix G. About PKCS.............................................70
Appendix H. Corrections Made During RFCPublication Process........70
Security Considerations............................................70
Acknowledgements...................................................71
Authors' Addresses.................................................71
Full Copyright Statement...........................................72

1. Introduction

This document provides recommendations for the implementation of
public-key cryptography based on the RSA algorithm [42], covering the
following aspects:

* Cryptographic primitives

* Encryption schemes

* Signature schemes with appendix

* ASN.1 syntax for representing keys and for identifying the schemes

The recommendations are intended for general application within
computer and communications systems, and as such include a fair
amount of flexibility. It is expected that application standards
based on these specifications may include additional constraints.
The recommendations are intended to be compatible with the standard
IEEE-1363-2000 [26] and draft standards currently being developed by
the ANSI X9F1 [1] and IEEE P1363 [27] working groups.

This document supersedes PKCS #1 version 2.0 [35][44] but includes
compatible techniques.

The organization of this document is as follows:

* Section 1 is an introduction.

* Section 2 defines some notation used in this document.

* Section 3 defines the RSA public and private key types.

* Sections 4 and 5 define several primitives, or basic mathematical
operations. Data conversion primitives are in Section 4, and
cryptographic primitives (encryption-decryption, signature-
verification) are in Section 5.

* Sections 6, 7, and 8 deal with the encryption and signature
schemes in this document. Section 6 gives an overview. Along
with the methods found in PKCS #1 v1.5, Section 7 defines an
OAEP-based [3] encryption scheme and Section 8 defines a PSS-based
[4][5] signature scheme with appendix.

* Section 9 defines the encoding methods for the signature schemes
in Section 8.

* Appendix A defines the ASN.1 syntax for the keys defined in
Section 3 and the schemes in Sections 7 and 8.

* Appendix B defines the hash functions and the mask generation
function used in this document, including ASN.1 syntax for the
techniques.

* Appendix C gives an ASN.1 module.

* Appendices D, E, F and G cover intellectual property issues,
outline the revision history of PKCS #1, give references to other
publications and standards, and provide general information about
the Public-Key Cryptography Standards.

2. Notation

c ciphertext representative, an integer between 0 and
n-1

C ciphertext, an octet string

d RSA private exponent

d_i additional factor r_i's CRT exponent, a positive
integer such that

e * d_i == 1 (mod (r_i-1)), i = 3, ..., u

dP p's CRT exponent, a positive integer such that

e * dP == 1 (mod (p-1))

dQ q's CRT exponent, a positive integer such that

e * dQ == 1 (mod (q-1))

e RSA public exponent

EM encoded message, an octet string

emBits (intended) length in bits of an encoded message EM

emLen (intended) length in octets of an encoded message EM

GCD(. , .) greatest common divisor of two nonnegative integers

Hash hash function

hLen output length in octets of hash function Hash

k length in octets of the RSA modulus n

K RSA private key

L optional RSAES-OAEP label, an octet string

LCM(., ..., .) least common multiple of a list of nonnegative
integers

m message representative, an integer between 0 and n-1

M message, an octet string

mask MGF output, an octet string

maskLen (intended) length of the octet string mask

MGF mask generation function

mgfSeed seed from which mask is generated, an octet string

mLen length in octets of a message M

n RSA modulus, n = r_1 * r_2 * ... * r_u , u >= 2

(n, e) RSA public key

p, q first two prime factors of the RSA modulus n

qInv CRT coefficient, a positive integer less than p such
that

q * qInv == 1 (mod p)

r_i prime factors of the RSA modulus n, including r_1 = p,
r_2 = q, and additional factors if any

s signature representative, an integer between 0 and n-1

S signature, an octet string

sLen length in octets of the EMSA-PSS salt

t_i additional prime factor r_i's CRT coefficient, a
positive integer less than r_i such that

r_1 * r_2 * ... * r_(i-1) * t_i == 1 (mod r_i) ,

i = 3, ... , u

u number of prime factors of the RSA modulus, u >= 2

x a nonnegative integer

X an octet string corresponding to x

xLen (intended) length of the octet string X

0x indicator of hexadecimal representation of an octet or
an octet string; "0x48" denotes the octet with
hexadecimal value 48; "(0x)48 09 0e" denotes the
string of three consecutive octets with hexadecimal
value 48, 09, and 0e, respectively

\lambda(n) LCM(r_1-1, r_2-1, ... , r_u-1)

\xor bit-wise exclusive-or of two octet strings

\ceil(.) ceiling function; \ceil(x) is the smallest integer
larger than or equal to the real number x

|| concatenation operator

== congruence symbol; a == b (mod n) means that the
integer n divides the integer a - b

Note. The CRT can be applied in a non-recursive as well as a
recursive way. In this document a recursive approach following
Garner's algorithm [22] is used. See also Note 1 in Section 3.2.

3. Key types

Two key types are employed in the primitives and schemes defined in
this document: RSA public key and RSA private key. Together, an RSA
public key and an RSA private key form an RSA key pair.

This specification supports so-called "multi-prime" RSA where the
modulus may have more than two prime factors. The benefit of multi-
prime RSA is lower computational cost for the decryption and
signature primitives, provided that the CRT (Chinese Remainder
Theorem) is used. Better performance can be achieved on single
processor platforms, but to a greater extent on multiprocessor
platforms, where the modular exponentiations involved can be done in
parallel.

For a discussion on how multi-prime affects the security of the RSA
cryptosystem, the reader is referred to [49].

3.1 RSA public key

For the purposes of this document, an RSA public key consists of two
components:

n the RSA modulus, a positive integer
e the RSA public exponent, a positive integer

In a valid RSA public key, the RSA modulus n is a product of u
distinct odd primes r_i, i = 1, 2, ..., u, where u >= 2, and the RSA
public exponent e is an integer between 3 and n - 1 satisfying GCD(e,
\lambda(n)) = 1, where \lambda(n) = LCM(r_1 - 1, ..., r_u - 1). By
convention, the first two primes r_1 and r_2 may also be denoted p
and q respectively.

A recommended syntax for interchanging RSA public keys between
implementations is given in Appendix A.1.1; an implementation's
internal representation may differ.

3.2 RSA private key

For the purposes of this document, an RSA private key may have either
of two representations.

1. The first representation consists of the pair (n, d), where the
components have the following meanings:

n the RSA modulus, a positive integer
d the RSA private exponent, a positive integer

2. The second representation consists of a quintuple (p, q, dP, dQ,
qInv) and a (possibly empty) sequence of triplets (r_i, d_i, t_i),
i = 3, ..., u, one for each prime not in the quintuple, where the
components have the following meanings:

p the first factor, a positive integer
q the second factor, a positive integer
dP the first factor's CRT exponent, a positive integer
dQ the second factor's CRT exponent, a positive integer
qInv the (first) CRT coefficient, a positive integer
r_i the i-th factor, a positive integer
d_i the i-th factor's CRT exponent, a positive integer
t_i the i-th factor's CRT coefficient, a positive integer

In a valid RSA private key with the first representation, the RSA
modulus n is the same as in the corresponding RSA public key and is
the product of u distinct odd primes r_i, i = 1, 2, ..., u, where u
>= 2. The RSA private exponent d is a positive integer less than n
satisfying

e * d == 1 (mod \lambda(n)),

where e is the corresponding RSA public exponent and \lambda(n) is
defined as in Section 3.1.

In a valid RSA private key with the second representation, the two
factors p and q are the first two prime factors of the RSA modulus n
(i.e., r_1 and r_2), the CRT exponents dP and dQ are positive
integers less than p and q respectively satisfying

e * dP == 1 (mod (p-1))
e * dQ == 1 (mod (q-1)) ,

and the CRT coefficient qInv is a positive integer less than p
satisfying

q * qInv == 1 (mod p).

If u > 2, the representation will include one or more triplets (r_i,
d_i, t_i), i = 3, ..., u. The factors r_i are the additional prime
factors of the RSA modulus n. Each CRT exponent d_i (i = 3, ..., u)
satisfies

e * d_i == 1 (mod (r_i - 1)).

Each CRT coefficient t_i (i = 3, ..., u) is a positive integer less
than r_i satisfying

R_i * t_i == 1 (mod r_i) ,

where R_i = r_1 * r_2 * ... * r_(i-1).

A recommended syntax for interchanging RSA private keys between
implementations, which includes components from both representations,
is given in Appendix A.1.2; an implementation's internal
representation may differ.

Notes.

1. The definition of the CRT coefficients here and the formulas that
use them in the primitives in Section 5 generally follow Garner's
algorithm [22] (see also Algorithm 14.71 in [37]). However, for
compatibility with the representations of RSA private keys in PKCS
#1 v2.0 and previous versions, the roles of p and q are reversed
compared to the rest of the primes. Thus, the first CRT
coefficient, qInv, is defined as the inverse of q mod p, rather
than as the inverse of R_1 mod r_2, i.e., of p mod q.

2. Quisquater and Couvreur [40] observed the benefit of applying the
Chinese Remainder Theorem to RSA operations.

4. Data conversion primitives

Two data conversion primitives are employed in the schemes defined in
this document:

* I2OSP - Integer-to-Octet-String primitive

* OS2IP - Octet-String-to-Integer primitive

For the purposes of this document, and consistent with ASN.1 syntax,
an octet string is an ordered sequence of octets (eight-bit bytes).
The sequence is indexed from first (conventionally, leftmost) to last
(rightmost). For purposes of conversion to and from integers, the
first octet is considered the most significant in the following
conversion primitives.

4.1 I2OSP

I2OSP converts a nonnegative integer to an octet string of a
specified length.

I2OSP (x, xLen)

Input:
x nonnegative integer to be converted
xLen intended length of the resulting octet string

Output:
X corresponding octet string of length xLen

Error: "integer too large"

Steps:

1. If x >= 256^xLen, output "integer too large" and stop.

2. Write the integer x in its unique xLen-digit representation in
base 256:

x = x_(xLen-1) 256^(xLen-1) + x_(xLen-2) 256^(xLen-2) + ...
+ x_1 256 + x_0,

where 0 <= x_i < 256 (note that one or more leading digits will be
zero if x is less than 256^(xLen-1)).

3. Let the octet X_i have the integer value x_(xLen-i) for 1 <= i <=
xLen. Output the octet string

X = X_1 X_2 ... X_xLen.

4.2 OS2IP

OS2IP converts an octet string to a nonnegative integer.

OS2IP (X)

Input:
X octet string to be converted

Output:
x corresponding nonnegative integer

Steps:

1. Let X_1 X_2 ... X_xLen be the octets of X from first to last,
and let x_(xLen-i) be the integer value of the octet X_i for
1 <= i <= xLen.

2. Let x = x_(xLen-1) 256^(xLen-1) + x_(xLen-2) 256^(xLen-2) + ...
+ x_1 256 + x_0.

3. Output x.

5. Cryptographic primitives

Cryptographic primitives are basic mathematical operations on which
cryptographic schemes can be built. They are intended for
implementation in hardware or as software modules, and are not
intended to provide security apart from a scheme.

Four types of primitive are specified in this document, organized in
pairs: encryption and decryption; and signature and verification.

The specifications of the primitives assume that certain conditions
are met by the inputs, in particular that RSA public and private keys
are valid.

5.1 Encryption and decryption primitives

An encryption primitive produces a ciphertext representative from a
message representative under the control of a public key, and a
decryption primitive recovers the message representative from the
ciphertext representative under the control of the corresponding
private key.

One pair of encryption and decryption primitives is employed in the
encryption schemes defined in this document and is specified here:
RSAEP/RSADP. RSAEP and RSADP involve the same mathematical
operation, with different keys as input.

The primitives defined here are the same as IFEP-RSA/IFDP-RSA in IEEE
Std 1363-2000 [26] (except that support for multi-prime RSA has been
added) and are compatible with PKCS #1 v1.5.

The main mathematical operation in each primitive is exponentiation.

5.1.1 RSAEP

RSAEP ((n, e), m)

Input:
(n, e) RSA public key
m message representative, an integer between 0 and n - 1

Output:
c ciphertext representative, an integer between 0 and n - 1

Error: "message representative out of range"

Assumption: RSA public key (n, e) is valid

Steps:

1. If the message representative m is not between 0 and n - 1, output
"message representative out of range" and stop.

2. Let c = m^e mod n.

3. Output c.

5.1.2 RSADP

RSADP (K, c)

Input:
K RSA private key, where K has one of the following forms:
- a pair (n, d)
- a quintuple (p, q, dP, dQ, qInv) and a possibly empty
sequence of triplets (r_i, d_i, t_i), i = 3, ..., u
c ciphertext representative, an integer between 0 and n - 1

Output:
m message representative, an integer between 0 and n - 1

Error: "ciphertext representative out of range"

Assumption: RSA private key K is valid

Steps:

1. If the ciphertext representative c is not between 0 and n - 1,
output "ciphertext representative out of range" and stop.

2. The message representative m is computed as follows.

a. If the first form (n, d) of K is used, let m = c^d mod n.

b. If the second form (p, q, dP, dQ, qInv) and (r_i, d_i, t_i)
of K is used, proceed as follows:

i. Let m_1 = c^dP mod p and m_2 = c^dQ mod q.

ii. If u > 2, let m_i = c^(d_i) mod r_i, i = 3, ..., u.

iii. Let h = (m_1 - m_2) * qInv mod p.

iv. Let m = m_2 + q * h.

v. If u > 2, let R = r_1 and for i = 3 to u do

1. Let R = R * r_(i-1).

2. Let h = (m_i - m) * t_i mod r_i.

3. Let m = m + R * h.

3. Output m.

Note. Step 2.b can be rewritten as a single loop, provided that one
reverses the order of p and q. For consistency with PKCS #1 v2.0,
however, the first two primes p and q are treated separately from
the additional primes.

5.2 Signature and verification primitives

A signature primitive produces a signature representative from a
message representative under the control of a private key, and a
verification primitive recovers the message representative from the
signature representative under the control of the corresponding
public key. One pair of signature and verification primitives is
employed in the signature schemes defined in this document and is
specified here: RSASP1/RSAVP1.

The primitives defined here are the same as IFSP-RSA1/IFVP-RSA1 in
IEEE 1363-2000 [26] (except that support for multi-prime RSA has
been added) and are compatible with PKCS #1 v1.5.

The main mathematical operation in each primitive is
exponentiation, as in the encryption and decryption primitives of
Section 5.1. RSASP1 and RSAVP1 are the same as RSADP and RSAEP
except for the names of their input and output arguments; they are
distinguished as they are intended for different purposes.

5.2.1 RSASP1

RSASP1 (K, m)

Input:
K RSA private key, where K has one of the following forms:
- a pair (n, d)
- a quintuple (p, q, dP, dQ, qInv) and a (possibly empty)
sequence of triplets (r_i, d_i, t_i), i = 3, ..., u
m message representative, an integer between 0 and n - 1

Output:
s signature representative, an integer between 0 and n - 1

Error: "message representative out of range"

Assumption: RSA private key K is valid

Steps:

1. If the message representative m is not between 0 and n - 1,
output "message representative out of range" and stop.

2. The signature representative s is computed as follows.

a. If the first form (n, d) of K is used, let s = m^d mod n.

b. If the second form (p, q, dP, dQ, qInv) and (r_i, d_i, t_i)
of K is used, proceed as follows:

i. Let s_1 = m^dP mod p and s_2 = m^dQ mod q.

ii. If u > 2, let s_i = m^(d_i) mod r_i, i = 3, ..., u.

iii. Let h = (s_1 - s_2) * qInv mod p.

iv. Let s = s_2 + q * h.

v. If u > 2, let R = r_1 and for i = 3 to u do

1. Let R = R * r_(i-1).

2. Let h = (s_i - s) * t_i mod r_i.

3. Let s = s + R * h.

3. Output s.

Note. Step 2.b can be rewritten as a single loop, provided that one
reverses the order of p and q. For consistency with PKCS #1 v2.0,
however, the first two primes p and q are treated separately from the
additional primes.

5.2.2 RSAVP1

RSAVP1 ((n, e), s)

Input:
(n, e) RSA public key
s signature representative, an integer between 0 and n - 1

Output:
m message representative, an integer between 0 and n - 1

Error: "signature representative out of range"

Assumption: RSA public key (n, e) is valid

Steps:

1. If the signature representative s is not between 0 and n - 1,
output "signature representative out of range" and stop.

2. Let m = s^e mod n.

3. Output m.

6. Overview of schemes

A scheme combines cryptographic primitives and other techniques to
achieve a particular security goal. Two types of scheme are
specified in this document: encryption schemes and signature schemes
with appendix.

The schemes specified in this document are limited in scope in that
their operations consist only of steps to process data with an RSA
public or private key, and do not include steps for obtaining or
validating the key. Thus, in addition to the scheme operations, an
application will typically include key management operations by which

parties may select RSA public and private keys for a scheme
operation. The specific additional operations and other details are
outside the scope of this document.

As was the case for the cryptographic primitives (Section 5), the
specifications of scheme operations assume that certain conditions
are met by the inputs, in particular that RSA public and private keys
are valid. The behavior of an implementation is thus unspecified
when a key is invalid. The impact of such unspecified behavior
depends on the application. Possible means of addressing key
validation include explicit key validation by the application; key
validation within the public-key infrastructure; and assignment of
liability for operations performed with an invalid key to the party
who generated the key.

A generally good cryptographic practice is to employ a given RSA key
pair in only one scheme. This avoids the risk that vulnerability in
one scheme may compromise the security of the other, and may be
essential to maintain provable security. While RSAES-PKCS1-v1_5
(Section 7.2) and RSASSA-PKCS1-v1_5 (Section 8.2) have traditionally
been employed together without any known bad interactions (indeed,
this is the model introduced by PKCS #1 v1.5), such a combined use of
an RSA key pair is not recommended for new applications.

To illustrate the risks related to the employment of an RSA key pair
in more than one scheme, suppose an RSA key pair is employed in both
RSAES-OAEP (Section 7.1) and RSAES-PKCS1-v1_5. Although RSAES-OAEP
by itself would resist attack, an opponent might be able to exploit a
weakness in the implementation of RSAES-PKCS1-v1_5 to recover
messages encrypted with either scheme. As another example, suppose
an RSA key pair is employed in both RSASSA-PSS (Section 8.1) and
RSASSA-PKCS1-v1_5. Then the security proof for RSASSA-PSS would no
longer be sufficient since the proof does not account for the
possibility that signatures might be generated with a second scheme.
Similar considerations may apply if an RSA key pair is employed in
one of the schemes defined here and in a variant defined elsewhere.

7. Encryption schemes

For the purposes of this document, an encryption scheme consists of
an encryption operation and a decryption operation, where the
encryption operation produces a ciphertext from a message with a
recipient's RSA public key, and the decryption operation recovers the
message from the ciphertext with the recipient's corresponding RSA
private key.

An encryption scheme can be employed in a variety of applications. A
typical application is a key establishment protocol, where the
message contains key material to be delivered confidentially from one
party to another. For instance, PKCS #7 [45] employs such a protocol
to deliver a content-encryption key from a sender to a recipient; the
encryption schemes defined here would be suitable key-encryption
algorithms in that context.

Two encryption schemes are specified in this document: RSAES-OAEP and
RSAES-PKCS1-v1_5. RSAES-OAEP is recommended for new applications;
RSAES-PKCS1-v1_5 is included only for compatibility with existing
applications, and is not recommended for new applications.

The encryption schemes given here follow a general model similar to
that employed in IEEE Std 1363-2000 [26], combining encryption and
decryption primitives with an encoding method for encryption. The
encryption operations apply a message encoding operation to a message
to produce an encoded message, which is then converted to an integer
message representative. An encryption primitive is applied to the
message representative to produce the ciphertext. Reversing this,
the decryption operations apply a decryption primitive to the
ciphertext to recover a message representative, which is then
converted to an octet string encoded message. A message decoding
operation is applied to the encoded message to recover the message
and verify the correctness of the decryption.

To avoid implementation weaknesses related to the way errors are
handled within the decoding operation (see [6] and [36]), the
encoding and decoding operations for RSAES-OAEP and RSAES-PKCS1-v1_5
are embedded in the specifications of the respective encryption
schemes rather than defined in separate specifications. Both
encryption schemes are compatible with the corresponding schemes in
PKCS #1 v2.0.

7.1 RSAES-OAEP

RSAES-OAEP combines the RSAEP and RSADP primitives (Sections 5.1.1
and 5.1.2) with the EME-OAEP encoding method (step 1.b in Section
7.1.1 and step 3 in Section 7.1.2). EME-OAEP is based on Bellare and
Rogaway's Optimal Asymmetric Encryption scheme [3]. (OAEP stands for
"Optimal Asymmetric Encryption Padding."). It is compatible with the
IFES scheme defined in IEEE Std 1363-2000 [26], where the encryption
and decryption primitives are IFEP-RSA and IFDP-RSA and the message
encoding method is EME-OAEP. RSAES-OAEP can operate on messages of
length up to k - 2hLen - 2 octets, where hLen is the length of the
output from the underlying hash function and k is the length in
octets of the recipient's RSA modulus.

Assuming that computing e-th roots modulo n is infeasible and the
mask generation function in RSAES-OAEP has appropriate properties,
RSAES-OAEP is semantically secure against adaptive chosen-ciphertext
attacks. This assurance is provable in the sense that the difficulty
of breaking RSAES-OAEP can be directly related to the difficulty of
inverting the RSA function, provided that the mask generation
function is viewed as a black box or random oracle; see [21] and the
note below for further discussion.

Both the encryption and the decryption operations of RSAES-OAEP take
the value of a label L as input. In this version of PKCS #1, L is
the empty string; other uses of the label are outside the scope of
this document. See Appendix A.2.1 for the relevant ASN.1 syntax.

RSAES-OAEP is parameterized by the choice of hash function and mask
generation function. This choice should be fixed for a given RSA
key. Suggested hash and mask generation functions are given in
Appendix B.

Note. Recent results have helpfully clarified the security
properties of the OAEP encoding method [3] (roughly the procedure
described in step 1.b in Section 7.1.1). The background is as
follows. In 1994, Bellare and Rogaway [3] introduced a security
concept that they denoted plaintext awareness (PA94). They proved
that if a deterministic public-key encryption primitive (e.g., RSAEP)
is hard to invert without the private key, then the corresponding
OAEP-based encryption scheme is plaintext-aware (in the random oracle
model), meaning roughly that an adversary cannot produce a valid
ciphertext without actually "knowing" the underlying plaintext.
Plaintext awareness of an encryption scheme is closely related to the
resistance of the scheme against chosen-ciphertext attacks. In such
attacks, an adversary is given the opportunity to send queries to an
oracle simulating the decryption primitive. Using the results of
these queries, the adversary attempts to decrypt a challenge
ciphertext.

However, there are two flavors of chosen-ciphertext attacks, and PA94
implies security against only one of them. The difference relies on
what the adversary is allowed to do after she is given the challenge
ciphertext. The indifferent attack scenario (denoted CCA1) does not
admit any queries to the decryption oracle after the adversary is
given the challenge ciphertext, whereas the adaptive scenario
(denoted CCA2) does (except that the decryption oracle refuses to
decrypt the challenge ciphertext once it is published). In 1998,
Bellare and Rogaway, together with Desai and Pointcheval [2], came up
with a new, stronger notion of plaintext awareness (PA98) that does
imply security against CCA2.

To summarize, there have been two potential sources for
misconception: that PA94 and PA98 are equivalent concepts; or that
CCA1 and CCA2 are equivalent concepts. Either assumption leads to
the conclusion that the Bellare-Rogaway paper implies security of
OAEP against CCA2, which it does not.

(Footnote: It might be fair to mention that PKCS #1 v2.0 cites [3]
and claims that "a chosen ciphertext attack is ineffective against a
plaintext-aware encryption scheme such as RSAES-OAEP" without
specifying the kind of plaintext awareness or chosen ciphertext
attack considered.)

OAEP has never been proven secure against CCA2; in fact, Victor Shoup
[48] has demonstrated that such a proof does not exist in the general
case. Put briefly, Shoup showed that an adversary in the CCA2
scenario who knows how to partially invert the encryption primitive
but does not know how to invert it completely may well be able to
break the scheme. For example, one may imagine an attacker who is
able to break RSAES-OAEP if she knows how to recover all but the
first 20 bytes of a random integer encrypted with RSAEP. Such an
attacker does not need to be able to fully invert RSAEP, because she
does not use the first 20 octets in her attack.

Still, RSAES-OAEP is secure against CCA2, which was proved by
Fujisaki, Okamoto, Pointcheval, and Stern [21] shortly after the
announcement of Shoup's result. Using clever lattice reduction
techniques, they managed to show how to invert RSAEP completely given
a sufficiently large part of the pre-image. This observation,
combined with a proof that OAEP is secure against CCA2 if the
underlying encryption primitive is hard to partially invert, fills
the gap between what Bellare and Rogaway proved about RSAES-OAEP and
what some may have believed that they proved. Somewhat
paradoxically, we are hence saved by an ostensible weakness in RSAEP
(i.e., the whole inverse can be deduced from parts of it).

Unfortunately however, the security reduction is not efficient for
concrete parameters. While the proof successfully relates an
adversary Adv against the CCA2 security of RSAES-OAEP to an algorithm
Inv inverting RSA, the probability of success for Inv is only
approximately \epsilon^2 / 2^18, where \epsilon is the probability of
success for Adv.

(Footnote: In [21] the probability of success for the inverter was
\epsilon^2 / 4. The additional factor 1 / 2^16 is due to the eight
fixed zero bits at the beginning of the encoded message EM, which are
not present in the variant of OAEP considered in [21] (Inv must apply
Adv twice to invert RSA, and each application corresponds to a factor
1 / 2^8).)

In addition, the running time for Inv is approximately t^2, where t
is the running time of the adversary. The consequence is that we
cannot exclude the possibility that attacking RSAES-OAEP is
considerably easier than inverting RSA for concrete parameters.
Still, the existence of a security proof provides some assurance that
the RSAES-OAEP construction is sounder than ad hoc constructions such
as RSAES-PKCS1-v1_5.

Hybrid encryption schemes based on the RSA-KEM key encapsulation
paradigm offer tight proofs of security directly applicable to
concrete parameters; see [30] for discussion. Future versions of
PKCS #1 may specify schemes based on this paradigm.

7.1.1 Encryption operation

RSAES-OAEP-ENCRYPT ((n, e), M, L)

Options:
Hash hash function (hLen denotes the length in octets of the hash
function output)
MGF mask generation function

Input:
(n, e) recipient's RSA public key (k denotes the length in octets
of the RSA modulus n)
M message to be encrypted, an octet string of length mLen,
where mLen <= k - 2hLen - 2
L optional label to be associated with the message; the
default value for L, if L is not provided, is the empty
string

Output:
C ciphertext, an octet string of length k

Errors: "message too long"; "label too long"

Assumption: RSA public key (n, e) is valid

Steps:

1. Length checking:

a. If the length of L is greater than the input limitation for the
hash function (2^61 - 1 octets for SHA-1), output "label too
long" and stop.

b. If mLen > k - 2hLen - 2, output "message too long" and stop.

2. EME-OAEP encoding (see Figure 1 below):

a. If the label L is not provided, let L be the empty string. Let
lHash = Hash(L), an octet string of length hLen (see the note
below).

b. Generate an octet string PS consisting of k - mLen - 2hLen - 2
zero octets. The length of PS may be zero.

c. Concatenate lHash, PS, a single octet with hexadecimal value
0x01, and the message M to form a data block DB of length k -
hLen - 1 octets as

DB = lHash || PS || 0x01 || M.

d. Generate a random octet string seed of length hLen.

e. Let dbMask = MGF(seed, k - hLen - 1).

f. Let maskedDB = DB \xor dbMask.

g. Let seedMask = MGF(maskedDB, hLen).

h. Let maskedSeed = seed \xor seedMask.

i. Concatenate a single octet with hexadecimal value 0x00,
maskedSeed, and maskedDB to form an encoded message EM of
length k octets as

EM = 0x00 || maskedSeed || maskedDB.

3. RSA encryption:

a. Convert the encoded message EM to an integer message
representative m (see Section 4.2):

m = OS2IP (EM).

b. Apply the RSAEP encryption primitive (Section 5.1.1) to the RSA
public key (n, e) and the message representative m to produce
an integer ciphertext representative c:

c = RSAEP ((n, e), m).

c. Convert the ciphertext representative c to a ciphertext C of
length k octets (see Section 4.1):

C = I2OSP (c, k).

4. Output the ciphertext C.

Note. If L is the empty string, the corresponding hash value lHash
has the following hexadecimal representation for different choices of
Hash:

SHA-1: (0x)da39a3ee 5e6b4b0d 3255bfef 95601890 afd80709
SHA-256: (0x)e3b0c442 98fc1c14 9afbf4c8 996fb924 27ae41e4 649b934c
a495991b 7852b855
SHA-384: (0x)38b060a7 51ac9638 4cd9327e b1b1e36a 21fdb711 14be0743
4c0cc7bf 63f6e1da 274edebf e76f65fb d51ad2f1 4898b95b
SHA-512: (0x)cf83e135 7eefb8bd f1542850 d66d8007 d620e405 0b5715dc
83f4a921 d36ce9ce 47d0d13c 5d85f2b0 ff8318d2 877eec2f
63b931bd 47417a81 a538327a f927da3e

__________________________________________________________________

+----------+---------+-------+
DB = | lHash | PS | M |
+----------+---------+-------+
|
+----------+ V
| seed |--> MGF ---> xor
+----------+ |
| |
+--+ V |
|00| xor <----- MGF <-----|
+--+ | |
| | |
V V V
+--+----------+----------------------------+
EM = |00|maskedSeed| maskedDB |
+--+----------+----------------------------+
__________________________________________________________________

Figure 1: EME-OAEP encoding operation. lHash is the hash of the
optional label L. Decoding operation follows reverse steps to
recover M and verify lHash and PS.

7.1.2 Decryption operation

RSAES-OAEP-DECRYPT (K, C, L)

Options:
Hash hash function (hLen denotes the length in octets of the hash
function output)
MGF mask generation function

Input:
K recipient's RSA private key (k denotes the length in octets
of the RSA modulus n)
C ciphertext to be decrypted, an octet string of length k,
where k = 2hLen + 2
L optional label whose association with the message is to be
verified; the default value for L, if L is not provided, is
the empty string

Output:
M message, an octet string of length mLen, where mLen <= k -
2hLen - 2

Error: "decryption error"

Steps:

1. Length checking:

a. If the length of L is greater than the input limitation for the
hash function (2^61 - 1 octets for SHA-1), output "decryption
error" and stop.

b. If the length of the ciphertext C is not k octets, output
"decryption error" and stop.

c. If k < 2hLen + 2, output "decryption error" and stop.

2. RSA decryption:

a. Convert the ciphertext C to an integer ciphertext
representative c (see Section 4.2):

c = OS2IP (C).

b. Apply the RSADP decryption primitive (Section 5.1.2) to the
RSA private key K and the ciphertext representative c to
produce an integer message representative m:

m = RSADP (K, c).

If RSADP outputs "ciphertext representative out of range"
(meaning that c >= n), output "decryption error" and stop.

c. Convert the message representative m to an encoded message EM
of length k octets (see Section 4.1):

EM = I2OSP (m, k).

3. EME-OAEP decoding:

a. If the label L is not provided, let L be the empty string. Let
lHash = Hash(L), an octet string of length hLen (see the note
in Section 7.1.1).

b. Separate the encoded message EM into a single octet Y, an octet
string maskedSeed of length hLen, and an octet string maskedDB
of length k - hLen - 1 as

EM = Y || maskedSeed || maskedDB.

c. Let seedMask = MGF(maskedDB, hLen).

d. Let seed = maskedSeed \xor seedMask.

e. Let dbMask = MGF(seed, k - hLen - 1).

f. Let DB = maskedDB \xor dbMask.

g. Separate DB into an octet string lHash' of length hLen, a
(possibly empty) padding string PS consisting of octets with
hexadecimal value 0x00, and a message M as

DB = lHash' || PS || 0x01 || M.

If there is no octet with hexadecimal value 0x01 to separate PS
from M, if lHash does not equal lHash', or if Y is nonzero,
output "decryption error" and stop. (See the note below.)

4. Output the message M.

Note. Care must be taken to ensure that an opponent cannot
distinguish the different error conditions in Step 3.g, whether by
error message or timing, or, more generally, learn partial
information about the encoded message EM. Otherwise an opponent may
be able to obtain useful information about the decryption of the
ciphertext C, leading to a chosen-ciphertext attack such as the one
observed by Manger [36].

7.2 RSAES-PKCS1-v1_5

RSAES-PKCS1-v1_5 combines the RSAEP and RSADP primitives (Sections
5.1.1 and 5.1.2) with the EME-PKCS1-v1_5 encoding method (step 1 in
Section 7.2.1 and step 3 in Section 7.2.2). It is mathematically
equivalent to the encryption scheme in PKCS #1 v1.5. RSAES-PKCS1-
v1_5 can operate on messages of length up to k - 11 octets (k is the
octet length of the RSA modulus), although care should be taken to

avoid certain attacks on low-exponent RSA due to Coppersmith,
Franklin, Patarin, and Reiter when long messages are encrypted (see
the third bullet in the notes below and [10]; [14] contains an
improved attack). As a general rule, the use of this scheme for
encrypting an arbitrary message, as opposed to a randomly generated
key, is not recommended.

It is possible to generate valid RSAES-PKCS1-v1_5 ciphertexts without
knowing the corresponding plaintexts, with a reasonable probability
of success. This ability can be exploited in a chosen- ciphertext
attack as shown in [6]. Therefore, if RSAES-PKCS1-v1_5 is to be
used, certain easily implemented countermeasures should be taken to
thwart the attack found in [6]. Typical examples include the
addition of structure to the data to be encoded, rigorous checking of
PKCS #1 v1.5 conformance (and other redundancy) in decrypted
messages, and the consolidation of error messages in a client-server
protocol based on PKCS #1 v1.5. These can all be effective
countermeasures and do not involve changes to a PKCS #1 v1.5-based
protocol. See [7] for a further discussion of these and other
countermeasures. It has recently been shown that the security of the
SSL/TLS handshake protocol [17], which uses RSAES-PKCS1-v1_5 and
certain countermeasures, can be related to a variant of the RSA
problem; see [32] for discussion.

Note. The following passages describe some security recommendations
pertaining to the use of RSAES-PKCS1-v1_5. Recommendations from
version 1.5 of this document are included as well as new
recommendations motivated by cryptanalytic advances made in the
intervening years.

* It is recommended that the pseudorandom octets in step 2 in
Section 7.2.1 be generated independently for each encryption
process, especially if the same data is input to more than one
encryption process. Haastad's results [24] are one motivation for
this recommendation.

* The padding string PS in step 2 in Section 7.2.1 is at least eight
octets long, which is a security condition for public-key
operations that makes it difficult for an attacker to recover data
by trying all possible encryption blocks.

* The pseudorandom octets can also help thwart an attack due to
Coppersmith et al. [10] (see [14] for an improvement of the
attack) when the size of the message to be encrypted is kept
small. The attack works on low-exponent RSA when similar messages
are encrypted with the same RSA public key. More specifically, in
one flavor of the attack, when two inputs to RSAEP agree on a
large fraction of bits (8/9) and low-exponent RSA (e = 3) is used

to encrypt both of them, it may be possible to recover both inputs
with the attack. Another flavor of the attack is successful in
decrypting a single ciphertext when a large fraction (2/3) of the
input to RSAEP is already known. For typical applications, the
message to be encrypted is short (e.g., a 128-bit symmetric key)
so not enough information will be known or common between two
messages to enable the attack. However, if a long message is
encrypted, or if part of a message is known, then the attack may
be a concern. In any case, the RSAES-OAEP scheme overcomes the
attack.

7.2.1 Encryption operation

RSAES-PKCS1-V1_5-ENCRYPT ((n, e), M)

Input:
(n, e) recipient's RSA public key (k denotes the length in octets
of the modulus n)
M message to be encrypted, an octet string of length mLen,
where mLen <= k - 11

Output:
C ciphertext, an octet string of length k

Error: "message too long"

Steps:

1. Length checking: If mLen > k - 11, output "message too long" and
stop.

2. EME-PKCS1-v1_5 encoding:

a. Generate an octet string PS of length k - mLen - 3 consisting
of pseudo-randomly generated nonzero octets. The length of PS
will be at least eight octets.

b. Concatenate PS, the message M, and other padding to form an
encoded message EM of length k octets as

EM = 0x00 || 0x02 || PS || 0x00 || M.

3. RSA encryption:

a. Convert the encoded message EM to an integer message
representative m (see Section 4.2):

m = OS2IP (EM).

b. Apply the RSAEP encryption primitive (Section 5.1.1) to the RSA
public key (n, e) and the message representative m to produce
an integer ciphertext representative c:

c = RSAEP ((n, e), m).

c. Convert the ciphertext representative c to a ciphertext C of
length k octets (see Section 4.1):

C = I2OSP (c, k).

4. Output the ciphertext C.

7.2.2 Decryption operation

RSAES-PKCS1-V1_5-DECRYPT (K, C)

Input:
K recipient's RSA private key
C ciphertext to be decrypted, an octet string of length k,
where k is the length in octets of the RSA modulus n

Output:
M message, an octet string of length at most k - 11

Error: "decryption error"

Steps:

1. Length checking: If the length of the ciphertext C is not k octets
(or if k < 11), output "decryption error" and stop.

2. RSA decryption:

a. Convert the ciphertext C to an integer ciphertext
representative c (see Section 4.2):

c = OS2IP (C).

b. Apply the RSADP decryption primitive (Section 5.1.2) to the RSA
private key (n, d) and the ciphertext representative c to
produce an integer message representative m:

m = RSADP ((n, d), c).

If RSADP outputs "ciphertext representative out of range"
(meaning that c >= n), output "decryption error" and stop.

c. Convert the message representative m to an encoded message EM
of length k octets (see Section 4.1):

EM = I2OSP (m, k).

3. EME-PKCS1-v1_5 decoding: Separate the encoded message EM into an
octet string PS consisting of nonzero octets and a message M as

EM = 0x00 || 0x02 || PS || 0x00 || M.

If the first octet of EM does not have hexadecimal value 0x00, if
the second octet of EM does not have hexadecimal value 0x02, if
there is no octet with hexadecimal value 0x00 to separate PS from
M, or if the length of PS is less than 8 octets, output
"decryption error" and stop. (See the note below.)

4. Output M.

Note. Care shall be taken to ensure that an opponent cannot
distinguish the different error conditions in Step 3, whether by
error message or timing. Otherwise an opponent may be able to obtain
useful information about the decryption of the ciphertext C, leading
to a strengthened version of Bleichenbacher's attack [6]; compare to
Manger's attack [36].

8. Signature schemes with appendix

For the purposes of this document, a signature scheme with appendix
consists of a signature generation operation and a signature
verification operation, where the signature generation operation
produces a signature from a message with a signer's RSA private key,
and the signature verification operation verifies the signature on
the message with the signer's corresponding RSA public key. To
verify a signature constructed with this type of scheme it is
necessary to have the message itself. In this way, signature schemes
with appendix are distinguished from signature schemes with message
recovery, which are not supported in this document.

A signature scheme with appendix can be employed in a variety of
applications. For instance, the signature schemes with appendix
defined here would be suitable signature algorithms for X.509
certificates [28]. Related signature schemes could be employed in
PKCS #7 [45], although for technical reasons the current version of
PKCS #7 separates a hash function from a signature scheme, which is
different than what is done here; see the note in Appendix A.2.3 for
more discussion.

Two signature schemes with appendix are specified in this document:
RSASSA-PSS and RSASSA-PKCS1-v1_5. Although no attacks are known
against RSASSA-PKCS1-v1_5, in the interest of increased robustness,
RSASSA-PSS is recommended for eventual adoption in new applications.
RSASSA-PKCS1-v1_5 is included for compatibility with existing
applications, and while still appropriate for new applications, a
gradual transition to RSASSA-PSS is encouraged.

The signature schemes with appendix given here follow a general model
------分隔线----------------------------
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
最新评论 查看所有评论
发表评论 查看所有评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 密码: 验证码:
推荐内容