summaryrefslogtreecommitdiffstats
path: root/prsa.c
blob: 1391dd355845c9dac39becd4ca58a953aaa08ca2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
/* ***** BEGIN LICENSE BLOCK *****
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
 *
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is the Netscape security libraries.
 *
 * The Initial Developer of the Original Code is
 * Netscape Communications Corporation.
 * Portions created by the Initial Developer are Copyright (C) 1994-2000
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s):
 *   Rob Crittenden (rcritten@redhat.com)
 *
 * Alternatively, the contents of this file may be used under the terms of
 * either the GNU General Public License Version 2 or later (the "GPL"), or
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 * in which case the provisions of the GPL or the LGPL are applicable instead
 * of those above. If you wish to allow use of your version of this file only
 * under the terms of either the GPL or the LGPL, and not to allow others to
 * use your version of this file under the terms of the MPL, indicate your
 * decision by deleting the provisions above and replace them with the notice
 * and other provisions required by the GPL or the LGPL. If you do not delete
 * the provisions above, a recipient may use your version of this file under
 * the terms of any one of the MPL, the GPL or the LGPL.
 *
 * ***** END LICENSE BLOCK ***** */

#include "ckpem.h"
#include "secdert.h"
#include "secoid.h"
#include "nssckmdt.h"

#define SSL3_SHAMD5_HASH_SIZE  36       /* LEN_MD5 (16) + LEN_SHA1 (20) */

/*
 * prsa.c
 *
 * This file implements the NSSCKMDMechnaism and NSSCKMDCryptoOperation objects
 * for the RSA operation.
 */

const SEC_ASN1Template pem_RSAPrivateKeyTemplate[] = {
    {SEC_ASN1_SEQUENCE, 0, NULL, sizeof(pemLOWKEYPrivateKey)} ,
    {SEC_ASN1_INTEGER, offsetof(pemLOWKEYPrivateKey, u.rsa.version)},
    {SEC_ASN1_INTEGER, offsetof(pemLOWKEYPrivateKey, u.rsa.modulus)},
    {SEC_ASN1_INTEGER, offsetof(pemLOWKEYPrivateKey, u.rsa.publicExponent)},
    {SEC_ASN1_INTEGER, offsetof(pemLOWKEYPrivateKey, u.rsa.privateExponent)},
    {SEC_ASN1_INTEGER, offsetof(pemLOWKEYPrivateKey, u.rsa.prime1)},
    {SEC_ASN1_INTEGER, offsetof(pemLOWKEYPrivateKey, u.rsa.prime2)},
    {SEC_ASN1_INTEGER, offsetof(pemLOWKEYPrivateKey, u.rsa.exponent1)},
    {SEC_ASN1_INTEGER, offsetof(pemLOWKEYPrivateKey, u.rsa.exponent2)},
    {SEC_ASN1_INTEGER, offsetof(pemLOWKEYPrivateKey, u.rsa.coefficient)},
    {0}
};

/* Declarations */
SECStatus pem_RSA_Sign(pemLOWKEYPrivateKey * key, unsigned char *output,
                       unsigned int *outputLen, unsigned int maxOutputLen,
                       unsigned char *input, unsigned int inputLen);
SECStatus pem_RSA_DecryptBlock(pemLOWKEYPrivateKey * key,
                               unsigned char *output, unsigned int *outputLen,
                               unsigned int maxOutputLen, unsigned char *input,
                               unsigned int inputLen);

void prepare_low_rsa_priv_key_for_asn1(pemLOWKEYPrivateKey * key)
{
    key->u.rsa.modulus.type = siUnsignedInteger;
    key->u.rsa.publicExponent.type = siUnsignedInteger;
    key->u.rsa.privateExponent.type = siUnsignedInteger;
    key->u.rsa.prime1.type = siUnsignedInteger;
    key->u.rsa.prime2.type = siUnsignedInteger;
    key->u.rsa.exponent1.type = siUnsignedInteger;
    key->u.rsa.exponent2.type = siUnsignedInteger;
    key->u.rsa.coefficient.type = siUnsignedInteger;
}

