{ERR_PACK(0, 0, GOST_R_ERROR_SETTING_PEER_KEY), "error setting peer key"},
{ERR_PACK(0, 0, GOST_R_INCOMPATIBLE_ALGORITHMS), "incompatible algorithms"},
{ERR_PACK(0, 0, GOST_R_INCOMPATIBLE_PEER_KEY), "incompatible peer key"},
+ {ERR_PACK(0, 0, GOST_R_INVALID_BUFFER_SIZE), "invalid buffer size"},
{ERR_PACK(0, 0, GOST_R_INVALID_CIPHER), "invalid cipher"},
{ERR_PACK(0, 0, GOST_R_INVALID_CIPHER_PARAMS), "invalid cipher params"},
{ERR_PACK(0, 0, GOST_R_INVALID_CIPHER_PARAM_OID),
# define GOST_R_ERROR_SETTING_PEER_KEY 139
# define GOST_R_INCOMPATIBLE_ALGORITHMS 108
# define GOST_R_INCOMPATIBLE_PEER_KEY 109
+# define GOST_R_INVALID_BUFFER_SIZE 140
# define GOST_R_INVALID_CIPHER 134
# define GOST_R_INVALID_CIPHER_PARAMS 110
# define GOST_R_INVALID_CIPHER_PARAM_OID 111
int exp_len = 0, iv_len = 0;
unsigned char *exp_buf = NULL;
int key_is_ephemeral = 0;
+ int res_len = 0;
switch (data->cipher_nid) {
case NID_magma_ctr:
goto err;
}
- if ((*out_len = i2d_PSKeyTransport_gost(pst, out ? &out : NULL)) > 0)
+ res_len = i2d_PSKeyTransport_gost(pst, NULL);
+ if (res_len <= 0) {
+ GOSTerr(GOST_F_PKEY_GOST2018_ENCRYPT, ERR_R_ASN1_LIB);
+ goto err;
+ }
+
+ if (out == NULL) {
+ *out_len = res_len;
ret = 1;
+ } else {
+ if ((size_t)res_len > *out_len) {
+ GOSTerr(GOST_F_PKEY_GOST2018_ENCRYPT, GOST_R_INVALID_BUFFER_SIZE);
+ goto err;
+ }
+ if ((*out_len = i2d_PSKeyTransport_gost(pst, &out)) > 0)
+ ret = 1;
+ else
+ GOSTerr(GOST_F_PKEY_GOST2018_ENCRYPT, ERR_R_ASN1_LIB);
+ }
+
err:
OPENSSL_cleanse(expkeys, sizeof(expkeys));
if (key_is_ephemeral)