twofish-test.m4 1.29 KB
Newer Older
Niels Möller's avatar
Niels Möller committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "twofish.h"

BEGIN_TEST

struct twofish_ctx ctx;

uint8_t msg[TWOFISH_BLOCK_SIZE];
uint8_t cipher[TWOFISH_BLOCK_SIZE];
uint8_t clear[TWOFISH_BLOCK_SIZE];

/* 128 bit key */
H(msg, "0000000000000000 0000000000000000");

twofish_set_key(&ctx, 16, H("0000000000000000 0000000000000000"))
twofish_encrypt(&ctx, TWOFISH_BLOCK_SIZE, cipher, msg);

if (!MEMEQ(TWOFISH_BLOCK_SIZE, cipher,
	H("9F589F5CF6122C32 B6BFEC2F2AE8C35A")))
  FAIL;

twofish_decrypt(&ctx, TWOFISH_BLOCK_SIZE, clear, cipher);
if (!MEMEQ(TWOFISH_BLOCK_SIZE, msg, clear))
  FAIL;

/* 192 bit key */

twofish_set_key(&ctx, 24, H("0123456789ABCDEF FEDCBA9876543210"
			    "0011223344556677"));
twofish_encrypt(&ctx, TWOFISH_BLOCK_SIZE, cipher, msg);

if (!MEMEQ(TWOFISH_BLOCK_SIZE, cipher,
	H("CFD1D2E5A9BE9CDF 501F13B892BD2248")))
  FAIL;

twofish_decrypt(&ctx, TWOFISH_BLOCK_SIZE, clear, cipher);
if (!MEMEQ(TWOFISH_BLOCK_SIZE, msg, clear))
  FAIL;

/* 256 bit key */
twofish_set_key(&ctx, 32, H("0123456789ABCDEF FEDCBA9876543210"
			    "0011223344556677 8899AABBCCDDEEFF"));
  FAIL;

twofish_encrypt(&ctx, TWOFISH_BLOCK_SIZE, cipher, msg);

if (!MEMEQ(TWOFISH_BLOCK_SIZE, cipher,
	H("37527BE0052334B8 9F0CFCCAE87CFA20")))
  FAIL;

twofish_decrypt(&ctx, TWOFISH_BLOCK_SIZE, clear, cipher);
if (!MEMEQ(TWOFISH_BLOCK_SIZE, msg, clear))
  FAIL;