Commit graph

17 commits

Author SHA1 Message Date
Alex Shinn
6d3ae7a28e replacing (srfi 142) with (srfi 151) 2017-08-21 22:32:57 +09:00
Alex Shinn
eb79e98d20 adding (srfi 142), using that in place of (srfi 33) 2017-04-16 22:06:56 +09:00
Alex Shinn
46687d7307 removing (chibi) import from sha2 tests 2017-01-23 23:29:26 +09:00
Alex Shinn
cd258bfc08 removing (chibi) import from md5 tests 2017-01-23 23:26:31 +09:00
Alex Shinn
b60a9a28a7 move definitions to start of body 2016-02-28 18:05:02 +09:00
Alex Shinn
c52873e8b9 Prefer SRFI 33 over SRFI 60, preventing import cycles when a user has
a SRFI 60 installed which imports (scheme base).  This can still break
in theory if a user installs a third-party SRFI 33 in the search path
in front of the Chibi SRFI 33, but we can't always be safe against
such behavior.
Fixes issue #267.
2015-06-09 00:14:03 +09:00
Alex Shinn
76ba196fba More documentation improvements. 2015-05-01 07:55:25 +09:00
Alex Shinn
00691b64f1 Making libraries portable where possible.
Many still import (chibi), and as (scheme base) is somewhat more
expensive to load at present these are changed to cond-expand.
Many libraries also rely on (srfi 33), and these have been changed
to a cond-expand first trying (srfi 60) where available.
Also fixing a few portability concerns (duplicate imports of the
same binding), and adding a few libraries missing from lib-tests.scm.
2015-04-26 16:17:38 +09:00
ilammy
a6ca2e39dc chibi.crypto: move sexp_uintN_t typedefs to <sexp.h>
First we check for C99 support in Makefile.detect, looking for the
header we need and verifying whether it is the right one by using
a definition required by C99 standard to be present in that header.

uintN_t types are optional, but implementations are required to
provide corresponding limit #defines for the types they support,
so we can check for this with preprocessor only.

Finally, we define SEXP_UINTN_DEFINED for any sexp_uintN_t we have
so that the code can use #ifs to check for exact integer support.
2015-04-19 16:01:11 +03:00
ilammy
db2b598cde chibi.crypto: code style fixes
- Fixed some typos in sha-native.scm
- Removed unnecessary structs and unions from sha_context
- Used more efficient implementation of hex32
- Made (scheme base) a common import in (chibi crypto sha2)
2015-04-19 16:01:07 +03:00
ilammy
9088b1954c chibi.crypto: make Chibi use native SHA-2 by default
This change concerns only Chibi. The portable implementation is
still kept around because it is... well... portable and can be
used by other Scheme implementations.
2015-04-18 17:31:46 +03:00
ilammy
1f8c0088a7 chibi.crypto: fix formatting bug in portable SHA-2
We can't use 'integer->hex-string' alone to print out SHA-224/256
digest because it rightly converts #x00001234 into "1234", while
we need to keep the padding zero nibbles and get "00001234".

'hex' got renamed into 'hex32' because SHA-512 will need some
different 'hex64' which returns 16-character-long strings.
2015-04-18 17:31:46 +03:00
ilammy
37d808e470 chibi.crypto: more tests for SHA-2
* Boundary cases

  Both SHA-224 and SHA-256 use 512-bit data chunks and have a special
  behavior when chunk size is near the 448-bit boundary.

* Source type support

  Basic smoke tests for accepting bytevectors and binary input ports
  as valid arguments.
2015-04-18 17:31:45 +03:00
ilammy
baff1af72d chibi.crypto: native SHA-2 implementation
The original Scheme implementation is astonishingly slow. Rewriting
SHA-2 in C yields around x10000 speed boost for premade strings and
bytevectors. For input ports this is alleviated to x100 boost.

The implementation is divided into two parts: native computational
backend and thin Scheme interface. It is tedious to properly do IO
from C, so the Scheme code handles reading data from an input port
and the C code performs actual computations on byte buffers (which
is also used to handle strings and bytevectors directly).

Scheme wrapper reads data in chunked manner with 'read-bytevector'.
Currently, the chunk size has insignificant impact on performance
as soon as it is bigger than 64. Also, using simply read-bytevector
turned out to be 33% faster than preallocating a buffer and filling
it with read-bytevector!

One tricky part is how to get exact 32-bit integers in C89. We have
no <inttypes.h> there, so instead we use <limits.h> to see whether
we have a standard type with suitable boundaries.

The other one is how to return a properly tagged sha_context from C.
Chibi FFI currently cannot handle the case when a procedure returns
either a C pointer (which needs to be boxed) or an exception (which
should be left as is). To workaround this sexp_start_sha() receives
a dummy argument of type sha_context; this makes Chibi FFI to put a
proper type tag into 'self', which is then extracted in the C code.

This commits adds a new shared library 'crypto$(SO)' with intent to
keep there all native code of (chibi crypto) libraries. This allows
to simply put any future native implementation of SHA-512 or MD5 in
some md5.c and just include those files into crypto.stub.
2015-04-18 17:31:45 +03:00
ilammy
78a57dfe83 chibi.crypto: documentation for (chibi crypto sha-2)
Clearly state what kind of arguments sha-224 and sha-256 can handle
and what they return as a result.
2015-04-18 17:31:44 +03:00
Alex Shinn
4e5cdedc03 Converting tests to modules instead of separate programs.
By convention, a library meant for testing exports "run-tests".
Also by convention, assume the test for (foo bar) is (foo bar-test),
keeping the test in the same directory and avoiding confusion since
(chibi test) is not a test for (chibi).
- Avoids the hack of "load"ing test, with resulting namespace complications.
- Allows keeping tests together with the libraries.
- Allows setting up test hooks before running.
- Allows implicit inference of test locations when using above conventions.
2015-04-05 23:38:51 +09:00
Alex Shinn
2922ed591d Forgot to install regexp (patch from Lorenzo) 2015-01-26 08:06:59 +09:00