aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/utils/README.md
blob: d07d559842293bf46717b33c6d61b16a29adc68b (plain) (blame)
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# Utilities

Here are a couple of useful utilities built on top of the library.
Each of the utilities accepts the `--help` flag, which can be used to examine
utility's usage info.

The included utilities are:

* [block encryption](#block-encryption) utilities,
* [file encryption](#file-encryption) utilities,
* and [bitmap encryption](#bitmap-encryption) utilities.

On older CPUs, you can run the utilities
[using Intel SDE](../README.md#running-on-older-cpus).

## Block encryption

The block encryption utilities can produce verbose human-readable output,
including round keys, intermediate initialization vector values, etc.
This is primarily intended for debugging purposes.
Enable verbose output by passing the `--verbose` flag to the utilities.
Please note that verbose output can only be produced when *not* using "boxes"
(the `--boxes` flag).

### encrypt_block.exe

Encrypts blocks using the selected algorithm in the specified mode of
operation.

#### Usage examples

For example, to encrypt

* the plaintext block `0x00112233445566778899aabbccddeeff`
* using AES-128 in ECB mode
* with key `0x000102030405060708090a0b0c0d0e0f`,

run:

    encrypt_block.exe -a aes128 -m ecb 000102030405060708090a0b0c0d0e0f 00112233445566778899aabbccddeeff

To encrypt

* the plaintext block `0x00112233445566778899aabbccddeeff`
* using AES-192 in OFB mode
* with initialization vector `0x22222222222222222222222222222222`
* and key `0x000102030405060708090a0b0c0d0e0f101112131415161718`,

run:

    encrypt_block.exe -a aes192 -m ofb 000102030405060708090a0b0c0d0e0f101112131415161718 22222222222222222222222222222222 00112233445566778899aabbccddeeff

### decrypt_block.exe

Decrypts blocks using the selected algorithm in the specified mode of
operation.

#### Usage examples

For example, to decrypt

* the ciphertext block `0x69c4e0d86a7b0430d8cdb78070b4c55a`
* using AES-128 in ECB mode
* with key `0x000102030405060708090a0b0c0d0e0f`,

run:

    decrypt_block.exe -a aes128 -m ecb 000102030405060708090a0b0c0d0e0f 69c4e0d86a7b0430d8cdb78070b4c55a

To decrypt

* the ciphertext block `0x762a5ab50929189cefdb99434790aad8`
* using AES-192 in OFB mode
* with initialization vector `0x22222222222222222222222222222222`
* and key `0x000102030405060708090a0b0c0d0e0f101112131415161718`,

run:

    decrypt_block.exe -a aes192 -m ofb 000102030405060708090a0b0c0d0e0f101112131415161718 22222222222222222222222222222222 bda298884f5c3a9eb7068aa7063a3b75

## File encryption

### encrypt_file.exe

Encrypts a file using the selected algorithm in the specified mode of
operation.

#### Usage examples

For example, to encrypt the plaintext `input.txt`

* using AES-128 in ECB mode
* with key `0x11111111111111111111111111111111`
* and write the ciphertext to `output.txt`,

run:

    encrypt_file.exe -a aes128 -m ecb 11111111111111111111111111111111 input.txt output.txt

To encrypt the plaintext from `input.txt`

* using AES-192 in OFB mode
* with key `0x111111111111111111111111111111111111111111111111`
* and initialization vector `0x22222222222222222222222222222222`
* and write the ciphertext to `output.txt`:

run

    encrypt_file.exe -a aes192 -m ofb 111111111111111111111111111111111111111111111111 22222222222222222222222222222222 input.txt output.txt

### decrypt_file.exe

Decrypts a file using the selected algorithm in the specified mode of
operation.

#### Usage examples

To decrypt the ciphertext from `input.txt`

* using AES-128 in ECB mode
* with key `0x11111111111111111111111111111111`
* and write the plaintext to `output.txt`,

run

    decrypt_file.exe -a aes128 -m ecb 11111111111111111111111111111111 input.txt output.txt

To decrypt the ciphertext from `input.txt`

* using AES-192 in OFB mode
* with key `0x111111111111111111111111111111111111111111111111`
* and initialization vector `0x22222222222222222222222222222222`
* and write the plaintext to `output.txt`,

run

    decrypt_file.exe -a aes192 -m ofb 111111111111111111111111111111111111111111111111 22222222222222222222222222222222 input.txt output.txt

## Bitmap encryption

These utilities were developed primarily to demonstrate the drawbacks of using
ECB mode (namely, the fact that identical plaintext blocks get mapped to
identical ciphertext blocks).
This can be explicitly shown using 8-bit-per-pixel bitmaps:

Plaintext BMP | Encrypted in ECB mode | Encrypted in CBC mode
------------- | --------------------- | ---------------------
![Plaintext butterfly](bmp/butterfly.bmp?raw=true) | ![Ciphertext butterfly in ECB mode](bmp/cipherfly_ecb.bmp?raw=true) | ![Ciphertext butterfly in CBC mode](bmp/cipherfly_cbc.bmp?raw=true)

### encrypt_bmp.exe

Encrypts the pixels in a BMP image file, preserving the header.
The usage is the same as for [encrypt_file.exe](#encrypt_fileexe).

### decrypt_bmp.exe

Decrypts the pixels in a BMP image file, preserving the header.
The usage is the same as for [decrypt_file.exe](#decrypt_fileexe).