SharkSSL™ Embedded SSL/TLS Stack
selib.h
1/*
2 * ____ _________ __ _
3 * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____
4 * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/
5 * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__
6 * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/
7 * /____/
8 *
9 * SharkSSL Embedded SSL/TLS Stack
10 ****************************************************************************
11 * PROGRAM MODULE
12 *
13 * $Id: selib.h 5209 2022-07-31 18:06:02Z gianluca $
14 *
15 * COPYRIGHT: Real Time Logic LLC, 2013 - 2022
16 *
17 * This software is copyrighted by and is the sole property of Real
18 * Time Logic LLC. All rights, title, ownership, or other interests in
19 * the software remain the property of Real Time Logic LLC. This
20 * software may only be used in accordance with the terms and
21 * conditions stipulated in the corresponding license agreement under
22 * which the software has been supplied. Any unauthorized use,
23 * duplication, transmission, distribution, or disclosure of this
24 * software is expressly forbidden.
25 *
26 * This Copyright notice may not be removed or modified without prior
27 * written consent of Real Time Logic LLC.
28 *
29 * Real Time Logic LLC. reserves the right to modify this software
30 * without notice.
31 *
32 * http://realtimelogic.com
33 * http://sharkssl.com
34 ****************************************************************************
35 *
36 */
37
38#ifndef _selib_h
39#define _selib_h
40
41#include <SharkSSL.h>
42#include <SharkSslEx.h>
43
44/* secure version of selib */
45#define MS_SEC
46
47
73#define INFINITE_TMO (~((U32)0))
74
75#include <selibplat.h>
76
77#ifndef XPRINTF
78#if HOST_PLATFORM
79#define XPRINTF 1
80#else
81#define XPRINTF 0
82#endif
83#endif
84
85#include <string.h>
86#if XPRINTF
87#include <stdarg.h>
88#endif
89
90#ifndef SE_CTX
91#define SeCtx void
92#endif
93
96#ifndef NO_BSD_SOCK
102#define SOCKET int
103#endif
104
105#ifndef SOCKET_constructor
106#define SOCKET_constructor(o, ctx) (void)ctx,memset(o,0,sizeof(SOCKET))
107#endif
108
109
110#ifdef __cplusplus
111extern "C" {
112#endif
113
116#if XPRINTF
117void se_disableTrace(int disable);
118#else
119#define se_disableTrace(disable)
120#endif
121
122
125#if XPRINTF && SHARKSSL_ENABLE_INFO_API
126void printCiphersuite(U16 cipherSuite);
127#else
128#define printCiphersuite(notused)
129#endif
130
131
162 SharkSslCon *s, SOCKET* sock, U32 timeout, const char* commonName);
163
179int seSec_read(SharkSslCon *s,SOCKET* sock,U8 **buf,U32 timeout);
180
184int seSec_write(SharkSslCon *s, SOCKET* sock, U8* buf, int maxLen);
185
194int se_connect(SOCKET* sock, const char* address, U16 port);
195
204int se_bind(SOCKET* sock, U16 port);
205
215int se_accept(SOCKET** listenSock, U32 timeout, SOCKET** outSock);
216
219void se_close(SOCKET* sock);
220
224
227S32 se_send(SOCKET* sock, const void* buf, U32 len);
228
238S32 se_recv(SOCKET* sock, void* buf, U32 len, U32 timeout);
239
240
241/* Macro function designed for IPv4
242 sock: a pointer to SOCKET
243 buf: a buf large enough to hold 4 bytes
244 status: int pointer: out value is negative on error and 4 (len) on success
245*/
246#ifndef se_getSockName
247#define se_getSockName(sock, buf, status) do { \
248 struct sockaddr_in in; int size=sizeof(struct sockaddr_in); \
249 *(status) = getsockname(*(sock), (struct sockaddr *)&in, &size); \
250 memcpy((buf), &in.sin_addr.s_addr, 4); \
251 if(*(status) == 0) *(status) = 4; \
252} while(0)
253#endif
254
255#if XPRINTF == 1
261#define xprintf(data) _xprintf data
267#ifndef _xprintf /* to handle #define _xprintf printf */
268void _xprintf(const char* fmt, ...);
269#endif
270#else
271#ifndef xprintf
272#define xprintf(data)
273#endif
274#endif
275
277void mainTask(SeCtx* ctx);
278
279#ifdef __cplusplus
280}
281#endif
282
283 /* end group selib */ /* end group Examples */
286
287#endif
struct SharkSslCon SharkSslCon
SharkSslCon is an opaque handle returned by function SharkSsl_createCon.
Definition: SharkSSL.h:553
void se_close(SOCKET *sock)
Close a connected socket connection.
int se_accept(SOCKET **listenSock, U32 timeout, SOCKET **outSock)
Waits for remote connections on the server SOCKET object 'listenSock', initialized by function se_bin...
S32 se_send(SOCKET *sock, const void *buf, U32 len)
Sends data to the connected peer.
int se_connect(SOCKET *sock, const char *address, U16 port)
Initializes a SOCKET object connected to a remote host/address at a given port.
int se_sockValid(SOCKET *sock)
Returns TRUE if socket is valid (connected).
int seSec_read(SharkSslCon *s, SOCKET *sock, U8 **buf, U32 timeout)
Read data from socket stream and decode the encrypted data.
#define printCiphersuite(notused)
Print the selected ciphersuite.
Definition: selib.h:128
int seSec_write(SharkSslCon *s, SOCKET *sock, U8 *buf, int maxLen)
Encrypts and sends encrypted data to the connected peer side.
void mainTask(SeCtx *ctx)
Main entry for all example programs.
int se_bind(SOCKET *sock, U16 port)
Initializes a SOCKET object bound to a local port, ready to accept client connections.
S32 se_recv(SOCKET *sock, void *buf, U32 len, U32 timeout)
Waits for data sent by peer.
int seSec_handshake(SharkSslCon *s, SOCKET *sock, U32 timeout, const char *commonName)
Performs the initial SSL handshaking using an asymmetric cipher in order to establish cipher settings...
void se_disableTrace(int disable)
Disable/enable the trace when XPRINTF is defined.
void _xprintf(const char *fmt,...)
The example code and macro xprintf requires this function when the code is compiled with macro XPRINT...
#define SOCKET
Infinite wait time option for socket read functions.
Definition: selib.h:102
SeCtx structure: See Context Manager and Bare Metal Systems for details.
Definition: SeCtx.h:71