~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to libdrizzle/password.c

  • Committer: Monty Taylor
  • Date: 2009-01-09 07:02:24 UTC
  • mto: (779.1.2 devel)
  • mto: This revision was merged to the branch mainline in revision 784.
  • Revision ID: mordred@inaugust.com-20090109070224-prwl5p52mfql3zfw
Split out readline.

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