ReactOS 0.4.16-dev-1946-g52006dd
hash.c File Reference
#include <stdio.h>
#include <stdarg.h>
#include "windef.h"
#include "winbase.h"
#include "winnls.h"
#include "widltypes.h"
#include "hash.h"
Include dependency graph for hash.c:

Go to the source code of this file.

Macros

#define DWORD2BE(x)   ((((x) >> 24) & 0xff) | (((x) >> 8) & 0xff00) | (((x) << 8) & 0xff0000) | (((x) << 24) & 0xff000000))
 
#define rol(value, bits)   (((value) << (bits)) | ((value) >> (32 - (bits))))
 
#define blk0(i)   (block[i] = DWORD2BE(block[i]))
 
#define blk1(i)   (block[i&15] = rol(block[(i+13)&15]^block[(i+8)&15]^block[(i+2)&15]^block[i&15],1))
 
#define f1(x, y, z)   (z^(x&(y^z)))
 
#define f2(x, y, z)   (x^y^z)
 
#define f3(x, y, z)   ((x&y)|(z&(x|y)))
 
#define f4(x, y, z)   (x^y^z)
 
#define R0(v, w, x, y, z, i)   z+=f1(w,x,y)+blk0(i)+0x5A827999+rol(v,5);w=rol(w,30);
 
#define R1(v, w, x, y, z, i)   z+=f1(w,x,y)+blk1(i)+0x5A827999+rol(v,5);w=rol(w,30);
 
#define R2(v, w, x, y, z, i)   z+=f2(w,x,y)+blk1(i)+0x6ED9EBA1+rol(v,5);w=rol(w,30);
 
#define R3(v, w, x, y, z, i)   z+=f3(w,x,y)+blk1(i)+0x8F1BBCDC+rol(v,5);w=rol(w,30);
 
#define R4(v, w, x, y, z, i)   z+=f4(w,x,y)+blk1(i)+0xCA62C1D6+rol(v,5);w=rol(w,30);
 

Functions

unsigned int lhash_val_of_name_sys (syskind_t skind, int lcid, const char *lpStr)
 
static void sha1_transform (struct sha1_context *ctx)
 
void sha1_init (struct sha1_context *ctx)
 
void sha1_update (struct sha1_context *ctx, const char *data, size_t data_size)
 
void sha1_finalize (struct sha1_context *ctx, unsigned int result[5])
 

Variables

static const unsigned char Lookup_16 [128 *3]
 
static const unsigned char Lookup_32 [128 *3]
 
static const unsigned char Lookup_48 [128 *3]
 
static const unsigned char Lookup_64 [128 *3]
 
static const unsigned char Lookup_80 [128 *3]
 
static const unsigned char Lookup_112 [128 *3]
 
static const unsigned char Lookup_128 [128 *3]
 
static const unsigned char Lookup_144 [128 *3]
 
static const unsigned char Lookup_160 [128 *3]
 
static const unsigned char Lookup_176 [128 *3]
 
static const unsigned char Lookup_208 [128 *3]
 
static const unsigned char Lookup_224 [128 *3]
 

Macro Definition Documentation

◆ blk0

#define blk0 (   i)    (block[i] = DWORD2BE(block[i]))

Definition at line 608 of file hash.c.

◆ blk1

#define blk1 (   i)    (block[i&15] = rol(block[(i+13)&15]^block[(i+8)&15]^block[(i+2)&15]^block[i&15],1))

Definition at line 609 of file hash.c.

◆ DWORD2BE

#define DWORD2BE (   x)    ((((x) >> 24) & 0xff) | (((x) >> 8) & 0xff00) | (((x) << 8) & 0xff0000) | (((x) << 24) & 0xff000000))

Definition at line 604 of file hash.c.

◆ f1

#define f1 (   x,
  y,
  z 
)    (z^(x&(y^z)))

Definition at line 610 of file hash.c.

◆ f2

#define f2 (   x,
  y,
  z 
)    (x^y^z)

Definition at line 611 of file hash.c.

