#Include #include "internal.h" #include #define CIPHERTEXT "\x01\x0c\x07\x1b\x58\x73\x2e\x09"\ "\x0b\x14\x1f\x1a\x1d\x65\x6c\x2e" static char *key = "Mein Schluessel."; struct crypt_result { struct completion completion; int err; }; static void request_done(struct crypto_async_request *req, int err) { struct crypt_result *res = req->data; printk("request_done()\n"); if (err == -EINPROGRESS) return; res->err = err; complete(&res->completion); } static int __init ablkuser_init( void ) { int ret; struct scatterlist sg[2]; char *encrypted, *decrypted; struct crypto_ablkcipher *tfm; struct ablkcipher_request *req; struct crypt_result result; printk("ablkuser_init\n"); encrypted = kzalloc(16, GFP_KERNEL); if (!encrypted) goto alloc_encrypted_failed; decrypted = kzalloc(16, GFP_KERNEL); if (!decrypted) goto free_encrypted; init_completion(&result.completion); memcpy(encrypted, CIPHERTEXT, 16); sg_init_table( sg, ARRAY_SIZE(sg) ); sg_set_buf( &sg[0], encrypted, 16 ); sg_set_buf( &sg[1], decrypted, 16 ); tfm = crypto_alloc_ablkcipher("ablk", 0, 0); if (IS_ERR(tfm)) { printk("crypto_alloc_ablkcipher failed %ld\n", (long)tfm); goto free_decrypted; } ret = crypto_ablkcipher_setkey(tfm, key, strlen(key)); if (ret<0) { printk("crypto_ablkcipher_setkey failed\n"); goto free_cipher; } /* Auftragsvergabe */ req = ablkcipher_request_alloc(tfm, GFP_KERNEL); if (!req) { printk("ablkcipher_request_alloc failed\n"); goto free_cipher; } ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, request_done, &result); crypto_ablkcipher_clear_flags(tfm, ~0); ablkcipher_request_set_crypt(req, &sg[0], &sg[1], 16, NULL); ret = crypto_ablkcipher_decrypt(req); if (ret == 0) { request_done( &req->base, 0 ); } else if (ret!=-EINPROGRESS && ret!=-EBUSY) { printk("crypte_ablkcipher_decrypt failed %d\n", ret); goto free_all; } ret = wait_for_completion_interruptible( &result.completion); if (ret || (ret = result.err)) { printk("decryption failed %d\n", ret); goto free_all; } print_hex_dump(KERN_INFO,"encr> ",DUMP_PREFIX_NONE,16,1,encrypted,16,1); printk("\n"); print_hex_dump(KERN_INFO,"decr> ",DUMP_PREFIX_NONE,16,1,decrypted,16,1); printk("\n"); free_all: ablkcipher_request_free(req); free_cipher: crypto_free_ablkcipher(tfm); free_decrypted: kfree(decrypted); free_encrypted: kfree(encrypted); alloc_encrypted_failed: return -EIO; /* macht das Testen einfacher */ } static void __exit ablkuser_exit( void ) { return; } module_init(ablkuser_init); module_exit(ablkuser_exit); MODULE_LICENSE("GPL");