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

时间:2005-02-17 来源: 作者: 点击:
similar to that employed in IEEE Std 1363-2000 [26], combining signature and verification primitives with an encoding method for signatures. The signature generation operations apply a message encodi
  
similar to that employed in IEEE Std 1363-2000 [26], combining
signature and verification primitives with an encoding method for
signatures. The signature generation operations apply a message
encoding operation to a message to produce an encoded message, which
is then converted to an integer message representative. A signature
primitive is applied to the message representative to produce the
signature. Reversing this, the signature verification operations
apply a signature verification primitive to the signature to recover
a message representative, which is then converted to an octet string
encoded message. A verification operation is applied to the message
and the encoded message to determine whether they are consistent.

If the encoding method is deterministic (e.g., EMSA-PKCS1-v1_5), the
verification operation may apply the message encoding operation to
the message and compare the resulting encoded message to the
previously derived encoded message. If there is a match, the
signature is considered valid. If the method is randomized (e.g.,
EMSA-PSS), the verification operation is typically more complicated.
For example, the verification operation in EMSA-PSS extracts the
random salt and a hash output from the encoded message and checks
whether the hash output, the salt, and the message are consistent;
the hash output is a deterministic function in terms of the message
and the salt.

For both signature schemes with appendix defined in this document,
the signature generation and signature verification operations are
readily implemented as "single-pass" operations if the signature is
placed after the message. See PKCS #7 [45] for an example format in
the case of RSASSA-PKCS1-v1_5.

8.1 RSASSA-PSS

RSASSA-PSS combines the RSASP1 and RSAVP1 primitives with the EMSA-
PSS encoding method. It is compatible with the IFSSA scheme as
amended in the IEEE P1363a draft [27], where the signature and
verification primitives are IFSP-RSA1 and IFVP-RSA1 as defined in
IEEE Std 1363-2000 [26] and the message encoding method is EMSA4.
EMSA4 is slightly more general than EMSA-PSS as it acts on bit
strings rather than on octet strings. EMSA-PSS is equivalent to
EMSA4 restricted to the case that the operands as well as the hash
and salt values are octet strings.

The length of messages on which RSASSA-PSS can operate is either
unrestricted or constrained by a very large number, depending on the
hash function underlying the EMSA-PSS encoding method.

Assuming that computing e-th roots modulo n is infeasible and the
hash and mask generation functions in EMSA-PSS have appropriate
properties, RSASSA-PSS provides secure signatures. This assurance is
provable in the sense that the difficulty of forging signatures can
be directly related to the difficulty of inverting the RSA function,
provided that the hash and mask generation functions are viewed as
black boxes or random oracles. The bounds in the security proof are
essentially "tight", meaning that the success probability and running
time for the best forger against RSASSA-PSS are very close to the
corresponding parameters for the best RSA inversion algorithm; see
[4][13][31] for further discussion.

In contrast to the RSASSA-PKCS1-v1_5 signature scheme, a hash
function identifier is not embedded in the EMSA-PSS encoded message,
so in theory it is possible for an adversary to substitute a
different (and potentially weaker) hash function than the one
selected by the signer. Therefore, it is recommended that the EMSA-
PSS mask generation function be based on the same hash function. In
this manner the entire encoded message will be dependent on the hash
function and it will be difficult for an opponent to substitute a
different hash function than the one intended by the signer. This
matching of hash functions is only for the purpose of preventing hash
function substitution, and is not necessary if hash function
substitution is addressed by other means (e.g., the verifier accepts
only a designated hash function). See [34] for further discussion of
these points. The provable security of RSASSA-PSS does not rely on
the hash function in the mask generation function being the same as
the hash function applied to the message.

RSASSA-PSS is different from other RSA-based signature schemes in
that it is probabilistic rather than deterministic, incorporating a
randomly generated salt value. The salt value enhances the security

of the scheme by affording a "tighter" security proof than
deterministic alternatives such as Full Domain Hashing (FDH); see [4]
for discussion. However, the randomness is not critical to security.
In situations where random generation is not possible, a fixed value
or a sequence number could be employed instead, with the resulting
provable security similar to that of FDH [12].

8.1.1 Signature generation operation

RSASSA-PSS-SIGN (K, M)

Input:
K signer's RSA private key
M message to be signed, an octet string

Output:
S signature, an octet string of length k, where k is the
length in octets of the RSA modulus n

Errors: "message too long;" "encoding error"

Steps:

1. EMSA-PSS encoding: Apply the EMSA-PSS encoding operation (Section
9.1.1) to the message M to produce an encoded message EM of length
\ceil ((modBits - 1)/8) octets such that the bit length of the
integer OS2IP (EM) (see Section 4.2) is at most modBits - 1, where
modBits is the length in bits of the RSA modulus n:

EM = EMSA-PSS-ENCODE (M, modBits - 1).

Note that the octet length of EM will be one less than k if
modBits - 1 is divisible by 8 and equal to k otherwise. If the
encoding operation outputs "message too long," output "message too
long" and stop. If the encoding operation outputs "encoding
error," output "encoding error" and stop.

2. RSA signature:

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

m = OS2IP (EM).

b. Apply the RSASP1 signature primitive (Section 5.2.1) to the RSA
private key K and the message representative m to produce an
integer signature representative s:

s = RSASP1 (K, m).

c. Convert the signature representative s to a signature S of
length k octets (see Section 4.1):

S = I2OSP (s, k).

3. Output the signature S.

8.1.2 Signature verification operation

RSASSA-PSS-VERIFY ((n, e), M, S)

Input:
(n, e) signer's RSA public key
M message whose signature is to be verified, an octet string
S signature to be verified, an octet string of length k, where
k is the length in octets of the RSA modulus n

Output:
"valid signature" or "invalid signature"

Steps:

