[EC][ASN1] Detect missing OID when serializing EC parameters and keys
[openssl.git] / providers / implementations / serializers / serializer_ec.c
index 4d81651c5aa7ca6cc66058652601a39d66388ee6..0dbc889d343e0878446c215a9f69929f9a64995b 100644 (file)
@@ -11,6 +11,7 @@
 #include "crypto/ec.h"
 #include "prov/bio.h"             /* ossl_prov_bio_printf() */
 #include "prov/implementations.h" /* ec_keymgmt_functions */
+#include "prov/providercommonerr.h" /* PROV_R_MISSING_OID */
 #include "serializer_local.h"
 
 void ec_get_new_free_import(OSSL_FUNC_keymgmt_new_fn **ec_new,
@@ -117,6 +118,13 @@ int ossl_prov_prepare_ec_params(const void *eckey, int nid,
         return 0;
     }
 
+    if (OBJ_length(params) == 0) {
+        /* Some curves might not have an associated OID */
+        ERR_raise(ERR_LIB_PROV, PROV_R_MISSING_OID);
+        ASN1_OBJECT_free(params);
+        return 0;
+    }
+
     *pstr = params;
     *pstrtype = V_ASN1_OBJECT;
     return 1;