Allow the configuration of padding when using CID extension
diff --git a/library/ssl_tls.c b/library/ssl_tls.c
index 7e7d5a0..3882622 100644
--- a/library/ssl_tls.c
+++ b/library/ssl_tls.c
@@ -2013,7 +2013,9 @@
                                           uint8_t rec_type )
 {
     size_t len = *content_size;
-    size_t pad = ~len & 0xF; /* Pad to a multiple of 16 */
+
+    /* MBEDTLS_SSL_CID_PADDING_GRANULARITY must be a power of 2. */
+    size_t pad = ~len & ( MBEDTLS_SSL_CID_PADDING_GRANULARITY - 1 );
 
     /* Write real content type */
     if( remaining == 0 )