Skynet Labs
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Help
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Encrypted Files on MySky ###### tags: `Specifications` This document is intended to describe the protocol for storing encrypted data on MySky. Users will be able to encrypt data and store it in files and folders, such that they can share the encryption key to just a single file, or to an entire nested folder. Note that this is a separate specification from the hidden files specification. Encrypted files can still be associated with the user after being stored on Skynet. Hidden files provide better protection, preventing outside observers from knowing that a file is owned by the user. Encrypted files have been created as an interim step, as the advanced cryptography required to make hidden files work will take longer to implement. ## Pubkey and Tweak Derivation The pubkey is the same is the user's discoverable pubkey, but the tweak is derived using a private "path seed" to ensure that encrypted files are in a different namespace than discoverable files. The root path seed is defined by: ```go rootPathSeed := sha512(append(sha512("encrypted filesystem path seed"), sha512(mySkySeed)...)) ``` The path seed and file tweak for a child file or folder is derived using the following methodology: ```go type DerivationPathObj stuct { pathSeed hash directory bool name string } derivationPath := sha512(derivationPathObj) childPathSeed := sha512(append(sha512("encrypted filesystem child"), sha512(derivationPath)...)) childTweak := sha512(append(sha512("encrypted filesystem tweak"), sha512(childPathSeed)...)) ``` ## Encryption MySky will be supporting multiple types of files, each of which has their own encryption scheme. It should be noted that Skynet data is already authenticated, encryption schemes for encrypted files do not need authentication to be secure. One weakness of supporting multiple filetypes is that different types of files are distinct in how they are accessed and updated. Encrypted files of different types may be distinguishable to a network adversary, but this may be acceptable as long as all formats are commonly used and files are sufficiently unlinked from their users and from each other. Regardess of file type, the entropy for the encryption key of a file is generated with the following method: ```go encryptionKeyEntropy := Hash("encryption" || pathSeed) ``` ### Json Files v1 A json file is a file that is storing a single json object. The file is always uploaded and downloaded in its entirety, and always decrypts to a single json object. The file is encrypted using `xsalsa20-poly1305`. The main reason for choosing this algorithm is that our SDK already supports this algorithm thanks to other cryptography we do elsewhere. `xsalsa20-poly1305` is unnecessarily authenticated, but in this case we view the savings in SDK size and complexity as being more important than the computational savings and filesize savings of using unauthenticated encryption. One notable weakness of `xsalsa20-poly1305` is that data cannot be safely modified. This is acceptable for the json files because updates to the file always re-write the entire file using new IVs. ### Raw Files v1 A raw file is an interface provided to developers that mimics the traditional file format. Developers can do partial reads and partial writes to the file, and are not limited in the type of data that can be stored. The file is broken up into sectors of 4096 bytes, each sector containing 4056 data bytes from the file and 40 bytes of overhead. The overhead appears at the front of the sector. The first 24 bytes of the overhead are a nonce, and the next 16 bytes of overhead are an authentication tag. The nonce and authentication tag are part of the `xsalsa20-poly1305` encryption algorithm. Each sector of the file is encrypted separately using `xsalsa20-poly1305` with a randomly generated nonce. When the file is modified, entire sectors must be modified together. The nonce must be re-randomized, which means the entire sector will need to be re-encrypted and re-uploaded. We have chosen `xsalsa20-poly1305` as our cipher because there is good support for this cipher in javascript and other languages, and because the cipher is already imported by other dependencies of our SDK. We could save ourselves the 40 bytes of overhead in each sector by using a tweakable cipher such as AES-XTS or Threefish, however there is not good support for either in javascript at this time. ## Padding To prevent analysis that can occur by looking at the sizes of files, all encrypted files will be padded to the nearest "pad block", after encryption. A pad block is minimally 4 kib in size, is always a power of 2, and is always at least 5% of the size of the file. For example, a 1 kib encrypted file would be padded to 4 kib, a 5 kib file would be padded to 8 kib, and a 105 kib file would be padded to 112 kib. Below is a short table of valid file sizes: ``` 4 KiB 8 KiB 12 KiB 16 KiB 20 KiB 24 KiB 28 KiB 32 KiB 36 KiB 40 KiB 44 KiB 48 KiB 52 KiB 56 KiB 60 KiB 64 KiB 68 KiB 72 KiB 76 KiB 80 KiB 88 KiB 96 KiB 104 KiB 112 KiB 120 KiB 128 KiB 136 KiB 144 KiB 152 KiB 160 KiB 176 KiB 192 Kib 208 KiB 224 KiB 240 KiB 256 KiB 272 KiB 288 KiB 304 KiB 320 KiB 352 KiB ... etc ``` Note that the first 20 valid sizes are all a multiple of 4 KiB, the next 10 are a multiple of 8 KiB, and each 10 after that the multiple doubles. We use this method of padding files to prevent an adversary from guessing the contents or structure of the file based on its size.

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully