ndn-lite
Data Structures | Typedefs | Functions
ndn-lite-sha.h File Reference
#include "ndn-lite-sec-config.h"
#include "../ndn-error-code.h"
#include "../ndn-constants.h"

Go to the source code of this file.

Data Structures

struct  ndn_sha_backend
 The structure to represent the backend implementation. More...
 
struct  ndn_sha256_state
 The structure to represent the SHA256 hash state. More...
 

Typedefs

typedef struct abstract_sha256_state abstract_sha256_state_t
 The opaque abstract SHA256 state struct to be implemented by the backend. More...
 
typedef int(* ndn_sha256_init_impl) (abstract_sha256_state_t *state)
 The APIs that are supposed to be implemented by the backend. More...
 
typedef int(* ndn_sha256_update_impl) (abstract_sha256_state_t *state, const uint8_t *data, uint32_t datalen)
 
typedef int(* ndn_sha256_finish_impl) (abstract_sha256_state_t *state, uint8_t *hash_result)
 
typedef struct ndn_sha_backend ndn_sha_backend_t
 The structure to represent the backend implementation. More...
 
typedef struct ndn_sha256_state ndn_sha256_state_t
 The structure to represent the SHA256 hash state. More...
 

Functions

ndn_sha_backend_tndn_sha_get_backend (void)
 
int ndn_sha256_init (ndn_sha256_state_t *state)
 SHA256 initialization procedure. More...
 
int ndn_sha256_update (ndn_sha256_state_t *state, const uint8_t *data, uint32_t datalen)
 
int ndn_sha256_finish (ndn_sha256_state_t *state, uint8_t *hash_result)
 SHA256 final procedure. More...
 
int ndn_sha256 (const uint8_t *data, uint32_t datalen, uint8_t *hash_result)
 SHA256 a series of bytes into the result. More...
 
int ndn_sha256_sign (const uint8_t *input_value, uint32_t input_size, uint8_t *output_value, uint32_t output_max_size, uint32_t *output_used_size)
 Sign a buffer using SHA-256 algorithm. More...
 
int ndn_sha256_verify (const uint8_t *input_value, uint32_t input_size, const uint8_t *sig_value, uint32_t sig_size)
 Verify a SHA-256 signature. More...
 

Typedef Documentation

◆ abstract_sha256_state_t

The opaque abstract SHA256 state struct to be implemented by the backend.

◆ ndn_sha256_finish_impl

typedef int(* ndn_sha256_finish_impl) (abstract_sha256_state_t *state, uint8_t *hash_result)

◆ ndn_sha256_init_impl

typedef int(* ndn_sha256_init_impl) (abstract_sha256_state_t *state)

The APIs that are supposed to be implemented by the backend.

◆ ndn_sha256_state_t

The structure to represent the SHA256 hash state.

◆ ndn_sha256_update_impl

typedef int(* ndn_sha256_update_impl) (abstract_sha256_state_t *state, const uint8_t *data, uint32_t datalen)

◆ ndn_sha_backend_t

The structure to represent the backend implementation.

Function Documentation

◆ ndn_sha256()

int ndn_sha256 ( const uint8_t *  data,
uint32_t  datalen,
uint8_t *  hash_result 
)

SHA256 a series of bytes into the result.

Parameters
data.Input. The input data buffer.
datalen.Input. The length of the input data.
hash_result.Output. Output buffer whose length should be at least 32.
Returns
NDN_SUCCESS (0) if there is no error.

◆ ndn_sha256_finish()

int ndn_sha256_finish ( ndn_sha256_state_t state,
uint8_t *  hash_result 
)

SHA256 final procedure.

Inserts the completed hash computation into digest.

Parameters
hash_result.Output. digest in unsigned eight bit integer.
state.Input. SHA256 state struct.
Returns
NDN_SUCCESS (0) if there is no error.

◆ ndn_sha256_init()

int ndn_sha256_init ( ndn_sha256_state_t state)

SHA256 initialization procedure.

Parameters
state.Input. SHA256 state struct.
Returns
NDN_SUCCESS (0) if there if no error.

◆ ndn_sha256_sign()

int ndn_sha256_sign ( const uint8_t *  input_value,
uint32_t  input_size,
uint8_t *  output_value,
uint32_t  output_max_size,
uint32_t *  output_used_size 
)

Sign a buffer using SHA-256 algorithm.

The memory buffer to hold the signature should not be smaller than 32 bytes.

Parameters
input_value.Input. Buffer prepared to sign.
input_size.Input. Size of input buffer.
output_value.Output. Signature value.
output_max_size.Input. Buffer size of output_value
output_used_size.Output. Size of used output buffer when signing complete.
Returns
NDN_SUCCESS if there is no error.

◆ ndn_sha256_update()

int ndn_sha256_update ( ndn_sha256_state_t state,
const uint8_t *  data,
uint32_t  datalen 
)

◆ ndn_sha256_verify()

int ndn_sha256_verify ( const uint8_t *  input_value,
uint32_t  input_size,
const uint8_t *  sig_value,
uint32_t  sig_size 
)

Verify a SHA-256 signature.

Parameters
input_value.Input. SHA-256-signed buffer.
input_size.Input. Size of input buffer.
sig_value.Input. SHA-256 signature value.
sig_size.Input. SHA-256 signature size. Should be 32 bytes.
Returns
NDN_SUCCESS if verification succeeded.

◆ ndn_sha_get_backend()

ndn_sha_backend_t* ndn_sha_get_backend ( void  )