示例#1
0
文件: cbc.c 项目: Voskrese/mipsonqemu
static int crypto_cbc_encrypt(struct blkcipher_desc *desc,
			      struct scatterlist *dst, struct scatterlist *src,
			      unsigned int nbytes)
{
	struct blkcipher_walk walk;
	struct crypto_blkcipher *tfm = desc->tfm;
	struct crypto_cbc_ctx *ctx = crypto_blkcipher_ctx(tfm);
	struct crypto_cipher *child = ctx->child;
	void (*xor)(u8 *, const u8 *, unsigned int bs) = ctx->xor;
	int err;

	blkcipher_walk_init(&walk, dst, src, nbytes);
	err = blkcipher_walk_virt(desc, &walk);

	while ((nbytes = walk.nbytes)) {
		if (walk.src.virt.addr == walk.dst.virt.addr)
			nbytes = crypto_cbc_encrypt_inplace(desc, &walk, child,
							    xor);
		else
			nbytes = crypto_cbc_encrypt_segment(desc, &walk, child,
							    xor);
		err = blkcipher_walk_done(desc, &walk, nbytes);
	}

	return err;
}
示例#2
0
文件: cbc.c 项目: jhbsz/DIR-850L_A1
static int crypto_cbc_encrypt(struct blkcipher_desc *desc,
                              struct scatterlist *dst, struct scatterlist *src,
                              unsigned int nbytes)
{
    struct blkcipher_walk walk;
    struct crypto_blkcipher *tfm = desc->tfm;
    struct crypto_cbc_ctx *ctx = crypto_blkcipher_ctx(tfm);
    struct crypto_cipher *child = ctx->child;
    int err;

    blkcipher_walk_init(&walk, dst, src, nbytes);
    err = blkcipher_walk_virt(desc, &walk);

    while ((nbytes = walk.nbytes)) {
#ifdef CONFIG_CRYPTO_DEV_REALTEK_DBG
        printk("%s: total=%d, walk=%d, blk=%d, src=%p, dst=%p\n", __FUNCTION__,
               walk.total, walk.nbytes, crypto_cipher_blocksize(child),
               walk.src.virt.addr, walk.dst.virt.addr
              );
#endif
#ifdef CONFIG_CRYPTO_DEV_REALTEK
        if (ctx->rtl_ctx.mode >= 0)
        {
            nbytes = rtl_cipher_crypt(child, 1,
                                      &ctx->rtl_ctx, walk.src.virt.addr, nbytes,
                                      walk.iv, walk.dst.virt.addr);

            // cbc mode update
            memcpy(walk.iv, walk.dst.virt.addr,
                   crypto_cipher_blocksize(child));

            err = blkcipher_walk_done(desc, &walk, nbytes);
            continue;
        }
#endif
        if (walk.src.virt.addr == walk.dst.virt.addr)
            nbytes = crypto_cbc_encrypt_inplace(desc, &walk, child);
        else
            nbytes = crypto_cbc_encrypt_segment(desc, &walk, child);
        err = blkcipher_walk_done(desc, &walk, nbytes);
    }

    return err;
}