Constify the parameter getters for RSA, DSA and DH
authorRichard Levitte <levitte@openssl.org>
Tue, 14 Jun 2016 13:48:16 +0000 (15:48 +0200)
committerRichard Levitte <levitte@openssl.org>
Wed, 15 Jun 2016 18:09:27 +0000 (20:09 +0200)
Including documentation changes

Reviewed-by: Stephen Henson <steve@openssl.org>
Reviewed-by: Emilia Käsper <emilia@openssl.org>
crypto/dh/dh_lib.c
crypto/dsa/dsa_lib.c
crypto/rsa/rsa_lib.c
doc/crypto/DH_get0_pqg.pod
doc/crypto/DSA_get0_pqg.pod
doc/crypto/RSA_get0_key.pod
include/openssl/dh.h
include/openssl/dsa.h
include/openssl/rsa.h

index 6a59f7faa4320a6ee055aa6f95bba371d073428a..56f9db67691ff61d4c784097d12e0137b1818a18 100644 (file)
@@ -183,7 +183,8 @@ int DH_security_bits(const DH *dh)
 }
 
 
-void DH_get0_pqg(const DH *dh, BIGNUM **p, BIGNUM **q, BIGNUM **g)
+void DH_get0_pqg(const DH *dh,
+                 const BIGNUM **p, const BIGNUM **q, const BIGNUM **g)
 {
     if (p != NULL)
         *p = dh->p;
@@ -197,11 +198,9 @@ 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.
-     *
-     * It is an error to give the results from get0 on d
-     * as input parameters.
      */
-    if (p == dh->p || (dh->q != NULL && q == dh->q) || g == dh->g)
+    if (dh->p == NULL && p == NULL
+        || dh->g == NULL && g == NULL)
         return 0;
 
     if (p != NULL) {
@@ -235,7 +234,7 @@ int DH_set_length(DH *dh, long length)
     return 1;
 }
 
-void DH_get0_key(const DH *dh, BIGNUM **pub_key, BIGNUM **priv_key)
+void DH_get0_key(const DH *dh, const BIGNUM **pub_key, const BIGNUM **priv_key)
 {
     if (pub_key != NULL)
         *pub_key = dh->pub_key;
@@ -245,15 +244,11 @@ void DH_get0_key(const DH *dh, BIGNUM **pub_key, BIGNUM **priv_key)
 
 int DH_set0_key(DH *dh, BIGNUM *pub_key, BIGNUM *priv_key)
 {
-    /* If the pub_key in dh is NULL, the corresponding input
+    /* If the field pub_key in dh is NULL, the corresponding input
      * parameters MUST be non-NULL.  The priv_key field may
      * be left NULL.
-     *
-     * It is an error to give the results from get0 on dh
-     * as input parameters.
      */
-    if (dh->pub_key == pub_key
-        || (dh->priv_key != NULL && priv_key == dh->priv_key))
+    if (dh->pub_key == NULL && pub_key == NULL)
         return 0;
 
     if (pub_key != NULL) {
index 14cb35f82e28f374afa67adff817d61d228a6fb1..8146330a549015014cc6ad492d6644a1e77e03c4 100644 (file)
@@ -253,7 +253,8 @@ DH *DSA_dup_DH(const DSA *r)
 }
 #endif
 
-void DSA_get0_pqg(const DSA *d, BIGNUM **p, BIGNUM **q, BIGNUM **g)
+void DSA_get0_pqg(const DSA *d,
+                  const BIGNUM **p, const BIGNUM **q, const BIGNUM **g)
 {
     if (p != NULL)
         *p = d->p;
@@ -265,13 +266,12 @@ void DSA_get0_pqg(const DSA *d, BIGNUM **p, BIGNUM **q, BIGNUM **g)
 
 int DSA_set0_pqg(DSA *d, BIGNUM *p, BIGNUM *q, BIGNUM *g)
 {
-    /* If the fields in d are NULL, the corresponding input
+    /* If the fields p, q and g in d are NULL, the corresponding input
      * parameters MUST be non-NULL.
-     *
-     * It is an error to give the results from get0 on d
-     * as input parameters.
      */
-    if (p == d->p || q == d->q || g == d->g)
+    if (d->p == NULL && p == NULL
+        || d->q == NULL && q == NULL
+        || d->g == NULL && g == NULL)
         return 0;
 
     if (p != NULL) {
@@ -290,7 +290,8 @@ int DSA_set0_pqg(DSA *d, BIGNUM *p, BIGNUM *q, BIGNUM *g)
     return 1;
 }
 
-void DSA_get0_key(const DSA *d, BIGNUM **pub_key, BIGNUM **priv_key)
+void DSA_get0_key(const DSA *d,
+                  const BIGNUM **pub_key, const BIGNUM **priv_key)
 {
     if (pub_key != NULL)
         *pub_key = d->pub_key;
@@ -300,15 +301,11 @@ void DSA_get0_key(const DSA *d, BIGNUM **pub_key, BIGNUM **priv_key)
 
 int DSA_set0_key(DSA *d, BIGNUM *pub_key, BIGNUM *priv_key)
 {
-    /* If the pub_key in d is NULL, the corresponding input
+    /* If the field pub_key in d is NULL, the corresponding input
      * parameters MUST be non-NULL.  The priv_key field may
      * be left NULL.
-     *
-     * It is an error to give the results from get0 on d
-     * as input parameters.
      */
-    if (d->pub_key == pub_key
-        || (d->priv_key != NULL && priv_key == d->priv_key))
+    if (d->pub_key == NULL && pub_key == NULL)
         return 0;
 
     if (pub_key != NULL) {
index 4f93cbcc4301c052016ffcc47fa3089014cce38c..540dc93fd5b3dd33f0b305b322e0f7a1d318f70b 100644 (file)
@@ -232,15 +232,12 @@ int RSA_security_bits(const RSA *rsa)
 
 int RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d)
 {
-    /* If the fields in r are NULL, the corresponding input
+    /* If the fields n and e in r are NULL, the corresponding input
      * parameters MUST be non-NULL for n and e.  d may be
      * left NULL (in case only the public key is used).
-     *
-     * It is an error to give the results from get0 on r
-     * as input parameters.
      */
-    if (n == r->n || e == r->e
-        || (r->d != NULL && d == r->d))
+    if (r->n == NULL && n == NULL
+        || r->e == NULL && e == NULL)
         return 0;
 
     if (n != NULL) {
@@ -261,13 +258,11 @@ int RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d)
 
 int RSA_set0_factors(RSA *r, BIGNUM *p, BIGNUM *q)
 {
-    /* If the fields in r are NULL, the corresponding input
+    /* If the fields p and q in r are NULL, the corresponding input
      * parameters MUST be non-NULL.
-     *
-     * It is an error to give the results from get0 on r
-     * as input parameters.
      */
-    if (p == r->p || q == r->q)
+    if (r->p == NULL && p == NULL
+        || r->q == NULL && q == NULL)
         return 0;
 
     if (p != NULL) {
@@ -284,13 +279,12 @@ int RSA_set0_factors(RSA *r, BIGNUM *p, BIGNUM *q)
 
 int RSA_set0_crt_params(RSA *r, BIGNUM *dmp1, BIGNUM *dmq1, BIGNUM *iqmp)
 {
-    /* If the fields in r are NULL, the corresponding input
+    /* If the fields dmp1, dmq1 and iqmp in r are NULL, the corresponding input
      * parameters MUST be non-NULL.
-     *
-     * It is an error to give the results from get0 on r
-     * as input parameters.
      */
-    if (dmp1 == r->dmp1 || dmq1 == r->dmq1 || iqmp == r->iqmp)
+    if (r->dmp1 == NULL && dmp1 == NULL
+        || r->dmq1 == NULL && dmq1 == NULL
+        || r->iqmp == NULL && iqmp == NULL)
         return 0;
 
     if (dmp1 != NULL) {
@@ -309,7 +303,8 @@ int RSA_set0_crt_params(RSA *r, BIGNUM *dmp1, BIGNUM *dmq1, BIGNUM *iqmp)
     return 1;
 }
 
-void RSA_get0_key(const RSA *r, BIGNUM **n, BIGNUM **e, BIGNUM **d)
+void RSA_get0_key(const RSA *r,
+                  const BIGNUM **n, const BIGNUM **e, const BIGNUM **d)
 {
     if (n != NULL)
         *n = r->n;
@@ -319,7 +314,7 @@ void RSA_get0_key(const RSA *r, BIGNUM **n, BIGNUM **e, BIGNUM **d)
         *d = r->d;
 }
 
-void RSA_get0_factors(const RSA *r, BIGNUM **p, BIGNUM **q)
+void RSA_get0_factors(const RSA *r, const BIGNUM **p, const BIGNUM **q)
 {
     if (p != NULL)
         *p = r->p;
@@ -328,7 +323,8 @@ void RSA_get0_factors(const RSA *r, BIGNUM **p, BIGNUM **q)
 }
 
 void RSA_get0_crt_params(const RSA *r,
-                         BIGNUM **dmp1, BIGNUM **dmq1, BIGNUM **iqmp)
+                         const BIGNUM **dmp1, const BIGNUM **dmq1,
+                         const BIGNUM **iqmp)
 {
     if (dmp1 != NULL)
         *dmp1 = r->dmp1;
index 6c6b66108691a29cb1f8e046ebd626d345456dda..79647bf890b6399a197a41d3eafe0a956680967c 100644 (file)
@@ -10,9 +10,11 @@ DH_set_length - Routines for getting and setting data in a DH object
 
  #include <openssl/dh.h>
 
- void DH_get0_pqg(const DH *dh, BIGNUM **p, BIGNUM **q, BIGNUM **g);
+ void DH_get0_pqg(const DH *dh,
+                  const BIGNUM **p, const BIGNUM **q, const BIGNUM **g);
  int DH_set0_pqg(DH *dh, BIGNUM *p, BIGNUM *q, BIGNUM *g);
- void DH_get0_key(const DH *dh, BIGNUM **pub_key, BIGNUM **priv_key);
+ void DH_get0_key(const DH *dh,
+                  const BIGNUM **pub_key, const BIGNUM **priv_key);
  int DH_set0_key(DH *dh, BIGNUM *pub_key, BIGNUM *priv_key);
  void DH_clear_flags(DH *dh, int flags);
  int DH_test_flags(const DH *dh, int flags);
index 95173bca6840032f19f91b5710f30961b8c2c043..e87e42a4597869d835189b0f879b0c994f3474ef 100644 (file)
@@ -10,9 +10,11 @@ setting data in a DSA object
 
  #include <openssl/dsa.h>
 
- void DSA_get0_pqg(const DSA *d, BIGNUM **p, BIGNUM **q, BIGNUM **g);
+ void DSA_get0_pqg(const DSA *d,
+                   const BIGNUM **p, const BIGNUM **q, const BIGNUM **g);
  int DSA_set0_pqg(DSA *d, BIGNUM *p, BIGNUM *q, BIGNUM *g);
- void DSA_get0_key(const DSA *d, BIGNUM **pub_key, BIGNUM **priv_key);
+ void DSA_get0_key(const DSA *d,
+                   const BIGNUM **pub_key, const BIGNUM **priv_key);
  int DSA_set0_key(DSA *d, BIGNUM *pub_key, BIGNUM *priv_key);
  void DSA_clear_flags(DSA *d, int flags);
  int DSA_test_flags(const DSA *d, int flags);
index 19c7f3d3345f1cf5ebe053e21daf5f6e6586a415..77e0d3b42cf2953970a51778a729d76099eafe16 100644 (file)
@@ -14,10 +14,12 @@ and setting data in an RSA object
  int RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d);
  int RSA_set0_factors(RSA *r, BIGNUM *p, BIGNUM *q);
  int RSA_set0_crt_params(RSA *r,BIGNUM *dmp1, BIGNUM *dmq1, BIGNUM *iqmp);
- void RSA_get0_key(const RSA *r, BIGNUM **n, BIGNUM **e, BIGNUM **d);
- void RSA_get0_factors(const RSA *r, BIGNUM **p, BIGNUM **q);
+ void RSA_get0_key(const RSA *r,
+                   const BIGNUM **n, const BIGNUM **e, const BIGNUM **d);
+ void RSA_get0_factors(const RSA *r, const BIGNUM **p, const BIGNUM **q);
  void RSA_get0_crt_params(const RSA *r,
-                          BIGNUM **dmp1, BIGNUM **dmq1, BIGNUM **iqmp);
+                          const BIGNUM **dmp1, const BIGNUM **dmq1,
+                          const BIGNUM **iqmp);
  void RSA_clear_flags(RSA *r, int flags);
  int RSA_test_flags(const RSA *r, int flags);
  void RSA_set_flags(RSA *r, int flags);
index 2eb596d2bab85888638536a4cb812266a94e9a8b..a574e1871e10337ef543238b1c5c46596affafb1 100644 (file)
@@ -151,9 +151,11 @@ int DH_KDF_X9_42(unsigned char *out, size_t outlen,
                  const unsigned char *ukm, size_t ukmlen, const EVP_MD *md);
 # endif
 
-void DH_get0_pqg(const DH *dh, BIGNUM **p, BIGNUM **q, BIGNUM **g);
+void DH_get0_pqg(const DH *dh,
+                 const BIGNUM **p, const BIGNUM **q, const BIGNUM **g);
 int DH_set0_pqg(DH *dh, BIGNUM *p, BIGNUM *q, BIGNUM *g);
-void DH_get0_key(const DH *dh, BIGNUM **pub_key, BIGNUM **priv_key);
+void DH_get0_key(const DH *dh,
+                 const BIGNUM **pub_key, const BIGNUM **priv_key);
 int DH_set0_key(DH *dh, BIGNUM *pub_key, BIGNUM *priv_key);
 void DH_clear_flags(DH *dh, int flags);
 int DH_test_flags(const DH *dh, int flags);
index ce1346c2f07dd45a008a5fd92af6993009a31c11..0c5196d08af164e439704fac955abb6876c543f4 100644 (file)
@@ -169,9 +169,11 @@ DH *DSA_dup_DH(const DSA *r);
 # define EVP_PKEY_CTRL_DSA_PARAMGEN_Q_BITS       (EVP_PKEY_ALG_CTRL + 2)
 # define EVP_PKEY_CTRL_DSA_PARAMGEN_MD           (EVP_PKEY_ALG_CTRL + 3)
 
-void DSA_get0_pqg(const DSA *d, BIGNUM **p, BIGNUM **q, BIGNUM **g);
+void DSA_get0_pqg(const DSA *d,
+                  const BIGNUM **p, const BIGNUM **q, const BIGNUM **g);
 int DSA_set0_pqg(DSA *d, BIGNUM *p, BIGNUM *q, BIGNUM *g);
-void DSA_get0_key(const DSA *d, BIGNUM **pub_key, BIGNUM **priv_key);
+void DSA_get0_key(const DSA *d,
+                  const BIGNUM **pub_key, const BIGNUM **priv_key);
 int DSA_set0_key(DSA *d, BIGNUM *pub_key, BIGNUM *priv_key);
 void DSA_clear_flags(DSA *d, int flags);
 int DSA_test_flags(const DSA *d, int flags);
index 4b82081d93d8ce62cc3ae00c8c3fbffd0fb41900..70d375512492aa54676b6f16fa969a205e29f256 100644 (file)
@@ -178,10 +178,12 @@ int RSA_security_bits(const RSA *rsa);
 int RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d);
 int RSA_set0_factors(RSA *r, BIGNUM *p, BIGNUM *q);
 int RSA_set0_crt_params(RSA *r,BIGNUM *dmp1, BIGNUM *dmq1, BIGNUM *iqmp);
-void RSA_get0_key(const RSA *r, BIGNUM **n, BIGNUM **e, BIGNUM **d);
-void RSA_get0_factors(const RSA *r, BIGNUM **p, BIGNUM **q);
+void RSA_get0_key(const RSA *r,
+                  const BIGNUM **n, const BIGNUM **e, const BIGNUM **d);
+void RSA_get0_factors(const RSA *r, const BIGNUM **p, const BIGNUM **q);
 void RSA_get0_crt_params(const RSA *r,
-                         BIGNUM **dmp1, BIGNUM **dmq1, BIGNUM **iqmp);
+                         const BIGNUM **dmp1, const BIGNUM **dmq1,
+                         const BIGNUM **iqmp);
 void RSA_clear_flags(RSA *r, int flags);
 int RSA_test_flags(const RSA *r, int flags);
 void RSA_set_flags(RSA *r, int flags);