score.c 740 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include "stdinc.h"
  2. #include "dat.h"
  3. #include "fns.h"
  4. u8int zeroscore[VtScoreSize];
  5. /* Call this function to force linking of score.o for zeroscore on OS X */
  6. void needzeroscore(void) { }
  7. void
  8. scoremem(u8int *score, u8int *buf, int n)
  9. {
  10. DigestState s;
  11. memset(&s, 0, sizeof s);
  12. sha1(buf, n, score, &s);
  13. }
  14. static int
  15. hexv(int c)
  16. {
  17. if(c >= '0' && c <= '9')
  18. return c - '0';
  19. if(c >= 'a' && c <= 'f')
  20. return c - 'a' + 10;
  21. if(c >= 'A' && c <= 'F')
  22. return c - 'A' + 10;
  23. return -1;
  24. }
  25. int
  26. strscore(char *s, u8int *score)
  27. {
  28. int i, c, d;
  29. for(i = 0; i < VtScoreSize; i++){
  30. c = hexv(s[2 * i]);
  31. if(c < 0)
  32. return -1;
  33. d = hexv(s[2 * i + 1]);
  34. if(d < 0)
  35. return -1;
  36. score[i] = (c << 4) + d;
  37. }
  38. return s[2 * i] == '\0';
  39. }