Make the RSA structure opaque
[openssl.git] / crypto / rsa / rsa_x931g.c
index 599161578440d97b59de84fc6e2389e089d60c96..1e164e86e14580eb89876d75dcca8205c345d604 100644 (file)
@@ -1,4 +1,3 @@
-/* crypto/rsa/rsa_gen.c */
 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
  * All rights reserved.
  *
@@ -61,7 +60,7 @@
 #include <time.h>
 #include <openssl/err.h>
 #include <openssl/bn.h>
-#include <openssl/rsa.h>
+#include "rsa_locl.h"
 
 /* X9.31 RSA key derivation and generation */
 
@@ -78,7 +77,7 @@ int RSA_X931_derive_ex(RSA *rsa, BIGNUM *p1, BIGNUM *p2, BIGNUM *q1,
         goto err;
 
     ctx = BN_CTX_new();
-    if (!ctx)
+    if (ctx == NULL)
         goto err;
     BN_CTX_start(ctx);
 
@@ -101,9 +100,9 @@ int RSA_X931_derive_ex(RSA *rsa, BIGNUM *p1, BIGNUM *p2, BIGNUM *q1,
      * test programs to output selective parameters.
      */
 
-    if (Xp && !rsa->p) {
+    if (Xp && rsa->p == NULL) {
         rsa->p = BN_new();
-        if (!rsa->p)
+        if (rsa->p == NULL)
             goto err;
 
         if (!BN_X931_derive_prime_ex(rsa->p, p1, p2,
@@ -111,16 +110,16 @@ int RSA_X931_derive_ex(RSA *rsa, BIGNUM *p1, BIGNUM *p2, BIGNUM *q1,
             goto err;
     }
 
-    if (Xq && !rsa->q) {
+    if (Xq && rsa->q == NULL) {
         rsa->q = BN_new();
-        if (!rsa->q)
+        if (rsa->q == NULL)
             goto err;
         if (!BN_X931_derive_prime_ex(rsa->q, q1, q2,
                                      Xq, Xq1, Xq2, e, ctx, cb))
             goto err;
     }
 
-    if (!rsa->p || !rsa->q) {
+    if (rsa->p == NULL || rsa->q == NULL) {
         BN_CTX_end(ctx);
         BN_CTX_free(ctx);
         return 2;
@@ -153,7 +152,7 @@ int RSA_X931_derive_ex(RSA *rsa, BIGNUM *p1, BIGNUM *p2, BIGNUM *q1,
         goto err;               /* LCM((p-1)(q-1)) */
 
     ctx2 = BN_CTX_new();
-    if (!ctx2)
+    if (ctx2 == NULL)
         goto err;
 
     rsa->d = BN_mod_inverse(NULL, rsa->e, r0, ctx2); /* d */
@@ -179,12 +178,10 @@ int RSA_X931_derive_ex(RSA *rsa, BIGNUM *p1, BIGNUM *p2, BIGNUM *q1,
 
     ret = 1;
  err:
-    if (ctx) {
+    if (ctx)
         BN_CTX_end(ctx);
-        BN_CTX_free(ctx);
-    }
-    if (ctx2)
-        BN_CTX_free(ctx2);
+    BN_CTX_free(ctx);
+    BN_CTX_free(ctx2);
 
     return ret;
 
@@ -198,7 +195,7 @@ int RSA_X931_generate_key_ex(RSA *rsa, int bits, const BIGNUM *e,
     BN_CTX *ctx = NULL;
 
     ctx = BN_CTX_new();
-    if (!ctx)
+    if (ctx == NULL)
         goto error;
 
     BN_CTX_start(ctx);
@@ -209,7 +206,7 @@ int RSA_X931_generate_key_ex(RSA *rsa, int bits, const BIGNUM *e,
 
     rsa->p = BN_new();
     rsa->q = BN_new();
-    if (!rsa->p || !rsa->q)
+    if (rsa->p == NULL || rsa->q == NULL)
         goto error;
 
     /* Generate two primes from Xp, Xq */
@@ -234,10 +231,9 @@ int RSA_X931_generate_key_ex(RSA *rsa, int bits, const BIGNUM *e,
     ok = 1;
 
  error:
-    if (ctx) {
+    if (ctx)
         BN_CTX_end(ctx);
-        BN_CTX_free(ctx);
-    }
+    BN_CTX_free(ctx);
 
     if (ok)
         return 1;