Skip to content

Commit

Permalink
Merge pull request #5132 from openluopworld/origin/development_2.x
Browse files Browse the repository at this point in the history
Backport 2.x: Fix GCM calculation with very long IV
  • Loading branch information
gilles-peskine-arm committed Nov 22, 2021
2 parents b80aa7c + 5d5f520 commit 989a4e9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 4 additions & 0 deletions ChangeLog.d/bugfix-for-gcm-long-iv-size.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Bugfix
* Fix a bug in mbedtls_gcm_starts() when bits of iv are longer than 2^32.
* Fix #4884.

4 changes: 3 additions & 1 deletion library/gcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ int mbedtls_gcm_starts( mbedtls_gcm_context *ctx,
size_t i;
const unsigned char *p;
size_t use_len, olen = 0;
uint64_t iv_bits;

GCM_VALIDATE_RET( ctx != NULL );
GCM_VALIDATE_RET( iv != NULL );
Expand Down Expand Up @@ -286,7 +287,8 @@ int mbedtls_gcm_starts( mbedtls_gcm_context *ctx,
else
{
memset( work_buf, 0x00, 16 );
MBEDTLS_PUT_UINT32_BE( iv_len * 8, work_buf, 12 );
iv_bits = (uint64_t)iv_len * 8;
MBEDTLS_PUT_UINT64_BE( iv_bits, work_buf, 8 );

p = iv;
while( iv_len > 0 )
Expand Down

0 comments on commit 989a4e9

Please sign in to comment.