@@ -453,6 +453,7 @@ static CK_ULONG get_EC_point(EVP_PKEY *pubkey, CK_BYTE_PTR *buf)
453453 EC_KEY * ec = NULL ;
454454 int i2dlen = 0 ;
455455 unsigned char * octp = NULL , * octbuf = NULL ;
456+ ASN1_OCTET_STRING * wrapped = NULL ;
456457
457458 if ( pubkey && EVP_PKEY_base_id (pubkey )== EVP_PKEY_EC ) {
458459
@@ -508,7 +509,7 @@ static CK_ULONG get_EC_point(EVP_PKEY *pubkey, CK_BYTE_PTR *buf)
508509 /* DER-encoded of point in octbuf */
509510 /* now wrap this into OCTET_STRING */
510511
511- ASN1_OCTET_STRING * wrapped = ASN1_OCTET_STRING_new ();
512+ wrapped = ASN1_OCTET_STRING_new ();
512513
513514 if (wrapped == NULL ) {
514515 P_ERR ();
@@ -551,6 +552,7 @@ static CK_ULONG get_EC_point(EVP_PKEY *pubkey, CK_BYTE_PTR *buf)
551552 }
552553error :
553554 if (octbuf != NULL ) { OPENSSL_free (octbuf ); }
555+ if (wrapped != NULL ) { ASN1_OCTET_STRING_free (wrapped ); }
554556
555557 return rv ;
556558}
@@ -624,50 +626,50 @@ static CK_ULONG get_ED_point(EVP_PKEY *pubkey, CK_BYTE_PTR *buf)
624626
625627 const uint8_t * pk ;
626628 int pklen ;
627-
629+
628630 X509_PUBKEY_get0_param (NULL , & pk , & pklen , NULL , x509_pk ); /* nothing to test, always returns 1 */
629631
630632 if ( (point = ASN1_OCTET_STRING_new ()) == NULL ) {
631633 P_ERR ();
632634 goto error ;
633635 }
634636 ASN1_OCTET_STRING_set (point , pk , pklen ); /* assign */
635-
637+
636638 len = i2d_ASN1_OCTET_STRING (point , buf );
637639 if (len < 0 ) {
638640 P_ERR ();
639641 goto error ;
640642 }
641643
642644 rv = len ;
643-
645+
644646error :
645647 if (point ) { ASN1_OCTET_STRING_free (point ); }
646648 if (x509_pk ) { X509_PUBKEY_free (x509_pk ); }
647- if (pkeybuf ) { OPENSSL_free (pkeybuf ); }
649+ if (pkeybuf ) { OPENSSL_free (pkeybuf ); }
648650 return rv ;
649651}
650652
651653static CK_ULONG get_ED_params (EVP_PKEY * pubkey , CK_BYTE_PTR * buf )
652654{
653655 CK_ULONG rv = 0 ;
654656 ASN1_OBJECT * obj = NULL ;
655-
657+
656658 obj = OBJ_nid2obj (EVP_PKEY_base_id (pubkey ));
657659 if (!obj ) {
658660 P_ERR ();
659661 goto error ;
660662 }
661663
662- assert ( * buf == NULL ); /* make sure we point to nowhere */
664+ assert ( * buf == NULL ); /* make sure we point to nowhere */
663665 int len = i2d_ASN1_OBJECT (obj , buf );
664666 if (len < 0 ) {
665667 P_ERR ();
666668 goto error ;
667669 }
668670
669671 rv = len ;
670-
672+
671673error :
672674 if (obj ) { ASN1_OBJECT_free (obj ); }
673675 return rv ;
@@ -870,7 +872,6 @@ static CK_ULONG get_EVP_PKEY_sha1(EVP_PKEY *pubkey, CK_BYTE_PTR *buf) {
870872 }
871873 /* get0 on ec_point & ec_group, we can safely forget */
872874 }
873- EC_KEY_free (ec );
874875 }
875876 }
876877 break ;
@@ -904,7 +905,7 @@ static CK_ULONG get_EVP_PKEY_sha1(EVP_PKEY *pubkey, CK_BYTE_PTR *buf) {
904905 }
905906 }
906907 break ;
907-
908+
908909
909910 case EVP_PKEY_DH : {
910911 DH * dh ;
@@ -1043,7 +1044,7 @@ static CK_OBJECT_HANDLE _importpubk( pkcs11Context * p11Context,
10431044 {0L , NULL , 0L },
10441045 {0L , NULL , 0L },
10451046 };
1046-
1047+
10471048 size_t pubk_template_len_max = (sizeof (pubktemplate )/sizeof (CK_ATTRIBUTE ));
10481049 size_t pubk_template_len_min = pubk_template_len_max - 12 ;
10491050 size_t pubk_num_elems = pubk_template_len_min ;
@@ -1077,7 +1078,7 @@ static CK_OBJECT_HANDLE _importpubk( pkcs11Context * p11Context,
10771078 case CKA_VERIFY :
10781079 case CKA_VERIFY_RECOVER : /* not in template onwards */
10791080 case CKA_DERIVE :
1080- case CKA_TRUSTED :
1081+ case CKA_TRUSTED :
10811082 case CKA_PRIVATE :
10821083 case CKA_WRAP_TEMPLATE :
10831084 case CKA_COPYABLE :
@@ -1089,7 +1090,7 @@ static CK_OBJECT_HANDLE _importpubk( pkcs11Context * p11Context,
10891090 case CKA_PUBLIC_KEY_INFO :
10901091 {
10911092 size_t next_pubk_num_elems = pubk_num_elems ;
1092-
1093+
10931094 CK_ATTRIBUTE_PTR match = lsearch ( & attrs [i ],
10941095 pubktemplate ,
10951096 & next_pubk_num_elems ,
@@ -1108,7 +1109,7 @@ static CK_OBJECT_HANDLE _importpubk( pkcs11Context * p11Context,
11081109 else {
11091110 /* everything was copied by lsearch */
11101111 /* just increment array length */
1111- pubk_num_elems = next_pubk_num_elems ;
1112+ pubk_num_elems = next_pubk_num_elems ;
11121113 }
11131114 } else {
11141115 fprintf (stderr , "***Error: can't update attribute array - skipping 0x%08lx\n" , attrs [i ].type );
@@ -1125,7 +1126,7 @@ static CK_OBJECT_HANDLE _importpubk( pkcs11Context * p11Context,
11251126 break ;
11261127 }
11271128 }
1128-
1129+
11291130 retCode = p11Context -> FunctionList .C_CreateObject (p11Context -> Session ,
11301131 pubktemplate ,
11311132 pubk_num_elems ,
@@ -1229,7 +1230,7 @@ static CK_OBJECT_HANDLE _importpubk( pkcs11Context * p11Context,
12291230 case CKA_VERIFY :
12301231 case CKA_VERIFY_RECOVER : /* not in template onwards */
12311232 case CKA_DERIVE :
1232- case CKA_TRUSTED :
1233+ case CKA_TRUSTED :
12331234 case CKA_PRIVATE :
12341235 case CKA_COPYABLE :
12351236 case CKA_MODIFIABLE :
@@ -1240,7 +1241,7 @@ static CK_OBJECT_HANDLE _importpubk( pkcs11Context * p11Context,
12401241 case CKA_PUBLIC_KEY_INFO :
12411242 {
12421243 size_t next_pubk_num_elems = pubk_num_elems ;
1243-
1244+
12441245 CK_ATTRIBUTE_PTR match = lsearch ( & attrs [i ],
12451246 pubktemplate ,
12461247 & next_pubk_num_elems ,
@@ -1259,7 +1260,7 @@ static CK_OBJECT_HANDLE _importpubk( pkcs11Context * p11Context,
12591260 else {
12601261 /* everything was copied by lsearch */
12611262 /* just increment array length */
1262- pubk_num_elems = next_pubk_num_elems ;
1263+ pubk_num_elems = next_pubk_num_elems ;
12631264 }
12641265 } else {
12651266 fprintf (stderr , "***Error: can't update attribute array - skipping 0x%08lx\n" , attrs [i ].type );
@@ -1380,7 +1381,7 @@ static CK_OBJECT_HANDLE _importpubk( pkcs11Context * p11Context,
13801381 case CKA_PUBLIC_KEY_INFO :
13811382 {
13821383 size_t next_pubk_num_elems = pubk_num_elems ;
1383-
1384+
13841385 CK_ATTRIBUTE_PTR match = lsearch ( & attrs [i ],
13851386 pubktemplate ,
13861387 & next_pubk_num_elems ,
@@ -1399,7 +1400,7 @@ static CK_OBJECT_HANDLE _importpubk( pkcs11Context * p11Context,
13991400 else {
14001401 /* everything was copied by lsearch */
14011402 /* just increment array length */
1402- pubk_num_elems = next_pubk_num_elems ;
1403+ pubk_num_elems = next_pubk_num_elems ;
14031404 }
14041405 } else {
14051406 fprintf (stderr , "***Error: can't update attribute array - skipping 0x%08lx\n" , attrs [i ].type );
@@ -1416,7 +1417,7 @@ static CK_OBJECT_HANDLE _importpubk( pkcs11Context * p11Context,
14161417 break ;
14171418 }
14181419 }
1419-
1420+
14201421 retCode = p11Context -> FunctionList .C_CreateObject (p11Context -> Session ,
14211422 pubktemplate ,
14221423 pubk_num_elems ,
@@ -1500,7 +1501,7 @@ static CK_OBJECT_HANDLE _importpubk( pkcs11Context * p11Context,
15001501 case CKA_VERIFY :
15011502 case CKA_VERIFY_RECOVER : /* not in template onwards */
15021503 case CKA_DERIVE :
1503- case CKA_TRUSTED :
1504+ case CKA_TRUSTED :
15041505 case CKA_PRIVATE :
15051506 case CKA_COPYABLE :
15061507 case CKA_MODIFIABLE :
@@ -1511,7 +1512,7 @@ static CK_OBJECT_HANDLE _importpubk( pkcs11Context * p11Context,
15111512 case CKA_PUBLIC_KEY_INFO :
15121513 {
15131514 size_t next_pubk_num_elems = pubk_num_elems ;
1514-
1515+
15151516 CK_ATTRIBUTE_PTR match = lsearch ( & attrs [i ],
15161517 pubktemplate ,
15171518 & next_pubk_num_elems ,
@@ -1530,7 +1531,7 @@ static CK_OBJECT_HANDLE _importpubk( pkcs11Context * p11Context,
15301531 else {
15311532 /* everything was copied by lsearch */
15321533 /* just increment array length */
1533- pubk_num_elems = next_pubk_num_elems ;
1534+ pubk_num_elems = next_pubk_num_elems ;
15341535 }
15351536 } else {
15361537 fprintf (stderr , "***Error: can't update attribute array - skipping 0x%08lx\n" , attrs [i ].type );
@@ -1547,7 +1548,7 @@ static CK_OBJECT_HANDLE _importpubk( pkcs11Context * p11Context,
15471548 break ;
15481549 }
15491550 }
1550-
1551+
15511552 retCode = p11Context -> FunctionList .C_CreateObject (p11Context -> Session ,
15521553 pubktemplate ,
15531554 pubk_num_elems ,
@@ -1595,9 +1596,9 @@ static CK_OBJECT_HANDLE _importpubk( pkcs11Context * p11Context,
15951596 {0L , NULL , 0L },
15961597 {0L , NULL , 0L },
15971598 {0L , NULL , 0L },
1598- {0L , NULL , 0L },
15991599 {0L , NULL , 0L },
1600- {0L , NULL , 0L },
1600+ {0L , NULL , 0L },
1601+ {0L , NULL , 0L },
16011602 };
16021603
16031604 size_t pubk_template_len_max = (sizeof (pubktemplate )/sizeof (CK_ATTRIBUTE ));
@@ -1633,7 +1634,7 @@ static CK_OBJECT_HANDLE _importpubk( pkcs11Context * p11Context,
16331634 case CKA_VERIFY :
16341635 case CKA_VERIFY_RECOVER : /* not in template onwards */
16351636 case CKA_DERIVE :
1636- case CKA_TRUSTED :
1637+ case CKA_TRUSTED :
16371638 case CKA_PRIVATE :
16381639 case CKA_WRAP_TEMPLATE :
16391640 case CKA_COPYABLE :
@@ -1645,7 +1646,7 @@ static CK_OBJECT_HANDLE _importpubk( pkcs11Context * p11Context,
16451646 case CKA_PUBLIC_KEY_INFO :
16461647 {
16471648 size_t next_pubk_num_elems = pubk_num_elems ;
1648-
1649+
16491650 CK_ATTRIBUTE_PTR match = lsearch ( & attrs [i ],
16501651 pubktemplate ,
16511652 & next_pubk_num_elems ,
@@ -1664,7 +1665,7 @@ static CK_OBJECT_HANDLE _importpubk( pkcs11Context * p11Context,
16641665 else {
16651666 /* everything was copied by lsearch */
16661667 /* just increment array length */
1667- pubk_num_elems = next_pubk_num_elems ;
1668+ pubk_num_elems = next_pubk_num_elems ;
16681669 }
16691670 } else {
16701671 fprintf (stderr , "***Error: can't update attribute array - skipping 0x%08lx\n" , attrs [i ].type );
@@ -1681,7 +1682,7 @@ static CK_OBJECT_HANDLE _importpubk( pkcs11Context * p11Context,
16811682 break ;
16821683 }
16831684 }
1684-
1685+
16851686 retCode = p11Context -> FunctionList .C_CreateObject (p11Context -> Session ,
16861687 pubktemplate ,
16871688 pubk_num_elems ,
@@ -1705,7 +1706,7 @@ static CK_OBJECT_HANDLE _importpubk( pkcs11Context * p11Context,
17051706 break ;
17061707 }
17071708
1708- OPENSSL_free (pubk );
1709+ EVP_PKEY_free (pubk );
17091710
17101711 }
17111712 return pubkhandle ;
@@ -1734,4 +1735,3 @@ inline CK_OBJECT_HANDLE pkcs11_importpubk_from_buffer( pkcs11Context * p11Contex
17341735 CK_ULONG numattrs ) {
17351736 return _importpubk (p11Context , NULL , buffer , len , label , attrs , numattrs , source_buffer );
17361737}
1737-
0 commit comments