4 * Null algorithms, aka Much Ado About Nothing.
6 * These are needed for IPsec, and may be useful in general for
9 * The null cipher is compliant with RFC2410.
11 * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
19 #include <linux/init.h>
20 #include <linux/module.h>
22 #include <linux/crypto.h>
23 #include <linux/string.h>
25 #define NULL_KEY_SIZE 0
26 #define NULL_BLOCK_SIZE 1
27 #define NULL_DIGEST_SIZE 0
29 static int null_compress(struct crypto_tfm *tfm, const u8 *src,
30 unsigned int slen, u8 *dst, unsigned int *dlen)
34 memcpy(dst, src, slen);
39 static void null_init(struct crypto_tfm *tfm)
42 static void null_update(struct crypto_tfm *tfm, const u8 *data,
46 static void null_final(struct crypto_tfm *tfm, u8 *out)
49 static int null_setkey(struct crypto_tfm *tfm, const u8 *key,
53 static void null_crypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
55 memcpy(dst, src, NULL_BLOCK_SIZE);
58 static struct crypto_alg compress_null = {
59 .cra_name = "compress_null",
60 .cra_flags = CRYPTO_ALG_TYPE_COMPRESS,
61 .cra_blocksize = NULL_BLOCK_SIZE,
63 .cra_module = THIS_MODULE,
64 .cra_list = LIST_HEAD_INIT(compress_null.cra_list),
65 .cra_u = { .compress = {
66 .coa_compress = null_compress,
67 .coa_decompress = null_compress } }
70 static struct crypto_alg digest_null = {
71 .cra_name = "digest_null",
72 .cra_flags = CRYPTO_ALG_TYPE_DIGEST,
73 .cra_blocksize = NULL_BLOCK_SIZE,
75 .cra_module = THIS_MODULE,
76 .cra_list = LIST_HEAD_INIT(digest_null.cra_list),
77 .cra_u = { .digest = {
78 .dia_digestsize = NULL_DIGEST_SIZE,
79 .dia_init = null_init,
80 .dia_update = null_update,
81 .dia_final = null_final } }
84 static struct crypto_alg cipher_null = {
85 .cra_name = "cipher_null",
86 .cra_flags = CRYPTO_ALG_TYPE_CIPHER,
87 .cra_blocksize = NULL_BLOCK_SIZE,
89 .cra_module = THIS_MODULE,
90 .cra_list = LIST_HEAD_INIT(cipher_null.cra_list),
91 .cra_u = { .cipher = {
92 .cia_min_keysize = NULL_KEY_SIZE,
93 .cia_max_keysize = NULL_KEY_SIZE,
94 .cia_setkey = null_setkey,
95 .cia_encrypt = null_crypt,
96 .cia_decrypt = null_crypt } }
99 MODULE_ALIAS("compress_null");
100 MODULE_ALIAS("digest_null");
101 MODULE_ALIAS("cipher_null");
103 static int __init init(void)
107 ret = crypto_register_alg(&cipher_null);
111 ret = crypto_register_alg(&digest_null);
113 crypto_unregister_alg(&cipher_null);
117 ret = crypto_register_alg(&compress_null);
119 crypto_unregister_alg(&digest_null);
120 crypto_unregister_alg(&cipher_null);
128 static void __exit fini(void)
130 crypto_unregister_alg(&compress_null);
131 crypto_unregister_alg(&digest_null);
132 crypto_unregister_alg(&cipher_null);
138 MODULE_LICENSE("GPL");
139 MODULE_DESCRIPTION("Null Cryptographic Algorithms");