Implementation of SHA-1 in CPP
#include<stdio.h> //including header files
#include"crypto++/cryptlib.h"
using namespace CryptoPP;
/*****defining functions used in the algorithms as macros*****/
#define f1(x,y,z) (z^(x&(y^z)));
#define f2(x,y,z) (x^y^z);
#define f3(x,y,z) ((x&y)|(z&(x|y)));
#define f4(x,y,z) (x^y^z);
/***************To find the power of a number***************/
word32 pow(int a,int b)
{
int i,c=1;
for(i=0;i<3-b;i++)
c=c*a;
return c;
}
/****to circular shifts the word by required no of bits*****/
word32 shift(word32 a,int n)
{
word32 X,Y;
X=a<<n;Y=a>>32-n;
X=X|Y;
return X;
}
/*********generating 80 words from 16 msg words************/
word32 wordgen(word32 w[],int t)
{
word32 p;
p=w[t-3]^w[t-8]^w[t-14]^w[t-16];
p=shift(p,1);
return p;
}
/***********actual hash computation algorithm*************/