Browse Source

Merge pull request #5757 from SparkiDev/enc_err_forcezero_fix

ForceZero fix: encryption fail and not EtM
JacobBarthelmeh 1 year ago
parent
commit
502a395723
1 changed files with 10 additions and 2 deletions
  1. 10 2
      src/internal.c

+ 10 - 2
src/internal.c

@@ -20813,8 +20813,16 @@ int BuildMessage(WOLFSSL* ssl, byte* output, int outSz, const byte* input,
             #endif
                 {
                     /* Zeroize plaintext. */
-                    ForceZero(output + args->headerSz,
-                        (word16)(args->size - args->digestSz));
+            #if defined(HAVE_ENCRYPT_THEN_MAC) && !defined(WOLFSSL_AEAD_ONLY)
+                    if (ssl->options.startedETMWrite) {
+                        ForceZero(output + args->headerSz,
+                            (word16)(args->size - args->digestSz));
+                    }
+                    else
+            #endif
+                    {
+                        ForceZero(output + args->headerSz, (word16)args->size);
+                    }
                 }
                 goto exit_buildmsg;
             }