1. Length checking: If the length of the signature S is not k octets,
output "invalid signature" and stop.

2. RSA verification:

a. Convert the signature S to an integer signature representative
s (see Section 4.2):

s = OS2IP (S).

b. Apply the RSAVP1 verification primitive (Section 5.2.2) to the
RSA public key (n, e) and the signature representative s to
produce an integer message representative m:

m = RSAVP1 ((n, e), s).

If RSAVP1 output "signature representative out of range,"
output "invalid signature" and stop.

c. Convert the message representative m to an encoded message EM
of length emLen = \ceil ((modBits - 1)/8) octets, where modBits
is the length in bits of the RSA modulus n (see Section 4.1):

EM = I2OSP (m, emLen).

Note that emLen will be one less than k if modBits - 1 is
divisible by 8 and equal to k otherwise. If I2OSP outputs
"integer too large," output "invalid signature" and stop.

3. EMSA-PSS verification: Apply the EMSA-PSS verification operation
(Section 9.1.2) to the message M and the encoded message EM to
determine whether they are consistent:

Result = EMSA-PSS-VERIFY (M, EM, modBits - 1).

4. If Result = "consistent," output "valid signature." Otherwise,
output "invalid signature."

8.2. RSASSA-PKCS1-v1_5

RSASSA-PKCS1-v1_5 combines the RSASP1 and RSAVP1 primitives with the
EMSA-PKCS1-v1_5 encoding method. It is compatible with the IFSSA
scheme defined in IEEE Std 1363-2000 [26], where the signature and
verification primitives are IFSP-RSA1 and IFVP-RSA1 and the message
encoding method is EMSA-PKCS1-v1_5 (which is not defined in IEEE Std
1363-2000, but is in the IEEE P1363a draft [27]).

The length of messages on which RSASSA-PKCS1-v1_5 can operate is
either unrestricted or constrained by a very large number, depending
on the hash function underlying the EMSA-PKCS1-v1_5 method.

Assuming that computing e-th roots modulo n is infeasible and the
hash function in EMSA-PKCS1-v1_5 has appropriate properties, RSASSA-
PKCS1-v1_5 is conjectured to provide secure signatures. More
precisely, forging signatures without knowing the RSA private key is
conjectured to be computationally infeasible. Also, in the encoding
method EMSA-PKCS1-v1_5, a hash function identifier is embedded in the
encoding. Because of this feature, an adversary trying to find a
message with the same signature as a previously signed message must
find collisions of the particular hash function being used; attacking
a different hash function than the one selected by the signer is not
useful to the adversary. See [34] for further discussion.

Note. As noted in PKCS #1 v1.5, the EMSA-PKCS1-v1_5 encoding method
has the property that the encoded message, converted to an integer
message representative, is guaranteed to be large and at least
somewhat "random". This prevents attacks of the kind proposed by

Desmedt and Odlyzko [16] where multiplicative relationships between
message representatives are developed by factoring the message
representatives into a set of small values (e.g., a set of small
primes). Coron, Naccache, and Stern [15] showed that a stronger form
of this type of attack could be quite effective against some
instances of the ISO/IEC 9796-2 signature scheme. They also analyzed
the complexity of this type of attack against the EMSA-PKCS1-v1_5
encoding method and concluded that an attack would be impractical,
requiring more operations than a collision search on the underlying
hash function (i.e., more than 2^80 operations). Coppersmith,
Halevi, and Jutla [11] subsequently extended Coron et al.'s attack to
break the ISO/IEC 9796-1 signature scheme with message recovery. The
various attacks illustrate the importance of carefully constructing
the input to the RSA signature primitive, particularly in a signature
scheme with message recovery. Accordingly, the EMSA-PKCS-v1_5
encoding method explicitly includes a hash operation and is not
intended for signature schemes with message recovery. Moreover,
while no attack is known against the EMSA-PKCS-v1_5 encoding method,
a gradual transition to EMSA-PSS is recommended as a precaution
against future developments.

8.2.1 Signature generation operation

RSASSA-PKCS1-V1_5-SIGN (K, M)

Input:
K signer's RSA private key
M message to be signed, an octet string

Output:
S signature, an octet string of length k, where k is the
length in octets of the RSA modulus n

Errors: "message too long"; "RSA modulus too short"

Steps:

1. EMSA-PKCS1-v1_5 encoding: Apply the EMSA-PKCS1-v1_5 encoding
operation (Section 9.2) to the message M to produce an encoded
message EM of length k octets:

EM = EMSA-PKCS1-V1_5-ENCODE (M, k).

If the encoding operation outputs "message too long," output
"message too long" and stop. If the encoding operation outputs
"intended encoded message length too short," output "RSA modulus
too short" and stop.

2. RSA signature:

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

m = OS2IP (EM).

b. Apply the RSASP1 signature primitive (Section 5.2.1) to the RSA
private key K and the message representative m to produce an
integer signature representative s:

s = RSASP1 (K, m).

c. Convert the signature representative s to a signature S of
length k octets (see Section 4.1):

S = I2OSP (s, k).

3. Output the signature S.

8.2.2 Signature verification operation

RSASSA-PKCS1-V1_5-VERIFY ((n, e), M, S)

Input:
(n, e) signer's RSA public key
M message whose signature is to be verified, an octet string
S signature to be verified, an octet string of length k, where
k is the length in octets of the RSA modulus n

Output:
"valid signature" or "invalid signature"

Errors: "message too long"; "RSA modulus too short"

Steps:

1. Length checking: If the length of the signature S is not k octets,
output "invalid signature" and stop.

2. RSA verification:

a. Convert the signature S to an integer signature representative
s (see Section 4.2):

s = OS2IP (S).

b. Apply the RSAVP1 verification primitive (Section 5.2.2) to the
RSA public key (n, e) and the signature representative s to
produce an integer message representative m:

