github.com/cloudflare/circl@v1.5.0/sign/ed25519/rfc8032_test.go (about) 1 package ed25519_test 2 3 import ( 4 "archive/zip" 5 "bufio" 6 "bytes" 7 "encoding/hex" 8 "fmt" 9 "strings" 10 "testing" 11 12 "github.com/cloudflare/circl/internal/test" 13 "github.com/cloudflare/circl/sign/ed25519" 14 ) 15 16 type rfc8032Vector struct { 17 private ed25519.PrivateKey 18 public ed25519.PublicKey 19 message []byte 20 signature []byte 21 } 22 23 func (v *rfc8032Vector) fetch(line string) { 24 values := strings.Split(line, ":") 25 if len(values) != 5 { 26 panic(fmt.Errorf("len: %v %v", len(values), values)) 27 } 28 v.private, _ = hex.DecodeString(values[0]) 29 v.public, _ = hex.DecodeString(values[1]) 30 v.message, _ = hex.DecodeString(values[2]) 31 v.signature, _ = hex.DecodeString(values[3]) 32 v.private = v.private[:ed25519.SeedSize] 33 v.signature = v.signature[:ed25519.SignatureSize] 34 } 35 36 func (v *rfc8032Vector) test(t *testing.T, lineNum int) { 37 key := ed25519.NewKeyFromSeed(v.private) 38 { 39 got := key.Public().(ed25519.PublicKey) 40 want := v.public 41 if !bytes.Equal(got, want) { 42 test.ReportError(t, got, want, lineNum, v) 43 } 44 45 got = ed25519.Sign(key, v.message) 46 want = v.signature 47 if !bytes.Equal(got, want) { 48 test.ReportError(t, got, want, lineNum, v) 49 } 50 } 51 { 52 got := ed25519.Verify(key.Public().(ed25519.PublicKey), v.message, v.signature) 53 want := true 54 if got != want { 55 test.ReportError(t, got, want, lineNum, v) 56 } 57 } 58 } 59 60 func TestRFC8032(t *testing.T) { 61 const nameFile = "testdata/sign.input.zip" 62 zipFile, err := zip.OpenReader(nameFile) 63 if err != nil { 64 t.Fatalf("File %v can not be opened. Error: %v", nameFile, err) 65 } 66 defer zipFile.Close() 67 68 for _, f := range zipFile.File { 69 unzipped, err := f.Open() 70 if err != nil { 71 t.Fatalf("File %v can not be opened. Error: %v", f.Name, err) 72 } 73 defer unzipped.Close() 74 75 fScanner := bufio.NewScanner(unzipped) 76 var v rfc8032Vector 77 for i := 1; fScanner.Scan(); i++ { 78 v.fetch(fScanner.Text()) 79 v.test(t, i) 80 } 81 } 82 } 83 84 type vector struct { 85 name string 86 scheme string 87 sk []byte 88 pk []byte 89 sig []byte 90 msg []byte 91 msgLen uint 92 ph bool 93 ctx []byte 94 ctxLen uint 95 } 96 97 var vectorsEd25519 = [...]vector{ 98 { 99 name: "-----TEST 1", 100 scheme: "Ed25519Pure", 101 sk: []byte{ 102 0x9d, 0x61, 0xb1, 0x9d, 0xef, 0xfd, 0x5a, 0x60, 0xba, 0x84, 0x4a, 0xf4, 0x92, 0xec, 0x2c, 0xc4, 103 0x44, 0x49, 0xc5, 0x69, 0x7b, 0x32, 0x69, 0x19, 0x70, 0x3b, 0xac, 0x03, 0x1c, 0xae, 0x7f, 0x60, 104 }, 105 pk: []byte{ 106 0xd7, 0x5a, 0x98, 0x01, 0x82, 0xb1, 0x0a, 0xb7, 0xd5, 0x4b, 0xfe, 0xd3, 0xc9, 0x64, 0x07, 0x3a, 107 0x0e, 0xe1, 0x72, 0xf3, 0xda, 0xa6, 0x23, 0x25, 0xaf, 0x02, 0x1a, 0x68, 0xf7, 0x07, 0x51, 0x1a, 108 }, 109 msg: []byte{}, 110 msgLen: 0, 111 sig: []byte{ 112 0xe5, 0x56, 0x43, 0x00, 0xc3, 0x60, 0xac, 0x72, 0x90, 0x86, 0xe2, 0xcc, 0x80, 0x6e, 0x82, 0x8a, 113 0x84, 0x87, 0x7f, 0x1e, 0xb8, 0xe5, 0xd9, 0x74, 0xd8, 0x73, 0xe0, 0x65, 0x22, 0x49, 0x01, 0x55, 114 0x5f, 0xb8, 0x82, 0x15, 0x90, 0xa3, 0x3b, 0xac, 0xc6, 0x1e, 0x39, 0x70, 0x1c, 0xf9, 0xb4, 0x6b, 115 0xd2, 0x5b, 0xf5, 0xf0, 0x59, 0x5b, 0xbe, 0x24, 0x65, 0x51, 0x41, 0x43, 0x8e, 0x7a, 0x10, 0x0b, 116 }, 117 ph: false, 118 ctx: []byte{}, 119 ctxLen: 0, 120 }, 121 { 122 name: "-----TEST 2", 123 scheme: "Ed25519Pure", 124 sk: []byte{ 125 0x4c, 0xcd, 0x08, 0x9b, 0x28, 0xff, 0x96, 0xda, 0x9d, 0xb6, 0xc3, 0x46, 0xec, 0x11, 0x4e, 0x0f, 126 0x5b, 0x8a, 0x31, 0x9f, 0x35, 0xab, 0xa6, 0x24, 0xda, 0x8c, 0xf6, 0xed, 0x4f, 0xb8, 0xa6, 0xfb, 127 }, 128 pk: []byte{ 129 0x3d, 0x40, 0x17, 0xc3, 0xe8, 0x43, 0x89, 0x5a, 0x92, 0xb7, 0x0a, 0xa7, 0x4d, 0x1b, 0x7e, 0xbc, 130 0x9c, 0x98, 0x2c, 0xcf, 0x2e, 0xc4, 0x96, 0x8c, 0xc0, 0xcd, 0x55, 0xf1, 0x2a, 0xf4, 0x66, 0x0c, 131 }, 132 msg: []byte{ 133 0x72, 134 }, 135 msgLen: 1, 136 sig: []byte{ 137 0x92, 0xa0, 0x09, 0xa9, 0xf0, 0xd4, 0xca, 0xb8, 0x72, 0x0e, 0x82, 0x0b, 0x5f, 0x64, 0x25, 0x40, 138 0xa2, 0xb2, 0x7b, 0x54, 0x16, 0x50, 0x3f, 0x8f, 0xb3, 0x76, 0x22, 0x23, 0xeb, 0xdb, 0x69, 0xda, 139 0x08, 0x5a, 0xc1, 0xe4, 0x3e, 0x15, 0x99, 0x6e, 0x45, 0x8f, 0x36, 0x13, 0xd0, 0xf1, 0x1d, 0x8c, 140 0x38, 0x7b, 0x2e, 0xae, 0xb4, 0x30, 0x2a, 0xee, 0xb0, 0x0d, 0x29, 0x16, 0x12, 0xbb, 0x0c, 0x00, 141 }, 142 ph: false, 143 ctx: []byte{}, 144 ctxLen: 0, 145 }, 146 { 147 name: "-----TEST 3", 148 scheme: "Ed25519Pure", 149 sk: []byte{ 150 0xc5, 0xaa, 0x8d, 0xf4, 0x3f, 0x9f, 0x83, 0x7b, 0xed, 0xb7, 0x44, 0x2f, 0x31, 0xdc, 0xb7, 0xb1, 151 0x66, 0xd3, 0x85, 0x35, 0x07, 0x6f, 0x09, 0x4b, 0x85, 0xce, 0x3a, 0x2e, 0x0b, 0x44, 0x58, 0xf7, 152 }, 153 pk: []byte{ 154 0xfc, 0x51, 0xcd, 0x8e, 0x62, 0x18, 0xa1, 0xa3, 0x8d, 0xa4, 0x7e, 0xd0, 0x02, 0x30, 0xf0, 0x58, 155 0x08, 0x16, 0xed, 0x13, 0xba, 0x33, 0x03, 0xac, 0x5d, 0xeb, 0x91, 0x15, 0x48, 0x90, 0x80, 0x25, 156 }, 157 msg: []byte{ 158 0xaf, 0x82, 159 }, 160 msgLen: 2, 161 sig: []byte{ 162 0x62, 0x91, 0xd6, 0x57, 0xde, 0xec, 0x24, 0x02, 0x48, 0x27, 0xe6, 0x9c, 0x3a, 0xbe, 0x01, 0xa3, 163 0x0c, 0xe5, 0x48, 0xa2, 0x84, 0x74, 0x3a, 0x44, 0x5e, 0x36, 0x80, 0xd7, 0xdb, 0x5a, 0xc3, 0xac, 164 0x18, 0xff, 0x9b, 0x53, 0x8d, 0x16, 0xf2, 0x90, 0xae, 0x67, 0xf7, 0x60, 0x98, 0x4d, 0xc6, 0x59, 165 0x4a, 0x7c, 0x15, 0xe9, 0x71, 0x6e, 0xd2, 0x8d, 0xc0, 0x27, 0xbe, 0xce, 0xea, 0x1e, 0xc4, 0x0a, 166 }, 167 ph: false, 168 ctx: []byte{}, 169 ctxLen: 0, 170 }, 171 { 172 name: "-----TEST 1024", 173 scheme: "Ed25519Pure", 174 sk: []byte{ 175 0xf5, 0xe5, 0x76, 0x7c, 0xf1, 0x53, 0x31, 0x95, 0x17, 0x63, 0x0f, 0x22, 0x68, 0x76, 0xb8, 0x6c, 176 0x81, 0x60, 0xcc, 0x58, 0x3b, 0xc0, 0x13, 0x74, 0x4c, 0x6b, 0xf2, 0x55, 0xf5, 0xcc, 0x0e, 0xe5, 177 }, 178 pk: []byte{ 179 0x27, 0x81, 0x17, 0xfc, 0x14, 0x4c, 0x72, 0x34, 0x0f, 0x67, 0xd0, 0xf2, 0x31, 0x6e, 0x83, 0x86, 180 0xce, 0xff, 0xbf, 0x2b, 0x24, 0x28, 0xc9, 0xc5, 0x1f, 0xef, 0x7c, 0x59, 0x7f, 0x1d, 0x42, 0x6e, 181 }, 182 msg: []byte{ 183 0x08, 0xb8, 0xb2, 0xb7, 0x33, 0x42, 0x42, 0x43, 0x76, 0x0f, 0xe4, 0x26, 0xa4, 0xb5, 0x49, 0x08, 184 0x63, 0x21, 0x10, 0xa6, 0x6c, 0x2f, 0x65, 0x91, 0xea, 0xbd, 0x33, 0x45, 0xe3, 0xe4, 0xeb, 0x98, 185 0xfa, 0x6e, 0x26, 0x4b, 0xf0, 0x9e, 0xfe, 0x12, 0xee, 0x50, 0xf8, 0xf5, 0x4e, 0x9f, 0x77, 0xb1, 186 0xe3, 0x55, 0xf6, 0xc5, 0x05, 0x44, 0xe2, 0x3f, 0xb1, 0x43, 0x3d, 0xdf, 0x73, 0xbe, 0x84, 0xd8, 187 0x79, 0xde, 0x7c, 0x00, 0x46, 0xdc, 0x49, 0x96, 0xd9, 0xe7, 0x73, 0xf4, 0xbc, 0x9e, 0xfe, 0x57, 188 0x38, 0x82, 0x9a, 0xdb, 0x26, 0xc8, 0x1b, 0x37, 0xc9, 0x3a, 0x1b, 0x27, 0x0b, 0x20, 0x32, 0x9d, 189 0x65, 0x86, 0x75, 0xfc, 0x6e, 0xa5, 0x34, 0xe0, 0x81, 0x0a, 0x44, 0x32, 0x82, 0x6b, 0xf5, 0x8c, 190 0x94, 0x1e, 0xfb, 0x65, 0xd5, 0x7a, 0x33, 0x8b, 0xbd, 0x2e, 0x26, 0x64, 0x0f, 0x89, 0xff, 0xbc, 191 0x1a, 0x85, 0x8e, 0xfc, 0xb8, 0x55, 0x0e, 0xe3, 0xa5, 0xe1, 0x99, 0x8b, 0xd1, 0x77, 0xe9, 0x3a, 192 0x73, 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 237 0xb9, 0x32, 0x46, 0xf6, 0xb1, 0x11, 0x63, 0x98, 0xa3, 0x46, 0xf1, 0xa6, 0x41, 0xf3, 0xb0, 0x41, 238 0xe9, 0x89, 0xf7, 0x91, 0x4f, 0x90, 0xcc, 0x2c, 0x7f, 0xff, 0x35, 0x78, 0x76, 0xe5, 0x06, 0xb5, 239 0x0d, 0x33, 0x4b, 0xa7, 0x7c, 0x22, 0x5b, 0xc3, 0x07, 0xba, 0x53, 0x71, 0x52, 0xf3, 0xf1, 0x61, 240 0x0e, 0x4e, 0xaf, 0xe5, 0x95, 0xf6, 0xd9, 0xd9, 0x0d, 0x11, 0xfa, 0xa9, 0x33, 0xa1, 0x5e, 0xf1, 241 0x36, 0x95, 0x46, 0x86, 0x8a, 0x7f, 0x3a, 0x45, 0xa9, 0x67, 0x68, 0xd4, 0x0f, 0xd9, 0xd0, 0x34, 242 0x12, 0xc0, 0x91, 0xc6, 0x31, 0x5c, 0xf4, 0xfd, 0xe7, 0xcb, 0x68, 0x60, 0x69, 0x37, 0x38, 0x0d, 243 0xb2, 0xea, 0xaa, 0x70, 0x7b, 0x4c, 0x41, 0x85, 0xc3, 0x2e, 0xdd, 0xcd, 0xd3, 0x06, 0x70, 0x5e, 244 0x4d, 0xc1, 0xff, 0xc8, 0x72, 0xee, 0xee, 0x47, 0x5a, 0x64, 0xdf, 0xac, 0x86, 0xab, 0xa4, 0x1c, 245 0x06, 0x18, 0x98, 0x3f, 0x87, 0x41, 0xc5, 0xef, 0x68, 0xd3, 0xa1, 0x01, 0xe8, 0xa3, 0xb8, 0xca, 246 0xc6, 0x0c, 0x90, 0x5c, 0x15, 0xfc, 0x91, 0x08, 0x40, 0xb9, 0x4c, 0x00, 0xa0, 0xb9, 0xd0, 247 }, 248 msgLen: 1023, 249 sig: []byte{ 250 0x0a, 0xab, 0x4c, 0x90, 0x05, 0x01, 0xb3, 0xe2, 0x4d, 0x7c, 0xdf, 0x46, 0x63, 0x32, 0x6a, 0x3a, 251 0x87, 0xdf, 0x5e, 0x48, 0x43, 0xb2, 0xcb, 0xdb, 0x67, 0xcb, 0xf6, 0xe4, 0x60, 0xfe, 0xc3, 0x50, 252 0xaa, 0x53, 0x71, 0xb1, 0x50, 0x8f, 0x9f, 0x45, 0x28, 0xec, 0xea, 0x23, 0xc4, 0x36, 0xd9, 0x4b, 253 0x5e, 0x8f, 0xcd, 0x4f, 0x68, 0x1e, 0x30, 0xa6, 0xac, 0x00, 0xa9, 0x70, 0x4a, 0x18, 0x8a, 0x03, 254 }, 255 ph: false, 256 ctx: []byte{}, 257 ctxLen: 0, 258 }, 259 { 260 name: "-----TEST sha(abc)", 261 scheme: "Ed25519Pure", 262 sk: []byte{ 263 0x83, 0x3f, 0xe6, 0x24, 0x09, 0x23, 0x7b, 0x9d, 0x62, 0xec, 0x77, 0x58, 0x75, 0x20, 0x91, 0x1e, 264 0x9a, 0x75, 0x9c, 0xec, 0x1d, 0x19, 0x75, 0x5b, 0x7d, 0xa9, 0x01, 0xb9, 0x6d, 0xca, 0x3d, 0x42, 265 }, 266 pk: []byte{ 267 0xec, 0x17, 0x2b, 0x93, 0xad, 0x5e, 0x56, 0x3b, 0xf4, 0x93, 0x2c, 0x70, 0xe1, 0x24, 0x50, 0x34, 268 0xc3, 0x54, 0x67, 0xef, 0x2e, 0xfd, 0x4d, 0x64, 0xeb, 0xf8, 0x19, 0x68, 0x34, 0x67, 0xe2, 0xbf, 269 }, 270 msg: []byte{ 271 0xdd, 0xaf, 0x35, 0xa1, 0x93, 0x61, 0x7a, 0xba, 0xcc, 0x41, 0x73, 0x49, 0xae, 0x20, 0x41, 0x31, 272 0x12, 0xe6, 0xfa, 0x4e, 0x89, 0xa9, 0x7e, 0xa2, 0x0a, 0x9e, 0xee, 0xe6, 0x4b, 0x55, 0xd3, 0x9a, 273 0x21, 0x92, 0x99, 0x2a, 0x27, 0x4f, 0xc1, 0xa8, 0x36, 0xba, 0x3c, 0x23, 0xa3, 0xfe, 0xeb, 0xbd, 274 0x45, 0x4d, 0x44, 0x23, 0x64, 0x3c, 0xe8, 0x0e, 0x2a, 0x9a, 0xc9, 0x4f, 0xa5, 0x4c, 0xa4, 0x9f, 275 }, 276 msgLen: 64, 277 sig: []byte{ 278 0xdc, 0x2a, 0x44, 0x59, 0xe7, 0x36, 0x96, 0x33, 0xa5, 0x2b, 0x1b, 0xf2, 0x77, 0x83, 0x9a, 0x00, 279 0x20, 0x10, 0x09, 0xa3, 0xef, 0xbf, 0x3e, 0xcb, 0x69, 0xbe, 0xa2, 0x18, 0x6c, 0x26, 0xb5, 0x89, 280 0x09, 0x35, 0x1f, 0xc9, 0xac, 0x90, 0xb3, 0xec, 0xfd, 0xfb, 0xc7, 0xc6, 0x64, 0x31, 0xe0, 0x30, 281 0x3d, 0xca, 0x17, 0x9c, 0x13, 0x8a, 0xc1, 0x7a, 0xd9, 0xbe, 0xf1, 0x17, 0x73, 0x31, 0xa7, 0x04, 282 }, 283 ph: false, 284 ctx: []byte{}, 285 ctxLen: 0, 286 }, 287 { 288 name: "-----TEST abc", 289 scheme: "Ed25519Ph", 290 sk: []byte{ 291 0x83, 0x3f, 0xe6, 0x24, 0x09, 0x23, 0x7b, 0x9d, 0x62, 0xec, 0x77, 0x58, 0x75, 0x20, 0x91, 0x1e, 292 0x9a, 0x75, 0x9c, 0xec, 0x1d, 0x19, 0x75, 0x5b, 0x7d, 0xa9, 0x01, 0xb9, 0x6d, 0xca, 0x3d, 0x42, 293 }, 294 pk: []byte{ 295 0xec, 0x17, 0x2b, 0x93, 0xad, 0x5e, 0x56, 0x3b, 0xf4, 0x93, 0x2c, 0x70, 0xe1, 0x24, 0x50, 0x34, 296 0xc3, 0x54, 0x67, 0xef, 0x2e, 0xfd, 0x4d, 0x64, 0xeb, 0xf8, 0x19, 0x68, 0x34, 0x67, 0xe2, 0xbf, 297 }, 298 msg: []byte{ 299 0x61, 0x62, 0x63, 300 }, 301 msgLen: 3, 302 sig: []byte{ 303 0x98, 0xa7, 0x02, 0x22, 0xf0, 0xb8, 0x12, 0x1a, 0xa9, 0xd3, 0x0f, 0x81, 0x3d, 0x68, 0x3f, 0x80, 304 0x9e, 0x46, 0x2b, 0x46, 0x9c, 0x7f, 0xf8, 0x76, 0x39, 0x49, 0x9b, 0xb9, 0x4e, 0x6d, 0xae, 0x41, 305 0x31, 0xf8, 0x50, 0x42, 0x46, 0x3c, 0x2a, 0x35, 0x5a, 0x20, 0x03, 0xd0, 0x62, 0xad, 0xf5, 0xaa, 306 0xa1, 0x0b, 0x8c, 0x61, 0xe6, 0x36, 0x06, 0x2a, 0xaa, 0xd1, 0x1c, 0x2a, 0x26, 0x08, 0x34, 0x06, 307 }, 308 ph: true, 309 ctx: []byte{}, 310 ctxLen: 0, 311 }, 312 { 313 name: "-----foo", 314 scheme: "Ed25519Ctx", 315 sk: []byte{ 316 0x03, 0x05, 0x33, 0x4e, 0x38, 0x1a, 0xf7, 0x8f, 0x14, 0x1c, 0xb6, 0x66, 0xf6, 0x19, 0x9f, 0x57, 317 0xbc, 0x34, 0x95, 0x33, 0x5a, 0x25, 0x6a, 0x95, 0xbd, 0x2a, 0x55, 0xbf, 0x54, 0x66, 0x63, 0xf6, 318 }, 319 pk: []byte{ 320 0xdf, 0xc9, 0x42, 0x5e, 0x4f, 0x96, 0x8f, 0x7f, 0x0c, 0x29, 0xf0, 0x25, 0x9c, 0xf5, 0xf9, 0xae, 321 0xd6, 0x85, 0x1c, 0x2b, 0xb4, 0xad, 0x8b, 0xfb, 0x86, 0x0c, 0xfe, 0xe0, 0xab, 0x24, 0x82, 0x92, 322 }, 323 msg: []byte{ 324 0xf7, 0x26, 0x93, 0x6d, 0x19, 0xc8, 0x00, 0x49, 0x4e, 0x3f, 0xda, 0xff, 0x20, 0xb2, 0x76, 0xa8, 325 }, 326 msgLen: 16, 327 sig: []byte{ 328 0x55, 0xa4, 0xcc, 0x2f, 0x70, 0xa5, 0x4e, 0x04, 0x28, 0x8c, 0x5f, 0x4c, 0xd1, 0xe4, 0x5a, 0x7b, 329 0xb5, 0x20, 0xb3, 0x62, 0x92, 0x91, 0x18, 0x76, 0xca, 0xda, 0x73, 0x23, 0x19, 0x8d, 0xd8, 0x7a, 330 0x8b, 0x36, 0x95, 0x0b, 0x95, 0x13, 0x00, 0x22, 0x90, 0x7a, 0x7f, 0xb7, 0xc4, 0xe9, 0xb2, 0xd5, 331 0xf6, 0xcc, 0xa6, 0x85, 0xa5, 0x87, 0xb4, 0xb2, 0x1f, 0x4b, 0x88, 0x8e, 0x4e, 0x7e, 0xdb, 0x0d, 332 }, 333 ph: false, 334 ctx: []byte{ 335 0x66, 0x6f, 0x6f, 336 }, 337 ctxLen: 3, 338 }, 339 { 340 name: "-----bar", 341 scheme: "Ed25519Ctx", 342 sk: []byte{ 343 0x03, 0x05, 0x33, 0x4e, 0x38, 0x1a, 0xf7, 0x8f, 0x14, 0x1c, 0xb6, 0x66, 0xf6, 0x19, 0x9f, 0x57, 344 0xbc, 0x34, 0x95, 0x33, 0x5a, 0x25, 0x6a, 0x95, 0xbd, 0x2a, 0x55, 0xbf, 0x54, 0x66, 0x63, 0xf6, 345 }, 346 pk: []byte{ 347 0xdf, 0xc9, 0x42, 0x5e, 0x4f, 0x96, 0x8f, 0x7f, 0x0c, 0x29, 0xf0, 0x25, 0x9c, 0xf5, 0xf9, 0xae, 348 0xd6, 0x85, 0x1c, 0x2b, 0xb4, 0xad, 0x8b, 0xfb, 0x86, 0x0c, 0xfe, 0xe0, 0xab, 0x24, 0x82, 0x92, 349 }, 350 msg: []byte{ 351 0xf7, 0x26, 0x93, 0x6d, 0x19, 0xc8, 0x00, 0x49, 0x4e, 0x3f, 0xda, 0xff, 0x20, 0xb2, 0x76, 0xa8, 352 }, 353 msgLen: 16, 354 sig: []byte{ 355 0xfc, 0x60, 0xd5, 0x87, 0x2f, 0xc4, 0x6b, 0x3a, 0xa6, 0x9f, 0x8b, 0x5b, 0x43, 0x51, 0xd5, 0x80, 356 0x8f, 0x92, 0xbc, 0xc0, 0x44, 0x60, 0x6d, 0xb0, 0x97, 0xab, 0xab, 0x6d, 0xbc, 0xb1, 0xae, 0xe3, 357 0x21, 0x6c, 0x48, 0xe8, 0xb3, 0xb6, 0x64, 0x31, 0xb5, 0xb1, 0x86, 0xd1, 0xd2, 0x8f, 0x8e, 0xe1, 358 0x5a, 0x5c, 0xa2, 0xdf, 0x66, 0x68, 0x34, 0x62, 0x91, 0xc2, 0x04, 0x3d, 0x4e, 0xb3, 0xe9, 0x0d, 359 }, 360 ph: false, 361 ctx: []byte{ 362 0x62, 0x61, 0x72, 363 }, 364 ctxLen: 3, 365 }, 366 { 367 name: "-----foo2", 368 scheme: "Ed25519Ctx", 369 sk: []byte{ 370 0x03, 0x05, 0x33, 0x4e, 0x38, 0x1a, 0xf7, 0x8f, 0x14, 0x1c, 0xb6, 0x66, 0xf6, 0x19, 0x9f, 0x57, 371 0xbc, 0x34, 0x95, 0x33, 0x5a, 0x25, 0x6a, 0x95, 0xbd, 0x2a, 0x55, 0xbf, 0x54, 0x66, 0x63, 0xf6, 372 }, 373 pk: []byte{ 374 0xdf, 0xc9, 0x42, 0x5e, 0x4f, 0x96, 0x8f, 0x7f, 0x0c, 0x29, 0xf0, 0x25, 0x9c, 0xf5, 0xf9, 0xae, 375 0xd6, 0x85, 0x1c, 0x2b, 0xb4, 0xad, 0x8b, 0xfb, 0x86, 0x0c, 0xfe, 0xe0, 0xab, 0x24, 0x82, 0x92, 376 }, 377 msg: []byte{ 378 0x50, 0x8e, 0x9e, 0x68, 0x82, 0xb9, 0x79, 0xfe, 0xa9, 0x00, 0xf6, 0x2a, 0xdc, 0xea, 0xca, 0x35, 379 }, 380 msgLen: 16, 381 sig: []byte{ 382 0x8b, 0x70, 0xc1, 0xcc, 0x83, 0x10, 0xe1, 0xde, 0x20, 0xac, 0x53, 0xce, 0x28, 0xae, 0x6e, 0x72, 383 0x07, 0xf3, 0x3c, 0x32, 0x95, 0xe0, 0x3b, 0xb5, 0xc0, 0x73, 0x2a, 0x1d, 0x20, 0xdc, 0x64, 0x90, 384 0x89, 0x22, 0xa8, 0xb0, 0x52, 0xcf, 0x99, 0xb7, 0xc4, 0xfe, 0x10, 0x7a, 0x5a, 0xbb, 0x5b, 0x2c, 385 0x40, 0x85, 0xae, 0x75, 0x89, 0x0d, 0x02, 0xdf, 0x26, 0x26, 0x9d, 0x89, 0x45, 0xf8, 0x4b, 0x0b, 386 }, 387 ph: false, 388 ctx: []byte{ 389 0x66, 0x6f, 0x6f, 390 }, 391 ctxLen: 3, 392 }, 393 { 394 name: "-----foo3", 395 scheme: "Ed25519Ctx", 396 sk: []byte{ 397 0xab, 0x9c, 0x28, 0x53, 0xce, 0x29, 0x7d, 0xda, 0xb8, 0x5c, 0x99, 0x3b, 0x3a, 0xe1, 0x4b, 0xca, 398 0xd3, 0x9b, 0x2c, 0x68, 0x2b, 0xea, 0xbc, 0x27, 0xd6, 0xd4, 0xeb, 0x20, 0x71, 0x1d, 0x65, 0x60, 399 }, 400 pk: []byte{ 401 0x0f, 0x1d, 0x12, 0x74, 0x94, 0x3b, 0x91, 0x41, 0x58, 0x89, 0x15, 0x2e, 0x89, 0x3d, 0x80, 0xe9, 402 0x32, 0x75, 0xa1, 0xfc, 0x0b, 0x65, 0xfd, 0x71, 0xb4, 0xb0, 0xdd, 0xa1, 0x0a, 0xd7, 0xd7, 0x72, 403 }, 404 msg: []byte{ 405 0xf7, 0x26, 0x93, 0x6d, 0x19, 0xc8, 0x00, 0x49, 0x4e, 0x3f, 0xda, 0xff, 0x20, 0xb2, 0x76, 0xa8, 406 }, 407 msgLen: 16, 408 sig: []byte{ 409 0x21, 0x65, 0x5b, 0x5f, 0x1a, 0xa9, 0x65, 0x99, 0x6b, 0x3f, 0x97, 0xb3, 0xc8, 0x49, 0xea, 0xfb, 410 0xa9, 0x22, 0xa0, 0xa6, 0x29, 0x92, 0xf7, 0x3b, 0x3d, 0x1b, 0x73, 0x10, 0x6a, 0x84, 0xad, 0x85, 411 0xe9, 0xb8, 0x6a, 0x7b, 0x60, 0x05, 0xea, 0x86, 0x83, 0x37, 0xff, 0x2d, 0x20, 0xa7, 0xf5, 0xfb, 412 0xd4, 0xcd, 0x10, 0xb0, 0xbe, 0x49, 0xa6, 0x8d, 0xa2, 0xb2, 0xe0, 0xdc, 0x0a, 0xd8, 0x96, 0x0f, 413 }, 414 ph: false, 415 ctx: []byte{ 416 0x66, 0x6f, 0x6f, 417 }, 418 ctxLen: 3, 419 }, 420 } 421 422 func (v vector) isPure() bool { return v.scheme == "Ed25519Pure" } 423 func (v vector) isPreHashed() bool { return v.scheme == "Ed25519Ph" } 424 func (v vector) hasContext() bool { return v.scheme == "Ed25519Ctx" } 425 func (v vector) matchMsgLen() bool { return uint(len(v.msg)) == v.msgLen } 426 func (v vector) matchCtxLen() bool { return uint(len(v.ctx)) == v.ctxLen } 427 428 func (v vector) testPublicKey(t *testing.T) { 429 keys := ed25519.NewKeyFromSeed(v.sk) 430 got := keys.Public().(ed25519.PublicKey) 431 want := v.pk 432 433 if !bytes.Equal(got, want) { 434 test.ReportError(t, got, want, v.name) 435 } 436 } 437 438 func (v vector) testSign(t *testing.T) { 439 key := ed25519.NewKeyFromSeed(v.sk) 440 441 var got []byte 442 443 if v.ph { 444 got = ed25519.SignPh(key, v.msg, "") 445 } else if v.ctxLen > 0 { 446 got = ed25519.SignWithCtx(key, v.msg, string(v.ctx)) 447 } else { 448 got = ed25519.Sign(key, v.msg) 449 } 450 451 want := v.sig 452 if !bytes.Equal(got, want) { 453 test.ReportError(t, got, want, v.name) 454 } 455 } 456 457 func (v vector) testVerify(t *testing.T) { 458 var got bool 459 if v.ph { 460 got = ed25519.VerifyPh(v.pk, v.msg, v.sig, "") 461 } else if v.ctxLen > 0 { 462 got = ed25519.VerifyWithCtx(v.pk, v.msg, v.sig, string(v.ctx)) 463 } else { 464 got = ed25519.Verify(v.pk, v.msg, v.sig) 465 } 466 467 want := true 468 469 if got != want { 470 test.ReportError(t, got, want, v.name) 471 } 472 } 473 474 func TestEd25519(t *testing.T) { 475 for _, v := range vectorsEd25519 { 476 got := (v.isPure() || v.isPreHashed() || v.hasContext()) && v.matchMsgLen() && v.matchCtxLen() 477 want := true 478 if got != want { 479 test.ReportError(t, got, want, v.sk) 480 } 481 482 v.testPublicKey(t) 483 v.testSign(t) 484 v.testVerify(t) 485 } 486 }