本文整理汇总了C++中PK11_DestroyContext函数的典型用法代码示例。如果您正苦于以下问题:C++ PK11_DestroyContext函数的具体用法?C++ PK11_DestroyContext怎么用?C++ PK11_DestroyContext使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PK11_DestroyContext函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: sec_pkcs12_generate_mac
/* MAC is generated per PKCS 12 section 6. It is expected that key, msg
* and mac_dest are pre allocated, non-NULL arrays. msg_len is passed in
* because it is not known how long the message actually is. String
* manipulation routines will not necessarily work because msg may have
* imbedded NULLs
*/
SECItem *
sec_pkcs12_generate_mac(SECItem *key,
SECItem *msg,
PRBool old_method)
{
SECStatus res = SECFailure;
SECItem *mac = NULL;
PK11Context *pk11cx = NULL;
SECItem ignore = {0};
if((key == NULL) || (msg == NULL)) {
return NULL;
}
if(old_method == PR_TRUE) {
return sec_pkcs12_generate_old_mac(key, msg);
}
/* allocate return item */
mac = SECITEM_AllocItem(NULL, NULL, SHA1_LENGTH);
if (mac == NULL) {
return NULL;
}
pk11cx = PK11_CreateContextByRawKey(NULL, CKM_SHA_1_HMAC, PK11_OriginDerive,
CKA_SIGN, key, &ignore, NULL);
if (pk11cx == NULL) {
goto loser;
}
res = PK11_DigestBegin(pk11cx);
if (res == SECFailure) {
goto loser;
}
res = PK11_DigestOp(pk11cx, msg->data, msg->len);
if (res == SECFailure) {
goto loser;
}
res = PK11_DigestFinal(pk11cx, mac->data, &mac->len, SHA1_LENGTH);
if (res == SECFailure) {
goto loser;
}
PK11_DestroyContext(pk11cx, PR_TRUE);
pk11cx = NULL;
loser:
if(res != SECSuccess) {
SECITEM_ZfreeItem(mac, PR_TRUE);
mac = NULL;
if (pk11cx) {
PK11_DestroyContext(pk11cx, PR_TRUE);
}
}
return mac;
}
开发者ID:Anachid,项目名称:mozilla-central,代码行数:66,代码来源:p12local.c
示例2: hmac_final
void hmac_final(u_char *output, struct hmac_ctx *ctx)
{
unsigned int outlen = 0;
SECStatus status = PK11_DigestFinal(ctx->ctx_nss, output, &outlen,
ctx->hmac_digest_len);
PR_ASSERT(status == SECSuccess);
PR_ASSERT(outlen == ctx->hmac_digest_len);
PK11_DestroyContext(ctx->ctx_nss, PR_TRUE);
ctx->ctx_nss = NULL;
ctx->ctx_nss = PK11_CreateDigestContext(nss_hash_oid(ctx->h));
PR_ASSERT(ctx->ctx_nss != NULL);
status = PK11_DigestBegin(ctx->ctx_nss);
PR_ASSERT(status == SECSuccess);
status = PK11_DigestKey(ctx->ctx_nss, ctx->okey);
PR_ASSERT(status == SECSuccess);
status = PK11_DigestOp(ctx->ctx_nss, output, outlen);
PR_ASSERT(status == SECSuccess);
status = PK11_DigestFinal(ctx->ctx_nss, output, &outlen,
ctx->hmac_digest_len);
PR_ASSERT(status == SECSuccess);
PR_ASSERT(outlen == ctx->hmac_digest_len);
PK11_DestroyContext(ctx->ctx_nss, PR_TRUE);
if (ctx->ikey != NULL)
PK11_FreeSymKey(ctx->ikey);
if (ctx->okey != NULL)
PK11_FreeSymKey(ctx->okey);
/* DBG(DBG_CRYPT, DBG_log("NSS: hmac final end")); */
}
开发者ID:jgimenez,项目名称:libreswan,代码行数:35,代码来源:hmac.c
示例3: PK11_CloneContext
/*
* create a new context which is the clone of the state of old context.
*/
PK11Context *
PK11_CloneContext(PK11Context *old)
{
PK11Context *newcx;
PRBool needFree = PR_FALSE;
SECStatus rv = SECSuccess;
void *data;
unsigned long len;
newcx = pk11_CreateNewContextInSlot(old->type, old->slot, old->operation,
old->key, old->param);
if (newcx == NULL)
return NULL;
/* now clone the save state. First we need to find the save state
* of the old session. If the old context owns it's session,
* the state needs to be saved, otherwise the state is in saveData. */
if (old->ownSession) {
PK11_EnterContextMonitor(old);
data = pk11_saveContext(old, NULL, &len);
PK11_ExitContextMonitor(old);
needFree = PR_TRUE;
} else {
data = old->savedData;
len = old->savedLength;
}
if (data == NULL) {
PK11_DestroyContext(newcx, PR_TRUE);
return NULL;
}
/* now copy that state into our new context. Again we have different
* work if the new context owns it's own session. If it does, we
* restore the state gathered above. If it doesn't, we copy the
* saveData pointer... */
if (newcx->ownSession) {
PK11_EnterContextMonitor(newcx);
rv = pk11_restoreContext(newcx, data, len);
PK11_ExitContextMonitor(newcx);
} else {
PORT_Assert(newcx->savedData != NULL);
if ((newcx->savedData == NULL) || (newcx->savedLength < len)) {
PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
rv = SECFailure;
} else {
PORT_Memcpy(newcx->savedData, data, len);
newcx->savedLength = len;
}
}
if (needFree)
PORT_Free(data);
if (rv != SECSuccess) {
PK11_DestroyContext(newcx, PR_TRUE);
return NULL;
}
return newcx;
}
开发者ID:Wafflespeanut,项目名称:gecko-dev,代码行数:63,代码来源:pk11cxt.c
示例4: JAR_digest_file
/*
* J A R _ d i g e s t _ f i l e
*
* Calculates the MD5 and SHA1 digests for a file
* present on disk, and returns these in JAR_Digest struct.
*
*/
int
JAR_digest_file (char *filename, JAR_Digest *dig)
{
JAR_FILE fp;
PK11Context *md5 = 0;
PK11Context *sha1 = 0;
unsigned char *buf = (unsigned char *) PORT_ZAlloc (FILECHUNQ);
int num;
unsigned int md5_length, sha1_length;
if (buf == NULL) {
/* out of memory */
return JAR_ERR_MEMORY;
}
if ((fp = JAR_FOPEN (filename, "rb")) == 0) {
/* perror (filename); FIX XXX XXX XXX XXX XXX XXX */
PORT_Free (buf);
return JAR_ERR_FNF;
}
md5 = PK11_CreateDigestContext (SEC_OID_MD5);
sha1 = PK11_CreateDigestContext (SEC_OID_SHA1);
if (md5 == NULL || sha1 == NULL) {
/* can't generate digest contexts */
PORT_Free (buf);
JAR_FCLOSE (fp);
return JAR_ERR_GENERAL;
}
PK11_DigestBegin (md5);
PK11_DigestBegin (sha1);
while (1) {
if ((num = JAR_FREAD (fp, buf, FILECHUNQ)) == 0)
break;
PK11_DigestOp (md5, buf, num);
PK11_DigestOp (sha1, buf, num);
}
PK11_DigestFinal (md5, dig->md5, &md5_length, MD5_LENGTH);
PK11_DigestFinal (sha1, dig->sha1, &sha1_length, SHA1_LENGTH);
PK11_DestroyContext (md5, PR_TRUE);
PK11_DestroyContext (sha1, PR_TRUE);
PORT_Free (buf);
JAR_FCLOSE (fp);
return 0;
}
开发者ID:AOSC-Dev,项目名称:nss-purified,代码行数:60,代码来源:jarsign.c
示例5: DigestFile
static int
DigestFile(FILE *outFile, FILE *inFile, SECOidData *hashOID)
{
int nb;
unsigned char ibuf[4096], digest[32];
PK11Context *hashcx;
unsigned int len;
SECStatus rv;
hashcx = PK11_CreateDigestContext(hashOID->offset);
if (hashcx == NULL) {
return -1;
}
PK11_DigestBegin(hashcx);
for (;;) {
if (feof(inFile)) break;
nb = fread(ibuf, 1, sizeof(ibuf), inFile);
if (nb != sizeof(ibuf)) {
if (nb == 0) {
if (ferror(inFile)) {
PORT_SetError(SEC_ERROR_IO);
PK11_DestroyContext(hashcx,PR_TRUE);
return -1;
}
/* eof */
break;
}
}
rv = PK11_DigestOp(hashcx, ibuf, nb);
if (rv != SECSuccess) {
PK11_DestroyContext(hashcx, PR_TRUE);
return -1;
}
}
rv = PK11_DigestFinal(hashcx, digest, &len, 32);
PK11_DestroyContext(hashcx, PR_TRUE);
if (rv != SECSuccess) return -1;
nb = fwrite(digest, 1, len, outFile);
if (nb != len) {
PORT_SetError(SEC_ERROR_IO);
return -1;
}
return 0;
}
开发者ID:AOSC-Dev,项目名称:nss-purified,代码行数:50,代码来源:digest.c
示例6: PK11_DestroyContext
void
nsCryptoHMAC::destructorSafeDestroyNSSReference()
{
if (mHMACContext)
PK11_DestroyContext(mHMACContext, true);
mHMACContext = nullptr;
}
开发者ID:Andrel322,项目名称:gecko-dev,代码行数:7,代码来源:nsCryptoHash.cpp
示例7: sha512_result
void inline sha512_result(sha512_context *ctx, u_int8_t * hash, int hashlen) {
unsigned int len;
SECStatus s = PK11_DigestFinal(ctx->ctx_nss, hash, &len, hashlen);
PR_ASSERT(len==hashlen);
PR_ASSERT(s==SECSuccess);
PK11_DestroyContext(ctx->ctx_nss, PR_TRUE);
}
开发者ID:st3fan,项目名称:libreswan,代码行数:7,代码来源:hmac_sha2.c
示例8: oauth_init_nss
char *oauth_body_hash_data(size_t length, const char *data) {
PK11SlotInfo *slot = NULL;
PK11Context *context = NULL;
unsigned char digest[20]; // Is there a way to tell how large the output is?
unsigned int len;
SECStatus s;
char *rv=NULL;
oauth_init_nss();
slot = PK11_GetInternalKeySlot();
if (!slot) goto looser;
context = PK11_CreateDigestContext(SEC_OID_SHA1);
if (!context) goto looser;
s = PK11_DigestBegin(context);
if (s != SECSuccess) goto looser;
s = PK11_DigestOp(context, (unsigned char*) data, length);
if (s != SECSuccess) goto looser;
s = PK11_DigestFinal(context, digest, &len, sizeof digest);
if (s != SECSuccess) goto looser;
unsigned char *dgst = xmalloc(len*sizeof(char)); // oauth_body_hash_encode frees the digest..
memcpy(dgst, digest, len);
rv=oauth_body_hash_encode(len, dgst);
looser:
if (context) PK11_DestroyContext(context, PR_TRUE);
if (slot) PK11_FreeSlot(slot);
return rv;
}
开发者ID:Aakanksha,项目名称:c-twitter,代码行数:31,代码来源:hash.c
示例9: nss_hash_init
static int nss_hash_init(void **pctx, SECOidTag hash_alg)
{
PK11Context *ctx;
/* we have to initialize NSS if not initialized alraedy */
#ifdef HAVE_NSS_INITCONTEXT
if(!NSS_IsInitialized() && !nss_context) {
static NSSInitParameters params;
params.length = sizeof params;
nss_context = NSS_InitContext("", "", "", "", ¶ms, NSS_INIT_READONLY
| NSS_INIT_NOCERTDB | NSS_INIT_NOMODDB | NSS_INIT_FORCEOPEN
| NSS_INIT_NOROOTINIT | NSS_INIT_OPTIMIZESPACE | NSS_INIT_PK11RELOAD);
}
#endif
ctx = PK11_CreateDigestContext(hash_alg);
if(!ctx)
return /* failure */ 0;
if(PK11_DigestBegin(ctx) != SECSuccess) {
PK11_DestroyContext(ctx, PR_TRUE);
return /* failure */ 0;
}
*pctx = ctx;
return /* success */ 1;
}
开发者ID:fquinto,项目名称:curl,代码行数:27,代码来源:tool_metalink.c
示例10: sxi_hmac_sha1_init_ex
int sxi_hmac_sha1_init_ex(sxi_hmac_sha1_ctx *ctx,
const void *key, int key_len)
{
if (!ctx)
return 0;
/* NOTE: params must be provided, but may be empty */
SECItem noParams;
noParams.type = siBuffer;
noParams.data = 0;
noParams.len = 0;
if (ctx->context)
PK11_DestroyContext(ctx->context, PR_TRUE);
if (ctx->key)
PK11_FreeSymKey(ctx->key);
if (ctx->keysec)
SECITEM_FreeItem(ctx->keysec, PR_TRUE);
ctx->keysec = SECITEM_AllocItem(NULL, NULL, key_len);
if (ctx->keysec) {
memcpy(ctx->keysec->data, key, key_len);
ctx->key = PK11_ImportSymKey(ctx->slot, CKM_SHA_1_HMAC, PK11_OriginDerive, CKA_SIGN,
ctx->keysec, &noParams);
if(ctx->key) {
ctx->context = PK11_CreateContextBySymKey(CKM_SHA_1_HMAC, CKA_SIGN, ctx->key, &noParams);
if (ctx->context && PK11_DigestBegin(ctx->context) == SECSuccess)
return 1;
}
}
return 0;
}
开发者ID:flashfoxter,项目名称:sx,代码行数:30,代码来源:nss.c
示例11: nss_hash_final
static void nss_hash_final(void **pctx, unsigned char *out, unsigned int len)
{
PK11Context *ctx = *pctx;
unsigned int outlen;
PK11_DigestFinal(ctx, out, &outlen, len);
PK11_DestroyContext(ctx, PR_TRUE);
}
开发者ID:fquinto,项目名称:curl,代码行数:7,代码来源:tool_metalink.c
示例12: hmac_final
void
hmac_final(u_char *output, struct hmac_ctx *ctx)
{
#ifndef HAVE_LIBNSS
const struct hash_desc *h = ctx->h;
h->hash_final(output, &ctx->hash_ctx);
h->hash_init(&ctx->hash_ctx);
h->hash_update(&ctx->hash_ctx, ctx->buf2, HMAC_BUFSIZE);
h->hash_update(&ctx->hash_ctx, output, h->hash_digest_len);
h->hash_final(output, &ctx->hash_ctx);
#else
unsigned int outlen = 0;
SECStatus status = PK11_DigestFinal(ctx->ctx_nss, output, &outlen, ctx->hmac_digest_len);
PR_ASSERT(status == SECSuccess);
PR_ASSERT(outlen == ctx->hmac_digest_len);
PK11_DestroyContext(ctx->ctx_nss, PR_TRUE);
ctx->ctx_nss = NULL;
ctx->ctx_nss = PK11_CreateDigestContext(nss_hash_oid(ctx->h));
PR_ASSERT(ctx->ctx_nss!=NULL);
status=PK11_DigestBegin(ctx->ctx_nss);
PR_ASSERT(status==SECSuccess);
status=PK11_DigestKey(ctx->ctx_nss, ctx->okey);
PR_ASSERT(status==SECSuccess);
status = PK11_DigestOp(ctx->ctx_nss, output, outlen);
PR_ASSERT(status == SECSuccess);
status = PK11_DigestFinal(ctx->ctx_nss, output, &outlen, ctx->hmac_digest_len);
PR_ASSERT(status == SECSuccess);
PR_ASSERT(outlen == ctx->hmac_digest_len);
PK11_DestroyContext(ctx->ctx_nss, PR_TRUE);
if(ctx->ikey !=NULL) {
PK11_FreeSymKey(ctx->ikey);
}
if(ctx->okey != NULL) {
PK11_FreeSymKey(ctx->okey);
}
/* DBG(DBG_CRYPT, DBG_log("NSS: hmac final end")); */
#endif
}
开发者ID:JasonCC,项目名称:Openswan,代码行数:46,代码来源:hmac.c
示例13: PK11_CreateContextBySymKey
/*
* for Secure Messaging in Secure Channel
*/
TPS_PUBLIC PRStatus Util::EncryptData(PK11SymKey *encSessionKey,
Buffer &input, Buffer &output)
{
PRStatus rv = PR_FAILURE;
SECStatus s = SECFailure;
//static SECItem noParams = { siBuffer, 0, 0 };
static unsigned char d[8] = { 0,0,0,0,0,0,0,0 };
static SECItem ivParams = { siBuffer, d, 8 };
PK11Context *context = NULL;
unsigned char result[8];
int len;
int i;
/* this is ECB mode
context = PK11_CreateContextBySymKey(CKM_DES3_ECB, CKA_ENCRYPT, encSessionKey,
&noParams);
*/
// use CBC mode
context = PK11_CreateContextBySymKey(CKM_DES3_CBC, CKA_ENCRYPT, encSessionKey,
&ivParams);
if (!context) {
goto done;
}
for(i = 0;i < (int)input.size();i += 8) {
s = PK11_CipherOp(context, result, &len, 8,
(unsigned char *)(((BYTE*)input)+i), 8);
if (s != SECSuccess) {
goto done;
}
output.replace(i, result, 8);
}
rv = PR_SUCCESS;
// RA::Debug("Util::EncryptData", "success");
done:
//#define VRFY_ENC_SESSION_KEY
// fix this to use CBC mode later
#ifdef VRFY_ENC_SESSION_KEY
Buffer enc_key_buffer = Buffer((BYTE *) PK11_GetKeyData(encSessionKey)->data, PK11_GetKeyData(encSessionKey)->len);
RA::DebugBuffer("Util::EncryptData", "Verifying Encrypted Data",
&output);
Buffer out1 = Buffer(16, (BYTE)0);
PRStatus status = Util::DecryptData(enc_key_buffer, output, out1);
RA::DebugBuffer("Util::EncryptData", "Decrypted Data",
&out1);
#endif
if( context != NULL ) {
PK11_DestroyContext( context, PR_TRUE );
context = NULL;
}
return rv;
}
开发者ID:encukou,项目名称:pki,代码行数:61,代码来源:Util.cpp
示例14: ssl_DestroyKeyMaterial
static void
ssl_DestroyKeyMaterial(ssl3KeyMaterial *keyMaterial)
{
PK11_FreeSymKey(keyMaterial->key);
PK11_FreeSymKey(keyMaterial->macKey);
if (keyMaterial->macContext != NULL) {
PK11_DestroyContext(keyMaterial->macContext, PR_TRUE);
}
}
开发者ID:luke-chang,项目名称:gecko-1,代码行数:9,代码来源:sslspec.c
示例15: PK11_Derive_osw
PK11SymKey * PK11_Derive_osw(PK11SymKey *base, CK_MECHANISM_TYPE mechanism
, SECItem *param, CK_MECHANISM_TYPE target
, CK_ATTRIBUTE_TYPE operation, int keysize)
{
SECOidTag oid;
PK11Context *ctx;
unsigned char dkey[HMAC_BUFSIZE];
SECItem dkey_param;
SECStatus status;
unsigned int len=0;
CK_EXTRACT_PARAMS bs;
chunk_t dkey_chunk;
if( ((mechanism == CKM_SHA256_KEY_DERIVATION) ||
(mechanism == CKM_SHA384_KEY_DERIVATION)||
(mechanism == CKM_SHA512_KEY_DERIVATION)) && (param == NULL) && (keysize ==0)) {
switch (mechanism) {
case CKM_SHA256_KEY_DERIVATION: oid = SEC_OID_SHA256; break;
case CKM_SHA384_KEY_DERIVATION: oid = SEC_OID_SHA384; break;
case CKM_SHA512_KEY_DERIVATION: oid = SEC_OID_SHA512; break;
default: DBG(DBG_CRYPT, DBG_log("PK11_Derive_osw: Invalid NSS mechanism ")); break; /*should not reach here*/
}
ctx = PK11_CreateDigestContext(oid);
PR_ASSERT(ctx!=NULL);
status=PK11_DigestBegin(ctx);
PR_ASSERT(status == SECSuccess);
status=PK11_DigestKey(ctx, base);
PR_ASSERT(status == SECSuccess);
PK11_DigestFinal(ctx, dkey, &len, sizeof dkey);
PK11_DestroyContext(ctx, PR_TRUE);
dkey_chunk.ptr = dkey;
dkey_chunk.len = len;
PK11SymKey *tkey1 = pk11_derive_wrapper_osw(base, CKM_CONCATENATE_DATA_AND_BASE, dkey_chunk, CKM_EXTRACT_KEY_FROM_KEY, CKA_DERIVE, 0);
PR_ASSERT(tkey1!=NULL);
bs=0;
dkey_param.data = (unsigned char*)&bs;
dkey_param.len = sizeof (bs);
PK11SymKey *tkey2 = PK11_Derive(tkey1, CKM_EXTRACT_KEY_FROM_KEY, &dkey_param, target, operation, len);
PR_ASSERT(tkey2!=NULL);
if(tkey1!=NULL) {
PK11_FreeSymKey(tkey1);
}
return tkey2;
}
else {
return PK11_Derive(base, mechanism, param, target, operation, keysize);
}
}
开发者ID:JasonCC,项目名称:Openswan,代码行数:57,代码来源:hmac.c
示例16: PK11_HashOK
/*
* This is to get FIPS compliance until we can convert
* libjar to use PK11_ hashing functions. It returns PR_FALSE
* if we can't get a PK11 Context.
*/
PRBool
PK11_HashOK(SECOidTag algID) {
PK11Context *cx;
cx = PK11_CreateDigestContext(algID);
if (cx == NULL) return PR_FALSE;
PK11_DestroyContext(cx, PR_TRUE);
return PR_TRUE;
}
开发者ID:rhencke,项目名称:mozilla-cvs-history,代码行数:14,代码来源:pk11cxt.c
示例17: sxi_md_cleanup
void sxi_md_cleanup(sxi_md_ctx **ctxptr)
{
if (!ctxptr || !*ctxptr)
return;
if ((*ctxptr)->context)
PK11_DestroyContext((*ctxptr)->context, PR_TRUE);
free(*ctxptr);
*ctxptr = NULL;
}
开发者ID:flashfoxter,项目名称:sx,代码行数:9,代码来源:nss.c
示例18: sss_nss_crypto_ctx_destructor
static int sss_nss_crypto_ctx_destructor(struct sss_nss_crypto_ctx *cctx)
{
if (cctx->ectx) PK11_DestroyContext(cctx->ectx, PR_TRUE);
if (cctx->sparam) SECITEM_FreeItem(cctx->sparam, PR_TRUE);
if (cctx->slot) PK11_FreeSlot(cctx->slot);
if (cctx->keyobj) PK11_FreeSymKey(cctx->keyobj);
return EOK;
}
开发者ID:jhrozek,项目名称:sssd,代码行数:9,代码来源:nss_util.c
示例19: lsMD5Final
/* MD5 finalization. Ends an MD5 message-digest operation, writing the
* the message digest and zeroing the context.
*/
void lsMD5Final(unsigned char digest[MD5_DIGEST_SIZE], lsMD5_CTX *context)
{
unsigned int length;
SECStatus status = PK11_DigestFinal(context->ctx_nss, digest, &length,
MD5_DIGEST_SIZE);
passert(status == SECSuccess);
passert(length == MD5_DIGEST_SIZE);
PK11_DestroyContext(context->ctx_nss, PR_TRUE);
}
开发者ID:doctaweeks,项目名称:libreswan,代码行数:13,代码来源:md5.c
示例20: crypto_md5_final
void
crypto_md5_final(CryptoMd5 md5, uint8 * out_data)
{
unsigned int len;
SECStatus s = PK11_DigestFinal(md5->context, out_data, &len, 16);
check(s, "Error finalizing md5");
ASSERT(len == 16);
PK11_DestroyContext(md5->context, PR_TRUE);
xfree(md5);
}
开发者ID:alama,项目名称:freerdp,代码行数:10,代码来源:crypto_nss.c
注:本文中的PK11_DestroyContext函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论