func NewCircuit(id CircuitID, fSeed, bSeed, fKey, bKey []byte) *Circuit { if id == 0 { panic("wtf?") } StatsNewCircuit() aes_fwd := aes.New(fKey, zeroIv[:]) aes_rev := aes.New(bKey, zeroIv[:]) dig_fwd := sha1.New() dig_fwd.Write(fSeed) dig_rev := sha1.New() dig_rev.Write(bSeed) circ := &Circuit{ id: id, forward: DirectionalCircuitState{ cipher: aes_fwd, digest: dig_fwd, }, backward: DirectionalCircuitState{ cipher: aes_rev, digest: dig_rev, }, backwardWindow: NewWindow(1000), forwardWindow: 1000, streams: make(map[StreamID]*Stream), } return circ }
func HybridDecrypt(priv openssl.PrivateKey, d []byte) ([]byte, error) { // XXX this could probably be optimized a little res, err := priv.Decrypt(d[0:128]) if err != nil { return nil, err } if len(res) < 86 { return res, nil } data1 := res[16:86] aes := aes.New(res[0:16], make([]byte, 16)) res2 := make([]byte, len(d)-128) res2, err = aes.Crypt(d[128:len(d)], res2) if err != nil { return nil, err } finalRes := make([]byte, len(data1)+len(res2)) copy(finalRes, data1) copy(finalRes[len(data1):], res2) return finalRes, nil }