Example #1
0
static int
gost2814789_md_ctrl(EVP_MD_CTX *ctx, int cmd, int p1, void *p2)
{
	GOST2814789IMIT_CTX *gctx = ctx->md_data;

	switch (cmd) {
	case EVP_MD_CTRL_SET_KEY:
		return Gost2814789_set_key(&gctx->cipher, p2, p1);
	case EVP_MD_CTRL_GOST_SET_SBOX:
		return Gost2814789_set_sbox(&gctx->cipher, p1);
	}
	return -2;
}
Example #2
0
static int
gost2814789_ctl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr)
{
	EVP_GOST2814789_CTX *c = ctx->cipher_data;

	switch (type) {
	case EVP_CTRL_PBE_PRF_NID:
		if (ptr != NULL) {
			*((int *)ptr) = NID_id_HMACGostR3411_94;
			return 1;
		} else {
			return 0;
		}
	case EVP_CTRL_INIT:
		/* Default value to have any s-box set at all */
		c->param_nid = NID_id_Gost28147_89_CryptoPro_A_ParamSet;
		return Gost2814789_set_sbox(&c->ks, c->param_nid);
	case EVP_CTRL_GOST_SET_SBOX:
		return Gost2814789_set_sbox(&c->ks, arg);
	default:
		return -1;
	}
}
Example #3
0
int
gost2814789_get_asn1_params(EVP_CIPHER_CTX *ctx, ASN1_TYPE *params)
{
	int ret = -1;
	int len;
	GOST_CIPHER_PARAMS *gcp = NULL;
	EVP_GOST2814789_CTX *c = ctx->cipher_data;
	unsigned char *p;

	if (ASN1_TYPE_get(params) != V_ASN1_SEQUENCE)
		return ret;

	p = params->value.sequence->data;

	gcp = d2i_GOST_CIPHER_PARAMS(NULL, (const unsigned char **)&p,
	    params->value.sequence->length);

	len = gcp->iv->length;
	if (len != ctx->cipher->iv_len) {
		GOST_CIPHER_PARAMS_free(gcp);
		GOSTerr(GOST_F_GOST89_GET_ASN1_PARAMETERS,
		    GOST_R_INVALID_IV_LENGTH);
		return -1;
	}

	if (!Gost2814789_set_sbox(&c->ks, OBJ_obj2nid(gcp->enc_param_set))) {
		GOST_CIPHER_PARAMS_free(gcp);
		return -1;
	}
	c->param_nid = OBJ_obj2nid(gcp->enc_param_set);

	memcpy(ctx->oiv, gcp->iv->data, len);
	memcpy(ctx->iv, gcp->iv->data, len);

	GOST_CIPHER_PARAMS_free(gcp);

	return 1;
}
Example #4
0
int
GOSTR341194_Init(GOSTR341194_CTX *c, int nid)
{
	memset(c, 0, sizeof(*c));
	return Gost2814789_set_sbox(&c->cipher, nid);
}