资源简介
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语言嵌入式Modbus协议栈,支持主站和
- C语言封装的HttpClient接口
- C语言课设计算器
- C语言 学生兴趣管理系统
- c语言实现火车订票系统(控制台)源
- 模拟笔记本电脑(C语言实现)
- c语言实现竞技比赛打分系统
- KMP算法C语言程序
- Linux c语言 学生成绩管理系统
- 弹跳的小球(test.c)
- 林锐—高质量C编程
- 基于c语言的通讯录系统
- C语言全套课件与教学资料-哈工大
- 计算机二级C语言真题.docx
- C语言实现 设备信息管理系统
- aes加解密(vc源程序)
- GBT 28169-2011 嵌入式软件 C语言编码规范
- C语言标准库函数大全.chm
- C语言常用代码(分章节)
- c语言课程设计:客房登记系统源码
- C语言常用算法源代码
- 吕鑫:VS2015之博大精深的0基础C语言视
- c语言文都讲义2020
- c语言课件56883
- C语言推箱子win控制台
- C语言程序设计50例.docx
- 烟花优化算法(c语言版)
- C语言程序设计教材习题参考答案.do
- 数据结构(C语言版)ppt课件,清华,
- c语言编程经典例题100例 word版
评论
共有 条评论