MCC Expt 6 GSM A5 - A8

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Department of Computer Engineering Exp. No.

Semester B.E. Semester VII – Computer Engineering


Subject Mobile Application Development Technology Lab
Subject Professor In-charge
Assisting Teachers
Laboratory M314A

Student Name
Roll Number 17102A0057
Grade and Subject
Teacher’s Signature

Experiment Number 6

Experiment Title Implementation of generation of Authentication Key and Encryption in


GSM using A8 & A5 Algorithm
Resources Required Hardware: Programming Language :
Computer system Python/Java/C/C++
Theory GSM offers several security services using confidential information
stored in the AuC and in the individual SIM (which is plugged into an
arbitrary MS). The SIM stores personal, secret data and is protected
with a PIN against unauthorized use. (For example, the secret key Ki
used for authentication and encryption procedures is stored in the
SIM.) The security services offered by GSM are explained below:

● Access control and authentication: The first step includes the


authentication of a valid user for the SIM. The user needs a secret PIN
to access the SIM. The next step is the subscriber authentication. This
step is based on a challenge-response scheme as presented in section

● Confidentiality: All user-related data is encrypted. After


authentication, BTS and MS apply encryption to voice, data, and
signaling. This confidentiality exists only between MS and BTS, but it
does not exist end-to-end or within the whole fixed GSM/telephone
network.

● Anonymity: To provide user anonymity, all data is encrypted before


transmission, and user identifiers (which would reveal an identity) are
not used over the air. Instead, GSM transmits a temporary identifier
Department of Computer Engineering Exp. No.6
(TMSI), which is newly assigned by the VLR after each location
update. Additionally, the VLR can change the TMSI at any time.

Encryption:

To ensure privacy, all messages containing user-related information are


encrypted in GSM over the air interface. After authentication, MS and
BSS can start using encryption by applying the cipher key Kc (the
precise location of security functions for encryption, BTS and/or BSC
are vendor dependent). Kc is generated using the individual key Ki and
a random value by applying the algorithm A8. Note that the SIM in the
MS and the network both calculate the same Kc based on the random
value RAND. The key Kc itself is not transmitted over the air
interface. MS and BTS can now encrypt and decrypt data using the
algorithm A5 and the cipher key Kc. As shown in Figure, Kc should be
a 64 bit key – which is not very strong, but is at least a good protection
against simple eavesdropping. However, the publication of A3 and A8
on the internet showed that in certain implementations 10 of the 64 bits
are always set to 0, so that the real length of the key is thus only 54
consequently, the encryption is much weaker.

A8 - Key generation:
Department of Computer Engineering Exp. No.6
The key generation algorithm A8 is very similar to A3. In fact the same
COMP128 algorithm is used to create the 64-bit ciphering key (Kc)
which is subsequently used in A5. Taking the 128-bit RAND received
from the Mobile Services Switching Center (MSC) and the 128-bit Ki
stored in the SIM as input, A8 calculates 128 bits of output.

A5 – Encryption:

To protect privacy all over-the-air transmissions on a GSM network are


encrypted with a stream cipher known as A5. Though the A5
algorithm is described in the specifications of GSM it has never been
made public officially. Companies implementing GSM networks have to
buy the GSM specifications from ETSI. A5 is a stream cipher4. It
operates on 228-bit blocks called ”frames“ sent and received over the air
every 4.6 milliseconds. 114 bits represent data sent from the MSE and
the
other 114 bits are data received by the MSE, both mainly containing
digitized audio signals. Taking the session key Kc produced by A8 and a
frame counter5 Fn, A5 generates 228 pseudo random bits (PRAND)
which are XOR’ed with the plaintext frame resulting in 228 bits of
ciphertext. A schema of this data flow is shown in figure

Program:
import random

def A5(rand, K):


left_rand = rand[:64]
right_rand = rand[64:]
Department of Computer Engineering Exp. No.6
left_k = K[:64]
right_k = K[64:]

lhs_xor = []
rhs_xor = []

for i in range(64):
lhs_xor.append(left_rand[i] ^ right_k[i])
rhs_xor.append(right_rand[i] ^ left_k[i])

result = []
for i in range(64):
result.append(lhs_xor[i] ^ rhs_xor[i])

result = [str(x) for x in result]

return int("".join(result), 2)

def A5_test():
print("\nTesting A5 Algorithm")

global stored_Ki
global rand

data = [int(x) for x in list(bin(int(input("Enter data to


encrypt: ")))[2:])]
data = (64 - len(data)) * [0] + data
int_data = int("".join([str(x) for x in data]), 2)

Kc = A5(rand, stored_Ki)

print("Key:", int("".join([str(x) for x in stored_Ki]), 2))


print("Kc:", Kc)

encrypted_data = Kc ^ int_data
print("Encrypted Data:", encrypted_data)

decrypted_data = encrypted_data ^ Kc
print("Decrypted Data:", decrypted_data)

stored_Ki = 128
stored_Ki = [int(x) for x in list(bin(stored_Ki)[2:])]
stored_Ki = (128 - len(stored_Ki)) * [0] + stored_Ki

rand = []
for i in range(128):
rand.append(random.choice([0, 1]))

A5_test()
Department of Computer Engineering Exp. No.6

Output

Conclusion Implementation of A8 Key generation and Encryption algorithm using


A5 for GSM architecture is successfully completed.

You might also like