/crypto/crypto_null.c

https://bitbucket.org/evzijst/gittest · C · 137 lines · 98 code · 21 blank · 18 comment · 3 complexity · c34bc347e12e68a270ebb83dcc7696fc MD5 · raw file

  1. /*
  2. * Cryptographic API.
  3. *
  4. * Null algorithms, aka Much Ado About Nothing.
  5. *
  6. * These are needed for IPsec, and may be useful in general for
  7. * testing & debugging.
  8. *
  9. * The null cipher is compliant with RFC2410.
  10. *
  11. * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
  12. *
  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.
  17. *
  18. */
  19. #include <linux/init.h>
  20. #include <linux/module.h>
  21. #include <linux/mm.h>
  22. #include <asm/scatterlist.h>
  23. #include <linux/crypto.h>
  24. #define NULL_KEY_SIZE 0
  25. #define NULL_BLOCK_SIZE 1
  26. #define NULL_DIGEST_SIZE 0
  27. static int null_compress(void *ctx, const u8 *src, unsigned int slen,
  28. u8 *dst, unsigned int *dlen)
  29. { return 0; }
  30. static int null_decompress(void *ctx, const u8 *src, unsigned int slen,
  31. u8 *dst, unsigned int *dlen)
  32. { return 0; }
  33. static void null_init(void *ctx)
  34. { }
  35. static void null_update(void *ctx, const u8 *data, unsigned int len)
  36. { }
  37. static void null_final(void *ctx, u8 *out)
  38. { }
  39. static int null_setkey(void *ctx, const u8 *key,
  40. unsigned int keylen, u32 *flags)
  41. { return 0; }
  42. static void null_encrypt(void *ctx, u8 *dst, const u8 *src)
  43. { }
  44. static void null_decrypt(void *ctx, u8 *dst, const u8 *src)
  45. { }
  46. static struct crypto_alg compress_null = {
  47. .cra_name = "compress_null",
  48. .cra_flags = CRYPTO_ALG_TYPE_COMPRESS,
  49. .cra_blocksize = NULL_BLOCK_SIZE,
  50. .cra_ctxsize = 0,
  51. .cra_module = THIS_MODULE,
  52. .cra_list = LIST_HEAD_INIT(compress_null.cra_list),
  53. .cra_u = { .compress = {
  54. .coa_compress = null_compress,
  55. .coa_decompress = null_decompress } }
  56. };
  57. static struct crypto_alg digest_null = {
  58. .cra_name = "digest_null",
  59. .cra_flags = CRYPTO_ALG_TYPE_DIGEST,
  60. .cra_blocksize = NULL_BLOCK_SIZE,
  61. .cra_ctxsize = 0,
  62. .cra_module = THIS_MODULE,
  63. .cra_list = LIST_HEAD_INIT(digest_null.cra_list),
  64. .cra_u = { .digest = {
  65. .dia_digestsize = NULL_DIGEST_SIZE,
  66. .dia_init = null_init,
  67. .dia_update = null_update,
  68. .dia_final = null_final } }
  69. };
  70. static struct crypto_alg cipher_null = {
  71. .cra_name = "cipher_null",
  72. .cra_flags = CRYPTO_ALG_TYPE_CIPHER,
  73. .cra_blocksize = NULL_BLOCK_SIZE,
  74. .cra_ctxsize = 0,
  75. .cra_module = THIS_MODULE,
  76. .cra_list = LIST_HEAD_INIT(cipher_null.cra_list),
  77. .cra_u = { .cipher = {
  78. .cia_min_keysize = NULL_KEY_SIZE,
  79. .cia_max_keysize = NULL_KEY_SIZE,
  80. .cia_setkey = null_setkey,
  81. .cia_encrypt = null_encrypt,
  82. .cia_decrypt = null_decrypt } }
  83. };
  84. MODULE_ALIAS("compress_null");
  85. MODULE_ALIAS("digest_null");
  86. MODULE_ALIAS("cipher_null");
  87. static int __init init(void)
  88. {
  89. int ret = 0;
  90. ret = crypto_register_alg(&cipher_null);
  91. if (ret < 0)
  92. goto out;
  93. ret = crypto_register_alg(&digest_null);
  94. if (ret < 0) {
  95. crypto_unregister_alg(&cipher_null);
  96. goto out;
  97. }
  98. ret = crypto_register_alg(&compress_null);
  99. if (ret < 0) {
  100. crypto_unregister_alg(&digest_null);
  101. crypto_unregister_alg(&cipher_null);
  102. goto out;
  103. }
  104. out:
  105. return ret;
  106. }
  107. static void __exit fini(void)
  108. {
  109. crypto_unregister_alg(&compress_null);
  110. crypto_unregister_alg(&digest_null);
  111. crypto_unregister_alg(&cipher_null);
  112. }
  113. module_init(init);
  114. module_exit(fini);
  115. MODULE_LICENSE("GPL");
  116. MODULE_DESCRIPTION("Null Cryptographic Algorithms");