Remove unused functions from aes.c and sha4.c

This commit is contained in:
Con Kolivas 2011-03-16 00:51:28 +11:00
parent 5da0633893
commit e1af8fb0c0
2 changed files with 0 additions and 162 deletions

45
aes.c
View file

@ -812,48 +812,3 @@ int aes_crypt_cbc( aes_context *ctx,
return( 0 ); return( 0 );
} }
/*
* AES-CFB128 buffer encryption/decryption
*/
int aes_crypt_cfb128( aes_context *ctx,
int mode,
int length,
int *iv_off,
unsigned char iv[16],
const unsigned char *input,
unsigned char *output )
{
int c, n = *iv_off;
if( mode == AES_DECRYPT )
{
while( length-- )
{
if( n == 0 )
aes_crypt_ecb( ctx, AES_ENCRYPT, iv, iv );
c = *input++;
*output++ = (unsigned char)( c ^ iv[n] );
iv[n] = (unsigned char) c;
n = (n + 1) & 0x0F;
}
}
else
{
while( length-- )
{
if( n == 0 )
aes_crypt_ecb( ctx, AES_ENCRYPT, iv, iv );
iv[n] = *output++ = (unsigned char)( iv[n] ^ *input++ );
n = (n + 1) & 0x0F;
}
}
*iv_off = n;
return( 0 );
}

117
sha4.c
View file

@ -322,120 +322,3 @@ void sha4( const unsigned char *input, int ilen,
memset( &ctx, 0, sizeof( sha4_context ) ); memset( &ctx, 0, sizeof( sha4_context ) );
} }
/*
* output = SHA-512( file contents )
*/
int sha4_file( const char *path, unsigned char output[64], int is384 )
{
FILE *f;
size_t n;
sha4_context ctx;
unsigned char buf[1024];
if( ( f = fopen( path, "rb" ) ) == NULL )
return( 1 );
sha4_starts( &ctx, is384 );
while( ( n = fread( buf, 1, sizeof( buf ), f ) ) > 0 )
sha4_update( &ctx, buf, (int) n );
sha4_finish( &ctx, output );
memset( &ctx, 0, sizeof( sha4_context ) );
if( ferror( f ) != 0 )
{
fclose( f );
return( 2 );
}
fclose( f );
return( 0 );
}
/*
* SHA-512 HMAC context setup
*/
void sha4_hmac_starts( sha4_context *ctx, const unsigned char *key, int keylen,
int is384 )
{
int i;
unsigned char sum[64];
if( keylen > 128 )
{
sha4( key, keylen, sum, is384 );
keylen = ( is384 ) ? 48 : 64;
key = sum;
}
memset( ctx->ipad, 0x36, 128 );
memset( ctx->opad, 0x5C, 128 );
for( i = 0; i < keylen; i++ )
{
ctx->ipad[i] = (unsigned char)( ctx->ipad[i] ^ key[i] );
ctx->opad[i] = (unsigned char)( ctx->opad[i] ^ key[i] );
}
sha4_starts( ctx, is384 );
sha4_update( ctx, ctx->ipad, 128 );
memset( sum, 0, sizeof( sum ) );
}
/*
* SHA-512 HMAC process buffer
*/
void sha4_hmac_update( sha4_context *ctx,
const unsigned char *input, int ilen )
{
sha4_update( ctx, input, ilen );
}
/*
* SHA-512 HMAC final digest
*/
void sha4_hmac_finish( sha4_context *ctx, unsigned char output[64] )
{
int is384, hlen;
unsigned char tmpbuf[64];
is384 = ctx->is384;
hlen = ( is384 == 0 ) ? 64 : 48;
sha4_finish( ctx, tmpbuf );
sha4_starts( ctx, is384 );
sha4_update( ctx, ctx->opad, 128 );
sha4_update( ctx, tmpbuf, hlen );
sha4_finish( ctx, output );
memset( tmpbuf, 0, sizeof( tmpbuf ) );
}
/*
* SHA-512 HMAC context reset
*/
void sha4_hmac_reset( sha4_context *ctx )
{
sha4_starts( ctx, ctx->is384 );
sha4_update( ctx, ctx->ipad, 128 );
}
/*
* output = HMAC-SHA-512( hmac key, input buffer )
*/
void sha4_hmac( const unsigned char *key, int keylen,
const unsigned char *input, int ilen,
unsigned char output[64], int is384 )
{
sha4_context ctx;
sha4_hmac_starts( &ctx, key, keylen, is384 );
sha4_hmac_update( &ctx, input, ilen );
sha4_hmac_finish( &ctx, output );
memset( &ctx, 0, sizeof( sha4_context ) );
}