Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Functions
tlsprf.c File Reference
#include "pkcs11i.h"
#include "blapi.h"

Go to the source code of this file.

Classes

struct  TLSPRFContext

Defines

#define SFTK_OFFSETOF(str, memb)   ((PRPtrdiff)(&(((str *)0)->memb)))

Functions

static void sftk_TLSPRFNull (void *data, PRBool freeit)
static void sftk_TLSPRFHashUpdate (TLSPRFContext *cx, const unsigned char *data, unsigned int data_len)
static void sftk_TLSPRFEnd (TLSPRFContext *ctx, unsigned char *hashout, unsigned int *pDigestLen, unsigned int maxDigestLen)
static SECStatus sftk_TLSPRFUpdate (TLSPRFContext *cx, unsigned char *sig, unsigned int *sigLen, unsigned int maxLen, unsigned char *hash, unsigned int hashLen)
static SECStatus sftk_TLSPRFVerify (TLSPRFContext *cx, unsigned char *sig, unsigned int sigLen, unsigned char *hash, unsigned int hashLen)
static void sftk_TLSPRFHashDestroy (TLSPRFContext *cx, PRBool freeit)
CK_RV sftk_TLSPRFInit (SFTKSessionContext *context, SFTKObject *key, CK_KEY_TYPE key_type)

Class Documentation

struct TLSPRFContext

Definition at line 50 of file tlsprf.c.

Class Members
unsigned char cxBuf
unsigned char * cxBufPtr
PRUint32 cxBufSize
PRUint32 cxDataLen
PRBool cxIsFIPS
PRUint32 cxKeyLen
SECStatus cxRv
PRUint32 cxSize

Define Documentation

#define SFTK_OFFSETOF (   str,
  memb 
)    ((PRPtrdiff)(&(((str *)0)->memb)))

Definition at line 43 of file tlsprf.c.


Function Documentation

static void sftk_TLSPRFEnd ( TLSPRFContext ctx,
unsigned char *  hashout,
unsigned int pDigestLen,
unsigned int  maxDigestLen 
) [static]

Definition at line 92 of file tlsprf.c.

{
    *pDigestLen = 0; /* tells Verify that no data has been input yet. */
}

Here is the caller graph for this function:

static void sftk_TLSPRFHashDestroy ( TLSPRFContext cx,
PRBool  freeit 
) [static]

Definition at line 159 of file tlsprf.c.

{
    if (freeit) {
       if (cx->cxBufPtr != cx->cxBuf) 
           PORT_ZFree(cx->cxBufPtr, cx->cxBufSize);
       PORT_ZFree(cx, cx->cxSize);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void sftk_TLSPRFHashUpdate ( TLSPRFContext cx,
const unsigned char *  data,
unsigned int  data_len 
) [static]

Definition at line 62 of file tlsprf.c.

{
    PRUint32 bytesUsed = cx->cxKeyLen + cx->cxDataLen;

    if (cx->cxRv != SECSuccess)    /* function has previously failed. */
       return;
    if (bytesUsed + data_len > cx->cxBufSize) {
       /* We don't use realloc here because 
       ** (a) realloc doesn't zero out the old block, and 
       ** (b) if realloc fails, we lose the old block.
       */
       PRUint32 newBufSize = bytesUsed + data_len + 512;
       unsigned char * newBuf = (unsigned char *)PORT_Alloc(newBufSize);
       if (!newBuf) {
          cx->cxRv = SECFailure;
          return;
       }
       PORT_Memcpy(newBuf, cx->cxBufPtr, bytesUsed);
       if (cx->cxBufPtr != cx->cxBuf) {
           PORT_ZFree(cx->cxBufPtr, bytesUsed);
       }
       cx->cxBufPtr  = newBuf;
       cx->cxBufSize = newBufSize;
    }
    PORT_Memcpy(cx->cxBufPtr + bytesUsed, data, data_len);
    cx->cxDataLen += data_len;
}

Here is the call graph for this function:

Here is the caller graph for this function:

CK_RV sftk_TLSPRFInit ( SFTKSessionContext *  context,
SFTKObject *  key,
CK_KEY_TYPE  key_type 
)

Definition at line 169 of file tlsprf.c.

{
    SFTKAttribute * keyVal;
    TLSPRFContext * prf_cx;
    CK_RV           crv = CKR_HOST_MEMORY;
    PRUint32        keySize;
    PRUint32        blockSize;

    if (key_type != CKK_GENERIC_SECRET)
       return CKR_KEY_TYPE_INCONSISTENT; /* CKR_KEY_FUNCTION_NOT_PERMITTED */

    context->multi = PR_TRUE;

    keyVal = sftk_FindAttribute(key, CKA_VALUE);
    keySize = (!keyVal) ? 0 : keyVal->attrib.ulValueLen;
    blockSize = keySize + sizeof(TLSPRFContext);
    prf_cx = (TLSPRFContext *)PORT_Alloc(blockSize);
    if (!prf_cx) 
       goto done;
    prf_cx->cxSize    = blockSize;
    prf_cx->cxKeyLen  = keySize;
    prf_cx->cxDataLen = 0;
    prf_cx->cxBufSize = blockSize - SFTK_OFFSETOF(TLSPRFContext, cxBuf);
    prf_cx->cxRv      = SECSuccess;
    prf_cx->cxIsFIPS  = (key->slot->slotID == FIPS_SLOT_ID);
    prf_cx->cxBufPtr  = prf_cx->cxBuf;
    if (keySize)
       PORT_Memcpy(prf_cx->cxBufPtr, keyVal->attrib.pValue, keySize);

    context->hashInfo    = (void *) prf_cx;
    context->cipherInfo  = (void *) prf_cx;
    context->hashUpdate  = (SFTKHash)    sftk_TLSPRFHashUpdate;
    context->end         = (SFTKEnd)     sftk_TLSPRFEnd;
    context->update      = (SFTKCipher)  sftk_TLSPRFUpdate;
    context->verify      = (SFTKVerify)  sftk_TLSPRFVerify;
    context->destroy     = (SFTKDestroy) sftk_TLSPRFNull;
    context->hashdestroy = (SFTKDestroy) sftk_TLSPRFHashDestroy;
    crv = CKR_OK;

done:
    if (keyVal) 
       sftk_FreeAttribute(keyVal);
    return crv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void sftk_TLSPRFNull ( void data,
PRBool  freeit 
) [static]

Definition at line 45 of file tlsprf.c.

{
    return;
} 

Here is the caller graph for this function:

static SECStatus sftk_TLSPRFUpdate ( TLSPRFContext cx,
unsigned char *  sig,
unsigned int sigLen,
unsigned int  maxLen,
unsigned char *  hash,
unsigned int  hashLen 
) [static]

Definition at line 100 of file tlsprf.c.

{
    SECStatus rv;
    SECItem sigItem;
    SECItem seedItem;
    SECItem secretItem;

    if (cx->cxRv != SECSuccess)
       return cx->cxRv;

    secretItem.data = cx->cxBufPtr;
    secretItem.len  = cx->cxKeyLen;

    seedItem.data = cx->cxBufPtr + cx->cxKeyLen;
    seedItem.len  = cx->cxDataLen;

    sigItem.data = sig;
    sigItem.len  = maxLen;

    rv = TLS_PRF(&secretItem, NULL, &seedItem, &sigItem, cx->cxIsFIPS);
    if (rv == SECSuccess && sigLen != NULL)
       *sigLen = sigItem.len;
    return rv;

}

Here is the call graph for this function:

Here is the caller graph for this function:

static SECStatus sftk_TLSPRFVerify ( TLSPRFContext cx,
unsigned char *  sig,
unsigned int  sigLen,
unsigned char *  hash,
unsigned int  hashLen 
) [static]

Definition at line 132 of file tlsprf.c.

{
    unsigned char * tmp    = (unsigned char *)PORT_Alloc(sigLen);
    unsigned int    tmpLen = sigLen;
    SECStatus       rv;

    if (!tmp)
       return SECFailure;
    if (hashLen) {
       /* hashLen is non-zero when the user does a one-step verify.
       ** In this case, none of the data has been input yet.
       */
       sftk_TLSPRFHashUpdate(cx, hash, hashLen);
    }
    rv = sftk_TLSPRFUpdate(cx, tmp, &tmpLen, sigLen, NULL, 0);
    if (rv == SECSuccess) {
       rv = (SECStatus)(1 - !PORT_Memcmp(tmp, sig, sigLen));
    }
    PORT_ZFree(tmp, sigLen);
    return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function: