sha256.h
author Ryan C. Gordon <icculus@icculus.org>
Sun, 18 Jun 2017 19:50:43 -0400
changeset 57 4974e5368a29
parent 46 fe4f59680246
permissions -rw-r--r--
Minor type cleanup ("unsigned char" -> "uint8_t").
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
46
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     1
/*********************************************************************
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     2
* Filename:   sha256.h
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     3
* Author:     Brad Conte (brad AT bradconte.com)
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     4
* Copyright:
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     5
* Disclaimer: This code is presented "as is" without any guarantees.
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     6
* Details:    Defines the API for the corresponding SHA1 implementation.
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     7
*********************************************************************/
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     8
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     9
#ifndef SHA256_H
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    10
#define SHA256_H
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    11
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    12
/*************************** HEADER FILES ***************************/
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    13
#include <stddef.h>
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    14
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    15
/****************************** MACROS ******************************/
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    16
#define SHA256_BLOCK_SIZE 32            // SHA256 outputs a 32 byte digest
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    17
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    18
/**************************** DATA TYPES ****************************/
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    19
typedef unsigned char BYTE;             // 8-bit byte
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    20
typedef unsigned int  WORD;             // 32-bit word, change to "long" for 16-bit machines
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    21
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    22
typedef struct {
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    23
	BYTE data[64];
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    24
	WORD datalen;
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    25
	unsigned long long bitlen;
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    26
	WORD state[8];
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    27
} SHA256_CTX;
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    28
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    29
/*********************** FUNCTION DECLARATIONS **********************/
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    30
void sha256_init(SHA256_CTX *ctx);
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    31
void sha256_update(SHA256_CTX *ctx, const BYTE data[], size_t len);
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    32
void sha256_final(SHA256_CTX *ctx, BYTE hash[]);
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    33
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    34
#endif   // SHA256_H