Last active
August 29, 2015 14:01
Symphony Message SHA512 Hash Digest in Objective C
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSString* createSymphonySHA512MessageDigest(const char* s, const char* salt) { | |
uint8_t digest[CC_SHA512_DIGEST_LENGTH]; | |
char salted[strlen(s) + strlen(salt) + 3]; | |
snprintf(salted, sizeof salted, "%s{%s}", s, salt); | |
CC_SHA512(salted, (CC_LONG) strlen(salted), digest); | |
for (int i = 0; i < 4999; i++) { | |
CC_SHA512_CTX context; | |
CC_SHA512_Init(&context); | |
CC_SHA512_Update(&context, digest, (CC_LONG) CC_SHA512_DIGEST_LENGTH); | |
CC_SHA512_Update(&context, salted, (CC_LONG)strlen(salted)); | |
CC_SHA512_Final(digest, &context); | |
} | |
return [[NSData dataWithBytes:digest length:CC_SHA512_DIGEST_LENGTH] base64EncodedStringWithOptions:0]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Got stuck on the iteration hashing at first.