aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOnur Gündüz <ogunduz@gmail.com>2026-03-11 11:20:38 +0100
committerOnur Gündüz <ogunduz@gmail.com>2026-03-11 11:20:38 +0100
commit6e37bc1f2755ef2e2270d2c1cb988d14ff6d0957 (patch)
tree286c7f2e78a229cc137da3aa91fb24e147535447
parent03b95111f19a93ccee00e8e8e0afaab8112f5484 (diff)
downloadnoise-6e37bc1f2755ef2e2270d2c1cb988d14ff6d0957.tar.gz
noise-6e37bc1f2755ef2e2270d2c1cb988d14ff6d0957.zip
Naming
-rw-r--r--README.md14
-rw-r--r--example_test.go6
-rw-r--r--noise.go26
-rw-r--r--noise_test.go38
-rw-r--r--symmetric_state.go4
5 files changed, 43 insertions, 45 deletions
diff --git a/README.md b/README.md
index e9775f1..9a78f5e 100644
--- a/README.md
+++ b/README.md
@@ -68,15 +68,15 @@ func main() {
if initiator.IsComplete() && responder.IsComplete() {
fmt.Println("Handshake complete!")
- // Get handshake hash (can be used for channel binding)
- hash := initiator.GetHash()
+ // Handshake hash (can be used for channel binding)
+ hash := initiator.Hash()
fmt.Printf("Handshake hash: %x\n", hash)
- // Get transport cipher states
- txInit := initiator.GetTX()
- rxInit := initiator.GetRX()
- txResp := responder.GetTX()
- rxResp := responder.GetRX()
+ // Transport cipher states
+ txInit := initiator.Tx()
+ rxInit := initiator.Rx()
+ txResp := responder.Tx()
+ rxResp := responder.Rx()
// Send encrypted messages
plaintext := []byte("Secret message")
diff --git a/example_test.go b/example_test.go
index 46a81b3..e0d52c4 100644
--- a/example_test.go
+++ b/example_test.go
@@ -54,8 +54,8 @@ func Example() {
// Use transport keys for encrypted communication
plaintext := []byte("Secret")
- ciphertext, _ := initiator.GetTX().Encrypt(nil, plaintext, nil)
- decrypted, _ := responder.GetRX().Decrypt(nil, ciphertext, nil)
+ ciphertext, _ := initiator.Tx().Encrypt(nil, plaintext, nil)
+ decrypted, _ := responder.Rx().Decrypt(nil, ciphertext, nil)
fmt.Printf("Transport message: %s\n", decrypted)
}
@@ -108,7 +108,7 @@ func Example_ik() {
false,
&nhs.Config{},
)
- responderPublicKey := responder.GetStaticPublicKey()
+ responderPublicKey := responder.StaticPublicKey()
// Initiator knows responder's key in advance
initiator, _ := nhs.NewNoiseState(
diff --git a/noise.go b/noise.go
index 4ed792d..cba3606 100644
--- a/noise.go
+++ b/noise.go
@@ -396,7 +396,7 @@ func (ns *NoiseState) Recv(message []byte) ([]byte, error) {
// final completes the handshake and derives transport keys.
func (ns *NoiseState) final() error {
- ns.hash = ns.getHandshakeHash()
+ ns.hash = ns.handshakeHash()
keys, err := ns.split()
if err != nil {
@@ -456,8 +456,8 @@ func (ns *NoiseState) IsComplete() bool {
return ns.complete
}
-// GetHash returns the handshake hash (only valid after completion).
-func (ns *NoiseState) GetHash() []byte {
+// Hash returns the handshake hash (only valid after completion).
+func (ns *NoiseState) Hash() []byte {
if ns.hash != nil {
result := make([]byte, len(ns.hash))
copy(result, ns.hash)
@@ -466,18 +466,18 @@ func (ns *NoiseState) GetHash() []byte {
return nil
}
-// GetTX returns the transmit cipher state (only valid after completion).
-func (ns *NoiseState) GetTX() *CipherState {
+// Tx returns the transmit cipher state (only valid after completion).
+func (ns *NoiseState) Tx() *CipherState {
return ns.tx
}
-// GetRX returns the receive cipher state (only valid after completion).
-func (ns *NoiseState) GetRX() *CipherState {
+// Rx returns the receive cipher state (only valid after completion).
+func (ns *NoiseState) Rx() *CipherState {
return ns.rx
}
-// GetStaticPublicKey returns the local static public key.
-func (ns *NoiseState) GetStaticPublicKey() []byte {
+// StaticPublicKey returns the local static public key.
+func (ns *NoiseState) StaticPublicKey() []byte {
if ns.s != nil {
key := make([]byte, len(ns.s.PublicKey))
copy(key, ns.s.PublicKey)
@@ -486,8 +486,8 @@ func (ns *NoiseState) GetStaticPublicKey() []byte {
return nil
}
-// GetRemoteStaticPublicKey returns a copy of the remote static public key (rs).
-func (ns *NoiseState) GetRemoteStaticPublicKey() []byte {
+// RemoteStaticPublicKey returns a copy of the remote static public key (rs).
+func (ns *NoiseState) RemoteStaticPublicKey() []byte {
if ns.rs == nil {
return nil
}
@@ -503,9 +503,7 @@ type keyPatternResult struct {
}
// getKeyPattern determines which keys to use based on token and role.
-func getKeyPattern(token Token, initiator bool) keyPatternResult {
- result := keyPatternResult{}
-
+func getKeyPattern(token Token, initiator bool) (result keyPatternResult) {
switch token {
case TokenEE:
// Both ephemeral
diff --git a/noise_test.go b/noise_test.go
index a0932ed..6fc5f5a 100644
--- a/noise_test.go
+++ b/noise_test.go
@@ -83,8 +83,8 @@ func TestBasicHandshakeXX(t *testing.T) {
}
// Verify handshake hashes match and are non-zero
- initHash := initiator.GetHash()
- respHash := responder.GetHash()
+ initHash := initiator.Hash()
+ respHash := responder.Hash()
if !bytes.Equal(initHash, respHash) {
t.Error("Handshake hashes do not match")
}
@@ -199,12 +199,12 @@ func TestTransportMessagesXX(t *testing.T) {
plaintext := []byte("Secret message")
// Initiator sends to responder
- ciphertext, err := initiator.GetTX().Encrypt(nil, plaintext, nil)
+ ciphertext, err := initiator.Tx().Encrypt(nil, plaintext, nil)
if err != nil {
t.Fatalf("Failed to encrypt: %v", err)
}
- decrypted, err := responder.GetRX().Decrypt(nil, ciphertext, nil)
+ decrypted, err := responder.Rx().Decrypt(nil, ciphertext, nil)
if err != nil {
t.Fatalf("Failed to decrypt: %v", err)
}
@@ -215,12 +215,12 @@ func TestTransportMessagesXX(t *testing.T) {
// Responder sends to initiator
plaintext2 := []byte("Secret reply")
- ciphertext2, err := responder.GetTX().Encrypt(nil, plaintext2, nil)
+ ciphertext2, err := responder.Tx().Encrypt(nil, plaintext2, nil)
if err != nil {
t.Fatalf("Failed to encrypt reply: %v", err)
}
- decrypted2, err := initiator.GetRX().Decrypt(nil, ciphertext2, nil)
+ decrypted2, err := initiator.Rx().Decrypt(nil, ciphertext2, nil)
if err != nil {
t.Fatalf("Failed to decrypt reply: %v", err)
}
@@ -310,10 +310,10 @@ func TestPSKHandshakeXXpsk0(t *testing.T) {
}
// Verify hashes match and are non-zero
- if !bytes.Equal(initiator.GetHash(), responder.GetHash()) {
+ if !bytes.Equal(initiator.Hash(), responder.Hash()) {
t.Error("PSK handshake hashes do not match")
}
- hash := initiator.GetHash()
+ hash := initiator.Hash()
allZero := true
for _, b := range hash {
if b != 0 {
@@ -332,7 +332,7 @@ func TestIKPattern(t *testing.T) {
if err != nil {
t.Fatalf("Failed to create responder: %v", err)
}
- responderStaticPub := responder.GetStaticPublicKey()
+ responderStaticPub := responder.StaticPublicKey()
// Initiator knows responder's static public key
initiator, err := nhs.NewNoiseState(nhs.PatternIK, true, &nhs.Config{})
@@ -380,7 +380,7 @@ func TestXKPattern(t *testing.T) {
if err != nil {
t.Fatalf("Failed to create responder: %v", err)
}
- responderStaticPub := responder.GetStaticPublicKey()
+ responderStaticPub := responder.StaticPublicKey()
initiator, err := nhs.NewNoiseState(nhs.PatternXK, true, &nhs.Config{})
if err != nil {
@@ -425,17 +425,17 @@ func TestXKPattern(t *testing.T) {
}
// Both sides should arrive at the same hash
- if !bytes.Equal(initiator.GetHash(), responder.GetHash()) {
+ if !bytes.Equal(initiator.Hash(), responder.Hash()) {
t.Error("XK handshake hashes do not match")
}
// Transport: initiator -> responder and back
plain := []byte("XK transport test")
- ct, err := initiator.GetTX().Encrypt(nil, plain, nil)
+ ct, err := initiator.Tx().Encrypt(nil, plain, nil)
if err != nil {
t.Fatalf("Failed to encrypt: %v", err)
}
- got, err := responder.GetRX().Decrypt(nil, ct, nil)
+ got, err := responder.Rx().Decrypt(nil, ct, nil)
if err != nil {
t.Fatalf("Failed to decrypt: %v", err)
}
@@ -483,12 +483,12 @@ func TestNNpsk0Pattern(t *testing.T) {
if !initiator.IsComplete() || !responder.IsComplete() {
t.Error("NNpsk0 handshake not complete")
}
- if !bytes.Equal(initiator.GetHash(), responder.GetHash()) {
+ if !bytes.Equal(initiator.Hash(), responder.Hash()) {
t.Error("NNpsk0 handshake hashes do not match")
}
}
-func TestGetRemoteStaticPublicKey(t *testing.T) {
+func TestRemoteStaticPublicKey(t *testing.T) {
// After an XX handshake, each side should know the other's static public key
initiator, err := nhs.NewNoiseState(nhs.PatternXX, true, &nhs.Config{})
if err != nil {
@@ -499,8 +499,8 @@ func TestGetRemoteStaticPublicKey(t *testing.T) {
t.Fatalf("Failed to create responder: %v", err)
}
- initStaticPub := initiator.GetStaticPublicKey()
- respStaticPub := responder.GetStaticPublicKey()
+ initStaticPub := initiator.StaticPublicKey()
+ respStaticPub := responder.StaticPublicKey()
prologue := []byte("remote-static-test")
initiator.Initialize(prologue, nil)
@@ -514,11 +514,11 @@ func TestGetRemoteStaticPublicKey(t *testing.T) {
responder.Recv(msg3)
// Initiator should have learned responder's static key
- if !bytes.Equal(initiator.GetRemoteStaticPublicKey(), respStaticPub) {
+ if !bytes.Equal(initiator.RemoteStaticPublicKey(), respStaticPub) {
t.Error("Initiator has wrong remote static public key")
}
// Responder should have learned initiator's static key
- if !bytes.Equal(responder.GetRemoteStaticPublicKey(), initStaticPub) {
+ if !bytes.Equal(responder.RemoteStaticPublicKey(), initStaticPub) {
t.Error("Responder has wrong remote static public key")
}
}
diff --git a/symmetric_state.go b/symmetric_state.go
index 4ecbfa7..13ac4cc 100644
--- a/symmetric_state.go
+++ b/symmetric_state.go
@@ -97,8 +97,8 @@ func (ss *symmetricState) decryptAndHash(ciphertext []byte) ([]byte, error) {
return plaintext, nil
}
-// getHandshakeHash returns the current handshake hash.
-func (ss *symmetricState) getHandshakeHash() []byte {
+// handshakeHash returns the current handshake hash.
+func (ss *symmetricState) handshakeHash() []byte {
hash := make([]byte, hashLen)
copy(hash, ss.digest)
return hash