Hello agl@chromium.org, minux.ma@gmail.com (cc: golang-dev@googlegroups.com), I'd like you to review this change to https://code.google.com/p/go.crypto
10 years, 6 months ago
(2013-03-07 22:44:58 UTC)
#1
At the high level, we've not exposed a KDF API before and it's unclear whether ...
10 years, 6 months ago
(2013-03-12 15:12:15 UTC)
#3
At the high level, we've not exposed a KDF API before and it's unclear whether a
Reader interface is the right one. The alternative would be to pass in a length,
or a []byte to be filled, and have it be a one-shot operation.
However, since one typically takes a number of outputs (a couple of keys and a
couple of IVs) from a KDF, the Reader interface may save people having to
manually split up a single output so I think I like it.
However, the implementation itself allocates far more than is needed. I can fix
this up before landing if you wish but I've pointed out a few cases in case you
wish to iterate yourself.
(p.s. have you signed the CLA?)
https://codereview.appspot.com/7474049/diff/17001/hkdf/hkdf.go
File hkdf/hkdf.go (right):
https://codereview.appspot.com/7474049/diff/17001/hkdf/hkdf.go#newcode44
hkdf/hkdf.go:44: input := append(f.prev, append(f.info, f.counter)...)
this is better written as two, non-nested appends. The nested append is actually
copying f.info into a new buffer just to append a single byte and returning it.
input can also be reused between iterations.
https://codereview.appspot.com/7474049/diff/17001/hkdf/hkdf.go#newcode46
hkdf/hkdf.go:46: expander := hmac.New(f.hash, f.prk)
the HMAC from New can be passed in and Reset() rather than creating afresh each
time.
https://codereview.appspot.com/7474049/diff/17001/hkdf/hkdf.go#newcode48
hkdf/hkdf.go:48: output := expander.Sum(nil)
in the case where the full hash result fits in p, it could be written directly.
https://codereview.appspot.com/7474049/diff/17001/hkdf/hkdf.go#newcode63
hkdf/hkdf.go:63: func New(hash func() hash.Hash, master []byte, salt []byte,
info []byte) io.Reader {
argument names should either be commonly used, or match the RFC. Thus I would
call "master" either "secret" or "ikm".
https://codereview.appspot.com/7474049/diff/17001/hkdf/hkdf.go#newcode64
hkdf/hkdf.go:64: extractor := hmac.New(hash, salt)
If a salt is not provided, hash.Size() zero bytes should be used.
https://codereview.appspot.com/7474049/diff/17001/hkdf/hkdf.go#newcode67
hkdf/hkdf.go:67: return &hkdf{hash, hash().Size(), extractor.Sum(nil), info, 1,
[]byte{}, []byte{}}
s/[]byte{}/nil/
I think I'll manage the fixes, I'll commit in a few hours, just let me ...
10 years, 6 months ago
(2013-03-12 15:38:36 UTC)
#4
I think I'll manage the fixes, I'll commit in a few hours, just let me finish up
something first.
Btw, there's one slight design change I've added since the review request:
instead of passing in "hash-maker" functions, I've changed to the crypto.Hash
enums:
hkdf.New(sha1.New, ...) -> hkdf.New(crypto.SHA1, ...)
Which design do you prefer? The original or the crypto-enum one? (the latter is
available at https://github.com/karalabe/iris/blob/master/crypto/hkdf/hkdf.go ).
PS: Yes I've signed the CLA (at least the digital version)
On Tue, Mar 12, 2013 at 11:38 AM, <peterke@gmail.com> wrote: > Btw, there's one slight ...
10 years, 6 months ago
(2013-03-12 15:45:40 UTC)
#5
On Tue, Mar 12, 2013 at 11:38 AM, <peterke@gmail.com> wrote:
> Btw, there's one slight design change I've added since the review
> request: instead of passing in "hash-maker" functions, I've changed to
> the crypto.Hash enums:
Passing in the function is more canonical.
Cheers
AGL
https://codereview.appspot.com/7474049/diff/32001/hkdf/hkdf.go File hkdf/hkdf.go (right): https://codereview.appspot.com/7474049/diff/32001/hkdf/hkdf.go#newcode6 hkdf/hkdf.go:6: // Function (HKDF) as defined in Internet Engineering Task ...
9 years, 9 months ago
(2013-12-19 21:10:13 UTC)
#9
On 2014/01/14 14:25:32, agl1 wrote: > Any interest in continuing with this? Yes, yes. Sorry ...
9 years, 7 months ago
(2014-01-29 09:10:53 UTC)
#12
On 2014/01/14 14:25:32, agl1 wrote:
> Any interest in continuing with this?
Yes, yes. Sorry for not responding, I'm prepping a demo for the FOSDEM Go
devroom for the weekend and it takes up all my time. But I'll get back to this
asap.
LGTM. I'll make these changes before landing because they're small. Thanks! https://codereview.appspot.com/7474049/diff/76001/hkdf/example_test.go File hkdf/example_test.go (right): ...
9 years, 7 months ago
(2014-02-12 19:03:54 UTC)
#14
Issue 7474049: code review 7474049: hkdf: implemented hash based key derivation.
Created 10 years, 6 months ago by karalabe
Modified 9 years, 7 months ago
Reviewers:
Base URL:
Comments: 16