I use STM32 configuration MBEDTLS function, I use the WIFI module to communication, I configuration the underlying function of sending and receiving module, time, etc., I set the maximum connection length MBEDTLS_SSL_MAX_CONTENT_LEN is 2048 bytes, when I connect to our server, with WIFI module ,the situation is shake hands connection is successful each time , however, after shake hands ,sending and receiving data will appear to verify the MAC errors or receive an invalid session, during CCM or GCM mode, data decryption error, two errors occur:
MBEDTLS_ERR_SSL_INVALID_MAC -0x7180 /< Verification of the message MAC failed. */MBEDTLS_ERR_SSL_INVALID_RECORD -0x7200 /< An invalid SSL record was received. */
As soon as the errors occurs, It’s not going back to normal communication until I reconnect and shake hands. I think sometimes it have something errors, but it should can go back to normal. The connection is very unstable. Any good suggestions, my configuration is as follows:
//TIME Support
#define MBEDTLS_HAVE_TIME
#define MBEDTLS_HAVE_TIME_DATE
#define MBEDTLS_TIMING_C
#define MBEDTLS_TIMING_ALT
// RNG Support
#define MBEDTLS_NO_PLATFORM_ENTROPY
#define MBEDTLS_ENTROPY_C
#define MBEDTLS_CTR_DRBG_C
#define MBEDTLS_HMAC_DRBG_C
#define MBEDTLS_ENTROPY_HARDWARE_ALT
#define MBEDTLS_ENTROPY_FORCE_SHA256
#define MBEDTLS_ENTROPY_MAX_SOURCES 2
/* mbed TLS feature support */
#define MBEDTLS_SSL_PROTO_TLS1_2
#define MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
#define MBEDTLS_ECP_DP_SECP256R1_ENABLED
#define MBEDTLS_CIPHER_MODE_CBC
#define MBEDTLS_CIPHER_MODE_CFB
#define MBEDTLS_CIPHER_MODE_CTR
#define MBEDTLS_SHA1_C
#define MBEDTLS_RSA_C
#define MBEDTLS_PKCS1_V21
#define MBEDTLS_PKCS1_V15
#define MBEDTLS_BIGNUM_C
#define MBEDTLS_AES_C
#define MBEDTLS_CCM_C
#define MBEDTLS_GCM_C
#define MBEDTLS_DES_C
#define MBEDTLS_SHA256_C
#define MBEDTLS_MD_C
#define MBEDTLS_CIPHER_C
#define MBEDTLS_ASN1_PARSE_C
#define MBEDTLS_ASN1_WRITE_C
#define MBEDTLS_OID_C
#define MBEDTLS_PK_PARSE_C
#define MBEDTLS_PK_C
#define MBEDTLS_X509_CRT_PARSE_C
#define MBEDTLS_X509_USE_C
#define MBEDTLS_X509_CREATE_C
#define MBEDTLS_X509_CRT_WRITE_C
#define MBEDTLS_PEM_PARSE_C
#define MBEDTLS_BASE64_C
#define MBEDTLS_ECDSA_DETERMINISTIC
#define MBEDTLS_SSL_SERVER_NAME_INDICATION
#define MBEDTLS_PK_WRITE_C
/* Save RAM at the expense of ROM */
#define MBEDTLS_AES_ROM_TABLES
#define MBEDTLS_SSL_MAX_CONTENT_LEN 2048
/* Save RAM by adjusting to our exact needs */
#define MBEDTLS_ECP_MAX_BITS 384 /**< Maximum bit size of groups */
#define MBEDTLS_MPI_MAX_SIZE 2048 // 384 bits is 48 bytes
#define MBEDTLS_MPI_WINDOW_SIZE 2
///* Save RAM at the expense of speed, see ecp.h */
#define MBEDTLS_ECP_WINDOW_SIZE 2 /< Maximum window size used */
#define MBEDTLS_ECP_FIXED_POINT_OPTIM 0 /< Enable fixed-point speed-up */
/* Significant speed benefit at the expense of some ROM */
#define MBEDTLS_ECP_NIST_OPTIM
#define MBEDTLS_SSL_ENCRYPT_THEN_MAC
/* Save ROM and a few bytes of RAM by specifying our own ciphersuite list */
#define MBEDTLS_SSL_CIPHERSUITES MBEDTLS_TLS_RSA_WITH_AES_128_GCM_SHA256