makesalt.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /************************************************************************
  2. * psybnc2.2.2, tools/makesalt.c
  3. * Copyright (C) 2001 the most psychoid and
  4. * the cool lam3rz IRC Group, IRCnet
  5. * http://www.psychoid.lam3rz.de
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 1, or (at your option)
  10. * any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <strings.h>
  24. #include <time.h>
  25. char rbuf[100];
  26. const char *
  27. randstring (int length)
  28. {
  29. char *po;
  30. int i;
  31. po = rbuf;
  32. if (length > 100)
  33. length = 100;
  34. for (i = 0; i < length; i++)
  35. {
  36. *po = (char) (0x61 + (rand () & 15));
  37. po++;
  38. }
  39. *po = 0;
  40. po = rbuf;
  41. return po;
  42. }
  43. int
  44. main (void)
  45. {
  46. FILE *salt;
  47. int saltlen1;
  48. int saltlen2;
  49. int foo;
  50. srand (time (NULL));
  51. saltlen1 = (rand () & 20) + 5;
  52. saltlen2 = (rand () & 20) + 5;
  53. if ((salt = fopen ("salt.h", "r")) != NULL)
  54. {
  55. fclose (salt);
  56. printf ("Using existent Salt-File\n");
  57. exit (0x0);
  58. }
  59. printf ("Creating Salt File\n");
  60. if ((salt = fopen ("salt.h", "w")) == NULL)
  61. {
  62. printf ("Cannot created Salt-File.. aborting\n");
  63. exit (0x1);
  64. }
  65. fprintf (salt,
  66. "/* The 1. Salt -> string containing anything, %d chars */\n",
  67. saltlen1);
  68. fprintf (salt, "#define SALT1 %c%s%c\n", 34, randstring (saltlen1), 34);
  69. fprintf (salt, "\n");
  70. fprintf (salt,
  71. "/* The 2. Salt -> string containing anything, %d chars */\n",
  72. saltlen2);
  73. fprintf (salt, "#define SALT2 %c%s%c\n", 34, randstring (saltlen2), 34);
  74. fprintf (salt, "\n");
  75. fprintf (salt, "/* the 1. Code -> a one byte startup code */\n");
  76. fprintf (salt, "#define CODE1 %d\n", 64 + (rand () & 15));
  77. fprintf (salt, "\n");
  78. fprintf (salt, "/* the 2. Code -> a one byte startup code */\n");
  79. fprintf (salt, "#define CODE2 %d\n", 64 + (rand () & 15));
  80. fprintf (salt, "\n");
  81. fprintf (salt, "/* the 1. Salt Offset -> value from 0-%d */\n",
  82. saltlen1 - 1);
  83. fprintf (salt, "#define SA1 %d\n", rand () & (saltlen1 - 1));
  84. fprintf (salt, "\n");
  85. fprintf (salt, "/* the 2. Salt Offset -> value from 0-%d */\n",
  86. saltlen2 - 1);
  87. fprintf (salt, "#define SA2 %d\n", rand () & (saltlen2 - 1));
  88. fprintf (salt, "\n");
  89. fprintf (salt, "/* the make salt routine */\n");
  90. fprintf (salt,
  91. "/* dont wonder about the redundance, its needed to somehow hide the fully salts */\n");
  92. fprintf (salt, "\n");
  93. fprintf (salt, "/* salt buffers */\n");
  94. fprintf (salt, "\n");
  95. fprintf (salt, "unsigned char slt1[%d];\n", saltlen1 + 1);
  96. fprintf (salt, "unsigned char slt2[%d];\n", saltlen2 + 1);
  97. fprintf (salt, "\n");
  98. fprintf (salt, "int makesalt(void)\n");
  99. fprintf (salt, "{\n");
  100. for (foo = 0; foo < saltlen1; foo++)
  101. fprintf (salt, " slt1[%d]=SALT1[%d];\n", foo, foo);
  102. fprintf (salt, " slt1[%d]=0;\n", saltlen1);
  103. for (foo = 0; foo < saltlen2; foo++)
  104. fprintf (salt, " slt2[%d]=SALT2[%d];\n", foo, foo);
  105. fprintf (salt, " slt2[%d]=0;\n", saltlen2);
  106. fprintf (salt, "}");
  107. fprintf (salt, "\n");
  108. fclose (salt);
  109. printf ("Salt File created.\n");
  110. exit (0x0);
  111. }