m = RSAVP1 ((n, e), s).

If RSAVP1 outputs "signature representative out of range,"
output "invalid signature" 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).

If I2OSP outputs "integer too large," output "invalid
signature" and stop.

3. EMSA-PKCS1-v1_5 encoding: Apply the EMSA-PKCS1-v1_5 encoding
operation (Section 9.2) to the message M to produce a second
encoded message EM' of length k octets:

EM' = EMSA-PKCS1-V1_5-ENCODE (M, k).

If the encoding operation outputs "message too long," output
"message too long" and stop. If the encoding operation outputs
"intended encoded message length too short," output "RSA modulus
too short" and stop.

4. Compare the encoded message EM and the second encoded message EM'.
If they are the same, output "valid signature"; otherwise, output
"invalid signature."

Note. Another way to implement the signature verification operation
is to apply a "decoding" operation (not specified in this document)
to the encoded message to recover the underlying hash value, and then
to compare it to a newly computed hash value. This has the advantage
that it requires less intermediate storage (two hash values rather
than two encoded messages), but the disadvantage that it requires
additional code.

9. Encoding methods for signatures with appendix

Encoding methods consist of operations that map between octet string
messages and octet string encoded messages, which are converted to
and from integer message representatives in the schemes. The integer
message representatives are processed via the primitives. The
encoding methods thus provide the connection between the schemes,
which process messages, and the primitives.

An encoding method for signatures with appendix, for the purposes of
this document, consists of an encoding operation and optionally a
verification operation. An encoding operation maps a message M to an
encoded message EM of a specified length. A verification operation
determines whether a message M and an encoded message EM are
consistent, i.e., whether the encoded message EM is a valid encoding
of the message M.

The encoding operation may introduce some randomness, so that
different applications of the encoding operation to the same message
will produce different encoded messages, which has benefits for
provable security. For such an encoding method, both an encoding and
a verification operation are needed unless the verifier can reproduce
the randomness (e.g., by obtaining the salt value from the signer).
For a deterministic encoding method only an encoding operation is
needed.

Two encoding methods for signatures with appendix are employed in the
signature schemes and are specified here: EMSA-PSS and EMSA-PKCS1-
v1_5.

9.1 EMSA-PSS

This encoding method is parameterized by the choice of hash function,
mask generation function, and salt length. These options should be
fixed for a given RSA key, except that the salt length can be
variable (see [31] for discussion). Suggested hash and mask
generation functions are given in Appendix B. The encoding method is
based on Bellare and Rogaway's Probabilistic Signature Scheme (PSS)
[4][5]. It is randomized and has an encoding operation and a
verification operation.

Figure 2 illustrates the encoding operation.

__________________________________________________________________

+-----------+
| M |
+-----------+
|
V
Hash
|
V
+--------+----------+----------+
M' = |Padding1| mHash | salt |
+--------+----------+----------+
|
+--------+----------+ V
DB = |Padding2|maskedseed| Hash
+--------+----------+ |
| |
V | +--+
xor <--- MGF <---| |bc|
| | +--+
| | |
V V V
+-------------------+----------+--+
EM = | maskedDB |maskedseed|bc|
+-------------------+----------+--+
__________________________________________________________________

Figure 2: EMSA-PSS encoding operation. Verification operation
follows reverse steps to recover salt, then forward steps to
recompute and compare H.

Notes.

1. The encoding method defined here differs from the one in Bellare
and Rogaway's submission to IEEE P1363a [5] in three respects:

* It applies a hash function rather than a mask generation
function to the message. Even though the mask generation
function is based on a hash function, it seems more natural to
apply a hash function directly.

* The value that is hashed together with the salt value is the
string (0x)00 00 00 00 00 00 00 00 || mHash rather than the
message M itself. Here, mHash is the hash of M. Note that the

