Skip to content

Commit

Permalink
Whitespace refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
carlbennett committed Jul 1, 2016
1 parent 877f3ff commit 85b8058
Show file tree
Hide file tree
Showing 26 changed files with 2,401 additions and 2,400 deletions.
73 changes: 37 additions & 36 deletions src/bncsutil/Makefile
Original file line number Diff line number Diff line change
@@ -1,36 +1,37 @@
SHELL = /bin/sh
SYSTEM = $(shell uname)
CXX = g++
CXXFLAGS = -Wall -O3 -I ../ -Wno-multichar -fPIC
CXXOBJ = bsha1.o cdkeydecoder.o checkrevision.o decodekey.o file.o libinfo.o oldauth.o
CC = gcc
CCFLAGS = -Wall -O3 -I ../ -Wno-multichar -fPIC
CCOBJ = nls.o pe.o sha1.o stack.o

ifeq ($(SYSTEM),Darwin)
LDFLAGS = -dynamiclib -lgmp -L/opt/local/lib
TARGET = libbncsutil.dylib
else
LDFLAGS = -shared -lgmp
TARGET = libbncsutil.so
endif

$(TARGET): $(CXXOBJ) $(CCOBJ)
$(CXX) $(CXXFLAGS) $(LDFLAGS) $(CXXOBJ) $(CCOBJ) -o $(TARGET)

$(CXXOBJ): %.o: %.cpp
$(CXX) $(CXXFLAGS) -c $< -o $@

$(CCOBJ): %.o: %.c
$(CC) $(CCFLAGS) -c $< -o $@

clean:
rm -f $(CCOBJ) $(CXXOBJ) $(TARGET) *~
all:
make $(TARGET)

install: $(TARGET)
mkdir -p /usr/include/bncsutil
cp *.h /usr/include/bncsutil
cp $(TARGET) /usr/lib
ldconfig
SHELL = /bin/sh
SYSTEM = $(shell uname)
CXX = g++
CXXFLAGS = -Wall -O3 -I ../ -Wno-multichar -fPIC
CXXOBJ = bsha1.o cdkeydecoder.o checkrevision.o decodekey.o file.o libinfo.o oldauth.o
CC = gcc
CCFLAGS = -Wall -O3 -I ../ -Wno-multichar -fPIC
CCOBJ = nls.o pe.o sha1.o stack.o

ifeq ($(SYSTEM),Darwin)
LDFLAGS = -dynamiclib -lgmp -L/opt/local/lib
TARGET = libbncsutil.dylib
else
LDFLAGS = -shared -lgmp
TARGET = libbncsutil.so
endif

$(TARGET): $(CXXOBJ) $(CCOBJ)
$(CXX) $(CXXFLAGS) $(LDFLAGS) $(CXXOBJ) $(CCOBJ) -o $(TARGET)

$(CXXOBJ): %.o: %.cpp
$(CXX) $(CXXFLAGS) -c $< -o $@

$(CCOBJ): %.o: %.c
$(CC) $(CCFLAGS) -c $< -o $@

clean:
rm -f $(CCOBJ) $(CXXOBJ) $(TARGET) *~

all:
make $(TARGET)

install: $(TARGET)
mkdir -p /usr/include/bncsutil
cp *.h /usr/include/bncsutil
cp $(TARGET) /usr/lib
ldconfig
156 changes: 78 additions & 78 deletions src/bncsutil/bsha1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include <bncsutil/bsha1.h>
#include <cstring>

#define USE_NEW_BSHA1 0
#define USE_NEW_BSHA1 0

#define BSHA_IC1 0x67452301lu
#define BSHA_IC2 0xEFCDAB89lu
Expand All @@ -41,10 +41,10 @@
#define BSHA_OC4 0x359D3E2Alu

#if !USE_NEW_BSHA1
# define BSHA_COP e = d; d = c; c = ROL(b, 30); b = a; a = g;
# define BSHA_COP e = d; d = c; c = ROL(b, 30); b = a; a = g;
#else
# define BSHA_N_COP t[4] = t[3]; t[3] = t[2]; t[2] = ROL(t[1], 30); \
t[1] = t[0]; t[0] = x
# define BSHA_N_COP t[4] = t[3]; t[3] = t[2]; t[2] = ROL(t[1], 30); \
t[1] = t[0]; t[0] = x
#endif

#if !USE_NEW_BSHA1
Expand All @@ -60,108 +60,108 @@
#else

#define BSHA_N_OP1() x = LSB4(*p++) + ROL(t[0], 5) + t[4] + \
((t[1] & t[2]) | (~t[1] & t[3])) + BSHA_OC1; BSHA_N_COP
((t[1] & t[2]) | (~t[1] & t[3])) + BSHA_OC1; BSHA_N_COP
#define BSHA_N_OP2() x = (t[3] ^ t[2] ^ t[1]) + t[4] + ROL(x, 5) + \
LSB4(*p++) + BSHA_OC2; BSHA_N_COP
LSB4(*p++) + BSHA_OC2; BSHA_N_COP
#define BSHA_N_OP3() x = LSB4(*p++) + ROL(x, 5) + t[4] + \
((t[2] & t[1]) | (t[3] & t[2]) | (t[3] & t[1])) - BSHA_OC3; BSHA_N_COP
((t[2] & t[1]) | (t[3] & t[2]) | (t[3] & t[1])) - BSHA_OC3; BSHA_N_COP
#define BSHA_N_OP4() x = (t[3] ^ t[2] ^ t[1]) + t[4] + ROL(x, 5) + \
LSB4(*p++) - BSHA_OC4; BSHA_N_COP
LSB4(*p++) - BSHA_OC4; BSHA_N_COP
#endif

#if USE_NEW_BSHA1
MEXP(void) calcHashBuf(const char* input, unsigned int length, char* result) {
uint32_t vals[5];
uint32_t t[5]; // a, b, c, d, e
uint32_t buf[0x50];
uint32_t* p;
uint32_t x;
const char* in = input;
unsigned int i, j;
unsigned int sub_length;
/* Initializer Values */
p = vals;
*p++ = BSHA_IC1;
*p++ = BSHA_IC2;
*p++ = BSHA_IC3;
*p++ = BSHA_IC4;
*p++ = BSHA_IC5;
memset(buf, 0, 320); // zero buf
/* Process input in chunks. */
for (i = 0; i < length; i += 0x40) {
sub_length = length - i;
/* Maximum chunk size is 0x40 (64) bytes. */
if (sub_length > 0x40)
sub_length = 0x40;
memcpy(buf, in, sub_length);
in += sub_length;
/* If necessary, pad with zeroes to 64 bytes. */
if (sub_length < 0x40)
memset(buf + sub_length, 0, 0x40 - sub_length);
for (j = 0; j < 64; j++) {
buf[j + 16] =
LSB4(ROL(1, LSB4(buf[j] ^ buf[j+8] ^ buf[j+2] ^ buf[j+13]) % 32));
}
memcpy(t, vals, 20);
p = buf;
/* It's a kind of magic. */
BSHA_N_OP1(); BSHA_N_OP1(); BSHA_N_OP1(); BSHA_N_OP1(); BSHA_N_OP1();
BSHA_N_OP1(); BSHA_N_OP1(); BSHA_N_OP1(); BSHA_N_OP1(); BSHA_N_OP1();
BSHA_N_OP2(); BSHA_N_OP2(); BSHA_N_OP2(); BSHA_N_OP2(); BSHA_N_OP2();
BSHA_N_OP2(); BSHA_N_OP2(); BSHA_N_OP2(); BSHA_N_OP2(); BSHA_N_OP2();
BSHA_N_OP3(); BSHA_N_OP3(); BSHA_N_OP3(); BSHA_N_OP3(); BSHA_N_OP3();
BSHA_N_OP3(); BSHA_N_OP3(); BSHA_N_OP3(); BSHA_N_OP3(); BSHA_N_OP3();
BSHA_N_OP4(); BSHA_N_OP4(); BSHA_N_OP4(); BSHA_N_OP4(); BSHA_N_OP4();
BSHA_N_OP4(); BSHA_N_OP4(); BSHA_N_OP4(); BSHA_N_OP4(); BSHA_N_OP4();
vals[0] += t[0];
vals[1] += t[1];
vals[2] += t[2];
vals[3] += t[3];
vals[4] += t[4];
}
/* Return result. */
memcpy(result, vals, 20);
uint32_t vals[5];
uint32_t t[5]; // a, b, c, d, e
uint32_t buf[0x50];
uint32_t* p;
uint32_t x;
const char* in = input;
unsigned int i, j;
unsigned int sub_length;

/* Initializer Values */
p = vals;
*p++ = BSHA_IC1;
*p++ = BSHA_IC2;
*p++ = BSHA_IC3;
*p++ = BSHA_IC4;
*p++ = BSHA_IC5;

memset(buf, 0, 320); // zero buf

/* Process input in chunks. */
for (i = 0; i < length; i += 0x40) {
sub_length = length - i;

/* Maximum chunk size is 0x40 (64) bytes. */
if (sub_length > 0x40)
sub_length = 0x40;

memcpy(buf, in, sub_length);
in += sub_length;

/* If necessary, pad with zeroes to 64 bytes. */
if (sub_length < 0x40)
memset(buf + sub_length, 0, 0x40 - sub_length);

for (j = 0; j < 64; j++) {
buf[j + 16] =
LSB4(ROL(1, LSB4(buf[j] ^ buf[j+8] ^ buf[j+2] ^ buf[j+13]) % 32));
}

memcpy(t, vals, 20);
p = buf;

/* It's a kind of magic. */
BSHA_N_OP1(); BSHA_N_OP1(); BSHA_N_OP1(); BSHA_N_OP1(); BSHA_N_OP1();
BSHA_N_OP1(); BSHA_N_OP1(); BSHA_N_OP1(); BSHA_N_OP1(); BSHA_N_OP1();

BSHA_N_OP2(); BSHA_N_OP2(); BSHA_N_OP2(); BSHA_N_OP2(); BSHA_N_OP2();
BSHA_N_OP2(); BSHA_N_OP2(); BSHA_N_OP2(); BSHA_N_OP2(); BSHA_N_OP2();

BSHA_N_OP3(); BSHA_N_OP3(); BSHA_N_OP3(); BSHA_N_OP3(); BSHA_N_OP3();
BSHA_N_OP3(); BSHA_N_OP3(); BSHA_N_OP3(); BSHA_N_OP3(); BSHA_N_OP3();

BSHA_N_OP4(); BSHA_N_OP4(); BSHA_N_OP4(); BSHA_N_OP4(); BSHA_N_OP4();
BSHA_N_OP4(); BSHA_N_OP4(); BSHA_N_OP4(); BSHA_N_OP4(); BSHA_N_OP4();

vals[0] += t[0];
vals[1] += t[1];
vals[2] += t[2];
vals[3] += t[3];
vals[4] += t[4];
}

/* Return result. */
memcpy(result, vals, 20);
}

