Skip to content
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

Refactor the crypt package to support FIPS encryption #6

Merged
merged 1 commit into from
Feb 10, 2022
Merged

Conversation

atheriel
Copy link
Collaborator

This is with the aim of providing a FIPS-140 compliant version of this package and related tools: #2.

The existing NaCl secretbox algorithm is not a FIPS-140 approved algorithm, so this commit adds a second AES-256-GCM option, which is.

Users can make an explicit runtime decision to use the FIPS algorithm through the new EncryptFIPS() method. The existing Decrypt() method has been taught to recognise ciphertext encrypted this way using the version prefix machinery.

In addition, the package can now be built with a 'fips' tag. When this occurs, we swap out the NaCl algorithm for AES-256-GCM in Encrypt() and all attempts to call the NaCl algorithm will result in a new error, ErrFIPS.

Since software essentially expects to be FIPS-compliant or not (there is no gray zone), a compile-time setting seems like the most coherent choice for users who are expected to operate in these environments. I've found a few other examples of this pattern in the Go ecosystem.

The crypt API now includes a global constant indicates whether the package was built in "FIPS mode", and there are also some new tests for this constant that effectively verify the build tags.

Important Caveat

This change alone cannot produce a FIPS-compliant binary, because Go's crypto packages are not FIPS-compilant.

One must also build using the dev.boringcrypto Go toolchain, which swaps out the crypto package for one backed by BoringSSL -- itself a validated library. This is an emerging best practice for Go tools that want to be FIPS-compliant.

This is with the aim of providing a FIPS-140 compliant version of this
package and related tools.

The existing NaCl secretbox algorithm is not a FIPS-140 approved
algorithm, so this commit adds a second AES-256-GCM option, which is.

Users can make an explicit runtime decision to use the FIPS algorithm
through the new `EncryptFIPS()` method. The existing `Decrypt()` method
has been taught to recognise ciphertext encrypted this way using the
version prefix machinery.

In addition, the package can now be built with a 'fips' tag. When this
occurs, we swap out the NaCl algorithm for AES-256-GCM in `Encrypt()`
and all attempts to call the NaCl algorithm will result in a new error,
`ErrFIPS`.

Since software essentially expects to be FIPS-compliant or not (there is
no gray zone), a compile-time setting seems like the most coherent
choice for users who are expected to operate in these environments. I've
found a few other examples of this pattern in the Go ecosystem [0].

The crypt API now includes a global constant indicates whether the
package was built in "FIPS mode", and there are also some new tests for
this constant that effectively verify the build tags.

**Important Caveat**

This change alone *cannot* produce a FIPS-compliant binary, because Go's
crypto packages *are not FIPS-compilant*.

One must also build using the dev.boringcrypto Go toolchain, which swaps
out the crypto package for one backed by BoringSSL -- itself a validated
library. This is an emerging best pratice for Go tools that want to be
FIPS-compliant.

[0]: https://github.com/elastic/harp/

Signed-off-by: Aaron Jacobs <[email protected]>
@atheriel atheriel merged commit afeda30 into main Feb 10, 2022
@atheriel atheriel deleted the fips branch February 10, 2022 19:54
@atheriel atheriel added enhancement New feature or request product-feature Enhancements that would be made in coordination with downstream products labels Apr 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request product-feature Enhancements that would be made in coordination with downstream products
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant