score.c 611 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include "stdinc.h"
  2. #include "dat.h"
  3. #include "fns.h"
  4. #include "libsec.h"
  5. u8int zeroScore[VtScoreSize];
  6. void
  7. scoreMem(u8int *score, u8int *buf, int n)
  8. {
  9. sha1(buf, n, score, nil);
  10. }
  11. static int
  12. hexv(int c)
  13. {
  14. if(c >= '0' && c <= '9')
  15. return c - '0';
  16. if(c >= 'a' && c <= 'f')
  17. return c - 'a' + 10;
  18. if(c >= 'A' && c <= 'F')
  19. return c - 'A' + 10;
  20. return -1;
  21. }
  22. int
  23. strScore(char *s, u8int *score)
  24. {
  25. int i, c, d;
  26. for(i = 0; i < VtScoreSize; i++){
  27. c = hexv(s[2 * i]);
  28. if(c < 0)
  29. return 0;
  30. d = hexv(s[2 * i + 1]);
  31. if(d < 0)
  32. return 0;
  33. score[i] = (c << 4) + d;
  34. }
  35. return s[2 * i] == '\0';
  36. }