mirror of
https://git.suyu.dev/suyu/mbedtls.git
synced 2025-12-21 21:36:21 +01:00
- Fixed cipher interface for encrypt/decrypt functions
This commit is contained in:
parent
4fc45522f1
commit
f3ccc68100
21 changed files with 286 additions and 170 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue