mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-07-29 11:41:15 +03:00
Add output parameter to mbedtls_gcm_finish
Alternative implementations of GCM may delay the output of partial blocks from mbedtls_gcm_update(). Add an output parameter to mbedtls_gcm_finish() to allow such implementations to pass the final partial block back to the caller. With the software implementation, this final output is always empty. Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
@ -471,8 +471,8 @@ int mbedtls_gcm_update( mbedtls_gcm_context *ctx,
|
||||
}
|
||||
|
||||
int mbedtls_gcm_finish( mbedtls_gcm_context *ctx,
|
||||
unsigned char *tag,
|
||||
size_t tag_len )
|
||||
unsigned char *output, size_t output_len,
|
||||
unsigned char *tag, size_t tag_len )
|
||||
{
|
||||
unsigned char work_buf[16];
|
||||
size_t i;
|
||||
@ -482,6 +482,11 @@ int mbedtls_gcm_finish( mbedtls_gcm_context *ctx,
|
||||
GCM_VALIDATE_RET( ctx != NULL );
|
||||
GCM_VALIDATE_RET( tag != NULL );
|
||||
|
||||
/* We never pass any output in finish(). The output parameter exists only
|
||||
* for the sake of alternative implementations. */
|
||||
(void) output;
|
||||
(void) output_len;
|
||||
|
||||
orig_len = ctx->len * 8;
|
||||
orig_add_len = ctx->add_len * 8;
|
||||
|
||||
@ -541,7 +546,7 @@ int mbedtls_gcm_crypt_and_tag( mbedtls_gcm_context *ctx,
|
||||
if( ( ret = mbedtls_gcm_update( ctx, length, input, output ) ) != 0 )
|
||||
return( ret );
|
||||
|
||||
if( ( ret = mbedtls_gcm_finish( ctx, tag, tag_len ) ) != 0 )
|
||||
if( ( ret = mbedtls_gcm_finish( ctx, NULL, 0, tag, tag_len ) ) != 0 )
|
||||
return( ret );
|
||||
|
||||
return( 0 );
|
||||
@ -979,7 +984,7 @@ int mbedtls_gcm_self_test( int verbose )
|
||||
goto exit;
|
||||
}
|
||||
|
||||
ret = mbedtls_gcm_finish( &ctx, tag_buf, 16 );
|
||||
ret = mbedtls_gcm_finish( &ctx, NULL, 0, tag_buf, 16 );
|
||||
if( ret != 0 )
|
||||
goto exit;
|
||||
|
||||
@ -1039,7 +1044,7 @@ int mbedtls_gcm_self_test( int verbose )
|
||||
goto exit;
|
||||
}
|
||||
|
||||
ret = mbedtls_gcm_finish( &ctx, tag_buf, 16 );
|
||||
ret = mbedtls_gcm_finish( &ctx, NULL, 0, tag_buf, 16 );
|
||||
if( ret != 0 )
|
||||
goto exit;
|
||||
|
||||
|
Reference in New Issue
Block a user