Added mechanism to provide alternative cipher / hash implementations
All symmetric cipher algorithms and hash algorithms now include support
for a POLARSSL_XXX_ALT flag that prevents the definition of the
algorithm context structure and all 'core' functions.
diff --git a/include/polarssl/aes.h b/include/polarssl/aes.h
index b79894c..30fdf61 100644
--- a/include/polarssl/aes.h
+++ b/include/polarssl/aes.h
@@ -3,7 +3,7 @@
*
* \brief AES block cipher
*
- * Copyright (C) 2006-2010, Brainspark B.V.
+ * Copyright (C) 2006-2013, Brainspark B.V.
*
* This file is part of PolarSSL (http://www.polarssl.org)
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
@@ -27,6 +27,8 @@
#ifndef POLARSSL_AES_H
#define POLARSSL_AES_H
+#include "config.h"
+
#include <string.h>
#ifdef _MSC_VER
@@ -42,6 +44,10 @@
#define POLARSSL_ERR_AES_INVALID_KEY_LENGTH -0x0020 /**< Invalid key length. */
#define POLARSSL_ERR_AES_INVALID_INPUT_LENGTH -0x0022 /**< Invalid data input length. */
+#if !defined(POLARSSL_AES_ALT)
+// Regular implementation
+//
+
/**
* \brief AES context structure
*/
@@ -169,6 +175,19 @@
unsigned char stream_block[16],
const unsigned char *input,
unsigned char *output );
+
+#ifdef __cplusplus
+}
+#endif
+
+#else /* POLARSSL_AES_ALT */
+#include "aes_alt.h"
+#endif /* POLARSSL_AES_ALT */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
/**
* \brief Checkup routine
*
diff --git a/include/polarssl/arc4.h b/include/polarssl/arc4.h
index 7233384..1672fa2 100644
--- a/include/polarssl/arc4.h
+++ b/include/polarssl/arc4.h
@@ -3,7 +3,7 @@
*
* \brief The ARCFOUR stream cipher
*
- * Copyright (C) 2006-2010, Brainspark B.V.
+ * Copyright (C) 2006-2013, Brainspark B.V.
*
* This file is part of PolarSSL (http://www.polarssl.org)
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
@@ -27,8 +27,14 @@
#ifndef POLARSSL_ARC4_H
#define POLARSSL_ARC4_H
+#include "config.h"
+
#include <string.h>
+#if !defined(POLARSSL_ARC4_ALT)
+// Regular implementation
+//
+
/**
* \brief ARC4 context structure
*/
@@ -66,6 +72,18 @@
int arc4_crypt( arc4_context *ctx, size_t length, const unsigned char *input,
unsigned char *output );
+#ifdef __cplusplus
+}
+#endif
+
+#else /* POLARSSL_ARC4_ALT */
+#include "arc4_alt.h"
+#endif /* POLARSSL_ARC4_ALT */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
/**
* \brief Checkup routine
*
diff --git a/include/polarssl/blowfish.h b/include/polarssl/blowfish.h
index 313d898..9b269b7 100644
--- a/include/polarssl/blowfish.h
+++ b/include/polarssl/blowfish.h
@@ -3,7 +3,7 @@
*
* \brief Blowfish block cipher
*
- * Copyright (C) 2012-2012, Brainspark B.V.
+ * Copyright (C) 2012-2013, Brainspark B.V.
*
* This file is part of PolarSSL (http://www.polarssl.org)
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
@@ -27,6 +27,8 @@
#ifndef POLARSSL_BLOWFISH_H
#define POLARSSL_BLOWFISH_H
+#include "config.h"
+
#include <string.h>
#ifdef _MSC_VER
@@ -46,6 +48,10 @@
#define POLARSSL_ERR_BLOWFISH_INVALID_KEY_LENGTH -0x0016 /**< Invalid key length. */
#define POLARSSL_ERR_BLOWFISH_INVALID_INPUT_LENGTH -0x0018 /**< Invalid data input length. */
+#if !defined(POLARSSL_BLOWFISH_ALT)
+// Regular implementation
+//
+
/**
* \brief Blowfish context structure
*/
@@ -158,4 +164,8 @@
}
#endif
+#else /* POLARSSL_BLOWFISH_ALT */
+#include "blowfish_alt.h"
+#endif /* POLARSSL_BLOWFISH_ALT */
+
#endif /* blowfish.h */
diff --git a/include/polarssl/camellia.h b/include/polarssl/camellia.h
index f073d46..050c6cd 100644
--- a/include/polarssl/camellia.h
+++ b/include/polarssl/camellia.h
@@ -3,7 +3,7 @@
*
* \brief Camellia block cipher
*
- * Copyright (C) 2006-2010, Brainspark B.V.
+ * Copyright (C) 2006-2013, Brainspark B.V.
*
* This file is part of PolarSSL (http://www.polarssl.org)
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
@@ -27,6 +27,8 @@
#ifndef POLARSSL_CAMELLIA_H
#define POLARSSL_CAMELLIA_H
+#include "config.h"
+
#include <string.h>
#ifdef _MSC_VER
@@ -42,6 +44,10 @@
#define POLARSSL_ERR_CAMELLIA_INVALID_KEY_LENGTH -0x0024 /**< Invalid key length. */
#define POLARSSL_ERR_CAMELLIA_INVALID_INPUT_LENGTH -0x0026 /**< Invalid data input length. */
+#if !defined(POLARSSL_CAMELLIA_ALT)
+// Regular implementation
+//
+
/**
* \brief CAMELLIA context structure
*/
@@ -168,6 +174,18 @@
const unsigned char *input,
unsigned char *output );
+#ifdef __cplusplus
+}
+#endif
+
+#else /* POLARSSL_CAMELLIA_ALT */
+#include "camellia_alt.h"
+#endif /* POLARSSL_CAMELLIA_ALT */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
/**
* \brief Checkup routine
*
diff --git a/include/polarssl/config.h b/include/polarssl/config.h
index 579b5d6..409d756 100644
--- a/include/polarssl/config.h
+++ b/include/polarssl/config.h
@@ -105,6 +105,35 @@
*/
/**
+ * \def POLARSSL_XXX_ALT
+ *
+ * Uncomment a macro to let PolarSSL use your alternate core implementation of
+ * a symmetric or hash algorithm (e.g. platform specific assembly optimized
+ * implementations). Keep in mind that the function prototypes should remain
+ * the same.
+ *
+ * Example: In case you uncomment POLARSSL_AES_ALT, PolarSSL will no longer
+ * provide the "struct aes_context" definition and omit the base function
+ * declarations and implementations. "aes_alt.h" will be included from
+ * "aes.h" to include the new function definitions.
+ *
+ * Uncomment a macro to enable alternate implementation for core algorithm
+ * functions
+#define POLARSSL_AES_ALT
+#define POLARSSL_ARC4_ALT
+#define POLARSSL_BLOWFISH_ALT
+#define POLARSSL_CAMELLIA_ALT
+#define POLARSSL_DES_ALT
+#define POLARSSL_XTEA_ALT
+#define POLARSSL_MD2_ALT
+#define POLARSSL_MD4_ALT
+#define POLARSSL_MD5_ALT
+#define POLARSSL_SHA1_ALT
+#define POLARSSL_SHA2_ALT
+#define POLARSSL_SHA4_ALT
+ */
+
+/**
* \def POLARSSL_AES_ROM_TABLES
*
* Store the AES tables in ROM.
diff --git a/include/polarssl/des.h b/include/polarssl/des.h
index 5eee7ac..d78b568 100644
--- a/include/polarssl/des.h
+++ b/include/polarssl/des.h
@@ -3,7 +3,7 @@
*
* \brief DES block cipher
*
- * Copyright (C) 2006-2010, Brainspark B.V.
+ * Copyright (C) 2006-2013, Brainspark B.V.
*
* This file is part of PolarSSL (http://www.polarssl.org)
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
@@ -27,6 +27,8 @@
#ifndef POLARSSL_DES_H
#define POLARSSL_DES_H
+#include "config.h"
+
#include <string.h>
#ifdef _MSC_VER
@@ -43,6 +45,10 @@
#define DES_KEY_SIZE 8
+#if !defined(POLARSSL_DES_ALT)
+// Regular implementation
+//
+
/**
* \brief DES context structure
*/
@@ -220,6 +226,18 @@
const unsigned char *input,
unsigned char *output );
+#ifdef __cplusplus
+}
+#endif
+
+#else /* POLARSSL_DES_ALT */
+#include "des_alt.h"
+#endif /* POLARSSL_DES_ALT */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
/**
* \brief Checkup routine
*
diff --git a/include/polarssl/md2.h b/include/polarssl/md2.h
index 1f60470..94f19fc 100644
--- a/include/polarssl/md2.h
+++ b/include/polarssl/md2.h
@@ -3,7 +3,7 @@
*
* \brief MD2 message digest algorithm (hash function)
*
- * Copyright (C) 2006-2010, Brainspark B.V.
+ * Copyright (C) 2006-2013, Brainspark B.V.
*
* This file is part of PolarSSL (http://www.polarssl.org)
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
@@ -27,10 +27,16 @@
#ifndef POLARSSL_MD2_H
#define POLARSSL_MD2_H
+#include "config.h"
+
#include <string.h>
#define POLARSSL_ERR_MD2_FILE_IO_ERROR -0x0070 /**< Read/write error in file. */
+#if !defined(POLARSSL_MD2_ALT)
+// Regular implementation
+//
+
/**
* \brief MD2 context structure
*/
@@ -74,6 +80,18 @@
*/
void md2_finish( md2_context *ctx, unsigned char output[16] );
+#ifdef __cplusplus
+}
+#endif
+
+#else /* POLARSSL_MD2_ALT */
+#include "md2_alt.h"
+#endif /* POLARSSL_MD2_ALT */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
/**
* \brief Output = MD2( input buffer )
*
diff --git a/include/polarssl/md4.h b/include/polarssl/md4.h
index 641edf1..56fba2f 100644
--- a/include/polarssl/md4.h
+++ b/include/polarssl/md4.h
@@ -3,7 +3,7 @@
*
* \brief MD4 message digest algorithm (hash function)
*
- * Copyright (C) 2006-2010, Brainspark B.V.
+ * Copyright (C) 2006-2013, Brainspark B.V.
*
* This file is part of PolarSSL (http://www.polarssl.org)
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
@@ -27,6 +27,8 @@
#ifndef POLARSSL_MD4_H
#define POLARSSL_MD4_H
+#include "config.h"
+
#include <string.h>
#ifdef _MSC_VER
@@ -38,6 +40,10 @@
#define POLARSSL_ERR_MD4_FILE_IO_ERROR -0x0072 /**< Read/write error in file. */
+#if !defined(POLARSSL_MD4_ALT)
+// Regular implementation
+//
+
/**
* \brief MD4 context structure
*/
@@ -80,6 +86,18 @@
*/
void md4_finish( md4_context *ctx, unsigned char output[16] );
+#ifdef __cplusplus
+}
+#endif
+
+#else /* POLARSSL_MD4_ALT */
+#include "md4_alt.h"
+#endif /* POLARSSL_MD4_ALT */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
/**
* \brief Output = MD4( input buffer )
*
diff --git a/include/polarssl/md5.h b/include/polarssl/md5.h
index b0611e2..c90789d 100644
--- a/include/polarssl/md5.h
+++ b/include/polarssl/md5.h
@@ -3,7 +3,7 @@
*
* \brief MD5 message digest algorithm (hash function)
*
- * Copyright (C) 2006-2010, Brainspark B.V.
+ * Copyright (C) 2006-2013, Brainspark B.V.
*
* This file is part of PolarSSL (http://www.polarssl.org)
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
@@ -27,6 +27,8 @@
#ifndef POLARSSL_MD5_H
#define POLARSSL_MD5_H
+#include "config.h"
+
#include <string.h>
#ifdef _MSC_VER
@@ -38,6 +40,10 @@
#define POLARSSL_ERR_MD5_FILE_IO_ERROR -0x0074 /**< Read/write error in file. */
+#if !defined(POLARSSL_MD5_ALT)
+// Regular implementation
+//
+
/**
* \brief MD5 context structure
*/
@@ -80,6 +86,21 @@
*/
void md5_finish( md5_context *ctx, unsigned char output[16] );
+/* Internal use */
+void md5_process( md5_context *ctx, const unsigned char data[64] );
+
+#ifdef __cplusplus
+}
+#endif
+
+#else /* POLARSSL_MD5_ALT */
+#include "md5_alt.h"
+#endif /* POLARSSL_MD5_ALT */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
/**
* \brief Output = MD5( input buffer )
*
@@ -154,9 +175,6 @@
*/
int md5_self_test( int verbose );
-/* Internal use */
-void md5_process( md5_context *ctx, const unsigned char data[64] );
-
#ifdef __cplusplus
}
#endif
diff --git a/include/polarssl/sha1.h b/include/polarssl/sha1.h
index 48da246..81ea77d 100644
--- a/include/polarssl/sha1.h
+++ b/include/polarssl/sha1.h
@@ -3,7 +3,7 @@
*
* \brief SHA-1 cryptographic hash function
*
- * Copyright (C) 2006-2010, Brainspark B.V.
+ * Copyright (C) 2006-2013, Brainspark B.V.
*
* This file is part of PolarSSL (http://www.polarssl.org)
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
@@ -27,6 +27,8 @@
#ifndef POLARSSL_SHA1_H
#define POLARSSL_SHA1_H
+#include "config.h"
+
#include <string.h>
#ifdef _MSC_VER
@@ -38,6 +40,10 @@
#define POLARSSL_ERR_SHA1_FILE_IO_ERROR -0x0076 /**< Read/write error in file. */
+#if !defined(POLARSSL_SHA1_ALT)
+// Regular implementation
+//
+
/**
* \brief SHA-1 context structure
*/
@@ -80,6 +86,21 @@
*/
void sha1_finish( sha1_context *ctx, unsigned char output[20] );
+/* Internal use */
+void sha1_process( sha1_context *ctx, const unsigned char data[64] );
+
+#ifdef __cplusplus
+}
+#endif
+
+#else /* POLARSSL_SHA1_ALT */
+#include "sha1_alt.h"
+#endif /* POLARSSL_SHA1_ALT */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
/**
* \brief Output = SHA-1( input buffer )
*
@@ -152,9 +173,6 @@
*/
int sha1_self_test( int verbose );
-/* Internal use */
-void sha1_process( sha1_context *ctx, const unsigned char data[64] );
-
#ifdef __cplusplus
}
#endif
diff --git a/include/polarssl/sha2.h b/include/polarssl/sha2.h
index 39d9347..795299e 100644
--- a/include/polarssl/sha2.h
+++ b/include/polarssl/sha2.h
@@ -3,7 +3,7 @@
*
* \brief SHA-224 and SHA-256 cryptographic hash function
*
- * Copyright (C) 2006-2010, Brainspark B.V.
+ * Copyright (C) 2006-2013, Brainspark B.V.
*
* This file is part of PolarSSL (http://www.polarssl.org)
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
@@ -27,6 +27,8 @@
#ifndef POLARSSL_SHA2_H
#define POLARSSL_SHA2_H
+#include "config.h"
+
#include <string.h>
#ifdef _MSC_VER
@@ -38,6 +40,10 @@
#define POLARSSL_ERR_SHA2_FILE_IO_ERROR -0x0078 /**< Read/write error in file. */
+#if !defined(POLARSSL_SHA2_ALT)
+// Regular implementation
+//
+
/**
* \brief SHA-256 context structure
*/
@@ -82,6 +88,21 @@
*/
void sha2_finish( sha2_context *ctx, unsigned char output[32] );
+/* Internal use */
+void sha2_process( sha2_context *ctx, const unsigned char data[64] );
+
+#ifdef __cplusplus
+}
+#endif
+
+#else /* POLARSSL_SHA2_ALT */
+#include "sha2_alt.h"
+#endif /* POLARSSL_SHA2_ALT */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
/**
* \brief Output = SHA-256( input buffer )
*
@@ -160,9 +181,6 @@
*/
int sha2_self_test( int verbose );
-/* Internal use */
-void sha2_process( sha2_context *ctx, const unsigned char data[64] );
-
#ifdef __cplusplus
}
#endif
diff --git a/include/polarssl/sha4.h b/include/polarssl/sha4.h
index 6aae124..7b0cdf6 100644
--- a/include/polarssl/sha4.h
+++ b/include/polarssl/sha4.h
@@ -3,7 +3,7 @@
*
* \brief SHA-384 and SHA-512 cryptographic hash function
*
- * Copyright (C) 2006-2010, Brainspark B.V.
+ * Copyright (C) 2006-2013, Brainspark B.V.
*
* This file is part of PolarSSL (http://www.polarssl.org)
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
@@ -27,6 +27,8 @@
#ifndef POLARSSL_SHA4_H
#define POLARSSL_SHA4_H
+#include "config.h"
+
#include <string.h>
#if defined(_MSC_VER) || defined(__WATCOMC__)
@@ -39,6 +41,10 @@
#define POLARSSL_ERR_SHA4_FILE_IO_ERROR -0x007A /**< Read/write error in file. */
+#if !defined(POLARSSL_SHA1_ALT)
+// Regular implementation
+//
+
/**
* \brief SHA-512 context structure
*/
@@ -83,6 +89,18 @@
*/
void sha4_finish( sha4_context *ctx, unsigned char output[64] );
+#ifdef __cplusplus
+}
+#endif
+
+#else /* POLARSSL_SHA4_ALT */
+#include "sha4_alt.h"
+#endif /* POLARSSL_SHA4_ALT */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
/**
* \brief Output = SHA-512( input buffer )
*
diff --git a/include/polarssl/xtea.h b/include/polarssl/xtea.h
index 0db7bc8..c95cb76 100644
--- a/include/polarssl/xtea.h
+++ b/include/polarssl/xtea.h
@@ -3,7 +3,7 @@
*
* \brief XTEA block cipher (32-bit)
*
- * Copyright (C) 2006-2010, Brainspark B.V.
+ * Copyright (C) 2006-2013, Brainspark B.V.
*
* This file is part of PolarSSL (http://www.polarssl.org)
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
@@ -27,6 +27,8 @@
#ifndef POLARSSL_XTEA_H
#define POLARSSL_XTEA_H
+#include "config.h"
+
#include <string.h>
#ifdef _MSC_VER
@@ -41,6 +43,10 @@
#define POLARSSL_ERR_XTEA_INVALID_INPUT_LENGTH -0x0028 /**< The data input has an invalid length. */
+#if !defined(POLARSSL_XTEA_ALT)
+// Regular implementation
+//
+
/**
* \brief XTEA context structure
*/
@@ -97,6 +103,18 @@
unsigned char *input,
unsigned char *output);
+#ifdef __cplusplus
+}
+#endif
+
+#else /* POLARSSL_XTEA_ALT */
+#include "xtea_alt.h"
+#endif /* POLARSSL_XTEA_ALT */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
/**
* \brief Checkup routine
*