--- openbsd_hw.c.orig	2016-03-02 15:36:57.236927351 -0800
+++ openbsd_hw.c	2016-03-02 15:40:29.525908189 -0800
@@ -133,6 +133,10 @@
         return 0;
 
     CDATA(ctx)->key = OPENSSL_malloc(MAX_HW_KEY);
+    if (CDATA(ctx)->key == NULL {
+	err("CDATA(ctx)->key memory allocation failed");
+	return 0;
+    }
 
     assert(ctx->cipher->iv_len <= MAX_HW_IV);
 
@@ -186,6 +190,11 @@
 
             if (((unsigned long)in & 3) || cinl != inl) {
                 cin = OPENSSL_malloc(cinl);
+		if (cin == NULL) {
+		    err("cin - memory allocation failed");
+		    abort();
+		    return 0;
+		}
                 memcpy(cin, in, inl);
                 cryp.src = cin;
             }
@@ -334,6 +343,11 @@
             char *dcopy;
 
             dcopy = OPENSSL_malloc(len);
+	    if (dcopy == NULL) {
+		err("dcopy - memory allocation failed");
+		abort();
+		return 0;
+	    }
             memcpy(dcopy, data, len);
             cryp.src = dcopy;
             cryp.dst = cryp.src; // FIXME!!!
@@ -397,6 +411,10 @@
     assert(from->digest->flags & EVP_MD_FLAG_ONESHOT);
 
     to_md->data = OPENSSL_malloc(from_md->len);
+    if (to_md->data == NULL) {
+	err("DEV_CRYPTO_MD5_COPY: unable to allocate memory");
+	return 0;
+    }
     memcpy(to_md->data, from_md->data, from_md->len);
 
     return 1;
