Shinichi Fuchita / Twitter

Twitter with OAuth Example.\\ see also http://www.soramimi.jp/twicpp/index.html

Dependencies:   mbed HTTPClient NTPClient_NetServices EthernetNetIf

Committer:
soramimi
Date:
Thu Nov 15 00:51:45 2012 +0000
Revision:
1:c3f74457cad4
Twitter API address changed.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
soramimi0:7ddb56bfde0c 1/*
soramimi0:7ddb56bfde0c 2 * sha1.c
soramimi0:7ddb56bfde0c 3 *
soramimi0:7ddb56bfde0c 4 * Description:
soramimi0:7ddb56bfde0c 5 * This file implements the Secure Hashing Algorithm 1 as
soramimi0:7ddb56bfde0c 6 * defined in FIPS PUB 180-1 published April 17, 1995.
soramimi0:7ddb56bfde0c 7 *
soramimi0:7ddb56bfde0c 8 * The SHA-1, produces a 160-bit message digest for a given
soramimi0:7ddb56bfde0c 9 * data stream. It should take about 2**n steps to find a
soramimi0:7ddb56bfde0c 10 * message with the same digest as a given message and
soramimi0:7ddb56bfde0c 11 * 2**(n/2) to find any two messages with the same digest,
soramimi0:7ddb56bfde0c 12 * when n is the digest size in bits. Therefore, this
soramimi0:7ddb56bfde0c 13 * algorithm can serve as a means of providing a
soramimi0:7ddb56bfde0c 14 * "fingerprint" for a message.
soramimi0:7ddb56bfde0c 15 *
soramimi0:7ddb56bfde0c 16 * Portability Issues:
soramimi0:7ddb56bfde0c 17 * SHA-1 is defined in terms of 32-bit "words". This code
soramimi0:7ddb56bfde0c 18 * uses <stdint.h> (included via "sha1.h" to define 32 and 8
soramimi0:7ddb56bfde0c 19 * bit unsigned integer types. If your C compiler does not
soramimi0:7ddb56bfde0c 20 * support 32 bit unsigned integers, this code is not
soramimi0:7ddb56bfde0c 21 * appropriate.
soramimi0:7ddb56bfde0c 22 *
soramimi0:7ddb56bfde0c 23 * Caveats:
soramimi0:7ddb56bfde0c 24 * SHA-1 is designed to work with messages less than 2^64 bits
soramimi0:7ddb56bfde0c 25 * long. Although SHA-1 allows a message digest to be generated
soramimi0:7ddb56bfde0c 26 * for messages of any number of bits less than 2^64, this
soramimi0:7ddb56bfde0c 27 * implementation only works with messages with a length that is
soramimi0:7ddb56bfde0c 28 * a multiple of the size of an 8-bit character.
soramimi0:7ddb56bfde0c 29 *
soramimi0:7ddb56bfde0c 30 */
soramimi0:7ddb56bfde0c 31
soramimi0:7ddb56bfde0c 32#include "sha1.h"
soramimi0:7ddb56bfde0c 33
soramimi0:7ddb56bfde0c 34
soramimi0:7ddb56bfde0c 35/*
soramimi0:7ddb56bfde0c 36 * Define the SHA1 circular left shift macro
soramimi0:7ddb56bfde0c 37 */
soramimi0:7ddb56bfde0c 38#define SHA1CircularShift(bits,word) \
soramimi0:7ddb56bfde0c 39 (((word) << (bits)) | ((word) >> (32-(bits))))
soramimi0:7ddb56bfde0c 40
soramimi0:7ddb56bfde0c 41/* Local Function Prototyptes */
soramimi0:7ddb56bfde0c 42void SHA1PadMessage(SHA1Context *);
soramimi0:7ddb56bfde0c 43void SHA1ProcessMessageBlock(SHA1Context *);
soramimi0:7ddb56bfde0c 44
soramimi0:7ddb56bfde0c 45/*
soramimi0:7ddb56bfde0c 46 * SHA1Reset
soramimi0:7ddb56bfde0c 47 *
soramimi0:7ddb56bfde0c 48 * Description:
soramimi0:7ddb56bfde0c 49 * This function will initialize the SHA1Context in preparation
soramimi0:7ddb56bfde0c 50 * for computing a new SHA1 message digest.
soramimi0:7ddb56bfde0c 51 *
soramimi0:7ddb56bfde0c 52 * Parameters:
soramimi0:7ddb56bfde0c 53 * context: [in/out]
soramimi0:7ddb56bfde0c 54 * The context to reset.
soramimi0:7ddb56bfde0c 55 *
soramimi0:7ddb56bfde0c 56 * Returns:
soramimi0:7ddb56bfde0c 57 * sha Error Code.
soramimi0:7ddb56bfde0c 58 *
soramimi0:7ddb56bfde0c 59 */
soramimi0:7ddb56bfde0c 60int SHA1Reset(SHA1Context *context)
soramimi0:7ddb56bfde0c 61{
soramimi0:7ddb56bfde0c 62 if (!context)
soramimi0:7ddb56bfde0c 63 {
soramimi0:7ddb56bfde0c 64 return shaNull;
soramimi0:7ddb56bfde0c 65 }
soramimi0:7ddb56bfde0c 66
soramimi0:7ddb56bfde0c 67 context->Length_Low = 0;
soramimi0:7ddb56bfde0c 68 context->Length_High = 0;
soramimi0:7ddb56bfde0c 69 context->Message_Block_Index = 0;
soramimi0:7ddb56bfde0c 70
soramimi0:7ddb56bfde0c 71 context->Intermediate_Hash[0] = 0x67452301;
soramimi0:7ddb56bfde0c 72 context->Intermediate_Hash[1] = 0xEFCDAB89;
soramimi0:7ddb56bfde0c 73 context->Intermediate_Hash[2] = 0x98BADCFE;
soramimi0:7ddb56bfde0c 74 context->Intermediate_Hash[3] = 0x10325476;
soramimi0:7ddb56bfde0c 75 context->Intermediate_Hash[4] = 0xC3D2E1F0;
soramimi0:7ddb56bfde0c 76
soramimi0:7ddb56bfde0c 77 context->Computed = 0;
soramimi0:7ddb56bfde0c 78 context->Corrupted = 0;
soramimi0:7ddb56bfde0c 79
soramimi0:7ddb56bfde0c 80 return shaSuccess;
soramimi0:7ddb56bfde0c 81}
soramimi0:7ddb56bfde0c 82
soramimi0:7ddb56bfde0c 83/*
soramimi0:7ddb56bfde0c 84 * SHA1Result
soramimi0:7ddb56bfde0c 85 *
soramimi0:7ddb56bfde0c 86 * Description:
soramimi0:7ddb56bfde0c 87 * This function will return the 160-bit message digest into the
soramimi0:7ddb56bfde0c 88 * Message_Digest array provided by the caller.
soramimi0:7ddb56bfde0c 89 * NOTE: The first octet of hash is stored in the 0th element,
soramimi0:7ddb56bfde0c 90 * the last octet of hash in the 19th element.
soramimi0:7ddb56bfde0c 91 *
soramimi0:7ddb56bfde0c 92 * Parameters:
soramimi0:7ddb56bfde0c 93 * context: [in/out]
soramimi0:7ddb56bfde0c 94 * The context to use to calculate the SHA-1 hash.
soramimi0:7ddb56bfde0c 95 * Message_Digest: [out]
soramimi0:7ddb56bfde0c 96 * Where the digest is returned.
soramimi0:7ddb56bfde0c 97 *
soramimi0:7ddb56bfde0c 98 * Returns:
soramimi0:7ddb56bfde0c 99 * sha Error Code.
soramimi0:7ddb56bfde0c 100 *
soramimi0:7ddb56bfde0c 101 */
soramimi0:7ddb56bfde0c 102int SHA1Result( SHA1Context *context,
soramimi0:7ddb56bfde0c 103 uint8_t Message_Digest[SHA1HashSize])
soramimi0:7ddb56bfde0c 104{
soramimi0:7ddb56bfde0c 105 int i;
soramimi0:7ddb56bfde0c 106
soramimi0:7ddb56bfde0c 107 if (!context || !Message_Digest)
soramimi0:7ddb56bfde0c 108 {
soramimi0:7ddb56bfde0c 109 return shaNull;
soramimi0:7ddb56bfde0c 110 }
soramimi0:7ddb56bfde0c 111
soramimi0:7ddb56bfde0c 112 if (context->Corrupted)
soramimi0:7ddb56bfde0c 113 {
soramimi0:7ddb56bfde0c 114 return context->Corrupted;
soramimi0:7ddb56bfde0c 115 }
soramimi0:7ddb56bfde0c 116
soramimi0:7ddb56bfde0c 117 if (!context->Computed)
soramimi0:7ddb56bfde0c 118 {
soramimi0:7ddb56bfde0c 119 SHA1PadMessage(context);
soramimi0:7ddb56bfde0c 120 for(i=0; i<64; ++i)
soramimi0:7ddb56bfde0c 121 {
soramimi0:7ddb56bfde0c 122 /* message may be sensitive, clear it out */
soramimi0:7ddb56bfde0c 123 context->Message_Block[i] = 0;
soramimi0:7ddb56bfde0c 124 }
soramimi0:7ddb56bfde0c 125 context->Length_Low = 0; /* and clear length */
soramimi0:7ddb56bfde0c 126 context->Length_High = 0;
soramimi0:7ddb56bfde0c 127 context->Computed = 1;
soramimi0:7ddb56bfde0c 128 }
soramimi0:7ddb56bfde0c 129
soramimi0:7ddb56bfde0c 130 for(i = 0; i < SHA1HashSize; ++i)
soramimi0:7ddb56bfde0c 131 {
soramimi0:7ddb56bfde0c 132 Message_Digest[i] = context->Intermediate_Hash[i>>2] >> 8 * ( 3 - ( i & 0x03 ) );
soramimi0:7ddb56bfde0c 133 }
soramimi0:7ddb56bfde0c 134
soramimi0:7ddb56bfde0c 135 return shaSuccess;
soramimi0:7ddb56bfde0c 136}
soramimi0:7ddb56bfde0c 137
soramimi0:7ddb56bfde0c 138/*
soramimi0:7ddb56bfde0c 139 * SHA1Input
soramimi0:7ddb56bfde0c 140 *
soramimi0:7ddb56bfde0c 141 * Description:
soramimi0:7ddb56bfde0c 142 * This function accepts an array of octets as the next portion
soramimi0:7ddb56bfde0c 143 * of the message.
soramimi0:7ddb56bfde0c 144 *
soramimi0:7ddb56bfde0c 145 * Parameters:
soramimi0:7ddb56bfde0c 146 * context: [in/out]
soramimi0:7ddb56bfde0c 147 * The SHA context to update
soramimi0:7ddb56bfde0c 148 * message_array: [in]
soramimi0:7ddb56bfde0c 149 * An array of characters representing the next portion of
soramimi0:7ddb56bfde0c 150 * the message.
soramimi0:7ddb56bfde0c 151 * length: [in]
soramimi0:7ddb56bfde0c 152 * The length of the message in message_array
soramimi0:7ddb56bfde0c 153 *
soramimi0:7ddb56bfde0c 154 * Returns:
soramimi0:7ddb56bfde0c 155 * sha Error Code.
soramimi0:7ddb56bfde0c 156 *
soramimi0:7ddb56bfde0c 157 */
soramimi0:7ddb56bfde0c 158int SHA1Input( SHA1Context *context,
soramimi0:7ddb56bfde0c 159 const uint8_t *message_array,
soramimi0:7ddb56bfde0c 160 unsigned length)
soramimi0:7ddb56bfde0c 161{
soramimi0:7ddb56bfde0c 162 if (!length)
soramimi0:7ddb56bfde0c 163 {
soramimi0:7ddb56bfde0c 164 return shaSuccess;
soramimi0:7ddb56bfde0c 165 }
soramimi0:7ddb56bfde0c 166
soramimi0:7ddb56bfde0c 167 if (!context || !message_array)
soramimi0:7ddb56bfde0c 168 {
soramimi0:7ddb56bfde0c 169 return shaNull;
soramimi0:7ddb56bfde0c 170 }
soramimi0:7ddb56bfde0c 171
soramimi0:7ddb56bfde0c 172 if (context->Computed)
soramimi0:7ddb56bfde0c 173 {
soramimi0:7ddb56bfde0c 174 context->Corrupted = shaStateError;
soramimi0:7ddb56bfde0c 175 return shaStateError;
soramimi0:7ddb56bfde0c 176 }
soramimi0:7ddb56bfde0c 177
soramimi0:7ddb56bfde0c 178 if (context->Corrupted)
soramimi0:7ddb56bfde0c 179 {
soramimi0:7ddb56bfde0c 180 return context->Corrupted;
soramimi0:7ddb56bfde0c 181 }
soramimi0:7ddb56bfde0c 182 while(length-- && !context->Corrupted)
soramimi0:7ddb56bfde0c 183 {
soramimi0:7ddb56bfde0c 184 context->Message_Block[context->Message_Block_Index++] =
soramimi0:7ddb56bfde0c 185 (*message_array & 0xFF);
soramimi0:7ddb56bfde0c 186
soramimi0:7ddb56bfde0c 187 context->Length_Low += 8;
soramimi0:7ddb56bfde0c 188 if (context->Length_Low == 0)
soramimi0:7ddb56bfde0c 189 {
soramimi0:7ddb56bfde0c 190 context->Length_High++;
soramimi0:7ddb56bfde0c 191 if (context->Length_High == 0)
soramimi0:7ddb56bfde0c 192 {
soramimi0:7ddb56bfde0c 193 /* Message is too long */
soramimi0:7ddb56bfde0c 194 context->Corrupted = 1;
soramimi0:7ddb56bfde0c 195 }
soramimi0:7ddb56bfde0c 196 }
soramimi0:7ddb56bfde0c 197
soramimi0:7ddb56bfde0c 198 if (context->Message_Block_Index == 64)
soramimi0:7ddb56bfde0c 199 {
soramimi0:7ddb56bfde0c 200 SHA1ProcessMessageBlock(context);
soramimi0:7ddb56bfde0c 201 }
soramimi0:7ddb56bfde0c 202
soramimi0:7ddb56bfde0c 203 message_array++;
soramimi0:7ddb56bfde0c 204 }
soramimi0:7ddb56bfde0c 205
soramimi0:7ddb56bfde0c 206 return shaSuccess;
soramimi0:7ddb56bfde0c 207}
soramimi0:7ddb56bfde0c 208
soramimi0:7ddb56bfde0c 209/*
soramimi0:7ddb56bfde0c 210 * SHA1ProcessMessageBlock
soramimi0:7ddb56bfde0c 211 *
soramimi0:7ddb56bfde0c 212 * Description:
soramimi0:7ddb56bfde0c 213 * This function will process the next 512 bits of the message
soramimi0:7ddb56bfde0c 214 * stored in the Message_Block array.
soramimi0:7ddb56bfde0c 215 *
soramimi0:7ddb56bfde0c 216 * Parameters:
soramimi0:7ddb56bfde0c 217 * None.
soramimi0:7ddb56bfde0c 218 *
soramimi0:7ddb56bfde0c 219 * Returns:
soramimi0:7ddb56bfde0c 220 * Nothing.
soramimi0:7ddb56bfde0c 221 *
soramimi0:7ddb56bfde0c 222 * Comments:
soramimi0:7ddb56bfde0c 223 * Many of the variable names in this code, especially the
soramimi0:7ddb56bfde0c 224 * single character names, were used because those were the
soramimi0:7ddb56bfde0c 225 * names used in the publication.
soramimi0:7ddb56bfde0c 226 *
soramimi0:7ddb56bfde0c 227 *
soramimi0:7ddb56bfde0c 228 */
soramimi0:7ddb56bfde0c 229void SHA1ProcessMessageBlock(SHA1Context *context)
soramimi0:7ddb56bfde0c 230{
soramimi0:7ddb56bfde0c 231 const uint32_t K[] = { /* Constants defined in SHA-1 */
soramimi0:7ddb56bfde0c 232 0x5A827999,
soramimi0:7ddb56bfde0c 233 0x6ED9EBA1,
soramimi0:7ddb56bfde0c 234 0x8F1BBCDC,
soramimi0:7ddb56bfde0c 235 0xCA62C1D6
soramimi0:7ddb56bfde0c 236 };
soramimi0:7ddb56bfde0c 237 int t; /* Loop counter */
soramimi0:7ddb56bfde0c 238 uint32_t temp; /* Temporary word value */
soramimi0:7ddb56bfde0c 239 uint32_t W[80]; /* Word sequence */
soramimi0:7ddb56bfde0c 240 uint32_t A, B, C, D, E; /* Word buffers */
soramimi0:7ddb56bfde0c 241
soramimi0:7ddb56bfde0c 242 /*
soramimi0:7ddb56bfde0c 243 * Initialize the first 16 words in the array W
soramimi0:7ddb56bfde0c 244 */
soramimi0:7ddb56bfde0c 245 for(t = 0; t < 16; t++)
soramimi0:7ddb56bfde0c 246 {
soramimi0:7ddb56bfde0c 247 W[t] = context->Message_Block[t * 4] << 24;
soramimi0:7ddb56bfde0c 248 W[t] |= context->Message_Block[t * 4 + 1] << 16;
soramimi0:7ddb56bfde0c 249 W[t] |= context->Message_Block[t * 4 + 2] << 8;
soramimi0:7ddb56bfde0c 250 W[t] |= context->Message_Block[t * 4 + 3];
soramimi0:7ddb56bfde0c 251 }
soramimi0:7ddb56bfde0c 252
soramimi0:7ddb56bfde0c 253 for(t = 16; t < 80; t++)
soramimi0:7ddb56bfde0c 254 {
soramimi0:7ddb56bfde0c 255 W[t] = SHA1CircularShift(1,W[t-3] ^ W[t-8] ^ W[t-14] ^ W[t-16]);
soramimi0:7ddb56bfde0c 256 }
soramimi0:7ddb56bfde0c 257
soramimi0:7ddb56bfde0c 258 A = context->Intermediate_Hash[0];
soramimi0:7ddb56bfde0c 259 B = context->Intermediate_Hash[1];
soramimi0:7ddb56bfde0c 260 C = context->Intermediate_Hash[2];
soramimi0:7ddb56bfde0c 261 D = context->Intermediate_Hash[3];
soramimi0:7ddb56bfde0c 262 E = context->Intermediate_Hash[4];
soramimi0:7ddb56bfde0c 263
soramimi0:7ddb56bfde0c 264 for(t = 0; t < 20; t++)
soramimi0:7ddb56bfde0c 265 {
soramimi0:7ddb56bfde0c 266 temp = SHA1CircularShift(5,A) +
soramimi0:7ddb56bfde0c 267 ((B & C) | ((~B) & D)) + E + W[t] + K[0];
soramimi0:7ddb56bfde0c 268 E = D;
soramimi0:7ddb56bfde0c 269 D = C;
soramimi0:7ddb56bfde0c 270 C = SHA1CircularShift(30,B);
soramimi0:7ddb56bfde0c 271 B = A;
soramimi0:7ddb56bfde0c 272 A = temp;
soramimi0:7ddb56bfde0c 273 }
soramimi0:7ddb56bfde0c 274
soramimi0:7ddb56bfde0c 275 for(t = 20; t < 40; t++)
soramimi0:7ddb56bfde0c 276 {
soramimi0:7ddb56bfde0c 277 temp = SHA1CircularShift(5,A) + (B ^ C ^ D) + E + W[t] + K[1];
soramimi0:7ddb56bfde0c 278 E = D;
soramimi0:7ddb56bfde0c 279 D = C;
soramimi0:7ddb56bfde0c 280 C = SHA1CircularShift(30,B);
soramimi0:7ddb56bfde0c 281 B = A;
soramimi0:7ddb56bfde0c 282 A = temp;
soramimi0:7ddb56bfde0c 283 }
soramimi0:7ddb56bfde0c 284
soramimi0:7ddb56bfde0c 285 for(t = 40; t < 60; t++)
soramimi0:7ddb56bfde0c 286 {
soramimi0:7ddb56bfde0c 287 temp = SHA1CircularShift(5,A) +
soramimi0:7ddb56bfde0c 288 ((B & C) | (B & D) | (C & D)) + E + W[t] + K[2];
soramimi0:7ddb56bfde0c 289 E = D;
soramimi0:7ddb56bfde0c 290 D = C;
soramimi0:7ddb56bfde0c 291 C = SHA1CircularShift(30,B);
soramimi0:7ddb56bfde0c 292 B = A;
soramimi0:7ddb56bfde0c 293 A = temp;
soramimi0:7ddb56bfde0c 294 }
soramimi0:7ddb56bfde0c 295
soramimi0:7ddb56bfde0c 296 for(t = 60; t < 80; t++)
soramimi0:7ddb56bfde0c 297 {
soramimi0:7ddb56bfde0c 298 temp = SHA1CircularShift(5,A) + (B ^ C ^ D) + E + W[t] + K[3];
soramimi0:7ddb56bfde0c 299 E = D;
soramimi0:7ddb56bfde0c 300 D = C;
soramimi0:7ddb56bfde0c 301 C = SHA1CircularShift(30,B);
soramimi0:7ddb56bfde0c 302 B = A;
soramimi0:7ddb56bfde0c 303 A = temp;
soramimi0:7ddb56bfde0c 304 }
soramimi0:7ddb56bfde0c 305
soramimi0:7ddb56bfde0c 306 context->Intermediate_Hash[0] += A;
soramimi0:7ddb56bfde0c 307 context->Intermediate_Hash[1] += B;
soramimi0:7ddb56bfde0c 308 context->Intermediate_Hash[2] += C;
soramimi0:7ddb56bfde0c 309 context->Intermediate_Hash[3] += D;
soramimi0:7ddb56bfde0c 310 context->Intermediate_Hash[4] += E;
soramimi0:7ddb56bfde0c 311
soramimi0:7ddb56bfde0c 312 context->Message_Block_Index = 0;
soramimi0:7ddb56bfde0c 313}
soramimi0:7ddb56bfde0c 314
soramimi0:7ddb56bfde0c 315
soramimi0:7ddb56bfde0c 316/*
soramimi0:7ddb56bfde0c 317 * SHA1PadMessage
soramimi0:7ddb56bfde0c 318 *
soramimi0:7ddb56bfde0c 319 * Description:
soramimi0:7ddb56bfde0c 320 * According to the standard, the message must be padded to an even
soramimi0:7ddb56bfde0c 321 * 512 bits. The first padding bit must be a '1'. The last 64
soramimi0:7ddb56bfde0c 322 * bits represent the length of the original message. All bits in
soramimi0:7ddb56bfde0c 323 * between should be 0. This function will pad the message
soramimi0:7ddb56bfde0c 324 * according to those rules by filling the Message_Block array
soramimi0:7ddb56bfde0c 325 * accordingly. It will also call the ProcessMessageBlock function
soramimi0:7ddb56bfde0c 326 * provided appropriately. When it returns, it can be assumed that
soramimi0:7ddb56bfde0c 327 * the message digest has been computed.
soramimi0:7ddb56bfde0c 328 *
soramimi0:7ddb56bfde0c 329 * Parameters:
soramimi0:7ddb56bfde0c 330 * context: [in/out]
soramimi0:7ddb56bfde0c 331 * The context to pad
soramimi0:7ddb56bfde0c 332 * ProcessMessageBlock: [in]
soramimi0:7ddb56bfde0c 333 * The appropriate SHA*ProcessMessageBlock function
soramimi0:7ddb56bfde0c 334 * Returns:
soramimi0:7ddb56bfde0c 335 * Nothing.
soramimi0:7ddb56bfde0c 336 *
soramimi0:7ddb56bfde0c 337 */
soramimi0:7ddb56bfde0c 338
soramimi0:7ddb56bfde0c 339void SHA1PadMessage(SHA1Context *context)
soramimi0:7ddb56bfde0c 340{
soramimi0:7ddb56bfde0c 341 /*
soramimi0:7ddb56bfde0c 342 * Check to see if the current message block is too small to hold
soramimi0:7ddb56bfde0c 343 * the initial padding bits and length. If so, we will pad the
soramimi0:7ddb56bfde0c 344 * block, process it, and then continue padding into a second
soramimi0:7ddb56bfde0c 345 * block.
soramimi0:7ddb56bfde0c 346 */
soramimi0:7ddb56bfde0c 347 if (context->Message_Block_Index > 55)
soramimi0:7ddb56bfde0c 348 {
soramimi0:7ddb56bfde0c 349 context->Message_Block[context->Message_Block_Index++] = 0x80;
soramimi0:7ddb56bfde0c 350 while(context->Message_Block_Index < 64)
soramimi0:7ddb56bfde0c 351 {
soramimi0:7ddb56bfde0c 352 context->Message_Block[context->Message_Block_Index++] = 0;
soramimi0:7ddb56bfde0c 353 }
soramimi0:7ddb56bfde0c 354
soramimi0:7ddb56bfde0c 355 SHA1ProcessMessageBlock(context);
soramimi0:7ddb56bfde0c 356
soramimi0:7ddb56bfde0c 357 while(context->Message_Block_Index < 56)
soramimi0:7ddb56bfde0c 358 {
soramimi0:7ddb56bfde0c 359 context->Message_Block[context->Message_Block_Index++] = 0;
soramimi0:7ddb56bfde0c 360 }
soramimi0:7ddb56bfde0c 361 }
soramimi0:7ddb56bfde0c 362 else
soramimi0:7ddb56bfde0c 363 {
soramimi0:7ddb56bfde0c 364 context->Message_Block[context->Message_Block_Index++] = 0x80;
soramimi0:7ddb56bfde0c 365 while(context->Message_Block_Index < 56)
soramimi0:7ddb56bfde0c 366 {
soramimi0:7ddb56bfde0c 367 context->Message_Block[context->Message_Block_Index++] = 0;
soramimi0:7ddb56bfde0c 368 }
soramimi0:7ddb56bfde0c 369 }
soramimi0:7ddb56bfde0c 370
soramimi0:7ddb56bfde0c 371 /*
soramimi0:7ddb56bfde0c 372 * Store the message length as the last 8 octets
soramimi0:7ddb56bfde0c 373 */
soramimi0:7ddb56bfde0c 374 context->Message_Block[56] = context->Length_High >> 24;
soramimi0:7ddb56bfde0c 375 context->Message_Block[57] = context->Length_High >> 16;
soramimi0:7ddb56bfde0c 376 context->Message_Block[58] = context->Length_High >> 8;
soramimi0:7ddb56bfde0c 377 context->Message_Block[59] = context->Length_High;
soramimi0:7ddb56bfde0c 378 context->Message_Block[60] = context->Length_Low >> 24;
soramimi0:7ddb56bfde0c 379 context->Message_Block[61] = context->Length_Low >> 16;
soramimi0:7ddb56bfde0c 380 context->Message_Block[62] = context->Length_Low >> 8;
soramimi0:7ddb56bfde0c 381 context->Message_Block[63] = context->Length_Low;
soramimi0:7ddb56bfde0c 382
soramimi0:7ddb56bfde0c 383 SHA1ProcessMessageBlock(context);
soramimi0:7ddb56bfde0c 384}
soramimi0:7ddb56bfde0c 385