From 4606c7317b02d5745682d52e718355a0ea25ee77 Mon Sep 17 00:00:00 2001
From: Paul Bakker
Date: Sun, 15 Sep 2013 17:04:23 +0200
Subject: [PATCH] Added POLARSSL_PK_PARSE_C and POLARSSL_PK_WRITE_C
---
include/polarssl/config.h | 44 +++++++++++++++++++++---
include/polarssl/pk.h | 8 +++++
library/pkparse.c | 4 +--
library/pkwrite.c | 4 +--
tests/suites/test_suite_pkparse.function | 2 +-
tests/suites/test_suite_pkwrite.function | 2 +-
6 files changed, 54 insertions(+), 10 deletions(-)
diff --git a/include/polarssl/config.h b/include/polarssl/config.h
index f75d94d2e..23bbae027 100644
--- a/include/polarssl/config.h
+++ b/include/polarssl/config.h
@@ -1184,6 +1184,34 @@
*/
#define POLARSSL_PK_C
+/**
+ * \def POLARSSL_PK_PARSE_C
+ *
+ * Enable the generic public (asymetric) key parser.
+ *
+ * Module: library/pkparse.c
+ * Caller: library/x509parse.c
+ *
+ * Requires: POLARSSL_PK_C
+ *
+ * Uncomment to enable generic public key parse functions.
+ */
+#define POLARSSL_PK_PARSE_C
+
+/**
+ * \def POLARSSL_PK_WRITE_C
+ *
+ * Enable the generic public (asymetric) key write.
+ *
+ * Module: library/pkwrite.c
+ * Caller: library/x509write.c
+ *
+ * Requires: POLARSSL_PK_C
+ *
+ * Uncomment to enable generic public key write functions.
+ */
+#define POLARSSL_PK_WRITE_C
+
/**
* \def POLARSSL_PKCS5_C
*
@@ -1379,7 +1407,7 @@
* library/ssl_tls.c
*
* Requires: POLARSSL_ASN1_PARSE_C, POLARSSL_BIGNUM_C, POLARSSL_OID_C,
- * POLARSSL_PK_C
+ * POLARSSL_PK_PARSE_C
*
* This module is required for X.509 certificate parsing.
*/
@@ -1392,7 +1420,7 @@
*
* Module: library/x509write.c
*
- * Requires: POLARSSL_BIGNUM_C, POLARSSL_OID_C, POLARSSL_PK_C
+ * Requires: POLARSSL_BIGNUM_C, POLARSSL_OID_C, POLARSSL_PK_WRITE_C
*
* This module is required for X.509 certificate request writing.
*/
@@ -1562,6 +1590,14 @@
#error "POLARSSL_PEM_C defined, but not all prerequisites"
#endif
+#if defined(POLARSSL_PK_PARSE_C) && !defined(POLARSSL_PK_C)
+#error "POLARSSL_PK_PARSE_C defined, but not all prerequisites"
+#endif
+
+#if defined(POLARSSL_PK_WRITE_C) && !defined(POLARSSL_PK_C)
+#error "POLARSSL_PK_WRITE_C defined, but not all prerequisites"
+#endif
+
#if defined(POLARSSL_PKCS11_C) && !defined(POLARSSL_PK_C)
#error "POLARSSL_PKCS11_C defined, but not all prerequisites"
#endif
@@ -1614,13 +1650,13 @@
#if defined(POLARSSL_X509_PARSE_C) && ( !defined(POLARSSL_BIGNUM_C) || \
!defined(POLARSSL_OID_C) || !defined(POLARSSL_ASN1_PARSE_C) || \
- !defined(POLARSSL_PK_C) )
+ !defined(POLARSSL_PK_PARSE_C) )
#error "POLARSSL_X509_PARSE_C defined, but not all prerequisites"
#endif
#if defined(POLARSSL_X509_WRITE_C) && ( !defined(POLARSSL_BIGNUM_C) || \
!defined(POLARSSL_OID_C) || !defined(POLARSSL_ASN1_WRITE_C) || \
- !defined(POLARSSL_RSA_C) )
+ !defined(POLARSSL_RSA_C) || !defined(POLARSSL_PK_WRITE_C) )
#error "POLARSSL_X509_WRITE_C defined, but not all prerequisites"
#endif
diff --git a/include/polarssl/pk.h b/include/polarssl/pk.h
index 584f77fa3..e1fdf8903 100644
--- a/include/polarssl/pk.h
+++ b/include/polarssl/pk.h
@@ -389,6 +389,7 @@ const char * pk_get_name( const pk_context *ctx );
*/
pk_type_t pk_get_type( const pk_context *ctx );
+#if defined(POLARSSL_PK_PARSE_C)
/** \ingroup x509_module */
/**
* \brief Parse a private key
@@ -443,7 +444,9 @@ int pk_parse_keyfile( pk_context *ctx,
*/
int pk_parse_public_keyfile( pk_context *ctx, const char *path );
#endif /* POLARSSL_FS_IO */
+#endif /* POLARSSL_PK_PARSE_C */
+#if defined(POLARSSL_PK_WRITE_C)
/**
* \brief Write a private key to a PKCS#1 or SEC1 DER structure
* Note: data is written at the end of the buffer! Use the
@@ -497,12 +500,14 @@ int pk_write_pubkey_pem( pk_context *key, unsigned char *buf, size_t size );
*/
int pk_write_key_pem( pk_context *key, unsigned char *buf, size_t size );
#endif /* POLARSSL_BASE64_C */
+#endif /* POLARSSL_PK_WRITE_C */
/*
* WARNING: Low-level functions. You probably do not want to use these unless
* you are certain you do ;)
*/
+#if defined(POLARSSL_PK_PARSE_C)
/**
* \brief Parse a SubjectPublicKeyInfo DER structure
*
@@ -514,7 +519,9 @@ int pk_write_key_pem( pk_context *key, unsigned char *buf, size_t size );
*/
int pk_parse_get_pubkey( unsigned char **p, const unsigned char *end,
pk_context *pk );
+#endif /* POLARSSL_PK_PARSE_C */
+#if defined(POLARSSL_PK_WRITE_C)
/**
* \brief Write a subjectPublicKey to ASN.1 data
* Note: function works backwards in data buffer
@@ -527,6 +534,7 @@ int pk_parse_get_pubkey( unsigned char **p, const unsigned char *end,
*/
int pk_write_pubkey( unsigned char **p, unsigned char *start,
const pk_context *key );
+#endif /* POLARSSL_PK_WRITE_C */
#ifdef __cplusplus
}
diff --git a/library/pkparse.c b/library/pkparse.c
index e04bbea43..2d244f16a 100644
--- a/library/pkparse.c
+++ b/library/pkparse.c
@@ -25,7 +25,7 @@
#include "polarssl/config.h"
-#if defined(POLARSSL_PK_C)
+#if defined(POLARSSL_PK_PARSE_C)
#include "polarssl/pk.h"
#include "polarssl/asn1.h"
@@ -954,4 +954,4 @@ int pk_parse_public_key( pk_context *ctx,
return( ret );
}
-#endif /* POLARSSL_PK_C */
+#endif /* POLARSSL_PK_PARSE_C */
diff --git a/library/pkwrite.c b/library/pkwrite.c
index 741df08e9..022281d42 100644
--- a/library/pkwrite.c
+++ b/library/pkwrite.c
@@ -25,7 +25,7 @@
#include "polarssl/config.h"
-#if defined(POLARSSL_PK_C)
+#if defined(POLARSSL_PK_WRITE_C)
#include "polarssl/pk.h"
#include "polarssl/asn1write.h"
@@ -386,4 +386,4 @@ int pk_write_key_pem( pk_context *key, unsigned char *buf, size_t size )
}
#endif /* POLARSSL_BASE64_C */
-#endif /* POLARSSL_PK_C */
+#endif /* POLARSSL_PK_WRITE_C */
diff --git a/tests/suites/test_suite_pkparse.function b/tests/suites/test_suite_pkparse.function
index 9d8d8d8dd..5cdd84497 100644
--- a/tests/suites/test_suite_pkparse.function
+++ b/tests/suites/test_suite_pkparse.function
@@ -5,7 +5,7 @@
/* END_HEADER */
/* BEGIN_DEPENDENCIES
- * depends_on:POLARSSL_PK_C:POLARSSL_BIGNUM_C
+ * depends_on:POLARSSL_PK_PARSE_C:POLARSSL_BIGNUM_C
* END_DEPENDENCIES
*/
diff --git a/tests/suites/test_suite_pkwrite.function b/tests/suites/test_suite_pkwrite.function
index ce74d7103..455b9aa0f 100644
--- a/tests/suites/test_suite_pkwrite.function
+++ b/tests/suites/test_suite_pkwrite.function
@@ -5,7 +5,7 @@
/* END_HEADER */
/* BEGIN_DEPENDENCIES
- * depends_on:POLARSSL_PK_C:POLARSSL_BIGNUM_C:POLARSSL_FS_IO
+ * depends_on:POLARSSL_PK_WRITE_C:POLARSSL_BIGNUM_C:POLARSSL_FS_IO
* END_DEPENDENCIES
*/