Toeplitz hash

Overview

Definition of API to calculate hash used by RSS

Copyright (C) 2004-2022 OKTET Labs Ltd. More…

// typedefs

typedef struct te_toeplitz_hash_cache te_toeplitz_hash_cache;
typedef enum te_toeplitz_hash_variant te_toeplitz_hash_variant;

// enums

enum te_toeplitz_hash_variant;

// global functions

uint32_t te_toeplitz_hash_data(const te_toeplitz_hash_cache* toeplitz_hash_cache, const uint8_t* input, unsigned int pos, unsigned int datalen);
uint32_t te_toeplitz_hash(const te_toeplitz_hash_cache* toeplitz_hash_cache, unsigned int addr_size, const uint8_t* src_addr, uint16_t src_port, const uint8_t* dst_addr, uint16_t dst_port);
te_errno te_toeplitz_hash_sa(const te_toeplitz_hash_cache* toeplitz_hash_cache, const struct sockaddr* src_addr, const struct sockaddr* dst_addr, te_toeplitz_hash_variant hash_var, uint32_t* hash_out);
uint32_t te_toeplitz_hash_sym_or_xor(const te_toeplitz_hash_cache* toeplitz_hash_cache, unsigned int addr_size, const uint8_t* src_addr, uint16_t src_port, const uint8_t* dst_addr, uint16_t dst_port);
void te_toeplitz_hash_fini(te_toeplitz_hash_cache* toeplitz_hash_cache);
te_toeplitz_hash_cache* te_toeplitz_cache_init(const uint8_t* key);
te_toeplitz_hash_cache* te_toeplitz_cache_init_size(const uint8_t* key, size_t key_size);

Detailed Documentation

Definition of API to calculate hash used by RSS

Copyright (C) 2004-2022 OKTET Labs Ltd. All rights reserved.

Typedefs

typedef enum te_toeplitz_hash_variant te_toeplitz_hash_variant

Known variants of Toeplitz hash algorithm

Global Functions

uint32_t te_toeplitz_hash_data(const te_toeplitz_hash_cache* toeplitz_hash_cache, const uint8_t* input, unsigned int pos, unsigned int datalen)

Calculate a Toeplitz hash of input data

Parameters:

toeplitz_hash_cache

Pre-constructed cache

input

Pointer to input data

pos

Position of input data

datalen

Length of input data in bytes

RSS

hash value of input data

uint32_t te_toeplitz_hash(const te_toeplitz_hash_cache* toeplitz_hash_cache, unsigned int addr_size, const uint8_t* src_addr, uint16_t src_port, const uint8_t* dst_addr, uint16_t dst_port)

Calculate a RSS hash using pre-calculated cache

Parameters:

toeplitz_hash_cache

Pre-constructed cache

addr_size

IPv4 / IPv6 address length

src_addr

Pointer to source address

src_port

Source port number in network byte order

dst_addr

Pointer to destination address

dst_port

Desination port number in network byte order

RSS

hash value

te_errno te_toeplitz_hash_sa(const te_toeplitz_hash_cache* toeplitz_hash_cache, const struct sockaddr* src_addr, const struct sockaddr* dst_addr, te_toeplitz_hash_variant hash_var, uint32_t* hash_out)

Calculate a RSS hash for address/port pairs using pre-calculated cache.

Parameters:

toeplitz_hash_cache

Pre-constructed cache

src_addr

Source address/port

dst_addr

Destination address/port

hash_var

Hash variant

hash_out

Where to save computed hash

Returns:

Status code

uint32_t te_toeplitz_hash_sym_or_xor(const te_toeplitz_hash_cache* toeplitz_hash_cache, unsigned int addr_size, const uint8_t* src_addr, uint16_t src_port, const uint8_t* dst_addr, uint16_t dst_port)

Calculate a RSS hash using pre-calculated cache and symmetric algorithm with OR and XOR.

Parameters:

toeplitz_hash_cache

Pre-constructed cache

addr_size

IPv4 / IPv6 address length

src_addr

Pointer to source address

src_port

Source port number in network byte order

dst_addr

Pointer to destination address

dst_port

Desination port number in network byte order

Returns:

RSS hash value.

void te_toeplitz_hash_fini(te_toeplitz_hash_cache* toeplitz_hash_cache)

Free pre-constructed cache

Parameters:

toeplitz_hash_cache

Pointer to cache

te_toeplitz_hash_cache* te_toeplitz_cache_init(const uint8_t* key)

Pre-construct cache to use it for faster calculating of hash used by Toeplitz hash function

Parameters:

key

40-byte hash key

cache

or NULL in case of error

te_toeplitz_hash_cache* te_toeplitz_cache_init_size(const uint8_t* key, size_t key_size)

Pre-construct cache to use it for faster calculation of Toeplitz hash function.

Parameters:

key

Hash key

key_size

Length of the key in bytes

cache

or NULL in case of error