libwebsockets
Lightweight C library for HTML5 websockets
Generic Hash

Data Structures

struct  lws_genhash_ctx
 
struct  lws_genhmac_ctx
 

Macros

#define LWS_GENHASH_LARGEST   64
 

Enumerations

enum  lws_genhash_types {
  LWS_GENHASH_TYPE_UNKNOWN , LWS_GENHASH_TYPE_MD5 , LWS_GENHASH_TYPE_SHA1 , LWS_GENHASH_TYPE_SHA256 ,
  LWS_GENHASH_TYPE_SHA384 , LWS_GENHASH_TYPE_SHA512
}
 
enum  lws_genhmac_types { LWS_GENHMAC_TYPE_UNKNOWN , LWS_GENHMAC_TYPE_SHA256 , LWS_GENHMAC_TYPE_SHA384 , LWS_GENHMAC_TYPE_SHA512 }
 

Functions

LWS_VISIBLE LWS_EXTERN size_t LWS_WARN_UNUSED_RESULT lws_genhash_size (enum lws_genhash_types type)
 
LWS_VISIBLE LWS_EXTERN size_t LWS_WARN_UNUSED_RESULT lws_genhmac_size (enum lws_genhmac_types type)
 
LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT lws_genhash_init (struct lws_genhash_ctx *ctx, enum lws_genhash_types type)
 
LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT lws_genhash_update (struct lws_genhash_ctx *ctx, const void *in, size_t len)
 
LWS_VISIBLE LWS_EXTERN int lws_genhash_destroy (struct lws_genhash_ctx *ctx, void *result)
 
LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT lws_genhmac_init (struct lws_genhmac_ctx *ctx, enum lws_genhmac_types type, const uint8_t *key, size_t key_len)
 
LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT lws_genhmac_update (struct lws_genhmac_ctx *ctx, const void *in, size_t len)
 
LWS_VISIBLE LWS_EXTERN int lws_genhmac_destroy (struct lws_genhmac_ctx *ctx, void *result)
 

Detailed Description

Generic Hash related functions

Lws provides generic hash / digest accessors that abstract the ones provided by whatever tls library you are linking against.

It lets you use the same code if you build against mbedtls or OpenSSL for example.


Data Structure Documentation

◆ lws_genhash_ctx

struct lws_genhash_ctx

Definition at line 54 of file lws-genhash.h.

+ Collaboration diagram for lws_genhash_ctx:
Data Fields
uint8_t type
const EVP_MD * evp_type
EVP_MD_CTX * mdctx

◆ lws_genhmac_ctx

struct lws_genhmac_ctx

Definition at line 70 of file lws-genhash.h.

+ Collaboration diagram for lws_genhmac_ctx:
Data Fields
uint8_t type
const EVP_MD * evp_type
HMAC_CTX ctx

Macro Definition Documentation

◆ LWS_GENHASH_LARGEST

#define LWS_GENHASH_LARGEST   64

#include <include/libwebsockets/lws-genhash.h>

Definition at line 52 of file lws-genhash.h.

Enumeration Type Documentation

◆ lws_genhash_types

#include <include/libwebsockets/lws-genhash.h>

Enumerator
LWS_GENHASH_TYPE_UNKNOWN 
LWS_GENHASH_TYPE_MD5 
LWS_GENHASH_TYPE_SHA1 
LWS_GENHASH_TYPE_SHA256 
LWS_GENHASH_TYPE_SHA384 
LWS_GENHASH_TYPE_SHA512 

Definition at line 36 of file lws-genhash.h.

36 {
43};
@ LWS_GENHASH_TYPE_SHA384
Definition: lws-genhash.h:41
@ LWS_GENHASH_TYPE_UNKNOWN
Definition: lws-genhash.h:37
@ LWS_GENHASH_TYPE_MD5
Definition: lws-genhash.h:38
@ LWS_GENHASH_TYPE_SHA1
Definition: lws-genhash.h:39
@ LWS_GENHASH_TYPE_SHA512
Definition: lws-genhash.h:42
@ LWS_GENHASH_TYPE_SHA256
Definition: lws-genhash.h:40

◆ lws_genhmac_types

#include <include/libwebsockets/lws-genhash.h>

Enumerator
LWS_GENHMAC_TYPE_UNKNOWN 
LWS_GENHMAC_TYPE_SHA256 
LWS_GENHMAC_TYPE_SHA384 
LWS_GENHMAC_TYPE_SHA512 

Definition at line 45 of file lws-genhash.h.

