-
Notifications
You must be signed in to change notification settings - Fork 915
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add SHA-1 and SHA-2 hash functions. (#14391)
This PR adds support for SHA-1 and SHA-2 (SHA-256, SHA-512, and truncated digests SHA-224, SHA-384) hash functions. Resolves #8641. Replaces #9215. Authors: - Bradley Dice (https://github.com/bdice) Approvers: - Robert Maynard (https://github.com/robertmaynard) - Matthew Roeschke (https://github.com/mroeschke) - David Wendt (https://github.com/davidwendt) - https://github.com/nvdbaranec URL: #14391
- Loading branch information
Showing
23 changed files
with
2,348 additions
and
97 deletions.
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 |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Copyright (c) 2024, NVIDIA CORPORATION. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include "sha_hash.cuh" | ||
|
||
#include <cudf/column/column.hpp> | ||
#include <cudf/scalar/scalar.hpp> | ||
#include <cudf/table/table_view.hpp> | ||
|
||
#include <rmm/cuda_stream_view.hpp> | ||
#include <rmm/exec_policy.hpp> | ||
#include <rmm/mr/device/device_memory_resource.hpp> | ||
|
||
#include <memory> | ||
|
||
namespace cudf { | ||
namespace hashing { | ||
namespace detail { | ||
|
||
namespace { | ||
|
||
struct sha1_hash_state { | ||
uint64_t message_length = 0; | ||
uint32_t buffer_length = 0; | ||
uint32_t hash_value[5] = {0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0}; | ||
uint8_t buffer[64]; | ||
}; | ||
|
||
struct SHA1Hash : HashBase<SHA1Hash> { | ||
__device__ inline SHA1Hash(char* result_location) : HashBase<SHA1Hash>(result_location) {} | ||
|
||
// Intermediate data type storing the hash state | ||
using hash_state = sha1_hash_state; | ||
// The word type used by this hash function | ||
using sha_word_type = uint32_t; | ||
// Number of bytes processed in each hash step | ||
static constexpr uint32_t message_chunk_size = 64; | ||
// Digest size in bytes | ||
static constexpr uint32_t digest_size = 40; | ||
// Number of bytes used for the message length | ||
static constexpr uint32_t message_length_size = 8; | ||
|
||
__device__ inline void hash_step(hash_state& state) { sha1_hash_step(state); } | ||
|
||
hash_state state; | ||
}; | ||
|
||
} // namespace | ||
|
||
std::unique_ptr<column> sha1(table_view const& input, | ||
rmm::cuda_stream_view stream, | ||
rmm::mr::device_memory_resource* mr) | ||
{ | ||
return sha_hash<SHA1Hash>(input, stream, mr); | ||
} | ||
|
||
} // namespace detail | ||
|
||
std::unique_ptr<column> sha1(table_view const& input, | ||
rmm::cuda_stream_view stream, | ||
rmm::mr::device_memory_resource* mr) | ||
{ | ||
CUDF_FUNC_RANGE(); | ||
return detail::sha1(input, stream, mr); | ||
} | ||
|
||
} // namespace hashing | ||
} // namespace cudf |
Oops, something went wrong.