資源簡介
這是一個用于計算AES CBC算法的程序,key長度128bit
滿足fips-197規格,這個是最近在做一個OMS(Open Metering Sytem)項目用到的,自己在網上找了半天都找不到C語言的源代碼。找到的不是工具就是別的沒用的東西,要不就是找到的代碼只是AES算法,不是CBC的,和spec上的數據對不上,結果經過多番實驗(try啊try啊),終于成功了,哇哈哈,要不然項目要被賠款的。。。
代碼片段和文件信息
/*
******************************************************************
**???????Advanced?Encryption?Standard?implementation?in?C.??????**
**???????By?Niyaz?PK????????????????????????????????????????????**
**???????E-mail:?niyazlife@gmail.com????????????????????????????**
**???????Downloaded?from?Website:?www.hoozi.com?????????????????**
******************************************************************
This?is?the?source?code?for?encryption?using?the?latest?AES?algorithm.
AES?algorithm?is?also?called?Rijndael?algorithm.?AES?algorithm?is?
recommended?for?non-classified?by?the?National?Institute?of?Standards?
and?Technology(NIST)?USA.?Now-a-days?AES?is?being?used?for?almost?
all?encryption?applications?all?around?the?world.
THE?MAIN?FEATURE?OF?THIS?AES?ENCRYPTION?PROGRAM?IS?NOT?EFFICIENCY;?IT
IS?SIMPLICITY?AND?READABILITY.?THIS?SOURCE?CODE?IS?PROVIDED?FOR?ALL
TO?UNDERSTAND?THE?AES?ALGORITHM.
Comments?are?provided?as?needed?to?understand?the?program.?But?the?
user?must?read?some?AES?documentation?to?understand?the?underlying?
theory?correctly.
It?is?not?possible?to?describe?the?complete?AES?algorithm?in?detail?
here.?For?the?complete?description?of?the?algorithm?point?your?
browser?to:
http://www.csrc.nist.gov/publications/fips/fips197/fips-197.pdf
Find?the?Wikipedia?page?of?AES?at:
http://en.wikipedia.org/wiki/Advanced_Encryption_Standard
******************************************************************
*/
/*?Include?stdio.h?for?standard?input/output.
//?Used?for?giving?output?to?the?screen.
*/
#include
/*?The?number?of?columns?comprising?a?state?in?AES.?This?is?a?constant?in?AES.?Value=4
*/
/*#define?Nb?4
*/
/*?The?number?of?rounds?in?AES?Cipher.?It?is?simply?initiated?to?zero.?The?actual?value?is?recieved?in?the?program.
int?Nr=0;
*/
/*?The?number?of?32?bit?words?in?the?key.?It?is?simply?initiated?to?zero.?The?actual?value?is?recieved?in?the?program.
int?Nk=0;
*/
/*?in?-?it?is?the?array?that?holds?the?plain?text?to?be?encrypted.
//?out?-?it?is?the?array?that?holds?the?key?for?encryption.
//?state?-?the?array?that?holds?the?intermediate?results?during?encryption.
*/
/*unsigned?char?in[16]?out[16]?state[4][4];
unsigned?char?in[16]state[4][4];*/
unsigned?state[4][4];
/*?The?array?that?stores?the?round?keys.
*/
unsigned?char?RoundKey[240];
/*?The?Key?input?to?the?AES?Program
unsigned?char?Key[16];
*/
int?getSBoxValue(int?num)
{
????int?sbox[256]?=???{
????/*0?????1????2??????3?????4????5?????6?????7??????8????9?????A??????B????C?????D?????E?????F
????*/
????0x63?0x7c?0x77?0x7b?0xf2?0x6b?0x6f?0xc5?0x30?0x01?0x67?0x2b?0xfe?0xd7?0xab?0x76?/*0*/
????0xca?0x82?0xc9?0x7d?0xfa?0x59?0x47?0xf0?0xad?0xd4?0xa2?0xaf?0x9c?0xa4?0x72?0xc0?/*1*/
????0xb7?0xfd?0x93?0x26?0x36?0x3f?0xf7?0xcc?0x34?0xa5?0xe5?0xf1?0x71?0xd8?0x31?0x15?/*2*/
????0x04?0xc7?0x23?0xc3?0x18?0x96?0x05?0x9a?0x07?0x12?0x80?0xe2?0xeb?0x27?0xb2
- 上一篇:c語言課程設計-職工信息管理系統-單鏈表
- 下一篇:攝影測量相對定向VC++程序
評論
共有 條評論