5G/4G128-EEA3与128-NEA3算法详解

Posted 从善若水

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了5G/4G128-EEA3与128-NEA3算法详解相关的知识,希望对你有一定的参考价值。

本人就职于国际知名终端厂商,负责modem芯片研发。
在5G早期负责终端数据业务层、核心网相关的开发工作,目前牵头6G算力网络技术标准研究。


博客内容主要围绕:
       5G协议讲解
       算力网络讲解(云计算,边缘计算,端计算)
       高级C语言讲解
       Rust语言讲解

【5G/4G】128-EEA3与128-NEA3算法详解

secu_defs.h

typedef struct {
  uint8_t *key;
  uint32_t key_length;
  uint32_t count;
  uint8_t  bearer;
  uint8_t  direction;
  uint8_t  *message;
  /* length in bits */
  uint32_t  blength;
} stream_cipher_t;

nea3_eea3_stream.c

#include <stdlib.h>
#include "secu_defs.h"
#include <arpa/inet.h>

//这两个函数定义在《ZUC算法源码介绍》博文中
extern void Initialization(uint8_t*,uint8_t*);
extern void GenerateKeystream(uint32_t*,int);

/* ---------------------------- EEA3 ----------------------------------------- */
/* The ZUC algorithm 《ZUC算法源码介绍》*/
void ZUC(uint8_t* k, uint8_t* iv, uint32_t* ks, int len)
{
	/* The initialization of ZUC, see page 17 of ref. [3]*/
	Initialization(k, iv);
	
	/*  The procedure of generating keystream of ZUC, see page 18 of ref. [3]*/
	GenerateKeystream(ks, len);
}

int nea3_eea3(stream_cipher_t *stream_cipher, uint8_t *out)
{
	uint32_t*z, L, i;
	uint8_t IV[16];
	
	L 	= (stream_cipher->blength + 31)/32;
	z 	= (uint32_t*) malloc(L*sizeof(uint32_t));
	
	IV[0]	= (stream_cipher->count>>24) & 0xFF;
	IV[1]	= (stream_cipher->count>>16) & 0xFF;
	IV[2]	= (stream_cipher->count>>8)  & 0xFF;
	IV[3]	= stream_cipher->count       & 0xFF;
	
	IV[4]	= ((stream_cipher->bearer<< 3) | ((stream_cipher->direction&1)<<2)) & 0xFC;
	IV[5]	= 0;
	IV[6]	= 0;
	IV[7]	= 0;
	
	IV[8]	= IV[0];
	IV[9]	= IV[1];
	IV[10]	= IV[2];
	IV[11]	= IV[3];
	
	IV[12]	= IV[4];
	IV[13]	= IV[5];
	IV[14]	= IV[6];
	IV[15]	= IV[7];
	
	ZUC(stream_cipher->key,IV,z,L);
	
	for (i=0; i<L; i++)
	{
		((uint32_t*)out)[i] = htol(htol(((uint32_t*)stream_cipher->message)[i]) ^ z[i]);
	}
	
	free(z);
	return 0;
}

《Snow 3G算法源码介绍》
《128-bit AES算法源码介绍》
《ZUC算法源码介绍》

【5G/4G】128-EEA1与128-NEA1算法详解
【5G/4G】128-EEA2与128-NEA2算法详解
【5G/4G】128-EEA3与128-NEA3算法详解

【5G/4G】128-EIA1与128-NIA1算法详解
【5G/4G】128-EIA2与128-NIA2算法详解
【5G/4G】128-EIA3与128-NIA3算法详解


以上是关于5G/4G128-EEA3与128-NEA3算法详解的主要内容,如果未能解决你的问题,请参考以下文章

5G/4G128-EIA1与128-NIA1算法详解

5G/4G128-EIA3与128-NIA3算法详解

5G/4G128-EEA2与128-NEA2算法详解

5G/4G128-EIA3与128-NIA3算法详解

5G/4G128-EEA2与128-NEA2算法详解

5G/4G128-EIA1与128-NIA1算法详解