fileChecksum in "Photo Details.csv" from iCloud Photos
If you requested a copy of your data from privacy.apple.com, and like me, you did it to download your photos from iCloud you may have wondered what is the field fileChecksum contained along other metadata of your media in the files "Photo Details.csv".
It took a bit, but this is what I found out.
Please, note that some of the details below are based on assumptions.
The fileChecksum is actually called MMCS Hash, most likely from MobileMe Cloud Storage / MobileMe Chunk Storage / MobileMe Chunking Service, the backend that Apple introduced back in 2008, the predecessor of iCloud.
It is a content-addressable algorithm (it depends only on the file’s raw bytes, not on metadata) based on chunking (the file is split into chunks, each chunk is hashed) and aggregation (these hashes are aggregated to form a digest) that produces a stable hash used for deduplication and integrity verification during cloud synchronization.
To conclude, this algorithm is implemented inside the Private Framework CoreMediaStream (MS).
Here is a snippet I wrote to compute the hash of any file:
// MSMMCSHashForFileAtPath.m
#import <Foundation/Foundation.h>
extern NSData *MSMMCSHashForFileAtPath(NSString *path, CFErrorRef *errorOut);
int main(int argc, const char * argv[]) {
@autoreleasepool {
if (argc != 2) {
fprintf(stderr, "usage: %s /path/to/file\n", argv[0]);
return 2;
}
NSString *path = [NSString stringWithUTF8String:argv[1]];
NSData *digest = MSMMCSHashForFileAtPath(path, NULL);
if (!digest) {
fprintf(stderr, "MSMMCSHashForFileAtPath returned NULL\n");
return 1;
}
const unsigned char *bytes = digest.bytes;
NSUInteger len = digest.length;
printf("Hex:\t");
for (NSUInteger i = 0; i < len; i++) printf("%02x", bytes[i]);
printf("\n");
NSString *b64 = [digest base64EncodedStringWithOptions:0];
printf("Base64:\t%s\n", [b64 UTF8String]);
}
return 0;
}
/*
clang -o MSMMCSHashForFileAtPath \
MSMMCSHashForFileAtPath.m \
-F /System/Library/PrivateFrameworks \
-framework CoreMediaStream \
-framework Foundation
./MSMMCSHashForFileAtPath "path/to/file"
*/