5 #define SCRAMBLE_LENGTH_323 8
7 typedef unsigned long ulong;
8 typedef unsigned int uint;
9 typedef unsigned char uchar;
12 unsigned long seed1,seed2,max_value;
16 void hash_password(ulong *result, const char *password, uint password_len)
18 register ulong nr=1345345333L, add=7, nr2=0x12345671L;
20 const char *password_end= password + password_len;
21 for (; password < password_end; password++)
23 if (*password == ' ' || *password == '\t')
24 continue; /* skip space in password */
25 tmp= (ulong) (uchar) *password;
26 nr^= (((nr & 63)+add)*tmp)+ (nr << 8);
30 result[0]=nr & (((ulong) 1L << 31) -1L); /* Don't use sign bit (str2int) */;
31 result[1]=nr2 & (((ulong) 1L << 31) -1L);
34 void randominit(struct rand_struct *rand_st, ulong seed1, ulong seed2)
35 { /* For mysql 3.21.# */
37 bzero((char*) rand_st,sizeof(*rand_st)); /* Avoid UMC varnings */
39 rand_st->max_value= 0x3FFFFFFFL;
40 rand_st->max_value_dbl=(double) rand_st->max_value;
41 rand_st->seed1=seed1%rand_st->max_value ;
42 rand_st->seed2=seed2%rand_st->max_value;
45 double my_rnd(struct rand_struct *rand_st)
47 rand_st->seed1=(rand_st->seed1*3+rand_st->seed2) % rand_st->max_value;
48 rand_st->seed2=(rand_st->seed1+rand_st->seed2+33) % rand_st->max_value;
49 return (((double) rand_st->seed1)/rand_st->max_value_dbl);
52 void scramble_323(char *to, const char *message, const char *password)
54 struct rand_struct rand_st;
55 ulong hash_pass[2], hash_message[2];
57 if (password && password[0])
59 char extra, *to_start=to;
60 const char *message_end= message + SCRAMBLE_LENGTH_323;
61 hash_password(hash_pass,password, (uint) strlen(password));
62 hash_password(hash_message, message, SCRAMBLE_LENGTH_323);
63 randominit(&rand_st,hash_pass[0] ^ hash_message[0],
64 hash_pass[1] ^ hash_message[1]);
65 for (; message < message_end; message++)
66 *to++= (char) (floor(my_rnd(&rand_st)*31)+64);
67 extra=(char) (floor(my_rnd(&rand_st)*31));
68 while (to_start != to)
75 const char password1[] = "root";
76 const char password2[] = "long password test";
77 const char password3[] = "saf789yasfbsd89f";
79 char scrm[9]; // SCRAMBLE_LENGTH_323+1
80 struct rand_struct rand_st;
84 hash_password((ulong*)result, password1, strlen(password1));
85 printf("hash_password(\"%s\") = %08x%08x\n", password1, result[0], result[1]);
87 hash_password((ulong*)result, password2, strlen(password2));
88 printf("hash_password(\"%s\") = %08x%08x\n", password2, result[0], result[1]);
90 hash_password((ulong*)result, password3, strlen(password3));
91 printf("hash_password(\"%s\") = %08x%08x\n", password3, result[0], result[1]);
95 randominit(&rand_st, 0, 0);
96 printf("randominit(0x00000000,0x00000000) = %08x, %08x\n", rand_st.seed1, rand_st.seed2);
98 randominit(&rand_st, 0xFFFF, 0xFFFF);
99 printf("randominit(0x0000FFFF,0x0000FFFF) = %08x, %08x\n", rand_st.seed1, rand_st.seed2);
101 randominit(&rand_st, 0x50000000, 0x50000000);
102 printf("randominit(0x50000000,0x50000000) = %08x, %08x\n", rand_st.seed1, rand_st.seed2);
104 randominit(&rand_st, 0xFFFFFFFF, 0xFFFFFFFF);
105 printf("randominit(0xFFFFFFFF,0xFFFFFFFF) = %08x, %08x\n", rand_st.seed1, rand_st.seed2);
109 randominit(&rand_st, 3252345, 7149734);
110 printf("randominit(3252345, 7149734) = %08x, %08x\n", rand_st.seed1, rand_st.seed2);
111 for (i=0; i<10; i++){
112 printf("my_rnd() : %.16f\n", my_rnd(&rand_st));
117 scramble_323(scrm, "8bytesofstuff", "root");
118 printf("scramble323(8bytesofstuff, root): %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
119 scrm[0], scrm[1], scrm[2], scrm[3], scrm[4], scrm[5], scrm[6], scrm[7], scrm[8]);
121 scramble_323(scrm, "e8cf00cec9ec825af22", "saf789yasfbsd");
122 printf("scramble323(e8cf00cec9ec825af22, saf789yasfbsd): %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
123 scrm[0], scrm[1], scrm[2], scrm[3], scrm[4], scrm[5], scrm[6], scrm[7], scrm[8]);