#else

MEXP(void) calcHashBuf(const char* input, size_t length, char* result) {
int i;
uint32_t a, b, c, d, e, g;
uint32_t* ldata;
uint32_t* ldata;
char data[1024];
memset(data, 0, 1024);
memcpy(data, input, length);
ldata = (uint32_t*) data;

for (i = 0; i < 64; i++) {
ldata[i + 16] =
LSB4(ROL(1, LSB4(ldata[i] ^ ldata[i+8] ^ ldata[i+2] ^ ldata[i+13]) % 32));
}
//dumpbuf(data, 1024);

//dumpbuf(data, 1024);

a = BSHA_IC1;
b = BSHA_IC2;
c = BSHA_IC3;
d = BSHA_IC4;
e = BSHA_IC5;
g = 0;

// Loops unrolled.
BSHA_OP1(a, b, c, d, e, *ldata++, g) BSHA_OP1(a, b, c, d, e, *ldata++, g)
BSHA_OP1(a, b, c, d, e, *ldata++, g) BSHA_OP1(a, b, c, d, e, *ldata++, g)
Expand Down
2 changes: 1 addition & 1 deletion src/bncsutil/bsha1.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ extern "C" {
* hash: Buffer, at least 20 bytes in length, to receive the hash.
*/
MEXP(void) calcHashBuf(const char* data, size_t length, char* hash);

/*
* New implementation. Broken. No plans to fix.
*/
Expand Down
Loading

0 comments on commit 85b8058

Please sign in to comment.