mozilla/ security/ nss/ lib/ softoken/ pkcs11c.c

old:
757             /* encrypt the current padded data */
758             rv = (*context->update)(context->cipherInfo,pEncryptedPart,
759
&outlen,context->blockSize,context->padBuf,context->blockSize);

may be:

757             /* encrypt the current padded data */
758             rv = (*context->update)(context->cipherInfo,pEncryptedPart,
759
&padoutlen,context->blockSize,context->padBuf,context->blockSize);



723
724 /* NSC_EncryptUpdate continues a multiple-part encryption operation. */
725 CK_RV NSC_EncryptUpdate(CK_SESSION_HANDLE hSession,
726     CK_BYTE_PTR pPart, CK_ULONG ulPartLen, CK_BYTE_PTR pEncryptedPart,
727                                         CK_ULONG_PTR
pulEncryptedPartLen)
728 {
729     PK11SessionContext *context;
730     unsigned int outlen,i;
731     unsigned int padoutlen = 0;
732     unsigned int maxout = *pulEncryptedPartLen;
733     CK_RV crv;
734     SECStatus rv;
735
736     /* make sure we're legal */
737     crv = pk11_GetContext(hSession,&context,PK11_ENCRYPT,PR_TRUE,NULL);
738     if (crv != CKR_OK) return crv;
739
740     /* do padding */
741     if (context->doPad) {
742         /* deal with previous buffered data */
743         if (context->padDataLength != 0) {
744             /* fill in the padded to a full block size */
745             for (i=context->padDataLength;
746                         (ulPartLen != 0) && i < context->blockSize; i++)
{
747                 context->padBuf[i] = *pPart++;
748                 ulPartLen--;
749                 context->padDataLength++;
750             }
751
752             /* not enough data to encrypt yet? then return */
753             if (context->padDataLength != context->blockSize) {
754                 *pulEncryptedPartLen = 0;
755                 return CKR_OK;
756             }
757             /* encrypt the current padded data */
758             rv = (*context->update)(context->cipherInfo,pEncryptedPart,
759
&outlen,context->blockSize,context->padBuf,context->blockSize);
760             if (rv != SECSuccess) return CKR_DEVICE_ERROR;
761             pEncryptedPart += padoutlen;
762             maxout -= padoutlen;
763         }
764         /* save the residual */
765         context->padDataLength = ulPartLen % context->blockSize;
766         if (context->padDataLength) {
767             PORT_Memcpy(context->padBuf,
768                         &pPart[ulPartLen-context->padDataLength],
769
context->padDataLength);
770             ulPartLen -= context->padDataLength;
771         }
772         /* if we've exhausted our new buffer, we're done */
773         if (ulPartLen == 0) {
774             *pulEncryptedPartLen = padoutlen;
775             return CKR_OK;
776         }
777     }
778
779
780
781     /* do it: NOTE: this assumes buf size in is >= buf size out! */
782     rv = (*context->update)(context->cipherInfo,pEncryptedPart,
783                                         &outlen, maxout, pPart,
ulPartLen);
784     *pulEncryptedPartLen = (CK_ULONG) (outlen + padoutlen);
785     return (rv == SECSuccess) ? CKR_OK : CKR_DEVICE_ERROR;
786 }
787




Reply via email to