Archived
1
0

omg public key derivation works, signing still suck

This commit is contained in:
Jeff Becker 2017-08-26 11:47:40 -04:00
parent 4ede62a667
commit f2d854d88f
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05
7 changed files with 3263 additions and 10 deletions

View File

@ -9,6 +9,30 @@ import (
"testing" "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) { func TestVerify(t *testing.T) {
d := filepath.Join("testdata", "article.test.txt") d := filepath.Join("testdata", "article.test.txt")

View File

@ -4,7 +4,7 @@ package srnd
import ( import (
"crypto/sha512" "crypto/sha512"
"golang.org/x/crypto/curve25519" "edwards25519"
"golang.org/x/crypto/ed25519" "golang.org/x/crypto/ed25519"
) )
@ -21,16 +21,14 @@ func naclCryptoSignFucky(hash, sk []byte) []byte {
} }
func naclSeedToKeyPair(seed []byte) (pk, sk []byte) { func naclSeedToKeyPair(seed []byte) (pk, sk []byte) {
h := sha512.Sum512(seed)
h := sha512.Sum512(seed[0:32])
sk = h[:] sk = h[:]
sk[0] &= 248 sk[0] &= 248
sk[31] &= 127 sk[31] &= 63
sk[31] |= 64 sk[31] |= 64
// scalarmult magick shit // scalarmult magick shit
pk = scalarBaseMult(sk) pk = scalarBaseMult(sk[0:32])
copy(sk[0:32], seed[0:32])
copy(sk[32:64], pk[0:32]) copy(sk[32:64], pk[0:32])
return return
@ -39,8 +37,10 @@ func naclSeedToKeyPair(seed []byte) (pk, sk []byte) {
func scalarBaseMult(sk []byte) (pk []byte) { func scalarBaseMult(sk []byte) (pk []byte) {
var skey [32]byte var skey [32]byte
var pkey [32]byte var pkey [32]byte
copy(skey[0:32], sk[0:32]) copy(skey[:], sk[0:32])
curve25519.ScalarBaseMult(&pkey, &skey) var h edwards25519.ExtendedGroupElement
pk = pkey[0:32] edwards25519.GeScalarMultBase(&h, &skey)
h.ToBytes(&pkey)
pk = pkey[:]
return return
} }

View 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__"],
)

View 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.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1 @@
cloned from https://github.com/kevinburke/nacl/commit/38707d146a0b97e13e5de807a3ad62a933f7668c