Tuesday, April 1, 2014

Verilog programs 03 : 8 bit unsigned carry look ahead adder



Verilog code for 8 bit unsigned carry look ahead adder is shown below.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//////////////////////////////////////////////////////////////////////////////////
// Website:         www.technoburst.net 
// Engineer:        Anil C S
// Create Date:     14:16:21 01/17/2014 
// Design Name:     Verilog basic modules development
// Module Name:     u8binary_carry_look_ahead_adder 
// Description:     8 bit unsigned carry look ahead adder module
// Dependencies:    none
//////////////////////////////////////////////////////////////////////////////////

`timescale 1ns/1ps

module u8binary_carry_look_ahead_adder (input [7:0] IN1,IN2, output [7:0] SUM, output CY,AC);

  wire [7:0] P,G,C;
  assign C[0] = 0;
  assign P = IN1^IN2;
  assign G = IN1&IN2;
  assign SUM = P^C;
  assign CY = C[7];
  assign AC = C[4];

generate
  genvar i;
  for (i=7;i>0;i=i-1)
    assign C[i] = G[i-1]|(P[i-1]&C[i-1]);
endgenerate

endmodule

Verilog code for 8 bit unsigned binary carry look ahead adder is shown below.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//////////////////////////////////////////////////////////////////////////////////
// Website:         www.technoburst.net 
// Engineer:        Anil C S
// Create Date:     14:16:21 01/17/2014 
// Design Name:     Verilog basic modules development
// Module Name:     u8binary_carry_look_ahead_adder_test 
// Description:     8 bit unsigned ripple carry adder module test bench
// Dependencies:    8 bit unsigned carry look ahead adder module (u8binary_carry_look_ahead_adder)
//////////////////////////////////////////////////////////////////////////////////

`timescale 1ns/1ps

module u8binary_carry_look_ahead_adder_test;
  
  reg [7:0] IN1,IN2;
  wire [7:0] SUM;
  wire CY,AC;
  
  u8binary_carry_look_ahead_adder inst(.IN1(IN1),.IN2(IN2),.SUM(SUM),.CY(CY),.AC(AC));
  
  initial begin
    
    $display ($time,"\t\tIN1\t\tIN2\t\tSUM\tCY\tAC");
    
    IN1 = 8'd0; IN2 = 8'd0;

#10 IN1 = 8'd0;   IN2 = 8'd1;  
#10 IN1 = 8'd1;   IN2 = 8'd2;
#10 IN1 = 8'd3;   IN2 = 8'd4;
#10 IN1 = 8'd5;   IN2 = 8'd6;
#10 IN1 = 8'd7;   IN2 = 8'd8;
#10 IN1 = 8'd15;  IN2 = 8'd15;
#10 IN1 = 8'd255; IN2 = 8'd1;
#10 IN1 = 8'd1;   IN2 = 8'd255;
#10 IN1 = 8'd127; IN2 = 8'd128;
#10 IN1 = 8'd128; IN2 = 8'd127;

end

initial $monitor($time,"\t%d [%b]\t%d [%b]\t%d [%b]\t%b\t%b",IN1,IN1,IN2,IN2,SUM,SUM,CY,AC);

endmodule

Simulation output is shown below.



Friday, March 21, 2014

SIM cards tutorial Part 6: GSM Authentication Procedure



Whenever GSM mobile equipment (ME) is switched on, it has to be registered with operator’s network. For this registration, operator network should identify the user. There is a well-defined authentication procedure for verifying user identity of ME. The procedure is as follows.

  1. A GSM ME is switched ON. 
  2. ME uses a common channel to communicate with the operator network by providing IMSI. 
  3. When operator network detects an active unregistered ME, it verifies its IMSI. If it is a valid one, authentication procedure starts. Operator network will then fetch Ki corresponding to IMSI received from its database and will generate a random number (RAND). RAND is then encrypted with A3 algorithm with Ki as key to produce an output called SRES_1. Along with this, operator network will send this RAND to ME along with an indication of the algorithm used to generate SRES_1. 
  4. When ME receives RAND, it will pass this to SIM card along with the command RUN GSM ALGORITM. SIM card will encrypt this RAND with the same algorithm used by network operator using Ki in the SIM card as key and will generate SRES_2 as output. ME will send SRES_2 back to operator network. 
  5. On receiving SRES_2, operator network will match it with SRES_1 generated by it. If both matches authentication is success and ME is granted access to operator network

It is important to note that during authentication procedure, Ki is never transmitted anywhere. It always resides in operator network’s data base and in SIM card. Thus there is no way to get Ki for a third party.


Next part - SIM card Data Storage Architecture

SIM cards tutorial Part 5: Security features



SIM cards acts as security key in mobile networks.  Do you know how SIM cards help in implementing such a high security? In this post we discuss about security features in SIM cards.

