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

Added missing buffer cleanses for some sensitive buffers #454

Open
wants to merge 1 commit 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
6 changes: 5 additions & 1 deletion gost_crypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@ static int magma_cipher_init_ctr_acpkm_omac(EVP_CIPHER_CTX *ctx, const unsigned
if (key) {
struct ossl_gost_cipher_ctx *c = EVP_CIPHER_CTX_get_cipher_data(ctx);
unsigned char cipher_key[32];
int ret;
c->omac_ctx = EVP_MD_CTX_new();

if (c->omac_ctx == NULL) {
Expand All @@ -543,7 +544,9 @@ static int magma_cipher_init_ctr_acpkm_omac(EVP_CIPHER_CTX *ctx, const unsigned
return 0;
}

return magma_cipher_init(ctx, cipher_key, iv, enc);
ret = magma_cipher_init(ctx, cipher_key, iv, enc);
OPENSSL_cleanse(cipher_key, sizeof(cipher_key));
return ret;
}

return magma_cipher_init(ctx, key, iv, enc);
Expand Down Expand Up @@ -1324,6 +1327,7 @@ static int magma_cipher_ctl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr)
memcpy(EVP_CIPHER_CTX_iv_noconst(ctx), adjusted_iv, 8);

magma_key(c, newkey);
OPENSSL_cleanse(newkey, sizeof(newkey));
return 1;
}
}
Expand Down
7 changes: 6 additions & 1 deletion gost_grasshopper_cipher.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ static void acpkm_next(gost_grasshopper_cipher_ctx * c)
&c->buffer);
}
gost_grasshopper_cipher_key(c, newkey);
OPENSSL_cleanse(newkey, sizeof(newkey));
}

/* Set 256 bit key into context */
Expand Down Expand Up @@ -351,6 +352,7 @@ gost_grasshopper_cipher_init_ctracpkm_omac(EVP_CIPHER_CTX

if (key) {
unsigned char cipher_key[32];
int ret;
c->omac_ctx = EVP_MD_CTX_new();

if (c->omac_ctx == NULL) {
Expand All @@ -365,7 +367,9 @@ gost_grasshopper_cipher_init_ctracpkm_omac(EVP_CIPHER_CTX
return 0;
}

return gost_grasshopper_cipher_init(ctx, cipher_key, iv, enc);
ret = gost_grasshopper_cipher_init(ctx, cipher_key, iv, enc);
OPENSSL_cleanse(cipher_key, sizeof(cipher_key));
return ret;
}

return gost_grasshopper_cipher_init(ctx, key, iv, enc);
Expand Down Expand Up @@ -1158,6 +1162,7 @@ static int gost_grasshopper_cipher_ctl(EVP_CIPHER_CTX *ctx, int type, int arg, v
memcpy(EVP_CIPHER_CTX_iv_noconst(ctx), adjusted_iv, 16);

gost_grasshopper_cipher_key(c, newkey);
OPENSSL_cleanse(newkey, sizeof(newkey));
return 1;
}
}
Expand Down
10 changes: 6 additions & 4 deletions gost_keyexpimp.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ int gost_tlstree(int cipher_nid, const unsigned char *in, unsigned char *out,
uint64_t seed1, seed2, seed3;
uint64_t seq;
unsigned char ko1[32], ko2[32];
int ret;

switch (cipher_nid) {
case NID_magma_cbc:
Expand All @@ -293,15 +294,16 @@ int gost_tlstree(int cipher_nid, const unsigned char *in, unsigned char *out,
seed2 = seq & c2;
seed3 = seq & c3;

if (gost_kdftree2012_256(ko1, 32, in, 32, (const unsigned char *)"level1", 6,
ret = !(gost_kdftree2012_256(ko1, 32, in, 32, (const unsigned char *)"level1", 6,
(const unsigned char *)&seed1, 8, 1) <= 0
|| gost_kdftree2012_256(ko2, 32, ko1, 32, (const unsigned char *)"level2", 6,
(const unsigned char *)&seed2, 8, 1) <= 0
|| gost_kdftree2012_256(out, 32, ko2, 32, (const unsigned char *)"level3", 6,
(const unsigned char *)&seed3, 8, 1) <= 0)
return 0;
(const unsigned char *)&seed3, 8, 1) <= 0);

return 1;
OPENSSL_cleanse(ko1, sizeof(ko1));
OPENSSL_cleanse(ko2, sizeof(ko2));
return ret;
}

#define GOST_WRAP_FLAGS EVP_CIPH_CTRL_INIT | EVP_CIPH_WRAP_MODE | EVP_CIPH_CUSTOM_IV | EVP_CIPH_FLAG_CUSTOM_CIPHER | EVP_CIPH_FLAG_DEFAULT_ASN1
Expand Down
1 change: 1 addition & 0 deletions gost_omac.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ int omac_imit_ctrl(EVP_MD_CTX *ctx, int type, int arg, void *ptr)
|| (cipher = EVP_CIPHER_fetch(NULL, c->cipher_name, NULL)))
ret = omac_key(c, cipher, diversed_key, 32);
EVP_CIPHER_free(cipher);
OPENSSL_cleanse(diversed_key, sizeof(diversed_key));
}
return ret;
}
Expand Down
Loading