libcoap  4.3.0
murmur3.c File Reference
#include <assert.h>
#include <string.h>
#include "murmur3.h"
+ Include dependency graph for murmur3.c:

Go to the source code of this file.

Macros

#define min(a, b)   (((a) < (b)) ? (a) : (b))
 Naïve implementation of Murmur3 for 32 bit with update functionality. More...
 

Functions

static uint32_t rol (uint32_t val, uint8_t bits)
 
void murmur3_32_init (murmur3_context_t *mctx)
 Initializes the provided murmur3 context object mctx. More...
 
static void murmur3_32_eatblock (murmur3_context_t *mctx)
 
static size_t murmur3_32_fillblock (murmur3_context_t *mctx, const void *data, size_t len)
 
void murmur3_32_update (murmur3_context_t *mctx, const void *data, size_t len)
 Updates the state of the murmur3 context object mctx with len bytes from data. More...
 
uint32_t murmur3_32_finalize (murmur3_context_t *mctx)
 Finalizes the given murmur3 context mctx and calculates the resulting murmur3 hash value. More...
 
uint32_t murmur3_32 (const void *data, size_t len)
 Calculcates the murmur3 hash value of data. More...
 

Variables

const size_t murmur3_block_length = sizeof(uint32_t)
 
const uint32_t c1 = 0xcc9e2d51
 
const uint32_t c2 = 0x1b873593
 
const uint8_t r1 = 15
 
const uint8_t r2 = 13
 
const uint8_t m = 5
 
const uint32_t n = 0xe6546b64
 

Macro Definition Documentation

◆ min

#define min (   a,
 
)    (((a) < (b)) ? (a) : (b))

Naïve implementation of Murmur3 for 32 bit with update functionality.

See https://en.wikipedia.org/wiki/MurmurHash#Algorithm and https://github.com/aappleby/smhasher/wiki/MurmurHash3

Copyright (C) 2020 Olaf Bergmann bergm.nosp@m.ann@.nosp@m.tzi.o.nosp@m.rg

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.

Definition at line 37 of file murmur3.c.

Function Documentation

◆ murmur3_32()

uint32_t murmur3_32 ( const void *  data,
size_t  len 
)

Calculcates the murmur3 hash value of data.

This is a convenience function that encapsulates the required calls to murmur3_32_init(), murmur3_32_update(), and murmur3_32_finalize().

Parameters
dataThe data to hash.
lenThe actual length of data.
Returns
The murmur3 hash value of the data.

Definition at line 145 of file murmur3.c.

+ Here is the call graph for this function:

◆ murmur3_32_eatblock()

static void murmur3_32_eatblock ( murmur3_context_t mctx)
static

Definition at line 59 of file murmur3.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ murmur3_32_fillblock()

static size_t murmur3_32_fillblock ( murmur3_context_t mctx,
const void *  data,
size_t  len 
)
static

Definition at line 74 of file murmur3.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ murmur3_32_finalize()

uint32_t murmur3_32_finalize ( murmur3_context_t mctx)

Finalizes the given murmur3 context mctx and calculates the resulting murmur3 hash value.

Parameters
mctxThe murmur3 context to update.
Returns
The murmur3 hash value of the data that was passed to murmur3_32_update() for the context mctx.

Definition at line 123 of file murmur3.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ murmur3_32_init()

void murmur3_32_init ( murmur3_context_t mctx)

Initializes the provided murmur3 context object mctx.

Parameters
mctxThe murmur3 context to initialize.

Definition at line 46 of file murmur3.c.

+ Here is the caller graph for this function:

◆ murmur3_32_update()

void murmur3_32_update ( murmur3_context_t mctx,
const void *  data,
size_t  len 
)

Updates the state of the murmur3 context object mctx with len bytes from data.

Parameters
mctxThe murmur3 context to update.
dataThe data to hash.
lenThe actual length of data.

Definition at line 98 of file murmur3.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rol()

static uint32_t rol ( uint32_t  val,
uint8_t  bits 
)
inlinestatic

Definition at line 41 of file murmur3.c.

+ Here is the caller graph for this function:

Variable Documentation

◆ c1

const uint32_t c1 = 0xcc9e2d51

Definition at line 51 of file murmur3.c.

◆ c2

const uint32_t c2 = 0x1b873593

Definition at line 52 of file murmur3.c.

◆ m

const uint8_t m = 5

Definition at line 55 of file murmur3.c.

◆ murmur3_block_length

const size_t murmur3_block_length = sizeof(uint32_t)

Definition at line 50 of file murmur3.c.

◆ n

const uint32_t n = 0xe6546b64

Definition at line 56 of file murmur3.c.

◆ r1

const uint8_t r1 = 15

Definition at line 53 of file murmur3.c.

◆ r2

const uint8_t r2 = 13

Definition at line 54 of file murmur3.c.