Beispiel #1
0
uint8_t bcal_ofb_init(const bcdesc_t* desc, const void* key, uint16_t keysize_b, bcal_ofb_ctx_t* ctx){
	ctx->desc = (bcdesc_t*)desc;
	ctx->blocksize_B = (bcal_cipher_getBlocksize_b(desc)+7)/8;
	ctx->in_block=malloc(ctx->blocksize_B);
	if(ctx->in_block==NULL){
			return 0x11;
	}
	return bcal_cipher_init(desc, key, keysize_b, &(ctx->cctx));
}
Beispiel #2
0
uint8_t bcal_ctr_init(const bcdesc_t* desc, const void* key, uint16_t keysize_b, inc_fp_t inc_func, bcal_ctr_ctx_t* ctx){
	ctx->desc = (bcdesc_t*)desc;
	if(inc_func){
		ctx->inc_func = inc_func;
	}else{
		ctx->inc_func = increment_be;
	}
	ctx->blocksize_B = (bcal_cipher_getBlocksize_b(desc)+7)/8;
	ctx->in_block=malloc(ctx->blocksize_B);
	if(ctx->in_block==NULL){
			return 0x11;
	}
	return bcal_cipher_init(desc, key, keysize_b, &(ctx->cctx));
}
Beispiel #3
0
uint8_t bcal_cmac_init(const bcdesc_t *desc, const void *key,
        uint16_t keysize_b, bcal_cmac_ctx_t *ctx)
{
    uint8_t r;
    ctx->desc = (bcdesc_t*) desc;
    ctx->blocksize_B = bcal_cipher_getBlocksize_b(desc) / 8;
    if (ctx->blocksize_B != 128 / 8 && ctx->blocksize_B != 64 / 8) {
        return 0x13;
    }
    ctx->accu = malloc(ctx->blocksize_B);
    if (ctx->accu == NULL) {
        return 0x14;
    }
    ctx->k1 = malloc(ctx->blocksize_B);
    if (ctx->k1 == NULL) {
        return 0x15;
    }
    ctx->k2 = malloc(ctx->blocksize_B);
    if (ctx->k2 == NULL) {
        return 0x16;
    }
    ctx->lastblock = malloc(ctx->blocksize_B);
    if (ctx->lastblock == NULL) {
        return 0x17;
    }
    r = bcal_cipher_init(desc, key, keysize_b, &(ctx->cctx));
    if (r) {
        return r;
    }
    if (ctx->blocksize_B == 128 / 8) {
        r = const_128;
    } else {
        r = const_64;
    }
    /* subkey computation */
    memset(ctx->accu, 0x00, ctx->blocksize_B);
    memset(ctx->k1, 0x00, ctx->blocksize_B);
    bcal_cipher_enc(ctx->k1, &(ctx->cctx));
    if (left_shift_be_block(ctx->k1, ctx->blocksize_B)) {
        ctx->k1[ctx->blocksize_B - 1] ^= r;
    }
    memcpy(ctx->k2, ctx->k1, ctx->blocksize_B);
    if (left_shift_be_block(ctx->k2, ctx->blocksize_B)) {
        ctx->k2[ctx->blocksize_B - 1] ^= r;
    }
    ctx->last_set = 0;
    return 0;
}
Beispiel #4
0
void testrun_test_aes(void){
	uint8_t key[16] = { 0x2b, 0x7e, 0x15, 0x16,
	                    0x28, 0xae, 0xd2, 0xa6,
	                    0xab, 0xf7, 0x15, 0x88,
	                    0x09, 0xcf, 0x4f, 0x3c };
	uint8_t data[16] = { 0x32, 0x43, 0xf6, 0xa8,
	                     0x88, 0x5a, 0x30, 0x8d,
	                     0x31, 0x31, 0x98, 0xa2,
	                     0xe0, 0x37, 0x07, 0x34 };
	aes128_ctx_t ctx;
	aes128_init(key, &ctx);
	cli_putstr("\r\n\r\n cipher test (FIPS 197):\r\n key:        ");
	cli_hexdump(key, 16);
	cli_putstr("\r\n plaintext:  ");
	cli_hexdump(data, 16);
	aes128_enc(data, &ctx);
	cli_putstr("\r\n ciphertext: ");
	cli_hexdump(data, 16);
	aes128_dec(data, &ctx);
	cli_putstr("\r\n plaintext:  ");
	cli_hexdump(data, 16);
	cli_putstr("\r\n testing bcal:");
	bcgen_ctx_t bcal_ctx;
	uint8_t r;
	r = bcal_cipher_init(&aes128_desc, key, 128, &bcal_ctx);
	cli_putstr("\r\n init = 0x");
	cli_hexdump(&r, 1);

	bcal_cipher_enc(data, &bcal_ctx);
	cli_putstr("\r\n ciphertext: ");
	cli_hexdump(data, 16);
	bcal_cipher_dec(data, &bcal_ctx);
	cli_putstr("\r\n plaintext:  ");
	cli_hexdump(data, 16);
	bcal_cipher_free(&bcal_ctx);
}