MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / ACLHashPassword

Function ACLHashPassword

src/acl.cpp:163–178  ·  view source on GitHub ↗

Given an SDS string, returns the SHA256 hex representation as a * new SDS string. */

Source from the content-addressed store, hash-verified

161/* Given an SDS string, returns the SHA256 hex representation as a
162 * new SDS string. */
163sds ACLHashPassword(unsigned char *cleartext, size_t len) {
164 SHA256_CTX ctx;
165 unsigned char hash[SHA256_BLOCK_SIZE];
166 char hex[HASH_PASSWORD_LEN];
167 const char *cset = "0123456789abcdef";
168
169 sha256_init(&ctx);
170 sha256_update(&ctx,(unsigned char*)cleartext,len);
171 sha256_final(&ctx,hash);
172
173 for (int j = 0; j < SHA256_BLOCK_SIZE; j++) {
174 hex[j*2] = cset[((hash[j]&0xF0)>>4)];
175 hex[j*2+1] = cset[(hash[j]&0xF)];
176 }
177 return sdsnewlen(hex,HASH_PASSWORD_LEN);
178}
179
180/* Given a hash and the hash length, returns C_OK if it is a valid password
181 * hash, or C_ERR otherwise. */

Callers 2

ACLSetUserFunction · 0.85
ACLCheckUserCredentialsFunction · 0.85

Calls 4

sha256_initFunction · 0.85
sha256_updateFunction · 0.85
sha256_finalFunction · 0.85
sdsnewlenFunction · 0.85

Tested by

no test coverage detected