1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
|
<?xml version='1.0' encoding='iso-8859-1'?>
<!doctype html public '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
<html xmlns='http://www.w3c.org/1999/xhtml' lang='en-us'>
<head>
<title>
SHA256Block.c
</title>
<meta http-equiv='content-type' content='text/html;iso-8859-1'/>
<meta name='generator' content='motley-tools 1.9.4 13:40:33 Feb 18 2015'/>
<meta name='author' content='cmaier@cmassoc.net'/>
<meta name='robots' content='noindex,nofollow'/>
<link href='toolkit.css' rel='stylesheet' type='text/css'/>
</head>
<body>
<div class='headerlink'>
[<a href='SetProperty.c.html' title=' SetProperty.c '>PREV</a>]
[<a href='toolkit.html' title=' Index '>HOME</a>]
[<a href='SHA256.c.html' title=' SHA256.c '>NEXT</a>]
</div>
<pre>
/*====================================================================*
*
* void SHA256Block (struct sha256 * sha256, void const * memory);
*
* SHA256.h
*
* encode a fixed-length block of memory into the hash buffer and
* update the hash state; the length is implicit in the algorithm
* and need not be specified as an argument;
*
* Read standard FIPS180-2 sec 5.3.2 for an explanation;
*
* Motley Tools by Charles Maier <cmaier@cmassoc.net>;
* Copyright (c) 2001-2006 by Charles Maier Associates;
* Licensed under the Internet Software Consortium License;
*
*--------------------------------------------------------------------*/
#ifndef SHA256MERGE_SOURCE
#define SHA256MERGE_SOURCE
#include <stdio.h>
#include "../key/SHA256.h"
#define SHR(word,bits) ((word & 0xFFFFFFFF) >> bits)
#define ROTR(word,bits) (SHR(word,bits) | (word << (32 - bits)))
void SHA256Block (struct sha256 * sha256, void const * memory)
{
static const uint32_t K [sizeof (sha256->block)] =
{
0x428A2F98,
0x71374491,
0xB5C0FBCF,
0xE9B5DBA5,
0x3956C25B,
0x59F111F1,
0x923F82A4,
0xAB1C5ED5,
0xD807AA98,
0x12835B01,
0x243185BE,
0x550C7DC3,
0x72BE5D74,
0x80DEB1FE,
0x9BDC06A7,
0xC19BF174,
0xE49B69C1,
0xEFBE4786,
0x0FC19DC6,
0x240CA1CC,
0x2DE92C6F,
0x4A7484AA,
0x5CB0A9DC,
0x76F988DA,
0x983E5152,
0xA831C66D,
0xB00327C8,
0xBF597FC7,
0xC6E00BF3,
0xD5A79147,
0x06CA6351,
0x14292967,
0x27B70A85,
0x2E1B2138,
0x4D2C6DFC,
0x53380D13,
0x650A7354,
0x766A0ABB,
0x81C2C92E,
0x92722C85,
0xA2BFE8A1,
0xA81A664B,
0xC24B8B70,
0xC76C51A3,
0xD192E819,
0xD6990624,
0xF40E3585,
0x106AA070,
0x19A4C116,
0x1E376C08,
0x2748774C,
0x34B0BCB5,
0x391C0CB3,
0x4ED8AA4A,
0x5B9CCA4F,
0x682E6FF3,
0x748F82EE,
0x78A5636F,
0x84C87814,
0x8CC70208,
0x90BEFFFA,
0xA4506CEB,
0xBEF9A3F7,
0xC67178F2
};
unsigned pass;
unsigned word;
uint32_t H [sizeof (sha256->state)/sizeof (uint32_t)];
uint32_t W [sizeof (sha256->block)];
uint8_t * buffer = (uint8_t *)(memory);
for (word = 0; word < 16; word++)
{
W [word] = 0;
W [word] |= (uint32_t)(*buffer++) << 24;
W [word] |= (uint32_t)(*buffer++) << 16;
W [word] |= (uint32_t)(*buffer++) << 8;
W [word] |= (uint32_t)(*buffer++) << 0;;
}
for ( ; word < sizeof (sha256->block); word++)
{
uint32_t s0 = ROTR (W [word-15], 7) ^ ROTR (W [word-15], 18) ^ SHR (W [word-15], 3);
uint32_t s1 = ROTR (W [word- 2], 17) ^ ROTR (W [word- 2], 19) ^ SHR (W [word- 2], 10);
W [word] = W [word - 16] + s0 + W [word - 7] + s1;
}
for (word = 0; word < (sizeof (sha256->state) / sizeof (uint32_t)); word++)
{
H [word] = sha256->state [word];
}
for (pass = 0; pass < sizeof (sha256->block); pass++)
{
uint32_t s2 = ROTR (H [0], 2) ^ ROTR (H [0], 13) ^ ROTR (H [0], 22);
uint32_t maj = (H [0] & H [1]) ^ (H [0] & H [2]) ^ (H [1] & H [2]);
uint32_t t2 = s2 + maj;
uint32_t s3 = ROTR (H [4], 6) ^ ROTR (H [4], 11) ^ ROTR (H [4], 25);
uint32_t ch = (H [4] & H [5]) ^ ((~ H [4]) & H [6]);
uint32_t t1 = H [7] + s3 + ch + K [pass] + W [pass];
for (word = (sizeof (sha256->state) / sizeof (uint32_t)) - 1; word > 0; word--)
{
H [word] = H [word-1];
}
H [0] = t1 + t2;
H [4] += t1;
}
for (word = 0; word < (sizeof (sha256->state) / sizeof (uint32_t)); word++)
{
sha256->state [word] += H [word];
}
return;
}
#endif
</pre>
<div class='footerlink'>
[<a href='SetProperty.c.html' title=' SetProperty.c '>PREV</a>]
[<a href='toolkit.html' title=' Index '>HOME</a>]
[<a href='SHA256.c.html' title=' SHA256.c '>NEXT</a>]
</div>
</body>
</html>
|