Group :: System/Libraries
RPM: openssl-gost-engine
Main Changelog Spec Patches Sources Download Gear Bugs and FR Repocop
Patch: openssl-gost-engine-1.1.0.3.0.255.ge3af41d-gost89-ecb.patch
Download
Download
gost_crypt.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
gost_eng.c | 4 ++++
gost_lcl.h | 1 +
test/00-engine.t | 2 +-
4 files changed, 65 insertions(+), 1 deletion(-)
diff --git a/gost_crypt.c b/gost_crypt.c
index 930d40a..d7580a9 100644
--- a/gost_crypt.c
+++ b/gost_crypt.c
@@ -20,6 +20,8 @@
#endif
#include <assert.h>
+static int gost_cipher_init_ecb(EVP_CIPHER_CTX *ctx, const unsigned char *key,
+ const unsigned char *iv, int enc);
static int gost_cipher_init(EVP_CIPHER_CTX *ctx, const unsigned char *key,
const unsigned char *iv, int enc);
static int gost_cipher_init_cbc(EVP_CIPHER_CTX *ctx, const unsigned char *key,
@@ -29,6 +31,9 @@ static int gost_cipher_init_cpa(EVP_CIPHER_CTX *ctx, const unsigned char *key,
static int gost_cipher_init_cp_12(EVP_CIPHER_CTX *ctx,
const unsigned char *key,
const unsigned char *iv, int enc);
+/* Handles block of data in ECB mode */
+static int gost_cipher_do_ecb(EVP_CIPHER_CTX *ctx, unsigned char *out,
+ const unsigned char *in, size_t inl);
/* Handles block of data in CFB mode */
static int gost_cipher_do_cfb(EVP_CIPHER_CTX *ctx, unsigned char *out,
const unsigned char *in, size_t inl);
@@ -54,6 +59,43 @@ static int magma_cipher_do_cbc(EVP_CIPHER_CTX *ctx, unsigned char *out,
static int magma_cipher_do_ctr(EVP_CIPHER_CTX *ctx, unsigned char *out,
const unsigned char *in, size_t inl);
+static EVP_CIPHER *_hidden_Gost28147_89_ecb = NULL;
+const EVP_CIPHER *cipher_gost_ecb(void)
+{
+ if (_hidden_Gost28147_89_ecb == NULL
+ && ((_hidden_Gost28147_89_ecb =
+ EVP_CIPHER_meth_new(NID_gost89_ecb, 1 /* block_size */ ,
+ 32 /* key_size */ )) == NULL
+ || !EVP_CIPHER_meth_set_iv_length(_hidden_Gost28147_89_ecb, 8)
+ || !EVP_CIPHER_meth_set_flags(_hidden_Gost28147_89_ecb,
+ EVP_CIPH_ECB_MODE |
+ EVP_CIPH_NO_PADDING |
+ EVP_CIPH_CUSTOM_IV |
+ EVP_CIPH_RAND_KEY |
+ EVP_CIPH_ALWAYS_CALL_INIT)
+ || !EVP_CIPHER_meth_set_init(_hidden_Gost28147_89_ecb,
+ gost_cipher_init_ecb)
+ || !EVP_CIPHER_meth_set_do_cipher(_hidden_Gost28147_89_ecb,
+ gost_cipher_do_ecb)
+ || !EVP_CIPHER_meth_set_cleanup(_hidden_Gost28147_89_ecb,
+ gost_cipher_cleanup)
+ || !EVP_CIPHER_meth_set_impl_ctx_size(_hidden_Gost28147_89_ecb,
+ sizeof(struct
+ ossl_gost_cipher_ctx))
+ ||
+ !EVP_CIPHER_meth_set_set_asn1_params(_hidden_Gost28147_89_ecb,
+ gost89_set_asn1_parameters)
+ ||
+ !EVP_CIPHER_meth_set_get_asn1_params(_hidden_Gost28147_89_ecb,
+ gost89_get_asn1_parameters)
+ || !EVP_CIPHER_meth_set_ctrl(_hidden_Gost28147_89_ecb,
+ gost_cipher_ctl))) {
+ EVP_CIPHER_meth_free(_hidden_Gost28147_89_ecb);
+ _hidden_Gost28147_89_ecb = NULL;
+ }
+ return _hidden_Gost28147_89_ecb;
+}
+
static EVP_CIPHER *_hidden_Gost28147_89_cipher = NULL;
const EVP_CIPHER *cipher_gost(void)
{
@@ -513,6 +555,14 @@ static int gost_cipher_init_cp_12(EVP_CIPHER_CTX *ctx,
return gost_cipher_init_cnt(ctx, key, iv, &Gost28147_TC26ParamSetZ);
}
+/* Initializes EVP_CIPHER_CTX with default values, in ECB mode */
+int gost_cipher_init_ecb(EVP_CIPHER_CTX *ctx, const unsigned char *key,
+ const unsigned char *iv, int enc)
+{
+ return gost_cipher_init_param(ctx, key, iv, enc, NID_undef,
+ EVP_CIPH_ECB_MODE);
+}
+
/* Initializes EVP_CIPHER_CTX with default values */
int gost_cipher_init(EVP_CIPHER_CTX *ctx, const unsigned char *key,
const unsigned char *iv, int enc)
@@ -586,6 +636,15 @@ static void gost_cnt_next(void *ctx, unsigned char *iv, unsigned char *buf)
c->count = c->count % 1024 + 8;
}
+/* GOST encryption in ECB mode */
+int gost_cipher_do_ecb(EVP_CIPHER_CTX *ctx, unsigned char *out,
+ const unsigned char *in, size_t inl)
+{
+ struct ossl_gost_cipher_ctx *c = EVP_CIPHER_CTX_get_cipher_data(ctx);
+ gost_enc(&(c->cctx), in, out, inl/8);
+ return 1;
+}
+
/* GOST encryption in CBC mode */
int gost_cipher_do_cbc(EVP_CIPHER_CTX *ctx, unsigned char *out,
const unsigned char *in, size_t inl)
diff --git a/gost_eng.c b/gost_eng.c
index 69f9975..fabb554 100644
--- a/gost_eng.c
+++ b/gost_eng.c
@@ -38,6 +38,7 @@ static int gost_pkey_asn1_meths(ENGINE* e, EVP_PKEY_ASN1_METHOD** ameth,
const int** nids, int nid);
static int gost_cipher_nids[] = {
+ NID_gost89_ecb,
NID_id_Gost28147_89,
NID_gost89_cnt,
NID_gost89_cnt_12,
@@ -270,6 +271,7 @@ static int bind_gost(ENGINE* e, const char* id) {
|| !ENGINE_register_digests(e)
|| !ENGINE_register_pkey_meths(e)
/* These two actually should go in LIST_ADD command */
+ || !EVP_add_cipher(cipher_gost_ecb())
|| !EVP_add_cipher(cipher_gost())
|| !EVP_add_cipher(cipher_gost_cbc())
|| !EVP_add_cipher(cipher_gost_cpacnt())
@@ -358,6 +360,8 @@ static int gost_ciphers(ENGINE* e, const EVP_CIPHER** cipher,
*cipher = cipher_gost_cpcnt_12();
} else if (nid == NID_gost89_cbc) {
*cipher = cipher_gost_cbc();
+ } else if (nid == NID_gost89_ecb) {
+ *cipher = cipher_gost_ecb();
} else if (nid == NID_grasshopper_ecb) {
*cipher = cipher_gost_grasshopper_ecb();
} else if (nid == NID_grasshopper_cbc) {
diff --git a/gost_lcl.h b/gost_lcl.h
index 78c6523..737c955 100644
--- a/gost_lcl.h
+++ b/gost_lcl.h
@@ -240,6 +240,7 @@ extern struct gost_cipher_info gost_cipher_list[];
/* Find encryption params from ASN1_OBJECT */
const struct gost_cipher_info *get_encryption_params(ASN1_OBJECT *obj);
/* Implementation of GOST 28147-89 cipher in CFB and CNT modes */
+const EVP_CIPHER *cipher_gost_ecb();
const EVP_CIPHER *cipher_gost();
const EVP_CIPHER *cipher_gost_cbc();
const EVP_CIPHER *cipher_gost_cpacnt();
diff --git a/test/00-engine.t b/test/00-engine.t
index e6685aa..fd24e88 100644
--- a/test/00-engine.t
+++ b/test/00-engine.t
@@ -43,7 +43,7 @@ if ( -f $engine . ".info") {
$engine_info= <<EOINF;
(gost) Reference implementation of GOST engine
- [gost89, gost89-cnt, gost89-cnt-12, gost89-cbc, grasshopper-ecb, grasshopper-cbc, grasshopper-cfb, grasshopper-ofb, grasshopper-ctr, magma-cbc, magma-ctr, id-tc26-cipher-gostr3412-2015-kuznyechik-ctracpkm, md_gost94, gost-mac, md_gost12_256, md_gost12_512, gost-mac-12, magma-mac, grasshopper-mac, id-tc26-cipher-gostr3412-2015-kuznyechik-ctracpkm-omac, gost2001, gost-mac, gost2012_256, gost2012_512, gost-mac-12, magma-mac, grasshopper-mac, id-tc26-cipher-gostr3412-2015-magma-ctracpkm-omac, id-tc26-cipher-gostr3412-2015-kuznyechik-ctracpkm-omac]
+ [gost89-ecb, gost89, gost89-cnt, gost89-cnt-12, gost89-cbc, grasshopper-ecb, grasshopper-cbc, grasshopper-cfb, grasshopper-ofb, grasshopper-ctr, magma-cbc, magma-ctr, id-tc26-cipher-gostr3412-2015-kuznyechik-ctracpkm, md_gost94, gost-mac, md_gost12_256, md_gost12_512, gost-mac-12, magma-mac, grasshopper-mac, id-tc26-cipher-gostr3412-2015-kuznyechik-ctracpkm-omac, gost2001, gost-mac, gost2012_256, gost2012_512, gost-mac-12, magma-mac, grasshopper-mac, id-tc26-cipher-gostr3412-2015-magma-ctracpkm-omac, id-tc26-cipher-gostr3412-2015-kuznyechik-ctracpkm-omac]
EOINF
}