[PATCH 2/8] Replace memset() with memzero_explicit()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Replace memset(address,0,bytes) which may be optimised away
with memzero_explicit(address,bytes) which resists
such optimisation

---
 crypto/drbg.c | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)

diff --git a/crypto/drbg.c b/crypto/drbg.c
index f72f340a1321..08c4586a4cc9 100644
--- a/crypto/drbg.c
+++ b/crypto/drbg.c
@@ -507,9 +507,9 @@ static int drbg_ctr_df(struct drbg_state *drbg,
     ret = 0;

 out:
-    memset(iv, 0, drbg_blocklen(drbg));
-    memset(temp, 0, drbg_statelen(drbg) + drbg_blocklen(drbg));
-    memset(pad, 0, drbg_blocklen(drbg));
+    memzero_explicit(iv, drbg_blocklen(drbg));
+    memzero_explicit(temp, drbg_statelen(drbg) + drbg_blocklen(drbg));
+    memzero_explicit(pad, drbg_blocklen(drbg));
     return ret;
 }

@@ -580,9 +580,9 @@ static int drbg_ctr_update(struct drbg_state
*drbg, struct list_head *seed,
     ret = 0;

 out:
-    memset(temp, 0, drbg_statelen(drbg) + drbg_blocklen(drbg));
+    memzero_explicit(temp, drbg_statelen(drbg) + drbg_blocklen(drbg));
     if (2 != reseed)
-        memset(df_data, 0, drbg_statelen(drbg));
+        memzero_explicit(df_data, drbg_statelen(drbg));
     return ret;
 }

@@ -852,7 +852,7 @@ static int drbg_hash_df(struct drbg_state *drbg,
     }

 out:
-    memset(tmp, 0, drbg_blocklen(drbg));
+    memzero_explicit(tmp, drbg_blocklen(drbg));
     return ret;
 }

@@ -895,7 +895,7 @@ static int drbg_hash_update(struct drbg_state
*drbg, struct list_head *seed,
     ret = drbg_hash_df(drbg, drbg->C, drbg_statelen(drbg), &datalist2);

 out:
-    memset(drbg->scratchpad, 0, drbg_statelen(drbg));
+    memzero_explicit(drbg->scratchpad, drbg_statelen(drbg));
     return ret;
 }

@@ -927,7 +927,7 @@ static int drbg_hash_process_addtl(struct drbg_state *drbg,
              drbg->scratchpad, drbg_blocklen(drbg));

 out:
-    memset(drbg->scratchpad, 0, drbg_blocklen(drbg));
+    memzero_explicit(drbg->scratchpad, drbg_blocklen(drbg));
     return ret;
 }

@@ -967,8 +967,7 @@ static int drbg_hash_hashgen(struct drbg_state *drbg,
     }

 out:
-    memset(drbg->scratchpad, 0,
-           (drbg_statelen(drbg) + drbg_blocklen(drbg)));
+    memzero_explicit(drbg->scratchpad, (drbg_statelen(drbg) +
drbg_blocklen(drbg)));
     return len;
 }

@@ -1015,7 +1014,7 @@ static int drbg_hash_generate(struct drbg_state *drbg,
     drbg_add_buf(drbg->V, drbg_statelen(drbg), u.req, 8);

 out:
-    memset(drbg->scratchpad, 0, drbg_blocklen(drbg));
+    memzero_explicit(drbg->scratchpad, drbg_blocklen(drbg));
     return len;
 }

@@ -1202,8 +1201,8 @@ static int drbg_seed(struct drbg_state *drbg,
struct drbg_string *pers,
     }

     if (!reseed) {
-        memset(drbg->V, 0, drbg_statelen(drbg));
-        memset(drbg->C, 0, drbg_statelen(drbg));
+        memzero_explicit(drbg->V, drbg_statelen(drbg));
+        memzero_explicit(drbg->C, drbg_statelen(drbg));
     }

     ret = __drbg_seed(drbg, &seedlist, reseed);
-- 
2.25.1



[Index of Archives]     [Kernel]     [Gnu Classpath]     [Gnu Crypto]     [DM Crypt]     [Netfilter]     [Bugtraq]

  Powered by Linux