                  else if (RAND_bytes(rec->input, ivlen) <= 0)
                      return -1;
              }
+diff --git a/test/cms-test.pl b/test/cms-test.pl
+index baa3b59..1ee3f02 100644
+--- a/test/cms-test.pl
++++ b/test/cms-test.pl
+@@ -100,6 +100,13 @@ my $no_ec2m;
+ my $no_ecdh;
+ my $ossl8 = `$ossl_path version -v` =~ /0\.9\.8/;
+ 
++system ("$ossl_path no-cms > $null_path");
++if ($? == 0)
++        {
++        print "CMS disabled\n";
++        exit 0;
++        }
++
+ system ("$ossl_path no-ec > $null_path");
+ if ($? == 0)
+ 	{
+diff --git a/util/libeay.num b/util/libeay.num
+index 7f7487d..13b2e3a 100755
+--- a/util/libeay.num
++++ b/util/libeay.num
+@@ -4368,7 +4368,7 @@ DH_compute_key_padded                   4732	EXIST::FUNCTION:DH
+ ECDSA_METHOD_set_sign                   4733	EXIST::FUNCTION:ECDSA
+ CMS_RecipientEncryptedKey_cert_cmp      4734	EXIST:!VMS:FUNCTION:CMS
+ CMS_RecipEncryptedKey_cert_cmp          4734	EXIST:VMS:FUNCTION:CMS
+-DH_KDF_X9_42                            4735	EXIST::FUNCTION:DH
++DH_KDF_X9_42                            4735	EXIST::FUNCTION:CMS,DH
+ RSA_OAEP_PARAMS_free                    4736	EXIST::FUNCTION:RSA
+ EVP_des_ede3_wrap                       4737	EXIST::FUNCTION:DES
+ RSA_OAEP_PARAMS_it                      4738	EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:RSA
 diff --git a/util/mkerr.pl b/util/mkerr.pl
 index 09ebebe..cd57ade 100644
 --- a/util/mkerr.pl

 int DES_read_password(DES_cblock *key, const char *prompt, int verify)
 {
     int ok;
diff --git a/crypto/dh/dh_pmeth.c b/crypto/dh/dh_pmeth.c
index b58e3fa..e5f345a 100644
--- a/crypto/dh/dh_pmeth.c
+++ b/crypto/dh/dh_pmeth.c
@@ -449,6 +449,9 @@ static int pkey_dh_derive(EVP_PKEY_CTX *ctx, unsigned char *key,
         *keylen = ret;
         return 1;
     } else if (dctx->kdf_type == EVP_PKEY_DH_KDF_X9_42) {
+#ifdef OPENSSL_NO_CMS
+        return 0;
+#else
         unsigned char *Z = NULL;
         size_t Zlen = 0;
         if (!dctx->kdf_outlen || !dctx->kdf_oid)
@@ -478,6 +481,7 @@ static int pkey_dh_derive(EVP_PKEY_CTX *ctx, unsigned char *key,
             OPENSSL_free(Z);
         }
         return ret;
+#endif
     }
     return 1;
 }
diff --git a/crypto/engine/eng_int.h b/crypto/engine/eng_int.h
index 46f163b..b4a72a0 100644
--- a/crypto/engine/eng_int.h

 
 static int rsa_item_sign(EVP_MD_CTX *ctx, const ASN1_ITEM *it, void *asn,
                          X509_ALGOR *alg1, X509_ALGOR *alg2,
@@ -762,6 +768,7 @@ static int rsa_item_sign(EVP_MD_CTX *ctx, const ASN1_ITEM *it, void *asn,
     return 2;
 }
 
+#ifndef OPENSSL_NO_CMS
 static RSA_OAEP_PARAMS *rsa_oaep_decode(const X509_ALGOR *alg,
                                         X509_ALGOR **pmaskHash)
 {
@@ -920,6 +927,7 @@ static int rsa_cms_encrypt(CMS_RecipientInfo *ri)
         ASN1_STRING_free(os);
     return rv;
 }
