diff --git a/index.html b/index.html index 3e5889b..faf3de8 100644 --- a/index.html +++ b/index.html @@ -5609,106 +5609,104 @@ and a password. 99{ 100    int ret = -EFAULT; 101    unsigned char key[SYMMETRIC_KEY_LENGTH]; -102    crypto_completion_t compl ; -103 -104    if (!sk->tfm) { -105        sk->tfm = crypto_alloc_skcipher("cbc-aes-aesni", 0, 0); -106        if (IS_ERR(sk->tfm)) { -107            pr_info("could not allocate skcipher handle\n"); -108            return PTR_ERR(sk->tfm); -109        } -110    } -111 -112    if (!sk->req) { -113        sk->req = skcipher_request_alloc(sk->tfm, GFP_KERNEL); -114        if (!sk->req) { -115            pr_info("could not allocate skcipher request\n"); -116            ret = -ENOMEM; -117            goto out; -118        } -119    } -120 -121    compl = (crypto_completion_t)test_skcipher_callback; -122    skcipher_request_set_callback(sk->req, CRYPTO_TFM_REQ_MAY_BACKLOG, compl, -123                                  &sk->result); -124 -125    /* clear the key */ -126    memset((void *)key, '\0', SYMMETRIC_KEY_LENGTH); -127 -128    /* Use the world's favourite password */ -129    sprintf((char *)key, "%s", password); -130 -131    /* AES 256 with given symmetric key */ -132    if (crypto_skcipher_setkey(sk->tfm, key, SYMMETRIC_KEY_LENGTH)) { -133        pr_info("key could not be set\n"); -134        ret = -EAGAIN; -135        goto out; -136    } -137    pr_info("Symmetric key: %s\n", key); -138    pr_info("Plaintext: %s\n", plaintext); -139 -140    if (!sk->ivdata) { -141        /* see https://en.wikipedia.org/wiki/Initialization_vector */ -142        sk->ivdata = kmalloc(CIPHER_BLOCK_SIZE, GFP_KERNEL); -143        if (!sk->ivdata) { -144            pr_info("could not allocate ivdata\n"); -145            goto out; -146        } -147        get_random_bytes(sk->ivdata, CIPHER_BLOCK_SIZE); -148    } -149 -150    if (!sk->scratchpad) { -151        /* The text to be encrypted */ -152        sk->scratchpad = kmalloc(CIPHER_BLOCK_SIZE, GFP_KERNEL); -153        if (!sk->scratchpad) { -154            pr_info("could not allocate scratchpad\n"); -155            goto out; -156        } -157    } -158    sprintf((char *)sk->scratchpad, "%s", plaintext); -159 -160    sg_init_one(&sk->sg, sk->scratchpad, CIPHER_BLOCK_SIZE); -161    skcipher_request_set_crypt(sk->req, &sk->sg, &sk->sg, CIPHER_BLOCK_SIZE, -162                               sk->ivdata); -163    init_completion(&sk->result.completion); -164 -165    /* encrypt data */ -166    ret = crypto_skcipher_encrypt(sk->req); -167    ret = test_skcipher_result(sk, ret); -168    if (ret) -169        goto out; +102 +103    if (!sk->tfm) { +104        sk->tfm = crypto_alloc_skcipher("cbc-aes-aesni", 0, 0); +105        if (IS_ERR(sk->tfm)) { +106            pr_info("could not allocate skcipher handle\n"); +107            return PTR_ERR(sk->tfm); +108        } +109    } +110 +111    if (!sk->req) { +112        sk->req = skcipher_request_alloc(sk->tfm, GFP_KERNEL); +113        if (!sk->req) { +114            pr_info("could not allocate skcipher request\n"); +115            ret = -ENOMEM; +116            goto out; +117        } +118    } +119 +120    skcipher_request_set_callback(sk->req, CRYPTO_TFM_REQ_MAY_BACKLOG, +121                                  test_skcipher_callback, &sk->result); +122 +123    /* clear the key */ +124    memset((void *)key, '\0', SYMMETRIC_KEY_LENGTH); +125 +126    /* Use the world's favourite password */ +127    sprintf((char *)key, "%s", password); +128 +129    /* AES 256 with given symmetric key */ +130    if (crypto_skcipher_setkey(sk->tfm, key, SYMMETRIC_KEY_LENGTH)) { +131        pr_info("key could not be set\n"); +132        ret = -EAGAIN; +133        goto out; +134    } +135    pr_info("Symmetric key: %s\n", key); +136    pr_info("Plaintext: %s\n", plaintext); +137 +138    if (!sk->ivdata) { +139        /* see https://en.wikipedia.org/wiki/Initialization_vector */ +140        sk->ivdata = kmalloc(CIPHER_BLOCK_SIZE, GFP_KERNEL); +141        if (!sk->ivdata) { +142            pr_info("could not allocate ivdata\n"); +143            goto out; +144        } +145        get_random_bytes(sk->ivdata, CIPHER_BLOCK_SIZE); +146    } +147 +148    if (!sk->scratchpad) { +149        /* The text to be encrypted */ +150        sk->scratchpad = kmalloc(CIPHER_BLOCK_SIZE, GFP_KERNEL); +151        if (!sk->scratchpad) { +152            pr_info("could not allocate scratchpad\n"); +153            goto out; +154        } +155    } +156    sprintf((char *)sk->scratchpad, "%s", plaintext); +157 +158    sg_init_one(&sk->sg, sk->scratchpad, CIPHER_BLOCK_SIZE); +159    skcipher_request_set_crypt(sk->req, &sk->sg, &sk->sg, CIPHER_BLOCK_SIZE, +160                               sk->ivdata); +161    init_completion(&sk->result.completion); +162 +163    /* encrypt data */ +164    ret = crypto_skcipher_encrypt(sk->req); +165    ret = test_skcipher_result(sk, ret); +166    if (ret) +167        goto out; +168 +169    pr_info("Encryption request successful\n"); 170 -171    pr_info("Encryption request successful\n"); -172 -173out: -174    return ret; -175} -176 -177static int __init cryptoapi_init(void) -178{ -179    /* The world's favorite password */ -180    char *password = "password123"; -181 -182    sk.tfm = NULL; -183    sk.req = NULL; -184    sk.scratchpad = NULL; -185    sk.ciphertext = NULL; -186    sk.ivdata = NULL; -187 -188    test_skcipher_encrypt("Testing", password, &sk); -189    return 0; -190} -191 -192static void __exit cryptoapi_exit(void) -193{ -194    test_skcipher_finish(&sk); -195} -196 -197module_init(cryptoapi_init); -198module_exit(cryptoapi_exit); -199 -200MODULE_DESCRIPTION("Symmetric key encryption example"); -201MODULE_LICENSE("GPL"); +171out: +172    return ret; +173} +174 +175static int __init cryptoapi_init(void) +176{ +177    /* The world's favorite password */ +178    char *password = "password123"; +179 +180    sk.tfm = NULL; +181    sk.req = NULL; +182    sk.scratchpad = NULL; +183    sk.ciphertext = NULL; +184    sk.ivdata = NULL; +185 +186    test_skcipher_encrypt("Testing", password, &sk); +187    return 0; +188} +189 +190static void __exit cryptoapi_exit(void) +191{ +192    test_skcipher_finish(&sk); +193} +194 +195module_init(cryptoapi_init); +196module_exit(cryptoapi_exit); +197 +198MODULE_DESCRIPTION("Symmetric key encryption example"); +199MODULE_LICENSE("GPL");

