Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
Merge pull request #10 from keybase/maxtaco/CORE-2505
Browse files Browse the repository at this point in the history
More GNU S2K dummy: don't bother to read the hash
  • Loading branch information
maxtaco committed Feb 7, 2016
2 parents 01dea31 + 9cddb8c commit 826ac31
Showing 1 changed file with 32 additions and 23 deletions.
55 changes: 32 additions & 23 deletions openpgp/s2k/s2k.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,31 @@ func Iterated(out []byte, h hash.Hash, in []byte, salt []byte, count int) {
}
}

func parseGNUExtensions(r io.Reader) (f func(out, in []byte), err error) {
var buf [9]byte

// A three-byte string identifier
_, err = io.ReadFull(r, buf[:3])
if err != nil {
return
}
gnuExt := string(buf[:3])

if gnuExt != "GNU" {
return nil, errors.UnsupportedError("Malformed GNU extension: " + gnuExt)
}
_, err = io.ReadFull(r, buf[:1])
if err != nil {
return
}
gnuExtType := int(buf[0])
if gnuExtType != 1 {
return nil, errors.UnsupportedError("unknown S2K GNU protection mode: " + strconv.Itoa(int(gnuExtType)))
}

return nil, nil
}

// Parse reads a binary specification for a string-to-key transformation from r
// and returns a function which performs that transform.
func Parse(r io.Reader) (f func(out, in []byte), err error) {
Expand All @@ -160,6 +185,13 @@ func Parse(r io.Reader) (f func(out, in []byte), err error) {
return
}

// GNU Extensions; handle them before we try to look for a hash, which won't
// be needed in most cases anyway.
if buf[0] == 101 {
return parseGNUExtensions(r)
}


hash, ok := HashIdToHash(buf[1])
if !ok {
return nil, errors.UnsupportedError("hash for S2K function: " + strconv.Itoa(int(buf[1])))
Expand Down Expand Up @@ -194,29 +226,6 @@ func Parse(r io.Reader) (f func(out, in []byte), err error) {
Iterated(out, h, in, buf[:8], count)
}
return f, nil

// GNU Extensions
case 101:

// A three-byte string identifier
_, err = io.ReadFull(r, buf[:3])
if err != nil {
return
}
gnuExt := string(buf[:3])

if gnuExt != "GNU" {
return nil, errors.UnsupportedError("Malformed GNU extension: " + gnuExt)
}
_, err = io.ReadFull(r, buf[:1])
if err != nil {
return
}
gnuExtType := int(buf[0])
if gnuExtType != 1 {
return nil, errors.UnsupportedError("unknown S2K GNU protection mode: " + strconv.Itoa(int(gnuExtType)))
}
return nil, nil
}

return nil, errors.UnsupportedError("S2K function")
Expand Down

0 comments on commit 826ac31

Please sign in to comment.