◆ f3

#define f3 (   x,
  y,
  z 
)    ((x&y)|(z&(x|y)))

Definition at line 612 of file hash.c.

◆ f4

#define f4 (   x,
  y,
  z 
)    (x^y^z)

Definition at line 613 of file hash.c.

◆ R0

#define R0 (   v,
  w,
  x,
  y,
  z,
  i 
)    z+=f1(w,x,y)+blk0(i)+0x5A827999+rol(v,5);w=rol(w,30);

Definition at line 615 of file hash.c.

◆ R1

#define R1 (   v,
  w,
  x,
  y,
  z,
  i 
)    z+=f1(w,x,y)+blk1(i)+0x5A827999+rol(v,5);w=rol(w,30);

Definition at line 616 of file hash.c.

◆ R2

#define R2 (   v,
  w,
  x,
  y,
  z,
  i 
)    z+=f2(w,x,y)+blk1(i)+0x6ED9EBA1+rol(v,5);w=rol(w,30);

Definition at line 617 of file hash.c.

◆ R3

#define R3 (   v,
  w,
  x,
  y,
  z,
  i 
)    z+=f3(w,x,y)+blk1(i)+0x8F1BBCDC+rol(v,5);w=rol(w,30);

Definition at line 618 of file hash.c.

◆ R4

#define R4 (   v,
  w,
  x,
  y,
  z,
  i 
)    z+=f4(w,x,y)+blk1(i)+0xCA62C1D6+rol(v,5);w=rol(w,30);

Definition at line 619 of file hash.c.

◆ rol

#define rol (   value,
  bits 
)    (((value) << (bits)) | ((value) >> (32 - (bits))))

Definition at line 607 of file hash.c.

Function Documentation

◆ lhash_val_of_name_sys()

unsigned int lhash_val_of_name_sys ( syskind_t  skind,
int  lcid,
const char lpStr 
)

Definition at line 511 of file hash.c.

