资源简介
AES 算法C语言实现(linux), 可直接编译运行. 可自由移植到其他平台
代码片段和文件信息
/*
* FIPS-197 compliant AES implementation
*
* Copyright (C) 2006-2015 ARM Limited All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License Version 2.0 (the “License“); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing software
* distributed under the License is distributed on an “AS IS“ BASIS WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* This file is part of mbed TLS (https://tls.mbed.org)
*/
/*
* The AES block cipher was designed by Vincent Rijmen and Joan Daemen.
*
* http://csrc.nist.gov/encryption/aes/rijndael/Rijndael.pdf
* http://csrc.nist.gov/publications/fips/fips197/fips-197.pdf
*/
#if !defined(MBEDTLS_CONFIG_FILE)
//#include “config.h“
#else
#include MBEDTLS_CONFIG_FILE
#endif
#include
#include
#include
#include “aes.h“
#if !defined(MBEDTLS_AES_ALT)
/* Implementation that should never be optimized out by the compiler */
static void mbedtls_zeroize( void *v size_t n ) {
volatile unsigned char *p = (unsigned char*)v; while( n-- ) *p++ = 0;
}
/* Add base64 and padding By zhanggf start 1 */
#ifndef base64
static const char *ALPHA_base = “ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/“;
unsigned char* str2hex(char *str) {
unsigned char *ret = NULL;
int str_len = strlen(str);
int i = 0;
ret = (char *)malloc(str_len/2);
memset(ret 0 str_len/2);
for (i =0;i < str_len; i = i+2 ) {
sscanf(str+i“%2hhx“&ret[i/2]);
}
return ret;
}
int AES_padding7_buf(char *pszBufint iSize char *pszOutbuf int iOutbufLen) {
int iFinalSize = -1;
int pidding_size = AES_BLOCK_SIZE - (iSize % AES_BLOCK_SIZE);
int i;
if (iOutbufLen == 0) {
return iFinalSize;
}
iFinalSize = iSize + pidding_size;
memset(pszOutbuf 0 iOutbufLen);
memcpy(pszOutbuf pszBuf iSize);
if (pidding_size!=0) {
for (i = iSize;i < (iSize + pidding_size); i++ ) {
pszOutbuf[i] = pidding_size;
}
}
return iFinalSize;
}
int AES_padding0_buf(char *pszBufint iSize char *pszOutbuf int iOutbufLen) {
int iFinalSize = -1;
int pidding_size = AES_BLOCK_SIZE - (iSize % AES_BLOCK_SIZE);
int i;
if (iOutbufLen == 0) {
return iFinalSize;
}
iFinalSize = iSize + pidding_size;
memset(pszOutbuf 0 iOutbufLen);
memcpy(pszOutbuf pszBuf iSize);
if (pidding_size!=0) {
for (i = iSize;i < (iSize + pidding_size); i++ ) {
pszOutbuf[i] = 0;
}
}
return iFinalSize;
}
void AES_printf_hex(char *pszBuf int iBufLen)
{
int iLoop = 0;
for (; iLoop < iBufLen; iLoop ++ ) {
printf(“%02x“ (unsigned char)ps - 上一篇:C++ 程序设计第二版 钱能 源码
- 下一篇:操作系统磁盘调度算法实现
相关资源
- C语言面试笔试题,经典题目
- C语言编程常见问题解答.pdf
- 操作系统c语言模拟文件管理系统844
- C语言开发实战宝典
- C++中头文件与源文件的作用详解
- C语言代码高亮html输出工具
- 猜数字游戏 c语言代码
- C语言课程设计
- 数字电位器C语言程序
- CCS FFT c语言算法
- 使用C语言编写的病房管理系统
- 通信过程中的RS编译码程序(c语言)
- 计算机二级C语言上机填空,改错,编
- 用回溯法解决八皇后问题C语言实现
- 简易教务管理系统c语言开发文档
- 操作系统课设 读写者问题 c语言实现
- 小波变换算法 c语言版
- C流程图生成器,用C语言代码 生成C语
- 3des加密算法C语言实现
- 简单的C语言点对点聊天程序
- 单片机c语言源程序(51定时器 八个按
- 个人日常财务管理系统(C语言)
- c语言电子商务系统
- 小甲鱼C语言课件 源代码
- 将图片转换为C语言数组的程序
- C语言实现的一个内存泄漏检测程序
- DES加密算法C语言实现
- LINUX下命令行界面的C语言细胞游戏
- 用单片机控制蜂鸣器播放旋律程序(
- 学校超市选址问题(数据结构C语言版
川公网安备 51152502000135号
评论
共有 条评论