Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
ae5054b4
Commit
ae5054b4
authored
Sep 12, 2019
by
antirez
Browse files
ACL: SHA256 based password hashing function implemented.
parent
9d2ecf6b
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/acl.c
View file @
ae5054b4
...
...
@@ -28,6 +28,7 @@
*/
#include "server.h"
#include "sha256.h"
#include <fcntl.h>
/* =============================================================================
...
...
@@ -139,6 +140,25 @@ int time_independent_strcmp(char *a, char *b) {
return
diff
;
/* If zero strings are the same. */
}
/* Given an SDS string, returns the SHA256 hex representation as a
* new SDS string. */
sds
ACLHashPassword
(
sds
cleartext
)
{
SHA256_CTX
ctx
;
unsigned
char
hash
[
SHA256_BLOCK_SIZE
];
char
hex
[
SHA256_BLOCK_SIZE
*
2
];
char
*
cset
=
"0123456789abcdef"
;
sha256_init
(
&
ctx
);
sha256_update
(
&
ctx
,(
unsigned
char
*
)
cleartext
,
sdslen
(
cleartext
));
sha256_final
(
&
ctx
,
hash
);
for
(
int
j
=
0
;
j
<
SHA256_BLOCK_SIZE
;
j
++
)
{
hex
[
j
*
2
]
=
cset
[((
hash
[
j
]
&
0xF0
)
>>
4
)];
hex
[
j
*
2
+
1
]
=
cset
[(
hash
[
j
]
&
0xF
)];
}
return
sdsnewlen
(
hex
,
SHA256_BLOCK_SIZE
*
2
);
}
/* =============================================================================
* Low level ACL API
* ==========================================================================*/
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment