Skip to content

Commit 355020d

Browse files
author
Christopher Gurnee
committed
use BSWAP intrinsic in sha256.c
* other minor changes (style/comments)
1 parent 400d8a6 commit 355020d

File tree

5 files changed

+17
-18
lines changed

5 files changed

+17
-18
lines changed

HashCheckTranslations.rc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ STRINGTABLE LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
3232
IDS_HP_FIND_NOTFOUND "Text not found."
3333
IDS_HP_SAVE "&Save..."
3434
IDS_HP_OPTIONS "&Options"
35-
IDS_HP_FILELABEL " File: " // should have the same width as "CRC-32: "; may translate "Name" if "File" is too long
35+
IDS_HP_FILELABEL " File: " // should have the same width as "SHA-256: "; may translate "Name" if "File" is too long
3636

3737
// Strings used exclusively in the HashVerify module
3838
IDS_HV_LOADERROR_FMT "Cannot load ""%s""" // %s == name of the checksum file

libs/WinHash.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* Windows Hashing/Checksumming Library
3-
* Last modified: 2009/01/13
3+
* Last modified: 2014/12/04
44
* Original work copyright (C) Kai Liu. All rights reserved.
55
* Modified work copyright (C) 2014 Christopher Gurnee. All rights reserved.
66
*

libs/WinHash.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* Windows Hashing/Checksumming Library
3-
* Last modified: 2009/01/13
3+
* Last modified: 2014/12/04
44
* Original work copyright (C) Kai Liu. All rights reserved.
55
* Modified work copyright (C) 2014 Christopher Gurnee. All rights reserved.
66
*

libs/sha256.c

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@
2020
//
2121
#if _MSC_VER >= 1300
2222
# define ROTR(n, x) _rotr(x, n)
23+
# define SWAP_32(x) _byteswap_ulong(x) // swap endianness of a uint32
2324
#else
2425
# define ROTR(n, x) ( (x) >> (n) | (x) << (32-(n)) )
26+
# define SWAP_32(x) ( (x) << 24 | ((x) & 0xff00) << 8 | ((x) & 0xff0000) >> 8 | (x) >> 24 )
2527
#endif
2628

2729
// secion 4.1.2
@@ -46,9 +48,6 @@ const uint32_t K[] = {
4648
};
4749

4850

49-
// swap endianness of a uint32
50-
#define SWAP_32(x) ( (x) << 24 | ((x) & 0xff00) << 8 | ((x) & 0xff0000) >> 8 | (x) >> 24 )
51-
5251
// array length (WARNING: arg must be of array type, not pointer)
5352
#define ARRAYLEN(a) ( sizeof(a) / sizeof(a[0]) )
5453

@@ -110,14 +109,14 @@ void sha256_block(uint32_t H[8], const uint32_t M[16])
110109
}
111110

112111
// section 6.2.2 step 4
113-
H[0] = a + H[0];
114-
H[1] = b + H[1];
115-
H[2] = c + H[2];
116-
H[3] = d + H[3];
117-
H[4] = e + H[4];
118-
H[5] = f + H[5];
119-
H[6] = g + H[6];
120-
H[7] = h + H[7];
112+
H[0] += a;
113+
H[1] += b;
114+
H[2] += c;
115+
H[3] += d;
116+
H[4] += e;
117+
H[5] += f;
118+
H[6] += g;
119+
H[7] += h;
121120
}
122121

123122

@@ -135,7 +134,7 @@ void sha256_update(Sha256Context* context, const uint8_t* input, size_t input_si
135134
// copy bytes from the input to the working buffer
136135
int num_bytes_to_copy = (int)min(input_size, sizeof(context->buffer) - context->cur_buffer_size);
137136
memcpy(&context->buffer[context->cur_buffer_size], input, num_bytes_to_copy);
138-
137+
139138
// update our data structures
140139
context->cur_buffer_size += num_bytes_to_copy;
141140
input += num_bytes_to_copy;
@@ -190,7 +189,7 @@ void sha256_finalize(Sha256Context* context)
190189
context->cur_buffer_size = 0;
191190
empty_bytes = sizeof(context->buffer);
192191
}
193-
192+
194193
// append the "0" padding bits (leaving 64 bits at the end untouched)
195194
memset(&context->buffer[context->cur_buffer_size], 0, empty_bytes - 8);
196195

version.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
#define HASHCHECK_NAME_STR "HashCheck Shell Extension"
1212

1313
// Full version: MUST be in the form of major,minor,revision,build
14-
#define HASHCHECK_VERSION_FULL 2,2,0,3
14+
#define HASHCHECK_VERSION_FULL 2,2,1,4
1515

1616
// String version: May be any suitable string
17-
#define HASHCHECK_VERSION_STR "2.2.0.3"
17+
#define HASHCHECK_VERSION_STR "2.2.1.4"
1818

1919
#ifdef _USRDLL
2020
// PE version: MUST be in the form of major.minor

0 commit comments

Comments
 (0)