512{
513 unsigned int nOffset, nMask = skind == SYS_MAC ? 1 : 0;
514 unsigned int nHiWord, nLoWord = 0x0deadbee;
515 const unsigned char *str = (const unsigned char *)lpStr, *pnLookup = NULL;
516
517 if (!str)
518 return 0;
519
521 {
522 default:
523 nOffset = 16;
524 pnLookup = Lookup_16;
525 break;
526 case LANG_CZECH: case LANG_HUNGARIAN: case LANG_POLISH:
527 case LANG_SLOVAK: case LANG_SPANISH:
528 nOffset = 32;
529 pnLookup = Lookup_32;
530 break;
531 case LANG_HEBREW:
532 nOffset = 48;
533 pnLookup = Lookup_48;
534 break;
535 case LANG_JAPANESE:
536 nOffset = 64;
537 pnLookup = Lookup_64;
538 break;
539 case LANG_KOREAN:
540 nOffset = 80;
541 pnLookup = Lookup_80;
542 break;
543 case LANG_CHINESE:
544 nOffset = 112;
545 pnLookup = Lookup_112;
546 break;
547 case LANG_GREEK:
548 nOffset = 128;
549 pnLookup = Lookup_128;
550 break;
551 case LANG_ICELANDIC:
552 nOffset = 144;
553 pnLookup = Lookup_144;
554 break;
555 case LANG_TURKISH:
556 nOffset = 160;
557 pnLookup = Lookup_160;
558 break;
559 case LANG_NORWEGIAN:
561 {
562 nOffset = 176;
563 pnLookup = Lookup_176;
564 }
565 else
566 {
567 nOffset = 16;
568 pnLookup = Lookup_16;
569 }
570 break;
571 case LANG_ARABIC:
572 case LANG_FARSI:
573 nOffset = 208;
574 pnLookup = Lookup_208;
575 break;
576 case LANG_RUSSIAN:
577 nOffset = 224;
578 pnLookup = Lookup_224;
579 break;
580 }
581
582 nHiWord = (nOffset | nMask) << 16;
583
584 while (*str)
585 {
586 nLoWord = 37 * nLoWord + pnLookup[*str > 0x7f && nMask ? *str + 0x80 : *str];
587 str++;
588 }
589 /* Constrain to a prime modulo and sizeof(WORD) */
590 nLoWord = (nLoWord % 65599) & 0xffff;
591
592 return nHiWord | nLoWord;
593}
#define NULL
Definition: types.h:112
LCID lcid
Definition: locale.c:5656
static const unsigned char Lookup_16[128 *3]
Definition: hash.c:32
static const unsigned char Lookup_208[128 *3]
Definition: hash.c:411
static const unsigned char Lookup_112[128 *3]
Definition: hash.c:221
static const unsigned char Lookup_48[128 *3]
Definition: hash.c:108
static const unsigned char Lookup_128[128 *3]
Definition: hash.c:259
static const unsigned char Lookup_144[128 *3]
Definition: hash.c:297
static const unsigned char Lookup_80[128 *3]
Definition: hash.c:183
static const unsigned char Lookup_224[128 *3]
Definition: hash.c:449
static const unsigned char Lookup_160[128 *3]
Definition: hash.c:335
static const unsigned char Lookup_32[128 *3]
Definition: hash.c:70
static const unsigned char Lookup_64[128 *3]
Definition: hash.c:146
static const unsigned char Lookup_176[128 *3]
Definition: hash.c:373
const WCHAR * str
#define SUBLANG_NORWEGIAN_NYNORSK
Definition: nls.h:301
#define LANG_FARSI
Definition: nls.h:55
#define LANG_NORWEGIAN
Definition: nls.h:102
#define SUBLANGID(l)
Definition: nls.h:17
#define LANG_TURKISH
Definition: nls.h:136
#define LANG_SPANISH
Definition: nls.h:123
#define LANG_POLISH
Definition: nls.h:107
#define LANG_HEBREW
Definition: nls.h:67
#define LANG_GREEK
Definition: nls.h:63
#define LANGIDFROMLCID(l)
Definition: nls.h:18
#define LANG_RUSSIAN
Definition: nls.h:113
#define LANG_CZECH
Definition: nls.h:47
#define LANG_HUNGARIAN
Definition: nls.h:69
#define LANG_ARABIC
Definition: nls.h:29
#define LANG_CHINESE
Definition: nls.h:42
#define LANG_JAPANESE
Definition: nls.h:76
#define PRIMARYLANGID(l)
Definition: nls.h:16
#define LANG_ICELANDIC
Definition: nls.h:70
#define LANG_SLOVAK
Definition: nls.h:120
#define LANG_KOREAN
Definition: nls.h:84
@ SYS_MAC
Definition: widltypes.h:648

Referenced by ctl2_encode_name().

◆ sha1_finalize()

void sha1_finalize ( struct sha1_context ctx,
unsigned int  result[5] 
)

Definition at line 703 of file hash.c.

704{
705 unsigned int *count, length_hi, length_lo, i;
706 size_t pad_size, buffer_size;
707 char pad[72];
708
709 buffer_size = ctx->count[1] & 63;
710 if (buffer_size >= 56) pad_size = 56 + 64 - buffer_size;
711 else pad_size = 56 - buffer_size;
712
713 length_hi = (ctx->count[0] << 3) | (ctx->count[1] >> (32 - 3));
714 length_lo = (ctx->count[1] << 3);
715
716 memset(pad + 1, 0, pad_size - 1);
717 pad[0] = 0x80;
718 count = (unsigned int*)(pad + pad_size);
719 count[0] = DWORD2BE(length_hi);
720 count[1] = DWORD2BE(length_lo);
721 sha1_update(ctx, pad, pad_size + 8);
722
723 for (i = 0; i < 5; i++) result[i] = DWORD2BE(ctx->state[i]);
724
725 sha1_init(ctx);
726}
#define sha1_init
Definition: compat-1.3.h:2266
#define sha1_update
Definition: compat-1.3.h:2270
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLuint64EXT * result
Definition: glext.h:11304
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define memset(x, y, z)
Definition: compat.h:39
#define DWORD2BE(x)
Definition: hash.c:604
wchar_t const *const size_t const buffer_size
Definition: stat.cpp:95