unsigned int
pem_PrivateModulusLen(pemLOWKEYPrivateKey * privk)
{

    unsigned char b0;

    switch (privk->keyType) {
    case pemLOWKEYRSAKey:
        b0 = privk->u.rsa.modulus.data[0];
        return b0 ? privk->u.rsa.modulus.len : privk->u.rsa.modulus.len -
            1;
    default:
        break;
    }
    return 0;
}

struct SFTKHashSignInfoStr {
    SECOidTag hashOid;
    pemLOWKEYPrivateKey *key;
};
typedef struct SFTKHashSignInfoStr SFTKHashSignInfo;

void
pem_DestroyPrivateKey(pemLOWKEYPrivateKey * privk)
{
    if (privk && privk->arena) {
        PORT_FreeArena(privk->arena, PR_TRUE);
    }
}

void
pem_PopulateModulusExponent(pemInternalObject * io)
{
    const NSSItem *classItem = pem_FetchAttribute(io, CKA_CLASS);
    const NSSItem *keyType = pem_FetchAttribute(io, CKA_KEY_TYPE);
    pemLOWKEYPrivateKey *lpk = NULL;
    PLArenaPool *arena;
    SECStatus rv;

    arena = PORT_NewArena(2048);
    if (!arena) {
        return;
    }

    /* make sure we have the right objects */
    if (((const NSSItem *) NULL == classItem) ||
        (sizeof(CK_OBJECT_CLASS) != classItem->size) ||
        (CKO_PRIVATE_KEY != *(CK_OBJECT_CLASS *) classItem->data) ||
        ((const NSSItem *) NULL == keyType) ||
        (sizeof(CK_KEY_TYPE) != keyType->size) ||
        (CKK_RSA != *(CK_KEY_TYPE *) keyType->data)) {
        return;
    }

    lpk = (pemLOWKEYPrivateKey *) nss_ZAlloc(NULL,
                                             sizeof(pemLOWKEYPrivateKey));
    if (lpk == NULL) {
        PORT_FreeArena(arena, PR_FALSE);
        return;
    }

    lpk->arena = arena;
    lpk->keyType = pemLOWKEYRSAKey;
    prepare_low_rsa_priv_key_for_asn1(lpk);

    /* decode the private key and any algorithm parameters */
    rv = SEC_QuickDERDecodeItem(arena, lpk, pem_RSAPrivateKeyTemplate,
                                io->u.key.key.privateKey);

    if (rv != SECSuccess) {
        PORT_FreeArena(arena, PR_FALSE);
        return;
    }

    io->u.key.key.modulus.data =
        (void *) nss_ZAlloc(NULL, lpk->u.rsa.modulus.len);
    io->u.key.key.modulus.size = lpk->u.rsa.modulus.len;
    nsslibc_memcpy(io->u.key.key.modulus.data, lpk->u.rsa.modulus.data,
                   lpk->u.rsa.modulus.len);

    io->u.key.key.exponent.data =
        (void *) nss_ZAlloc(NULL, lpk->u.rsa.publicExponent.len);
    io->u.key.key.exponent.size = lpk->u.rsa.publicExponent.len;
    nsslibc_memcpy(io->u.key.key.exponent.data,
                   lpk->u.rsa.publicExponent.data,
                   lpk->u.rsa.publicExponent.len);

    io->u.key.key.privateExponent.data =
        (void *) nss_ZAlloc(NULL, lpk->u.rsa.privateExponent.len);
    io->u.key.key.privateExponent.size = lpk->u.rsa.privateExponent.len;
    nsslibc_memcpy(io->u.key.key.privateExponent.data,
                   lpk->u.rsa.privateExponent.data,
                   lpk->u.rsa.privateExponent.len);

    io->u.key.key.prime1.data =
        (void *) nss_ZAlloc(NULL, lpk->u.rsa.prime1.len);
    io->u.key.key.prime1.size = lpk->u.rsa.prime1.len;
    nsslibc_memcpy(io->u.key.key.prime1.data, lpk->u.rsa.prime1.data,
                   lpk->u.rsa.prime1.len);

    io->u.key.key.prime2.data =
        (void *) nss_ZAlloc(NULL, lpk->u.rsa.prime2.len);
    io->u.key.key.prime2.size = lpk->u.rsa.prime2.len;
    nsslibc_memcpy(io->u.key.key.prime2.data, lpk->u.rsa.prime2.data,
                   lpk->u.rsa.prime2.len);

    io->u.key.key.exponent1.data =
        (void *) nss_ZAlloc(NULL, lpk->u.rsa.exponent1.len);
    io->u.key.key.exponent1.size = lpk->u.rsa.exponent1.len;
    nsslibc_memcpy(io->u.key.key.exponent1.data, lpk->u.rsa.exponent1.data,
                   lpk->u.rsa.exponent1.len);

    io->u.key.key.exponent2.data =
        (void *) nss_ZAlloc(NULL, lpk->u.rsa.exponent2.len);
    io->u.key.key.exponent2.size = lpk->u.rsa.exponent2.len;
    nsslibc_memcpy(io->u.key.key.exponent2.data, lpk->u.rsa.exponent2.data,
                   lpk->u.rsa.exponent2.len);

    io->u.key.key.coefficient.data =
        (void *) nss_ZAlloc(NULL, lpk->u.rsa.coefficient.len);
    io->u.key.key.coefficient.size = lpk->u.rsa.coefficient.len;
    nsslibc_memcpy(io->u.key.key.coefficient.data,
                   lpk->u.rsa.coefficient.data,
                   lpk->u.rsa.coefficient.len);

    pem_DestroyPrivateKey(lpk);
    return;
}

