Ordo  0.3.4
Symmetric Cryptography Library
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
Macros | Functions
digest.h File Reference

Module. More...

#include "ordo/primitives/hash_functions.h"
Include dependency graph for digest.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define ordo_digest_init
 
#define ordo_digest_update
 
#define ordo_digest_final
 
#define ordo_digest_bsize
 

Functions

ORDO_PUBLIC size_t digest_length (prim_t hash)
 

Detailed Description

Module.

Module to compute cryptographic digests, using cryptographic hash function primitives.

The advantage of using this digest module instead of the hash function abstraction layer is this keeps track of the hash function primitive for you within an opaque DIGEST_CTX context structure, simplifying code and making it less error-prone.

Usage snippet:

struct DIGEST_CTX ctx;
int err = digest_init(&ctx, HASH_SHA256, 0);
if (err) printf("Got error!\n");
const char x[] = "Hello, world!";
digest_update(&ctx, x, strlen(x));
unsigned char out[32];
digest_final(&ctx, out);
// out = 315f5bdb76d0...

Macro Definition Documentation

#define ordo_digest_init

Initializes a digest context.

Parameters
[in,out]ctxA digest context.
[in]primitiveA hash function primitive.
[in]paramsHash function parameters.
Returns
ORDO_SUCCESS on success, else an error code.
Remarks
It is always valid to pass 0 into params if you don't want to use special features offered by a specific hash function.
Warning
It is not valid to initialize digest contexts more than once before calling digest_final(), this is because some algorithms may allocate additional memory depending on the parameters given.
#define ordo_digest_update

Feeds data into a digest context.

Parameters
[in,out]ctxAn initialized digest context.
[in]inThe data to feed into the context.
[in]in_lenThe length, in bytes, of the data.
Remarks
This function has the same property as hash_update(), in that it will concatenate the input buffers of successive calls.
It is valid to pass a zero-length buffer (in_len == 0), which will do nothing (if this is the case, in may be 0).
#define ordo_digest_final

Finalizes a digest context, returning the digest of all the data fed into it through successive digest_update() calls.

Parameters
[in,out]ctxAn initialized digest context.
[out]digestThe output buffer for the digest.
Remarks
The digest buffer should be large enough to accomodate the digest - you can query the hash function's default digest length in bytes by the digest_length() function.
Calling this function immediately after digest_init() is valid and will return the so-called "zero-length" digest, which is the digest of the input of length zero.
Warning
After this function returns, you may not call digest_update() again until you reinitialize the context using digest_init().
#define ordo_digest_bsize

Gets the size in bytes of a DIGEST_CTX.

Returns
The size in bytes of the structure.
Remarks
Binary compatibility layer.

Function Documentation

ORDO_PUBLIC size_t digest_length ( prim_t  hash)

Returns the default digest length of a hash function.

Parameters
[in]hashA hash function primitive.
Returns
The length of the digest to be written in the digest parameter of digest_final().