Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some code improvements. #32

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions Changelog
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ Changes with version 0.11 22 Feb 2013

* Bugfix: variables, structures, functions changed their names from
*GOST3411* to fully-qualified *GOST34112012*

* Bugfix: API: GOST34112012Init() now operates on allocated memory.
Previously, memory allocation for context has been done with
GOST34112012Init() call - this guarantee proper alignment for context's
members. As for now, alignment is done with ALIGN keyword in object
declaration and GOST34112012Init() does not allocate any byte of memory.

* Bugfix: API: GOST34112012Final() now returns digest in memory pointed by
second argument. Context member "hexdigest" not used anymore thus
abandoned. It is up to calling application to present digest in
Expand All @@ -39,18 +39,18 @@ Changes with version 0.10 29 Jan 2013
substitution by Pi[] while generating multiplication lookup table.
Lookup table arranged in a such way totally eliminates the need to do
whole S-cycle in LPS.

* Feature: use SSE4.1 instructions set in LPS if available.

* Feature: multiplication lookup table is now statically precomputed in
header file and is in constant memory.

* Bugfix: rewrite GOST3411Update() function to implement streaming mode
when processing large amount of data.

* Bugfix: rename round2() and round3() to stage2() and stage3()
respectively.

* Bugfix: in auto configuration probes: delete temporary files.

Changes with version 0.09 22 Jan 2013
Expand All @@ -60,10 +60,10 @@ Changes with version 0.09 22 Jan 2013
quadruples. This avoid copying of temporary key and internal state
between rounds in g(), thus reduce instructions count per plaintext
block.

* Feature: with code optimization above, performance on 32-bit systems
greatly improved and is now about as fast as with 64-bit systems.

