Commit graph

59 commits

Author SHA1 Message Date
Dag-Erling Smørgrav
531eeec36b Add a simple implementation of the Adler-32 checksum. 2015-08-18 13:27:06 +00:00
Dag-Erling Smørgrav
1609b4e08a Cite the Fletcher paper. 2015-08-18 10:42:41 +00:00
Dag-Erling Smørgrav
aa97da3335 Add simple implementations of Fletcher's checksum. 2015-08-17 15:21:47 +00:00
Dag-Erling Smørgrav
dc75f2edd8 Add a memset_s() implementation (cf. C11 / WG14 N1381) 2015-02-15 09:18:18 +00:00
Dag-Erling Smørgrav
342ac3fd78 Note that rand_bytes() is just a placeholder for the sake of liboath. 2015-01-08 12:24:19 +00:00
Dag-Erling Smørgrav
a33f58cad7 Fix equality predicate. 2015-01-07 19:23:38 +00:00
Dag-Erling Smørgrav
d0fb2359f1 Implement mpi_{add,sub}() in terms of mpi_{add,sub}_abs(). 2015-01-07 18:59:44 +00:00
Dag-Erling Smørgrav
7a90ca7b42 Since X may point to the same MPI as either G or L (or even both), we
can't set the carry flag based on the contents of G or L after having
modified X.  Instead, compute and stash the new carry value first.
2014-12-30 19:14:59 +00:00
Dag-Erling Smørgrav
0d483f20ab Fix msb calculation. We may have to backtrack quite a bit, for
instance when subtracting two nearly equal large numbers.
2014-12-30 16:45:18 +00:00
Dag-Erling Smørgrav
1c024928f9 Fix off-by-one bug in mpi_cmp() which could cause it to read past the
end of the buffer.
2014-12-30 16:35:13 +00:00
Dag-Erling Smørgrav
43b870dc83 WIP: implement subtraction correctly. The actual result is now correct
most of the time, but the MSB calculation is not.
2014-12-30 11:23:30 +00:00
Dag-Erling Smørgrav
7524a14386 comment nit 2014-12-30 11:15:28 +00:00
Dag-Erling Smørgrav
c5b962387c Add mpi_eq_abs() and mpi_eq() predicates. 2014-12-30 11:12:11 +00:00
Dag-Erling Smørgrav
bc8e9d67ba In both mpi_add_abs() and mpi_sub_abs(), make sure that the target is
untouched if the operation fails.  Also ensure that A = A +/- A works.
2014-12-29 23:44:34 +00:00
Dag-Erling Smørgrav
98c6349d4a In mpi_zero(), save a memset() if the target is already zero. 2014-12-29 23:22:54 +00:00
Dag-Erling Smørgrav
1412dac680 Shifting any number by zero places is a no-op, but so is shifting zero by
any number of places.
2014-12-29 23:20:26 +00:00
Dag-Erling Smørgrav
8228f19d5a In mpi_copy(), any failure should leave the target untouched. 2014-12-29 23:18:57 +00:00
Dag-Erling Smørgrav
82f5c5cf77 In mpi_load(), use be32dec() when possible.
In mpi_set(), it is impossible for the value being loaded to exceed
the minimum size of an mpi; thus, there is no need for mpi_grow().
2014-12-29 15:08:09 +00:00
Dag-Erling Smørgrav
79967f2844 Fix string_equal() for strings of unequal length. 2014-12-29 12:46:44 +00:00
Dag-Erling Smørgrav
2ad45cfccf Add a string comparison function and a string equality predicate.
Write test cases for the former.
2014-12-29 12:41:39 +00:00
Dag-Erling Smørgrav
f82bbc1400 Catch up with OpenPAM's latest OATH changes:
Add an oath_mode(3) function which translates from mode names to numbers.

 Consistently use UINT_MAX, not -1, to indicate an invalid response.

 Change the meaning of the window parameter to always indicate the number
 of codes to check *in addition* to the current code.  Note that for TOTP,
 the window goes in both directions; a window of 1 means to check the
 current code plus the previous and next.