Referenced by compute_interface_signature_uuid().

◆ sha1_init()

void sha1_init ( struct sha1_context ctx)

Definition at line 666 of file hash.c.

667{
668 /* SHA1 initialization constants */
669 ctx->state[0] = 0x67452301;
670 ctx->state[1] = 0xEFCDAB89;
671 ctx->state[2] = 0x98BADCFE;
672 ctx->state[3] = 0x10325476;
673 ctx->state[4] = 0xC3D2E1F0;
674 ctx->count[0] = 0;
675 ctx->count[1] = 0;
676}

◆ sha1_transform()

static void sha1_transform ( struct sha1_context ctx)
static

Definition at line 622 of file hash.c.

623{
624 unsigned int a, b, c, d, e, *block = (unsigned int *)ctx->buffer;
625
626 /* Copy ctx->state[] to working variables */
627 a = ctx->state[0];
628 b = ctx->state[1];
629 c = ctx->state[2];
630 d = ctx->state[3];
631 e = ctx->state[4];
632
633 /* 4 rounds of 20 operations each. Loop unrolled. */
634 R0(a,b,c,d,e, 0); R0(e,a,b,c,d, 1); R0(d,e,a,b,c, 2); R0(c,d,e,a,b, 3);
635 R0(b,c,d,e,a, 4); R0(a,b,c,d,e, 5); R0(e,a,b,c,d, 6); R0(d,e,a,b,c, 7);
636 R0(c,d,e,a,b, 8); R0(b,c,d,e,a, 9); R0(a,b,c,d,e,10); R0(e,a,b,c,d,11);
637 R0(d,e,a,b,c,12); R0(c,d,e,a,b,13); R0(b,c,d,e,a,14); R0(a,b,c,d,e,15);
638 R1(e,a,b,c,d,16); R1(d,e,a,b,c,17); R1(c,d,e,a,b,18); R1(b,c,d,e,a,19);
639 R2(a,b,c,d,e,20); R2(e,a,b,c,d,21); R2(d,e,a,b,c,22); R2(c,d,e,a,b,23);
640 R2(b,c,d,e,a,24); R2(a,b,c,d,e,25); R2(e,a,b,c,d,26); R2(d,e,a,b,c,27);
641 R2(c,d,e,a,b,28); R2(b,c,d,e,a,29); R2(a,b,c,d,e,30); R2(e,a,b,c,d,31);
642 R2(d,e,a,b,c,32); R2(c,d,e,a,b,33); R2(b,c,d,e,a,34); R2(a,b,c,d,e,35);
643 R2(e,a,b,c,d,36); R2(d,e,a,b,c,37); R2(c,d,e,a,b,38); R2(b,c,d,e,a,39);
644 R3(a,b,c,d,e,40); R3(e,a,b,c,d,41); R3(d,e,a,b,c,42); R3(c,d,e,a,b,43);
645 R3(b,c,d,e,a,44); R3(a,b,c,d,e,45); R3(e,a,b,c,d,46); R3(d,e,a,b,c,47);
646 R3(c,d,e,a,b,48); R3(b,c,d,e,a,49); R3(a,b,c,d,e,50); R3(e,a,b,c,d,51);
647 R3(d,e,a,b,c,52); R3(c,d,e,a,b,53); R3(b,c,d,e,a,54); R3(a,b,c,d,e,55);
648 R3(e,a,b,c,d,56); R3(d,e,a,b,c,57); R3(c,d,e,a,b,58); R3(b,c,d,e,a,59);
649 R4(a,b,c,d,e,60); R4(e,a,b,c,d,61); R4(d,e,a,b,c,62); R4(c,d,e,a,b,63);
650 R4(b,c,d,e,a,64); R4(a,b,c,d,e,65); R4(e,a,b,c,d,66); R4(d,e,a,b,c,67);
651 R4(c,d,e,a,b,68); R4(b,c,d,e,a,69); R4(a,b,c,d,e,70); R4(e,a,b,c,d,71);
652 R4(d,e,a,b,c,72); R4(c,d,e,a,b,73); R4(b,c,d,e,a,74); R4(a,b,c,d,e,75);
653 R4(e,a,b,c,d,76); R4(d,e,a,b,c,77); R4(c,d,e,a,b,78); R4(b,c,d,e,a,79);
654
655 /* Add the working variables back into ctx->state[] */
656 ctx->state[0] += a;
657 ctx->state[1] += b;
658 ctx->state[2] += c;
659 ctx->state[3] += d;
660 ctx->state[4] += e;
661
662 /* Wipe variables */
663 a = b = c = d = e = 0;
664}
const GLubyte * c
Definition: glext.h:8905
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204
#define d
Definition: ke_i.h:81
#define e
Definition: ke_i.h:82
#define a
Definition: ke_i.h:78
#define c
Definition: ke_i.h:80
#define b
Definition: ke_i.h:79
#define R1(v, w, x, y, z, i)
Definition: hash.c:616
#define R2(v, w, x, y, z, i)
Definition: hash.c:617
#define R0(v, w, x, y, z, i)
Definition: hash.c:615
#define R3(v, w, x, y, z, i)
Definition: hash.c:618
#define R4(v, w, x, y, z, i)
Definition: hash.c:619
static unsigned int block
Definition: xmlmemory.c:101

