mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-18 21:29:19 +02:00
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.
This commit is contained in:
parent
db2b598cde
commit
a6ca2e39dc
4 changed files with 40 additions and 30 deletions
|
@ -108,7 +108,7 @@ RLDFLAGS=-Wl,-R$(DESTDIR)$(LIBDIR)
|
|||
endif
|
||||
|
||||
########################################################################
|
||||
# Check for NTP (who needs autoconf?)
|
||||
# Check for headers (who needs autoconf?)
|
||||
|
||||
ifndef $(SEXP_USE_NTP_GETTIME)
|
||||
SEXP_USE_NTP_GETTIME := $(shell echo "main(){struct ntptimeval n; ntp_gettime(&n);}" | gcc -fsyntax-only -include sys/timex.h -xc - >/dev/null 2>/dev/null && echo 1 || echo 0)
|
||||
|
@ -117,3 +117,11 @@ endif
|
|||
ifeq ($(SEXP_USE_NTP_GETTIME),1)
|
||||
CPPFLAGS += -DSEXP_USE_NTPGETTIME
|
||||
endif
|
||||
|
||||
ifndef $(SEXP_USE_INTTYPES)
|
||||
SEXP_USE_INTTYPES := $(shell echo "main(){int_least8_t x;}" | gcc -fsyntax-only -include inttypes.h -xc - >/dev/null 2>/dev/null && echo 1 || echo 0)
|
||||
endif
|
||||
|
||||
ifeq ($(SEXP_USE_INTTYPES),1)
|
||||
CPPFLAGS += -DSEXP_USE_INTTYPES
|
||||
endif
|
||||
|
|
|
@ -195,6 +195,34 @@ typedef int sexp_sint_t;
|
|||
#define sexp_heap_align(n) sexp_align(n, 4)
|
||||
#endif
|
||||
|
||||
#ifdef SEXP_USE_INTTYPES
|
||||
# include <inttypes.h>
|
||||
# ifdef UINT8_MAX
|
||||
# define SEXP_UINT8_DEFINED 1
|
||||
typedef uint8_t sexp_uint8_t;
|
||||
# endif
|
||||
# ifdef UINT32_MAX
|
||||
# define SEXP_UINT32_DEFINED 1
|
||||
typedef uint32_t sexp_uint32_t;
|
||||
# endif
|
||||
#else
|
||||
# include <limits.h>
|
||||
# if UCHAR_MAX == 255
|
||||
# define SEXP_UINT8_DEFINED 1
|
||||
typedef unsigned char sexp_uint8_t;
|
||||
# endif
|
||||
# if UINT_MAX == 4294967295U
|
||||
# define SEXP_UINT32_DEFINED 1
|
||||
typedef unsigned int sexp_uint32_t;
|
||||
# elif ULONG_MAX == 4294967295UL
|
||||
# define SEXP_UINT32_DEFINED 1
|
||||
typedef unsigned long sexp_uint32_t;
|
||||
# elif USHRT_MAX == 4294967295U
|
||||
# define SEXP_UINT32_DEFINED 1
|
||||
typedef unsigned short sexp_uint32_t;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if SEXP_USE_LONG_PROCEDURE_ARGS
|
||||
typedef int sexp_proc_num_args_t;
|
||||
#else
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
#ifndef CHIBI_CRYPTO_INTEGERS_H
|
||||
#define CHIBI_CRYPTO_INTEGERS_H
|
||||
|
||||
#if __STDC_VERSION__ >= 199901L /* C99 */
|
||||
# include <inttypes.h>
|
||||
typedef uint32_t sexp_uint32_t;
|
||||
typedef uint8_t sexp_uint8_t;
|
||||
#else
|
||||
# include <limits.h>
|
||||
#
|
||||
# if UCHAR_MAX == 255
|
||||
typedef unsigned char sexp_uint8_t;
|
||||
# else
|
||||
# error Could not find 8-bit type
|
||||
# endif
|
||||
#
|
||||
# if UINT_MAX == 4294967295U
|
||||
typedef unsigned int sexp_uint32_t;
|
||||
# elif ULONG_MAX == 4294967295UL
|
||||
typedef unsigned long sexp_uint32_t;
|
||||
# elif USHRT_MAX == 4294967295U
|
||||
typedef unsigned short sexp_uint32_t;
|
||||
# else
|
||||
# error Could not find 32-bit type
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#endif /* CHIBI_CRYPTO_INTEGERS_H */
|
|
@ -2,7 +2,9 @@
|
|||
/* Copyright (c) 2015 Alexei Lozovsky. All rights reserved. */
|
||||
/* BSD-style license: http://synthcode.com/license.txt */
|
||||
|
||||
#include "integers.h"
|
||||
#if !(SEXP_UINT8_DEFINED && SEXP_UINT32_DEFINED)
|
||||
# error SHA-2 requires exact 8-bit and 32-bit integers to be available
|
||||
#endif
|
||||
|
||||
/*
|
||||
* SHA-2 algorithms are described in RFC 6234:
|
||||
|
|
Loading…
Add table
Reference in a new issue