* Feature: detect MMX and SSE2 capabilities on compile time and use faster
code when possible. From this version onward there are at least two
versions of implementation: portable (not using any extensions like MMX
Expand All @@ -76,7 +76,7 @@ Changes with version 0.09 22 Jan 2013

* Bugfix: integer overflow incorrectly handled in addition by modulo 2.
This could lead to incorrect results on some files.

Changes with version 0.08 19 Jan 2013

* Feature: boost performance on 32-bit systems by using 64-bit MMX XOR
Expand All @@ -94,31 +94,31 @@ Changes with version 0.07 17 Jan 2013

* Bugfix: key generation function K replaced with XLPS macros to avoid
inlining issues when max inline instruction limit reached.

* Bugfix: encryption function E inlined to compression g to avoid
compile-time inlining issues when max inline instruction limit reached.

* Bugfix: use unsigned integers where possible.

* Bugfix: fix typo in update() when comparing bufsize.

* Bugfix: memory allocator rewritten to use posix_memalign().

Changes with version 0.06 09 Jan 2013

* Feature: performance optimization in LPS: hint compiler to use eight
registers instead of union buffer.

* Feature: performance optimization in permutation P: rotate matrix by
cyclic right shifting bits in source matrix columns to rows in
destination matrix.

* Feature: as result of previous two optimizations: replace LPS macros
with improved macros XLPS.

* Bugfix: improve constant table C presentation to avoid runtime
conversion in key generator K.

* Bugfix: unroll key generation loop in E.

* Bugfix: rename union member names according to their natural meaning.
Expand Down
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2013, Alexey Degtyarev <[email protected]>.
# Copyright (c) 2013, Alexey Degtyarev <[email protected]>.
# All rights reserved.
#
# $Id$
Expand Down Expand Up @@ -69,7 +69,7 @@ clean: rmconfig

dist: clean man
mkdir -p $(DISTNAME)
cp $(SOURCES) $(HEADERS) $(DISTNAME)
cp $(SOURCES) $(HEADERS) $(DISTNAME)
cp Changelog LICENSE Makefile VERSION README.md configure $(DISTNAME)
cp gost3411-2012.1 gost3411-2012.1.h2m $(DISTNAME)
cp -R auto examples $(DISTNAME)/
Expand All @@ -78,14 +78,14 @@ dist: clean man
tar czf $(DISTNAME).tar.gz $(DISTNAME)
rm -r $(DISTNAME)

distclean:
distclean:
-rm $(DISTNAME).tar.gz 2>/dev/null

test: gost3411-2012
./gost3411-2012 -t
./gost3411-2012 -t | cmp auto/test.txt

bench:
bench:
$(MAKE) remake CC=clang && ./gost3411-2012 -b
$(MAKE) remake CC=gcc46 && ./gost3411-2012 -b
$(MAKE) remake CC=gcc47 && ./gost3411-2012 -b
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ void GOST34112012Update(GOST34112012Context *CTX, const unsigned char *data, siz

Hash some `data` of `len` bytes size. The best performance results are
achieved when `len` is multiple of 64.

Note that this call does not modify original data in memory. If
security is an issue, calling application should destroy that memory
block right after `GOST34112012Update()`, by e.g. `memset()` to zero.
Expand Down
2 changes: 1 addition & 1 deletion auto/header/endianness
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2013, Alexey Degtyarev <[email protected]>.
# Copyright (c) 2013, Alexey Degtyarev <[email protected]>.
# All rights reserved.
#
# Detect running system endianness.
Expand Down
2 changes: 1 addition & 1 deletion auto/header/mmx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2013, Alexey Degtyarev <[email protected]>.
# Copyright (c) 2013, Alexey Degtyarev <[email protected]>.
# All rights reserved.
#
# Detect MMX capability in processor and compiler.
Expand Down
2 changes: 1 addition & 1 deletion auto/header/sse2
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2013, Alexey Degtyarev <[email protected]>.
# Copyright (c) 2013, Alexey Degtyarev <[email protected]>.
# All rights reserved.
#
# Detect SSE2 capability in processor and compiler.
Expand Down
2 changes: 1 addition & 1 deletion auto/header/sse41
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2013, Alexey Degtyarev <[email protected]>.
# Copyright (c) 2013, Alexey Degtyarev <[email protected]>.
# All rights reserved.
#
# Detect SSE4.1 capability in processor and compiler.
Expand Down
2 changes: 1 addition & 1 deletion auto/header/supercop
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2013, Alexey Degtyarev <[email protected]>.
# Copyright (c) 2013, Alexey Degtyarev <[email protected]>.
# All rights reserved.
#
# Activate SUPERCOP stuff when SUPERCOP environment variable is set.
Expand Down
2 changes: 1 addition & 1 deletion auto/mk/mmx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2013, Alexey Degtyarev <[email protected]>.
# Copyright (c) 2013, Alexey Degtyarev <[email protected]>.
# All rights reserved.
#
# Detect MMX capability in processor and compiler.
Expand Down
2 changes: 1 addition & 1 deletion auto/mk/sse2
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2013, Alexey Degtyarev <[email protected]>.
# Copyright (c) 2013, Alexey Degtyarev <[email protected]>.
# All rights reserved.
#
# Detect SSE2 capability in processor and compiler.
Expand Down
2 changes: 1 addition & 1 deletion auto/mk/sse41
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2013, Alexey Degtyarev <[email protected]>.
# Copyright (c) 2013, Alexey Degtyarev <[email protected]>.
# All rights reserved.
#
# Detect SSE4.1 capability in processor and compiler.
Expand Down
2 changes: 1 addition & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ EOF

cat ${AUTO_CONF_MK}.t >> ${AUTO_CONF_MK} && rm -f ${AUTO_CONF_MK}.t

cat >>${AUTO_CONF_MK} <<"EOF"
cat >>${AUTO_CONF_MK} <<"EOF"

compile:
$(CC) $(CFLAGS) -o gost3411-2012 $(SOURCES)
Expand Down
88 changes: 44 additions & 44 deletions gost3411-2012-const.h
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
/*
* Copyright (c) 2013, Alexey Degtyarev <[email protected]>.
* Copyright (c) 2013, Alexey Degtyarev <[email protected]>.
* All rights reserved.
*
* Iteration constants defined in standard.
*
* $Id$
*/

ALIGN(16) static const union uint512_u buffer0 = {{ 0x0ULL, 0x0ULL, 0x0ULL,
GOST3411_ALIGN(16) static const gost34112012_uint512_u buffer0 = {{ 0x0ULL, 0x0ULL, 0x0ULL,
0x0ULL, 0x0ULL, 0x0ULL, 0x0ULL, 0x0ULL }};

#ifndef __GOST3411_BIG_ENDIAN__
ALIGN(16) static const union uint512_u buffer512 = {{ 0x0000000000000200ULL,
GOST3411_ALIGN(16) static const gost34112012_uint512_u buffer512 = {{ 0x0000000000000200ULL,
0x0ULL, 0x0ULL, 0x0ULL, 0x0ULL, 0x0ULL, 0x0ULL, 0x0ULL }};
#else
ALIGN(16) static const union uint512_u buffer512 = {{ 0x0002000000000000ULL,
GOST3411_ALIGN(16) static const gost34112012_uint512_u buffer512 = {{ 0x0002000000000000ULL,
0x0ULL, 0x0ULL, 0x0ULL, 0x0ULL, 0x0ULL, 0x0ULL, 0x0ULL }};
#endif

#ifndef __GOST3411_BIG_ENDIAN__
ALIGN(16) static const union uint512_u C[12] = {
GOST3411_ALIGN(16) static const gost34112012_uint512_u C[12] = {
{{
0xdd806559f2a64507ULL,
0x05767436cc744d23ULL,
Expand Down Expand Up @@ -142,7 +142,7 @@ ALIGN(16) static const union uint512_u C[12] = {
}}
};
#else
ALIGN(16) static const union uint512_u C[12] = {
GOST3411_ALIGN(16) static const gost34112012_uint512_u C[12] = {
{{
0x0745a6f2596580ddULL,
0x234d74cc36747605ULL,
Expand Down Expand Up @@ -267,47 +267,47 @@ ALIGN(16) static const union uint512_u C[12] = {
#endif

static const unsigned char Tau[64] = {
0, 8, 16, 24, 32, 40, 48, 56,
1, 9, 17, 25, 33, 41, 49, 57,
2, 10, 18, 26, 34, 42, 50, 58,
3, 11, 19, 27, 35, 43, 51, 59,
4, 12, 20, 28, 36, 44, 52, 60,
5, 13, 21, 29, 37, 45, 53, 61,
6, 14, 22, 30, 38, 46, 54, 62,
0, 8, 16, 24, 32, 40, 48, 56,
1, 9, 17, 25, 33, 41, 49, 57,
2, 10, 18, 26, 34, 42, 50, 58,
3, 11, 19, 27, 35, 43, 51, 59,
4, 12, 20, 28, 36, 44, 52, 60,
5, 13, 21, 29, 37, 45, 53, 61,
6, 14, 22, 30, 38, 46, 54, 62,
7, 15, 23, 31, 39, 47, 55, 63
};

static const unsigned char Pi[256] = {
252, 238, 221, 17, 207, 110, 49, 22,
251, 196, 250, 218, 35, 197, 4, 77,
233, 119, 240, 219, 147, 46, 153, 186,
23, 54, 241, 187, 20, 205, 95, 193,
249, 24, 101, 90, 226, 92, 239, 33,
129, 28, 60, 66, 139, 1, 142, 79,
5, 132, 2, 174, 227, 106, 143, 160,
6, 11, 237, 152, 127, 212, 211, 31,
235, 52, 44, 81, 234, 200, 72, 171,
242, 42, 104, 162, 253, 58, 206, 204,
181, 112, 14, 86, 8, 12, 118, 18,
191, 114, 19, 71, 156, 183, 93, 135,
21, 161, 150, 41, 16, 123, 154, 199,
243, 145, 120, 111, 157, 158, 178, 177,
50, 117, 25, 61, 255, 53, 138, 126,
109, 84, 198, 128, 195, 189, 13, 87,
223, 245, 36, 169, 62, 168, 67, 201,
215, 121, 214, 246, 124, 34, 185, 3,
224, 15, 236, 222, 122, 148, 176, 188,
220, 232, 40, 80, 78, 51, 10, 74,
167, 151, 96, 115, 30, 0, 98, 68,
26, 184, 56, 130, 100, 159, 38, 65,
173, 69, 70, 146, 39, 94, 85, 47,
140, 163, 165, 125, 105, 213, 149, 59,
7, 88, 179, 64, 134, 172, 29, 247,
48, 55, 107, 228, 136, 217, 231, 137,
225, 27, 131, 73, 76, 63, 248, 254,
141, 83, 170, 144, 202, 216, 133, 97,
32, 113, 103, 164, 45, 43, 9, 91,
203, 155, 37, 208, 190, 229, 108, 82,
89, 166, 116, 210, 230, 244, 180, 192,
252, 238, 221, 17, 207, 110, 49, 22,
251, 196, 250, 218, 35, 197, 4, 77,
233, 119, 240, 219, 147, 46, 153, 186,
23, 54, 241, 187, 20, 205, 95, 193,
249, 24, 101, 90, 226, 92, 239, 33,
129, 28, 60, 66, 139, 1, 142, 79,
5, 132, 2, 174, 227, 106, 143, 160,
6, 11, 237, 152, 127, 212, 211, 31,
235, 52, 44, 81, 234, 200, 72, 171,
242, 42, 104, 162, 253, 58, 206, 204,
181, 112, 14, 86, 8, 12, 118, 18,
191, 114, 19, 71, 156, 183, 93, 135,
21, 161, 150, 41, 16, 123, 154, 199,
243, 145, 120, 111, 157, 158, 178, 177,
50, 117, 25, 61, 255, 53, 138, 126,
109, 84, 198, 128, 195, 189, 13, 87,
223, 245, 36, 169, 62, 168, 67, 201,
215, 121, 214, 246, 124, 34, 185, 3,
224, 15, 236, 222, 122, 148, 176, 188,
220, 232, 40, 80, 78, 51, 10, 74,
167, 151, 96, 115, 30, 0, 98, 68,
26, 184, 56, 130, 100, 159, 38, 65,
173, 69, 70, 146, 39, 94, 85, 47,
140, 163, 165, 125, 105, 213, 149, 59,
7, 88, 179, 64, 134, 172, 29, 247,
48, 55, 107, 228, 136, 217, 231, 137,
225, 27, 131, 73, 76, 63, 248, 254,
141, 83, 170, 144, 202, 216, 133, 97,
32, 113, 103, 164, 45, 43, 9, 91,
203, 155, 37, 208, 190, 229, 108, 82,
89, 166, 116, 210, 230, 244, 180, 192,
209, 102, 175, 194, 57, 75, 99, 182
};
Loading