aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDavid M. Syzdek <david@syzdek.net>2022-04-29 22:08:50 -0800
committerDavid M. Syzdek <david@syzdek.net>2022-04-29 22:12:31 -0800
commitb9312a2108fefe165b8c1c1d05be910cd968c772 (patch)
tree825b3b6930d533b383177cbb0247313b18fac00f
parent93bb9df2c5f09f08b8542c625f8444c48b1a9235 (diff)
downloadtinytac-b9312a2108fefe165b8c1c1d05be910cd968c772.tar.gz
tinytac-b9312a2108fefe165b8c1c1d05be910cd968c772.tar.bz2
tinytac-b9312a2108fefe165b8c1c1d05be910cd968c772.tar.xz
tinytac-b9312a2108fefe165b8c1c1d05be910cd968c772.zip
libtinytac: adding tinytac_md5pad()
-rw-r--r--include/tinytac.h35
-rw-r--r--lib/libtinytac/libtinytac.sym3
-rw-r--r--lib/libtinytac/lproto.c68
3 files changed, 74 insertions, 32 deletions
diff --git a/include/tinytac.h b/include/tinytac.h
index 5bf14df..ad86bb9 100644
--- a/include/tinytac.h
+++ b/include/tinytac.h
@@ -205,6 +205,19 @@
205#pragma mark - Data Types 205#pragma mark - Data Types
206 206
207typedef struct _tinytac TinyTac; 207typedef struct _tinytac TinyTac;
208typedef struct _tinytac_packet tinytac_pckt_t;
209
210
211struct _tinytac_packet
212{
213 uint8_t pckt_version; // 4 bits major and 4 bits minor
214 uint8_t pckt_type;
215 uint8_t pckt_seq_no;
216 uint8_t pckt_flags;
217 uint32_t pckt_session_id;
218 uint32_t pckt_length;
219 uint8_t pckt_body[];
220};
208 221
209 222
210////////////////// 223//////////////////
@@ -245,4 +258,26 @@ tinytac_set_option(
245 const void * invalue ); 258 const void * invalue );
246 259
247 260
261//---------------------//
262// protocol prototypes //
263//---------------------//
264#pragma mark protocol prototypes
265
266/// generates pseudo-random pad used to obfuscate the packet body
267///
268/// @param[in] pckt packet used to generate psuedo-random pad
269/// @param[in] key shared secret key used to protect the communication
270/// @param[in] key_len length of shared secret key
271/// @param[in] md5pad_prev previously generated psuedo-random pad (must be 16 bytes)
272/// @param[out] md5pad buffer to store generated
273///
274/// @return Returns 0 on success or -1 on error.
275_TINYTAC_F int
276tinytac_pckt_md5pad(
277 tinytac_pckt_t * pckt,
278 char * key,
279 size_t key_len,
280 uint8_t * md5pad_prev,
281 uint8_t * md5pad );
282
248#endif /* end of header */ 283#endif /* end of header */
diff --git a/lib/libtinytac/libtinytac.sym b/lib/libtinytac/libtinytac.sym
index 80d6b6d..ad039cd 100644
--- a/lib/libtinytac/libtinytac.sym
+++ b/lib/libtinytac/libtinytac.sym
@@ -33,4 +33,7 @@
33# memory functions 33# memory functions
34tinytac_free 34tinytac_free
35tinytac_initialize 35tinytac_initialize
36#
37# protocol functions
38tinytac_pckt_md5pad
36# end of symbol export file 39# end of symbol export file
diff --git a/lib/libtinytac/lproto.c b/lib/libtinytac/lproto.c
index 864ecdb..8c64798 100644
--- a/lib/libtinytac/lproto.c
+++ b/lib/libtinytac/lproto.c
@@ -52,14 +52,7 @@
52#include <netinet/in.h> 52#include <netinet/in.h>
53#include <netdb.h> 53#include <netdb.h>
54#include <assert.h> 54#include <assert.h>
55 55#include <openssl/evp.h>
56
57///////////////////
58// //
59// Definitions //
60// //
61///////////////////
62#pragma mark - Definitions
63 56
64 57
65////////////////// 58//////////////////
@@ -69,25 +62,6 @@
69////////////////// 62//////////////////
70#pragma mark - Prototypes 63#pragma mark - Prototypes
71 64
72//--------------------//
73// TinyTac prototypes //
74//--------------------//
75#pragma mark TinyTac prototypes
76
77
78//-------------------//
79// object prototypes //
80//-------------------//
81#pragma mark object prototypes
82
83
84/////////////////
85// //
86// Variables //
87// //
88/////////////////
89#pragma mark - Variables
90
91 65
92///////////////// 66/////////////////
93// // 67// //
@@ -96,10 +70,40 @@
96///////////////// 70/////////////////
97#pragma mark - Functions 71#pragma mark - Functions
98 72
99//-------------------// 73//------------------//
100// TinyTac functions // 74// packet functions //
101//-------------------// 75//------------------//
102#pragma mark TinyTac functions 76#pragma mark packet functions
103 77
78int
79tinytac_pckt_md5pad(
80 tinytac_pckt_t * pckt,
81 char * key,
82 size_t key_len,
83 uint8_t * md5pad_prev,
84 uint8_t * md5pad )
85{
86 unsigned md_len;
87 EVP_MD_CTX * mdctx;
88
89 assert(pckt != NULL);
90 assert(key != NULL);
91 assert(md5pad != NULL);
92
93 key_len = ((key)) ? key_len : 0;
94
95 mdctx = EVP_MD_CTX_new();
96 EVP_DigestInit_ex(mdctx, EVP_md5(), NULL);
97 EVP_DigestUpdate(mdctx, &pckt->pckt_session_id, 4);
98 EVP_DigestUpdate(mdctx, key, key_len);
99 EVP_DigestUpdate(mdctx, &pckt->pckt_version, 1);
100 EVP_DigestUpdate(mdctx, &pckt->pckt_seq_no, 1);
101 if ((md5pad_prev))
102 EVP_DigestUpdate(mdctx, md5pad_prev, 16);
103 EVP_DigestFinal_ex(mdctx, md5pad, &md_len);
104 EVP_MD_CTX_free(mdctx);
105
106 return(0);
107}
104 108
105/* end of source */ 109/* end of source */