Container sealing algorithm is inspired from Keybase saltpack specification
This sealing process is based on Public Key Encryption scheme.
This algorithm implements multi recipient authenticated encryption with
sign-then-encrypt
pattern.
-
Preparation
- Serialize
unsealed
container as protobuf ascontainer_content
- Generate a random 32 bytes array as
payload_key
- Generate ed25519
ephemeral signing keypair
- Seal
ephemeral_signing_public_key
using asecretbox
- the fixed 24 bytes nonce (
harp_container_psigk_box
) - with
payload_key
- the fixed 24 bytes nonce (
- Generate X25519
ephemeral encryption keypair
- Serialize
-
Header
- Set
ContentType
toapplication/vnd.harp.v1.SealedContainer
- Set
EncryptionPublicKey
toephemeral encryption public key
- Set
ContainerBox
toencrypted ephemeral signing public key
- For each given
recipient_public_key
- Derive recipient key
- Prepare fixed 24 bytes nonce (
harp_derived_id_sboxkey0
) - Initialize 32 bytes zero filled array
- Seal the zero filled array using fixed nonce, the
recipient_public_key
and theephemeral_encryption_private_key
- Get the last 32 bytes of the result and save it as
derived_recipient_key
- Prepare fixed 24 bytes nonce (
- Derive recipient identifier
- Prepare Blake2b-512 hash function with a fixed 41 bytes as key (
harp signcryption box key identifier
) - Hash the
derived_recipient_key
- Save first 32 bytes of result as
recipient_identifier
- Prepare Blake2b-512 hash function with a fixed 41 bytes as key (
- Pack the
containerv1.Recipient
object- Set
Identifier
torecipient_identifier
- Set
Key
torecipient_key
- Set
- Add
Recipient
object torecipients
list
- Derive recipient key
- Calculate
header_hash
- Serialize
containerv1.Header
object as protobuf byte array - Compute Blake2b-512 hash of serialized byte array
- Save the hash result byte array as
header_hash
- Serialize
- Set
-
Content
- Signature
- Prepare
protected_content
by concatenating :- the ASCII string
harp encrypted signature
- a zero byte (
0x00
) - the
header_hash
content - the Blake2b-512 hash result of the
container_content
- the ASCII string
- Sign using
ed25519
signature scheme- Sign
protected_content
withephemeral signing private key
- Save signature as
content_signature
- Sign
- Prepare
- Encryption
- Concatenate the
content_signature
andcontainer_content
- Seal the result with
payload_key
and the first 24 bytes ofheader_hash
as nonce - Set
Raw
to encryption result
- Concatenate the
- Signature
-
Requirements
- A set of
identity_private_key
- A set of
-
Header
- Validate
ContentType
withapplication/vnd.harp.v1.SealedContainer
- Retrieve
EncryptionPublicKey
and validate the required length (32 bytes) - For each
identity_private_key
- Derive recipient key
- Prepare fixed 24 bytes nonce (
harp_derived_id_sboxkey0
) - Initialize 32 bytes zero filled array
- Seal the zero filled array using fixed nonce, the
ephemral_encryption_public_key
and therecipient_private_key
- Get the last 32 bytes of the result and save it as
derived_recipient_key
- Prepare fixed 24 bytes nonce (
- Derive recipient identifier
- Prepare Blake2b-512 hash function with a fixed 41 bytes as key (
harp signcryption box key identifier
) - Hash the
derived_recipient_key
- Save first 32 bytes of result as
recipient_identifier
- Prepare Blake2b-512 hash function with a fixed 41 bytes as key (
- For each
Recipients
inrecipients
list- Compare
Identifier
withrecipient_identifier
- If not match continue until you find a match, unless error
- If matched, unseal the
recipient_key
fromKey
using thederived_recipient_key
- Save the result as
payload_key
- Compare
- Derive recipient key
- Validate
-
Content
- Decryption
- Retrieve
ephemeral_signing_public_key
- Open
ContainerBox
secretbox with- the fixed 24 bytes nonce (
harp_container_psigk_box
) - with
payload_key
- the fixed 24 bytes nonce (
- Save the result as
ephemeral_signing_public_key
- Open
- Calculate
header_hash
- Serialize
containerv1.Header
object as protobuf byte array - Compute Blake2b-512 hash of serialized byte array
- Save the hash result byte array as
header_hash
- Serialize
- Open
Raw
box with- the first 24 bytes of
header_hash
as nonce - the
payload_key
- the first 24 bytes of
- Retrieve
- Signature
- Prepare
protected_content
by concatenating :- the ASCII string
harp encrypted signature
- a zero byte (
0x00
) - the
header_hash
content - the Blake2b-512 hash result of the
container_content
- the ASCII string
- Verify using
ed25519
signature scheme- Verify
protected_content
withephemeral_signing_public_key
- Save signature as
content_signature
- Verify
- Prepare
- Unmarshal
payload
as&containerv1.Container{}
- Decryption
TODO