Enable NSS to use tokens that support X9.31 RSA key pair generation.



13 years ago
13 years ago


(Reporter: wtc, Assigned: wtc)


(Blocks: 1 bug)

Firefox Tracking Flags

(Not tracked)



(3 attachments)



13 years ago
This enhancement request is related to but different
from bug 181570.

This enhancement request merely asks that NSS be able
to invoke the CKM_RSA_X9_31_KEY_PAIR_GEN mechanism on
tokens that support it.  The RSA public/private key
objects generated by this mechanism has the same key
type (CKK_RSA) as the RSA public/private key objects
generated by the CKM_RSA_PKCS_KEY_PAIR_GEN, and therefore
can used with PKCS #1 RSA mechanisms.

(Note: in contrast, the Diffie Hellman public/private
key objects in PKCS #11 have different key types for
PKCS #3 and ANSI X9.41.)

I compared Sec. 12.1.4 "PKCS #1 RSA key pair generation"
and Sec. 12.1.5 "X9.31 RSA key pair generation" in PKCS #11
v2.20 carefully.  The only two differences are:

attribute to be omitted from the template for the public key.

Since NSS's PK11_GenerateKeyPair function requires that the
"pe" member of the PK11RSAGenParams structure be nonzero and
always specifies the CKA_PUBLIC_EXPONENT attribute in
"rsaPubTemplate", this difference is irrelevant to NSS.

2. CKM_RSA_X9_31_KEY_PAIR_GEN is guaranteed to generate p and
q values that meet the strong primes requirement of X9.31.

This is an action performed inside the token and so is
transparent to NSS.

So I believe it is very simple to implement this enhancement.


13 years ago
Priority: -- → P1
Target Milestone: --- → 3.11

Comment 1

13 years ago
Created attachment 190583 [details] [diff] [review]
Proposed patch for PK11_GenerateKeyPair (checked in)

I believe we just need to add CKM_RSA_X9_31_KEY_PAIR_GEN
whenever we see CKM_RSA_PKCS_KEY_PAIR_GEN in PK11_GenerateKeyPair.

I also added code to test for a zero public exponent input
argument (rsaParams->pe == 0).	This code backs up the assertion
PORT_Assert(peCount != 0) a few lines below.

I don't know I need to add CKM_RSA_X9_31_KEY_PAIR_GEN to other
functions in NSS, in particular PK11_GetKeyType and
PK11_GetKeyGenWithSize in lib/pk11wrap/pk11mech.c.  Bob, could
you advise?
Attachment #190583 - Flags: review?(rrelyea)

Comment 2

13 years ago
Created attachment 190599 [details] [diff] [review]
Proposed patch for pk11mech.c (checked in)

I believe this is how the functions in lib/pk11wrap/pk11mech.c
should be updated to support CKM_RSA_X9_31_KEY_PAIR_GEN.

I still don't know what to do with the PK11_GetSlotList function
in lib/pk11wrap/pk11slot.c.
Attachment #190599 - Flags: review?(rrelyea)

Comment 3

13 years ago
Created attachment 190601 [details] [diff] [review]
Proposed patch for pk11slot.c
Attachment #190601 - Flags: review?(rrelyea)

Comment 4

13 years ago
Comment on attachment 190583 [details] [diff] [review]
Proposed patch for PK11_GenerateKeyPair (checked in)

This one looks good. r=relyea

The second switch statement  kinda calls for merging with
I'm not sure how many versions of this are scattered throughtout the  wrapper
code... that that's a preexisting issue.
Attachment #190583 - Flags: review?(rrelyea) → review+


13 years ago
Attachment #190583 - Attachment description: Proposed patch for PK11_GenerateKeyPair → Proposed patch for PK11_GenerateKeyPair (checked in)

Comment 5

13 years ago
Comment on attachment 190599 [details] [diff] [review]
Proposed patch for pk11mech.c (checked in)

Attachment #190599 - Flags: review?(rrelyea) → review+

Comment 6

13 years ago
Comment on attachment 190601 [details] [diff] [review]
Proposed patch for pk11slot.c


let's not link this with the default RSA lists. If we do, then if you issue a
GetBestSlot with CKM_RSA_X9_31_KEY_PAIR_GEN could potentially return slots that
can't do CKM_RSA_X9_31_KEY_PAIR_GEN. (slots need to support all the 'prereq'
mechanisms to be on these lists). PK11_GetBestSlot and PK11_GetBestSlotMultiple
can easily find slots that can do functions that are not specified in

Attachment #190601 - Flags: review?(rrelyea) → review-

Comment 7

13 years ago
On reviewing the patches, and knowing where the request comes from, it seems to
me it might be desirable to define a 'psuedo'-Mechanism: CKM_RSA_KEY_PAIR_GEN
which tells PK11_GenerateKeyPair to use either CKM_RSA_PKCS_KEY_PAIR_GEN or
CKM_RSA_X9_31_KEY_PAIR_GEN since the resultant keys are identical. Applications
would provide CKM_RSA_PKCS_XXX or CKM_RSA_X9_31_XXX if they need the specific
semantics of these key generation algorithms, or CKM_RSA_XXX if the application
just needs an RSA Key.



13 years ago
Attachment #190599 - Attachment description: Proposed patch for pk11mech.c → Proposed patch for pk11mech.c (checked in)

Comment 8

13 years ago
Comment on attachment 190601 [details] [diff] [review]
Proposed patch for pk11slot.c

Bob: doesn't PK11_GetBestSlotMultiple verify that the slot on
the list can actually do the mechanisms?  Here is the code snippet
that I think does this check:  

2054		 for (i=0; i < mech_count; i++) {
2055		     if (!PK11_DoesMechanism(le->slot,type[i])) {
2056			 doExit = PR_TRUE;
2057			 break;
2058		     }
2059		 }

Comment 9

13 years ago
Hmm that's correct, I initially though it only verified subsequent, mechanisms.
I still think it's better to leave it off the list, though. The list is your
'default' or preferred devices. It's not a good idea to have a default or
preferred device which doesn't implement the specified mechanism. Note that if
you use the slot list only devices registered on the slot list will be searched
(we don't search the general list of slots unless we don't get a slotlist).

It's really mute for this algorithm, though. Usually you aren't looking for the
'best slot to generate RSA keys', you are generating the keys in the pre-chosen
target slot.


Comment 10

13 years ago
According to the document "Differences between ANSI X9.31 and RSA PKCS #1"

    All key components generated with compliance to ANSI X9.31
    with an odd e are also RSA PKCS #1 compliant.

So if our customer is to use CKM_RSA_X9_31_KEY_PAIR_GEN to generate an
RSA key pair for use with PKCS #1, he must specify an odd public exponent e.
Last Resolved: 13 years ago
Resolution: --- → FIXED


13 years ago
Blocks: 303021
You need to log in before you can comment on or make changes to this bug.