1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-07-30 22:43:08 +03:00

- Changed interface for AES and Camellia setkey functions to indicate invalid key lengths.

This commit is contained in:
Paul Bakker
2009-07-27 21:03:45 +00:00
parent 33768bf19b
commit 2b222c830b
9 changed files with 182 additions and 129 deletions

View File

@ -438,7 +438,7 @@ static void aes_gen_tables( void )
/*
* AES key schedule (encryption)
*/
void aes_setkey_enc( aes_context *ctx, unsigned char *key, int keysize )
int aes_setkey_enc( aes_context *ctx, unsigned char *key, int keysize )
{
int i;
unsigned long *RK;
@ -456,7 +456,7 @@ void aes_setkey_enc( aes_context *ctx, unsigned char *key, int keysize )
case 128: ctx->nr = 10; break;
case 192: ctx->nr = 12; break;
case 256: ctx->nr = 14; break;
default : return;
default : return( POLARSSL_ERR_AES_INVALID_KEY_LENGTH );
}
#if defined(PADLOCK_ALIGN16)
@ -536,24 +536,27 @@ void aes_setkey_enc( aes_context *ctx, unsigned char *key, int keysize )
break;
}
return( 0 );
}
/*
* AES key schedule (decryption)
*/
void aes_setkey_dec( aes_context *ctx, unsigned char *key, int keysize )
int aes_setkey_dec( aes_context *ctx, unsigned char *key, int keysize )
{
int i, j;
aes_context cty;
unsigned long *RK;
unsigned long *SK;
int ret;
switch( keysize )
{
case 128: ctx->nr = 10; break;
case 192: ctx->nr = 12; break;
case 256: ctx->nr = 14; break;
default : return;
default : return( POLARSSL_ERR_AES_INVALID_KEY_LENGTH );
}
#if defined(PADLOCK_ALIGN16)
@ -562,7 +565,10 @@ void aes_setkey_dec( aes_context *ctx, unsigned char *key, int keysize )
ctx->rk = RK = ctx->buf;
#endif
aes_setkey_enc( &cty, key, keysize );
ret = aes_setkey_enc( &cty, key, keysize );
if( ret != 0 )
return( ret );
SK = cty.rk + cty.nr * 4;
*RK++ = *SK++;
@ -587,6 +593,8 @@ void aes_setkey_dec( aes_context *ctx, unsigned char *key, int keysize )
*RK++ = *SK++;
memset( &cty, 0, sizeof( aes_context ) );
return( 0 );
}
#define AES_FROUND(X0,X1,X2,X3,Y0,Y1,Y2,Y3) \

View File

@ -304,7 +304,7 @@ static void camellia_feistel(uint32_t x[2], uint32_t k[2], uint32_t z[2])
/*
* Camellia key schedule (encryption)
*/
void camellia_setkey_enc( camellia_context *ctx, unsigned char *key, int keysize )
int camellia_setkey_enc( camellia_context *ctx, unsigned char *key, int keysize )
{
int i, idx;
uint32_t *RK;
@ -323,7 +323,7 @@ void camellia_setkey_enc( camellia_context *ctx, unsigned char *key, int keysize
case 128: ctx->nr = 3; idx = 0; break;
case 192:
case 256: ctx->nr = 4; idx = 1; break;
default : return;
default : return( POLARSSL_ERR_CAMELLIA_INVALID_KEY_LENGTH );
}
for( i = 0; i < keysize / 8; ++i)
@ -400,29 +400,34 @@ void camellia_setkey_enc( camellia_context *ctx, unsigned char *key, int keysize
RK[32 + 12 * idx + i] = RK[transposes[idx][i]];
}
}
return( 0 );
}
/*
* Camellia key schedule (decryption)
*/
void camellia_setkey_dec( camellia_context *ctx, unsigned char *key, int keysize )
int camellia_setkey_dec( camellia_context *ctx, unsigned char *key, int keysize )
{
int i, idx;
camellia_context cty;
uint32_t *RK;
uint32_t *SK;
int ret;
switch( keysize )
{
case 128: ctx->nr = 3; idx = 0; break;
case 192:
case 256: ctx->nr = 4; idx = 1; break;
default : return;
default : return( POLARSSL_ERR_CAMELLIA_INVALID_KEY_LENGTH );
}
RK = ctx->rk;
camellia_setkey_enc(&cty, key, keysize);
ret = camellia_setkey_enc(&cty, key, keysize);
if( ret != 0 )
return( ret );
SK = cty.rk + 24 * 2 + 8 * idx * 2;
@ -445,6 +450,8 @@ void camellia_setkey_dec( camellia_context *ctx, unsigned char *key, int keysize
*RK++ = *SK++;
memset( &cty, 0, sizeof( camellia_context ) );
return( 0 );
}
/*