int Sha512Hash(const byte* data, word32 len, byte* hash) { int ret = 0; #ifdef CYASSL_SMALL_STACK Sha512* sha512; #else Sha512 sha512[1]; #endif #ifdef CYASSL_SMALL_STACK sha512 = (Sha512*)XMALLOC(sizeof(Sha512), NULL, DYNAMIC_TYPE_TMP_BUFFER); if (sha512 == NULL) return MEMORY_E; #endif if ((ret = InitSha512(sha512)) != 0) { CYASSL_MSG("InitSha512 failed"); } else if ((ret = Sha512Update(sha512, data, len)) != 0) { CYASSL_MSG("Sha512Update failed"); } else if ((ret = Sha512Final(sha512, hash)) != 0) { CYASSL_MSG("Sha512Final failed"); } #ifdef CYASSL_SMALL_STACK XFREE(sha512, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return ret; }
static word32 RsaUnPad(const byte *pkcsBlock, unsigned int pkcsBlockLen, byte **output, byte padValue) { word32 maxOutputLen = (pkcsBlockLen > 10) ? (pkcsBlockLen - 10) : 0, invalid = 0, i = 1, outputLen; if (pkcsBlock[0] != 0x0) /* skip past zero */ invalid = 1; pkcsBlock++; pkcsBlockLen--; /* Require block type padValue */ invalid = (pkcsBlock[0] != padValue) || invalid; /* skip past the padding until we find the separator */ while (i<pkcsBlockLen && pkcsBlock[i++]) { /* null body */ } if(!(i==pkcsBlockLen || pkcsBlock[i-1]==0)) { CYASSL_MSG("RsaUnPad error, bad formatting"); return 0; } outputLen = pkcsBlockLen - i; invalid = (outputLen > maxOutputLen) || invalid; if (invalid) { CYASSL_MSG("RsaUnPad error, bad formatting"); return 0; } *output = (byte *)(pkcsBlock + i); return outputLen; }
int Sha384Hash(const byte* data, word32 len, byte* hash) { int ret = 0; #ifdef CYASSL_SMALL_STACK Sha384* sha384; #else Sha384 sha384[1]; #endif #ifdef CYASSL_SMALL_STACK sha384 = (Sha384*)XMALLOC(sizeof(Sha384), NULL, DYNAMIC_TYPE_TMP_BUFFER); if (sha384 == NULL) return MEMORY_E; #endif if ((ret = InitSha384(sha384)) != 0) { CYASSL_MSG("InitSha384 failed"); } else if ((ret = Sha384Update(sha384, data, len)) != 0) { CYASSL_MSG("Sha384Update failed"); } else if ((ret = Sha384Final(sha384, hash)) != 0) { CYASSL_MSG("Sha384Final failed"); } #ifdef CYASSL_SMALL_STACK XFREE(sha384, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return ret; }
static void Arc4CaviumProcess(Arc4* arc4, byte* out, const byte* in, word32 length) { word offset = 0; word32 requestId; while (length > CYASSL_MAX_16BIT) { word16 slen = (word16)CYASSL_MAX_16BIT; if (CspEncryptRc4(CAVIUM_BLOCKING, arc4->contextHandle,CAVIUM_UPDATE, slen, (byte*)in + offset, out + offset, &requestId, arc4->devId) != 0) { CYASSL_MSG("Bad Cavium Arc4 Encrypt"); } length -= CYASSL_MAX_16BIT; offset += CYASSL_MAX_16BIT; } if (length) { word16 slen = (word16)length; if (CspEncryptRc4(CAVIUM_BLOCKING, arc4->contextHandle,CAVIUM_UPDATE, slen, (byte*)in + offset, out + offset, &requestId, arc4->devId) != 0) { CYASSL_MSG("Bad Cavium Arc4 Encrypt"); } } }
/* Free all CRL resources */ void FreeCRL(CYASSL_CRL* crl, int dynamic) { CRL_Entry* tmp = crl->crlList; CYASSL_ENTER("FreeCRL"); if (crl->monitors[0].path) XFREE(crl->monitors[0].path, NULL, DYNAMIC_TYPE_CRL_MONITOR); if (crl->monitors[1].path) XFREE(crl->monitors[1].path, NULL, DYNAMIC_TYPE_CRL_MONITOR); while(tmp) { CRL_Entry* next = tmp->next; FreeCRL_Entry(tmp); XFREE(tmp, NULL, DYNAMIC_TYPE_CRL_ENTRY); tmp = next; } #ifdef HAVE_CRL_MONITOR if (crl->tid != 0) { CYASSL_MSG("stopping monitor thread"); if (StopMonitor(crl->mfd) == 0) pthread_join(crl->tid, NULL); else { CYASSL_MSG("stop monitor failed, cancel instead"); pthread_cancel(crl->tid); } } #endif FreeMutex(&crl->crlLock); if (dynamic) /* free self */ XFREE(crl, NULL, DYNAMIC_TYPE_CRL); }
static OCSP_Entry* find_ocsp_entry(CYASSL_OCSP* ocsp, DecodedCert* cert) { OCSP_Entry* entry = ocsp->ocspList; while (entry) { if (XMEMCMP(entry->issuerHash, cert->issuerHash, SHA_DIGEST_SIZE) == 0 && XMEMCMP(entry->issuerKeyHash, cert->issuerKeyHash, SHA_DIGEST_SIZE) == 0) { CYASSL_MSG("Found OCSP responder"); break; } else { entry = entry->next; } } if (entry == NULL) { CYASSL_MSG("Add a new OCSP entry"); entry = (OCSP_Entry*)XMALLOC(sizeof(OCSP_Entry), NULL, DYNAMIC_TYPE_OCSP_ENTRY); if (entry != NULL) { InitOCSP_Entry(entry, cert); entry->next = ocsp->ocspList; ocsp->ocspList = entry; } } return entry; }
/* Add Decoded CRL, 0 on success */ static int AddCRL(CYASSL_CRL* crl, DecodedCRL* dcrl) { CRL_Entry* crle; CYASSL_ENTER("AddCRL"); crle = (CRL_Entry*)XMALLOC(sizeof(CRL_Entry), NULL, DYNAMIC_TYPE_CRL_ENTRY); if (crle == NULL) { CYASSL_MSG("alloc CRL Entry failed"); return -1; } if (InitCRL_Entry(crle, dcrl) < 0) { CYASSL_MSG("Init CRL Entry failed"); XFREE(crle, NULL, DYNAMIC_TYPE_CRL_ENTRY); return -1; } if (LockMutex(&crl->crlLock) != 0) { CYASSL_MSG("LockMutex failed"); FreeCRL_Entry(crle); XFREE(crle, NULL, DYNAMIC_TYPE_CRL_ENTRY); return BAD_MUTEX_E; } crle->next = crl->crlList; crl->crlList = crle; UnLockMutex(&crl->crlLock); return 0; }
static void Des3_CaviumCbcDecrypt(Des3* des3, byte* out, const byte* in, word32 length) { word32 requestId; word offset = 0; while (length > CYASSL_MAX_16BIT) { word16 slen = (word16)CYASSL_MAX_16BIT; XMEMCPY(des3->tmp, in + offset + slen - DES_BLOCK_SIZE, DES_BLOCK_SIZE); if (CspDecrypt3Des(CAVIUM_BLOCKING, des3->contextHandle, CAVIUM_NO_UPDATE, slen, (byte*)in+offset, out+offset, (byte*)des3->reg, (byte*)des3->key[0], &requestId, des3->devId) != 0) { CYASSL_MSG("Bad Cavium 3Des Decrypt"); } length -= CYASSL_MAX_16BIT; offset += CYASSL_MAX_16BIT; XMEMCPY(des3->reg, des3->tmp, DES_BLOCK_SIZE); } if (length) { word16 slen = (word16)length; XMEMCPY(des3->tmp, in + offset + slen - DES_BLOCK_SIZE,DES_BLOCK_SIZE); if (CspDecrypt3Des(CAVIUM_BLOCKING, des3->contextHandle, CAVIUM_NO_UPDATE, slen, (byte*)in+offset, out+offset, (byte*)des3->reg, (byte*)des3->key[0], &requestId, des3->devId) != 0) { CYASSL_MSG("Bad Cavium 3Des Decrypt"); } XMEMCPY(des3->reg, des3->tmp, DES_BLOCK_SIZE); } }
int Sha256Hash(const byte* data, word32 len, byte* hash) { int ret = 0; #ifdef CYASSL_SMALL_STACK Sha256* sha256; #else Sha256 sha256[1]; #endif #ifdef CYASSL_SMALL_STACK sha256 = (Sha256*)XMALLOC(sizeof(Sha256), NULL, DYNAMIC_TYPE_TMP_BUFFER); if (sha256 == NULL) return MEMORY_E; #endif if ((ret = InitSha256(sha256)) != 0) { CYASSL_MSG("InitSha256 failed"); } else if ((ret = Sha256Update(sha256, data, len)) != 0) { CYASSL_MSG("Sha256Update failed"); } else if ((ret = Sha256Final(sha256, hash)) != 0) { CYASSL_MSG("Sha256Final failed"); } #ifdef CYASSL_SMALL_STACK XFREE(sha256, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return ret; }
static void HmacCaviumUpdate(Hmac* hmac, const byte* msg, word32 length) { word16 add = (word16)length; word32 total; byte* tmp; if (length > CYASSL_MAX_16BIT) { CYASSL_MSG("Too big msg for cavium hmac"); return; } if (hmac->innerHashKeyed == 0) { /* starting new */ hmac->dataLen = 0; hmac->innerHashKeyed = 1; } total = add + hmac->dataLen; if (total > CYASSL_MAX_16BIT) { CYASSL_MSG("Too big msg for cavium hmac"); return; } tmp = XMALLOC(hmac->dataLen + add, NULL,DYNAMIC_TYPE_CAVIUM_TMP); if (tmp == NULL) { CYASSL_MSG("Out of memory for cavium update"); return; } if (hmac->dataLen) XMEMCPY(tmp, hmac->data, hmac->dataLen); XMEMCPY(tmp + hmac->dataLen, msg, add); hmac->dataLen += add; XFREE(hmac->data, NULL, DYNAMIC_TYPE_CAVIUM_TMP); hmac->data = tmp; }
static int http_ocsp_transaction(CYASSL_OCSP* ocsp, DecodedCert* cert, byte* ocspReqBuf, int ocspReqSz, byte** ocspRespBuf) { SOCKET_T sfd = -1; byte httpBuf[SCRATCH_BUFFER_SIZE]; int httpBufSz = SCRATCH_BUFFER_SIZE; char domainName[80], path[80]; int port, ocspRespSz; if (ocsp->useOverrideUrl || cert->extAuthInfo == NULL) { if (ocsp->overrideName != NULL) { XMEMCPY(domainName, ocsp->overrideName, 80); XMEMCPY(path, ocsp->overridePath, 80); port = ocsp->overridePort; } else return OCSP_NEED_URL; } else { if (!decode_url((const char*)cert->extAuthInfo, cert->extAuthInfoSz, domainName, path, &port)) return OCSP_NEED_URL; } httpBufSz = build_http_request(domainName, path, ocspReqSz, httpBuf, httpBufSz); tcp_connect(&sfd, domainName, port); if (sfd > 0) { int written; written = (int)write(sfd, httpBuf, httpBufSz); if (written == httpBufSz) { written = (int)write(sfd, ocspReqBuf, ocspReqSz); if (written == ocspReqSz) { httpBufSz = (int)read(sfd, httpBuf, SCRATCH_BUFFER_SIZE); if (httpBufSz > 0) { ocspRespSz = decode_http_response(httpBuf, httpBufSz, ocspRespBuf); } } } close(sfd); if (ocspRespSz == 0) { CYASSL_MSG("HTTP response was not OK, no OCSP response"); return OCSP_LOOKUP_FAIL; } } else { CYASSL_MSG("OCSP Responder connection failed"); return OCSP_LOOKUP_FAIL; } return ocspRespSz; }
/* Load CRL File of type, SSL_SUCCESS on ok */ int BufferLoadCRL(CYASSL_CRL* crl, const byte* buff, long sz, int type) { int ret = SSL_SUCCESS; const byte* myBuffer = buff; /* if DER ok, otherwise switch */ buffer der; DecodedCRL dcrl; der.buffer = NULL; CYASSL_ENTER("BufferLoadCRL"); if (crl == NULL || buff == NULL || sz == 0) return BAD_FUNC_ARG; if (type == SSL_FILETYPE_PEM) { int eccKey = 0; /* not used */ EncryptedInfo info; info.ctx = NULL; ret = PemToDer(buff, sz, CRL_TYPE, &der, NULL, &info, &eccKey); if (ret == 0) { myBuffer = der.buffer; sz = der.length; } else { CYASSL_MSG("Pem to Der failed"); return -1; } } InitDecodedCRL(&dcrl); ret = ParseCRL(&dcrl, myBuffer, (word32)sz, crl->cm); if (ret != 0) { CYASSL_MSG("ParseCRL error"); } else { ret = AddCRL(crl, &dcrl); if (ret != 0) { CYASSL_MSG("AddCRL error"); } } FreeDecodedCRL(&dcrl); if (der.buffer) XFREE(der.buffer, NULL, DYNAMIC_TYPE_CRL); if (ret == 0) return SSL_SUCCESS; /* convert */ return ret; }
/* The NetX receive callback * return : bytes read, or error */ int NetX_Receive(CYASSL *ssl, char *buf, int sz, void *ctx) { NetX_Ctx* nxCtx = (NetX_Ctx*)ctx; ULONG left; ULONG total; ULONG copied = 0; UINT status; if (nxCtx == NULL || nxCtx->nxSocket == NULL) { CYASSL_MSG("NetX Recv NULL parameters"); return CYASSL_CBIO_ERR_GENERAL; } if (nxCtx->nxPacket == NULL) { status = nx_tcp_socket_receive(nxCtx->nxSocket, &nxCtx->nxPacket, nxCtx->nxWait); if (status != NX_SUCCESS) { CYASSL_MSG("NetX Recv receive error"); return CYASSL_CBIO_ERR_GENERAL; } } if (nxCtx->nxPacket) { status = nx_packet_length_get(nxCtx->nxPacket, &total); if (status != NX_SUCCESS) { CYASSL_MSG("NetX Recv length get error"); return CYASSL_CBIO_ERR_GENERAL; } left = total - nxCtx->nxOffset; status = nx_packet_data_extract_offset(nxCtx->nxPacket, nxCtx->nxOffset, buf, sz, &copied); if (status != NX_SUCCESS) { CYASSL_MSG("NetX Recv data extract offset error"); return CYASSL_CBIO_ERR_GENERAL; } nxCtx->nxOffset += copied; if (copied == left) { CYASSL_MSG("NetX Recv Drained packet"); nx_packet_release(nxCtx->nxPacket); nxCtx->nxPacket = NULL; nxCtx->nxOffset = 0; } } return copied; }
/*** tcp_connect is actually associated with following syassl_tcp_connect. ***/ int Cyassl_connect(int sd, const struct sockaddr* sa, int sz) { int ret = 0 ; #if defined(CYASSL_KEIL_TCP_NET) SOCKADDR_IN addr ; addr = *(SOCKADDR_IN *)sa ; do { #undef connect /* Go to KEIL TCPnet connect */ ret = connect(sd, (SOCKADDR *)&addr, sizeof(addr)) ; os_dly_wait(50); } while(ret == SCK_EWOULDBLOCK) ; #ifdef DEBUG_CYASSL { char msg[50] ; sprintf(msg, "BSD Connect return code: %d\n", ret) ; CYASSL_MSG(msg) ; } #endif #endif /* CYASSL_KEIL_TCP_NET */ return(ret ) ; }
struct tm *Cyassl_MDK_gmtime(const time_t *c) { static struct tm date ; RTC_TIME_Type RTCFullTime; RTC_GetFullTime (LPC_RTC, &RTCFullTime); date.tm_year = RTCFullTime.YEAR + 100 ; date.tm_mon = RTCFullTime.MONTH - 1 ; date.tm_mday = RTCFullTime.DOM ; date.tm_hour = RTCFullTime.HOUR ; date.tm_min = RTCFullTime.MIN ; date.tm_sec = RTCFullTime.SEC ; #if defined(DEBUG_CYASSL) { extern void CYASSL_MSG(char *msg) ; char msg[100] ; sprintf(msg, "Debug::Cyassl_KEIL_gmtime(DATE=/%4d/%02d/%02d TIME=%02d:%02d:%02d)\n", RTCFullTime.YEAR+2000, RTCFullTime.MONTH, RTCFullTime.DOM, RTCFullTime.HOUR, RTCFullTime.MIN, RTCFullTime.SEC) ; CYASSL_MSG(msg) ; } #endif return(&date) ; }
static INLINE void tcp_socket(SOCKET_T* sockfd, SOCKADDR_IN_T* addr, const char* peer, word16 port) { const char* host = peer; /* peer could be in human readable form */ if (peer != INADDR_ANY && isalpha(peer[0])) { struct hostent* entry = gethostbyname(peer); if (entry) { struct sockaddr_in tmp; memset(&tmp, 0, sizeof(struct sockaddr_in)); memcpy(&tmp.sin_addr.s_addr, entry->h_addr_list[0], entry->h_length); host = inet_ntoa(tmp.sin_addr); } else { CYASSL_MSG("no entry for host"); } } *sockfd = socket(AF_INET_V, SOCK_STREAM, 0); memset(addr, 0, sizeof(SOCKADDR_IN_T)); addr->sin_family = AF_INET_V; addr->sin_port = htons(port); if (host == INADDR_ANY) addr->sin_addr.s_addr = INADDR_ANY; else addr->sin_addr.s_addr = inet_addr(host); }
struct tm *Cyassl_MDK_gmtime(const time_t *c) { RTC_TimeTypeDef RTC_Time ; RTC_DateTypeDef RTC_Date ; static struct tm date ; RTC_GetTime(RTC_Format_BIN, &RTC_Time) ; RTC_GetDate(RTC_Format_BIN, &RTC_Date) ; date.tm_year = RTC_Date.RTC_Year + 100 ; date.tm_mon = RTC_Date.RTC_Month - 1 ; date.tm_mday = RTC_Date.RTC_Date ; date.tm_hour = RTC_Time.RTC_Hours ; date.tm_min = RTC_Time.RTC_Minutes ; date.tm_sec = RTC_Time.RTC_Seconds ; #if defined(DEBUG_CYASSL) { char msg[100] ; sprintf(msg, "Debug::Cyassl_KEIL_gmtime(DATE=/%4d/%02d/%02d TIME=%02d:%02d:%02d)\n", RTC_Date.RTC_Year+2000, RTC_Date.RTC_Month, RTC_Date.RTC_Date, RTC_Time.RTC_Hours, RTC_Time.RTC_Minutes, RTC_Time.RTC_Seconds) ; CYASSL_MSG(msg) ; } #endif return(&date) ; }
/* true or false, zero for error */ static int SetPrefix(byte* sha_input, int idx) { switch (idx) { case 0: XMEMCPY(sha_input, "A", 1); break; case 1: XMEMCPY(sha_input, "BB", 2); break; case 2: XMEMCPY(sha_input, "CCC", 3); break; case 3: XMEMCPY(sha_input, "DDDD", 4); break; case 4: XMEMCPY(sha_input, "EEEEE", 5); break; case 5: XMEMCPY(sha_input, "FFFFFF", 6); break; case 6: XMEMCPY(sha_input, "GGGGGGG", 7); break; default: CYASSL_MSG("Set Prefix error, bad input"); return 0; } return 1; }
int ShaHash(const byte* data, word32 len, byte* hash) { int ret = 0; #ifdef CYASSL_SMALL_STACK Sha* sha; #else Sha sha[1]; #endif #ifdef CYASSL_SMALL_STACK sha = (Sha*)XMALLOC(sizeof(Sha), NULL, DYNAMIC_TYPE_TMP_BUFFER); if (sha == NULL) return MEMORY_E; #endif if ((ret = InitSha(sha)) != 0) { CYASSL_MSG("InitSha failed"); } else { ShaUpdate(sha, data, len); ShaFinal(sha, hash); } #ifdef CYASSL_SMALL_STACK XFREE(sha, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return ret; }
/* The DTLS Generate Cookie callback * return : number of bytes copied into buf, or error */ int EmbedGenerateCookie(CYASSL* ssl, byte *buf, int sz, void *ctx) { int sd = ssl->wfd; struct sockaddr_storage peer; XSOCKLENT peerSz = sizeof(peer); byte digest[SHA_DIGEST_SIZE]; int ret = 0; (void)ctx; XMEMSET(&peer, 0, sizeof(peer)); if (getpeername(sd, (struct sockaddr*)&peer, &peerSz) != 0) { CYASSL_MSG("getpeername failed in EmbedGenerateCookie"); return GEN_COOKIE_E; } ret = ShaHash((byte*)&peer, peerSz, digest); if (ret != 0) return ret; if (sz > SHA_DIGEST_SIZE) sz = SHA_DIGEST_SIZE; XMEMCPY(buf, digest, sz); return sz; }
/*** This is the parent task entry ***/ void main_task (void) { #ifdef CYASSL_KEIL_TCP_NET init_TcpNet (); os_tsk_create (tcp_tick, 2); os_tsk_create (tcp_poll, 1); #endif #ifdef CYASSL_MDK_SHELL #ifdef HAVE_KEIL_RTX os_tsk_create_user(shell_main, 1, Shell_stack, SHELL_STACKSIZE) ; #else shell_main() ; #endif #else /************************************/ /*** USER APPLICATION HERE ***/ /************************************/ printf("USER LOGIC STARTED\n") ; #endif #ifdef HAVE_KEIL_RTX CYASSL_MSG("Terminating tcp_main\n") ; os_tsk_delete_self (); #endif }
/* read in new CRL entries and save new list */ static int SwapLists(CYASSL_CRL* crl) { int ret; CYASSL_CRL tmp; CRL_Entry* newList; if (InitCRL(&tmp, crl->cm) < 0) { CYASSL_MSG("Init tmp CRL failed"); return -1; } if (crl->monitors[0].path) { ret = LoadCRL(&tmp, crl->monitors[0].path, SSL_FILETYPE_PEM, 0); if (ret != SSL_SUCCESS) { CYASSL_MSG("PEM LoadCRL on dir change failed"); FreeCRL(&tmp, 0); return -1; } } if (crl->monitors[1].path) { ret = LoadCRL(&tmp, crl->monitors[1].path, SSL_FILETYPE_ASN1, 0); if (ret != SSL_SUCCESS) { CYASSL_MSG("DER LoadCRL on dir change failed"); FreeCRL(&tmp, 0); return -1; } } if (LockMutex(&crl->crlLock) != 0) { CYASSL_MSG("LockMutex failed"); FreeCRL(&tmp, 0); return -1; } newList = tmp.crlList; /* swap lists */ tmp.crlList = crl->crlList; crl->crlList = newList; UnLockMutex(&crl->crlLock); FreeCRL(&tmp, 0); return 0; }
/*----------------------------------------------------------------------------- * TCP/IP tasks *----------------------------------------------------------------------------*/ void tcp_poll (void const *arg) { CYASSL_MSG("TCP polling started.\n") ; while (1) { net_main (); osDelay(100) ; } }
static void Arc4CaviumSetKey(Arc4* arc4, const byte* key, word32 length) { word32 requestId; if (CspInitializeRc4(CAVIUM_BLOCKING, arc4->contextHandle, length, (byte*)key, &requestId, arc4->devId) != 0) { CYASSL_MSG("Bad Cavium Arc4 Init"); } }
static INLINE void tcp_connect(SOCKET_T* sockfd, const char* ip, word16 port) { SOCKADDR_IN_T addr; tcp_socket(sockfd, &addr, ip, port); if (connect(*sockfd, (const struct sockaddr*)&addr, sizeof(addr)) != 0) { CYASSL_MSG("tcp connect failed"); } }
static int StartMonitorCRL(CYASSL_CRL* crl) { (void)crl; CYASSL_ENTER("StartMonitorCRL"); CYASSL_MSG("Not compiled in"); return NOT_COMPILED_IN; }
static INLINE int tcp_connect(SOCKET_T* sockfd, const char* ip, word16 port) { SOCKADDR_IN_T addr; const char* host = ip; /* peer could be in human readable form */ if (ip != INADDR_ANY && isalpha(ip[0])) { struct hostent* entry = gethostbyname(ip); if (entry) { struct sockaddr_in tmp; XMEMSET(&tmp, 0, sizeof(struct sockaddr_in)); XMEMCPY(&tmp.sin_addr.s_addr, entry->h_addr_list[0], entry->h_length); host = inet_ntoa(tmp.sin_addr); } else { CYASSL_MSG("no addr entry for OCSP responder"); return -1; } } *sockfd = socket(AF_INET_V, SOCK_STREAM, 0); if (*sockfd < 0) { CYASSL_MSG("bad socket fd, out of fds?"); return -1; } XMEMSET(&addr, 0, sizeof(SOCKADDR_IN_T)); addr.sin_family = AF_INET_V; addr.sin_port = htons(port); if (host == INADDR_ANY) addr.sin_addr.s_addr = INADDR_ANY; else addr.sin_addr.s_addr = inet_addr(host); if (connect(*sockfd, (const struct sockaddr*)&addr, sizeof(addr)) != 0) { CYASSL_MSG("OCSP responder tcp connect failed"); return -1; } return 0; }
__task void tcp_poll (void) { CYASSL_MSG("TCP polling started.\n") ; while (1) { main_TcpNet (); #if defined (HAVE_KEIL_RTX) os_tsk_pass (); #endif } }
static void HmacCaviumFinal(Hmac* hmac, byte* hash) { word32 requestId; if (CspHmac(CAVIUM_BLOCKING, hmac->type, NULL, hmac->keyLen, (byte*)hmac->ipad, hmac->dataLen, hmac->data, hash, &requestId, hmac->devId) != 0) { CYASSL_MSG("Cavium Hmac failed"); } hmac->innerHashKeyed = 0; /* tell update to start over if used again */ }
/* shutdown monitor thread, 0 on success */ static int StopMonitor(int mfd) { word64 w64 = 1; /* write to our custom event */ if (write(mfd, &w64, sizeof(w64)) < 0) { CYASSL_MSG("StopMonitor write failed"); return -1; } return 0; }