typedef struct pemInternalCryptoOperationRSAPrivStr
               pemInternalCryptoOperationRSAPriv;
struct pemInternalCryptoOperationRSAPrivStr
{
    NSSCKMDCryptoOperation mdOperation;
    NSSCKMDMechanism *mdMechanism;
    pemInternalObject *iKey;
    pemLOWKEYPrivateKey *lpk;
    NSSItem *buffer;
};

/*
 * pem_mdCryptoOperationRSAPriv_Create
 */
static NSSCKMDCryptoOperation *
pem_mdCryptoOperationRSAPriv_Create
(
    const NSSCKMDCryptoOperation * proto,
    NSSCKMDMechanism * mdMechanism,
    NSSCKMDObject * mdKey,
    CK_RV * pError
)
{
    pemInternalObject *iKey = (pemInternalObject *) mdKey->etc;
    const NSSItem *classItem = pem_FetchAttribute(iKey, CKA_CLASS);
    const NSSItem *keyType = pem_FetchAttribute(iKey, CKA_KEY_TYPE);
    pemInternalCryptoOperationRSAPriv *iOperation;
    pemLOWKEYPrivateKey *lpk = NULL;
    PLArenaPool *arena;
    SECStatus rv;

    arena =  PORT_NewArena(2048);
    if (!arena) {
        *pError = CKR_HOST_MEMORY;
        return (NSSCKMDCryptoOperation *) NULL;
    }

    /* make sure we have the right objects */
    if (((const NSSItem *) NULL == classItem) ||
        (sizeof(CK_OBJECT_CLASS) != classItem->size) ||
        (CKO_PRIVATE_KEY != *(CK_OBJECT_CLASS *) classItem->data) ||
        ((const NSSItem *) NULL == keyType) ||
        (sizeof(CK_KEY_TYPE) != keyType->size) ||
        (CKK_RSA != *(CK_KEY_TYPE *) keyType->data)) {
        *pError = CKR_KEY_TYPE_INCONSISTENT;
        return (NSSCKMDCryptoOperation *) NULL;
    }

    lpk = (pemLOWKEYPrivateKey *) nss_ZAlloc(NULL,
                                             sizeof (pemLOWKEYPrivateKey));
    if (lpk == NULL) {
        *pError = CKR_HOST_MEMORY;
        return (NSSCKMDCryptoOperation *) NULL;
    }
    lpk->arena = arena;
    lpk->keyType = pemLOWKEYRSAKey;
    prepare_low_rsa_priv_key_for_asn1(lpk);
    iKey->u.key.key.modulus.data =
        (void *) nss_ZAlloc(NULL, lpk->u.rsa.modulus.len);
    iKey->u.key.key.modulus.size = lpk->u.rsa.modulus.len;
    nsslibc_memcpy(iKey->u.key.key.modulus.data, lpk->u.rsa.modulus.data,
                   lpk->u.rsa.modulus.len);

    /* decode the private key and any algorithm parameters */
    rv = SEC_QuickDERDecodeItem(arena, lpk, pem_RSAPrivateKeyTemplate,
                                iKey->u.key.key.privateKey);

    if (rv != SECSuccess) {
        PORT_FreeArena(arena, PR_FALSE);
        *pError = CKR_HOST_MEMORY;
        return (NSSCKMDCryptoOperation *) NULL;
    }

    iOperation = nss_ZNEW(NULL, pemInternalCryptoOperationRSAPriv);
    if ((pemInternalCryptoOperationRSAPriv *) NULL == iOperation) {
        *pError = CKR_HOST_MEMORY;
        return (NSSCKMDCryptoOperation *) NULL;
    }
    iOperation->mdMechanism = mdMechanism;
    iOperation->iKey = iKey;
    iOperation->lpk = lpk;

    nsslibc_memcpy(&iOperation->mdOperation,
                   proto, sizeof(NSSCKMDCryptoOperation));
    iOperation->mdOperation.etc = iOperation;

    return &iOperation->mdOperation;
}

