~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to libdrizzleclient/password.c

  • Committer: Monty Taylor
  • Date: 2009-02-08 11:11:30 UTC
  • mto: This revision was merged to the branch mainline in revision 852.
  • Revision ID: mordred@inaugust.com-20090208111130-futpwptxv5he3boe
Renamed non-prefixed things from libdrizzleclient to drizzleclient.

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
 
41
41
  The new authentication is performed in following manner:
42
42
 
43
 
  SERVER:  public_seed=create_random_string()
 
43
  SERVER:  public_seed=drizzleclient_create_random_string()
44
44
           send(public_seed)
45
45
 
46
46
  CLIENT:  recv(public_seed)
73
73
/*
74
74
  New (MySQL 3.21+) random generation structure initialization
75
75
  SYNOPSIS
76
 
    randominit()
 
76
    drizzleclient_drizzleclient_randominit()
77
77
    rand_st    OUT  Structure to initialize
78
78
    seed1      IN   First initialization parameter
79
79
    seed2      IN   Second initialization parameter
80
80
*/
81
81
 
82
 
void randominit(struct rand_struct *rand_st, uint32_t seed1, uint32_t seed2)
 
82
void drizzleclient_drizzleclient_randominit(struct rand_struct *rand_st, uint32_t seed1, uint32_t seed2)
83
83
{                                               /* For mysql 3.21.# */
84
84
  memset(rand_st, 0, sizeof(*rand_st));      /* Avoid UMC varnings */
85
85
  rand_st->max_value= 0x3FFFFFFFL;
92
92
/*
93
93
    Generate random number.
94
94
  SYNOPSIS
95
 
    my_rnd()
 
95
    drizzleclient_my_rnd()
96
96
    rand_st    INOUT  Structure used for number generation
97
97
  RETURN VALUE
98
98
    generated pseudo random number
99
99
*/
100
100
 
101
 
double my_rnd(struct rand_struct *rand_st)
 
101
double drizzleclient_my_rnd(struct rand_struct *rand_st)
102
102
{
103
103
  rand_st->seed1=(rand_st->seed1*3+rand_st->seed2) % rand_st->max_value;
104
104
  rand_st->seed2=(rand_st->seed1+rand_st->seed2+33) % rand_st->max_value;
110
110
    Generate binary hash from raw text string
111
111
    Used for Pre-4.1 password handling
112
112
  SYNOPSIS
113
 
    hash_password()
 
113
    drizzleclient_hash_password()
114
114
    result       OUT store hash in this location
115
115
    password     IN  plain text password to build hash
116
116
    password_len IN  password length (password may be not null-terminated)
117
117
*/
118
118
 
119
 
void hash_password(uint32_t *result, const char *password, uint32_t password_len)
 
119
void drizzleclient_hash_password(uint32_t *result, const char *password, uint32_t password_len)
120
120
{
121
121
  register uint32_t nr=1345345333L, add=7, nr2=0x12345671L;
122
122
  uint32_t tmp;
148
148
/*
149
149
    Generate string of printable random characters of requested length
150
150
  SYNOPSIS
151
 
    create_random_string()
 
151
    drizzleclient_create_random_string()
152
152
    to       OUT   buffer for generation; must be at least length+1 bytes
153
153
                   long; result string is always null-terminated
154
154
    length   IN    how many random characters to put in buffer
155
155
    rand_st  INOUT structure used for number generation
156
156
*/
157
157
 
158
 
void create_random_string(char *to, uint32_t length, struct rand_struct *rand_st)
 
158
void drizzleclient_create_random_string(char *to, uint32_t length, struct rand_struct *rand_st)
159
159
{
160
160
  char *end= to + length;
161
161
  /* Use pointer arithmetics as it is faster way to do so. */
162
162
  for (; to < end; to++)
163
 
    *to= (char) (my_rnd(rand_st)*94+33);
 
163
    *to= (char) (drizzleclient_my_rnd(rand_st)*94+33);
164
164
  *to= '\0';
165
165
}
166
166
 
170
170
    Convert given octet sequence to asciiz string of hex characters;
171
171
    str..str+len and 'to' may not overlap.
172
172
  SYNOPSIS
173
 
    octet2hex()
 
173
    drizzleclient_drizzleclient_octet2hex()
174
174
    buf       OUT output buffer. Must be at least 2*len+1 bytes
175
175
    str, len  IN  the beginning and the length of the input string
176
176
 
178
178
    buf+len*2
179
179
*/
180
180
 
181
 
char *octet2hex(char *to, const char *str, uint32_t len)
 
181
char *drizzleclient_drizzleclient_octet2hex(char *to, const char *str, uint32_t len)
182
182
{
183
183
  static const char _dig_vec_upper[]= "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
184
184