aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/lib
diff options
context:
space:
mode:
authorDavid M. Syzdek <david@syzdek.net>2022-04-29 23:18:53 -0800
committerDavid M. Syzdek <david@syzdek.net>2022-04-30 22:48:37 -0800
commit46033c20f3bd6afc8222910d45d8d6733359a782 (patch)
treec1e7653e6f11b3014fcf95b1810b7cf0a82bf3e5 /lib
parent8621fe0dd127599f0a1b91b654b470a4c73c12cf (diff)
downloadtinytac-46033c20f3bd6afc8222910d45d8d6733359a782.tar.gz
tinytac-46033c20f3bd6afc8222910d45d8d6733359a782.tar.bz2
tinytac-46033c20f3bd6afc8222910d45d8d6733359a782.tar.xz
tinytac-46033c20f3bd6afc8222910d45d8d6733359a782.zip
libtinytac: adding tinytac_pckt_obfuscate()
Diffstat (limited to 'lib')
-rw-r--r--lib/libtinytac/libtinytac.sym1
-rw-r--r--lib/libtinytac/lproto.c40
2 files changed, 41 insertions, 0 deletions
diff --git a/lib/libtinytac/libtinytac.sym b/lib/libtinytac/libtinytac.sym
index ad039cd..206db9d 100644
--- a/lib/libtinytac/libtinytac.sym
+++ b/lib/libtinytac/libtinytac.sym
@@ -36,4 +36,5 @@ tinytac_initialize
36# 36#
37# protocol functions 37# protocol functions
38tinytac_pckt_md5pad 38tinytac_pckt_md5pad
39tinytac_pckt_obfuscate
39# end of symbol export file 40# end of symbol export file
diff --git a/lib/libtinytac/lproto.c b/lib/libtinytac/lproto.c
index 8c64798..0ed365e 100644
--- a/lib/libtinytac/lproto.c
+++ b/lib/libtinytac/lproto.c
@@ -106,4 +106,44 @@ tinytac_pckt_md5pad(
106 return(0); 106 return(0);
107} 107}
108 108
109
110int
111tinytac_pckt_obfuscate(
112 tinytac_pckt_t * pckt,
113 char * key,
114 size_t key_len,
115 unsigned unencrypted )
116{
117 uint8_t md_value[EVP_MAX_MD_SIZE];
118 size_t pckt_len;
119 size_t off;
120 size_t pos;
121
122 assert(pckt != NULL);
123 assert(key != NULL);
124
125 // check for existing obfuscation and flip flag
126 unencrypted = (unencrypted == TTAC_NO) ? 0 : TAC_PLUS_FLAG_UNENCRYPTED;
127 if ((pckt->pckt_flags & TAC_PLUS_FLAG_UNENCRYPTED) == unencrypted)
128 return(0);
129 pckt->pckt_flags ^= TAC_PLUS_FLAG_UNENCRYPTED;
130
131 // create initial pad
132 tinytac_pckt_md5pad(pckt, key, key_len, NULL, md_value);
133 pckt_len = ntohl(pckt->pckt_length);
134
135 // apply pads to packet body
136 for(off = 0; ((pckt_len - off) > 15); off += 16)
137 {
138 for(pos = 0; (pos < 16); pos++)
139 pckt->pckt_body[off+pos] ^= md_value[pos];
140 tinytac_pckt_md5pad(pckt, key, key_len, md_value, md_value);
141 };
142 for(pos = 0; ((pos+off) < pckt_len); pos++)
143 pckt->pckt_body[off+pos] ^= md_value[pos];
144
145 return(0);
146}
147
148
109/* end of source */ 149/* end of source */