static CK_RV
pem_mdCryptoOperationRSAPriv_Destroy
(
    NSSCKMDCryptoOperation * mdOperation,
    NSSCKFWCryptoOperation * fwOperation,
    NSSCKMDInstance * mdInstance,
    NSSCKFWInstance * fwInstance
)
{
    pemInternalCryptoOperationRSAPriv *iOperation =
        (pemInternalCryptoOperationRSAPriv *) mdOperation->etc;

    if (iOperation->buffer) {
        nssItem_Destroy(iOperation->buffer);
    }
    nss_ZFreeIf(iOperation);
    return CKR_OK;
}

static CK_ULONG
pem_mdCryptoOperationRSA_GetFinalLength
(
    NSSCKMDCryptoOperation * mdOperation,
    NSSCKFWCryptoOperation * fwOperation,
    NSSCKMDSession * mdSession,
    NSSCKFWSession * fwSession,
    NSSCKMDToken * mdToken,
    NSSCKFWToken * fwToken,
    NSSCKMDInstance * mdInstance,
    NSSCKFWInstance * fwInstance,
    CK_RV * pError
)
{
    pemInternalCryptoOperationRSAPriv *iOperation =
        (pemInternalCryptoOperationRSAPriv *) mdOperation->etc;
    const NSSItem *modulus =
        pem_FetchAttribute(iOperation->iKey, CKA_MODULUS);

    return modulus->size;
}


/*
 * pem_mdCryptoOperationRSADecrypt_GetOperationLength
 * we won't know the length until we actually decrypt the
 * input block. Since we go to all the work to decrypt the
 * the block, we'll save if for when the block is asked for
 */
static CK_ULONG
pem_mdCryptoOperationRSADecrypt_GetOperationLength
(
    NSSCKMDCryptoOperation * mdOperation,
    NSSCKFWCryptoOperation * fwOperation,
    NSSCKMDSession * mdSession,
    NSSCKFWSession * fwSession,
    NSSCKMDToken * mdToken,
    NSSCKFWToken * fwToken,
    NSSCKMDInstance * mdInstance,
    NSSCKFWInstance * fwInstance,
    const NSSItem * input,
    CK_RV * pError
)
{
    pemInternalCryptoOperationRSAPriv *iOperation =
        (pemInternalCryptoOperationRSAPriv *) mdOperation->etc;
    SECStatus rv;

    /* FIXME: Just because Microsoft is broken doesn't mean I have to be.
     * but this is faster to do for now */

    /* Microsoft's Decrypt operation works in place. Since we don't want
     * to trash our input buffer, we make a copy of it */
    iOperation->buffer = nssItem_Duplicate((NSSItem *) input, NULL, NULL);
    if ((NSSItem *) NULL == iOperation->buffer) {
        *pError = CKR_HOST_MEMORY;
        return 0;
    }

    rv = pem_RSA_DecryptBlock(iOperation->lpk, iOperation->buffer->data,
                              &iOperation->buffer->size,
                              iOperation->buffer->size, input->data,
                              input->size);

    if (rv != SECSuccess) {
        return 0;
    }

    return iOperation->buffer->size;
}

