ecryptfs_format.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * ecryptfs_format.c: helper functions for the encrypted key type
  4. *
  5. * Copyright (C) 2006 International Business Machines Corp.
  6. * Copyright (C) 2010 Politecnico di Torino, Italy
  7. * TORSEC group -- https://security.polito.it
  8. *
  9. * Authors:
  10. * Michael A. Halcrow <[email protected]>
  11. * Tyler Hicks <[email protected]>
  12. * Roberto Sassu <[email protected]>
  13. */
  14. #include <linux/export.h>
  15. #include <linux/string.h>
  16. #include "ecryptfs_format.h"
  17. u8 *ecryptfs_get_auth_tok_key(struct ecryptfs_auth_tok *auth_tok)
  18. {
  19. return auth_tok->token.password.session_key_encryption_key;
  20. }
  21. EXPORT_SYMBOL(ecryptfs_get_auth_tok_key);
  22. /*
  23. * ecryptfs_get_versions()
  24. *
  25. * Source code taken from the software 'ecryptfs-utils' version 83.
  26. *
  27. */
  28. void ecryptfs_get_versions(int *major, int *minor, int *file_version)
  29. {
  30. *major = ECRYPTFS_VERSION_MAJOR;
  31. *minor = ECRYPTFS_VERSION_MINOR;
  32. if (file_version)
  33. *file_version = ECRYPTFS_SUPPORTED_FILE_VERSION;
  34. }
  35. EXPORT_SYMBOL(ecryptfs_get_versions);
  36. /*
  37. * ecryptfs_fill_auth_tok - fill the ecryptfs_auth_tok structure
  38. *
  39. * Fill the ecryptfs_auth_tok structure with required ecryptfs data.
  40. * The source code is inspired to the original function generate_payload()
  41. * shipped with the software 'ecryptfs-utils' version 83.
  42. *
  43. */
  44. int ecryptfs_fill_auth_tok(struct ecryptfs_auth_tok *auth_tok,
  45. const char *key_desc)
  46. {
  47. int major, minor;
  48. ecryptfs_get_versions(&major, &minor, NULL);
  49. auth_tok->version = (((uint16_t)(major << 8) & 0xFF00)
  50. | ((uint16_t)minor & 0x00FF));
  51. auth_tok->token_type = ECRYPTFS_PASSWORD;
  52. strncpy((char *)auth_tok->token.password.signature, key_desc,
  53. ECRYPTFS_PASSWORD_SIG_SIZE);
  54. auth_tok->token.password.session_key_encryption_key_bytes =
  55. ECRYPTFS_MAX_KEY_BYTES;
  56. /*
  57. * Removed auth_tok->token.password.salt and
  58. * auth_tok->token.password.session_key_encryption_key
  59. * initialization from the original code
  60. */
  61. /* TODO: Make the hash parameterizable via policy */
  62. auth_tok->token.password.flags |=
  63. ECRYPTFS_SESSION_KEY_ENCRYPTION_KEY_SET;
  64. /* The kernel code will encrypt the session key. */
  65. auth_tok->session_key.encrypted_key[0] = 0;
  66. auth_tok->session_key.encrypted_key_size = 0;
  67. /* Default; subject to change by kernel eCryptfs */
  68. auth_tok->token.password.hash_algo = PGP_DIGEST_ALGO_SHA512;
  69. auth_tok->token.password.flags &= ~(ECRYPTFS_PERSISTENT_PASSWORD);
  70. return 0;
  71. }
  72. EXPORT_SYMBOL(ecryptfs_fill_auth_tok);