NTCP: fix IV functions

This commit is contained in:
eyedeekay
2024-11-20 16:02:14 -05:00
parent 5d789973b2
commit 4a6f49d14a
2 changed files with 9 additions and 6 deletions

View File

@ -290,12 +290,12 @@ func (router_address RouterAddress) StaticKey() ([32]byte, error) {
return [32]byte(sk), nil
}
func (router_address RouterAddress) InitializationVector() ([32]byte, error) {
func (router_address RouterAddress) InitializationVector() ([16]byte, error) {
iv := router_address.InitializationVectorString()
if len([]byte(iv)) != 32 {
return [32]byte{}, fmt.Errorf("error: invalid static key")
if len([]byte(iv)) != 16 {
return [16]byte{}, fmt.Errorf("error: invalid IV")
}
return [32]byte(iv), nil
return [16]byte(iv), nil
}
func (router_address RouterAddress) ProtocolVersion() (string, error) {

View File

@ -62,7 +62,7 @@ func (s *NTCP2Session) peerStaticKey() ([32]byte, error) {
return [32]byte{}, fmt.Errorf("Remote static key error")
}
func (s *NTCP2Session) peerStaticIV() ([32]byte, error) {
func (s *NTCP2Session) peerStaticIV() ([16]byte, error) {
for _, addr := range s.RouterInfo.RouterAddresses() {
transportStyle, err := addr.TransportStyle().Data()
if err != nil {
@ -72,7 +72,7 @@ func (s *NTCP2Session) peerStaticIV() ([32]byte, error) {
return addr.InitializationVector()
}
}
return [32]byte{}, fmt.Errorf("Remote static IV error")
return [16]byte{}, fmt.Errorf("Remote static IV error")
}
// ObfuscateEphemeral implements NTCP2's key obfuscation using AES-256-CBC
@ -82,6 +82,9 @@ func (s *NTCP2Session) ObfuscateEphemeral(ephemeralKey []byte) ([]byte, error) {
return nil, err
}
staticIV, err := s.peerStaticIV()
if err != nil {
return nil, err
}
var AESStaticKey *crypto.AESSymmetricKey
AESStaticKey.Key = static[:]
AESStaticKey.IV = staticIV[:]