Ejemplo n.º 1
0
void lnc_cast6_dec(void *context) {
	lnc_cast6_ctx_t *ctx = context;
	int i;

	for(i = 11; i > 5; i--)
		Q(ctx, i);
	for(i = 5; i >= 0; i--)
		QBAR(ctx, i);
}
Ejemplo n.º 2
0
void lnc_cast6_enc(void *context) {
	lnc_cast6_ctx_t *ctx = context;
	int i;

	for(i = 0; i < 6; i++)
		Q(ctx, i);
	for(i = 6; i < 12; i++)
		QBAR(ctx, i);
}
Ejemplo n.º 3
0
static void cast6_decrypt(struct crypto_tfm *tfm, u8 *outbuf, const u8 *inbuf) {
	struct cast6_ctx * c = crypto_tfm_ctx(tfm);
	const __be32 *src = (const __be32 *)inbuf;
	__be32 *dst = (__be32 *)outbuf;
	u32 block[4];
	u32 * Km; 
	u8 * Kr;

	block[0] = be32_to_cpu(src[0]);
	block[1] = be32_to_cpu(src[1]);
	block[2] = be32_to_cpu(src[2]);
	block[3] = be32_to_cpu(src[3]);

	Km = c->Km[11]; Kr = c->Kr[11]; Q (block, Kr, Km);
	Km = c->Km[10]; Kr = c->Kr[10]; Q (block, Kr, Km);
	Km = c->Km[9]; Kr = c->Kr[9]; Q (block, Kr, Km);
	Km = c->Km[8]; Kr = c->Kr[8]; Q (block, Kr, Km);
	Km = c->Km[7]; Kr = c->Kr[7]; Q (block, Kr, Km);
	Km = c->Km[6]; Kr = c->Kr[6]; Q (block, Kr, Km);
	Km = c->Km[5]; Kr = c->Kr[5]; QBAR (block, Kr, Km);
	Km = c->Km[4]; Kr = c->Kr[4]; QBAR (block, Kr, Km);
	Km = c->Km[3]; Kr = c->Kr[3]; QBAR (block, Kr, Km);
	Km = c->Km[2]; Kr = c->Kr[2]; QBAR (block, Kr, Km);
	Km = c->Km[1]; Kr = c->Kr[1]; QBAR (block, Kr, Km);
	Km = c->Km[0]; Kr = c->Kr[0]; QBAR (block, Kr, Km);
	
	dst[0] = cpu_to_be32(block[0]);
	dst[1] = cpu_to_be32(block[1]);
	dst[2] = cpu_to_be32(block[2]);
	dst[3] = cpu_to_be32(block[3]);
}	
Ejemplo n.º 4
0
std::string CAST256::run(const std::string & DATA){
    if (!keyset){
        throw std::runtime_error("Error: Key has not been set.");
    }

    if (DATA.size() != 16){
        throw std::runtime_error("Error: Data must be 128 bits in length.");
    }

    A = toint(DATA.substr(0, 4), 256);
    B = toint(DATA.substr(4, 4), 256);
    C = toint(DATA.substr(8, 4), 256);
    D = toint(DATA.substr(12, 4), 256);
    for(uint8_t i = 0; i < 6; i++){
        Q(i);
    }
    for(uint8_t i = 6; i < 12; i++){
        QBAR(i);
    }
    return unhexlify(makehex(A, 8) + makehex(B, 8) + makehex(C, 8) + makehex(D, 8));
}