Big rename fest in makefile.shared: link_a / link_o -> link_shlib / link_dso
[openssl.git] / engines / e_ubsec.c
index 2d6331d690e27a366ff7934a6efd39d6fead2a75..dab8d12e3faa52e910bbe3bd6ed05e8ca56fee91 100644 (file)
@@ -1,4 +1,3 @@
-/* crypto/engine/hw_ubsec.c */
 /*
  * Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL project
  * 2000. Cloned shamelessly by Joe Tardo.
@@ -233,14 +232,14 @@ static int bind_helper(ENGINE *e)
 
 #  ifndef OPENSSL_NO_RSA
     /*
-     * We know that the "PKCS1_SSLeay()" functions hook properly to the
+     * We know that the "PKCS1_OpenSSL()" functions hook properly to the
      * Broadcom-specific mod_exp and mod_exp_crt so we use those functions.
      * NB: We don't use ENGINE_openssl() or anything "more generic" because
      * something like the RSAref code may not hook properly, and if you own
      * one of these cards then you have the right to do RSA operations on it
      * anyway!
      */
-    meth1 = RSA_PKCS1_SSLeay();
+    meth1 = RSA_PKCS1_OpenSSL();
     ubsec_rsa.rsa_pub_enc = meth1->rsa_pub_enc;
     ubsec_rsa.rsa_pub_dec = meth1->rsa_pub_dec;
     ubsec_rsa.rsa_priv_enc = meth1->rsa_priv_enc;
@@ -265,7 +264,7 @@ static int bind_helper(ENGINE *e)
 static ENGINE *engine_ubsec(void)
 {
     ENGINE *ret = ENGINE_new();
-    if (!ret)
+    if (ret == NULL)
         return NULL;
     if (!bind_helper(ret)) {
         ENGINE_free(ret);
@@ -339,15 +338,14 @@ static const char *get_UBSEC_LIBNAME(void)
 
 static void free_UBSEC_LIBNAME(void)
 {
-    if (UBSEC_LIBNAME)
-        OPENSSL_free((void *)UBSEC_LIBNAME);
+    OPENSSL_free(UBSEC_LIBNAME);
     UBSEC_LIBNAME = NULL;
 }
 
 static long set_UBSEC_LIBNAME(const char *name)
 {
     free_UBSEC_LIBNAME();
-    return (((UBSEC_LIBNAME = BUF_strdup(name)) != NULL) ? 1 : 0);
+    return (((UBSEC_LIBNAME = OPENSSL_strdup(name)) != NULL) ? 1 : 0);
 }
 
 static const char *UBSEC_F1 = "ubsec_bytes_to_bits";
@@ -415,38 +413,26 @@ static int ubsec_init(ENGINE *e)
         goto err;
     }
 
-    if (!(p1 = (t_UBSEC_ubsec_bytes_to_bits *)
-          DSO_bind_func(ubsec_dso, UBSEC_F1))
-        || !(p2 = (t_UBSEC_ubsec_bits_to_bytes *)
-             DSO_bind_func(ubsec_dso, UBSEC_F2))
-        || !(p3 = (t_UBSEC_ubsec_open *)
-             DSO_bind_func(ubsec_dso, UBSEC_F3))
-        || !(p4 = (t_UBSEC_ubsec_close *)
-             DSO_bind_func(ubsec_dso, UBSEC_F4))
+#define BINDIT(t, name) (t *)DSO_bind_func(ubsec_dso, name)
+    if ((p1 = BINDIT(t_UBSEC_ubsec_bytes_to_bits, UBSEC_F1)) == NULL
+        || (p2 = BINDIT(t_UBSEC_ubsec_bits_to_bytes, UBSEC_F2)) == NULL
+        || (p3 = BINDIT(t_UBSEC_ubsec_open, UBSEC_F3)) == NULL
+        || (p4 = BINDIT(t_UBSEC_ubsec_close, UBSEC_F4)) == NULL
 #  ifndef OPENSSL_NO_DH
-        || !(p5 = (t_UBSEC_diffie_hellman_generate_ioctl *)
-             DSO_bind_func(ubsec_dso, UBSEC_F5))
-        || !(p6 = (t_UBSEC_diffie_hellman_agree_ioctl *)
-             DSO_bind_func(ubsec_dso, UBSEC_F6))
+        || (p5 = BINDIT(t_UBSEC_diffie_hellman_generate_ioctl, UBSEC_F5)) == NULL
+        || (p6 = BINDIT(t_UBSEC_diffie_hellman_agree_ioctl, UBSEC_F6)) == NULL
 #  endif
 /* #ifndef OPENSSL_NO_RSA */
-        || !(p7 = (t_UBSEC_rsa_mod_exp_ioctl *)
-             DSO_bind_func(ubsec_dso, UBSEC_F7))
-        || !(p8 = (t_UBSEC_rsa_mod_exp_crt_ioctl *)
-             DSO_bind_func(ubsec_dso, UBSEC_F8))
+        || (p7 = BINDIT(t_UBSEC_rsa_mod_exp_ioctl, UBSEC_F7)) == NULL
+        || (p8 = BINDIT(t_UBSEC_rsa_mod_exp_crt_ioctl, UBSEC_F8)) == NULL
 /* #endif */
 #  ifndef OPENSSL_NO_DSA
-        || !(p9 = (t_UBSEC_dsa_sign_ioctl *)
-             DSO_bind_func(ubsec_dso, UBSEC_F9))
-        || !(p10 = (t_UBSEC_dsa_verify_ioctl *)
-             DSO_bind_func(ubsec_dso, UBSEC_F10))
+        || (p9 = BINDIT(t_UBSEC_dsa_sign_ioctl, UBSEC_F9)) == NULL
+        || (p10 = BINDIT(t_UBSEC_dsa_verify_ioctl, UBSEC_F10)) == NULL
 #  endif
-        || !(p11 = (t_UBSEC_math_accelerate_ioctl *)
-             DSO_bind_func(ubsec_dso, UBSEC_F11))
-        || !(p12 = (t_UBSEC_rng_ioctl *)
-             DSO_bind_func(ubsec_dso, UBSEC_F12))
-        || !(p13 = (t_UBSEC_max_key_len_ioctl *)
-             DSO_bind_func(ubsec_dso, UBSEC_F13))) {
+        || (p11 = BINDIT(t_UBSEC_math_accelerate_ioctl, UBSEC_F11)) == NULL
+        || (p12 = BINDIT(t_UBSEC_rng_ioctl, UBSEC_F12)) == NULL
+        || (p13 = BINDIT(t_UBSEC_max_key_len_ioctl, UBSEC_F13)) == NULL) {
         UBSECerr(UBSEC_F_UBSEC_INIT, UBSEC_R_DSO_FAILURE);
         goto err;
     }
@@ -482,8 +468,7 @@ static int ubsec_init(ENGINE *e)
     }
 
  err:
-    if (ubsec_dso)
-        DSO_free(ubsec_dso);
+    DSO_free(ubsec_dso);
     ubsec_dso = NULL;
     p_UBSEC_ubsec_bytes_to_bits = NULL;
     p_UBSEC_ubsec_bits_to_bytes = NULL;
@@ -625,7 +610,7 @@ static int ubsec_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa,
         /*
          * Do in software as hardware failed.
          */
-        const RSA_METHOD *meth = RSA_PKCS1_SSLeay();
+        const RSA_METHOD *meth = RSA_PKCS1_OpenSSL();
         to_return = (*meth->rsa_mod_exp) (r0, I, rsa, ctx);
     }
  err:
