static int crypto_pcbc_decrypt_segment(struct skcipher_request *req, struct skcipher_walk *walk, struct crypto_cipher *tfm) { int bsize = crypto_cipher_blocksize(tfm); unsigned int nbytes = walk->nbytes; u8 *src = walk->src.virt.addr; u8 *dst = walk->dst.virt.addr; u8 *iv = walk->iv; do { crypto_cipher_decrypt_one(tfm, dst, src); crypto_xor(dst, iv, bsize); crypto_xor_cpy(iv, dst, src, bsize); src += bsize; dst += bsize; } while ((nbytes -= bsize) >= bsize); memcpy(walk->iv, iv, bsize); return nbytes; }
static int crypto_pcbc_decrypt_inplace(struct skcipher_request *req, struct skcipher_walk *walk, struct crypto_cipher *tfm) { int bsize = crypto_cipher_blocksize(tfm); unsigned int nbytes = walk->nbytes; u8 *src = walk->src.virt.addr; u8 *iv = walk->iv; u8 tmpbuf[MAX_CIPHER_BLOCKSIZE] __aligned(__alignof__(u32)); do { memcpy(tmpbuf, src, bsize); crypto_cipher_decrypt_one(tfm, src, src); crypto_xor(src, iv, bsize); crypto_xor_cpy(iv, src, tmpbuf, bsize); src += bsize; } while ((nbytes -= bsize) >= bsize); memcpy(walk->iv, iv, bsize); return nbytes; }
static void aes_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in) { const struct s390_aes_ctx *sctx = crypto_tfm_ctx(tfm); if (unlikely(need_fallback(sctx->key_len))) { crypto_cipher_decrypt_one(sctx->fallback.cip, out, in); return; } switch (sctx->key_len) { case 16: crypt_s390_km(KM_AES_128_DECRYPT, &sctx->key, out, in, AES_BLOCK_SIZE); break; case 24: crypt_s390_km(KM_AES_192_DECRYPT, &sctx->key, out, in, AES_BLOCK_SIZE); break; case 32: crypt_s390_km(KM_AES_256_DECRYPT, &sctx->key, out, in, AES_BLOCK_SIZE); break; } }
/* * Handle an I/O request. */ static void sbd_transfer(struct sbd_device *dev, sector_t sector, unsigned long nsect, char *buffer, int write) { unsigned long offset = sector * logical_block_size; unsigned long nbytes = nsect * logical_block_size; char *encrypts[2]; u8 *dst, *src; unsigned long len; int i; //set up the key crypto_cipher_setkey(crypto, crypto_key, crypto_key_len); if ((offset + nbytes) > dev->size) { printk (KERN_NOTICE "sbd: Beyond-end write (%ld %ld)\n", offset, nbytes); return; } if (write) { encrypts[0] = "UNECRYPTED"; encrypts[1] = "ENCRYPTED"; dst = dev->data + offset; src = buffer; for (i = 0; i < nbytes; i += crypto_cipher_blocksize(crypto)) { /* * crypto_cipher_encrypt_one() - encrypt one block of plaintext * @tfm: cipher handle * @dst: points to the buffer that will be filled with the ciphertext * @src: buffer holding the plaintext to be encrypted * * Invoke the encryption operation of one block. The caller must ensure that * the plaintext and ciphertext buffers are at least one block in size. static inline void crypto_cipher_encrypt_one(struct crypto_cipher *tfm, u8 *dst, const u8 *src) { crypto_cipher_crt(tfm)->cit_encrypt_one(crypto_cipher_tfm(tfm), dst, src); } */ crypto_cipher_encrypt_one(crypto, dst + i, src + i); } } else { //backwards from encrypt encrypts[0] = "ENCRYPTED"; encrypts[1] = "UNENCRYPTED"; dst = buffer; src = dev->data + offset; for (i = 0; i < nbytes; i += crypto_cipher_blocksize(crypto)) { /* * crypto_cipher_decrypt_one() - decrypt one block of ciphertext * @tfm: cipher handle * @dst: points to the buffer that will be filled with the plaintext * @src: buffer holding the ciphertext to be decrypted * * Invoke the decryption operation of one block. The caller must ensure that * the plaintext and ciphertext buffers are at least one block in size. static inline void crypto_cipher_decrypt_one(struct crypto_cipher *tfm, u8 *dst, const u8 *src) { crypto_cipher_crt(tfm)->cit_decrypt_one(crypto_cipher_tfm(tfm), dst, src); } */ crypto_cipher_decrypt_one(crypto, dst + i, src + i); } } // print out both buffers of encrypted and unencrypted // len = nbytes; // printk("%s:", encrypts[0]); // while (len--) { // printk("%u", (unsigned) *src++); // } // len = nbytes; // printk("\n%s:", encrypts[1]); // while (len--) { // printk("%u", (unsigned) *dst++); // } // printk("\n"); }
/****************************************************************************** * Handle an I/O request. * ******************************************************************************/ static void sbd_transfer(struct sbd_device *dev, sector_t sector, unsigned long nsect, char *buffer, int write) { unsigned long offset = sector * logical_block_size; unsigned long nbytes = nsect * logical_block_size; int i; int encrypt_flag; int decrypt_flag; unsigned long length; u8 *dst; u8 *src; /* Setting the Key */ crypto_cipher_setkey(crypt_cipher, key, key_len); if ((offset + nbytes) > dev->size) { printk (KERN_NOTICE "sbd: Beyond-end write (%ld %ld)\n", offset, nbytes); return; } if (write){ decrypt_flag = 0; encrypt_flag = 1; dst = dev->data + offset; src = buffer; for (i = 0; i < nbytes; i += crypto_cipher_blocksize(crypt_cipher)) { crypto_cipher_encrypt_one(crypt_cipher, dst + i, src + i); } } else { decrypt_flag = 1; encrypt_flag = 0; dst = buffer; src = dev->data + offset; for (i = 0; i < nbytes; i += crypto_cipher_blocksize(crypt_cipher)) { crypto_cipher_decrypt_one(crypt_cipher, dst + i, src + i); } } length = nbytes; printk("\n\n"); if (encrypt_flag && !decrypt_flag) { printk("Encrypt:\n"); } else { printk("Decrypt:\n"); } while (length--) { printk("%u ", (unsigned) *src++); } length = nbytes; printk("\n\n"); if (encrypt_flag && !decrypt_flag) { printk("Decrypt:\n"); } else { printk("Encrypt:\n"); } while (length--) { printk("%u ", (unsigned) *dst++); } printk("\n"); }