Skip to content

Fix integer truncation in ppc_aes_gcm_crypt#30437

Closed
Scottcjn wants to merge 1 commit intoopenssl:masterfrom
Scottcjn:fix/ppc-aes-gcm-int-truncation
Closed

Fix integer truncation in ppc_aes_gcm_crypt#30437
Scottcjn wants to merge 1 commit intoopenssl:masterfrom
Scottcjn:fix/ppc-aes-gcm-int-truncation

Conversation

@Scottcjn
Copy link
Copy Markdown
Contributor

Problem

In ppc_aes_gcm_crypt(), the PPC64 assembly functions ppc_aes_gcm_encrypt
and ppc_aes_gcm_decrypt are declared as returning size_t (64-bit on PPC64)
in include/crypto/aes_platform.h, but their return values are stored in local
int variables (s and ndone), which are 32-bit signed.

This causes silent truncation for inputs exceeding 2GB, which is reachable
through EVP_Cipher() (takes unsigned int length).

Fixes #30381

Fix

Change the types of s and ndone from int to size_t to match the
return type of the assembly functions and the return type of
ppc_aes_gcm_crypt itself.

Testing

Built and tested on IBM POWER8 S824 (ppc64le, Ubuntu 20.04):

  • make test TESTS='test_evp test_evp_extra test_aes_wrap test_cipherlist'all pass
  • AES-128-GCM benchmark: 2.94 GB/s with hardware acceleration (CPUINFO: OPENSSL_ppccap=0x2e)
type             16 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes  16384 bytes
AES-128-GCM      10449.57k    37975.17k   142365.87k  1131144.53k  2739066.20k  2938301.10k

CLA: trivial

The assembly functions ppc_aes_gcm_encrypt and ppc_aes_gcm_decrypt
return size_t, but their return values were stored in int variables,
causing truncation on PPC64 where size_t is 64-bit. This could lead
to incorrect results when processing inputs larger than 2GB via
EVP_Cipher() which accepts unsigned int lengths.

Change the types of s and ndone from int to size_t to match the
function return type and the return type of ppc_aes_gcm_crypt itself.

Tested on POWER8 S824 (ppc64le) — all EVP and cipher tests pass,
AES-128-GCM benchmarks at 2.94 GB/s with hardware acceleration.

CLA: trivial
@openssl-machine openssl-machine added the approval: review pending This pull request needs review by a committer label Mar 16, 2026
@openssl-machine openssl-machine added approval: done This pull request has the required number of approvals and removed approval: review pending This pull request needs review by a committer labels Mar 16, 2026
@t8m t8m added cla: trivial One of the commits is marked as 'CLA: trivial' triaged: bug The issue/pr is/fixes a bug tests: exempted The PR is exempt from requirements for testing branch: master Applies to master branch branch: 3.3 Applies to openssl-3.3 branch: 3.4 Applies to openssl-3.4 branch: 3.5 Applies to openssl-3.5 branch: 3.6 Applies to openssl-3.6 branch: 4.0 Applies to openssl-4.0 labels Mar 16, 2026
Copy link
Copy Markdown
Member

@t8m t8m left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK with CLA trivial

@paulidale
Copy link
Copy Markdown
Contributor

I'm okay with trivial too.

@openssl-machine
Copy link
Copy Markdown
Collaborator

24 hours has passed since 'approval: done' was set, but as this PR has been updated in that time the label 'approval: ready to merge' is not being automatically set. Please review the updates and set the label manually.

@t8m t8m added approval: ready to merge The 24 hour grace period has passed, ready to merge and removed approval: done This pull request has the required number of approvals labels Mar 17, 2026
openssl-machine pushed a commit that referenced this pull request Mar 17, 2026
The assembly functions ppc_aes_gcm_encrypt and ppc_aes_gcm_decrypt
return size_t, but their return values were stored in int variables,
causing truncation on PPC64 where size_t is 64-bit. This could lead
to incorrect results when processing inputs larger than 2GB via
EVP_Cipher() which accepts unsigned int lengths.

Change the types of s and ndone from int to size_t to match the
function return type and the return type of ppc_aes_gcm_crypt itself.

Tested on POWER8 S824 (ppc64le) — all EVP and cipher tests pass,
AES-128-GCM benchmarks at 2.94 GB/s with hardware acceleration.

CLA: trivial

