blob: aba2628c42e119ae8573c86c9627e1556844d0c1 [file] [log] [blame]
Jiri Simsad7616c92015-03-24 23:44:30 -07001// Copyright 2015 The Vanadium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
Jiri Simsa5293dcb2014-05-10 09:56:38 -07005// Package crypto implements encryption and decryption interfaces intended for
6// securing communication over VCs.
7package crypto
8
Suharsh Sivakumardcc11d72015-05-11 12:19:20 -07009import "v.io/x/ref/runtime/internal/lib/iobuf"
Jiri Simsa5293dcb2014-05-10 09:56:38 -070010
11type Encrypter interface {
12 // Encrypt encrypts the provided plaintext data and returns the
13 // corresponding ciphertext slice (or nil if an error is returned).
14 //
15 // It always calls Release on plaintext and thus plaintext should not
16 // be used after calling Encrypt.
17 Encrypt(plaintext *iobuf.Slice) (ciphertext *iobuf.Slice, err error)
18}
19
20type Decrypter interface {
21 // Decrypt decrypts the provided ciphertext slice and returns the
22 // corresponding plaintext (or nil if an error is returned).
23 //
24 // It always calls Release on ciphertext and thus ciphertext should not
25 // be used after calling Decrypt.
26 Decrypt(ciphertext *iobuf.Slice) (plaintext *iobuf.Slice, err error)
27}
28
29type Crypter interface {
30 Encrypter
31 Decrypter
Jungho Ahn19e84b22015-05-18 13:22:27 -070032 // ChannelBinding returns a byte slice that is unique for the the
Jason Hickey96d30e82014-11-13 07:40:00 -080033 // particular crypter (and the parties between which it is operating).
Andres Erbsenffa45742014-08-13 10:13:11 -070034 // Having both parties assert out of the band that they are indeed
35 // participating in a connection with that channel binding value is
36 // sufficient to authenticate the data received through the crypter.
37 ChannelBinding() []byte
Jiri Simsa5293dcb2014-05-10 09:56:38 -070038 String() string
39}