本文整理汇总了C++中pk_free函数的典型用法代码示例。如果您正苦于以下问题:C++ pk_free函数的具体用法?C++ pk_free怎么用?C++ pk_free使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pk_free函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: tcp_rcv
int
tcp_rcv(PACKET pkt) /* NOTE: pkt has nb_prot pointing to IP header */
{
struct mbuf * m_in;
struct ip * bip; /* IP header, berkeley version */
struct tcphdr * tcpp;
unshort len; /* scratch length holder */
/* For TCP, the netport IP layer is modified to set nb_prot to the
* start of the IP header (not TCP). We need to do some further
* mods which the BSD code expects:
*/
bip = (struct ip *)pkt->nb_prot; /* get ip header */
len = ntohs(bip->ip_len); /* get length in local endian */
/* verify checksum of received packet */
tcpp = (struct tcphdr *)ip_data(bip);
if (tcp_cksum(bip) != tcpp->th_sum)
{
TCP_MIB_INC(tcpInErrs); /* keep MIB stats */
tcpstat.tcps_rcvbadsum++; /* keep BSD stats */
LOCK_NET_RESOURCE(FREEQ_RESID);
pk_free(pkt); /* punt packet */
UNLOCK_NET_RESOURCE(FREEQ_RESID);
return ENP_BAD_HEADER;
}
m_in = m_getnbuf(MT_RXDATA, 0);
if (!m_in){
LOCK_NET_RESOURCE(FREEQ_RESID);
pk_free(pkt);
UNLOCK_NET_RESOURCE(FREEQ_RESID);
return ENP_RESOURCE;
}
IN_PROFILER(PF_TCP, PF_ENTRY); /* measure time in TCP */
/* subtract IP header length from total IP packet length */
len -= ((unshort)(bip->ip_ver_ihl & 0x0f) << 2);
bip->ip_len = len; /* put TCP length in struct for TCP code to use */
/* set mbuf to point to start of IP header (not TCP) */
m_in->pkt = pkt;
m_in->m_data = pkt->nb_prot;
m_in->m_len = pkt->nb_plen;
m_in->m_base = pkt->nb_buff; /* ??? */
m_in->m_memsz = pkt->nb_blen; /* ??? */
tcp_input(m_in, pkt->net);
IN_PROFILER(PF_TCP, PF_EXIT); /* measure time in TCP */
return 0;
}
开发者ID:ECE492W2014G4,项目名称:G4Capstone,代码行数:55,代码来源:nptcp.c
示例2: rfsim_timer
void
rfsim_timer()
{
ip_addr hop;
struct ip * pip;
PACKET pkt;
/* send al packets which have timed out */
while(((PACKET)(simq.q_head))->nb_tstamp < cticks)
{
pkt = (PACKET)getq(&simq); /* get pkt to send */
hop = pkt->fhost; /* get hop from host field */
pip = ip_head(pkt); /* get real host address */
pkt->fhost = pip->ip_dest; /* restore host field */
simpkts++;
/* see if it's time to drop a packet */
if((lossrate) &&
((simpkts - simlastloss) > lossrate) &&
((cticks & deviation) == 1))
{
LOCK_NET_RESOURCE(FREEQ_RESID);
pk_free(pkt); /* drop instead of send */
UNLOCK_NET_RESOURCE(FREEQ_RESID);
simlastloss = simpkts; /* reset drop timer */
simdrops++; /* count drops */
}
else
ip2mac(pkt, hop); /* send pkt to hardware */
}
return;
}
开发者ID:fjanssen,项目名称:Car2X,代码行数:32,代码来源:rfsim.c
示例3: x509_csr_free
/*
* Unallocate all CSR data
*/
void x509_csr_free( x509_csr *csr )
{
x509_name *name_cur;
x509_name *name_prv;
if( csr == NULL )
return;
pk_free( &csr->pk );
name_cur = csr->subject.next;
while( name_cur != NULL )
{
name_prv = name_cur;
name_cur = name_cur->next;
memset( name_prv, 0, sizeof( x509_name ) );
polarssl_free( name_prv );
}
if( csr->raw.p != NULL )
{
memset( csr->raw.p, 0, csr->raw.len );
polarssl_free( csr->raw.p );
}
memset( csr, 0, sizeof( x509_csr ) );
}
开发者ID:BenKoerber,项目名称:clearskies_core,代码行数:30,代码来源:x509_csr.c
示例4: x509_csr_free
/*
* Unallocate all CSR data
*/
void x509_csr_free( x509_csr *csr )
{
x509_name *name_cur;
x509_name *name_prv;
if( csr == NULL )
return;
pk_free( &csr->pk );
#if defined(POLARSSL_X509_RSASSA_PSS_SUPPORT)
polarssl_free( csr->sig_opts );
#endif
name_cur = csr->subject.next;
while( name_cur != NULL )
{
name_prv = name_cur;
name_cur = name_cur->next;
polarssl_zeroize( name_prv, sizeof( x509_name ) );
polarssl_free( name_prv );
}
if( csr->raw.p != NULL )
{
polarssl_zeroize( csr->raw.p, csr->raw.len );
polarssl_free( csr->raw.p );
}
polarssl_zeroize( csr, sizeof( x509_csr ) );
}
开发者ID:RuralHunter,项目名称:showtime,代码行数:34,代码来源:x509_csr.c
示例5: pk_prepend
PACKET
pk_prepend(PACKET pkt, int bigger)
{
PACKET newpkt;
LOCK_NET_RESOURCE(FREEQ_RESID);
newpkt = pk_alloc(bigger);
UNLOCK_NET_RESOURCE(FREEQ_RESID);
if(!newpkt)
{
LOCK_NET_RESOURCE(FREEQ_RESID);
pk_free(pkt);
UNLOCK_NET_RESOURCE(FREEQ_RESID);
return NULL;
}
newpkt->nb_prot = newpkt->nb_buff; /* no MAC prepend */
/* set lengths of this buffer - no data yet */
newpkt->nb_plen = 0; /* nothing in this buffer */
newpkt->nb_tlen = pkt->nb_tlen; /* total chain length unchanged */
newpkt->pk_next = pkt;
newpkt->pk_prev = NULL;
/* ensure that the newly allocated buffer's PKF_HEAPBUF and
* PKF_INTRUNSAFE flags aren't overwritten */
newpkt->flags |= (pkt->flags & (~(PKF_HEAPBUF | PKF_INTRUNSAFE)));
newpkt->net = pkt->net;
pkt->pk_prev = newpkt; /* link new pkt */
return(newpkt);
}
开发者ID:hds17,项目名称:hwswcd-car2x,代码行数:30,代码来源:pktalloc.c
示例6: pk_parse_subpubkey
/*
* SubjectPublicKeyInfo ::= SEQUENCE {
* algorithm AlgorithmIdentifier,
* subjectPublicKey BIT STRING }
*/
int pk_parse_subpubkey( unsigned char **p, const unsigned char *end,
pk_context *pk )
{
int ret;
size_t len;
asn1_buf alg_params;
pk_type_t pk_alg = POLARSSL_PK_NONE;
const pk_info_t *pk_info;
if( ( ret = asn1_get_tag( p, end, &len,
ASN1_CONSTRUCTED | ASN1_SEQUENCE ) ) != 0 )
{
return( POLARSSL_ERR_PK_KEY_INVALID_FORMAT + ret );
}
end = *p + len;
if( ( ret = pk_get_pk_alg( p, end, &pk_alg, &alg_params ) ) != 0 )
return( ret );
if( ( ret = asn1_get_bitstring_null( p, end, &len ) ) != 0 )
return( POLARSSL_ERR_PK_INVALID_PUBKEY + ret );
if( *p + len != end )
return( POLARSSL_ERR_PK_INVALID_PUBKEY +
POLARSSL_ERR_ASN1_LENGTH_MISMATCH );
if( ( pk_info = pk_info_from_type( pk_alg ) ) == NULL )
return( POLARSSL_ERR_PK_UNKNOWN_PK_ALG );
if( ( ret = pk_init_ctx( pk, pk_info ) ) != 0 )
return( ret );
#if defined(POLARSSL_RSA_C)
if( pk_alg == POLARSSL_PK_RSA )
{
ret = pk_get_shrsapubkey( p, end, pk_rsa( *pk ) );
} else
#endif /* POLARSSL_RSA_C */
#if defined(POLARSSL_ECP_C)
if( pk_alg == POLARSSL_PK_ECKEY_DH || pk_alg == POLARSSL_PK_ECKEY )
{
ret = pk_use_ecparams( &alg_params, &pk_ec( *pk )->grp );
if( ret == 0 )
ret = pk_get_ecpubkey( p, end, pk_ec( *pk ) );
} else
#endif /* POLARSSL_ECP_C */
ret = POLARSSL_ERR_PK_UNKNOWN_PK_ALG;
if( ret == 0 && *p != end )
ret = POLARSSL_ERR_PK_INVALID_PUBKEY
POLARSSL_ERR_ASN1_LENGTH_MISMATCH;
if( ret != 0 )
pk_free( pk );
return( ret );
}
开发者ID:neonatura,项目名称:share,代码行数:63,代码来源:pkparse.c
示例7: dealloc
void dealloc()
{
if (ctx)
{
pk_free(ctx);
delete ctx;
ctx = NULL;
}
}
开发者ID:akoshelnik,项目名称:openvpn3,代码行数:9,代码来源:pkctx.hpp
示例8: m_getnbuf
struct mbuf *
m_getnbuf(int type, int len)
{
struct mbuf * m;
PACKET pkt = NULL;
#ifdef NPDEBUG
if (type < MT_RXDATA || type > MT_IFADDR)
{
dtrap(); /* is this OK? */
}
#endif
/* if caller has data (len >= 0), we need to allocate
* a packet buffer; else all we need is the mbuf */
if (len != 0)
{
LOCK_NET_RESOURCE(FREEQ_RESID);
pkt = pk_alloc(len + HDRSLEN);
UNLOCK_NET_RESOURCE(FREEQ_RESID);
if (!pkt)
return NULL;
}
m = (struct mbuf *)getq(&mfreeq);
if (!m)
{
if (pkt)
{
LOCK_NET_RESOURCE(FREEQ_RESID);
pk_free(pkt);
UNLOCK_NET_RESOURCE(FREEQ_RESID);
}
return NULL;
}
m->m_type = type;
if (len == 0)
{
m->pkt = NULL;
m->m_base = NULL; /* caller better fill these in! */
m->m_memsz = 0;
}
else
{
m->pkt = pkt;
/* set m_data to the part where tcp data should go */
m->m_base = m->m_data = pkt->nb_prot = pkt->nb_buff + HDRSLEN;
m->m_memsz = pkt->nb_blen - HDRSLEN;
}
m->m_len = 0;
m->m_next = m->m_act = NULL;
mbstat.allocs++; /* maintain local statistics */
putq(&mbufq, (qp)m);
return m;
}
开发者ID:ECE492W2014G4,项目名称:G4Capstone,代码行数:56,代码来源:nptcp.c
示例9: __ustream_ssl_context_free
__hidden void __ustream_ssl_context_free(struct ustream_ssl_ctx *ctx)
{
#ifdef USE_VERSION_1_3
pk_free(&ctx->key);
x509_crt_free(&ctx->cert);
#else
rsa_free(&ctx->key);
x509_free(&ctx->cert);
#endif
free(ctx);
}
开发者ID:asriadi,项目名称:ustream-ssl,代码行数:11,代码来源:ustream-polarssl.c
示例10: igmpv2_input
int igmpv2_input (PACKET p)
{
struct igmp * igmp;
struct ip * pip;
int igmplen;
u_char type;
int rc;
pip = ip_head (p);
/* compute length of IGMP packet (after accounting for IP header,
* including the IP Router Alert option (if present)) */
igmplen = p->nb_plen - ip_hlen (pip);
igmp = (struct igmp *) (ip_data (pip));
/* extract the IGMP packet type from received packet */
type = igmp->igmp_type;
switch (type)
{
case IGMP_HOST_MEMBERSHIP_QUERY:
rc = igmpv2_process_query (p);
break;
case IGMP_HOST_MEMBERSHIP_REPORT:
case IGMPv2_MEMBERSHIP_REPORT:
rc = igmpv2_process_report (p);
break;
case IGMPv2_LEAVE_GROUP:
/* Leave messages are typically addressed to the all-routers
* multicast address group (224.0.0.2). We do not implement
* multicast router functionality, and therefore, do not
* expect to receive such messages. However, according to
* RFC 2236, some implementations of an older version of the
* IGMPv2 specification send leave messages to the group
* being left. If we do receive such a message, we will
* drop it. */
++igmpstats.igmpv2mode_v2_leave_msgs_rcvd;
rc = IGMP_OK;
break;
default:
++igmpstats.igmpv2mode_unknown_pkttype;
rc = IGMP_ERR;
break;
} /* end SWITCH */
/* we're done processing the received packet; return packet buffer
* back to free pool */
LOCK_NET_RESOURCE(FREEQ_RESID);
pk_free(p);
UNLOCK_NET_RESOURCE(FREEQ_RESID);
return rc;
}
开发者ID:ECE492W2014G4,项目名称:G4Capstone,代码行数:54,代码来源:igmp2.c
示例11: ms_dtls_srtp_context_destroy
void ms_dtls_srtp_context_destroy(MSDtlsSrtpContext *ctx) {
/* clean polarssl contexts */
if (ctx->rtp_dtls_context) {
x509_crt_free( &(ctx->rtp_dtls_context->crt) );
ssl_free( &(ctx->rtp_dtls_context->ssl) );
ctr_drbg_free( &(ctx->rtp_dtls_context->ctr_drbg) );
entropy_free( &(ctx->rtp_dtls_context->entropy) );
pk_free( &(ctx->rtp_dtls_context->pkey) );
ssl_cookie_free( &(ctx->rtp_dtls_context->cookie_ctx) );
ms_mutex_destroy(&ctx->rtp_dtls_context->ssl_context_mutex);
ms_free(ctx->rtp_dtls_context);
}
if (ctx->rtcp_dtls_context) {
x509_crt_free( &(ctx->rtcp_dtls_context->crt) );
ssl_free( &(ctx->rtcp_dtls_context->ssl) );
ctr_drbg_free( &(ctx->rtcp_dtls_context->ctr_drbg) );
entropy_free( &(ctx->rtcp_dtls_context->entropy) );
pk_free( &(ctx->rtcp_dtls_context->pkey) );
ssl_cookie_free( &(ctx->rtcp_dtls_context->cookie_ctx) );
ms_mutex_destroy(&ctx->rtcp_dtls_context->ssl_context_mutex);
ms_free(ctx->rtcp_dtls_context);
}
/* clean incoming buffers */
while (ctx->rtp_incoming_buffer!=NULL) {
DtlsRawPacket *next_packet = ctx->rtp_incoming_buffer->next;
ms_free(ctx->rtp_incoming_buffer->data);
ms_free(ctx->rtp_incoming_buffer);
ctx->rtp_incoming_buffer = next_packet;
}
while (ctx->rtcp_incoming_buffer!=NULL) {
DtlsRawPacket *next_packet = ctx->rtcp_incoming_buffer->next;
ms_free(ctx->rtcp_incoming_buffer->data);
ms_free(ctx->rtcp_incoming_buffer);
ctx->rtcp_incoming_buffer = next_packet;
}
ms_free(ctx);
ms_message("DTLS-SRTP context destroyed");
}
开发者ID:krieger-od,项目名称:mediastreamer2,代码行数:39,代码来源:dtls_srtp.c
示例12: pk_gather
PACKET
pk_gather(PACKET pkt, int headerlen)
{
PACKET newpkt;
PACKET tmppkt;
int oldlen, newlen;
char * cp;
oldlen = pkt->nb_tlen;
LOCK_NET_RESOURCE(FREEQ_RESID);
newpkt = pk_alloc(oldlen + headerlen);
UNLOCK_NET_RESOURCE(FREEQ_RESID);
if(!newpkt)
return NULL;
newpkt->nb_prot = newpkt->nb_buff + headerlen;
/* ensure that the newly allocated buffer's PKF_HEAPBUF and
* PKF_INTRUNSAFE flags aren't overwritten */
newpkt->flags |= (pkt->flags & (~(PKF_HEAPBUF | PKF_INTRUNSAFE)));
newpkt->net = pkt->net;
newpkt->pk_prev = newpkt->pk_next = NULL;
tmppkt = pkt; /* save packet for pk_free call below */
newlen = 0;
cp = newpkt->nb_prot;
while(pkt)
{
MEMCPY(cp, pkt->nb_prot, pkt->nb_plen);
newlen += pkt->nb_plen;
cp += pkt->nb_plen; /* bump pointer to data */
pkt = pkt->pk_next; /* next packet in chain */
}
LOCK_NET_RESOURCE(FREEQ_RESID);
pk_free(tmppkt); /* free last packet in chain */
UNLOCK_NET_RESOURCE(FREEQ_RESID);
if(newlen != oldlen) /* make sure length was right */
panic("pk_gather");
newpkt->nb_plen = newlen;
return newpkt;
}
开发者ID:hds17,项目名称:hwswcd-car2x,代码行数:42,代码来源:pktalloc.c
示例13: igmp_input
int igmp_input (PACKET p)
{
u_char mode;
int rc;
++igmpstats.igmp_total_rcvd;
/* validate the received packet; if validation fails,
* drop the packet and return */
if ((rc = igmp_validate (p)) != IGMP_OK) goto end;
/* determine the operating mode for IGMP on the ingress link */
mode = p->net->igmp_oper_mode;
/* feed packet to IGMPv1 or IGMPv2 code based on the operating
* mode of the ingress link */
switch (mode)
{
#ifdef IGMP_V1
case IGMP_MODE_V1:
return (igmpv1_input (p));
#endif
#ifdef IGMP_V2
case IGMP_MODE_V2:
return (igmpv2_input (p));
#endif
default:
++igmpstats.igmp_bad_oper_mode;
rc = IGMP_ERR;
break;
}
end:
/* return packet buffer back to free pool */
LOCK_NET_RESOURCE(FREEQ_RESID);
pk_free(p);
UNLOCK_NET_RESOURCE(FREEQ_RESID);
return rc;
}
开发者ID:ECE492W2014G4,项目名称:G4Capstone,代码行数:40,代码来源:igmp_cmn.c
示例14: m_free
struct mbuf *
m_free(struct mbuf * m)
{
struct mbuf * nextptr;
#ifdef NPDEBUG
if (mbufq.q_len < 1)
panic("mfree: q_len");
if (m->m_type < MT_RXDATA || m->m_type > MT_IFADDR)
{
if (m->m_type == MT_FREE)
{
dtrap(); /* debug double free of mbuf by tcp_in() */
return m->m_next; /* seems harmless, though.... */
}
else
panic("m_free: type");
}
#endif /* NPDEBUG */
nextptr = m->m_next; /* remember value to return */
if (qdel(&mbufq, m) == NULL)
panic("m_free: missing");
m->m_type = MT_FREE; /* this may seem silly, but helps error checking */
if (m->pkt)
{
LOCK_NET_RESOURCE(FREEQ_RESID);
pk_free(m->pkt); /* free up the netport buffer */
UNLOCK_NET_RESOURCE(FREEQ_RESID);
}
mbstat.frees++;
putq(&mfreeq, (qp)m);
return nextptr;
}
开发者ID:ECE492W2014G4,项目名称:G4Capstone,代码行数:38,代码来源:nptcp.c
示例15: mrb_ecdsa_load_pem
static mrb_value mrb_ecdsa_load_pem(mrb_state *mrb, mrb_value self) {
ecdsa_context *ecdsa;
pk_context pkey;
mrb_value pem;
int ret = 0;
mrb_get_args(mrb, "S", &pem);
pk_init( &pkey );
ret = pk_parse_key(&pkey, RSTRING_PTR(pem), RSTRING_LEN(pem), NULL, 0);
if (ret == 0) {
ecdsa = DATA_CHECK_GET_PTR(mrb, self, &mrb_ecdsa_type, ecdsa_context);
ret = ecdsa_from_keypair(ecdsa, pk_ec(pkey));
if (ret == 0) {
return mrb_true_value();
}
}
pk_free( &pkey );
mrb_raise(mrb, E_RUNTIME_ERROR, "can't parse pem");
return mrb_false_value();
}
开发者ID:toch,项目名称:mruby-polarssl,代码行数:23,代码来源:polarssl.c
示例16: main
//.........这里部分代码省略.........
goto reset;
}
if( ret != POLARSSL_ERR_NET_WANT_READ && ret != POLARSSL_ERR_NET_WANT_WRITE )
{
printf( " failed\n ! ssl_write returned %d\n\n", ret );
goto exit;
}
}
}
buf[written] = '\0';
printf( " %d bytes written in %d fragments\n\n%s\n", written, frags, (char *) buf );
#ifdef TEST_RENEGO
/*
* Request renegotiation (this must be done when the client is still
* waiting for input from our side).
*/
printf( " . Requestion renegotiation..." );
fflush( stdout );
while( ( ret = ssl_renegotiate( &ssl ) ) != 0 )
{
if( ret != POLARSSL_ERR_NET_WANT_READ && ret != POLARSSL_ERR_NET_WANT_WRITE )
{
printf( " failed\n ! ssl_renegotiate returned %d\n\n", ret );
goto exit;
}
}
/*
* Should be a while loop, not an if, but here we're not actually
* expecting data from the client, and since we're running tests locally,
* we can just hope the handshake will finish the during the first call.
*/
if( ( ret = ssl_read( &ssl, buf, 0 ) ) != 0 )
{
if( ret != POLARSSL_ERR_NET_WANT_READ && ret != POLARSSL_ERR_NET_WANT_WRITE )
{
printf( " failed\n ! ssl_read returned %d\n\n", ret );
/* Unexpected message probably means client didn't renegotiate */
if( ret == POLARSSL_ERR_SSL_UNEXPECTED_MESSAGE )
goto reset;
else
goto exit;
}
}
printf( " ok\n" );
#endif
ret = 0;
goto reset;
exit:
#ifdef POLARSSL_ERROR_C
if( ret != 0 )
{
char error_buf[100];
polarssl_strerror( ret, error_buf, 100 );
printf("Last error was: -0x%X - %s\n\n", -ret, error_buf );
}
#endif
net_close( client_fd );
#if defined(POLARSSL_X509_CRT_PARSE_C)
x509_crt_free( &cacert );
x509_crt_free( &srvcert );
pk_free( &pkey );
x509_crt_free( &srvcert2 );
pk_free( &pkey2 );
#endif
ssl_free( &ssl );
entropy_free( &entropy );
#if defined(POLARSSL_SSL_CACHE_C)
ssl_cache_free( &cache );
#endif
#if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C)
#if defined(POLARSSL_MEMORY_DEBUG)
memory_buffer_alloc_status();
#endif
memory_buffer_alloc_free();
#endif
#if defined(_WIN32)
printf( " + Press Enter to exit this program.\n" );
fflush( stdout ); getchar();
#endif
// Shell can not handle large exit numbers -> 1 for errors
if( ret < 0 )
ret = 1;
return( ret );
}
开发者ID:BenKoerber,项目名称:clearskies_core,代码行数:101,代码来源:ssl_server2.c
示例17: principal
struct item *asymmetric_decryption(struct item *key, struct item *item, char tag)
/*@ requires [?f]world(?pub, ?key_clsfy) &*& true == valid_tag(tag) &*&
principal(?principal1, ?count1) &*&
item(item, ?enc, pub) &*& item(key, ?k, pub) &*&
enc == asymmetric_encrypted_item(?principal2, ?count2,
?pay, ?ent) &*&
k == private_key_item(?principal3, ?count3); @*/
/*@ ensures [f]world(pub, key_clsfy) &*&
principal(principal1, count1 + 1) &*&
item(item, enc, pub) &*& item(key, k, pub) &*&
item(result, ?dec, pub) &*& tag_for_item(dec) == tag &*&
col ?
[_]pub(dec)
: principal2 != principal3 || count2 != count3 ?
true == key_clsfy(principal3, count3, false) &*&
[_]pub(dec)
:
switch(pay)
{
case some(dec2):
return dec == dec2;
case none:
return false;
}; @*/
{
struct item* result = 0;
debug_print("DECRYPTING:\n");
print_item(item);
check_is_asymmetric_encrypted(item);
{
pk_context context;
unsigned int olen;
char output[MAX_PACKAGE_SIZE];
// Key
//@ close pk_context(&context);
//@ open [f]world(pub, key_clsfy);
pk_init(&context);
//@ close [f]world(pub, key_clsfy);
set_private_key(&context, key);
//@ open [f]world(pub, key_clsfy);
/*@ assert pk_context_with_key(&context, pk_private,
?principal, ?count, RSA_BIT_KEY_SIZE); @*/
// Decryption
//@ open item(item, enc, pub);
/*@ assert enc == asymmetric_encrypted_item(principal2, count2,
pay, ent); @*/
//@ open [_]item_constraints(enc, ?enc_cs, pub);
//@ assert [_]ic_parts(enc)(?enc_tag, ?enc_cont);
//@ assert enc_cs == append(enc_tag, enc_cont);
//@ open [_]ic_cg(enc)(_, ?enc_cg);
//@ assert enc_cg == cg_asym_encrypted(principal2, count2, ?cs_pay, ent);
if (item->size - TAG_LENGTH > RSA_KEY_SIZE ||
item->size - TAG_LENGTH < MINIMAL_STRING_SIZE)
abort_crypto_lib("Asymmetric decryption failed: incorrect sizes");
//@ assert item->content |-> ?i_cont &*& item->size |-> ?i_size;
//@ crypto_chars_split(i_cont, TAG_LENGTH);
//@ drop_append(TAG_LENGTH, enc_tag, enc_cont);
//@ assert crypto_chars(secret, i_cont + TAG_LENGTH, i_size - TAG_LENGTH, enc_cont);
//@ if (col) enc_cg = chars_for_cg_sur(enc_cont, tag_asym_encrypted);
//@ if (col) public_crypto_chars_extract(i_cont + TAG_LENGTH, enc_cg);
//@ close cryptogram(i_cont + TAG_LENGTH, i_size - TAG_LENGTH, enc_cont, enc_cg);
void *random_state = nonces_expose_state();
//@ close random_state_predicate(havege_state_initialized);
/*@ produce_function_pointer_chunk random_function(
asym_enc_havege_random_stub)
(havege_state_initialized)(state, out, len) { call(); } @*/
//@ open principal(principal1, count1);
//@ structure s = known_value(0, full_tag(tag));
//@ close decryption_pre(false, false, principal1, s, enc_cont);
if(pk_decrypt(&context, item->content + TAG_LENGTH,
(unsigned int) item->size - TAG_LENGTH,
output, &olen, MAX_PACKAGE_SIZE,
asym_enc_havege_random_stub, random_state) != 0)
abort_crypto_lib("Decryption failed");
/*@ open decryption_post(false, ?garbage, principal1,
s, ?p_key, ?c_key, ?cs_out); @*/
//@ assert u_integer(&olen, ?size_out);
//@ pk_release_context_with_key(&context);
//@ open cryptogram(i_cont + TAG_LENGTH, i_size - TAG_LENGTH, enc_cont, enc_cg);
pk_free(&context);
//@ open pk_context(&context);
nonces_hide_state(random_state);
//@ assert chars((void*)output + size_out, MAX_PACKAGE_SIZE - size_out, ?cs_rest);
result = malloc(sizeof(struct item));
if (result == 0) {abort_crypto_lib("Malloc failed");}
result->size = (int) olen;
if ((int) olen <= MINIMAL_STRING_SIZE)
abort_crypto_lib("Decryption: Incorrect size");
result->content = malloc(result->size);
if (result->content == 0) {abort_crypto_lib("Malloc failed");}
//@ close [f]world(pub, key_clsfy);
//@ assert u_integer(&olen, ?olen_val);
//@ assert crypto_chars(_, output, olen_val, cs_out);
//@ crypto_chars_split(output, TAG_LENGTH);
//@ assert crypto_chars(_, output, TAG_LENGTH, ?cs_tag);
//@ assert crypto_chars(_, (void*) output + TAG_LENGTH, olen_val - TAG_LENGTH, ?cs_i);
/*@ if (col)
//.........这里部分代码省略.........
开发者ID:amintimany,项目名称:verifast,代码行数:101,代码来源:asymmetric_encrypted_item.c
示例18: main
int main( int argc, char *argv[] )
{
FILE *f;
int ret = 1;
pk_context pk;
entropy_context entropy;
ctr_drbg_context ctr_drbg;
unsigned char hash[20];
unsigned char buf[POLARSSL_MPI_MAX_SIZE];
char filename[512];
const char *pers = "pk_sign";
size_t olen = 0;
entropy_init( &entropy );
pk_init( &pk );
if( argc != 3 )
{
polarssl_printf( "usage: pk_sign <key_file> <filename>\n" );
#if defined(_WIN32)
polarssl_printf( "\n" );
#endif
goto exit;
}
polarssl_printf( "\n . Seeding the random number generator..." );
fflush( stdout );
if( ( ret = ctr_drbg_init( &ctr_drbg, entropy_func, &entropy,
(const unsigned char *) pers,
strlen( pers ) ) ) != 0 )
{
polarssl_printf( " failed\n ! ctr_drbg_init returned -0x%04x\n", -ret );
goto exit;
}
polarssl_printf( "\n . Reading private key from '%s'", argv[1] );
fflush( stdout );
if( ( ret = pk_parse_keyfile( &pk, argv[1], "" ) ) != 0 )
{
ret = 1;
polarssl_printf( " failed\n ! Could not open '%s'\n", argv[1] );
goto exit;
}
/*
* Compute the SHA-1 hash of the input file,
* then calculate the signature of the hash.
*/
polarssl_printf( "\n . Generating the SHA-1 signature" );
fflush( stdout );
if( ( ret = sha1_file( argv[2], hash ) ) != 0 )
{
polarssl_printf( " failed\n ! Could not open or read %s\n\n", argv[2] );
goto exit;
}
if( ( ret = pk_sign( &pk, POLARSSL_MD_SHA1, hash, 0, buf, &olen,
ctr_drbg_random, &ctr_drbg ) ) != 0 )
{
polarssl_printf( " failed\n ! pk_sign returned -0x%04x\n", -ret );
goto exit;
}
/*
* Write the signature into <filename>-sig.txt
*/
snprintf( filename, sizeof(filename), "%s.sig", argv[2] );
if( ( f = fopen( filename, "wb+" ) ) == NULL )
{
ret = 1;
polarssl_printf( " failed\n ! Could not create %s\n\n", filename );
goto exit;
}
if( fwrite( buf, 1, olen, f ) != olen )
{
polarssl_printf( "failed\n ! fwrite failed\n\n" );
goto exit;
}
fclose( f );
polarssl_printf( "\n . Done (created \"%s\")\n\n", filename );
exit:
pk_free( &pk );
ctr_drbg_free( &ctr_drbg );
entropy_free( &entropy );
#if defined(POLARSSL_ERROR_C)
polarssl_strerror( ret, (char *) buf, sizeof(buf) );
polarssl_printf( " ! Last error was: %s\n", buf );
#endif
//.........这里部分代码省略.........
开发者ID:randombit,项目名称:hacrypto,代码行数:101,代码来源:pk_sign.c
示例19: main
//.........这里部分代码省略.........
}
printf( " ok\n" );
/*
* 2. Start the connection
*/
printf( " . SSL connection to tcp/%s/%-4d...", opt.server_name,
opt.server_port );
fflush( stdout );
if( ( ret = net_connect( &server_fd, opt.server_name,
opt.server_port ) ) != 0 )
{
printf( " failed\n ! net_connect returned %d\n\n", ret );
goto exit;
}
/*
* 3. Setup stuff
*/
if( ( ret = ssl_init( &ssl ) ) != 0 )
{
printf( " failed\n ! ssl_init returned %d\n\n", ret );
goto exit;
}
ssl_set_endpoint( &ssl, SSL_IS_CLIENT );
if( verify )
{
ssl_set_authmode( &ssl, SSL_VERIFY_REQUIRED );
ssl_set_ca_chain( &ssl, &cacert, NULL, opt.server_name );
ssl_set_verify( &ssl, my_verify, NULL );
}
else
ssl_set_authmode( &ssl, SSL_VERIFY_NONE );
ssl_set_rng( &ssl, ctr_drbg_random, &ctr_drbg );
ssl_set_dbg( &ssl, my_debug, stdout );
ssl_set_bio( &ssl, net_recv, &server_fd,
net_send, &server_fd );
ssl_set_own_cert( &ssl, &clicert, &pkey );
#if defined(POLARSSL_SSL_SERVER_NAME_INDICATION)
ssl_set_hostname( &ssl, opt.server_name );
#endif
/*
* 4. Handshake
*/
while( ( ret = ssl_handshake( &ssl ) ) != 0 )
{
if( ret != POLARSSL_ERR_NET_WANT_READ && ret != POLARSSL_ERR_NET_WANT_WRITE )
{
printf( " failed\n ! ssl_handshake returned %d\n\n", ret );
ssl_free( &ssl );
goto exit;
}
}
printf( " ok\n" );
/*
* 5. Print the certificate
*/
printf( " . Peer certificate information ...\n" );
ret = x509_crt_info( (char *) buf, sizeof( buf ) - 1, " ",
ssl.session->peer_cert );
if( ret == -1 )
{
printf( " failed\n ! x509_crt_info returned %d\n\n", ret );
ssl_free( &ssl );
goto exit;
}
printf( "%s\n", buf );
ssl_close_notify( &ssl );
ssl_free( &ssl );
}
else
goto usage;
exit:
if( server_fd )
net_close( server_fd );
x509_crt_free( &cacert );
x509_crt_free( &clicert );
pk_free( &pkey );
entropy_free( &entropy );
#if defined(_WIN32)
printf( " + Press Enter to exit this program.\n" );
fflush( stdout ); getchar();
#endif
return( ret );
}
开发者ID:AgileBits,项目名称:polarssl,代码行数:101,代码来源:cert_app.c
示例20: SSL_CTX_free
void SSL_CTX_free(SSL_CTX *ctx) {
x509_crt_free(&ctx->cert);
x509_crt_free(&ctx->CA_cert);
pk_free(&ctx->pk);
free(ctx);
}
开发者ID:AustinHunting,项目名称:polar,代码行数:6,代码来源:polarssl_compat.c
注:本文中的pk_free函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论