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
Add a FIPS provider and implement SHA256 in it #8537
Closed
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
52f6b22
Create a FIPS provider and put SHA256 in it
mattcaswell 0febe62
Add a no-fips Configure option
mattcaswell e0ec00a
Test that we can use the FIPS provider
mattcaswell 2aadb0e
Complain if there are missing symbols when creating a provider .so file
mattcaswell e692d33
fixup! Create a FIPS provider and put SHA256 in it
mattcaswell 4eba605
fixup! Create a FIPS provider and put SHA256 in it
mattcaswell ac424b7
fixup! Create a FIPS provider and put SHA256 in it
mattcaswell 7c5888f
fixup! Add a no-fips Configure option
mattcaswell 699e4b5
fixup! Test that we can use the FIPS provider
mattcaswell 1e7f342
fixup! Create a FIPS provider and put SHA256 in it
mattcaswell b5e530f
fixup! Create a FIPS provider and put SHA256 in it
mattcaswell 32bd0e3
fixup! Test that we can use the FIPS provider
mattcaswell File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,12 @@ | ||
SUBDIRS=common default | ||
|
||
IF[{- !$disabled{fips} -}] | ||
SUBDIRS=fips | ||
MODULES=fips | ||
IF[{- defined $target{shared_defflag} -}] | ||
SOURCE[fips]=fips.ld | ||
GENERATE[fips.ld]=../util/providers.num | ||
ENDIF | ||
INCLUDE[fips]=.. ../include ../crypto/include | ||
DEFINE[fips]=FIPS_MODE | ||
ENDIF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
LIBS=../../../libcrypto | ||
SOURCE[../../../libcrypto]=\ | ||
sha2.c | ||
|
||
SOURCE[../../fips]=\ | ||
sha2.c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
SOURCE[../fips]=fipsprov.c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
* Copyright 2019 The OpenSSL Project Authors. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License 2.0 (the "License"). You may not use | ||
* this file except in compliance with the License. You can obtain a copy | ||
* in the file LICENSE in the source distribution or at | ||
* https://www.openssl.org/source/license.html | ||
*/ | ||
|
||
#include <string.h> | ||
#include <stdio.h> | ||
#include <openssl/core.h> | ||
#include <openssl/core_numbers.h> | ||
#include <openssl/core_names.h> | ||
#include <openssl/params.h> | ||
|
||
/* Functions provided by the core */ | ||
static OSSL_core_get_param_types_fn *c_get_param_types = NULL; | ||
static OSSL_core_get_params_fn *c_get_params = NULL; | ||
|
||
/* Parameters we provide to the core */ | ||
static const OSSL_ITEM fips_param_types[] = { | ||
{ OSSL_PARAM_UTF8_PTR, OSSL_PROV_PARAM_NAME }, | ||
{ OSSL_PARAM_UTF8_PTR, OSSL_PROV_PARAM_VERSION }, | ||
{ OSSL_PARAM_UTF8_PTR, OSSL_PROV_PARAM_BUILDINFO }, | ||
{ 0, NULL } | ||
}; | ||
|
||
static const OSSL_ITEM *fips_get_param_types(const OSSL_PROVIDER *prov) | ||
{ | ||
return fips_param_types; | ||
} | ||
|
||
static int fips_get_params(const OSSL_PROVIDER *prov, | ||
const OSSL_PARAM params[]) | ||
{ | ||
const OSSL_PARAM *p; | ||
|
||
p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_NAME); | ||
if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, "OpenSSL FIPS Provider")) | ||
return 0; | ||
p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_VERSION); | ||
if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, OPENSSL_VERSION_STR)) | ||
return 0; | ||
p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_BUILDINFO); | ||
if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, OPENSSL_FULL_VERSION_STR)) | ||
return 0; | ||
|
||
return 1; | ||
} | ||
|
||
extern const OSSL_DISPATCH sha256_functions[]; | ||
paulidale marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
static const OSSL_ALGORITHM fips_digests[] = { | ||
{ "SHA256", "fips=yes", sha256_functions }, | ||
levitte marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ NULL, NULL, NULL } | ||
}; | ||
|
||
static const OSSL_ALGORITHM *fips_query(OSSL_PROVIDER *prov, | ||
int operation_id, | ||
int *no_cache) | ||
{ | ||
*no_cache = 0; | ||
switch (operation_id) { | ||
case OSSL_OP_DIGEST: | ||
return fips_digests; | ||
} | ||
return NULL; | ||
} | ||
|
||
/* Functions we provide to the core */ | ||
static const OSSL_DISPATCH fips_dispatch_table[] = { | ||
{ OSSL_FUNC_PROVIDER_GET_PARAM_TYPES, (void (*)(void))fips_get_param_types }, | ||
{ OSSL_FUNC_PROVIDER_GET_PARAMS, (void (*)(void))fips_get_params }, | ||
{ OSSL_FUNC_PROVIDER_QUERY_OPERATION, (void (*)(void))fips_query }, | ||
{ 0, NULL } | ||
}; | ||
|
||
int OSSL_provider_init(const OSSL_PROVIDER *provider, | ||
const OSSL_DISPATCH *in, | ||
const OSSL_DISPATCH **out) | ||
{ | ||
for (; in->function_id != 0; in++) { | ||
switch (in->function_id) { | ||
case OSSL_FUNC_CORE_GET_PARAM_TYPES: | ||
c_get_param_types = OSSL_get_core_get_param_types(in); | ||
break; | ||
case OSSL_FUNC_CORE_GET_PARAMS: | ||
c_get_params = OSSL_get_core_get_params(in); | ||
break; | ||
/* Just ignore anything we don't understand */ | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
*out = fips_dispatch_table; | ||
return 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure it should generate the
OPENSSL_NO_FIPS
macro, though. That will just add confusion, 'cause that's not a library option.There's this section in
Configure
that has a selection of config options that shouldn't end up as C macros of that form,'fips'
should be added there:openssl/Configure
Lines 1224 to 1226 in e321ba2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess I don't understand that argument. It's something that we want to be able to write conditional code on (as evidenced by the fact I've used it already in the tests) - so why would we suppress the macro generation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm. Thinking about this more - I guess this is about whether it is appropriate to have the macro in opensslconf.h (a public header file). Is that it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, exactly