func DecryptAuth(in []byte, ratch *ratchet.Ratchet) (*ratchet.Ratchet, []byte, error) { msg, err := ratch.Decrypt(in) if err != nil { return nil, nil, err } unpadMsg := proto.Unpad(msg) return ratch, unpadMsg, nil }
func LoadRatchet(d *Daemon, name string, fillAuth func(tag, data []byte, theirAuthPublic *[32]byte), checkAuth func(tag, data, msg []byte, ourAuthPrivate *[32]byte) error) (*ratchet.Ratchet, error) { ratch := new(ratchet.Ratchet) if err := persistence.UnmarshalFromFile(d.ratchetPath(name), ratch); err != nil { return nil, err } ratch.FillAuth = fillAuth ratch.CheckAuth = checkAuth return ratch, nil }
func AllRatchets(d *Daemon, fillAuth func(tag, data []byte, theirAuthPublic *[32]byte), checkAuth func(tag, data, msg []byte, ourAuthPrivate *[32]byte) error) ([]*ratchet.Ratchet, error) { files, err := ioutil.ReadDir(d.ratchetKeysDir()) if err != nil { return nil, err } ret := make([]*ratchet.Ratchet, 0, len(files)) for _, file := range files { if file.IsDir() { continue } ratch := new(ratchet.Ratchet) err := persistence.UnmarshalFromFile(filepath.Join(d.ratchetKeysDir(), file.Name()), ratch) if err != nil { return nil, fmt.Errorf("failed to parse ratchet for \"%s\": %s", file.Name(), err) } ratch.FillAuth = fillAuth ratch.CheckAuth = checkAuth ret = append(ret, ratch) } return ret, nil }
func EncryptAuth(message []byte, ratch *ratchet.Ratchet) ([]byte, *ratchet.Ratchet, error) { paddedMsg := proto.Pad(message, proto.MAX_MESSAGE_SIZE-ENCRYPT_ADDED_LEN) out := ratch.Encrypt(nil, paddedMsg) return out, ratch, nil }