diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index 4d9408f3863a8a842735f4dc98cc8ee3550e3dc7..e9ef2d695c4fdcb98c91e2af07e2aef56b975bcf 100644
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -18529,7 +18529,9 @@ static int build_reply_digest(struct sip_pvt *p, int method, char* digest, int d
 	} else {
 		/* No authentication, use peer or register= config */
 		username = p->authname;
-		secret =  p->peersecret;
+ 		secret = p->relatedpeer 
+			&& !ast_strlen_zero(p->relatedpeer->remotesecret)
+			? p->relatedpeer->remotesecret : p->peersecret;
 		md5secret = p->peermd5secret;
 	}
 	if (ast_strlen_zero(username))	/* We have no authentication */
diff --git a/configs/sip.conf.sample b/configs/sip.conf.sample
index 91276288227e795e016768e49ccc418fdf6fec50..92e41e4403ae54da8150c769acec7c1d5752006a 100644
--- a/configs/sip.conf.sample
+++ b/configs/sip.conf.sample
@@ -1014,6 +1014,10 @@ srvlookup=yes                   ; Enable DNS SRV lookups on outbound calls
 ;   Asterisk only matches on IP/port, not on names. This is mostly used for SIP
 ;   trunks.
 ;
+; Use remotesecret for outbound authentication, and secret for authenticating
+; inbound requests. For historical reasons, if no remotesecret is supplied for an
+; outbound registration or call, the secret will be used. 
+;
 ; For device names, we recommend using only a-z, numerics (0-9) and underscore
 ;
 ; For local phones, type=friend works most of the time