Moved to advanced ciphersuite representation and more dynamic SSL code
diff --git a/include/polarssl/cipher.h b/include/polarssl/cipher.h
index 8224128..2ffdf66 100644
--- a/include/polarssl/cipher.h
+++ b/include/polarssl/cipher.h
@@ -5,7 +5,7 @@
*
* \author Adriaan de Jong <dejong@fox-it.com>
*
- * Copyright (C) 2006-2012, 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>
@@ -54,6 +54,7 @@
POLARSSL_CIPHER_ID_3DES,
POLARSSL_CIPHER_ID_CAMELLIA,
POLARSSL_CIPHER_ID_BLOWFISH,
+ POLARSSL_CIPHER_ID_ARC4,
} cipher_id_t;
typedef enum {
@@ -68,6 +69,8 @@
POLARSSL_CIPHER_AES_128_CTR,
POLARSSL_CIPHER_AES_192_CTR,
POLARSSL_CIPHER_AES_256_CTR,
+ POLARSSL_CIPHER_AES_128_GCM,
+ POLARSSL_CIPHER_AES_256_GCM,
POLARSSL_CIPHER_CAMELLIA_128_CBC,
POLARSSL_CIPHER_CAMELLIA_192_CBC,
POLARSSL_CIPHER_CAMELLIA_256_CBC,
@@ -83,6 +86,7 @@
POLARSSL_CIPHER_BLOWFISH_CBC,
POLARSSL_CIPHER_BLOWFISH_CFB64,
POLARSSL_CIPHER_BLOWFISH_CTR,
+ POLARSSL_CIPHER_ARC4_128,
} cipher_type_t;
typedef enum {
@@ -92,6 +96,8 @@
POLARSSL_MODE_CFB,
POLARSSL_MODE_OFB,
POLARSSL_MODE_CTR,
+ POLARSSL_MODE_GCM,
+ POLARSSL_MODE_STREAM,
} cipher_mode_t;
typedef enum {
@@ -351,10 +357,10 @@
*/
static inline int cipher_get_key_size ( const cipher_context_t *ctx )
{
- if( NULL == ctx )
+ if( NULL == ctx || NULL == ctx->cipher_info )
return POLARSSL_KEY_LENGTH_NONE;
- return ctx->key_length;
+ return ctx->cipher_info->key_length;
}
/**
@@ -448,7 +454,6 @@
*/
int cipher_finish( cipher_context_t *ctx, unsigned char *output, size_t *olen);
-
/**
* \brief Checkup routine
*
diff --git a/include/polarssl/cipher_wrap.h b/include/polarssl/cipher_wrap.h
index 4abbc4e..4dabb44 100644
--- a/include/polarssl/cipher_wrap.h
+++ b/include/polarssl/cipher_wrap.h
@@ -5,7 +5,7 @@
*
* \author Adriaan de Jong <dejong@fox-it.com>
*
- * Copyright (C) 2006-2012, 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>
@@ -54,6 +54,11 @@
extern const cipher_info_t aes_256_ctr_info;
#endif /* POLARSSL_CIPHER_MODE_CTR */
+#if defined(POLARSSL_GCM_C)
+extern const cipher_info_t aes_128_gcm_info;
+extern const cipher_info_t aes_256_gcm_info;
+#endif /* POLARSSL_GCM_C */
+
#endif /* defined(POLARSSL_AES_C) */
#if defined(POLARSSL_CAMELLIA_C)
@@ -96,6 +101,10 @@
#endif /* POLARSSL_CIPHER_MODE_CTR */
#endif /* defined(POLARSSL_BLOWFISH_C) */
+#if defined(POLARSSL_ARC4_C)
+extern const cipher_info_t arc4_128_info;
+#endif /* defined(POLARSSL_ARC4_C) */
+
#if defined(POLARSSL_CIPHER_NULL_CIPHER)
extern const cipher_info_t null_cipher_info;
#endif /* defined(POLARSSL_CIPHER_NULL_CIPHER) */
diff --git a/include/polarssl/ssl.h b/include/polarssl/ssl.h
index c2ecbaf..756441c 100644
--- a/include/polarssl/ssl.h
+++ b/include/polarssl/ssl.h
@@ -3,7 +3,7 @@
*
* \brief SSL/TLS functions.
*
- * Copyright (C) 2006-2012, 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>
@@ -37,6 +37,7 @@
#include "sha4.h"
#include "x509.h"
#include "config.h"
+#include "ssl_ciphersuites.h"
#if defined(POLARSSL_DHM_C)
#include "dhm.h"
@@ -323,6 +324,8 @@
/*
* Session specific crypto layer
*/
+ const ssl_ciphersuite_t *ciphersuite_info;
+ /*!< Chosen cipersuite_info */
unsigned int keylen; /*!< symmetric key length */
size_t minlen; /*!< min. ciphertext length */
size_t ivlen; /*!< IV length */
@@ -332,8 +335,12 @@
unsigned char iv_enc[16]; /*!< IV (encryption) */
unsigned char iv_dec[16]; /*!< IV (decryption) */
- unsigned char mac_enc[32]; /*!< MAC (encryption) */
- unsigned char mac_dec[32]; /*!< MAC (decryption) */
+ /* Needed only for SSL v3.0 secret */
+ unsigned char mac_enc[32]; /*!< SSL v3.0 secret (enc) */
+ unsigned char mac_dec[32]; /*!< SSL v3.0 secret (dec) */
+
+ md_context_t md_ctx_enc; /*!< MAC (encryption) */
+ md_context_t md_ctx_dec; /*!< MAC (decryption) */
uint32_t ctx_enc[136]; /*!< encryption context */
uint32_t ctx_dec[136]; /*!< decryption context */
@@ -520,8 +527,6 @@
extern "C" {
#endif
-extern const int ssl_default_ciphersuites[];
-
#if defined(POLARSSL_SSL_HW_RECORD_ACCEL)
#define SSL_CHANNEL_OUTBOUND 0
@@ -547,10 +552,7 @@
* \return a statically allocated array of ciphersuites, the last
* entry is 0.
*/
-static inline const int *ssl_list_ciphersuites( void )
-{
- return ssl_default_ciphersuites;
-}
+const int *ssl_list_ciphersuites( void );
/**
* \brief Return the name of the ciphersuite associated with the given
diff --git a/include/polarssl/ssl_ciphersuites.h b/include/polarssl/ssl_ciphersuites.h
new file mode 100644
index 0000000..62a928e
--- /dev/null
+++ b/include/polarssl/ssl_ciphersuites.h
@@ -0,0 +1,76 @@
+/**
+ * \file ssl_ciphersuites.h
+ *
+ * \brief SSL Ciphersuites for PolarSSL
+ *
+ * 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>
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+#ifndef POLARSSL_SSL_CIPHERSUITES_H
+#define POLARSSL_SSL_CIPHERSUITES_H
+
+#include "cipher.h"
+#include "md.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef enum {
+ POLARSSL_KEY_EXCHANGE_NONE = 0,
+ POLARSSL_KEY_EXCHANGE_RSA,
+ POLARSSL_KEY_EXCHANGE_DHE_RSA
+} key_exchange_type_t;
+
+typedef struct _ssl_ciphersuite_t ssl_ciphersuite_t;
+
+#define POLARSSL_CIPHERSUITE_WEAK 0x01
+
+/**
+ * \brief This structure is used for storing ciphersuite information
+ */
+struct _ssl_ciphersuite_t
+{
+ int id;
+ const char * name;
+
+ cipher_type_t cipher;
+ md_type_t mac;
+ key_exchange_type_t key_exchange;
+
+ int min_major_ver;
+ int min_minor_ver;
+ int max_major_ver;
+ int max_minor_ver;
+
+ unsigned char flags;
+};
+
+const int *ssl_ciphersuites_list( void );
+
+const ssl_ciphersuite_t *ssl_ciphersuite_from_string( const char *ciphersuite_name );
+const ssl_ciphersuite_t *ssl_ciphersuite_from_id( int ciphersuite_id );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* ssl_ciphersuites.h */