Skip to content

Instantly share code, notes, and snippets.

@austindavidbrown
Last active August 29, 2015 14:01
Symphony Message SHA512 Hash Digest in Objective C
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];
}
@austindavidbrown
Copy link
Author

Got stuck on the iteration hashing at first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment