home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / x / xntp3.zip / gizmo / gizmo_util.c < prev    next >
C/C++ Source or Header  |  1989-09-17  |  2KB  |  118 lines

  1. /*
  2.  * gizmo_util.c - stuff I didn't have any other place for
  3.  */
  4. #include <stdio.h>
  5. #include <errno.h>
  6. #include <strings.h>
  7. #include <sys/types.h>
  8. #include <sys/socket.h>
  9. #include <net/if.h>
  10. #include <netinet/in.h>
  11.  
  12. #include "ntp_syslog.h"
  13. #include "ntp_fp.h"
  14. #include "ntp.h"
  15. #include "gizmo.h"
  16.  
  17.  
  18. /*
  19.  * This contains odds and ends.  For the Unix daemon these odds and ends
  20.  * fortunately contained a lot of Unix dependent stuff.  These are
  21.  * replaced wholesale.
  22.  *
  23.  * We retain support for the hourly call.  We also include entries
  24.  * to decode and set individual authentication keys and a dummy entry
  25.  * for rereading the authentication keys (which we can't do).
  26.  */
  27.  
  28. #ifdef DEBUG
  29. extern int debug;
  30. #endif
  31.  
  32. /*
  33.  * init_util - initialize the utilities
  34.  */
  35. void
  36. init_util()
  37. {
  38.     /*
  39.      * Nothing to do here
  40.      */
  41. }
  42.  
  43.  
  44. /*
  45.  * hourly_stats - print some interesting stats
  46.  */
  47. void
  48. hourly_stats()
  49. {
  50.     extern l_fp drift_comp;
  51.     extern long compliance;
  52.     extern char *lfptoa();
  53.     extern char *mfptoa();
  54.  
  55.     syslog(LOG_INFO, "hourly check: drift %s compliance %s",
  56.         lfptoa(&drift_comp, 8),
  57.         mfptoa((compliance<0)?(-1):0, compliance, 8));
  58. }
  59.  
  60.  
  61.  
  62. /*
  63.  * setauthkey - decode and use an authentication key
  64.  */
  65. void
  66. setauthkey(keyno, rawkeys)
  67.     u_long keyno;
  68.     u_long *rawkeys;
  69. {
  70.     u_long keys[2];
  71.     u_long masterkey[2];
  72.     u_char ekeys[128];
  73.     u_char dkeys[128];
  74.     extern void auth_subkeys();
  75.     extern void auth_des();
  76.     extern void auth_setkey();
  77.     extern int auth_parity();
  78.  
  79.     keys[0] = rawkeys[0];
  80.     keys[1] = rawkeys[1];
  81.  
  82.     masterkey[0] = (GIZMO_KEY_L ^ keyno) ^ (keyno << 1);
  83.     masterkey[1] = (GIZMO_KEY_R ^ keyno) ^ (keyno << 1);
  84.     auth_subkeys(masterkey, ekeys, dkeys);
  85.     auth_des(keys, dkeys);
  86.     if (!auth_parity(keys)) {
  87.         syslog(LOG_ERR, "parity error on key number %d, not used",
  88.             keyno);
  89.     } else {
  90.         auth_setkey(keyno, keys);
  91.     }
  92. }
  93.  
  94.  
  95. /*
  96.  * rereadkeys - read the authentication key file over again.
  97.  */
  98. void
  99. rereadkeys()
  100. {
  101. }
  102.  
  103.  
  104. /*
  105.  * clock_parms - return the gizmo's clock parameters
  106.  */
  107. void
  108. clock_parms(tickadj, tick)
  109.     u_long *tickadj;
  110.     u_long *tick;
  111. {
  112.     /*
  113.      * These values are hardwired, in gizmo.h
  114.      */
  115.     *tickadj = (u_long)GIZMO_TICKADJ;
  116.     *tick = (u_long)GIZMO_TICK;
  117. }
  118.