Richard Levitte [Sat, 1 May 2021 06:36:55 +0000 (08:36 +0200)]
Make test programs less hard-coded
The following programs had a hard coded load of the gost engine.
This changes them to rely more on the testing environment, and to
load engines through configuration files.
This affects: test_ciphers.c, test_context.c, test_derive.c,
test_digest.c, test_params.c, test_sign.c, test_tls.c
Richard Levitte [Tue, 30 Mar 2021 19:53:38 +0000 (21:53 +0200)]
.github/workflows/codeql-analysis.yml: Bump the OpenSSL version
From 3.0.0-alpha6 to 3.0.0-alpha13, mostly for Analysis to avoid
getting failures when compiling, considering that the GOST source has
adapted for the latter version.
Richard Levitte [Mon, 22 Feb 2021 05:08:55 +0000 (06:08 +0100)]
Always cNORM before "\n"
Using cNORM after "\n" may or may not work, probably because of the
line buffered nature of standard output.
If an error is displayed immediately after a printf that has cNORM
after "\n", the error output sometimes "overrides" the cNORM, and you
may end up with a surprisingly colorful error message, not to mention
that this may also affect your prompt in the same manner.
The lesson is to always output cNORM before the ending "\n".
Richard Levitte [Sun, 21 Feb 2021 16:32:47 +0000 (17:32 +0100)]
Modify installation instructions for gost-engine library and module
- Simplify the installation of libraries and programs to simply use
defaults.
- Install only the gost engine in module form into the OpenSSL engine
directory.
- Install the gostsum and gost12sum manuals in the normal man1 directory,
as there's really no reason to install them among OpenSSL stuff
specifically.
- Install the cmake configuration file.
Richard Levitte [Wed, 17 Feb 2021 18:01:19 +0000 (19:01 +0100)]
Also build gost-engine in library form
In this form, the GOST engine isn't loadable through OpenSSL's dynamic
ENGINE loader, but directly as its own function, ENGINE_load_gost().
After making that call, the engine functionality can be used as usual.
This includes a public header file called gost-engine.h, which declares
that functions.
This also rearranges the code in gost_eng.c, as the binding
functionality was spread around in the file. Now, it's all nicely
tucked at the end.
Richard Levitte [Wed, 17 Feb 2021 05:07:20 +0000 (06:07 +0100)]
Fix gost engine suffix (for MacOS X)
On MacOS X, OpenSSL and cmake have different ideas on what suffix a
dynamically loadable module should have. OpenSSL expects .dylib,
while cmake uses .so by default.
Fixed by explicitly telling cmake to use the same suffix as for shared
libraries.
Richard Levitte [Sun, 14 Feb 2021 20:53:02 +0000 (21:53 +0100)]
Remove the use of test/run_tests in favor of 'prove'
'prove' is a well developed TAP harness program, there's no real need
to write one's own.
We do need to set certain paths properly for the appropriate 'openssl'
program to be run. We do that with a 'prove' plugin (WrapOpenSSL.pm)
that simply amends the appropriate system environment variables, given
a number of cmake generated environment variables that indicate where
OpenSSL files reside.
Richard Levitte [Sat, 13 Feb 2021 10:38:43 +0000 (11:38 +0100)]
Cleanup source organisation, and make 'gost' an actual module
GOST_CORE_SOURCE_FILES and GOST_ENGINE_SOURCE_FILES were a bit
disorganised, they are now re-arranged so GOST_ENGINE_SOURCE_FILES
contains ENGINE specific source only, and what was less ENGINE
specific was moved to GOST_CORE_SOURCE_FILES. Furthermore,
GOST_LIB_SOURCE_FILES now includes GOST_CORE_SOURCE_FILES, so the
gost_core library is complete with all implementations.
As a consequence, 'gost' is now explicitly made into a dlopenable
module. On some operating systems, that makes a difference.
This paves the way for alternative implementations based on the same
base code, such as a provider implementation.
It's quite possible that the re-arrangement done here isn't "pure"
enough. Future development will tell.
gost_crypt: process full available block in CFB and CNT mode
If at the input of the encryption function in the CFB mode we have
an integer number of blocks, then in the main loop all blocks will be
processed, except for the last one due to an incorrect border check.
The last block will be fully processed as a "partial" remainder, but
the initialization vector will not be updated. And, thus, the value
of IV will always be incorrect in this case.
This breaks stateless protocols due to an invalid initialization vector:
all messages except the first cannot be decrypted. (Naturally, we are
talking about a case with disabled key meshing, which does not allow
context recovery due to an erroneous implementation.)
It is worth noting here that the code for processing partial blocks
(both at the input of the encryption functions and at the output) is
a historically unnecessary artifact, since we do not set the
EVP_CIPH_FLAG_CUSTOM_CIPHER flag and, as a result, OpenSSL processes
partial blocks for us.
This patch corrects the checking of the main loop boundary.
A similar error is present in the code for the CNT mode, but there it
does not manifest itself in any way, because the restoration of the
state in this mode is impossible: even after disabling key meshing, we
still have the state-dependent transformation of the IV.
As an extra result of this fix, the code for processing partial blocks
can be completely removed now.
Igor Kirillov [Thu, 26 Nov 2020 15:26:03 +0000 (18:26 +0300)]
update magma cipher ctr_acpkm mode encrypting
Fixed bug when acpkm key meshing didn't apply at appropriate time
during TLS secure exchange.
Unify usage of 'num' variable of EVP_CIPHER_CTX for kuznetchik and
magma.
Provide cmake test if alignment requirement is strict
This is based on AX_CHECK_ALIGNED_ACCESS_REQUIRED from autoconf-archive.
Note, that on some arches unaligned access behavior could be changed at
runtime via prctl(1). Also, unaligned memory access is still slower (and
very slow on some arches) even if it's not strictly required.
Vitaly Chikunov [Wed, 13 May 2020 02:10:57 +0000 (05:10 +0300)]
Add static to functions that not need to be exported
After registration rework many callbacks not need to be exported. Also,
some functions inconsistently declared static in headers and non-static
in the code. Finally, some functions just not need to be exported.
Vitaly Chikunov [Tue, 12 May 2020 23:24:07 +0000 (02:24 +0300)]
Update Copyright lines after registration rework
- Add year 2020 to old lines.
- Some files did not have original Copyright line - added "Update
at 2020" to show that I'm not original contributor.
- Some files did not have License line - added reference to OpenSSL
license.
Vitaly Chikunov [Tue, 12 May 2020 09:26:01 +0000 (12:26 +0300)]
gost_crypt: Add some sanity checking to GOST_init_cipher
- Stream cipher should have block_size 1, other should not.
- Stream cipher should not have padding.
- If IV is specified Custom IV flag should be set.