2014-12-20 01:45:01 +00:00
Dag-Erling Smørgrav
a98753b6ef Fix various cast-qual bugs. 2014-12-20 00:44:24 +00:00
Dag-Erling Smørgrav
6ed802ddf3 Consistently use #if HAVE_FOO instead of #ifdef HAVE_FOO. The reason is
that AC_CHECK_DECLS([foo]), unlike AC_CHECK_FUNCS([foo]), will always
define HAVE_FOO, so #ifdef HAVE_FOO will always be true even if it is 0.
This commit finally fixes the [bl]e{32,64}{enc,dec} issue on Linux.
2014-12-20 00:38:54 +00:00
Dag-Erling Smørgrav
20dab3e342 Provisionally include strlcmp(), although it is not (currently) used
anywhere.  Opinion is divided as to whether this is useful, or whether
its usefulness is outweighed by its awkwardness.  Still, we have it, so
we may as well commit it.
2014-12-20 00:23:59 +00:00
Dag-Erling Smørgrav
e4dd25fa79 Use wstring throughout (except internally in struct cpe_name).
Add a typedef for struct cpe_name and use it throughout.
Fix inverted logic in cpe_upgrade().
2014-11-01 20:15:45 +00:00
Dag-Erling Smørgrav
f7bdd342dc Add our own version of <endian.h> which includes implementations of the
unaligned encoding / decoding functions which Linux lacks.
2014-10-30 12:48:21 +00:00
Dag-Erling Smørgrav
d4fd9a1958 rm unused variable 2014-08-12 07:33:30 +00:00
Dag-Erling Smørgrav
be31515f5e Start of a multiple-precision integer arithmetic library. 2014-08-12 07:30:31 +00:00
Dag-Erling Smørgrav
35d982ea57 Rename CPEXX_VER to cpeXX_ver and remove CPEXX_NATTR, which is redundant. 2014-08-01 22:38:36 +00:00
Dag-Erling Smørgrav
479ffbba4a Remove author and sponsor tags; we'll deal with that some other way.
Remove $Cryb$ tags as it is likely that the code will move to git.
2014-08-01 14:31:07 +00:00
Dag-Erling Smørgrav
526303caad WIP: CPE library. 2014-08-01 14:18:25 +00:00
Dag-Erling Smørgrav
bec11577b0 sbuf-inspired managed string implementation which also supports wide
strings.
2014-08-01 13:53:04 +00:00
Dag-Erling Smørgrav
fe2d45ad56 Create rol / ror functions for all integer sizes. 2014-07-19 15:36:07 +00:00
Dag-Erling Smørgrav
0023f57ab5 Add a library of general (non-cryptographic) hash functions, currently
consisting of the Pearson string hash function and the Murmur3-32 hash
function.
2014-07-19 06:03:57 +00:00
Dag-Erling Smørgrav
541d65a3cc pacify autoindenters 2014-07-19 02:59:42 +00:00
Dag-Erling Smørgrav
3ed82792fc Fix a bug that affected unterminated buffers: strlcat() would write a NUL
past the end of the buffer and return one less than the correct length.
2014-07-13 20:42:56 +00:00
Dag-Erling Smørgrav
910c782b2f In the md4 code, use a 64-bit counter to avoid a manual carry operation. 2014-07-12 22:10:57 +00:00
Dag-Erling Smørgrav
340b3240cf Consistently use const void * for data and keys, uint8_t * for digests
and MACs, and uint8_t, uint32_t or uint64_t (as appropriate) for internal
state.  Also remove a few unnecessary casts.
2014-07-12 21:57:31 +00:00
Dag-Erling Smørgrav
7f410bdfd3 Silence a GCC warning about an empty if statement. 2014-07-11 15:14:23 +00:00
Dag-Erling Smørgrav
30c8e19de7 Remove HMAC-MD2 and HMAC-MD4. They may or may not reappear at a later
date in libcryb-mac.
2014-07-11 13:54:22 +00:00
Dag-Erling Smørgrav
729e501b79 Mechanical whitespace cleanup 2014-07-11 13:40:06 +00:00
Dag-Erling Smørgrav
2c697a472b Implement SHA-224 and HMAC-SHA224. 2014-07-11 13:33:58 +00:00
Dag-Erling Smørgrav
6aa7f9a0e6 Implement HMAC-SHA{256,384,512} and add unit tests. Remove pre-existing
HMAC implementations from the libcperciva and XySSL code.
2014-07-11 13:01:32 +00:00
Dag-Erling Smørgrav
5bb81214cc Instead of storing the key in the hmac_sha1_ctx so we can compute the
output pad in hmac_sha1_final(), prepare a sha1 context in advance and
discard the key as early as possible.
Inspired by Colin Percival's HMAC-SHA-256 implementation.
2014-07-11 10:28:55 +00:00
Dag-Erling Smørgrav
950a1770e5 Breathe 2014-07-11 10:11:18 +00:00
Dag-Erling Smørgrav
26b512bfd7 Eliminate a variable 2014-07-11 10:10:50 +00:00
Dag-Erling Smørgrav
8f42136d40 Trust the compiler to eliminate unnecessary conversions. 2014-07-11 10:07:24 +00:00
Dag-Erling Smørgrav
fd77c1c38e Unroll the loop in sha1_compute(), speeding it up by about 50%. 2014-07-11 09:58:58 +00:00
Dag-Erling Smørgrav
dffacacccf The spec says XOR here, not OR. Interestingly, it doesn't seem to
make any difference.
2014-07-11 09:45:29 +00:00
Dag-Erling Smørgrav
cc13b6a16a Remove k from the sha1 context structure, as it is a constant.
Rearrange the sha1 context structure to improve alignment.
2014-07-11 09:17:05 +00:00