Turnstile encrypts data so that it can only be decrypted on another computer

Overview

Turnstile - One Way Encryption

Turnstile encrypts data so that it can only be decrypted on another computer (and can't be decrypted on the encrypting computer).

Cryptographically, Turnstile is just a wrapper around libsodium's box. Similar functionality could be acheived with an ECIES variant.

Encrypting

  • The source computer makes an ephemeral keypair.
  • The source's private key is used with the target's public key to make the precomputed key.
  • The precomputed key is used to encrypt the message.
  • The source's public key is part of the encrypted message, but otherwise not kept.
  • The source's private key is discarded.

Decrypting

  • The target computer has a long-lived keypair.
  • The target's private key is used with the source's public key (contained in the encrypted message) to make the precomputed key.
  • The precomputed key is used to decrypt the message.

Uses Cases

Logging

Piping logs through Turnstile causes logs to be readable only after moving them off-box, to the computer with the target private key. This means that historical logs are protected if a webserver, for example, is compromised.

Encrypting Files

If you are given a recipient's public key, you can encrypt data and put it in a public place, knowing that only they can decrypt it. (You can't even decrypt it yourself, so you'd better keep the original, if it's needed.)

Usage

Creating a base62 ed25519 key on the target machine:

target:/some/dir $ turnstile keygen
new secret key written into /home/fadedbee/.turnstile/i8q8p2L8gZpZsPD8NRcTiFfQHLfrhoq3IvsaEwWzPJH.secret

Encrypt a stream on the source machine:

filename.txt.t7e">
source:/other/dir $ echo "hello world" | turnstile encrypt i8q8p2L8gZpZsPD8NRcTiFfQHLfrhoq3IvsaEwWzPJH > filename.txt.t7e

Encrypt a file on the source machine:

source:/other/dir $ turnstile -i filename.txt -o filename.txt.t7e encrypt i8q8p2L8gZpZsPD8NRcTiFfQHLfrhoq3IvsaEwWzPJH

Decrypt a stream on the target machine:

target:/some/dir $ cat filename.txt.t7e | turnstile decrypt
hello world

