Commit graph

164 commits

Author SHA1 Message Date
Dag-Erling Smørgrav
06c2f1280a Add a missing break.
This was harmless as it would either fall through to an empty default statement (if CRYB_COVERAGE was defined) or out of the switch, but it's still bad style.
2017-09-04 21:00:01 +02:00
Dag-Erling Smørgrav
5c8745138e Add strchrnul(), wcschrnul(), and tests for the former. 2017-08-23 13:41:40 +02:00
Dag-Erling Smørgrav
944782f506 Remove unnecessary headers. 2017-08-23 13:19:59 +02:00
Dag-Erling Smørgrav
562ffa391e Slight cleanup. 2017-05-11 00:08:45 +02:00
Dag-Erling Smørgrav
8e0f4a293e Determine the default for CRYB_LEAKTEST at run-time.
When cryb-test is used as a framework for another project, the compile-time test is useless since cryb-test itself will have been built with coverage disabled.  Besides, it is not a reliable indicator of whether leak detection will work.  Instead, check if the heap is already dirty when we first gain control.
2017-05-11 00:08:45 +02:00
Dag-Erling Smørgrav
49c0d954ca Staticize an internal function. 2017-05-11 00:08:45 +02:00
Dag-Erling Smørgrav
7d22bec7bc Improve man pages for strlcat() and strlcpy(). 2017-05-02 12:52:19 +02:00
Dag-Erling Smørgrav
e99877752f Pass the correct va_list to vsnprintf(). 2017-05-01 21:20:50 +02:00
Dag-Erling Smørgrav
d80dc09f3c Improve comments for strlcat() and strlcpy(). 2017-05-01 21:20:50 +02:00
Dag-Erling Smørgrav
d4ae7a43cb Fix compiler warnings in Travis.
Travis forces _FORTIFY_SOURCE, which enables warn_unused_result annotations in glibc. Some of those annotations are of dubious value; in the case of asprintf(3) and vasprintf(3), they flag code that doesn't check the return value as unsafe even if it checks the pointer instead (which is guaranteed to be NULL in case of failure, and arguably more useful than the return value). Unfortunately, gcc intentionally ignores (void) casts, so we have no choice but to quench the warning with -Wno-unused-result. However, some of the compilers we wish to support don't recognize it, so we move it from the developer flags to the Travis environment.

While there, switch Travis from Precious to Trusty.
2017-05-01 16:52:22 +02:00
Dag-Erling Smørgrav
9926ca1118 Use the English name of the University. 2017-04-29 02:31:15 +02:00
Dag-Erling Smørgrav
a610b40c7b Merge pull request #10 from cryb-to/cryb-mpi
Fix equality predicates.
2017-04-22 06:03:03 +02:00
Dag-Erling Smørgrav
a09cdc6318 Fix equality predicates.
The count we passed to memcmp() in mpi_eq() and mpi_eq_abs() was actually the number of significant words in the MPI, rather than the number of bytes we wanted to compare.  Multiply by 4 to get the correct value.

To make the intent of the code more apparent, introduce a private MPI_MSW() macro which evaluates to the number of significant words (or 1-based index of the most significant word).  This also comes in handy in mpi_{add,sub,mul}_abs().

Add a couple of test cases which not only demonstrate the bug we fixed here but also demonstrate why we must compare whole words: on a big-endian machine, we would be comparing the unused upper bytes of the first and only word instead of the lower bytes which actually hold a value...
2017-04-22 05:32:25 +02:00
Dag-Erling Smørgrav
b28507b0e9 Fix counter increment in Salsa and ChaCha.
In my eagerness to eliminate a branch which is taken once per 2^38 bytes of keystream, I forgot that the state words are in host order.  Thus, the counter increment code worked fine on little-endian machines, but not on big-endian ones.  Switch to a simpler (branchful) solution.
2017-04-22 03:10:10 +02:00
Dag-Erling Smørgrav
bd3e353455 Add missing algorithms. 2017-04-21 18:57:51 +02:00
Dag-Erling Smørgrav
938dcaa450 Avoid any assumptions about the signedness of char. 2017-04-21 18:56:52 +02:00
Dag-Erling Smørgrav
c556bc0aa8 Implement MPI division. 2017-04-06 19:52:23 +02:00
Dag-Erling Smørgrav
3c2b134fe4 Implement fast increment / decrement functions. 2017-04-06 19:52:23 +02:00
Dag-Erling Smørgrav
111efcb949 Correct function descriptions. 2017-04-06 19:52:23 +02:00
Dag-Erling Smørgrav
2a66f62078 Implement MPI multiplication. 2017-04-06 19:52:23 +02:00
Dag-Erling Smørgrav
206c6ffc85 Implement ffs() / fls() and use the latter to compute the MSB. 2017-04-06 19:52:23 +02:00
Dag-Erling Smørgrav
8477c4ae0b Slightly improve function descriptions. 2017-04-06 19:51:47 +02:00
Dag-Erling Smørgrav
094635f394 Remove debugging code. 2017-04-06 19:51:47 +02:00
Dag-Erling Smørgrav
b4eb918dad Implement GCD using Stein's binary algorithm. 2017-04-06 19:51:47 +02:00
Dag-Erling Smørgrav
a11c52e896 Refactor the comparison predicates, check for identity first. 2017-04-06 19:51:47 +02:00
Dag-Erling Smørgrav
47a0bf838f Add functions for comparing an MPI to an integer. 2017-04-06 19:51:47 +02:00
Dag-Erling Smørgrav
26e434d64b Add functions that return the LSB and MSB of an MPI. 2017-04-06 19:51:47 +02:00
Dag-Erling Smørgrav
7e05fe419a Remove unused headers. 2017-04-06 19:51:47 +02:00
Dag-Erling Smørgrav
895d1eb539 Constify where possible. 2017-04-06 19:51:47 +02:00
Dag-Erling Smørgrav
9ee45d4e34 Fix sign bug in special cases in mpi_{add,sub}_abs().
We failed to clear the negative flag when handling trivial cases, so if one of the terms was 0 and the other was negative, the result would be an exact copy of the non-zero term instead of its absolute value.
2017-04-06 19:51:47 +02:00
Dag-Erling Smørgrav
cdbb565482 Silence compiler warnings about operator precedence. 2017-04-06 19:51:46 +02:00
Dag-Erling Smørgrav
c6536641c5 Major cleanup of the MD and SHA digests.
- Use the new vector byte-order conversion functions where appropriate.
- Use memset_s() instead of memset() where appropriate.
- Use consistent names and types for function arguments.
- Reindent, rename and reorganize to conform to Cryb style and idiom.

