mirror of
https://github.com/go-i2p/go-i2p.git
synced 2025-07-17 13:54:33 -04:00
NTCP: fix IV functions
This commit is contained in:
@ -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) {
|
||||
|
@ -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[:]
|
||||
|
Reference in New Issue
Block a user