Reviewed-by: Nikola Pajkovsky <[email protected]>
Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
MergeDate: Tue Mar 17 09:44:33 2026
(Merged from #30437)
openssl-machine pushed a commit that referenced this pull request Mar 17, 2026
The assembly functions ppc_aes_gcm_encrypt and ppc_aes_gcm_decrypt
return size_t, but their return values were stored in int variables,
causing truncation on PPC64 where size_t is 64-bit. This could lead
to incorrect results when processing inputs larger than 2GB via
EVP_Cipher() which accepts unsigned int lengths.

Change the types of s and ndone from int to size_t to match the
function return type and the return type of ppc_aes_gcm_crypt itself.

Tested on POWER8 S824 (ppc64le) — all EVP and cipher tests pass,
AES-128-GCM benchmarks at 2.94 GB/s with hardware acceleration.

CLA: trivial

Reviewed-by: Nikola Pajkovsky <[email protected]>
Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
MergeDate: Tue Mar 17 09:44:33 2026
(Merged from #30437)

(cherry picked from commit e443447)
openssl-machine pushed a commit that referenced this pull request Mar 17, 2026
The assembly functions ppc_aes_gcm_encrypt and ppc_aes_gcm_decrypt
return size_t, but their return values were stored in int variables,
causing truncation on PPC64 where size_t is 64-bit. This could lead
to incorrect results when processing inputs larger than 2GB via
EVP_Cipher() which accepts unsigned int lengths.

Change the types of s and ndone from int to size_t to match the
function return type and the return type of ppc_aes_gcm_crypt itself.

Tested on POWER8 S824 (ppc64le) — all EVP and cipher tests pass,
AES-128-GCM benchmarks at 2.94 GB/s with hardware acceleration.

CLA: trivial

Reviewed-by: Nikola Pajkovsky <[email protected]>
Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
MergeDate: Tue Mar 17 09:44:33 2026
(Merged from #30437)

(cherry picked from commit e443447)
@t8m
Copy link
Copy Markdown
Member

t8m commented Mar 17, 2026

Merged to the master, 4.0, 3.6, 3.5, 3.4 and 3.3 branches. Thank you for your contribution.

@t8m t8m closed this Mar 17, 2026
openssl-machine pushed a commit that referenced this pull request Mar 17, 2026
The assembly functions ppc_aes_gcm_encrypt and ppc_aes_gcm_decrypt
return size_t, but their return values were stored in int variables,
causing truncation on PPC64 where size_t is 64-bit. This could lead
to incorrect results when processing inputs larger than 2GB via
EVP_Cipher() which accepts unsigned int lengths.

Change the types of s and ndone from int to size_t to match the
function return type and the return type of ppc_aes_gcm_crypt itself.

Tested on POWER8 S824 (ppc64le) — all EVP and cipher tests pass,
AES-128-GCM benchmarks at 2.94 GB/s with hardware acceleration.

CLA: trivial

Reviewed-by: Nikola Pajkovsky <[email protected]>
Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
MergeDate: Tue Mar 17 09:44:33 2026
(Merged from #30437)

(cherry picked from commit e443447)
openssl-machine pushed a commit that referenced this pull request Mar 17, 2026
The assembly functions ppc_aes_gcm_encrypt and ppc_aes_gcm_decrypt
return size_t, but their return values were stored in int variables,
causing truncation on PPC64 where size_t is 64-bit. This could lead
to incorrect results when processing inputs larger than 2GB via
EVP_Cipher() which accepts unsigned int lengths.

Change the types of s and ndone from int to size_t to match the
function return type and the return type of ppc_aes_gcm_crypt itself.

Tested on POWER8 S824 (ppc64le) — all EVP and cipher tests pass,
AES-128-GCM benchmarks at 2.94 GB/s with hardware acceleration.

CLA: trivial

Reviewed-by: Nikola Pajkovsky <[email protected]>
Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
MergeDate: Tue Mar 17 09:44:33 2026
(Merged from #30437)

(cherry picked from commit e443447)
openssl-machine pushed a commit that referenced this pull request Mar 17, 2026
The assembly functions ppc_aes_gcm_encrypt and ppc_aes_gcm_decrypt
return size_t, but their return values were stored in int variables,
causing truncation on PPC64 where size_t is 64-bit. This could lead
to incorrect results when processing inputs larger than 2GB via
EVP_Cipher() which accepts unsigned int lengths.

Change the types of s and ndone from int to size_t to match the
function return type and the return type of ppc_aes_gcm_crypt itself.

Tested on POWER8 S824 (ppc64le) — all EVP and cipher tests pass,
AES-128-GCM benchmarks at 2.94 GB/s with hardware acceleration.

CLA: trivial

Reviewed-by: Nikola Pajkovsky <[email protected]>
Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
MergeDate: Tue Mar 17 09:44:33 2026
(Merged from #30437)

(cherry picked from commit e443447)
@Scottcjn
Copy link
Copy Markdown
Contributor Author

Thank you to @paulidale, @npajkovsky, and @t8m for the reviews and merge. Honored to contribute to OpenSSL — this was our first contribution to the project and we're glad it strengthens the POWER8 AES-GCM path. Looking forward to contributing more.

— Scott Boudreaux, Elyan Labs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approval: ready to merge The 24 hour grace period has passed, ready to merge branch: master Applies to master branch branch: 3.3 Applies to openssl-3.3 branch: 3.4 Applies to openssl-3.4 branch: 3.5 Applies to openssl-3.5 branch: 3.6 Applies to openssl-3.6 branch: 4.0 Applies to openssl-4.0 cla: trivial One of the commits is marked as 'CLA: trivial' tests: exempted The PR is exempt from requirements for testing triaged: bug The issue/pr is/fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ppc_aes_gcm_crypt: integer truncation for inputs >2GB

5 participants