-
大小: 957KB文件類(lèi)型: .gz金幣: 1下載: 0 次發(fā)布日期: 2021-06-08
- 語(yǔ)言: 其他
- 標(biāo)簽: 控件??源碼??統(tǒng)計(jì)計(jì)數(shù)??資源??
資源簡(jiǎn)介
Serpent加密算法
代碼片段和文件信息
/*
??$Id:?cbc_d_m.cv?1.11?1998/06/10?20:04:10?fms?Exp?$
??#?This?file?is?part?of?the?C?reference?implementation?of?Serpent.
??#
??#?Written?by?Frank?Stajano
??#?Olivetti?Oracle?Research?Laboratory? ?and
??#?Cambridge?University?Computer?Laboratory? .
??#?
??#?(c)?1998?Olivetti?Oracle?Research?Laboratory?(ORL)
??#
??#?Original?(Python)?Serpent?reference?development?started?on?1998?02?12.
??#?C?implementation?development?started?on?1998?03?04.
??#
??#?Serpent?cipher?invented?by?Ross?Anderson?Eli?Biham?Lars?Knudsen.
??#?Serpent?is?a?candidate?for?the?Advanced?Encryption?Standard.
??
*/
/*?--------------------------------------------------?*/
#include?
#include?“serpent-api.h“
#include?“serpent-aux.h“
/*?--------------------------------------------------?*/
embed_RCS(cbc_d_m_c
??????????“$Id:?cbc_d_m.cv?1.11?1998/06/10?20:04:10?fms?Exp?$“)
/*?The?“NIST?SPEC“?markers?refer?to?the?pseudo-code?instructions?in?figure
???6?(Monte?Carlo?Test?-?CBC?Decryption)?of?the?NIST?document?“Description
???of?Known?Answer?Tests?and?Monte?Carlo?Tests?for?Advanced?Encryption
???Standard?(AES)?Candidate?Algorithm?Submissions“?as?updated?on?February
???17?1998?*/
int?main(void)?{
??int?i?j?k?bitsPerShortKey?result;
??BLOCK?plainText?cipherText?PT_9998;
??KEY?binaryKey;
??char?asciiKey[HEX_DIGITS_PER_KEY+1];
??keyInstance?key;
??cipherInstance?cipher;
??/*?The?hack?that?remembers?PT_9998?only?works?if...?*/
??assert(BITS_PER_KEY?<=?2*BITS_PER_BLOCK);
??/*?...otherwise?we‘d?have?to?remember?more?than?just?PT_9998.?*/
??printHeader(“cbc_d_m“?“Cipher?Block?Chaining?(CBC)?Mode?-?DECRYPTION“
??????????????“Monte?Carlo?Test“);
??for(bitsPerShortKey=BITS_PER_SHORTEST_KEY;?bitsPerShortKey<=BITS_PER_KEY;
??????bitsPerShortKey+=BITS_PER_KEY_STEP)?{
????printf(“KEYSIZE=%d\n\n“?bitsPerShortKey);
????/*?Construct?(backwards)?an?ascii?key?of?all?0s?of?length
???????bitsPerShortKey?bits.?*/
????i=bitsPerShortKey/BITS_PER_HEX_DIGIT;
????asciiKey[i]?=?0;?/*?terminating?null?*/?
????for?(i--;?i?>=0;?i--)?{
??????asciiKey[i]?=?‘0‘;
????}
????result?=?makeKey(&key?DIR_DECRYPT?bitsPerShortKey?asciiKey);
????if?(result?!=?TRUE)?goto?error;
????result?=?stringToWords(“00000000000000000000000000000000“?cipherText
???????????????????????????WORDS_PER_BLOCK);
????if?(result?!=?TRUE)?goto?error;
????result?=?cipherInit(&cipher?MODE_CBC?“00000000000000000000000000000000“);
????if?(result?!=?TRUE)?goto?error;
????for(i=0;?i ??????/*?NIST?SPEC:?if?(i==0)?CV_0?=?IV_0?*/
??????/*?This?has?already?been?done?by?cipherInit?outside?this?loop.?Our?CV
?????????is?held?in?cipher.IV.?*/
??????/*?NIST?SPEC:?Record?i?KEY_i?CV_0?CT_0?*/
??????printf(“I=%d\n“?i);
??????render(“KEY=“?key.userKey?bitsPerShortKey/BITS_PER_WORD);
??????render(“IV=“?(WORD*)?cipher.IV?WORDS_PER_BLOCK);
??????render(“CT=“?cip
- 上一篇:行程編碼,JPEG壓縮編碼
- 下一篇:局域網(wǎng)跳棋源代碼
評(píng)論
共有 條評(píng)論