Skip to content

Commit ed4eab6

Browse files
authored
Merge pull request gost-engine#517 from Mironenko/keyexpimp3
Extract kexp15, kimp15, kdftree2012_256 and tlstree implementations into a separate module
2 parents 2ae0310 + 27e0df7 commit ed4eab6

17 files changed

Lines changed: 538 additions & 392 deletions

CMakeLists.txt

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,12 @@ set(GOST_HASH_2012_SOURCE_FILES
138138
gosthash2012_sse2.h
139139
)
140140

141+
set(GOST_TLS12_ADDITIONAL_SOURCE_FILES
142+
gost_tls12_additional_kdftree.c
143+
gost_tls12_additional_kexpimp.c
144+
gost_tls12_additional_tlstree.c
145+
)
146+
141147
set(GOST_GRASSHOPPER_SOURCE_FILES
142148
gost_grasshopper.h
143149
gost_grasshopper_core.h
@@ -309,11 +315,14 @@ add_test(NAME context-with-provider COMMAND test_context)
309315
set_tests_properties(context-with-provider
310316
PROPERTIES ENVIRONMENT "${TEST_ENVIRONMENT_PROVIDER}")
311317

312-
# test_keyexpimp is an internals testing program, it doesn't need a test env
313-
add_executable(test_keyexpimp test_keyexpimp.c)
314-
#target_compile_definitions(test_keyexpimp PUBLIC -DOPENSSL_LOAD_CONF)
315-
target_link_libraries(test_keyexpimp gost_core gost_err)
316-
add_test(NAME keyexpimp COMMAND test_keyexpimp)
318+
add_executable(test_tls12additional test_tls12additional.c)
319+
target_link_libraries(test_tls12additional gost_err gosttls12additional OpenSSL::Crypto)
320+
add_test(NAME tls12additional-with-engine COMMAND test_tls12additional)
321+
set_tests_properties(tls12additional-with-engine
322+
PROPERTIES ENVIRONMENT "${TEST_ENVIRONMENT_ENGINE}")
323+
add_test(NAME tls12additional-with-provider COMMAND test_tls12additional)
324+
set_tests_properties(tls12additional-with-provider
325+
PROPERTIES ENVIRONMENT "${TEST_ENVIRONMENT_PROVIDER}")
317326

318327
# test_gost89 is an internals testing program, it doesn't need a test env
319328
add_executable(test_gost89 test_gost89.c)
@@ -377,7 +386,7 @@ set(BINARY_TESTS_TARGETS
377386
test_derive
378387
test_sign
379388
test_context
380-
test_keyexpimp
389+
test_tls12additional
381390
test_gost89
382391
test_tls
383392
test_gosthash
@@ -397,9 +406,13 @@ add_library(gosthash2012 STATIC ${GOST_HASH_2012_SOURCE_FILES})
397406
set_target_properties(gosthash2012 PROPERTIES POSITION_INDEPENDENT_CODE ON)
398407
target_link_libraries(gosthash2012 PRIVATE OpenSSL::Crypto)
399408

409+
add_library(gosttls12additional STATIC ${GOST_TLS12_ADDITIONAL_SOURCE_FILES})
410+
set_target_properties(gosttls12additional PROPERTIES POSITION_INDEPENDENT_CODE ON)
411+
target_link_libraries(gosttls12additional PRIVATE OpenSSL::Crypto gost_err)
412+
400413
add_library(gost_core STATIC ${GOST_LIB_SOURCE_FILES})
401414
set_target_properties(gost_core PROPERTIES POSITION_INDEPENDENT_CODE ON)
402-
target_link_libraries(gost_core PRIVATE OpenSSL::Crypto gost89 gosthash gosthash2012)
415+
target_link_libraries(gost_core PRIVATE OpenSSL::Crypto gost89 gosthash gosthash2012 gosttls12additional)
403416

404417
add_library(gost_err STATIC ${GOST_ERR_SOURCE_FILES})
405418
set_target_properties(gost_err PROPERTIES POSITION_INDEPENDENT_CODE ON)

gost_crypt.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "e_gost_err.h"
1616
#include "gost_lcl.h"
1717
#include "gost_gost2015.h"
18+
#include "gost_tls12_additional.h"
1819

1920
#if !defined(CCGOST_DEBUG) && !defined(DEBUG)
2021
# ifndef NDEBUG
@@ -1164,7 +1165,7 @@ static int gost_magma_mgm_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr)
11641165
case EVP_CTRL_TLSTREE:
11651166
{
11661167
unsigned char newkey[32];
1167-
if (gost_tlstree(OBJ_sn2nid(SN_magma_mgm),
1168+
if (gost_tlstree_magma_mgm(
11681169
(const unsigned char *)mctx->ks.g_ks.cctx.master_key,
11691170
newkey, (const unsigned char *)ptr, mctx->tlstree_mode)
11701171
> 0) {
@@ -1336,7 +1337,7 @@ static int magma_cipher_ctl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr)
13361337
return -1;
13371338
}
13381339

1339-
if (gost_tlstree(NID_magma_cbc, (const unsigned char *)c->master_key, newkey,
1340+
if (gost_tlstree_magma_cbc((const unsigned char *)c->master_key, newkey,
13401341
(const unsigned char *)seq, TLSTREE_MODE_NONE) > 0) {
13411342
memset(adjusted_iv, 0, 8);
13421343
memcpy(adjusted_iv, EVP_CIPHER_CTX_original_iv(ctx), 4);

gost_ec_keyx.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "e_gost_err.h"
2323
#include "gost_keywrap.h"
2424
#include "gost_lcl.h"
25+
#include "gost_tls12_additional.h"
2526

2627
int internal_compute_ecdh(unsigned char *out, size_t *out_len,
2728
const unsigned char *ukm, size_t ukm_size,

gost_gost2015.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "gost_gost2015.h"
99
#include "gost_grasshopper_defines.h"
1010
#include "gost_grasshopper_math.h"
11+
#include "gost_tls12_additional.h"
1112
#include "e_gost_err.h"
1213
#include <string.h>
1314
#include <openssl/rand.h>

gost_grasshopper_cipher.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <string.h>
1717

1818
#include "gost_lcl.h"
19+
#include "gost_tls12_additional.h"
1920
#include "e_gost_err.h"
2021

2122
enum GRASSHOPPER_CIPHER_TYPE {
@@ -1105,7 +1106,7 @@ static int gost_grasshopper_mgm_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void
11051106
case EVP_CTRL_TLSTREE:
11061107
{
11071108
unsigned char newkey[32];
1108-
if (gost_tlstree(OBJ_sn2nid(SN_kuznyechik_mgm),
1109+
if (gost_tlstree_grasshopper_mgm(
11091110
mctx->ks.gh_ks.master_key.k.b, newkey,
11101111
(const unsigned char *)ptr, mctx->tlstree_mode)
11111112
> 0) {
@@ -1174,7 +1175,7 @@ static int gost_grasshopper_cipher_ctl(EVP_CIPHER_CTX *ctx, int type, int arg, v
11741175
return -1;
11751176
}
11761177

1177-
if (gost_tlstree(NID_grasshopper_cbc, c->master_key.k.b, newkey,
1178+
if (gost_tlstree_grasshopper_cbc(c->master_key.k.b, newkey,
11781179
(const unsigned char *)seq, TLSTREE_MODE_NONE) > 0) {
11791180
memset(adjusted_iv, 0, 16);
11801181
memcpy(adjusted_iv, EVP_CIPHER_CTX_original_iv(ctx), 8);

0 commit comments

Comments
 (0)