コード例 #1
0
void testrun_aes128_cbc(void){
	uint8_t key[16];
	uint8_t iv[16];
	uint8_t plain[64];

	bcal_cbc_ctx_t ctx;
	uint8_t r;

	memcpy(key,   modes_key,   16);
	memcpy(iv,    modes_iv,    16);
	memcpy(plain, modes_plain, 64);

	cli_putstr("\r\n** AES128-CBC-TEST **");
	r = bcal_cbc_init(&aes128_desc, key, 128, &ctx);
	cli_putstr("\r\n  init = 0x");
	cli_hexdump(&r, 1);
	cli_putstr("\r\n  key:   ");
	cli_hexdump(key, 128/8);
	cli_putstr("\r\n  IV:    ");
	cli_hexdump(iv, 128/8);
	cli_putstr("\r\n  plaintext:");
	cli_hexdump_block(plain, 4*128/8, 4, 16);
	if(r)
		return;
	bcal_cbc_encMsg(iv, plain, 4, &ctx);
	cli_putstr("\r\n  ciphertext:  ");
	cli_hexdump_block(plain, 4*128/8, 4, 16);
	bcal_cbc_decMsg(iv, plain, 4, &ctx);
	cli_putstr("\r\n  plaintext:   ");
	cli_hexdump_block(plain, 4*128/8, 4, 16);
	bcal_cbc_free(&ctx);
}
コード例 #2
0
ファイル: AESLib.c プロジェクト: 9zigen/AESLib
// prepare an encrypted to use for encrypting multiple blocks lateron.
// key and iv are assumed to be both 192bit thus 24 uint8_t's
aes_context aes192_cbc_enc_start(const uint8_t* key, const void* iv){
	bcal_cbc_ctx_t* ctx = (bcal_cbc_ctx_t*)malloc(sizeof(bcal_cbc_ctx_t));
	uint8_t r = bcal_cbc_init(&aes192_desc, key, 192, ctx);
	if (r) {
		free(ctx);
		return NULL;
	}
	bcal_cbc_loadIV(iv, ctx);
	return (aes_context)ctx;
}
コード例 #3
0
ファイル: AESLib.c プロジェクト: 9zigen/AESLib
// encrypt multiple blocks of 128bit data, data_len but be mod 16
// key and iv are assumed to be both 192bit thus 24 uint8_t's
void aes192_cbc_enc(const uint8_t* key, const uint8_t* iv, void* data, const uint16_t data_len){
	if (data_len % 16 != 0) {
		return;
	}
	bcal_cbc_ctx_t ctx;
	uint8_t r;
	r = bcal_cbc_init(&aes192_desc, key, 192, &ctx);
	if (r) {
		return;
	}
	bcal_cbc_encMsg(iv, data, data_len / 16, &ctx);
	bcal_cbc_free(&ctx);
}