Authentication using HMAC
#include<conio.h>
#include<stdio.h>
#include<iostream.h>
#include<stdlib.h>
#include<dos.h>
void main()
{
clrscr();
int hmac,a=65,b=66,ra,rb,kab;
ra=random(10)+1;
kab=random(10)+1;
cout<<"A generated random number "<<ra<<"\n";
cout<<"Shared secret key for session is "<<kab<<"\n";
cout<<"Identity of A is 65 and for B its 66\n";
rb=random(10)+1;
cout<<"B generate random number "<<rb<<"\n";
//calculate hmac(simple add of all keys and rand no's)
hmac=ra+rb+a+b+kab;
cout<<"Hash function value by B is "<<hmac<<"\n";
cout<<"A verifies,......\n";
delay(3000);
cout<<"B authnticatd\n";
hmac=ra+rb+kab;
cout<<"A send hmac on ra,rb,kab "<<hmac<<"\n";
cout<<"B verifies,......\n";
delay(3000);
cout<<"A authnticatd\n";
getch();
}
OUTPUT:
A generated random number 1
Shared secret key for session is 1
Identity of A is 65 and for B its 66
B generate random number 4
Hash function value by B is 137
A verifies,......
B authnticatd
A send hmac on ra,rb,kab 6
B verifies,......
A authnticatd