-
Notifications
You must be signed in to change notification settings - Fork 184
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
Improve cryptography tests. #3979
Merged
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
5abe57d
Move the crypto unit tests to a dedicated project.
teo-tsirpanis 85966b3
Test the cryptographic random number generator.
teo-tsirpanis 9dfef2b
Add SHA256 tests from the NIST test vectors.
teo-tsirpanis ae89383
Add MD5 tests from RFC1321 test vectors.
teo-tsirpanis 0ade268
Fix compile errors around mismatched loop counter types.
teo-tsirpanis 7cbd02f
Remove the previous hash tests.
teo-tsirpanis 7083a61
Make sure formatting does not put `bcrypt.h` before `windows.h`.
teo-tsirpanis 453f5c6
Put `Win32CNG::md5` and `sha256` in the header.
teo-tsirpanis f39f026
Change `get_random_bytes` to not require a buffer and work with raw p…
teo-tsirpanis e4289cd
Use an alias to choose the platform-specific crypto class in `crypto.…
teo-tsirpanis 8305fb6
Add `Crypto::get_random_bytes`, removing the platform-specific code f…
teo-tsirpanis 488c4a0
Refactor `test_hash` to use template parameters for the hash instead …
teo-tsirpanis fb741c1
Use a vector of test cases.
teo-tsirpanis a2837c8
Improve documentation and naming.
teo-tsirpanis e8dd34d
Fix formatting.
teo-tsirpanis 3c06639
Use spans in `Crypto::get_random`.
teo-tsirpanis da7e47b
Add documentation for the AES-GCM tests.
teo-tsirpanis 9e0fa00
Fix compile errors.
teo-tsirpanis 535d352
Fix CI.
teo-tsirpanis 1c0c9f4
Merge branch 'dev' into crypto-tests
teo-tsirpanis ca102fb
Use `string_view`.
teo-tsirpanis 2e68386
Refactor the AES-GCM `TestCase` class to use spans and constexpr.
teo-tsirpanis 10ab36d
Update `to_hex` to accept a span.
teo-tsirpanis bf805d3
Fix infinite loop.
teo-tsirpanis 9073c89
Fix indentation.
teo-tsirpanis 4dd0359
Make `get_random_bytes` private and remove its test.
teo-tsirpanis 100ce2b
Remove `tiledb/sm/crypto/test/main.cc`.
teo-tsirpanis fdc9aad
Update template definition in the hash test.
teo-tsirpanis 8b08750
Revert changing the size parameter in the hash function template.
teo-tsirpanis ff4d989
Merge branch 'dev' into crypto-tests
teo-tsirpanis c67b6f7
Add comment about linking to OpenSSL target.
teo-tsirpanis fb5c7e6
Merge branch 'dev' into crypto-tests
teo-tsirpanis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,7 @@ | |
#include <windows.h> | ||
|
||
#include <bcrypt.h> | ||
|
||
#include "tiledb/common/status.h" | ||
|
||
using namespace tiledb::common; | ||
|
@@ -101,7 +102,9 @@ class Win32CNG { | |
* @return Status | ||
*/ | ||
static Status md5( | ||
const void* input, uint64_t input_read_size, Buffer* output); | ||
const void* input, uint64_t input_read_size, Buffer* output) { | ||
return hash_bytes(input, input_read_size, output, BCRYPT_MD5_ALGORITHM); | ||
} | ||
|
||
/** | ||
* Compute sha256 checksum of data | ||
|
@@ -112,11 +115,14 @@ class Win32CNG { | |
* @return Status | ||
*/ | ||
static Status sha256( | ||
const void* input, uint64_t input_read_size, Buffer* output); | ||
const void* input, uint64_t input_read_size, Buffer* output) { | ||
return hash_bytes(input, input_read_size, output, BCRYPT_SHA256_ALGORITHM); | ||
} | ||
|
||
private: | ||
/** | ||
* | ||
* Compute a has using Win32CNG functions | ||
* Compute a hash using Win32CNG functions | ||
* | ||
* @param input Plaintext to compute hash of | ||
* @param input_read_size size of input to read for hash | ||
|
@@ -129,16 +135,6 @@ class Win32CNG { | |
uint64_t input_read_size, | ||
Buffer* output, | ||
LPCWSTR hash_algorithm); | ||
|
||
private: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Leave it private. Or better yet, since it's static, take it out of the class and define it only in the |
||
/** | ||
* Generates a number of cryptographically random bytes. | ||
* | ||
* @param num_bytes Number of bytes to generate. | ||
* @param output Buffer to store random bytes. | ||
* @return Status | ||
*/ | ||
static Status get_random_bytes(unsigned num_bytes, Buffer* output); | ||
}; | ||
|
||
} // namespace sm | ||
|
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,32 @@ | ||
# | ||
# tiledb/sm/crypto/test/CMakeLists.txt | ||
# | ||
# The MIT License | ||
# | ||
# Copyright (c) 2024 TileDB, Inc. | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in | ||
# all copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
# THE SOFTWARE. | ||
# | ||
|
||
include(unit_test) | ||
|
||
commence(unit_test tiledb_crypto) | ||
this_target_sources(unit_tiledb_crypto.cc) | ||
this_target_object_libraries(tiledb_crypto) | ||
conclude(unit_test) |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
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.
What's the resolution on this? It hasn't been addressed from last time.
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.
The difference is that
this_target_link_libraries
links withPUBLIC
visibility, which is undesirable in this case, because we use OpenSSL as an internal implementation detail. Changing it right now does not break anything, but it will have undesirable effects once thetiledb_crypto
object library is incorporated to the main build (and theOpenSSL::Crypto
target would be a requirement even for shared libraries).I am going to remove the commented line, and add a comment on why we can't use
this_target_link_libraries
.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.
Done.