md5pickle.c (712B)
1 #include "os.h" 2 #include <libsec.h> 3 4 char* 5 md5pickle(MD5state *s) 6 { 7 char *p; 8 int m, n; 9 10 m = 17+4*9+4*((s->blen+3)/3); 11 p = malloc(m); 12 if(p == nil) 13 return p; 14 n = sprint(p, "%16.16llux %8.8ux %8.8ux %8.8ux %8.8ux ", 15 s->len, 16 s->state[0], s->state[1], s->state[2], 17 s->state[3]); 18 enc64(p+n, m-n, s->buf, s->blen); 19 return p; 20 } 21 22 MD5state* 23 md5unpickle(char *p) 24 { 25 MD5state *s; 26 27 s = malloc(sizeof(*s)); 28 if(s == nil) 29 return nil; 30 s->len = strtoull(p, &p, 16); 31 s->state[0] = strtoul(p, &p, 16); 32 s->state[1] = strtoul(p, &p, 16); 33 s->state[2] = strtoul(p, &p, 16); 34 s->state[3] = strtoul(p, &p, 16); 35 s->blen = dec64(s->buf, sizeof(s->buf), p, strlen(p)); 36 s->malloced = 1; 37 s->seeded = 1; 38 return s; 39 }