Package: LSC.SHA256

Dependencies

with LSC.Types;

use type LSC.Types.Index;
use type LSC.Types.Word32;
use type LSC.Types.Word64;

Description

The SHA-256 hash algorithm

Header

package LSC.SHA256 is
 

Known child units

LSC.SHA256.Tables(private package)

Type Summary

Context_Type
Primitive Operations:  Context_Finalize, Context_Update, SHA256_Context_Init, SHA256_Get_Hash
Message_Type

Constants and Named Numbers

Block_Size : constant := 512;
SHA-256 block size
Null_Block : constant Block_Type;
Empty block
SHA256_Null_Hash : constant SHA256_Hash_Type;
Empty Hash

Other Items:

type Context_Type is private;
SHA-256 context

subtype Block_Index is Types.Index range 0 .. 15;
Index for SHA-256 block

subtype Block_Type is Types.Word32_Array_Type (Block_Index);
SHA-256 block

subtype SHA256_Hash_Index is Types.Index range 0 .. 7;
Index for SHA-256 hash

subtype SHA256_Hash_Type is Types.Word32_Array_Type (SHA256_Hash_Index);
SHA-256 hash

subtype Block_Length_Type is Types.Word32 range 0 .. Block_Size - 1;
SHA-256 block length

subtype Message_Index is Types.Word64 range 0 .. 2 ** 53 - 1;
Index for SHA-256 message

A SHA-256 message can be at most 2^64 bit long. As one block has 511 bit, this makes 2^53 blocks.


type Message_Type is array (Message_Index range <>) of Block_Type;
SHA-256 message

function SHA256_Context_Init return Context_Type;
Initialize SHA-256 context.

procedure Context_Update
  (Context : in out Context_Type;
   Block   : in     Block_Type);
pragma Inline (Context_Update);
Update SHA-256 Context with message block Block.
 derives Context from *,
                      Block;

procedure Context_Finalize
  (Context : in out Context_Type;
   Block   : in     Block_Type;
   Length  : in     Block_Length_Type);
Finalize SHA-256 Context using Length bits of final message block Block.
 derives Context from *,
                      Block,
                      Length;

function SHA256_Get_Hash (Context : Context_Type) return SHA256_Hash_Type;
Return SHA-256 hash from Context.

private

   --  Implementation-defined ...
end LSC.SHA256;