ВходНаше всё Теги codebook 无线电组件 Поиск Опросы Закон Четверг
18 июля
145463
Pahan (21.01.2009 11:50, просмотров: 1630) reZident
Доброго времени суток! Есть проблема: алгоритм Rijndael, mode CBC. зашифровывает правильно (проверял), расшифровывает неверно. Вот кусок кода:  switch (cipher->mode) { case MODE_ECB: for (i = 0; i < numBlocks; i++) { for (j = 0; j < cipher->blockLen/32; j++) { /* parse input stream into rectangular array */ for(t = 0; t < 4; t++) { block[t][j] = input[cipher->blockLen/8*i+4*j+t] & 0xFF;}} rijndaelDecrypt (block, key->keyLen, cipher->blockLen, key->keySched); for (j = 0; j < cipher->blockLen/32; j++) { /* parse rectangular array into output ciphertext bytes */ for(t = 0; t < 4; t++) { outBuffer[cipher->blockLen/8*i+4*j+t] = (UINT8) block[t][j];}} } break; case MODE_CBC: /* first block */ for (j = 0; j < cipher->blockLen/32; j++) { /* parse input stream into rectangular array */ for(t = 0; t < 4; t++) { block[t][j] = input[4*j+t] & 0xFF;}} rijndaelDecrypt (block, key->keyLen, cipher->blockLen, key->keySched); for (j = 0; j < cipher->blockLen/32; j++) { /* exor the IV and parse rectangular array into output ciphertext bytes */ for(t = 0; t < 4; t++) { outBuffer[4*j+t] = (UINT8) (block[t][j] ^ cipher->IV[t+4*j]);}} /* next blocks */ for (i = 1; i < numBlocks; i++) { for (j = 0; j < cipher->blockLen/32; j++) { /* parse input stream into rectangular array */ for(t = 0; t < 4; t++) { block[t][j] = input[cipher->blockLen/8*i+4*j+t] & 0xFF;}} rijndaelDecrypt (block, key->keyLen, cipher->blockLen, key->keySched); for (j = 0; j < cipher->blockLen/32; j++) { /* exor previous ciphertext block and parse rectangular array into output ciphertext bytes */ for(t = 0; t < 4; t++) { outBuffer[cipher->blockLen/8*i+4*j+t] = (UINT8) (block[t][j] ^ input[4*j+t-4*cipher->blockLen/32]);}} } break;