
/************************************************************************
File name: zuc.c
Version: V1.1
Date: Oct 28,2016
Description: This code provide the implement of ZUC algorithm,which consist of three parts:key
stream generation,confidentiality algorithm
and integrity algorithm.
Function List:
1.AddMod // calculate a+b mod 2^31-1
2.PowMod // calculate x*2^k mod 2^31-1
3.L1 // linear transformation L1:X^(X<<< 2)^(X<<<10)^(X<<<18)^(X<<<24)
4.L2 // linear transformation L2:X^(X<<< 8)^(X<<<14)^(X<<<22)^(X<<<30)
5.BitValue // test if the value of M at the position i equals 0
6.GetWord // get a 32bit word ki from bit strings k[i],k[i+1]...,
// namely ki=k[i]||k[i+1]||…||k[i+31]
7.LFSRWithInitMode // Initialisation mode,refresh the current state of LFSR
8.LFSRWithWorkMode // working mode,refresh the current state of LFSR
9.BR // Bit Reconstruction
10.F // nonlinear function
11.ZUC_Init // Initialisation process of ZUC
12.ZUC_Work // working stage of ZUC
13.ZUC_GenKeyStream // generate key stream
14.ZUC_Confidentiality // the ZUC-based condifentiality algorithm
15.ZUC_Integrity // the ZUC-based integrity algorithm
**************************************************************************/
#include "zuc.h"
/************************************************************
Function: AddMod
Description: calculate a+b mod 2^31-1
Calls:
Called By: LFSRWithInitMode
Input: a,b: unsigned int(32bit)
Output:
Return: c, c=a+b mod 2^31-1
Others:
************************************************************/
unsigned int AddMod(unsigned int a, unsigned int b)
{
unsigned int c = a + b;
if(c >> 31)
{
评论0