md5pickle.c 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include "os.h"
  10. #include <libsec.h>
  11. int8_t*
  12. md5pickle(MD5state *s)
  13. {
  14. int8_t *p;
  15. int m, n;
  16. m = 4*9+4*((s->blen+3)/3);
  17. p = malloc(m);
  18. if(p == nil)
  19. return p;
  20. n = sprint(p, "%8.8ux %8.8ux %8.8ux %8.8ux ",
  21. s->state[0], s->state[1], s->state[2],
  22. s->state[3]);
  23. enc64(p+n, m-n, s->buf, s->blen);
  24. return p;
  25. }
  26. MD5state*
  27. md5unpickle(int8_t *p)
  28. {
  29. MD5state *s;
  30. s = malloc(sizeof(*s));
  31. if(s == nil)
  32. return nil;
  33. s->state[0] = strtoul(p, &p, 16);
  34. s->state[1] = strtoul(p, &p, 16);
  35. s->state[2] = strtoul(p, &p, 16);
  36. s->state[3] = strtoul(p, &p, 16);
  37. s->blen = dec64(s->buf, sizeof(s->buf), p, strlen(p));
  38. s->malloced = 1;
  39. s->seeded = 1;
  40. return s;
  41. }