Skip to content

x/crypto/openpgp/packet: Optimizing Struct Field Alignment #70897

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ZuhairORZaki opened this issue Dec 18, 2024 · 3 comments
Closed

x/crypto/openpgp/packet: Optimizing Struct Field Alignment #70897

ZuhairORZaki opened this issue Dec 18, 2024 · 3 comments
Labels
Milestone

Comments

@ZuhairORZaki
Copy link

Proposal Details

Overview

In file: one_pass_signature.go, the fields of the OnePassSignature struct are organized in a way that takes more memory. The fields of the struct can be sorted in a way that takes less memory than the initial alignment.

// OnePassSignature represents a one-pass signature packet. See RFC 4880,
// section 5.4.
type OnePassSignature struct {
	SigType    SignatureType
	Hash       crypto.Hash
	PubKeyAlgo PublicKeyAlgorithm
	KeyId      uint64
	IsLast     bool
}

For the above alignment, the size of the struct is 40 bytes (for 64-bit systems). It can be reduced to 24 bytes by aligning the fields as follows:

type OnePassSignature struct {
	Hash       crypto.Hash
	KeyId      uint64
	SigType    SignatureType
	PubKeyAlgo PublicKeyAlgorithm
	IsLast     bool
}

Sponsorship and Support:

This work is done by the security researchers from OpenRefactory and is supported by the Open Source Security Foundation (OpenSSF): Project Alpha-Omega. Alpha-Omega is a project partnering with open source software project maintainers to systematically find new, as-yet-undiscovered vulnerabilities in open source code - and get them fixed - to improve global software supply chain security.

The bug is found by running the iCR tool by OpenRefactory, Inc. and then manually triaging the results.

@gopherbot gopherbot added this to the Unreleased milestone Dec 18, 2024
@seankhliao
Copy link
Member

The openpgp package is frozen.

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Dec 18, 2024
@seankhliao seankhliao changed the title x/crypto: Optimizing Struct Field Alignment x/crypto/openpgp/packet: Optimizing Struct Field Alignment Dec 18, 2024
@zigo101
Copy link

zigo101 commented Dec 18, 2024

See #66408, field reordering might be supported later.

@ZuhairORZaki
Copy link
Author

@zigo101 Thank you for clarifying.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants