X-Git-Url: http://wagner.pp.ru/gitweb/?a=blobdiff_plain;f=gost89.c;h=90d5515d9c7041c7305a9279afe69fe85350532d;hb=eea1e27c2b49d7604df939aeefaa7f45a5519fc8;hp=f940dab384b57cd0ca3ca76400077a498cb49ac5;hpb=53579492efb0cfa87405a7a4b1956ffec9506a22;p=openssl-gost%2Fengine.git diff --git a/gost89.c b/gost89.c index f940dab..90d5515 100644 --- a/gost89.c +++ b/gost89.c @@ -444,15 +444,13 @@ void gost_dec_cfb(gost_ctx * ctx, const byte * iv, const byte * cipher, void gost_enc_with_key(gost_ctx * c, byte * key, byte * inblock, byte * outblock) { - gost_key(c, key); + gost_key_nomask(c, key); gostcrypt(c, inblock, outblock); } -/* Set 256 bit gost89 key into context */ -void gost_key(gost_ctx * c, const byte * k) +static void gost_key_impl(gost_ctx * c, const byte * k) { int i, j; - RAND_bytes((unsigned char *)c->mask, sizeof(c->mask)); for (i = 0, j = 0; i < 8; ++i, j += 4) { c->key[i] = (k[j] | (k[j + 1] << 8) | (k[j + 2] << 16) | ((word32) k[j + 3] << @@ -460,11 +458,25 @@ void gost_key(gost_ctx * c, const byte * k) } } +/* Set 256 bit gost89 key into context */ +void gost_key(gost_ctx * c, const byte * k) +{ + RAND_priv_bytes((unsigned char *)c->mask, sizeof(c->mask)); + gost_key_impl(c, k); +} + +/* Set 256 bit gost89 key into context without key mask */ +void gost_key_nomask(gost_ctx * c, const byte * k) +{ + memset(c->mask, 0, sizeof(c->mask)); + gost_key_impl(c, k); +} + /* Set 256 bit Magma key into context */ void magma_key(gost_ctx * c, const byte * k) { int i, j; - RAND_bytes((unsigned char *)c->mask, sizeof(c->mask)); + RAND_priv_bytes((unsigned char *)c->mask, sizeof(c->mask)); for (i = 0, j = 0; i < 8; ++i, j += 4) { c->key[i] = (k[j + 3] | (k[j + 2] << 8) | (k[j + 1] << 16) | ((word32) k[j] << @@ -472,6 +484,10 @@ void magma_key(gost_ctx * c, const byte * k) } } +void magma_master_key(gost_ctx *c, const byte *k) { + memcpy(c->master_key, k, sizeof(c->master_key)); +} + /* Retrieve 256-bit gost89 key from context */ void gost_get_key(gost_ctx * c, byte * k) { @@ -508,6 +524,7 @@ void gost_init(gost_ctx * c, const gost_subst_block * b) /* Cleans up key from context */ void gost_destroy(gost_ctx * c) { + OPENSSL_cleanse(c->master_key, sizeof(c->master_key)); OPENSSL_cleanse(c->key, sizeof(c->key)); OPENSSL_cleanse(c->mask, sizeof(c->mask)); }