mirror of
https://github.com/zeek/zeek.git
synced 2025-10-07 17:18:20 +00:00
Hash unification: address PR feedback
This commit is contained in:
parent
7f137b7d50
commit
ce8b121e12
8 changed files with 33 additions and 29 deletions
3
.gitmodules
vendored
3
.gitmodules
vendored
|
@ -37,3 +37,6 @@
|
|||
[submodule "aux/libkqueue"]
|
||||
path = aux/libkqueue
|
||||
url = https://github.com/zeek/libkqueue
|
||||
[submodule "aux/highwayhash"]
|
||||
path = aux/highwayhash
|
||||
url = https://github.com/zeek/highwayhash
|
||||
|
|
|
@ -328,7 +328,7 @@ endif ()
|
|||
include_directories(BEFORE ${OPENSSL_INCLUDE_DIR})
|
||||
|
||||
# Make everyone find the highwayhash includes
|
||||
include_directories(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/src/3rdparty/highwayhash)
|
||||
include_directories(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/aux/highwayhash)
|
||||
|
||||
# Alpine support
|
||||
if ( ${CMAKE_SYSTEM_NAME} MATCHES Linux AND EXISTS /etc/os-release )
|
||||
|
|
1
aux/highwayhash
Submodule
1
aux/highwayhash
Submodule
|
@ -0,0 +1 @@
|
|||
Subproject commit 0aaf66bb8a1634ceee4b778df51a652bdf4e1f17
|
|
@ -1 +1 @@
|
|||
Subproject commit 8975ce11a9f0a9692fc2247107d036f9e11f9cd3
|
||||
Subproject commit ae9ff26a100e9f4ba03da8697c7ca14c3df4d4ab
|
|
@ -319,41 +319,41 @@ set(THIRD_PARTY_SRCS
|
|||
# Highwayhash. Highwayhash is a bit special since it has architecture dependent code...
|
||||
|
||||
set(HH_SRCS
|
||||
3rdparty/highwayhash/highwayhash/sip_hash.cc
|
||||
3rdparty/highwayhash/highwayhash/sip_tree_hash.cc
|
||||
3rdparty/highwayhash/highwayhash/scalar_sip_tree_hash.cc
|
||||
3rdparty/highwayhash/highwayhash/arch_specific.cc
|
||||
3rdparty/highwayhash/highwayhash/instruction_sets.cc
|
||||
3rdparty/highwayhash/highwayhash/nanobenchmark.cc
|
||||
3rdparty/highwayhash/highwayhash/os_specific.cc
|
||||
3rdparty/highwayhash/highwayhash/hh_portable.cc
|
||||
../aux/highwayhash/highwayhash/sip_hash.cc
|
||||
../aux/highwayhash/highwayhash/sip_tree_hash.cc
|
||||
../aux/highwayhash/highwayhash/scalar_sip_tree_hash.cc
|
||||
../aux/highwayhash/highwayhash/arch_specific.cc
|
||||
../aux/highwayhash/highwayhash/instruction_sets.cc
|
||||
../aux/highwayhash/highwayhash/nanobenchmark.cc
|
||||
../aux/highwayhash/highwayhash/os_specific.cc
|
||||
../aux/highwayhash/highwayhash/hh_portable.cc
|
||||
)
|
||||
|
||||
if (${COMPILER_ARCHITECTURE} STREQUAL "arm")
|
||||
set_source_files_properties(${HH_SRCS} PROPERTIES COMPILE_FLAGS
|
||||
-mfloat-abi=hard -march=armv7-a -mfpu=neon)
|
||||
list(APPEND HH_SRCS
|
||||
3rdparty/highwayhash/highwayhash/hh_neon.cc
|
||||
../aux/highwayhash/highwayhash/hh_neon.cc
|
||||
)
|
||||
elseif (${COMPILER_ARCHITECTURE} STREQUAL "aarch64")
|
||||
list(APPEND HH_SRCS
|
||||
3rdparty/highwayhash/highwayhash/hh_neon.cc
|
||||
../aux/highwayhash/highwayhash/hh_neon.cc
|
||||
)
|
||||
elseif (${COMPILER_ARCHITECTURE} STREQUAL "power")
|
||||
set_source_files_properties(3rdparty/highwayhash/highwayhash/hh_avx2.cc PROPERTIES COMPILE_FLAGS
|
||||
set_source_files_properties(../aux/highwayhash/highwayhash/hh_avx2.cc PROPERTIES COMPILE_FLAGS
|
||||
-mvsx)
|
||||
list(APPEND HH_SRCS
|
||||
3rdparty/highwayhash/highwayhash/hh_vsc.cc
|
||||
../aux/highwayhash/highwayhash/hh_vsc.cc
|
||||
)
|
||||
elseif(${COMPILER_ARCHITECTURE} STREQUAL "x86_64")
|
||||
set_source_files_properties(3rdparty/highwayhash/highwayhash/hh_avx2.cc PROPERTIES COMPILE_FLAGS
|
||||
set_source_files_properties(../aux/highwayhash/highwayhash/hh_avx2.cc PROPERTIES COMPILE_FLAGS
|
||||
-mavx2)
|
||||
set_source_files_properties(3rdparty/highwayhash/highwayhash/hh_sse41.cc PROPERTIES COMPILE_FLAGS
|
||||
set_source_files_properties(../aux/highwayhash/highwayhash/hh_sse41.cc PROPERTIES COMPILE_FLAGS
|
||||
-msse4.1)
|
||||
|
||||
list(APPEND HH_SRCS
|
||||
3rdparty/highwayhash/highwayhash/hh_avx2.cc
|
||||
3rdparty/highwayhash/highwayhash/hh_sse41.cc
|
||||
../aux/highwayhash/highwayhash/hh_avx2.cc
|
||||
../aux/highwayhash/highwayhash/hh_sse41.cc
|
||||
)
|
||||
endif ()
|
||||
|
||||
|
|
10
src/Hash.h
10
src/Hash.h
|
@ -4,7 +4,7 @@
|
|||
* This file contains functions to generate hashes used keyed hash functions.
|
||||
* Keyed hash functions make it difficult/impossible to find information about the
|
||||
* output of a hash when the key is unknown to the attacker. This fact holds, even
|
||||
* when the input value us known.
|
||||
* when the input value is known.
|
||||
*
|
||||
* We use these kinds of hashes heavily internally - e.g. for scriptland hash generation.
|
||||
* It is important that these hashes are not easily guessable to prevent complexity attacks.
|
||||
|
@ -102,7 +102,7 @@ public:
|
|||
* or a restart.
|
||||
*
|
||||
* To be more exact - the seed value for this hash is generated from the script-level
|
||||
* :seek:see:`digest_salt` constant. The seeds are stable as long as this value
|
||||
* :zeek:see:`digest_salt` constant. The seeds are stable as long as this value
|
||||
* is not changed.
|
||||
*
|
||||
* This should be used for hashes that have to remain stable over the entire
|
||||
|
@ -123,7 +123,7 @@ public:
|
|||
* or a restart.
|
||||
*
|
||||
* To be more exact - the seed value for this hash is generated from the script-level
|
||||
* :seek:see:`digest_salt` constant. The seeds are stable as long as this value
|
||||
* :zeek:see:`digest_salt` constant. The seeds are stable as long as this value
|
||||
* is not changed.
|
||||
*
|
||||
* This should be used for hashes that have to remain stable over the entire
|
||||
|
@ -144,7 +144,7 @@ public:
|
|||
* or a restart.
|
||||
*
|
||||
* To be more exact - the seed value for this hash is generated from the script-level
|
||||
* :seek:see:`digest_salt` constant. The seeds are stable as long as this value
|
||||
* :zeek:see:`digest_salt` constant. The seeds are stable as long as this value
|
||||
* is not changed.
|
||||
*
|
||||
* This should be used for hashes that have to remain stable over the entire
|
||||
|
@ -180,7 +180,7 @@ public:
|
|||
|
||||
/**
|
||||
* Initializes the static hash seeds using the script-level
|
||||
* :seek:see:`digest_salt` constant.
|
||||
* :zeek:see:`digest_salt` constant.
|
||||
*/
|
||||
static void InitOptions();
|
||||
|
||||
|
|
|
@ -66,7 +66,7 @@ unsigned char* internal_md5(const unsigned char* data, unsigned long len, unsign
|
|||
return calculate_digest(Hash_MD5, data, len, out);
|
||||
}
|
||||
|
||||
unsigned char* calculate_digest(HashAlgorithm Alg, const unsigned char* data, uint64_t len, unsigned char* out)
|
||||
unsigned char* calculate_digest(HashAlgorithm alg, const unsigned char* data, uint64_t len, unsigned char* out)
|
||||
{
|
||||
// maximum possible length for supported hashes
|
||||
static unsigned char static_out[SHA512_DIGEST_LENGTH];
|
||||
|
@ -74,7 +74,7 @@ unsigned char* calculate_digest(HashAlgorithm Alg, const unsigned char* data, ui
|
|||
if ( ! out )
|
||||
out = static_out; // use static array for return, see OpenSSL man page
|
||||
|
||||
EVP_MD_CTX* c = hash_init(Alg);
|
||||
EVP_MD_CTX* c = hash_init(alg);
|
||||
hash_update(c, data, len);
|
||||
hash_final(c, out);
|
||||
return out;
|
||||
|
|
|
@ -1031,7 +1031,7 @@ static bool read_random_seeds(const char* read_file, uint32_t* seed,
|
|||
}
|
||||
|
||||
// Read seeds for hmac-md5/siphash/highwayhash.
|
||||
for ( int i = 0; i < KeyedHash::SEED_INIT_SIZE; ++i )
|
||||
for ( auto &v : buf )
|
||||
{
|
||||
int tmp;
|
||||
if ( fscanf(f, "%u", &tmp) != 1 )
|
||||
|
@ -1040,7 +1040,7 @@ static bool read_random_seeds(const char* read_file, uint32_t* seed,
|
|||
return false;
|
||||
}
|
||||
|
||||
buf[i] = tmp;
|
||||
v = tmp;
|
||||
}
|
||||
|
||||
fclose(f);
|
||||
|
@ -1061,8 +1061,8 @@ static bool write_random_seeds(const char* write_file, uint32_t seed,
|
|||
|
||||
fprintf(f, "%u\n", seed);
|
||||
|
||||
for ( int i = 0; i < KeyedHash::SEED_INIT_SIZE; ++i )
|
||||
fprintf(f, "%u\n", buf[i]);
|
||||
for ( const auto &v: buf )
|
||||
fprintf(f, "%u\n", v);
|
||||
|
||||
fclose(f);
|
||||
return true;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue