Skip to content

Commit

Permalink
Merge branch 'jn/block-sha1' into maint
Browse files Browse the repository at this point in the history
* jn/block-sha1:
  Makefile: BLK_SHA1 does not require fast htonl() and unaligned loads
  block-sha1: put expanded macro parameters in parentheses
  block-sha1: avoid pointer conversion that violates alignment constraints
  • Loading branch information
gitster committed Aug 6, 2012
2 parents dbf64e1 + f200197 commit c8dacba
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
5 changes: 2 additions & 3 deletions Makefile
Expand Up @@ -127,9 +127,8 @@ all::
# specify your own (or DarwinPort's) include directories and # specify your own (or DarwinPort's) include directories and
# library directories by defining CFLAGS and LDFLAGS appropriately. # library directories by defining CFLAGS and LDFLAGS appropriately.
# #
# Define BLK_SHA1 environment variable if you want the C version # Define BLK_SHA1 environment variable to make use of the bundled
# of the SHA1 that assumes you can do unaligned 32-bit loads and # optimized C SHA1 routine.
# have a fast htonl() function.
# #
# Define PPC_SHA1 environment variable when running make to make use of # Define PPC_SHA1 environment variable when running make to make use of
# a bundled SHA1 routine optimized for PowerPC. # a bundled SHA1 routine optimized for PowerPC.
Expand Down
8 changes: 4 additions & 4 deletions block-sha1/sha1.c
Expand Up @@ -101,8 +101,8 @@
* Where do we get the source from? The first 16 iterations get it from * Where do we get the source from? The first 16 iterations get it from
* the input data, the next mix it from the 512-bit array. * the input data, the next mix it from the 512-bit array.
*/ */
#define SHA_SRC(t) get_be32(data + t) #define SHA_SRC(t) get_be32((unsigned char *) block + (t)*4)
#define SHA_MIX(t) SHA_ROL(W(t+13) ^ W(t+8) ^ W(t+2) ^ W(t), 1) #define SHA_MIX(t) SHA_ROL(W((t)+13) ^ W((t)+8) ^ W((t)+2) ^ W(t), 1);


#define SHA_ROUND(t, input, fn, constant, A, B, C, D, E) do { \ #define SHA_ROUND(t, input, fn, constant, A, B, C, D, E) do { \
unsigned int TEMP = input(t); setW(t, TEMP); \ unsigned int TEMP = input(t); setW(t, TEMP); \
Expand All @@ -115,7 +115,7 @@
#define T_40_59(t, A, B, C, D, E) SHA_ROUND(t, SHA_MIX, ((B&C)+(D&(B^C))) , 0x8f1bbcdc, A, B, C, D, E ) #define T_40_59(t, A, B, C, D, E) SHA_ROUND(t, SHA_MIX, ((B&C)+(D&(B^C))) , 0x8f1bbcdc, A, B, C, D, E )
#define T_60_79(t, A, B, C, D, E) SHA_ROUND(t, SHA_MIX, (B^C^D) , 0xca62c1d6, A, B, C, D, E ) #define T_60_79(t, A, B, C, D, E) SHA_ROUND(t, SHA_MIX, (B^C^D) , 0xca62c1d6, A, B, C, D, E )


static void blk_SHA1_Block(blk_SHA_CTX *ctx, const unsigned int *data) static void blk_SHA1_Block(blk_SHA_CTX *ctx, const void *block)
{ {
unsigned int A,B,C,D,E; unsigned int A,B,C,D,E;
unsigned int array[16]; unsigned int array[16];
Expand All @@ -126,7 +126,7 @@ static void blk_SHA1_Block(blk_SHA_CTX *ctx, const unsigned int *data)
D = ctx->H[3]; D = ctx->H[3];
E = ctx->H[4]; E = ctx->H[4];


/* Round 1 - iterations 0-16 take their input from 'data' */ /* Round 1 - iterations 0-16 take their input from 'block' */
T_0_15( 0, A, B, C, D, E); T_0_15( 0, A, B, C, D, E);
T_0_15( 1, E, A, B, C, D); T_0_15( 1, E, A, B, C, D);
T_0_15( 2, D, E, A, B, C); T_0_15( 2, D, E, A, B, C);
Expand Down

0 comments on commit c8dacba

Please sign in to comment.