ZDCCloudFileHeader

struct ZDCCloudFileHeader {}

ZeroDark.cloud uses 2 different types of encrypted files:

  • cache files
  • cloud files

A cloud file is what we store in the cloud, and it contains 4 separate sections:

  • header prefix
  • metadata (optional)
  • thumbnail (optional)
  • data

By storing the metadata & thumbnail sections separately, we make it possible for client devices to download only what they need. For example, a mobile device might just download the thumbnails for a picture or video. This significantly decreases bandwidth demand, while maintaining a proper user experience.

A cloud file is created like so:

  1. append this header to the beginning of the plaintext (non-encrypted) file
  2. append a metadata section (JSON) (optional)
  3. append a thumbnail (such as small jpg/png) (optional)
  4. append the raw file data
  5. encrypt the data (header + metadata + thumbnail + data) using the encryption key

The output will be an encrypted file whose size is rounded up to the nearest kZDCNode_TweakBlockSizeInBytes. When attempting decryption, we can verify the decryption key is correct by inspecting the decrypted header.

  • This value should be kZDCCloudFileContextMagic, otherwise it’s not a valid cloud file.

    Declaration

    Objective-C

    uint64_t magic

    Swift

    var magic: Int32
  • Indicates the size of the (optional) metadata.

    Declaration

    Objective-C

    uint64_t metadataSize

    Swift

    var metadataSize: Int32
  • Indicates the size of the (optional) thumbnail.

    Declaration

    Objective-C

    uint64_t thumbnailSize

    Swift

    var thumbnailSize: Int32
  • Indicates the size of the data (in cleartext). This value excludes the padding that may have been applied.

    Declaration

    Objective-C

    uint64_t dataSize

    Swift

    var dataSize: Int32
  • A hash of the thumbnail bytes. Can be used to detect if the thumbnail was changed since last downloaded.

    Note

    It’s often the case the data is changed, but the thumbnail remains the same. For example, if a multi-page document is modified, the thumbnail (of the cover page) may not change.

    Declaration

    Objective-C

    uint64_t thumbnailxxHash64

    Swift

    var thumbnailxxHash64: Int32
  • Refers to the version of this header.

    Declaration

    Objective-C

    uint8_t version

    Swift

    var version: Int32
  • Reserved for future extensibility.

    Declaration

    Objective-C

    uint8_t reserved[23]

    Swift

    var reserved: (Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32)