SHA224 and SHA256 were left mostly unchanged.  MD2 and MD4 were completely rewritten as the previous versions (taken from XySSL) seem to have been copied from RSAREF.

This breaks the ABI as some context structures have grown or shrunk and some function arguments have been changed from int to size_t.
2017-04-06 19:51:46 +02:00
Dag-Erling Smørgrav
ce5562d568 Remove unused struct member. 2017-04-06 19:51:46 +02:00
Dag-Erling Smørgrav
5c98dc1084 Assert that the cipher mode and key length are valid. 2017-04-06 19:51:46 +02:00
Dag-Erling Smørgrav
239ab3a471 Implement double- and triple-DES.
Single-DES is now a special case of triple-DES with all three keys being the same.  This is significantly slower than a pure single-DES implementation, but that's fine since nobody should be using it anyway.
2017-04-06 19:51:45 +02:00
Dag-Erling Smørgrav
0c06ab5330 Slight cleanup of the DES code. 2017-04-06 19:51:45 +02:00
Dag-Erling Smørgrav
700fa0718b Implement DES (single-key ECB only for now). 2017-04-06 19:51:45 +02:00
Dag-Erling Smørgrav
c671da9b1c Implement the Salsa family of stream ciphers.
Note that we only have unit tests for Salsa20.
2017-04-06 19:51:45 +02:00
Dag-Erling Smørgrav
cfd3951ee1 Implement the ChaCha family of stream ciphers. 2017-04-06 19:51:45 +02:00
Dag-Erling Smørgrav
d383e7ab62 Misc cleanup after API change. 2017-04-06 19:51:45 +02:00
Dag-Erling Smørgrav
c2f4fa524f Second iteration of the cryb-cipher API.
We now have separate encryption and decryption methods, and can process an arbitrary amount of plaintext or ciphertext per call, rounded down to the block size (if applicable).  For stream ciphers, we also have a keystream method which fills the provided buffer with an arbitrary amount of keystream (once again, rounded down if applicable).
2017-04-06 19:51:45 +02:00
Dag-Erling Smørgrav
52cf1f9d3c Rename t_verbose*() to t_printv*().
Not only is this a slightly more logical name, but it allows us to expose the verbose flag, previously private to cryb_t_main.c, as the equally logically named t_verbose.
2017-03-14 14:36:52 +01:00
Dag-Erling Smørgrav
fbf69f31cb Start using pkg-config / pkgconf. 2017-03-07 00:54:46 +01:00
Dag-Erling Smørgrav
cf46393d5e Remove an unused header and fix some naming nits. 2017-03-06 23:40:05 +01:00
Dag-Erling Smørgrav
d017611d76 All property names and values may be percent-encoded.
If the key length is not a multiple of 40 bits, its base32 representation may be padded, and that padding will be encoded.   We already decoded the label (which may contain spaces and other unsafe characters), but not the key.  For the sake of simplicity and robustness, we now decode the name and value of every property.

This corresponds to OpenPAM r886.
2017-03-05 17:06:30 +01:00
Dag-Erling Smørgrav
d419d7388a Remove an unnecessary pointer from struct aes_ctx.
The rk pointer in struct aes_ctx always pointed to the context's buffer and served no purpose whatsoever, but the compiler had no way of knowing that and could therefore not optimize away assignments to and from it.

Note that the removal of rk breaks the ABI, since it changes the size of struct aes_ctx, but we allow ourselves that because neither the API nor the ABI have been fixed yet.
2017-03-03 23:49:00 +01:00
Dag-Erling Smørgrav
f70dac496f Mechanically bump copyright dates to the date of the latest commit. 2017-02-19 20:07:43 +01:00
Dag-Erling Smørgrav
d4626dbd70 When freeing a mapped allocation, call UTRACE_FREE() again for the metadata. 2017-02-19 19:49:27 +01:00
Dag-Erling Smørgrav
d8f6837026 Eliminate a redundant newline. 2017-02-19 18:45:43 +01:00
Dag-Erling Smørgrav
692852a349 Report the correct size when tracing a realloc() call. 2017-02-19 18:13:07 +01:00