Beispiel #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;
}
Beispiel #2
0
void bcal_cmac_lastBlock(bcal_cmac_ctx_t* ctx, const void* block, uint16_t length_b){
	uint16_t blocksize_b;
	blocksize_b = ctx->blocksize_B*8;
	while(length_b>=blocksize_b){
		bcal_cmac_nextBlock(ctx, block);
		block = (uint8_t*)block + ctx->blocksize_B;
		length_b -= blocksize_b;
	}
	if(ctx->last_set==0){
		memxor(ctx->accu, block, (length_b+7)/8);
		memxor(ctx->accu, ctx->k2, ctx->blocksize_B);
		ctx->accu[length_b/8] ^= 0x80>>(length_b&7);
	}else{
Beispiel #3
0
void bcal_eax_decNextBlock(void *block, bcal_eax_ctx_t *ctx){
	bcal_cmac_nextBlock(&(ctx->ctag), block);
	bcal_ctr_decNext(block, &(ctx->cipher));
}
Beispiel #4
0
void bcal_eax_addNextHeader(const void *header, bcal_eax_ctx_t *ctx){
	bcal_cmac_nextBlock(&(ctx->htag), header);
}