Implementation of pkey_rsa_verify. Some constification.
[openssl.git] / engines / e_4758cca.c
index e7f308e31403d54da6736df933a139676836350a..9f6572e677191aa56a657d3f1fb7a8e1a18aafb3 100644 (file)
@@ -61,7 +61,9 @@
 #include <openssl/objects.h>
 #include <openssl/engine.h>
 #include <openssl/rand.h>
+#ifndef OPENSSL_NO_RSA
 #include <openssl/rsa.h>
+#endif
 #include <openssl/bn.h>
 
 #ifndef OPENSSL_NO_HW
@@ -90,7 +92,7 @@ static int cca_rsa_priv_dec(int flen, const unsigned char *from,
 static int cca_rsa_sign(int type, const unsigned char *m, unsigned int m_len,
                unsigned char *sigret, unsigned int *siglen, const RSA *rsa);
 static int cca_rsa_verify(int dtype, const unsigned char *m, unsigned int m_len,
-               unsigned char *sigbuf, unsigned int siglen, const RSA *rsa);
+       const unsigned char *sigbuf, unsigned int siglen, const RSA *rsa);
 
 /* utility functions */
 /*-----------------------*/
@@ -109,8 +111,10 @@ static int getModulusAndExponent(const unsigned char *token, long *exponentLengt
 static int cca_get_random_bytes(unsigned char*, int );
 static int cca_random_status(void);
 
+#ifndef OPENSSL_NO_RSA
 static void cca_ex_free(void *obj, void *item, CRYPTO_EX_DATA *ad,
                int idx,long argl, void *argp);
+#endif
 
 /* Function pointers for CCA verbs */
 /*---------------------------------*/
@@ -154,7 +158,9 @@ static const char* n_pkaDecrypt = CSNDPKD;
 #endif
 static const char* n_randomNumberGenerate = CSNBRNG;
 
+#ifndef OPENSSL_NO_RSA
 static int hndidx = -1;
+#endif
 static DSO *dso = NULL;
 
 /* openssl engine initialization structures */
@@ -202,8 +208,10 @@ static RAND_METHOD ibm_4758_cca_rand =
 
 static const char *engine_4758_cca_id = "4758cca";
 static const char *engine_4758_cca_name = "IBM 4758 CCA hardware engine support";
+#ifndef OPENSSL_NO_DYNAMIC_ENGINE 
 /* Compatibility hack, the dynamic library uses this form in the path */
 static const char *engine_4758_cca_id_alt = "4758_cca";
+#endif
 
 /* engine implementation */
 /*-----------------------*/
@@ -219,8 +227,10 @@ static int bind_helper(ENGINE *e)
                        !ENGINE_set_init_function(e, ibm_4758_cca_init) ||
                        !ENGINE_set_finish_function(e, ibm_4758_cca_finish) ||
                        !ENGINE_set_ctrl_function(e, ibm_4758_cca_ctrl) ||
+#ifndef OPENSSL_NO_RSA
                        !ENGINE_set_load_privkey_function(e, ibm_4758_load_privkey) ||
                        !ENGINE_set_load_pubkey_function(e, ibm_4758_load_pubkey) ||
+#endif
                        !ENGINE_set_cmd_defns(e, cca4758_cmd_defns))
                return 0;
        /* Ensure the error handling is set up */
@@ -302,8 +312,10 @@ static int ibm_4758_cca_init(ENGINE *e)
                }
 #endif
 
+#ifndef OPENSSL_NO_RSA
        hndidx = RSA_get_ex_new_index(0, "IBM 4758 CCA RSA key handle",
                NULL, NULL, cca_ex_free);
+#endif
 
        return 1;
 err:
@@ -311,13 +323,15 @@ err:
                DSO_free(dso);
        dso = NULL;
 
+#ifndef OPENSSL_NO_RSA
        keyRecordRead = (F_KEYRECORDREAD)0;
-       randomNumberGenerate = (F_RANDOMNUMBERGENERATE)0;
        digitalSignatureGenerate = (F_DIGITALSIGNATUREGENERATE)0;
        digitalSignatureVerify = (F_DIGITALSIGNATUREVERIFY)0;
        publicKeyExtract = (F_PUBLICKEYEXTRACT)0;
        pkaEncrypt = (F_PKAENCRYPT)0;
        pkaDecrypt = (F_PKADECRYPT)0;
+#endif
+       randomNumberGenerate = (F_RANDOMNUMBERGENERATE)0;
        return 0;
        }
 
@@ -337,6 +351,7 @@ static int ibm_4758_cca_finish(ENGINE *e)
                return 0;
                }
        dso = NULL;
+#ifndef OPENSSL_NO_RSA
        keyRecordRead = (F_KEYRECORDREAD)0;
        randomNumberGenerate = (F_RANDOMNUMBERGENERATE)0;
        digitalSignatureGenerate = (F_DIGITALSIGNATUREGENERATE)0;
@@ -344,6 +359,8 @@ static int ibm_4758_cca_finish(ENGINE *e)
        publicKeyExtract = (F_PUBLICKEYEXTRACT)0;
        pkaEncrypt = (F_PKAENCRYPT)0;
        pkaDecrypt = (F_PKADECRYPT)0;
+#endif
+       randomNumberGenerate = (F_RANDOMNUMBERGENERATE)0;
        return 1;
        }
 
@@ -465,10 +482,6 @@ static EVP_PKEY *ibm_4758_load_privkey(ENGINE* e, const char* key_id,
 err:
        if (keyToken)
                OPENSSL_free(keyToken);
-       if (res)
-               EVP_PKEY_free(res);
-       if (rtmp)
-               RSA_free(rtmp);
        return NULL;
        }
 
@@ -543,10 +556,6 @@ static EVP_PKEY *ibm_4758_load_pubkey(ENGINE* e, const char* key_id,
 err:
        if (keyToken)
                OPENSSL_free(keyToken);
-       if (res)
-               EVP_PKEY_free(res);
-       if (rtmp)
-               RSA_free(rtmp);
        return NULL;
        }
 
@@ -609,7 +618,7 @@ static int cca_rsa_priv_dec(int flen, const unsigned char *from,
 #define SSL_SIG_LEN 36
 
 static int cca_rsa_verify(int type, const unsigned char *m, unsigned int m_len,
-               unsigned char *sigbuf, unsigned int siglen, const RSA *rsa)
+       const unsigned char *sigbuf, unsigned int siglen, const RSA *rsa)
        {
        long returnCode;
        long reasonCode;
@@ -718,7 +727,8 @@ static int cca_rsa_verify(int type, const unsigned char *m, unsigned int m_len,
 
        digitalSignatureVerify(&returnCode, &reasonCode, &exitDataLength,
                exitData, &ruleArrayLength, ruleArray, &keyTokenLength,
-               keyToken, &length, hashBuffer, &lsiglen, sigbuf);
+               keyToken, &length, hashBuffer, &lsiglen,
+                                               (unsigned char *)sigbuf);
 
        if (type == NID_sha1 || type == NID_md5)
                {
@@ -949,12 +959,14 @@ static int cca_get_random_bytes(unsigned char* buf, int num)
        return 1;
        }
 
+#ifndef OPENSSL_NO_RSA
 static void cca_ex_free(void *obj, void *item, CRYPTO_EX_DATA *ad, int idx,
                long argl, void *argp)
        {
        if (item)
                OPENSSL_free(item);
        }
+#endif
 
 /* Goo to handle building as a dynamic engine */
 #ifndef OPENSSL_NO_DYNAMIC_ENGINE