Lines Matching +full:p +full:- +full:384

3  * AUTHOR:	Aaron D. Gifford - http://www.aarongifford.com/
5 * Copyright (c) 2000-2001, Aaron D. Gifford
9 * system-defined SHA code.
11 * - Renamed (external) functions and constants to fit ldns style
12 * - Removed _End and _Data functions
13 * - Added ldns_shaX(data, len, digest) convenience functions
14 * - Removed prototypes of _Transform functions and made those static
66 /*** SHA-256/384/512 Machine Architecture Definitions *****************/
71 * architecture is little-endian, make sure it also defines
81 * And for little-endian machines, add:
85 * Or for big-endian machines:
106 /*** SHA-256/384/512 Various Length Definitions ***********************/
107 #define SHA512_SHORT_BLOCK_LENGTH (SHA512_BLOCK_LENGTH - 16)
132 * Macro for incrementally adding the unsigned 64-bit integer n to the
133 * unsigned 128-bit integer (represented using a two-element array of
134 * 64-bit words):
166 #define MEMSET_BZERO(p,l) memset((p), 0, (l)) argument
170 #define MEMSET_BZERO(p,l) bzero((p), (l)) argument
177 * Bit shifting and rotation (used by the six SHA-XYZ logical functions:
180 * S is a ROTATION) because the SHA-256/384/512 description document
181 * (see http://csrc.nist.gov/cryptval/shs/sha256-384-512.pdf) uses this
184 /* Shift-right (used in SHA-256, SHA-384, and SHA-512): */
186 /* 64-bit Rotate-right (used in SHA-384 and SHA-512): */
187 #define S64(b,x) (((x) >> (b)) | ((x) << (64 - (b))))
189 /* Two of six logical functions used in SHA-256, SHA-384, and SHA-512: */
193 /* Four of six logical functions used in SHA-384 and SHA-512: */
199 /*** SHA-XYZ INITIAL HASH VALUES AND CONSTANTS ************************/
200 /* Hash constant words K for SHA-384 and SHA-512: */
244 /* initial hash value H for SHA-512 */
261 /*** SHA-512: *********************************************************/
266 MEMCPY_BCOPY(context->state, sha512_initial_hash_value, SHA512_DIGEST_LENGTH); in SHA512_Init()
267 MEMSET_BZERO(context->buffer, SHA512_BLOCK_LENGTH); in SHA512_Init()
268 context->bitcount[0] = context->bitcount[1] = 0; in SHA512_Init()
274 sha2_word64 T1, T2, *W512 = (sha2_word64*)context->buffer; in SHA512_Transform()
278 a = context->state[0]; in SHA512_Transform()
279 b = context->state[1]; in SHA512_Transform()
280 c = context->state[2]; in SHA512_Transform()
281 d = context->state[3]; in SHA512_Transform()
282 e = context->state[4]; in SHA512_Transform()
283 f = context->state[5]; in SHA512_Transform()
284 g = context->state[6]; in SHA512_Transform()
285 h = context->state[7]; in SHA512_Transform()
292 /* Apply the SHA-512 compression function to update a..h */ in SHA512_Transform()
295 /* Apply the SHA-512 compression function to update a..h with copy */ in SHA512_Transform()
318 /* Apply the SHA-512 compression function to update a..h */ in SHA512_Transform()
335 context->state[0] += a; in SHA512_Transform()
336 context->state[1] += b; in SHA512_Transform()
337 context->state[2] += c; in SHA512_Transform()
338 context->state[3] += d; in SHA512_Transform()
339 context->state[4] += e; in SHA512_Transform()
340 context->state[5] += f; in SHA512_Transform()
341 context->state[6] += g; in SHA512_Transform()
342 context->state[7] += h; in SHA512_Transform()
353 /* Calling with no data is valid - we do nothing */ in SHA512_Update()
360 usedspace = (context->bitcount[0] >> 3) % SHA512_BLOCK_LENGTH; in SHA512_Update()
363 freespace = SHA512_BLOCK_LENGTH - usedspace; in SHA512_Update()
367 MEMCPY_BCOPY(&context->buffer[usedspace], data, freespace); in SHA512_Update()
368 ADDINC128(context->bitcount, freespace << 3); in SHA512_Update()
369 len -= freespace; in SHA512_Update()
371 SHA512_Transform(context, (sha2_word64*)context->buffer); in SHA512_Update()
374 MEMCPY_BCOPY(&context->buffer[usedspace], data, len); in SHA512_Update()
375 ADDINC128(context->bitcount, len << 3); in SHA512_Update()
384 ADDINC128(context->bitcount, SHA512_BLOCK_LENGTH << 3); in SHA512_Update()
385 len -= SHA512_BLOCK_LENGTH; in SHA512_Update()
389 /* There's left-overs, so save 'em */ in SHA512_Update()
390 MEMCPY_BCOPY(context->buffer, data, len); in SHA512_Update()
391 ADDINC128(context->bitcount, len << 3); in SHA512_Update()
401 usedspace = (context->bitcount[0] >> 3) % SHA512_BLOCK_LENGTH; in SHA512_Last()
404 REVERSE64(context->bitcount[0],context->bitcount[0]); in SHA512_Last()
405 REVERSE64(context->bitcount[1],context->bitcount[1]); in SHA512_Last()
409 context->buffer[usedspace++] = 0x80; in SHA512_Last()
412 /* Set-up for the last transform: */ in SHA512_Last()
413 MEMSET_BZERO(&context->buffer[usedspace], SHA512_SHORT_BLOCK_LENGTH - usedspace); in SHA512_Last()
416 MEMSET_BZERO(&context->buffer[usedspace], SHA512_BLOCK_LENGTH - usedspace); in SHA512_Last()
418 /* Do second-to-last transform: */ in SHA512_Last()
419 SHA512_Transform(context, (sha2_word64*)context->buffer); in SHA512_Last()
421 /* And set-up for the last transform: */ in SHA512_Last()
422 MEMSET_BZERO(context->buffer, SHA512_BLOCK_LENGTH - 2); in SHA512_Last()
426 MEMSET_BZERO(context->buffer, SHA512_SHORT_BLOCK_LENGTH); in SHA512_Last()
429 *context->buffer = 0x80; in SHA512_Last()
432 cast_var.theChars = context->buffer; in SHA512_Last()
433 cast_var.theLongs[SHA512_SHORT_BLOCK_LENGTH / 8] = context->bitcount[1]; in SHA512_Last()
434 cast_var.theLongs[SHA512_SHORT_BLOCK_LENGTH / 8 + 1] = context->bitcount[0]; in SHA512_Last()
437 SHA512_Transform(context, (sha2_word64*)context->buffer); in SHA512_Last()
456 REVERSE64(context->state[j],context->state[j]); in SHA512_Final()
457 *d++ = context->state[j]; in SHA512_Final()
461 MEMCPY_BCOPY(d, context->state, SHA512_DIGEST_LENGTH); in SHA512_Final()