MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / EncryptJoinAccept

Function EncryptJoinAccept

pkg/crypto/join_messages.go:31–44  ·  view source on GitHub ↗

EncryptJoinAccept uses AES Decrypt to encrypt a join-accept message - The payload contains JoinNonce/AppNonce | NetID | DevAddr | DLSettings | RxDelay | (CFList | CFListType) | MIC - In LoRaWAN 1.0, the AppKey is used - In LoRaWAN 1.1, the NwkKey is used in reply to a JoinRequest - In LoRaWAN 1.1, t

(key types.AES128Key, payload []byte)

Source from the content-addressed store, hash-verified

29// - In LoRaWAN 1.1, the NwkKey is used in reply to a JoinRequest
30// - In LoRaWAN 1.1, the JSEncKey is used in reply to a RejoinRequest (type 0,1,2)
31func EncryptJoinAccept(key types.AES128Key, payload []byte) ([]byte, error) {
32 if len(payload) != 16 && len(payload) != 32 {
33 return nil, errInvalidJoinAcceptMessageSize.WithAttributes("size", len(payload))
34 }
35 cipher, err := aes.NewCipher(key[:])
36 if err != nil {
37 return nil, err
38 }
39 encrypted := make([]byte, len(payload))
40 for i := 0; i < len(encrypted); i += 16 {
41 cipher.Decrypt(encrypted[i:i+16], payload[i:i+16])
42 }
43 return encrypted, nil
44}
45
46// DecryptJoinAccept uses AES Encrypt to decrypt a join-accept message
47// - The returned payload contains JoinNonce/AppNonce | NetID | DevAddr | DLSettings | RxDelay | (CFList | CFListType) | MIC

Callers 4

EncryptJoinAcceptMethod · 0.92
EncryptRejoinAcceptMethod · 0.92
mustEncryptJoinAcceptFunction · 0.92
TestJoinAcceptEncryptionFunction · 0.85

Calls 2

DecryptMethod · 0.65
WithAttributesMethod · 0.45

Tested by 2

mustEncryptJoinAcceptFunction · 0.74
TestJoinAcceptEncryptionFunction · 0.68