1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* 3 * Cryptographic API. 4 * 5 * Null algorithms, aka Much Ado About Nothing. 6 * 7 * These are needed for IPsec, and may be useful in general for 8 * testing & debugging. 9 * 10 * The null cipher is compliant with RFC2410. 11 * 12 * Copyright (c) 2002 James Morris <jmorris@intercode.com.au> 13 */ 14 15 #include <crypto/null.h> 16 #include <crypto/internal/hash.h> 17 #include <crypto/internal/skcipher.h> 18 #include <crypto/scatterwalk.h> 19 #include <linux/init.h> 20 #include <linux/module.h> 21 #include <linux/string.h> 22 23 static int null_init(struct shash_desc *desc) 24 { 25 return 0; 26 } 27 28 static int null_update(struct shash_desc *desc, const u8 *data, 29 unsigned int len) 30 { 31 return 0; 32 } 33 34 static int null_final(struct shash_desc *desc, u8 *out) 35 { 36 return 0; 37 } 38 39 static int null_digest(struct shash_desc *desc, const u8 *data, 40 unsigned int len, u8 *out) 41 { 42 return 0; 43 } 44 45 static int null_hash_setkey(struct crypto_shash *tfm, const u8 *key, 46 unsigned int keylen) 47 { return 0; } 48 49 static int null_skcipher_setkey(struct crypto_skcipher *tfm, const u8 *key, 50 unsigned int keylen) 51 { return 0; } 52 53 static int null_skcipher_crypt(struct skcipher_request *req) 54 { 55 if (req->src != req->dst) 56 memcpy_sglist(req->dst, req->src, req->cryptlen); 57 return 0; 58 } 59 60 static struct shash_alg digest_null = { 61 .digestsize = NULL_DIGEST_SIZE, 62 .setkey = null_hash_setkey, 63 .init = null_init, 64 .update = null_update, 65 .finup = null_digest, 66 .digest = null_digest, 67 .final = null_final, 68 .base = { 69 .cra_name = "digest_null", 70 .cra_driver_name = "digest_null-generic", 71 .cra_blocksize = NULL_BLOCK_SIZE, 72 .cra_module = THIS_MODULE, 73 } 74 }; 75 76 static struct skcipher_alg skcipher_null = { 77 .base.cra_name = "ecb(cipher_null)", 78 .base.cra_driver_name = "ecb-cipher_null", 79 .base.cra_priority = 100, 80 .base.cra_blocksize = NULL_BLOCK_SIZE, 81 .base.cra_ctxsize = 0, 82 .base.cra_module = THIS_MODULE, 83 .min_keysize = NULL_KEY_SIZE, 84 .max_keysize = NULL_KEY_SIZE, 85 .ivsize = NULL_IV_SIZE, 86 .setkey = null_skcipher_setkey, 87 .encrypt = null_skcipher_crypt, 88 .decrypt = null_skcipher_crypt, 89 }; 90 91 MODULE_ALIAS_CRYPTO("digest_null"); 92 MODULE_ALIAS_CRYPTO("ecb(cipher_null)"); 93 94 static int __init crypto_null_mod_init(void) 95 { 96 int ret = 0; 97 98 ret = crypto_register_shash(&digest_null); 99 if (ret < 0) 100 goto out; 101 102 ret = crypto_register_skcipher(&skcipher_null); 103 if (ret < 0) 104 goto out_unregister_shash; 105 106 return 0; 107 108 out_unregister_shash: 109 crypto_unregister_shash(&digest_null); 110 out: 111 return ret; 112 } 113 114 static void __exit crypto_null_mod_fini(void) 115 { 116 crypto_unregister_shash(&digest_null); 117 crypto_unregister_skcipher(&skcipher_null); 118 } 119 120 module_init(crypto_null_mod_init); 121 module_exit(crypto_null_mod_fini); 122 123 MODULE_LICENSE("GPL"); 124 MODULE_DESCRIPTION("Null Cryptographic Algorithms"); 125