#include <openssl/cms.h>
#include <openssl/rand.h>
#include "crypto/evp.h"
+#include "crypto/asn1.h"
#include "cms_local.h"
/* CMS EncryptedData Utilities */
if (enc) {
calg->algorithm = OBJ_nid2obj(EVP_CIPHER_CTX_get_type(ctx));
+ if (calg->algorithm == NULL || calg->algorithm->nid == NID_undef) {
+ ERR_raise(ERR_LIB_CMS, CMS_R_UNSUPPORTED_CONTENT_ENCRYPTION_ALGORITHM);
+ goto err;
+ }
/* Generate a random IV if we need one */
ivlen = EVP_CIPHER_CTX_get_iv_length(ctx);
if (ivlen < 0) {