New function EC_GROUP_check_discriminant().
[openssl.git] / crypto / pem / pem_info.c
index b6ca51a1869ad603c8936f284eaf4fc486d3cea3..dba1c430da1ca9e69c60c586f76a60bb05045c60 100644 (file)
@@ -111,7 +111,7 @@ STACK_OF(X509_INFO) *PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk, pe
                i=PEM_read_bio(bp,&name,&header,&data,&len);
                if (i == 0)
                        {
-                       error=ERR_GET_REASON(ERR_peek_error());
+                       error=ERR_GET_REASON(ERR_peek_last_error());
                        if (error == PEM_R_NO_START_LINE)
                                {
                                ERR_clear_error();
@@ -202,6 +202,30 @@ start:
                                raw=1;
                        }
                else
+#endif
+#ifndef OPENSSL_NO_ECDSA
+                       if (strcmp(name,PEM_STRING_ECDSA) == 0)
+                       {
+                               d2i=(char *(*)())d2i_ECDSAPrivateKey;
+                               if (xi->x_pkey != NULL) 
+                               {
+                                       if (!sk_X509_INFO_push(ret,xi)) goto err;
+                                       if ((xi=X509_INFO_new()) == NULL) goto err;
+                                               goto start;
+                               }
+                       xi->enc_data=NULL;
+                       xi->enc_len=0;
+                       xi->x_pkey=X509_PKEY_new();
+                       if ((xi->x_pkey->dec_pkey=EVP_PKEY_new()) == NULL)
+                               goto err;
+                       xi->x_pkey->dec_pkey->type=EVP_PKEY_ECDSA;
+                       pp=(char **)&(xi->x_pkey->dec_pkey->pkey.ecdsa);
+                       if ((int)strlen(header) > 10) /* assume encrypted */
+                               raw=1;
+                       }
+               else
 #endif
                        {
                        d2i=NULL;
@@ -326,7 +350,7 @@ int PEM_X509_INFO_write_bio(BIO *bp, X509_INFO *xi, EVP_CIPHER *enc,
                        /* create the right magic header stuff */
                        buf[0]='\0';
                        PEM_proc_type(buf,PEM_TYPE_ENCRYPTED);
-                       PEM_dek_info(buf,objstr,8,(char *)iv);
+                       PEM_dek_info(buf,objstr,enc->iv_len,(char *)iv);
 
                        /* use the normal code to write things out */
                        i=PEM_write_bio(bp,PEM_STRING_RSA,buf,data,i);