mirror of
https://github.com/3proxy/3proxy.git
synced 2026-05-13 13:30:12 +08:00
Use blake2 hashsize
This commit is contained in:
parent
6286bfcd6e
commit
95029e9e41
@ -231,14 +231,12 @@ int strongauth(struct clientparam * param){
|
||||
if(!strncmp(pass + 1, (char *)param->password, pwl_table.recsize - 1)) return 0;
|
||||
} else {
|
||||
blake2b_state S;
|
||||
unsigned char _b2tmp[64];
|
||||
unsigned hashsz;
|
||||
hashsz = pwl_table.recsize - 1 < 64 ? pwl_table.recsize - 1 : 64;
|
||||
memset(buf, 0, pwl_table.recsize - 1);
|
||||
blake2b_init(&S, 64);
|
||||
blake2b_init(&S, hashsz);
|
||||
blake2b_update(&S, param->password, pwlen + 1);
|
||||
blake2b_final(&S, _b2tmp, 64);
|
||||
memcpy(buf, _b2tmp, hashsz);
|
||||
blake2b_final(&S, buf, hashsz);
|
||||
if(!memcmp(pass + 1, buf, pwl_table.recsize - 1)) return 0;
|
||||
}
|
||||
return 6;
|
||||
|
||||
@ -10,11 +10,9 @@ static void char_index2hash(const struct hashtable *ht, void *index, uint8_t *ha
|
||||
memset(hash, 0, ht->hash_size);
|
||||
if(len <= ht->hash_size) memcpy(hash, index, len);
|
||||
else {
|
||||
unsigned char _b2tmp[64];
|
||||
blake2b_init(&S, 64);
|
||||
blake2b_init(&S, ht->hash_size);
|
||||
blake2b_update(&S, index, strlen((const char*)index) + 1);
|
||||
blake2b_final(&S, _b2tmp, 64);
|
||||
memcpy(hash, _b2tmp, ht->hash_size);
|
||||
blake2b_final(&S, hash, ht->hash_size);
|
||||
}
|
||||
}
|
||||
|
||||
@ -51,8 +49,7 @@ static void param2hash_add(const struct hashtable *ht, void *index, uint8_t *has
|
||||
if((type & 2048)){ memcpy(hash + offset, SAPORT(¶m->srv->intsa), p2len); offset += 2; }
|
||||
}
|
||||
else {
|
||||
unsigned char _b2tmp[64];
|
||||
blake2b_init(&S, 64);
|
||||
blake2b_init(&S, ht->hash_size);
|
||||
if((type & 2) && param->username)blake2b_update(&S, param->username, ulen);
|
||||
if((type & 4) && param->password)blake2b_update(&S, param->password, plen);
|
||||
if((type & 1) && !(type & 8))blake2b_update(&S, SAADDR(¶m->sincr), a1len);
|
||||
@ -63,10 +60,8 @@ static void param2hash_add(const struct hashtable *ht, void *index, uint8_t *has
|
||||
if((type & 512))blake2b_update(&S, ¶m->operation, sizeof(param->operation));
|
||||
if((type & 1024))blake2b_update(&S, SAADDR(¶m->srv->intsa), a3len);
|
||||
if((type & 2048))blake2b_update(&S, SAPORT(¶m->srv->intsa), 2);
|
||||
blake2b_final(&S, _b2tmp, 64);
|
||||
memcpy(hash, _b2tmp, ht->hash_size);
|
||||
blake2b_final(&S, hash, ht->hash_size);
|
||||
}
|
||||
memcpy(param->hash, hash, ht->hash_size);
|
||||
}
|
||||
|
||||
void param2hash_search(const struct hashtable *ht, void *index, uint8_t *hash){
|
||||
@ -78,14 +73,12 @@ void param2hash_search(const struct hashtable *ht, void *index, uint8_t *hash){
|
||||
static void udpparam2hash(const struct hashtable *ht, void *index, uint8_t *hash){
|
||||
struct clientparam *param = (struct clientparam *)index;
|
||||
blake2b_state S;
|
||||
unsigned char _b2tmp[64];
|
||||
blake2b_init(&S, 64);
|
||||
blake2b_init(&S, ht->hash_size);
|
||||
blake2b_update(&S, SAADDR(¶m->srv->intsa), SAADDRLEN(¶m->srv->intsa));
|
||||
blake2b_update(&S, SAPORT(¶m->srv->intsa), 2);
|
||||
blake2b_update(&S, SAADDR(¶m->sincr), SAADDRLEN(¶m->sincr));
|
||||
blake2b_update(&S, SAPORT(¶m->sincr), 2);
|
||||
blake2b_final(&S, _b2tmp, 64);
|
||||
memcpy(hash, _b2tmp, ht->hash_size);
|
||||
blake2b_final(&S, hash, ht->hash_size);
|
||||
}
|
||||
|
||||
struct hashtable dns_table = {char_index2hash, char_index2hash, 4, 32};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user