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

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