Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
number571 committed Aug 7, 2024
1 parent 2316ab9 commit d4cab1e
Show file tree
Hide file tree
Showing 7 changed files with 5,428 additions and 5,424 deletions.
4,640 changes: 2,320 additions & 2,320 deletions cmd/hidden_lake/_test/result/coverage.out

Large diffs are not rendered by default.

20 changes: 12 additions & 8 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import (
"github.com/number571/go-peer/pkg/payload/joiner"
)

const (
cSaltSize = 32 // bytes
)

var (
_ IClient = &sClient{}
)
Expand Down Expand Up @@ -92,9 +96,9 @@ func (p *sClient) encryptWithParams(
pPadd uint64,
) ([]byte, error) {
var (
rand = random.NewCSPRNG()
salt = rand.GetBytes(symmetric.CAESKeySize)
session = rand.GetBytes(symmetric.CAESKeySize)
rand = random.NewCSPRNG()
salt = rand.GetBytes(cSaltSize)
skey = rand.GetBytes(symmetric.CAESKeySize)
)

data := joiner.NewBytesJoiner32([][]byte{pMsg, rand.GetBytes(pPadd)})
Expand All @@ -107,12 +111,12 @@ func (p *sClient) encryptWithParams(
[]byte{},
)).ToBytes()

encKey := pRecv.EncryptBytes(session)
encKey := pRecv.EncryptBytes(skey)
if encKey == nil {
return nil, ErrEncryptSymmetricKey
}

cipher := symmetric.NewAESCipher(session)
cipher := symmetric.NewAESCipher(skey)
return message.NewMessage(
encKey,
cipher.EncryptBytes(joiner.NewBytesJoiner32([][]byte{
Expand All @@ -134,13 +138,13 @@ func (p *sClient) DecryptMessage(pMsg []byte) (asymmetric.IPubKey, []byte, error
}

// Decrypt session key by private key of receiver.
session := p.fPrivKey.DecryptBytes(msg.GetEnck())
if session == nil {
skey := p.fPrivKey.DecryptBytes(msg.GetEnck())
if skey == nil {
return nil, nil, ErrDecryptCipherKey
}

// Decrypt data block by decrypted session key. Decode data block.
decJoiner := symmetric.NewAESCipher(session).DecryptBytes(msg.GetEncd())
decJoiner := symmetric.NewAESCipher(skey).DecryptBytes(msg.GetEncd())
decSlice, err := joiner.LoadBytesJoiner32(decJoiner)
if err != nil || len(decSlice) != 5 {
return nil, nil, ErrDecodeBytesJoiner
Expand Down
8 changes: 4 additions & 4 deletions pkg/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ func (p *sClient) tInvalidEncryptPayload1(pRecv asymmetric.IPubKey, pPld payload
func (p *sClient) tInvalidEncryptWithParams1(pRecv asymmetric.IPubKey, pPld payload.IPayload64, pPadd uint64) message.IMessage {
var (
rand = random.NewCSPRNG()
salt = rand.GetBytes(symmetric.CAESKeySize)
salt = rand.GetBytes(cSaltSize)
session = rand.GetBytes(symmetric.CAESKeySize)
)

Expand Down Expand Up @@ -433,7 +433,7 @@ func (p *sClient) tInvalidEncryptWithParams2(
) (message.IMessage, error) {
var (
rand = random.NewCSPRNG()
salt = rand.GetBytes(symmetric.CAESKeySize)
salt = rand.GetBytes(cSaltSize)
session = rand.GetBytes(symmetric.CAESKeySize)
)

Expand Down Expand Up @@ -501,7 +501,7 @@ func (p *sClient) tInvalidEncryptWithParams3(
) (message.IMessage, error) {
var (
rand = random.NewCSPRNG()
salt = rand.GetBytes(symmetric.CAESKeySize)
salt = rand.GetBytes(cSaltSize)
session = rand.GetBytes(symmetric.CAESKeySize)
)

Expand Down Expand Up @@ -563,7 +563,7 @@ func (p *sClient) tInvalidEncryptWithParams4(
) (message.IMessage, error) {
var (
rand = random.NewCSPRNG()
salt = rand.GetBytes(symmetric.CAESKeySize)
salt = rand.GetBytes(cSaltSize)
session = rand.GetBytes(symmetric.CAESKeySize)
)

Expand Down
8 changes: 4 additions & 4 deletions pkg/crypto/keybuilder/keybuilder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import (
"bytes"
"testing"

"github.com/number571/go-peer/pkg/crypto/symmetric"
"github.com/number571/go-peer/pkg/encoding"
testutils "github.com/number571/go-peer/test/utils"
)

const (
tcHash = "8d47725f8604cb2e8f1be5e0b49ef143ea62625dd37ea4ce5f24501a32591784"
tcKeySize = 32
tcHash = "8d47725f8604cb2e8f1be5e0b49ef143ea62625dd37ea4ce5f24501a32591784"
)

func TestKeyBuilder(t *testing.T) {
Expand All @@ -21,13 +21,13 @@ func TestKeyBuilder(t *testing.T) {
salt = []byte("it's a salt!")
)

hash := NewKeyBuilder(1<<testutils.TCWorkSize, salt).Build(pasw, symmetric.CAESKeySize)
hash := NewKeyBuilder(1<<testutils.TCWorkSize, salt).Build(pasw, tcKeySize)
if encoding.HexEncode(hash) != tcHash {
t.Error("hash is correct?")
return
}

if !bytes.Equal(hash, NewKeyBuilder(1<<testutils.TCWorkSize, salt).Build(pasw, symmetric.CAESKeySize)) {
if !bytes.Equal(hash, NewKeyBuilder(1<<testutils.TCWorkSize, salt).Build(pasw, tcKeySize)) {
t.Error("hash is not determined")
return
}
Expand Down
2 changes: 1 addition & 1 deletion test/result/badge_codelines.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit d4cab1e

Please sign in to comment.