-
Notifications
You must be signed in to change notification settings - Fork 93
codec: AES encrypted blocks #349
base: master
Are you sure you want to change the base?
Changes from 5 commits
2f07383
4a60e40
03d54df
417e69c
bbb6014
bf8e5e0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| # Specification: AES CODECS | ||
|
|
||
| **Status: Prescriptive - Draft** | ||
|
|
||
| This document describes codecs for IPLD blocks (CID + Data) that are encrypted with | ||
| an AES cipher. | ||
|
|
||
| The following AES variants are defined in this spec: | ||
|
|
||
| | name | multicodec | iv size (in bytes) | | ||
| | --- | --- | --- | | ||
| | aes-gcm | 0x1400 | 12 | | ||
| | aes-cbc | 0x1401 | 16 | | ||
| | aes-ctr | 0x1402 | 12 | | ||
|
|
||
| ## What this spec is not | ||
|
|
||
| This is not a complete system for application privacy. The following issues are | ||
| out of scope for this specification, although they can obviously leverage these codecs: | ||
|
|
||
| * Key signaling | ||
| * Access controls | ||
| * Dual-layer encryption w/ replication keys | ||
|
|
||
| How you determine what key to apply to an encrypted block will need to be done in the | ||
| application layer. How you decide to encrypt a graph and potentially link the encrypted | ||
| blocks together for replication is done at the application layer. How you manage and access | ||
| keys is done in the application layer. | ||
|
|
||
| ## Encode/Decode vs Encrypt/Decrypt | ||
|
|
||
| The goal of specifying codecs that are used for encryption is to allow the codecs to | ||
| include encryption and decryption programs alongside the codec. However, encrypting and | ||
| decrypting are done by the user and are not done automatically as part of any encode/decode | ||
| operation in the codec. | ||
|
|
||
| The encryption program returns a data model value suitable for the block encode program. The | ||
| decode program provides a data model value suitable for the decryption program. And the decryption | ||
| program provides a data model value suitable for parsing into a new block (CID and Bytes). These | ||
| programs are designed to interoperate but it's up to the user to combine them and provide the | ||
| necessary key during encryption and decryption. | ||
|
|
||
| ## Encrypted Block Format | ||
|
|
||
| An encrypted block can be decoded into its initializing vector and the encrypted byte | ||
| payload. Since the initializing vector is a known size for each AES variant the block | ||
| format is simply the iv followed by the byte payload. | ||
|
|
||
| ``` | ||
| | iv | bytes | | ||
| ``` | ||
|
|
||
| This is decoded into IPLD data model of the following schema. | ||
|
|
||
| ```ipldsch | ||
| type AES struct { | ||
| iv Bytes | ||
| bytes Bytes | ||
| } representation map | ||
| ``` | ||
|
|
||
| ## Decrypted Block Format | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe it's just me missing/misunderstanding something, but this section seems like it isn't related to the aes-* codec specs. Is there a codec that turns into If so, what is it called and where is it used/referenced? Is aes-gcm encoded data that properly satisfies
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We’re in a bit of a grey area as to what “is” and “is not” part of the codec. Sure, you could say that anything that falls outside the encode/decode function “is not” part of the codec. However:
However, I DO NOT want to overly formalize the representation of the block because, ideally, what is input/output for encrypt/decrypt functions would align with the IPLD library in that language and map to how that library handles blocks, which is NOT formalized and there are big differences between implementations. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I get what you're saying, although I wonder if we should be disambiguating a bit in this doc by saying what implementers of the codec MUST do (e.g. follow the encoding/decoding rules for the encrypted block format) and what users of the codec SHOULD do (encrypt data of the form presented here, i.e. |
||
|
|
||
| The decrypted payload has a defined format so that it can be parsed into a pair of `CID` and | ||
| `bytes`. | ||
|
|
||
| ``` | ||
| | uint32(CID byteLength) | CID | Bytes | ||
| ``` | ||
|
|
||
| The decrypted state is decoded into IPLD data model of the following schema. | ||
|
|
||
| ```ipldsch | ||
| type DecryptedBlock struct { | ||
| cid Link | ||
| bytes Bytes | ||
| } representation map | ||
| ``` | ||
|
|
||
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think using
representation tuplewould be clearer. I know that a codec can decide how to encode a Data Model Map, but just concatenating two byte streams reminds me conceptually more of a an array/tuple than of a map. Same for theDecryptBlock.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This describes what the parsed data model state is, not the encoded binary. It should be a map, not a tuple, because even without a schema being applied it’s a map.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to think about that quite a bit, now I get it. It makes sense. Then this codec only supports
BytesandMaps (so replaceListwithMapin my other comment).