Prime purpose of SIM card is to provide user authentication in mobile networks. Whenever mobile equipment (ME, which refers to mobile phones and similar device which uses SIM cards) is switched on, it searches for network availability. On finding a registered network, it will request for a channel. Upon receiving this request, network operator will initiate an authentication procedure with the requested ME. If this authentication procedure succeeds, user is identified and allowed to use the network. From now onwards, user can make/receive calls, send SMS and access many other value added services. For performing the above mentioned authentication procedure, mobile equipment uses SIM card.

Authentication Key – Ki

Every SIM card will be having a unique key called Ki. Ki is a 128-bit value used in authenticating the SIM cards on the mobile network. Ki is stored inside SIM card. SIM cards are designed in such a way that, there are no means to read this Ki. Only the network operator who provides the SIM card knows the Ki of a registered SIM. If it cannot be read, what is the use of this key Ki? This is explained below.

For authentication purpose, SIM cards support a command for encrypting a random number (RAND). ME sends this command to SIM along with RAND. When a SIM receive this command, it uses A3 algorithm with Ki as key to encrypt RAND to produce an output called SRES_2. At the same time network operator who send this RAND will also does the same procedure to produce SRES_1. Mobile equipment will send back this SRES_2 to network operator. If both match, authentication is success. This is how SIM card take part in authentication procedure. And it is because of this SIM card is called - a security key.

SIM card PIN (Personal Identification number) or CHV (Card holder verification information) 

SIM cards can be protected from unauthorized use by setting a password called PIN or CHV. PIN is an old name and CHV is the currently used one according to standards. User of SIM card can enable this security feature at any time. By default, when a new SIM card is provided, this feature is disabled. While enabling CHV feature, user is asked to provide 4 to 8 digit number as a password. After enabling CHV feature, every time SIM card is inserted into ME, it will request for this CHV. If user provides an incorrect CHV, critical data (like IMSI) required for registering into mobile network cannot be read from the SIM cards. This in fact makes SIM cards useless for a person who doesn’t know CHV.

There are only 3 wrong attempts allowed while entering CHV. Once user enters more than 3 wrong passwords, SIM will be blocked. Some newer SIM cards allows up to 10 wrong attempts. Once a SIM is blocked, there is no use in knowing CHV. To unlock a blocked SIM card, PUK (PIN Unlocking Key) is required. PUK is provided by the service provider on submitting proper user ID proofs. PUK is an 8 digit number. For PUK 10 wrong attempts are allowed. Once this is crossed, SIM is blocked forever. Only thing which user can do further is to get a new SIM card from service provider.

PIN1 vs. PIN2 (CHV1 vs. CHV2)

CHV1 (PIN1) protects unauthorized use of SIM cards. CHV2 (PIN2) is similar to CHV1. But those data protected by CHV are not critical ones. It just provides some additional features. Apart from CHV1, CHV2 is enabled by default. But normally mobile phones won’t ask CHV2, since it is not required for normal operation. Like CHV1,CHV2  also has 3 or 10 wrong attempts allowed. Once this limit in crossed, that particular SIM card will be CHV2 blocked. Still SIM card can be used as normal. In order to unlock a CHV2 blocked SIM card, PUK2 is required.

Next Part - GSM Authentication Procedure


Wednesday, March 19, 2014

SIM cards tutorial Part 4: Key Terminology



Ki - Ki is a 128-bit value used in authenticating the SIMs on the mobile network.

ICCID - Integrated circuit card identifier. It is used to identify a SIM card internationally. Each SIM is internationally identified by its integrated circuit card identifier (ICCID).

IMSI - International mobile subscriber identity. IMSI is used to identify the user of a cellular network and is a unique identification associated with all cellular networks. 

MSISDN - Mobile Station International Subscriber Directory Number. (Normal mobile number which we use) 

PLMN - Public land mobile network

PIN/CHV - Personal identification number or Card Holder Verification information

PUK - PIN Unblocking Key

MNC/MCC - Mobile Country code/Mobile network code

ESN - Electronic Serial number

MEID - Mobile equipment Identifier

UIM - User Identity Module

RUIM - Removable User Identity Module

RUIMID - 32 bit electronic identification number ID unique to the RUIM

MIN - Mobile Identification Number: A 10-digit number assigned by a wireless operator to a Mobile station.


Next part - SIM card Security Features

Monday, March 17, 2014

SIM cards tutorial Part 3: Data contents



We know that SIM card contains memory. Lets have a look at contents of this memory.

Messages:  A major part of SIM memory is utilized for storing SMS. According to standards, theoretically, up to 256 SMS can be stored on a SIM card. Depending on the size of the EEPROM in SIM cards, message storage capacity changes. A typical value is 30 -50. But there are also SIM cards that can store more than 200 messages. While deleting a message in SIM card normally there won’t be an overwriting unless the space is full. Thus deleted message recovery is possible in SIM cards. Only plain text messages can be stored on SIM cards. There is no space for saving multimedia messages

Contacts: Another major portion of memory is used for storing contacts. Theoretically up to 255 contacts can be stored. Typically most of the SIM cards support more than 200 contacts. Unlike messages, once contacts are a deleted they cannot be recovered by any means. This is because every time a contact is deleted SIM will by default overwrite it with 0xff’s. There are only two fields in a contact: one for the contact name and another for the phone number. You cannot store multiple phone numbers under a single contact name in on SIM card.

