tst-sha.c 931 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /* iksemel (XML parser for Jabber)
  2. ** Copyright (C) 2000-2003 Gurer Ozen <madcat@e-kolay.net>
  3. ** This code is free software; you can redistribute it and/or
  4. ** modify it under the terms of GNU Lesser General Public License.
  5. */
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include "iksemel.h"
  10. int main (int argc, char *argv[])
  11. {
  12. struct lala {
  13. char *str;
  14. char *hash;
  15. } known_hashes[] = {
  16. { "abc", "a9993e364706816aba3e25717850c26c9cd0d89d" },
  17. { "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
  18. "84983e441c3bd26ebaae4aa1f95129e5e54670f1" },
  19. { NULL, NULL }
  20. };
  21. int i = 0;
  22. char buf[42];
  23. while (known_hashes[i].str) {
  24. iks_sha (known_hashes[i].str, buf);
  25. if (strcmp (buf, known_hashes[i].hash) != 0) {
  26. printf("SHA1 hash of \"%s\"\n", known_hashes[i].str);
  27. printf(" Result: %s\n", buf);
  28. printf(" Expected: %s\n", known_hashes[i].hash);
  29. return 1;
  30. }
  31. i++;
  32. }
  33. return 0;
  34. }