예제 #1
0
uint8_t bcal_eax_init(const bcdesc_t *desc, const void *key, uint16_t keysize_b, bcal_eax_ctx_t *ctx){
	uint8_t r;
	ctx->blocksize_B = (bcal_cipher_getBlocksize_b(desc)+7)/8;
	ctx->nonce = malloc(ctx->blocksize_B);
	if(ctx->nonce==NULL){
		return 0x81;
	}
	r = bcal_cmac_init(desc, key, keysize_b, &(ctx->ctag));
	if(r){
		return r;
	}
	r = bcal_cmac_init(desc, key, keysize_b, &(ctx->htag));
	if(r){
		return (r|0x10);
	}
	r = bcal_cmac_init(desc, key, keysize_b, &(ctx->ntag));
	if(r){
		return (r|0x20);
	}
	r = bcal_ctr_init(desc, key, keysize_b, NULL, &(ctx->cipher));
	if(r){
		return (r|0x30);
	}
	ctx->header_set=0;
	uint8_t tmp[ctx->blocksize_B];
	memset(tmp, 0, ctx->blocksize_B);
	bcal_cmac_nextBlock(&(ctx->ntag), tmp);
	tmp[ctx->blocksize_B-1]=1;
	bcal_cmac_nextBlock(&(ctx->htag), tmp);
	tmp[ctx->blocksize_B-1]=2;
	bcal_cmac_nextBlock(&(ctx->ctag), tmp);
	return 0;
}
예제 #2
0
void testrun_aes128_ctr(void){
	uint8_t key[16];
	uint8_t iv[16];
	uint8_t plain[64];

	bcal_ctr_ctx_t ctx;
	uint8_t r;

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

	cli_putstr("\r\n** AES128-CTR-TEST **");
	r = bcal_ctr_init(&aes128_desc, key, 128, NULL, &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_ctr_encMsg(iv, plain, 4*128, &ctx);
	cli_putstr("\r\n  ciphertext:  ");
	cli_hexdump_block(plain, 4*128/8, 4, 16);
	bcal_ctr_decMsg(iv, plain, 4*128, &ctx);
	cli_putstr("\r\n  plaintext:   ");
	cli_hexdump_block(plain, 4*128/8, 4, 16);
	bcal_ctr_free(&ctx);
}