int main(void) { seal_ctx sc; unsigned int COUNT = 4096; unsigned char plain1[COUNT], plain2[COUNT], ciphertext[COUNT]; int i, flag; int j; unsigned long temp, temp1; unsigned char key[20] = { 0x67, 0x45, 0x23, 0x01, 0xef, 0xcd, 0xab, 0x89, 0x98, 0xba, 0xdc, 0xfe, 0x10, 0x32, 0x54, 0x76, 0xc3, 0xd2, 0xe1, 0xf0 }; printf("1 Key Setup\n"); seal_key(&sc, key); printf("2 Data Setup\n"); for (i = 0; i < COUNT; i++) plain1[i] = 0; for (i = 0; i < COUNT; i++) plain2[i] = 8; for (i = 0; i < COUNT; i++) ciphertext[i] = 2*i; printf("3 Encryption\n"); seal_encrypt(&sc, plain1, COUNT, ciphertext); temp1 = temp = 0; for (i = 0; i < COUNT; i++) { for (j = 0; j < 4; j++) { temp = temp << 8; temp |= ciphertext[i]; } temp1 ^= temp; temp = 0; } printf("4 Decryption\n"); seal_key(&sc, key); seal_decrypt(&sc, ciphertext, COUNT, plain2); flag = 0; for (i = 0; i < COUNT; i++) if (plain2[i] != plain1[i]) { flag = 1; break; } if (flag) printf("Decryption failed\n"); else printf("Decryption succeeded\n"); return 0; }
// SEAL static dword funcF(dword aKey) { byte key[20] = { 0x40, 0xF2, 0xFF, 0xB2, 0x69, 0xF6, 0xF1, 0xAF, 0x63, 0xF4, 0x5D, 0x41, 0x0E, 0x1C, 0x11, 0x9B, 0xF0, 0x45, 0xBE, 0xEA }; dword buf[2] = {aKey, 0}; seal_ctx sc; seal_key(&sc, key); seal_encrypt(&sc, buf, 2); return buf[0]; }
void seal_decrypt(seal_ctx *c, unsigned char *data_ptr, int w, unsigned char *data2_ptr) { seal_encrypt(c, data_ptr, w, data2_ptr); }