Zephyr Project API 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches

Crypto Hash APIs. More...

Files

file  hash.h
 Crypto Hash APIs.

Data Structures

struct  hash_ctx
 Structure encoding session parameters. More...
struct  hash_pkt
 Structure encoding IO parameters of a hash operation. More...

Typedefs

typedef int(* hash_op_t) (struct hash_ctx *ctx, struct hash_pkt *pkt, bool finish)
 Perform a hash operation.
typedef void(* hash_completion_cb) (struct hash_pkt *completed, int status)
 Handle completion of an asynchronous hash request.

Enumerations

enum  hash_algo { CRYPTO_HASH_ALGO_SHA224 = 1 , CRYPTO_HASH_ALGO_SHA256 = 2 , CRYPTO_HASH_ALGO_SHA384 = 3 , CRYPTO_HASH_ALGO_SHA512 = 4 }
 Hash algorithms. More...

Functions

static int hash_begin_session (const struct device *dev, struct hash_ctx *ctx, enum hash_algo algo)
 Setup a hash session.
static int hash_free_session (const struct device *dev, struct hash_ctx *ctx)
 Cleanup a hash session.
static int hash_callback_set (const struct device *dev, hash_completion_cb cb)
 Registers an async hash completion callback with the driver.
static int hash_compute (struct hash_ctx *ctx, struct hash_pkt *pkt)
 Perform a cryptographic hash function.
static int hash_update (struct hash_ctx *ctx, struct hash_pkt *pkt)
 Perform a cryptographic multipart hash operation.

Detailed Description

Crypto Hash APIs.

Typedef Documentation

◆ hash_completion_cb

typedef void(* hash_completion_cb) (struct hash_pkt *completed, int status)

#include <hash.h>

Handle completion of an asynchronous hash request.

The application can get the session context from the completed packet's ctx field.

Parameters
completedCompleted hash packet.
statusCompletion status. A value of 0 indicates success and a negative errno code indicates failure.

◆ hash_op_t

typedef int(* hash_op_t) (struct hash_ctx *ctx, struct hash_pkt *pkt, bool finish)

#include <hash.h>

Perform a hash operation.

Parameters
ctxHash session context.
pktPacket containing input and output buffers.
finishFinalize the hash operation when true. Continue a multipart hash operation when false.
Return values
0Operation completed successfully.
-errnoNegative errno code on failure.

Enumeration Type Documentation

◆ hash_algo

enum hash_algo

#include <hash.h>

Hash algorithms.

Enumerator
CRYPTO_HASH_ALGO_SHA224 

SHA-224 algorithm.

CRYPTO_HASH_ALGO_SHA256 

SHA-256 algorithm.

CRYPTO_HASH_ALGO_SHA384 

SHA-384 algorithm.

CRYPTO_HASH_ALGO_SHA512 

SHA-512 algorithm.

Function Documentation

◆ hash_begin_session()

int hash_begin_session ( const struct device * dev,
struct hash_ctx * ctx,
enum hash_algo algo )
inlinestatic

#include <crypto.h>

Setup a hash session.

Initializes one time parameters, like the algorithm which may remain constant for all operations in the session. The state may be cached in hardware and/or driver data state variables.

Parameters
devPointer to the device structure for the driver instance.
ctxPointer to the context structure. Various one time parameters like session capabilities and algorithm are supplied via this structure. The structure documentation specifies which fields are to be populated by the app before making this call.
algoThe hash algorithm to be used in this session. e.g sha256
Returns
0 on success, negative errno code on fail.

◆ hash_callback_set()

int hash_callback_set ( const struct device * dev,
hash_completion_cb cb )
inlinestatic

#include <crypto.h>

Registers an async hash completion callback with the driver.

The application can register an async hash completion callback handler to be invoked by the driver, on completion of a prior request submitted via hash_compute(). Based on crypto device hardware semantics, this is likely to be invoked from an ISR context.

Parameters
devPointer to the device structure for the driver instance.
cbPointer to application callback to be called by the driver.
Returns
0 on success, -ENOTSUP if the driver does not support async op, negative errno code on other error.

◆ hash_compute()

int hash_compute ( struct hash_ctx * ctx,
struct hash_pkt * pkt )
inlinestatic

#include <crypto.h>

Perform a cryptographic hash function.

Parameters
ctxPointer to the hash context of this op.
pktStructure holding the input/output.
Returns
0 on success, negative errno code on fail.

◆ hash_free_session()

int hash_free_session ( const struct device * dev,
struct hash_ctx * ctx )
inlinestatic

#include <crypto.h>

Cleanup a hash session.

Clears the hardware and/or driver state of a session.

See also
hash_begin_session
Parameters
devPointer to the device structure for the driver instance.
ctxPointer to the crypto hash context structure of the session to be freed.
Returns
0 on success, negative errno code on fail.

◆ hash_update()

int hash_update ( struct hash_ctx * ctx,
struct hash_pkt * pkt )
inlinestatic

#include <crypto.h>

Perform a cryptographic multipart hash operation.

This function can be called zero or more times, passing a slice of the data. The hash is calculated using all the given pieces. To calculate the hash call hash_compute().

Parameters
ctxPointer to the hash context of this op.
pktStructure holding the input.
Returns
0 on success, negative errno code on fail.