45 {
50};
@ LWS_GENHMAC_TYPE_SHA384
Definition: lws-genhash.h:48
@ LWS_GENHMAC_TYPE_SHA512
Definition: lws-genhash.h:49
@ LWS_GENHMAC_TYPE_UNKNOWN
Definition: lws-genhash.h:46
@ LWS_GENHMAC_TYPE_SHA256
Definition: lws-genhash.h:47

Function Documentation

◆ lws_genhash_size()

LWS_VISIBLE LWS_EXTERN size_t LWS_WARN_UNUSED_RESULT lws_genhash_size ( enum lws_genhash_types  type)

#include <include/libwebsockets/lws-genhash.h>

lws_genhash_size() - get hash size in bytes

Parameters
typeone of LWS_GENHASH_TYPE_...

Returns number of bytes in this type of hash, if the hash type is unknown, it will return 0.

◆ lws_genhmac_size()

LWS_VISIBLE LWS_EXTERN size_t LWS_WARN_UNUSED_RESULT lws_genhmac_size ( enum lws_genhmac_types  type)

#include <include/libwebsockets/lws-genhash.h>

lws_genhmac_size() - get hash size in bytes

Parameters
typeone of LWS_GENHASH_TYPE_...

Returns number of bytes in this type of hmac, if the hmac type is unknown, it will return 0.

◆ lws_genhash_init()

LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT lws_genhash_init ( struct lws_genhash_ctx ctx,
enum lws_genhash_types  type 
)

#include <include/libwebsockets/lws-genhash.h>

lws_genhash_init() - prepare your struct lws_genhash_ctx for use

Parameters
ctxyour struct lws_genhash_ctx
typeone of LWS_GENHASH_TYPE_...

Initializes the hash context for the type you requested

◆ lws_genhash_update()

LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT lws_genhash_update ( struct lws_genhash_ctx ctx,
const void *  in,
size_t  len 
)

#include <include/libwebsockets/lws-genhash.h>

lws_genhash_update() - digest len bytes of the buffer starting at in

Parameters
ctxyour struct lws_genhash_ctx
instart of the bytes to digest
lencount of bytes to digest

Updates the state of your hash context to reflect digesting len bytes from in

◆ lws_genhash_destroy()

LWS_VISIBLE LWS_EXTERN int lws_genhash_destroy ( struct lws_genhash_ctx ctx,
void *  result 
)

#include <include/libwebsockets/lws-genhash.h>

lws_genhash_destroy() - copy out the result digest and destroy the ctx

Parameters
ctxyour struct lws_genhash_ctx
resultNULL, or where to copy the result hash

Finalizes the hash and copies out the digest. Destroys any allocations such that ctx can safely go out of scope after calling this.

NULL result is supported so that you can destroy the ctx cleanly on error conditions, where there is no valid result.

◆ lws_genhmac_init()

LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT lws_genhmac_init ( struct lws_genhmac_ctx ctx,
enum lws_genhmac_types  type,
const uint8_t *  key,
size_t  key_len 
)

#include <include/libwebsockets/lws-genhash.h>

lws_genhmac_init() - prepare your struct lws_genhmac_ctx for use

Parameters
ctxyour struct lws_genhmac_ctx
typeone of LWS_GENHMAC_TYPE_...
keypointer to the start of the HMAC key
key_lenlength of the HMAC key

Initializes the hash context for the type you requested

If the return is nonzero, it failed and there is nothing needing to be destroyed.

◆ lws_genhmac_update()

LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT lws_genhmac_update ( struct lws_genhmac_ctx ctx,
const void *  in,
size_t  len 
)

#include <include/libwebsockets/lws-genhash.h>

lws_genhmac_update() - digest len bytes of the buffer starting at in

Parameters
ctxyour struct lws_genhmac_ctx
instart of the bytes to digest
lencount of bytes to digest

Updates the state of your hash context to reflect digesting len bytes from in

If the return is nonzero, it failed and needs destroying.

◆ lws_genhmac_destroy()

LWS_VISIBLE LWS_EXTERN int lws_genhmac_destroy ( struct lws_genhmac_ctx ctx,
void *  result 
)

#include <include/libwebsockets/lws-genhash.h>

lws_genhmac_destroy() - copy out the result digest and destroy the ctx

Parameters
ctxyour struct lws_genhmac_ctx
resultNULL, or where to copy the result hash

Finalizes the hash and copies out the digest. Destroys any allocations such that ctx can safely go out of scope after calling this.

NULL result is supported so that you can destroy the ctx cleanly on error conditions, where there is no valid result.