make update (libeay.num has been edited to match 0.9.7-stable)
[openssl.git] / crypto / engine / hw_openbsd_dev_crypto.c
index e3c51d18d7aa5ae1af13f728f4f2dcdf8a4d5617..f946389b8a31bc9e867702d9cbb7ecfb2687d006 100644 (file)
  *
  */
 
  *
  */
 
+#include <openssl/engine.h>
+#include <openssl/evp.h>
+#include "eng_int.h"
+/* Maybe this is needed? ... */
+#ifdef FLAT_INC
+#include "evp_locl.h"
+#else
+#include "../evp/evp_locl.h"
+#endif
+#include <openssl/conf.h>
+
 #ifndef OPENSSL_OPENBSD_DEV_CRYPTO
 
 #ifndef OPENSSL_OPENBSD_DEV_CRYPTO
 
-static void *dummy=&dummy;
+void ENGINE_load_openbsd_dev_crypto(void)
+       {
+       /* This is a NOP unless OPENSSL_OPENBSD_DEV_CRYPTO is defined */
+       return;
+       }
 
 #else /* OPENSSL_OPENBSD_DEV_CRYPTO */
 
 #include <fcntl.h>
 #include <stdio.h>
 #include <errno.h>
 
 #else /* OPENSSL_OPENBSD_DEV_CRYPTO */
 
 #include <fcntl.h>
 #include <stdio.h>
 #include <errno.h>
+#include <assert.h>
+#include <unistd.h>
 #include <sys/ioctl.h>
 #include <sys/ioctl.h>
+
 #include <crypto/cryptodev.h>
 #include <crypto/cryptodev.h>
-#include <openssl/engine.h>
-#include <openssl/evp.h>
-#include "eng_int.h"
-/* Maybe this is needed? ... */
-#include "../evp/evp_locl.h"
 
 /****************************************************/
 /* Declare the normal generic ENGINE stuff here ... */
 
 /****************************************************/
 /* Declare the normal generic ENGINE stuff here ... */
@@ -78,17 +91,44 @@ static int dev_crypto_ciphers(ENGINE *e, const EVP_CIPHER **cipher,
 static int dev_crypto_digests(ENGINE *e, const EVP_MD **digest,
                                const int **nids, int nid);
 
 static int dev_crypto_digests(ENGINE *e, const EVP_MD **digest,
                                const int **nids, int nid);
 
-static const char *dev_crypto_id = "openbsd_dev_crypto";
-static const char *dev_crypto_name = "OpenBSD /dev/crypto";
+static const char dev_crypto_id[] = "openbsd_dev_crypto";
+static const char dev_crypto_name[] = "OpenBSD /dev/crypto";
+
+static long allow_misaligned;
+
+#define DEV_CRYPTO_CMD_ALLOW_MISALIGNED                ENGINE_CMD_BASE
+static const ENGINE_CMD_DEFN dev_crypto_cmd_defns[]=
+       {
+       { DEV_CRYPTO_CMD_ALLOW_MISALIGNED,
+         "allow_misaligned",
+         "Permit misaligned data to be used",
+         ENGINE_CMD_FLAG_NUMERIC },
+       { 0, NULL, NULL, 0 }
+       };
+
+static int dev_crypto_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)())
+       {
+       switch(cmd)
+               {
+       case DEV_CRYPTO_CMD_ALLOW_MISALIGNED:
+               allow_misaligned=i;
+               printf("allow misaligned=%ld\n",allow_misaligned);
+               break;
+               }
+
+       return 1;
+       }
 
 static ENGINE *engine_openbsd_dev_crypto(void)
        {
        ENGINE *engine=ENGINE_new();
 
        if(!ENGINE_set_id(engine, dev_crypto_id) ||
 
 static ENGINE *engine_openbsd_dev_crypto(void)
        {
        ENGINE *engine=ENGINE_new();
 
        if(!ENGINE_set_id(engine, dev_crypto_id) ||
-                       !ENGINE_set_name(engine, dev_crypto_name) ||
-                       !ENGINE_set_ciphers(engine, dev_crypto_ciphers) ||
-                       !ENGINE_set_digests(engine, dev_crypto_digests))
+          !ENGINE_set_name(engine, dev_crypto_name) ||
+          !ENGINE_set_ciphers(engine, dev_crypto_ciphers) ||
+          !ENGINE_set_digests(engine, dev_crypto_digests) ||
+          !ENGINE_set_ctrl_function(engine, dev_crypto_ctrl) ||
+          !ENGINE_set_cmd_defns(engine, dev_crypto_cmd_defns))
                {
                ENGINE_free(engine);
                return NULL;
                {
                ENGINE_free(engine);
                return NULL;
@@ -176,6 +216,7 @@ static int dev_crypto_init(session_op *ses)
 
 static int dev_crypto_cleanup(EVP_CIPHER_CTX *ctx)
     {
 
 static int dev_crypto_cleanup(EVP_CIPHER_CTX *ctx)
     {
+    fprintf(stderr,"cleanup %d\n",CDATA(ctx)->ses);
     if(ioctl(fd,CIOCFSESSION,&CDATA(ctx)->ses) == -1)
        err("CIOCFSESSION failed");
 
     if(ioctl(fd,CIOCFSESSION,&CDATA(ctx)->ses) == -1)
        err("CIOCFSESSION failed");
 
@@ -325,11 +366,13 @@ static int dev_crypto_init_digest(MD_DATA *md_data,int mac)
        err("CIOCGSESSION failed");
        return 0;
        }
        err("CIOCGSESSION failed");
        return 0;
        }
+    fprintf(stderr,"opened %d\n",md_data->sess.ses);
     return 1;
     }
 
 static int dev_crypto_cleanup_digest(MD_DATA *md_data)
     {
     return 1;
     }
 
 static int dev_crypto_cleanup_digest(MD_DATA *md_data)
     {
+    fprintf(stderr,"cleanup %d\n",md_data->sess.ses);
     if (ioctl(fd,CIOCFSESSION,&md_data->sess.ses) == -1)
        {
        err("CIOCFSESSION failed");
     if (ioctl(fd,CIOCFSESSION,&md_data->sess.ses) == -1)
        {
        err("CIOCFSESSION failed");
@@ -370,7 +413,7 @@ static int do_digest(int ses,unsigned char *md,const void *data,int len)
 
     if(ioctl(fd, CIOCCRYPT, &cryp) == -1)
        {
 
     if(ioctl(fd, CIOCCRYPT, &cryp) == -1)
        {
-       if(errno == EINVAL) /* buffer is misaligned */
+       if(errno == EINVAL && allow_misaligned) /* buffer is misaligned */
            {
            char *dcopy;
 
            {
            char *dcopy;