int mycb(struct kgpu_req *req, struct kgpu_resp *resp) { printk("[calg2]: REQ ID: %d, RESP ID: %d, RESP CODE: %d, %d\n", req->kureq.id, resp->kuresp.id, resp->kuresp.errcode, *(int*)(__va(((struct kgpu_buffer*)(req->data))->pas[0]))); free_gpu_buffer((struct kgpu_buffer*)(req->data)); free_kgpu_request(req); free_kgpu_response(resp); return 0; }
static int crypto_gecb_crypt(struct blkcipher_desc *desc, struct scatterlist *dst, struct scatterlist *src, unsigned int sz, int enc) { int err=0; unsigned int nbytes; u8* gpos; int i = 0; struct kgpu_req *req; struct kgpu_resp *resp; struct kgpu_buffer *buf; struct crypto_blkcipher *tfm = desc->tfm; struct crypto_gecb_ctx *ctx = crypto_blkcipher_ctx(tfm); struct blkcipher_walk walk; blkcipher_walk_init(&walk, dst, src, sz); buf = alloc_gpu_buffer(); if (!buf) { printk("[gecb] Error: GPU buffer is null.\n"); return -EFAULT; } req = alloc_kgpu_request(); resp = alloc_kgpu_response(); if (!req || !resp) { return -EFAULT; } err = blkcipher_walk_virt(desc, &walk); while ((nbytes = walk.nbytes)) { u8 *wsrc = walk.src.virt.addr; if (nbytes > KGPU_BUF_FRAME_SIZE) { return -EFAULT; } #ifndef _NDEBUG if (nbytes != PAGE_SIZE) printk("[gecb] WARNING: %u is not PAGE_SIZE\n", nbytes); #endif gpos = buf->paddrs[i++]; memcpy(__va(gpos), wsrc, nbytes); err = blkcipher_walk_done(desc, &walk, 0); } gpos = buf->paddrs[i]; memcpy(__va(gpos), &(ctx->aes_ctx), sizeof(struct crypto_aes_ctx)); strcpy(req->kureq.sname, enc?"gecb-enc":"gecb-dec"); req->kureq.input = buf->gb.addr; req->kureq.output = buf->gb.addr; req->kureq.insize = sz+PAGE_SIZE; req->kureq.outsize = sz; if (call_gpu_sync(req, resp)) { err = -EFAULT; printk("[gecb] Error: callgpu error\n"); } else { i=0; blkcipher_walk_init(&walk, dst, src, sz); err = blkcipher_walk_virt(desc, &walk); while ((nbytes = walk.nbytes)) { u8 *wdst = walk.dst.virt.addr; if (nbytes > KGPU_BUF_FRAME_SIZE) { return -EFAULT; } #ifndef _NDEBUG if (nbytes != PAGE_SIZE) printk("[gecb] WARNING: %u is not PAGE_SIZE\n", nbytes); #endif gpos = buf->paddrs[i++]; memcpy(wdst, __va(gpos), nbytes); err = blkcipher_walk_done(desc, &walk, 0); } } free_kgpu_request(req); free_kgpu_response(resp); free_gpu_buffer(buf); return err; }