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.

Function Documentation

◆ 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_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_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_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_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.

◆ 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_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_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.