makesalt.c 3.6 KB

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