des-test.m4 1.8 KB
Newer Older
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "des.h"

BEGIN_TEST

struct des_ctx ctx;

uint8_t msg[DES_BLOCK_SIZE];
uint8_t cipher[DES_BLOCK_SIZE];
uint8_t clear[DES_BLOCK_SIZE];

H(msg, "00 00 00 00 00 00 00 00");

if (!des_set_key(&ctx, H("01 01 01 01 01 01 01 80")))
  FAIL;

des_encrypt(&ctx, DES_BLOCK_SIZE, cipher, msg);

if (!MEMEQ(DES_BLOCK_SIZE, cipher,
	H("9C C6 2D F4 3B 6E ED 74")))
  FAIL;

des_decrypt(&ctx, DES_BLOCK_SIZE, clear, cipher);
if (!MEMEQ(DES_BLOCK_SIZE, msg, clear))
  FAIL;

H(msg, "00 00 00 00 00 00 00 40");

if (!des_set_key(&ctx, H("80 01 01 01 01 01 01 01")))
  FAIL;

des_encrypt(&ctx, DES_BLOCK_SIZE, cipher, msg);

if (!MEMEQ(DES_BLOCK_SIZE, cipher,
	H("A3 80 E0 2A 6B E5 46 96")))
  FAIL;

des_decrypt(&ctx, DES_BLOCK_SIZE, clear, cipher);
if (!MEMEQ(DES_BLOCK_SIZE, msg, clear))
  FAIL;

H(msg, "00 00 00 00 00 00 00 00");

if (!des_set_key(&ctx, H("08 19 2A 3B 4C 5D 6E 7F")))
  FAIL;

des_encrypt(&ctx, DES_BLOCK_SIZE, cipher, msg);

if (!MEMEQ(DES_BLOCK_SIZE, cipher,
	H("25 DD AC 3E 96 17 64 67")))
  FAIL;

des_decrypt(&ctx, DES_BLOCK_SIZE, clear, cipher);
if (!MEMEQ(DES_BLOCK_SIZE, msg, clear))
  FAIL;

if (!des_set_key(&ctx, H("01 23 45 67 89 AB CD EF")))
  FAIL;

des_encrypt(&ctx, DES_BLOCK_SIZE, cipher, "Now is t");

if (!MEMEQ(DES_BLOCK_SIZE, cipher,
	H("3F A4 0E 8A 98 4D 48 15")))
  FAIL;

des_decrypt(&ctx, DES_BLOCK_SIZE, clear, cipher);
if (!MEMEQ(DES_BLOCK_SIZE, "Now is t", clear))
  FAIL;

/* Parity check */
if (des_set_key(&ctx, H("01 01 01 01 01 01 01 00"))
    || (ctx.status != DES_BAD_PARITY))
  FAIL;

/* Weak key check */
if (des_set_key(&ctx, H("01 01 01 01 01 01 01 01"))
    || (ctx.status != DES_WEAK_KEY))
  FAIL;

if (des_set_key(&ctx, H("01 FE 01 FE 01 FE 01 FE"))
    || (ctx.status != DES_WEAK_KEY))
  FAIL;

if (des_set_key(&ctx, H("FE E0 FE E0 FE F1 FE F1"))
    || (ctx.status != DES_WEAK_KEY))
  FAIL;