Added POLARSSL_MODE_ECB to the cipher layer
diff --git a/library/cipher.c b/library/cipher.c
index 8d90a64..8e59e62 100644
--- a/library/cipher.c
+++ b/library/cipher.c
@@ -51,6 +51,9 @@
static const int supported_ciphers[] = {
#if defined(POLARSSL_AES_C)
+ POLARSSL_CIPHER_AES_128_ECB,
+ POLARSSL_CIPHER_AES_192_ECB,
+ POLARSSL_CIPHER_AES_256_ECB,
POLARSSL_CIPHER_AES_128_CBC,
POLARSSL_CIPHER_AES_192_CBC,
POLARSSL_CIPHER_AES_256_CBC,
@@ -80,6 +83,9 @@
#endif
#if defined(POLARSSL_CAMELLIA_C)
+ POLARSSL_CIPHER_CAMELLIA_128_ECB,
+ POLARSSL_CIPHER_CAMELLIA_192_ECB,
+ POLARSSL_CIPHER_CAMELLIA_256_ECB,
POLARSSL_CIPHER_CAMELLIA_128_CBC,
POLARSSL_CIPHER_CAMELLIA_192_CBC,
POLARSSL_CIPHER_CAMELLIA_256_CBC,
@@ -99,12 +105,16 @@
#endif /* defined(POLARSSL_CAMELLIA_C) */
#if defined(POLARSSL_DES_C)
+ POLARSSL_CIPHER_DES_ECB,
+ POLARSSL_CIPHER_DES_EDE_ECB,
+ POLARSSL_CIPHER_DES_EDE3_ECB,
POLARSSL_CIPHER_DES_CBC,
POLARSSL_CIPHER_DES_EDE_CBC,
POLARSSL_CIPHER_DES_EDE3_CBC,
#endif /* defined(POLARSSL_DES_C) */
#if defined(POLARSSL_BLOWFISH_C)
+ POLARSSL_CIPHER_BLOWFISH_ECB,
POLARSSL_CIPHER_BLOWFISH_CBC,
#if defined(POLARSSL_CIPHER_MODE_CFB)
@@ -135,6 +145,13 @@
switch ( cipher_type )
{
#if defined(POLARSSL_AES_C)
+ case POLARSSL_CIPHER_AES_128_ECB:
+ return &aes_128_ecb_info;
+ case POLARSSL_CIPHER_AES_192_ECB:
+ return &aes_192_ecb_info;
+ case POLARSSL_CIPHER_AES_256_ECB:
+ return &aes_256_ecb_info;
+
case POLARSSL_CIPHER_AES_128_CBC:
return &aes_128_cbc_info;
case POLARSSL_CIPHER_AES_192_CBC:
@@ -172,6 +189,13 @@
#endif
#if defined(POLARSSL_CAMELLIA_C)
+ case POLARSSL_CIPHER_CAMELLIA_128_ECB:
+ return &camellia_128_ecb_info;
+ case POLARSSL_CIPHER_CAMELLIA_192_ECB:
+ return &camellia_192_ecb_info;
+ case POLARSSL_CIPHER_CAMELLIA_256_ECB:
+ return &camellia_256_ecb_info;
+
case POLARSSL_CIPHER_CAMELLIA_128_CBC:
return &camellia_128_cbc_info;
case POLARSSL_CIPHER_CAMELLIA_192_CBC:
@@ -200,6 +224,13 @@
#endif
#if defined(POLARSSL_DES_C)
+ case POLARSSL_CIPHER_DES_ECB:
+ return &des_ecb_info;
+ case POLARSSL_CIPHER_DES_EDE_ECB:
+ return &des_ede_ecb_info;
+ case POLARSSL_CIPHER_DES_EDE3_ECB:
+ return &des_ede3_ecb_info;
+
case POLARSSL_CIPHER_DES_CBC:
return &des_cbc_info;
case POLARSSL_CIPHER_DES_EDE_CBC:
@@ -214,6 +245,9 @@
#endif
#if defined(POLARSSL_BLOWFISH_C)
+ case POLARSSL_CIPHER_BLOWFISH_ECB:
+ return &blowfish_ecb_info;
+
case POLARSSL_CIPHER_BLOWFISH_CBC:
return &blowfish_cbc_info;
@@ -467,8 +501,24 @@
return POLARSSL_ERR_CIPHER_BAD_INPUT_DATA;
}
+ if( ctx->cipher_info->mode == POLARSSL_MODE_ECB )
+ {
+ if( ilen != cipher_get_block_size( ctx ) )
+ return POLARSSL_ERR_CIPHER_FULL_BLOCK_EXPECTED;
+
+ *olen = ilen;
+
+ if( 0 != ( ret = ctx->cipher_info->base->ecb_func( ctx->cipher_ctx,
+ ctx->operation, input, output ) ) )
+ {
+ return ret;
+ }
+
+ return 0;
+ }
+
#if defined(POLARSSL_GCM_C)
- if( ctx->cipher_info->mode == POLARSSL_MODE_GCM)
+ if( ctx->cipher_info->mode == POLARSSL_MODE_GCM )
{
*olen = ilen;
return gcm_update( ctx->cipher_ctx, ilen, input, output );
@@ -780,6 +830,14 @@
return 0;
}
+ if( POLARSSL_MODE_ECB == ctx->cipher_info->mode )
+ {
+ if( ctx->unprocessed_len != 0 )
+ return POLARSSL_ERR_CIPHER_FULL_BLOCK_EXPECTED;
+
+ return 0;
+ }
+
if( POLARSSL_MODE_CBC == ctx->cipher_info->mode )
{
if( POLARSSL_ENCRYPT == ctx->operation )
diff --git a/library/cipher_wrap.c b/library/cipher_wrap.c
index f09823a..253fcdc 100644
--- a/library/cipher_wrap.c
+++ b/library/cipher_wrap.c
@@ -68,6 +68,12 @@
#if defined(POLARSSL_AES_C)
+static int aes_crypt_ecb_wrap( void *ctx, operation_t operation,
+ const unsigned char *input, unsigned char *output )
+{
+ return aes_crypt_ecb( (aes_context *) ctx, operation, input, output );
+}
+
static int aes_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length,
unsigned char *iv, const unsigned char *input, unsigned char *output )
{
@@ -134,6 +140,7 @@
const cipher_base_t aes_info = {
POLARSSL_CIPHER_ID_AES,
+ aes_crypt_ecb_wrap,
aes_crypt_cbc_wrap,
aes_crypt_cfb128_wrap,
aes_crypt_ctr_wrap,
@@ -144,6 +151,39 @@
aes_ctx_free
};
+const cipher_info_t aes_128_ecb_info = {
+ POLARSSL_CIPHER_AES_128_ECB,
+ POLARSSL_MODE_ECB,
+ 128,
+ "AES-128-ECB",
+ 16,
+ 0,
+ 16,
+ &aes_info
+};
+
+const cipher_info_t aes_192_ecb_info = {
+ POLARSSL_CIPHER_AES_192_ECB,
+ POLARSSL_MODE_ECB,
+ 192,
+ "AES-192-ECB",
+ 16,
+ 0,
+ 16,
+ &aes_info
+};
+
+const cipher_info_t aes_256_ecb_info = {
+ POLARSSL_CIPHER_AES_256_ECB,
+ POLARSSL_MODE_ECB,
+ 256,
+ "AES-256-ECB",
+ 16,
+ 0,
+ 16,
+ &aes_info
+};
+
const cipher_info_t aes_128_cbc_info = {
POLARSSL_CIPHER_AES_128_CBC,
POLARSSL_MODE_CBC,
@@ -269,6 +309,7 @@
NULL,
NULL,
NULL,
+ NULL,
gcm_setkey_wrap,
gcm_setkey_wrap,
gcm_ctx_alloc,
@@ -313,6 +354,12 @@
#if defined(POLARSSL_CAMELLIA_C)
+static int camellia_crypt_ecb_wrap( void *ctx, operation_t operation,
+ const unsigned char *input, unsigned char *output )
+{
+ return camellia_crypt_ecb( (camellia_context *) ctx, operation, input, output );
+}
+
static int camellia_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length,
unsigned char *iv, const unsigned char *input, unsigned char *output )
{
@@ -379,6 +426,7 @@
const cipher_base_t camellia_info = {
POLARSSL_CIPHER_ID_CAMELLIA,
+ camellia_crypt_ecb_wrap,
camellia_crypt_cbc_wrap,
camellia_crypt_cfb128_wrap,
camellia_crypt_ctr_wrap,
@@ -389,6 +437,39 @@
camellia_ctx_free
};
+const cipher_info_t camellia_128_ecb_info = {
+ POLARSSL_CIPHER_CAMELLIA_128_ECB,
+ POLARSSL_MODE_ECB,
+ 128,
+ "CAMELLIA-128-ECB",
+ 16,
+ 0,
+ 16,
+ &camellia_info
+};
+
+const cipher_info_t camellia_192_ecb_info = {
+ POLARSSL_CIPHER_CAMELLIA_192_ECB,
+ POLARSSL_MODE_ECB,
+ 192,
+ "CAMELLIA-192-ECB",
+ 16,
+ 0,
+ 16,
+ &camellia_info
+};
+
+const cipher_info_t camellia_256_ecb_info = {
+ POLARSSL_CIPHER_CAMELLIA_256_ECB,
+ POLARSSL_MODE_ECB,
+ 256,
+ "CAMELLIA-256-ECB",
+ 16,
+ 0,
+ 16,
+ &camellia_info
+};
+
const cipher_info_t camellia_128_cbc_info = {
POLARSSL_CIPHER_CAMELLIA_128_CBC,
POLARSSL_MODE_CBC,
@@ -496,6 +577,20 @@
#if defined(POLARSSL_DES_C)
+static int des_crypt_ecb_wrap( void *ctx, operation_t operation,
+ const unsigned char *input, unsigned char *output )
+{
+ ((void) operation);
+ return des_crypt_ecb( (des_context *) ctx, input, output );
+}
+
+static int des3_crypt_ecb_wrap( void *ctx, operation_t operation,
+ const unsigned char *input, unsigned char *output )
+{
+ ((void) operation);
+ return des3_crypt_ecb( (des3_context *) ctx, input, output );
+}
+
static int des_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length,
unsigned char *iv, const unsigned char *input, unsigned char *output )
{
@@ -596,6 +691,7 @@
const cipher_base_t des_info = {
POLARSSL_CIPHER_ID_DES,
+ des_crypt_ecb_wrap,
des_crypt_cbc_wrap,
des_crypt_cfb128_wrap,
des_crypt_ctr_wrap,
@@ -606,6 +702,17 @@
des_ctx_free
};
+const cipher_info_t des_ecb_info = {
+ POLARSSL_CIPHER_DES_ECB,
+ POLARSSL_MODE_ECB,
+ POLARSSL_KEY_LENGTH_DES,
+ "DES-ECB",
+ 8,
+ 0,
+ 8,
+ &des_info
+};
+
const cipher_info_t des_cbc_info = {
POLARSSL_CIPHER_DES_CBC,
POLARSSL_MODE_CBC,
@@ -619,6 +726,7 @@
const cipher_base_t des_ede_info = {
POLARSSL_CIPHER_ID_DES,
+ des3_crypt_ecb_wrap,
des3_crypt_cbc_wrap,
des_crypt_cfb128_wrap,
des_crypt_ctr_wrap,
@@ -629,6 +737,17 @@
des_ctx_free
};
+const cipher_info_t des_ede_ecb_info = {
+ POLARSSL_CIPHER_DES_EDE_ECB,
+ POLARSSL_MODE_ECB,
+ POLARSSL_KEY_LENGTH_DES_EDE,
+ "DES-EDE-ECB",
+ 8,
+ 0,
+ 8,
+ &des_ede_info
+};
+
const cipher_info_t des_ede_cbc_info = {
POLARSSL_CIPHER_DES_EDE_CBC,
POLARSSL_MODE_CBC,
@@ -642,6 +761,7 @@
const cipher_base_t des_ede3_info = {
POLARSSL_CIPHER_ID_DES,
+ des3_crypt_ecb_wrap,
des3_crypt_cbc_wrap,
des_crypt_cfb128_wrap,
des_crypt_ctr_wrap,
@@ -652,6 +772,16 @@
des_ctx_free
};
+const cipher_info_t des_ede3_ecb_info = {
+ POLARSSL_CIPHER_DES_EDE3_ECB,
+ POLARSSL_MODE_ECB,
+ POLARSSL_KEY_LENGTH_DES_EDE3,
+ "DES-EDE3-ECB",
+ 8,
+ 0,
+ 8,
+ &des_ede3_info
+};
const cipher_info_t des_ede3_cbc_info = {
POLARSSL_CIPHER_DES_EDE3_CBC,
POLARSSL_MODE_CBC,
@@ -666,6 +796,12 @@
#if defined(POLARSSL_BLOWFISH_C)
+static int blowfish_crypt_ecb_wrap( void *ctx, operation_t operation,
+ const unsigned char *input, unsigned char *output )
+{
+ return blowfish_crypt_ecb( (blowfish_context *) ctx, operation, input, output );
+}
+
static int blowfish_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length,
unsigned char *iv, const unsigned char *input, unsigned char *output )
{
@@ -727,6 +863,7 @@
const cipher_base_t blowfish_info = {
POLARSSL_CIPHER_ID_BLOWFISH,
+ blowfish_crypt_ecb_wrap,
blowfish_crypt_cbc_wrap,
blowfish_crypt_cfb64_wrap,
blowfish_crypt_ctr_wrap,
@@ -737,6 +874,17 @@
blowfish_ctx_free
};
+const cipher_info_t blowfish_ecb_info = {
+ POLARSSL_CIPHER_BLOWFISH_ECB,
+ POLARSSL_MODE_ECB,
+ 128,
+ "BLOWFISH-ECB",
+ 8,
+ 0,
+ 8,
+ &blowfish_info
+};
+
const cipher_info_t blowfish_cbc_info = {
POLARSSL_CIPHER_BLOWFISH_CBC,
POLARSSL_MODE_CBC,
@@ -809,6 +957,7 @@
NULL,
NULL,
NULL,
+ NULL,
arc4_crypt_stream_wrap,
arc4_setkey_wrap,
arc4_setkey_wrap,
@@ -863,6 +1012,7 @@
NULL,
NULL,
NULL,
+ NULL,
null_crypt_stream,
null_setkey,
null_setkey,