ecryptfs_format.c 2.6 KB

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