ecryptfs.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #ifndef _LINUX_ECRYPTFS_H
  2. #define _LINUX_ECRYPTFS_H
  3. /* Version verification for shared data structures w/ userspace */
  4. #define ECRYPTFS_VERSION_MAJOR 0x00
  5. #define ECRYPTFS_VERSION_MINOR 0x04
  6. #define ECRYPTFS_SUPPORTED_FILE_VERSION 0x03
  7. /* These flags indicate which features are supported by the kernel
  8. * module; userspace tools such as the mount helper read the feature
  9. * bits from a sysfs handle in order to determine how to behave. */
  10. #define ECRYPTFS_VERSIONING_PASSPHRASE 0x00000001
  11. #define ECRYPTFS_VERSIONING_PUBKEY 0x00000002
  12. #define ECRYPTFS_VERSIONING_PLAINTEXT_PASSTHROUGH 0x00000004
  13. #define ECRYPTFS_VERSIONING_POLICY 0x00000008
  14. #define ECRYPTFS_VERSIONING_XATTR 0x00000010
  15. #define ECRYPTFS_VERSIONING_MULTKEY 0x00000020
  16. #define ECRYPTFS_VERSIONING_DEVMISC 0x00000040
  17. #define ECRYPTFS_VERSIONING_HMAC 0x00000080
  18. #define ECRYPTFS_VERSIONING_FILENAME_ENCRYPTION 0x00000100
  19. #define ECRYPTFS_VERSIONING_GCM 0x00000200
  20. #define ECRYPTFS_MAX_PASSWORD_LENGTH 64
  21. #define ECRYPTFS_MAX_PASSPHRASE_BYTES ECRYPTFS_MAX_PASSWORD_LENGTH
  22. #define ECRYPTFS_SALT_SIZE 8
  23. #define ECRYPTFS_SALT_SIZE_HEX (ECRYPTFS_SALT_SIZE*2)
  24. /* The original signature size is only for what is stored on disk; all
  25. * in-memory representations are expanded hex, so it better adapted to
  26. * be passed around or referenced on the command line */
  27. #define ECRYPTFS_SIG_SIZE 8
  28. #define ECRYPTFS_SIG_SIZE_HEX (ECRYPTFS_SIG_SIZE*2)
  29. #define ECRYPTFS_PASSWORD_SIG_SIZE ECRYPTFS_SIG_SIZE_HEX
  30. #define ECRYPTFS_MAX_KEY_BYTES 64
  31. #define ECRYPTFS_MAX_ENCRYPTED_KEY_BYTES 512
  32. #define ECRYPTFS_FILE_VERSION 0x03
  33. #define ECRYPTFS_MAX_PKI_NAME_BYTES 16
  34. #define RFC2440_CIPHER_DES3_EDE 0x02
  35. #define RFC2440_CIPHER_CAST_5 0x03
  36. #define RFC2440_CIPHER_BLOWFISH 0x04
  37. #define RFC2440_CIPHER_AES_128 0x07
  38. #define RFC2440_CIPHER_AES_192 0x08
  39. #define RFC2440_CIPHER_AES_256 0x09
  40. #define RFC2440_CIPHER_TWOFISH 0x0a
  41. #define RFC2440_CIPHER_CAST_6 0x0b
  42. #define RFC2440_CIPHER_RSA 0x01
  43. /**
  44. * For convenience, we may need to pass around the encrypted session
  45. * key between kernel and userspace because the authentication token
  46. * may not be extractable. For example, the TPM may not release the
  47. * private key, instead requiring the encrypted data and returning the
  48. * decrypted data.
  49. */
  50. struct ecryptfs_session_key {
  51. #define ECRYPTFS_USERSPACE_SHOULD_TRY_TO_DECRYPT 0x00000001
  52. #define ECRYPTFS_USERSPACE_SHOULD_TRY_TO_ENCRYPT 0x00000002
  53. #define ECRYPTFS_CONTAINS_DECRYPTED_KEY 0x00000004
  54. #define ECRYPTFS_CONTAINS_ENCRYPTED_KEY 0x00000008
  55. u32 flags;
  56. u32 encrypted_key_size;
  57. u32 decrypted_key_size;
  58. u8 encrypted_key[ECRYPTFS_MAX_ENCRYPTED_KEY_BYTES];
  59. u8 decrypted_key[ECRYPTFS_MAX_KEY_BYTES];
  60. };
  61. struct ecryptfs_password {
  62. u32 password_bytes;
  63. s32 hash_algo;
  64. u32 hash_iterations;
  65. u32 session_key_encryption_key_bytes;
  66. #define ECRYPTFS_PERSISTENT_PASSWORD 0x01
  67. #define ECRYPTFS_SESSION_KEY_ENCRYPTION_KEY_SET 0x02
  68. u32 flags;
  69. /* Iterated-hash concatenation of salt and passphrase */
  70. u8 session_key_encryption_key[ECRYPTFS_MAX_KEY_BYTES];
  71. u8 signature[ECRYPTFS_PASSWORD_SIG_SIZE + 1];
  72. /* Always in expanded hex */
  73. u8 salt[ECRYPTFS_SALT_SIZE];
  74. };
  75. enum ecryptfs_token_types {ECRYPTFS_PASSWORD, ECRYPTFS_PRIVATE_KEY};
  76. struct ecryptfs_private_key {
  77. u32 key_size;
  78. u32 data_len;
  79. u8 signature[ECRYPTFS_PASSWORD_SIG_SIZE + 1];
  80. char pki_type[ECRYPTFS_MAX_PKI_NAME_BYTES + 1];
  81. u8 data[];
  82. };
  83. /* May be a password or a private key */
  84. struct ecryptfs_auth_tok {
  85. u16 version; /* 8-bit major and 8-bit minor */
  86. u16 token_type;
  87. #define ECRYPTFS_ENCRYPT_ONLY 0x00000001
  88. u32 flags;
  89. struct ecryptfs_session_key session_key;
  90. u8 reserved[32];
  91. union {
  92. struct ecryptfs_password password;
  93. struct ecryptfs_private_key private_key;
  94. } token;
  95. } __attribute__ ((packed));
  96. #endif /* _LINUX_ECRYPTFS_H */