/*
 * pem_mdCryptoOperationRSADecrypt_UpdateFinal
 *
 * NOTE: pem_mdCryptoOperationRSADecrypt_GetOperationLength is presumed to 
 * have been called previously.
 */
static CK_RV
pem_mdCryptoOperationRSADecrypt_UpdateFinal
(
    NSSCKMDCryptoOperation * mdOperation,
    NSSCKFWCryptoOperation * fwOperation,
    NSSCKMDSession * mdSession,
    NSSCKFWSession * fwSession,
    NSSCKMDToken * mdToken,
    NSSCKFWToken * fwToken,
    NSSCKMDInstance * mdInstance,
    NSSCKFWInstance * fwInstance,
    const NSSItem * input,
    NSSItem * output
)
{
    pemInternalCryptoOperationRSAPriv *iOperation =
        (pemInternalCryptoOperationRSAPriv *) mdOperation->etc;
    NSSItem *buffer = iOperation->buffer;

    if ((NSSItem *) NULL == buffer) {
        return CKR_GENERAL_ERROR;
    }
    nsslibc_memcpy(output->data, buffer->data, buffer->size);
    output->size = buffer->size;
    return CKR_OK;
}

/*
 * pem_mdCryptoOperationRSASign_UpdateFinal
 *
 */
static CK_RV
pem_mdCryptoOperationRSASign_UpdateFinal
(
    NSSCKMDCryptoOperation * mdOperation,
    NSSCKFWCryptoOperation * fwOperation,
    NSSCKMDSession * mdSession,
    NSSCKFWSession * fwSession,
    NSSCKMDToken * mdToken,
    NSSCKFWToken * fwToken,
    NSSCKMDInstance * mdInstance,
    NSSCKFWInstance * fwInstance,
    const NSSItem * input,
    NSSItem * output
)
{
    pemInternalCryptoOperationRSAPriv *iOperation =
        (pemInternalCryptoOperationRSAPriv *) mdOperation->etc;
    CK_RV error = CKR_OK;
    SECStatus rv = SECSuccess;

    rv = pem_RSA_Sign(iOperation->lpk, output->data, &output->size,
                      output->size, input->data, input->size);

    if (rv != SECSuccess) {
        error = CKR_GENERAL_ERROR;
    }

    return error;
}

NSS_IMPLEMENT_DATA const NSSCKMDCryptoOperation
pem_mdCryptoOperationRSADecrypt_proto = {
    NULL, /* etc */
    pem_mdCryptoOperationRSAPriv_Destroy,
    NULL, /* GetFinalLengh - not needed for one shot Decrypt/Encrypt */
    pem_mdCryptoOperationRSADecrypt_GetOperationLength,
    NULL, /* Final - not needed for one shot operation */
    NULL, /* Update - not needed for one shot operation */
    NULL, /* DigestUpdate - not needed for one shot operation */
    pem_mdCryptoOperationRSADecrypt_UpdateFinal,
    NULL, /* UpdateCombo - not needed for one shot operation */
    NULL, /* DigestKey - not needed for one shot operation */
    (void *) NULL /* null terminator */
};

NSS_IMPLEMENT_DATA const NSSCKMDCryptoOperation
pem_mdCryptoOperationRSASign_proto = {
    NULL, /* etc */
    pem_mdCryptoOperationRSAPriv_Destroy,
    pem_mdCryptoOperationRSA_GetFinalLength,
    NULL, /* GetOperationLengh - not needed for one shot Sign/Verify */
    NULL, /* Final - not needed for one shot operation */
    NULL, /* Update - not needed for one shot operation */
    NULL, /* DigestUpdate - not needed for one shot operation */
    pem_mdCryptoOperationRSASign_UpdateFinal,
    NULL, /* UpdateCombo - not needed for one shot operation */
    NULL, /* DigestKey - not needed for one shot operation */
    (void *) NULL /* null terminator */
};

/********** NSSCKMDMechansim functions ***********************/
/*
 * pem_mdMechanismRSA_Destroy
 */
