diff --git a/pkg/README.md b/p256k1/README.md similarity index 100% rename from pkg/README.md rename to p256k1/README.md diff --git a/pkg/context.go b/p256k1/context.go similarity index 100% rename from pkg/context.go rename to p256k1/context.go diff --git a/pkg/ecmult.go b/p256k1/ecmult.go similarity index 100% rename from pkg/ecmult.go rename to p256k1/ecmult.go diff --git a/pkg/ecmult_test.go b/p256k1/ecmult_test.go similarity index 100% rename from pkg/ecmult_test.go rename to p256k1/ecmult_test.go diff --git a/pkg/field.go b/p256k1/field.go similarity index 100% rename from pkg/field.go rename to p256k1/field.go diff --git a/pkg/field_mul.go b/p256k1/field_mul.go similarity index 100% rename from pkg/field_mul.go rename to p256k1/field_mul.go diff --git a/pkg/go.mod b/p256k1/go.mod similarity index 100% rename from pkg/go.mod rename to p256k1/go.mod diff --git a/pkg/go.sum b/p256k1/go.sum similarity index 100% rename from pkg/go.sum rename to p256k1/go.sum diff --git a/pkg/group.go b/p256k1/group.go similarity index 100% rename from pkg/group.go rename to p256k1/group.go diff --git a/pkg/hash.go b/p256k1/hash.go similarity index 99% rename from pkg/hash.go rename to p256k1/hash.go index 7c053c6..ab90f2c 100644 --- a/pkg/hash.go +++ b/p256k1/hash.go @@ -2,6 +2,7 @@ package p256k1 import ( "hash" + "github.com/minio/sha256-simd" ) @@ -26,7 +27,7 @@ func (h *SHA256) Initialize() { func (h *SHA256) InitializeTagged(tag []byte) { // Compute SHA256(tag) tagHash := sha256.Sum256(tag) - + // Initialize with SHA256(tag) || SHA256(tag) h.hasher.Reset() h.hasher.Write(tagHash[:]) @@ -43,7 +44,7 @@ func (h *SHA256) Finalize(output []byte) { if len(output) != 32 { panic("SHA-256 output must be 32 bytes") } - + result := h.hasher.Sum(nil) copy(output, result[:]) } @@ -58,16 +59,16 @@ func TaggedSHA256(output []byte, tag []byte, msg []byte) { if len(output) != 32 { panic("output must be 32 bytes") } - + // Compute SHA256(tag) tagHash := sha256.Sum256(tag) - + // Compute SHA256(SHA256(tag) || SHA256(tag) || msg) hasher := sha256.New() hasher.Write(tagHash[:]) hasher.Write(tagHash[:]) hasher.Write(msg) - + result := hasher.Sum(nil) copy(output, result) } @@ -77,7 +78,7 @@ func SHA256Simple(output []byte, input []byte) { if len(output) != 32 { panic("output must be 32 bytes") } - + result := sha256.Sum256(input) copy(output, result[:]) } @@ -100,24 +101,24 @@ func (h *HMACSHA256) Initialize(key []byte) { for i := range h.v { h.v[i] = 0x01 } - + // Initialize K = 0x00 0x00 0x00 ... 0x00 for i := range h.k { h.k[i] = 0x00 } - + // K = HMAC_K(V || 0x00 || key) h.updateK(0x00, key) - + // V = HMAC_K(V) h.updateV() - + // K = HMAC_K(V || 0x01 || key) h.updateK(0x01, key) - + // V = HMAC_K(V) h.updateV() - + h.init = true } @@ -145,14 +146,14 @@ func (h *HMACSHA256) Generate(output []byte) { if !h.init { panic("HMAC not initialized") } - + outputLen := len(output) generated := 0 - + for generated < outputLen { // V = HMAC_K(V) h.updateV() - + // Copy V to output toCopy := 32 if generated+toCopy > outputLen { @@ -194,7 +195,7 @@ func NewHMACWithKey(key []byte) *HMAC { outer: NewSHA256(), keyLen: len(key), } - + // Prepare key var k [64]byte if len(key) > 64 { @@ -206,22 +207,22 @@ func NewHMACWithKey(key []byte) *HMAC { } else { copy(k[:], key) } - + // Create inner and outer keys var ikey, okey [64]byte for i := 0; i < 64; i++ { ikey[i] = k[i] ^ 0x36 okey[i] = k[i] ^ 0x5c } - + // Initialize inner hash with inner key h.inner.Initialize() h.inner.Write(ikey[:]) - + // Initialize outer hash with outer key h.outer.Initialize() h.outer.Write(okey[:]) - + return h } @@ -235,11 +236,11 @@ func (h *HMAC) Finalize(output []byte) { if len(output) != 32 { panic("HMAC output must be 32 bytes") } - + // Get inner hash result var innerResult [32]byte h.inner.Finalize(innerResult[:]) - + // Complete outer hash h.outer.Write(innerResult[:]) h.outer.Finalize(output) diff --git a/pkg/scalar.go b/p256k1/scalar.go similarity index 100% rename from pkg/scalar.go rename to p256k1/scalar.go diff --git a/pkg/secp256k1.go b/p256k1/secp256k1.go similarity index 100% rename from pkg/secp256k1.go rename to p256k1/secp256k1.go diff --git a/pkg/secp256k1_test.go b/p256k1/secp256k1_test.go similarity index 100% rename from pkg/secp256k1_test.go rename to p256k1/secp256k1_test.go diff --git a/pkg/util.go b/p256k1/util.go similarity index 100% rename from pkg/util.go rename to p256k1/util.go