Fix the build and tests following constification of DH, DSA, RSA
authorMatt Caswell <matt@openssl.org>
Thu, 16 Jun 2016 09:07:32 +0000 (10:07 +0100)
committerMatt Caswell <matt@openssl.org>
Thu, 16 Jun 2016 12:34:44 +0000 (13:34 +0100)
Misc fixes following the constification of the DH, DSA and RSA
getters.

Reviewed-by: Stephen Henson <steve@openssl.org>
crypto/dh/dh_lib.c
crypto/dsa/dsa_lib.c
crypto/rsa/rsa_lib.c
test/dhtest.c
test/dsatest.c

index 56f9db67691ff61d4c784097d12e0137b1818a18..adf177151486b73ce18418148e225f2740f9fa6f 100644 (file)
@@ -199,8 +199,8 @@ int DH_set0_pqg(DH *dh, BIGNUM *p, BIGNUM *q, BIGNUM *g)
     /* If the fields p and g in d are NULL, the corresponding input
      * parameters MUST be non-NULL.  q may remain NULL.
      */
-    if (dh->p == NULL && p == NULL
-        || dh->g == NULL && g == NULL)
+    if ((dh->p == NULL && p == NULL)
+        || (dh->g == NULL && g == NULL))
         return 0;
 
     if (p != NULL) {
index 8146330a549015014cc6ad492d6644a1e77e03c4..9c001d7b1bf78972ae38919e4016c46336267f21 100644 (file)
@@ -269,9 +269,9 @@ int DSA_set0_pqg(DSA *d, BIGNUM *p, BIGNUM *q, BIGNUM *g)
     /* If the fields p, q and g in d are NULL, the corresponding input
      * parameters MUST be non-NULL.
      */
-    if (d->p == NULL && p == NULL
-        || d->q == NULL && q == NULL
-        || d->g == NULL && g == NULL)
+    if ((d->p == NULL && p == NULL)
+        || (d->q == NULL && q == NULL)
+        || (d->g == NULL && g == NULL))
         return 0;
 
     if (p != NULL) {
index 540dc93fd5b3dd33f0b305b322e0f7a1d318f70b..87a326184ca267c154d989e937f6844ae6e4e075 100644 (file)
@@ -236,8 +236,8 @@ int RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d)
      * parameters MUST be non-NULL for n and e.  d may be
      * left NULL (in case only the public key is used).
      */
-    if (r->n == NULL && n == NULL
-        || r->e == NULL && e == NULL)
+    if ((r->n == NULL && n == NULL)
+        || (r->e == NULL && e == NULL))
         return 0;
 
     if (n != NULL) {
@@ -261,8 +261,8 @@ int RSA_set0_factors(RSA *r, BIGNUM *p, BIGNUM *q)
     /* If the fields p and q in r are NULL, the corresponding input
      * parameters MUST be non-NULL.
      */
-    if (r->p == NULL && p == NULL
-        || r->q == NULL && q == NULL)
+    if ((r->p == NULL && p == NULL)
+        || (r->q == NULL && q == NULL))
         return 0;
 
     if (p != NULL) {
@@ -282,9 +282,9 @@ int RSA_set0_crt_params(RSA *r, BIGNUM *dmp1, BIGNUM *dmq1, BIGNUM *iqmp)
     /* If the fields dmp1, dmq1 and iqmp in r are NULL, the corresponding input
      * parameters MUST be non-NULL.
      */
-    if (r->dmp1 == NULL && dmp1 == NULL
-        || r->dmq1 == NULL && dmq1 == NULL
-        || r->iqmp == NULL && iqmp == NULL)
+    if ((r->dmp1 == NULL && dmp1 == NULL)
+        || (r->dmq1 == NULL && dmq1 == NULL)
+        || (r->iqmp == NULL && iqmp == NULL))
         return 0;
 
     if (dmp1 != NULL) {
index 1dc395b44ebabd76b94b98500c239821ca396b6d..2847c5c03827436f63df847f483a4b9b14d57ef7 100644 (file)
@@ -40,8 +40,9 @@ int main(int argc, char *argv[])
     BN_GENCB *_cb = NULL;
     DH *a = NULL;
     DH *b = NULL;
-    BIGNUM *ap = NULL, *ag = NULL, *bp = NULL, *bg = NULL, *apub_key = NULL;
-    BIGNUM *bpub_key = NULL, *priv_key = NULL;
+    const BIGNUM *ap = NULL, *ag = NULL, *apub_key = NULL, *priv_key = NULL;
+    const BIGNUM *bpub_key = NULL;
+    BIGNUM *bp = NULL, *bg = NULL;
     char buf[12] = {0};
     unsigned char *abuf = NULL;
     unsigned char *bbuf = NULL;
@@ -476,6 +477,7 @@ static int run_rfc5114_tests(void)
     unsigned char *Z2 = NULL;
     const rfc5114_td *td = NULL;
     BIGNUM *bady = NULL, *priv_key = NULL, *pub_key = NULL;
+    const BIGNUM *pub_key_tmp;
 
     for (i = 0; i < (int)OSSL_NELEM(rfctd); i++) {
         td = rfctd + i;
@@ -511,17 +513,13 @@ static int run_rfc5114_tests(void)
          * Work out shared secrets using both sides and compare with expected
          * values.
          */
-        DH_get0_key(dhB, &pub_key, NULL);
-        if (DH_compute_key(Z1, pub_key, dhA) == -1) {
-            pub_key = NULL;
+        DH_get0_key(dhB, &pub_key_tmp, NULL);
+        if (DH_compute_key(Z1, pub_key_tmp, dhA) == -1)
             goto bad_err;
-        }
-        DH_get0_key(dhA, &pub_key, NULL);
-        if (DH_compute_key(Z2, pub_key, dhB) == -1) {
-            pub_key = NULL;
+
+        DH_get0_key(dhA, &pub_key_tmp, NULL);
+        if (DH_compute_key(Z2, pub_key_tmp, dhB) == -1)
             goto bad_err;
-        }
-        pub_key = NULL;
 
         if (memcmp(Z1, td->Z, td->Z_len))
             goto err;
index b99c467e1735e1542ea6c8e16aec4a2eb24a1a9c..10854224aaac0ab8e81cb6d318efc14bff1b3fbf 100644 (file)
@@ -85,7 +85,7 @@ int main(int argc, char **argv)
     unsigned long h;
     unsigned char sig[256];
     unsigned int siglen;
-    BIGNUM *p = NULL, *q = NULL, *g = NULL;
+    const BIGNUM *p = NULL, *q = NULL, *g = NULL;
 
     if (bio_err == NULL)
         bio_err = BIO_new_fp(stderr, BIO_NOCLOSE | BIO_FP_TEXT);