static int crc32be_vx_final(struct shash_desc *desc, u8 *out) { struct crc_desc_ctx *ctx = shash_desc_ctx(desc); *(__be32 *)out = cpu_to_be32p(&ctx->crc); return 0; }
/* * prepare the request of RPMB frame * RPMB frame is MSB first * convert needed bytes * return how many frames will be prepared */ int mmc_rpmb_pre_frame(struct mmc_core_rpmb_req *rpmb_req, struct mmc_card *card) { int i, ret; struct mmc_ioc_rpmb_req *p_req; __u8 *buf_frame; __u16 blk_cnt, addr, type; __u32 w_counter; if (!rpmb_req || !card) return -EINVAL; p_req = rpmb_req->req; if (!p_req) { pr_err("%s: mmc_ioc_rpmb_req is NULL. Wrong parameter\n", mmc_hostname(card->host)); return -EINVAL; } /* * make sure these two items are clear */ rpmb_req->ready = 0; rpmb_req->frame = NULL; ret = mmc_rpmb_request_check(card, p_req); if (ret) return ret; buf_frame = kzalloc(512 * p_req->blk_cnt, GFP_KERNEL); if (!buf_frame) { pr_err("%s: cannot allocate frame for type %d\n", mmc_hostname(card->host), p_req->type); return -ENOMEM; } type = cpu_to_be16p(&p_req->type); if (p_req->type == RPMB_GET_WRITE_COUNTER || p_req->type == RPMB_READ_DATA) { /* * One package prepared * This request needs Nonce and type * If is data read, then also need addr */ memcpy(buf_frame + RPMB_TYPE_BEG, &type, 2); if (p_req->type == RPMB_READ_DATA) { addr = cpu_to_be16p(&p_req->addr); memcpy(buf_frame + RPMB_ADDR_BEG, &addr, 2); } /* convert Nonce code */ memcpy(buf_frame + RPMB_NONCE_BEG, p_req->nonce, 16); } else if (p_req->type == RPMB_WRITE_DATA) { __u8 *data = p_req->data; /* * multiple package prepared * This request nees blk_cnt, addr, write_counter, * data and mac */ blk_cnt = cpu_to_be16p(&p_req->blk_cnt); addr = cpu_to_be16p(&p_req->addr); w_counter = cpu_to_be32p(p_req->wc); for (i = 0; i < p_req->blk_cnt; i++) { memcpy(buf_frame + i * 512 + RPMB_TYPE_BEG, &type, 2); memcpy(buf_frame + i * 512 + RPMB_BLKS_BEG, &blk_cnt, 2); memcpy(buf_frame + i * 512 + RPMB_ADDR_BEG, &addr, 2); memcpy(buf_frame + i * 512 + RPMB_WCOUNTER_BEG, &w_counter, 4); memcpy(buf_frame + i * 512 + RPMB_DATA_BEG, data, 256); data += 256; } /* convert MAC code */ memcpy(buf_frame + 512 * (i - 1) + RPMB_MAC_BEG, p_req->mac, 32); } else { pr_err("%s: We shouldn't be here\n", mmc_hostname(card->host)); kfree(buf_frame); return -EINVAL; } rpmb_req->ready = 1; rpmb_req->frame = buf_frame; return 0; }
/** * uint8p_to_uint32_be - 4*uint8 to uint32 big endian * @in: Data to convert. */ static inline u32 uint8p_to_uint32_be(u8 *in) { u32 *data = (u32 *)in; return cpu_to_be32p(data); }