Last dialed numbers: SIM card can have a log of last dialed numbers. Typically last 10 or 20 dialed number are stored I this field. Storage format is same as that of contacts. There is no field for storing received/missed call logs.

Phone Number: SIM cards do have a field for storing phone number. Earlier SIM cards used to store phone numbers.  In later revisions of standards, it is not necessary to store phone number on a SIM card. So these days you cannot get phone number from a SIM card.

Above said are major contents of a SIM card from the end users perspective. But it is not for storing the above items SIM card is designed for.  SIM card contains lot of other technical and network related data. Those are listed below

IMSI number
ICCID number
Ciphering key Kc
Authentication key Ki
Administrative data
SIM card phase/class info
PLMN list
MNC,MCC codes
Service provider name
Type of service
Language preference codes
Metering info
Service tables which indicates which services are allocated, and whether, if allocated, the service is activated etc.
Data for communication with the service provider.
Network parameters
Location Information


Saturday, March 15, 2014

Verilog programs 02: 8 bit unsigned ripple carry adder



Verilog code for 8 bit unsigned binary ripple carry adder is shown below.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//////////////////////////////////////////////////////////////////////////////////
// Website:         www.technoburst.net
// Engineer:        Anil C S
// Create Date:     14:16:21 01/17/2014 
// Design Name:     Verilog basic module development
// Module Name:     u8binary_adder 
// Description:     8 bit unsigned ripple carry adder module 
// Dependencies:    Full adder module (full_adder)
//////////////////////////////////////////////////////////////////////////////////

`timescale 1ns/1ps

module u8binary_adder (input [7:0] IN1,IN2,input CIN, output [7:0] SUM, output CY,AC);
  
  wire c0,c1,c2,c4,c5,c6;
  
  full_adder inst1(.IN1(IN1[0]),.IN2(IN2[0]),.SUM(SUM[0]),.CIN(0),.COUT(c0));
  
  full_adder inst2(.IN1(IN1[1]),.IN2(IN2[1]),.SUM(SUM[1]),.CIN(c0),.COUT(c1));  
  
  full_adder inst3(.IN1(IN1[2]),.IN2(IN2[2]),.SUM(SUM[2]),.CIN(c1),.COUT(c2));
  
  full_adder inst4(.IN1(IN1[3]),.IN2(IN2[3]),.SUM(SUM[3]),.CIN(c2),.COUT(AC));
  
  full_adder inst5(.IN1(IN1[4]),.IN2(IN2[4]),.SUM(SUM[4]),.CIN(AC),.COUT(c4));
  
  full_adder inst6(.IN1(IN1[5]),.IN2(IN2[5]),.SUM(SUM[5]),.CIN(c4),.COUT(c5));

  full_adder inst7(.IN1(IN1[6]),.IN2(IN2[6]),.SUM(SUM[6]),.CIN(c5),.COUT(c6));
      
  full_adder inst8(.IN1(IN1[7]),.IN2(IN2[7]),.SUM(SUM[7]),.CIN(c6),.COUT(CY));
        
endmodule

Verilog code of test bench for 8 bit unsigned binary ripple carry adder is shown below.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Engineer:        Anil C S
// Website:         www.technoburst.net
// Create Date:     14:16:21 01/17/2014 
// Design Name:     Verilog basic module development
// Module Name:     u8binary_adder_test 
// Description:     8 bit unsigned ripple carry adder module test bench
// Dependencies:    8 bit unsigned ripple carry adder module (u8binary_adder)
//////////////////////////////////////////////////////////////////////////////////

`timescale 1ns/1ps

module u8binary_adder_test;
  
  reg [7:0] IN1,IN2;
  wire [7:0] SUM;
  wire CY,AC;
  
  u8binary_adder inst(.IN1(IN1),.IN2(IN2),.SUM(SUM),.CY(CY),.AC(AC));
  
  initial begin
    
    $display ($time,"\t\tIN1\t\tIN2\t\tSUM\tCY\tAC");
    
    IN1 = 8'd0; IN2 = 8'd0;

#10 IN1 = 8'd0;   IN2 = 8'd1;  
#10 IN1 = 8'd1;   IN2 = 8'd2;
#10 IN1 = 8'd3;   IN2 = 8'd4;
#10 IN1 = 8'd5;   IN2 = 8'd6;
#10 IN1 = 8'd7;   IN2 = 8'd8;
#10 IN1 = 8'd15;  IN2 = 8'd15;
#10 IN1 = 8'd255; IN2 = 8'd1;
#10 IN1 = 8'd1;   IN2 = 8'd255;
#10 IN1 = 8'd127; IN2 = 8'd128;
#10 IN1 = 8'd128; IN2 = 8'd127;

end

initial $monitor($time,"\t%d [%b]\t%d [%b]\t%d [%b]\t%b\t%b",IN1,IN1,IN2,IN2,SUM,SUM,CY,AC);

endmodule

Simulation output is shown below


Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | coupon codes