package crypto

import (
	 // #nosec G505

	
)

// sha1a returns sha1_a value.
//
// sha1_a = SHA1 (msg_key + substr (auth_key, x, 32));
func ( []byte,  Key,  bin.Int128,  int) []byte {
	 := sha1.New() // #nosec G401

	_, _ = .Write([:])
	_, _ = .Write([ : +32])

	return .Sum()
}

// sha1b returns sha1_b value.
//
// sha1_b = SHA1 (substr (auth_key, 32+x, 16) + msg_key + substr (auth_key, 48+x, 16));
func ( []byte,  Key,  bin.Int128,  int) []byte {
	 := sha1.New() // #nosec G401

	_, _ = .Write([32+ : 32++16])
	_, _ = .Write([:])
	_, _ = .Write([48+ : 48++16])

	return .Sum()
}

// sha1c returns sha1_c value.
//
// sha1_c = SHA1 (substr (auth_key, 64+x, 32) + msg_key);
func ( []byte,  Key,  bin.Int128,  int) []byte {
	 := sha1.New() // #nosec G401

	_, _ = .Write([64+ : 64++32])
	_, _ = .Write([:])

	return .Sum()
}

// sha1d returns sha1_d value.
//
// sha1_d = SHA1 (msg_key + substr (auth_key, 96+x, 32));
func ( []byte,  Key,  bin.Int128,  int) []byte {
	 := sha1.New() // #nosec G401

	_, _ = .Write([:])
	_, _ = .Write([96+ : 96++32])

	return .Sum()
}

// OldKeys returns (aes_key, aes_iv) pair for AES-IGE.
//
// See https://core.telegram.org/mtproto/description_v1#defining-aes-key-and-initialization-vector
//
// Example:
//
//	key, iv := crypto.OldKeys(authKey, messageKey, crypto.Client)
//	cipher, err := aes.NewCipher(key[:])
//	if err != nil {
//		return nil, err
//	}
//	encryptor := ige.NewIGEEncrypter(cipher, iv[:])
//
// Warning: MTProto 1.0 is deprecated.
func ( Key,  bin.Int128,  Side) (,  bin.Int256) {
	 := getX()

	 := func(, ,  []byte) ( bin.Int256) {
		// aes_key = substr (sha1_a, 0, 8) + substr (sha1_b, 8, 12) + substr (sha1_c, 4, 12);
		 := copy([:], [:8])
		 += copy([:], [8:8+12])
		copy([:], [4:4+12])
		return 
	}
	 := func(, , ,  []byte) ( bin.Int256) {
		// aes_iv = substr(sha1_a, 8, 12) + substr(sha1_b, 0, 8) + substr(sha1_c, 16, 4) + substr(sha1_d, 0, 8);
		 := copy([:], [8:8+12])
		 += copy([:], [:8])
		 += copy([:], [16:16+4])
		copy([:], [:8])
		return 
	}

	 := make([]byte, sha1.Size*4)

	 := sha1a([0:0], , , )
	 := sha1b([sha1.Size:sha1.Size], , , )
	 := sha1c([2*sha1.Size:2*sha1.Size], , , )
	 := sha1d([3*sha1.Size:3*sha1.Size], , , )

	return (, , ), (, , , )
}