/* * sync_provider.c * * Copyright (c) 2004 Evgeniy Polyakov * * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include #include #include #include #include #include #include //#define SYNC_DEBUG #ifdef SYNC_DEBUG #define dprintk(f, a...) printk(KERN_EMERG f, ##a) #else #define dprintk(f, a...) do {} while(0) #endif #define OP_ENCRYPT 0 #define OP_DECRYPT 1 static char sync_algo[] = "aes"; static char sync_key[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}; static struct crypto_tfm *tfm; void bd_encrypt(void *src, void *dst, u64 size, void *priv) { struct scatterlist s, d; s.page = virt_to_page(src); s.offset = offset_in_page(src); s.length = size; d.page = virt_to_page(dst); d.offset = offset_in_page(dst); d.length = size; /* * A hack to fool crypto layer - it thinks that we can sleep here... * Sigh. * * preempt_count() |= SOFTIRQ_MASK; */ preempt_count() |= SOFTIRQ_MASK; crypto_cipher_encrypt(tfm, &d, &s, size); preempt_count() &= ~SOFTIRQ_MASK; } void bd_decrypt(void *src, void *dst, u64 size, void *priv) { struct scatterlist s, d; s.page = virt_to_page(src); s.offset = offset_in_page(src); s.length = size; d.page = virt_to_page(dst); d.offset = offset_in_page(dst); d.length = size; /* * A hack to fool crypto layer - it thinks that we can sleep here... * Sigh. * * preempt_count() |= SOFTIRQ_MASK; */ preempt_count() |= SOFTIRQ_MASK; crypto_cipher_decrypt(tfm, &d, &s, size); preempt_count() &= ~SOFTIRQ_MASK; } int __devinit sync_init(void) { int err; err = -ENODEV; tfm = crypto_alloc_tfm(sync_algo, 0); if (!tfm) { dprintk("Failed to allocate %s tfm.\n", sync_algo); goto err_out_exit; } err = crypto_cipher_setkey(tfm, sync_key, sizeof(sync_key)); if (err) { dprintk("Failed to set key [keylen=%d]: err=%d.\n", sizeof(sync_key), err); goto err_out_free_tfm; } return 0; err_out_free_tfm: crypto_free_tfm(tfm); err_out_exit: return err; } void __devexit sync_fini(void) { crypto_free_tfm(tfm); } module_init(sync_init); module_exit(sync_fini); MODULE_AUTHOR("Evgeniy Polyakov "); MODULE_LICENSE("GPL"); EXPORT_SYMBOL(bd_encrypt); EXPORT_SYMBOL(bd_decrypt);