文章目录

  • 128-EEA1与128-NEA1算法详解

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

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

128-EEA1与128-NEA1算法详解

注意下面用到了 nettle库,记得添加链接参数 -lnettle

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;

conversions.h

/* Endianness conversions for 16 and 32 bits integers from host to network order */
#if (BYTE_ORDER == LITTLE_ENDIAN)
# define hton_int32(x)   \(((x & 0x000000FF) << 24) | ((x & 0x0000FF00) << 8) |  \((x & 0x00FF0000) >> 8) | ((x & 0xFF000000) >> 24))# define hton_int16(x)   \(((x & 0x00FF) << 8) | ((x & 0xFF00) >> 8)# define ntoh_int32_buf(bUF)        \((*(bUF)) << 24) | ((*((bUF) + 1)) << 16) | ((*((bUF) + 2)) << 8)   \| (*((bUF) + 3))
#else
# define hton_int32(x) (x)
# define hton_int16(x) (x)
#endif

nea1_eea1_stream.c

#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>#include <nettle/nettle-meta.h>
#include <nettle/aes.h>
#include <nettle/ctr.h>#include "assert.h"
#include "conversions.h"
#include "secu_defs.h"
#include "snow3g.h" //定义在《Snow 3G算法源码介绍》blog中// #define SECU_DEBUGint nea1_eea1(stream_cipher_t*stream_cipher, uint8_t *out)
{snow_3g_context_t snow_3g_context;int       n ;int       i           = 0;uint32_t  zero_bit    = 0;//uint32_t  byte_length;uint32_t *KS;uint32_t  K[4],IV[4];assert(stream_cipher != NULL);assert(stream_cipher->key != NULL);assert(stream_cipher->key_length == 16);assert(out != NULL);n = ( stream_cipher->blength + 31 ) / 32;zero_bit = stream_cipher->blength & 0x7;//byte_length = stream_cipher->blength >> 3;memset(&snow_3g_context, 0, sizeof(snow_3g_context));/*Initialisation*//* Load the confidentiality key for SNOW 3G initialization as in section3.4. */memcpy(K+3,stream_cipher->key+0,4); /*K[3] = key[0]; we assumeK[3]=key[0]||key[1]||...||key[31] , with key[0] the* most important bit of key*/memcpy(K+2,stream_cipher->key+4,4); /*K[2] = key[1];*/memcpy(K+1,stream_cipher->key+8,4); /*K[1] = key[2];*/memcpy(K+0,stream_cipher->key+12,4); /*K[0] = key[3]; we assumeK[0]=key[96]||key[97]||...||key[127] , with key[127] the* least important bit of key*/K[3] = hton_int32(K[3]);K[2] = hton_int32(K[2]);K[1] = hton_int32(K[1]);K[0] = hton_int32(K[0]);/* Prepare the initialization vector (IV) for SNOW 3G initialization as insection 3.4. */IV[3] = stream_cipher->count;IV[2] = ((((uint32_t)stream_cipher->bearer) << 3) | ((((uint32_t)stream_cipher->direction) & 0x1) << 2)) << 24;IV[1] = IV[3];IV[0] = IV[2];/* Run SNOW 3G algorithm to generate sequence of key stream bits KS*/snow3g_initialize(K, IV, &snow_3g_context);KS = (uint32_t *)malloc(4*n);snow3g_generate_key_stream(n,(uint32_t*)KS, &snow_3g_context);if (zero_bit > 0) {KS[n - 1] = KS[n - 1] & (uint32_t)(0xFFFFFFFF << (8 - zero_bit));}for (i=0; i<n; i++) {KS[i] = hton_int32(KS[i]);}/* Exclusive-OR the input data with keystream to generate the output bitstream */for (i=0; i<n*4; i++) {stream_cipher->message[i] ^= *(((uint8_t*)KS)+i);}int ceil_index = 0;if (zero_bit > 0) {ceil_index = (stream_cipher->blength+7) >> 3;stream_cipher->message[ceil_index - 1] = stream_cipher->message[ceil_index - 1] & (uint8_t)(0xFF << (8 - zero_bit));}free(KS);memcpy(out, stream_cipher->message, n*4);if (zero_bit > 0) {out[ceil_index - 1] = stream_cipher->message[ceil_index - 1];}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安全系列】加解密+完整性保护安全算法测试cases


【5G/4G】128-EEA1与128-NEA1算法详解相关推荐

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

    文章目录 [5G/4G]128-EEA3与128-NEA3算法详解 本人就职于国际知名终端厂商,负责modem芯片研发. 在5G早期负责终端数据业务层.核心网相关的开发工作,目前牵头6G算力网络技术标 ...

  2. 【5G/4G】128-EEA2与128-NEA2算法详解

    文章目录 [5G/4G]128-EEA2与128-NEA2算法详解 本人就职于国际知名终端厂商,负责modem芯片研发. 在5G早期负责终端数据业务层.核心网相关的开发工作,目前牵头6G算力网络技术标 ...

  3. 【目标检测】Faster RCNN算法详解

    转载自:http://blog.csdn.net/shenxiaolu1984/article/details/51152614 Ren, Shaoqing, et al. "Faster ...

  4. CenterNet算法详解

    Objects as Points-论文链接-代码链接 目录 1.需求解读 2.CenterNet算法简介 3.CenterNet算法详解 3.1 CenterNet网络结构 3.2 CenterNe ...

  5. java break 在if 中使用_java中使用国密SM4算法详解

    前言 上次总结了一下加密算法的分类(加密算法有集中形式,各有什么不同?),现在我们用java语言实现一下SM4:无线局域网标准的分组数据算法.对称加密,密钥长度和分组长度均为128位. ps:我们既可 ...

  6. 基于多相滤波器的数字信道化算法详解(Python, Verilog代码已开源)

    基于多相滤波器的数字信道化算法详解 推导过程 总结 仿真 本文详细介绍了基于多相滤波器的数字信道化算法的推导过程, 如果您在阅读的过程中发现算法推导过程中有任何错误, 请不吝指出. 此外, 进入我的G ...

  7. 计算机图形几何算法详解勘误

    一直在看<计算机图形几何算法详解>这本书,但是在用的过程中发现了一些错误,一直以为是自己的错误,后来在网上找到了这本书的勘误信息,不过是英文原版的,但是还是想贴出来,以便查找 07 Jul ...

  8. SIFT特征点提取及描述论文算法详解

    SIFT特征点提取及描述论文算法详解 1. 尺度空间极值检测(Scale-space extrema detection) 1.1 尺度空间和极值 1.2 DoG和LoG的关系 1.3 构建高斯尺度差 ...

  9. Simhash算法详解及python实现

    Simhash算法详解及python实现 GoogleMoses Charikar发表的一篇论文"detecting near-duplicates for web crawling&quo ...

最新文章

  1. java amr 转 mp3_JAVA 音频转换AMR 转MP3,OS,Linux cent os 7
  2. 使用qmeu-img创建虚拟机[创建虚拟机,虚拟机快照]
  3. 电镀用整流电源设计matlab,基于MATLAB的三相整流电路的仿真研究毕业设计论文
  4. Android存储数据到本地文件
  5. Tomcat一些小事
  6. vscode 怎么让光标一下子跳到行尾部_动图演示23个常用 VsCode 快捷键(Window Mac)...
  7. Spring Cloud Alibaba迁移指南(三):极简的 Config 1
  8. 【JAVA SE】第四章 变量和方法
  9. yum安装jdk1.8
  10. 时间序列分析(6)| DF检验
  11. [MyBatis日记](3)映射器配置文件与映射器接口
  12. mybatis源码详解
  13. 自动排单功能的一些思考
  14. 校内计算机无法报名高考,没有奖项可以报名自主招生吗?报考条件建议65问
  15. Vue3.x 深入浅出系列(连载三)
  16. 倒数第02周,入书的推荐名单【人人都是产品经理:9071】
  17. 为什么Arduino UNO工作电压是5V,但是需要9V的电源适配器
  18. MAC JDK 卸载方法、环境配置
  19. 什么硬技能,什么是软技能,怎么提高它们!
  20. C语言各数据类型所占字节数和取值范围

热门文章

  1. 比天若OCR,PandaOCR更方便使用的OCR扫描文字识别软件,易用AI
  2. 38-博客网站数据库-博文分类信息数据操作(二)
  3. 隧道保活超时或协商超时_隧道人员定位系统和隧道门禁系统
  4. 2021-2025年中国高频太阳能逆变器行业市场供需与战略研究报告
  5. 13. Fabric2.2 区块链农产品溯源系统 - 智能合约调试
  6. 欢迎报名第三届中国移动互联网测试开发大会
  7. 达内java作业_【达内JAVA教程】达内Java基础题
  8. nba2konline2 竞品分析
  9. 初级平面设计师必须熟练掌握的软件
  10. 立创EDA导出3D模型到KiCad软件中