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