OCB实施计划
我尝试了OCB算法的参考实现,在添加解密数据的打印输出后,缺少了一个元素 由于我在pastebin上发布的代码的大小 主要功能OCB实施计划,c,security,encryption,ocb-mode,C,Security,Encryption,Ocb Mode,我尝试了OCB算法的参考实现,在添加解密数据的打印输出后,缺少了一个元素 由于我在pastebin上发布的代码的大小 主要功能 #include <stdio.h> #include <stdlib.h> #define PLAIN_SIZE 8 int main() { uint8_t zeroes[PLAIN_SIZE]; uint8_t nonce[12] = {0,}; uint8_t p[PLAIN_SIZE+8] =
#include <stdio.h>
#include <stdlib.h>
#define PLAIN_SIZE 8
int main() {
uint8_t zeroes[PLAIN_SIZE];
uint8_t nonce[12] = {0,};
uint8_t p[PLAIN_SIZE+8] = {0,};
uint8_t final[16];
uint8_t *c;
unsigned i, next;
int result;
for (i=0; i<(PLAIN_SIZE); i++) {
zeroes[i]=2;
p[i]=5;
}
p[i+8]=5;
printf("Nonece: %d\n",NONCEBYTES);
/* Encrypt and output RFC vector */
c = malloc(22400);
next = 0;
for (i=0; i<PLAIN_SIZE; i++) {
nonce[10] = i;
ocb_encrypt(c+next, zeroes, nonce, zeroes, i, zeroes, i);
next = next + i + TAGBYTES;
ocb_encrypt(c+next, zeroes, nonce, zeroes, 0, zeroes, i);
next = next + i + TAGBYTES;
ocb_encrypt(c+next, zeroes, nonce, zeroes, i, zeroes, 0);
next = next + TAGBYTES;
}
nonce[10] = 0;
ocb_encrypt(final, zeroes, nonce, c, next, zeroes, 0);
if (NONCEBYTES == 12) {
printf("AEAD_AES_%d_OCB_TAGLEN%d Output: ", KEYBYTES*8, TAGBYTES*8);
for (i=0; i<TAGBYTES; i++) printf("%02X", final[i]); printf("\n");
}
/* Decrypt and test for all zeros and authenticity */
result = ocb_decrypt(p, zeroes, nonce, c, next, final, TAGBYTES);
if (result) { printf("FAIL\n"); return 0; }
next = 0;
for (i=0; i<PLAIN_SIZE; i++) {
nonce[10] = i;
result = ocb_decrypt(p, zeroes, nonce, zeroes, i, c+next, i+TAGBYTES);
if (result || memcmp(p,zeroes,i)) { printf("FAIL\n"); return 0; }
next = next + i + TAGBYTES;
result = ocb_decrypt(p, zeroes, nonce, zeroes, 0, c+next, i+TAGBYTES);
if (result || memcmp(p,zeroes,i)) { printf("FAIL\n"); return 0; }
next = next + i + TAGBYTES;
result = ocb_decrypt(p, zeroes, nonce, zeroes, i, c+next, TAGBYTES);
if (result || memcmp(p,zeroes,i)) { printf("FAIL\n"); return 0; }
next = next + TAGBYTES;
}
for (i=0; i<(PLAIN_SIZE); i++) printf("%d", zeroes[i]); printf("\n");
for (i=0; i<(PLAIN_SIZE); i++) printf("%d", p[i]); printf("\n");
free(c);
return 0;
}
因此,数组的最后一个元素尚未写入,但身份验证已通过
有什么想法吗?代码有一些问题:\
ocb_encrypt()
需要包含适当的头文件结果
未使用p
已设置但未使用ocb\u encrypt()
的原型)
- 假设输入都是整数
- 假设返回值(如果有)为整数
ocb\u encrypt()
的编译器假设可能是主要原因
输出不正确
如果编译器警告都被启用,然后被更正,从而产生一个干净的编译,那么问题将是可调试的,因为它是,任何人都可以猜测编译器传递给
ocb\u encrypt()
的内容以及ocb\u encrypt()的方式
函数对传递错误类型的参数作出反应您在说什么?包括什么?你真的读过我写的吗?“由于我在pastebin上发布的代码的大小”,当函数在main上面的同一个文件中声明时,不需要原型。您还可以在我的帖子“gcc-W-g-lcrypto ocb_rev.c&./a.out”中看到编译标志,因此我没有看到任何警告。p是用来。。。。你在浏览之前注意一下帖子怎么样?
->gcc -W -g -lcrypto ocb_rev.c && ./a.out
Nonece: 12
AEAD_AES_128_OCB_TAGLEN128 Output: 0DA35760F29E327625FBC0071E18E330
22222222
22222225