Blame SOURCES/0023-semodule-libsemanage-move-module-hashing-into-libsem.patch

8db498
From 7809f29b68e17a455478990ae9b22728381a126b Mon Sep 17 00:00:00 2001
8db498
From: Ondrej Mosnacek <omosnace@redhat.com>
8db498
Date: Thu, 3 Feb 2022 17:53:23 +0100
8db498
Subject: [PATCH] semodule,libsemanage: move module hashing into libsemanage
8db498
8db498
The main goal of this move is to have the SHA-256 implementation under
8db498
libsemanage, since upcoming patches will make use of SHA-256 for a
8db498
different (but similar) purpose in libsemanage. Having the hashing code
8db498
in libsemanage will reduce code duplication and allow for easier hash
8db498
algorithm upgrade in the future.
8db498
8db498
Note that libselinux currently also contains a hash function
8db498
implementation (for yet another different purpose). This patch doesn't
8db498
make any effort to address that duplicity yet.
8db498
8db498
This patch also changes the format of the hash string printed by
8db498
semodule to include the name of the hash. The intent is to avoid
8db498
ambiguity and potential collisions when the algorithm is potentially
8db498
changed in the future.
8db498
8db498
Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com>
8db498
---
8db498
 policycoreutils/semodule/Makefile   |   2 +-
8db498
 policycoreutils/semodule/semodule.c |  53 ++---
8db498
 policycoreutils/semodule/sha256.c   | 294 ----------------------------
8db498
 policycoreutils/semodule/sha256.h   |  89 ---------
8db498
 4 files changed, 17 insertions(+), 421 deletions(-)
8db498
 delete mode 100644 policycoreutils/semodule/sha256.c
8db498
 delete mode 100644 policycoreutils/semodule/sha256.h
8db498
8db498
diff --git a/policycoreutils/semodule/Makefile b/policycoreutils/semodule/Makefile
8db498
index 9875ac383280..73801e487a76 100644
8db498
--- a/policycoreutils/semodule/Makefile
8db498
+++ b/policycoreutils/semodule/Makefile
8db498
@@ -6,7 +6,7 @@ MANDIR = $(PREFIX)/share/man
8db498
 
8db498
 CFLAGS ?= -Werror -Wall -W
8db498
 override LDLIBS += -lsepol -lselinux -lsemanage
8db498
-SEMODULE_OBJS = semodule.o sha256.o
8db498
+SEMODULE_OBJS = semodule.o
8db498
 
8db498
 all: semodule genhomedircon
8db498
 
8db498
diff --git a/policycoreutils/semodule/semodule.c b/policycoreutils/semodule/semodule.c
8db498
index 94a9d131bb79..f4a76289efa3 100644
8db498
--- a/policycoreutils/semodule/semodule.c
8db498
+++ b/policycoreutils/semodule/semodule.c
8db498
@@ -25,8 +25,6 @@
8db498
 #include <sepol/cil/cil.h>
8db498
 #include <semanage/modules.h>
8db498
 