static void
pem_mdMechanismRSA_Destroy
(
    NSSCKMDMechanism * mdMechanism,
    NSSCKFWMechanism * fwMechanism,
    NSSCKMDInstance * mdInstance,
    NSSCKFWInstance * fwInstance
)
{
    nss_ZFreeIf(fwMechanism);
}

/*
 * pem_mdMechanismRSA_GetMinKeySize
 */
static CK_ULONG
pem_mdMechanismRSA_GetMinKeySize
(
    NSSCKMDMechanism * mdMechanism,
    NSSCKFWMechanism * fwMechanism,
    NSSCKMDToken * mdToken,
    NSSCKFWToken * fwToken,
    NSSCKMDInstance * mdInstance,
    NSSCKFWInstance * fwInstance,
    CK_RV * pError
)
{
    return 384;
}

/*
 * pem_mdMechanismRSA_GetMaxKeySize
 */
static CK_ULONG
pem_mdMechanismRSA_GetMaxKeySize
(
    NSSCKMDMechanism * mdMechanism,
    NSSCKFWMechanism * fwMechanism,
    NSSCKMDToken * mdToken,
    NSSCKFWToken * fwToken,
    NSSCKMDInstance * mdInstance,
    NSSCKFWInstance * fwInstance,
    CK_RV * pError
)
{
    return 16384;
}

/*
 * pem_mdMechanismRSA_DecryptInit
 */
static NSSCKMDCryptoOperation *
pem_mdMechanismRSA_DecryptInit
(
    NSSCKMDMechanism * mdMechanism,
    NSSCKFWMechanism * fwMechanism,
    CK_MECHANISM * pMechanism,
    NSSCKMDSession * mdSession,
    NSSCKFWSession * fwSession,
    NSSCKMDToken * mdToken,
    NSSCKFWToken * fwToken,
    NSSCKMDInstance * mdInstance,
    NSSCKFWInstance * fwInstance,
    NSSCKMDObject * mdKey,
    NSSCKFWObject * fwKey,
    CK_RV * pError
)
{
    return pem_mdCryptoOperationRSAPriv_Create
        (&pem_mdCryptoOperationRSADecrypt_proto, mdMechanism, mdKey,
         pError);
}

/*
 * pem_mdMechanismRSA_SignInit
 */
static NSSCKMDCryptoOperation *
pem_mdMechanismRSA_SignInit
(
    NSSCKMDMechanism * mdMechanism,
    NSSCKFWMechanism * fwMechanism,
    CK_MECHANISM * pMechanism,
    NSSCKMDSession * mdSession,
    NSSCKFWSession * fwSession,
    NSSCKMDToken * mdToken,
    NSSCKFWToken * fwToken,
    NSSCKMDInstance * mdInstance,
    NSSCKFWInstance * fwInstance,
    NSSCKMDObject * mdKey,
    NSSCKFWObject * fwKey,
    CK_RV * pError
)
{
    return pem_mdCryptoOperationRSAPriv_Create
        (&pem_mdCryptoOperationRSASign_proto, mdMechanism, mdKey, pError);
}

NSS_IMPLEMENT_DATA const NSSCKMDMechanism
pem_mdMechanismRSA = {
    (void *) NULL, /* etc */
    pem_mdMechanismRSA_Destroy,
    pem_mdMechanismRSA_GetMinKeySize,
    pem_mdMechanismRSA_GetMaxKeySize,
    NULL, /* GetInHardware - default false */
    NULL, /* EncryptInit - default errs */
    pem_mdMechanismRSA_DecryptInit,
    NULL, /* DigestInit - default errs */
    pem_mdMechanismRSA_SignInit,
    NULL, /* VerifyInit - default errs */
    pem_mdMechanismRSA_SignInit,        /* SignRecoverInit */
    NULL, /* VerifyRecoverInit - default errs */
    NULL, /* GenerateKey - default errs */
    NULL, /* GenerateKeyPair - default errs */
    NULL, /* GetWrapKeyLength - default errs */
    NULL, /* WrapKey - default errs */
    NULL, /* UnwrapKey - default errs */
    NULL, /* DeriveKey - default errs */
    (void *) NULL /* null terminator */
};