void afsnode::mkfh (nfs_fh *fhp) { if (!fhsecret_initialized) { rnd.getbytes (fhsecret, sizeof (fhsecret)); fhsecret_initialized = true; } bzero (fhp->data.base (), fhp->data.size ()); puthyper (fhp->data.base (), ino); memcpy (fhp->data.base () + 8, fhsecret, sizeof (fhsecret)); }
bool ocb::decrypt (void *_ptext, u_int64_t nonce, const void *_ctext, const blk *tag, size_t len) const { char *ptext = static_cast <char *> (_ptext); const char *ctext = static_cast <const char *> (_ctext); blk r; blkclear (&r); puthyper (r.c + (r.nc - 8), nonce); blkxor (&r, l[0]); k.encipher_bytes (r.c); blk s; blkclear (&s); size_t i = 1; blk tmp; while (len > blk::nc) { blkxor (&r, l[ffs (i) - 1]); tmp.get (ctext); blkxor (&tmp, r); k.decipher_bytes (tmp.c); blkxor (&tmp, r); tmp.put (ptext); blkxor (&s, tmp); ptext += blk::nc; ctext += blk::nc; len -= blk::nc; i++; }; blkxor (&r, l[ffs (i) - 1]); blkxor (&tmp, l[-1], r); tmp.c[tmp.nc - 1] ^= len << 3; k.encipher_bytes (tmp.c); blkxor (&s, tmp); for (u_int b = 0; b < len; b++) { s.c[b] ^= ctext[b]; ptext[b] = tmp.c[b] ^ ctext[b]; } blkxor (&tmp, s, r); k.encipher_bytes (tmp.c); return !memcmp (tag->c, tmp.c, tag->nc); }
void sha1oracle_init (sha1oracle_ctx *soc, size_t nbytes, u_int64_t idx) { u_char prefix[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; size_t i; mdblock_init (&soc->mdb, sha1oracle_consume); puthyper (prefix + 8, idx); mdblock_update (&soc->mdb, prefix, sizeof (prefix)); soc->firstblock = 1; soc->nbytes = nbytes; soc->nstate = (nbytes + 19) / 20; soc->state = malloc (20 * soc->nstate); for (i = 0; i < soc->nstate; i++) sha1_newstate (soc->state[i]); }
static void sha1oracle_consume (struct mdblock *mp, const u_char block[64]) { sha1oracle_ctx *soc = (sha1oracle_ctx *) mp; size_t i; if (soc->firstblock) { u_char wblock[64]; memcpy (wblock, block, sizeof (wblock)); for (i = 0; i < soc->nstate; i++) { puthyper (wblock, i); sha1_transform (soc->state[i], wblock); } soc->firstblock = 0; return; } for (i = 0; i < soc->nstate; i++) sha1_transform (soc->state[i], block); }