Referenced by sha1_update().

◆ sha1_update()

void sha1_update ( struct sha1_context ctx,
const char data,
size_t  data_size 
)

Definition at line 678 of file hash.c.

679{
680 size_t buffer_size;
681
682 buffer_size = ctx->count[1] & 63;
683 ctx->count[1] += data_size;
684 if (ctx->count[1] < data_size) ctx->count[0]++;
685 ctx->count[0] += (data_size >> 29);
686
687 if (buffer_size + data_size < 64)
688 memcpy(&ctx->buffer[buffer_size], data, data_size);
689 else
690 {
691 while (buffer_size + data_size >= 64)
692 {
693 memcpy(ctx->buffer + buffer_size, data, 64 - buffer_size);
694 data += 64 - buffer_size;
695 data_size -= 64 - buffer_size;
697 buffer_size = 0;
698 }
699 memcpy(ctx->buffer + buffer_size, data, data_size);
700 }
701}
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static void sha1_transform(struct sha1_context *ctx)
Definition: hash.c:622

Variable Documentation

◆ Lookup_112

const unsigned char Lookup_112[128 *3]
static

Definition at line 225 of file hash.c.

◆ Lookup_128

const unsigned char Lookup_128[128 *3]
static

Definition at line 263 of file hash.c.

◆ Lookup_144

const unsigned char Lookup_144[128 *3]
static

Definition at line 301 of file hash.c.

◆ Lookup_16

const unsigned char Lookup_16[128 *3]
static

Definition at line 36 of file hash.c.

◆ Lookup_160

const unsigned char Lookup_160[128 *3]
static

Definition at line 339 of file hash.c.

◆ Lookup_176

const unsigned char Lookup_176[128 *3]
static

Definition at line 377 of file hash.c.

◆ Lookup_208

const unsigned char Lookup_208[128 *3]
static

Definition at line 415 of file hash.c.

◆ Lookup_224

const unsigned char Lookup_224[128 *3]
static

Definition at line 453 of file hash.c.

◆ Lookup_32

const unsigned char Lookup_32[128 *3]
static

Definition at line 74 of file hash.c.

◆ Lookup_48

const unsigned char Lookup_48[128 *3]
static

Definition at line 112 of file hash.c.

◆ Lookup_64

const unsigned char Lookup_64[128 *3]
static

Definition at line 150 of file hash.c.

◆ Lookup_80

const unsigned char Lookup_80[128 *3]
static

Definition at line 187 of file hash.c.