(filename.txt.t7e contains the target's public key. Decryption reads the associated secret key from /home/fadedbee/.turnstile/i8q8p2L8gZpZsPD8NRcTiFfQHLfrhoq3IvsaEwWzPJH.secret.)

Decrypt a file on the target machine:

target:/some/dir $ turnstile -i filename.txt -o filename.txt.t7e -o decrypted.txt decrypt
target:/some/dir $ cat decrypted.txt
hello world

Stream/File Format for Version 1.0.X.##

Header:

+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|FA|DE|DB|EE|t |u |r |n |s |t |i |l |e |Version |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|                                               |
+            Encryptor's Public Key             +
|                                               |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|                                               |
+        Intended Decryptor's Public Key        |
|             (informational only)              |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|                 Initial Nonce                 |
+                       +--+--+--+--+--+--+--+--+
|                       |
+--+--+--+--+--+--+--+--+

Chunks:

+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| Len |                                         |
+--+--+                                         +
|                                               |
+                  Ciphertext                   +
|                                               |
v                                               v

Final Chunk:

+--+--+
|00 00|
+--+--+

Design Choices

Documentation of trade-offs anmd compromises.

Requiring private keys to be contained in files (in ~/.turnstile)

It would have been possible to specify target secret keys on the command line, rather than using ~/.turnstile.

This would be insecure for multi-user machines, as ps and top show the command line arguments of other users.

Using Base62

  • Base64 is more common, but needs to be quoted in shell commands and does not cut and paste easily.
  • Base58 has guards which might be useful for hand-typing keys, but is longer and variably sized.
  • In a nice coincidence, 43 base 62 digits provide 256.03 bits. log2(62)*43 == 256.03

Including the Target Public Key in the Encryption Output

There is no need for the target public key to exist in the encryption output.

Pros:

  • Allows decryption to only try one secret key, rather than all that it knows.
  • Users can inspect a .t7e file to find which public key they need to use to decrypt it.

Cons:

  • Adds identifiable information to the encryption output.

Using ~/.turnstile rather than Ed25519 SSH keys from ~/.ssh

The encryption used by turnstile is compatible with SSH's .ssh/id_ed25519.pub files.

It would have been nice to use pre-existing keys, but:

  • We'd need to explain the differences between SSH key types to users.
  • Base64 and quoting would have to be used.

Using a 16-bit Ciphertext Length in Chunks

In order to deal with streaming, we must break the input up into chunks, each of which can be decrypted in turn. (Decryption includes an integrity check.)

Smaller chunks have more overhead. but allowing larger chunks means more length overhead for each small chunk.

We could have used a variably-sized integer for the length, which would have saved some space, at the expense of some CPU cycles and complexity.

For the time-being, we've settled on a maximum chunk size of 65,535 bytes.

For large files, every 65,519 bytes of plaintext results in a chunk containing 2 bytes of length and 65,535 bytes of cipher text.

This is less than a 0.03% overhead. This is acceptable, for v1.0.0, given the simplicity of using a u16 for the chunk length.

Nonce generation

Nonces must not be reused for any given pair of public and secret keys.

Every chunk is encrypted with a different nonce, which is simple an XOR of the initial nonce and the chunk number.

As each message is encrypted using a different secret key, there is no need for initial nonces to differ. But we randomly generate initial nonces and write them into the header, just in case...

You might also like...
A demo of the Internet Computer's Bitcoin API

Bitcoin Integration Demo A demo of the bitcoin endpoints on the Internet Computer. This demo is already deployed to the IC, so you can already try it

Simple PoC to issue JSON Web Tokens (JWTs) with a canister on the Internet Computer.

JWT Issuer Proof of Concept Overview Simple PoC to issue JSON Web Tokens (JWTs) with a canister on the Internet Computer. It allows the issuance of tw

An implementation of the append-only log described in the Certificate Transparency specification (RFC 6962)

CT Merkle This is an implementation of the append-only log described in the Certificate Transparency specification (RFC 6962). The log is a Merkle tre

A black-box raw calldata decoder using only calldata to guess types and parse parameters.
A black-box raw calldata decoder using only calldata to guess types and parse parameters.

Calldata Decoder A black-box raw calldata decoder using only calldata. Based off the topics discussed in DeGatchi's article, Reverse The EVM: Raw Call

Frost in Rust (Study only)

FROST (Study only) This implementation was part of the contribution for the following paper: Chelsea Komlo, Ian Goldberg. "FROST: Flexible Round-Optim

Yet another gem miner

Rusty Pickaxe Multithreaded CPU miner for Provably Rare Gems, written in Rust. There is also closed-source GPU version, waiting to be released. Config

Easy to use cryptographic framework for data protection: secure messaging with forward secrecy and secure data storage. Has unified APIs across 14 platforms.
Easy to use cryptographic framework for data protection: secure messaging with forward secrecy and secure data storage. Has unified APIs across 14 platforms.

Themis provides strong, usable cryptography for busy people General purpose cryptographic library for storage and messaging for iOS (Swift, Obj-C), An

Demonstrates Solana data account versioning used in supporting the Solana Cookbook article: Account Data Versioning
Demonstrates Solana data account versioning used in supporting the Solana Cookbook article: Account Data Versioning

versioning-solana This repo demonstrates ONE rudimentary way to upgrade/migrate account data changes with solana program changes. What is data version

reth-indexer reads directly from the reth db and indexes the data into a postgres database all decoded with a simple config file and no extra setup alongside exposing a API ready to query the data.
reth-indexer reads directly from the reth db and indexes the data into a postgres database all decoded with a simple config file and no extra setup alongside exposing a API ready to query the data.

reth-indexer reth-indexer reads directly from the reth db and indexes the data into a postgres database all decoded with a simple config file and no e

Comments
  • Looking fro Rust dev

    Looking fro Rust dev

    Hi, I'm max and I am looking for a rust dev for an infrastructure project. Would love to discuss if this is of interest. Team is 12 devs, international but located in the UK!

    opened by blutooth 1
  • Errors when using `--output` switch.

    Errors when using `--output` switch.

    $ ls filename.txt.t7e 
    filename.txt.t7e
    
    $ target/release/turnstile -i filename.txt -o filename.txt.t7e encrypt i8q8p2L8gZpZsPD8NRcTiFfQHLfrhoq3IvsaEwWzPJH
    Error: Bad file descriptor (os error 9)
    
    $ rm filename.txt.t7e 
    
    $ target/release/turnstile -i filename.txt -o filename.txt.t7e encrypt i8q8p2L8gZpZsPD8NRcTiFfQHLfrhoq3IvsaEwWzPJH
    Error: unable to open 'filename.txt.t7e' for output
    
    Caused by:
        No such file or directory (os error 2)
    
    opened by fadedbee 0
Owner
Faded Bee
Faded Bee
Decrypts/encrypts Judgment and Lost Judgment PC chara.par archives

yagami-decryption-agency Decrypts/encrypts Judgment and Lost Judgment PC chara.par archives Installation Download the latest release. Usage USAGE:

null 3 Dec 1, 2022
A simple key-value store with a log-structured, append-only storage architecture where data is encrypted with AES GCM.

akvdb A simple key-value store with a log-structured, append-only storage architecture where data is encrypted with AES GCM. Modified from the actionk

Olle W 3 Oct 10, 2022
A guide for Mozilla's developers and data scientists to analyze and interpret the data gathered by our data collection systems.

Mozilla Data Documentation This documentation was written to help Mozillians analyze and interpret data collected by our products, such as Firefox and

Mozilla 75 Dec 1, 2022
Source project for the Internet Computer software

The Internet Computer is the world’s first blockchain that runs at web speed and can increase its capacity without bound. Like the Internet (which is composed of many machines adhering to TCP/IP protocol) and blockchain protocols (such as Bitcoin and Ethereum).

DFINITY 1.2k Jan 1, 2023
secret folders generator to hide hentais in your computer

hentai dream 95 secret folders generator to hide hentais in your computer, but its really old way as **** used techniquee one injection technique from

jumango pussu 7 Jul 8, 2021
Dank - The Internet Computer Decentralized Bank - A collection of Open Internet Services - Including the Cycles Token (XTC)

Dank - The Internet Computer Decentralized Bank Dank is a collection of Open Internet Services for users and developers on the Internet Computer. In t

Psychedelic 56 Nov 12, 2022
Terabethia - A Bridge and Messaging Protocol between Ethereum and the Internet Computer.

Terabethia - A Bridge Between Ethereum & the Internet Computer Terabethia is a bridge between Ethereum & the Internet Computer that contracts in both

Psychedelic 36 Dec 26, 2022
DIP721 - An Internet Computer Non-fungible Token Standard

DIP721 - Introduction DIP721 is an ERC-721 style non-fungible token standard built mirroring its Ethereum counterpart and adapting it to the Internet

Psychedelic 48 Nov 24, 2022
A preview of the integration between Bitcoin and the Internet Computer.

Bitcoin Integration Developer Preview Overview The integration between the Internet Computer and Bitcoin will enable developers to build canisters tha

DFINITY 39 Sep 21, 2022
Rust library for build smart contracts on Internet Computer, by the Spinner.Cash team.

Spinner Rust library for building smart contracts on the Internet Computer. More specifically it is used by Spinner.Cash, a decentralized layer-2 prot

Spinner 6 May 31, 2022