Serpent と Twofish を使用して unsigned char (16 バイト長) の配列を暗号化する必要があります。私は公式ウェブサイトから 2 つのライブラリ -c で書く - を使用します。私はそれらを使用しようとしますが、取得する暗号文は正しくありません。確認には、このサイトを使用します。どこが間違っているのか分かりません。
私のコードは次のとおりです。
keyInstance keyTwofish;
cipherInstance cipherTwofish;
unsigned char *buffer_out_twofish;
char path_file_twofish[DIM];
...
//Twofish
if(cipherInit(&cipherTwofish,MODE_ECB,NULL)!=TRUE)
{
perror("[ERROR] Function module02: makeKey.\n");
return 0;
}
//key_dim*8=128 and key is an unsigned char key [16] that contain key
makeKey(&keyTwofish, DIR_ENCRYPT, key_dim*8, key);
…
//Buffer in is unsigned char buffer_in[16] contain plaintext
//byte_for_file=16 than byte_for_file*8=128
//Buffer out is unsigned char buffer_out_twofish[16]
blockEncrypt(&cipherTwofish, &keyTwofish, buffer_in, byte_for_file*8, buffer_out_twofish);
Serpent は同じ実装です。
変数の型の sizeof を出力すると、結果は次のようになります。
Size of Char: 1
Size of Integer: 4
Size of Long: 8
そして私がするとき:
printf("\nPrint Char Array: ");
for (int j = 0; j < byte_for_file; ++j)
printf("%x ", buffer_in[j]);
printf("\nPrint long Array: ");
test(buffer_in, byte_for_file);
どこ
void test (unsigned long * a, int b)
{
for (int i = 0; i < b/sizeof(long); ++i)
printf("%lx ", a[i]);
}
私はこれを得る:
Print Char Array: 87 ae bd 58 71 75 1d 36 43 ab 1d ef 69 f5 54 d7
Print long Array: 361d757158bdae87 d754f569ef1dab43