Skip to content

Commit

Permalink
fix qpp usage
Browse files Browse the repository at this point in the history
  • Loading branch information
xtaci committed Dec 27, 2024
1 parent 7520349 commit 8638333
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions std/qpp.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,25 @@ import (
type QPPPort struct {
underlying io.ReadWriteCloser // io.Writer is not enough, we need to close the underlying writer as well

qpp *qpp.QuantumPermutationPad
pad *qpp.QuantumPermutationPad
wprng *qpp.Rand
rprng *qpp.Rand
}

func NewQPPPort(underlying io.ReadWriteCloser, qpp *qpp.QuantumPermutationPad, seed []byte) *QPPPort {
func NewQPPPort(underlying io.ReadWriteCloser, pad *qpp.QuantumPermutationPad, seed []byte) *QPPPort {
wprng := qpp.CreatePRNG(seed)
rprng := qpp.CreatePRNG(seed)
return &QPPPort{underlying, qpp, wprng, rprng}
return &QPPPort{underlying, pad, wprng, rprng}
}

func (port *QPPPort) Read(p []byte) (n int, err error) {
n, err = port.underlying.Read(p)
port.qpp.DecryptWithPRNG(p[:n], port.rprng)
func (r *QPPPort) Read(p []byte) (n int, err error) {
n, err = r.underlying.Read(p)
r.pad.DecryptWithPRNG(p[:n], r.rprng)
return
}

func (r *QPPPort) Write(p []byte) (n int, err error) {
r.qpp.EncryptWithPRNG(p, r.wprng)
r.pad.EncryptWithPRNG(p, r.wprng)
return r.underlying.Write(p)
}

Expand Down

0 comments on commit 8638333

Please sign in to comment.