[PATCH 3 of 4] sha1: use explicit memzero to avoid optimizations

Vadim Fedorenko vadim.fedorenko at cdnnow.ru
Mon Apr 17 23:07:09 UTC 2023


# HG changeset patch
# User Vadim Fedorenko <vadim.fedorenko at cdnnow.ru>
# Date 1681771220 -10800
#      Tue Apr 18 01:40:20 2023 +0300
# Node ID 5663d8ff4399e7e76369c024db59c40178290213
# Parent  8f8773a3076bdbd91fc7a4e96d7a068f7ff29b09
sha1: use explicit memzero to avoid optimizations.

GCC11 is optimizing memzero functions in sha1 implementation.
Use ngx_explicit_memzero() instead.
---
 src/core/ngx_sha1.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff -r 8f8773a3076b -r 5663d8ff4399 src/core/ngx_sha1.c
--- a/src/core/ngx_sha1.c	Tue Apr 18 01:40:00 2023 +0300
+++ b/src/core/ngx_sha1.c	Tue Apr 18 01:40:20 2023 +0300
@@ -72,13 +72,13 @@
     free = 64 - used;
 
     if (free < 8) {
-        ngx_memzero(&ctx->buffer[used], free);
+        ngx_explicit_memzero(&ctx->buffer[used], free);
         (void) ngx_sha1_body(ctx, ctx->buffer, 64);
         used = 0;
         free = 64;
     }
 
-    ngx_memzero(&ctx->buffer[used], free - 8);
+    ngx_explicit_memzero(&ctx->buffer[used], free - 8);
 
     ctx->bytes <<= 3;
     ctx->buffer[56] = (u_char) (ctx->bytes >> 56);
@@ -113,7 +113,7 @@
     result[18] = (u_char) (ctx->e >> 8);
     result[19] = (u_char) ctx->e;
 
-    ngx_memzero(ctx, sizeof(*ctx));
+    ngx_explicit_memzero(ctx, sizeof(*ctx));
 }
 
 


More information about the nginx-devel mailing list