Given an SDS string, returns the SHA256 hex representation as a * new SDS string. */
| 161 | /* Given an SDS string, returns the SHA256 hex representation as a |
| 162 | * new SDS string. */ |
| 163 | sds 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. */ |
no test coverage detected