From 818bac55ef59c2fdd5a3f5047977eb925aa567c4 Mon Sep 17 00:00:00 2001
From: Hanno Becker <hanno.becker@arm.com>
Date: Fri, 26 Oct 2018 09:13:26 +0100
Subject: [PATCH] Add further missing brackets around macro parameters

---
 library/aes.c    | 2 +-
 library/md4.c    | 4 ++--
 library/md5.c    | 2 +-
 library/sha1.c   | 4 ++--
 library/sha256.c | 4 ++--
 library/sha512.c | 4 ++--
 6 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/library/aes.c b/library/aes.c
index b2e346ec11..aff0a9939a 100644
--- a/library/aes.c
+++ b/library/aes.c
@@ -397,7 +397,7 @@ static uint32_t RCON[10];
  */
 #define ROTL8(x) ( ( (x) << 8 ) & 0xFFFFFFFF ) | ( (x) >> 24 )
 #define XTIME(x) ( ( (x) << 1 ) ^ ( ( (x) & 0x80 ) ? 0x1B : 0x00 ) )
-#define MUL(x,y) ( ( (x) && (y) ) ? pow[(log[x]+log[y]) % 255] : 0 )
+#define MUL(x,y) ( ( (x) && (y) ) ? pow[(log[(x)]+log[(y)]) % 255] : 0 )
 
 static int aes_init_done = 0;
 
diff --git a/library/md4.c b/library/md4.c
index 156e715340..41c5d545f4 100644
--- a/library/md4.c
+++ b/library/md4.c
@@ -148,8 +148,8 @@ int mbedtls_internal_md4_process( mbedtls_md4_context *ctx,
 #define P(a,b,c,d,x,s)         \
     do                         \
     {                          \
-        (a) += F(b,c,d) + (x); \
-        (a) = S(a,s);          \
+        (a) += F((b),(c),(d)) + (x);             \
+        (a) = S((a),(s));                        \
     } while( 0 )
 
 
diff --git a/library/md5.c b/library/md5.c
index bdbb760ede..a93da8a061 100644
--- a/library/md5.c
+++ b/library/md5.c
@@ -142,7 +142,7 @@ int mbedtls_internal_md5_process( mbedtls_md5_context *ctx,
 #define P(a,b,c,d,k,s,t)                                        \
     do                                                          \
     {                                                           \
-        (a) += F((b),(c),(d)) + X[k] + (t);                     \
+        (a) += F((b),(c),(d)) + X[(k)] + (t);                   \
         (a) = S((a),(s)) + (b);                                 \
     } while( 0 )
 
diff --git a/library/sha1.c b/library/sha1.c
index 2f2946b551..355c83d2f7 100644
--- a/library/sha1.c
+++ b/library/sha1.c
@@ -164,8 +164,8 @@ int mbedtls_internal_sha1_process( mbedtls_sha1_context *ctx,
 #define P(a,b,c,d,e,x)                                          \
     do                                                          \
     {                                                           \
-        (e) += S(a,5) + F(b,c,d) + K + (x);                     \
-        (b) = S(b,30);                                          \
+        (e) += S((a),5) + F((b),(c),(d)) + K + (x);             \
+        (b) = S((b),30);                                        \
     } while( 0 )
 
     A = ctx->state[0];
diff --git a/library/sha256.c b/library/sha256.c
index 09d3fe349e..2dc0e1a2c9 100644
--- a/library/sha256.c
+++ b/library/sha256.c
@@ -193,8 +193,8 @@ static const uint32_t K[] =
 #define P(a,b,c,d,e,f,g,h,x,K)                          \
     do                                                  \
     {                                                   \
-        temp1 = (h) + S3(e) + F1(e,f,g) + (K) + (x);    \
-        temp2 = S2(a) + F0(a,b,c);                      \
+        temp1 = (h) + S3(e) + F1((e),(f),(g)) + (K) + (x);      \
+        temp2 = S2(a) + F0((a),(b),(c));                        \
         (d) += temp1; (h) = temp1 + temp2;              \
     } while( 0 )
 
diff --git a/library/sha512.c b/library/sha512.c
index cec955b4c7..efc4acb405 100644
--- a/library/sha512.c
+++ b/library/sha512.c
@@ -239,8 +239,8 @@ int mbedtls_internal_sha512_process( mbedtls_sha512_context *ctx,
 #define P(a,b,c,d,e,f,g,h,x,K)                          \
     do                                                  \
     {                                                   \
-        temp1 = (h) + S3(e) + F1(e,f,g) + (K) + (x);    \
-        temp2 = S2(a) + F0(a,b,c);                      \
+        temp1 = (h) + S3(e) + F1((e),(f),(g)) + (K) + (x);      \
+        temp2 = S2(a) + F0((a),(b),(c));                        \
         (d) += temp1; (h) = temp1 + temp2;              \
     } while( 0 )