MilenageAlgo.h
#ifndef MILENAGE_ALGO_H_INCLUDED
#define MILENAGE_ALGO_H_INCLUDED
typedef unsigned char BYTE;
/*--------------------------- prototypes --------------------------*/
void f1( BYTE op_c[16], BYTE key[16], BYTE rand[16], BYTE sqn[6], BYTE amf[2], BYTE mac_a[8] );
void KeyAdd(BYTE state[4][4], BYTE roundKeys[11][4][4], int round);
int ByteSub(BYTE state[4][4]);
void f2345 ( BYTE op_c[16], BYTE k[16], BYTE rand[16], BYTE res[8], BYTE ck[16], BYTE ik[16], BYTE ak[6] );
void f1star(BYTE op_c[16], BYTE k[16], BYTE rand[16], BYTE sqn[6], BYTE amf[2], BYTE mac_s[8] );
void f5star( BYTE op_c[16], BYTE k[16], BYTE rand[16], BYTE ak[6] );
void KeyAdd(BYTE state[4][4], BYTE roundKeys[11][4][4], int round);
void MixColumn(BYTE state[4][4]);
void ComputeOPc( BYTE op[16], BYTE key[16], BYTE op_c[16] );
void RijndaelKeySchedule( BYTE key[16] );
void RijndaelEncrypt( BYTE input[16], BYTE output[16] );
void ShiftRow(BYTE state[4][4]);
#endif
MilenageAlgo.cpp
#include "MilenageAlgo.h"
/*-------------------------------------------------------------------
* Example algorithms f1, f1*, f2, f3, f4, f5, f5*
*-------------------------------------------------------------------
*
* A sample implementation of the example 3GPP authentication and
* key agreement functions f1, f1*, f2, f3, f4, f5 and f5*. This is
* a byte-oriented implementation of the functions, and of the block
* cipher kernel function Rijndael.
*
* This has been coded for clarity, not necessarily for efficiency.
*
* The functions f2, f3, f4 and f5 share the same inputs and have
* been coded together as a single function. f1, f1* and f5* are
* all coded separately.
*
*-----------------------------------------------------------------*/
/*-------------------- Rijndael round subkeys ---------------------*/
BYTE roundKeys[11][4][4];
/*--------------------- Rijndael S box table ----------------------*/
BYTE S[256] = {
99,124,119,123,242,107,111,197, 48, 1,103, 43,254,215,171,118,
202,130,201,125,250, 89, 71,240,173,212,162,175,156,164,114,192,
183,253,147, 38, 54, 63,247,204, 52,165,229,241,113,216, 49, 21,
4,199, 35,195, 24,150, 5,154, 7, 18,128,226,235, 39,178,117,
9,131, 44, 26, 27,110, 90,160, 82, 59,214,179, 41,227, 47,132,
83,209, 0,237, 32,252,177, 91,106,203,190, 57, 74, 76, 88,207,
208,239,170,251, 67, 77, 51,133, 69,249, 2,127, 80, 60,159,168,
81,163, 64,143,146,157, 56,245,188,182,218, 33, 16,255,243,210,
205, 12, 19,236, 95,151, 68, 23,196,167,126, 61,100, 93, 25,115,
96,129, 79,220, 34, 42,144,136, 70,238,184, 20,222, 94, 11,219,
224, 50, 58, 10, 73, 6, 36, 92,194,211,172, 98,145,149,228,121,
231,200, 55,109,141,213, 78,169,108, 86,244,234,101,122,174, 8,
186,120, 37, 46, 28,166,180,198,232,221,116, 31, 75,189,139,138,
112, 62,181,102, 72, 3,246, 14, 97, 53, 87,185,134,193, 29,158,
225,248,152, 17,105,217,142,148,155, 30,135,233,206, 85, 40,223,
140,161,137, 13,191,230, 66,104, 65,153, 45, 15,176, 84,187, 22,
};
/*------- This array does the multiplication by x in GF(2^8) ------*/
BYTE
关于登网鉴权Milenage算法C++实现(根据3GPP TS 35.206 V6.0.0程序修改)
最新推荐文章于 2021-06-12 12:40:21 发布
本文提供了3GPP TS 35.206 V6.0.0中Milenage算法的C++实现,包括f1、f1*、f2345和f5*等核心函数。通过Rijndael加密引擎,实现了鉴权过程中的MAC-A、RES、CK、IK和AK的计算,详细展示了密钥和挑战的处理流程。
摘要由CSDN通过智能技术生成