PageRenderTime 41ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/fs/ecryptfs/debug.c

https://gitlab.com/LiquidSmooth-Devices/android_kernel_htc_msm8974
C | 108 lines | 80 code | 6 blank | 22 comment | 16 complexity | 32b67cc5a8aa01594a8649df27849597 MD5 | raw file
Possible License(s): GPL-2.0
  1. /**
  2. * eCryptfs: Linux filesystem encryption layer
  3. * Functions only useful for debugging.
  4. *
  5. * Copyright (C) 2006 International Business Machines Corp.
  6. * Author(s): Michael A. Halcrow <mahalcro@us.ibm.com>
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of the
  11. * License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  21. * 02111-1307, USA.
  22. */
  23. #include "ecryptfs_kernel.h"
  24. void ecryptfs_dump_auth_tok(struct ecryptfs_auth_tok *auth_tok)
  25. {
  26. char salt[ECRYPTFS_SALT_SIZE * 2 + 1];
  27. char sig[ECRYPTFS_SIG_SIZE_HEX + 1];
  28. ecryptfs_printk(KERN_DEBUG, "Auth tok at mem loc [%p]:\n",
  29. auth_tok);
  30. if (auth_tok->flags & ECRYPTFS_PRIVATE_KEY) {
  31. ecryptfs_printk(KERN_DEBUG, " * private key type\n");
  32. } else {
  33. ecryptfs_printk(KERN_DEBUG, " * passphrase type\n");
  34. ecryptfs_to_hex(salt, auth_tok->token.password.salt,
  35. ECRYPTFS_SALT_SIZE);
  36. salt[ECRYPTFS_SALT_SIZE * 2] = '\0';
  37. ecryptfs_printk(KERN_DEBUG, " * salt = [%s]\n", salt);
  38. if (auth_tok->token.password.flags &
  39. ECRYPTFS_PERSISTENT_PASSWORD) {
  40. ecryptfs_printk(KERN_DEBUG, " * persistent\n");
  41. }
  42. memcpy(sig, auth_tok->token.password.signature,
  43. ECRYPTFS_SIG_SIZE_HEX);
  44. sig[ECRYPTFS_SIG_SIZE_HEX] = '\0';
  45. ecryptfs_printk(KERN_DEBUG, " * signature = [%s]\n", sig);
  46. }
  47. ecryptfs_printk(KERN_DEBUG, " * session_key.flags = [0x%x]\n",
  48. auth_tok->session_key.flags);
  49. if (auth_tok->session_key.flags
  50. & ECRYPTFS_USERSPACE_SHOULD_TRY_TO_DECRYPT)
  51. ecryptfs_printk(KERN_DEBUG,
  52. " * Userspace decrypt request set\n");
  53. if (auth_tok->session_key.flags
  54. & ECRYPTFS_USERSPACE_SHOULD_TRY_TO_ENCRYPT)
  55. ecryptfs_printk(KERN_DEBUG,
  56. " * Userspace encrypt request set\n");
  57. if (auth_tok->session_key.flags & ECRYPTFS_CONTAINS_DECRYPTED_KEY) {
  58. ecryptfs_printk(KERN_DEBUG, " * Contains decrypted key\n");
  59. ecryptfs_printk(KERN_DEBUG,
  60. " * session_key.decrypted_key_size = [0x%x]\n",
  61. auth_tok->session_key.decrypted_key_size);
  62. ecryptfs_printk(KERN_DEBUG, " * Decrypted session key "
  63. "dump:\n");
  64. if (ecryptfs_verbosity > 0)
  65. ecryptfs_dump_hex(auth_tok->session_key.decrypted_key,
  66. ECRYPTFS_DEFAULT_KEY_BYTES);
  67. }
  68. if (auth_tok->session_key.flags & ECRYPTFS_CONTAINS_ENCRYPTED_KEY) {
  69. ecryptfs_printk(KERN_DEBUG, " * Contains encrypted key\n");
  70. ecryptfs_printk(KERN_DEBUG,
  71. " * session_key.encrypted_key_size = [0x%x]\n",
  72. auth_tok->session_key.encrypted_key_size);
  73. ecryptfs_printk(KERN_DEBUG, " * Encrypted session key "
  74. "dump:\n");
  75. if (ecryptfs_verbosity > 0)
  76. ecryptfs_dump_hex(auth_tok->session_key.encrypted_key,
  77. auth_tok->session_key.
  78. encrypted_key_size);
  79. }
  80. }
  81. void ecryptfs_dump_hex(char *data, int bytes)
  82. {
  83. int i = 0;
  84. int add_newline = 1;
  85. if (ecryptfs_verbosity < 1)
  86. return;
  87. if (bytes != 0) {
  88. printk(KERN_DEBUG "0x%.2x.", (unsigned char)data[i]);
  89. i++;
  90. }
  91. while (i < bytes) {
  92. printk("0x%.2x.", (unsigned char)data[i]);
  93. i++;
  94. if (i % 16 == 0) {
  95. printk("\n");
  96. add_newline = 0;
  97. } else
  98. add_newline = 1;
  99. }
  100. if (add_newline)
  101. printk("\n");
  102. }