59 #ifndef OPENSSL_NO_SRP
68 #define SRP_RANDOM_SALT_LEN 20
71 static char b64table[] =
72 "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz./";
79 static int t_fromb64(
unsigned char *
a,
const char *src)
85 while(*src && (*src ==
' ' || *src ==
'\t' || *src ==
'\n'))
91 loc = strchr(b64table, src[i]);
92 if(loc == (
char *) 0)
break;
93 else a[i] = loc - b64table;
103 a[j] |= (a[i] & 3) << 6;
105 a[j] = (
unsigned char) ((a[i] & 0x3c) >> 2);
107 a[j] |= (a[i] & 0xf) << 4;
109 a[j] = (
unsigned char) ((a[i] & 0x30) >> 4);
116 while(a[j] == 0 && j <= size) ++j;
118 while (j <= size) a[i++] = a[j++];
126 static char *t_tob64(
char *dst,
const unsigned char *src,
int size)
128 int c, pos = size % 3;
129 unsigned char b0 = 0, b1 = 0, b2 = 0, notleading = 0;
145 c = (b0 & 0xfc) >> 2;
146 if(notleading || c != 0)
148 *dst++ = b64table[c];
151 c = ((b0 & 3) << 4) | ((b1 & 0xf0) >> 4);
152 if(notleading || c != 0)
154 *dst++ = b64table[c];
157 c = ((b1 & 0xf) << 2) | ((b2 & 0xc0) >> 6);
158 if(notleading || c != 0)
160 *dst++ = b64table[c];
164 if(notleading || c != 0)
166 *dst++ = b64table[c];
169 if(pos >= size)
break;
184 if (user_pwd == NULL)
214 static int SRP_user_pwd_set_ids(
SRP_user_pwd *vinfo,
const char *
id,
219 return (info == NULL || NULL != (vinfo->
info =
BUF_strdup(info))) ;
222 static int SRP_user_pwd_set_sv(
SRP_user_pwd *vinfo,
const char *s,
230 len = t_fromb64(tmp, v);
231 if (NULL == (vinfo->
v =
BN_bin2bn(tmp, len, NULL)) )
233 len = t_fromb64(tmp, s);
234 return ((vinfo->
s =
BN_bin2bn(tmp, len, NULL)) != NULL) ;
241 return (vinfo->
s != NULL && vinfo->
v != NULL) ;
259 if ((seed_key != NULL) &&
293 len = t_fromb64(tmp, ch);
306 if (gN_cache == NULL)
322 if (gN && (
id == NULL || strcmp(gN->
id,
id)==0))
332 if (gN_cache == NULL)
339 if (strcmp(cache->
b64_bn,ch)==0)
364 char *last_index = NULL;
403 || !(gN->
g = SRP_gN_place_bn(vb->gN_cache,pp[
DB_srpsalt]))
418 if ((lgN = SRP_get_gN_by_id(pp[
DB_srpgN],SRP_gN_tab))!=NULL)
421 if ((user_pwd = SRP_user_pwd_new()) == NULL)
424 SRP_user_pwd_set_gN(user_pwd,lgN->
g,lgN->
N);
439 if (last_index != NULL)
443 if (((gN = SRP_get_gN_by_id(last_index,SRP_gN_tab))==NULL))
463 SRP_user_pwd_free(user_pwd);
488 if (strcmp(user->
id,username)==0)
498 if ((user = SRP_user_pwd_new()) == NULL)
503 if (!SRP_user_pwd_set_ids(user,username,NULL))
516 err: SRP_user_pwd_free(user);
525 char **verifier,
const char *
N,
const char *g)
530 BIGNUM *N_bn = NULL, *g_bn = NULL, *s = NULL, *v = NULL;
533 char * defgNid = NULL;
543 if (!(len = t_fromb64(tmp, N)))
goto err;
545 if (!(len = t_fromb64(tmp, g)))
goto err;
551 SRP_gN * gN = SRP_get_gN_by_id(g, NULL) ;
567 if (!(len = t_fromb64(tmp2, *salt)))
636 if(*verifier == NULL)
goto err;