1
0

makesalt.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * makesalt.c -- handles:
  3. * making the salt for the encryption.
  4. *
  5. */
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <strings.h>
  9. #include <time.h>
  10. #include <sys/types.h>
  11. #include <unistd.h>
  12. /* Create a string with random letters and digits
  13. */
  14. char *randstring(int len)
  15. {
  16. int j, r = 0;
  17. static char s[100];
  18. for (j = 0; j < len; j++) {
  19. r = random();
  20. if (r % 4 == 0)
  21. s[j] = '0' + (random() % 10);
  22. else if (r % 4 == 1)
  23. s[j] = 'a' + (random() % 26);
  24. else if (r % 4 == 2)
  25. s[j] = 'A' + (random() % 26);
  26. else
  27. s[j] = '!' + (random() % 15);
  28. if (s[j] == 33 || s[j] == 37 || s[j] == 34 || s[j] == 40 || s[j] == 41 || s[j] == 38 || s[j] == 36) //no % ( ) &
  29. s[j] = 35;
  30. }
  31. s[len] = '\0';
  32. return s;
  33. }
  34. int main(void)
  35. {
  36. FILE *saltfd;
  37. int saltlen1;
  38. int saltlen2;
  39. time_t now = time(NULL);
  40. srandom(now % (getpid() + getppid()));
  41. saltlen1 = 32;
  42. saltlen2 = 32;
  43. if ((saltfd = fopen("pack/salt.h", "r"))!= NULL) {
  44. fclose(saltfd);
  45. printf("Using existent Salt-File\n");
  46. exit(0);
  47. }
  48. printf("Creating Salt File\n");
  49. if ((saltfd = fopen("pack/salt.h", "w")) == NULL) {
  50. printf("Cannot created Salt-File.. aborting\n");
  51. exit(1);
  52. }
  53. fprintf(saltfd,"/* SALT1 is for local files */\n",saltlen1);
  54. fprintf(saltfd,"#define SALT1 %c%s%c\n",34,randstring(saltlen1),34);
  55. fprintf(saltfd,"\n");
  56. fprintf(saltfd,"/* SALT2 is for botlink */\n",saltlen2);
  57. fprintf(saltfd,"#define SALT2 %c%s%c\n",34,randstring(saltlen2),34);
  58. fprintf(saltfd,"\n");
  59. fclose(saltfd);
  60. printf("Salt File created.\n");
  61. exit (0);
  62. }