@@ -680,40 +665,6 @@ static int ubsec_mod_exp_crt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
 }
 #  endif
 
-#  ifndef OPENSSL_NO_DSA
-#   ifdef NOT_USED
-static int ubsec_dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1,
-                             BIGNUM *p1, BIGNUM *a2, BIGNUM *p2, BIGNUM *m,
-                             BN_CTX *ctx, BN_MONT_CTX *in_mont)
-{
-    BIGNUM t;
-    int to_return = 0;
-
-    BN_init(&t);
-    /* let rr = a1 ^ p1 mod m */
-    if (!ubsec_mod_exp(rr, a1, p1, m, ctx))
-        goto end;
-    /* let t = a2 ^ p2 mod m */
-    if (!ubsec_mod_exp(&t, a2, p2, m, ctx))
-        goto end;
-    /* let rr = rr * t mod m */
-    if (!BN_mod_mul(rr, rr, &t, m, ctx))
-        goto end;
-    to_return = 1;
- end:
-    BN_free(&t);
-    return to_return;
-}
-
-static int ubsec_mod_exp_dsa(DSA *dsa, BIGNUM *r, BIGNUM *a,
-                             const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx,
-                             BN_MONT_CTX *m_ctx)
-{
-    return ubsec_mod_exp(r, a, p, m, ctx);
-}
-#   endif
-#  endif
-
 #  ifndef OPENSSL_NO_RSA
 
 /*
@@ -727,7 +678,7 @@ static int ubsec_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
 
     /* Do in software if the key is too large for the hardware. */
     if (BN_num_bits(m) > max_key_len) {
-        const RSA_METHOD *meth = RSA_PKCS1_SSLeay();
+        const RSA_METHOD *meth = RSA_PKCS1_OpenSSL();
         ret = (*meth->bn_mod_exp) (r, a, p, m, ctx, m_ctx);
     } else {
         ret = ubsec_mod_exp(r, a, p, m, ctx);
@@ -825,10 +776,8 @@ static DSA_SIG *ubsec_dsa_do_sign(const unsigned char *dgst, int dlen,
 
  err:
     if (!to_return) {
-        if (r)
-            BN_free(r);
-        if (s)
-            BN_free(s);
+        BN_free(r);
+        BN_free(s);
     }
     BN_clear_free(&m);
     return to_return;
@@ -967,11 +916,11 @@ static int ubsec_dh_generate_key(DH *dh)
 
     if (dh->pub_key == NULL) {
         pub_key = BN_new();
+        if (pub_key == NULL)
+            goto err;
         pub_key_len = BN_num_bits(dh->p);
         if (bn_wexpand(pub_key, dh->p->top) == NULL)
             goto err;
-        if (pub_key == NULL)
-            goto err;
     } else {
         pub_key = dh->pub_key;
     }
@@ -1028,7 +977,7 @@ static int ubsec_rand_bytes(unsigned char *buf, int num)
         const RAND_METHOD *meth;
         UBSECerr(UBSEC_F_UBSEC_RAND_BYTES, UBSEC_R_UNIT_FAILURE);
         num = p_UBSEC_ubsec_bits_to_bytes(num);
-        meth = RAND_SSLeay();
+        meth = RAND_OpenSSL();
         meth->seed(buf, num);
         ret = meth->bytes(buf, num);
         goto err;
@@ -1044,7 +993,7 @@ static int ubsec_rand_bytes(unsigned char *buf, int num)
         p_UBSEC_ubsec_close(fd);
 
         num = p_UBSEC_ubsec_bits_to_bytes(num);
-        meth = RAND_SSLeay();
+        meth = RAND_OpenSSL();
         meth->seed(buf, num);
         ret = meth->bytes(buf, num);