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

WIP: MGM mode for magma/kuznyechik cipher. Initial implementation. #393

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
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,15 @@ add_test(NAME ciphers-with-provider COMMAND test_ciphers)
set_tests_properties(ciphers-with-provider
PROPERTIES ENVIRONMENT "${TEST_ENVIRONMENT_PROVIDER}")

add_executable(test_mgm test_mgm.c)
target_link_libraries(test_mgm OpenSSL::Crypto)
add_test(NAME mgm-with-engine COMMAND test_mgm)
set_tests_properties(mgm-with-engine
PROPERTIES ENVIRONMENT "${TEST_ENVIRONMENT_ENGINE}")
add_test(NAME mgm-with-provider COMMAND test_mgm)
set_tests_properties(mgm-with-provider
PROPERTIES ENVIRONMENT "${TEST_ENVIRONMENT_PROVIDER}")

# test_curves is an internals testing program, it doesn't need a test env
add_executable(test_curves test_curves.c)
target_link_libraries(test_curves gost_core gost_err)
Expand Down Expand Up @@ -328,6 +337,7 @@ set(BINARY_TESTS_TARGETS
test_keyexpimp
test_gost89
test_tls
test_mgm
)
set_property(TARGET ${BINARY_TESTS_TARGETS} APPEND PROPERTY COMPILE_DEFINITIONS ENGINE_DIR="${OUTPUT_DIRECTORY}")

