chiark / gitweb /
rsa1: rsapriv_apply: Initialise local mpz's early
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 6 Oct 2019 20:13:31 +0000 (21:13 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 15 Feb 2020 21:56:49 +0000 (21:56 +0000)
This will make it easier to support non-fatal early return.

No overall functional change.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
rsa.c

diff --git a/rsa.c b/rsa.c
index 57ea2424f6273eb1c4003be191fcda18ea5bd73e..2bb6f551c3d563466072f61d2a5f4b038170b4c4 100644 (file)
--- a/rsa.c
+++ b/rsa.c
@@ -349,11 +349,18 @@ static list_t *rsapriv_apply(closure_t *self, struct cloc loc, dict_t *context,
     cstring_t filename;
     item_t *i;
     long length;
-    uint8_t *b, *c;
+    uint8_t *b=0, *c=0;
     int cipher_type;
     MP_INT e,d,iqmp,tmp,tmp2,tmp3;
     bool_t valid;
 
+    mpz_init(&e);
+    mpz_init(&d);
+    mpz_init(&iqmp);
+    mpz_init(&tmp);
+    mpz_init(&tmp2);
+    mpz_init(&tmp3);
+
     NEW(st);
     st->cl.description="rsapriv";
     st->cl.type=CL_SIGPRIVKEY;
@@ -430,7 +437,6 @@ static list_t *rsapriv_apply(closure_t *self, struct cloc loc, dict_t *context,
     if (fread(b,length,1,f)!=1) {
        LDFATAL_FILE("rsa-private","error reading e\n");
     }
-    mpz_init(&e);
     read_mpbin(&e,b,length);
     FREE(b);
     
@@ -463,7 +469,6 @@ static list_t *rsapriv_apply(closure_t *self, struct cloc loc, dict_t *context,
        LDFATAL_FILE("rsa-private",
                           "error reading decryption key\n");
     }
-    mpz_init(&d);
     read_mpbin(&d,b,length);
     FREE(b);
     /* Read iqmp (inverse of q mod p) */
@@ -477,7 +482,6 @@ static list_t *rsapriv_apply(closure_t *self, struct cloc loc, dict_t *context,
        LDFATAL_FILE("rsa-private",
                           "error reading decryption key\n");
     }
-    mpz_init(&iqmp);
     read_mpbin(&iqmp,b,length);
     FREE(b);
     /* Read q (the smaller of the two primes) */
@@ -519,9 +523,6 @@ static list_t *rsapriv_apply(closure_t *self, struct cloc loc, dict_t *context,
      */
     valid=False;
     i=list_elem(args,1);
-    mpz_init(&tmp);
-    mpz_init(&tmp2);
-    mpz_init(&tmp3);
     if (i && i->type==t_bool && i->data.bool==False) {
        Message(M_INFO,"rsa-private (%s:%d): skipping RSA key validity "
                "check\n",loc.file,loc.line);