// ComputeRESStar computes RESStar from serving network name, RAND and RES
// as described in A.4 RES* and XRES* derivation function, TS 33.501.
//
// Note that this function should be called after all other calculations
// is done (to generate RAND and RES).
ComputeRESStar computes RESStar from serving network name, RAND and RES
as described in A.4 RES* and XRES* derivation function, TS 33.501.

Note that this function should be called after all other calculations
is done (to generate RAND and RES).
// ComputeRESStar computes RESStar from serving network name RAND and RES // as described in A . 4 RES * and XRES * derivation function TS 33 . 501 . // // Note that this function should be called after all other calculations // is done ( to generate RAND and RES ) .
func (m *Milenage) ComputeRESStar(mcc, mnc string) ([]byte, error) {
	if err := m.validateLength(); err != nil {
		return nil, err
	}
	if len(mcc) != 3 {
		return nil, fmt.Errorf("invalid MCC: %s", mcc)
	}
	if l := len(mnc); l == 2 {
		mnc = "0" + mnc
	} else if l != 3 {
		return nil, fmt.Errorf("invalid MNC: %s", mnc)
	}
	snn := []byte(fmt.Sprintf("5G:mnc%s.mcc%s.3gppnetwork.org", mnc, mcc))
	if l := len(snn); l != 32 {
		return nil, fmt.Errorf("failed to build SNN: %s", snn)
	}
	b := make([]byte, 63)
	b[0] = 0x6b
	copy(b[1:33], snn)
	binary.BigEndian.PutUint16(b[33:35], uint16(len(snn)))
	copy(b[35:51], m.RAND)
	binary.BigEndian.PutUint16(b[51:53], uint16(len(m.RAND)))
	copy(b[53:61], m.RES)
	binary.BigEndian.PutUint16(b[61:63], uint16(len(m.RES)))
	k := make([]byte, 32)
	copy(k[0:16], m.CK)
	copy(k[16:32], m.IK)
	mac := hmac.New(sha256.New, k)
	if _, err := mac.Write(b); err != nil {
		return nil, fmt.Errorf("failed to compute RES*: %w", err)
	}
	out := mac.Sum(nil)
	return out[len(out)-16:], nil
}
func ( m * Milenage ) ComputeRESStar ( mcc , mnc string ) ( [ ] byte , error ) { if err := m . validateLength ( ) ; err != nil { return nil , err } if len ( mcc ) != 3 { return nil , fmt . Errorf ( " " , mcc ) } if l := len ( mnc ) ; l == 2 { mnc = " " + mnc } else if l != 3 { return nil , fmt . Errorf ( " " , mnc ) } snn := [ ] byte ( fmt . Sprintf ( " " , mnc , mcc ) ) if l := len ( snn ) ; l != 32 { return nil , fmt . Errorf ( " " , snn ) } b := make ( [ ] byte , 63 ) b [ 0 ] = 0x6b copy ( b [ 1 : 33 ] , snn ) binary . BigEndian . PutUint16 ( b [ 33 : 35 ] , uint16 ( len ( snn ) ) ) copy ( b [ 35 : 51 ] , m . RAND ) binary . BigEndian . PutUint16 ( b [ 51 : 53 ] , uint16 ( len ( m . RAND ) ) ) copy ( b [ 53 : 61 ] , m . RES ) binary . BigEndian . PutUint16 ( b [ 61 : 63 ] , uint16 ( len ( m . RES ) ) ) k := make ( [ ] byte , 32 ) copy ( k [ 0 : 16 ] , m . CK ) copy ( k [ 16 : 32 ] , m . IK ) mac := hmac . New ( sha256 . New , k ) if _ , err := mac . Write ( b ) ; err != nil { return nil , fmt . Errorf ( " " , err ) } out := mac . Sum ( nil ) return out [ len ( out ) - 16 : ] , nil }
ComputeRESStar computes RESStar from serving network name, RAND and RES
as described in A.4 RES* and XRES* derivation function, TS 33.501.
ComputeRESStar computes RESStar from serving network name RAND and RES as described in A . 4 RES * and XRES * derivation function TS 33 . 501 .