]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
kod_management.h, main.c, kod_management.c:
authorJohannes Maximilian Kuehn <kuehn@ntp.org>
Fri, 5 Sep 2008 00:08:08 +0000 (00:08 +0000)
committerJohannes Maximilian Kuehn <kuehn@ntp.org>
Fri, 5 Sep 2008 00:08:08 +0000 (00:08 +0000)
  Fixes
networking.h:
  fixes + broadcast mode
crypto.h:
  BitKeeper file /pogo/users/kuehn/rsync_repo/ntp-dev/gsoc_sntp/crypto.h
crypto.c:
  BitKeeper file /pogo/users/kuehn/rsync_repo/ntp-dev/gsoc_sntp/crypto.c
networking.c:
  Fixes
  Broadcast mode
sntp-opts.def:
  Added new options, removed host list

bk: 48c07868HN5rhS7s4nhzvoR89eynGg

gsoc_sntp/crypto.c [new file with mode: 0644]
gsoc_sntp/crypto.h [new file with mode: 0644]

diff --git a/gsoc_sntp/crypto.c b/gsoc_sntp/crypto.c
new file mode 100644 (file)
index 0000000..9fba3de
--- /dev/null
@@ -0,0 +1,97 @@
+#include "crypto.h"
+
+int key_cnt = 0;
+
+int
+auth_md5 (
+               void *pkt_data,
+               int mac_size,
+               char *cmp_key,
+               int cmp_size
+        )
+{
+       register int a;
+       MD5Context ctx;
+       char digest[16];
+       
+       MD5Init(&ctx);
+       unsigned char *digest_data = (unsigned char *) malloc(sizeof(char) * (LEN_PKT_NOMAC + cmp_size));
+
+       for(a=0; a<LEN_PKT_NOMAC; a++)
+               digest_data[a] = (unsigned char) pkt_data[a];
+
+       for(a=0; a<cmp_size; a++)
+               digest_data[LEN_PKT_NOMAC + a] = (unsigned char) cmp_key[a];
+
+
+       MD5Update(&ctx, digest_data, LEN_PKT_NOMAC + cmp_size);
+       MD5Final(digest, &ctx);
+
+       free(digest_data);
+
+       if(strncmp(cmp_key, digest, cmp_size) != 0) {
+               return 0;
+       }
+       else {
+               return 1;
+       }
+}
+
+int
+auth_init (
+               char *keyfile,
+               struct key *keys
+               )
+{
+       char kbuf[96];
+       FILE *keyf = fopen(keyfile, "r"); 
+       register int a, line_cnt;
+       struct key *prev;
+
+       if(keyf == NULL) {
+               /* Do something about it */
+       }
+
+       line_cnt = 0;
+
+       while(!feof(keyf)) {
+               struct key *act = (struct key *) malloc(sizeof(struct key));
+
+               fgets(kbuf, 96, keyf);
+
+               sscanf(fbuf, "%i %c %16s", act->key_id, act->type, act->key_seq);
+
+#ifdef DEBUG
+               printf("auth_init: key_id %i type %c with key %s\n", act->key_id, act->type, act->key_seq);
+#endif
+
+               if(line_cnt == 0) {
+                       keys = act;
+                       prev = act;
+               }
+               else {
+                       prev->next = act;
+                       prev = act;
+               }
+
+               line_cnt++;
+       }
+
+       fclose(keyf);
+
+       key_cnt = line_cnt;
+
+       return line_cnt;
+}
+
+
+
+
+
+
+       }
+       
+       rewind(keyf);
+
+
+
diff --git a/gsoc_sntp/crypto.h b/gsoc_sntp/crypto.h
new file mode 100644 (file)
index 0000000..1260718
--- /dev/null
@@ -0,0 +1,19 @@
+#ifndef CRYPTO_H
+#define CRYPTO_H
+
+#include <ntp_md5.h>
+#include <string.h>
+
+/* #include "sntp-opts.h" */
+
+int auth_md5(void *pkt_data, int mac_size, char *cmp_key, int cmp_size);
+int auth_init(char *keyfile, struct key *keys);
+
+struct key {
+       unsigned int key_id;
+       char type;
+       char key_seq[16];
+       struct key *next;
+};
+
+#endif