2019-01-15 14:35:25 +00:00
|
|
|
#ifndef SHA2_H
|
|
|
|
#define SHA2_H
|
|
|
|
|
2019-03-11 13:41:11 +00:00
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
2019-03-13 16:23:30 +00:00
|
|
|
/* The incremental API allows hashing of individual input blocks; these blocks
|
|
|
|
must be exactly 64 bytes each.
|
|
|
|
Use the 'finalize' functions for any remaining bytes (possibly over 64). */
|
|
|
|
|
2019-12-12 13:29:29 +00:00
|
|
|
/* Structure for the incremental API */
|
2019-05-20 08:20:12 +01:00
|
|
|
typedef struct {
|
|
|
|
uint8_t ctx[40];
|
|
|
|
} sha224ctx;
|
|
|
|
|
2019-12-12 13:29:29 +00:00
|
|
|
/* Structure for the incremental API */
|
2019-05-20 08:20:12 +01:00
|
|
|
typedef struct {
|
|
|
|
uint8_t ctx[40];
|
|
|
|
} sha256ctx;
|
|
|
|
|
2019-12-12 13:29:29 +00:00
|
|
|
/* Structure for the incremental API */
|
2019-05-20 08:20:12 +01:00
|
|
|
typedef struct {
|
|
|
|
uint8_t ctx[72];
|
|
|
|
} sha384ctx;
|
|
|
|
|
2019-12-12 13:29:29 +00:00
|
|
|
/* Structure for the incremental API */
|
2019-05-20 08:20:12 +01:00
|
|
|
typedef struct {
|
|
|
|
uint8_t ctx[72];
|
|
|
|
} sha512ctx;
|
|
|
|
|
2019-12-12 13:29:29 +00:00
|
|
|
/* ====== SHA224 API ==== */
|
|
|
|
/**
|
|
|
|
* Initialize the incremental hashing API
|
|
|
|
*/
|
2019-05-20 08:20:12 +01:00
|
|
|
void sha224_inc_init(sha224ctx *state);
|
2019-12-12 13:29:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Copy the hashing state
|
|
|
|
*/
|
2019-07-30 18:25:23 +01:00
|
|
|
void sha224_inc_clone_state(sha224ctx *stateout, const sha224ctx *statein);
|
2019-12-12 13:29:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Absorb blocks
|
|
|
|
*/
|
2019-05-20 08:20:12 +01:00
|
|
|
void sha224_inc_blocks(sha224ctx *state, const uint8_t *in, size_t inblocks);
|
2019-12-12 13:29:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Finalize and obtain the digest
|
|
|
|
*
|
|
|
|
* If applicable, this function will free the memory associated with the sha224ctx.
|
|
|
|
*/
|
2019-05-20 08:20:12 +01:00
|
|
|
void sha224_inc_finalize(uint8_t *out, sha224ctx *state, const uint8_t *in, size_t inlen);
|
2019-12-12 13:29:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Destroy the state. Make sure to use this, as this API may not always be stack-based.
|
|
|
|
*/
|
|
|
|
void sha224_inc_destroy(sha224ctx *state);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* All-in-one sha224 function
|
|
|
|
*/
|
2019-03-11 15:48:29 +00:00
|
|
|
void sha224(uint8_t *out, const uint8_t *in, size_t inlen);
|
|
|
|
|
2019-12-12 13:29:29 +00:00
|
|
|
/* ====== SHA256 API ==== */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize the incremental hashing API
|
|
|
|
*/
|
2019-05-20 08:20:12 +01:00
|
|
|
void sha256_inc_init(sha256ctx *state);
|
2019-12-12 13:29:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Copy the hashing state
|
|
|
|
*/
|
2019-07-30 18:23:22 +01:00
|
|
|
void sha256_inc_clone_state(sha256ctx *stateout, const sha256ctx *statein);
|
2019-12-12 13:29:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Absorb blocks
|
|
|
|
*/
|
2019-05-20 08:20:12 +01:00
|
|
|
void sha256_inc_blocks(sha256ctx *state, const uint8_t *in, size_t inblocks);
|
2019-12-12 13:29:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Finalize and obtain the digest
|
|
|
|
*
|
|
|
|
* If applicable, this function will free the memory associated with the sha256ctx.
|
|
|
|
*/
|
2019-05-20 08:20:12 +01:00
|
|
|
void sha256_inc_finalize(uint8_t *out, sha256ctx *state, const uint8_t *in, size_t inlen);
|
2019-12-12 13:29:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Destroy the state. Make sure to use this, as this API may not always be stack-based.
|
|
|
|
*/
|
|
|
|
void sha256_inc_destroy(sha256ctx *state);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* All-in-one sha256 function
|
|
|
|
*/
|
2019-03-11 15:33:47 +00:00
|
|
|
void sha256(uint8_t *out, const uint8_t *in, size_t inlen);
|
2019-03-11 13:41:11 +00:00
|
|
|
|
2019-12-12 13:29:29 +00:00
|
|
|
/* ====== SHA384 API ==== */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize the incremental hashing API
|
|
|
|
*/
|
2019-05-20 08:20:12 +01:00
|
|
|
void sha384_inc_init(sha384ctx *state);
|
2019-12-12 13:29:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Copy the hashing state
|
|
|
|
*/
|
2019-07-30 18:25:23 +01:00
|
|
|
void sha384_inc_clone_state(sha384ctx *stateout, const sha384ctx *statein);
|
2019-12-12 13:29:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Absorb blocks
|
|
|
|
*/
|
2019-05-20 08:20:12 +01:00
|
|
|
void sha384_inc_blocks(sha384ctx *state, const uint8_t *in, size_t inblocks);
|
2019-12-12 13:29:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Finalize and obtain the digest.
|
|
|
|
*
|
|
|
|
* If applicable, this function will free the memory associated with the sha384ctx.
|
|
|
|
*/
|
2019-05-20 08:20:12 +01:00
|
|
|
void sha384_inc_finalize(uint8_t *out, sha384ctx *state, const uint8_t *in, size_t inlen);
|
2019-12-12 13:29:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Destroy the state. Make sure to use this, as this API may not always be stack-based.
|
|
|
|
*/
|
|
|
|
void sha384_inc_destroy(sha384ctx *state);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* All-in-one sha384 function
|
|
|
|
*/
|
2019-03-11 15:33:47 +00:00
|
|
|
void sha384(uint8_t *out, const uint8_t *in, size_t inlen);
|
2019-03-11 13:41:11 +00:00
|
|
|
|
2019-12-12 13:29:29 +00:00
|
|
|
|
|
|
|
/* ====== SHA512 API ==== */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize the incremental hashing API
|
|
|
|
*/
|
2019-05-20 08:20:12 +01:00
|
|
|
void sha512_inc_init(sha512ctx *state);
|
2019-12-12 13:29:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Copy the hashing state
|
|
|
|
*/
|
2019-07-30 18:25:23 +01:00
|
|
|
void sha512_inc_clone_state(sha512ctx *stateout, const sha512ctx *statein);
|
2019-12-12 13:29:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Absorb blocks
|
|
|
|
*/
|
2019-05-20 08:20:12 +01:00
|
|
|
void sha512_inc_blocks(sha512ctx *state, const uint8_t *in, size_t inblocks);
|
2019-12-12 13:29:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Finalize and obtain the digest
|
|
|
|
*
|
|
|
|
* If applicable, this function will free the memory associated with the sha512ctx.
|
|
|
|
*/
|
2019-05-20 08:20:12 +01:00
|
|
|
void sha512_inc_finalize(uint8_t *out, sha512ctx *state, const uint8_t *in, size_t inlen);
|
2019-12-12 13:29:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Destroy the state. Make sure to use this, as this API may not always be stack-based.
|
|
|
|
*/
|
|
|
|
void sha512_inc_destroy(sha512ctx *state);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* All-in-one sha512 function
|
|
|
|
*/
|
2019-03-11 15:33:47 +00:00
|
|
|
void sha512(uint8_t *out, const uint8_t *in, size_t inlen);
|
2019-01-15 14:35:25 +00:00
|
|
|
|
|
|
|
#endif
|