From bb4493a7cd07adf85452fd551be54b47d4416a32 Mon Sep 17 00:00:00 2001 From: Filippo Valsorda Date: Thu, 16 Jun 2022 11:47:27 +0200 Subject: [PATCH] tests: add X25519 low order point tests --- testdata/testkit/{bad_hmac => hmac_bad} | Bin ...lid_characters => stanza_valid_characters} | Bin 532 -> 536 bytes testdata/testkit/x25519_identity | Bin 0 -> 457 bytes testdata/testkit/x25519_low_order | Bin 0 -> 457 bytes tests/{bad_hmac.go => hmac_bad.go} | 0 ...aracters.go => stanza_valid_characters.go} | 5 ++- tests/x25519_identity.go | 34 ++++++++++++++++ tests/x25519_low_order.go | 38 ++++++++++++++++++ 8 files changed, 75 insertions(+), 2 deletions(-) rename testdata/testkit/{bad_hmac => hmac_bad} (100%) rename testdata/testkit/{valid_characters => stanza_valid_characters} (69%) create mode 100644 testdata/testkit/x25519_identity create mode 100644 testdata/testkit/x25519_low_order rename tests/{bad_hmac.go => hmac_bad.go} (100%) rename tests/{valid_characters.go => stanza_valid_characters.go} (78%) create mode 100644 tests/x25519_identity.go create mode 100644 tests/x25519_low_order.go diff --git a/testdata/testkit/bad_hmac b/testdata/testkit/hmac_bad similarity index 100% rename from testdata/testkit/bad_hmac rename to testdata/testkit/hmac_bad diff --git a/testdata/testkit/valid_characters b/testdata/testkit/stanza_valid_characters similarity index 69% rename from testdata/testkit/valid_characters rename to testdata/testkit/stanza_valid_characters index 0c88a6e0c043d80d2a47b2f97d3661a13e84f0af..c506f3094dd844c07bb80de3e48f16aed839c76c 100644 GIT binary patch delta 64 zcmbQjGJ|D<1|tg>m#*Dp4aT|J6{f}(RhAWAg_aSn-iC=GAt7ZJ28rP=VP#<{LH=cl U5qU->1%(j-&KBvDKQO8Q09h6k82|tP delta 59 zcmbQiGKFP>2IFKM#<|)NDZ$0*&Tif%l>tr_p$3UXDcY_%p^>3!{sm?cfh8^(RW9ys Pq0T-@S^1N{Fsc9mOBoa& diff --git a/testdata/testkit/x25519_identity b/testdata/testkit/x25519_identity new file mode 100644 index 0000000000000000000000000000000000000000..eb254e70a9f5c578cfb42b0db5aaa2c3082adcfd GIT binary patch literal 457 zcma)$yN=U96o!SwA~6#0FeL@U+T$4PxGT?a3*txBE0z`{= z11dyM%LC9*QX|nLM2oW$J^v~G=KIb$ux}vmhIj>80UDQ?tTq}@DJ#G);V{J9VVvdt zl-#BUw>W2%70l$6ISd#_vVgjiU5~nBk38|tXWpFnUP?@FJYPhkQACY_#e+DF?or#A zCTZl;$PW@K#DyQH{#1--Z1B{L6J|W7A)N{X@2 zS}={sOl6D`no@-k+NVI7#8b#?UhmPNspE5fVWjm%vdl$nXr1F$Zi0#NyQfxN++5xIpfI`BU(nr-Q7Jzt#Vw4p- zT!_Qrvfz3B3{}NFd5@&1fgj8PTtRH8-BOzB+MAso+J&w1-a@|>*m z;LKc(`)g$f-FDg=N}t}m)E@nuY`=eeh>Q?", "@ABCDEFG", - "HIJKLMNO", "PQRSTUVW", "XYZ[\\]^_", "`abcdefg", "hijklmno", "pqrstuvw", "xyz{|}~") + f.ArgsLine("!\"#$%&'", "()*+,-./", "01234567", "89:;<=>?", "@ABCDEFG", "HIJKLMNO") + f.Body([]byte("")) + f.ArgsLine("PQRSTUVW", "XYZ[\\]^_", "`abcdefg", "hijklmno", "pqrstuvw", "xyz{|}~") f.Body([]byte("")) f.X25519(testkit.TestX25519Recipient) f.HMAC() diff --git a/tests/x25519_identity.go b/tests/x25519_identity.go new file mode 100644 index 0000000..be8e531 --- /dev/null +++ b/tests/x25519_identity.go @@ -0,0 +1,34 @@ +// Copyright 2022 The age Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//go:build ignore + +package main + +import ( + "crypto/sha256" + "encoding/base64" + + "filippo.io/age/internal/testkit" + "golang.org/x/crypto/curve25519" + "golang.org/x/crypto/hkdf" +) + +func main() { + f := testkit.NewTestFile() + f.VersionLine("v1") + f.X25519RecordIdentity(testkit.TestX25519Identity) + share := make([]byte, curve25519.PointSize) + f.ArgsLine("X25519", base64.RawStdEncoding.EncodeToString(share)) + secret := make([]byte, curve25519.PointSize) + key := make([]byte, 32) + hkdf.New(sha256.New, secret, append(share, testkit.TestX25519Recipient...), + []byte("age-encryption.org/v1/X25519")).Read(key) + f.AEADBody(key, testkit.TestFileKey) + f.HMAC() + f.Payload("age") + f.ExpectHeaderFailure() + f.Comment("the X25519 share is a low-order point, so the shared secret is the disallowed all-zero value") + f.Generate() +} diff --git a/tests/x25519_low_order.go b/tests/x25519_low_order.go new file mode 100644 index 0000000..fbc374a --- /dev/null +++ b/tests/x25519_low_order.go @@ -0,0 +1,38 @@ +// Copyright 2022 The age Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//go:build ignore + +package main + +import ( + "crypto/sha256" + "encoding/base64" + + "filippo.io/age/internal/testkit" + "golang.org/x/crypto/curve25519" + "golang.org/x/crypto/hkdf" +) + +func main() { + f := testkit.NewTestFile() + f.VersionLine("v1") + f.X25519RecordIdentity(testkit.TestX25519Identity) + // Point of order 8 on Curve25519, chosen to be the least likely to be + // flagged by hardcoded list exclusions. + share := []byte{0x5f, 0x9c, 0x95, 0xbc, 0xa3, 0x50, 0x8c, 0x24, 0xb1, 0xd0, + 0xb1, 0x55, 0x9c, 0x83, 0xef, 0x5b, 0x04, 0x44, 0x5c, 0xc4, 0x58, 0x1c, + 0x8e, 0x86, 0xd8, 0x22, 0x4e, 0xdd, 0xd0, 0x9f, 0x11, 0xd7} + f.ArgsLine("X25519", base64.RawStdEncoding.EncodeToString(share)) + secret := make([]byte, curve25519.PointSize) + key := make([]byte, 32) + hkdf.New(sha256.New, secret, append(share, testkit.TestX25519Recipient...), + []byte("age-encryption.org/v1/X25519")).Read(key) + f.AEADBody(key, testkit.TestFileKey) + f.HMAC() + f.Payload("age") + f.ExpectHeaderFailure() + f.Comment("the X25519 share is a low-order point, so the shared secret is the disallowed all-zero value") + f.Generate() +}