~jkaivo/deonebook

ref: dbd1640b9f41dd0699e5ac09df6f0b1f2a607bdb deonebook/deonebook.c -rw-r--r-- 1.1 KiB
dbd1640b — Jakob Kaivo fail if the device isn't an mmcblk device 1 year, 10 months ago
                                                                                
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
#define _XOPEN_SOURCE 700
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include "deonebook.h"

int main(int argc, char *argv[])
{
	enum { DECRYPT, GENERATE, READ } mode = DECRYPT;

	int c;
	while ((c = getopt(argc, argv, "RGk:")) != -1) {
		switch (c) {
		case 'R':
			mode = READ;
			break;

		case 'G':
			mode = GENERATE;
			break;

		case 'k':
			/* keyfile = optarg; */
			break;

		default:
			return 1;
		}
	}

	if (mode != DECRYPT) {
		unsigned char *key = NULL;
		if (mode == READ) {
			key = readkey("./.shm");
		} else {
			char *device = "mmcblk0";
			if (optind < argc) {
				device = argv[optind];
			}
			if (strstr(device, "mmcblk") != device) {
				fprintf(stderr, "device must be an mmcblk device\n");
				return 1;
			}

			key = genkey(device);
		}

		if (key == NULL) {
			return 1;
		}

		for (int i = 0; i < KEY_SIZE; i++) {
			printf("%02hhx", key[i]);
		}
		printf("\n");

		return 0;
	}

	if (optind >= argc) {
		fprintf(stderr, "%s: missing operands\n", argv[0]);
		return 1;
	}

	do {
		printf("decrypting %s\n", argv[optind]);
	} while (++optind < argc);
}