omg public key derivation works, signing still suck
This commit is contained in:
parent
4ede62a667
commit
f2d854d88f
@ -9,6 +9,30 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
const asdKey = "3c7850617b4fe116c98f4ed4a2eaf00ab219d16dd6351d9ee786f9fc710bad55"
|
||||
|
||||
func TestSeedToKeypair(t *testing.T) {
|
||||
seed := parseTripcodeSecret("asd")
|
||||
pk, _ := naclSeedToKeyPair(seed)
|
||||
hexpk := hexify(pk)
|
||||
if hexpk != asdKey {
|
||||
t.Logf("%s != %s", asdKey, hexpk)
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
||||
func TestSign(t *testing.T) {
|
||||
|
||||
msgid := "<wut@wut.wut>"
|
||||
seed := randbytes(32)
|
||||
pk, sec := naclSeedToKeyPair(seed)
|
||||
sig := msgidFrontendSign(sec, msgid)
|
||||
t.Log(sig)
|
||||
if !verifyFrontendSig(hexify(pk), sig, msgid) {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
||||
func TestVerify(t *testing.T) {
|
||||
d := filepath.Join("testdata", "article.test.txt")
|
||||
|
||||
|
@ -4,7 +4,7 @@ package srnd
|
||||
|
||||
import (
|
||||
"crypto/sha512"
|
||||
"golang.org/x/crypto/curve25519"
|
||||
"edwards25519"
|
||||
"golang.org/x/crypto/ed25519"
|
||||
)
|
||||
|
||||
@ -21,16 +21,14 @@ func naclCryptoSignFucky(hash, sk []byte) []byte {
|
||||
}
|
||||
|
||||
func naclSeedToKeyPair(seed []byte) (pk, sk []byte) {
|
||||
h := sha512.Sum512(seed)
|
||||
|
||||
h := sha512.Sum512(seed[0:32])
|
||||
sk = h[:]
|
||||
sk[0] &= 248
|
||||
sk[31] &= 127
|
||||
sk[31] &= 63
|
||||
sk[31] |= 64
|
||||
|
||||
// scalarmult magick shit
|
||||
pk = scalarBaseMult(sk)
|
||||
|
||||
copy(sk[0:32], seed[0:32])
|
||||
pk = scalarBaseMult(sk[0:32])
|
||||
copy(sk[32:64], pk[0:32])
|
||||
|
||||
return
|
||||
@ -39,8 +37,10 @@ func naclSeedToKeyPair(seed []byte) (pk, sk []byte) {
|
||||
func scalarBaseMult(sk []byte) (pk []byte) {
|
||||
var skey [32]byte
|
||||
var pkey [32]byte
|
||||
copy(skey[0:32], sk[0:32])
|
||||
curve25519.ScalarBaseMult(&pkey, &skey)
|
||||
pk = pkey[0:32]
|
||||
copy(skey[:], sk[0:32])
|
||||
var h edwards25519.ExtendedGroupElement
|
||||
edwards25519.GeScalarMultBase(&h, &skey)
|
||||
h.ToBytes(&pkey)
|
||||
pk = pkey[:]
|
||||
return
|
||||
}
|
||||
|
10
contrib/backends/srndv2/src/srnd/vendor/edwards25519/BUILD.bazel
vendored
Normal file
10
contrib/backends/srndv2/src/srnd/vendor/edwards25519/BUILD.bazel
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [
|
||||
"const.go",
|
||||
"edwards25519.go",
|
||||
],
|
||||
visibility = ["//sign:__subpackages__"],
|
||||
)
|
27
contrib/backends/srndv2/src/srnd/vendor/edwards25519/LICENSE
vendored
Normal file
27
contrib/backends/srndv2/src/srnd/vendor/edwards25519/LICENSE
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
Copyright (c) 2017 The Go Authors. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following disclaimer
|
||||
in the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the name of Google Inc. nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
1422
contrib/backends/srndv2/src/srnd/vendor/edwards25519/const.go
vendored
Normal file
1422
contrib/backends/srndv2/src/srnd/vendor/edwards25519/const.go
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1769
contrib/backends/srndv2/src/srnd/vendor/edwards25519/edwards25519.go
vendored
Normal file
1769
contrib/backends/srndv2/src/srnd/vendor/edwards25519/edwards25519.go
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1
contrib/backends/srndv2/src/srnd/vendor/edwards25519/readme.txt
vendored
Normal file
1
contrib/backends/srndv2/src/srnd/vendor/edwards25519/readme.txt
vendored
Normal file
@ -0,0 +1 @@
|
||||
cloned from https://github.com/kevinburke/nacl/commit/38707d146a0b97e13e5de807a3ad62a933f7668c
|
Reference in New Issue
Block a user