Expand Down
14 changes: 14 additions & 0 deletions e_gost_err.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,14 @@ static ERR_STRING_DATA GOST_str_functs[] = {
"gost_grasshopper_cipher_ctl"},
{ERR_PACK(0, GOST_F_GOST_GRASSHOPPER_CIPHER_DO_CTRACPKM_OMAC, 0),
"gost_grasshopper_cipher_do_ctracpkm_omac"},
{ERR_PACK(0, GOST_F_GOST_GRASSHOPPER_CIPHER_DO_MGM, 0),
"gost_grasshopper_cipher_do_mgm"},
{ERR_PACK(0, GOST_F_GOST_GRASSHOPPER_CIPHER_INIT, 0),
"gost_grasshopper_cipher_init"},
{ERR_PACK(0, GOST_F_GOST_GRASSHOPPER_CIPHER_INIT_CTRACPKM_OMAC, 0),
"gost_grasshopper_cipher_init_ctracpkm_omac"},
{ERR_PACK(0, GOST_F_GOST_GRASSHOPPER_MGM_CTRL, 0),
"gost_grasshopper_mgm_ctrl"},
{ERR_PACK(0, GOST_F_GOST_GRASSHOPPER_SET_ASN1_PARAMETERS, 0),
"gost_grasshopper_set_asn1_parameters"},
{ERR_PACK(0, GOST_F_GOST_IMIT_CTRL, 0), "gost_imit_ctrl"},
Expand All @@ -64,6 +70,12 @@ static ERR_STRING_DATA GOST_str_functs[] = {
{ERR_PACK(0, GOST_F_GOST_KDFTREE2012_256, 0), "gost_kdftree2012_256"},
{ERR_PACK(0, GOST_F_GOST_KEXP15, 0), "gost_kexp15"},
{ERR_PACK(0, GOST_F_GOST_KIMP15, 0), "gost_kimp15"},
{ERR_PACK(0, GOST_F_GOST_MAGMA_CIPHER_DO_MGM, 0),
"gost_magma_cipher_do_mgm"},
{ERR_PACK(0, GOST_F_GOST_MAGMA_MGM_CTRL, 0), "gost_magma_mgm_ctrl"},
{ERR_PACK(0, GOST_F_GOST_MGM128_AAD, 0), "gost_mgm128_aad"},
{ERR_PACK(0, GOST_F_GOST_MGM128_DECRYPT, 0), "gost_mgm128_decrypt"},
{ERR_PACK(0, GOST_F_GOST_MGM128_ENCRYPT, 0), "gost_mgm128_encrypt"},
{ERR_PACK(0, GOST_F_MAGMA_CIPHER_CTL, 0), "magma_cipher_ctl"},
{ERR_PACK(0, GOST_F_MAGMA_CIPHER_CTL_ACPKM_OMAC, 0),
"magma_cipher_ctl_acpkm_omac"},
Expand Down Expand Up @@ -129,6 +141,7 @@ static ERR_STRING_DATA GOST_str_reasons[] = {
"cannot unpack ephemeral key"},
{ERR_PACK(0, 0, GOST_R_CIPHER_NOT_FOUND), "cipher not found"},
{ERR_PACK(0, 0, GOST_R_CTRL_CALL_FAILED), "ctrl call failed"},
{ERR_PACK(0, 0, GOST_R_DATA_TOO_LARGE), "data too large"},
{ERR_PACK(0, 0, GOST_R_ERROR_COMPUTING_EXPORT_KEYS),
"error computing export keys"},
{ERR_PACK(0, 0, GOST_R_ERROR_COMPUTING_SHARED_KEY),
Expand All @@ -152,6 +165,7 @@ static ERR_STRING_DATA GOST_str_reasons[] = {
{ERR_PACK(0, 0, GOST_R_INVALID_MAC_PARAMS), "invalid mac params"},
{ERR_PACK(0, 0, GOST_R_INVALID_MAC_SIZE), "invalid mac size"},
{ERR_PACK(0, 0, GOST_R_INVALID_PARAMSET), "invalid paramset"},
{ERR_PACK(0, 0, GOST_R_INVALID_TAG_LENGTH), "invalid tag length"},
{ERR_PACK(0, 0, GOST_R_KEY_IS_NOT_INITIALIZED), "key is not initialized"},
{ERR_PACK(0, 0, GOST_R_KEY_PARAMETERS_MISSING), "key parameters missing"},
{ERR_PACK(0, 0, GOST_R_MAC_KEY_NOT_SET), "mac key not set"},
Expand Down
10 changes: 10 additions & 0 deletions e_gost_err.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,22 @@ void ERR_GOST_error(int function, int reason, char *file, int line);
# define GOST_F_GOST_ENCODE_CMS_PARAMS 161
# define GOST_F_GOST_GRASSHOPPER_CIPHER_CTL 111
# define GOST_F_GOST_GRASSHOPPER_CIPHER_DO_CTRACPKM_OMAC 160
# define GOST_F_GOST_GRASSHOPPER_CIPHER_DO_MGM 166
# define GOST_F_GOST_GRASSHOPPER_CIPHER_INIT 167
# define GOST_F_GOST_GRASSHOPPER_CIPHER_INIT_CTRACPKM_OMAC 162
# define GOST_F_GOST_GRASSHOPPER_MGM_CTRL 168
# define GOST_F_GOST_GRASSHOPPER_SET_ASN1_PARAMETERS 112
# define GOST_F_GOST_IMIT_CTRL 113
# define GOST_F_GOST_IMIT_FINAL 114
# define GOST_F_GOST_IMIT_UPDATE 115
# define GOST_F_GOST_KDFTREE2012_256 149
# define GOST_F_GOST_KEXP15 143
# define GOST_F_GOST_KIMP15 148
# define GOST_F_GOST_MAGMA_CIPHER_DO_MGM 170
# define GOST_F_GOST_MAGMA_MGM_CTRL 169
# define GOST_F_GOST_MGM128_AAD 171
# define GOST_F_GOST_MGM128_DECRYPT 172
# define GOST_F_GOST_MGM128_ENCRYPT 173
# define GOST_F_MAGMA_CIPHER_CTL 163
# define GOST_F_MAGMA_CIPHER_CTL_ACPKM_OMAC 164
# define GOST_F_MAGMA_CIPHER_INIT_CTR_ACPKM_OMAC 165
Expand Down Expand Up @@ -107,6 +115,7 @@ void ERR_GOST_error(int function, int reason, char *file, int line);
# define GOST_R_CANNOT_UNPACK_EPHEMERAL_KEY 136
# define GOST_R_CIPHER_NOT_FOUND 103
# define GOST_R_CTRL_CALL_FAILED 104
# define GOST_R_DATA_TOO_LARGE 141
# define GOST_R_ERROR_COMPUTING_EXPORT_KEYS 135
# define GOST_R_ERROR_COMPUTING_SHARED_KEY 105
# define GOST_R_ERROR_DECODING_PUBLIC_KEY 138
Expand All @@ -125,6 +134,7 @@ void ERR_GOST_error(int function, int reason, char *file, int line);
# define GOST_R_INVALID_MAC_PARAMS 116
# define GOST_R_INVALID_MAC_SIZE 117
# define GOST_R_INVALID_PARAMSET 118
# define GOST_R_INVALID_TAG_LENGTH 140
# define GOST_R_KEY_IS_NOT_INITIALIZED 119
# define GOST_R_KEY_PARAMETERS_MISSING 120
# define GOST_R_MAC_KEY_NOT_SET 121
Expand Down
Loading