summaryrefslogtreecommitdiffstats
path: root/chksum.c
Commit message (Collapse)AuthorAgeFilesLines
* sha256/md5: allow characters and byte values.Kaz Kylheku2019-08-291-0/+42
| | | | | | | | | * chksum.c (sha256_utf8_byte_callback, md5_utf8_byte_callback): New static functions. (sha256_hash, md5_hash): Support character and integer objects. * txr.1: Documented.
* sha256/md5: state-based hash: handle size_t overflow.Kaz Kylheku2019-08-241-20/+20
| | | | | | | | | | | | * chksum.c (sha256_szmax_upd, md5_szmax_upd): New static functions, consisting of logic from sha256_buf and md5_buf, respectively. (sha256_buf, md5_buf): Use sha256_szmax_up and md5_szmax_upd, respectively, to handle the unlikely possiblity of the ucnum buffer length being larger than the range of size_t. (sha256_hash, md5_hash): Also use the new static functions instead of callig SHA256_update or MD5_update directly to deal with the same issue.
* sha256/md5: hash string more efficiently.Kaz Kylheku2019-08-241-4/+12
| | | | | | * chksum.c (sha256_str, md5_str): Don't construct a byte input stream for hashing a string. Just convert whole thing to temporary UTF-8, hash, and free.
* New state-object-based sha256 and md5 digesting.Kaz Kylheku2019-08-231-0/+112
| | | | | | | | | | | | | | | * chksum.c (sha256_ctx_s, md5_ctx_s): New symbol variables. (sha256_ops, md5_ops): New static structs. (sha256_begin, sha256_hash, sha256_end, md5_begin, md5_hash, md5_end): New functions. (chksum_init): New symbol variables initialized; sha256-begin, sha256-hash, sha256-end, md5-begin, md5-hash, md5-end intrinsics registered. * chksum.h (sha256_begin, sha256_hash, sha256_end, md5_begin, md5_hash, md5_end): Declared. * txr.1: Documented.
* New: MD5 digest functions.Kaz Kylheku2019-08-231-10/+116
| | | | | | | | | | | | | | | | | * Makefile (OBJS): New object file, chksums/md5.o. * chksum.c (sha256_ensure_buf): Renamed to chksum_ensure_buf and made generic so MD5 code can borrow it. (sha256_stream, sha256): Call chksum_ensure_buf instead of sha256_ensure_buf, passing in new length and hash name parameters. (md5_stream_impl, md5_buf, md5_str): New static functions. (md5_stream, md5): New functions. (chksum_init): Register md5-stream and md5 intrinsics. * chksum.h (md5_stream, md5): Declared. * chksums/md5.c, chksums/md5.h: New files.
* crc32-stream: recycle I/O buffer.Kaz Kylheku2019-07-041-2/+3
| | | | | * chksum.c (crc32_stream): use iobuf_get to obtain the I/O buffer, and iobuf_put to recycle it.
* sha256: allow application to specify digest buffer.Kaz Kylheku2019-07-041-13/+38
| | | | | | | | | | | | | | | | | | | | | * chksum.c (sha256_stream_impl): New static function, formed out of bulk of sha256_stream. Takes a pointer to a buffer where the digest is stored. (sha256_ensure_buf): New static function. (sha256_stream): Take buf argument; use sha256_ensure_buf to allocate a buffer if necessary, and to obtain the low-level buffer pointer. Implementation moved into sha256_stream_impl. (sha256_buf, sha256_str): Take pointer to digest buffer; don't allocate a buf object, don't return anything. (sha256): Take buf argument; use sha256_ensure_buf to allocate a buffer if necessary, and to obtain the low-level buffer pointer, which is passed to sha256_buf and sha256_str. (chksum_init): Update registrations of intrinsics with new optional parameters. * chksum.h (sha256_stream, sha256): Declarations updated. * txr.1: Updated.
* sha256: recycle I/O buffer used in stream hash.Kaz Kylheku2019-07-041-2/+3
| | | | | | | | | | | | | * chksum.c (sha256_stream): Use iobuf_get and iobuf_put. * gc.c (gc): Do not mark the list of recycled buffers; just consider them to be garbage and clear the list, like we do with recycled conses via rcyc_empty. * stream.c (iobuf_free_list): New static variable. (iobuf_get, iobuf_put, iobuf_list_empty): New functions. * stream.h (iobuf_get, iobuf_put, iobuf_list_empty): Declared.
* New: CRC-32 functions.Kaz Kylheku2019-06-241-0/+87
| | | | | | | | | | | | * Makefile (OBJS): Add chksums/crc32.o. * chksum.c (crc32_stream, crc32): New functions. (chksum_init): Register crc32-stream and crc32 intrinsic functions. * chksums/crc32.c, chksums/crc32.h: New files. * txr.1: Documented.
* * Makefile (OBJS): New objects chksum.o and chksums/sha256.o.Kaz Kylheku2019-06-231-0/+142
* chksum.c, chksum.h, chksums/sha256.c, chksums/sha256.h: New files. * lib.c (init): Call chksum_init. * txr.1: Documented. * LICENSE: Add SHA-256 copyright notice.