summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRose Hogenson <rosehogenson@posteo.net>2026-02-06 16:55:40 -0800
committerRose Hogenson <rosehogenson@posteo.net>2026-02-06 16:55:40 -0800
commit083878218b9a95038e499732cc8aefa0e66a9a0d (patch)
tree1c2956296d58f72ef4ae23b1a05cc074439e235a
parentcf9e3f0f753e69c5bfa0838787e1c9833a060646 (diff)
downloadroseh.moe-083878218b9a95038e499732cc8aefa0e66a9a0d.tar.zst
Do a little less sha256
Since oae2 will internally also call hkdf, there's no reason to hkdf the encryption key twice. We can hkdf it once for the primary key, and then let oae2 hkdf it again for the encryption key. Since the second hkdf uses a 32 byte random salt, the two calls will certainly use different parameters.
-rw-r--r--roseh.moe.go10
1 files changed, 4 insertions, 6 deletions
diff --git a/roseh.moe.go b/roseh.moe.go
index cd443a6..49f62d3 100644
--- a/roseh.moe.go
+++ b/roseh.moe.go
@@ -251,17 +251,16 @@ const blockSize = 4 * 1024 * 1024
func writeHoleFile(part *multipart.Part) (string, error) {
hole := makeHole()
- key, err := hkdf.Key(sha256.New, []byte(hole), nil, "", 48)
+ primaryKey, err := hkdf.Key(sha256.New, []byte(hole), nil, "", 32)
if err != nil {
return "", err
}
- primaryKey, encryptionKey := key[:32], key[32:]
f, err := os.Create(fmt.Sprintf("%s/%x", *holeTempDir, primaryKey))
if err != nil {
return "", err
}
defer f.Close()
- w := oae2.NewWriter(f, encryptionKey, blockSize, nil)
+ w := oae2.NewWriter(f, []byte(hole), blockSize, nil)
fileName := part.FileName()
buf := make([]byte, 8)
binary.BigEndian.PutUint64(buf, uint64(len(fileName)))
@@ -296,11 +295,10 @@ func (r *offsetReader) Seek(offset int64, whence int) (int64, error) {
var errNoHole = errors.New("no such hole")
func readHoleFile(w http.ResponseWriter, req *http.Request, hole string) error {
- key, err := hkdf.Key(sha256.New, []byte(hole), nil, "", 48)
+ primaryKey, err := hkdf.Key(sha256.New, []byte(hole), nil, "", 32)
if err != nil {
return err
}
- primaryKey, encryptionKey := key[:32], key[32:]
f, err := os.Open(fmt.Sprintf("%s/%x", *holeTempDir, primaryKey))
if err != nil {
if errors.Is(err, fs.ErrNotExist) {
@@ -309,7 +307,7 @@ func readHoleFile(w http.ResponseWriter, req *http.Request, hole string) error {
return err
}
defer f.Close()
- r := oae2.NewReader(f, encryptionKey, blockSize, nil)
+ r := oae2.NewReader(f, []byte(hole), blockSize, nil)
buf := make([]byte, 8)
if _, err := io.ReadFull(r, buf); err != nil {
return err