Пример #1
0
int
px_find_cipher(const char *name, PX_Cipher ** res)
{
	char		nbuf[PX_MAX_NAMELEN + 1];
	const char *mode = NULL;
	char	   *p;
	MCRYPT		ctx;

	PX_Cipher  *c;

	strcpy(nbuf, name);

	if ((p = strrchr(nbuf, '-')) != NULL)
	{
		if (is_mode(p + 1))
		{
			mode = p + 1;
			*p = 0;
		}
	}

	name = px_resolve_alias(aliases, nbuf);

	if (!mode)
	{
		mode = "cbc";

		/*
		 * if (mcrypt_module_is_block_algorithm(name, NULL)) mode = "cbc";
		 * else mode = "stream";
		 */
	}
	mode = px_resolve_alias(mode_aliases, mode);

	ctx = mcrypt_module_open((char *) name, NULL, (char *) mode, NULL);
	if (ctx == (void *) MCRYPT_FAILED)
		return -1;

	c = palloc(sizeof *c);
	c->iv_size = cipher_iv_size;
	c->key_size = cipher_key_size;
	c->block_size = cipher_block_size;
	c->init = cipher_init;
	c->encrypt = cipher_encrypt;
	c->decrypt = cipher_decrypt;
	c->free = cipher_free;
	c->ptr = ctx;
	c->pstat = 0;

	*res = c;
	return 0;
}
Пример #2
0
int
px_find_cipher(const char *name, PX_Cipher **res)
{
	const struct ossl_cipher_lookup *i;
	PX_Cipher  *c = NULL;
	ossldata   *od;

	name = px_resolve_alias(ossl_aliases, name);
	for (i = ossl_cipher_types; i->name; i++)
		if (!strcmp(i->name, name))
			break;
	if (i->name == NULL)
		return PXE_NO_CIPHER;

	od = px_alloc(sizeof(*od));
	memset(od, 0, sizeof(*od));
	od->ciph = i->ciph;

	c = px_alloc(sizeof(*c));
	c->block_size = gen_ossl_block_size;
	c->key_size = gen_ossl_key_size;
	c->iv_size = gen_ossl_iv_size;
	c->free = gen_ossl_free;
	c->init = od->ciph->init;
	c->encrypt = od->ciph->encrypt;
	c->decrypt = od->ciph->decrypt;
	c->ptr = od;

	*res = c;
	return 0;
}
int
px_find_cipher(const char *name, PX_Cipher **res)
{
	int			i;
	PX_Cipher  *c = NULL;

	name = px_resolve_alias(int_aliases, name);

	for (i = 0; int_ciphers[i].name; i++)
		if (!strcmp(int_ciphers[i].name, name))
		{
			c = int_ciphers[i].load();
			break;
		}

	if (c == NULL)
		return PXE_NO_CIPHER;

	*res = c;
	return 0;
}