17 Virtual Input Device Driver

diff --git a/lkmpg-for-ht.html b/lkmpg-for-ht.html index 3e5889b..faf3de8 100644 --- a/lkmpg-for-ht.html +++ b/lkmpg-for-ht.html @@ -5609,106 +5609,104 @@ and a password. 99{ 100    int ret = -EFAULT; 101    unsigned char key[SYMMETRIC_KEY_LENGTH]; -102    crypto_completion_t compl ; -103 -104    if (!sk->tfm) { -105        sk->tfm = crypto_alloc_skcipher("cbc-aes-aesni", 0, 0); -106        if (IS_ERR(sk->tfm)) { -107            pr_info("could not allocate skcipher handle\n"); -108            return PTR_ERR(sk->tfm); -109        } -110    } -111 -112    if (!sk->req) { -113        sk->req = skcipher_request_alloc(sk->tfm, GFP_KERNEL); -114        if (!sk->req) { -115            pr_info("could not allocate skcipher request\n"); -116            ret = -ENOMEM; -117            goto out; -118        } -119    } -120 -121    compl = (crypto_completion_t)test_skcipher_callback; -122    skcipher_request_set_callback(sk->req, CRYPTO_TFM_REQ_MAY_BACKLOG, compl, -123                                  &sk->result); -124 -125    /* clear the key */ -126    memset((void *)key, '\0', SYMMETRIC_KEY_LENGTH); -127 -128    /* Use the world's favourite password */ -129    sprintf((char *)key, "%s", password); -130 -131    /* AES 256 with given symmetric key */ -132    if (crypto_skcipher_setkey(sk->tfm, key, SYMMETRIC_KEY_LENGTH)) { -133        pr_info("key could not be set\n"); -134        ret = -EAGAIN; -135        goto out; -136    } -137    pr_info("Symmetric key: %s\n", key); -138    pr_info("Plaintext: %s\n", plaintext); -139 -140    if (!sk->ivdata) { -141        /* see https://en.wikipedia.org/wiki/Initialization_vector */ -142        sk->ivdata = kmalloc(CIPHER_BLOCK_SIZE, GFP_KERNEL); -143        if (!sk->ivdata) { -144            pr_info("could not allocate ivdata\n"); -145            goto out; -146        } -147        get_random_bytes(sk->ivdata, CIPHER_BLOCK_SIZE); -148    } -149 -150    if (!sk->scratchpad) { -151        /* The text to be encrypted */ -152        sk->scratchpad = kmalloc(CIPHER_BLOCK_SIZE, GFP_KERNEL); -153        if (!sk->scratchpad) { -154            pr_info("could not allocate scratchpad\n"); -155            goto out; -156        } -157    } -158    sprintf((char *)sk->scratchpad, "%s", plaintext); -159 -160    sg_init_one(&sk->sg, sk->scratchpad, CIPHER_BLOCK_SIZE); -161    skcipher_request_set_crypt(sk->req, &sk->sg, &sk->sg, CIPHER_BLOCK_SIZE, -162                               sk->ivdata); -163    init_completion(&sk->result.completion); -164 -165    /* encrypt data */ -166    ret = crypto_skcipher_encrypt(sk->req); -167    ret = test_skcipher_result(sk, ret); -168    if (ret) -169        goto out; +102 +103    if (!sk->tfm) { +104        sk->tfm = crypto_alloc_skcipher("cbc-aes-aesni", 0, 0); +105        if (IS_ERR(sk->tfm)) { +106            pr_info("could not allocate skcipher handle\n"); +107            return PTR_ERR(sk->tfm); +108        } +109    } +110 +111    if (!sk->req) { +112        sk->req = skcipher_request_alloc(sk->tfm, GFP_KERNEL); +113        if (!sk->req) { +114            pr_info("could not allocate skcipher request\n"); +115            ret = -ENOMEM; +116            goto out; +117        } +118    } +119 +120    skcipher_request_set_callback(sk->req, CRYPTO_TFM_REQ_MAY_BACKLOG, +121                                  test_skcipher_callback, &sk->result); +122 +123    /* clear the key */ +124    memset((void *)key, '\0', SYMMETRIC_KEY_LENGTH); +125 +126    /* Use the world's favourite password */ +127    sprintf((char *)key, "%s", password); +128 +129    /* AES 256 with given symmetric key */ +130    if (crypto_skcipher_setkey(sk->tfm, key, SYMMETRIC_KEY_LENGTH)) { +131        pr_info("key could not be set\n"); +132        ret = -EAGAIN; +133        goto out; +134    } +135    pr_info("Symmetric key: %s\n", key); +136    pr_info("Plaintext: %s\n", plaintext); +137 +138    if (!sk->ivdata) { +139        /* see https://en.wikipedia.org/wiki/Initialization_vector */ +140        sk->ivdata = kmalloc(CIPHER_BLOCK_SIZE, GFP_KERNEL); +141        if (!sk->ivdata) { +142            pr_info("could not allocate ivdata\n"); +143            goto out; +144        } +145        get_random_bytes(sk->ivdata, CIPHER_BLOCK_SIZE); +146    } +147 +148    if (!sk->scratchpad) { +149        /* The text to be encrypted */ +150        sk->scratchpad = kmalloc(CIPHER_BLOCK_SIZE, GFP_KERNEL); +151        if (!sk->scratchpad) { +152            pr_info("could not allocate scratchpad\n"); +153            goto out; +154        } +155    } +156    sprintf((char *)sk->scratchpad, "%s", plaintext); +157 +158    sg_init_one(&sk->sg, sk->scratchpad, CIPHER_BLOCK_SIZE); +159    skcipher_request_set_crypt(sk->req, &sk->sg, &sk->sg, CIPHER_BLOCK_SIZE, +160                               sk->ivdata); +161    init_completion(&sk->result.completion); +162 +163    /* encrypt data */ +164    ret = crypto_skcipher_encrypt(sk->req); +165    ret = test_skcipher_result(sk, ret); +166    if (ret) +167        goto out; +168 +169    pr_info("Encryption request successful\n"); 170 -171    pr_info("Encryption request successful\n"); -172 -173out: -174    return ret; -175} -176 -177static int __init cryptoapi_init(void) -178{ -179    /* The world's favorite password */ -180    char *password = "password123"; -181 -182    sk.tfm = NULL; -183    sk.req = NULL; -184    sk.scratchpad = NULL; -185    sk.ciphertext = NULL; -186    sk.ivdata = NULL; -187 -188    test_skcipher_encrypt("Testing", password, &sk); -189    return 0; -190} -191 -192static void __exit cryptoapi_exit(void) -193{ -194    test_skcipher_finish(&sk); -195} -196 -197module_init(cryptoapi_init); -198module_exit(cryptoapi_exit); -199 -200MODULE_DESCRIPTION("Symmetric key encryption example"); -201MODULE_LICENSE("GPL"); +171out: +172    return ret; +173} +174 +175static int __init cryptoapi_init(void) +176{ +177    /* The world's favorite password */ +178    char *password = "password123"; +179 +180    sk.tfm = NULL; +181    sk.req = NULL; +182    sk.scratchpad = NULL; +183    sk.ciphertext = NULL; +184    sk.ivdata = NULL; +185 +186    test_skcipher_encrypt("Testing", password, &sk); +187    return 0; +188} +189 +190static void __exit cryptoapi_exit(void) +191{ +192    test_skcipher_finish(&sk); +193} +194 +195module_init(cryptoapi_init); +196module_exit(cryptoapi_exit); +197 +198MODULE_DESCRIPTION("Symmetric key encryption example"); +199MODULE_LICENSE("GPL");

17 Virtual Input Device Driver