Handle NULL as a stream cipher for more uniformity

This commit is contained in:
Manuel Pégourié-Gonnard 2013-08-28 16:36:14 +02:00
parent 37e230c022
commit b5e85885de
4 changed files with 42 additions and 49 deletions

View file

@ -95,7 +95,6 @@ typedef enum {
typedef enum { typedef enum {
POLARSSL_MODE_NONE = 0, POLARSSL_MODE_NONE = 0,
POLARSSL_MODE_NULL,
POLARSSL_MODE_CBC, POLARSSL_MODE_CBC,
POLARSSL_MODE_CFB, POLARSSL_MODE_CFB,
POLARSSL_MODE_OFB, POLARSSL_MODE_OFB,

View file

@ -36,7 +36,7 @@
#include <stdlib.h> #include <stdlib.h>
#if defined(POLARSSL_ARC4_C) #if defined(POLARSSL_ARC4_C) || defined(POLARSSL_CIPHER_NULL_CIPHER)
#define POLARSSL_CIPHER_MODE_STREAM #define POLARSSL_CIPHER_MODE_STREAM
#endif #endif
@ -367,11 +367,6 @@ int cipher_setkey( cipher_context_t *ctx, const unsigned char *key,
ctx->key_length = key_length; ctx->key_length = key_length;
ctx->operation = operation; ctx->operation = operation;
#if defined(POLARSSL_CIPHER_NULL_CIPHER)
if( ctx->cipher_info->mode == POLARSSL_MODE_NULL )
return 0;
#endif /* defined(POLARSSL_CIPHER_NULL_CIPHER) */
/* /*
* For CFB and CTR mode always use the encryption key schedule * For CFB and CTR mode always use the encryption key schedule
*/ */
@ -421,19 +416,6 @@ int cipher_update( cipher_context_t *ctx, const unsigned char *input, size_t ile
return POLARSSL_ERR_CIPHER_BAD_INPUT_DATA; return POLARSSL_ERR_CIPHER_BAD_INPUT_DATA;
} }
#if defined(POLARSSL_CIPHER_NULL_CIPHER)
if( ctx->cipher_info->mode == POLARSSL_MODE_NULL )
{
*olen = ilen;
if( output == input )
return( 0 );
memcpy( output, input, ilen );
return 0;
}
#endif /* defined(POLARSSL_CIPHER_NULL_CIPHER) */
if( ctx->cipher_info->mode == POLARSSL_MODE_CBC ) if( ctx->cipher_info->mode == POLARSSL_MODE_CBC )
{ {
/* /*
@ -725,8 +707,7 @@ int cipher_finish( cipher_context_t *ctx, unsigned char *output, size_t *olen)
if( POLARSSL_MODE_CFB == ctx->cipher_info->mode || if( POLARSSL_MODE_CFB == ctx->cipher_info->mode ||
POLARSSL_MODE_CTR == ctx->cipher_info->mode || POLARSSL_MODE_CTR == ctx->cipher_info->mode ||
POLARSSL_MODE_STREAM == ctx->cipher_info->mode || POLARSSL_MODE_STREAM == ctx->cipher_info->mode )
POLARSSL_MODE_NULL == ctx->cipher_info->mode )
{ {
return 0; return 0;
} }

View file

@ -645,12 +645,7 @@ static int blowfish_crypt_ctr_wrap( void *ctx, size_t length,
#endif #endif
} }
static int blowfish_setkey_dec_wrap( void *ctx, const unsigned char *key, unsigned int key_length ) static int blowfish_setkey_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
{
return blowfish_setkey( (blowfish_context *) ctx, key, key_length );
}
static int blowfish_setkey_enc_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
{ {
return blowfish_setkey( (blowfish_context *) ctx, key, key_length ); return blowfish_setkey( (blowfish_context *) ctx, key, key_length );
} }
@ -671,8 +666,8 @@ const cipher_base_t blowfish_info = {
blowfish_crypt_cfb64_wrap, blowfish_crypt_cfb64_wrap,
blowfish_crypt_ctr_wrap, blowfish_crypt_ctr_wrap,
NULL, NULL,
blowfish_setkey_enc_wrap, blowfish_setkey_wrap,
blowfish_setkey_dec_wrap, blowfish_setkey_wrap,
blowfish_ctx_alloc, blowfish_ctx_alloc,
blowfish_ctx_free blowfish_ctx_free
}; };
@ -761,12 +756,30 @@ const cipher_info_t arc4_128_info = {
#endif /* POLARSSL_ARC4_C */ #endif /* POLARSSL_ARC4_C */
#if defined(POLARSSL_CIPHER_NULL_CIPHER) #if defined(POLARSSL_CIPHER_NULL_CIPHER)
static int null_crypt_stream( void *ctx, size_t length,
const unsigned char *input,
unsigned char *output )
{
((void) ctx);
memmove( output, input, length );
return( 0 );
}
static int null_setkey( void *ctx, const unsigned char *key,
unsigned int key_length )
{
((void) ctx);
((void) key);
((void) key_length);
return( 0 );
}
static void * null_ctx_alloc( void ) static void * null_ctx_alloc( void )
{ {
return (void *) 1; return (void *) 1;
} }
static void null_ctx_free( void *ctx ) static void null_ctx_free( void *ctx )
{ {
((void) ctx); ((void) ctx);
@ -777,16 +790,16 @@ const cipher_base_t null_base_info = {
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, null_crypt_stream,
NULL, null_setkey,
NULL, null_setkey,
null_ctx_alloc, null_ctx_alloc,
null_ctx_free null_ctx_free
}; };
const cipher_info_t null_cipher_info = { const cipher_info_t null_cipher_info = {
POLARSSL_CIPHER_NULL, POLARSSL_CIPHER_NULL,
POLARSSL_MODE_NULL, POLARSSL_MODE_STREAM,
0, 0,
"NULL", "NULL",
0, 0,

View file

@ -7,59 +7,59 @@ dec_empty_buf:
NULL Encrypt and decrypt 0 bytes NULL Encrypt and decrypt 0 bytes
depends_on:POLARSSL_CIPHER_NULL_CIPHER depends_on:POLARSSL_CIPHER_NULL_CIPHER
enc_dec_buf:POLARSSL_CIPHER_NULL:NULL:0:0 enc_dec_buf:POLARSSL_CIPHER_NULL:"NULL":0:0:-1
NULL Encrypt and decrypt 1 bytes NULL Encrypt and decrypt 1 bytes
depends_on:POLARSSL_CIPHER_NULL_CIPHER depends_on:POLARSSL_CIPHER_NULL_CIPHER
enc_dec_buf:POLARSSL_CIPHER_NULL:NULL:0:1 enc_dec_buf:POLARSSL_CIPHER_NULL:"NULL":0:1:-1
NULL Encrypt and decrypt 2 bytes NULL Encrypt and decrypt 2 bytes
depends_on:POLARSSL_CIPHER_NULL_CIPHER depends_on:POLARSSL_CIPHER_NULL_CIPHER
enc_dec_buf:POLARSSL_CIPHER_NULL:NULL:0:2 enc_dec_buf:POLARSSL_CIPHER_NULL:"NULL":0:2:-1
NULL Encrypt and decrypt 7 bytes NULL Encrypt and decrypt 7 bytes
depends_on:POLARSSL_CIPHER_NULL_CIPHER depends_on:POLARSSL_CIPHER_NULL_CIPHER
enc_dec_buf:POLARSSL_CIPHER_NULL:NULL:0:7 enc_dec_buf:POLARSSL_CIPHER_NULL:"NULL":0:7:-1
NULL Encrypt and decrypt 8 bytes NULL Encrypt and decrypt 8 bytes
depends_on:POLARSSL_CIPHER_NULL_CIPHER depends_on:POLARSSL_CIPHER_NULL_CIPHER
enc_dec_buf:POLARSSL_CIPHER_NULL:NULL:0:8 enc_dec_buf:POLARSSL_CIPHER_NULL:"NULL":0:8:-1
NULL Encrypt and decrypt 9 bytes NULL Encrypt and decrypt 9 bytes
depends_on:POLARSSL_CIPHER_NULL_CIPHER depends_on:POLARSSL_CIPHER_NULL_CIPHER
enc_dec_buf:POLARSSL_CIPHER_NULL:NULL:0:9 enc_dec_buf:POLARSSL_CIPHER_NULL:"NULL":0:9:-1
NULL Encrypt and decrypt 15 bytes NULL Encrypt and decrypt 15 bytes
depends_on:POLARSSL_CIPHER_NULL_CIPHER depends_on:POLARSSL_CIPHER_NULL_CIPHER
enc_dec_buf:POLARSSL_CIPHER_NULL:NULL:0:15 enc_dec_buf:POLARSSL_CIPHER_NULL:"NULL":0:15:-1
NULL Encrypt and decrypt 16 bytes NULL Encrypt and decrypt 16 bytes
depends_on:POLARSSL_CIPHER_NULL_CIPHER depends_on:POLARSSL_CIPHER_NULL_CIPHER
enc_dec_buf:POLARSSL_CIPHER_NULL:NULL:0:16 enc_dec_buf:POLARSSL_CIPHER_NULL:"NULL":0:16:-1
NULL Encrypt and decrypt 31 bytes NULL Encrypt and decrypt 31 bytes
depends_on:POLARSSL_CIPHER_NULL_CIPHER depends_on:POLARSSL_CIPHER_NULL_CIPHER
enc_dec_buf:POLARSSL_CIPHER_NULL:NULL:0:31 enc_dec_buf:POLARSSL_CIPHER_NULL:"NULL":0:31:-1
NULL Encrypt and decrypt 32 bytes NULL Encrypt and decrypt 32 bytes
depends_on:POLARSSL_CIPHER_NULL_CIPHER depends_on:POLARSSL_CIPHER_NULL_CIPHER
enc_dec_buf:POLARSSL_CIPHER_NULL:NULL:0:32 enc_dec_buf:POLARSSL_CIPHER_NULL:"NULL":0:32:-1
NULL Encrypt and decrypt 33 bytes NULL Encrypt and decrypt 33 bytes
depends_on:POLARSSL_CIPHER_NULL_CIPHER depends_on:POLARSSL_CIPHER_NULL_CIPHER
enc_dec_buf:POLARSSL_CIPHER_NULL:NULL:0:33 enc_dec_buf:POLARSSL_CIPHER_NULL:"NULL":0:33:-1
NULL Encrypt and decrypt 47 bytes NULL Encrypt and decrypt 47 bytes
depends_on:POLARSSL_CIPHER_NULL_CIPHER depends_on:POLARSSL_CIPHER_NULL_CIPHER
enc_dec_buf:POLARSSL_CIPHER_NULL:NULL:0:47 enc_dec_buf:POLARSSL_CIPHER_NULL:"NULL":0:47:-1
NULL Encrypt and decrypt 48 bytes NULL Encrypt and decrypt 48 bytes
depends_on:POLARSSL_CIPHER_NULL_CIPHER depends_on:POLARSSL_CIPHER_NULL_CIPHER
enc_dec_buf:POLARSSL_CIPHER_NULL:NULL:0:48 enc_dec_buf:POLARSSL_CIPHER_NULL:"NULL":0:48:-1
NULL Encrypt and decrypt 49 bytes NULL Encrypt and decrypt 49 bytes
depends_on:POLARSSL_CIPHER_NULL_CIPHER depends_on:POLARSSL_CIPHER_NULL_CIPHER
enc_dec_buf:POLARSSL_CIPHER_NULL:NULL:0:49 enc_dec_buf:POLARSSL_CIPHER_NULL:"NULL":0:49:-1
NULL Encrypt and decrypt 1 bytes in multiple parts 1 NULL Encrypt and decrypt 1 bytes in multiple parts 1
depends_on:POLARSSL_CIPHER_NULL_CIPHER depends_on:POLARSSL_CIPHER_NULL_CIPHER