mbedtls: just format related files

method from !46
This commit is contained in:
Wu Jian Gang 2016-09-02 11:31:38 +08:00
parent f4ff32977d
commit fc2bfc1f49
13 changed files with 574 additions and 548 deletions

View File

@ -45,15 +45,19 @@ void esp_aes_init( AES_CTX *ctx )
void esp_aes_free( AES_CTX *ctx )
{
if( ctx == NULL )
if ( ctx == NULL ) {
return;
}
bzero( ctx, sizeof( AES_CTX ) );
AES_LOCK();
AES_GIVE();
if (false == AES_IS_USED())
if (false == AES_IS_USED()) {
ets_aes_disable();
}
AES_UNLOCK();
}
@ -65,6 +69,7 @@ int esp_aes_setkey_enc( AES_CTX *ctx, const unsigned char *key,
{
enum AES_BITS keybit;
uint16_t keybyte = keybits / 8;
switch (keybits) {
case 128:
keybit = AES128;
@ -75,8 +80,10 @@ int esp_aes_setkey_enc( AES_CTX *ctx, const unsigned char *key,
case 256:
keybit = AES256;
break;
default : return( ERR_AES_INVALID_KEY_LENGTH );
default:
return ( ERR_AES_INVALID_KEY_LENGTH );
}
if (ctx->enc.keyflag == false) {
ctx->enc.keyflag = true;
ctx->enc.keybits = keybits;
@ -85,6 +92,7 @@ int esp_aes_setkey_enc( AES_CTX *ctx, const unsigned char *key,
} else {
ets_aes_setkey_enc(key, keybit);
}
return 0;
}
@ -96,6 +104,7 @@ int esp_aes_setkey_dec( AES_CTX *ctx, const unsigned char *key,
{
enum AES_BITS keybit;
uint16_t keybyte = keybits / 8;
switch (keybits) {
case 128:
keybit = AES128;
@ -106,8 +115,10 @@ int esp_aes_setkey_dec( AES_CTX *ctx, const unsigned char *key,
case 256:
keybit = AES256;
break;
default : return( ERR_AES_INVALID_KEY_LENGTH );
default:
return ( ERR_AES_INVALID_KEY_LENGTH );
}
if (ctx->dec.keyflag == false) {
ctx->dec.keyflag = true;
ctx->dec.keybits = keybits;
@ -116,8 +127,8 @@ int esp_aes_setkey_dec( AES_CTX *ctx, const unsigned char *key,
} else {
ets_aes_setkey_dec(key, keybit);
}
return 0;
return 0;
}
static void esp_aes_process_enable(AES_CTX *ctx, int mode)
@ -127,6 +138,7 @@ static void esp_aes_process_enable(AES_CTX *ctx, int mode)
} else {
esp_aes_setkey_dec(ctx, ctx->dec.key, ctx->dec.keybits);
}
return;
}
@ -144,6 +156,7 @@ void esp_aes_encrypt( AES_CTX *ctx,
unsigned char output[16] )
{
ets_aes_crypt(input, output);
return ;
}
@ -157,6 +170,7 @@ void esp_aes_decrypt( AES_CTX *ctx,
unsigned char output[16] )
{
ets_aes_crypt(input, output);
return ;
}
@ -173,10 +187,11 @@ int esp_aes_crypt_ecb( AES_CTX *ctx,
esp_aes_process_enable(ctx, mode);
if( mode == AES_ENCRYPT )
if ( mode == AES_ENCRYPT ) {
esp_aes_encrypt( ctx, input, output );
else
} else {
esp_aes_decrypt( ctx, input, output );
}
esp_aes_process_disable(ctx, mode);
@ -199,18 +214,18 @@ int esp_aes_crypt_cbc( AES_CTX *ctx,
int i;
unsigned char temp[16];
if( length % 16 )
if ( length % 16 ) {
return ( ERR_AES_INVALID_INPUT_LENGTH );
}
if( mode == AES_DECRYPT )
{
while( length > 0 )
{
if ( mode == AES_DECRYPT ) {
while ( length > 0 ) {
memcpy( temp, input, 16 );
esp_aes_crypt_ecb( ctx, mode, input, output );
for( i = 0; i < 16; i++ )
for ( i = 0; i < 16; i++ ) {
output[i] = (unsigned char)( output[i] ^ iv[i] );
}
memcpy( iv, temp, 16 );
@ -218,13 +233,11 @@ int esp_aes_crypt_cbc( AES_CTX *ctx,
output += 16;
length -= 16;
}
}
else
{
while( length > 0 )
{
for( i = 0; i < 16; i++ )
} else {
while ( length > 0 ) {
for ( i = 0; i < 16; i++ ) {
output[i] = (unsigned char)( input[i] ^ iv[i] );
}
esp_aes_crypt_ecb( ctx, mode, output, output );
memcpy( iv, output, 16 );
@ -252,12 +265,11 @@ int esp_aes_crypt_cfb128( AES_CTX *ctx,
int c;
size_t n = *iv_off;
if( mode == AES_DECRYPT )
{
while( length-- )
{
if( n == 0 )
if ( mode == AES_DECRYPT ) {
while ( length-- ) {
if ( n == 0 ) {
esp_aes_crypt_ecb( ctx, AES_ENCRYPT, iv, iv );
}
c = *input++;
*output++ = (unsigned char)( c ^ iv[n] );
@ -265,13 +277,11 @@ int esp_aes_crypt_cfb128( AES_CTX *ctx,
n = ( n + 1 ) & 0x0F;
}
}
else
{
while( length-- )
{
if( n == 0 )
} else {
while ( length-- ) {
if ( n == 0 ) {
esp_aes_crypt_ecb( ctx, AES_ENCRYPT, iv, iv );
}
iv[n] = *output++ = (unsigned char)( iv[n] ^ *input++ );
@ -297,18 +307,19 @@ int esp_aes_crypt_cfb8( AES_CTX *ctx,
unsigned char c;
unsigned char ov[17];
while( length-- )
{
while ( length-- ) {
memcpy( ov, iv, 16 );
esp_aes_crypt_ecb( ctx, AES_ENCRYPT, iv, iv );
if( mode == AES_DECRYPT )
if ( mode == AES_DECRYPT ) {
ov[16] = *input;
}
c = *output++ = (unsigned char)( iv[0] ^ *input++ );
if( mode == AES_ENCRYPT )
if ( mode == AES_ENCRYPT ) {
ov[16] = c;
}
memcpy( iv, ov + 1, 16 );
}
@ -330,15 +341,15 @@ int esp_aes_crypt_ctr( AES_CTX *ctx,
int c, i;
size_t n = *nc_off;
while( length-- )
{
while ( length-- ) {
if ( n == 0 ) {
esp_aes_crypt_ecb( ctx, AES_ENCRYPT, nonce_counter, stream_block );
for ( i = 16; i > 0; i-- )
if( ++nonce_counter[i - 1] != 0 )
if ( ++nonce_counter[i - 1] != 0 ) {
break;
}
}
c = *input++;
*output++ = (unsigned char)( c ^ stream_block[n] );

View File

@ -28,8 +28,9 @@ int esp_crypto_init(void)
failed1:
ESP_DEBUG("esp_crypto_init failed\n");
for (i--; i >= 0; i--)
for (i--; i >= 0; i--) {
vQueueDelete(esp_crypto_mutex[i]);
}
return -1;
}
@ -53,9 +54,10 @@ void esp_crypto_take(unsigned int num)
void esp_crypto_give(unsigned int num)
{
if (esp_crypto_sig[num])
if (esp_crypto_sig[num]) {
esp_crypto_sig[num]--;
}
}
bool esp_crypto_is_used(unsigned int num)
{

View File

@ -53,8 +53,7 @@ typedef struct{
* - to simplify key expansion in the 256-bit case by
* generating an extra round key
*/
typedef struct
{
typedef struct {
int nr; /*!< number of rounds */
uint32_t *rk; /*!< AES round keys */
KEY_CTX enc;

View File

@ -44,15 +44,19 @@ void esp_sha1_init( SHA1_CTX *ctx )
void esp_sha1_free( SHA1_CTX *ctx )
{
if( ctx == NULL )
if ( ctx == NULL ) {
return;
}
bzero( ctx, sizeof( SHA1_CTX ) );
SHA_LOCK();
SHA_GIVE();
if (false == SHA_IS_USED())
if (false == SHA_IS_USED()) {
ets_sha_disable();
}
SHA_UNLOCK();
}
@ -127,15 +131,19 @@ void esp_sha256_process(SHA256_CTX *ctx, const unsigned char data[64])
void esp_sha256_free( SHA256_CTX *ctx )
{
if( ctx == NULL )
if ( ctx == NULL ) {
return;
}
bzero( ctx, sizeof( SHA256_CTX ) );
SHA_LOCK();
SHA_GIVE();
if (false == SHA_IS_USED())
if (false == SHA_IS_USED()) {
ets_sha_disable();
}
SHA_UNLOCK();
}
@ -152,8 +160,7 @@ void esp_sha256_start( SHA256_CTX *ctx, int is224 )
SHA_LOCK();
ets_sha_init(&ctx->context);
if( is224 == 0 )
{
if ( is224 == 0 ) {
/* SHA-256 */
ctx->context_type = SHA256;
} else {
@ -212,15 +219,19 @@ void esp_sha512_process( SHA512_CTX *ctx, const unsigned char data[128] )
void esp_sha512_free( SHA512_CTX *ctx )
{
if( ctx == NULL )
if ( ctx == NULL ) {
return;
}
bzero( ctx, sizeof( SHA512_CTX ) );
SHA_LOCK();
SHA_GIVE();
if (false == SHA_IS_USED())
if (false == SHA_IS_USED()) {
ets_sha_disable();
}
SHA_UNLOCK();
}
@ -237,13 +248,10 @@ void esp_sha512_start( SHA512_CTX *ctx, int is384 )
SHA_LOCK();
ets_sha_init(&ctx->context);
if( is384 == 0 )
{
if ( is384 == 0 ) {
/* SHA-512 */
ctx->context_type = SHA2_512;
}
else
{
} else {
/* SHA-384 */
ctx->context_type = SHA2_384;
}

View File

@ -7,6 +7,7 @@
#include <sys/types.h>
#include <stdlib.h>
#include <stdio.h>
#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
/**
* \brief Entropy poll callback for a hardware source
@ -20,6 +21,7 @@ static int os_get_random(unsigned char *buf, size_t len)
{
int i, j;
unsigned long tmp;
for (i = 0; i < ((len + 3) & ~3) / 4; i ++) {
tmp = rand();
for (j = 0; j < 4; j ++) {
@ -31,6 +33,7 @@ static int os_get_random(unsigned char *buf, size_t len)
}
}
return 0;
}
@ -39,6 +42,7 @@ int mbedtls_hardware_poll( void *data,
{
os_get_random(output, len);
*olen = len;
return 0;
}
#endif

View File

@ -56,10 +56,10 @@ static int net_prepare( void )
!defined(EFI32)
WSADATA wsaData;
if( wsa_init_done == 0 )
{
if( WSAStartup( MAKEWORD(2,0), &wsaData ) != 0 )
if ( wsa_init_done == 0 ) {
if ( WSAStartup( MAKEWORD(2, 0), &wsaData ) != 0 ) {
return ( MBEDTLS_ERR_NET_SOCKET_FAILED );
}
wsa_init_done = 1;
}
@ -72,7 +72,9 @@ static int mbedtls_net_errno(int fd)
{
int sock_errno = 0;
u32_t optlen = sizeof(sock_errno);
getsockopt(fd, SOL_SOCKET, SO_ERROR, &sock_errno, &optlen);
return sock_errno;
}
@ -92,8 +94,9 @@ int mbedtls_net_connect( mbedtls_net_context *ctx, const char *host, const char
int ret;
struct addrinfo hints, *addr_list, *cur;
if( ( ret = net_prepare() ) != 0 )
if ( ( ret = net_prepare() ) != 0 ) {
return ( ret );
}
/* Do name resolution with both IPv6 and IPv4 */
memset( &hints, 0, sizeof( hints ) );
@ -101,23 +104,21 @@ int mbedtls_net_connect( mbedtls_net_context *ctx, const char *host, const char
hints.ai_socktype = proto == MBEDTLS_NET_PROTO_UDP ? SOCK_DGRAM : SOCK_STREAM;
hints.ai_protocol = proto == MBEDTLS_NET_PROTO_UDP ? IPPROTO_UDP : IPPROTO_TCP;
if( getaddrinfo( host, port, &hints, &addr_list ) != 0 )
if ( getaddrinfo( host, port, &hints, &addr_list ) != 0 ) {
return ( MBEDTLS_ERR_NET_UNKNOWN_HOST );
}
/* Try the sockaddrs until a connection succeeds */
ret = MBEDTLS_ERR_NET_UNKNOWN_HOST;
for( cur = addr_list; cur != NULL; cur = cur->ai_next )
{
for ( cur = addr_list; cur != NULL; cur = cur->ai_next ) {
ctx->fd = (int) socket( cur->ai_family, cur->ai_socktype,
cur->ai_protocol );
if( ctx->fd < 0 )
{
if ( ctx->fd < 0 ) {
ret = MBEDTLS_ERR_NET_SOCKET_FAILED;
continue;
}
if( connect( ctx->fd, cur->ai_addr, cur->ai_addrlen ) == 0 )
{
if ( connect( ctx->fd, cur->ai_addr, cur->ai_addrlen ) == 0 ) {
ret = 0;
break;
}
@ -139,8 +140,9 @@ int mbedtls_net_bind( mbedtls_net_context *ctx, const char *bind_ip, const char
int n, ret;
struct addrinfo hints, *addr_list, *cur;
if( ( ret = net_prepare() ) != 0 )
if ( ( ret = net_prepare() ) != 0 ) {
return ( ret );
}
/* Bind to IPv6 and/or IPv4, but only in the desired protocol */
memset( &hints, 0, sizeof( hints ) );
@ -148,17 +150,16 @@ int mbedtls_net_bind( mbedtls_net_context *ctx, const char *bind_ip, const char
hints.ai_socktype = proto == MBEDTLS_NET_PROTO_UDP ? SOCK_DGRAM : SOCK_STREAM;
hints.ai_protocol = proto == MBEDTLS_NET_PROTO_UDP ? IPPROTO_UDP : IPPROTO_TCP;
if( getaddrinfo( bind_ip, port, &hints, &addr_list ) != 0 )
if ( getaddrinfo( bind_ip, port, &hints, &addr_list ) != 0 ) {
return ( MBEDTLS_ERR_NET_UNKNOWN_HOST );
}
/* Try the sockaddrs until a binding succeeds */
ret = MBEDTLS_ERR_NET_UNKNOWN_HOST;
for( cur = addr_list; cur != NULL; cur = cur->ai_next )
{
for ( cur = addr_list; cur != NULL; cur = cur->ai_next ) {
ctx->fd = (int) socket( cur->ai_family, cur->ai_socktype,
cur->ai_protocol );
if( ctx->fd < 0 )
{
if ( ctx->fd < 0 ) {
ret = MBEDTLS_ERR_NET_SOCKET_FAILED;
continue;
}
@ -167,8 +168,7 @@ int mbedtls_net_bind( mbedtls_net_context *ctx, const char *bind_ip, const char
#if SO_REUSE
n = 1;
if ( setsockopt( ctx->fd, SOL_SOCKET, SO_REUSEADDR,
(const char *) &n, sizeof( n ) ) != 0 )
{
(const char *) &n, sizeof( n ) ) != 0 ) {
close( ctx->fd );
ret = MBEDTLS_ERR_NET_SOCKET_FAILED;
continue;
@ -178,18 +178,15 @@ int mbedtls_net_bind( mbedtls_net_context *ctx, const char *bind_ip, const char
struct sockaddr_in *serv_addr = NULL;
serv_addr = (struct sockaddr_in *)cur->ai_addr;
serv_addr->sin_addr.s_addr = htonl(INADDR_ANY); /* Any incoming interface */
if( bind( ctx->fd, (struct sockaddr *)serv_addr, cur->ai_addrlen ) != 0 )
{
if ( bind( ctx->fd, (struct sockaddr *)serv_addr, cur->ai_addrlen ) != 0 ) {
close( ctx->fd );
ret = MBEDTLS_ERR_NET_BIND_FAILED;
continue;
}
/* Listen only makes sense for TCP */
if( proto == MBEDTLS_NET_PROTO_TCP )
{
if( listen( ctx->fd, MBEDTLS_NET_LISTEN_BACKLOG ) != 0 )
{
if ( proto == MBEDTLS_NET_PROTO_TCP ) {
if ( listen( ctx->fd, MBEDTLS_NET_LISTEN_BACKLOG ) != 0 ) {
close( ctx->fd );
ret = MBEDTLS_ERR_NET_LISTEN_FAILED;
continue;
@ -230,13 +227,13 @@ static int net_would_block( const mbedtls_net_context *ctx )
/*
* Never return 'WOULD BLOCK' on a non-blocking socket
*/
if( ( fcntl( ctx->fd, F_GETFL, 0) & O_NONBLOCK ) != O_NONBLOCK )
if ( ( fcntl( ctx->fd, F_GETFL, 0) & O_NONBLOCK ) != O_NONBLOCK ) {
return ( 0 );
}
int error = mbedtls_net_errno(ctx->fd);
switch( error )
{
switch ( error ) {
#if defined EAGAIN
case EAGAIN:
#endif
@ -267,19 +264,15 @@ int mbedtls_net_accept( mbedtls_net_context *bind_ctx,
/* Is this a TCP or UDP socket? */
if ( getsockopt( bind_ctx->fd, SOL_SOCKET, SO_TYPE,
(void *) &type, (socklen_t *) &type_len ) != 0 ||
( type != SOCK_STREAM && type != SOCK_DGRAM ) )
{
( type != SOCK_STREAM && type != SOCK_DGRAM ) ) {
return ( MBEDTLS_ERR_NET_ACCEPT_FAILED );
}
if( type == SOCK_STREAM )
{
if ( type == SOCK_STREAM ) {
/* TCP: actual accept() */
ret = client_ctx->fd = (int) accept( bind_ctx->fd,
(struct sockaddr *) &client_addr, &n );
}
else
{
} else {
/* UDP: wait for a message, but keep it in the queue */
char buf[1] = { 0 };
@ -288,31 +281,30 @@ int mbedtls_net_accept( mbedtls_net_context *bind_ctx,
#if defined(_WIN32)
if ( ret == SOCKET_ERROR &&
WSAGetLastError() == WSAEMSGSIZE )
{
WSAGetLastError() == WSAEMSGSIZE ) {
/* We know buf is too small, thanks, just peeking here */
ret = 0;
}
#endif
}
if( ret < 0 )
{
if( net_would_block( bind_ctx ) != 0 )
if ( ret < 0 ) {
if ( net_would_block( bind_ctx ) != 0 ) {
return ( MBEDTLS_ERR_SSL_WANT_READ );
}
return ( MBEDTLS_ERR_NET_ACCEPT_FAILED );
}
/* UDP: hijack the listening socket to communicate with the client,
* then bind a new socket to accept new connections */
if( type != SOCK_STREAM )
{
if ( type != SOCK_STREAM ) {
struct sockaddr_in local_addr;
int one = 1;
if( connect( bind_ctx->fd, (struct sockaddr *) &client_addr, n ) != 0 )
if ( connect( bind_ctx->fd, (struct sockaddr *) &client_addr, n ) != 0 ) {
return ( MBEDTLS_ERR_NET_ACCEPT_FAILED );
}
client_ctx->fd = bind_ctx->fd;
bind_ctx->fd = -1; /* In case we exit early */
@ -323,24 +315,22 @@ int mbedtls_net_accept( mbedtls_net_context *bind_ctx,
( bind_ctx->fd = (int) socket( AF_INET,
SOCK_DGRAM, IPPROTO_UDP ) ) < 0 ||
setsockopt( bind_ctx->fd, SOL_SOCKET, SO_REUSEADDR,
(const char *) &one, sizeof( one ) ) != 0 )
{
(const char *) &one, sizeof( one ) ) != 0 ) {
return ( MBEDTLS_ERR_NET_SOCKET_FAILED );
}
if( bind( bind_ctx->fd, (struct sockaddr *) &local_addr, n ) != 0 )
{
if ( bind( bind_ctx->fd, (struct sockaddr *) &local_addr, n ) != 0 ) {
return ( MBEDTLS_ERR_NET_BIND_FAILED );
}
}
if( client_ip != NULL )
{
if ( client_ip != NULL ) {
struct sockaddr_in *addr4 = (struct sockaddr_in *) &client_addr;
*ip_len = sizeof( addr4->sin_addr.s_addr );
if( buf_size < *ip_len )
if ( buf_size < *ip_len ) {
return ( MBEDTLS_ERR_NET_BUFFER_TOO_SMALL );
}
memcpy( client_ip, &addr4->sin_addr.s_addr, *ip_len );
}
@ -402,27 +392,31 @@ int mbedtls_net_recv( void *ctx, unsigned char *buf, size_t len )
int fd = ((mbedtls_net_context *) ctx)->fd;
int error = 0;
if( fd < 0 )
if ( fd < 0 ) {
return ( MBEDTLS_ERR_NET_INVALID_CONTEXT );
}
ret = (int) read( fd, buf, len );
if( ret < 0 )
{
if( net_would_block( ctx ) != 0 )
if ( ret < 0 ) {
if ( net_would_block( ctx ) != 0 ) {
return ( MBEDTLS_ERR_SSL_WANT_READ );
}
error = mbedtls_net_errno(fd);
#if ( defined(_WIN32) || defined(_WIN32_WCE) ) && !defined(EFIX64) && \
!defined(EFI32)
if( WSAGetLastError() == WSAECONNRESET )
if ( WSAGetLastError() == WSAECONNRESET ) {
return ( MBEDTLS_ERR_NET_CONN_RESET );
}
#else
if( error == EPIPE || error == ECONNRESET )
if ( error == EPIPE || error == ECONNRESET ) {
return ( MBEDTLS_ERR_NET_CONN_RESET );
}
if( error == EINTR )
if ( error == EINTR ) {
return ( MBEDTLS_ERR_SSL_WANT_READ );
}
#endif
return ( MBEDTLS_ERR_NET_RECV_FAILED );
@ -442,8 +436,9 @@ int mbedtls_net_recv_timeout( void *ctx, unsigned char *buf, size_t len,
fd_set read_fds;
int fd = ((mbedtls_net_context *) ctx)->fd;
if( fd < 0 )
if ( fd < 0 ) {
return ( MBEDTLS_ERR_NET_INVALID_CONTEXT );
}
FD_ZERO( &read_fds );
FD_SET( fd, &read_fds );
@ -454,18 +449,20 @@ int mbedtls_net_recv_timeout( void *ctx, unsigned char *buf, size_t len,
ret = select( fd + 1, &read_fds, NULL, NULL, timeout == 0 ? NULL : &tv );
/* Zero fds ready means we timed out */
if( ret == 0 )
if ( ret == 0 ) {
return ( MBEDTLS_ERR_SSL_TIMEOUT );
}
if( ret < 0 )
{
if ( ret < 0 ) {
#if ( defined(_WIN32) || defined(_WIN32_WCE) ) && !defined(EFIX64) && \
!defined(EFI32)
if( WSAGetLastError() == WSAEINTR )
if ( WSAGetLastError() == WSAEINTR ) {
return ( MBEDTLS_ERR_SSL_WANT_READ );
}
#else
if( errno == EINTR )
if ( errno == EINTR ) {
return ( MBEDTLS_ERR_SSL_WANT_READ );
}
#endif
return ( MBEDTLS_ERR_NET_RECV_FAILED );
@ -485,27 +482,31 @@ int mbedtls_net_send( void *ctx, const unsigned char *buf, size_t len )
int error = 0;
if( fd < 0 )
if ( fd < 0 ) {
return ( MBEDTLS_ERR_NET_INVALID_CONTEXT );
}
ret = (int) write( fd, buf, len );
if( ret < 0 )
{
if( net_would_block( ctx ) != 0 )
if ( ret < 0 ) {
if ( net_would_block( ctx ) != 0 ) {
return ( MBEDTLS_ERR_SSL_WANT_WRITE );
}
error = mbedtls_net_errno(fd);
#if ( defined(_WIN32) || defined(_WIN32_WCE) ) && !defined(EFIX64) && \
!defined(EFI32)
if( WSAGetLastError() == WSAECONNRESET )
if ( WSAGetLastError() == WSAECONNRESET ) {
return ( MBEDTLS_ERR_NET_CONN_RESET );
}
#else
if( error == EPIPE || error == ECONNRESET )
if ( error == EPIPE || error == ECONNRESET ) {
return ( MBEDTLS_ERR_NET_CONN_RESET );
}
if( error == EINTR )
if ( error == EINTR ) {
return ( MBEDTLS_ERR_SSL_WANT_WRITE );
}
#endif
return ( MBEDTLS_ERR_NET_SEND_FAILED );
@ -519,8 +520,9 @@ int mbedtls_net_send( void *ctx, const unsigned char *buf, size_t len )
*/
void mbedtls_net_free( mbedtls_net_context *ctx )
{
if( ctx->fd == -1 )
if ( ctx->fd == -1 ) {
return;
}
shutdown( ctx->fd, 2 );
close( ctx->fd );