i think the key is to find something secure (and thus, "correct") and not doused with tons of portability goo (ifdefs, etc.)
look at openssh, but the one in openbsd's tree and not the portable branch. for that matter, any of the openbsd-developed daemons (openbgpd, openntpd, etc.) at http://www.openbsd.org/cgi-bin/cvsweb/src/usr.sbin/ or usr.bin/ssh for openssh.
any of the openwall projects are also small and easy to work with - http://www.openwall.com/