Add EC support to x509write_pubkey
diff --git a/include/polarssl/asn1write.h b/include/polarssl/asn1write.h
index 6116502..1eb7e69 100644
--- a/include/polarssl/asn1write.h
+++ b/include/polarssl/asn1write.h
@@ -29,7 +29,7 @@
 
 #include "asn1.h"
 
-#define ASN1_CHK_ADD(g, f) if( ( ret = f ) < 0 ) return( ret ); else g += ret
+#define ASN1_CHK_ADD(g, f) do { if( ( ret = f ) < 0 ) return( ret ); else g += ret; } while( 0 )
 
 #ifdef __cplusplus
 extern "C" {
diff --git a/include/polarssl/ecp.h b/include/polarssl/ecp.h
index ad31bff..c7689c1 100644
--- a/include/polarssl/ecp.h
+++ b/include/polarssl/ecp.h
@@ -133,6 +133,7 @@
  */
 #define POLARSSL_ECP_MAX_BITS     521
 #define POLARSSL_ECP_MAX_BYTES    ( ( POLARSSL_ECP_MAX_BITS + 7 ) / 8 )
+#define POLARSSL_ECP_MAX_PT_LEN   ( 2 * POLARSSL_ECP_MAX_BYTES + 1 )
 
 /*
  * Maximum window size (actually, NAF width) used for point multipliation.
diff --git a/include/polarssl/oid.h b/include/polarssl/oid.h
index b0e781f..6981237 100644
--- a/include/polarssl/oid.h
+++ b/include/polarssl/oid.h
@@ -370,8 +370,9 @@
  */
 int oid_get_pk_alg( const asn1_buf *oid, pk_type_t *pk_alg );
 
+#if defined(POLARSSL_ECP_C)
 /**
- * \brief          Translate ECParameters OID into an EC group identifier
+ * \brief          Translate NamedCurve OID into an EC group identifier
  *
  * \param oid      OID to use
  * \param grp_id   place to store group id
@@ -380,6 +381,19 @@
  */
 int oid_get_ec_grp( const asn1_buf *oid, ecp_group_id *grp_id );
 
+/**
+ * \brief           Translate EC group identifier into NamedCurve OID
+ *
+ * \param grp_id    EC group identifier
+ * \param oid      place to store ASN.1 OID string pointer
+ * \param olen     length of the OID
+ *
+ * \return         0 if successful, or POLARSSL_ERR_OID_NOT_FOUND
+ */
+int oid_get_oid_by_ec_grp( ecp_group_id grp_id,
+                           const char **oid, size_t *olen );
+#endif /* POLARSSL_ECP_C */
+
 #if defined(POLARSSL_MD_C)
 /**
  * \brief          Translate SignatureAlgorithm OID into md_type and pk_type