ECP: Write RFC5480 representation of a group/point

New functions to write a representation of an elliptic curve group and
point according to X9.62 and RFC5480: ECParameters as OID and ECPoint
as octet string.
diff --git a/tests/suites/test_suite_ecp.data b/tests/suites/test_suite_ecp.data
index a43e7d7..c165d18 100644
--- a/tests/suites/test_suite_ecp.data
+++ b/tests/suites/test_suite_ecp.data
@@ -30,6 +30,26 @@
 depends_on:MBEDTLS_ECP_DP_SECP192R1_ENABLED
 mbedtls_ecp_curve_info:MBEDTLS_ECP_DP_SECP192R1:19:192:"secp192r1"
 
+ECP write ECParameters OID secp192r1
+depends_on:MBEDTLS_ASN1_WRITE_C:MBEDTLS_OID_C:MBEDTLS_ECP_DP_SECP192R1_ENABLED
+ecp_ansi_write_group:MBEDTLS_ECP_DP_SECP192R1:"06082a8648ce3d030101"
+
+ECP write ECParameters OID secp521r1
+depends_on:MBEDTLS_ASN1_WRITE_C:MBEDTLS_OID_C:MBEDTLS_ECP_DP_SECP521R1_ENABLED
+ecp_ansi_write_group:MBEDTLS_ECP_DP_SECP521R1:"06052b81040023"
+
+ECP write ECParameters OID brainpoolP512r1
+depends_on:MBEDTLS_ASN1_WRITE_C:MBEDTLS_OID_C:MBEDTLS_ECP_DP_BP512R1_ENABLED
+ecp_ansi_write_group:MBEDTLS_ECP_DP_BP512R1:"06092b240303020801010d"
+
+ECP write ECPoint octet string (uncompressed)
+depends_on:MBEDTLS_ASN1_WRITE_C:MBEDTLS_OID_C:MBEDTLS_PK_PARSE_C:MBEDTLS_ECP_DP_SECP192R1_ENABLED
+ecp_ansi_write_point:"data_files/ec_pub.der":MBEDTLS_ECP_PF_UNCOMPRESSED:"043104bc797db3ae7f08ec3d496b4fb411b3f620a558a501e0222d08cfe0dc8aec8b1a7bf24be92951cc5ba1bebb2474909ae0"
+
+ECP write ECPoint octet string (compressed)
+depends_on:MBEDTLS_ASN1_WRITE_C:MBEDTLS_OID_C:MBEDTLS_PK_PARSE_C:MBEDTLS_ECP_DP_SECP192R1_ENABLED
+ecp_ansi_write_point:"data_files/ec_pub.der":MBEDTLS_ECP_PF_COMPRESSED:"041902bc797db3ae7f08ec3d496b4fb411b3f620a558a501e0222d"
+
 ECP check pubkey Montgomery #1 (too big)
 depends_on:MBEDTLS_ECP_DP_CURVE25519_ENABLED
 ecp_check_pub:MBEDTLS_ECP_DP_CURVE25519:"010000000000000000000000000000000000000000000000000000000000000000":"0":"1":MBEDTLS_ERR_ECP_INVALID_KEY
diff --git a/tests/suites/test_suite_ecp.function b/tests/suites/test_suite_ecp.function
index 99780c0..4b81090 100644
--- a/tests/suites/test_suite_ecp.function
+++ b/tests/suites/test_suite_ecp.function
@@ -1,5 +1,6 @@
 /* BEGIN_HEADER */
 #include "mbedtls/ecp.h"
+#include "mbedtls/pk.h"
 
 #define ECP_PF_UNKNOWN     -1
 /* END_HEADER */
@@ -412,6 +413,63 @@
 }
 /* END_CASE */
 
+/* BEGIN_CASE depends_on:MBEDTLS_ASN1_WRITE_C:MBEDTLS_OID_C */
+void ecp_ansi_write_group( int id, char *hex )
+{
+    mbedtls_ecp_group grp;
+    unsigned char good[MBEDTLS_OID_EC_GRP_MAX_SIZE];
+    unsigned char tested[MBEDTLS_OID_EC_GRP_MAX_SIZE];
+    size_t good_len = unhexify( good, hex );
+    int ret = 0;
+    mbedtls_ecp_group_init( &grp );
+    TEST_ASSERT( mbedtls_ecp_group_load( &grp, id ) == 0 );
+
+    /* Positive test */
+    ret = mbedtls_ecp_ansi_write_group( &grp, tested, sizeof( tested ) );
+    TEST_ASSERT( ret >= 0 && good_len == (unsigned) ret );
+    TEST_ASSERT( memcmp( good, tested, good_len ) == 0 );
+
+    /* Buffer too small */
+    TEST_ASSERT( mbedtls_ecp_ansi_write_group( &grp, tested, good_len - 1 ) ==
+                 MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL );
+
+exit:
+    mbedtls_ecp_group_free( &grp );
+}
+/* END_CASE */
+
+/* BEGIN_CASE depends_on:MBEDTLS_ASN1_WRITE_C:MBEDTLS_OID_C:MBEDTLS_PK_PARSE_C:MBEDTLS_FS_IO */
+void ecp_ansi_write_point( char *key_file, int format, char *good_hex )
+{
+    unsigned char good_buf[1000];
+    unsigned char tested_buf[1000];
+    size_t good_len = unhexify( good_buf, good_hex );
+    mbedtls_pk_context pk;
+    int ret = 0;
+    mbedtls_pk_init( &pk );
+    TEST_ASSERT( mbedtls_pk_parse_public_keyfile( &pk, key_file ) == 0 );
+
+    /* Positive test */
+    ret = mbedtls_ecp_ansi_write_point( mbedtls_pk_ec( pk ), format,
+                                        tested_buf, sizeof( tested_buf ) );
+    TEST_ASSERT( ret >= 0 && good_len == (unsigned) ret );
+    TEST_ASSERT( memcmp( good_buf, tested_buf, good_len ) == 0 );
+
+    /* Buffer too small */
+    TEST_ASSERT( mbedtls_ecp_ansi_write_point( mbedtls_pk_ec( pk ), format,
+                                               tested_buf, good_len - 1 ) ==
+                 MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL );
+
+exit:
+    if( ret >= 0 ) {
+        unsigned char out[999] = {0};
+        hexify( out, tested_buf, ret );
+        printf("== %s ==\n", out);
+    }
+    mbedtls_pk_free( &pk );
+}
+/* END_CASE */
+
 /* BEGIN_CASE */
 void mbedtls_ecp_check_privkey( int id, char *key_hex, int ret )
 {