-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;
+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;