static int crypto_ofb_crypt(struct skcipher_request *req) { struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); struct crypto_cipher *cipher = skcipher_cipher_simple(tfm); const unsigned int bsize = crypto_cipher_blocksize(cipher); struct skcipher_walk walk; int err; err = skcipher_walk_virt(&walk, req, false); while (walk.nbytes >= bsize) { const u8 *src = walk.src.virt.addr; u8 *dst = walk.dst.virt.addr; u8 * const iv = walk.iv; unsigned int nbytes = walk.nbytes; do { crypto_cipher_encrypt_one(cipher, iv, iv); crypto_xor_cpy(dst, src, iv, bsize); dst += bsize; src += bsize; } while ((nbytes -= bsize) >= bsize); err = skcipher_walk_done(&walk, nbytes); } if (walk.nbytes) { crypto_cipher_encrypt_one(cipher, walk.iv, walk.iv); crypto_xor_cpy(walk.dst.virt.addr, walk.src.virt.addr, walk.iv, walk.nbytes); err = skcipher_walk_done(&walk, 0); } return err; }
static int crypto_ctr_crypt(struct skcipher_request *req) { struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); struct crypto_cipher *cipher = skcipher_cipher_simple(tfm); const unsigned int bsize = crypto_cipher_blocksize(cipher); struct skcipher_walk walk; unsigned int nbytes; int err; err = skcipher_walk_virt(&walk, req, false); while (walk.nbytes >= bsize) { if (walk.src.virt.addr == walk.dst.virt.addr) nbytes = crypto_ctr_crypt_inplace(&walk, cipher); else nbytes = crypto_ctr_crypt_segment(&walk, cipher); err = skcipher_walk_done(&walk, nbytes); } if (walk.nbytes) { crypto_ctr_crypt_final(&walk, cipher); err = skcipher_walk_done(&walk, 0); } return err; }