Exemplo n.º 1
0
void
serpent_xts_crypt(struct serpent_xts_ctx *ctx, u_int8_t *data, u_int8_t *iv,
    u_int do_encrypt)
{
	u_int8_t block[SERPENT_XTS_BLOCK_LEN];
	u_int i, carry_in, carry_out;

	for (i = 0; i < SERPENT_XTS_BLOCK_LEN; i++)
		block[i] = data[i] ^ iv[i];

	if (do_encrypt)
		serpent_encrypt(&ctx->key1, block, data);
	else
		serpent_decrypt(&ctx->key1, block, data);

	for (i = 0; i < SERPENT_XTS_BLOCK_LEN; i++)
		data[i] ^= iv[i];

	/* Exponentiate tweak */
	carry_in = 0;
	for (i = 0; i < SERPENT_XTS_BLOCK_LEN; i++) {
		carry_out = iv[i] & 0x80;
		iv[i] = (iv[i] << 1) | (carry_in ? 1 : 0);
		carry_in = carry_out;
	}
	if (carry_in)
		iv[0] ^= AES_XTS_ALPHA;
	bzero(block, sizeof(block));
}
Exemplo n.º 2
0
void DecipherBlock(int cipher, void *data, void *ks)
{
	switch (cipher)
	{
	case SERPENT:	serpent_decrypt (data, data, ks); break;
	case TWOFISH:	twofish_decrypt (ks, data, data); break;
#ifndef TC_WINDOWS_BOOT

	case AES:
#if defined (_WIN64) || !defined (TC_WINDOWS_DRIVER)
		if (IsAesHwCpuSupported())
			aes_hw_cpu_decrypt ((byte *) ks + sizeof (aes_encrypt_ctx), data);
		else
#endif
			aes_decrypt (data, data, (void *) ((char *) ks + sizeof(aes_encrypt_ctx)));
		break;

	case BLOWFISH:	BlowfishEncryptLE (data, data, ks, 0); break;	// Deprecated/legacy
	case CAST:		Cast5Decrypt (data, data, ks); break;			// Deprecated/legacy
	case TRIPLEDES:	TripleDesEncrypt (data, data, ks, 0); break;	// Deprecated/legacy
#else
	case AES:		aes_decrypt (data, data, ks); break;
#endif
	default:		TC_THROW_FATAL_EXCEPTION;	// Unknown/wrong ID
	}
}
Exemplo n.º 3
0
int main(void){
	unsigned char plaintext[SERPENT_BLOCK_NB_BYTE] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff};
	unsigned char key[SERPENT_KEY_MAX_NB_BYTE] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
	unsigned char round_key[SERPENT_ROUND_KEY_NB_BYTE];
	unsigned char ciphertext[SERPENT_BLOCK_NB_BYTE];
	unsigned char deciphertext[SERPENT_BLOCK_NB_BYTE];

	printf("Plaintext:  ");
	fprintBuffer_raw(stdout, (char*)plaintext, SERPENT_BLOCK_NB_BYTE);

	printf("\nKey:        ");
	fprintBuffer_raw(stdout, (char*)key, KEY_SIZE);

	serpent_key_expand((uint32_t*)key, KEY_SIZE * 8, (uint32_t*)round_key);
	serpent_encrypt((uint32_t*)plaintext, (uint32_t*)round_key, (uint32_t*)ciphertext);

	printf("\nCiphertext: ");
	fprintBuffer_raw(stdout, (char*)ciphertext, SERPENT_BLOCK_NB_BYTE);

	serpent_decrypt((uint32_t*)ciphertext, (uint32_t*)round_key, (uint32_t*)deciphertext);

	if (memcmp(deciphertext, plaintext, SERPENT_BLOCK_NB_BYTE) == 0){
		printf("\nRecovery:   OK\n");
	}
	else{
		printf("\nRecovery:   FAIL\n");
	}

	return EXIT_SUCCESS;
}
void DecryptCBC::decrypt_block(const uint8_t src[16], uint8_t dst[16])
{
    cbc_copy(src, l_cbcivsave); // this is needed if (src == dst)

    serpent_decrypt((const uint32_t*)src, (uint32_t*)dst, l_key);

    cbc_xor(l_cbciv, dst);
    cbc_copy(l_cbcivsave, l_cbciv);
}
Exemplo n.º 5
0
int main(void)
{
	uint8_t ct1[32], pt1[32], pt2[32], key[64];
	int klen, plen, clen, i, j;
	serpent_key_t skey;
	serpent_blk ct2;
	uint32_t *p;

	printf("\nserpent-256 test\n");

	for (i = 0; i<sizeof(keys) / sizeof(char*); i++) {
		clen = hex2bin(ct1, cipher[i]);
		plen = hex2bin(pt1, plain[i]);
		klen = hex2bin(key, keys[i]);

		/* set key */
		memset(&skey, 0, sizeof(skey));
		p = (uint32_t*)&skey.x[0][0];

		serpent_set_encrypt_key(&skey, key);
		printf("\nkey=");

		for (j = 0; j<sizeof(skey) / sizeof(serpent_subkey_t) * 4; j++) {
			if ((j % 8) == 0) 
				putchar('\n');
			printf("%08X ", p[j]);
		}

		/* encrypt */
		memcpy(ct2.b, pt1, SERPENT_BLOCK_SIZE);

		printf("\n\n");
		dump_hex("plaintext", ct2.b, 16);

		serpent_encrypt(pt1,ct2.b, &skey);

		dump_hex("ciphertext", ct2.b, 16);

		if (memcmp(ct1, ct2.b, clen) == 0) {
			printf("\nEncryption OK");
			serpent_decrypt(ct2.b,pt1, &skey);
			if (memcmp(pt1, ct2.b, plen) == 0) {
				printf("\nDecryption OK");
				dump_hex("plaintext", ct2.b, 16);
			}
			else {
				printf("\nDecryption failed");
			}
		}
		else {
			printf("\nEncryption failed");
		}
	}
	return 0;
}
Exemplo n.º 6
0
void DecipherBlock(int cipher, void *data, void *ks)
{
#ifdef GST_WINDOWS_BOOT_AES
	if (IsAesHwCpuSupported())
		aes_hw_cpu_decrypt ((byte *) ks + sizeof (aes_encrypt_ctx) + 14 * 16, data);
	else
		aes_decrypt (data, data, (aes_decrypt_ctx *) ((byte *) ks + sizeof(aes_encrypt_ctx))); 
#elif defined (GST_WINDOWS_BOOT_SERPENT)
	serpent_decrypt (data, data, ks);
#elif defined (GST_WINDOWS_BOOT_TWOFISH)
	twofish_decrypt (ks, data, data);
#endif
}
Exemplo n.º 7
0
static void tnepres_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
{
	const u32 * const s = (const u32 * const)src;
	u32 * const d = (u32 * const)dst;

	u32 rs[4], rd[4];

	rs[0] = swab32(s[3]);
	rs[1] = swab32(s[2]);
	rs[2] = swab32(s[1]);
	rs[3] = swab32(s[0]);

	serpent_decrypt(tfm, (u8 *)rd, (u8 *)rs);

	d[0] = swab32(rd[3]);
	d[1] = swab32(rd[2]);
	d[2] = swab32(rd[1]);
	d[3] = swab32(rd[0]);
}
Exemplo n.º 8
0
	// Serpent
	void CipherSerpent::Decrypt (byte *data) const
	{
		serpent_decrypt (data, data, ScheduledKey);
	}
Exemplo n.º 9
0
void SERPENT_decrypt(SERPENT_KEY *serpent_key,char *input, char *output)
{
    serpent_decrypt(serpent_key, (const serpent_word32 *)output, (serpent_word32 *)input);
}
Exemplo n.º 10
0
static void
serpent128_decrypt(caddr_t key, u_int8_t *blk, u_int8_t *iv)
{
	serpent_decrypt(((serpent_ctx *) key), blk, blk);
}
Exemplo n.º 11
0
void DecryptECB::decrypt_block(const uint8_t src[16], uint8_t dst[16]) const
{
    serpent_decrypt((const uint32_t*)src, (uint32_t*)dst, l_key);
}