1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-07-29 11:41:15 +03:00

- Fixed cipher interface for encrypt/decrypt functions

This commit is contained in:
Paul Bakker
2010-03-18 21:21:02 +00:00
parent 4fc45522f1
commit f3ccc68100
21 changed files with 286 additions and 170 deletions

View File

@ -647,7 +647,7 @@ int aes_setkey_dec( aes_context *ctx, const unsigned char *key, int keysize )
/*
* AES-ECB block encryption/decryption
*/
void aes_crypt_ecb( aes_context *ctx,
int aes_crypt_ecb( aes_context *ctx,
int mode,
const unsigned char input[16],
unsigned char output[16] )
@ -659,7 +659,11 @@ void aes_crypt_ecb( aes_context *ctx,
if( padlock_supports( PADLOCK_ACE ) )
{
if( padlock_xcryptecb( ctx, mode, input, output ) == 0 )
return;
return( 0 );
// If padlock data misaligned, we just fall back to
// unaccelerated mode
//
}
#endif
@ -743,12 +747,14 @@ void aes_crypt_ecb( aes_context *ctx,
PUT_ULONG_LE( X1, output, 4 );
PUT_ULONG_LE( X2, output, 8 );
PUT_ULONG_LE( X3, output, 12 );
return( 0 );
}
/*
* AES-CBC buffer encryption/decryption
*/
void aes_crypt_cbc( aes_context *ctx,
int aes_crypt_cbc( aes_context *ctx,
int mode,
int length,
unsigned char iv[16],
@ -758,11 +764,18 @@ void aes_crypt_cbc( aes_context *ctx,
int i;
unsigned char temp[16];
if( length % 16 )
return( POLARSSL_ERR_AES_INVALID_INPUT_LENGTH );
#if defined(POLARSSL_PADLOCK_C) && defined(POLARSSL_HAVE_X86)
if( padlock_supports( PADLOCK_ACE ) )
{
if( padlock_xcryptcbc( ctx, mode, length, iv, input, output ) == 0 )
return;
return( 0 );
// If padlock data misaligned, we just fall back to
// unaccelerated mode
//
}
#endif
@ -798,12 +811,14 @@ void aes_crypt_cbc( aes_context *ctx,
length -= 16;
}
}
return( 0 );
}
/*
* AES-CFB128 buffer encryption/decryption
*/
void aes_crypt_cfb128( aes_context *ctx,
int aes_crypt_cfb128( aes_context *ctx,
int mode,
int length,
int *iv_off,
@ -841,6 +856,8 @@ void aes_crypt_cfb128( aes_context *ctx,
}
*iv_off = n;
return( 0 );
}
#if defined(POLARSSL_SELF_TEST)

View File

@ -63,7 +63,7 @@ void arc4_setup( arc4_context *ctx, const unsigned char *key, int keylen )
/*
* ARC4 cipher function
*/
void arc4_crypt( arc4_context *ctx, unsigned char *buf, int buflen )
int arc4_crypt( arc4_context *ctx, unsigned char *buf, int buflen )
{
int i, x, y, a, b;
unsigned char *m;
@ -86,6 +86,8 @@ void arc4_crypt( arc4_context *ctx, unsigned char *buf, int buflen )
ctx->x = x;
ctx->y = y;
return( 0 );
}
#if defined(POLARSSL_SELF_TEST)

View File

@ -458,7 +458,7 @@ int camellia_setkey_dec( camellia_context *ctx, const unsigned char *key, int ke
/*
* Camellia-ECB block encryption/decryption
*/
void camellia_crypt_ecb( camellia_context *ctx,
int camellia_crypt_ecb( camellia_context *ctx,
int mode,
const unsigned char input[16],
unsigned char output[16] )
@ -513,12 +513,14 @@ void camellia_crypt_ecb( camellia_context *ctx,
PUT_ULONG_BE( X[3], output, 4 );
PUT_ULONG_BE( X[0], output, 8 );
PUT_ULONG_BE( X[1], output, 12 );
return( 0 );
}
/*
* Camellia-CBC buffer encryption/decryption
*/
void camellia_crypt_cbc( camellia_context *ctx,
int camellia_crypt_cbc( camellia_context *ctx,
int mode,
int length,
unsigned char iv[16],
@ -528,6 +530,9 @@ void camellia_crypt_cbc( camellia_context *ctx,
int i;
unsigned char temp[16];
if( length % 16 )
return( POLARSSL_ERR_CAMELLIA_INVALID_INPUT_LENGTH );
if( mode == CAMELLIA_DECRYPT )
{
while( length > 0 )
@ -560,12 +565,14 @@ void camellia_crypt_cbc( camellia_context *ctx,
length -= 16;
}
}
return( 0 );
}
/*
* Camellia-CFB128 buffer encryption/decryption
*/
void camellia_crypt_cfb128( camellia_context *ctx,
int camellia_crypt_cfb128( camellia_context *ctx,
int mode,
int length,
int *iv_off,
@ -603,6 +610,8 @@ void camellia_crypt_cfb128( camellia_context *ctx,
}
*iv_off = n;
return( 0 );
}
#if defined(POLARSSL_SELF_TEST)

View File

@ -476,7 +476,7 @@ void des3_set3key_dec( des3_context *ctx, const unsigned char key[24] )
/*
* DES-ECB block encryption/decryption
*/
void des_crypt_ecb( des_context *ctx,
int des_crypt_ecb( des_context *ctx,
const unsigned char input[8],
unsigned char output[8] )
{
@ -500,12 +500,14 @@ void des_crypt_ecb( des_context *ctx,
PUT_ULONG_BE( Y, output, 0 );
PUT_ULONG_BE( X, output, 4 );
return( 0 );
}
/*
* DES-CBC buffer encryption/decryption
*/
void des_crypt_cbc( des_context *ctx,
int des_crypt_cbc( des_context *ctx,
int mode,
int length,
unsigned char iv[8],
@ -515,6 +517,9 @@ void des_crypt_cbc( des_context *ctx,
int i;
unsigned char temp[8];
if( length % 8 )
return( POLARSSL_ERR_DES_INVALID_INPUT_LENGTH );
if( mode == DES_ENCRYPT )
{
while( length > 0 )
@ -547,12 +552,14 @@ void des_crypt_cbc( des_context *ctx,
length -= 8;
}
}
return( 0 );
}
/*
* 3DES-ECB block encryption/decryption
*/
void des3_crypt_ecb( des3_context *ctx,
int des3_crypt_ecb( des3_context *ctx,
const unsigned char input[8],
unsigned char output[8] )
{
@ -588,12 +595,14 @@ void des3_crypt_ecb( des3_context *ctx,
PUT_ULONG_BE( Y, output, 0 );
PUT_ULONG_BE( X, output, 4 );
return( 0 );
}
/*
* 3DES-CBC buffer encryption/decryption
*/
void des3_crypt_cbc( des3_context *ctx,
int des3_crypt_cbc( des3_context *ctx,
int mode,
int length,
unsigned char iv[8],
@ -603,6 +612,9 @@ void des3_crypt_cbc( des3_context *ctx,
int i;
unsigned char temp[8];
if( length % 8 )
return( POLARSSL_ERR_DES_INVALID_INPUT_LENGTH );
if( mode == DES_ENCRYPT )
{
while( length > 0 )
@ -635,6 +647,8 @@ void des3_crypt_cbc( des3_context *ctx,
length -= 8;
}
}
return( 0 );
}
#if defined(POLARSSL_SELF_TEST)

View File

@ -126,7 +126,7 @@ int padlock_xcryptcbc( aes_context *ctx,
if( ( (long) input & 15 ) != 0 ||
( (long) output & 15 ) != 0 )
return( 1 );
return( POLARSSL_ERR_PADLOCK_DATA_MISALIGNED );
rk = ctx->rk;
iw = PADLOCK_ALIGN16( buf );

View File

@ -68,7 +68,7 @@ void xtea_setup( xtea_context *ctx, unsigned char key[16] )
/*
* XTEA encrypt function
*/
void xtea_crypt_ecb( xtea_context *ctx, int mode, unsigned char input[8],
int xtea_crypt_ecb( xtea_context *ctx, int mode, unsigned char input[8],
unsigned char output[8])
{
uint32_t *k, v0, v1, i;
@ -103,6 +103,8 @@ void xtea_crypt_ecb( xtea_context *ctx, int mode, unsigned char input[8],
PUT_ULONG_BE( v0, output, 0 );
PUT_ULONG_BE( v1, output, 4 );
return( 0 );
}
#if defined(POLARSSL_SELF_TEST)