hash function is the same in both steps. See Note 3 below for
further discussion. (Also, the name "salt" is used instead of
"seed", as it is more reflective of the value's role.)

* The encoded message in EMSA-PSS has nine fixed bits; the first
bit is 0 and the last eight bits form a "trailer field", the
octet 0xbc. In the original scheme, only the first bit is
fixed. The rationale for the trailer field is for
compatibility with the Rabin-Williams IFSP-RW signature
primitive in IEEE Std 1363-2000 [26] and the corresponding
primitive in the draft ISO/IEC 9796-2 [29].

2. Assuming that the mask generation function is based on a hash
function, it is recommended that the hash function be the same as
the one that is applied to the message; see Section 8.1 for
further discussion.

3. Without compromising the security proof for RSASSA-PSS, one may
perform steps 1 and 2 of EMSA-PSS-ENCODE and EMSA-PSS-VERIFY (the
application of the hash function to the message) outside the
module that computes the rest of the signature operation, so that
mHash rather than the message M itself is input to the module. In
other words, the security proof for RSASSA-PSS still holds even if
an opponent can control the value of mHash. This is convenient if
the module has limited I/O bandwidth, e.g., a smart card. Note
that previous versions of PSS [4][5] did not have this property.
Of course, it may be desirable for other security reasons to have
the module process the full message. For instance, the module may
need to "see" what it is signing if it does not trust the
component that computes the hash value.

4. Typical salt lengths in octets are hLen (the length of the output
of the hash function Hash) and 0. In both cases the security of
RSASSA-PSS can be closely related to the hardness of inverting
RSAVP1. Bellare and Rogaway [4] give a tight lower bound for the
security of the original RSA-PSS scheme, which corresponds roughly
to the former case, while Coron [12] gives a lower bound for the
related Full Domain Hashing scheme, which corresponds roughly to
the latter case. In [13] Coron provides a general treatment with
various salt lengths ranging from 0 to hLen; see [27] for
discussion. See also [31], which adapts the security proofs in
[4][13] to address the differences between the original and the
present version of RSA-PSS as listed in Note 1 above.

5. As noted in IEEE P1363a [27], the use of randomization in
signature schemes - such as the salt value in EMSA-PSS - may
provide a "covert channel" for transmitting information other than
the message being signed. For more on covert channels, see [50].

9.1.1 Encoding operation

EMSA-PSS-ENCODE (M, emBits)

Options:

Hash hash function (hLen denotes the length in octets of the hash
function output)
MGF mask generation function
sLen intended length in octets of the salt

Input:
M message to be encoded, an octet string
emBits maximal bit length of the integer OS2IP (EM) (see Section
4.2), at least 8hLen + 8sLen + 9

Output:
EM encoded message, an octet string of length emLen = \ceil
(emBits/8)

Errors: "encoding error"; "message too long"

Steps:

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

2. Let mHash = Hash(M), an octet string of length hLen.

3. If emLen < hLen + sLen + 2, output "encoding error" and stop.

4. Generate a random octet string salt of length sLen; if sLen = 0,
then salt is the empty string.

5. Let
M' = (0x)00 00 00 00 00 00 00 00 || mHash || salt;

M' is an octet string of length 8 + hLen + sLen with eight
initial zero octets.

6. Let H = Hash(M'), an octet string of length hLen.

7. Generate an octet string PS consisting of emLen - sLen - hLen - 2
zero octets. The length of PS may be 0.

8. Let DB = PS || 0x01 || salt; DB is an octet string of length
emLen - hLen - 1.

9. Let dbMask = MGF(H, emLen - hLen - 1).

10. Let maskedDB = DB \xor dbMask.

11. Set the leftmost 8emLen - emBits bits of the leftmost octet in
maskedDB to zero.

12. Let EM = maskedDB || H || 0xbc.

13. Output EM.

9.1.2 Verification operation

EMSA-PSS-VERIFY (M, EM, emBits)

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

Input:
M message to be verified, an octet string
EM encoded message, an octet string of length emLen = \ceil
(emBits/8)
emBits maximal bit length of the integer OS2IP (EM) (see Section
4.2), at least 8hLen + 8sLen + 9

Output:
"consistent" or "inconsistent"

Steps:

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

2. Let mHash = Hash(M), an octet string of length hLen.

3. If emLen < hLen + sLen + 2, output "inconsistent" and stop.

4. If the rightmost octet of EM does not have hexadecimal value
0xbc, output "inconsistent" and stop.

5. Let maskedDB be the leftmost emLen - hLen - 1 octets of EM, and
let H be the next hLen octets.

6. If the leftmost 8emLen - emBits bits of the leftmost octet in
maskedDB are not all equal to zero, output "inconsistent" and
stop.

7. Let dbMask = MGF(H, emLen - hLen - 1).

8. Let DB = maskedDB \xor dbMask.

9. Set the leftmost 8emLen - emBits bits of the leftmost octet in DB
to zero.

10. If the emLen - hLen - sLen - 2 leftmost octets of DB are not zero
or if the octet at position emLen - hLen - sLen - 1 (the leftmost
position is "position 1") does not have hexadecimal value 0x01,
output "inconsistent" and stop.

11. Let salt be the last sLen octets of DB.

12. Let
M' = (0x)00 00 00 00 00 00 00 00 || mHash || salt ;

M' is an octet string of length 8 + hLen + sLen with eight
initial zero octets.

13. Let H' = Hash(M'), an octet string of length hLen.

14. If H = H', output "consistent." Otherwise, output "inconsistent."

9.2 EMSA-PKCS1-v1_5

This encoding method is deterministic and only has an encoding
operation.

EMSA-PKCS1-v1_5-ENCODE (M, emLen)

Option:
Hash hash function (hLen denotes the length in octets of the hash
function output)

Input:
M message to be encoded
emLen intended length in octets of the encoded message, at least
tLen + 11, where tLen is the octet length of the DER
encoding T of a certain value computed during the encoding
operation

Output:
EM encoded message, an octet string of length emLen

Errors:
"message too long"; "intended encoded message length too short"

Steps:

1. Apply the hash function to the message M to produce a hash value
H:

H = Hash(M).

If the hash function outputs "message too long," output "message
too long" and stop.

2. Encode the algorithm ID for the hash function and the hash value
into an ASN.1 value of type DigestInfo (see Appendix A.2.4) with
the Distinguished Encoding Rules (DER), where the type DigestInfo
has the syntax

DigestInfo ::= SEQUENCE {
digestAlgorithm AlgorithmIdentifier,
digest OCTET STRING
}

The first field identifies the hash function and the second
contains the hash value. Let T be the DER encoding of the
DigestInfo value (see the notes below) and let tLen be the length
in octets of T.

3. If emLen < tLen + 11, output "intended encoded message length too
short" and stop.

4. Generate an octet string PS consisting of emLen - tLen - 3 octets
with hexadecimal value 0xff. The length of PS will be at least 8
octets.

5. Concatenate PS, the DER encoding T, and other padding to form the
encoded message EM as

EM = 0x00 || 0x01 || PS || 0x00 || T.

6. Output EM.

Notes.

1. For the six hash functions mentioned in Appendix B.1, the DER
encoding T of the DigestInfo value is equal to the following:

MD2: (0x)30 20 30 0c 06 08 2a 86 48 86 f7 0d 02 02 05 00 04
10 || H.
MD5: (0x)30 20 30 0c 06 08 2a 86 48 86 f7 0d 02 05 05 00 04
10 || H.
SHA-1: (0x)30 21 30 09 06 05 2b 0e 03 02 1a 05 00 04 14 || H.
SHA-256: (0x)30 31 30 0d 06 09 60 86 48 01 65 03 04 02 01 05 00
04 20 || H.
SHA-384: (0x)30 41 30 0d 06 09 60 86 48 01 65 03 04 02 02 05 00
04 30 || H.
SHA-512: (0x)30 51 30 0d 06 09 60 86 48 01 65 03 04 02 03 05 00
04 40 || H.

2. In version 1.5 of this document, T was defined as the BER
encoding, rather than the DER encoding, of the DigestInfo value.
In particular, it is possible - at least in theory - that the
verification operation defined in this document (as well as in
version 2.0) rejects a signature that is valid with respect to the
specification given in PKCS #1 v1.5. This occurs if other rules
than DER are applied to DigestInfo (e.g., an indefinite length
encoding of the underlying SEQUENCE type). While this is unlikely
to be a concern in practice, a cautious implementer may choose to
employ a verification operation based on a BER decoding operation
as specified in PKCS #1 v1.5. In this manner, compatibility with
any valid implementation based on PKCS #1 v1.5 is obtained. Such
a verification operation should indicate whether the underlying
BER encoding is a DER encoding and hence whether the signature is
valid with respect to the specification given in this document.

Appendix A. ASN.1 syntax

A.1 RSA key representation

This section defines ASN.1 object identifiers for RSA public and
private keys, and defines the types RSAPublicKey and RSAPrivateKey.
The intended application of these definitions includes X.509
certificates, PKCS #8 [46], and PKCS #12 [47].

The object identifier rsaEncryption identifies RSA public and private
keys as defined in Appendices A.1.1 and A.1.2. The parameters field
associated with this OID in a value of type AlgorithmIdentifier shall
have a value of type NULL.

rsaEncryption OBJECT IDENTIFIER ::= { pkcs-1 1 }

The definitions in this section have been extended to support multi-
prime RSA, but are backward compatible with previous versions.

A.1.1 RSA public key syntax

An RSA public key should be represented with the ASN.1 type
RSAPublicKey:

RSAPublicKey ::= SEQUENCE {
modulus INTEGER, -- n
publicExponent INTEGER -- e
}

The fields of type RSAPublicKey have the following meanings:

* modulus is the RSA modulus n.

* publicExponent is the RSA public exponent e.

A.1.2 RSA private key syntax

An RSA private key should be represented with the ASN.1 type
RSAPrivateKey:

RSAPrivateKey ::= SEQUENCE {
version Version,
modulus INTEGER, -- n
publicExponent INTEGER, -- e
privateExponent INTEGER, -- d
prime1 INTEGER, -- p
prime2 INTEGER, -- q
exponent1 INTEGER, -- d mod (p-1)
exponent2 INTEGER, -- d mod (q-1)
coefficient INTEGER, -- (inverse of q) mod p
otherPrimeInfos OtherPrimeInfos OPTIONAL
}

The fields of type RSAPrivateKey have the following meanings:

* version is the version number, for compatibility with future
revisions of this document. It shall be 0 for this version of the
document, unless multi-prime is used, in which case it shall be 1.

Version ::= INTEGER { two-prime(0), multi(1) }
(CONSTRAINED BY
{-- version must be multi if otherPrimeInfos present --})

* modulus is the RSA modulus n.

* publicExponent is the RSA public exponent e.

* privateExponent is the RSA private exponent d.

* prime1 is the prime factor p of n.

* prime2 is the prime factor q of n.

* exponent1 is d mod (p - 1).

* exponent2 is d mod (q - 1).

* coefficient is the CRT coefficient q^(-1) mod p.

* otherPrimeInfos contains the information for the additional primes
r_3, ..., r_u, in order. It shall be omitted if version is 0 and
shall contain at least one instance of OtherPrimeInfo if version
is 1.

OtherPrimeInfos ::= SEQUENCE SIZE(1..MAX) OF OtherPrimeInfo

OtherPrimeInfo ::= SEQUENCE {
prime INTEGER, -- ri
exponent INTEGER, -- di
coefficient INTEGER -- ti
}

The fields of type OtherPrimeInfo have the following meanings:

* prime is a prime factor r_i of n, where i >= 3.

* exponent is d_i = d mod (r_i - 1).

* coefficient is the CRT coefficient t_i = (r_1 * r_2 * ... * r_(i-
1))^(-1) mod r_i.

Note. It is important to protect the RSA private key against both
disclosure and modification. Techniques for such protection are
outside the scope of this document. Methods for storing and
distributing private keys and other cryptographic data are described
in PKCS #12 and #15.

A.2 Scheme identification

This section defines object identifiers for the encryption and
signature schemes. The schemes compatible with PKCS #1 v1.5 have the
same definitions as in PKCS #1 v1.5. The intended application of
these definitions includes X.509 certificates and PKCS #7.

Here are type identifier definitions for the PKCS #1 OIDs:

PKCS1Algorithms ALGORITHM-IDENTIFIER ::= {
{ OID rsaEncryption PARAMETERS NULL } |
{ OID md2WithRSAEncryption PARAMETERS NULL } |
{ OID md5WithRSAEncryption PARAMETERS NULL } |
{ OID sha1WithRSAEncryption PARAMETERS NULL } |
{ OID sha256WithRSAEncryption PARAMETERS NULL } |
{ OID sha384WithRSAEncryption PARAMETERS NULL } |
{ OID sha512WithRSAEncryption PARAMETERS NULL } |
{ OID id-RSAES-OAEP PARAMETERS RSAES-OAEP-params } |
PKCS1PSourceAlgorithms |
{ OID id-RSASSA-PSS PARAMETERS RSASSA-PSS-params } ,
... -- Allows for future expansion --
}

A.2.1 RSAES-OAEP

The object identifier id-RSAES-OAEP identifies the RSAES-OAEP
encryption scheme.

id-RSAES-OAEP OBJECT IDENTIFIER ::= { pkcs-1 7 }

The parameters field associated with this OID in a value of type
AlgorithmIdentifier shall have a value of type RSAES-OAEP-params:

RSAES-OAEP-params ::= SEQUENCE {
hashAlgorithm [0] HashAlgorithm DEFAULT sha1,
maskGenAlgorithm [1] MaskGenAlgorithm DEFAULT mgf1SHA1,
pSourceAlgorithm [2] PSourceAlgorithm DEFAULT pSpecifiedEmpty
}

The fields of type RSAES-OAEP-params have the following meanings:

* hashAlgorithm identifies the hash function. It shall be an
algorithm ID with an OID in the set OAEP-PSSDigestAlgorithms.
For a discussion of supported hash functions, see Appendix B.1.

HashAlgorithm ::= AlgorithmIdentifier {
{OAEP-PSSDigestAlgorithms}
}

OAEP-PSSDigestAlgorithms ALGORITHM-IDENTIFIER ::= {
{ OID id-sha1 PARAMETERS NULL }|
{ OID id-sha256 PARAMETERS NULL }|
{ OID id-sha384 PARAMETERS NULL }|
{ OID id-sha512 PARAMETERS NULL },
... -- Allows for future expansion --
}

The default hash function is SHA-1:

sha1 HashAlgorithm ::= {
algorithm id-sha1,
parameters SHA1Parameters : NULL
}

SHA1Parameters ::= NULL

* maskGenAlgorithm identifies the mask generation function. It
shall be an algorithm ID with an OID in the set
PKCS1MGFAlgorithms, which for this version shall consist of
id-mgf1, identifying the MGF1 mask generation function (see
Appendix B.2.1). The parameters field associated with id-mgf1

shall be an algorithm ID with an OID in the set
OAEP-PSSDigestAlgorithms, identifying the hash function on which
MGF1 is based.

MaskGenAlgorithm ::= AlgorithmIdentifier {
{PKCS1MGFAlgorithms}
}
PKCS1MGFAlgorithms ALGORITHM-IDENTIFIER ::= {
{ OID id-mgf1 PARAMETERS HashAlgorithm },
... -- Allows for future expansion --
}

The default mask generation function is MGF1 with SHA-1:

mgf1SHA1 MaskGenAlgorithm ::= {
algorithm id-mgf1,
parameters HashAlgorithm : sha1
}

* pSourceAlgorithm identifies the source (and possibly the value)
of the label L. It shall be an algorithm ID with an OID in the
set PKCS1PSourceAlgorithms, which for this version shall consist
of id-pSpecified, indicating that the label is specified
explicitly. The parameters field associated with id-pSpecified
shall have a value of type OCTET STRING, containing the
label. In previous versions of this specification, the term
"encoding parameters" was used rather than "label", hence the
name of the type below.

PSourceAlgorithm ::= AlgorithmIdentifier {
{PKCS1PSourceAlgorithms}
}

PKCS1PSourceAlgorithms ALGORITHM-IDENTIFIER ::= {
{ OID id-pSpecified PARAMETERS EncodingParameters },
... -- Allows for future expansion --
}

id-pSpecified OBJECT IDENTIFIER ::= { pkcs-1 9 }

EncodingParameters ::= OCTET STRING(SIZE(0..MAX))

The default label is an empty string (so that lHash will contain
the hash of the empty string):

pSpecifiedEmpty PSourceAlgorithm ::= {
algorithm id-pSpecified,
parameters EncodingParameters : emptyString
}

emptyString EncodingParameters ::= ''H

If all of the default values of the fields in RSAES-OAEP-params
are used, then the algorithm identifier will have the following
value:

rSAES-OAEP-Default-Identifier RSAES-AlgorithmIdentifier ::= {
algorithm id-RSAES-OAEP,
parameters RSAES-OAEP-params : {
hashAlgorithm sha1,
maskGenAlgorithm mgf1SHA1,
pSourceAlgorithm pSpecifiedEmpty
}
}

RSAES-AlgorithmIdentifier ::= AlgorithmIdentifier {
{PKCS1Algorithms}
}

A.2.2 RSAES-PKCS1-v1_5

The object identifier rsaEncryption (see Appendix A.1) identifies the
RSAES-PKCS1-v1_5 encryption scheme. The parameters field associated
with this OID in a value of type AlgorithmIdentifier shall have a
value of type NULL. This is the same as in PKCS #1 v1.5.

rsaEncryption OBJECT IDENTIFIER ::= { pkcs-1 1 }

A.2.3 RSASSA-PSS

The object identifier id-RSASSA-PSS identifies the RSASSA-PSS
encryption scheme.

id-RSASSA-PSS OBJECT IDENTIFIER ::= { pkcs-1 10 }

The parameters field associated with this OID in a value of type
AlgorithmIdentifier shall have a value of type RSASSA-PSS-params:

RSASSA-PSS-params ::= SEQUENCE {
hashAlgorithm [0] HashAlgorithm DEFAULT sha1,
maskGenAlgorithm [1] MaskGenAlgorithm DEFAULT mgf1SHA1,
saltLength [2] INTEGER DEFAULT 20,
trailerField [3] TrailerField DEFAULT trailerFieldBC
}

The fields of type RSASSA-PSS-params have the following meanings:

* hashAlgorithm identifies the hash function. It shall be an
algorithm ID with an OID in the set OAEP-PSSDigestAlgorithms (see
Appendix A.2.1). The default hash function is SHA-1.

* maskGenAlgorithm identifies the mask generation function. It
shall be an algorithm ID with an OID in the set

PKCS1MGFAlgorithms (see Appendix A.2.1). The default mask
generation function is MGF1 with SHA-1. For MGF1 (and more
generally, for other mask generation functions based on a hash
function), it is recommended that the underlying hash function be
the same as the one identified by hashAlgorithm; see Note 2 in
Section 9.1 for further comments.

* saltLength is the octet length of the salt. It shall be an
integer. For a given hashAlgorithm, the default value of
saltLength is the octet length of the hash value. Unlike the
other fields of type RSASSA-PSS-params, saltLength does not need
to be fixed for a given RSA key pair.

* trailerField is the trailer field number, for compatibility with
the draft IEEE P1363a [27]. It shall be 1 for this version of the
document, which represents the trailer field with hexadecimal
value 0xbc. Other trailer fields (including the trailer field
HashID || 0xcc in IEEE P1363a) are not supported in this document.

TrailerField ::= INTEGER { trailerFieldBC(1) }

If the default values of the hashAlgorithm, maskGenAlgorithm, and
trailerField fields of RSASSA-PSS-params are used, then the
algorithm identifier will have the following value:

rSASSA-PSS-Default-Identifier RSASSA-AlgorithmIdentifier ::= {
algorithm id-RSASSA-PSS,
parameters RSASSA-PSS-params : {
hashAlgorithm sha1,
maskGenAlgorithm mgf1SHA1,
saltLength 20,
trailerField trailerFieldBC
}
}

RSASSA-AlgorithmIdentifier ::=
AlgorithmIdentifier { {PKCS1Algorithms} }

Note. In some applications, the hash function underlying a signature
scheme is identified separately from the rest of the operations in
the signature scheme. For instance, in PKCS #7 [45], a hash function
identifier is placed before the message and a "digest encryption"
algorithm identifier (indicating the rest of the operations) is
carried with the signature. In order for PKCS #7 to support the
RSASSA-PSS signature scheme, an object identifier would need to be
defined for the operations in RSASSA-PSS after the hash function
(analogous to the RSAEncryption OID for the RSASSA-PKCS1-v1_5
scheme). S/MIME CMS [25] takes a different approach. Although a
hash function identifier is placed before the message, an algorithm
identifier for the full signature scheme may be carried with a CMS
signature (this is done for DSA signatures). Following this
convention, the id-RSASSA-PSS OID can be used to identify RSASSA-PSS
signatures in CMS. Since CMS is considered the successor to PKCS #7
and new developments such as the addition of support for RSASSA-PSS
will be pursued with respect to CMS rather than PKCS #7, an OID for
the "rest of" RSASSA-PSS is not defined in this version of PKCS #1.

A.2.4 RSASSA-PKCS1-v1_5

The object identifier for RSASSA-PKCS1-v1_5 shall be one of the
following. The choice of OID depends on the choice of hash
algorithm: MD2, MD5, SHA-1, SHA-256, SHA-384, or SHA-512. Note that
if either MD2 or MD5 is used, then the OID is just as in PKCS #1
v1.5. For each OID, the parameters field associated with this OID in
a value of type AlgorithmIdentifier shall have a value of type NULL.
The OID should be chosen in accordance with the following table:

Hash algorithm OID
--------------------------------------------------------
MD2 md2WithRSAEncryption ::= {pkcs-1 2}
MD5 md5WithRSAEncryption ::= {pkcs-1 4}
SHA-1 sha1WithRSAEncryption ::= {pkcs-1 5}
SHA-256 sha256WithRSAEncryption ::= {pkcs-1 11}

SHA-384 sha384WithRSAEncryption ::= {pkcs-1 12}
SHA-512 sha512WithRSAEncryption ::= {pkcs-1 13}

The EMSA-PKCS1-v1_5 encoding method includes an ASN.1 value of type
DigestInfo, where the type DigestInfo has the syntax

DigestInfo ::= SEQUENCE {
digestAlgorithm DigestAlgorithm,
digest OCTET STRING
}

digestAlgorithm identifies the hash function and shall be an
algorithm ID with an OID in the set PKCS1-v1-5DigestAlgorithms. For
a discussion of supported hash functions, see Appendix B.1.

DigestAlgorithm ::=
AlgorithmIdentifier { {PKCS1-v1-5DigestAlgorithms} }

PKCS1-v1-5DigestAlgorithms ALGORITHM-IDENTIFIER ::= {
{ OID id-md2 PARAMETERS NULL }|
{ OID id-md5 PARAMETERS NULL }|
{ OID id-sha1 PARAMETERS NULL }|
{ OID id-sha256 PARAMETERS NULL }|
{ OID id-sha384 PARAMETERS NULL }|
{ OID id-sha512 PARAMETERS NULL }
}

Appendix B. Supporting techniques

This section gives several examples of underlying functions
supporting the encryption schemes in Section 7 and the encoding
methods in Section 9. A range of techniques is given here to allow
compatibility with existing applications as well as migration to new
techniques. While these supporting techniques are appropriate for
applications to implement, none of them is required to be
implemented. It is expected that profiles for PKCS #1 v2.1 will be
developed that specify particular supporting techniques.

This section also gives object identifiers for the supporting
techniques.

B.1 Hash functions

Hash functions are used in the operations contained in Sections 7 and
9. Hash functions are deterministic, meaning that the output is
completely determined by the input. Hash functions take octet
strings of variable length, and generate fixed length octet strings.

The hash functions used in the operations contained in Sections 7 and
9 should generally be collision-resistant. This means that it is
infeasible to find two distinct inputs to the hash function that
produce the same output. A collision-resistant hash function also
has the desirable property of being one-way; this means that given an
output, it is infeasible to find an input whose hash is the specified
output. In addition to the requirements, the hash function should
yield a mask generation function (Appendix B.2) with pseudorandom
output.

Six hash functions are given as examples for the encoding methods in
this document: MD2 [33], MD5 [41], SHA-1 [38], and the proposed
algorithms SHA-256, SHA-384, and SHA-512 [39]. For the RSAES-OAEP
encryption scheme and EMSA-PSS encoding method, only SHA-1 and SHA-
256/384/512 are recommended. For the EMSA-PKCS1-v1_5 encoding
method, SHA-1 or SHA-256/384/512 are recommended for new
applications. MD2 and MD5 are recommended only for compatibility
with existing applications based on PKCS #1 v1.5.

The object identifiers id-md2, id-md5, id-sha1, id-sha256, id-sha384,
and id-sha512, identify the respective hash functions:

id-md2 OBJECT IDENTIFIER ::= {
iso(1) member-body(2) us(840) rsadsi(113549)
digestAlgorithm(2) 2
}

id-md5 OBJECT IDENTIFIER ::= {
iso(1) member-body(2) us(840) rsadsi(113549)
digestAlgorithm(2) 5
}

id-sha1 OBJECT IDENTIFIER ::= {
iso(1) identified-organization(3) oiw(14) secsig(3)
algorithms(2) 26
}

id-sha256 OBJECT IDENTIFIER ::= {
joint-iso-itu-t(2) country(16) us(840) organization(1)
gov(101) csor(3) nistalgorithm(4) hashalgs(2) 1
}

id-sha384 OBJECT IDENTIFIER ::= {
joint-iso-itu-t(2) country(16) us(840) organization(1)
gov(101) csor(3) nistalgorithm(4) hashalgs(2) 2
}

id-sha512 OBJECT IDENTIFIER ::= {
joint-iso-itu-t(2) country(16) us(840) organization(1)
gov(101) csor(3) nistalgorithm(4) hashalgs(2) 3
}

The parameters field associated with id-md2 and id-md5 in a value of
type AlgorithmIdentifier shall have a value of type NULL.

The parameters field associated with id-sha1, id-sha256, id-sha384,
and id-sha512 should be omitted, but if present, shall have a value
of type NULL.

Note. Version 1.5 of PKCS #1 also allowed for the use of MD4 in
signature schemes. The cryptanalysis of MD4 has progressed
significantly in the intervening years. For example, Dobbertin [18]
demonstrated how to find collisions for MD4 and that the first two
rounds of MD4 are not one-way [20]. Because of these results and
others (e.g., [8]), MD4 is no longer recommended. There have also
been advances in the cryptanalysis of MD2 and MD5, although not
enough to warrant removal from existing applications. Rogier and
Chauvaud [43] demonstrated how to find collisions in a modified
version of MD2. No one has demonstrated how to find collisions for
the full MD5 algorithm, although partial results have been found
(e.g., [9][19]).

To address these concerns, SHA-1, SHA-256, SHA-384, or SHA-512 are
recommended for new applications. As of today, the best (known)
collision attacks against these hash functions are generic attacks
with complexity 2^(L/2), where L is the bit length of the hash
output. For the signature schemes in this document, a collision
attack is easily translated into a signature forgery. Therefore, the
value L / 2 should be at least equal to the desired security level in
bits of the signature scheme (a security level of B bits means that
the best attack has complexity 2^B). The same rule of thumb can be
applied to RSAES-OAEP; it is recommended that the bit length of the
seed (which is equal to the bit length of the hash output) be twice
the desired security level in bits.

B.2 Mask generation functions

A mask generation function takes an octet string of variable length
and a desired output length as input, and outputs an octet string of
the desired length. There may be restrictions on the length of the
input and output octet strings, but such bounds are generally very
large. Mask generation functions are deterministic; the octet string
output is completely determined by the input octet string. The
output of a mask generation function should be pseudorandom: Given
one part of the output but not the input, it should be infeasible to

predict another part of the output. The provable security of RSAES-
OAEP and RSASSA-PSS relies on the random nature of the output of the
mask generation function, which in turn relies on the random nature
of the underlying hash.

One mask generation function is given here: MGF1, which is based on a
hash function. MGF1 coincides with the mask generation functions
defined in IEEE Std 1363-2000 [26] and the draft ANSI X9.44 [1].
Future versions of this document may define other mask generation
functions.

B.2.1 MGF1

MGF1 is a Mask Generation Function based on a hash function.

MGF1 (mgfSeed, maskLen)

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

Input:
mgfSeed seed from which mask is generated, an octet string
maskLen intended length in octets of the mask, at most 2^32 hLen

Output:
mask mask, an octet string of length maskLen

Error: "mask too long"

Steps:

1. If maskLen > 2^32 hLen, output "mask too long" and stop.

2. Let T be the empty octet string.

3. For counter from 0 to \ceil (maskLen / hLen) - 1, do the
following:

a. Convert counter to an octet string C of length 4 octets (see
Section 4.1):

C = I2OSP (counter, 4) .

b. Concatenate the hash of the seed mgfSeed and C to the octet
string T:

T = T || Hash(mgfSeed || C) .

4. Output the leading maskLen octets of T as the octet string mask.

The object identifier id-mgf1 identifies the MGF1 mask generation
function:

id-mgf1 OBJECT IDENTIFIER ::= { pkcs-1 8 }

The parameters field associated with this OID in a value of type
AlgorithmIdentifier shall have a value of type hashAlgorithm,
identifying the hash function on which MGF1 is based.

Appendix C. ASN.1 module

PKCS-1 {
iso(1) member-body(2) us(840) rsadsi(113549) pkcs(1) pkcs-1(1)
modules(0) pkcs-1(1)
}

-- $ Revision: 2.1r1 $

-- This module has been checked for conformance with the ASN.1
-- standard by the OSS ASN.1 Tools

DEFINITIONS EXPLICIT TAGS ::=

BEGIN

-- EXPORTS ALL
-- All types and values defined in this module are exported for use
-- in other ASN.1 modules.

IMPORTS

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