~ubuntu-branches/ubuntu/maverick/nss/maverick

« back to all changes in this revision

Viewing changes to mozilla/security/nss/lib/ckfw/mechanism.c

  • Committer: Bazaar Package Importer
  • Author(s): Alexander Sack
  • Date: 2009-06-16 13:23:47 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20090616132347-311ysb8oep74b98y
Tags: 3.12.3-0ubuntu1
* new upstream release 3.12.3 RTM (NSS_3_12_3_RTM) (LP: #387751)
* adjust patches to changed upstream code base
  - update debian/patches/38_kbsd.patch
* needs nspr >= 4.7.4
  - update debian/control
* update 85_security_load.patch to latest debian version
  - update debian/patches/85_security_load.patch
* add new symbols for 3.12.3
  - update debian/libnss3-1d.symbols

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
 * ***** END LICENSE BLOCK ***** */
36
36
 
37
37
#ifdef DEBUG
38
 
static const char CVS_ID[] = "@(#) $RCSfile: mechanism.c,v $ $Revision: 1.5 $ $Date: 2007/12/12 00:50:58 $";
 
38
static const char CVS_ID[] = "@(#) $RCSfile: mechanism.c,v $ $Revision: 1.6 $ $Date: 2009/02/09 07:55:52 $";
39
39
#endif /* DEBUG */
40
40
 
41
41
/*
118
118
 
119
119
 
120
120
  fwMechanism = nss_ZNEW(NULL, NSSCKFWMechanism);
121
 
  if ((NSSCKFWMechanism *)NULL == fwMechanism) {
 
121
  if (!fwMechanism) {
122
122
    return (NSSCKFWMechanism *)NULL;
123
123
  }
124
124
  fwMechanism->mdMechanism = mdMechanism;
141
141
{
142
142
  /* destroy any fw resources held by nssCKFWMechanism (currently none) */
143
143
 
144
 
  if ((void *)NULL == (void *)fwMechanism->mdMechanism->Destroy) {
 
144
  if (!fwMechanism->mdMechanism->Destroy) {
145
145
    /* destroys it's parent as well */
146
146
    fwMechanism->mdMechanism->Destroy(
147
147
        fwMechanism->mdMechanism, 
178
178
  CK_RV *pError
179
179
)
180
180
{
181
 
  if ( (void *)NULL == (void *)fwMechanism->mdMechanism->GetMinKeySize) {
 
181
  if (!fwMechanism->mdMechanism->GetMinKeySize) {
182
182
    return 0;
183
183
  }
184
184
 
198
198
  CK_RV *pError
199
199
)
200
200
{
201
 
  if ( (void *)NULL == (void *)fwMechanism->mdMechanism->GetMaxKeySize) {
 
201
  if (!fwMechanism->mdMechanism->GetMaxKeySize) {
202
202
    return 0;
203
203
  }
204
204
 
218
218
  CK_RV *pError
219
219
)
220
220
{
221
 
  if ( (void *)NULL == (void *)fwMechanism->mdMechanism->GetInHardware) {
 
221
  if (!fwMechanism->mdMechanism->GetInHardware) {
222
222
    return CK_FALSE;
223
223
  }
224
224
 
243
243
  CK_RV *pError
244
244
)
245
245
{
246
 
  if ( (void *)NULL == (void *)fwMechanism->mdMechanism->EncryptInit) {
 
246
  if (!fwMechanism->mdMechanism->EncryptInit) {
247
247
    return CK_FALSE;
248
248
  }
249
249
  return CK_TRUE;
260
260
  CK_RV *pError
261
261
)
262
262
{
263
 
  if ( (void *)NULL == (void *)fwMechanism->mdMechanism->DecryptInit) {
 
263
  if (!fwMechanism->mdMechanism->DecryptInit) {
264
264
    return CK_FALSE;
265
265
  }
266
266
  return CK_TRUE;
277
277
  CK_RV *pError
278
278
)
279
279
{
280
 
  if ( (void *)NULL == (void *)fwMechanism->mdMechanism->DigestInit) {
 
280
  if (!fwMechanism->mdMechanism->DigestInit) {
281
281
    return CK_FALSE;
282
282
  }
283
283
  return CK_TRUE;
294
294
  CK_RV *pError
295
295
)
296
296
{
297
 
  if ( (void *)NULL == (void *)fwMechanism->mdMechanism->SignInit) {
 
297
  if (!fwMechanism->mdMechanism->SignInit) {
298
298
    return CK_FALSE;
299
299
  }
300
300
  return CK_TRUE;
311
311
  CK_RV *pError
312
312
)
313
313
{
314
 
  if ( (void *)NULL == (void *)fwMechanism->mdMechanism->SignRecoverInit) {
 
314
  if (!fwMechanism->mdMechanism->SignRecoverInit) {
315
315
    return CK_FALSE;
316
316
  }
317
317
  return CK_TRUE;
328
328
  CK_RV *pError
329
329
)
330
330
{
331
 
  if ( (void *)NULL == (void *)fwMechanism->mdMechanism->VerifyInit) {
 
331
  if (!fwMechanism->mdMechanism->VerifyInit) {
332
332
    return CK_FALSE;
333
333
  }
334
334
  return CK_TRUE;
345
345
  CK_RV *pError
346
346
)
347
347
{
348
 
  if ( (void *)NULL == (void *)fwMechanism->mdMechanism->VerifyRecoverInit) {
 
348
  if (!fwMechanism->mdMechanism->VerifyRecoverInit) {
349
349
    return CK_FALSE;
350
350
  }
351
351
  return CK_TRUE;
362
362
  CK_RV *pError
363
363
)
364
364
{
365
 
  if ( (void *)NULL == (void *)fwMechanism->mdMechanism->GenerateKey) {
 
365
  if (!fwMechanism->mdMechanism->GenerateKey) {
366
366
    return CK_FALSE;
367
367
  }
368
368
  return CK_TRUE;
379
379
  CK_RV *pError
380
380
)
381
381
{
382
 
  if ( (void *)NULL == (void *)fwMechanism->mdMechanism->GenerateKeyPair) {
 
382
  if (!fwMechanism->mdMechanism->GenerateKeyPair) {
383
383
    return CK_FALSE;
384
384
  }
385
385
  return CK_TRUE;
396
396
  CK_RV *pError
397
397
)
398
398
{
399
 
  if ( (void *)NULL == (void *)fwMechanism->mdMechanism->UnwrapKey) {
 
399
  if (!fwMechanism->mdMechanism->UnwrapKey) {
400
400
    return CK_FALSE;
401
401
  }
402
402
  return CK_TRUE;
413
413
  CK_RV *pError
414
414
)
415
415
{
416
 
  if ( (void *)NULL == (void *)fwMechanism->mdMechanism->WrapKey) {
 
416
  if (!fwMechanism->mdMechanism->WrapKey) {
417
417
    return CK_FALSE;
418
418
  }
419
419
  return CK_TRUE;
430
430
  CK_RV *pError
431
431
)
432
432
{
433
 
  if ( (void *)NULL == (void *)fwMechanism->mdMechanism->DeriveKey) {
 
433
  if (!fwMechanism->mdMechanism->DeriveKey) {
434
434
    return CK_FALSE;
435
435
  }
436
436
  return CK_TRUE;
462
462
 
463
463
  fwOperation = nssCKFWSession_GetCurrentCryptoOperation(fwSession, 
464
464
                        NSSCKFWCryptoOperationState_EncryptDecrypt);
465
 
  if ((NSSCKFWCryptoOperation *)NULL != fwOperation) {
 
465
  if (fwOperation) {
466
466
    return CKR_OPERATION_ACTIVE;
467
467
  }
468
468
 
469
 
  if ( (void *)NULL == (void *)fwMechanism->mdMechanism->EncryptInit) {
 
469
  if (!fwMechanism->mdMechanism->EncryptInit) {
470
470
    return CKR_FUNCTION_FAILED;
471
471
  }
472
472
 
486
486
        fwObject,
487
487
        &error
488
488
  );
489
 
  if ((NSSCKMDCryptoOperation *)NULL == mdOperation) {
 
489
  if (!mdOperation) {
490
490
    goto loser;
491
491
  }
492
492
 
494
494
        mdSession, fwSession, fwMechanism->mdToken, fwMechanism->fwToken,
495
495
        fwMechanism->mdInstance, fwMechanism->fwInstance,
496
496
        NSSCKFWCryptoOperationType_Encrypt, &error);
497
 
  if ((NSSCKFWCryptoOperation *)NULL != fwOperation) {
 
497
  if (fwOperation) {
498
498
    nssCKFWSession_SetCurrentCryptoOperation(fwSession, fwOperation,
499
499
                NSSCKFWCryptoOperationState_EncryptDecrypt);
500
500
  }
525
525
 
526
526
  fwOperation = nssCKFWSession_GetCurrentCryptoOperation(fwSession, 
527
527
                        NSSCKFWCryptoOperationState_EncryptDecrypt);
528
 
  if ((NSSCKFWCryptoOperation *)NULL != fwOperation) {
 
528
  if (fwOperation) {
529
529
    return CKR_OPERATION_ACTIVE;
530
530
  }
531
531
 
532
 
  if ( (void *)NULL == (void *)fwMechanism->mdMechanism->DecryptInit) {
 
532
  if (!fwMechanism->mdMechanism->DecryptInit) {
533
533
    return CKR_FUNCTION_FAILED;
534
534
  }
535
535
 
549
549
        fwObject,
550
550
        &error
551
551
  );
552
 
  if ((NSSCKMDCryptoOperation *)NULL == mdOperation) {
 
552
  if (!mdOperation) {
553
553
    goto loser;
554
554
  }
555
555
 
557
557
        mdSession, fwSession, fwMechanism->mdToken, fwMechanism->fwToken,
558
558
        fwMechanism->mdInstance, fwMechanism->fwInstance,
559
559
        NSSCKFWCryptoOperationType_Decrypt, &error);
560
 
  if ((NSSCKFWCryptoOperation *)NULL != fwOperation) {
 
560
  if (fwOperation) {
561
561
    nssCKFWSession_SetCurrentCryptoOperation(fwSession, fwOperation,
562
562
                NSSCKFWCryptoOperationState_EncryptDecrypt);
563
563
  }
586
586
 
587
587
  fwOperation = nssCKFWSession_GetCurrentCryptoOperation(fwSession, 
588
588
                        NSSCKFWCryptoOperationState_Digest);
589
 
  if ((NSSCKFWCryptoOperation *)NULL != fwOperation) {
 
589
  if (fwOperation) {
590
590
    return CKR_OPERATION_ACTIVE;
591
591
  }
592
592
 
593
 
  if ( (void *)NULL == (void *)fwMechanism->mdMechanism->DigestInit) {
 
593
  if (!fwMechanism->mdMechanism->DigestInit) {
594
594
    return CKR_FUNCTION_FAILED;
595
595
  }
596
596
 
607
607
        fwMechanism->fwInstance,
608
608
        &error
609
609
  );
610
 
  if ((NSSCKMDCryptoOperation *)NULL == mdOperation) {
 
610
  if (!mdOperation) {
611
611
    goto loser;
612
612
  }
613
613
 
615
615
        mdSession, fwSession, fwMechanism->mdToken, fwMechanism->fwToken,
616
616
        fwMechanism->mdInstance, fwMechanism->fwInstance,
617
617
        NSSCKFWCryptoOperationType_Digest, &error);
618
 
  if ((NSSCKFWCryptoOperation *)NULL != fwOperation) {
 
618
  if (fwOperation) {
619
619
    nssCKFWSession_SetCurrentCryptoOperation(fwSession, fwOperation,
620
620
                NSSCKFWCryptoOperationState_Digest);
621
621
  }
646
646
 
647
647
  fwOperation = nssCKFWSession_GetCurrentCryptoOperation(fwSession, 
648
648
                        NSSCKFWCryptoOperationState_SignVerify);
649
 
  if ((NSSCKFWCryptoOperation *)NULL != fwOperation) {
 
649
  if (fwOperation) {
650
650
    return CKR_OPERATION_ACTIVE;
651
651
  }
652
652
 
653
 
  if ( (void *)NULL == (void *)fwMechanism->mdMechanism->SignInit) {
 
653
  if (!fwMechanism->mdMechanism->SignInit) {
654
654
    return CKR_FUNCTION_FAILED;
655
655
  }
656
656
 
670
670
        fwObject,
671
671
        &error
672
672
  );
673
 
  if ((NSSCKMDCryptoOperation *)NULL == mdOperation) {
 
673
  if (!mdOperation) {
674
674
    goto loser;
675
675
  }
676
676
 
678
678
        mdSession, fwSession, fwMechanism->mdToken, fwMechanism->fwToken,
679
679
        fwMechanism->mdInstance, fwMechanism->fwInstance,
680
680
        NSSCKFWCryptoOperationType_Sign, &error);
681
 
  if ((NSSCKFWCryptoOperation *)NULL != fwOperation) {
 
681
  if (fwOperation) {
682
682
    nssCKFWSession_SetCurrentCryptoOperation(fwSession, fwOperation,
683
683
                NSSCKFWCryptoOperationState_SignVerify);
684
684
  }
709
709
 
710
710
  fwOperation = nssCKFWSession_GetCurrentCryptoOperation(fwSession, 
711
711
                        NSSCKFWCryptoOperationState_SignVerify);
712
 
  if ((NSSCKFWCryptoOperation *)NULL != fwOperation) {
 
712
  if (fwOperation) {
713
713
    return CKR_OPERATION_ACTIVE;
714
714
  }
715
715
 
716
 
  if ( (void *)NULL == (void *)fwMechanism->mdMechanism->VerifyInit) {
 
716
  if (!fwMechanism->mdMechanism->VerifyInit) {
717
717
    return CKR_FUNCTION_FAILED;
718
718
  }
719
719
 
733
733
        fwObject,
734
734
        &error
735
735
  );
736
 
  if ((NSSCKMDCryptoOperation *)NULL == mdOperation) {
 
736
  if (!mdOperation) {
737
737
    goto loser;
738
738
  }
739
739
 
741
741
        mdSession, fwSession, fwMechanism->mdToken, fwMechanism->fwToken,
742
742
        fwMechanism->mdInstance, fwMechanism->fwInstance,
743
743
        NSSCKFWCryptoOperationType_Verify, &error);
744
 
  if ((NSSCKFWCryptoOperation *)NULL != fwOperation) {
 
744
  if (fwOperation) {
745
745
    nssCKFWSession_SetCurrentCryptoOperation(fwSession, fwOperation,
746
746
                NSSCKFWCryptoOperationState_SignVerify);
747
747
  }
772
772
 
773
773
  fwOperation = nssCKFWSession_GetCurrentCryptoOperation(fwSession, 
774
774
                        NSSCKFWCryptoOperationState_SignVerify);
775
 
  if ((NSSCKFWCryptoOperation *)NULL != fwOperation) {
 
775
  if (fwOperation) {
776
776
    return CKR_OPERATION_ACTIVE;
777
777
  }
778
778
 
779
 
  if ( (void *)NULL == (void *)fwMechanism->mdMechanism->SignRecoverInit) {
 
779
  if (!fwMechanism->mdMechanism->SignRecoverInit) {
780
780
    return CKR_FUNCTION_FAILED;
781
781
  }
782
782
 
796
796
        fwObject,
797
797
        &error
798
798
  );
799
 
  if ((NSSCKMDCryptoOperation *)NULL == mdOperation) {
 
799
  if (!mdOperation) {
800
800
    goto loser;
801
801
  }
802
802
 
804
804
        mdSession, fwSession, fwMechanism->mdToken, fwMechanism->fwToken,
805
805
        fwMechanism->mdInstance, fwMechanism->fwInstance,
806
806
        NSSCKFWCryptoOperationType_SignRecover, &error);
807
 
  if ((NSSCKFWCryptoOperation *)NULL != fwOperation) {
 
807
  if (fwOperation) {
808
808
    nssCKFWSession_SetCurrentCryptoOperation(fwSession, fwOperation,
809
809
                NSSCKFWCryptoOperationState_SignVerify);
810
810
  }
835
835
 
836
836
  fwOperation = nssCKFWSession_GetCurrentCryptoOperation(fwSession, 
837
837
                        NSSCKFWCryptoOperationState_SignVerify);
838
 
  if ((NSSCKFWCryptoOperation *)NULL != fwOperation) {
 
838
  if (fwOperation) {
839
839
    return CKR_OPERATION_ACTIVE;
840
840
  }
841
841
 
842
 
  if ( (void *)NULL == (void *)fwMechanism->mdMechanism->VerifyRecoverInit) {
 
842
  if (!fwMechanism->mdMechanism->VerifyRecoverInit) {
843
843
    return CKR_FUNCTION_FAILED;
844
844
  }
845
845
 
859
859
        fwObject,
860
860
        &error
861
861
  );
862
 
  if ((NSSCKMDCryptoOperation *)NULL == mdOperation) {
 
862
  if (!mdOperation) {
863
863
    goto loser;
864
864
  }
865
865
 
867
867
        mdSession, fwSession, fwMechanism->mdToken, fwMechanism->fwToken,
868
868
        fwMechanism->mdInstance, fwMechanism->fwInstance,
869
869
        NSSCKFWCryptoOperationType_VerifyRecover, &error);
870
 
  if ((NSSCKFWCryptoOperation *)NULL != fwOperation) {
 
870
  if (fwOperation) {
871
871
    nssCKFWSession_SetCurrentCryptoOperation(fwSession, fwOperation,
872
872
                NSSCKFWCryptoOperationState_SignVerify);
873
873
  }
895
895
  NSSCKFWObject  *fwObject = NULL;
896
896
  NSSArena       *arena;
897
897
 
898
 
  if ( (void *)NULL == (void *)fwMechanism->mdMechanism->GenerateKey) {
 
898
  if (!fwMechanism->mdMechanism->GenerateKey) {
899
899
    *pError = CKR_FUNCTION_FAILED;
900
900
    return (NSSCKFWObject *)NULL;
901
901
  }
902
902
 
903
903
  arena = nssCKFWToken_GetArena(fwMechanism->fwToken, pError);
904
 
  if ((NSSArena *)NULL == arena) {
 
904
  if (!arena) {
905
905
    if (CKR_OK == *pError) {
906
906
      *pError = CKR_GENERAL_ERROR;
907
907
    }
923
923
        ulAttributeCount,
924
924
        pError);
925
925
 
926
 
  if ((NSSCKMDObject *)NULL == mdObject) {
 
926
  if (!mdObject) {
927
927
    return (NSSCKFWObject *)NULL;
928
928
  }
929
929
 
956
956
  NSSArena       *arena;
957
957
  CK_RV         error = CKR_OK;
958
958
 
959
 
  if ( (void *)NULL == (void *)fwMechanism->mdMechanism->GenerateKey) {
 
959
  if (!fwMechanism->mdMechanism->GenerateKey) {
960
960
    return CKR_FUNCTION_FAILED;
961
961
  }
962
962
 
963
963
  arena = nssCKFWToken_GetArena(fwMechanism->fwToken, &error);
964
 
  if ((NSSArena *)NULL == arena) {
 
964
  if (!arena) {
965
965
    if (CKR_OK == error) {
966
966
      error = CKR_GENERAL_ERROR;
967
967
    }
992
992
 
993
993
  *fwPublicKeyObject = nssCKFWObject_Create(arena, mdPublicKeyObject, 
994
994
        fwSession, fwMechanism->fwToken, fwMechanism->fwInstance, &error);
995
 
  if ((NSSCKFWObject *)NULL == *fwPublicKeyObject) {
 
995
  if (!*fwPublicKeyObject) {
996
996
    return error;
997
997
  }
998
998
  *fwPrivateKeyObject = nssCKFWObject_Create(arena, mdPrivateKeyObject, 
1019
1019
  NSSCKMDObject  *mdWrappingKeyObject;
1020
1020
  NSSCKMDObject  *mdKeyObject;
1021
1021
 
1022
 
  if ( (void *)NULL == (void *)fwMechanism->mdMechanism->WrapKey) {
 
1022
  if (!fwMechanism->mdMechanism->WrapKey) {
1023
1023
    *pError = CKR_FUNCTION_FAILED;
1024
1024
    return (CK_ULONG) 0;
1025
1025
  }
1062
1062
  NSSCKMDObject  *mdWrappingKeyObject;
1063
1063
  NSSCKMDObject  *mdKeyObject;
1064
1064
 
1065
 
  if ( (void *)NULL == (void *)fwMechanism->mdMechanism->WrapKey) {
 
1065
  if (!fwMechanism->mdMechanism->WrapKey) {
1066
1066
    return CKR_FUNCTION_FAILED;
1067
1067
  }
1068
1068
 
1108
1108
  NSSCKFWObject  *fwObject = NULL;
1109
1109
  NSSArena       *arena;
1110
1110
 
1111
 
  if ( (void *)NULL == (void *)fwMechanism->mdMechanism->UnwrapKey) {
 
1111
  if (!fwMechanism->mdMechanism->UnwrapKey) {
1112
1112
    /* we could simulate UnwrapKey using Decrypt and Create object, but
1113
1113
     * 1) it's not clear that would work well, and 2) the low level token
1114
1114
     * may want to restrict unwrap key for a reason, so just fail it it
1118
1118
  }
1119
1119
 
1120
1120
  arena = nssCKFWToken_GetArena(fwMechanism->fwToken, pError);
1121
 
  if ((NSSArena *)NULL == arena) {
 
1121
  if (!arena) {
1122
1122
    if (CKR_OK == *pError) {
1123
1123
      *pError = CKR_GENERAL_ERROR;
1124
1124
    }
1144
1144
        ulAttributeCount,
1145
1145
        pError);
1146
1146
 
1147
 
  if ((NSSCKMDObject *)NULL == mdObject) {
 
1147
  if (!mdObject) {
1148
1148
    return (NSSCKFWObject *)NULL;
1149
1149
  }
1150
1150
 
1175
1175
  NSSCKFWObject  *fwObject = NULL;
1176
1176
  NSSArena       *arena;
1177
1177
 
1178
 
  if ( (void *)NULL == (void *)fwMechanism->mdMechanism->DeriveKey) {
 
1178
  if (!fwMechanism->mdMechanism->DeriveKey) {
1179
1179
    *pError = CKR_FUNCTION_FAILED;
1180
1180
    return (NSSCKFWObject *)NULL;
1181
1181
  }
1182
1182
 
1183
1183
  arena = nssCKFWToken_GetArena(fwMechanism->fwToken, pError);
1184
 
  if ((NSSArena *)NULL == arena) {
 
1184
  if (!arena) {
1185
1185
    if (CKR_OK == *pError) {
1186
1186
      *pError = CKR_GENERAL_ERROR;
1187
1187
    }
1206
1206
        ulAttributeCount,
1207
1207
        pError);
1208
1208
 
1209
 
  if ((NSSCKMDObject *)NULL == mdObject) {
 
1209
  if (!mdObject) {
1210
1210
    return (NSSCKFWObject *)NULL;
1211
1211
  }
1212
1212