8db498
-#include "sha256.h"
8db498
-
8db498
 enum client_modes {
8db498
 	NO_MODE, INSTALL_M, REMOVE_M, EXTRACT_M, CIL_M, HLL_M,
8db498
 	LIST_M, RELOAD, PRIORITY_M, ENABLE_M, DISABLE_M
8db498
@@ -348,60 +346,38 @@ static void parse_command_line(int argc, char **argv)
8db498
 
8db498
 /* Get module checksum */
8db498
 static char *hash_module_data(const char *module_name, const int prio) {
8db498
-	semanage_module_info_t *extract_info = NULL;
8db498
 	semanage_module_key_t *modkey = NULL;
8db498
-	Sha256Context context;
8db498
-	uint8_t sha256_hash[SHA256_HASH_SIZE];
8db498
-	char *sha256_buf = NULL;
8db498
-	void *data;
8db498
-	size_t data_len = 0, i;
8db498
+	char *hash_str = NULL;
8db498
+	void *hash = NULL;
8db498
+	size_t hash_len = 0;
8db498
 	int result;
8db498
 
8db498
 	result = semanage_module_key_create(sh, &modkey);
8db498
 	if (result != 0) {
8db498
-		goto cleanup_extract;
8db498
+		goto cleanup;
8db498
 	}
8db498
 
8db498
 	result = semanage_module_key_set_name(sh, modkey, module_name);
8db498
 	if (result != 0) {
8db498
-		goto cleanup_extract;
8db498
+		goto cleanup;
8db498
 	}
8db498
 
8db498
 	result = semanage_module_key_set_priority(sh, modkey, prio);
8db498
 	if (result != 0) {
8db498
-		goto cleanup_extract;
8db498
+		goto cleanup;
8db498
 	}
8db498
 
8db498
-	result = semanage_module_extract(sh, modkey, 1, &data, &data_len,
8db498
-									 &extract_info);
8db498
+	result = semanage_module_compute_checksum(sh, modkey, 1, &hash_str,
8db498
+						  &hash_len);
8db498
 	if (result != 0) {
8db498
-		goto cleanup_extract;
8db498
-	}
8db498
-
8db498
-	Sha256Initialise(&context);
8db498
-	Sha256Update(&context, data, data_len);
8db498
-
8db498
-	Sha256Finalise(&context, (SHA256_HASH *)sha256_hash);
8db498
-
8db498
-	sha256_buf = calloc(1, SHA256_HASH_SIZE * 2 + 1);
8db498
-
8db498
-	if (sha256_buf == NULL)
8db498
-		goto cleanup_extract;
8db498
-
8db498
-	for (i = 0; i < SHA256_HASH_SIZE; i++) {
8db498
-		sprintf((&sha256_buf[i * 2]), "%02x", sha256_hash[i]);
8db498
+		goto cleanup;
8db498
 	}
8db498
-	sha256_buf[i * 2] = 0;
8db498
 
8db498
-cleanup_extract:
8db498
-	if (data_len > 0) {
8db498
-		munmap(data, data_len);
8db498
-	}
8db498
-	semanage_module_info_destroy(sh, extract_info);
8db498
-	free(extract_info);
8db498
+cleanup:
8db498
+	free(hash);
8db498
 	semanage_module_key_destroy(sh, modkey);
8db498
 	free(modkey);
8db498
-	return sha256_buf;
8db498
+	return hash_str;
8db498
 }
8db498
 
8db498
 int main(int argc, char *argv[])
8db498
@@ -669,7 +645,10 @@ cleanup_extract:
8db498
 					/* fixed width columns */
8db498
 					column[0] = sizeof("000") - 1;
8db498
 					column[3] = sizeof("disabled") - 1;
8db498
-					column[4] = 64; /* SHA256_HASH_SIZE * 2 */
8db498
+
8db498
+					result = semanage_module_compute_checksum(sh, NULL, 0, NULL,
8db498
+										  &column[4]);
8db498
+					if (result != 0) goto cleanup_list;
8db498
 
8db498
 					/* variable width columns */
8db498
 					const char *tmp = NULL;
8db498
diff --git a/policycoreutils/semodule/sha256.c b/policycoreutils/semodule/sha256.c
8db498
deleted file mode 100644
8db498
index fe2aeef07f53..000000000000
8db498
--- a/policycoreutils/semodule/sha256.c
8db498
+++ /dev/null
8db498
@@ -1,294 +0,0 @@
8db498
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
8db498
-//  WjCryptLib_Sha256
8db498
-//
8db498
-//  Implementation of SHA256 hash function.
8db498
-//  Original author: Tom St Denis, tomstdenis@gmail.com, http://libtom.org
8db498
-//  Modified by WaterJuice retaining Public Domain license.
8db498
-//
8db498
-//  This is free and unencumbered software released into the public domain - June 2013 waterjuice.org
8db498
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
8db498
-
8db498
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
8db498
-//  IMPORTS
8db498
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
8db498
-
8db498
-#include "sha256.h"
8db498
-#include <memory.h>
8db498
-
8db498
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
8db498
-//  MACROS
8db498
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
8db498
-
8db498
-#define ror(value, bits) (((value) >> (bits)) | ((value) << (32 - (bits))))
8db498
-
8db498
-#define MIN(x, y) ( ((x)<(y))?(x):(y) )
8db498
-
8db498
-#define STORE32H(x, y)                                                                     \
8db498
-     { (y)[0] = (uint8_t)(((x)>>24)&255); (y)[1] = (uint8_t)(((x)>>16)&255);   \
8db498
-       (y)[2] = (uint8_t)(((x)>>8)&255); (y)[3] = (uint8_t)((x)&255); }
8db498
-
8db498
-#define LOAD32H(x, y)                            \
8db498
-     { x = ((uint32_t)((y)[0] & 255)<<24) | \
8db498
-           ((uint32_t)((y)[1] & 255)<<16) | \
8db498
-           ((uint32_t)((y)[2] & 255)<<8)  | \
8db498
-           ((uint32_t)((y)[3] & 255)); }
8db498
-
8db498
-#define STORE64H(x, y)                                                                     \
8db498
-   { (y)[0] = (uint8_t)(((x)>>56)&255); (y)[1] = (uint8_t)(((x)>>48)&255);     \
8db498
-     (y)[2] = (uint8_t)(((x)>>40)&255); (y)[3] = (uint8_t)(((x)>>32)&255);     \
8db498
-     (y)[4] = (uint8_t)(((x)>>24)&255); (y)[5] = (uint8_t)(((x)>>16)&255);     \
8db498
-     (y)[6] = (uint8_t)(((x)>>8)&255); (y)[7] = (uint8_t)((x)&255); }
8db498
-
8db498
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
8db498
-//  CONSTANTS
8db498
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
8db498
-
8db498
-// The K array
8db498
-static const uint32_t K[64] = {
8db498
-    0x428a2f98UL, 0x71374491UL, 0xb5c0fbcfUL, 0xe9b5dba5UL, 0x3956c25bUL,
8db498
-    0x59f111f1UL, 0x923f82a4UL, 0xab1c5ed5UL, 0xd807aa98UL, 0x12835b01UL,
8db498
-    0x243185beUL, 0x550c7dc3UL, 0x72be5d74UL, 0x80deb1feUL, 0x9bdc06a7UL,
8db498
-    0xc19bf174UL, 0xe49b69c1UL, 0xefbe4786UL, 0x0fc19dc6UL, 0x240ca1ccUL,
8db498
-    0x2de92c6fUL, 0x4a7484aaUL, 0x5cb0a9dcUL, 0x76f988daUL, 0x983e5152UL,
8db498
-    0xa831c66dUL, 0xb00327c8UL, 0xbf597fc7UL, 0xc6e00bf3UL, 0xd5a79147UL,
8db498
-    0x06ca6351UL, 0x14292967UL, 0x27b70a85UL, 0x2e1b2138UL, 0x4d2c6dfcUL,
8db498
-    0x53380d13UL, 0x650a7354UL, 0x766a0abbUL, 0x81c2c92eUL, 0x92722c85UL,
8db498
-    0xa2bfe8a1UL, 0xa81a664bUL, 0xc24b8b70UL, 0xc76c51a3UL, 0xd192e819UL,
8db498
-    0xd6990624UL, 0xf40e3585UL, 0x106aa070UL, 0x19a4c116UL, 0x1e376c08UL,
8db498
-    0x2748774cUL, 0x34b0bcb5UL, 0x391c0cb3UL, 0x4ed8aa4aUL, 0x5b9cca4fUL,
8db498
-    0x682e6ff3UL, 0x748f82eeUL, 0x78a5636fUL, 0x84c87814UL, 0x8cc70208UL,
8db498
-    0x90befffaUL, 0xa4506cebUL, 0xbef9a3f7UL, 0xc67178f2UL
8db498
-};
8db498
-
8db498
-#define BLOCK_SIZE          64
8db498
-
8db498
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
8db498
-//  INTERNAL FUNCTIONS
8db498
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
8db498
-
8db498
-// Various logical functions
8db498
-#define Ch( x, y, z )     (z ^ (x & (y ^ z)))
8db498
-#define Maj( x, y, z )    (((x | y) & z) | (x & y))
8db498
-#define S( x, n )         ror((x),(n))
8db498
-#define R( x, n )         (((x)&0xFFFFFFFFUL)>>(n))
8db498
-#define Sigma0( x )       (S(x, 2) ^ S(x, 13) ^ S(x, 22))
8db498
-#define Sigma1( x )       (S(x, 6) ^ S(x, 11) ^ S(x, 25))
8db498
-#define Gamma0( x )       (S(x, 7) ^ S(x, 18) ^ R(x, 3))
8db498
-#define Gamma1( x )       (S(x, 17) ^ S(x, 19) ^ R(x, 10))
8db498
-
8db498
-#define Sha256Round( a, b, c, d, e, f, g, h, i )       \
8db498
-     t0 = h + Sigma1(e) + Ch(e, f, g) + K[i] + W[i];   \
8db498
-     t1 = Sigma0(a) + Maj(a, b, c);                    \
8db498
-     d += t0;                                          \
8db498
-     h  = t0 + t1;
8db498
-
8db498
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
8db498
-//  TransformFunction
8db498
-//
8db498
-//  Compress 512-bits
8db498
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
8db498
-static
8db498
-void
8db498
-    TransformFunction
8db498
-    (
8db498
-        Sha256Context*      Context,
8db498
-        uint8_t const*      Buffer
8db498
-    )
8db498
-{
8db498
-    uint32_t    S[8];
8db498
-    uint32_t    W[64];
8db498
-    uint32_t    t0;
8db498
-    uint32_t    t1;
8db498
-    uint32_t    t;
8db498
-    int         i;
8db498
-
8db498
-    // Copy state into S
8db498
-    for( i=0; i<8; i++ )
8db498
-    {
8db498
-        S[i] = Context->state[i];
8db498
-    }
8db498
-
8db498
-    // Copy the state into 512-bits into W[0..15]
8db498
-    for( i=0; i<16; i++ )
8db498
-    {
8db498
-        LOAD32H( W[i], Buffer + (4*i) );
8db498
-    }
8db498
-
8db498
-    // Fill W[16..63]
8db498
-    for( i=16; i<64; i++ )
8db498
-    {
8db498
-        W[i] = Gamma1( W[i-2]) + W[i-7] + Gamma0( W[i-15] ) + W[i-16];
8db498
-    }
8db498
-
8db498
-    // Compress
8db498
-    for( i=0; i<64; i++ )
8db498
-    {
8db498
-        Sha256Round( S[0], S[1], S[2], S[3], S[4], S[5], S[6], S[7], i );
8db498
-        t = S[7];
8db498
-        S[7] = S[6];
8db498
-        S[6] = S[5];
8db498
-        S[5] = S[4];
8db498
-        S[4] = S[3];
8db498
-        S[3] = S[2];
8db498
-        S[2] = S[1];
8db498
-        S[1] = S[0];
8db498
-        S[0] = t;
8db498
-    }
8db498
-
8db498
-    // Feedback
8db498
-    for( i=0; i<8; i++ )
8db498
-    {
8db498
-        Context->state[i] = Context->state[i] + S[i];
8db498
-    }
8db498
-}
8db498
-
8db498
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
8db498
-//  PUBLIC FUNCTIONS
8db498
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
8db498
-
8db498
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
8db498
-//  Sha256Initialise
8db498
-//
8db498
-//  Initialises a SHA256 Context. Use this to initialise/reset a context.
8db498
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
8db498
-void
8db498
-    Sha256Initialise
8db498
-    (
8db498
-        Sha256Context*      Context         // [out]
8db498
-    )
8db498
-{
8db498
-    Context->curlen = 0;
8db498
-    Context->length = 0;
8db498
-    Context->state[0] = 0x6A09E667UL;
8db498
-    Context->state[1] = 0xBB67AE85UL;
8db498
-    Context->state[2] = 0x3C6EF372UL;
8db498
-    Context->state[3] = 0xA54FF53AUL;
8db498
-    Context->state[4] = 0x510E527FUL;
8db498
-    Context->state[5] = 0x9B05688CUL;
8db498
-    Context->state[6] = 0x1F83D9ABUL;
8db498
-    Context->state[7] = 0x5BE0CD19UL;
8db498
-}
8db498
-
8db498
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
8db498
-//  Sha256Update
8db498
-//
8db498
-//  Adds data to the SHA256 context. This will process the data and update the internal state of the context. Keep on
8db498
-//  calling this function until all the data has been added. Then call Sha256Finalise to calculate the hash.
8db498
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
8db498
-void
8db498
-    Sha256Update
8db498
-    (
8db498
-        Sha256Context*      Context,        // [in out]
8db498
-        void const*         Buffer,         // [in]
8db498
-        uint32_t            BufferSize      // [in]
8db498
-    )
8db498
-{
8db498
-    uint32_t n;
8db498
-
8db498
-    if( Context->curlen > sizeof(Context->buf) )
8db498
-    {
8db498
-       return;
8db498
-    }
8db498
-
8db498
-    while( BufferSize > 0 )
8db498
-    {
8db498
-        if( Context->curlen == 0 && BufferSize >= BLOCK_SIZE )
8db498
-        {
8db498
-           TransformFunction( Context, (uint8_t*)Buffer );
8db498
-           Context->length += BLOCK_SIZE * 8;
8db498
-           Buffer = (uint8_t*)Buffer + BLOCK_SIZE;
8db498
-           BufferSize -= BLOCK_SIZE;
8db498
-        }
8db498
-        else
8db498
-        {
8db498
-           n = MIN( BufferSize, (BLOCK_SIZE - Context->curlen) );
8db498
-           memcpy( Context->buf + Context->curlen, Buffer, (size_t)n );
8db498
-           Context->curlen += n;
8db498
-           Buffer = (uint8_t*)Buffer + n;
8db498
-           BufferSize -= n;
8db498
-           if( Context->curlen == BLOCK_SIZE )
8db498
-           {
8db498
-              TransformFunction( Context, Context->buf );
8db498
-              Context->length += 8*BLOCK_SIZE;
8db498
-              Context->curlen = 0;
8db498
-           }
8db498
-       }
8db498
-    }
8db498
-}
8db498
-
8db498
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
8db498
-//  Sha256Finalise
8db498
-//
8db498
-//  Performs the final calculation of the hash and returns the digest (32 byte buffer containing 256bit hash). After
8db498
-//  calling this, Sha256Initialised must be used to reuse the context.
8db498
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
8db498
-void
8db498
-    Sha256Finalise
8db498
-    (
8db498
-        Sha256Context*      Context,        // [in out]
8db498
-        SHA256_HASH*        Digest          // [out]
8db498
-    )
8db498
-{
8db498
-    int i;
8db498
-
8db498
-    if( Context->curlen >= sizeof(Context->buf) )
8db498
-    {
8db498
-       return;
8db498
-    }
8db498
-
8db498
-    // Increase the length of the message
8db498
-    Context->length += Context->curlen * 8;
8db498
-
8db498
-    // Append the '1' bit
8db498
-    Context->buf[Context->curlen++] = (uint8_t)0x80;
8db498
-
8db498
-    // if the length is currently above 56 bytes we append zeros
8db498
-    // then compress.  Then we can fall back to padding zeros and length
8db498
-    // encoding like normal.
8db498
-    if( Context->curlen > 56 )
8db498
-    {
8db498
-        while( Context->curlen < 64 )
8db498
-        {
8db498
-            Context->buf[Context->curlen++] = (uint8_t)0;
8db498
-        }
8db498
-        TransformFunction(Context, Context->buf);
8db498
-        Context->curlen = 0;
8db498
-    }
8db498
-
8db498
-    // Pad up to 56 bytes of zeroes
8db498
-    while( Context->curlen < 56 )
8db498
-    {
8db498
-        Context->buf[Context->curlen++] = (uint8_t)0;
8db498
-    }
8db498
-
8db498
-    // Store length
8db498
-    STORE64H( Context->length, Context->buf+56 );
8db498
-    TransformFunction( Context, Context->buf );
8db498
-
8db498
-    // Copy output
8db498
-    for( i=0; i<8; i++ )
8db498
-    {
8db498
-        STORE32H( Context->state[i], Digest->bytes+(4*i) );
8db498
-    }
8db498
-}
8db498
-
8db498
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
8db498
-//  Sha256Calculate
8db498
-//
8db498
-//  Combines Sha256Initialise, Sha256Update, and Sha256Finalise into one function. Calculates the SHA256 hash of the
8db498
-//  buffer.
8db498
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
8db498
-void
8db498
-    Sha256Calculate
8db498
-    (
8db498
-        void  const*        Buffer,         // [in]
8db498
-        uint32_t            BufferSize,     // [in]
8db498
-        SHA256_HASH*        Digest          // [in]
8db498
-    )
8db498
-{
8db498
-    Sha256Context context;
8db498
-
8db498
-    Sha256Initialise( &context );
8db498
-    Sha256Update( &context, Buffer, BufferSize );
8db498
-    Sha256Finalise( &context, Digest );
8db498
-}
8db498
diff --git a/policycoreutils/semodule/sha256.h b/policycoreutils/semodule/sha256.h
8db498
deleted file mode 100644
8db498
index 406ed869cd82..000000000000
8db498
--- a/policycoreutils/semodule/sha256.h
8db498
+++ /dev/null
8db498
@@ -1,89 +0,0 @@
8db498
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
8db498
-//  WjCryptLib_Sha256
8db498
-//
8db498
-//  Implementation of SHA256 hash function.
8db498
-//  Original author: Tom St Denis, tomstdenis@gmail.com, http://libtom.org
8db498
-//  Modified by WaterJuice retaining Public Domain license.
8db498
-//
8db498
-//  This is free and unencumbered software released into the public domain - June 2013 waterjuice.org
8db498
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
8db498
-
8db498
-#pragma once
8db498
-
8db498
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
8db498
-//  IMPORTS
8db498
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
8db498
-
8db498
-#include <stdint.h>
8db498
-#include <stdio.h>
8db498
-
8db498
-typedef struct
8db498
-{
8db498
-    uint64_t    length;
8db498
-    uint32_t    state[8];
8db498
-    uint32_t    curlen;
8db498
-    uint8_t     buf[64];
8db498
-} Sha256Context;
8db498
-
8db498
-#define SHA256_HASH_SIZE           ( 256 / 8 )
8db498
-
8db498
-typedef struct
8db498
-{
8db498
-    uint8_t      bytes [SHA256_HASH_SIZE];
8db498
-} SHA256_HASH;
8db498
-
8db498
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
8db498
-//  PUBLIC FUNCTIONS
8db498
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
8db498
-
8db498
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
8db498
-//  Sha256Initialise
8db498
-//
8db498
-//  Initialises a SHA256 Context. Use this to initialise/reset a context.
8db498
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
8db498
-void
8db498
-    Sha256Initialise
8db498
-    (
8db498
-        Sha256Context*      Context         // [out]
8db498
-    );
8db498
-
8db498
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
8db498
-//  Sha256Update
8db498
-//
8db498
-//  Adds data to the SHA256 context. This will process the data and update the internal state of the context. Keep on
8db498
-//  calling this function until all the data has been added. Then call Sha256Finalise to calculate the hash.
8db498
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
8db498
-void
8db498
-    Sha256Update
8db498
-    (
8db498
-        Sha256Context*      Context,        // [in out]
8db498
-        void const*         Buffer,         // [in]
8db498
-        uint32_t            BufferSize      // [in]
8db498
-    );
8db498
-
8db498
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
8db498
-//  Sha256Finalise
8db498
-//
8db498
-//  Performs the final calculation of the hash and returns the digest (32 byte buffer containing 256bit hash). After
8db498
-//  calling this, Sha256Initialised must be used to reuse the context.
8db498
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
8db498
-void
8db498
-    Sha256Finalise
8db498
-    (
8db498
-        Sha256Context*      Context,        // [in out]
8db498
-        SHA256_HASH*        Digest          // [out]
8db498
-    );
8db498
-
8db498
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
8db498
-//  Sha256Calculate
8db498
-//
8db498
-//  Combines Sha256Initialise, Sha256Update, and Sha256Finalise into one function. Calculates the SHA256 hash of the
8db498
-//  buffer.
8db498
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
8db498
-void
8db498
-    Sha256Calculate
8db498
-    (
8db498
-        void  const*        Buffer,         // [in]
8db498
-        uint32_t            BufferSize,     // [in]
8db498
-        SHA256_HASH*        Digest          // [in]
8db498
-    );
8db498
-- 
8db498
2.34.1
8db498