theGuard 10.0
Loading...
Searching...
No Matches
aguard_crypt.h
Go to the documentation of this file.
1
10/* LABEL-NO */
11
12#pragma once
13
14#include "key.h"
16#define IDENT "aguard"
17
18static void guard_crypt (register MK_BINN data, MK_SIZE size, bool const flag) {
19 if (selKey == 0) return;
20 register MK_BINN key = KEY_REF[selKey];
21 const MK_BINN keyend = KEY_REF[selKey]+KEY_LEN[selKey];
22 const MK_BINN dataend = data+size;
23 for (;data<dataend; data++,key++) {
24 if (key >= keyend) {
25 key=KEY_REF[selKey];
26 }
27 if (flag) {
28 *(MK_BIN)data += *key;
29 } else {
30 *(MK_BIN)data -= *key;
31 }
32 }
33}
34
35static void __attribute__ ((noreturn))
36FilterHelp (const char * base)
37{
38 fputs("\n", stderr);
39 fprintf(stderr, "usage: %s [OPTION]... [ARGUMENT]...\n", base);
40 fputs("\n", stderr);
41 fputs(" This tool is the data protection filter of NHI1.\n", stderr);
42 fputs("\n", stderr);
43 fprintf(stderr, " %s [ARGUMENT]... syntax:\n", base);
44 fprintf(stderr, " aclient... %c %s --key NUM ... [encrypted] ... %c %s --key NUM... %c aserver\n",
45 MK_ALFA, base, MK_ALFA, base, MK_ALFA);
46 fputs("\n", stderr);
47 fputs(MqHelp (NULL), stderr);
48 fputs("\n", stderr);
49 fprintf(stderr, " %s [OPTION]:\n", base);
50 fputs( " -h, --help print this help\n", stderr);
51 fputs( " -d, --dig print the key diggest\n", stderr);
52 fprintf(stderr, " -k, --key NUM select the KEY for encryption...(0 <= NUM <= %i)\n", KEY_NUM);
53 fputs( " 0 = NO\n", stderr);
54 fputs( " 1 = DEFAULT\n", stderr);
55 fputs("\n", stderr);
56
57 exit(EXIT_SUCCESS);
58}
59
60static enum MkErrorE
62{
63 bool printDIG = false;
64
65 MkBufferListCheckOptionO_3E(args, "-d", &printDIG);
66 MkBufferListCheckOptionO_3E(args, "--dig", &printDIG);
67
68 if (printDIG == true) {
69 fprintf(stderr,"\n");
70 fprintf(stderr,"'%s' key information..\n", MqConfigGetName(mqctx));
71 fprintf(stderr,"\n");
72 fprintf(stderr," sign-dat: %s\n", DIG_DATE);
73 fprintf(stderr," sign-dig: %s\n", DIG_DATA);
74 fprintf(stderr," sign-min: %i byte\n", KEY_MIN);
75 fprintf(stderr," sign-num: %i\n", KEY_NUM);
76 fprintf(stderr,"\n");
77
78 return MK_CONTINUE;
79 }
80
82 MkBufferListCheckOptionI_3E(args, "--key", &selKey);
83
85 return MkErrorSetV_1E("key-error: invalid value for argument '-k,--key', '%i' have to be: '0 <= NUM <= %i'",
87 }
88
89 return MK_OK;
90error:
91 return MK_ERROR;
92}
93
static enum MkErrorE FilterArgs(MK_RT_ARGS MQ_CTX mqctx, MK_BFL args)
MK_NUM selKey
static void FilterHelp(const char *base)
static void guard_crypt(register MK_BINN data, MK_SIZE size, bool const flag)
#define MkBufferListCheckOptionO_3E(bfl, opt, val_out)
#define MkBufferListCheckOptionI_3E(bfl, opt, val_out)
#define MkErrorSetV_1E(printfmt,...)
MkErrorE
MK_ERROR
MK_CONTINUE
MK_OK
int32_t MK_NUM
MK_BINB * MK_BIN
#define MK_ALFA
long MK_SIZE
MK_BINB const * MK_BINN
#define MK_RT_ARGS
static MK_STRN MqConfigGetName(MQ_CTXN const ctx)
MK_STR MqHelp(MK_STRN tool)
MK_NUM KEY_MIN
Definition key.h:108
MK_NUM KEY_NUM
Definition key.h:107
MK_NUM KEY_LEN[]
Definition key.h:100
MK_BIN KEY_REF[]
Definition key.h:103
MK_STRN DIG_DATA
Definition key.h:111
MK_STRN DIG_DATE
Definition key.h:110