/contrib/ntp/libntp/authusekey.c

https://bitbucket.org/freebsd/freebsd-head/ · C · 47 lines · 28 code · 8 blank · 11 comment · 3 complexity · 8dbb899a657f5ab15fe59c5b6f7eb409 MD5 · raw file

  1. /*
  2. * authusekey - decode a key from ascii and use it
  3. */
  4. #include <stdio.h>
  5. #include <ctype.h>
  6. #include "ntp_types.h"
  7. #include "ntp_string.h"
  8. #include "ntp_stdlib.h"
  9. /*
  10. * Types of ascii representations for keys. "Standard" means a 64 bit
  11. * hex number in NBS format, i.e. with the low order bit of each byte
  12. * a parity bit. "NTP" means a 64 bit key in NTP format, with the
  13. * high order bit of each byte a parity bit. "Ascii" means a 1-to-8
  14. * character string whose ascii representation is used as the key.
  15. */
  16. #define KEY_TYPE_MD5 4
  17. int
  18. authusekey(
  19. keyid_t keyno,
  20. int keytype,
  21. const u_char *str
  22. )
  23. {
  24. const u_char *cp;
  25. int len;
  26. cp = str;
  27. len = strlen((const char *)cp);
  28. if (len == 0)
  29. return 0;
  30. switch(keytype) {
  31. case KEY_TYPE_MD5:
  32. MD5auth_setkey(keyno, str, (int)strlen((const char *)str));
  33. break;
  34. default:
  35. /* Oh, well */
  36. return 0;
  37. }
  38. return 1;
  39. }