コード例 #1
0
ファイル: cmll_ctr.c プロジェクト: LucidOne/Rovio
/* The input encrypted as though 128bit counter mode is being
 * used.  The extra state information to record how much of the
 * 128bit block we have used is contained in *num, and the
 * encrypted counter is kept in ecount_buf.  Both *num and
 * ecount_buf must be initialised with zeros before the first
 * call to Camellia_ctr128_encrypt().
 *
 * This algorithm assumes that the counter is in the x lower bits
 * of the IV (ivec), and that the application has full control over
 * overflow and the rest of the IV.  This implementation takes NO
 * responsability for checking that the counter doesn't overflow
 * into the rest of the IV when incremented.
 */
void Camellia_ctr128_encrypt(const unsigned char *in, unsigned char *out,
	const unsigned long length, const CAMELLIA_KEY *key,
	unsigned char ivec[CAMELLIA_BLOCK_SIZE],
	unsigned char ecount_buf[CAMELLIA_BLOCK_SIZE],
	unsigned int *num) 
	{

	unsigned int n;
	unsigned long l=length;

	assert(in && out && key && counter && num);
	assert(*num < CAMELLIA_BLOCK_SIZE);

	n = *num;

	while (l--) 
		{
		if (n == 0) 
			{
			Camellia_encrypt(ivec, ecount_buf, key);
			Camellia_ctr128_inc(ivec);
			}
		*(out++) = *(in++) ^ ecount_buf[n];
		n = (n+1) % CAMELLIA_BLOCK_SIZE;
		}

	*num=n;
	}
コード例 #2
0
ファイル: cmll_ecb.c プロジェクト: RafaelRMachado/MinnowBoard
void Camellia_ecb_encrypt(const unsigned char *in, unsigned char *out,
	const CAMELLIA_KEY *key, const int enc) 
	{

	assert(in && out && key);
	assert((CAMELLIA_ENCRYPT == enc)||(CAMELLIA_DECRYPT == enc));

	if (CAMELLIA_ENCRYPT == enc)
		Camellia_encrypt(in, out, key);
	else
		Camellia_decrypt(in, out, key);
	}
コード例 #3
0
static void crypt_all(int count)
{
	int index = 0;
#ifdef _OPENMP
#pragma omp parallel for
	for (index = 0; index < count; index++)
#endif
	{
		CAMELLIA_KEY st_key;
		unsigned char in[16] = {0};
		unsigned char key[32] = {0};
		memcpy(key, saved_key[index], strlen(saved_key[index]));
		Camellia_set_key(key, 256, &st_key);
		Camellia_encrypt(in, crypt_out[index], &st_key);
	}
}
コード例 #4
0
ファイル: cipher-ctr.c プロジェクト: lifangbo/teraterm
//============================================================================
// Camellia
//============================================================================
static int
ssh_camellia_ctr(EVP_CIPHER_CTX *ctx, unsigned char *dest, const unsigned char *src, unsigned int len)
{
	struct ssh_camellia_ctr_ctx *c;
	unsigned int n = 0;
	unsigned char buf[CAMELLIA_BLOCK_SIZE];

	if (len == 0)
		return (1);
	if ((c = EVP_CIPHER_CTX_get_app_data(ctx)) == NULL)
		return (0);

	while ((len--) > 0) {
		if (n == 0) {
			Camellia_encrypt(c->camellia_counter, buf, &c->camellia_ctx);
			ssh_ctr_inc(c->camellia_counter, CAMELLIA_BLOCK_SIZE);
		}
		*(dest++) = *(src++) ^ buf[n];
		n = (n + 1) % CAMELLIA_BLOCK_SIZE;
	}
	return (1);
}
コード例 #5
0
ファイル: symmetric.c プロジェクト: Henauxg/minix
static void 
camellia_block_encrypt(pgp_crypt_t *crypt, void *out, const void *in)
{
	Camellia_encrypt(in, out, crypt->encrypt_key);
}